Browse Source

Merge remote-tracking branch 'origin/demo_' into demo_

hfxc226 3 years ago
parent
commit
ab1d2b0a80
26 changed files with 935 additions and 28 deletions
  1. 10 0
      platform-common/src/main/java/com/platform/common/constant/CommonConstants.java
  2. 5 0
      platform-dao/src/main/java/com/platform/dao/entity/part/PartInfo.java
  3. 1 0
      platform-dao/src/main/java/com/platform/dao/enums/SysConfigEnum.java
  4. 7 0
      platform-dao/src/main/java/com/platform/dao/mapper/sb/SbInfoMapper.java
  5. 5 0
      platform-dao/src/main/java/com/platform/dao/vo/sb/SbModelSpareBomVO.java
  6. 42 0
      platform-dao/src/main/java/com/platform/dao/vo/sb/SbTreeVO.java
  7. 5 2
      platform-dao/src/main/resources/application-daoDev.yml
  8. 2 0
      platform-dao/src/main/resources/mapper/part/PartInfoMapper.xml
  9. 13 0
      platform-dao/src/main/resources/mapper/sb/SbInfoMapper.xml
  10. 1 0
      platform-dao/src/main/resources/mapper/sb/SbModelSpareBomMapper.xml
  11. 1 1
      platform-dao/src/main/resources/mapper/store/InStoreFormMapper.xml
  12. 2 2
      platform-dao/src/main/resources/mapper/store/OutStoreFormMapper.xml
  13. 23 19
      platform-rest/src/main/java/com/platform/rest/controller/repair/RepairApplicationFormController.java
  14. 13 0
      platform-rest/src/main/java/com/platform/rest/controller/sb/SbInfoController.java
  15. 1 0
      platform-rest/src/main/resources/application-dev.yml
  16. 1 0
      platform-service/src/main/java/com/platform/service/check/impl/CheckJobServiceImpl.java
  17. 448 0
      platform-service/src/main/java/com/platform/service/repair/strategy/AbstractRepairBaseStrategy.java
  18. 57 0
      platform-service/src/main/java/com/platform/service/repair/strategy/RepairBaseStrategy.java
  19. 26 0
      platform-service/src/main/java/com/platform/service/repair/strategy/RepairStrategyFactory.java
  20. 9 0
      platform-service/src/main/java/com/platform/service/repair/strategy/impl/AllocateRepairBaseStrategy.java
  21. 161 0
      platform-service/src/main/java/com/platform/service/repair/strategy/impl/BaseRepairBaseStrategy.java
  22. 6 4
      platform-service/src/main/java/com/platform/service/sb/SbInfoService.java
  23. 79 0
      platform-service/src/main/java/com/platform/service/sb/impl/SbInfoServiceImpl.java
  24. 4 0
      platform-service/src/main/java/com/platform/service/sqarepartmanage/impl/SparePartUsedServiceImpl.java
  25. 8 0
      platform-service/src/main/java/com/platform/service/upms/SysUserService.java
  26. 5 0
      platform-service/src/main/java/com/platform/service/upms/impl/SysUserServiceImpl.java

+ 10 - 0
platform-common/src/main/java/com/platform/common/constant/CommonConstants.java

@@ -243,4 +243,14 @@ public interface CommonConstants {
      */
     String WORKPLACE_STORE_NORMAL="workplace_store_normal";
 
+    /**
+     * 系统策略模式定义
+     */
+    String REPAIR_STRATEGY_MODEL_BASE = "1"; // 基础模式,自主领取任务,估计没人选
+
+    String REPAIR_STRATEGY_MODEL_DISPATCH = "2"; // 派发模式,路由到具体派发人那里,由派发人进行分配处理
+
+    String REPAIR_STRATEGY_MODEL_DISPATCH_SB_MANAGER = "3"; // 派送给设备管理者进行维修
+
+
 }

+ 5 - 0
platform-dao/src/main/java/com/platform/dao/entity/part/PartInfo.java

@@ -1,6 +1,8 @@
 package com.platform.dao.entity.part;
 
 import com.platform.common.bean.DataScope;
+import com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO;
+import com.platform.dao.vo.sb.SbModelSpareBomVO;
 import lombok.Data;
 
 import javax.persistence.Id;
@@ -9,6 +11,7 @@ import javax.persistence.Transient;
 import java.io.Serializable;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.util.List;
 
 /**
  * @Description 部件信息实体类
@@ -92,4 +95,6 @@ public class PartInfo implements Serializable {
     @Transient
     private DataScope dataScope;
 
+    private List<SbModelSpareBomVO> sparePartInfoVOList;
+
 }

+ 1 - 0
platform-dao/src/main/java/com/platform/dao/enums/SysConfigEnum.java

@@ -44,6 +44,7 @@ public enum SysConfigEnum {
     SPARE_WARN_FORREST_EMAIL("保养库存邮件邮箱"),
     REPAIR_SUPER_USERS("维修管理中的超级用户集合"),
     PURCHASE_FORM_SUPER_USERS("采购入库单的超级用户集合"),
+    REPAIR_STRATEGY_MODEL("维修策略模式选择"),
     STORE_SUPER_USERS("仓库管理中的超级用户集合");
     private final String typeName;
 

+ 7 - 0
platform-dao/src/main/java/com/platform/dao/mapper/sb/SbInfoMapper.java

@@ -5,6 +5,7 @@ import com.platform.dao.dto.sb.SbInfoDTO;
 import com.platform.dao.entity.sb.SbInfo;
 import com.platform.dao.vo.sb.SbInfoScreenDetailVO;
 import com.platform.dao.vo.sb.SbInfoVO;
+import com.platform.dao.vo.sb.SbTreeVO;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Component;
 
@@ -129,4 +130,10 @@ public interface SbInfoMapper extends MyMapper<SbInfo> {
 
     List selectPageInfoForWarn(SbInfoDTO record);
 
+    SbTreeVO getSbTree(SbInfoDTO sbInfoDTO);
+
+    List<SbInfoVO> getSubSb(SbInfoDTO sbInfoDTO);
+
+
+
 }

+ 5 - 0
platform-dao/src/main/java/com/platform/dao/vo/sb/SbModelSpareBomVO.java

@@ -122,4 +122,9 @@ public class SbModelSpareBomVO extends BaseVO implements Serializable {
      */
     private String updateUserName;
 
+    /**
+     * 备件名称
+     */
+    private String spareName;
+
 }

+ 42 - 0
platform-dao/src/main/java/com/platform/dao/vo/sb/SbTreeVO.java

@@ -0,0 +1,42 @@
+package com.platform.dao.vo.sb;
+
+import com.platform.common.bean.BaseVO;
+import com.platform.dao.entity.part.PartInfo;
+import com.platform.dao.entity.upms.SysFile;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+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;
+
+/**
+ * @Description
+ * @Author chenli
+ * @Date 2019/8/5
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Data
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = true)
+public class SbTreeVO extends BaseVO implements Serializable {
+    private String name;
+    private String id;
+    /**
+     * 子设备集合
+     */
+    private List<SbTreeVO> subSbTreeVOList;
+    /**
+     * 设备部位集合
+     */
+    private List<PartInfo> partInfoList;
+    /**
+     * 备件集合
+     */
+    private List<SbModelSpareBomVO> sbModelSpareBomVOList;
+
+}

+ 5 - 2
platform-dao/src/main/resources/application-daoDev.yml

@@ -37,7 +37,10 @@ spring:
         driver-class-name: com.mysql.cj.jdbc.Driver
         url: jdbc:mysql://localhost:3306/hitch-sb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true
         username: root
-        password: 123456
+        password: mysql?MYSQLmoniu123
+        #url: jdbc:mysql://localhost:3306/hitch-sb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true
+        #username: root
+        #password: 123456
         filters: wall,stat
         filter:
           stat:
@@ -140,4 +143,4 @@ logging:
   level:
     com.platform.dao.mapper: DEBUG
     org.activiti: ERROR
