wangliang 1 жил өмнө
parent
commit
caed27b5a5

+ 2 - 4
sop-api/src/main/java/com/qmth/sop/server/api/TBSopInfoController.java

@@ -111,10 +111,8 @@ public class TBSopInfoController {
     @ApiOperation(value = "sop人员配置")
     @RequestMapping(value = "/allocation", method = RequestMethod.POST)
     @ApiResponses({ @ApiResponse(code = 200, message = "返回信息", response = Object.class) })
-    public Result allocation(@ApiParam(value = "sop单号", required = true) @RequestParam String sopNo) {
-        //        activitiService.taskApproverExchange(517334123287674880L, 524285274100858881L);
-        //todo 需要调曹子轩人员配置方法,项目经理变更后调用转审
-        return ResultUtil.ok();
+    public Result allocation(@ApiParam(value = "流程id", required = true) @RequestParam Long flowId) {
+        return ResultUtil.ok(tbSopInfoService.sopAllocation(flowId));
     }
 
     @ApiOperation(value = "sop作废")

+ 15 - 15
sop-business/src/main/java/com/qmth/sop/business/entity/TBCrmDetail.java

@@ -6,8 +6,8 @@ import com.qmth.sop.business.bean.dto.CrmDetailImportDto;
 import com.qmth.sop.common.base.BaseEntity;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.CrmStatusEnum;
-import com.qmth.sop.common.enums.FlowStatusEnum;
 import com.qmth.sop.common.enums.ServiceScopeEnum;
+import com.qmth.sop.common.enums.SopStatusEnum;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -75,13 +75,13 @@ public class TBCrmDetail extends BaseEntity implements Serializable {
     @NotNull(message = "阅卷结束时间不能为空")
     private Long markPaperEndTime;
 
-    @ApiModelProperty(value = "状态")
+    @ApiModelProperty(value = "sop状态")
     @TableField(exist = false)
-    String flowStatusStr;
+    String sopStatusStr;
 
-    @ApiModelProperty(value = "状态,START:已开始,AUDITING:审核中,REJECT:已驳回,END:已终止,FINISH:已结束")
+    @ApiModelProperty(value = "状态,DRAFT:草稿,START:提交")
     @TableField(exist = false)
-    private FlowStatusEnum flowStatus;
+    private SopStatusEnum sopStatus;
 
     public TBCrmDetail() {
 
@@ -132,24 +132,24 @@ public class TBCrmDetail extends BaseEntity implements Serializable {
         updateInfo(userId);
     }
 
-    public String getFlowStatusStr() {
-        if (Objects.nonNull(this.flowStatus)) {
-            return this.flowStatus.getTitle();
+    public String getSopStatusStr() {
+        if (Objects.nonNull(this.sopStatus)) {
+            return this.sopStatus.getTitle();
         } else {
-            return flowStatusStr;
+            return sopStatusStr;
         }
     }
 
-    public void setFlowStatusStr(String flowStatusStr) {
-        this.flowStatusStr = flowStatusStr;
+    public void setSopStatusStr(String sopStatusStr) {
+        this.sopStatusStr = sopStatusStr;
     }
 
-    public FlowStatusEnum getFlowStatus() {
-        return flowStatus;
+    public SopStatusEnum getSopStatus() {
+        return sopStatus;
     }
 
-    public void setFlowStatus(FlowStatusEnum flowStatus) {
-        this.flowStatus = flowStatus;
+    public void setSopStatus(SopStatusEnum sopStatus) {
+        this.sopStatus = sopStatus;
     }
 
     public String getCrmNo() {

+ 34 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TBSopInfoService.java

@@ -13,6 +13,7 @@ import com.qmth.sop.business.bean.result.SopInfoResult;
 import com.qmth.sop.business.entity.TBSopInfo;
 import com.qmth.sop.business.entity.TFCustomFlow;
 import com.qmth.sop.business.entity.TFCustomFlowEntity;
+import com.qmth.sop.common.enums.SopStatusEnum;
 import com.qmth.sop.common.enums.TFCustomTypeEnum;
 
 import java.util.List;
@@ -154,4 +155,37 @@ public interface TBSopInfoService extends IService<TBSopInfo> {
      */
     public SopPublishParam setSetupOne(SopPublishParam sopPublishParam, TFCustomFlow tfCustomFlow,
             CrmProjectResult crmProjectResult) throws Exception;
+
+    /**
+     * sop转审
+     *
+     * @param crmDetailId
+     * @return
+     */
+    Boolean sopApproverExchange(Long crmDetailId) throws InterruptedException;
+
+    /**
+     * 查询sop状态
+     *
+     * @param sopNo
+     * @return
+     */
+    SopStatusEnum findBySopNo(String sopNo);
+
+    /**
+     * sop人员配置
+     *
+     * @param flowId
+     * @return
+     */
+    Boolean sopAllocation(Long flowId);
+
+    /**
+     * 修改流程第一步
+     *
+     * @param flowId
+     * @param crmDetailId
+     * @return
+     */
+    Boolean updateFlowSetupOne(Long flowId, Long crmDetailId);
 }

+ 10 - 20
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBCrmDetailServiceImpl.java

@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.api.exception.ApiException;
-import com.qmth.sop.business.activiti.service.ActivitiService;
 import com.qmth.sop.business.bean.dto.CrmDetailImportDto;
 import com.qmth.sop.business.bean.params.CrmDetailSopParam;
 import com.qmth.sop.business.bean.params.SopPublishParam;
@@ -70,9 +69,6 @@ public class TBCrmDetailServiceImpl extends ServiceImpl<TBCrmDetailMapper, TBCrm
     @Resource
     TFFlowApproveService tfFlowApproveService;
 
-    @Resource
-    ActivitiService activitiService;
-
     /**
      * 查找派单sop信息
      *
@@ -216,12 +212,11 @@ public class TBCrmDetailServiceImpl extends ServiceImpl<TBCrmDetailMapper, TBCrm
                 TBCrmDetail tbCrmDetailDb = tbCrmDetailService.getById(tbCrmDetail.getId());
                 Objects.requireNonNull(tbCrmDetailDb, "未找到派单sop信息");
 
-                FlowStatusEnum flowStatus = tbCrmDetailService.findById(tbCrmDetailDb.getId());
-                if (Objects.nonNull(flowStatus) && (flowStatus == FlowStatusEnum.FINISH
-                        || flowStatus == FlowStatusEnum.END)) {
-                    throw ExceptionResultEnum.ERROR.exception("流程已结束,无法编辑");
-                } else if (Objects.nonNull(flowStatus) && (flowStatus != FlowStatusEnum.DRAFT)) {
-                    throw ExceptionResultEnum.ERROR.exception("在途流程不支持编辑");
+                if (tbCrmDetailDb.getStatus() == CrmStatusEnum.PUBLISH) {
+                    SopStatusEnum sopStatus = tbSopInfoService.findBySopNo(tbCrmDetailDb.getSopNo());
+                    if (sopStatus == SopStatusEnum.START) {
+                        throw ExceptionResultEnum.ERROR.exception("该条sop状态已改变,请刷新页面");
+                    }
                 }
                 tbCrmDetail.updateInfo(sysUser.getId());
             }
@@ -313,16 +308,11 @@ public class TBCrmDetailServiceImpl extends ServiceImpl<TBCrmDetailMapper, TBCrm
         TBCrmDetail tbCrmDetail = tbCrmDetailService.getById(id);
         Objects.requireNonNull(tbCrmDetail, "未找到派单sop信息");
 
-        FlowStatusEnum flowStatus = tbCrmDetailService.findById(id);
-        if (Objects.nonNull(flowStatus) && (flowStatus == FlowStatusEnum.FINISH || flowStatus == FlowStatusEnum.END)) {
-            throw ExceptionResultEnum.ERROR.exception("流程已结束,无法删除");
-        } else if (Objects.nonNull(flowStatus) && (flowStatus != FlowStatusEnum.DRAFT)) {
-            throw ExceptionResultEnum.ERROR.exception("在途流程不支持删除");
-        } else if (Objects.nonNull(flowStatus)) {
-            TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
-                    new QueryWrapper<TFCustomFlowEntity>().lambda()
-                            .eq(TFCustomFlowEntity::getCode, tbCrmDetail.getSopNo()));
-            activitiService.flowEnd(tfCustomFlowEntity.getFlowId());
+        if (tbCrmDetail.getStatus() == CrmStatusEnum.PUBLISH) {
+            SopStatusEnum sopStatus = tbSopInfoService.findBySopNo(tbCrmDetail.getSopNo());
+            if (sopStatus == SopStatusEnum.START) {
+                throw ExceptionResultEnum.ERROR.exception("该条sop状态已改变,请刷新页面");
+            }
         }
         boolean result = tbCrmDetailService.removeById(tbCrmDetail.getId());
         int count = tbCrmDetailService.count(

+ 152 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBSopInfoServiceImpl.java

@@ -18,6 +18,7 @@ import com.qmth.sop.business.mapper.TBSopInfoMapper;
 import com.qmth.sop.business.service.*;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.*;
+import com.qmth.sop.common.lock.MemoryLock;
 import com.qmth.sop.common.util.JacksonUtil;
 import com.qmth.sop.common.util.ResultUtil;
 import com.qmth.sop.common.util.ServletUtil;
@@ -103,6 +104,9 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
     @Resource
     TBUserArchivesService tbUserArchivesService;
 
+    @Resource
+    MemoryLock memoryLock;
+
     /**
      * 查询动态sop表名是否存在
      *
@@ -369,6 +373,154 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
         return sopPublishParam;
     }
 
+    /**
+     * sop转审
+     *
+     * @param crmDetailId
+     * @return
+     * @throws InterruptedException
+     */
+    @Override
+    @Transactional
+    public Boolean sopApproverExchange(Long crmDetailId) throws InterruptedException {
+        TBCrmDetail tbCrmDetail = tbCrmDetailService.getById(crmDetailId);
+        Objects.requireNonNull(tbCrmDetail, "未找到派单sop信息");
+
+        if (Objects.nonNull(tbCrmDetail.getSopNo())) {
+            //已发布且状态为草稿的sop可以修改
+            if (tbCrmDetail.getStatus() == CrmStatusEnum.PUBLISH) {
+                FlowStatusEnum flowStatus = tbCrmDetailService.findById(tbCrmDetail.getId());
+                if (Objects.nonNull(flowStatus) && (flowStatus == FlowStatusEnum.FINISH
+                        || flowStatus == FlowStatusEnum.END)) {
+                    throw ExceptionResultEnum.ERROR.exception("流程已结束,无法转审");
+                }
+            }
+            TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
+                    new QueryWrapper<TFCustomFlowEntity>().lambda()
+                            .eq(TFCustomFlowEntity::getCode, tbCrmDetail.getSopNo()));
+            Optional.ofNullable(tfCustomFlowEntity)
+                    .orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
+
+            Task task = taskService.createTaskQuery().processInstanceId(tfCustomFlowEntity.getFlowId().toString())
+                    .singleResult();
+            Optional.ofNullable(task).orElseThrow(() -> ExceptionResultEnum.FLOW_TASK_NO_DATA.exception());
+            //todo 需要调曹子轩人员配置方法,项目经理变更后调用转审
+            CrmProjectResult crmProjectResult = tbCrmService.findCrmProjectInfo(tfCustomFlowEntity.getCode(),
+                    crmDetailId, tfCustomFlowEntity.getCrmNo());
+            Optional.ofNullable(crmProjectResult).orElseThrow(() -> ExceptionResultEnum.CRM_NO_NO_DATA.exception());
+            if (!CollectionUtils.isEmpty(crmProjectResult.getProjectManagerList())) {
+                activitiService.taskApproverExchange(crmProjectResult.getProjectManagerList().get(0).getUserId(),
+                        Long.parseLong(task.getId()));
+                //修改流程one里面的工程师
+                tbSopInfoService.updateFlowSetupOne(tfCustomFlowEntity.getFlowId(), tbCrmDetail.getId());
+            }
+        }
+        return true;
+    }
+
+    /**
+     * 查询sop状态
+     *
+     * @param sopNo
+     * @return
+     */
+    @Override
+    public SopStatusEnum findBySopNo(String sopNo) {
+        TBSopInfo tbSopInfo = this.getOne(new QueryWrapper<TBSopInfo>().lambda().eq(TBSopInfo::getSopNo, sopNo));
+        Objects.requireNonNull(tbSopInfo, "未找到sop信息");
+        return tbSopInfo.getStatus();
+    }
+
+    /**
+     * sop人员配置
+     *
+     * @param flowId
+     * @return
+     */
+    @Override
+    @Transactional
+    public Boolean sopAllocation(Long flowId) {
+        TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
+                new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, flowId));
+        Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
+
+        TBCrmDetail tbCrmDetail = tbCrmDetailService.findBySopNo(tfCustomFlowEntity.getCode());
+        FlowStatusEnum flowStatus = tbCrmDetailService.findById(tbCrmDetail.getId());
+        if (Objects.nonNull(flowStatus) && (flowStatus == FlowStatusEnum.FINISH || flowStatus == FlowStatusEnum.END)) {
+            throw ExceptionResultEnum.ERROR.exception("流程已结束,无法分配人员");
+        }
+        Task task = taskService.createTaskQuery().processInstanceId(flowId.toString()).singleResult();
+        Optional.ofNullable(task).orElseThrow(() -> ExceptionResultEnum.FLOW_TASK_NO_DATA.exception());
+        //todo 需要调曹子轩人员配置方法,项目经理变更后调用转审
+        CrmProjectResult crmProjectResult = tbCrmService.findCrmProjectInfo(tfCustomFlowEntity.getCode(),
+                tbCrmDetail.getId(), tfCustomFlowEntity.getCrmNo());
+        Optional.ofNullable(crmProjectResult).orElseThrow(() -> ExceptionResultEnum.CRM_NO_NO_DATA.exception());
+        if (!CollectionUtils.isEmpty(crmProjectResult.getProjectManagerList())) {
+            activitiService.taskApproverExchange(crmProjectResult.getProjectManagerList().get(0).getUserId(),
+                    Long.parseLong(task.getId()));
+            //修改流程one里面的工程师
+            tbSopInfoService.updateFlowSetupOne(tfCustomFlowEntity.getFlowId(), tbCrmDetail.getId());
+        }
+        return true;
+    }
+
+    /**
+     * 修改流程第一步
+     *
+     * @param flowId
+     * @param crmDetailId
+     * @return
+     */
+    @Override
+    @Transactional
+    public Boolean updateFlowSetupOne(Long flowId, Long crmDetailId) {
+        boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_PROPERTIES_PREFIX + crmDetailId, crmDetailId,
+                SystemConstant.LOCK_FLOW_TIME_OUT);
+        if (!lock) {
+            throw ExceptionResultEnum.ERROR.exception("正在保存数据,请稍候再试!");
+        }
+        try {
+            TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(
+                    new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, flowId));
+            Optional.ofNullable(tfCustomFlowEntity)
+                    .orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
+
+            FlowResult flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
+            LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
+            FlowTaskResult flowTaskResult = tbSopInfoService.getFormProperties(tfCustomFlowEntity, 1);
+            if (flowTaskResult.getSetup() > 0) {
+                CrmProjectResult crmProjectResult = tbCrmService.findCrmProjectInfo(tfCustomFlowEntity.getCode(),
+                        crmDetailId, tfCustomFlowEntity.getCrmNo());
+                Optional.ofNullable(crmProjectResult).orElseThrow(() -> ExceptionResultEnum.CRM_NO_NO_DATA.exception());
+                List<FlowFormWidgetResult> flowFormWidgetResultList = flowTaskResult.getFormProperty();
+                for (FlowFormWidgetResult f : flowFormWidgetResultList) {
+                    if (f.getFormId().contains(ProcessLimitedEnum.ENGINEER_USERS_ID.getKey())) {
+                        List<String> list = new ArrayList<>(crmProjectResult.getEngineerList().size());
+                        crmProjectResult.getEngineerList().stream().peek(s -> list.add(s.getUserId().toString()))
+                                .collect(Collectors.toList());
+                        JSONObject jsonObject = new JSONObject();
+                        jsonObject.put(SystemConstant.VALUE, list);
+                        f.setValue(jsonObject.toJSONString());
+                        break;
+                    }
+                }
+            }
+            setupMap.put(flowTaskResult.getTaskKey(), flowTaskResult);
+            tfCustomFlowEntity.setFlowProcessVar(JacksonUtil.parseJson(flowResult));
+            return tfCustomFlowEntityService.updateById(tfCustomFlowEntity);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        } finally {
+            memoryLock.unlock(SystemConstant.LOCK_FLOW_PROPERTIES_PREFIX + crmDetailId);
+        }
+        return false;
+    }
+
     /**
      * sop填报信息
      *

+ 2 - 2
sop-business/src/main/resources/mapper/TBCrmDetailMapper.xml

@@ -3,9 +3,9 @@
 <mapper namespace="com.qmth.sop.business.mapper.TBCrmDetailMapper">
 
     <select id="list" resultType="com.qmth.sop.business.entity.TBCrmDetail">
-        select t.*,tffa.status as flowStatus from t_b_crm_detail t
+        select t.*,tbsi.status as sopStatus from t_b_crm_detail t
         left join t_f_custom_flow_entity tfcfe on tfcfe.code = t.sop_no
-        left join t_f_flow_approve tffa on tffa.flow_id = tfcfe.flow_id
+        left join t_b_sop_info tbsi on tbsi.sop_no = t.sop_no
         where t.crm_no = #{crmNo}
     </select>
 </mapper>

+ 1 - 0
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -356,6 +356,7 @@ public class SystemConstant {
     public static final String LOCK_FLOW_TASK_PREFIX = "lock:flow:task:";//流程节点锁
     public static final String LOCK_FLOW_END_PREFIX = "lock:flow:end:";//流程结束锁
     public static final String LOCK_FLOW_EXCHANGE_PREFIX = "lock:flow:exchange:";//流程转办锁
+    public static final String LOCK_FLOW_PROPERTIES_PREFIX = "lock:flow:properties:";//流程修改属性锁
     public static final String LOCK_SEQUENCE_PREFIX = "lock:sequence:";//序列锁
     public static final String LOCK_JOB_PREFIX = "lock:job:";//定时任务锁
     public static final String LOCK_CRM_DETAIL_SOP_IMPORT_PREFIX = "lock:crm:detail:sop:import";//派单明细sop锁