ly 1 месяц назад
Родитель
Сommit
b606fa696f

+ 192 - 135
master/src/main/java/com/ruoyi/project/sems/controller/TMeasureCuiHomeController.java

@@ -11,6 +11,7 @@ import com.ruoyi.project.officeConvert.OfficeConvertController;
 import com.ruoyi.project.sems.domain.TMeasureThickness;
 import com.ruoyi.project.sems.domain.TSpecdevYlgd;
 import com.ruoyi.project.sems.mapper.TMeasureStressMapper;
+import com.ruoyi.project.sems.mapper.TMeasureThicknessMapper;
 import com.ruoyi.project.sems.service.ITMeasureLoopService;
 import com.ruoyi.project.sems.service.ITMeasureRecordService;
 import com.ruoyi.project.sems.service.ITMeasureStressService;
@@ -44,6 +45,8 @@ public class TMeasureCuiHomeController extends BaseController {
     private ITMeasureStressService tMeasureStressService;
     @Autowired
     private ITMeasureLoopService tMeasureLoopService;
+    @Resource
+    private TMeasureThicknessMapper tMeasureThicknessMapper;
 
 
     /**
@@ -63,45 +66,62 @@ public class TMeasureCuiHomeController extends BaseController {
         if (plantIds.size() == 0) {
             plantIds.add("1");
         }
-       int sbAll = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code",plantIds)
-                .eq("dev_type" , "设备")
-                .eq("del_flag" , 0)
-        );
-        int gdAll = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code",plantIds)
-                .and(wrapper -> wrapper
-                        .ne("dev_type", "设备")    // 排除 dev_type = '设备'
-                        .or()                     // 或
-                        .isNull("dev_type")       // 包含 dev_type 为 null 的记录
-                )
-                .eq("del_flag" , 0)
-        );
-
-        int sbWarn = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code",plantIds)
-                .eq("dev_type" , "设备")
-                .eq("del_flag" , 0)
-                .isNotNull("NEXT_WARN_DATE") // 添加非空条件
-                .and(wrapper -> wrapper
-                        .le("NEXT_WARN_DATE", sqlDate)
-                )
-
-        );
-
-        int gdWarn = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code",plantIds)
-                .and(wrapper -> wrapper
-                        .ne("dev_type", "设备")    // 排除 dev_type = '设备'
-                        .or()                     // 或
-                        .isNull("dev_type")       // 包含 dev_type 为 null 的记录
-                )
-                .eq("del_flag" , 0)
-                .isNotNull("NEXT_WARN_DATE") // 添加非空条件
-                .and(wrapper -> wrapper
-                        .le("NEXT_WARN_DATE", sqlDate)
-                )
-        );
+
+        String plants = String.join(",", plantIds);
+
+        TMeasureThickness paramT = new TMeasureThickness();
+        paramT.setPlants(plants);
+        paramT.setIsPipe("0");
+        List<TMeasureThickness> sbAllList = tMeasureThicknessMapper.selectTMeasureThicknessList(paramT);
+        sbAllList = this.distinctByPlantAndTag(sbAllList);
+        int sbAll = sbAllList.size();
+
+        paramT.setPlants(plants);
+        paramT.setIsPipe("1");
+        List<TMeasureThickness> gdAllList = tMeasureThicknessMapper.selectTMeasureThicknessList(paramT);
+        gdAllList = this.distinctByPlantAndTag(gdAllList);
+        int gdAll = gdAllList.size();
+
+        paramT.setPlants(plants);
+        paramT.setIsPipe("0");
+        List<TMeasureThickness> sbWarnList = tMeasureThicknessMapper.selectTMeasureThicknessList(paramT);
+        sbWarnList = this.distinctByPlantAndTagAndDate(sbWarnList);
+        int sbWarn = sbWarnList.size();
+
+//        int sbWarn = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
+//                .in("plant_code",plantIds)
+//                .eq("dev_type" , "设备")
+//                .eq("del_flag" , 0)
+//                .isNotNull("NEXT_WARN_DATE") // 添加非空条件
+//                .and(wrapper -> wrapper
+//                        .le("NEXT_WARN_DATE", sqlDate)
+//                )
+//                .groupBy("plant_code", "TAGNO") // 按指定字段分组(实现去重)
+//                .select("1") // 优化性能,仅查询常量
+//
+//        );
+
+        paramT.setPlants(plants);
+        paramT.setIsPipe("1");
+        List<TMeasureThickness> gdWarnList = tMeasureThicknessMapper.selectTMeasureThicknessList(paramT);
+        gdWarnList = this.distinctByPlantAndTagAndDate(gdWarnList);
+        int gdWarn = gdWarnList.size();
+
+//        int gdWarn = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
+//                .in("plant_code",plantIds)
+//                .and(wrapper -> wrapper
+//                        .ne("dev_type", "设备")    // 排除 dev_type = '设备'
+//                        .or()                     // 或
+//                        .isNull("dev_type")       // 包含 dev_type 为 null 的记录
+//                )
+//                .eq("del_flag" , 0)
+//                .isNotNull("NEXT_WARN_DATE") // 添加非空条件
+//                .and(wrapper -> wrapper
+//                        .le("NEXT_WARN_DATE", sqlDate)
+//                )
+//                .groupBy("plant_code", "TAGNO") // 按指定字段分组(实现去重)
+//                .select("1") // 优化性能,仅查询常量
+//        );
         //
         Map<String, Object> res = new HashMap<String, Object>();
         res.put("sbAll" ,sbAll) ;
@@ -111,6 +131,71 @@ public class TMeasureCuiHomeController extends BaseController {
         return AjaxResult.success(res);
     }
 
+    public List<TMeasureThickness> distinctByPlantAndTag(List<TMeasureThickness> thicknesses) {
+        Map<String, TMeasureThickness> resultMap = new LinkedHashMap<>();
+        for (TMeasureThickness t : thicknesses) {
+            // 跳过空值
+            if (t.getPlantCode() == null || t.getTagno() == null) continue;
+
+            // 构建复合键
+            String key = t.getPlantCode() + "|" + t.getTagno();
+            // 仅当键不存在时添加
+            resultMap.putIfAbsent(key, t);
+        }
+        return new ArrayList<>(resultMap.values());
+    }
+
+    public List<TMeasureThickness> distinctByPlantAndTagAndDate(List<TMeasureThickness> thicknesses) {
+        // 计算一个月后的日期
+        LocalDate oneMonthLater = LocalDate.now().plusMonths(1);
+        Date sqlDate = java.sql.Date.valueOf(oneMonthLater);
+        // 转换为 SQL Date 类型
+
+        // 使用LinkedHashMap保持插入顺序
+        Map<String, TMeasureThickness> resultMap = new LinkedHashMap<>();
+
+        for (TMeasureThickness t : thicknesses) {
+            // 跳过关键字段为空的记录
+            if (t.getPlantCode() == null || t.getTagno() == null) continue;
+
+            // 核心新增:过滤NEXT_WARN_DATE ≥ 一个月后的记录
+            if (t.getNextWarnDate() != null && !t.getNextWarnDate().before(sqlDate)) {
+                continue;
+            }
+
+            // 构建复合键: plantCode + tagNo
+            String key = t.getPlantCode() + "|" + t.getTagno();
+
+            // 仅当键不存在时添加(保留第一个符合条件的记录)
+            resultMap.putIfAbsent(key, t);
+        }
+
+        return new ArrayList<>(resultMap.values());
+    }
+
+    public List<TMeasureThickness> distinctByPlantAndTag(List<TMeasureThickness> thicknesses, int min, int max) {
+        Map<String, TMeasureThickness> resultMap = new LinkedHashMap<>();
+        for (TMeasureThickness t : thicknesses) {
+            // 跳过空值
+            if (t.getPlantCode() == null || t.getTagno() == null || t.getEstRemain() == null) continue;
+
+            try {
+                double estRemain = Double.parseDouble(t.getEstRemain().trim());
+                if (estRemain < min || estRemain > max) continue;
+
+                // 构建复合键
+                String key = t.getPlantCode() + "|" + t.getTagno();
+                resultMap.putIfAbsent(key, t);
+            } catch (NumberFormatException e) {
+                // 如果转换失败,跳过该条记录
+                continue;
+            }
+        }
+        return new ArrayList<>(resultMap.values());
+    }
+
+
+
     /**
      * 管道预估寿命数据
      */
@@ -123,6 +208,8 @@ public class TMeasureCuiHomeController extends BaseController {
         if (plantIds.size() == 0) {
             plantIds.add("1");
         }
+        String plants = String.join(",", plantIds);
+
         // 1. 获取当前年份
         int currentYear = Year.now().getValue();
 
@@ -137,18 +224,24 @@ public class TMeasureCuiHomeController extends BaseController {
         List<Integer> resData = new ArrayList<>();
         // 4. 遍历每个年份并查询数据
         for (int year : targetYears) {
-            TMeasureThickness t = new TMeasureThickness();
-            int estRemainMin =year - currentYear;
-            int gd = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                    .in("plant_code", plantIds)
-                    .and(wrapper -> wrapper
-                            .ne("dev_type", "设备")    // 排除 dev_type = '设备'
-                            .or()                     // 或
-                            .isNull("dev_type")       // 包含 dev_type 为 null 的记录
-                    )
-                    .eq("del_flag", 0)
-                    .between("EST_REMAIN", estRemainMin, estRemainMin + 1)
-            );
+            int estRemainMin = year - currentYear;
+            TMeasureThickness paramT = new TMeasureThickness();
+            paramT.setPlants(plants);
+            paramT.setIsPipe("1");
+            List<TMeasureThickness> allList = tMeasureThicknessMapper.selectTMeasureThicknessList(paramT);
+            allList = this.distinctByPlantAndTag(allList,estRemainMin,estRemainMin + 1);
+            int gd = allList.size();
+
+//            int gd = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
+//                    .in("plant_code", plantIds)
+//                    .and(wrapper -> wrapper
+//                            .ne("dev_type", "设备")    // 排除 dev_type = '设备'
+//                            .or()                     // 或
+//                            .isNull("dev_type")       // 包含 dev_type 为 null 的记录
+//                    )
+//                    .eq("del_flag", 0)
+//                    .between("EST_REMAIN", estRemainMin, estRemainMin + 1)
+//            );
             resData.add(gd);
         }
 
@@ -170,6 +263,7 @@ public class TMeasureCuiHomeController extends BaseController {
         if (plantIds.size() == 0) {
             plantIds.add("1");
         }
+        String plants = String.join(",", plantIds);
         // 1. 获取当前年份
         int currentYear = Year.now().getValue();
 
@@ -186,12 +280,18 @@ public class TMeasureCuiHomeController extends BaseController {
         for (int year : targetYears) {
             TMeasureThickness t = new TMeasureThickness();
             int estRemainMin =year - currentYear;
-            int gd = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                    .in("plant_code", plantIds)
-                    .eq("dev_type" , "设备")
-                    .eq("del_flag", 0)
-                    .between("EST_REMAIN", estRemainMin, estRemainMin + 1)
-            );
+            TMeasureThickness paramT = new TMeasureThickness();
+            paramT.setPlants(plants);
+            paramT.setIsPipe("0");
+            List<TMeasureThickness> allList = tMeasureThicknessMapper.selectTMeasureThicknessList(paramT);
+            allList = this.distinctByPlantAndTag(allList,estRemainMin,estRemainMin + 1);
+            int gd = allList.size();
+//            int gd = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
+//                    .in("plant_code", plantIds)
+//                    .eq("dev_type" , "设备")
+//                    .eq("del_flag", 0)
+//                    .between("EST_REMAIN", estRemainMin, estRemainMin + 1)
+//            );
             resData.add(gd);
         }
 
@@ -213,58 +313,29 @@ public class TMeasureCuiHomeController extends BaseController {
         if (plantIds.size() == 0) {
             plantIds.add("1");
         }
+        String plants = String.join(",", plantIds);
 
 
         // 3. 存储查询结果(年份 -> 过期数据)
         List<Integer> resData = new ArrayList<>();
         // 4. 遍历每个年份并查询数据
-            int gd = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                    .in("plant_code", plantIds)
-                    .and(wrapper -> wrapper
-                            .ne("dev_type", "设备")    // 排除 dev_type = '设备'
-                            .or()                     // 或
-                            .isNull("dev_type")       // 包含 dev_type 为 null 的记录
-                    )
-                    .eq("del_flag", 0)
-                    .between("EST_REMAIN", 0, 3)
-            );
-            resData.add(gd);
+        TMeasureThickness paramT = new TMeasureThickness();
+        paramT.setPlants(plants);
+        paramT.setIsPipe("1");
+        List<TMeasureThickness> allList = tMeasureThicknessMapper.selectTMeasureThicknessList(paramT);
+        allList = this.distinctByPlantAndTag(allList,0,3);
+
+
+        resData.add(this.distinctByPlantAndTag(allList,0,3).size());
+
+
+        resData.add(this.distinctByPlantAndTag(allList,3,6).size());
+
 
-        int gd2 = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code", plantIds)
-                .and(wrapper -> wrapper
-                        .ne("dev_type", "设备")    // 排除 dev_type = '设备'
-                        .or()                     // 或
-                        .isNull("dev_type")       // 包含 dev_type 为 null 的记录
-                )
-                .eq("del_flag", 0)
-                .between("EST_REMAIN", 3, 6)
-        );
-        resData.add(gd2);
-
-        int gd3 = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code", plantIds)
-                .and(wrapper -> wrapper
-                        .ne("dev_type", "设备")    // 排除 dev_type = '设备'
-                        .or()                     // 或
-                        .isNull("dev_type")       // 包含 dev_type 为 null 的记录
-                )
-                .eq("del_flag", 0)
-                .between("EST_REMAIN", 6, 10)
-        );
-        resData.add(gd3);
-
-        int gd4 = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code", plantIds)
-                .and(wrapper -> wrapper
-                        .ne("dev_type", "设备")    // 排除 dev_type = '设备'
-                        .or()                     // 或
-                        .isNull("dev_type")       // 包含 dev_type 为 null 的记录
-                )
-                .eq("del_flag", 0)
-                .between("EST_REMAIN", 10, 999)
-        );
-        resData.add(gd4);
+        resData.add(this.distinctByPlantAndTag(allList,6,10).size());
+
+
+        resData.add(this.distinctByPlantAndTag(allList,10,999).size());
 
         Map<String, Object> res = new HashMap<String, Object>();
         res.put("resData" ,resData) ;
