From 6a7f1e5c70468c8e3d4524f6bb0a54939e6bd025 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 17 六月 2025 14:09:52 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ansteel-biz/src/main/java/com/iailab/module/ansteel/power/service/impl/PowerPriceMainServiceImpl.java |   63 ++++++++++++++++++++++++++++++-
 1 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/power/service/impl/PowerPriceMainServiceImpl.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/power/service/impl/PowerPriceMainServiceImpl.java
index 2ba703f..7620e4c 100644
--- a/ansteel-biz/src/main/java/com/iailab/module/ansteel/power/service/impl/PowerPriceMainServiceImpl.java
+++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/power/service/impl/PowerPriceMainServiceImpl.java
@@ -1,11 +1,13 @@
 package com.iailab.module.ansteel.power.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
 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.framework.security.core.util.SecurityFrameworkUtils;
 import com.iailab.module.ansteel.api.dto.PowerPriceDetDTO;
 import com.iailab.module.ansteel.api.dto.PowerPriceMainDTO;
+import com.iailab.module.ansteel.api.dto.PowerPriceRespVO;
 import com.iailab.module.ansteel.common.constant.CommonConstant;
 import com.iailab.module.ansteel.power.dao.PowerPriceDetDao;
 import com.iailab.module.ansteel.power.dao.PowerPriceMainDao;
@@ -13,13 +15,16 @@
 import com.iailab.module.ansteel.power.entity.PowerPriceMainEntity;
 import com.iailab.module.ansteel.power.service.PowerPriceDetService;
 import com.iailab.module.ansteel.power.service.PowerPriceMainService;
+import com.iailab.module.model.api.mcs.McsApi;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -41,6 +46,12 @@
 
     @Resource
     private PowerPriceDetService powerPriceDetService;
+    @Autowired
+    private McsApi mcsApi;
+
+    private String peakKey = "peak_periods_json";//峰
+    private String valleyKey = "valley_periods_json";//谷
+    private String flatKey = "flat_periods_json";//平
 
     @Override
     public List<PowerPriceMainDTO> list(Map<String, Object> params) {
@@ -64,7 +75,6 @@
         powerPriceMainDao.updateStatus();
 
         if (!CollectionUtils.isEmpty(mainDTO.getDetList())) {
-
             PowerPriceMainEntity powerPriceMainEntity = ConvertUtils.sourceToTarget(mainDTO, PowerPriceMainEntity.class);
             powerPriceMainEntity.setCode(DateUtils.format(new Date(), "yyyyMMddHHmmss"));
             powerPriceMainEntity.setStatus(CommonConstant.IS_ENABLE);
@@ -72,12 +82,37 @@
             powerPriceMainEntity.setCreateDate(new Date());
             powerPriceMainDao.insert(powerPriceMainEntity);
 
+            List<PowerPriceRespVO> list = new ArrayList<>();
             for (int i = 0; i < mainDTO.getDetList().size(); i++) {
                 PowerPriceDetEntity powerPriceDetEntity = ConvertUtils.sourceToTarget(mainDTO.getDetList().get(i), PowerPriceDetEntity.class);
                 powerPriceDetEntity.setMainId(powerPriceMainEntity.getId());
                 powerPriceDetEntity.setSort(i + 1);
                 powerPriceDetDao.insert(powerPriceDetEntity);
+
+                ArrayList arrayList = new ArrayList();
+                arrayList.add(powerPriceDetEntity.getStart());
+                arrayList.add(powerPriceDetEntity.getEnd());
+
+                PowerPriceRespVO powerPriceRespVO = new PowerPriceRespVO();
+                if ("峰".equals(powerPriceDetEntity.getName())) {
+                    powerPriceRespVO.setType("峰");
+                } else if ("谷".equals(powerPriceDetEntity.getName())) {
+                    powerPriceRespVO.setType("谷");
+                } else if ("平".equals(powerPriceDetEntity.getName())) {
+                    powerPriceRespVO.setType("平");
+                }
+
+                powerPriceRespVO.setValue(arrayList.stream().toArray(String[]::new));
+                list.add(powerPriceRespVO);
             }
+
+            Object[] peakArray = list.stream().filter(e -> e.getType().equals("峰")).collect(Collectors.toList()).stream().map(e -> e.getValue()).collect(Collectors.toList()).stream().toArray(Object[]::new);
+            Object[] valleyArray = list.stream().filter(e -> e.getType().equals("谷")).collect(Collectors.toList()).stream().map(e -> e.getValue()).collect(Collectors.toList()).stream().toArray(Object[]::new);
+            Object[] flatArray = list.stream().filter(e -> e.getType().equals("平")).collect(Collectors.toList()).stream().map(e -> e.getValue()).collect(Collectors.toList()).stream().toArray(Object[]::new);
+
+            mcsApi.updateScheduleModelSetting(CommonConstant.COAL_MODEL_CODE,peakKey,JSONArray.toJSONString(peakArray));
+            mcsApi.updateScheduleModelSetting(CommonConstant.COAL_MODEL_CODE,valleyKey,JSONArray.toJSONString(valleyArray));
+            mcsApi.updateScheduleModelSetting(CommonConstant.COAL_MODEL_CODE,flatKey,JSONArray.toJSONString(flatArray));
         }
         return true;
     }