-    org.activiti.engine.impl.persistence.entity: DEBUG
+    org.activiti.engine.impl.persistence.entity: DEBUG

+ 2 - 0
platform-dao/src/main/resources/mapper/part/PartInfoMapper.xml

@@ -53,4 +53,6 @@
         from t_part_info
         where id = #{id}
     </select>
+
+
 </mapper>

+ 13 - 0
platform-dao/src/main/resources/mapper/sb/SbInfoMapper.xml

@@ -722,4 +722,17 @@ user.real_name as saveUserName
             #{item}
         </foreach>
     </update>
+
+    <select id="getSbTree" parameterType="com.platform.dao.dto.sb.SbInfoDTO"
+            resultType="com.platform.dao.vo.sb.SbTreeVO">
+            SELECT info.id,info.name,bom.* FROM
+            t_sb_info info JOIN t_sb_model_spare_bom bom ON
+            info.id=bom.`sb_id`
+            WHERE bom.sb_id=#{id}
+    </select>
+
+    <select id="getSubSb" parameterType="com.platform.dao.dto.sb.SbInfoDTO"
+            resultType="com.platform.dao.vo.sb.SbInfoVO">
+            select id,name from t_sb_info where parent_id=#{id}
+    </select>
 </mapper>

+ 1 - 0
platform-dao/src/main/resources/mapper/sb/SbModelSpareBomMapper.xml

@@ -30,6 +30,7 @@
     <select id="selectVOList" parameterType="com.platform.dao.dto.sb.SbModelSpareBomDTO"
             resultType="com.platform.dao.vo.sb.SbModelSpareBomVO">
         select
+        partInfo.name as spareName,
         <include refid="Left_Column"/>
         from t_sb_model_spare_bom bom
         LEFT JOIN t_sb_info sbInfo ON bom.sb_id = sbInfo.id

+ 1 - 1
platform-dao/src/main/resources/mapper/store/InStoreFormMapper.xml

@@ -168,7 +168,7 @@
 
     <select id="getInStoreDetailVOs" parameterType="com.platform.dao.dto.store.InStoreFormDTO"
             resultType="com.platform.dao.vo.query.store.InStoreFormVO">
-        SELECT form.type,COUNT(*) instorenum FROM `t_in_store_form` form
+        SELECT form.type,COUNT(*) instorenum FROM `t_in_store_form` form left
          join t_store store on store.id=form.store_id
         <where>
 

+ 2 - 2
platform-dao/src/main/resources/mapper/store/OutStoreFormMapper.xml

@@ -109,7 +109,7 @@
             resultType="com.platform.dao.vo.query.store.OutStoreFormVO">
         select outstoreform.*, store.name storeName
         from t_out_store_form as outstoreform
-        join t_store store on store.id = outstoreform.store_id
+        left join t_store store on store.id = outstoreform.store_id
         <where>
             <include refid="List_Condition"/>
             <if test="useCompany != null and useCompany != ''">
@@ -147,7 +147,7 @@
 
     <select id="selectOutStoreList" parameterType="com.platform.dao.dto.store.OutStoreFormDTO"
             resultType="com.platform.dao.vo.query.store.OutStoreFormVO">
- SELECT form.type, COUNT(*) outstorenum FROM `t_out_store_form` form
+ SELECT form.type, COUNT(*) outstorenum FROM `t_out_store_form` form left
      join t_store store on store.id=form.store_id
     <where>
              status=1

+ 23 - 19
platform-rest/src/main/java/com/platform/rest/controller/repair/RepairApplicationFormController.java

@@ -1,33 +1,23 @@
 package com.platform.rest.controller.repair;
 
-import com.platform.common.exception.BusinessException;
 import com.platform.common.util.BeanConverterUtil;
 import com.platform.common.util.R;
 import com.platform.common.validation.group.AddGroup;
 import com.platform.common.validation.group.UpdateGroup;
 import com.platform.dao.dto.repair.RepairApplicationFormDTO;
-import com.platform.dao.dto.repair.RepairCheckDTO;
-import com.platform.dao.dto.repair.RepairFormDTO;
-import com.platform.dao.dto.repair.RepairReasonDTO;
-import com.platform.dao.entity.repair.RepairApplicationForm;
+import com.platform.dao.enums.RepairApplicationFormTypeEnum;
 import com.platform.dao.util.ExcelUtil;
-import com.platform.dao.vo.export.repair.ExportRepairApplicationFormMergeVO;
 import com.platform.dao.vo.export.repair.ExportRepairApplicationFormVO;
-import com.platform.dao.vo.export.repair.ExportRepairCheckVO;
 import com.platform.dao.vo.repair.RepairApplicationFormVO;
-import com.platform.rest.RestApplication;
 import com.platform.rest.log.annotation.SysLog;
 import com.platform.service.repair.RepairApplicationFormService;
-import freemarker.template.Configuration;
-import freemarker.template.Template;
+import com.platform.service.repair.strategy.RepairStrategyFactory;
 import lombok.AllArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -76,7 +66,8 @@ public class RepairApplicationFormController {
     @PostMapping
     @PreAuthorize("@pms.hasPermission('repair-application-forms-add')")
     public R save(@Validated({AddGroup.class}) @RequestBody RepairApplicationFormDTO repairApplicationFormDTO) {
-        return new R<>(repairApplicationFormService.saveModelByDTO(repairApplicationFormDTO));
+        return new R<>(RepairStrategyFactory.getStrategy().callRepair(repairApplicationFormDTO));
+        //return new R<>(repairApplicationFormService.saveModelByDTO(repairApplicationFormDTO));
     }
 
     /**
@@ -103,7 +94,11 @@ public class RepairApplicationFormController {
     @PreAuthorize("@pms.hasPermission('repair-application-forms-edit')")
     public R update(@PathVariable("id") String id, @Validated({UpdateGroup.class}) @RequestBody RepairApplicationFormDTO repairApplicationFormDTO) {
         repairApplicationFormDTO.setId(id);
-        repairApplicationFormService.modModelByDTO(repairApplicationFormDTO);
+        if(repairApplicationFormDTO.getType() == RepairApplicationFormTypeEnum.OUT.getValue()){
+            RepairStrategyFactory.getStrategy().sendRepairToThird(repairApplicationFormDTO);
+        }else{
+            repairApplicationFormService.modModelByDTO(repairApplicationFormDTO);
+        }
         return new R<>();
     }
 
@@ -183,7 +178,8 @@ public class RepairApplicationFormController {
     @PutMapping("/finish/{id}")
     @PreAuthorize("@pms.hasPermission('repair-application-forms-finish')")
     public R finish(@PathVariable("id") String id, @Validated({UpdateGroup.class}) @RequestBody RepairApplicationFormDTO repairFormDTO) {
-        repairApplicationFormService.finish(repairFormDTO);
+        RepairStrategyFactory.getStrategy().handleRepair(repairFormDTO);
+        //repairApplicationFormService.finish(repairFormDTO);
         return new R<>();
     }
 
@@ -197,7 +193,10 @@ public class RepairApplicationFormController {
     @PutMapping("/examine/{id}")
     @PreAuthorize("@pms.hasPermission('repair-application-forms-finish')")
     public R examineApply(@PathVariable("id") String id) {
-        repairApplicationFormService.examine(id);
+        RepairApplicationFormDTO repairFormDTO = new RepairApplicationFormDTO();
+        repairFormDTO.setId(id);
+        RepairStrategyFactory.getStrategy().submitRepair(repairFormDTO);
+        //repairApplicationFormService.examine(id);
         return new R<>();
     }
 
@@ -225,7 +224,10 @@ public class RepairApplicationFormController {
     @PutMapping("/deal/{id}")
     @PreAuthorize("@pms.hasPermission('repair-application-forms-deal')")
     public R repairFormDeal(@PathVariable("id") String id) {
-        repairApplicationFormService.receive(id);
+        RepairApplicationFormDTO repairApplicationFormDTO = new RepairApplicationFormDTO();
+        repairApplicationFormDTO.setId(id);
+        RepairStrategyFactory.getStrategy().sendRepair(repairApplicationFormDTO);
+        //repairApplicationFormService.receive(id);
         return new R<>();
     }
 
@@ -239,7 +241,8 @@ public class RepairApplicationFormController {
     @PutMapping("/approve/{id}")
     @PreAuthorize("@pms.hasPermission('repair-application-forms-approve')")
     public R approve(@PathVariable("id") String id, @Validated({UpdateGroup.class}) @RequestBody RepairApplicationFormDTO repairCheckDTO) {
-        repairApplicationFormService.approve(repairCheckDTO);
+        RepairStrategyFactory.getStrategy().verifyRepair(repairCheckDTO);
+        //repairApplicationFormService.approve(repairCheckDTO);
         return new R<>();
     }
 
@@ -253,7 +256,8 @@ public class RepairApplicationFormController {
     @PutMapping("/returnRepair/{id}")
     @PreAuthorize("@pms.hasPermission('repair-application-forms-reback')")
     public R returnRepair(@PathVariable("id") String id, @Validated({UpdateGroup.class}) @RequestBody RepairApplicationFormDTO repairCheckDTO) {
-        repairApplicationFormService.returnRepair(repairCheckDTO);
+        RepairStrategyFactory.getStrategy().verifyRefused(repairCheckDTO);
+        //repairApplicationFormService.returnRepair(repairCheckDTO);
         return new R<>();
     }
 

+ 13 - 0
platform-rest/src/main/java/com/platform/rest/controller/sb/SbInfoController.java

@@ -15,10 +15,12 @@ import com.platform.dao.vo.export.sb.ExportSbInfoMeasureVO;
 import com.platform.dao.vo.export.sb.ExportSbInfoVO;
 import com.platform.dao.vo.sb.SbInfoVO;
 import com.platform.dao.vo.sb.SbInfoWorkplaceVO;
+import com.platform.dao.vo.sb.SbTreeVO;
 import com.platform.office.poi.excel.ExcelImportUtil;
 import com.platform.office.poi.excel.entity.ImportParams;
 import com.platform.rest.log.annotation.SysLog;
 import com.platform.service.sb.SbInfoService;
+import com.platform.service.sb.impl.SbInfoServiceImpl;
 import lombok.AllArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -43,6 +45,7 @@ import java.util.List;
 public class SbInfoController {
 
     private final SbInfoService sbInfoService;
+    private final SbInfoServiceImpl sbInfoServiceimpl;
 
     /**
      * 设备工作台数据
@@ -480,4 +483,14 @@ public class SbInfoController {
         System.out.println(list.size());
     }
 
+    /**
+     * 获取设备树
+     * @param sbInfoDTO
+     * @return
+     */
+    @GetMapping("/sbTree")
+    public R getSbTree(SbInfoDTO sbInfoDTO) {
+        return new R<>(sbInfoServiceimpl.getSbVOById(sbInfoDTO));
+    }
+
 }

