ソースを参照

相关接口新增

王苗苗 6 ヶ月 前
コミット
d61cbce3f7

+ 59 - 0
src/main/java/com/xlht/xlhtproject/controller/FrontController.java

@@ -0,0 +1,59 @@
+package com.xlht.xlhtproject.controller;
+
+
+import com.xlht.xlhtproject.respParse.bean.AjaxResult;
+import com.xlht.xlhtproject.service.IFrontService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 前端用户相关接口
+ */
+@RestController
+@RequestMapping("/front")
+@Slf4j
+public class FrontController {
+
+    @Autowired
+    private IFrontService frontService;
+
+
+    /**
+     *
+     * 智能投药系统获取实时需要数据接口
+     * @return
+     */
+    @GetMapping("/bigModel/smartAdd/dataInfo")
+    public AjaxResult smartAddDataInfo()
+    {
+        log.info("进入了 智能投药系统获取实时需要数据 接口");
+        return AjaxResult.success(frontService.smartAddDataInfo());
+    }
+
+
+    /**
+     * type说明:
+     * 0:进水流量
+     * 1:#1好氧池硝酸盐
+     * 2:#2好氧池硝酸盐
+     * 3:#1缺氧池氨氮
+     * 4:#2缺氧池氨氮
+     * 5:进水COD
+     * 6:进水总氮
+     * 7:碳源投加量
+     *
+     *
+     * @param type
+     * @return
+     */
+    @GetMapping("/bigModel/smartAdd/charList/{type}")
+    public AjaxResult smartAddCharList(@PathVariable int type, @RequestParam(required = false, name = "timeBegin") String timeBegin, @RequestParam(required = false, name = "timeEnd") String timeEnd)
+    {
+        log.info("进入了 智能投药系统获取对应指标最近1天的数据情况 接口");
+        return AjaxResult.success(frontService.smartAddCharList(type, timeBegin, timeEnd));
+    }
+
+
+
+}

+ 31 - 0
src/main/java/com/xlht/xlhtproject/domain/ChartBasic.java

@@ -0,0 +1,31 @@
+package com.xlht.xlhtproject.domain;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+
+@Builder
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class ChartBasic {
+
+
+    private String time;
+
+    private BigDecimal val;
+
+    private BigDecimal ztTotalCo2;//总碳排放量
+
+    private BigDecimal wschytpfqd;//污水厂行业碳排放强度
+
+
+    public ChartBasic(String time, BigDecimal val) {
+        this.time = time;
+        this.val = val;
+    }
+}

+ 38 - 0
src/main/java/com/xlht/xlhtproject/domain/SmartAdd.java

@@ -0,0 +1,38 @@
+package com.xlht.xlhtproject.domain;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+
+@Builder
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class SmartAdd {
+
+    private BigDecimal jslYB;//进水流量-仪表
+    private BigDecimal jsCodYB;//进水cod-仪表
+    private BigDecimal jsTnYB;//进水总氮-仪表
+
+    private BigDecimal jsCodHY;//进水cod-化验
+
+    private BigDecimal hyXsyHYOne;//好氧硝酸盐-化验-一池
+    private BigDecimal hyXsyYCOne;//好氧硝酸盐-预测-一池
+    private BigDecimal qyXsyHYOne;//缺氧硝酸盐-化验-一池
+    private BigDecimal qyAdHYOne;//缺氧氨氮-化验-一池
+
+    private BigDecimal hyXsyHYTwo;//好氧硝酸盐-化验-二池
+    private BigDecimal hyXsyYCTwo;//好氧硝酸盐-预测-二池
+    private BigDecimal qyXsyHYTwo;//缺氧硝酸盐-化验-二池
+    private BigDecimal qyAdHYTwo;//缺氧氨氮-化验-二池
+
+
+//    private BigDecimal tdbJS;//碳氮比-计算
+
+
+
+}

+ 23 - 22
src/main/java/com/xlht/xlhtproject/domain/TShuju1.java

@@ -6,6 +6,7 @@ import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 /**
@@ -26,85 +27,85 @@ public class TShuju1
     private Long ID;
 
     /** 进水总流量 */
-    private Long scJsZll;
+    private BigDecimal scJsZll;
 
     /** 进水COD*/
-    private Long scJsCod;
+    private BigDecimal scJsCod;
 
     /** 进水总氮 */
-    private Long scJsZongdan;
+    private BigDecimal scJsZongdan;
 
     /** 进水氨氮 */
-    private Long scJsAndan;
+    private BigDecimal scJsAndan;
 
     /** 进水总磷 */
-    private Long scJsZonglin;
+    private BigDecimal scJsZonglin;
 
     /** 出水COD */
-    private Long scCsCod;
+    private BigDecimal scCsCod;
 
     /** 出水总氮 */
-    private Long scCsZongdan;
+    private BigDecimal scCsZongdan;
 
     /** 出水氨氮 */
-    private Long scCsAndan;
+    private BigDecimal scCsAndan;
 
     /** 出水总磷 */
-    private Long scCsZonglin;
+    private BigDecimal scCsZonglin;
 
     /** 出水总流量 */
-    private Long scCsZll;
+    private BigDecimal scCsZll;
 
     /** 1池缺氧氨氮 */
-    private Long jqr1QyAndan;
+    private BigDecimal jqr1QyAndan;
 
     /** 1池缺氧氨氮-化验时间 */
     private String jqr1QyAndanTime;
 
     /** 1池缺氧硝氮 */
-    private Long jqr1QyXiaodan;
+    private BigDecimal jqr1QyXiaodan;
 
     /** 1池缺氧硝氮-化验时间 */
     private String jqr1QyXiaodanTime;
 
     /** 1池好氧氨氮 */
-    private Long jqr1HyAndan;
+    private BigDecimal jqr1HyAndan;
 
     /** 1池好氧氨氮-化验时间 */
     private String jqr1HyAndanTime;
 
     /** 1池好氧硝氮 */
