|
|
@@ -1,14 +1,23 @@
|
|
|
package cn.iocoder.yudao.module.bpm.service.oa.entry;
|
|
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
|
|
|
+import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.entry.OaEntryPageReqVO;
|
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.entry.OaEntrySaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskApproveReqVO;
|
|
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.OaEntryDO;
|
|
|
import cn.iocoder.yudao.module.bpm.dal.mysql.oa.OaEntryMapper;
|
|
|
+import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
|
|
|
+import org.flowable.engine.RuntimeService;
|
|
|
+import org.flowable.engine.TaskService;
|
|
|
+import org.flowable.engine.runtime.ProcessInstance;
|
|
|
+import org.flowable.task.api.Task;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
import java.util.*;
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
@@ -16,7 +25,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
|
|
|
|
-
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
@@ -29,14 +37,110 @@ import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
|
|
|
@Validated
|
|
|
public class OaEntryServiceImpl implements OaEntryService {
|
|
|
|
|
|
+ /**
|
|
|
+ * OA 入职对应的流程定义 KEY
|
|
|
+ */
|
|
|
+ public static final String PROCESS_KEY = "oa_entry_workflow";
|
|
|
+
|
|
|
@Resource
|
|
|
private OaEntryMapper oaEntryMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private BpmProcessInstanceApi processInstanceApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BpmTaskService bpmTaskService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TaskService taskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RuntimeService runtimeService;
|
|
|
+
|
|
|
@Override
|
|
|
- public Integer createOaEntry(OaEntrySaveReqVO createReqVO) {
|
|
|
+ public Integer startOaEntry(Long userId, OaEntrySaveReqVO createReqVO) {
|
|
|
+ //判断是否已经发起流程
|
|
|
+ Boolean auditPass = createReqVO.getAuditPass();
|
|
|
// 插入
|
|
|
OaEntryDO oaEntry = BeanUtils.toBean(createReqVO, OaEntryDO.class);
|
|
|
oaEntryMapper.insert(oaEntry);
|
|
|
+ //如果提交
|
|
|
+ if (auditPass){
|
|
|
+ // 发起 BPM 流程
|
|
|
+ Map<String, Object> processInstanceVariables = new HashMap<>();
|
|
|
+ processInstanceVariables.put("auditPass",auditPass);
|
|
|
+ String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
|
|
+ new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
|
|
+ .setVariables(processInstanceVariables).setBusinessKey(String.valueOf(oaEntry.getId()))
|
|
|
+ .setStartUserSelectAssignees(createReqVO.getStartUserSelectAssignees()));
|
|
|
+
|
|
|
+ //获取下一个审批人
|
|
|
+ Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
|
|
|
+
|
|
|
+ // 将工作流的编号,单据状态 表单uuid 最后一次审批时间 当前审批人 更新到 OA 入职中
|
|
|
+ oaEntryMapper.updateById(new OaEntryDO().setId(oaEntry.getId()).setProcInstId(processInstanceId).setAuditStatus("1")
|
|
|
+ .setEntryId(IdUtil.fastSimpleUUID()).setFinalAuditDate(new Date()).setCurrentAuditEmployeeId(task.getAssignee()));
|
|
|
+ }else {
|
|
|
+ // 将单据状态 表单uuid 更新到 OA入职中
|
|
|
+ oaEntryMapper.updateById(new OaEntryDO().setId(oaEntry.getId()).setAuditStatus("0").setEntryId(UUID.randomUUID().toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 站内信发送
|
|
|
+ // loanInfoService.sendMassage(actBaseInfo);
|
|
|
+ // 返回
|
|
|
+ return oaEntry.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer completeOaEntry(Long userId, OaEntrySaveReqVO createReqVO, BpmTaskApproveReqVO reqVO) {
|
|
|
+ //判断是否已经发起流程
|
|
|
+ Boolean auditPass = createReqVO.getAuditPass();
|
|
|
+ // 修改
|
|
|
+ OaEntryDO oaEntry = BeanUtils.toBean(createReqVO, OaEntryDO.class);
|
|
|
+// oaEntryMapper.updateById(oaEntry);
|
|
|
+ //判断当前单据是否存在流程实例id,如果不存在说明没有发起流程
|
|
|
+ if (oaEntry.getProcInstId() == null && oaEntry.getProcInstId().equals("")) {
|
|
|
+ // 提交
|
|
|
+ if (createReqVO.getAuditPass()) {
|
|
|
+ // 发起 BPM 流程
|
|
|
+ Map<String, Object> processInstanceVariables = new HashMap<>();
|
|
|
+ processInstanceVariables.put("auditPass", auditPass);
|
|
|
+ String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
|
|
+ new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
|
|
+ .setVariables(processInstanceVariables).setBusinessKey(String.valueOf(oaEntry.getId()))
|
|
|
+ .setStartUserSelectAssignees(createReqVO.getStartUserSelectAssignees()));
|
|
|
+
|
|
|
+ // 将工作流的编号,单据状态 更新到 OA 入职中
|
|
|
+ oaEntryMapper.updateById(new OaEntryDO().setId(oaEntry.getId()).setProcInstId(processInstanceId).setAuditStatus("1"));
|
|
|
+ }else {
|
|
|
+ // 暂存 将单据状态 更新到 OA 入职中
|
|
|
+ oaEntryMapper.updateById(new OaEntryDO().setId(oaEntry.getId()).setAuditStatus("0"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //同意
|
|
|
+ if (createReqVO.getAuditPass()) {
|
|
|
+ //审批通过
|
|
|
+ bpmTaskService.approveTask(userId,reqVO);
|
|
|
+ //判断流程是否结束
|
|
|
+ ProcessInstance procIns = runtimeService.createProcessInstanceQuery().processInstanceId(createReqVO.getProcInstId()).active().singleResult();
|
|
|
+ if (procIns != null) {
|
|
|
+ //说明流程结束
|
|
|
+ //获取下一个审批人
|
|
|
+ Task task = taskService.createTaskQuery().processInstanceId(createReqVO.getProcInstId()).singleResult();
|
|
|
+ // 将单据状态 当前审批人 最后一次审批时间 更新到 OA 入职中
|
|
|
+ oaEntryMapper.updateById(new OaEntryDO().setId(oaEntry.getId()).setAuditStatus("2").setCurrentAuditEmployeeId(task.getAssignee())
|
|
|
+ .setFinalAuditDate(new Date()));
|
|
|
+ }else {
|
|
|
+ //流程结束
|
|
|
+ //todo 复制信息到入职信息表中
|
|
|
+
|
|
|
+ // 将单据状态 更新到 OA 入职中
|
|
|
+ oaEntryMapper.updateById(new OaEntryDO().setId(oaEntry.getId()).setAuditStatus("3").setCurrentAuditEmployeeId(" ").setFinalAuditDate(new Date()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // todo 站内信发送
|
|
|
+ // loanInfoService.sendMassage(actBaseInfo);
|
|
|
// 返回
|
|
|
return oaEntry.getId();
|
|
|
}
|
|
|
@@ -55,7 +159,9 @@ public class OaEntryServiceImpl implements OaEntryService {
|
|
|
// 校验存在
|
|
|
validateOaEntryExists(id);
|
|
|
// 删除
|
|
|
- oaEntryMapper.deleteById(id);
|
|
|
+// oaEntryMapper.deleteById(id);
|
|
|
+ // 将单据状态 更新到 OA 入职中
|
|
|
+ oaEntryMapper.updateById((OaEntryDO) new OaEntryDO().setId(id).setDeleted(true));
|
|
|
}
|
|
|
|
|
|
private void validateOaEntryExists(Integer id) {
|