+ 1 - 0
platform-rest/src/main/resources/application-dev.yml

@@ -64,6 +64,7 @@ spring:
 # 直接放行URL
 ignore:
   urls:
+    - /sb/infos/**
     - /upms/logs/**
     - /upms/dicts/data
     - /operate/**

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

@@ -602,6 +602,7 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
         }
         if (!CollectionUtils.isEmpty(jobList)) {
             mapper.insertListforComplex(jobList);
+
         }
 
         if (!CollectionUtils.isEmpty(updateStandardList)) {

+ 448 - 0
platform-service/src/main/java/com/platform/service/repair/strategy/AbstractRepairBaseStrategy.java

@@ -0,0 +1,448 @@
+package com.platform.service.repair.strategy;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.platform.common.cache.ConfigCache;
+import com.platform.common.constant.RedisKeyConstants;
+import com.platform.common.exception.BusinessException;
+import com.platform.common.exception.DeniedException;
+import com.platform.common.util.*;
+import com.platform.dao.dto.repair.RepairApplicationFormDTO;
+import com.platform.dao.dto.sb.SbInfoDTO;
+import com.platform.dao.entity.repair.RepairApplicationForm;
+import com.platform.dao.entity.sb.SbInfo;
+import com.platform.dao.entity.upms.SysFile;
+import com.platform.dao.entity.upms.SysUser;
+import com.platform.dao.enums.*;
+import com.platform.dao.mapper.repair.RepairApplicationFormMapper;
+import com.platform.dao.mapper.upms.SysFileMapper;
+import com.platform.dao.util.MessageTemplateUtil;
+import com.platform.service.event.WorkplaceBacklogEvent;
+import com.platform.service.sb.SbInfoService;
+import com.platform.service.upms.SysUserService;
+import com.platform.service.util.SysFileUtils;
+import com.platform.service.wechat.util.WeChatMessageUtil;
+import lombok.extern.slf4j.Slf4j;
+import tk.mybatis.mapper.weekend.Weekend;
+
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+public abstract class AbstractRepairBaseStrategy implements RepairBaseStrategy{
+    @Resource
+    protected RepairApplicationFormMapper repairApplicationFormMapper;
+    @Resource
+    protected SbInfoService sbInfoService;
+    @Resource
+    protected SysUserService sysUserService;
+    @Resource
+    private SysFileMapper sysFileMapper;
+
+    @Override
+    public RepairApplicationForm callRepair(RepairApplicationFormDTO model) {
+        if(StringUtils.isBlank(model.getSbId())){
+            throw new DeniedException("请填写报修设备");
+        }
+        model.setType(model.getType() == null ? 1 : model.getType());
+        Weekend<RepairApplicationForm> weekend = new Weekend<>(RepairApplicationForm.class);
+        weekend.weekendCriteria().andIsNotNull(RepairApplicationForm::getId).andEqualTo(RepairApplicationForm::getType, model.getType());
+        int count = repairApplicationFormMapper.selectCountByExample(weekend);
+        // 设备是否存在
+        String sbId = model.getSbId();
+        SbInfo sb = sbInfoService.getModelById(sbId);
+        if (sb == null) {
+            throw new DeniedException("设备不存在,无法报修");
+        }
+        // 存储报修人
+        if(StringUtils.isBlank(model.getActualUser())){
+            SysUser sysUser = sysUserService.getModelById(sb.getSaveUser());
+            if (sysUser != null) {
+                model.setUserId(sysUser.getUserId());
+                model.setActualUser(sysUser.getRealName());
+            } else {
+                model.setUserId("1");
+                model.setActualUser("superadmin");
+            }
+        }else{
+            SysUser sysUser = new SysUser();
+            sysUser.setRealName(model.getActualUser());
+            SysUser sysUser1 = sysUserService.getModelByModel(sysUser);
+            if (sysUser1 == null) {
+                // 设置设备的使用人
+                model.setUserId(sb.getSaveUser());
+            } else {
+                model.setUserId(sysUser1.getUserId());
+            }
+        }
+        if (model.getSource() == null) { // 报修来源,默认点检
+            model.setSource(1);
+        }
+        model.setModelId(sb.getModelId());
+        // 根据配置判断是否可以多个提交
+        String only = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_ONLY_ONE.name());
+        if (StringUtils.isNotBlank(only) && Integer.valueOf(only).equals(RepairOnlyOneEnum.ONLY_ONE.getValue())) {
+            if (sb.getStatus().intValue() == SbInfoStatusEnum.IN_MAINTAIN.getValue()) {
+                throw new BusinessException("设备已经在维修中,请等待维修完成, sbId" + model.getSbId());
+            }
+        }
+        // 如果保修的设备位置和设备本身不一样,则可以更新该设备
+        boolean updateSb = false;
+        SbInfoDTO info = BeanConverterUtil.copyObjectProperties(sb, SbInfoDTO.class);
+        if (StringUtils.isNotBlank(model.getSbCph()) && !model.getSbCph().equalsIgnoreCase((sb.getCph()))) {
+            info.setCph(model.getSbCph());
+            updateSb = true;
+        }
+        // 如果选择了设备停机,则要修改设备状态,记录设备状态变更变
+        if (model.getNeedStop() != null && model.getNeedStop().intValue() == RepairApplicationFormStopEnum.STOP.getValue()) {
+            info.setStatus(SbInfoStatusEnum.IN_STOP.getValue());
+            updateSb = true;
+        }
+        if (updateSb) {
+            info.setChangeReason("维修停机");
+            info.setActualUser(model.getActualUser());
+            sbInfoService.updateStatus(info);
+        }
+        model.setOutNo(model.getOutNo());
+        model.setNo(IdGeneratorUtils.getRepairApplicaitonFormNo(++count));
+
+        model.setStatus(RepairApplicationFormStatusEnum.NOT_ALLOCATED.getValue());
+        model.setApplyTime(LocalDateTime.now());
+        model.setCreatedTime(model.getApplyTime());
+        model.setUpdateTime(model.getApplyTime());
+        model.setId(IdGeneratorUtils.getObjectId());
+        this.saveFile(model); // 存储报修图片
+        RepairApplicationForm form = BeanConverterUtil.copyObjectProperties(model, RepairApplicationForm.class);
+        repairApplicationFormMapper.insert(form);
+        return form;
+    }
+
+    @Override
+    public RepairApplicationFormDTO sendRepair(RepairApplicationFormDTO model) {
+        String id = model.getId();
+        RepairApplicationForm applicationForm = repairApplicationFormMapper.selectById(id);
+        if (!RepairApplicationFormStatusEnum.NOT_ALLOCATED.getValue().equals(applicationForm.getStatus()) && !RepairApplicationFormStatusEnum.REBACK.getValue().equals(applicationForm.getStatus())) {
+            throw new BusinessException("该状态不允许接收任务");
+        }
+        model.setRepairStartTime(applicationForm.getRepairStartTime());
+        model.setApplyTime(applicationForm.getApplyTime());
+        model.setNo(applicationForm.getNo());
+        model.setUserId(applicationForm.getUserId());
+        SbInfo sbInfo = sbInfoService.getModelById(applicationForm.getSbId());
+        if (sbInfo == null) {
+            throw new BusinessException("设备不存在,无法接收");
+        }
+        /*if (sbInfo.getRepairUser() == null) {
+            throw new BusinessException("设备的第一维修人未设置,无法接受任务");
+        }
+        if (sbInfo.getRepairUserSecond() == null) {
+            throw new BusinessException("设备的第二维修人未设置,无法接受任务");
+        }
+        if (!SecurityUtils.isRole(SysRoleCodeEnum.MM.name()) && !SecurityUtils.isRole(SysRoleCodeEnum.Maintenance.name())) {
+            throw new BusinessException("您不是维修人或维修主管,无法接受任务");
+        }*/
+        return model;
+    }
+
+    @Override
+    public void handleRepair(RepairApplicationFormDTO dto) {
+        // 1. 将维修单的状态修改已完成
+        RepairApplicationForm applicationForm = repairApplicationFormMapper.selectById(dto.getId());
+        applicationForm.setStatus(RepairApplicationFormStatusEnum.WAIT_SUBMIT.getValue());
+        // 驳回重新完成的,不用更新这个时间,驳回应该状态是完成待审核,不需要重新维修
+        if (applicationForm.getRepairEndTime() == null) {
+            applicationForm.setRepairEndTime(LocalDateTime.now());
+        }
+        if (dto.getRepairEndTime() != null) {
+            applicationForm.setRepairEndTime(dto.getRepairEndTime());
+        }
+        applicationForm.setRepairMinutes(DateUtils.getDurationHours(applicationForm.getRepairStartTime(), applicationForm.getRepairEndTime()));
+        applicationForm.setDealMinutes(DateUtils.getDurationHours(applicationForm.getApplyTime(), applicationForm.getRepairEndTime()));
+        // 根据配置判断维修是否超时
+        String hourFirstStr = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_OVERTIME_MINUTE_FIRST.name());
+        int hourFirst = 180;// 默认3小时,180分钟
+        if (StringUtils.isNotBlank(hourFirstStr)) {
+            hourFirst = Integer.valueOf(hourFirstStr) * 60;
+        }
+        if (applicationForm.getRepairMinutes() > hourFirst) {
+            applicationForm.setRepairOvertime(true);
+        } else {
+            applicationForm.setRepairOvertime(false);
+        }
+        applicationForm.setRepairContent(dto.getRepairContent());
+        applicationForm.setNeedStop(dto.getNeedStop());
+        applicationForm.setUpdateTime(LocalDateTime.now());
+        applicationForm.setOutType(dto.getOutType());
+        // 保存维修图片
+        saveRepairFile(dto);
+        repairApplicationFormMapper.updateByPrimaryKeySelective(applicationForm);
+        // 更新设备状态为使用中
+        SbInfo sbInfo = sbInfoService.getModelById(applicationForm.getSbId());
+        sbInfo.setStatus(SbInfoStatusEnum.IN_USE.getValue());
+        sbInfoService.modModelByPrimaryKey(sbInfo);
+    }
+
+    @Override
+    public RepairApplicationForm submitRepair(RepairApplicationFormDTO model) {
+        RepairApplicationForm applicationForm = repairApplicationFormMapper.selectById(model.getId());
+        if (!RepairApplicationFormStatusEnum.WAIT_SUBMIT.getValue().equals(applicationForm.getStatus())) {
+            throw new BusinessException("未完成的不允许提交审核");
+        }
+        applicationForm.setStatus(RepairApplicationFormStatusEnum.NOT_ACCEPTANCE.getValue());
+        applicationForm.setCheckStartTime(LocalDateTime.now());
+        applicationForm.setUpdateTime(applicationForm.getCheckStartTime());
+        repairApplicationFormMapper.updateByPrimaryKeySelective(applicationForm);
+        return applicationForm;
+    }
+
+    @Override
+    public void verifyRepair(RepairApplicationFormDTO model) {
+        // 1.修改验收单状态和验收验收时间
+        RepairApplicationForm applicationForm = repairApplicationFormMapper.selectById(model.getId());
+        // 如果选择了设备停机,则要修改设备状态
+        SbInfo info = sbInfoService.getModelById(applicationForm.getSbId());
+        info.setStatus(SbInfoStatusEnum.IN_USE.getValue());
+        sbInfoService.modModelByPrimaryKey(info);
+
+        applicationForm.setCheckEndTime(LocalDateTime.now());
+        applicationForm.setStatus(RepairApplicationFormStatusEnum.FINISHED.getValue());
+        // }
+        applicationForm.setUpdateTime(applicationForm.getCheckEndTime());
+        repairApplicationFormMapper.updateByPrimaryKeySelective(applicationForm);
+    }
+
+    @Override
+    public RepairApplicationFormDTO verifyRefused(RepairApplicationFormDTO model) {
+        // 1.修改验收单状态
+        RepairApplicationForm applicationForm = repairApplicationFormMapper.selectById(model.getId());
+        applicationForm.setCheckContent(model.getCheckContent());
+        applicationForm.setStatus(RepairApplicationFormStatusEnum.REBACK.getValue());
+        applicationForm.setUpdateTime(LocalDateTime.now());
+        repairApplicationFormMapper.updateByPrimaryKeySelective(applicationForm);
+        model.setRepairUserId(applicationForm.getRepairUserId());
+        model.setNo(applicationForm.getNo());
+        return model;
+    }
+
+    @Override
+    public RepairApplicationFormDTO dispatchRepair(RepairApplicationFormDTO model) {
+        RepairApplicationForm applicationForm = repairApplicationFormMapper.selectById(model.getId());
+        if (!RepairApplicationFormStatusEnum.NOT_ALLOCATED.getValue().equals(applicationForm.getStatus()) && !RepairApplicationFormStatusEnum.REBACK.getValue().equals(applicationForm.getStatus())) {
+            throw new BusinessException("该状态不允许派工任务, id, status:" + applicationForm.getId() + "," + applicationForm.getStatus());
+        }
+
+        if (StringUtils.isBlank(applicationForm.getRepairDispatchList())) {
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("userId", applicationForm.getRepairUserId());
+            jsonObject.put("username", applicationForm.getRepairUserName());
+            jsonObject.put("remark", model.getRepairDispatchRemark());
+            jsonObject.put("time", LocalDateTime.now());
+            JSONArray jsonArray = new JSONArray();
+            jsonArray.add(jsonObject);
+            applicationForm.setRepairDispatchList(jsonArray.toJSONString());
+        } else {
+            JSONArray jsonArray = JSONArray.parseArray(applicationForm.getRepairDispatchList());
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("userId", applicationForm.getRepairUserId());
+            jsonObject.put("username", applicationForm.getRepairUserName());
+            jsonObject.put("remark", applicationForm.getRepairDispatchRemark());
+            jsonObject.put("time", LocalDateTime.now());
+            jsonArray.add(jsonObject);
+            applicationForm.setRepairDispatchList(jsonArray.toJSONString());
+        }
+        applicationForm.setId(model.getId());
+        applicationForm.setRepairUserId(model.getRepairUserId());
+        applicationForm.setRepairDispatchRemark(model.getRepairDispatchRemark());
+        applicationForm.setStatus(RepairApplicationFormStatusEnum.PROCESSING.getValue());
+        applicationForm.setRepairStartTime(LocalDateTime.now());
+        applicationForm.setUpdateTime(LocalDateTime.now());
+        // 转派其他人要将维修结束时间置空'
+        repairApplicationFormMapper.updateForRepairDispatch(applicationForm);
+
+        SysUser repairUser = sysUserService.getModelById(model.getRepairUserId());
+        SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_DISPATCH.getValue(),
+                applicationForm.getId(), MessageTemplateUtil.getRepairDispatch(applicationForm.getNo()),
+                applicationForm.getId(), ListUtils.newArrayList(model.getRepairUserId()), ListUtils.newArrayList(repairUser.getEmail())));
+        return model;
+    }
+
+    @Override
+    public void sendRepairToThird(RepairApplicationFormDTO model) {
+        model.setUpdateTime(LocalDateTime.now());
+        model.setUpdateUserId(SecurityUtils.getUserInfo().getUserId());
+        model.setUpdateUserName(SecurityUtils.getUserInfo().getUsername());
+        repairApplicationFormMapper.updateByPrimaryKeySelective(BeanConverterUtil.copyObjectProperties(model, RepairApplicationForm.class));
+    }
+
+    /**
+     * 保存维修上传的图片
+     * @param model
+     */
+    private void saveFile(RepairApplicationFormDTO model) {
+        if (CollectionUtil.isNotEmpty(model.getApplicationFileList())) {
+            Weekend<SysFile> weekend = new Weekend<>(SysFile.class);
+            weekend.weekendCriteria().andEqualTo(SysFile::getType, SysFileTypeEnum.REPAIR_APPLICATION_IMGS.getValue()).andEqualTo(SysFile::getTargetId, model.getId());
+            sysFileMapper.deleteByExample(weekend);
+            List<SysFile> list = SysFileUtils.changeFileList(model.getApplicationFileList(), model.getId(), SysFileTypeEnum.REPAIR_APPLICATION_IMGS.getValue());
+            if (CollectionUtil.isNotEmpty(list)) {
+                sysFileMapper.insertListforComplex(list);
+            }
+        }
+    }
+
+    /**
+     * 保存维修图片
+     *
+     * @param model
+     */
+    private void saveRepairFile(RepairApplicationFormDTO model) {
+        if (CollectionUtil.isNotEmpty(model.getRepairFileList())) {
+            Weekend<SysFile> weekend = new Weekend<>(SysFile.class);
+            weekend.weekendCriteria().andEqualTo(SysFile::getType, SysFileTypeEnum.REPAIR_REPAIR_IMGS.getValue()).andEqualTo(SysFile::getTargetId, model.getId());
+            sysFileMapper.deleteByExample(weekend);
+            List<SysFile> list = SysFileUtils.changeFileList(model.getRepairFileList(), model.getId(), SysFileTypeEnum.REPAIR_REPAIR_IMGS.getValue());
+            if (CollectionUtil.isNotEmpty(list)) {
+                sysFileMapper.insertListforComplex(list);
+            }
+        }
+    }
+
+    /**
+     * 推送站内信和邮箱
+     * @param mails
+     * @param userIds
+     * @param model
+     * @param sb
+     */
+    public void sendWorkplaceAndEmail(List<String> mails,List<String> userIds,RepairApplicationFormDTO model,SbInfo sb){
+        String domain = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.SYSTEM_DOMAIN.name());
+        if (StringUtils.isBlank(domain)) {
+            throw new BusinessException("请先设置系统域名地址,系统管理-》系统参数配置-》SYSTEM_DOMAIN");
+        }
+        if (!domain.endsWith("/")) {
+            domain = domain + "/";
+        }
+        String repairUrl = domain + "repair/form?no=" + model.getNo();
+
+        // 通过给当天值班维修人员
+        SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_APPLICATION.getValue(),
+                model.getId(),
+                MessageTemplateUtil.getFreemarkerHtmlContent(repairUrl, model, sb),
+                model.getId(), userIds, mails));
+    }
+
+    /**
+     * 微信通知
+     * @param openIds
+     * @param model
+     * @param sb
+     */
+    public void sendWechat(List<String> openIds,RepairApplicationFormDTO model,SbInfo sb){
+        // 发送微信通知给所有维修人角色
+        if (CollectionUtil.isNotEmpty(openIds) && BeanUtils.isProd()) {
+            String mobileDomain = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.SYSTEM_DOMAIN_MOBILE.name());
+            if (StringUtils.isBlank(mobileDomain)) {
+                throw new BusinessException("请先设置系统域名地址,系统管理-》系统参数配置-》SYSTEM_DOMAIN_MOBILE");
+            }
+            if (!mobileDomain.endsWith("/")) {
+                mobileDomain = mobileDomain + "/";
+            }
+            String mobileRepairUrl = mobileDomain + "pages/repair-detail/repair-detail?detailId=" + model.getId();
+            for (String openId : openIds) {
+                WeChatMessageUtil.repairMessage(openId, mobileRepairUrl, model, sb);
+            }
+        }
+    }
+
+    /**
+     * 短息发送
+     * @param receiverList
+     * @param model
+     */
+    public void sendSms(List<String> receiverList,RepairApplicationFormDTO model,SbInfo sb){
+        if (CollectionUtil.isNotEmpty(receiverList) && BeanUtils.isProd()) {
+            // String templateParas_repair = "[\"C-001\",\"1号车间\",\"熊超\"]";
+            String no = sb.getNo();
+            if (StringUtils.isNotBlank(no)) {
+                no = no.replace("_", "").replace("-", "");
+            }
+            String sbCph = model.getSbCph();
+            String actualUser = model.getActualUser();
+            if (StringUtils.isBlank(sbCph)) {
+                sbCph = "未知";
+            }
+            if (StringUtils.isBlank(actualUser)) {
+                actualUser = "未知";
+            }
+            String templateParas_repair = "[\"" + no + "\",\"" + sbCph + "\",\"" + actualUser + "\"]";
+            for (String receiver : receiverList) {
+                try {
+                    String numStr = RedisUtils.getString(RedisKeyConstants.HW_SMS + receiver);
+                    boolean isSend = false;
+                    if (StringUtils.isBlank(numStr)) {
+                        isSend = true;
+                        RedisUtils.setString(RedisKeyConstants.HW_SMS + receiver, "1", 24, TimeUnit.HOURS);
+                    } else if (Integer.valueOf(numStr) < 5) {
+                        isSend = true;
+                        RedisUtils.setString(RedisKeyConstants.HW_SMS + receiver, String.valueOf(Integer.valueOf(numStr) + 1), 24, TimeUnit.HOURS);
+                    }
+                    if (isSend) {
+                        System.out.println("templateParas_repair: " + templateParas_repair);
+                        SendSms.sendRepairSms(receiver, templateParas_repair);
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    /**
+     * 启动任务超时监控
+     * @param repairId
+     */
+    public void overTimeListen(String repairId){
+        // 启动接收超时监控
+        String minuteStr = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_WARN_MINUTE.name());
+        int minute = 30;// 默认30分钟
+        if (StringUtils.isNotBlank(minuteStr)) {
+            minute = Integer.valueOf(minuteStr);
+        }
+        RedisUtils.setString(RedisKeyConstants.EXPIRE_BUSINESS_KEY_REPAIR_STEP_FIRST + RedisKeyConstants.EXPIRE_BUSINESS_SEP + repairId, repairId, minute, TimeUnit.MINUTES);
+
+        // 启动维修超时监控,维修时间升级流程:超过3个小时没修好,升级给牛工,超过8个小时没修好,升级给相工,超过24 没修好,升级给田总,现在把三阶段的人员位置留好,可以先暂时升级给我,后期再改为具体的人。
+        String hourFirstStr = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_OVERTIME_MINUTE_FIRST.name());
+        int hourFirst = 3;// 默认3小时
+        if (StringUtils.isNotBlank(hourFirstStr)) {
+            hourFirst = Integer.valueOf(hourFirstStr);
+        }
+        String hourSecondStr = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_OVERTIME_MINUTE_SECOND.name());
+        int hourSecond = 8;// 默认8小时
+        if (StringUtils.isNotBlank(hourSecondStr)) {
+            hourSecond = Integer.valueOf(hourSecondStr);
+        }
+        String hourThirdStr = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_OVERTIME_MINUTE_THIRD.name());
+        int hourThird = 24;// 默认24小时
+        if (StringUtils.isNotBlank(hourThirdStr)) {
+            hourThird = Integer.valueOf(hourThirdStr);
+        }
+        RedisUtils.setString(RedisKeyConstants.EXPIRE_BUSINESS_KEY_REPAIR_OVERTIME_STEP_FIRST + RedisKeyConstants.EXPIRE_BUSINESS_SEP + repairId, repairId, hourFirst, TimeUnit.HOURS);
+        RedisUtils.setString(RedisKeyConstants.EXPIRE_BUSINESS_KEY_REPAIR_OVERTIME_STEP_SECOND + RedisKeyConstants.EXPIRE_BUSINESS_SEP + repairId, repairId, hourSecond, TimeUnit.HOURS);
+        RedisUtils.setString(RedisKeyConstants.EXPIRE_BUSINESS_KEY_REPAIR_OVERTIME_STEP_THIRD + RedisKeyConstants.EXPIRE_BUSINESS_SEP + repairId, repairId, hourThird, TimeUnit.HOURS);
+    }
+
+    /**
+     * 推送消息给报修人
+     * @param repairId  维修ID
+     * @param repairNo  维修单号
+     * @param userId    报修人ID
+     */
+    public void sendMessageToRepairCaller(String repairId,String repairNo,String userId){
+        SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.RECEIVE.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_RECEIVE.getValue(),
+                repairId, MessageTemplateUtil.getReceive(repairNo),
+                repairId, ListUtils.newArrayList(userId)));
+    }
+}

