3254194295 пре 3 година
родитељ
комит
02724817c5

+ 3 - 0
platform-dao/src/main/java/com/platform/dao/entity/check/CheckStandard.java

@@ -7,6 +7,7 @@ import lombok.Data;
 import javax.persistence.Id;
 import javax.persistence.Table;
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.List;
@@ -31,6 +32,8 @@ public class CheckStandard implements Serializable{
      */
         @Id
     private String id;
+
+        private BigDecimal isGet;
     /**
      * 设备id
      */

+ 3 - 0
platform-dao/src/main/java/com/platform/dao/vo/query/check/CheckStandardVO.java

@@ -12,6 +12,7 @@ import lombok.experimental.Accessors;
 
 import javax.persistence.Transient;
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.List;
@@ -26,6 +27,8 @@ import java.util.List;
 @Accessors(chain = true)
 @EqualsAndHashCode(callSuper = true)
 public class CheckStandardVO extends BaseVO implements Serializable{
+
+    private BigDecimal isGet;
     /**
      * 排序
      */

+ 4 - 1
platform-dao/src/main/resources/mapper/check/CheckStandardMapper.xml

@@ -207,7 +207,10 @@ checkstandard.last_date,
                      last_date = #{item.lastDate},
                 </if>
                 <if test="item.nextDate != null">
-                     next_date = #{item.nextDate}
+                     next_date = #{item.nextDate},
+                </if>
+                <if test="item.isGet != null">
+                    is_get = #{item.isGet}
                 </if>
             </set>
             where id = #{item.id}

+ 16 - 0
platform-rest/src/main/java/com/platform/rest/controller/check/CheckStandardController.java

@@ -6,6 +6,8 @@ import com.platform.dao.dto.check.CheckJobDTO;
 import com.platform.dao.dto.check.CheckStandardDTO;
 import com.platform.dao.entity.check.CheckStandard;
 import com.platform.dao.vo.query.check.CheckStandardVO;
+import com.platform.rest.task.CheckJobTask;
+import com.platform.service.check.CheckJobService;
 import com.platform.service.check.CheckStandardService;
 import com.platform.dao.util.ExcelUtil;
 import com.platform.dao.vo.export.check.ExportCheckStandardVO;
@@ -38,6 +40,7 @@ import javax.servlet.http.HttpServletResponse;
 public class CheckStandardController {
 
   private final  CheckStandardService checkStandardService;
+  private CheckJobService checkJobService;
 
   /**
    * 通过id查询单条记录
@@ -61,6 +64,12 @@ public class CheckStandardController {
         return new R<>(checkStandardService.getModelById(id));
     }
 
+    @PostMapping("/add/{id}")
+    public R<Integer> add(@PathVariable("id") String id){
+        checkJobService.genTaskById(id);
+        return new R<>();
+    }
+
   /**
    * 新增记录
    *
@@ -74,6 +83,13 @@ public class CheckStandardController {
       return new R<>(checkStandardService.saveModelByDTO(checkStandardDTO));
   }
 
+//    @SysLog("生成保养任务")
+//    @PostMapping
+//    @PreAuthorize("@pms.hasPermission('check-spot-standards-add') or @pms.hasPermission('check-spot-standards-add')")
+//    public R getBYTask(CheckStandardDTO checkStandardDTO) {
+//        return new R<>(checkStandardService.saveModelByDTO(checkStandardDTO));
+//    }
+
   /**
    * 修改记录
    *

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

@@ -81,6 +81,8 @@ public interface CheckJobService extends IBaseService<CheckJob, CheckJobDTO> {
      */
     void genTaskBySbId(int checkType);
 
+    void genTaskById(String id);
+
     /**
      * 检查任务状态
      */

+ 92 - 0
platform-service/src/main/java/com/platform/service/check/impl/CheckJobServiceImpl.java

@@ -9,6 +9,7 @@ import com.platform.common.bean.AbstractPageResultBean;
 import com.platform.common.cache.ConfigCache;
 import com.platform.common.enums.DataFilterTypeEnum;
 import com.platform.common.exception.BusinessException;
+import com.platform.common.exception.DeniedException;
 import com.platform.common.model.OauthUser;
 import com.platform.common.model.UserInfo;
 import com.platform.common.util.*;
@@ -81,6 +82,8 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
     private SbInfoService sbInfoService;
     private SysConfigService sysConfigService;
     private final SysFileMapper sysFileMapper;
+    private CheckStandardMapper checkStandardMapper;
+    private CheckJobMapper checkJobMapper;
 
     @Override
     public int batchDelete(List<String> ids) {
@@ -430,6 +433,13 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
         generateJobBySbId(currentDate);
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void genTaskById(String id) {
+        LocalDateTime currentDate = LocalDateTime.now();
+        generateJobById(id,currentDate);
+    }
+
     /**
      * 查询每个标准是否有已经存在未执行的任务,如果有则不生成,否则直接生成。
      *
@@ -503,6 +513,7 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
                     if(standard.getLastDate() == null){
                         standard.setLastDate(currentDate.toLocalDate());
                     }
+                    standard.setIsGet(new BigDecimal(1));
                     updateStandardList.add(standard);
                     jobList.add(checkJob);
                 }
@@ -517,6 +528,87 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
         }
     }
 
+    private void generateJobById(String id,LocalDateTime currentDate) {
+        List<CheckStandard> updateStandardList=new ArrayList<>();
+        List<CheckJob> jobList = new ArrayList<>();
+        CheckStandard query=new CheckStandard();
+        query.setId(id);
+        CheckStandard standard = checkStandardMapper.selectByPrimaryKey(query);
+        // 查询每个标准是否有已经存在未执行的任务,如果有则不生成,否则直接生成。初次执行的时候,没有未执行的任务
+//        Weekend<CheckJob> weekend = new Weekend<>(CheckJob.class);
+//        weekend.weekendCriteria().andNotEqualTo(CheckJob::getStatus, CheckJobStatusEnum.FINISHED.getValue());
+//        List<CheckJob> checkJobs = mapper.selectByExample(weekend);
+
+
+        if(!CheckPlanPeriodTypeEnum.MILES.getValue().equals(standard.getPeriodType()) && !CheckPlanPeriodTypeEnum.TAISHI.getValue().equals(standard.getPeriodType()) ){
+            boolean find = false;
+//            for(CheckJob unDoJob :checkJobs){
+//                if(standard.getId().equals(unDoJob.getStandardId()) && standard.getSbId().equals(unDoJob.getSbId())){
+//                    find = true;
+//                }
+//            }
+
+                CheckJob checkJob = new CheckJob();
+                checkJob.setSbId(standard.getSbId());
+
+                // 有可能设备已经删除了,继续执行其他的
+                if(StringUtils.isBlank(standard.getSbId())){
+                    throw new DeniedException("设备已经被删除了,无法生成保养任务!");
+                }
+                SbInfo sbInfo = sbInfoService.getModelById(standard.getSbId());
+                if(sbInfo == null){
+                    throw new DeniedException("没有找到该设备,无法生成保养任务!");
+                }
+                if(!sbInfo.getStatus().equals(SbInfoStatusEnum.IN_USE.getValue())){
+                    throw new DeniedException("设备不在使用中,无法生成保养任务!");
+                }
+                if(standard.getCheckUserType() == null){
+                    if(standard.getPeriodType()< CheckPlanPeriodTypeEnum.WEEK.getValue()){
+                        checkJob.setCheckUserId(sbInfo.getSaveUser());
+                        standard.setCheckUserType(CheckUserTypeEnum.USE_USER.getValue());
+                    }else{
+                        checkJob.setCheckUserId(sbInfo.getRepairUser());
+                        standard.setCheckUserType(CheckUserTypeEnum.REPAIR_USER.getValue());
+                    }
+                }else{
+                    if(standard.getCheckUserType().equals(CheckUserTypeEnum.USE_USER.getValue())){
+                        checkJob.setCheckUserId(sbInfo.getSaveUser());
+                    }else if(standard.getCheckUserType().equals(CheckUserTypeEnum.REPAIR_USER.getValue())){
+                        checkJob.setCheckUserId(sbInfo.getRepairUser());
+                    }else if(standard.getCheckUserType().equals(CheckUserTypeEnum.ZHIDING.getValue())){
+                        checkJob.setCheckUserId(sbInfo.getRepairUser());
+                    }
+                }
+                checkJob.setStandardHours(standard.getStandardHours());
+                checkJob.setStatus(CheckJobStatusEnum.NOT_EXECUTE.getValue());
+                // 计算计划开始时间和结束时间
+                calcTime(checkJob, currentDate, standard);
+                checkJob.setCreatedTime(LocalDateTime.now());
+                checkJob.setId(IdGeneratorUtils.getObjectId());
+                checkJob.setPartId(standard.getPart());
+                checkJob.setStandardId(standard.getId());
+                checkJob.setType(standard.getType());
+                checkJob.setReceiveOvertime(false);
+                checkJob.setRequirement(standard.getRequirement());
+                checkJob.setRemark(standard.getRemark());
+                checkJob.setName(standard.getName());
+                if(standard.getLastDate() == null){
+                    standard.setLastDate(currentDate.toLocalDate());
+                }
+                standard.setIsGet(new BigDecimal(1));
+                updateStandardList.add(standard);
+                jobList.add(checkJob);
+
+        }
+        if (!CollectionUtils.isEmpty(jobList)) {
+            mapper.insertListforComplex(jobList);
+        }
+
+        if (!CollectionUtils.isEmpty(updateStandardList)) {
+            standardMapper.updateBatch(updateStandardList);
+        }
+    }
+
     /**
      * 判断某个计划,某个设备,某个标准,是否要生成任务
      *