-    private Long jqr1HyXiaodan;
+    private BigDecimal jqr1HyXiaodan;
 
     /** 1池好氧硝氮-化验时间 */
     private String jqr1HyXiaodanTime;
 
     /** 2池缺氧氨氮 */
-    private Long jqr2QyAndan;
+    private BigDecimal jqr2QyAndan;
 
     /** 2池缺氧氨氮-化验时间 */
     private String jqr2QyAndanTime;
 
     /** 2池缺氧硝氮 */
-    private Long jqr2QyXiaodan;
+    private BigDecimal jqr2QyXiaodan;
 
     /** 2池缺氧硝氮-化验时间 */
     private String jqr2QyXiaodanTime;
 
     /** 2池好氧氨氮 */
-    private Long jqr2HyAndan;
+    private BigDecimal jqr2HyAndan;
 
     /** 2池好氧氨氮-化验时间 */
     private String jqr2HyAndanTime;
 
     /** 2池好样硝氮 */
-    private Long jqr2HyXiaodan;
+    private BigDecimal jqr2HyXiaodan;
 
     /** 2池好氧硝氮-化验时间 */
     private String jqr2HyXiaodanTime;
 
     /** 生物池进水COD */
-    private Long jqrSwcCod;
+    private BigDecimal jqrSwcCod;
 
     /** 生物池进水COD-化验时间 */
     private String jqrSwcCodTime;
@@ -113,19 +114,19 @@ public class TShuju1
     private String TIME;
 
     /** 1池好氧正磷 */
-    private Long jqr1HyZhenglin;
+    private BigDecimal jqr1HyZhenglin;
 
     /** 1池好氧正磷-化验时间 */
     private String jqr1HyZhenglinTime;
 
     /** 2池好氧正磷 */
-    private Long jqr2HyZhenglin;
+    private BigDecimal jqr2HyZhenglin;
 
     /** 2池好氧正磷-化验时间 */
     private String jqr2HyZhenglinTime;
 
     /** 生物池进水正磷 */
-    private Long jqrSwcZhenglin;
+    private BigDecimal jqrSwcZhenglin;
 
     /** 生物池进水正磷-化验时间 */
     private String jqrSwcZhenglinTime;

+ 6 - 6
src/main/java/com/xlht/xlhtproject/domain/TXinyiMedicineParam.java

@@ -31,10 +31,10 @@ public class TXinyiMedicineParam
     private Long numberBeng;
 
     /** 加药方式(0自动 1一号池 2二号池 3人工投放) */
-    private Long type;
+    private Integer type;
 
     /** 进水流量类型(0手动 1仪表) */
-    private Long jsLlType;
+    private Integer jsLlType;
 
     /** 进水流量1号池 */
     private BigDecimal jsLlOne;
@@ -43,7 +43,7 @@ public class TXinyiMedicineParam
     private BigDecimal jsLlTwo;
 
     /** 进水cod类型(0手动 1仪表 2化验) */
-    private Long jsCodType;
+    private Integer jsCodType;
 
     /** 进水cod1号池 */
     private BigDecimal jsCodOne;
@@ -52,7 +52,7 @@ public class TXinyiMedicineParam
     private BigDecimal jsCodTwo;
 
     /** 好氧池硝酸盐类型(0手动 1化验 2预测) */
-    private Long hycXsyType;
+    private Integer hycXsyType;
 
     /** 好氧池硝酸盐1号池 */
     private BigDecimal hycXsyOne;
@@ -61,7 +61,7 @@ public class TXinyiMedicineParam
     private BigDecimal hycXsyTwo;
 
     /** 缺氧池硝酸盐类型(0手动 1化验) */
-    private Long qycYxyType;
+    private Integer qycYxyType;
 
     /** 缺氧池硝酸盐1号池 */
     private BigDecimal qycYxyOne;
@@ -70,7 +70,7 @@ public class TXinyiMedicineParam
     private BigDecimal qycYxyTwo;
 
     /** 缺氧池氨氮类型(0手动 1化验) */
-    private Long qycAdType;
+    private Integer qycAdType;
 
     /** 缺氧池氨氮1号池 */
     private BigDecimal qycAdOne;

+ 86 - 0
src/main/java/com/xlht/xlhtproject/enums/BusinessEnum.java

@@ -0,0 +1,86 @@
+package com.xlht.xlhtproject.enums;
+
+public class BusinessEnum {
+
+    /**
+     *
+     * 数据来源枚举
+     *
+     */
+    public enum DataSourceEnum
+    {
+        YB("YB", "仪表"),
+        HY("HY", "化验"),
+        YC("YC", "预测"),
+
+
+        ;
+
+        private final String code;
+        private final String msg;
+
+        DataSourceEnum(String code, String msg)
+        {
+            this.code = code;
+            this.msg = msg;
+        }
+
+        public String getCode()
+        {
+            return code;
+        }
+
+        public String getMsg()
+        {
+            return msg;
+        }
+    }
+
+
+    /**
+     *
+     * 智能投药请求参数枚举
+     *      * 0:进水流量
+     *      * 1:#1好氧池硝酸盐
+     *      * 2:#2好氧池硝酸盐
+     *      * 3:#1缺氧池氨氮
+     *      * 4:#2缺氧池氨氮
+     *      * 5:进水COD
+     *      * 6:进水总氮
+     *      * 7:碳源投加量
+     *
+     */
+    public enum SmartAddMedicineReqEnum
+    {
+        JSLL(0, "进水流量"),
+        HY_1_XSY(1, "#1好氧池硝酸盐"),
+        HY_2_XSY(2, "#2好氧池硝酸盐"),
+        QY_1_AD(3, "#1缺氧池氨氮"),
+        QY_2_AD(4, "#2缺氧池氨氮"),
+        JSCOD(5, "进水COD"),
+        JSTN(6, "进水总氮"),
+        TYTJL(7, "碳源投加量"),
+
+
+        ;
+
+        private final int code;
+        private final String msg;
+
+        SmartAddMedicineReqEnum(int code, String msg)
+        {
+            this.code = code;
+            this.msg = msg;
+        }
+
+        public int getCode()
+        {
+            return code;
+        }
+
+        public String getMsg()
+        {
+            return msg;
+        }
+    }
+}