+ 57 - 0
platform-service/src/main/java/com/platform/service/repair/strategy/RepairBaseStrategy.java

@@ -0,0 +1,57 @@
+package com.platform.service.repair.strategy;
+
+import com.platform.dao.dto.repair.RepairApplicationFormDTO;
+import com.platform.dao.entity.repair.RepairApplicationForm;
+
+/**
+ * 维修策略基础接口
+ */
+public interface RepairBaseStrategy {
+
+    /**
+     * 报修
+     * @param model
+     */
+    RepairApplicationForm callRepair(RepairApplicationFormDTO model);
+
+    /**
+     * 派工/领取任务
+     * @param model
+     */
+    RepairApplicationFormDTO sendRepair(RepairApplicationFormDTO model);
+
+    /**
+     * 维修完成
+     * @param model
+     */
+    void handleRepair(RepairApplicationFormDTO model);
+
+    /**
+     * 提交审核
+     * @param model
+     */
+    RepairApplicationForm submitRepair(RepairApplicationFormDTO model);
+
+    /**
+     * 审核通过
+     * @param model
+     */
+    void verifyRepair(RepairApplicationFormDTO model);
+
+    /**
+     * 审核不通过
+     */
+    RepairApplicationFormDTO verifyRefused(RepairApplicationFormDTO model);
+
+    /**
+     * 转派给其他人
+     * 非自己业务范围
+     */
+    RepairApplicationFormDTO dispatchRepair(RepairApplicationFormDTO model);
+
+    /**
+     * 委外
+     * @param model
+     */
+    void sendRepairToThird(RepairApplicationFormDTO model);
+}

