| | |
| | | @Operation(summary = "修改调度模型设置参数") |
| | | Boolean modifyScheduleModelSetting(@RequestBody List<ScheduleModelSettingReqDTO> dtos); |
| | | |
| | | @GetMapping(PREFIX + "/schedule-model/out") |
| | | @Operation(summary = "调度模型数据下发") |
| | | Boolean scheduleModelOut(@RequestParam MdkScheduleRespDTO dto); |
| | | |
| | | @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.api.mcs.dto; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | @Schema(description = "RPC 模型 - 下发配置 DTO") |
| | | @Data |
| | | public class StScheduleModelOutDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | private String id; |
| | | |
| | | /** |
| | | * 模型id |
| | | */ |
| | | private String modelId; |
| | | |
| | | /** |
| | | * key |
| | | */ |
| | | private String resultKey; |
| | | |
| | | /** |
| | | * 数据类型 |
| | | */ |
| | | private String resultType; |
| | | |
| | | /** |
| | | * resultPort |
| | | */ |
| | | private Integer resultPort; |
| | | |
| | | /** |
| | | * resultIndex |
| | | */ |
| | | private Integer resultIndex; |
| | | |
| | | /** |
| | | * 是否下发 |
| | | */ |
| | | private Integer isWrite; |
| | | |
| | | /** |
| | | * 下发的点位 |
| | | */ |
| | | private String pointNo; |
| | | |
| | | /** |
| | | * 排序 |
| | | */ |
| | | private Integer sort; |
| | | |
| | | /** |
| | | * 无扰切换点位 |
| | | */ |
| | | private String disturbancePointNo; |
| | | } |
对比新文件 |
| | |
| | | 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 = '预测结果表'; |
| | | |
| | |
| | | import org.springframework.boot.CommandLineRunner; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.context.annotation.ComponentScan; |
| | | import org.springframework.scheduling.annotation.EnableAsync; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueWriteDTO; |
| | | import com.iailab.module.data.common.ApiDataQueryDTO; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.*; |
| | |
| | | import com.iailab.module.model.mcs.pre.entity.MmPredictAlarmMessageEntity; |
| | | import com.iailab.module.model.mcs.pre.service.*; |
| | | import com.iailab.module.model.mcs.pre.vo.MmPredictAlarmMessageSaveReqVO; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelOutEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleSuggestEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelOutService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleSchemeService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleSuggestService; |
| | | import com.iailab.module.model.mcs.sche.vo.StScheduleSuggestSaveReqVO; |
| | |
| | | public class McsApiImpl implements McsApi { |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private DmModuleService dmModuleService; |
| | | |
| | | @Autowired |
| | |
| | | |
| | | @Autowired |
| | | private MmItemResultLastPointService mmItemResultLastPointService; |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private MmItemResultJsonService mmItemResultJsonService; |
| | |
| | | |
| | | @Autowired |
| | | private StScheduleSchemeService stScheduleSchemeService; |
| | | |
| | | @Autowired |
| | | private StScheduleModelOutService stScheduleModelOutService; |
| | | |
| | | private int HOUR_MINS = 60; |
| | | |
| | |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean scheduleModelOut(MdkScheduleRespDTO dto) { |
| | | String modelId = stScheduleSchemeService.getByCode(dto.getScheduleCode()).getModelId(); |
| | | Map<String,Object> result = dto.getResult(); |
| | | List<StScheduleModelOutDTO> list = stScheduleModelOutService.list(modelId); |
| | | try{ |
| | | list.forEach( |
| | | item -> { |
| | | double value = 0; |
| | | //判断点位是否下发以及返回结果是否存在 |
| | | if(item.getIsWrite()==1){ |
| | | if(result.get(item.getResultKey())==null){ |
| | | log.error(result.get(item.getResultKey()) + "resultKey匹配失败"); |
| | | } |
| | | Object resultValue = result.get(item.getResultKey()); |
| | | //判断解析方式 |
| | | if(item.getResultType().equals("double")){ |
| | | if(resultValue instanceof Double) { |
| | | value = (Double) resultValue; |
| | | } |
| | | }else if(item.getResultType().equals("double[]")){ |
| | | ArrayList<Double> doubleList = (ArrayList<Double>) resultValue; |
| | | double[] array = new double[doubleList.size()]; |
| | | for (int i = 0; i < doubleList.size(); i++) { |
| | | array[i] = doubleList.get(i); |
| | | } |
| | | if(array!= null && item.getResultPort() < array.length){ |
| | | value = array[item.getResultPort()]; |
| | | }else{ |
| | | log.error(result.get(item.getResultKey()) + "下角标超限"); |
| | | } |
| | | |
| | | }else if(item.getResultType().equals("double[][]")){ |
| | | if (item.getResultType().equals("double[][]")) { |
| | | if (resultValue instanceof ArrayList) { |
| | | ArrayList<ArrayList<Double>> doubleListList = (ArrayList<ArrayList<Double>>) resultValue; |
| | | double[][] array = new double[doubleListList.size()][]; |
| | | for (int i = 0; i < doubleListList.size(); i++) { |
| | | ArrayList<Double> doubleList = doubleListList.get(i); |
| | | array[i] = new double[doubleList.size()]; |
| | | for (int j = 0; j < doubleList.size(); j++) { |
| | | array[i][j] = doubleList.get(j); |
| | | } |
| | | } |
| | | if (array != null && item.getResultPort() < array.length && item.getResultIndex() < array[item.getResultPort()].length) { |
| | | value = array[item.getResultPort()][item.getResultIndex()]; |
| | | } else { |
| | | log.error(result.get(item.getResultKey()) + "下标超限"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //下发到point点位 |
| | | ApiPointValueWriteDTO ApiPointValueWriteDTO = new ApiPointValueWriteDTO(); |
| | | ApiPointValueWriteDTO.setPointNo(item.getPointNo()); |
| | | ApiPointValueWriteDTO.setValue(value); |
| | | if (!dataPointApi.writePointRealValue(ApiPointValueWriteDTO)) { |
| | | log.error(result.get(item.getResultKey()) + "下发数据异常"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | ); |
| | | }catch (Exception ex){ |
| | | log.error("下发数据异常"); |
| | | ex.printStackTrace(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private Date[] calResultTime(ItemVO predictItem, Date startTimeReq, Date endTimeReq, int lengthLeft, int lengthRight) { |
| | | Date[] result = new Date[3]; |
| | |
| | | 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; |
| | |
| | | package com.iailab.module.model.api.controller.admin; |
| | | |
| | | import com.iailab.framework.apilog.core.annotation.ApiAccessLog; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.*; |
| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | return CommonResult.success(respVO); |
| | | } |
| | | |
| | | @PostMapping("/predict-data/cur") |
| | | @Operation(summary = "获取当前预测数据") |
| | | public CommonResult<Map<String, List<Object[]>>> getPreDataCur(HttpServletResponse response, HttpServletRequest |
| | | request, @RequestBody PreDataJsonReqVO reqVO)throws Exception { |
| | | apiSecurityUtils.validate(request); |
| | | reqVO.setPredictTime(new Date()); |
| | | Map<String, List<Object[]>> map = mcsApi.getPreDataCur(reqVO); |
| | | return CommonResult.success(map); |
| | | } |
| | | |
| | | @GetMapping("/predict-data/exportValue") |
| | | @Operation(summary = "导出预测数据") |
| | | public void exportPointValue(@RequestParam("itemId") String itemId, |
| | |
| | | List<ScheduleSuggestRespDTO> data = mcsApi.getLastLimitScheduleSuggest(scheduleObj, limit); |
| | | return CommonResult.success(data); |
| | | } |
| | | |
| | | @PostMapping("/schedule-model/out") |
| | | @Operation(summary = "调度模型数据下发") |
| | | public Boolean scheduleModelOut(HttpServletResponse response, HttpServletRequest |
| | | request, @RequestBody MdkScheduleRespDTO dto) throws Exception { |
| | | apiSecurityUtils.validate(request); |
| | | return mcsApi.scheduleModelOut(dto); |
| | | } |
| | | } |
| | |
| | | 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"); |
| | |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleModelOutDTO; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelOutEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelParamEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelSettingEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelOutService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelSettingService; |
| | |
| | | |
| | | @Autowired |
| | | private StScheduleModelSettingService stScheduleModelSettingService; |
| | | @Autowired |
| | | private StScheduleModelOutService stScheduleModelOutService; |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得分页") |
| | |
| | | result.setParamList(BeanUtils.toBean(paramList, StScheduleModelParamRespVO.class)); |
| | | List<StScheduleModelSettingEntity> settingList = stScheduleModelSettingService.getByModelId(data.getId()); |
| | | result.setSettingList(BeanUtils.toBean(settingList, StScheduleModelSettingRespVO.class)); |
| | | List<StScheduleModelOutDTO> outList = stScheduleModelOutService.list(data.getId()); |
| | | result.setModelOut(outList); |
| | | return success(result); |
| | | } |
| | | |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.framework.mybatis.core.mapper.BaseMapperX; |
| | | import com.iailab.framework.tenant.core.db.dynamic.TenantDS; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelOutEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dyk |
| | | * @date: 2024/12/30 17:50 |
| | | **/ |
| | | @TenantDS |
| | | @Mapper |
| | | public interface StScheduleModelOutDao extends BaseMapperX<StScheduleModelOutEntity> { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.iailab.framework.mybatis.core.dataobject.BaseDO; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * @description: 调度模型下发配置 |
| | | * @author: dyk |
| | | * @date: 2024/12/30 17:21 |
| | | **/ |
| | | @Data |
| | | @TableName("t_st_schedule_model_out") |
| | | public class StScheduleModelOutEntity implements Serializable { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | @TableId |
| | | private String id; |
| | | |
| | | /** |
| | | * 模型id |
| | | */ |
| | | private String modelId; |
| | | |
| | | /** |
| | | * key |
| | | */ |
| | | private String resultKey; |
| | | |
| | | /** |
| | | * 数据类型 |
| | | */ |
| | | private String resultType; |
| | | |
| | | /** |
| | | * 角标1 |
| | | */ |
| | | private Integer resultPort; |
| | | |
| | | /** |
| | | * 角标2 |
| | | */ |
| | | private Integer resultIndex; |
| | | |
| | | /** |
| | | * 是否下发 |
| | | */ |
| | | private Integer isWrite; |
| | | |
| | | /** |
| | | * 下发的点位 |
| | | */ |
| | | private String pointNo; |
| | | |
| | | /** |
| | | * 排序 |
| | | */ |
| | | private Integer sort; |
| | | |
| | | /** |
| | | * 无扰切换点位 |
| | | */ |
| | | private String disturbancePointNo; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.service; |
| | | |
| | | |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleModelOutDTO; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelOutEntity; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dyk |
| | | * @date: 2024/12/30 17:42 |
| | | **/ |
| | | public interface StScheduleModelOutService extends BaseService<StScheduleModelOutEntity> { |
| | | |
| | | void deleteByMap(Map<String, Object> map); |
| | | |
| | | void insertList(List<StScheduleModelOutEntity> list, String modelId); |
| | | |
| | | void deleteScheduleModelOut(String modelId); |
| | | |
| | | List<StScheduleModelOutDTO> list(String modelId); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.service.impl; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleModelOutDTO; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO; |
| | | import com.iailab.module.model.mcs.sche.dao.StScheduleModelOutDao; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelOutEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleSchemeEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelOutService; |
| | | import com.iailab.module.model.mpk.service.MethodSettingService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dyk |
| | | * @date: 2024/12/30 17:43 |
| | | **/ |
| | | @Slf4j |
| | | @Service |
| | | public class StScheduleModelOutServiceImpl extends BaseServiceImpl<StScheduleModelOutDao, StScheduleModelOutEntity> implements StScheduleModelOutService { |
| | | |
| | | @Autowired |
| | | private MethodSettingService methodSettingService; |
| | | |
| | | @Override |
| | | public void deleteByMap(Map<String, Object> map) { |
| | | baseDao.delete(getWrapper(map)); |
| | | } |
| | | |
| | | private QueryWrapper<StScheduleModelOutEntity> getWrapper(Map<String, Object> params) { |
| | | String mpkFileId = (String) params.get("modelId"); |
| | | |
| | | QueryWrapper<StScheduleModelOutEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq(StringUtils.isNotBlank(mpkFileId), "mpk_file_id", mpkFileId); |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | @Override |
| | | public void insertList(List<StScheduleModelOutEntity> list, String modelId) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | StScheduleModelOutEntity entity = ConvertUtils.sourceToTarget(list.get(i), StScheduleModelOutEntity.class); |
| | | entity.setId(UUID.randomUUID().toString()); |
| | | entity.setModelId(modelId); |
| | | entity.setSort(i); |
| | | baseDao.insert(entity); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void deleteScheduleModelOut(String modelId) { |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("model_id", modelId); |
| | | baseDao.deleteByMap(map); |
| | | } |
| | | |
| | | @Override |
| | | public List<StScheduleModelOutDTO> list(String modelId) { |
| | | QueryWrapper<StScheduleModelOutEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("model_id", modelId); |
| | | List<StScheduleModelOutEntity> list = baseDao.selectList(queryWrapper); |
| | | return ConvertUtils.sourceToTarget(list, StScheduleModelOutDTO.class); |
| | | } |
| | | } |
| | |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.module.model.mcs.sche.dao.StScheduleModelDao; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelOutService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelSettingService; |
| | |
| | | @Autowired |
| | | private StScheduleModelSettingService stScheduleModelSettingService; |
| | | |
| | | @Autowired |
| | | private StScheduleModelOutService stScheduleModelOutService; |
| | | |
| | | @Override |
| | | public PageResult<StScheduleModelEntity> page(StScheduleModelPageReqVO reqVO) { |
| | | return stScheduleModelDao.selectPage(reqVO); |
| | |
| | | entity.setId(UUID.randomUUID().toString()); |
| | | stScheduleModelDao.insert(entity); |
| | | stScheduleModelParamService.saveList(entity.getId(), reqVO.getParamList()); |
| | | stScheduleModelOutService.insertList(reqVO.getModelOut(), entity.getId()); |
| | | stScheduleModelSettingService.saveList(entity.getId(), reqVO.getSettingList()); |
| | | } |
| | | |
| | |
| | | stScheduleModelDao.updateById(entity); |
| | | stScheduleModelParamService.saveList(entity.getId(), reqVO.getParamList()); |
| | | stScheduleModelSettingService.saveList(entity.getId(), reqVO.getSettingList()); |
| | | stScheduleModelOutService.deleteScheduleModelOut(entity.getId()); |
| | | stScheduleModelOutService.insertList(reqVO.getModelOut(), entity.getId()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | stScheduleModelDao.deleteById(id); |
| | | stScheduleModelParamService.deleteByModelId(id); |
| | | stScheduleModelSettingService.deleteByModelId(id); |
| | | stScheduleModelOutService.deleteScheduleModelOut(id); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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); |
| | | } |
| | |
| | | package com.iailab.module.model.mcs.sche.vo; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleModelOutDTO; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | |
| | | |
| | | @Schema(description = "设置参数列表", example = "设置参数列表") |
| | | private List<StScheduleModelSettingRespVO> settingList; |
| | | |
| | | @Schema(description = "下发配置列表", example = "下发配置列表") |
| | | private List<StScheduleModelOutDTO> modelOut; |
| | | } |
| | |
| | | package com.iailab.module.model.mcs.sche.vo; |
| | | |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelOutEntity; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | |
| | | |
| | | @Schema(description = "设置参数", example = "设置参数") |
| | | private List<StScheduleModelSettingSaveReqVO> settingList; |
| | | |
| | | @Schema(description = "下发设置", example = "下发设置") |
| | | private List<StScheduleModelOutEntity> modelOut; |
| | | } |
| | |
| | | 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> |