@@ -86,7 +121,6 @@
     @Transactional(rollbackFor = Exception.class)
     public Boolean update(PowerPriceMainDTO mainDTO) {
         if (!CollectionUtils.isEmpty(mainDTO.getDetList())) {
-
             PowerPriceMainEntity powerPriceMainEntity = powerPriceMainDao.selectById(mainDTO.getId());
             powerPriceMainEntity.setCreator(SecurityFrameworkUtils.getLoginUser().getId());
             powerPriceMainEntity.setCreateDate(new Date());
@@ -96,12 +130,37 @@
             queryWrapper.eq("main_id", powerPriceMainEntity.getId());
             powerPriceDetDao.delete(queryWrapper);
 
+            List<PowerPriceRespVO> list = new ArrayList<>();
             for (int i = 0; i < mainDTO.getDetList().size(); i++) {
                 PowerPriceDetEntity powerPriceDetEntity = ConvertUtils.sourceToTarget(mainDTO.getDetList().get(i), PowerPriceDetEntity.class);
                 powerPriceDetEntity.setMainId(powerPriceMainEntity.getId());
                 powerPriceDetEntity.setSort(i + 1);
                 powerPriceDetDao.insert(powerPriceDetEntity);
+
+                ArrayList arrayList = new ArrayList();
+                arrayList.add(powerPriceDetEntity.getStart());
+                arrayList.add(powerPriceDetEntity.getEnd());
+
+                PowerPriceRespVO powerPriceRespVO = new PowerPriceRespVO();
+                if ("峰".equals(powerPriceDetEntity.getName())) {
+                    powerPriceRespVO.setType("峰");
+                } else if ("谷".equals(powerPriceDetEntity.getName())) {
+                    powerPriceRespVO.setType("谷");
+                } else if ("平".equals(powerPriceDetEntity.getName())) {
+                    powerPriceRespVO.setType("平");
+                }
+
+                powerPriceRespVO.setValue(arrayList.stream().toArray(String[]::new));
+                list.add(powerPriceRespVO);
             }
+
+            Object[] peakArray = list.stream().filter(e -> e.getType().equals("峰")).collect(Collectors.toList()).stream().map(e -> e.getValue()).collect(Collectors.toList()).stream().toArray(Object[]::new);
+            Object[] valleyArray = list.stream().filter(e -> e.getType().equals("谷")).collect(Collectors.toList()).stream().map(e -> e.getValue()).collect(Collectors.toList()).stream().toArray(Object[]::new);
+            Object[] flatArray = list.stream().filter(e -> e.getType().equals("平")).collect(Collectors.toList()).stream().map(e -> e.getValue()).collect(Collectors.toList()).stream().toArray(Object[]::new);
+
+            mcsApi.updateScheduleModelSetting(CommonConstant.COAL_MODEL_CODE,peakKey,JSONArray.toJSONString(peakArray));
+            mcsApi.updateScheduleModelSetting(CommonConstant.COAL_MODEL_CODE,valleyKey,JSONArray.toJSONString(valleyArray));
+            mcsApi.updateScheduleModelSetting(CommonConstant.COAL_MODEL_CODE,flatKey,JSONArray.toJSONString(flatArray));
         }
         return true;
     }

--
Gitblit v1.9.3