@@ -283,45 +354,31 @@ public class TMeasureCuiHomeController extends BaseController {
         if (plantIds.size() == 0) {
             plantIds.add("1");
         }
+        String plants = String.join(",", plantIds);
 
 
         // 3. 存储查询结果(年份 -> 过期数据)
         List<Integer> resData = new ArrayList<>();
         // 4. 遍历每个年份并查询数据
-        int gd = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code", plantIds)
-                .eq("dev_type" , "设备")
-                .eq("del_flag", 0)
-                .between("EST_REMAIN", 0, 3)
-        );
-        resData.add(gd);
-
-        int gd2 = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code", plantIds)
-                .eq("dev_type" , "设备")
-                .eq("del_flag", 0)
-                .between("EST_REMAIN", 3, 6)
-        );
-        resData.add(gd2);
-
-        int gd3 = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code", plantIds)
-                .eq("dev_type" , "设备")
-                .eq("del_flag", 0)
-                .between("EST_REMAIN", 6, 10)
-        );
-        resData.add(gd3);
-
-        int gd4 = tMeasureThicknessService.count(new QueryWrapper<TMeasureThickness>()
-                .in("plant_code", plantIds)
-                .eq("dev_type" , "设备")
-                .eq("del_flag", 0)
-                .between("EST_REMAIN", 10, 999)
-        );
-        resData.add(gd4);
+        TMeasureThickness paramT = new TMeasureThickness();
+        paramT.setPlants(plants);
+        paramT.setIsPipe("0");
+        List<TMeasureThickness> allList = tMeasureThicknessMapper.selectTMeasureThicknessList(paramT);
+        allList = this.distinctByPlantAndTag(allList,0,3);
+
+
+        resData.add(this.distinctByPlantAndTag(allList,0,3).size());
+
 