+ 26 - 0
platform-service/src/main/java/com/platform/service/repair/strategy/RepairStrategyFactory.java

@@ -0,0 +1,26 @@
+package com.platform.service.repair.strategy;
+
+import com.platform.common.cache.ConfigCache;
+import com.platform.common.constant.CommonConstants;
+import com.platform.common.util.BeanUtils;
+import com.platform.dao.enums.SysConfigEnum;
+import com.platform.service.repair.strategy.impl.AllocateRepairBaseStrategy;
+import com.platform.service.repair.strategy.impl.BaseRepairBaseStrategy;
+
+/**
+ * 获取具体策略类
+ */
+public class RepairStrategyFactory {
+    public static RepairBaseStrategy getStrategy(){
+        RepairBaseStrategy strategy = (BaseRepairBaseStrategy)BeanUtils.getBean("baseRepairBaseStrategy");
+        String strategyFlag = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_STRATEGY_MODEL.name());
+        switch (strategyFlag){
+            case CommonConstants.REPAIR_STRATEGY_MODEL_DISPATCH:
+                strategy = (AllocateRepairBaseStrategy)BeanUtils.getBean("allocateRepairBaseStrategy");
+                break;
+            case CommonConstants.REPAIR_STRATEGY_MODEL_BASE:
+                break;
+        }
+        return strategy;
+    }
+}

