package org.jeecg.modules.dncFlow.service.impl;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.google.common.collect.Lists;
|
import org.apache.shiro.SecurityUtils;
|
import org.flowable.engine.TaskService;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.system.vo.LoginUser;
|
import org.jeecg.modules.dnc.entity.*;
|
import org.jeecg.modules.dnc.exception.ExceptionCast;
|
import org.jeecg.modules.dnc.mapper.DocInfoMapper;
|
import org.jeecg.modules.dnc.request.DocInfoQueryRequest;
|
import org.jeecg.modules.dnc.response.ActivitiCode;
|
import org.jeecg.modules.dnc.response.CommonCode;
|
import org.jeecg.modules.dnc.response.UcenterCode;
|
import org.jeecg.modules.dnc.service.*;
|
import org.jeecg.modules.dnc.utils.ValidateUtil;
|
import org.jeecg.modules.dncFlow.entity.DispatchFile;
|
import org.jeecg.modules.dncFlow.mapper.DispatchFileMapper;
|
import org.jeecg.modules.dncFlow.service.IDispatchFileService;
|
import org.jeecg.modules.dncFlow.vo.DispatchFileFlowTaskVo;
|
import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
|
import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService;
|
import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI;
|
import org.jeecg.modules.flowable.apithird.service.FlowCommonService;
|
import org.jeecg.modules.flowable.service.IFlowDefinitionService;
|
import org.jeecg.modules.flowable.service.IFlowTaskService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @Description: nc程序与电子图版签派
|
* @Author: jeecg-boot
|
* @Date: 2025-03-19
|
* @Version: V1.0
|
*/
|
@Service("IDispatchFileService")
|
public class DispatchFileServiceImpl extends ServiceImpl<DispatchFileMapper, DispatchFile> implements IDispatchFileService, FlowCallBackServiceI {
|
|
@Autowired
|
@Lazy
|
private IDocInfoService docInfoService;
|
@Autowired
|
private IProcessStreamService processStreamService;
|
@Autowired
|
private IWorkStepService workStepService;
|
@Autowired
|
private IPermissionStreamNewService permissionStreamNewService;
|
@Resource
|
private FlowCommonService flowCommonService;
|
@Resource
|
private IFlowDefinitionService flowDefinitionService;
|
@Autowired
|
private IFlowTaskService flowTaskService;
|
@Autowired
|
private IDeviceTypeService deviceTypeService;
|
@Autowired
|
private TaskService taskService;
|
@Autowired
|
private IFlowMyBusinessService flowMyBusinessService;
|
@Autowired
|
private DocInfoMapper docInfoMapper;
|
/**
|
* 流程启动,保存对应的数据
|
* @param dispatchFile
|
* @return
|
*/
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public Result<?> saveDispatchFile(DispatchFile dispatchFile){
|
//校验参数
|
checkParam(dispatchFile);
|
//获取文件信息
|
DocInfo docInfo = docInfoService.getById(dispatchFile.getDocId());
|
PermissionStreamNew permissionStreams = getPermissionStreams(dispatchFile);
|
if (permissionStreams==null){
|
return Result.error("用户没有权限");
|
}
|
dispatchFile.setAttributionType(dispatchFile.getAttributionType());
|
dispatchFile.setAttributionId(dispatchFile.getAttributionId());
|
dispatchFile.setDocClassCode(dispatchFile.getDocClassCode());
|
super.save(dispatchFile);
|
System.out.println("NC程序和电子样板审签流程:" + dispatchFile.getDocId());
|
flowCommonService.initActBusiness(docInfo.getDocName()+"."+docInfo.getDocSuffix()+"文件进行审签",
|
dispatchFile.getId(), "IDispatchFileService", "nc_dispatch_file", null);
|
Map<String, Object> variables = new HashMap<>();
|
variables.put("dataId", dispatchFile.getId());
|
variables.put("organization", "导入文档默认启动流程");
|
variables.put("proofreading",true);
|
Result result= flowDefinitionService.startProcessInstanceByKey("nc_dispatch_file", variables);
|
if (!result.isSuccess()) {
|
super.removeById(dispatchFile.getId());
|
}else {
|
docInfo.setDocDispatchStatus(1);
|
docInfoService.updateById(docInfo);
|
}
|
return result;
|
}
|
|
/**
|
* 重新启动
|
* @param id
|
*/
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public Result<?> reStartDispatchFile(String id){
|
DispatchFile dispatchFile = this.getById(id);
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
if (!dispatchFile.getCreateBy().equals(user.getUsername())){
|
return Result.error("您没有权限重新启动");
|
}
|
FlowMyBusiness flowMyBusiness=flowMyBusinessService.list(new QueryWrapper<FlowMyBusiness>()
|
.eq("data_id",dispatchFile.getId())).get(0);
|
String processInstanceId = flowMyBusiness.getProcessInstanceId();
|
Map<String, Object> variables = new HashMap<>();
|
variables.put("dataId", dispatchFile.getId());
|
variables.put("organization", "重新启动");
|
String TaskId=taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult().getId();
|
taskService.complete(TaskId, variables);
|
return Result.ok("重新启动成功");
|
}
|
|
/**
|
* 审批操作
|
* @param dispatchFileFlowTaskVo
|
* @return
|
*/
|
@Override
|
public Result<?> auditDispatchFile(DispatchFileFlowTaskVo dispatchFileFlowTaskVo) {
|
try {
|
// 参数校验
|
if (!ValidateUtil.validateString(dispatchFileFlowTaskVo.getTaskId()) || !ValidateUtil.validateString(dispatchFileFlowTaskVo.getDataId())) {
|
return Result.error(CommonCode.INVALID_PARAM.toString());
|
}
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
String userId = user.getId();
|
dispatchFileFlowTaskVo.setAssignee(user.getUsername());
|
if (!ValidateUtil.validateString(userId)) {
|
return Result.error(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST.toString());
|
}
|
|
// 数据查询
|
DispatchFile dispatchFile = this.getById(dispatchFileFlowTaskVo.getDataId());
|
if (dispatchFile == null) {
|
return Result.error(CommonCode.INVALID_PARAM.toString());
|
}
|
DocInfo docInfo = docInfoService.getById(dispatchFile.getDocId());
|
if (docInfo == null) {
|
return Result.error(ActivitiCode.ACT_DOC_ERROR.toString());
|
}
|
|
// 设置流程变量
|
Map<String, Object> values = setProcessVariables(dispatchFile, userId, dispatchFileFlowTaskVo);
|
dispatchFileFlowTaskVo.setValues(values);
|
|
// 完成流程任务
|
Result result = flowTaskService.complete(dispatchFileFlowTaskVo);
|
if (result.isSuccess()) {
|
// 更新状态
|
updateStatus(dispatchFile, docInfo, dispatchFileFlowTaskVo);
|
docInfoService.updateById(docInfo);
|
this.updateById(dispatchFile);
|
} else {
|
return result;
|
}
|
|
return Result.OK("操作成功");
|
} catch (Exception e) {
|
return Result.error("操作失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 查询审签基本信息
|
* @param id
|
*/
|
public Result<?> queryDispatchFile(String id){
|
DispatchFile dispatchFile=this.getById(id);
|
if (dispatchFile==null){
|
return Result.error("审签基本信息不存在");
|
}
|
DocInfoQueryRequest docInfoQueryRequest=new DocInfoQueryRequest();
|
docInfoQueryRequest.setDocId(dispatchFile.getDocId());
|
docInfoQueryRequest.setAttributionId(dispatchFile.getAttributionId());
|
docInfoQueryRequest.setAttributionType(Integer.valueOf(dispatchFile.getAttributionType()));
|
docInfoQueryRequest.setDocClassCode(dispatchFile.getDocClassCode());
|
List<DocInfo> docInfoList = docInfoService.findList(docInfoQueryRequest);
|
return Result.OK(docInfoList);
|
}
|
|
private Map<String, Object> setProcessVariables(DispatchFile dispatchFile, String userId, DispatchFileFlowTaskVo dispatchFileFlowTaskVo) {
|
Map<String, Object> values = new HashMap<>();
|
values.put("dataId", dispatchFile.getId());
|
values.put("organization", dispatchFile.getOrganization());
|
values.put("assignee", userId);
|
values.put("comment", dispatchFileFlowTaskVo.getComment());
|
|
if (StrUtil.isNotBlank(dispatchFileFlowTaskVo.getProofreadStatus())) {
|
values.put("proofreadStatus", dispatchFileFlowTaskVo.getProofreadStatus());
|
}
|
if (dispatchFileFlowTaskVo.getRatify() != null) {
|
values.put("ratify", dispatchFileFlowTaskVo.getRatify());
|
}
|
if (dispatchFileFlowTaskVo.getCut() != null) {
|
values.put("cut", dispatchFileFlowTaskVo.getCut());
|
}
|
if (dispatchFileFlowTaskVo.getStereotype() != null) {
|
values.put("stereotype", dispatchFileFlowTaskVo.getStereotype());
|
}
|
return values;
|
}
|
|
private void updateStatus(DispatchFile dispatchFile, DocInfo docInfo, DispatchFileFlowTaskVo dispatchFileFlowTaskVo) {
|
if (StrUtil.isNotBlank(dispatchFileFlowTaskVo.getProofreadStatus())) {
|
switch (dispatchFileFlowTaskVo.getProofreadStatus()) {
|
case "1":
|
// 直接定型
|
dispatchFile.setCurrentNode("5");
|
docInfo.setDocDispatchStatus(5);
|
break;
|
case "2":
|
// 校对通过
|
dispatchFile.setCurrentNode("2");
|
docInfo.setDocDispatchStatus(2);
|
break;
|
default:
|
// 校对不通过
|
dispatchFile.setCurrentNode("1");
|
docInfo.setDocDispatchStatus(1);
|
break;
|
}
|
}
|
if (dispatchFileFlowTaskVo.getRatify() != null && dispatchFileFlowTaskVo.getRatify()) {
|
dispatchFile.setCurrentNode("3");
|
docInfo.setDocDispatchStatus(3);
|
}
|
if (dispatchFileFlowTaskVo.getCut() != null && dispatchFileFlowTaskVo.getCut()) {
|
dispatchFile.setCurrentNode("4");
|
docInfo.setDocDispatchStatus(4);
|
}
|
if (dispatchFileFlowTaskVo.getStereotype() != null && dispatchFileFlowTaskVo.getStereotype()) {
|
dispatchFile.setCurrentNode("5");
|
docInfo.setDocDispatchStatus(5);
|
}
|
}
|
|
//传参验证
|
public boolean checkParam(DispatchFile dispatchFile) {
|
if (dispatchFile == null) {
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
}
|
if (!ValidateUtil.validateString(dispatchFile.getAttributionId()) || !ValidateUtil.validateString(dispatchFile.getDocId())
|
|| !ValidateUtil.validateString(dispatchFile.getFileId()) || !ValidateUtil.validateString(dispatchFile.getAttributionType())) {
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
}
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
String userId = user.getId();
|
if (!ValidateUtil.validateString(userId)) {
|
ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
}
|
return true;
|
}
|
|
//获取文件信息
|
private DocInfo getDocInfo(DispatchFile dispatchFile) {
|
DocInfo docInfo = docInfoService.getByDocAttrAndDocId(dispatchFile.getDocId(),
|
Integer.parseInt(dispatchFile.getAttributionType()), dispatchFile.getAttributionId());
|
if (docInfo == null || docInfo.getDocStatus() == 3) {
|
ExceptionCast.cast(ActivitiCode.ACT_DOC_ERROR);
|
}
|
return docInfo;
|
}
|
|
|
private PermissionStreamNew getPermissionStreams(DispatchFile dispatchFile) {
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
DeviceType deviceType = deviceTypeService.getById(dispatchFile.getAttributionId());
|
String attributionId = deviceType != null ? deviceType.getAttributionId() : dispatchFile.getAttributionId();
|
|
PermissionStreamNew permissionStreams;
|
if (dispatchFile.getAttributionType().equals("5")) {
|
// 工序
|
permissionStreams = handleProcess(dispatchFile, attributionId, user);
|
} else {
|
// 工步
|
permissionStreams = handleWorkStep(dispatchFile, attributionId, user);
|
}
|
if (permissionStreams == null) {
|
ExceptionCast.cast(ActivitiCode.ACT_NODE_DEPART_NONE);
|
}
|
return permissionStreams;
|
}
|
|
private PermissionStreamNew handleProcess(DispatchFile dispatchFile, String attributionId, LoginUser user) {
|
ProcessStream processStream = processStreamService.getById(attributionId);
|
if (processStream == null) {
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
}
|
dispatchFile.setProductId(processStream.getProductId());
|
dispatchFile.setComponentId(processStream.getComponentId());
|
dispatchFile.setPartsId(processStream.getPartsId());
|
dispatchFile.setPsvId(processStream.getPsvId());
|
dispatchFile.setProcessId(processStream.getProcessId());
|
if (deviceTypeService.getById(dispatchFile.getAttributionId()) != null) {
|
dispatchFile.setDeviceTypeId(deviceTypeService.getById(dispatchFile.getAttributionId()).getId());
|
}
|
return permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processStream.getProcessId(), user.getId(), "5");
|
}
|
|
private PermissionStreamNew handleWorkStep(DispatchFile dispatchFile, String attributionId, LoginUser user) {
|
WorkStep workStep = workStepService.getById(attributionId);
|
if (workStep == null) {
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
}
|
dispatchFile.setProductId(workStep.getProductId());
|
dispatchFile.setComponentId(workStep.getComponentId());
|
dispatchFile.setPartsId(workStep.getPartsId());
|
dispatchFile.setPsvId(workStep.getPsvId());
|
dispatchFile.setProcessId(workStep.getProcessId());
|
dispatchFile.setStepId(workStep.getId());
|
if (deviceTypeService.getById(dispatchFile.getAttributionId()) != null) {
|
dispatchFile.setDeviceTypeId(deviceTypeService.getById(dispatchFile.getAttributionId()).getId());
|
}
|
return permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(workStep.getId(), user.getId(), "6");
|
}
|
|
@Override
|
public void afterFlowHandle(FlowMyBusiness business) {
|
business.getTaskNameId();//接下来审批的节点
|
business.getValues();//前端传进来的参数
|
business.getActStatus();
|
}
|
|
@Override
|
public Object getBusinessDataById(String dataId) {
|
return this.getById(dataId);
|
}
|
|
@Override
|
public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) {
|
return null;
|
}
|
|
@Override
|
public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) {
|
String dataId = values.get("dataId").toString();
|
FlowMyBusiness flowMyBusiness=flowMyBusinessService.list(new QueryWrapper<FlowMyBusiness>().eq("data_id",dataId)).get(0);
|
return Lists.newArrayList(flowMyBusiness.getCreateBy());
|
}
|
}
|