+        resData.add(this.distinctByPlantAndTag(allList,3,6).size());
+
+
+        resData.add(this.distinctByPlantAndTag(allList,6,10).size());
+
+
+        resData.add(this.distinctByPlantAndTag(allList,10,999).size());
         Map<String, Object> res = new HashMap<String, Object>();
-        res.put("resData" ,resData) ;
+        res.put("resData" ,resData);
         return AjaxResult.success(res);
     }
 

+ 1 - 1
master/src/main/resources/application.yml

@@ -13,7 +13,7 @@ ruoyi:
   profile: D:/ruoyi/uploadPath
   # 邮件中链接跳转路径 示例(本地:http://localhost/cpms/index.html#,服务器:http://47.114.101.16:8080/cpms/index.html# https://cpms.basf-ypc.net.cn/cpms/index.html#)
   requestJumpPath: https://cpms.basf-ypc.net.cn/cpms/index.html#
-  # 图像识别地址http://1.13.182.229:7089/detection_web
+  # 图像识别地址http://1.13.182.229:7089/detection_web 10.137.43.133:8096/detection_web
   imagePath: http://127.0.0.1:8096/detection_web
   # 获取ip地址开关
   addressEnabled: false

+ 1 - 1
master/src/main/resources/mybatis/sems/TMeasureThicknessMapper.xml

@@ -207,7 +207,7 @@
                 </foreach>
             </if>
             <if test="isPipe == 1 "> and (dev_type is null or dev_type != '设备')</if>
-            <if test="isPipe == 0 "> and dev_type == '设备'</if>
+            <if test="isPipe == 0 "> and dev_type = '设备'</if>
             <if test="year != null and year != ''">
                 AND EST_REMAIN BETWEEN ( #{year} - EXTRACT(YEAR FROM SYSDATE) )
                 AND (  #{year} -EXTRACT(YEAR FROM SYSDATE) + 1)