|
@@ -1,9 +1,14 @@
|
|
|
package com.qmth.sop.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+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.sop.business.activiti.service.ActivitiService;
|
|
|
import com.qmth.sop.business.bean.params.FlowApproveParam;
|
|
|
+import com.qmth.sop.business.bean.result.FlowFormWidgetResult;
|
|
|
+import com.qmth.sop.business.bean.result.FlowResult;
|
|
|
+import com.qmth.sop.business.bean.result.FlowTaskResult;
|
|
|
import com.qmth.sop.business.bean.result.TBQualityProblemApplyResult;
|
|
|
import com.qmth.sop.business.entity.SysUser;
|
|
|
import com.qmth.sop.business.entity.TBQualityProblemApply;
|
|
@@ -12,19 +17,18 @@ import com.qmth.sop.business.mapper.TBQualityProblemApplyMapper;
|
|
|
import com.qmth.sop.business.service.TBQualityProblemApplyService;
|
|
|
import com.qmth.sop.business.service.TFCustomFlowEntityService;
|
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
|
-import com.qmth.sop.common.enums.FlowApprovePassEnum;
|
|
|
-import com.qmth.sop.common.enums.InfluenceDegreeEnum;
|
|
|
-import com.qmth.sop.common.enums.QualityProblemReasonEnum;
|
|
|
-import com.qmth.sop.common.enums.QualityProblemTypeEnum;
|
|
|
+import com.qmth.sop.common.enums.*;
|
|
|
+import com.qmth.sop.common.util.GsonUtil;
|
|
|
import com.qmth.sop.common.util.ServletUtil;
|
|
|
+import org.activiti.engine.TaskService;
|
|
|
+import org.activiti.engine.task.Task;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -45,6 +49,12 @@ public class TBQualityProblemApplyServiceImpl extends ServiceImpl<TBQualityProbl
|
|
|
@Resource
|
|
|
ActivitiService activitiService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ TBQualityProblemApplyService tbQualityProblemApplyService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TaskService taskService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询列表
|
|
|
*
|
|
@@ -64,13 +74,75 @@ public class TBQualityProblemApplyServiceImpl extends ServiceImpl<TBQualityProbl
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Boolean saveTBQualityProblemApply(TBQualityProblemApply tbQualityProblemApply) throws InterruptedException {
|
|
|
+ if (tbQualityProblemApply.getFlowApprove() != FlowApprovePassEnum.START && tbQualityProblemApply.getFlowApprove() != FlowApprovePassEnum.DRAFT) {
|
|
|
+ throw ExceptionResultEnum.PARAMS_ERROR.exception("流程审批只能为提交或草稿");
|
|
|
+ }
|
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+
|
|
|
+ FlowTaskResult currFlowTaskResult = JSONObject.parseObject(tbQualityProblemApply.getFormProperties(), FlowTaskResult.class);
|
|
|
+ tbQualityProblemApply = this.updateFieldValue(currFlowTaskResult, tbQualityProblemApply);
|
|
|
+
|
|
|
Map<String, Object> map = activitiService.taskApprove(new FlowApproveParam(tbQualityProblemApply.getFlowDeploymentId(), FlowApprovePassEnum.START, tbQualityProblemApply.getFormProperties(), Arrays.asList(String.valueOf(sysUser.getId())), tbQualityProblemApply.getCrmNo()));
|
|
|
TFCustomFlowEntity tfCustomFlowEntity = (TFCustomFlowEntity) map.get(SystemConstant.FLOW_ENTITY);
|
|
|
tbQualityProblemApply.setCode(tfCustomFlowEntity.getCode(), tbQualityProblemApply.getAttachmentIdList(), tbQualityProblemApply.getUserIdList(), sysUser.getId());
|
|
|
tfCustomFlowEntity.setObjId(tbQualityProblemApply.getId());
|
|
|
tfCustomFlowEntityService.updateById(tfCustomFlowEntity);
|
|
|
- return this.saveOrUpdate(tbQualityProblemApply);
|
|
|
+ return tbQualityProblemApplyService.save(tbQualityProblemApply);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 质量问题反馈审核
|
|
|
+ *
|
|
|
+ * @param flowApproveParam
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean flowApprove(FlowApproveParam flowApproveParam) throws InterruptedException {
|
|
|
+ if (Objects.isNull(flowApproveParam.getTaskId())) {
|
|
|
+ throw ExceptionResultEnum.PARAMS_ERROR.exception("流程节点id不能为空");
|
|
|
+ }
|
|
|
+ if (flowApproveParam.getApprove() != FlowApprovePassEnum.PASS && flowApproveParam.getApprove() != FlowApprovePassEnum.REJECT && flowApproveParam.getApprove() != FlowApprovePassEnum.DRAFT) {
|
|
|
+ throw ExceptionResultEnum.PARAMS_ERROR.exception("sop填报只能为通过或驳回或草稿");
|
|
|
+ }
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ Task task = taskService.createTaskQuery().taskId(String.valueOf(flowApproveParam.getTaskId())).singleResult();
|
|
|
+ Optional.ofNullable(task).orElseThrow(() -> ExceptionResultEnum.FLOW_TASK_NO_DATA.exception());
|
|
|
+
|
|
|
+ List<Long> taskApproveUserList = activitiService.getTaskApprove(task);
|
|
|
+ if (flowApproveParam.getApprove() != FlowApprovePassEnum.DRAFT && !CollectionUtils.isEmpty(taskApproveUserList) && !taskApproveUserList.contains(sysUser.getId())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("不能审批他人的sop数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, Long.parseLong(task.getProcessInstanceId())));
|
|
|
+ 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 currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(task.getTaskDefinitionKey())), FlowTaskResult.class);
|
|
|
+
|
|
|
+ String approveUserId = null;
|
|
|
+ if (Objects.nonNull(currFlowTaskResult) && currFlowTaskResult.getSetup().intValue() > 1) {
|
|
|
+ FlowTaskResult flowTaskResultTemp = null;
|
|
|
+ for (Map.Entry<String, FlowTaskResult> entry : setupMap.entrySet()) {
|
|
|
+ flowTaskResultTemp = GsonUtil.fromJson(GsonUtil.toJson(entry.getValue()), FlowTaskResult.class);
|
|
|
+ if (flowTaskResultTemp.getSetup().intValue() == 2) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.getApproveUserIds(flowTaskResultTemp, currFlowTaskResult.getSetup(), approveUserId);
|
|
|
+ } else {
|
|
|
+ approveUserId = task.getAssignee();
|
|
|
+ }
|
|
|
+ TBQualityProblemApply tbQualityProblemApply = this.getOne(new QueryWrapper<TBQualityProblemApply>().lambda().eq(TBQualityProblemApply::getProblemNo, tfCustomFlowEntity.getCode()));
|
|
|
+ Optional.ofNullable(tbQualityProblemApply).orElseThrow(() -> ExceptionResultEnum.QUALITY_PROBLEM_APPLY_NO_DATA.exception());
|
|
|
+
|
|
|
+ tbQualityProblemApply = this.updateFieldValue(currFlowTaskResult, tbQualityProblemApply);
|
|
|
+ List<String> approveUserIds = Objects.nonNull(approveUserId) ? Arrays.asList(approveUserId) : Arrays.asList(String.valueOf(sysUser.getId()));
|
|
|
+ flowApproveParam.setApproveUserIds(approveUserIds);
|
|
|
+ activitiService.taskApprove(flowApproveParam);
|
|
|
+
|
|
|
+ tbQualityProblemApply.updateInfo(sysUser.getId());
|
|
|
+ return this.updateById(tbQualityProblemApply);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -85,4 +157,67 @@ public class TBQualityProblemApplyServiceImpl extends ServiceImpl<TBQualityProbl
|
|
|
return this.removeByIds(idList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取审批人
|
|
|
+ *
|
|
|
+ * @param flowTaskResult
|
|
|
+ * @param setup
|
|
|
+ * @param approveUserId
|
|
|
+ */
|
|
|
+ public void getApproveUserIds(FlowTaskResult flowTaskResult, Integer setup, String approveUserId) {
|
|
|
+ List<FlowFormWidgetResult> formProperty = flowTaskResult.getFormProperty();
|
|
|
+ for (FlowFormWidgetResult f : formProperty) {
|
|
|
+ if (setup.intValue() == 2 && f.getFormId().contains(SystemConstant.APPROVE_CHECK_USERS) && Objects.nonNull(f.getValue())) {//获取甲方复核人员
|
|
|
+ String string = f.getValue().replaceAll("\\[", "").replaceAll("\\]", "");
|
|
|
+ approveUserId = StringUtils.join(Arrays.asList(string), SystemConstant.LIST_JOIN_SPLIT);
|
|
|
+ break;
|
|
|
+ } else if (setup.intValue() == 3 && f.getFormId().contains(SystemConstant.APPROVE_CHECK_THIRD_USERS) && Objects.nonNull(f.getValue())) {//获取已方复核人员
|
|
|
+ String string = f.getValue().replaceAll("\\[", "").replaceAll("\\]", "");
|
|
|
+ approveUserId = StringUtils.join(Arrays.asList(string), SystemConstant.LIST_JOIN_SPLIT);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (setup.intValue() == 2 && Objects.isNull(approveUserId)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("甲方复核人不能为空");
|
|
|
+ } else if (setup.intValue() == 3 && Objects.isNull(approveUserId)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("已方复核人不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新字段
|
|
|
+ *
|
|
|
+ * @param currFlowTaskResult
|
|
|
+ * @param tbQualityProblemApply
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public TBQualityProblemApply updateFieldValue(FlowTaskResult currFlowTaskResult, TBQualityProblemApply tbQualityProblemApply) {
|
|
|
+ List<FlowFormWidgetResult> formWidgetResultList = currFlowTaskResult.getFormProperty();
|
|
|
+ if (!CollectionUtils.isEmpty(formWidgetResultList)) {//更新字段
|
|
|
+ for (FlowFormWidgetResult t : formWidgetResultList) {
|
|
|
+ if (t.getFormId().contains(SystemConstant.PROBLEM_POINT)) {//问题简要
|
|
|
+ tbQualityProblemApply.setSummary(t.getValue());
|
|
|
+ }
|
|
|
+ if (t.getFormId().contains(SystemConstant.PROBLEM_REMARK)) {//问题情况说明
|
|
|
+ tbQualityProblemApply.setRemark(t.getValue());
|
|
|
+ }
|
|
|
+ if (t.getFormId().contains(SystemConstant.ATTACHMENT_INFO)) {//附件id数组
|
|
|
+ tbQualityProblemApply.setAttachmentIds(t.getValue());
|
|
|
+ }
|
|
|
+ if (t.getFormId().contains(SystemConstant.PROBLEM_TYPE)) {//质量问题类型
|
|
|
+ tbQualityProblemApply.setType(QualityProblemTypeEnum.valueOf(t.getValue()));
|
|
|
+ }
|
|
|
+ if (t.getFormId().contains(SystemConstant.PROBLEM_REASON_RADIO)) {//问题归因
|
|
|
+ tbQualityProblemApply.setReason(QualityProblemReasonEnum.valueOf(t.getValue()));
|
|
|
+ }
|
|
|
+ if (t.getFormId().contains(SystemConstant.PROBLEM_DEGREE_RADIO)) {//问题影响度
|
|
|
+ tbQualityProblemApply.setInfluenceDegree(InfluenceDegreeEnum.valueOf(t.getValue()));
|
|
|
+ }
|
|
|
+ if (t.getFormId().contains(SystemConstant.PROBLEM_USERS)) {//责任人
|
|
|
+ tbQualityProblemApply.setUserIds(t.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return tbQualityProblemApply;
|
|
|
+ }
|
|
|
}
|