+ 19 - 0
src/main/java/com/xlht/xlhtproject/enums/MyConstants.java

@@ -0,0 +1,19 @@
+package com.xlht.xlhtproject.enums;
+
+import java.math.BigDecimal;
+
+public class MyConstants {
+
+
+    public static final int INT_3 = 3;
+
+
+    public static final int NUMBER_SCALE_4 = 4;
+    public static final int NUMBER_SCALE_10 = 10;
+
+
+    public static final BigDecimal BigDecimal_1 = new BigDecimal("1");
+    public static final BigDecimal BigDecimal_2 = new BigDecimal("2");
+    public static final BigDecimal BigDecimal_1000 = new BigDecimal(1000);
+
+}

+ 5 - 0
src/main/java/com/xlht/xlhtproject/mapper/TShuju1Mapper.java

@@ -1,6 +1,8 @@
 package com.xlht.xlhtproject.mapper;
 
 import java.util.List;
+
+import com.xlht.xlhtproject.domain.SmartAdd;
 import com.xlht.xlhtproject.domain.TShuju1;
 
 /**
@@ -58,4 +60,7 @@ public interface TShuju1Mapper
      * @return 结果
      */
     public int deleteTShuju1ByIDs(Long[] IDs);
+
+    //获取最新的一条数据,并且是按照之前的返回的对象处理【SQL 别名】
+    SmartAdd getNewestData();
 }

+ 15 - 0
src/main/java/com/xlht/xlhtproject/service/IFrontService.java

@@ -0,0 +1,15 @@
+package com.xlht.xlhtproject.service;
+
+import com.xlht.xlhtproject.domain.ChartBasic;
+import com.xlht.xlhtproject.domain.SmartAdd;
+
+import java.util.List;
+import java.util.Map;
+
+public interface IFrontService {
+
+
+    SmartAdd smartAddDataInfo();
+
+    Map<String, List<ChartBasic>> smartAddCharList(int type, String timeBegin, String timeEnd);
+}

+ 110 - 0
src/main/java/com/xlht/xlhtproject/service/impl/FrontServiceImpl.java

@@ -0,0 +1,110 @@
+package com.xlht.xlhtproject.service.impl;
+
+import com.xlht.xlhtproject.domain.ChartBasic;
+import com.xlht.xlhtproject.domain.SmartAdd;
+import com.xlht.xlhtproject.domain.TShuju1;
+import com.xlht.xlhtproject.enums.BusinessEnum;
+import com.xlht.xlhtproject.mapper.TShuju1Mapper;
+import com.xlht.xlhtproject.service.IFrontService;
+import com.xlht.xlhtproject.utils.DateUtils;
+import com.xlht.xlhtproject.utils.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class FrontServiceImpl implements IFrontService {
+
+    @Autowired
+    private TShuju1Mapper shuju1Mapper;
+
+
+    @Override
+    public SmartAdd smartAddDataInfo() {
+        return this.shuju1Mapper.getNewestData();
+    }
+
+    @Override
+    public Map<String, List<ChartBasic>> smartAddCharList(int type, String timeBegin, String timeEnd) {
+//        return Collections.emptyMap();
+        //日期兜底处理
+        Date nowDate = DateUtils.getNowDate();
+        Date dayBefore7 = DateUtils.plusDate(-1, nowDate);
+        //2024年09月13日17:02:59 支持前段自定义起止时间
+        //先用日期获取当天和前一天的数据,如果获取不到,则提示错误信息
+        String nowDateStr = StringUtils.isBlank(timeEnd) ? DateUtils.parseDateToStr(DateUtils.YYYYMMDD_TS, nowDate) : timeEnd;
+        String dayBefore1Str = StringUtils.isBlank(timeBegin) ? DateUtils.parseDateToStr(DateUtils.YYYYMMDD_TS, dayBefore7) : timeBegin;
+        //返回的对象
+        Map<String, List<ChartBasic>> result = new HashMap<>();
+        //获取筛选日期内的所有的数据
+        List<TShuju1> tShuju1List = this.shuju1Mapper.selectTShuju1List(TShuju1.builder().timeBegin(dayBefore1Str).timeEnd(nowDateStr).build());
+        List<ChartBasic> list = new ArrayList<>();
+        //先判断类型,然后根据不同类型,查询不同的数据
+        if(BusinessEnum.SmartAddMedicineReqEnum.JSLL.getCode() == type){
+            //查询仪表即可
+            list = tShuju1List.stream()
+                    .map(o -> new ChartBasic(o.getTIME(), o.getScJsZll()))
+                    .collect(Collectors.toList());
+            result.put(BusinessEnum.DataSourceEnum.YB.getCode(), list);
+        }else if(BusinessEnum.SmartAddMedicineReqEnum.HY_1_XSY.getCode() == type){
+            //查询化验室
+            list = tShuju1List.stream()
+                    .map(o -> new ChartBasic(o.getTIME(), o.getJqr1HyXiaodan()))
+                    .collect(Collectors.toList());
+            result.put(BusinessEnum.DataSourceEnum.HY.getCode(), list);
+            //查询预测 锡林浩特没有预测数据
+//            result.put(BusinessEnum.DataSourceEnum.YC.getCode(), list);
+        }else if(BusinessEnum.SmartAddMedicineReqEnum.HY_2_XSY.getCode() == type){
+            //查询化验室
+            list = tShuju1List.stream()
+                    .map(o -> new ChartBasic(o.getTIME(), o.getJqr2HyXiaodan()))
+                    .collect(Collectors.toList());
+            result.put(BusinessEnum.DataSourceEnum.HY.getCode(), list);
+            //查询预测 锡林浩特没有预测数据
+//            list =
+//            result.put(BusinessEnum.DataSourceEnum.YC.getCode(), list);
+        }else if(BusinessEnum.SmartAddMedicineReqEnum.QY_1_AD.getCode() == type){
+            //查询化验室
+            list = tShuju1List.stream()
+                    .map(o -> new ChartBasic(o.getTIME(), o.getJqr1QyAndan()))
+                    .collect(Collectors.toList());
+            result.put(BusinessEnum.DataSourceEnum.HY.getCode(), list);
+        }else if(BusinessEnum.SmartAddMedicineReqEnum.QY_2_AD.getCode() == type){
+            //查询化验室
+            list = tShuju1List.stream()
+                    .map(o -> new ChartBasic(o.getTIME(), o.getJqr2QyAndan()))
+                    .collect(Collectors.toList());
+            result.put(BusinessEnum.DataSourceEnum.HY.getCode(), list);
+        }else if(BusinessEnum.SmartAddMedicineReqEnum.JSCOD.getCode() == type){
+            //查询仪表即可
+            list = tShuju1List.stream()
+                    .map(o -> new ChartBasic(o.getTIME(), o.getScJsCod()))
+                    .collect(Collectors.toList());
+            result.put(BusinessEnum.DataSourceEnum.YB.getCode(), list);
+            //查询化验室
+            list = tShuju1List.stream()
+                    .map(o -> new ChartBasic(o.getTIME(), o.getJqrSwcCod()))
+                    .collect(Collectors.toList());
+            result.put(BusinessEnum.DataSourceEnum.HY.getCode(), list);
+        }else if(BusinessEnum.SmartAddMedicineReqEnum.JSTN.getCode() == type){
+            //查询仪表即可
+            list = tShuju1List.stream()
+                    .map(o -> new ChartBasic(o.getTIME(), o.getScJsZongdan()))
+                    .collect(Collectors.toList());
+            result.put(BusinessEnum.DataSourceEnum.YB.getCode(), list);
+        }else if(BusinessEnum.SmartAddMedicineReqEnum.TYTJL.getCode() == type){
+            //查询仪表即可  锡林浩特的没有
+            /*list = tShuju1List.stream()
+                    .map(o -> new ChartBasic(o.getTIME(), o.get()))
+                    .collect(Collectors.toList());
+            result.put(BusinessEnum.DataSourceEnum.YB.getCode(), list);*/
+        }else{
+            log.info("暂不支持的类型~~~");
+        }
+        return result;
+    }
+}