+ 9 - 0
platform-service/src/main/java/com/platform/service/repair/strategy/impl/AllocateRepairBaseStrategy.java

@@ -0,0 +1,9 @@
+package com.platform.service.repair.strategy.impl;
+
+import com.platform.service.repair.strategy.AbstractRepairBaseStrategy;
+import org.springframework.stereotype.Component;
+
+@Component
+public class AllocateRepairBaseStrategy extends AbstractRepairBaseStrategy {
+
+}

+ 161 - 0
platform-service/src/main/java/com/platform/service/repair/strategy/impl/BaseRepairBaseStrategy.java

@@ -0,0 +1,161 @@
+package com.platform.service.repair.strategy.impl;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.platform.common.cache.ConfigCache;
+import com.platform.common.exception.BusinessException;
+import com.platform.common.model.UserInfo;
+import com.platform.common.util.*;
+import com.platform.dao.dto.repair.RepairApplicationFormDTO;
+import com.platform.dao.dto.upms.SysUserDTO;
+import com.platform.dao.entity.repair.RepairApplicationForm;
+import com.platform.dao.entity.sb.SbInfo;
+import com.platform.dao.entity.upms.SysUser;
+import com.platform.dao.enums.*;
+import com.platform.dao.util.MessageTemplateUtil;
+import com.platform.dao.vo.SysUserVO;
+import com.platform.dao.vo.sb.SbInfoVO;
+import com.platform.service.event.WorkplaceBacklogEvent;
+import com.platform.service.repair.strategy.AbstractRepairBaseStrategy;
+import com.platform.service.repair.strategy.RepairBaseStrategy;
+import org.springframework.stereotype.Component;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 自由接单模式  -- free style
+ * 也是基础模式 -- base style
+ */
+@Component
+public class BaseRepairBaseStrategy extends AbstractRepairBaseStrategy {
+
+    @Override
+    public RepairApplicationForm callRepair(RepairApplicationFormDTO model) {
+        RepairApplicationForm form = super.callRepair(model);
+        // 根据自身需要将任务推送通知还是派送到具体主管手上
+        // 这里的基础模式是,维修人员自主接收,我们获取需要需要派送的信息Ids集合
+        List<String> openIds = new ArrayList<>();
+        List<String> userIds = new ArrayList<>();
+        List<String> mails = new ArrayList<>();
+        List<String> receiverList = new ArrayList<>();
+
+        // 发送短信通知给所有维修,且必须是正式环境
+        SysUserDTO sysUserDTO = new SysUserDTO();
+        sysUserDTO.setRoleCode(SysRoleCodeEnum.Maintenance.name());
+        List<SysUserVO> sysUserVOList = sysUserService.getDeptChildrenRoleUser(sysUserDTO);
+        if (CollectionUtil.isNotEmpty(sysUserVOList)) {
+            for (SysUserVO sysUserVO : sysUserVOList) {
+                // 站内信需要用户id
+                userIds.add(sysUserVO.getUserId());
+                if (StringUtils.isNotBlank(sysUserVO.getWxOpenid())) {
+                    // 微信id
+                    openIds.add(sysUserVO.getWxOpenid());
+                }
+                if (StringUtils.isNotBlank(sysUserVO.getPhone())) {
+                    // 手机
+                    receiverList.add(sysUserVO.getPhone());
+                }
+                if (StringUtils.isNotBlank(sysUserVO.getEmail())) {
+                    // 邮箱
+                    mails.add(sysUserVO.getEmail());
+                }
+            }
+        }
+        model = BeanConverterUtil.copyObjectProperties(form,RepairApplicationFormDTO.class);
+        SbInfo sb = sbInfoService.getModelById(model.getSbId());
+        // 推送站内信和邮箱,根据业务需要
+        sendWorkplaceAndEmail(mails,userIds,model,sb);
+        // 推送微信
+        sendWechat(openIds,model,sb);
+        // 短信
+        sendSms(receiverList,model,sb);
+        // 启动超时监控
+        overTimeListen(form.getId());
+        return form;
+    }
+
+    @Override
+    public RepairApplicationFormDTO sendRepair(RepairApplicationFormDTO model) {
+        RepairApplicationFormDTO superModel = super.sendRepair(model);
+        // 自由接单
+        UserInfo userInfo = SecurityUtils.getUserInfo();
+        RepairApplicationForm applicationForm = new RepairApplicationForm();
+        applicationForm.setId(model.getId());
+        applicationForm.setRepairUserId(userInfo.getUserId());
+        applicationForm.setStatus(RepairApplicationFormStatusEnum.PROCESSING.getValue());
+        if (superModel.getRepairStartTime() == null) {
+            applicationForm.setRepairStartTime(LocalDateTime.now());
+        }
+        applicationForm.setReceiveMinutes(DateUtils.getDurationHours(superModel.getApplyTime(), applicationForm.getRepairStartTime()));
+        // 根据配置判断维修是否超时
+        String minuteStr = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.REPAIR_WARN_MINUTE.name());
+        if (StringUtils.isBlank(minuteStr)) {
+            applicationForm.setReceiveOvertime(false);
+        } else if (applicationForm.getReceiveMinutes() > Double.valueOf(minuteStr)) {
+            applicationForm.setReceiveOvertime(true);
+        } else {
+            applicationForm.setReceiveOvertime(false);
+        }
+        applicationForm.setUpdateTime(LocalDateTime.now());
+        repairApplicationFormMapper.updateByPrimaryKeySelective(applicationForm);
+        // 给报修人发送消息
+        sendMessageToRepairCaller(superModel.getId(),superModel.getNo(),superModel.getUserId());
+        return model;
+    }
+
+    @Override
+    public RepairApplicationForm submitRepair(RepairApplicationFormDTO model) {
+        RepairApplicationForm applicationForm = super.submitRepair(model);
+        SbInfoVO sbInfoVO = sbInfoService.getById(applicationForm.getSbId());
+        // 默认的提交审核后的审核人,就是维修主管的角色,每家不同自行实现
+        SysUserVO userVO;
+        SysUserDTO query = new SysUserDTO();
+        query.setRoleCode(SysRoleCodeEnum.REPAIR_EXAMINE.name());
+        List<SysUserVO> users = sysUserService.selectDeptRoleUser(query);
+        if (CollectionUtil.isNotEmpty(users)) {
+            userVO = users.get(0);
+        } else {
+            throw new BusinessException("审核角色:REPAIR_EXAMINE未绑定用户,REPAIR_EXAMINE为维修单最终验收人,请设置用户");
+        }
+        applicationForm.setCheckUserId(userVO.getUserId());
+        repairApplicationFormMapper.updateByPrimaryKeySelective(applicationForm);
+        // 发送邮件和通知
+        String domain = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.SYSTEM_DOMAIN.name());
+        if (StringUtils.isBlank(domain)) {
+            throw new BusinessException("请先设置系统域名地址,系统管理-》系统参数配置-》SYSTEM_DOMAIN");
+        }
+        if (!domain.endsWith("/")) {
+            domain = domain + "/";
+        }
+        String repairUrl = domain + "repair/application/form/check?no=" + applicationForm.getNo();
+        SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_EXAMINE.getValue(),
+                applicationForm.getId(), MessageTemplateUtil.getFreemarkerHtmlContentCheck(repairUrl, BeanConverterUtil.copyObjectProperties(applicationForm, RepairApplicationFormDTO.class), sbInfoVO),
+                applicationForm.getId(), ListUtils.newArrayList(userVO.getUserId()), ListUtils.newArrayList(userVO.getEmail())));
+        return applicationForm;
+    }
+
+    @Override
+    public RepairApplicationFormDTO verifyRefused(RepairApplicationFormDTO model) {
+        RepairApplicationFormDTO dto = super.verifyRefused(model);
+        SysUser noticeUser = sysUserService.getModelById(dto.getRepairUserId());
+        SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.REPAIR.getValue(), WorkplaceBacklogDetailTypeEnum.REPAIR_BACK.getValue(),
+                dto.getId(), MessageTemplateUtil.getRepairBack(dto.getNo()),
+                dto.getId(), ListUtils.newArrayList(dto.getRepairUserId()), ListUtils.newArrayList(noticeUser.getEmail())));
+        return dto;
+    }
+
+    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+        RepairApplicationFormDTO dto = new RepairApplicationFormDTO();
+        RepairBaseStrategy tt = new BaseRepairBaseStrategy();
+        Class cla = tt.getClass();
+        Method[] methods = cla.getMethods();
+        for(Method method : methods){
+            System.out.println(method.getName());
+        }
+        Method method = cla.getMethod("callRepair", RepairApplicationFormDTO.class);
+        method.invoke(tt,dto);
+    }
+}

