Merge remote-tracking branch 'origin/master'
| | |
| | | */ |
| | | |
| | | import com.iailab.framework.common.constant.CommonConstant; |
| | | import com.iailab.module.data.channel.http.collector.asdb.HttpCollectorForAsdb; |
| | | import com.iailab.module.data.channel.http.collector.ihdb.HttpCollectorForIhd; |
| | | import com.iailab.module.data.channel.http.entity.HttpApiEntity; |
| | | import com.iailab.module.data.channel.http.service.HttpApiService; |
| | |
| | | @Autowired |
| | | private HttpCollectorForIhd httpCollectorForIhd; |
| | | |
| | | @Autowired |
| | | private HttpCollectorForAsdb httpCollectorForAsdb; |
| | | |
| | | public Object getTagValue(String apiId, String tag) { |
| | | HttpApiEntity httpApi = httpApiService.getFromCatch(apiId); |
| | | if (httpApi == null) { |
| | |
| | | if (SourceApiEnum.iHyperDB.getCode().equals(httpApi.getCode())) { |
| | | valueMap = httpCollectorForIhd.getLastValues(apiId, tagNames); |
| | | } |
| | | if (SourceApiEnum.ASDB.getCode().equals(httpApi.getCode())) { |
| | | valueMap = httpCollectorForAsdb.getLastValues(apiId, tagNames); |
| | | } |
| | | if (valueMap.get(tag) == null) { |
| | | return CommonConstant.BAD_VALUE; |
| | | } |
| | |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum SourceApiEnum { |
| | | iHyperDB("iHyperDB", "宝信IHD"); |
| | | iHyperDB("iHyperDB", "宝信IHD"), |
| | | ASDB("ASDB", "鞍钢DB"); |
| | | |
| | | private String code; |
| | | private String desc; |
对比新文件 |
| | |
| | | package com.iailab.module.data.channel.http.collector.asdb; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.iailab.framework.common.constant.CommonConstant; |
| | | import com.iailab.framework.common.util.http.HttpUtils; |
| | | import com.iailab.module.data.channel.http.collector.asdb.vo.HttpAsdbRespDataVO; |
| | | import com.iailab.module.data.channel.http.entity.HttpApiEntity; |
| | | import com.iailab.module.data.channel.http.service.HttpApiService; |
| | | import com.iailab.module.data.common.enums.DataSourceType; |
| | | import com.iailab.module.data.common.utils.TagUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.BoundHashOperations; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.concurrent.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * AnSteelDB采集 |
| | | * |
| | | * @author Jay |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class HttpCollectorForAsdb { |
| | | private static Map<String, HttpApiEntity> apiMap = new HashMap<>(); |
| | | |
| | | @Autowired |
| | | private HttpApiService httpApiService; |
| | | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | ThreadPoolExecutor threadPool = new ThreadPoolExecutor(18, 36, 30, TimeUnit.SECONDS, |
| | | new ArrayBlockingQueue<Runnable>(36), new ThreadPoolExecutor.AbortPolicy()); |
| | | |
| | | private static final String STA_TRUE = "true"; |
| | | |
| | | private static final int GROUP_MAX_COUNT = 300; |
| | | |
| | | private static final int MAX_WAIT = 30; |
| | | |
| | | private static final String pattern = "yyyyMMddHHmm00"; |
| | | |
| | | private static final String IS_SUCCESS = "isSuccess"; |
| | | |
| | | /** |
| | | * tagName |
| | | */ |
| | | private static final String N = "n"; |
| | | |
| | | /** |
| | | * dimension |
| | | */ |
| | | private static final String D = "d"; |
| | | |
| | | /** |
| | | * 类型 |
| | | */ |
| | | private static final String P = "p"; |
| | | |
| | | /** |
| | | * dataValue |
| | | */ |
| | | private static final String V = "v"; |
| | | |
| | | /** |
| | | * dataTime |
| | | */ |
| | | private static final String T = "t"; |
| | | |
| | | /** |
| | | * 数据质量G:good,B:bad |
| | | */ |
| | | private static final String Q = "q"; |
| | | |
| | | private HttpApiEntity getHttpApi(String id) { |
| | | if (apiMap.containsKey(id)) { |
| | | return apiMap.get(id); |
| | | } |
| | | HttpApiEntity httpApi = httpApiService.info(id); |
| | | apiMap.put(id, httpApi); |
| | | return httpApi; |
| | | } |
| | | |
| | | public BigDecimal getTagValue(String sourceId, String tagNo, Integer dimension, String valueType) { |
| | | BigDecimal value = CommonConstant.BAD_VALUE; |
| | | HttpApiEntity httpApi = this.getHttpApi(sourceId); |
| | | String responseStr = HttpUtils.sendGet(httpApi.getUrl(), null, ""); |
| | | if (responseStr == null) { |
| | | return value; |
| | | } |
| | | List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); |
| | | value = Objects.requireNonNull(dataList.stream().filter(data -> tagNo.equals(data.getPoint())).findFirst().orElse(null)).getValue(); |
| | | return value; |
| | | } |
| | | |
| | | public Map<String, Object> getLastValues(String sourceId, List<String> tagNames) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | HttpApiEntity httpApi = this.getHttpApi(sourceId); |
| | | try { |
| | | if (CollectionUtils.isEmpty(tagNames)) { |
| | | return result; |
| | | } |
| | | List<String> noCacheTagNames = new ArrayList<>();//未缓存的tag |
| | | for (int i = 0; i < tagNames.size(); i++) { |
| | | //先查缓存 |
| | | BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps(tagNames.get(i)); |
| | | if (ops.get(V) != null) { |
| | | BigDecimal value = new BigDecimal(ops.get(V).toString()); |
| | | result.put(tagNames.get(i), value.setScale(3, RoundingMode.HALF_UP)); |
| | | } else { |
| | | noCacheTagNames.add(tagNames.get(i)); |
| | | } |
| | | } |
| | | if (CollectionUtils.isEmpty(noCacheTagNames)) { |
| | | log.info("全部读取缓存"); |
| | | return result; |
| | | } |
| | | log.info("查询未缓存的数据"); |
| | | String responseStr = HttpUtils.sendGet(httpApi.getUrl(), null, ""); |
| | | List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); |
| | | List<HttpAsdbRespDataVO> noCacheDataList = dataList.stream().filter(data -> noCacheTagNames.contains(data.getPoint())).collect(Collectors.toList()); |
| | | for (HttpAsdbRespDataVO data : noCacheDataList ){ |
| | | if (data.getValue() != null){ |
| | | //存缓存 |
| | | BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps(data.getValue().toString()); |
| | | ops.put(V, data.getValue().toString()); |
| | | //设置过期时间 |
| | | redisTemplate.expire(data.getValue().toString(), 10, TimeUnit.SECONDS); |
| | | //把查询到的数据插入结果集 |
| | | BigDecimal value = new BigDecimal(data.getValue().toString()); |
| | | result.put(data.getPoint(), value.setScale(3, RoundingMode.HALF_UP)); |
| | | } else { |
| | | result.put(data.getPoint(), CommonConstant.BAD_VALUE); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.info("getCurrentValue异常"); |
| | | ex.printStackTrace(); |
| | | throw ex; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public Map<String, Object> getTagValues(List<Object[]> params, Date collectTime) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | if (CollectionUtils.isEmpty(params)) { |
| | | return new HashMap<>(); |
| | | } |
| | | try { |
| | | Map<Integer, List<Object[]>> measurePointsCountGroup = new HashMap<>(); |
| | | int pointListSize = params.size(); |
| | | int groupCount = pointListSize / GROUP_MAX_COUNT + ((pointListSize % GROUP_MAX_COUNT) > 0 ? 1 : 0); |
| | | log.info("groupCount=" + groupCount); |
| | | for (int i = 0; i < groupCount; i++) { |
| | | int end = (i + 1) * GROUP_MAX_COUNT; |
| | | if (end > pointListSize) { |
| | | end = pointListSize; |
| | | } |
| | | measurePointsCountGroup.put(i, params.subList(i * GROUP_MAX_COUNT, end)); |
| | | } |
| | | log.info("measurePointsCountGroup.size()=" + measurePointsCountGroup.size()); |
| | | result = new ConcurrentHashMap<>(params.size()); |
| | | CountDownLatch countDownLatch = new CountDownLatch(measurePointsCountGroup.size()); |
| | | for (Map.Entry<Integer, List<Object[]>> measurePointsItem : measurePointsCountGroup.entrySet()) { |
| | | HttpApiEntity httpApi = this.getHttpApi(measurePointsItem.getValue().get(0)[0].toString()); |
| | | // 并发 |
| | | Thread.sleep(1000); |
| | | threadPool.submit(new Task(httpApi.getUrl(), httpApi.getCode(), result, measurePointsItem.getValue(), |
| | | collectTime, countDownLatch)); |
| | | // 顺序 |
| | | //this.getByHtp(result, measurePointsItem.getValue(), collectTime); |
| | | } |
| | | countDownLatch.await(MAX_WAIT, TimeUnit.SECONDS); |
| | | |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 异步采集任务 |
| | | */ |
| | | private class Task implements Runnable { |
| | | String url; |
| | | String sourceName; |
| | | Date collectTime; |
| | | Map<String, Object> result; |
| | | List<Object[]> params; |
| | | CountDownLatch countDownLatch; |
| | | |
| | | public Task(String url, String sourceName, Map<String, Object> result, List<Object[]> params, |
| | | Date collectTime, CountDownLatch countDownLatch) { |
| | | this.url = url; |
| | | this.sourceName = sourceName; |
| | | this.result = result; |
| | | this.collectTime = collectTime; |
| | | this.params = params; |
| | | this.countDownLatch = countDownLatch; |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | log.info("请求的Tag数量:" + params.size()); |
| | | this.getByHtp(url, sourceName, result, params, collectTime); |
| | | log.info("请求结束:url=" + url); |
| | | } catch (Exception ex) { |
| | | log.info("获取采集值失败," + ex.getMessage()); |
| | | ex.printStackTrace(); |
| | | } finally { |
| | | countDownLatch.countDown(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * getTagDataByHttp |
| | | * |
| | | * @param url |
| | | * @param sourceName |
| | | * @param result |
| | | * @param params |
| | | * @param collectTime |
| | | */ |
| | | private void getByHtp(String url, String sourceName, Map<String, Object> result, List<Object[]> params, Date collectTime) { |
| | | String responseStr = HttpUtils.sendGet(url, null, ""); |
| | | List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); |
| | | for (HttpAsdbRespDataVO data : dataList){ |
| | | result.put(TagUtils.genTagId(DataSourceType.HTTP.getCode(), sourceName, data.getPoint()), data.getValue()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void getByHtp(String url, String sourceName, Map<String, Object> result, List<Object[]> params, Date collectTime) {String responseStr = HttpUtils.sendGet(url, null, ""); |
| | | List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); |
| | | for (HttpAsdbRespDataVO data : dataList){ |
| | | result.put(TagUtils.genTagId(DataSourceType.HTTP.getCode(), sourceName, data.getPoint()), data.getValue()); |
| | | }} |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.data.channel.http.collector.asdb.vo; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | |
| | | /** |
| | | * @author Jay |
| | | */ |
| | | @Schema(description = "数据平台 - KioDevice Response VO") |
| | | @Data |
| | | @ExcelIgnoreUnannotated |
| | | public class HttpAsdbRespDataVO { |
| | | |
| | | |
| | | @Schema(description = "点位名称") |
| | | @ExcelProperty("点位名称") |
| | | private String pointName; |
| | | |
| | | @Schema(description = "数据名称") |
| | | @ExcelProperty("数据名称") |
| | | private String dataName; |
| | | |
| | | @Schema(description = "数据值") |
| | | @ExcelProperty("数据值") |
| | | private BigDecimal value; |
| | | |
| | | @Schema(description = "点位编号") |
| | | @ExcelProperty("点位编号") |
| | | private String point; |
| | | } |
| | |
| | | import com.iailab.module.data.ind.item.service.IndItemService; |
| | | import com.iailab.module.data.ind.item.vo.IndItemCalVO; |
| | | import com.iailab.module.data.ind.item.vo.IndItemValueVO; |
| | | import com.iailab.module.data.ind.value.service.IndItemValueService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | } |
| | | IndItemEntity subItem = indItemService.getInfoByNo(s); |
| | | ItemTypeEnum itemType = ItemTypeEnum.getEumByCode(subItem.getItemType()); |
| | | List<IndItemValueVO> vl = new ArrayList<>(); |
| | | switch (itemType) { |
| | | case ATOM: |
| | | valueMix.add(atomItemHandler.queryValue(subItem.getId())); |
| | | vl = atomItemHandler.queryValue(subItem.getId()); |
| | | break; |
| | | case DER: |
| | | valueMix.add(derItemHandler.queryValue(subItem.getId(), startTime, endTime)); |
| | | vl = derItemHandler.queryValue(subItem.getId(), startTime, endTime); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | if (!CollectionUtils.isEmpty(vl)) { |
| | | vl.forEach(vi -> vi.setItemNo(s)); |
| | | } |
| | | valueMix.add(vl); |
| | | } |
| | | dataLength = valueMix.get(0).size(); |
| | | |
| | |
| | | IndItemValueVO valueDTO = valueMix.get(j).get(i); |
| | | dataMap.put(valueDTO.getItemNo(), valueDTO); |
| | | } |
| | | log.info("dataMap:" + dataMap); |
| | | IndItemValueVO itemValue = this.singleCompute(indItem, dataMap); |
| | | result.add(itemValue); |
| | | } |
| | |
| | | @Operation(summary = "修改调度模型配置") |
| | | Boolean updateScheduleModelSetting(@RequestParam("modelCode") String modelCode, @RequestParam("key") String key, @RequestParam("value") String value); |
| | | |
| | | @GetMapping(PREFIX + "/schedule/adjust/config-list") |
| | | @Operation(summary = "获取模拟调整配置") |
| | | List<StAdjustConfigDetDTO> getAdjustConfigListByModelId(@RequestParam("modelId") String modelId); |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.api.mcs.dto; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | @Schema(description = "RPC 模型 - 模拟调整配置详情 DTO") |
| | | @Data |
| | | public class StAdjustConfigDetDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @Schema(description = "ID") |
| | | private String id; |
| | | |
| | | @Schema(description = "配置ID") |
| | | private String configId; |
| | | |
| | | @Schema(description = "预测项类型") |
| | | private String itemTypeId; |
| | | |
| | | @Schema(description = "预测项ID") |
| | | private String predictItemId; |
| | | |
| | | @Schema(description = "输出KEY") |
| | | private String outKey; |
| | | |
| | | @Schema(description = "输出名称") |
| | | private String outName; |
| | | |
| | | @Schema(description = "参数排序") |
| | | private Integer modelParamOrder; |
| | | |
| | | @Schema(description = "输入排序") |
| | | private Integer modelParamPortOrder; |
| | | |
| | | @Schema(description = "执行顺序") |
| | | private Integer sort; |
| | | } |
| | |
| | | |
| | | alter table t_mm_item_output add column `iscumulant` tinyint default false COMMENT '是否累计'; |
| | | alter table t_mm_item_output add column `cumuldivisor` int DEFAULT NULL COMMENT '累计除数'; |
| | | alter table t_mm_item_output add column `cumulpoint` varchar(36) DEFAULT NULL, COMMENT '累计测点'; |
| | | alter table t_mm_item_output add column `cumulpoint` varchar(36) DEFAULT NULL, COMMENT '累计测点'; |
| | | |
| | | |
| | | CREATE TABLE `t_st_adjust_config` ( |
| | | `id` varchar(36) NOT NULL COMMENT 'ID', |
| | | `schedule_model_id` varchar(36) DEFAULT NULL COMMENT '调度模型ID', |
| | | `remark` varchar(200) DEFAULT NULL COMMENT '备注', |
| | | `status` tinyint DEFAULT 1 COMMENT '状态', |
| | | create_time datetime default current_timestamp, |
| | | update_time datetime default current_timestamp, |
| | | PRIMARY KEY (`id`) USING BTREE, |
| | | INDEX `idx_schedule_model_id`(`schedule_model_id` ASC) USING BTREE |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='模拟调整配置表'; |
| | | |
| | | CREATE TABLE `t_st_adjust_config_det` ( |
| | | `id` varchar(36) NOT NULL COMMENT 'ID', |
| | | `config_id` varchar(36) DEFAULT NULL COMMENT '配置ID', |
| | | `item_type_id` varchar(36) DEFAULT NULL COMMENT '预测项类型', |
| | | `predict_item_id` varchar(36) DEFAULT NULL COMMENT '预测项ID', |
| | | `out_key` varchar(50) DEFAULT NULL COMMENT '输出KEY', |
| | | `out_name` varchar(50) DEFAULT NULL COMMENT '输出名称', |
| | | `model_param_order` integer DEFAULT NULL COMMENT '参数排序', |
| | | `model_param_port_order` integer DEFAULT NULL COMMENT '输入排序', |
| | | `sort` integer COMMENT '执行顺序', |
| | | PRIMARY KEY (`id`) USING BTREE, |
| | | INDEX `idx_config_id`(`config_id` ASC) USING BTREE |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='模拟调整配置详细表'; |
| | | |
| | | CREATE TABLE `t_st_adjust_result` ( |
| | | `id` varchar(36) NOT NULL COMMENT 'ID', |
| | | `config_id` varchar(36) DEFAULT NULL COMMENT '配置ID', |
| | | `output_id` varchar(36) DEFAULT NULL COMMENT '预测项输出ID', |
| | | `schedule_model_id` varchar(36) DEFAULT NULL COMMENT '调度模型ID', |
| | | `adjust_time` datetime NULL DEFAULT NULL COMMENT '模拟调整时间', |
| | | `adjust_value` varchar(500) DEFAULT NULL COMMENT '模拟调整值', |
| | | `json_value` varchar(1000) DEFAULT NULL COMMENT '模拟调整结果', |
| | | PRIMARY KEY (`id`) USING BTREE, |
| | | INDEX `idx_output_id`(`output_id` ASC) USING BTREE, |
| | | INDEX `idx_schedule_model_id`(`schedule_model_id` ASC) USING BTREE |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='模拟调整结果表'; |
| | | |
| | |
| | | import com.iailab.module.model.mcs.pre.vo.MmItemOutputRespVO; |
| | | import com.iailab.module.model.mcs.pre.vo.MmPredictAlarmMessageSaveReqVO; |
| | | import com.iailab.module.model.mcs.pre.vo.MmPredictItemRespVO; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleSuggestEntity; |
| | | import com.iailab.module.model.mcs.sche.service.*; |
| | |
| | | @Autowired |
| | | private StScheduleModelSettingService stScheduleModelSettingService; |
| | | |
| | | @Autowired |
| | | private StAdjustConfigService stAdjustConfigService; |
| | | |
| | | private int HOUR_MINS = 60; |
| | | |
| | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public List<StAdjustConfigDetDTO> getAdjustConfigListByModelId(String modelId) { |
| | | List<StAdjustConfigDetEntity> list = stAdjustConfigService.getDetByModelId(modelId); |
| | | return ConvertUtils.sourceToTarget(list, StAdjustConfigDetDTO.class); |
| | | } |
| | | |
| | | /** |
| | | * 计算功率因数 p²/(根号:p²+Q²) |
| | | **/ |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.dao; |
| | | |
| | | 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.StAdjustConfigEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | @TenantDS |
| | | @Mapper |
| | | public interface StAdjustConfigDao extends BaseMapperX<StAdjustConfigEntity> { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.dao; |
| | | |
| | | 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.StAdjustConfigDetEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | @TenantDS |
| | | @Mapper |
| | | public interface StAdjustConfigDetDao extends BaseMapperX<StAdjustConfigDetEntity> { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.dao; |
| | | |
| | | 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.StAdjustResultEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | @TenantDS |
| | | @Mapper |
| | | public interface StAdjustResultDao extends BaseMapperX<StAdjustResultEntity> { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月20日 |
| | | */ |
| | | @Data |
| | | @TableName("t_st_adjust_config_det") |
| | | public class StAdjustConfigDetEntity implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @TableId(value = "id",type = IdType.INPUT) |
| | | private String id; |
| | | |
| | | /** |
| | | * 配置ID |
| | | */ |
| | | private String configId; |
| | | |
| | | /** |
| | | * 预测项类型 |
| | | */ |
| | | private String itemTypeId; |
| | | |
| | | /** |
| | | * 预测项ID |
| | | */ |
| | | private String predictItemId; |
| | | |
| | | /** |
| | | * 输出KEY |
| | | */ |
| | | private String outKey; |
| | | |
| | | /** |
| | | * 输出名称 |
| | | */ |
| | | private String outName; |
| | | |
| | | /** |
| | | * 参数排序 |
| | | */ |
| | | private Integer modelParamOrder; |
| | | |
| | | /** |
| | | * 输入排序 |
| | | */ |
| | | private Integer modelParamPortOrder; |
| | | |
| | | /** |
| | | * 执行顺序 |
| | | */ |
| | | private Integer sort; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月20日 |
| | | */ |
| | | @Data |
| | | @TableName("t_st_adjust_config") |
| | | public class StAdjustConfigEntity implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @TableId(value = "id",type = IdType.INPUT) |
| | | private String id; |
| | | |
| | | /** |
| | | * 调度模型ID |
| | | */ |
| | | private String scheduleModelId; |
| | | |
| | | /** |
| | | * 备注 |
| | | */ |
| | | private String remark; |
| | | |
| | | /** |
| | | * 状态 |
| | | */ |
| | | private Integer status; |
| | | |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | private Date createTime; |
| | | |
| | | /** |
| | | * 修改时间 |
| | | */ |
| | | private Date updateTime; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月20日 |
| | | */ |
| | | @Data |
| | | @TableName("t_st_adjust_result") |
| | | public class StAdjustResultEntity implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @TableId(value = "id",type = IdType.INPUT) |
| | | private String id; |
| | | |
| | | /** |
| | | * 配置ID |
| | | */ |
| | | private String configId; |
| | | |
| | | /** |
| | | * 预测项输出ID |
| | | */ |
| | | private String outputId; |
| | | |
| | | /** |
| | | * 调度模型ID |
| | | */ |
| | | private String scheduleModelId; |
| | | |
| | | /** |
| | | * 模拟调整时间 |
| | | */ |
| | | private Date adjustTime; |
| | | |
| | | /** |
| | | * 模拟调整值 |
| | | */ |
| | | private String adjustValue; |
| | | |
| | | /** |
| | | * 模拟调整结果 |
| | | */ |
| | | private String jsonValue; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.service; |
| | | |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | public interface StAdjustConfigDetService extends BaseService<StAdjustConfigDetEntity> { |
| | | |
| | | List<StAdjustConfigDetEntity> getListByConfigId(String configId); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.service; |
| | | |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustConfigEntity; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | public interface StAdjustConfigService extends BaseService<StAdjustConfigEntity> { |
| | | |
| | | StAdjustConfigEntity getByModelId(String modelId); |
| | | |
| | | List<StAdjustConfigDetEntity> getDetByModelId(String modelId); |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.service; |
| | | |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustResultEntity; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | public interface StAdjustResultService extends BaseService<StAdjustResultEntity> { |
| | | } |
对比新文件 |
| | |
| | | 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.module.model.mcs.sche.dao.StAdjustConfigDetDao; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustConfigDetService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class StAdjustConfigDetServiceImpl extends BaseServiceImpl<StAdjustConfigDetDao, StAdjustConfigDetEntity> implements StAdjustConfigDetService { |
| | | |
| | | public List<StAdjustConfigDetEntity> getListByConfigId(String configId) { |
| | | QueryWrapper<StAdjustConfigDetEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("config_id", configId); |
| | | queryWrapper.orderByAsc("sort"); |
| | | return baseDao.selectList(queryWrapper); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.service.impl; |
| | | |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.module.model.mcs.sche.dao.StAdjustConfigDao; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustConfigEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustConfigDetService; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class StAdjustConfigServiceImpl extends BaseServiceImpl<StAdjustConfigDao, StAdjustConfigEntity> implements StAdjustConfigService { |
| | | |
| | | @Autowired |
| | | private StAdjustConfigDetService stAdjustConfigDetService; |
| | | |
| | | public StAdjustConfigEntity getByModelId(String modelId) { |
| | | return baseDao.selectOne("schedule_model_id", modelId); |
| | | } |
| | | |
| | | |
| | | public List<StAdjustConfigDetEntity> getDetByModelId(String modelId) { |
| | | StAdjustConfigEntity configEntity = getByModelId(modelId); |
| | | return stAdjustConfigDetService.getListByConfigId(configEntity.getId()); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.service.impl; |
| | | |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.module.model.mcs.sche.dao.StAdjustResultDao; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustResultEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class StAdjustResultServiceImpl extends BaseServiceImpl<StAdjustResultDao, StAdjustResultEntity> implements StAdjustResultService { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.vo; |
| | | |
| | | import com.iailab.framework.common.pojo.PageParam; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.ToString; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月20日 |
| | | */ |
| | | @Schema(description = "模型服务 - 调度模型分页 Request VO") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class StAdjustConfigDetPageReqVO extends PageParam { |
| | | |
| | | @Schema(description = "配置ID", example = "") |
| | | private String configId; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.vo; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | public class StAdjustConfigDetRespVO { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.vo; |
| | | |
| | | import com.iailab.framework.common.pojo.PageParam; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.ToString; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月20日 |
| | | */ |
| | | @Schema(description = "模型服务 - 调度模型分页 Request VO") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class StAdjustConfigPageReqVO extends PageParam { |
| | | |
| | | @Schema(description = "模型编号,模糊匹配", example = "") |
| | | private String modelCode; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.vo; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | public class StAdjustConfigRespVO { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.vo; |
| | | |
| | | import com.iailab.framework.common.pojo.PageParam; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.ToString; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月20日 |
| | | */ |
| | | @Schema(description = "模型服务 - 调度模型分页 Request VO") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class StAdjustResultPageReqVO extends PageParam { |
| | | |
| | | @Schema(description = "开始时间", example = "") |
| | | private String startTime; |
| | | |
| | | @Schema(description = "结束时间", example = "") |
| | | private String endTime; |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mcs.sche.vo; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2025年02月23日 |
| | | */ |
| | | public class StAdjustResultRespVO { |
| | | } |
| | |
| | | * @throws ModelInvokeException |
| | | */ |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo) throws ModelInvokeException; |
| | | |
| | | /** |
| | | * 预测,模拟调整 |
| | | * |
| | | * @param predictTime |
| | | * @param predictModel |
| | | * @param itemName |
| | | * @param itemNo |
| | | * @param deviation |
| | | * @return |
| | | */ |
| | | PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo, double[][] deviation) throws ModelInvokeException; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 预测,模拟调整 |
| | | * |
| | | * @param predictTime |
| | | * @param predictModel |
| | | * @param itemName |
| | | * @param itemNo |
| | | * @return |
| | | * @throws ModelInvokeException |
| | | */ |
| | | @Override |
| | | public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName,String itemNo, double[][] deviation) throws ModelInvokeException { |
| | | PredictResultVO result = new PredictResultVO(); |
| | | if (predictModel == null) { |
| | | throw new ModelInvokeException("modelEntity is null"); |
| | | } |
| | | String modelId = predictModel.getId(); |
| | | try { |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime, itemName, new HashMap<>()); |
| | | String modelPath = predictModel.getModelpath(); |
| | | if (modelPath == null) { |
| | | log.info("模型路径不存在,modelId=" + modelId); |
| | | return null; |
| | | } |
| | | IAILModel newModelBean = composeNewModelBean(predictModel); |
| | | HashMap<String, Object> settings = getPredictSettingsByModelId(modelId); |
| | | // 校验setting必须有pyFile,否则可能导致程序崩溃 |
| | | if (!settings.containsKey(MdkConstant.PY_FILE_KEY)) { |
| | | throw new RuntimeException("模型设置参数缺少必要信息【" + MdkConstant.PY_FILE_KEY + "】,请重新上传模型!"); |
| | | } |
| | | |
| | | if (settings == null) { |
| | | log.error("模型setting不存在,modelId=" + modelId); |
| | | return null; |
| | | } |
| | | int portLength = sampleDataList.size(); |
| | | Object[] param2Values = new Object[portLength + 2]; |
| | | for (int i = 0; i < portLength; i++) { |
| | | param2Values[i] = sampleDataList.get(i).getMatrix(); |
| | | } |
| | | param2Values[portLength] = newModelBean.getDataMap().get("models"); |
| | | param2Values[portLength + 1] = settings; |
| | | |
| | | log.info("####################### 模拟调整 "+ "【itemId:" + predictModel.getItemid() + ",itemName:" + itemName + ",itemNo:" + itemNo + "】 ##########################"); |
| | | log.info("参数: " + JSON.toJSONString(param2Values)); |
| | | |
| | | //IAILMDK.run |
| | | HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, predictModel.getMpkprojectid()); |
| | | //打印结果 |
| | | log.info("预测模型计算完成:modelId=" + modelId + ",modelName=" + predictModel.getMethodname() + ",modelResult=" + JSON.toJSONString(modelResult)); |
| | | //判断模型结果 |
| | | 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 ModelResultErrorException("模型结果异常:" + modelResult); |
| | | } |
| | | modelResult = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT); |
| | | |
| | | List<MmItemOutputEntity> itemOutputList = mmItemOutputService.getByItemid(predictModel.getItemid()); |
| | | Map<MmItemOutputEntity, double[]> predictMatrixs = new HashMap<>(); |
| | | for (MmItemOutputEntity output : itemOutputList) { |
| | | if (!modelResult.containsKey(output.getResultstr())) { |
| | | continue; |
| | | } |
| | | OutResultType outResultType = OutResultType.getEumByCode(output.getResultType()); |
| | | switch (outResultType) { |
| | | case D1: |
| | | double[] temp1 = (double[]) modelResult.get(output.getResultstr()); |
| | | predictMatrixs.put(output, temp1); |
| | | break; |
| | | case D2: |
| | | double[][] temp2 = (double[][]) modelResult.get(output.getResultstr()); |
| | | double[] tempColumn = new double[temp2.length]; |
| | | for (int i = 0; i < tempColumn.length; i++) { |
| | | tempColumn[i] = temp2[i][output.getResultIndex()]; |
| | | } |
| | | predictMatrixs.put(output, tempColumn); |
| | | break; |
| | | case D: |
| | | Double temp3 = (Double) modelResult.get(output.getResultstr()); |
| | | predictMatrixs.put(output, new double[]{temp3}); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | result.setPredictMatrixs(predictMatrixs); |
| | | result.setModelResult(modelResult); |
| | | result.setPredictTime(predictTime); |
| | | } catch (ModelResultErrorException ex) { |
| | | log.error("模型结果异常", ex); |
| | | throw ex; |
| | | } catch (Exception ex) { |
| | | log.error("调用发生异常,异常信息为:{0}", ex.getMessage()); |
| | | throw new ModelInvokeException(ex.getMessage()); |
| | | } |
| | | return result; |
| | | } |
| | | /** |
| | | * 构造IAILMDK.run()方法的newModelBean参数 |
| | | * |
| | | * @param predictModel |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | int deviationIndex = 0; |
| | | |
| | | //对每个爪分别进行计算 |
| | | for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { |
| | | double[][] matrix = new double[0][0]; |
| | |
| | | } |
| | | } |
| | | |
| | | //找出对应的调整值 |
| | | double[] deviationItem = null; |
| | | if (sampleInfo.getDeviation() != null && sampleInfo.getDeviation().length > 0) { |
| | | deviationItem = sampleInfo.getDeviation()[deviationIndex]; |
| | | } |
| | | deviationIndex ++; |
| | | |
| | | //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 |
| | | for (int i = 0; i < entry.getColumnItemList().size(); i++) { |
| | | try { |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i), pointMap, planMap,indMap); |
| | | |
| | | //设置调整值 |
| | | if (deviationItem != null && deviationItem.length > 0) { |
| | | logger.info("设置调整值, i = " + i); |
| | | if (deviationItem[i] <= 0) { |
| | | continue; |
| | | } |
| | | for(int dataKey = 1; dataKey < dataEntityList.size(); dataKey ++) { |
| | | DataValueVO item = dataEntityList.get(dataKey); |
| | | item.setDataValue(item.getDataValue() + deviationItem[i]); |
| | | } |
| | | } |
| | | |
| | | //补全数据 |
| | | ColumnItem columnItem = entry.getColumnItemList().get(i); |
| | | dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, columnItem.getParamType(),columnItem.getGranularity()); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | SampleData sampleData = new SampleData(); |
| | | sampleData.setMatrix(matrix); |
| | | sampleDataList.add(sampleData); |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName, |
| | | Map<Integer, Integer> dynamicDataLength, double[][] deviation) throws ModelInvokeException { |
| | | try { |
| | | SampleInfoConstructor sampleInfoConstructor = sampleFactory.createSampleInfo(typeA, modelId); |
| | | SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime, dynamicDataLength); |
| | | sampleInfo.setDeviation(deviation); |
| | | SampleDataConstructor sampleDataConstructor = sampleFactory.createSampleData(typeA); |
| | | return sampleDataConstructor.prepareSampleData(sampleInfo); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("获取模型的算法参数异常",e); |
| | | throw new ModelInvokeException(MessageFormat.format("{0},Name:{1}", |
| | | ModelInvokeException.errorGetModelArithParam, itemName)); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | |
| | | private Integer sampleCycle; |
| | | |
| | | private BigDecimal[][] deviation; |
| | | // 调整值 |
| | | private double[][] deviation; |
| | | // 所有测点信息,避免重复查询 |
| | | private Map<String, ApiPointDTO> pointMap; |
| | | // 所有计划数据信息,避免重复查询 |
| | |
| | | |
| | | import cn.hutool.cache.CacheUtil; |
| | | import cn.hutool.cache.impl.FIFOCache; |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.iail.IAILMDK; |
| | | import com.iail.bean.FieldSet; |
| | | import com.iail.bean.Property; |
| | | import com.iail.bean.SelectItem; |
| | | import com.iail.model.IAILModel; |
| | | import com.iail.utils.RSAUtils; |
| | | import com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | |
| | | import com.iailab.module.model.mpk.dto.MethodSettingDTO; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.lang.reflect.Method; |
| | | import java.net.URLClassLoader; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.net.URLEncoder; |
| | | import java.nio.file.Files; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.error; |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | |
| | | @Value("${mpk.bak-file-path}") |
| | | private String mpkBakFilePath; |
| | | |
| | | // 先进先出缓存 |
| | | // 先进先出缓存 临时保存导入的数据 |
| | | private static FIFOCache<String, String> cache = CacheUtil.newFIFOCache(100); |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | private IAILModel createModelBean(MdkDTO dto) { |
| | | IAILModel modelBean = new IAILModel(); |
| | | |
| | | //ParamPathList |
| | | List<String> paramPathList = new ArrayList<>(); |
| | | List<String> paramNameList = new ArrayList<>(); |
| | | |
| | | for (Map.Entry<String, Object> entry : dto.getModel().entrySet()) { |
| | | paramNameList.add(entry.getKey()); |
| | | paramPathList.add(entry.getValue().toString()); |
| | | } |
| | | modelBean.setParamNameList(paramNameList); |
| | | modelBean.setParamPathList(paramPathList); |
| | | //ClassName MethodName |
| | | modelBean.setClassName(dto.getClassName()); |
| | | modelBean.setMethodName(dto.getMethodName()); |
| | | //ParamsArray |
| | | int paramLength = dto.getHasModel() ? dto.getDataLength() + 2 : dto.getDataLength() + 1; |
| | | Class<?>[] paramsArray = new Class[paramLength]; |
| | | |
| | | for (int i = 0; i < dto.getDataLength(); i++) { |
| | | paramsArray[i] = double[][].class; |
| | | } |
| | | |
| | | if (dto.getHasModel()) { |
| | | paramsArray[dto.getDataLength()] = HashMap.class; |
| | | paramsArray[dto.getDataLength() + 1] = HashMap.class; |
| | | }else { |
| | | paramsArray[dto.getDataLength()] = HashMap.class; |
| | | } |
| | | modelBean.setParamsArray(paramsArray); |
| | | //LoadFieldSetList |
| | | List<FieldSet> loadFieldSetList = new ArrayList<>(); |
| | | FieldSet fieldSet = new FieldSet(); |
| | | fieldSet.setFieldName(""); |
| | | List<Property> propertyList = new ArrayList<>(); |
| | | for (MethodSettingDTO modelSetting : dto.getPredModelSettings()) { |
| | | Property property = new Property(); |
| | | property.setKey(modelSetting.getSettingKey()); |
| | | property.setName(modelSetting.getName()); |
| | | property.setType(modelSetting.getType()); |
| | | property.setValueType(modelSetting.getValueType()); |
| | | property.setMin(modelSetting.getMin() == null ? "" : modelSetting.getMin().toString()); |
| | | property.setMax(modelSetting.getMax() == null ? "" : modelSetting.getMax().toString()); |
| | | property.setSelectItemList(CollectionUtils.isEmpty(modelSetting.getSettingSelects()) ? null : modelSetting.getSettingSelects().stream().map(e -> new SelectItem(e.getSelectKey(),e.getName())).collect(Collectors.toList())); |
| | | property.setValue(modelSetting.getValue()); |
| | | property.setFlow(false); |
| | | propertyList.add(property); |
| | | } |
| | | fieldSet.setPropertyList(propertyList); |
| | | loadFieldSetList.add(fieldSet); |
| | | modelBean.setLoadFieldSetList(loadFieldSetList); |
| | | //SettingConfigMap |
| | | Map<String, Object> settingConfigMap = new HashMap<String, Object>(); |
| | | List<com.iail.bean.Value> settingKeyList = new ArrayList<com.iail.bean.Value>(); |
| | | Map<String, Object> settingMap = new HashMap<String, Object>(); |
| | | for (MethodSettingDTO modelSetting : dto.getModelSettings()) { |
| | | settingKeyList.add(new com.iail.bean.Value(modelSetting.getSettingKey(),modelSetting.getSettingKey())); |
| | | settingConfigMap.put("settingKeyList", settingKeyList); |
| | | settingConfigMap.put("settingMap", handleModelSettings(dto.getModelSettings())); |
| | | } |
| | | modelBean.setSettingConfigMap(settingConfigMap); |
| | | //DataMap |
| | | modelBean.setDataMap(dto.getModelResult()); |
| | | //ResultKey |
| | | modelBean.setResultKey(dto.getResultKey()); |
| | | //ResultKey |
| | | modelBean.setVersion("1.0.0"); |
| | | |
| | | |
| | | return modelBean; |
| | | } |
| | | |
| | | @PostMapping("saveModel") |
| | | public void saveModel(@RequestBody MdkDTO dto, HttpServletResponse response) { |
| | | IAILModel modelBean = createModelBean(dto); |
| | | |
| | | try { |
| | | //临时文件夹 |
| | | File tempFile = null; |
| | | try { |
| | | tempFile = Files.createTempFile(dto.getPyName(),".miail").toFile(); |
| | | log.info("生成临时文件," + tempFile.getAbsolutePath()); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("创建临时文件异常",e); |
| | | } |
| | | |
| | | |
| | | |
| | | try { |
| | | IAILMDK.saveModel(tempFile, modelBean); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("IAILMDK.saveModel异常",e); |
| | | } |
| | | |
| | | byte[] data = FileUtil.readBytes(tempFile); |
| | | response.reset(); |
| | | response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(tempFile.getName(), "UTF-8") + "\""); |
| | | response.addHeader("Content-Length", "" + data.length); |
| | | response.setContentType("application/octet-stream; charset=UTF-8"); |
| | | |
| | | IOUtils.write(data, response.getOutputStream()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("代码生成异常",e); |
| | | } |
| | | } |
| | | |
| | | private HashMap<String, Object> handleModelSettings(List<MethodSettingDTO> modelSettings) { |
| | | HashMap<String, Object> resultMap = null; |
| | | try { |
| | |
| | | private List<MethodSettingDTO> modelSettings; |
| | | |
| | | private List<String> uuids; |
| | | |
| | | private List<MethodSettingDTO> predModelSettings; |
| | | |
| | | private Integer dataLength; |
| | | |
| | | private HashMap modelResult; |
| | | |
| | | private String resultKey; |
| | | |
| | | } |
| | |
| | | |
| | | influx-db: |
| | | org: iailab |
| | | token: NloIinwybvMwKlJ8SGOAqboXH72EhdQEsnnV7kwtstVu6sbt24LNJ0bVICepeAtl2pxpd1Hj8gDLj9m4hnB7Fw== |
| | | url: http://127.0.0.1:8086 |
| | | username: dzd |
| | | password: qwer1234 |
| | | token: _338h4Kbu2KQaes5QwAyOz9pTUueXoSF9XmPi8N9oTS1SrhTZVj4J9JfSraUyWA0PfWMZOlf9QWax-USkJQR_A== |
| | | url: http://172.16.8.200:8086 |
| | | username: iailab |
| | | password: iailab2019 |