+ 195 - 0
src/main/java/com/xlht/xlhtproject/utils/CalculateUtils.java

@@ -0,0 +1,195 @@
+package com.xlht.xlhtproject.utils;
+
+import com.xlht.xlhtproject.domain.SmartAdd;
+import com.xlht.xlhtproject.domain.TXinyiMedicineParam;
+import com.xlht.xlhtproject.mapper.TShuju1Mapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Objects;
+
+import static com.xlht.xlhtproject.enums.MyConstants.*;
+
+@Component
+public class CalculateUtils {
+
+    @Autowired
+    private TShuju1Mapper shuju1Mapper;
+
+    public BigDecimal calculateMedicineByLastRecord(TXinyiMedicineParam param, int type) {
+        if (Objects.isNull(param)) {
+            return null;
+        }
+        //计算用到的值
+        Integer hycXsyType = param.getHycXsyType();
+        BigDecimal hycXsyOne = param.getHycXsyOne();
+        BigDecimal hycXsyTwo = param.getHycXsyTwo();
+
+        BigDecimal htfksd = param.getHtfksd();
+
+        Integer qycAdType = param.getQycAdType();
+        BigDecimal qycAdOne = param.getQycAdOne();
+        BigDecimal qycAdTwo = param.getQycAdTwo();
+
+        Integer qycYxyType = param.getQycYxyType();
+        BigDecimal qycYxyOne = param.getQycYxyOne();
+        BigDecimal qycYxyTwo = param.getQycYxyTwo();
+
+        BigDecimal xzxs = param.getXzxs();
+
+        BigDecimal jzxs = param.getJzxs();
+
+        Integer jsLlType = param.getJsLlType();
+        BigDecimal jsLlOne = param.getJsLlOne();
+        BigDecimal jsLlTwo = param.getJsLlTwo();
+
+        BigDecimal slfpxs = param.getSlfpxs();
+
+        BigDecimal kzxs = param.getKzxs();
+
+        Integer jsCodType = param.getJsCodType();
+        BigDecimal jsCodOne = param.getJsCodOne();
+        BigDecimal jsCodTwo = param.getJsCodTwo();
+
+        BigDecimal zhxs = param.getZhxs();
+
+        BigDecimal tydl = param.getTydl();
+
+        BigDecimal medicineAmount = param.getMedicineAmount();//手动需要
+
+//        Integer type = param.getType();//0自动 1一号池 2二号池 3人工投放
+
+        BigDecimal yymd = param.getYymd();
+
+        BigDecimal sxps = param.getSxps();
+
+        //计算
+        if(!Objects.isNull(type)) {
+            if(3 == type){
+                return medicineAmount;
+            }
+            //2024年09月19日11:30:06 锡林浩特,碳源投放是1池和2池分开投放的
+            //计算1号池的值
+            //计算二号池的值
+            //判断,返回值
+            if(0 == type)//锡林浩特没有这个逻辑,连个池子是分开的
+                return null;
+            else if(1 == type) {
+                return getResultByDiff(hycXsyType, hycXsyOne, htfksd, qycAdType, qycAdOne, qycYxyType, qycYxyOne, xzxs, jzxs, jsLlType, jsLlOne, slfpxs, kzxs, jsCodType, jsCodOne, zhxs, tydl, "one", yymd, sxps);
+            }else if(2 == type)
+                return getResultByDiff(hycXsyType, hycXsyTwo, htfksd, qycAdType, qycAdTwo, qycYxyType, qycYxyTwo, xzxs, jzxs, jsLlType, jsLlTwo, slfpxs, kzxs, jsCodType, jsCodTwo, zhxs, tydl, "two", yymd, sxps);
+            else {
+                return null;//错误的配置
+            }
+        }
+        return null;
+    }
+
+    private BigDecimal getResultByDiff(Integer hycXsyType, BigDecimal hycXsyVal, BigDecimal htfksd, Integer qycAdType, BigDecimal qycAdVal, Integer qycYxyType,
+                                       BigDecimal qycYxyVal, BigDecimal xzxs, BigDecimal jzxs, Integer jsLlType, BigDecimal jsLlVal, BigDecimal slfpxs, BigDecimal kzxs, Integer jsCodType,
+                                       BigDecimal jsCodVal, BigDecimal zhxs, BigDecimal tydl, String whichCZ, BigDecimal yymd, BigDecimal sxps) {
+        //2024年09月14日10:26:11  不同池子,根据不同类型,获取最新的数据,计算碳源投加量
+        //获取最新的实时数据
+        SmartAdd smartAdd = this.shuju1Mapper.getNewestData();
+        if(!Objects.isNull(smartAdd)){
+            if("one".equals(whichCZ)){//一池
+                if(!Objects.isNull(hycXsyType)){
+                    if(1 == hycXsyType){//化验
+                        hycXsyVal = smartAdd.getHyXsyHYOne();
+                    }else if(2 == hycXsyType){//预测
+                        hycXsyVal = smartAdd.getHyXsyYCOne();
+                    }
+                }
+                if(!Objects.isNull(qycAdType) && 1 == qycAdType){//化验
+                    qycAdVal = smartAdd.getQyAdHYOne();
+                }
+                if(!Objects.isNull(qycYxyType) && 1 == qycYxyType){//化验
+                    qycYxyVal = smartAdd.getQyXsyHYOne();
+                }
+                if(!Objects.isNull(jsCodType)){
+                    if(1 == jsCodType){//仪表
+                        jsCodVal = smartAdd.getJsCodYB();
+                    }else if(2 == jsCodType){//化验
+                        jsCodVal = smartAdd.getJsCodHY();
+                    }
+                }
+                if(!Objects.isNull(jsLlType) && 1 == jsLlType){//仪表
+                    jsLlVal = smartAdd.getJslYB();
+                }
+            }else {//二池
+                if(!Objects.isNull(hycXsyType)){
+                    if(1 == hycXsyType){//化验
+                        hycXsyVal = smartAdd.getHyXsyHYTwo();
+                    }else if(2 == hycXsyType){//预测
+                        hycXsyVal = smartAdd.getHyXsyYCTwo();
+                    }
+                }
+                if(!Objects.isNull(qycAdType) && 1 == qycAdType){//化验
+                    qycAdVal = smartAdd.getQyAdHYTwo();
+                }
+                if(!Objects.isNull(qycYxyType) && 1 == qycYxyType){//化验
+                    qycYxyVal = smartAdd.getQyXsyHYTwo();
+                }
+                if(!Objects.isNull(jsCodType)){
+                    if(1 == jsCodType){//仪表
+                        jsCodVal = smartAdd.getJsCodYB();
+                    }else if(2 == jsCodType){//化验
+                        jsCodVal = smartAdd.getJsCodHY();
+                    }
+                }
+                if(!Objects.isNull(jsLlType) && 1 == jsLlType){//仪表
+                    jsLlVal = smartAdd.getJslYB();
+                }
+            }
+        }
+
+
+        //兜底处理
+        if(Objects.isNull(hycXsyVal))
+            hycXsyVal = BigDecimal.ZERO;
+        if(Objects.isNull(htfksd))
+            htfksd = BigDecimal.ZERO;
+        if(Objects.isNull(qycAdVal))
+            qycAdVal = BigDecimal.ZERO;
+        if(Objects.isNull(qycYxyVal))
+            qycYxyVal = BigDecimal.ZERO;
+        if(Objects.isNull(xzxs))
+            xzxs = BigDecimal.ZERO;
+        if(Objects.isNull(jzxs))
+            jzxs = BigDecimal.ZERO;
+        if(Objects.isNull(jsLlVal))
+            jsLlVal = BigDecimal.ZERO;
+        if(Objects.isNull(slfpxs))
+            slfpxs = BigDecimal.ZERO;
+        if(Objects.isNull(kzxs))
+            kzxs = BigDecimal.ZERO;
+        if(Objects.isNull(jsCodVal))
+            jsCodVal = BigDecimal.ZERO;
+        if(Objects.isNull(zhxs))
+            zhxs = BigDecimal.ZERO;
+        if(Objects.isNull(tydl))
+            return null;//除数不能为0
+        if(Objects.isNull(yymd) || yymd.compareTo(BigDecimal.ZERO) <= 0)
+            return null;//除数不能为0
+        if(Objects.isNull(sxps)){
+            sxps = BigDecimal.ZERO;
+        }
+        //1)计算挟走量
+        BigDecimal xzl = (((BigDecimal_2.multiply(hycXsyVal).subtract(htfksd)).add(((qycAdVal.add(qycYxyVal)).multiply(xzxs).subtract(htfksd)))).multiply((jzxs.subtract(BigDecimal_1)))).multiply((jsLlVal.multiply(slfpxs))).divide(BigDecimal_1000, NUMBER_SCALE_4, RoundingMode.HALF_UP);
+        //2)计算碳源投加总量
+        BigDecimal total = (xzl.multiply(kzxs).subtract((jsLlVal.multiply(slfpxs).multiply(jsCodVal).multiply(zhxs).divide(BigDecimal_1000, NUMBER_SCALE_4, RoundingMode.HALF_UP)))).divide(tydl, NUMBER_SCALE_4, RoundingMode.HALF_UP);
+        //2024年09月14日15:33:37 计算出来的结果太大,是几千,把第三步公式也加上
+        //计算加药流量
+        return DecimalUtils.getNLengthHalfUp(total.divide(yymd, NUMBER_SCALE_10, RoundingMode.HALF_UP).divide(BigDecimal_1000, NUMBER_SCALE_10, RoundingMode.HALF_UP).multiply(sxps), INT_3);
+    }
+
+
+    /*public static void main(String[] args) {
+        TXinyiMedicineParam tXinyiMedicineParam = new TXinyiMedicineParam();
+        tXinyiMedicineParam.setYymd(BigDecimal_2);
+        tXinyiMedicineParam.setTydl(BigDecimal_2);
+        System.out.println(calculateMedicineByLastRecord(tXinyiMedicineParam, 1));
+    }*/
+}

