|
@@ -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填报信息
|
|
|
*
|