Переглянути джерело

Merge branch 'dailyReport'

zhangcl 3 днів тому
батько
коміт
ede5aff16e

+ 49 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotrydailyreport/IotRyDailyReportMapper.java

@@ -204,6 +204,31 @@ public interface IotRyDailyReportMapper extends BaseMapperX<IotRyDailyReportDO>
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
     }
 
+    /**
+     * 查询指定部门、工单生成日期 前一天所在月份的最早的记录天 井深
+     * @param deptId
+     * @param reportDate
+     * @return
+     */
+    default BigDecimal monthStartFootage(Long deptId, LocalDateTime reportDate) {
+        if (reportDate == null) {
+            return BigDecimal.ZERO;
+        }
+        // 获取 reportDate 的前一天日期 查询前一天所在月份的井深
+        LocalDateTime previousDay = reportDate.minusDays(1);
+        int year = previousDay.getYear();
+        int month = previousDay.getMonthValue();
+
+        IotRyDailyReportDO report = selectOne(new LambdaQueryWrapperX<IotRyDailyReportDO>()
+                .eqIfPresent(IotRyDailyReportDO::getDeptId, deptId)
+                .apply("YEAR(construction_start_date) = {0}", year)
+                .apply("MONTH(construction_start_date) = {0}", month)
+                .orderByAsc(IotRyDailyReportDO::getCreateTime)
+                .last("limit 1"));
+
+        return ObjUtil.isEmpty(report) ? BigDecimal.ZERO : report.getCurrentDepth();
+    }
+
     /**
      * 查询每个施工队伍的 历史 年进尺
      * @param deptId 部门ID
@@ -229,6 +254,30 @@ public interface IotRyDailyReportMapper extends BaseMapperX<IotRyDailyReportDO>
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
     }
 
+    /**
+     * 查询指定部门、工单生成日期 前一天所在年份的最早记录天 井深
+     * @param deptId
+     * @param reportDate
+     * @return
+     */
+    default BigDecimal yearStartFootage(Long deptId, LocalDateTime reportDate) {
+        if (reportDate == null) {
+            return BigDecimal.ZERO;
+        }
+        // 获取 reportDate 的前一天日期 查询前一天所在年份每一条记录天的井深
+        LocalDateTime previousDay = reportDate.minusDays(1);
+        int year = previousDay.getYear();
+        int month = previousDay.getMonthValue();
+
+        IotRyDailyReportDO report = selectOne(new LambdaQueryWrapperX<IotRyDailyReportDO>()
+                .eqIfPresent(IotRyDailyReportDO::getDeptId, deptId)
+                .apply("YEAR(construction_start_date) = {0}", year)
+                .orderByAsc(IotRyDailyReportDO::getCreateTime)
+                .last("limit 1"));
+
+        return ObjUtil.isEmpty(report) ? BigDecimal.ZERO : report.getCurrentDepth();
+    }
+
     /**
      * 按部门统计任务数量
      * @return 部门任务统计列表

+ 16 - 11
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrydailyreport/IotRyDailyReportServiceImpl.java

@@ -104,11 +104,11 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
             // 计算月进尺 年累计进尺 reportDate对应的前一天的 年-月份 对应的日报记录日进尺的累加值
             // 查询指定部门、指定时间段 填写的日报记录的 ’月进尺数据‘(逻辑细则:reportDate 所在的月份与数据表的字段 construction_start_date
             // 所在的月份相匹配 且 create_time < reportDate 的记录的 ’daily_footage‘ 字段值累加计算得出
-            BigDecimal historyMonthlyFootage = iotRyDailyReportMapper.monthlyFootages(createReqVO.getDeptId(), reportDate);
+            BigDecimal monthStartFootage = iotRyDailyReportMapper.monthStartFootage(createReqVO.getDeptId(), reportDate);
 
             // 查询指定部门、指定时间段 填写的日报记录的 ’年进尺数据‘(逻辑细则:reportDate 所在的年份与数据表的字段 construction_start_date
             // 所在的年份相匹配 且 create_time < reportDate 的记录的 ’daily_footage‘ 字段值累加计算得出
-            BigDecimal historyAnnualFootage = iotRyDailyReportMapper.annualFootages(createReqVO.getDeptId(), reportDate);
+            BigDecimal yearStartFootage = iotRyDailyReportMapper.yearStartFootage(createReqVO.getDeptId(), reportDate);
 
             // 当前井深 计算 日进尺 月进尺 年累计进尺
             // (当前井深 - 前一天日报中填写的 ‘当前井深’)= 日进尺
@@ -119,16 +119,21 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
                 // 当前井深-前一天日报的当前井深 = 日进尺
                 BigDecimal dailyFootage = createReqVO.getCurrentDepth().subtract(lastReport.getCurrentDepth());
                 iotRyDailyReport.setDailyFootage(dailyFootage);
-                // 日进尺+历史的当前月进尺 = 总的月进尺
-                iotRyDailyReport.setMonthlyFootage(dailyFootage.add(historyMonthlyFootage));
-                // 日进尺+历史的当前年进尺 = 总的年进尺
-                iotRyDailyReport.setAnnualFootage(dailyFootage.add(historyAnnualFootage));
+                // 月进尺 = 当前井深 - 当前月份的最早记录天的井深
+                BigDecimal monthlyFootage = (monthStartFootage.compareTo(BigDecimal.ZERO) == 0)
+                        ? BigDecimal.ZERO : createReqVO.getCurrentDepth().subtract(monthStartFootage);
+                iotRyDailyReport.setMonthlyFootage(monthlyFootage);
+                // 年累计进尺 = 当前井深 - 当前年最早记录的井深
+                BigDecimal annualFootage = (yearStartFootage.compareTo(BigDecimal.ZERO) == 0)
+                        ? BigDecimal.ZERO : createReqVO.getCurrentDepth().subtract(yearStartFootage);
+                iotRyDailyReport.setAnnualFootage(annualFootage);
             } else {
-                // 如果没有查询到数据 则当前井深 就是日进尺
-                iotRyDailyReport.setDailyFootage(createReqVO.getCurrentDepth());
-                iotRyDailyReport.setMonthlyFootage(createReqVO.getCurrentDepth().add(historyMonthlyFootage));
-                // 日进尺+历史的当前年进尺 = 总的年进尺
-                iotRyDailyReport.setAnnualFootage(createReqVO.getCurrentDepth().add(historyAnnualFootage));
+                // 如果没有查询到数据 则设置 日进尺 为0 后期可修复数据
+                iotRyDailyReport.setDailyFootage(BigDecimal.ZERO);
+                // 月进尺 = 当前井深 - 当前月份的最早记录天的井深
+                iotRyDailyReport.setMonthlyFootage(BigDecimal.ZERO);
+                // 年累计进尺 = 当前井深 - 当前年最早记录的井深
+                iotRyDailyReport.setAnnualFootage(BigDecimal.ZERO);
             }
         }