+ 77 - 0
src/main/java/com/xlht/xlhtproject/utils/DecimalUtils.java

@@ -0,0 +1,77 @@
+package com.xlht.xlhtproject.utils;
+
+import com.alibaba.fastjson2.JSONArray;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.OptionalDouble;
+import java.util.stream.Collectors;
+
+public class DecimalUtils {
+
+
+    public static BigDecimal getAbs(BigDecimal req){
+        if(Objects.isNull(req))
+            return null;
+        return req.abs();
+    }
+
+
+    public static BigDecimal getAbsAndScale(BigDecimal req, int length){
+        if(Objects.isNull(req))
+            return null;
+        return req.abs().setScale(length, RoundingMode.DOWN);
+    }
+
+    public static BigDecimal getNLengthHalfUp(BigDecimal req, int length){
+        if(Objects.isNull(req))
+            return null;
+        return req.setScale(length, RoundingMode.HALF_UP);
+    }
+
+    /**
+     * 处理字符串类型的数值 取绝对值并保持N位小数。
+     * @param req
+     * @param length
+     * @return
+     */
+    public static String getAbsAndScaleStr(String req, int length){
+        if(StringUtils.isBlank(req))
+            return null;
+        return new BigDecimal(req).abs().setScale(length, RoundingMode.DOWN).toString();
+    }
+
+    public static String getAbsForArray(String list, int length) {
+        if (StringUtils.isBlank(list)) {
+            return null;
+        }
+        return JSONArray.parseArray(list, BigDecimal.class).stream().map(num -> getAbsAndScale(num, length)).collect(Collectors.toList()).toString();
+    }
+
+
+    public static void main(String[] args) {
+//         System.out.println(getAbsAndScale(null, 3));
+//         System.out.println(getAbsAndScale(new BigDecimal("33.33333"), 3));
+//         System.out.println(getAbsAndScale(new BigDecimal("-33.33333"), 3));
+//         List<Double> list = new ArrayList<>();
+//         list.add(1.1D);
+//         list.add(1.2D);
+//         list.add(1.3D);
+//         System.out.println(list.toString());
+//         System.out.println(JSON.toJSONString(list));
+//
+// //        System.out.println(getAbsForArray("a", 1));
+//
+//         System.out.println(new BigDecimal(1.1).divide(new BigDecimal(1.3), 0, RoundingMode.HALF_UP));
+//         System.out.println(DecimalUtils.getAbsAndScale(new BigDecimal("3486.000000"), INT_2));
+
+        List<Integer> arr = new ArrayList<>();
+        arr.add(1);
+        arr.add(2);
+        OptionalDouble average = arr.stream().mapToInt(Integer::intValue).average();
+        System.out.println(average.getAsDouble());
+    }
+}

