Commit a7c5a8a9 by “zcwang”

modify: 发起变更

parent 34f84e9a
......@@ -16,6 +16,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import com.alibaba.fastjson.JSON;
import com.netease.mail.yanxuan.change.biz.config.AppConfig;
......@@ -23,6 +24,7 @@ import com.netease.mail.yanxuan.change.biz.meta.exception.ExceptionFactory;
import com.netease.mail.yanxuan.change.biz.service.ChangeFlowService;
import com.netease.mail.yanxuan.change.biz.service.change.ChangeConfigService;
import com.netease.mail.yanxuan.change.common.bean.CommonConstants;
import com.netease.mail.yanxuan.change.common.bean.RequestLocalBean;
import com.netease.mail.yanxuan.change.common.bean.ResponseCode;
import com.netease.mail.yanxuan.change.common.bean.ResponseCodeEnum;
import com.netease.mail.yanxuan.change.common.enums.ChangeFlowEnum;
......@@ -34,6 +36,7 @@ import com.netease.mail.yanxuan.change.common.util.DateUtils;
import com.netease.mail.yanxuan.change.dal.entity.ChangeRecord;
import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeExecConfigReq;
import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeFlowCreateReq;
import com.netease.mail.yanxuan.change.dal.meta.model.req.ChangeFlowReq;
import com.netease.mail.yanxuan.change.integration.flow.FlowRpcService;
import com.netease.yanxuan.flowx.sdk.meta.controller.communal.AjaxResponse;
import com.netease.yanxuan.flowx.sdk.meta.dto.base.FlowDataDTO;
......@@ -62,11 +65,11 @@ public class ChangeFlowBiz {
@Autowired
private FlowRpcService flowRpcService;
public List<String> createAndSubmit(ChangeFlowCreateReq changeFlowCreateReq) {
public String createAndSubmit(ChangeFlowCreateReq changeFlowCreateReq) {
// String uid = RequestLocalBean.getUid();
String uid = "1";
// String name = RequestLocalBean.getName();
String name = "x@mesg.com";
// String userName = RequestLocalBean.getName();
String userName = "x@mesg.com";
// 校验变更主体
Boolean containsChangeSubject = ChangeSubjectEnum.getByType(changeFlowCreateReq.getChangeSubject());
Assert.isTrue(containsChangeSubject, "变更主体不存在");
......@@ -85,28 +88,39 @@ public class ChangeFlowBiz {
Long tomorrowSpecificTime = DateUtils.getTomorrowSpecificTime("09:00:00");
Assert.isTrue(changeFlowCreateReq.getChangeConfirmResultTime() >= tomorrowSpecificTime, "时间不可晚于下次执行时间");
Map<String, Object> content = new HashMap<>(10);
content.put("createUserName", name);
content.put("createUserName", userName);
content.put("createUser", uid);
content.put("createTime", System.currentTimeMillis());
content.put("updateTime", System.currentTimeMillis());
content.put(CommonConstants.FLOW_OPERATION_KEY, FlowOperationTypeEnum.PASS.getValue());
// 组装工单创建数据
FlowCreateReqDTO flowCreateReqDTO = buildFlowCreateReqDTO(ChangeFlowEnum.CHANGE_FLOW_CONFIRM.getTopoId(), uid, name, JSON.toJSONString(content),
FlowxOperationEnum.CREATE.getName());
FlowCreateReqDTO flowCreateReqDTO = buildFlowCreateReqDTO(ChangeFlowEnum.CHANGE_FLOW_START.getTopoId(), uid,
userName, JSON.toJSONString(content), FlowxOperationEnum.CREATE.getName());
// 创建工单
String flowId = createFlow(flowCreateReqDTO);
// 查询工单详情
FlowDataDTO flowDataDTO = detailFlow(flowId);
FlowDataDTO flowDataDTO = flowDetail(flowId);
String nodeId = flowDataDTO.getFlowMeta().getCurrNodeDataList().get(0).getNodeId();
// todo: 根据类型查询负责人详情,格式邮箱
String changeCommander = "";
// 保存工单数据
ChangeRecord changeRecord = buildRecord(flowId, nodeId, changeFlowCreateReq);
ChangeRecord changeRecord = buildRecord(flowId, nodeId, changeFlowCreateReq, changeCommander);
changeFlowService.saveRecord(changeRecord);
Integer occLock = flowDataDTO.getOccLock();
// todo:判断发起人和审核人
// 如果发起人=变更负责人
return submitFlow(flowId, nodeId, occLock, flowCreateReqDTO);
if (true) {
List<String> nextNodeIdList = submitFlow(flowId, flowDataDTO, uid, userName,
ChangeFlowEnum.CHANGE_FLOW_START.getTopoId(), JSON.toJSONString(content));
if (CollectionUtils.isEmpty(nextNodeIdList)) {
throw ExceptionFactory.createBiz(ResponseCode.SUBMIT_FLOW_ERROR, "首次提交节点失败");
}
return nextNodeIdList.get(0);
}
return flowId;
}
private FlowDataDTO detailFlow(String flowId) {
private FlowDataDTO flowDetail(String flowId) {
// 查询工单详情,根据详情提交
FlowDataDTO flowDataDTO;
AjaxResponse<FlowDataDTO> flowDetailResponse = flowRpcService.getDetail(CommonConstants.FLOWX_PRODUCT, flowId);
......@@ -115,13 +129,14 @@ public class ChangeFlowBiz {
log.info("[detailFlow] flowDataDTO={}", JSON.toJSONString(flowDataDTO));
} else {
log.error("[detailFlow] get flow detail failed, query={}, errMsg={}", JSON.toJSONString(flowId),
JSON.toJSONString(flowDetailResponse));
throw ExceptionFactory.createBiz(ResponseCode.DETAIL_FLOW_ERROR, flowDetailResponse.getErrorMsg());
JSON.toJSONString(flowDetailResponse));
throw ExceptionFactory.createBiz(ResponseCode.DETAIL_FLOW_ERROR, "查询工单详情错误");
}
return flowDataDTO;
}
private FlowCreateReqDTO buildFlowCreateReqDTO(String topoId, String uid, String userName, String content, String operateResult) {
private FlowCreateReqDTO buildFlowCreateReqDTO(String topoId, String uid, String userName, String content,
String operateResult) {
FlowCreateReqDTO flowCreateReqDTO = new FlowCreateReqDTO();
flowCreateReqDTO.setTopoId(topoId);
flowCreateReqDTO.setUid(uid);
......@@ -131,29 +146,31 @@ public class ChangeFlowBiz {
return flowCreateReqDTO;
}
private List<String> submitFlow(String flowId, String nodeId, Integer occLock, FlowCreateReqDTO flowCreateReqDTO) {
private List<String> submitFlow(String flowId, FlowDataDTO flowDataDTO, String uid, String userName, String topoId,
String content) {
NodeSubmitReqDTO nodeSubmitReqDTO = new NodeSubmitReqDTO();
nodeSubmitReqDTO.setFlowId(flowId);
nodeSubmitReqDTO.setNodeId(nodeId);
nodeSubmitReqDTO.setUid(flowCreateReqDTO.getUid());
nodeSubmitReqDTO.setUserName(flowCreateReqDTO.getUserName());
nodeSubmitReqDTO.setFlowId(flowId);
nodeSubmitReqDTO.setTopoId(flowCreateReqDTO.getTopoId());
nodeSubmitReqDTO.setContent(flowCreateReqDTO.getContent());
nodeSubmitReqDTO.setNodeId(flowDataDTO.getFlowMeta().getCurrNodeDataList().get(0).getNodeId());
nodeSubmitReqDTO.setUid(uid);
nodeSubmitReqDTO.setUserName(userName);
nodeSubmitReqDTO.setTopoId(topoId);
nodeSubmitReqDTO.setContent(content);
nodeSubmitReqDTO.setOperateResult(FlowxOperationEnum.SUBMIT.getName());
nodeSubmitReqDTO.setCreateTime(System.currentTimeMillis());
nodeSubmitReqDTO.setApproved(true);
nodeSubmitReqDTO.setOccLock(occLock + 1);
nodeSubmitReqDTO.setOccLock(flowDataDTO.getOccLock() + 1);
log.info("[submitFlow] nodeSubmitReqDTO={}", JSON.toJSONString(nodeSubmitReqDTO));
List<String> nextNodeIdList;
// 提交工单
AjaxResponse<List<String>> submitResponse = flowRpcService.submit(CommonConstants.FLOWX_PRODUCT, nodeSubmitReqDTO);
AjaxResponse<List<String>> submitResponse = flowRpcService.submit(CommonConstants.FLOWX_PRODUCT,
nodeSubmitReqDTO);
if (ResponseCodeEnum.SUCCESS.getCode() == submitResponse.getCode()) {
nextNodeIdList = submitResponse.getData();
log.info("[submitFlow] nextNodeIdList={}", JSON.toJSONString(nextNodeIdList));
} else {
log.error("[submitFlow] submit flow failed, query={}, errMsg={}", JSON.toJSONString(nodeSubmitReqDTO),
JSON.toJSONString(submitResponse));
throw ExceptionFactory.createBiz(ResponseCode.SUBMIT_FLOW_ERROR, submitResponse.getErrorMsg());
JSON.toJSONString(submitResponse));
throw ExceptionFactory.createBiz(ResponseCode.SUBMIT_FLOW_ERROR, "提交工单错误");
}
return nextNodeIdList;
}
......@@ -169,12 +186,12 @@ public class ChangeFlowBiz {
} else {
log.error("[createFlow] create flow failed, query={}, errMsg={}", JSON.toJSONString(flowCreateReqDTO),
JSON.toJSONString(flowCreateResponse));
throw ExceptionFactory.createBiz(ResponseCode.CREATE_FLOW_ERROR, flowCreateResponse.getErrorMsg());
throw ExceptionFactory.createBiz(ResponseCode.CREATE_FLOW_ERROR, "创建工单错误");
}
return flowId;
}
private ChangeRecord buildRecord(String flowId, String nodeId, ChangeFlowCreateReq changeFlowCreateReq) {
private ChangeRecord buildRecord(String flowId, String nodeId, ChangeFlowCreateReq changeFlowCreateReq, String changeCommander) {
ChangeRecord changeRecord = new ChangeRecord();
changeRecord.setFlowId(Long.parseLong(flowId));
changeRecord.setFlowNode(nodeId);
......@@ -182,32 +199,63 @@ public class ChangeFlowBiz {
changeRecord.setParentChangeClassId(changeFlowCreateReq.getParentChangeClassId());
changeRecord.setSonChangeClassId(changeFlowCreateReq.getSonChangeClassId());
changeRecord.setChangeLevel(changeFlowCreateReq.getChangeLevel());
changeRecord.setChangeCommander(changeFlowCreateReq.getChangeCommander());
// todo: 查询负责人
changeRecord.setChangeCommander("");
changeRecord.setChangeDepartment(changeFlowCreateReq.getChangeDepartment());
List<ChangeExecConfigReq> changeExecProject = changeFlowCreateReq.getChangeExecProject();
List<String> execDepartmentList = changeExecProject.stream().map(ChangeExecConfigReq::getChangeExecDepartment)
.collect(Collectors.toList());
changeRecord.setParticipateChangeExecDepartment(JSON.toJSONString(execDepartmentList));
// todo: 当变更类型是商品时有值
changeRecord.setChangeItem(changeFlowCreateReq.getChangeItems());
// todo: 当变更类型是供应商时有效
changeRecord.setChangeSupplier(changeFlowCreateReq.getChangeSupplier());
changeRecord.setChangeReason(changeFlowCreateReq.getChangeReason());
changeRecord.setChangeContent(changeFlowCreateReq.getChangeContent());
changeRecord.setChangeChecking("");
changeRecord.setChangeRiskDesc(changeFlowCreateReq.getChangeRiskDesc());
changeRecord.setChangeProfit(changeFlowCreateReq.getChangeProfit());
changeRecord.setChangeProfitDesc(changeFlowCreateReq.getChangeProfitDesc());
changeRecord.setChangeConfirmResultTime(changeFlowCreateReq.getChangeConfirmResultTime());
changeRecord.setState(ChangeStatusEnum.IN.getStatus());
changeRecord.setIsCancel(0);
// 变更结论
changeRecord.setChangeResult(1);
changeRecord.setCreateSource(changeFlowCreateReq.getCreateSource());
changeRecord.setCreateSupplier(changeFlowCreateReq.getChangeSupplier());
changeRecord.setChangeResultDesc("");
changeRecord.setRemark("");
changeRecord.setCreator("");
changeRecord.setCreateTime(DateUtils.getCurrentTime());
changeRecord.setUpdateTime(DateUtils.getCurrentTime());
return changeRecord;
}
public String submit(ChangeFlowReq changeFlowReq) {
log.info("[submit] changeFlowReq:{}", JSON.toJSONString(changeFlowReq));
Long flowId = changeFlowReq.getFlowId();
// 查询工单有效性
ChangeRecord changeRecord = changeFlowService.getByFlowId(flowId);
if (changeRecord == null) {
throw ExceptionFactory.createBiz(ResponseCode.ERROR_FLOW_ID, "工单id不存在");
}
if (!changeRecord.getFlowNode().equals(changeFlowReq.getCurrentNodeId())) {
throw ExceptionFactory.createBiz(ResponseCode.NODE_ERROR, "工单已流转至其他节点");
}
// todo:检验操作权限
// String uid = RequestLocalBean.getUid();
String userName = RequestLocalBean.getName();
String uid = "1";
String changeCommander = changeRecord.getChangeCommander();
if (!uid.equals(changeCommander)) {
throw ExceptionFactory.createBiz(ResponseCode.NO_AUTH, ResponseCode.NO_AUTH.getMsg());
}
// 获取工单详情
FlowDataDTO flowDataDTO = this.flowDetail(flowId.toString());
// 工单流传
Map<String, Object> content = new HashMap<>(CommonConstants.INIT_HASH_MAP_SIZE);
content.put("updateTime", System.currentTimeMillis());
content.put(CommonConstants.FLOW_OPERATION_KEY, FlowOperationTypeEnum.PASS.getValue());
List<String> nextNodeList = this.submitFlow(flowId.toString(), flowDataDTO, uid, userName,
ChangeFlowEnum.CHANGE_FLOW_SUBMIT.getTopoId(), JSON.toJSONString(content));
if (CollectionUtils.isEmpty(nextNodeList)) {
return ChangeFlowEnum.END.getNodeId();
}
return nextNodeList.get(0);
}
}
......@@ -21,5 +21,18 @@ public interface ChangeFlowService {
*/
TitleConfig getTitleConfig();
/**
* 保存工单详情
* @param changeRecord
* @return
*/
Boolean saveRecord(ChangeRecord changeRecord);
/**
* 根据工单id查询
* @param flowId
* @return
*/
ChangeRecord getByFlowId(Long flowId);
}
\ No newline at end of file
......@@ -38,4 +38,9 @@ public class ChangeFlowServiceImpl implements ChangeFlowService {
public Boolean saveRecord(ChangeRecord changeRecord) {
return changeRecordMapper.insertSelective(changeRecord) > 0;
}
@Override
public ChangeRecord getByFlowId(Long flowId) {
return changeRecordMapper.selectByFlowId(flowId);
}
}
\ No newline at end of file
......@@ -15,6 +15,8 @@ public class CommonConstants {
// 工单业务数据操作key
public static final String FLOW_OPERATION_KEY = "operation";;
public static final int INIT_HASH_MAP_SIZE = 10;
public static Integer SIZE = 1;
public static Integer PAGE = 10;
......
......@@ -122,7 +122,10 @@ public enum ResponseCode {
CREATE_FLOW_ERROR(1001, "创建工单错误"),
DETAIL_FLOW_ERROR(1002, "查询工单详情错误"),
SUBMIT_FLOW_ERROR(1002, "查询工单详情错误"),
SUBMIT_FLOW_ERROR(1002, "提交工单错误"),
ERROR_FLOW_ID(1003, "工单id不存在"),
NODE_ERROR(1004, "工单已流转至其他节点"),
NO_AUTH(1005, "没有当前节点操作权限"),
//----------10xx-----------
......
......@@ -13,7 +13,8 @@ package com.netease.mail.yanxuan.change.common.enums;
public enum ChangeStatusEnum {
IN(1, "进行中"),
END(2, "完结");
CANCEL(2, "取消"),
END(3, "完结");
private Integer status;
......
......@@ -130,7 +130,7 @@ public class ChangeRecord {
/**
* 是否被取消
*/
private Integer isCancel;
private String cancelReason;
/**
* 变更结论
......
......@@ -7,6 +7,8 @@
package com.netease.mail.yanxuan.change.dal.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.netease.mail.yanxuan.change.dal.entity.ChangeRecord;
......@@ -16,4 +18,7 @@ import com.netease.mail.yanxuan.change.dal.entity.ChangeRecord;
*/
@Mapper
public interface ChangeRecordMapper extends tk.mybatis.mapper.common.Mapper<ChangeRecord> {
@Select("select * from TB_YX_QC_CHANGE_RECORD where `flow_id` = #{flowId}")
ChangeRecord selectByFlowId(@Param("flowId") Long flowId);
}
\ No newline at end of file
......@@ -8,6 +8,10 @@ package com.netease.mail.yanxuan.change.dal.meta.model.req;
import java.util.List;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Data;
/**
......@@ -20,7 +24,15 @@ public class ChangeFlowReq {
/**
* 工单id
*/
private long flowId;
@NotNull(message = "工单id不能为空")
private Long flowId;
/**
* 当前节点id
*/
@NotBlank(message = "当前节点不能为空")
private String currentNodeId;
/**
* 一级类型id
*/
......
......@@ -75,7 +75,7 @@ public class ChangeFlowController {
* @return
*/
@PostMapping("/create")
public AjaxResult<List<String>> createAndSubmit(@RequestBody @Valid ChangeFlowCreateReq changeFlowCreateReq) {
public AjaxResult<String> createAndSubmit(@RequestBody @Valid ChangeFlowCreateReq changeFlowCreateReq) {
log.info("[createAndSubmit] createAndSubmit req={}", JSON.toJSONString(changeFlowCreateReq));
return AjaxResult.success(changeFlowBiz.createAndSubmit(changeFlowCreateReq));
}
......@@ -85,9 +85,8 @@ public class ChangeFlowController {
* @return
*/
@PostMapping("/submit")
public AjaxResult<Boolean> submit(@RequestBody ChangeFlowReq changeFlowReq) {
return AjaxResult.success();
public AjaxResult<String> submit(@RequestBody @Valid ChangeFlowReq changeFlowReq) {
return AjaxResult.success(changeFlowBiz.submit(changeFlowReq));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment