chenyuehu 4 years ago
parent
commit
7f3d8025db

+ 8 - 1
platform-dao/src/main/java/com/platform/dao/dto/repair/RepairApplicationFormDTO.java

@@ -235,5 +235,12 @@ public class RepairApplicationFormDTO extends BaseDTO implements Serializable {
      */
     private String mainRepairId;
 
-    private String outType;
+    /**
+     * 委外类别
+     */
+    private Integer outType;
+    /**
+     * 类型
+     */
+    private Integer type;
 }

+ 5 - 1
platform-dao/src/main/java/com/platform/dao/entity/repair/RepairApplicationForm.java

@@ -180,7 +180,11 @@ public class RepairApplicationForm implements Serializable {
     /**
      * 委外类别
      */
-    private String outType;
+    private Integer outType;
+    /**
+     * 类型
+     */
+    private Integer type;
     /**
      * 报修人
      */

+ 24 - 0
platform-dao/src/main/java/com/platform/dao/enums/RepairApplicationFormTypeEnum.java

@@ -0,0 +1,24 @@
+package com.platform.dao.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @Description 维修类别枚举
+ * @Author liuyu
+ * @Date 2020/05/05
+ * @Version Copyright (c) 2020,安徽阡陌网络科技有限公司 All rights reserved.
+ */
+@Getter
+@AllArgsConstructor
+public enum RepairApplicationFormTypeEnum {
+    /**
+     * 内部
+     */
+    IN(1),
+    /**
+     * 委外
+     */
+    OUT(2);
+    private final Integer value;
+}

+ 5 - 1
platform-dao/src/main/java/com/platform/dao/vo/repair/RepairApplicationFormVO.java

@@ -241,5 +241,9 @@ public class RepairApplicationFormVO extends BaseVO implements Serializable {
     /**
      * 委外类别
      */
-    private String outType;
+    private Integer outType;
+    /**
+     * 类型
+     */
+    private Integer type;
 }

+ 59 - 33
platform-service/src/main/java/com/platform/service/repair/impl/RepairApplicationFormServiceImpl.java

@@ -171,36 +171,51 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
     @Override
     @Transactional(rollbackFor = Exception.class)
     public RepairApplicationForm saveModelByDTO(RepairApplicationFormDTO model) {
+        Integer type = model.getType();
+        if (type == null) {
+            type = 1;
+            model.setType(type);
+        }
         Weekend<RepairApplicationForm> weekend = new Weekend<>(RepairApplicationForm.class);
-        weekend.weekendCriteria().andIsNotNull(RepairApplicationForm::getId);
+        weekend.weekendCriteria().andIsNotNull(RepairApplicationForm::getId).andEqualTo(RepairApplicationForm::getType, model.getType());
         int count = mapper.selectCountByExample(weekend);
         UserInfo userInfo = SecurityUtils.getUserInfo();
         model.setUserId(userInfo.getUserId());
         //model.setCheckUserId(userInfo.getUserId());
         // 查询对应的维修人,保存维修单
-        SbInfoVO sb = sbInfoService.getById(model.getSbId());
-
-        // 保存报修单
-        model.setModelId(sb.getModelId());
-        model.setNo(IdGeneratorUtils.getRepairApplicaitonFormNo(++count));
-        model.setStatus(RepairApplicationFormStatusEnum.NOT_ALLOCATED.getValue());
+        String sbId = model.getSbId();
+        if (StringUtils.isNotEmpty(sbId)) {
+            SbInfoVO sb = sbInfoService.getById(sbId);
+            // 保存报修单
+            model.setModelId(sb.getModelId());
+            if (sb.getStatus().intValue() == SbInfoStatusEnum.IN_MAINTAIN.getValue()) {
+                throw new BusinessException("设备已经在维修中,请等待维修完成, sbId" + model.getSbId());
+            }
+            // 如果选择了设备停机,则要修改设备状态
+            if (model.getNeedStop().intValue() == RepairApplicationFormStopEnum.STOP.getValue()) {
+                SbInfo info = new SbInfo();
+                info.setId(sb.getId());
+                info.setStatus(SbInfoStatusEnum.IN_MAINTAIN.getValue());
+                sbInfoService.modModelByPrimaryKey(info);
+            }
+            if (sb.getUseGroup() == null) {
+                throw new BusinessException("找不到设备对应的使用工作组,无法指派维修单,请先设置设备的归属组,sbId" + model.getSbId());
+            }
+        }
+        model.setNo(type == 1 ? IdGeneratorUtils.getRepairApplicaitonFormNo(++count) : model.getNo());
+        String repairUserId = model.getRepairUserId();
+        model.setStatus(StringUtils.isNotEmpty(repairUserId) ? RepairApplicationFormStatusEnum.ALLOCATED.getValue() : RepairApplicationFormStatusEnum.NOT_ALLOCATED.getValue());
         model.setApplyTime(LocalDateTime.now());
         model.setCreatedTime(model.getApplyTime());
         model.setUpdateTime(model.getApplyTime());
-        if (sb.getStatus().intValue() == SbInfoStatusEnum.IN_MAINTAIN.getValue()) {
-            throw new BusinessException("设备已经在维修中,请等待维修完成, sbId" + model.getSbId());
-        }
 
-        // 如果选择了设备停机,则要修改设备状态
-        if (model.getNeedStop().intValue() == RepairApplicationFormStopEnum.STOP.getValue()) {
-            SbInfo info = new SbInfo();
-            info.setId(sb.getId());
-            info.setStatus(SbInfoStatusEnum.IN_MAINTAIN.getValue());
-            sbInfoService.modModelByPrimaryKey(info);
-        }
-        if (sb.getUseGroup() == null) {
-            throw new BusinessException("找不到设备对应的使用工作组,无法指派维修单,请先设置设备的归属组,sbId" + model.getSbId());
+        // 关联维修单
+        String mainRepairId = model.getMainRepairId();
+        if (StringUtils.isNotEmpty(mainRepairId)) {
+            //TODO
         }
+
+
 //        List<SysUserVO> userList = sysUserService.selectDeptManager(sb.getUseGroup(), SysDeptManagerType.REPAIR.getValue());
 //        if (userList == null || userList.size() == 0) {
 //            throw new BusinessException("找不到设备对应的维修员,无法指派维修单,请先设置设备的归属组,sbId" + model.getSbId());
@@ -211,22 +226,33 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
         model.setId(IdGeneratorUtils.getObjectId());
         this.saveFile(model);
         RepairApplicationForm form = super.saveModelHaveCreateInfo(model);
-
-        List<SysUser> users = sysUserService.getRepairUser(new SysUserDTO());
-        List<SysUser> filterUsers = users.stream().filter(item -> item.getWorkFlag()).collect(Collectors.toList());
-        if (CollectionUtil.isEmpty(filterUsers)) {
-            filterUsers = users.stream().filter(item -> item.getIdentityType().equals(SysUserIdentityType.WXZG.getValue())).collect(Collectors.toList());
-        }
         List<String> userIds = new ArrayList<>();
         List<String> mails = new ArrayList<>();
-        filterUsers.forEach(item -> {
-            userIds.add(item.getUserId());
-            mails.add(item.getEmail());
-        });
-        // 通过给当天值班维修人员
-        SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_APPLICATION.getValue(),
-                model.getId(), MessageTemplateUtil.getRepairApplicationForReceive(model.getNo()),
-                model.getId(), userIds, mails));
+        if (StringUtils.isEmpty(repairUserId)) {
+            List<SysUser> users = sysUserService.getRepairUser(new SysUserDTO());
+            List<SysUser> filterUsers = users.stream().filter(item -> item.getWorkFlag()).collect(Collectors.toList());
+            if (CollectionUtil.isEmpty(filterUsers)) {
+                filterUsers = users.stream().filter(item -> item.getIdentityType().equals(SysUserIdentityType.WXZG.getValue())).collect(Collectors.toList());
+            }
+            filterUsers.forEach(item -> {
+                userIds.add(item.getUserId());
+                mails.add(item.getEmail());
+            });
+            // 通过给当天值班维修人员
+            SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_APPLICATION.getValue(),
+                    model.getId(), MessageTemplateUtil.getRepairApplicationForReceive(model.getNo()),
+                    model.getId(), userIds, mails));
+        } else {
+            SysUserVO user = sysUserService.selectUserVO(repairUserId);
+            userIds.add(repairUserId);
+            mails.add(user.getEmail());
+            // 通过给当天值班维修人员
+            SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_APPLICATION.getValue(),
+                    model.getId(), MessageTemplateUtil.getRepairDispatch(model.getNo()),
+                    model.getId(), userIds, mails));
+        }
+
+
         return form;
     }