+ 69 - 43
src/main/resources/mapper/TShuju1Mapper.xml

@@ -47,49 +47,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select ID, SC_JS_ZLL, SC_JS_COD, SC_JS_ZONGDAN, SC_JS_ANDAN, SC_JS_ZONGLIN, SC_CS_COD, SC_CS_ZONGDAN, SC_CS_ANDAN, SC_CS_ZONGLIN, SC_CS_ZLL, JQR_1_QY_ANDAN, JQR_1_QY_ANDAN_TIME, JQR_1_QY_XIAODAN, JQR_1_QY_XIAODAN_TIME, JQR_1_HY_ANDAN, JQR_1_HY_ANDAN_TIME, JQR_1_HY_XIAODAN, JQR_1_HY_XIAODAN_TIME, JQR_2_QY_ANDAN, JQR_2_QY_ANDAN_TIME, JQR_2_QY_XIAODAN, JQR_2_QY_XIAODAN_TIME, JQR_2_HY_ANDAN, JQR_2_HY_ANDAN_TIME, JQR_2_HY_XIAODAN, JQR_2_HY_XIAODAN_TIME, JQR_SWC_COD, JQR_SWC_COD_TIME, TIME, JQR_1_HY_ZHENGLIN, JQR_1_HY_ZHENGLIN_TIME, JQR_2_HY_ZHENGLIN, JQR_2_HY_ZHENGLIN_TIME, JQR_SWC_ZHENGLIN, JQR_SWC_ZHENGLIN_TIME from T_SHUJU_1
     </sql>
 
