| | |
| | | package com.iailab.module.ansteel.api.controller.admin; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | |
| | | import com.iailab.module.ansteel.api.dto.*; |
| | | import com.iailab.module.ansteel.api.vo.PowerCapacitorHisPageReqVO; |
| | | import com.iailab.module.ansteel.api.vo.PowerMaxDemandMainPageReqVO; |
| | | import com.iailab.module.ansteel.common.constant.CommonConstant; |
| | | import com.iailab.module.ansteel.common.enums.TransferTypeEnum; |
| | | import com.iailab.module.ansteel.common.utils.DecimalUtil; |
| | | import com.iailab.module.ansteel.common.utils.PowerUtil; |
| | | import com.iailab.module.ansteel.power.entity.*; |
| | |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointsValueQueryDTO; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.ChartParamDTO; |
| | | import com.iailab.module.model.api.mcs.dto.PredictLastValueReqVO; |
| | | import com.iailab.module.model.api.mdk.MdkApi; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.lang.reflect.Array; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.error; |
| | |
| | | private McsApi mcsApi; |
| | | |
| | | @Autowired |
| | | private MdkApi mdkApi; |
| | | |
| | | @Autowired |
| | | private PowerCapacitorHisService powerCapacitorHisService; |
| | | |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private PowerPriceMainService powerPriceMainService; |
| | | |
| | | @Autowired |
| | | private PowerFactorControlService powerFactorControlService; |
| | | |
| | | public static final String VALUE = "value"; |
| | | |
| | | public static final String TIME = "time"; |
| | | |
| | | private String pointNo = "F0000201825"; |
| | | |
| | | @GetMapping("/net-factor/list") |
| | | @Operation(summary = "功率因数-电网拓扑") |
| | |
| | | if (!CollectionUtils.isEmpty(pointsRealValue)) { |
| | | double pValue = new BigDecimal(pointsRealValue.get(entity.getPDay()).toString()).doubleValue(); |
| | | double qValue = new BigDecimal(pointsRealValue.get(entity.getQDay()).toString()).doubleValue(); |
| | | powerNetFactorDTO.setDayCos(new BigDecimal(PowerUtil.calculateCos(pValue, qValue)).setScale(2, BigDecimal.ROUND_HALF_UP)) ; |
| | | powerNetFactorDTO.setDayCos(new BigDecimal(PowerUtil.calculateCos(pValue, qValue)).setScale(2, BigDecimal.ROUND_HALF_UP)); |
| | | } |
| | | } |
| | | |
| | |
| | | if (!CollectionUtils.isEmpty(pointsRealValue)) { |
| | | double pValue = new BigDecimal(pointsRealValue.get(entity.getPMon()).toString()).doubleValue(); |
| | | double qValue = new BigDecimal(pointsRealValue.get(entity.getQMon()).toString()).doubleValue(); |
| | | powerNetFactorDTO.setMonthCos(new BigDecimal(PowerUtil.calculateCos(pValue, qValue)).setScale(2, BigDecimal.ROUND_HALF_UP)) ; |
| | | powerNetFactorDTO.setMonthCos(new BigDecimal(PowerUtil.calculateCos(pValue, qValue)).setScale(2, BigDecimal.ROUND_HALF_UP)); |
| | | } |
| | | } |
| | | result.add(powerNetFactorDTO); |
| | |
| | | if (pv.compareTo(BigDecimal.ZERO) <= 0) { |
| | | continue; |
| | | } |
| | | onCount ++; |
| | | onCount++; |
| | | } |
| | | dto.setOnCount(onCount); |
| | | String remark = String.format("共%d台,在投%d台", DecimalUtil.toBigDecimal(entity.getMainCount()).intValue(), onCount); |
| | |
| | | pointNos.add(netDropdown.getExt1()); |
| | | } |
| | | } |
| | | for(PowerNetDropdownEntity netDropdown : dropdownList) { |
| | | for (PowerNetDropdownEntity netDropdown : dropdownList) { |
| | | PowerDemandQueryRespDTO dto = ConvertUtils.sourceToTarget(netDropdown, PowerDemandQueryRespDTO.class); |
| | | dto.setCurDemand(null); |
| | | result.add(dto); |
| | |
| | | log.info("pointsHisValues is null"); |
| | | return success(result); |
| | | } |
| | | for(PowerDemandQueryRespDTO respDTO : result) { |
| | | for (PowerDemandQueryRespDTO respDTO : result) { |
| | | if (StringUtils.isBlank(demandPointMap.get(respDTO.getNodeCode()))) { |
| | | continue; |
| | | } |
| | |
| | | } |
| | | Map<String, Object> valueMap = hisList.get(hisList.size() - 1); |
| | | respDTO.setDataTime(DateUtils.parse(valueMap.get("time").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | respDTO.setCurDemand( DecimalUtil.toBigDecimal(valueMap.get("value"))); |
| | | respDTO.setCurDemand(DecimalUtil.toBigDecimal(valueMap.get("value"))); |
| | | } |
| | | return success(result); |
| | | } |
| | |
| | | @PostMapping("/power-price/update") |
| | | @Operation(summary = "修改峰谷平电价信息") |
| | | public CommonResult<Boolean> updatePowerPriceList(@RequestBody PowerPriceMainDTO mainDTO) { |
| | | if(StringUtils.isBlank(mainDTO.getId())) { |
| | | if (StringUtils.isBlank(mainDTO.getId())) { |
| | | return error(GlobalErrorCodeConstants.BAD_REQUEST); |
| | | } |
| | | return success(powerPriceMainService.update(mainDTO)); |
| | | } |
| | | |
| | | @PostMapping("/factor-control/list") |
| | | @Operation(summary = "功率因数管控") |
| | | public CommonResult<List<PowerFactorControlDTO>> powerFactorControlList(@RequestBody PowerFactorReqVO powerFactorReqVO) { |
| | | Map<String, Object> chartMap = new HashMap<>(); |
| | | List<ChartParamDTO> chartList = mcsApi.getChartParamList(CommonConstant.POWER_CODE); |
| | | chartList.forEach(item -> { |
| | | chartMap.put(item.getParamName(), item.getParamCode()); |
| | | }); |
| | | List<String> contentList = powerFactorReqVO.getContentList(); |
| | | if (CollectionUtils.isEmpty(contentList)) { |
| | | log.info("contentList为空"); |
| | | return new CommonResult<>(); |
| | | } |
| | | List<Integer> contentListNew = new ArrayList<>(); |
| | | contentList.forEach(item -> { |
| | | chartMap.forEach((key, value) -> { |
| | | if (item.contains(key)) { |
| | | contentListNew.add(Integer.parseInt(value.toString())); |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | MdkScheduleReqDTO dto = new MdkScheduleReqDTO(); |
| | | dto.setScheduleTime(calendar.getTime()); |
| | | dto.setScheduleCode("AnsteelOffPowerAC"); |
| | | Map<String, String> dynamicSettings = new HashMap<>(); |
| | | dynamicSettings.put("option_param", JSONArray.toJSONString(contentListNew.stream().toArray(Integer[]::new))); |
| | | dynamicSettings.put("cos_param", JSONArray.toJSONString(powerFactorReqVO.getAdjustValueList().stream().toArray(String[]::new))); |
| | | dto.setDynamicSettings(dynamicSettings); |
| | | |
| | | log.info("调度方案开始执行," + JSONObject.toJSONString(dto)); |
| | | MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto); |
| | | log.info("调度方案执行完成," + mdkScheduleRespDTO); |
| | | |
| | | String statusCode = mdkScheduleRespDTO.getStatusCode(); |
| | | if (!CommonConstant.MDK_STATUS_100.equals(statusCode)) { |
| | | log.info("statusCode=" + statusCode); |
| | | return CommonResult.error(GlobalErrorCodeConstants.UNKNOWN.getCode(), "工序异常,无计算结果"); |
| | | } |
| | | |
| | | Map<String, Object> data = mdkScheduleRespDTO.getResult(); |
| | | List<String> adjustCosList = Arrays.asList(data.get("adjust_cos").toString().split(","));//管控结果 |
| | | |
| | | PowerFactorControlDTO powerFactorControlDTO = new PowerFactorControlDTO(); |
| | | List<PowerFactorControlDTO> result = new ArrayList<>(); |
| | | List<PowerFactorControlDTO> list = powerFactorControlService.list(powerFactorControlDTO); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | log.info("list is empty"); |
| | | return success(result); |
| | | } |
| | | |
| | | for (int i = 0; i < list.size(); i++) { |
| | | PowerFactorControlDTO controlDTO = list.get(i); |
| | | try { |
| | | PredictLastValueReqVO reqVO = new PredictLastValueReqVO(); |
| | | reqVO.setPredictTime(calendar.getTime()); |
| | | List<String[]> itemNos = new ArrayList<>(); |
| | | if (StringUtils.isNotBlank(controlDTO.getPredResult())) { |
| | | itemNos.add(controlDTO.getPredResult().split(",")); |
| | | } |
| | | if (!CollectionUtils.isEmpty(itemNos)) { |
| | | reqVO.setItemNos(itemNos); |
| | | log.info("reqVO=" + JSONObject.toJSONString(reqVO)); |
| | | Map<String, BigDecimal> preValues = mcsApi.getPredictValueByTime(reqVO); |
| | | if (!ObjectUtils.isEmpty(preValues.get(controlDTO.getPredResult()))) { |
| | | controlDTO.setPredResult(preValues.get(controlDTO.getPredResult()).toString()); |
| | | } |
| | | } |
| | | controlDTO.setAdjustCos(adjustCosList.get(i)); |
| | | |
| | | } catch (Exception ex) { |
| | | log.info(controlDTO.getName() + "获取预测值异常," + ex.getMessage()); |
| | | ex.printStackTrace(); |
| | | } |
| | | result.add(controlDTO); |
| | | } |
| | | |
| | | List<String> points = new ArrayList<>(); |
| | | points.add(pointNo); |
| | | Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points); |
| | | |
| | | PowerFactorControlDTO controlDTO = new PowerFactorControlDTO(); |
| | | controlDTO.setName("望铁关口最大无功倒送量"); |
| | | controlDTO.setPredResult(pointsRealValue.get(pointNo).toString()); |
| | | controlDTO.setAdjustCos(data.get("back_wugong_buchang").toString()); |
| | | controlDTO.setSort(list.size() + 1); |
| | | result.add(controlDTO); |
| | | log.info("result===" + JSONObject.toJSONString(result)); |
| | | return success(result); |
| | | } |
| | | } |