| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.ansteel.api.dao.PowerRunStateDao; |
| | | import com.iailab.module.ansteel.api.dao.*; |
| | | import com.iailab.module.ansteel.api.dto.*; |
| | | import com.iailab.module.ansteel.api.service.DataApi; |
| | | import com.iailab.module.ansteel.common.enums.ProcessConfDataTypeEnum; |
| | | import com.iailab.module.ansteel.power.dao.*; |
| | | import com.iailab.module.ansteel.power.entity.PowerCapacitorStatusEntity; |
| | | import com.iailab.module.ansteel.power.entity.PowerControlDetEntity; |
| | | import com.iailab.module.ansteel.power.entity.PowerControlMainEntity; |
| | | import com.iailab.module.ansteel.power.entity.PowerNetFactorEntity; |
| | | import com.iailab.module.ansteel.api.service.DataService; |
| | | import com.iailab.module.ansteel.common.constant.CommonConstant; |
| | | import com.iailab.module.data.api.ind.IndItemApi; |
| | | import com.iailab.module.data.api.ind.dto.ApiIndItemQueryDTO; |
| | | import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO; |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class DataServiceImpl implements DataApi { |
| | | public class DataServiceImpl implements DataService { |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | @Autowired |
| | | private IndItemApi indItemApi; |
| | | |
| | | @Autowired |
| | | private McsApi mcsApi; |
| | |
| | | |
| | | @Autowired |
| | | private PowerRunStateDao powerRunStateDao; |
| | | |
| | | @Autowired |
| | | private MainProcessIndexDayDao mainProcessIndexDayDao; |
| | | |
| | | @Autowired |
| | | private MainProcessIndexTeamDao mainProcessIndexTeamDao; |
| | | |
| | | @Autowired |
| | | private PowerNetFactorDao powerNetFactorDao; |
| | | |
| | | @Autowired |
| | | private PowerCapacitorStatusDao powerCapacitorStatusDao; |
| | | |
| | | @Autowired |
| | | private PowerControlMainDao powerControlMainDao; |
| | | |
| | | @Autowired |
| | | private PowerControlDetDao powerControlDetDao; |
| | | |
| | | @Override |
| | | public List<PowerRunStateDTO> getPowerRunState() { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<MainProcessIndexDTO> getIndexList(Map<String, Object> params) { |
| | | List<MainProcessIndexDTO> list = new ArrayList<>(); |
| | | if ("day".equals(params.get("type"))) { |
| | | list = ConvertUtils.sourceToTarget(mainProcessIndexDayDao.selectList(new QueryWrapper<>()), MainProcessIndexDTO.class); |
| | | } else if ("team".equals(params.get("type"))) { |
| | | list = ConvertUtils.sourceToTarget(mainProcessIndexTeamDao.selectList(new QueryWrapper<>()), MainProcessIndexDTO.class); |
| | | } |
| | | if (!CollectionUtils.isEmpty(list)) { |
| | | list.stream().map(item -> { |
| | | StringBuffer sb = new StringBuffer(); |
| | | sb.append(item.getHisAvg()); |
| | | sb.append(","); |
| | | sb.append(item.getTheory()); |
| | | sb.append(","); |
| | | sb.append(item.getActual()); |
| | | sb.append(","); |
| | | sb.append(item.getRealData()); |
| | | String[] arr = sb.toString().split(","); |
| | | Map<String, Object> adjValue = dataPointApi.queryPointsRealValue(Arrays.asList(arr)); |
| | | item.setHisAvg(ObjectUtils.isEmpty(adjValue.get(arr[0])) ? "0" : new BigDecimal(adjValue.get(arr[0]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | item.setTheory(ObjectUtils.isEmpty(adjValue.get(arr[1])) ? "0" : new BigDecimal(adjValue.get(arr[1]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | item.setActual(ObjectUtils.isEmpty(adjValue.get(arr[2])) ? "0" : new BigDecimal(adjValue.get(arr[2]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | item.setRealData(ObjectUtils.isEmpty(adjValue.get(arr[3])) ? "0" : new BigDecimal(adjValue.get(arr[3]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | |
| | | return item; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean useSuggest(StAlarmAndSuggestReqVO ReqVO) { |
| | | return mcsApi.useSuggest(ReqVO); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean ignoreSuggest(StAlarmAndSuggestReqVO ReqVO) { |
| | | return mcsApi.ignoreSuggest(ReqVO); |
| | | } |
| | | |
| | | @Override |
| | | public PreDataChartRespVO getPreDataChart(PreDataSingleChartReqVO reqVO) { |
| | | Map<String, String> tMap = new HashMap<>(); |
| | | List<ChartParamDTO> list = mcsApi.getChartParamList(reqVO.getChartCode()); |
| | |
| | | PreDataSingleChartRespVO resultOld = mcsApi.getPreDataSingleChart(reqVO); |
| | | PreDataChartRespVO result = ConvertUtils.sourceToTarget(resultOld, PreDataChartRespVO.class); |
| | | PreDataViewDTO preDataView = ConvertUtils.sourceToTarget(resultOld.getDataView(), PreDataViewDTO.class); |
| | | if(trendsDataH != null) { |
| | | if (StringUtils.isNotBlank(trendsDataH)) { |
| | | // 动态上限 |
| | | ApiPointValueQueryDTO pointValueQueryDTO = new ApiPointValueQueryDTO(); |
| | | pointValueQueryDTO.setPointNo(trendsDataH); |
| | | pointValueQueryDTO.setStart(startTime); |
| | | pointValueQueryDTO.setEnd(endTime); |
| | | List<ApiPointValueDTO> trendsDataHList = ConvertUtils.sourceToTarget(dataPointApi.queryPointHistoryValue(pointValueQueryDTO), ApiPointValueDTO.class); |
| | | List<Object[]> newList = new ArrayList<>(); |
| | | trendsDataHList.forEach(item -> { |
| | |
| | | }); |
| | | preDataView.setTrendsDataH(newList); |
| | | } |
| | | if(trendsDataL != null) { |
| | | if (StringUtils.isNotBlank(trendsDataL)) { |
| | | // 动态下限 |
| | | ApiPointValueQueryDTO pointValueQueryDTO = new ApiPointValueQueryDTO(); |
| | | pointValueQueryDTO.setPointNo(trendsDataL); |
| | | pointValueQueryDTO.setStart(startTime); |
| | | pointValueQueryDTO.setEnd(endTime); |
| | | List<ApiPointValueDTO> trendsDataLList = ConvertUtils.sourceToTarget(dataPointApi.queryPointHistoryValue(pointValueQueryDTO), ApiPointValueDTO.class); |
| | | List<Object[]> newList = new ArrayList<>(); |
| | | trendsDataLList.forEach(item -> { |
| | |
| | | }); |
| | | preDataView.setTrendsDataL(newList); |
| | | } |
| | | MmItemOutputDTO outputDTO = mcsApi.getItemOutputByItemid(predictItem.getId(), resultStr, resultIndex); |
| | | |
| | | PreItemResultReqVO preItemResultReqVO = new PreItemResultReqVO(); |
| | | preItemResultReqVO.setOutputid(outputDTO.getId()); |
| | | preItemResultReqVO.setStartTime(startTime); |
| | | preItemResultReqVO.setEndTime(endTime); |
| | | preItemResultReqVO.setTimeFormat(timeFormat); |
| | | |
| | | preDataView.setPreData(resultOld.getDataView().getPreDataL()); |
| | | |
| | | result.setPreDataView(preDataView); |
| | | return result; |
| | | } |
| | |
| | | return result; |
| | | } |
| | | |
| | | private Date[] calResultTime2(Date predictTimeReq,String startTimeReq, String endTimeReq, int lengthLeft, int lengthRight) { |
| | | Date[] result = new Date[2]; |
| | | Date predictTime = predictTimeReq; |
| | | Date startTime = new Date(); |
| | | if (startTimeReq == null) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictTime); |
| | | calendar.add(Calendar.SECOND, -1 * lengthLeft * 60); |
| | | startTime = calendar.getTime(); |
| | | } |
| | | Date endTime = new Date(); |
| | | if (endTimeReq == null) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictTime); |
| | | calendar.add(Calendar.SECOND, lengthRight * 60); |
| | | endTime = calendar.getTime(); |
| | | } |
| | | if (endTime.getTime() <= startTime.getTime()) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(startTime); |
| | | calendar.add(Calendar.SECOND, lengthRight * 60); |
| | | endTime = calendar.getTime(); |
| | | } |
| | | result[0] = startTime; |
| | | result[1] = endTime; |
| | | return result; |
| | | } |
| | | /** |
| | | * 查询原始计划、修正计划数据 |
| | | * 查询原始计划、修正计划数据 |
| | | */ |
| | | @Override |
| | | public Map<String, Object> getPlanDataChart(PlanDataChartReqVO reqVO) { |
| | |
| | | list.forEach(item -> { |
| | | tMap.put(item.getParamCode(), item.getParamValue()); |
| | | }); |
| | | String planCode = tMap.get(CommonConstant.PLAN_CODE); |
| | | if (planCode == null) { |
| | | return null; |
| | | } |
| | | String itemCode = tMap.get(CommonConstant.ITEM_CODE); |
| | | if (itemCode == null) { |
| | | return null; |
| | | } |
| | | |
| | | PreDataSingleChartReqVO queryDto = new PreDataSingleChartReqVO(); |
| | | queryDto.setChartCode(reqVO.getChartCode()); |
| | | PreDataSingleChartRespVO chartData = mcsApi.getPreDataSingleChart(queryDto); |
| | | |
| | | Date predictTime = chartData.getPredictTime(); |
| | | int lengthLeft = new BigDecimal(tMap.get(CommonConstant.LENGTH_LEFT)).intValue(); |
| | | int lengthRight = reqVO.getLengthRight(); |
| | | |
| | | Date[] timeArray = calResultTime2(predictTime, reqVO.getStartTime(), reqVO.getEndTime(), lengthLeft, lengthRight); |
| | | Date startTime = timeArray[0]; |
| | | Date endTime = timeArray[1]; |
| | | Date startTime = chartData.getStartTime(); |
| | | Date endTime = chartData.getEndTime(); |
| | | |
| | | // 原始计划数据 |
| | | LinkedHashMap<String, List<String[]>> planData = getRealPlanData(planCode, startTime, endTime, predictTime); |
| | | LinkedHashMap<String, List<String[]>> planData = getRealPlanData(reqVO.getPlanCodes(), startTime, endTime, predictTime); |
| | | |
| | | // 修正计划数据 |
| | | LinkedHashMap<String, List<String[]>> predData = new LinkedHashMap<>(); |
| | | predData.put(reqVO.getChartCode(), getPrePlanData(reqVO.getChartCode(), predictTime, endTime)); |
| | | for (int i = 0; i < reqVO.getPlanCodes().size(); i++) { |
| | | predData.put(reqVO.getPlanCodes().get(i), getPrePlanData(reqVO.getPlanPreds().get(i), predictTime, endTime)); |
| | | } |
| | | result.put("planData", planData); |
| | | result.put("predData", predData); |
| | | return result; |
| | | } |
| | | |
| | | //原始计划 |
| | | public LinkedHashMap<String, List<String[]>> getRealPlanData(String planCode, Date startTime, Date endTime, Date predictTime) { |
| | | public LinkedHashMap<String, List<String[]>> getRealPlanData(List<String> planCodes, Date startTime, Date endTime, Date predictTime) { |
| | | LinkedHashMap<String, List<String[]>> result = new LinkedHashMap<>(); |
| | | ApiDataQueryDTO apiDataQueryDTO = new ApiDataQueryDTO(); |
| | | List<String> itemList = Arrays.asList(planCode.toString().split(",")); |
| | | apiDataQueryDTO.setItemNos(itemList); |
| | | apiDataQueryDTO.setItemNos(planCodes); |
| | | apiDataQueryDTO.setStart(startTime); |
| | | apiDataQueryDTO.setEnd(endTime); |
| | | LinkedHashMap<String, List<ApiPlanDataDTO>> planData = planItemApi.queryPlanItemRecordValue(apiDataQueryDTO); |
| | |
| | | } |
| | | return endTime; |
| | | } |
| | | |
| | | @Override |
| | | public List<PowerNetFactorDTO> getPowerNetFactorList() { |
| | | return ConvertUtils.sourceToTarget(powerNetFactorDao.selectList(new QueryWrapper<PowerNetFactorEntity>().orderByAsc("sort")), PowerNetFactorDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<PowerCapacitorStatusDTO> getPowerCapacitorStatusList() { |
| | | return ConvertUtils.sourceToTarget(powerCapacitorStatusDao.selectList(new QueryWrapper<PowerCapacitorStatusEntity>().orderByAsc("sort")), PowerCapacitorStatusDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<PowerControlMainDTO> getPowerControlMainList() { |
| | | return ConvertUtils.sourceToTarget(powerControlMainDao.selectList(new QueryWrapper<PowerControlMainEntity>().orderByAsc("sort")), PowerControlMainDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<PowerControlDetDTO> getPowerControlDetList(Map<String, Object> params) { |
| | | QueryWrapper<PowerControlDetEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("control_id", params.get("control_id")); |
| | | wrapper.orderByAsc("sort"); |
| | | return ConvertUtils.sourceToTarget(powerControlDetDao.selectList(wrapper), PowerControlDetDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<Object[]> getHistoryValue(Map<String, Object> params) { |
| | | List<Object[]> dataList = new ArrayList<>(); |
| | | |
| | | if (!params.containsKey("dataType") || !params.containsKey("dataNo")) { |
| | | return dataList; |
| | | } |
| | | String dataType = params.get("dataType").toString(); |
| | | String dataNo = params.get("dataNo").toString(); |
| | | |
| | | Date startTime = null; |
| | | Date endTime = null; |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | if (!params.containsKey("endTime") || StringUtils.isBlank(params.get("endTime").toString())) { |
| | | endTime = calendar.getTime(); |
| | | } else { |
| | | endTime = DateUtils.parse(params.get("endTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
| | | } |
| | | if (!params.containsKey("startTime") || StringUtils.isBlank(params.get("startTime").toString())) { |
| | | calendar.add(Calendar.DAY_OF_YEAR, -1); |
| | | startTime = calendar.getTime(); |
| | | } else { |
| | | startTime = DateUtils.parse(params.get("startTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
| | | } |
| | | |
| | | switch (ProcessConfDataTypeEnum.getEumByCode(dataType)) { |
| | | case DATAPOINT: |
| | | ApiPointValueQueryDTO queryParams1 = new ApiPointValueQueryDTO(); |
| | | queryParams1.setPointNo(dataNo); |
| | | queryParams1.setStart(startTime); |
| | | queryParams1.setEnd(endTime); |
| | | List<com.iailab.module.data.api.point.dto.ApiPointValueDTO> pointHisValue = dataPointApi.queryPointHistoryValue(queryParams1); |
| | | pointHisValue.forEach(item -> { |
| | | Object[] values = new Object[2]; |
| | | values[0] = DateUtils.format(item.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
| | | values[1] = new BigDecimal(item.getV()).setScale(3, BigDecimal.ROUND_HALF_UP); |
| | | dataList.add(values); |
| | | }); |
| | | break; |
| | | case IND: |
| | | log.info("IND"); |
| | | ApiIndItemQueryDTO queryParams2 = new ApiIndItemQueryDTO(); |
| | | queryParams2.setItemNo(dataNo); |
| | | queryParams2.setStart(startTime); |
| | | queryParams2.setEnd(endTime); |
| | | List<ApiIndItemValueDTO> indValues = indItemApi.queryIndItemHistoryValue(queryParams2); |
| | | indValues.forEach(item -> { |
| | | Object[] values = new Object[2]; |
| | | values[0] = item.getDataTime(); |
| | | values[1] = item.getDataValue(); |
| | | dataList.add(values); |
| | | }); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return dataList; |
| | | } |
| | | |
| | | @Override |
| | | public List<PreDataViewSimpleDTO> getPreDataByOutIds(PreDataBarLineReqVO reqVO) { |
| | | PreDataBarLineRespVO preDataBarLineRespVO = mcsApi.getPreDataCharts(reqVO); |
| | | List<PreDataViewSimpleDTO> preDataViewSimpleDTOList = new ArrayList<>(); |
| | | preDataBarLineRespVO.getDataViewList().forEach(item -> { |
| | | PreDataViewSimpleDTO preDataViewSimpleDTO = new PreDataViewSimpleDTO(); |
| | | preDataViewSimpleDTO.setItemName(item.getResultName()); |
| | | preDataViewSimpleDTO.setPredictTime(preDataBarLineRespVO.getPredictTime()); |
| | | preDataViewSimpleDTO.setCurData(item.getCurData()); |
| | | preDataViewSimpleDTO.setRealData(item.getRealData()); |
| | | preDataViewSimpleDTOList.add(preDataViewSimpleDTO); |
| | | }); |
| | | return preDataViewSimpleDTOList; |
| | | } |
| | | } |