| | |
| | | |
| | | @GetMapping(PREFIX + "/schedule-scheme/list") |
| | | @Operation(summary = "获取调度方案列表") |
| | | List<StScheduleSchemeDTO> listScheduleScheme(@RequestParam Map<String, Object> params); |
| | | List<StScheduleSchemeDTO> listScheduleScheme(@RequestParam("triggerMethod") String triggerMethod, @RequestParam("triggerCondition") String triggerCondition); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.enums; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * 调度模型触发方式 |
| | | * |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2024年12月31日 |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum ScheduleTriggerMethodEnum { |
| | | |
| | | EVENT("1", "事件触发"), |
| | | JOB("2", "定时触发"); |
| | | |
| | | private String code; |
| | | private String desc; |
| | | |
| | | public static ScheduleTriggerMethodEnum getEumByCode(String code) { |
| | | if (code == null) { |
| | | return null; |
| | | } |
| | | |
| | | for (ScheduleTriggerMethodEnum statusEnum : ScheduleTriggerMethodEnum.values()) { |
| | | if (statusEnum.getCode().equals(code)) { |
| | | return statusEnum; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | |
| | | datatime datetime, |
| | | datavalue decimal(19, 3), |
| | | primary key (id), |
| | | INDEX idx_outputid (outputid), |
| | | INDEX idx_datatime (datatime) |
| | | UNIQUE KEY `unique_outputid_datatime` (`outputid`,`datatime`), |
| | | KEY `idx_outputid_datatime` (`outputid`,`datatime`) USING BTREE |
| | | ) engine = innodb |
| | | default character set utf8mb4 COMMENT = '预测结果表'; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<StScheduleSchemeDTO> listScheduleScheme(Map<String, Object> params) { |
| | | public List<StScheduleSchemeDTO> listScheduleScheme(String triggerMethod, String triggerCondition) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("triggerMethod", triggerMethod); |
| | | params.put("triggerCondition", triggerCondition); |
| | | return stScheduleSchemeService.list(params); |
| | | } |
| | | |
| | |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleRecordService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleSchemeService; |
| | | import com.iailab.module.model.mdk.factory.ItemEntityFactory; |
| | | import com.iailab.module.model.mdk.factory.PredictItemFactory; |
| | | import com.iailab.module.model.mdk.predict.PredictModuleHandler; |
| | | import com.iailab.module.model.mdk.predict.PredictResultHandler; |
| | | import com.iailab.module.model.mdk.schedule.ScheduleModelHandler; |
| | |
| | | import com.iailab.framework.tenant.core.db.dynamic.TenantDS; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemResultEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | |
| | | void savePredictValue(Map<String, Object> params); |
| | | |
| | | void saveOrUpdateItemResult(@Param("list") List<MmItemResultEntity> list); |
| | | |
| | | void savePredictJsonValue(Map<String, Object> params); |
| | | } |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | map4.put("entity", resultJson); |
| | | mmItemResultDao.savePredictJsonValue(map4); |
| | | |
| | | Map<String, Object> params = new HashMap(4); |
| | | params.put("TABLENAME", T_MM_ITEM_RESULT); |
| | | params.put("OUTPUTID", entry.getKey()); |
| | | params.put("STARTTIME", importList.get(0).getDatatime()); |
| | | params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime()); |
| | | mmItemResultDao.deletePredictValue(params); |
| | | // Map<String, Object> params = new HashMap(4); |
| | | // params.put("TABLENAME", T_MM_ITEM_RESULT); |
| | | // params.put("OUTPUTID", entry.getKey()); |
| | | // params.put("STARTTIME", importList.get(0).getDatatime()); |
| | | // params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime()); |
| | | // mmItemResultDao.deletePredictValue(params); |
| | | } |
| | | mmItemResultDao.insertBatch(importList,max_group_count); |
| | | // 存在则修改,不存在插入 |
| | | mmItemResultDao.saveOrUpdateItemResult(importList); |
| | | |
| | | Map<String, Object> map3 = new HashMap<>(2); |
| | | map3.put("TABLENAME", "T_MM_ITEM_RESULT_LAST_POINT"); |
| | |
| | | for (Map.Entry<String, Object > entry: resultVO.getResult().entrySet()) { |
| | | StScheduleRecordDetailEntity entity = new StScheduleRecordDetailEntity(); |
| | | entity.setId(UUID.randomUUID().toString()); |
| | | entity.setId(recordId); |
| | | entity.setRecordId(recordId); |
| | | entity.setSchemeId(resultVO.getSchemeId()); |
| | | entity.setModelId(resultVO.getModelId()); |
| | | entity.setScheduleTime(resultVO.getScheduleTime()); |
| | |
| | | @Override |
| | | public List<StScheduleSchemeDTO> list(Map<String, Object> params) { |
| | | QueryWrapper<StScheduleSchemeEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("trigger_method", params.get("trigger_method")); |
| | | queryWrapper.eq("trigger_condition", params.get("trigger_condition")); |
| | | queryWrapper.eq("trigger_method", params.get("triggerMethod")); |
| | | queryWrapper.eq("trigger_condition", params.get("triggerCondition")); |
| | | List<StScheduleSchemeEntity> list = baseDao.selectList(queryWrapper); |
| | | return ConvertUtils.sourceToTarget(list, StScheduleSchemeDTO.class); |
| | | } |
| | |
| | | param2Values[portLength] = settings; |
| | | |
| | | log.info("#######################调度模型 " + scheduleModel.getModelName() + " ##########################"); |
| | | // JSONObject jsonObjNewModelBean = new JSONObject(); |
| | | // jsonObjNewModelBean.put("newModelBean", newModelBean); |
| | | // log.info(String.valueOf(jsonObjNewModelBean)); |
| | | // JSONObject jsonObjParam2Values = new JSONObject(); |
| | | // jsonObjParam2Values.put("param2Values", param2Values); |
| | | log.info("参数: " + JSON.toJSONString(param2Values)); |
| | | |
| | | //IAILMDK.run |
| | | HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, scheduleScheme.getMpkprojectid()); |
| | | if (!modelResult.containsKey(CommonConstant.MDK_STATUS_CODE) || !modelResult.containsKey(CommonConstant.MDK_RESULT) || |
| | | !modelResult.get(CommonConstant.MDK_STATUS_CODE).toString().equals(CommonConstant.MDK_STATUS_100)) { |
| | | throw new RuntimeException("模型结果异常:" + modelResult); |
| | | } |
| | | modelResult = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT); |
| | | String statusCode = modelResult.get(CommonConstant.MDK_STATUS_CODE).toString(); |
| | | modelResult = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT); |
| | | //打印结果 |
| | | JSONObject jsonObjResult = new JSONObject(); |
| | | jsonObjResult.put("result", modelResult); |
| | |
| | | import java.lang.reflect.Method; |
| | | import java.net.URL; |
| | | import java.net.URLClassLoader; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.Vector; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | public class DllUtils { |
| | | |
| | | private static HashMap<String, URLClassLoader> classLoaderCache = new HashMap<>(); |
| | | private static HashMap<String, Object> classCache = new HashMap<>(); |
| | | private static HashMap<String, Method> classMethodCache = new HashMap<>(); |
| | | |
| | | /** |
| | | * @description: 加载dll到指定class下 |
| | |
| | | unloadDll(urlClassLoader); |
| | | unloadJar(urlClassLoader); |
| | | classLoaderCache.remove(projectId); |
| | | removeClassCache(projectId); |
| | | removeClassMethodCache(projectId); |
| | | } |
| | | } |
| | | public static synchronized void removeClassCache(String projectId) { |
| | | for (String key : classCache.keySet()) { |
| | | if (key.startsWith(projectId)) { |
| | | classCache.remove(key); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static synchronized void removeClassMethodCache(String projectId) { |
| | | for (String key : classMethodCache.keySet()) { |
| | | if (key.startsWith(projectId)) { |
| | | classMethodCache.remove(key); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } else if (model == null) { |
| | | throw new RuntimeException("模型文件不能为空!"); |
| | | } else { |
| | | URLClassLoader classLoader = DllUtils.getClassLoader(projectId); |
| | | if (null == classLoader) { |
| | | throw new RuntimeException("dll未发布,classLoader为null"); |
| | | String classCacheKey = projectId + "_" + model.getClassName(); |
| | | String methodParams = Arrays.stream(model.getParamsArray()).map(e -> e.getName()).collect(Collectors.joining(",")); |
| | | String classMethodCacheKey = classCacheKey + "." + model.getMethodName() + "(" + methodParams + ")"; |
| | | if (classCache.containsKey(classCacheKey) && classMethodCache.containsKey(classMethodCacheKey)) { |
| | | return (HashMap)classMethodCache.get(classMethodCacheKey).invoke( classCache.get(classCacheKey), paramsValueArray); |
| | | }else { |
| | | URLClassLoader classLoader = DllUtils.getClassLoader(projectId); |
| | | if (null == classLoader) { |
| | | throw new RuntimeException("dll未发布,classLoader为null"); |
| | | } |
| | | Class<?> clazz = classLoader.loadClass(model.getClassName()); |
| | | Object o = clazz.newInstance(); |
| | | Method method = clazz.getMethod(model.getMethodName(), model.getParamsArray()); |
| | | classCache.put(classCacheKey,o); |
| | | classMethodCache.put(classMethodCacheKey,method); |
| | | return (HashMap)method.invoke(o, paramsValueArray); |
| | | } |
| | | Class<?> clazz = classLoader.loadClass(model.getClassName()); |
| | | Method method = clazz.getMethod(model.getMethodName(), model.getParamsArray()); |
| | | return (HashMap)method.invoke(clazz.newInstance(), paramsValueArray); |
| | | } |
| | | } |
| | | } |
| | |
| | | VALUES (#{entity.id},#{entity.outputid},#{entity.predicttime},#{entity.jsonvalue},#{entity.cumulant}) |
| | | </insert> |
| | | |
| | | <insert id="saveOrUpdateItemResult" parameterType="com.iailab.module.model.mcs.pre.entity.MmItemResultEntity"> |
| | | INSERT INTO t_mm_item_result (id,outputid, datatime, datavalue) VALUES |
| | | <foreach item="item" collection="list" separator=","> |
| | | (#{item.id},#{item.outputid},#{item.datatime},#{item.datavalue}) |
| | | </foreach> |
| | | ON DUPLICATE KEY UPDATE datavalue = VALUES(datavalue) |
| | | </insert> |
| | | |
| | | |
| | | </mapper> |