sampleInfo.setPlanMap 统一获取计划数据的信息,避免重复查询
| | |
| | | |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.common.ApiDataQueryDTO; |
| | | import com.iailab.module.data.common.ApiDataValueDTO; |
| | | import com.iailab.module.data.enums.ApiConstants; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | LinkedHashMap<String, List<ApiPlanDataDTO>> queryPlanItemRecordValue(@RequestBody ApiDataQueryDTO dto); |
| | | |
| | | @GetMapping(PREFIX + "/info/no/{itemNo}") |
| | | @Operation(summary = "根据测点编号查询测点信息") |
| | | @Operation(summary = "根据编号查询计划数据信息") |
| | | ApiPlanItemDTO getInfoByNo(@PathVariable("itemNo") String itemNo); |
| | | |
| | | @GetMapping(PREFIX + "/info/id/{id}") |
| | | @Operation(summary = "根据测点编号查询测点信息") |
| | | @Operation(summary = "根据id查询计划数据信息") |
| | | ApiPlanItemDTO getInfoById(@PathVariable("id") String id); |
| | | |
| | | @PostMapping(PREFIX + "/info/ids") |
| | | @Operation(summary = "根据多个id查询计划数据信息") |
| | | List<ApiPlanItemDTO> getInfoByIds(@RequestParam("planIds") Set<String> planIds); |
| | | } |
| | |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.common.ApiDataQueryDTO; |
| | | import com.iailab.module.data.common.ApiDataValueDTO; |
| | | import com.iailab.module.data.plan.item.collection.PlanItemCollector; |
| | |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | return ConvertUtils.sourceToTarget(entity, ApiPlanItemDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiPlanItemDTO> getInfoByIds(Set<String> planIds) { |
| | | List<PlanItemEntity> plans = planItemService.getInfoByIds(planIds); |
| | | return ConvertUtils.sourceToTarget(plans,ApiPlanItemDTO.class); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.plan.item.entity.PlanItemEntity; |
| | | import com.iailab.module.data.plan.item.vo.PlanItemDataVO; |
| | | import com.iailab.module.data.plan.item.vo.PlanItemPageReqVO; |
| | |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | void delete(String id); |
| | | |
| | | List<PlanItemDataVO> getSourceValue(Map<String, Object> params); |
| | | |
| | | List<PlanItemEntity> getInfoByIds(Set<String> planIds); |
| | | } |
| | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.object.BeanUtils; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.plan.item.dao.PlanItemDao; |
| | | import com.iailab.module.data.plan.item.entity.PlanItemEntity; |
| | | import com.iailab.module.data.plan.item.service.PlanItemService; |
| | |
| | | public List<PlanItemDataVO> getSourceValue(Map<String, Object> params) { |
| | | return baseDao.getSourceValue(params); |
| | | } |
| | | |
| | | @Override |
| | | public List<PlanItemEntity> getInfoByIds(Set<String> planIds) { |
| | | return baseDao.selectBatchIds(planIds); |
| | | } |
| | | } |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
| | |
| | | public List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception { |
| | | List<SampleData> sampleDataList = new ArrayList<>(); |
| | | Map<String, ApiPointDTO> pointMap = sampleInfo.getPointMap(); |
| | | Map<String, ApiPlanItemDTO> planMap = sampleInfo.getPlanMap(); |
| | | //对每个爪分别进行计算 |
| | | for (ColumnItemPort entry : sampleInfo.getColumnInfo()) { |
| | | //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数 |
| | |
| | | //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置 |
| | | for (int i = 0; i < entry.getColumnItemList().size(); i++) { |
| | | try { |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i),pointMap); |
| | | List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i),pointMap,planMap); |
| | | //补全数据 |
| | | ColumnItem columnItem = entry.getColumnItemList().get(i); |
| | | dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, |
| | | columnItem.paramId, columnItem.getParamType()); |
| | | columnItem.paramId, columnItem.getParamType(),pointMap,planMap); |
| | | |
| | | /** 如果数据取不满,把缺失的数据点放在后面 */ |
| | | if (dataEntityList != null && dataEntityList.size() != 0) { |
| | |
| | | * |
| | | * @param columnItem |
| | | * @param pointMap |
| | | * @param planMap |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap) throws Exception { |
| | | private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) throws Exception { |
| | | List<DataValueVO> dataList = new ArrayList<>(); |
| | | String paramType = columnItem.getParamType(); |
| | | switch (ModelParamType.getEumByCode(paramType)) { |
| | |
| | | break; |
| | | case PLAN: |
| | | ApiDataQueryDTO queryPlanItemDto = new ApiDataQueryDTO(); |
| | | queryPlanItemDto.setItemNo(columnItem.getParamId()); |
| | | queryPlanItemDto.setItemNo(planMap.get(columnItem.getParamId()).getItemNo()); |
| | | queryPlanItemDto.setStart(columnItem.getStartTime()); |
| | | queryPlanItemDto.setEnd(columnItem.getEndTime()); |
| | | List<ApiDataValueDTO> planValueList = planItemApi.queryPlanItemHistoryValue(queryPlanItemDto); |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity; |
| | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | /** |
| | | * 返回样本矩阵的列数 |
| | | * |
| | |
| | | Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); |
| | | Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity(), (e1,e2) -> e1)); |
| | | // 统一获取计划数据的信息 |
| | | Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds); |
| | | Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1,e2) -> e1)); |
| | | |
| | | for (MmModelParamEntity entry : modelInputParamEntityList) { |
| | | columnInfo.setParamType(entry.getModelparamtype()); |
| | |
| | | columnInfo.setDataLength(entry.getDatalength()); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo)); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap)); |
| | | |
| | | //对每一个爪进行数据项归并 |
| | | if (curPortOrder != entry.getModelparamportorder()){ |
| | |
| | | resultList.add(curPort); |
| | | sampleInfo.setColumnInfo(resultList); |
| | | sampleInfo.setPointMap(pointMap); |
| | | sampleInfo.setPlanMap(planMap); |
| | | return sampleInfo; |
| | | } |
| | | |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.util.*; |
| | | |
| | | abstract class SampleDataConstructor { |
| | |
| | | * @param dataEntityList |
| | | * @param startTime |
| | | * @param endTime |
| | | * @param planMap |
| | | * @return |
| | | */ |
| | | public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime, |
| | | String paramId, String paramType) { |
| | | String paramId, String paramType, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | if (CollectionUtils.isEmpty(dataEntityList) || length == dataEntityList.size()) { |
| | | return dataEntityList; |
| | | } else if (length < dataEntityList.size()) { |
| | |
| | | break; |
| | | case DATAPOINT: |
| | | // 测点值 |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(paramId); |
| | | ApiPointDTO dataPoint = pointMap.get(paramId); |
| | | oneMin = 1000L * DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); |
| | | // 设置时间偏移量 |
| | | start = start - (start % oneMin) + oneMin; |
| | |
| | | break; |
| | | case PLAN: |
| | | // 计划数据 |
| | | ApiPlanItemDTO planItem = planItemApi.getInfoById(paramId); |
| | | ApiPlanItemDTO planItem = planMap.get(paramId); |
| | | oneMin = 1000L * TimeGranularitySecEnum.getEumByCode(planItem.getTimeGranularity()).getValue(); |
| | | // 设置时间偏移量 |
| | | start = start - (start % oneMin) + oneMin; |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap) { |
| | | protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60); |
| | | break; |
| | | case PLAN: |
| | | dateTime = calendar.getTime(); |
| | | ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); |
| | | if (apiPlanItemDTO == null) { |
| | | return null; |
| | | } |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap) { |
| | | protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | case PLAN: |
| | | ApiPlanItemDTO planItem = planItemApi.getInfoByNo(columnItem.getParamId()); |
| | | if (planItem == null) { |
| | | ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); |
| | | if (apiPlanItemDTO == null) { |
| | | return null; |
| | | } |
| | | dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), |
| | | TimeGranularityEnum.getEumByCode(planItem.getTimeGranularity()).getValue()); |
| | | dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | protected Integer getGranularity(ColumnItem columnItem) { |
| | | protected Integer getGranularity(ColumnItem columnItem,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) { |
| | | // 默认60s |
| | | Integer granularity = 60; |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId()); |
| | | granularity = DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); |
| | | break; |
| | | case NORMALITEM: |
| | | granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); |
| | | break; |
| | | case MERGEITEM: |
| | | granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity(); |
| | | break; |
| | |
| | | granularity = TimeGranularitySecEnum.getEumByCode(indItemDTO.getTimeGranularity()).getValue();; |
| | | break; |
| | | case PLAN: |
| | | ApiPlanItemDTO apiPlanItemDTO = planItemApi.getInfoById(columnItem.getParamId()); |
| | | ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId()); |
| | | granularity = TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue(); |
| | | break; |
| | | default: |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity; |
| | | import com.iailab.module.model.mcs.sche.entity.StScheduleModelParamEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | @Override |
| | | protected Integer getSampleColumn(String modelId) { |
| | |
| | | Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds); |
| | | Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity())); |
| | | // 统一获取计划数据的信息 |
| | | Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet()); |
| | | List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds); |
| | | Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1,e2) -> e1)); |
| | | |
| | | for (StScheduleModelParamEntity entry : modelInputParamEntityList) { |
| | | columnInfo.setParamType(entry.getModelparamtype()); |
| | |
| | | columnInfo.setDataLength(entry.getDatalength()); |
| | | columnInfo.setModelParamOrder(entry.getModelparamorder()); |
| | | columnInfo.setModelParamPortOrder(entry.getModelparamportorder()); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo)); |
| | | columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap)); |
| | | columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap)); |
| | | |
| | | //对每一个爪进行数据项归并 |
| | | if (curPortOrder != entry.getModelparamportorder()){ |
| | |
| | | resultList.add(curPort); |
| | | sampleInfo.setColumnInfo(resultList); |
| | | sampleInfo.setPointMap(pointMap); |
| | | sampleInfo.setPlanMap(planMap); |
| | | return sampleInfo; |
| | | } |
| | | |
| | |
| | | package com.iailab.module.model.mdk.sample.dto; |
| | | |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Builder; |
| | |
| | | private BigDecimal[][] deviation; |
| | | // 所有测点信息,避免重复查询 |
| | | private Map<String, ApiPointDTO> pointMap; |
| | | // 所有计划数据信息,避免重复查询 |
| | | private Map<String, ApiPlanItemDTO> planMap; |
| | | } |