|
|
@@ -37,6 +37,7 @@ import cn.iocoder.yudao.module.pms.dal.mysql.iotrddailyreportdetail.IotRdDailyRe
|
|
|
import cn.iocoder.yudao.module.pms.enums.AttachmentCategoryEnum;
|
|
|
import cn.iocoder.yudao.module.pms.enums.AttachmentTypeEnum;
|
|
|
import cn.iocoder.yudao.module.pms.message.PmsMessage;
|
|
|
+import cn.iocoder.yudao.module.pms.util.LocalTimeUtils;
|
|
|
import cn.iocoder.yudao.module.supplier.enums.common.SupplierAuditStatusEnum;
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
@@ -61,8 +62,10 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.time.Duration;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
@@ -3225,4 +3228,62 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void repairHistoryProdStatus() {
|
|
|
+ // 修复历史生产动态数据 生产动态拆分明细后 需要把 productionStatus 值赋值到 明细表 rq_iot_rd_daily_report_detail
|
|
|
+ // 查询所有 日报数据 筛选出 production_status 有值的记录
|
|
|
+ IotRdDailyReportPageReqVO reqVO = new IotRdDailyReportPageReqVO();
|
|
|
+ List<IotRdDailyReportDO> reports = iotRdDailyReportMapper.dailyReports(reqVO);
|
|
|
+ List<IotRdDailyReportDetailDO> reportDetails = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(reports)) {
|
|
|
+ reports.forEach(report -> {
|
|
|
+ if (StrUtil.isNotBlank(report.getProductionStatus())) {
|
|
|
+ IotRdDailyReportDetailDO reportDetail = new IotRdDailyReportDetailDO();
|
|
|
+ reportDetail.setDeptId(report.getDeptId());
|
|
|
+ reportDetail.setReportId(report.getId());
|
|
|
+ reportDetail.setReportDate(report.getCreateTime());
|
|
|
+ reportDetail.setStartTime(report.getStartTime());
|
|
|
+ reportDetail.setEndTime(report.getEndTime());
|
|
|
+ // 计算2个时间之前间隔的小时数
|
|
|
+ reportDetail.setDuration(LocalTimeUtils.calculateDurationHours(report.getStartTime(), report.getEndTime()));
|
|
|
+ reportDetail.setConstructionDetail(report.getProductionStatus());
|
|
|
+ reportDetails.add(reportDetail);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (CollUtil.isNotEmpty(reportDetails)) {
|
|
|
+ iotRdDailyReportDetailMapper.insertBatch(reportDetails);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算两个LocalTime之间的间隔小时数(处理空值、跨天情况)
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 间隔小时数(保留2位小数),空值返回0
|
|
|
+ */
|
|
|
+ private BigDecimal calculateDurationHours(LocalTime startTime, LocalTime endTime) {
|
|
|
+ // 处理空值情况:任意一个时间为空,返回0
|
|
|
+ if (startTime == null || endTime == null) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算时间间隔(秒)
|
|
|
+ long seconds;
|
|
|
+ if (endTime.isAfter(startTime)) {
|
|
|
+ // 正常情况:结束时间在开始时间之后
|
|
|
+ seconds = Duration.between(startTime, endTime).getSeconds();
|
|
|
+ } else {
|
|
|
+ // 跨天情况:结束时间在开始时间之前(如23:00到01:00)
|
|
|
+ // 先计算到当天结束的秒数,再加次日开始到结束时间的秒数
|
|
|
+ seconds = Duration.between(startTime, LocalTime.MAX).getSeconds() + 1; // 23:59:59到startTime的秒数+1秒=当天剩余秒数
|
|
|
+ seconds += Duration.between(LocalTime.MIN, endTime).getSeconds(); // 次日00:00到endTime的秒数
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为小时数(秒数 / 3600),保留2位小数
|
|
|
+ BigDecimal hours = BigDecimal.valueOf(seconds).divide(BigDecimal.valueOf(3600), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ return hours;
|
|
|
+ }
|
|
|
+
|
|
|
}
|