+ 6 - 4
platform-service/src/main/java/com/platform/service/sb/SbInfoService.java

@@ -4,10 +4,7 @@ import com.platform.common.bean.AbstractPageResultBean;
 import com.platform.dao.bean.MyVOPage;
 import com.platform.dao.dto.sb.SbInfoDTO;
 import com.platform.dao.entity.sb.SbInfo;
-import com.platform.dao.vo.sb.SbInfoScreenDetailVO;
-import com.platform.dao.vo.sb.SbInfoScreenVO;
-import com.platform.dao.vo.sb.SbInfoVO;
-import com.platform.dao.vo.sb.SbInfoWorkplaceVO;
+import com.platform.dao.vo.sb.*;
 import com.platform.service.base.IBaseService;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -283,4 +280,9 @@ public interface SbInfoService extends IBaseService<SbInfo, SbInfoDTO> {
     void modImagesByDTO(SbInfoDTO sbInfoDTO);
 
     SbInfoWorkplaceVO getWorkplaceData();
+
+    SbTreeVO getSbTreeVo(SbInfoDTO sbInfoDTO);
+
+    public SbTreeVO getSbVOById(SbInfoDTO sbInfoDTO);
+
 }

+ 79 - 0
platform-service/src/main/java/com/platform/service/sb/impl/SbInfoServiceImpl.java

