dengzedong
6 天以前 c9e48bd2dff2b5766589024cf7264189b5f2a05c
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java
@@ -28,6 +28,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author PanZhibao
@@ -51,7 +52,8 @@
    private SampleConstructor sampleConstructor;
    @Override
    public ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime) throws ModelInvokeException {
    public ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime, Map<Integer, Integer> dynamicDataLength,
                                       Map<String, String> dynamicSettings) throws ModelInvokeException {
        ScheduleResultVO scheduleResult = new ScheduleResultVO();
        StScheduleSchemeEntity scheduleScheme = stScheduleSchemeService.getByCode(schemeCode);
        StScheduleModelEntity scheduleModel = stScheduleModelService.get(scheduleScheme.getModelId());
@@ -63,7 +65,8 @@
        try {
            //1.根据模型id构造模型输入样本
            long now = System.currentTimeMillis();
            List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime,scheduleScheme.getName());
            List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime,
                    scheduleScheme.getName(), dynamicDataLength);
            log.info("构造模型输入样本消耗时长:" + (System.currentTimeMillis() - now) / 1000 + "秒");
            if (CollectionUtils.isEmpty(sampleDataList)) {
                log.info("调度模型构造样本失败,schemeCode=" + schemeCode);
@@ -71,7 +74,7 @@
            }
            IAILModel newModelBean = composeNewModelBean(scheduleModel);
            HashMap<String, Object> settings = getScheduleSettingsByModelId(modelId);
            HashMap<String, Object> settings = getScheduleSettingsByModelId(modelId, dynamicSettings);
            if (settings == null) {
                log.error("模型setting不存在,modelId=" + modelId);
                return null;
@@ -93,10 +96,14 @@
            //IAILMDK.run
            HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, scheduleScheme.getMpkprojectid());
            if (!modelResult.containsKey(CommonConstant.MDK_STATUS_CODE) || !modelResult.containsKey(CommonConstant.MDK_RESULT)) {
                throw new RuntimeException("模型结果异常:" + modelResult);
                log.info("模型结果异常:" + modelResult);
            }
            String statusCode = modelResult.get(CommonConstant.MDK_STATUS_CODE).toString();
            HashMap<String, Object> result = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT);
            HashMap<String, Object> result = new HashMap<>();
            if (modelResult.containsKey(CommonConstant.MDK_RESULT) && modelResult.get(CommonConstant.MDK_RESULT) != null &&
                    CommonConstant.MDK_STATUS_100.equals(modelResult.get(CommonConstant.MDK_STATUS_CODE).toString())) {
                result = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT);
            }
            //打印结果
            JSONObject jsonObjResult = new JSONObject();
            jsonObjResult.put("result", result);
@@ -121,13 +128,22 @@
     * 根据模型id获取参数map
     *
     * @param modelId
     * @param dynamicSettings
     * @return
     */
    private HashMap<String, Object> getScheduleSettingsByModelId(String modelId) {
    private HashMap<String, Object> getScheduleSettingsByModelId(String modelId, Map<String, String> dynamicSettings) {
        List<StScheduleModelSettingEntity> list = stScheduleModelSettingService.getByModelId(modelId);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        //如果输入参数中包含setting,则覆盖默认的setting
        if (!CollectionUtils.isEmpty(dynamicSettings)){
            list.forEach(setting -> {
                if (dynamicSettings.containsKey(setting.getKey())) {
                    setting.setValue(dynamicSettings.get(setting.getKey()));
                }
            });
        }
        HashMap<String, Object> result = new HashMap<>();
        for (StScheduleModelSettingEntity entry : list) {
            String valueType = entry.getValuetype().trim(); //去除两端空格