| | |
| | | package com.iailab.module.model.mcs.sche.controller.admin; |
| | | |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | 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.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
| | | import com.iailab.module.data.common.ApiDataQueryDTO; |
| | | import com.iailab.module.data.common.ApiDataValueDTO; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.PreDataBarLineReqVO; |
| | | import com.iailab.module.model.api.mcs.dto.PreDataBarLineRespVO; |
| | | import com.iailab.module.model.common.enums.DataCategoryEnum; |
| | | import com.iailab.module.model.common.utils.DateUtils; |
| | | import com.iailab.module.model.mcs.sche.service.StSuggestSnapshotRecordService; |
| | | import com.iailab.module.model.mcs.sche.vo.StSuggestSnapshotRecordChartReqVO; |
| | | import com.iailab.module.model.mcs.sche.vo.StSuggestSnapshotRecordRespVO; |
| | | import com.iailab.module.model.mcs.sche.vo.StSuggestSnapshotRecordSaveReqVO; |
| | | import com.mysql.cj.util.TimeUtil; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.text.DateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | import static com.iailab.module.model.common.utils.DateUtils.DATE_TIME_PATTERN; |
| | | |
| | | /** |
| | | * @author Jay |
| | | */ |
| | | @Tag(name = "调度建议快照") |
| | | @RestController |
| | | @RequestMapping("/model/suggest/snapshot/record") |
| | | public class StSuggestSnapshotRecordController { |
| | | |
| | | @Autowired |
| | | private StSuggestSnapshotRecordService stSuggestSnapshotRecordService; |
| | | |
| | | @GetMapping("/page") |
| | | public CommonResult<PageResult<StSuggestSnapshotRecordRespVO>> getPage(@Valid StSuggestSnapshotRecordChartReqVO pageVO) { |
| | | PageResult<StSuggestSnapshotRecordRespVO> pageResult = stSuggestSnapshotRecordService.page(pageVO); |
| | | return success(pageResult); |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private IndItemApi indItemApi; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | @Autowired |
| | | private McsApi mcsApi; |
| | | |
| | | |
| | | @GetMapping("/list") |
| | | @Parameter(name = "operationId", description = "操作id", required = true, example = "1024") |
| | | public CommonResult<List<StSuggestSnapshotRecordRespVO>> getListByOperationId(@RequestParam("operationId") String operationId) { |
| | | return success(stSuggestSnapshotRecordService.getListByOperationId(operationId)); |
| | | } |
| | | |
| | | @PostMapping("/create") |
| | | public CommonResult<Boolean> create(@Valid @RequestBody StSuggestSnapshotRecordSaveReqVO createReqVO) { |
| | | stSuggestSnapshotRecordService.create(createReqVO); |
| | | return success(true); |
| | | } |
| | | @PostMapping("/getChartData") |
| | | public CommonResult<List<StSuggestSnapshotRecordRespVO>> getChartData(@RequestBody List<StSuggestSnapshotRecordRespVO> reqList){ |
| | | reqList.forEach(item -> { |
| | | List<Object[][]> dataList = new ArrayList<>(); |
| | | if(DataCategoryEnum.DATAPOINT.getCode().equals(item.getDataType())){ |
| | | ApiPointValueQueryDTO queryDTO = new ApiPointValueQueryDTO(); |
| | | queryDTO.setPointNo(item.getDataNo()); |
| | | queryDTO.setStart(item.getStartTime()); |
| | | queryDTO.setEnd(item.getEndTime()); |
| | | List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(queryDTO); |
| | | if (valueList != null && !valueList.isEmpty()){ |
| | | Object [][] data = new Object[valueList.size()][2]; |
| | | for (int i = 0; i < valueList.size(); i++){ |
| | | data[i][0] = DateUtils.format(new Date(String.valueOf(valueList.get(i).getT())),DATE_TIME_PATTERN); |
| | | data[i][1] = valueList.get(i).getV(); |
| | | } |
| | | dataList.add(data); |
| | | } |
| | | } else if (DataCategoryEnum.IND.getCode().equals(item.getDataType())) { |
| | | ApiIndItemQueryDTO queryDTO = new ApiIndItemQueryDTO(); |
| | | queryDTO.setItemNo(item.getDataNo()); |
| | | queryDTO.setStart(item.getStartTime()); |
| | | queryDTO.setEnd(item.getEndTime()); |
| | | List<ApiIndItemValueDTO> valueList = indItemApi.queryIndItemHistoryValue(queryDTO); |
| | | if (valueList != null && !valueList.isEmpty()){ |
| | | Object [][] data = new Object[valueList.size()][2]; |
| | | for (int i = 0; i < valueList.size(); i++){ |
| | | data[i][0] = DateUtils.format(new Date(valueList.get(i).getDataTime()),DATE_TIME_PATTERN); |
| | | data[i][1] = valueList.get(i).getDataValue(); |
| | | } |
| | | dataList.add(data); |
| | | } |
| | | } else if (DataCategoryEnum.PLAN.getCode().equals(item.getDataType())) { |
| | | ApiDataQueryDTO queryDTO = new ApiDataQueryDTO(); |
| | | queryDTO.setItemNo(item.getDataNo()); |
| | | queryDTO.setStart(item.getStartTime()); |
| | | queryDTO.setEnd(item.getEndTime()); |
| | | List<ApiDataValueDTO> valueList = planItemApi.queryPlanItemHistoryValue(queryDTO); |
| | | if (valueList != null && !valueList.isEmpty()){ |
| | | Object [][] data = new Object[valueList.size()][2]; |
| | | for (int i = 0; i < valueList.size(); i++){ |
| | | data[i][0] = DateUtils.format(valueList.get(i).getDataTime(),DATE_TIME_PATTERN); |
| | | data[i][1] = valueList.get(i).getDataValue(); |
| | | } |
| | | dataList.add(data); |
| | | } |
| | | } else if (DataCategoryEnum.PREDICT_ITEM_N.getCode().equals(item.getDataType())) { |
| | | dataList = getPreDataList(item, "N"); |
| | | }else if (DataCategoryEnum.PREDICT_ITEM_L.getCode().equals(item.getDataType())) { |
| | | dataList = getPreDataList(item, "L"); |
| | | }else if (DataCategoryEnum.PREDICT_ITEM_C.getCode().equals(item.getDataType())) { |
| | | dataList = getPreDataList(item, "C"); |
| | | } |
| | | item.setDataList(dataList); |
| | | |
| | | @PutMapping("/update") |
| | | public CommonResult<Boolean> update(@Valid @RequestBody StSuggestSnapshotRecordSaveReqVO updateReqVO) { |
| | | stSuggestSnapshotRecordService.update(updateReqVO); |
| | | return success(true); |
| | | }); |
| | | return success(reqList); |
| | | } |
| | | |
| | | @DeleteMapping("/delete") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | public CommonResult<Boolean> deleteTenant(@RequestParam("id") String id) { |
| | | stSuggestSnapshotRecordService.delete(id); |
| | | return success(true); |
| | | private List<Object[][]> getPreDataList(StSuggestSnapshotRecordRespVO resVo, String type){ |
| | | List<Object[][]> dataList = new ArrayList<>(); |
| | | PreDataBarLineReqVO reqVO = new PreDataBarLineReqVO(); |
| | | List<String> outIds = new ArrayList<>(); |
| | | outIds.add(resVo.getDataNo()); |
| | | reqVO.setOutIds(outIds); |
| | | reqVO.setStartTime(resVo.getStartTime()); |
| | | reqVO.setEndTime(resVo.getEndTime()); |
| | | PreDataBarLineRespVO result = mcsApi.getPreDataCharts(reqVO); |
| | | if (result == null || result.getDataViewList() == null || result.getDataViewList().size() == 0){ |
| | | return dataList; |
| | | } |
| | | List<String> xData = result.getCategories(); |
| | | List<Object[]> yData = new ArrayList<>(); |
| | | if ("N".equals(type) && result.getDataViewList().get(0).getPreDataN()!=null){ |
| | | yData = result.getDataViewList().get(0).getPreDataN(); |
| | | }else if ("L".equals(type) && result.getDataViewList().get(0).getPreDataL()!=null){ |
| | | yData = result.getDataViewList().get(0).getPreDataL(); |
| | | }else if ("C".equals(type) && result.getDataViewList().get(0).getCurData()!=null){ |
| | | yData = result.getDataViewList().get(0).getCurData(); |
| | | } |
| | | Object [][] data = new Object[xData.size()][1]; |
| | | for (int i = 0; i < xData.size(); i++){ |
| | | data[i][0] = xData.get(i); |
| | | data[i][1] = yData.get(i); |
| | | dataList.add(data); |
| | | } |
| | | return dataList; |
| | | } |
| | | } |