@@ -28,6 +28,7 @@ import com.platform.dao.dto.upms.SysUserDeptDTO;
 import com.platform.dao.dto.workplace.WorkplaceBacklogDTO;
 import com.platform.dao.dto.workplace.WorkplaceBacklogUserDTO;
 import com.platform.dao.entity.firm.FirmProducer;
+import com.platform.dao.entity.part.PartInfo;
 import com.platform.dao.entity.repair.RepairApplicationForm;
 import com.platform.dao.entity.sb.*;
 import com.platform.dao.entity.store.InStoreDetail;
@@ -38,6 +39,7 @@ import com.platform.dao.entity.upms.SysUser;
 import com.platform.dao.entity.upms.SysUserDept;
 import com.platform.dao.enums.*;
 import com.platform.dao.mapper.firm.FirmProducerMapper;
+import com.platform.dao.mapper.part.PartInfoMapper;
 import com.platform.dao.mapper.repair.RepairApplicationFormMapper;
 import com.platform.dao.mapper.sb.*;
 import com.platform.dao.mapper.upms.SysDeptMapper;
@@ -130,6 +132,9 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
     private final CheckStandardService checkStandardService;
     private final WorkplaceBacklogUserMapper backlogUserMapper;
     private final ActivitiBusinessService activitiBusinessService;
+    private final SbInfoMapper sbInfoMapper;
+    private final SbModelSpareBomMapper sbModelSpareBomMapper;
+    private final PartInfoMapper partInfoMapper;
 
     private final String useArea = "5e64ac691c527828b2114da0";
     private final String useCompany = "6063f905eb190003685af6d4";
@@ -563,6 +568,80 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         return vo;
     }
 
+    @Override
+    public SbTreeVO getSbTreeVo(SbInfoDTO sbInfoDTO) {
+        SbTreeVO sbTreeVO = new SbTreeVO();
+        SbModelSpareBomDTO sbModelSpareBomDTO = new SbModelSpareBomDTO();
+        PartInfoDTO partInfoDTO = new PartInfoDTO();
+        partInfoDTO.setSbId(sbInfoDTO.getId());
+        sbModelSpareBomDTO.setSbId(sbInfoDTO.getId());
+        List<PartInfo> partInfoList = partInfoMapper.selectPageList(partInfoDTO);
+        List<SbModelSpareBomVO> sbModelSpareBomVOList = sbModelSpareBomMapper.selectVOList(sbModelSpareBomDTO);
+        List<SbModelSpareBomVO> spareList = new ArrayList<>();
+        List<SbModelSpareBomVO> spareList2 = new ArrayList<>();
+        for (PartInfo info : partInfoList) {
+        for (SbModelSpareBomVO vo : sbModelSpareBomVOList) {
+            if (StringUtils.isBlank(vo.getSbPartId())) {
+                spareList.add(vo);
+            } else {
+                if (info.getId().equals(vo.getSbPartId())) {
+                    spareList2.add(vo);
+                }
+            }
+        }
+        info.setSparePartInfoVOList(spareList2);
+    }
+        sbTreeVO.setId(sbInfoDTO.getId());
+        sbTreeVO.setPartInfoList(partInfoList);
+        sbTreeVO.setSbModelSpareBomVOList(spareList);
+        return sbTreeVO;
+    }
+
+@Override
+    public SbTreeVO getSbVOById(SbInfoDTO sbInfoDTO) {
+        SbInfoVO sbInfoVO=sbInfoMapper.getById(sbInfoDTO.getId());
+        List<SbInfoVO> ids=sbInfoMapper.getSubSb(sbInfoDTO);
+        SbTreeVO sbTreeVO = new SbTreeVO();
+        sbTreeVO.setName(sbInfoVO.getName());
+        List<SbTreeVO> subSbTreeList=new ArrayList<>();
+        if(ids!=null&&ids.size()>0){
+            for(SbInfoVO id: ids){
+                SbInfoDTO infoDTO=new SbInfoDTO();
+                SbTreeVO subSbTreeVO= getSbVOById(infoDTO.setId(id.getId()));
+//                subSbTreeVO.setName(id.getName());
+                subSbTreeList.add(subSbTreeVO);
+
+            }
+        }
+        sbTreeVO.setSubSbTreeVOList(subSbTreeList);
+        SbModelSpareBomDTO sbModelSpareBomDTO = new SbModelSpareBomDTO();
+        PartInfoDTO partInfoDTO = new PartInfoDTO();
+        partInfoDTO.setSbId(sbInfoDTO.getId());
+        sbModelSpareBomDTO.setSbId(sbInfoDTO.getId());
+        List<PartInfo> partInfoList = partInfoMapper.selectPageList(partInfoDTO);
+        List<SbModelSpareBomVO> sbModelSpareBomVOList = sbModelSpareBomMapper.selectVOList(sbModelSpareBomDTO);
+        List<SbModelSpareBomVO> spareList = new ArrayList<>();
+        List<SbModelSpareBomVO> spareList2 = new ArrayList<>();
+        for (PartInfo info : partInfoList) {
+            for (SbModelSpareBomVO vo : sbModelSpareBomVOList) {
+                if (StringUtils.isBlank(vo.getSbPartId())) {
+                    spareList.add(vo);
+                } else {
+                    if (info.getId().equals(vo.getSbPartId())) {
+                        spareList2.add(vo);
+                    }
+                }
+            }
+            info.setSparePartInfoVOList(spareList2);
+        }
+
+        sbTreeVO.setId(sbInfoDTO.getId());
+        sbTreeVO.setPartInfoList(partInfoList);
+        sbTreeVO.setSbModelSpareBomVOList(spareList);
+        return sbTreeVO;
+    }
+
+
     private void setSbNum(LocalDateTime now, SbInfoWorkplaceVO vo) {
 
         List<SbInfo> sbInfoList = mapper.selectAll();

+ 4 - 0
platform-service/src/main/java/com/platform/service/sqarepartmanage/impl/SparePartUsedServiceImpl.java

@@ -344,5 +344,9 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
         // 如2021-10-15号码,则month=10,需要计算到11月份,需要加1
         int month = localDate.getMonthValue();
         System.out.println(month);
+        String str = "          kkjsd    kjads  kjd  ";
+        System.out.println(str+"--size+"+str.length());
+        str = str.replace(" ","");
+        System.out.println(str+"--size+"+str.length());
     }
 }

+ 8 - 0
platform-service/src/main/java/com/platform/service/upms/SysUserService.java

@@ -200,4 +200,12 @@ public interface SysUserService extends IBaseService<SysUser, SysUserDTO> {
      * @return
      */
     List<SysUser> getRepairUser(SysUserDTO sysUserDTO);
+
+    /**
+     * 根据部门和角色查询用户
+     *
+     * @param sysUserDTO
+     * @return
+     */
+    List<SysUserVO> selectDeptRoleUser(SysUserDTO sysUserDTO);
 }

+ 5 - 0
platform-service/src/main/java/com/platform/service/upms/impl/SysUserServiceImpl.java

@@ -746,4 +746,9 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser,
         weekendCriteria.andIn(SysUser::getIdentityType, Arrays.asList(new Integer[]{SysUserIdentityType.WXY.getValue(), SysUserIdentityType.WXZG.getValue(), SysUserIdentityType.WXZGMANAGER.getValue()}));
         return mapper.selectByExample(weekend);
     }
+
+    @Override
+    public List<SysUserVO> selectDeptRoleUser(SysUserDTO sysUserDTO) {
+        return mapper.selectDeptRoleUser(sysUserDTO);
+    }
 }