xiongchao 3 år sedan
förälder
incheckning
ec6c4d8f94

+ 1 - 1
platform-dao/src/main/java/com/platform/dao/entity/check/CheckJob.java

@@ -46,7 +46,7 @@ public class CheckJob implements Serializable {
      */
     private String standardHours;
     /**
-     * 实际工时
+     * 实际工时:分钟
      */
     private String realHours;
     /**

+ 2 - 3
platform-rest/src/main/java/com/platform/rest/controller/mobile/IgnoreController.java

@@ -164,9 +164,8 @@ public class IgnoreController {
      */
     @SysLog("接收点检任务")
     @PutMapping("/check/jobs/execute")
-    @PreAuthorize("@pms.hasPermission('check-polling-jobs-edit')")
     public R executeJob(@Validated({UpdateGroup.class}) @RequestBody CheckJobDTO checkJobDTO) {
-        checkJobService.executeJob(checkJobDTO.getId());
+        checkJobService.executeJobIgnore(checkJobDTO.getId());
         return new R<>();
     }
 
@@ -179,7 +178,7 @@ public class IgnoreController {
     @SysLog("完成点检任务")
     @PutMapping("/check/jobs/finish")
     public R finishJob(@Validated({UpdateGroup.class}) @RequestBody CheckJobDTO checkJobDTO) {
-        checkJobService.finishJob(checkJobDTO);
+        checkJobService.finishJobIgnore(checkJobDTO);
         return new R<>();
     }
 

+ 14 - 0
platform-service/src/main/java/com/platform/service/check/CheckJobService.java

@@ -97,6 +97,20 @@ public interface CheckJobService extends IBaseService<CheckJob, CheckJobDTO> {
      */
     void finishJob(CheckJobDTO dto);
 
+    /**
+     * 执行任务
+     *
+     * @param id
+     */
+    void executeJobIgnore(Object id);
+
+    /**
+     * 完成任务
+     *
+     * @param dto
+     */
+    void finishJobIgnore(CheckJobDTO dto);
+
     void executeJobBatch(List<String> ids);
 
     void finishJobBatch(List<String> ids);

+ 152 - 1
platform-service/src/main/java/com/platform/service/check/impl/CheckJobServiceImpl.java

@@ -76,6 +76,14 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
         return 1;
     }
 
+    /**
+     *
+     *
+     * @param model
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
     @Override
     public AbstractPageResultBean<CheckJobVO> selectPageList(CheckJobDTO model, int pageNum, int pageSize) {
 
@@ -647,6 +655,14 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
         endDate = DateUtils.plus(endDate, -1, ChronoUnit.DAYS);
         checkJob.setEndTime(endDate);
     }
+
+    /**
+     * 计算任务日期
+     *
+     * @param checkJob
+     * @param currentDate
+     * @param checkStandard
+     */
     private void calcTime(CheckJob checkJob, LocalDateTime currentDate, CheckStandard checkStandard) {
         LocalDate startDate = null;
         LocalDate endDate = null;
@@ -734,6 +750,47 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
         checkStandard.setNextDate(startDate);
     }
 
+    /**
+     * 计算任务日期
+     *
+     * @param checkJob:下次任务
+     * @param currentDate:本次完成的日期
+     * @param checkStandard
+     */
+    private void calcNextJobTime(CheckJob checkJob, LocalDateTime currentDate, CheckStandard checkStandard) {
+        LocalDate startDate = null;
+        LocalDate endDate = null;
+
+        // 查询上次任务生成时间
+        CheckJobDTO job = new CheckJobDTO();
+        job.setSbId(checkJob.getSbId());
+        job.setStandardId(checkJob.getStandardId());
+        LocalDateTime localDateTime = currentDate;
+        if (CheckPlanPeriodTypeEnum.DAY.getValue().equals(checkStandard.getPeriodType())) {
+            startDate = DateUtils.plus(localDateTime.toLocalDate(), checkStandard.getPeriod(), ChronoUnit.DAYS);
+            endDate = DateUtils.plus(startDate, checkStandard.getPeriod() + 2, ChronoUnit.DAYS);
+        }
+        if (CheckPlanPeriodTypeEnum.WEEK.getValue().equals(checkStandard.getPeriodType())) {
+            startDate = DateUtils.plus(localDateTime.toLocalDate(), checkStandard.getPeriod() * 7, ChronoUnit.DAYS);
+            endDate = DateUtils.plus(startDate, checkStandard.getPeriod() * 7 + 2, ChronoUnit.DAYS);
+        }
+        if (CheckPlanPeriodTypeEnum.MONTH.getValue().equals(checkStandard.getPeriodType())) {
+            startDate = DateUtils.plus(localDateTime.toLocalDate(), checkStandard.getPeriod(), ChronoUnit.MONTHS);
+            endDate = DateUtils.plus(startDate, 10, ChronoUnit.DAYS);
+        }
+        if (CheckPlanPeriodTypeEnum.SEASON.getValue().equals(checkStandard.getPeriodType())) {
+            startDate = DateUtils.plus(localDateTime.toLocalDate(), checkStandard.getPeriod() * 3, ChronoUnit.MONTHS);
+            endDate = DateUtils.plus(startDate, 20, ChronoUnit.DAYS);
+        }
+        if (CheckPlanPeriodTypeEnum.YEAR.getValue().equals(checkStandard.getPeriodType())) {
+            startDate = DateUtils.plus(localDateTime.toLocalDate(), checkStandard.getPeriod(), ChronoUnit.YEARS);
+            endDate = DateUtils.plus(startDate, 60, ChronoUnit.DAYS);
+        }
+
+        checkJob.setStartTime(startDate);
+        checkJob.setEndTime(endDate);
+    }
+
     public LocalDate getCheckJobEndDate(LocalDate startDate, Integer period, Integer periodType){
         LocalDate endDate = null;
         if (CheckPlanPeriodTypeEnum.DAY.getValue().equals(periodType)) {
@@ -838,6 +895,9 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
         if(checkJob.getActualStartTime() == null){
             checkJob.setActualStartTime(dto.getActualStartTime());
         }
+        if(checkJob.getActualStartTime() == null){
+            throw new BusinessException("为记录保养实际工时,请先接收任务");
+        }
         checkJob.setRealHours(DateUtils.getDurationMinutes(checkJob.getActualStartTime(), checkJob.getActualEndTime()) + "");
         OauthUser oauthUser = SecurityUtils.checkAndGetUser();
         if(oauthUser==null){// 未登录,在获取设备的使用人员
@@ -868,7 +928,95 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
             nextCheckJob.setStandardHours(checkStandard.getStandardHours());
             nextCheckJob.setStatus(CheckJobStatusEnum.NOT_EXECUTE.getValue());
             // 新任务
-            calcTime(nextCheckJob, checkJob.getActualEndTime(), checkStandard);
+            calcNextJobTime(nextCheckJob, checkJob.getActualEndTime(), checkStandard);
+            nextCheckJob.setCreatedTime(LocalDateTime.now());
+            nextCheckJob.setSbId(checkStandard.getSbId());
+            nextCheckJob.setCheckUserId(checkJob.getCheckUserId());
+            nextCheckJob.setPartId(checkStandard.getPart());
+            nextCheckJob.setStandardId(checkStandard.getId());
+            nextCheckJob.setType(checkStandard.getType());
+            nextCheckJob.setRequirement(checkStandard.getRequirement());
+            nextCheckJob.setRemark(checkStandard.getRemark());
+            nextCheckJob.setName(checkStandard.getName());
+            nextCheckJob.setId(IdGeneratorUtils.getObjectId());
+            mapper.insert(nextCheckJob);
+        }
+
+        // 更新标准的上次执行时间和下次预计执行时间
+        checkStandard.setLastDate(now.toLocalDate());
+        checkStandard.setNextDate(nextCheckJob.getStartTime());
+        standardMapper.updateByPrimaryKey(checkStandard);
+    }
+
+    /**
+     * 接收任务:记录接收任务时间,计算完成耗时
+     *
+     * @param id
+     */
+    @Override
+    public void executeJobIgnore(Object id) {
+        CheckJob checkJob = mapper.selectByPrimaryKey(id);
+/*        if(!CheckJobStatusEnum.NOT_EXECUTE.getValue().equals(checkJob.getStatus()) && !CheckJobStatusEnum.OUT_OF_DATE.getValue().equals(checkJob.getStatus())){
+            throw new BusinessException("任务状态无法接收,请重新尝试");
+        }*/
+        checkJob.setStatus(CheckJobStatusEnum.EXECUTING.getValue());
+        checkJob.setActualStartTime(LocalDateTime.now());
+
+        SbInfoVO sbInfoVO = sbInfoService.getById(checkJob.getSbId());
+        if (sbInfoVO == null) {
+            throw new BusinessException("设备不存在,无法完成任务");
+        }
+        checkJob.setUpdateUserId(sbInfoVO.getSaveUser());
+        checkJob.setUpdateUserName(sbInfoVO.getSaveUserName());
+
+        mapper.updateByPrimaryKeySelective(checkJob);
+    }
+
+    /**
+     * 完成任务,每次完成任务,生成下一次任务:不能用于公里和台时的,
+     * 公
+     * 里和台时的任务,需要定时器每天晚上定时来跑
+     *
+     *  如果是移动端的,未登录,不需要获取用户信息,
+     * @param dto
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void finishJobIgnore(CheckJobDTO dto) {
+        LocalDateTime now = LocalDateTime.now();
+        CheckJob checkJob = mapper.selectByPrimaryKey(dto.getId());
+        checkJob.setStatus(CheckJobStatusEnum.FINISHED.getValue());
+        checkJob.setActualEndTime(now);
+        if(checkJob.getActualStartTime() == null){
+            checkJob.setActualStartTime(dto.getActualStartTime());
+        }
+        if(checkJob.getActualStartTime() == null){
+            throw new BusinessException("为记录保养实际工时,请先接收任务");
+        }
+        checkJob.setRealHours(DateUtils.getDurationMinutes(checkJob.getActualStartTime(), checkJob.getActualEndTime()) + "");
+        SbInfoVO sbInfoVO = sbInfoService.getById(checkJob.getSbId());
+        if (sbInfoVO == null) {
+            throw new BusinessException("设备不存在,无法完成任务");
+        }
+        checkJob.setUpdateUserId(sbInfoVO.getSaveUser());
+        checkJob.setUpdateUserName(sbInfoVO.getSaveUserName());
+        checkJob.setUpdateTime(now);
+
+        // checkJob.setSbStatus(dto.getSbStatus());
+        checkJob.setFeedback(dto.getFeedback());
+        mapper.updateByPrimaryKeySelective(checkJob);
+
+        // 提交完成图片信息
+        this.saveFile(dto);
+
+        // 非台时和公里,则需要生成下一次的任务
+        CheckStandard checkStandard = standardMapper.selectByPrimaryKey(checkJob.getStandardId());
+        CheckJob nextCheckJob = new CheckJob();
+        if(!CheckPlanPeriodTypeEnum.MILES.getValue().equals(checkStandard.getPeriodType()) && !CheckPlanPeriodTypeEnum.TAISHI.getValue().equals(checkStandard.getPeriodType()) ){
+            nextCheckJob.setStandardHours(checkStandard.getStandardHours());
+            nextCheckJob.setStatus(CheckJobStatusEnum.NOT_EXECUTE.getValue());
+            // 新任务
+            calcNextJobTime(nextCheckJob, checkJob.getActualEndTime(), checkStandard);
             nextCheckJob.setCreatedTime(LocalDateTime.now());
             nextCheckJob.setSbId(checkStandard.getSbId());
             nextCheckJob.setCheckUserId(checkJob.getCheckUserId());
@@ -949,6 +1097,9 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
                 if (searchType == 1) {
                     weekendCriteria.andLessThan(CheckJob::getStartTime, DateUtils.getTodayEndTime());
                 } else if (searchType == 2) {
+                    // 查询当周的任务数
+                    weekendCriteria.andLessThan(CheckJob::getStartTime, DateUtils.getSundayOfThisWeek());
+                } else if (searchType == 3) {
                     // 查询当月的任务数
                     weekendCriteria.andLessThan(CheckJob::getStartTime, DateUtils.getLastDayOfThisMonth());
                 }