-    <select id="selectTShuju1List" parameterType="TShuju1" resultMap="TShuju1Result">
-        <include refid="selectTShuju1Vo"/>
-        <where>
-            1 = 1
-            <if test="scJsZll != null "> and SC_JS_ZLL = #{scJsZll}</if>
-            <if test="scJsCod != null "> and SC_JS_COD = #{scJsCod}</if>
-            <if test="scJsZongdan != null "> and SC_JS_ZONGDAN = #{scJsZongdan}</if>
-            <if test="scJsAndan != null "> and SC_JS_ANDAN = #{scJsAndan}</if>
-            <if test="scJsZonglin != null "> and SC_JS_ZONGLIN = #{scJsZonglin}</if>
-            <if test="scCsCod != null "> and SC_CS_COD = #{scCsCod}</if>
-            <if test="scCsZongdan != null "> and SC_CS_ZONGDAN = #{scCsZongdan}</if>
-            <if test="scCsAndan != null "> and SC_CS_ANDAN = #{scCsAndan}</if>
-            <if test="scCsZonglin != null "> and SC_CS_ZONGLIN = #{scCsZonglin}</if>
-            <if test="scCsZll != null "> and SC_CS_ZLL = #{scCsZll}</if>
-            <if test="jqr1QyAndan != null "> and JQR_1_QY_ANDAN = #{jqr1QyAndan}</if>
-            <if test="jqr1QyAndanTime != null  and jqr1QyAndanTime != ''"> and JQR_1_QY_ANDAN_TIME = #{jqr1QyAndanTime}</if>
-            <if test="jqr1QyXiaodan != null "> and JQR_1_QY_XIAODAN = #{jqr1QyXiaodan}</if>
-            <if test="jqr1QyXiaodanTime != null  and jqr1QyXiaodanTime != ''"> and JQR_1_QY_XIAODAN_TIME = #{jqr1QyXiaodanTime}</if>
-            <if test="jqr1HyAndan != null "> and JQR_1_HY_ANDAN = #{jqr1HyAndan}</if>
-            <if test="jqr1HyAndanTime != null  and jqr1HyAndanTime != ''"> and JQR_1_HY_ANDAN_TIME = #{jqr1HyAndanTime}</if>
-            <if test="jqr1HyXiaodan != null "> and JQR_1_HY_XIAODAN = #{jqr1HyXiaodan}</if>
-            <if test="jqr1HyXiaodanTime != null  and jqr1HyXiaodanTime != ''"> and JQR_1_HY_XIAODAN_TIME = #{jqr1HyXiaodanTime}</if>
-            <if test="jqr2QyAndan != null "> and JQR_2_QY_ANDAN = #{jqr2QyAndan}</if>
-            <if test="jqr2QyAndanTime != null  and jqr2QyAndanTime != ''"> and JQR_2_QY_ANDAN_TIME = #{jqr2QyAndanTime}</if>
-            <if test="jqr2QyXiaodan != null "> and JQR_2_QY_XIAODAN = #{jqr2QyXiaodan}</if>
-            <if test="jqr2QyXiaodanTime != null  and jqr2QyXiaodanTime != ''"> and JQR_2_QY_XIAODAN_TIME = #{jqr2QyXiaodanTime}</if>
-            <if test="jqr2HyAndan != null "> and JQR_2_HY_ANDAN = #{jqr2HyAndan}</if>
-            <if test="jqr2HyAndanTime != null  and jqr2HyAndanTime != ''"> and JQR_2_HY_ANDAN_TIME = #{jqr2HyAndanTime}</if>
-            <if test="jqr2HyXiaodan != null "> and JQR_2_HY_XIAODAN = #{jqr2HyXiaodan}</if>
-            <if test="jqr2HyXiaodanTime != null  and jqr2HyXiaodanTime != ''"> and JQR_2_HY_XIAODAN_TIME = #{jqr2HyXiaodanTime}</if>
-            <if test="jqrSwcCod != null "> and JQR_SWC_COD = #{jqrSwcCod}</if>
-            <if test="jqrSwcCodTime != null  and jqrSwcCodTime != ''"> and JQR_SWC_COD_TIME = #{jqrSwcCodTime}</if>
-            <if test="TIME != null  and TIME != ''"> and TIME = #{TIME}</if>
-            <if test="jqr1HyZhenglin != null "> and JQR_1_HY_ZHENGLIN = #{jqr1HyZhenglin}</if>
-            <if test="jqr1HyZhenglinTime != null  and jqr1HyZhenglinTime != ''"> and JQR_1_HY_ZHENGLIN_TIME = #{jqr1HyZhenglinTime}</if>
-            <if test="jqr2HyZhenglin != null "> and JQR_2_HY_ZHENGLIN = #{jqr2HyZhenglin}</if>
-            <if test="jqr2HyZhenglinTime != null  and jqr2HyZhenglinTime != ''"> and JQR_2_HY_ZHENGLIN_TIME = #{jqr2HyZhenglinTime}</if>
-            <if test="jqrSwcZhenglin != null "> and JQR_SWC_ZHENGLIN = #{jqrSwcZhenglin}</if>
-            <if test="jqrSwcZhenglinTime != null  and jqrSwcZhenglinTime != ''"> and JQR_SWC_ZHENGLIN_TIME = #{jqrSwcZhenglinTime}</if>
-        </where>
-        and del_flag = 0 order by id desc
-    </select>
-    
     <select id="selectTShuju1ByID" parameterType="Long" resultMap="TShuju1Result">
         <include refid="selectTShuju1Vo"/>
         where ID = #{ID} and del_flag = 0
@@ -230,4 +187,73 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{ID}
         </foreach>
     </delete>
