package com.iailab.module.any.controller; import com.alibaba.fastjson.JSONObject; import com.iailab.module.data.api.IFeignDataApi; import com.iailab.module.data.dto.ApiIndValueDTO; import com.iailab.module.data.dto.FeignQueryPointDTO; import com.iailab.framework.common.page.PageData; import com.iailab.common.utils.Constant; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.module.any.dto.AnyAllEvaluationDTO; import com.iailab.module.any.dto.AnyStoreReliabilityDTO; import com.iailab.module.any.dto.AnySugLibDTO; import com.iailab.module.any.dto.AnyTrendResultDTO; import com.iailab.module.any.service.AnySugLibService; import com.iailab.module.mcs.service.StModelResultService; import com.iailab.module.model.handler.ModelHandler; import com.iailab.module.param.service.PageParmService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import javax.annotation.Resource; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author PanZhibao * @Description * @createTime 2024年06月16日 */ @Slf4j @RestController @RequestMapping("any") public class AnyController { @Resource private PageParmService pageParmService; @Resource private IFeignDataApi feignDataApi; @Resource private ModelHandler modelHandler; @Resource private AnySugLibService anySugLibService; @Resource private StModelResultService stModelCommonResultService; private String MODEL_CODE_TREND = "trend_analysis"; /** * 仓储可靠性分析结果(分页) * * @param params * @return */ @GetMapping("store/page") @Operation(summary = "分页") @Parameters({ @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true), @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true), @Parameter(name = Constant.ORDER_FIELD, description = "排序字段"), @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") }) public CommonResult> storePage(@RequestParam Map params) { PageData page = stModelCommonResultService.getStorePage(params); return new CommonResult>().setData(page); } /** * 综合评价分析结果(分页) * * @param params * @return */ @GetMapping("evaluation/page") @Operation(summary = "分页") @Parameters({ @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true), @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true), @Parameter(name = Constant.ORDER_FIELD, description = "排序字段"), @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") }) public CommonResult> evaluationPage(@RequestParam Map params) { PageData page = stModelCommonResultService.getAllEvaluationPage(params); return new CommonResult>().setData(page); } /** * 实时趋势分析 * * @param params * @return */ @GetMapping("ind-item/trend") public CommonResult get(@RequestParam Map params) throws Exception { AnyTrendResultDTO result = new AnyTrendResultDTO(); String paramCode = params.get("paramCode").toString(); String paramValue = pageParmService.selectValue(params.get("page").toString(), params.get("paramCode").toString()); if (StringUtils.isBlank(paramValue)) { return new CommonResult(); } JSONObject paramObj = JSONObject.parseObject(paramValue); result.setChartCode(paramObj.getString("chartCode")); result.setLength(Integer.parseInt(paramObj.getString("length"))); result.setUnit(paramObj.getString("unit")); result.setMaxSlope(new BigDecimal(paramObj.getString("maxSlope"))); result.setMinSlope(new BigDecimal(paramObj.getString("minSlope"))); FeignQueryPointDTO queryIndDto = new FeignQueryPointDTO(); queryIndDto.setPointCode(result.getChartCode()); queryIndDto.setStartDate(params.get("startDate") == null ? null : params.get("startDate").toString()); queryIndDto.setEndDate(params.get("endDate") == null ? null : params.get("endDate").toString()); List indValues = feignDataApi.queryIndItemValuesRange(queryIndDto); result.setValueList(indValues); result.setLength(indValues.size()); List nv = indValues.stream().filter(dto -> {return dto.getDataValue() != null;}).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(nv)) { result.setCurrentValue(nv.get(nv.size() - 1).getDataValue()); } Map mr = new HashMap<>(); mr.put("mean_value", ""); mr.put("max_value", ""); mr.put("min_value", ""); try { List sampleDataList = new ArrayList<>(); double[][] mix = new double[nv.size()][1]; for (int i = 0; i < nv.size(); i++) { mix[i][0] = nv.get(i).getDataValue().doubleValue(); } sampleDataList.add(mix); mr = modelHandler.run(MODEL_CODE_TREND, sampleDataList); String slopeFlag = mr.get("slope_flag").toString(); switch (slopeFlag) { case "1": result.setTrend("上升"); result.setIconClass("el-icon-top"); result.setScopeValue("略有上升趋势"); break; case "2": result.setTrend("上升"); result.setIconClass("el-icon-top"); result.setScopeValue("上升趋势过大"); break; case "-1": result.setTrend("下降"); result.setIconClass("el-icon-bottom"); result.setScopeValue("略有下降趋势"); break; case "-2": result.setTrend("下降"); result.setIconClass("el-icon-bottom"); result.setScopeValue("下降趋势过大"); break; default: result.setTrend("平稳"); result.setScopeValue("平稳"); break; } AnySugLibDTO sugDto = anySugLibService.get("trend", paramCode, slopeFlag); if (sugDto != null) { result.setDispatchSug(sugDto.getContent()); } else { result.setDispatchSug("生产正常,暂无建议"); } } catch (Exception ex) { log.error("趋势模型运行异常"); ex.printStackTrace(); } result.setTrendValue(mr); return new CommonResult().setData(result); } }