EnginTestController.java 3.2 KB
package com.sy.controller;

import com.sy.model.GatherInfo;
import lombok.extern.slf4j.Slf4j;
import org.basis.enhance.groovy.entity.EngineExecutorResult;
import org.basis.enhance.groovy.entity.ExecuteParams;
import org.basis.enhance.groovy.entity.ScriptQuery;
import org.basis.enhance.groovy.executor.EngineExecutor;
import org.basis.enhance.groovy.helper.RefreshScriptHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@Slf4j
@RequestMapping("/v1/load-from-redis")
public class EnginTestController {


    @Autowired
    private EngineExecutor engineExecutor;

    @Autowired
    private RefreshScriptHelper refreshScriptHelper;

    @GetMapping("/x21-check")
    public String x21Check(String scriptName) {
        // 构建参数
        ExecuteParams executeParams = buildGatherInfoParams();
        // 执行脚本中指定的方法 changeProduct
        EngineExecutorResult executorResult = engineExecutor.execute(
                "baseCheck", new ScriptQuery(scriptName), executeParams);
        log.info("使用groovy脚本来动态修改闪屏信息=========>>>>>>>>>>>执行结果:{}", executorResult);

        return "success";
    }

    @GetMapping("/form-check")
    public String formCheck(String scriptName) {
        // 构建参数
        ExecuteParams executeParams = buildGatherInfoParams();
        // 执行脚本中指定的方法 changeProduct
        EngineExecutorResult executorResult = engineExecutor.execute(
                "formCheck", new ScriptQuery(scriptName), executeParams);
        log.info("使用groovy脚本来动态修改闪屏信息=========>>>>>>>>>>>执行结果:{}", executorResult);

        return "success";
    }

    /**
     * 过磅x21报文实体
     */
    public ExecuteParams buildGatherInfoParams(){
        GatherInfo gatherInfo = new GatherInfo();
        gatherInfo.setAreaid("4604600000");
        gatherInfo.setChnlno("4604601010");
        gatherInfo.setBarcode("fe3-4c1b-befe-afa4a68d80c1");
        gatherInfo.setGrosswt(new BigDecimal("6478"));
        gatherInfo.setSeqno("20220630184441000028");
        gatherInfo.setIetype("I");
        gatherInfo.setVename("豫A61CR7");

        ExecuteParams executeParams = new ExecuteParams();
        executeParams.put("gatherInfo", gatherInfo);

        return executeParams;
    }

    @GetMapping("/refreshCache")
    public String refresh(String scriptName) {
        // 手动刷新脚本到内存
        boolean flag = refreshScriptHelper.refresh(new ScriptQuery(scriptName), true);
        System.out.println("是否刷新成功:" + flag);
        return String.valueOf(flag);
    }

    /**
     * 手动刷新所有脚本到内存
     * url: http://localhost:1234/v1/refresh/test02
     */
    @GetMapping("/refreshCacheAll")
    public String refreshAll() throws Exception {
        // 手动刷新所有脚本到内存
        boolean flag = refreshScriptHelper.refreshAll();
        System.out.println("是否刷新成功:" + flag);
        return String.valueOf(flag);
    }
}