+
+
+    <!-- 下面是新增的 -->
+    <select id="getNewestData" resultType="com.xlht.xlhtproject.domain.SmartAdd">
+        SELECT TOP
+            1 SC_JS_ZLL jslYB,
+                SC_JS_COD jsCodYB,
+               SC_JS_ZONGDAN jsTnYB,
+               JQR_SWC_COD jsCodHY,
+               JQR_1_HY_XIAODAN hyXsyHYOne,
+               '' hyXsyYCOne,
+               JQR_1_QY_XIAODAN qyXsyHYOne,
+               JQR_1_QY_ANDAN qyAdHYOne,
+               JQR_2_HY_XIAODAN hyXsyHYTwo,
+               '' hyXsyYCTwo,
+               JQR_2_QY_XIAODAN qyXsyHYTwo,
+               JQR_2_QY_ANDAN qyAdHYTwo
+        FROM
+            T_SHUJU_1
+        ORDER BY
+            ID DESC
+    </select>
+
+
+    <select id="selectTShuju1List" parameterType="TShuju1" resultMap="TShuju1Result">
+        <include refid="selectTShuju1Vo"/>
+        <where>
+            1 = 1
+            <if test="scJsZll != null "> and SC_JS_ZLL = #{scJsZll}</if>
+            <if test="scJsCod != null "> and SC_JS_COD = #{scJsCod}</if>
+            <if test="scJsZongdan != null "> and SC_JS_ZONGDAN = #{scJsZongdan}</if>
+            <if test="scJsAndan != null "> and SC_JS_ANDAN = #{scJsAndan}</if>
+            <if test="scJsZonglin != null "> and SC_JS_ZONGLIN = #{scJsZonglin}</if>
+            <if test="scCsCod != null "> and SC_CS_COD = #{scCsCod}</if>
+            <if test="scCsZongdan != null "> and SC_CS_ZONGDAN = #{scCsZongdan}</if>
+            <if test="scCsAndan != null "> and SC_CS_ANDAN = #{scCsAndan}</if>
+            <if test="scCsZonglin != null "> and SC_CS_ZONGLIN = #{scCsZonglin}</if>
+            <if test="scCsZll != null "> and SC_CS_ZLL = #{scCsZll}</if>
+            <if test="jqr1QyAndan != null "> and JQR_1_QY_ANDAN = #{jqr1QyAndan}</if>
+            <if test="jqr1QyAndanTime != null  and jqr1QyAndanTime != ''"> and JQR_1_QY_ANDAN_TIME = #{jqr1QyAndanTime}</if>
+            <if test="jqr1QyXiaodan != null "> and JQR_1_QY_XIAODAN = #{jqr1QyXiaodan}</if>
+            <if test="jqr1QyXiaodanTime != null  and jqr1QyXiaodanTime != ''"> and JQR_1_QY_XIAODAN_TIME = #{jqr1QyXiaodanTime}</if>
+            <if test="jqr1HyAndan != null "> and JQR_1_HY_ANDAN = #{jqr1HyAndan}</if>
+            <if test="jqr1HyAndanTime != null  and jqr1HyAndanTime != ''"> and JQR_1_HY_ANDAN_TIME = #{jqr1HyAndanTime}</if>
+            <if test="jqr1HyXiaodan != null "> and JQR_1_HY_XIAODAN = #{jqr1HyXiaodan}</if>
+            <if test="jqr1HyXiaodanTime != null  and jqr1HyXiaodanTime != ''"> and JQR_1_HY_XIAODAN_TIME = #{jqr1HyXiaodanTime}</if>
+            <if test="jqr2QyAndan != null "> and JQR_2_QY_ANDAN = #{jqr2QyAndan}</if>
+            <if test="jqr2QyAndanTime != null  and jqr2QyAndanTime != ''"> and JQR_2_QY_ANDAN_TIME = #{jqr2QyAndanTime}</if>
+            <if test="jqr2QyXiaodan != null "> and JQR_2_QY_XIAODAN = #{jqr2QyXiaodan}</if>
+            <if test="jqr2QyXiaodanTime != null  and jqr2QyXiaodanTime != ''"> and JQR_2_QY_XIAODAN_TIME = #{jqr2QyXiaodanTime}</if>
+            <if test="jqr2HyAndan != null "> and JQR_2_HY_ANDAN = #{jqr2HyAndan}</if>
+            <if test="jqr2HyAndanTime != null  and jqr2HyAndanTime != ''"> and JQR_2_HY_ANDAN_TIME = #{jqr2HyAndanTime}</if>
+            <if test="jqr2HyXiaodan != null "> and JQR_2_HY_XIAODAN = #{jqr2HyXiaodan}</if>
+            <if test="jqr2HyXiaodanTime != null  and jqr2HyXiaodanTime != ''"> and JQR_2_HY_XIAODAN_TIME = #{jqr2HyXiaodanTime}</if>
+            <if test="jqrSwcCod != null "> and JQR_SWC_COD = #{jqrSwcCod}</if>
+            <if test="jqrSwcCodTime != null  and jqrSwcCodTime != ''"> and JQR_SWC_COD_TIME = #{jqrSwcCodTime}</if>
+            <if test="TIME != null  and TIME != ''"> and TIME = #{TIME}</if>
+            <if test="jqr1HyZhenglin != null "> and JQR_1_HY_ZHENGLIN = #{jqr1HyZhenglin}</if>
+            <if test="jqr1HyZhenglinTime != null  and jqr1HyZhenglinTime != ''"> and JQR_1_HY_ZHENGLIN_TIME = #{jqr1HyZhenglinTime}</if>
+            <if test="jqr2HyZhenglin != null "> and JQR_2_HY_ZHENGLIN = #{jqr2HyZhenglin}</if>
+            <if test="jqr2HyZhenglinTime != null  and jqr2HyZhenglinTime != ''"> and JQR_2_HY_ZHENGLIN_TIME = #{jqr2HyZhenglinTime}</if>
+            <if test="jqrSwcZhenglin != null "> and JQR_SWC_ZHENGLIN = #{jqrSwcZhenglin}</if>
+            <if test="jqrSwcZhenglinTime != null  and jqrSwcZhenglinTime != ''"> and JQR_SWC_ZHENGLIN_TIME = #{jqrSwcZhenglinTime}</if>
+            <!-- 下面是新增的SQL检索条件  SqlServer写法-->
+            <if test="timeBegin != null  and timeBegin != ''"> and SUBSTRING (CONVERT ( VARCHAR, create_time, 120 ), 1, 10 ) &gt;= #{timeBegin}</if>
+            <if test="timeEnd != null  and timeEnd != ''"> and SUBSTRING (CONVERT ( VARCHAR, create_time, 120 ), 1, 10 ) &lt;= #{timeEnd}</if>
+        </where>
+        and del_flag = 0 order by id desc
+    </select>
 </mapper>