Selaa lähdekoodia

分页列表接口计算优化

王苗苗 6 kuukautta sitten
vanhempi
commit
d7087073ba

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/business/domain/ZAssayResult.java

@@ -134,11 +134,11 @@ public class ZAssayResult
 
     /** 化验温度 */
     @Excel(name = "化验温度")
-    private Long resultWendu;
+    private Double resultWendu;
 
     /** 化验湿度 */
     @Excel(name = "化验湿度")
-    private Long resultShidu;
+    private Double resultShidu;
 
     /** 原始浓度值 */
     @Excel(name = "原始浓度值")

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/business/mapper/ZAssayMapper.java

@@ -2,6 +2,7 @@ package com.ruoyi.business.mapper;
 
 import java.util.List;
 import com.ruoyi.business.domain.ZAssay;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 化验项目信息Mapper接口
@@ -58,4 +59,9 @@ public interface ZAssayMapper
      * @return 结果
      */
     public int deleteZAssayByAssayIds(Long[] assayIds);
+
+    ZAssay selectUniqueRecordByAssayNo(String assayNo);
+
+    int getDistinctCountsByDeviceNoAndDate(@Param("assayDate") String assayDate, @Param("deviceNo") String deviceNo);
+
 }

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/business/req/DeviceReq.java

@@ -14,7 +14,7 @@ public class DeviceReq {
 
     private String assayStatus;//化验状态(0:在线;1:离线;2:化验中)
 
-    private String assayTime;//化验日期
+    private String assayDate;//化验日期
 
     private String worksId;//水厂ID
 

+ 3 - 3
ruoyi-system/src/main/java/com/ruoyi/business/res/DeviceRes.java

@@ -40,15 +40,15 @@ public class DeviceRes {
 
     private double assayProgress;//化验进度  计算
 
-    private double currentTemperature;//当前温度
+    private Double currentTemperature;//当前温度
 
-    private double currentHumidity;//当前湿度
+    private Double currentHumidity;//当前湿度
 
     private int assayCounts;//检验轮次 聚合
 
     private int assayTotals;//检验总次数  聚合
 
-    private double passCheckRates;//合格率(质控样) 计算
+    private double passAssayRates;//合格率(质控样) 计算
 
     private double wasteLiquidAmounts;//废液产生总量  todo 待提供数据
 

+ 3 - 3
ruoyi-system/src/main/java/com/ruoyi/business/res/HomeCountsRes.java

@@ -16,7 +16,7 @@ public class HomeCountsRes {
     private long onDeviceCounts;//今日化验中设备(台)
     private long standbyDeviceCounts;//今日待机设备(台)
     private long offDeviceCounts;//今日离线设备(台)
-    private int checkTotals;//今日质控样检测总数
-    private int passCheckTotals;//今日质控样合格总数
-    private double passCheckRates;//今日质控样合格率
+    private int assayTotals;//今日质控样检测总数
+    private int passAssayTotals;//今日质控样合格总数
+    private double passAssayRates;//今日质控样合格率
 }

+ 48 - 8
ruoyi-system/src/main/java/com/ruoyi/business/service/impl/BusinessServiceImpl.java

@@ -6,7 +6,6 @@ import com.ruoyi.business.req.DeviceReq;
 import com.ruoyi.business.res.DeviceRes;
 import com.ruoyi.business.res.HomeCountsRes;
 import com.ruoyi.business.service.IBusinessService;
-import com.ruoyi.common.enums.DataSourceType;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -60,22 +59,29 @@ public class BusinessServiceImpl implements IBusinessService {
         List<ZAssayResult> zAssayResults = this.zAssayResultMapper.selectZAssayResultList(ZAssayResult.builder().resultDate("2024-08-13").assayType("3").build());
         if(!CollectionUtils.isEmpty(zAssayResults)){
             int checkTotals = zAssayResults.size();
-            build.setCheckTotals(checkTotals);
+            build.setAssayTotals(checkTotals);
             int passCheckTotals = this.getPassedCounts(zAssayResults);
-            build.setPassCheckTotals(passCheckTotals);
-            build.setPassCheckRates((double)passCheckTotals / (double)checkTotals);//整数除以整数还是整数,所以这里要强转成小数
+            build.setPassAssayTotals(passCheckTotals);
+            build.setPassAssayRates((double)passCheckTotals / (double)checkTotals);//整数除以整数还是整数,所以这里要强转成小数
         }
         return build;
     }
 
     @Override
     public List<DeviceRes> devicePageList(DeviceReq deviceReq) {
+        //处理一下化验日期,如果没有,默认是今天
+        String assayDate = deviceReq.getAssayDate();
+        if(StringUtils.isBlank(assayDate)){
+            //todo 日期临时写死,因为数据不会同步,都是历史数据  正式以后,需要改成真实日期
+//            assayTime = DateUtils.getDate();
+            assayDate = "2024-08-13";
+        }
         //先获取设备列表 直接写SQL了,不使用copy
         List<DeviceRes> list =this.bizDeviceMapper.devicePageList(deviceReq);
         //额外处理其他数据
         if(!CollectionUtils.isEmpty(list)){
             for (DeviceRes deviceRes : list) {
-                this.addExtra(deviceRes);
+                this.addExtra(deviceRes, assayDate, deviceRes.getDeviceNo());
             }
         }
         return list;
@@ -83,11 +89,45 @@ public class BusinessServiceImpl implements IBusinessService {
 
     /**
      * 额外处理其他的字段 聚合,查询其他表,计算等
+     *
      * @param deviceRes
+     * @param assayDate
+     * @param deviceNo
      */
-    private void addExtra(DeviceRes deviceRes) {
-        //查询最近的一条化验记录明细
-
+    private void addExtra(DeviceRes deviceRes, String assayDate, String deviceNo) {
+        //查询最近的一条化验记录明细 及 化验统计(结果)
+        List<ZAssayResult> zAssayResults = this.zAssayResultMapper.selectZAssayResultList(ZAssayResult.builder().resultDate(assayDate).assayType("3").deviceNo(deviceNo).build());
+        if(!CollectionUtils.isEmpty(zAssayResults)){
+            int checkTotals = zAssayResults.size();
+            int passCheckTotals = this.getPassedCounts(zAssayResults);
+            deviceRes.setAssayTotals(passCheckTotals);
+            deviceRes.setPassAssayRates((double)passCheckTotals / (double)checkTotals);//整数除以整数还是整数,所以这里要强转成小数
+
+            //获取最新的一条化验明细数据
+            ZAssayResult zAssayResult = zAssayResults.get(0);
+            deviceRes.setLastAssayTime(zAssayResult.getUpdateTime());
+            deviceRes.setBeginAssayTime(zAssayResult.getCreateTime());
+            deviceRes.setCurrentTemperature(zAssayResult.getResultWendu());
+            deviceRes.setCurrentHumidity(zAssayResult.getResultShidu());
+
+            //获取最新的一条化验记录 处理化验进度的展示: 因为历史数据有总步进为0的,这种的默认进度就是0处理  只有化验中的才显示进度
+            String assayNo = zAssayResult.getAssayNo();
+            if("2".equals(deviceRes.getAssayStatus()) && StringUtils.isNotBlank(assayNo)){
+                ZAssay zAssay = this.zAssayMapper.selectUniqueRecordByAssayNo(assayNo);
+                if(!Objects.isNull(zAssay)){
+                    String stepNow = zAssay.getStepNow();
+                    String stepTotal = zAssay.getStepTotal();
+                    if(StringUtils.isBlank(stepNow) || StringUtils.isBlank(stepTotal) || "0".equals(stepNow) || "0".equals(stepTotal)){
+                        deviceRes.setAssayProgress(0);
+                    }else{
+                        deviceRes.setAssayProgress(Double.parseDouble(stepNow)/Double.parseDouble(stepTotal));
+                    }
+                }
+            }
+            //todo 废液量暂时无法计算
+        }
+        //因为有重复数据,需要去重
+        deviceRes.setAssayCounts(this.zAssayMapper.getDistinctCountsByDeviceNoAndDate(assayDate, deviceNo));
     }
 
     //判断每个质控样的数是否各个,然后获取汇总的数量

+ 2 - 0
ruoyi-system/src/main/resources/mapper/business/BizDeviceMapper.xml

@@ -197,6 +197,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             bd.device_id deviceId,
             bd.device_name deviceName,
             bd.device_no deviceNo,
+            bd.assay_status assayStatus,
             bzw.works_name worksName
         FROM
             biz_device bd
@@ -205,5 +206,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE bd.device_status = '0' AND bzw.del_flag = 0
         <if test="assayStatus != null  and assayStatus != ''"> and bd.assay_status = #{assayStatus}</if>
         <if test="worksId != null  and worksId != ''"> and bzw.works_id = #{worksId}</if>
+        order by bd.device_id desc
     </select>
 </mapper>

+ 9 - 0
ruoyi-system/src/main/resources/mapper/business/ZAssayMapper.xml

@@ -160,4 +160,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{assayId}
         </foreach>
     </delete>
+
+    <!-- 2024年09月27日14:14:02 下面是新增的SQL,不允许覆盖 -->
+    <select id="selectUniqueRecordByAssayNo" resultType="com.ruoyi.business.domain.ZAssay">
+        select  top 1 * from z_assay where assay_no = #{assayNo} order by assay_id desc
+    </select>
+
+    <select id="getDistinctCountsByDeviceNoAndDate" resultType="int">
+        SELECT COUNT(DISTINCT assay_no) FROM z_assay WHERE assay_date = #{assayDate} AND device_no = #{deviceNo}
+    </select>
 </mapper>