|
@@ -1,18 +1,28 @@
|
|
|
package cn.iocoder.yudao.module.pms.service.iotrydailyreport;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotprojecttask.vo.IotProjectTaskPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojecttask.IotProjectTaskDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotrydailyreport.IotRyDailyReportDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotprojecttask.IotProjectTaskMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotrydailyreport.IotRyDailyReportMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
-import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_RY_DAILY_REPORT_NOT_EXISTS;
|
|
|
+import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -26,12 +36,80 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
|
|
|
|
|
|
@Resource
|
|
|
private IotRyDailyReportMapper iotRyDailyReportMapper;
|
|
|
+ @Resource
|
|
|
+ private IotProjectTaskMapper iotProjectTaskMapper;
|
|
|
|
|
|
@Override
|
|
|
public Long createIotRyDailyReport(IotRyDailyReportSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
|
IotRyDailyReportDO iotRyDailyReport = BeanUtils.toBean(createReqVO, IotRyDailyReportDO.class);
|
|
|
- iotRyDailyReportMapper.insert(iotRyDailyReport);
|
|
|
+ LocalDateTime reportDate = createReqVO.getFillOrderCreateTime();
|
|
|
+ if (ObjUtil.isEmpty(reportDate)) {
|
|
|
+ throw exception(IOT_RH_DAILY_REPORT_NO_DATE);
|
|
|
+ }
|
|
|
+ if (ObjUtil.isEmpty(createReqVO.getDeptId())) {
|
|
|
+ throw exception(IOT_RH_DAILY_REPORT_NO_DEPT);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据日报的 施工队伍 deptId 查询队伍所在的 项目 任务
|
|
|
+ // 根据日报的施工状态 更新 对应任务的 状态
|
|
|
+ Long taskId = Long.MIN_VALUE;
|
|
|
+ Set<Long> deviceIds = new HashSet<>();
|
|
|
+ IotProjectTaskPageReqVO reqVO = new IotProjectTaskPageReqVO();
|
|
|
+ reqVO.setDeptId(createReqVO.getDeptId());
|
|
|
+ // 查询包含当前日报施工队伍的任务
|
|
|
+ List<IotProjectTaskDO> tasks = iotProjectTaskMapper.selectList(reqVO);
|
|
|
+ if (CollUtil.isNotEmpty(tasks)) {
|
|
|
+ IotProjectTaskDO task = tasks.get(0);
|
|
|
+ // 暂时只考虑1个施工队伍只属于1个任务
|
|
|
+ iotRyDailyReport.setProjectId(task.getProjectId());
|
|
|
+ iotRyDailyReport.setTaskId(task.getId());
|
|
|
+ taskId = task.getId();
|
|
|
+ // 根据日报状态 查询 日报所属任务的状态 瑞鹰任务状态数据字典 rigStatus
|
|
|
+ if (ObjUtil.isNotEmpty(createReqVO.getRigStatus())) {
|
|
|
+ task.setStatus(createReqVO.getRigStatus());
|
|
|
+ // 更新任务状态
|
|
|
+ iotProjectTaskMapper.updateById(task);
|
|
|
+ }
|
|
|
+ // 查询任务的设备列表
|
|
|
+ deviceIds = task.getDeviceIds();
|
|
|
+ } else {
|
|
|
+ // 当前队伍没有关联任务 不生成日报
|
|
|
+ throw exception(IOT_PROJECT_TASK_NOT_RELATED);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当前井深 计算 日进尺 月进尺 年累计进尺
|
|
|
+ // (当前井深 - 前一天日报中填写的 ‘当前井深’)= 日进尺
|
|
|
+ // 将 reportDate 减去1天 得到日期 date(yyyy-MM-dd) 查询date对应的日报记录
|
|
|
+ IotRyDailyReportDO lastReport = iotRyDailyReportMapper.selectLatestReportBeforeDate(
|
|
|
+ createReqVO.getDeptId(), taskId, reportDate);
|
|
|
+ if (ObjUtil.isNotEmpty(lastReport) && ObjUtil.isNotEmpty(lastReport.getCurrentDepth())) {
|
|
|
+ // 当前井深 - 前一天日报的当前井深 = 日进尺
|
|
|
+ BigDecimal dailyFootage = createReqVO.getCurrentDepth().subtract(lastReport.getCurrentDepth());
|
|
|
+ iotRyDailyReport.setDailyFootage(dailyFootage);
|
|
|
+ } else {
|
|
|
+ // 如果没有查询到数据 则当前井深 就是日进尺
|
|
|
+ iotRyDailyReport.setDailyFootage(createReqVO.getCurrentDepth());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当天如果已经有此小队的记录 新增 当天如果没有此小队的日报记录 修改
|
|
|
+ // deptId - taskId - createTime(yyyy-MM-dd) 确定唯一一条记录 不能使用 LocalDateTime.now() 来查询,应该使用 运行记录工单的创建日期查询
|
|
|
+ IotRyDailyReportDO existReport = iotRyDailyReportMapper.selectExistReport(createReqVO.getDeptId(), taskId, reportDate);
|
|
|
+ if (ObjUtil.isEmpty(existReport)) {
|
|
|
+ // reportDate 所代表日期前1天的7点
|
|
|
+ LocalDateTime today7am = reportDate.withHour(7).withMinute(0).withSecond(0).withNano(0);
|
|
|
+ // reportDate 所代表日期的7点
|
|
|
+ LocalDateTime yesterday7am = today7am.minusDays(1);
|
|
|
+ iotRyDailyReport.setConstructionStartDate(yesterday7am);
|
|
|
+ iotRyDailyReport.setConstructionEndDate(today7am);
|
|
|
+ iotRyDailyReport.setCreateTime(reportDate);
|
|
|
+ iotRyDailyReport.setUpdateTime(reportDate);
|
|
|
+ iotRyDailyReportMapper.insert(iotRyDailyReport);
|
|
|
+ } else {
|
|
|
+ // 修改现有记录
|
|
|
+ iotRyDailyReport.setId(existReport.getId());
|
|
|
+ iotRyDailyReportMapper.updateById(iotRyDailyReport);
|
|
|
+ }
|
|
|
// 返回
|
|
|
return iotRyDailyReport.getId();
|
|
|
}
|