✨ 解耦MK表单实例与业务ID,公开页按formInstanceId反查业务数据
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+9
-3
@@ -13,6 +13,7 @@ import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.process.pojo.dto.ApprovalDTO;
|
||||
import org.springblade.process.pojo.vo.ApprovalVO;
|
||||
import org.springblade.process.pojo.vo.ProcessApprovedRecordVO;
|
||||
@@ -55,22 +56,27 @@ public class BusinessProcessController extends BladeController {
|
||||
|
||||
@PostMapping("/processSubmit")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "提交MK审核流", description = "调用mk processSubmit,传入templateCode/submitIdentity/formInstanceId")
|
||||
@Operation(summary = "提交MK审核流", description = "传入bizId/bizType/templateCode,后端生成或复用formInstanceId后调用mk processSubmit")
|
||||
public R<String> processSubmit(@Validated @RequestBody MKProcessCreateDTO param) {
|
||||
return R.data(businessProcessService.processSubmit(param));
|
||||
}
|
||||
|
||||
@GetMapping("/hasMkProcessInstance")
|
||||
@ApiOperationSupport(order = 8)
|
||||
@Operation(summary = "查询MK流程实例是否存在", description = "传入业务id(formInstanceId),有数据则无需删除/重新提交")
|
||||
@Operation(summary = "查询MK流程实例是否存在", description = "传入业务主键bizId,有数据则无需删除/重新提交")
|
||||
public R<Boolean> hasMkProcessInstance(@Valid @NotBlank(message = "业务id不能为空") String bizId) {
|
||||
return R.data(businessProcessService.hasMkProcessInstance(bizId));
|
||||
}
|
||||
|
||||
@PostMapping("/processDelete")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "删除MK审核流", description = "传入bizId,删除当前业务对应MK流程实例")
|
||||
public R<Boolean> processDelete(@RequestBody MKProcessCreateDTO param) {
|
||||
return R.data(businessProcessService.processDelete(param == null ? null : param.getFormInstanceId()));
|
||||
String bizId = null;
|
||||
if (param != null) {
|
||||
bizId = StringUtil.isNotBlank(param.getBizId()) ? param.getBizId() : param.getFormInstanceId();
|
||||
}
|
||||
return R.data(businessProcessService.processDelete(bizId));
|
||||
}
|
||||
|
||||
@GetMapping("/isEditView")
|
||||
|
||||
+8
@@ -11,6 +11,7 @@ import org.springblade.process.pojo.dto.BusinessProcessDeleteDTO;
|
||||
import org.springblade.process.pojo.dto.BusinessProcessSubmitDTO;
|
||||
import org.springblade.process.pojo.dto.BusinessProcessUpdateDTO;
|
||||
import org.springblade.process.pojo.vo.BusinessProcessVO;
|
||||
import org.springblade.process.pojo.vo.MkFormBindVO;
|
||||
import org.springblade.process.pojo.vo.ProcessApprovedRecordVO;
|
||||
import org.springblade.process.pojo.vo.ProcessTodoVO;
|
||||
import org.springblade.process.service.IBusinessProcessService;
|
||||
@@ -94,4 +95,11 @@ public class BusinessProcessClient implements IBusinessProcessClient {
|
||||
@RequestParam(value = "loginName", required = false) String loginName) {
|
||||
return FR.data(businessProcessService.getProcessInfo(processInstanceId, loginName));
|
||||
}
|
||||
|
||||
@PreAuth(AuthConstant.PERMIT_ALL)
|
||||
@GetMapping(RESOLVE_BY_FORM_INSTANCE_ID)
|
||||
@Override
|
||||
public FR<MkFormBindVO> resolveByFormInstanceId(@RequestParam("formInstanceId") Long formInstanceId) {
|
||||
return FR.data(businessProcessService.resolveByFormInstanceId(formInstanceId));
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -6,6 +6,7 @@
|
||||
<resultMap id="businessProcessResultMap" type="org.springblade.process.pojo.entity.BusinessProcess">
|
||||
<result column="id" property="id"/>
|
||||
<result column="biz_id" property="bizId"/>
|
||||
<result column="form_instance_id" property="formInstanceId"/>
|
||||
<result column="process_instance_id" property="processInstanceId"/>
|
||||
<result column="process_type" property="processType"/>
|
||||
<result column="doc_code" property="docCode"/>
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.process.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springblade.process.pojo.entity.MkFormBind;
|
||||
|
||||
/**
|
||||
* MK表单实例绑定表 Mapper 接口
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public interface MkFormBindMapper extends BaseMapper<MkFormBind> {
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.springblade.process.mapper.MkFormBindMapper">
|
||||
|
||||
<resultMap id="mkFormBindResultMap" type="org.springblade.process.pojo.entity.MkFormBind">
|
||||
<result column="id" property="id"/>
|
||||
<result column="tenant_id" property="tenantId"/>
|
||||
<result column="biz_type" property="bizType"/>
|
||||
<result column="biz_id" property="bizId"/>
|
||||
<result column="form_instance_id" property="formInstanceId"/>
|
||||
<result column="process_instance_id" property="processInstanceId"/>
|
||||
<result column="is_current" property="isCurrent"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
+13
-5
@@ -29,7 +29,7 @@ public interface IBusinessProcessService extends IService<BusinessProcess> {
|
||||
/**
|
||||
* 直接调用 MK processSubmit 提交流程
|
||||
*
|
||||
* @param param MK 流程创建参数
|
||||
* @param param MK 流程创建参数(传 bizId+bizType,后端生成/复用 formInstanceId)
|
||||
* @return 流程实例 id
|
||||
*/
|
||||
String processSubmit(MKProcessCreateDTO param);
|
||||
@@ -37,18 +37,26 @@ public interface IBusinessProcessService extends IService<BusinessProcess> {
|
||||
/**
|
||||
* 按业务 id 查询 MK 流程实例是否仍有数据(本地有 processInstanceId 且 MK getProcessInfo 有返回)
|
||||
*
|
||||
* @param bizId 业务 id(如客商 id / formInstanceId)
|
||||
* @param bizId 业务主键
|
||||
* @return true=流程实例仍存在
|
||||
*/
|
||||
boolean hasMkProcessInstance(String bizId);
|
||||
|
||||
/**
|
||||
* 按业务表单实例 id 删除 MK 流程(不删除本地业务流程记录,供驳回后重新提交使用)
|
||||
* 按业务主键删除 MK 流程(不删除本地业务流程记录与表单绑定,供驳回后重新提交使用)
|
||||
*
|
||||
* @param formInstanceId 业务表单实例 id
|
||||
* @param bizId 业务主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean processDelete(String formInstanceId);
|
||||
boolean processDelete(String bizId);
|
||||
|
||||
/**
|
||||
* 按表单实例id解析业务绑定
|
||||
*
|
||||
* @param formInstanceId 表单实例id
|
||||
* @return 绑定信息
|
||||
*/
|
||||
MkFormBindVO resolveByFormInstanceId(Long formInstanceId);
|
||||
|
||||
/**
|
||||
* 获取流程当前节点详情
|
||||
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.process.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springblade.process.pojo.entity.MkFormBind;
|
||||
import org.springblade.process.pojo.vo.MkFormBindVO;
|
||||
|
||||
/**
|
||||
* MK表单实例绑定表 服务类
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public interface IMkFormBindService extends IService<MkFormBind> {
|
||||
|
||||
/**
|
||||
* 查询业务当前生效的表单实例绑定
|
||||
*
|
||||
* @param bizType 业务类型(可空,空时仅按业务id查)
|
||||
* @param bizId 业务主键
|
||||
* @return 当前绑定,不存在返回 null
|
||||
*/
|
||||
MkFormBind getCurrentBind(String bizType, Long bizId);
|
||||
|
||||
/**
|
||||
* 按表单实例id查询绑定
|
||||
*
|
||||
* @param formInstanceId 表单实例id
|
||||
* @return 绑定记录
|
||||
*/
|
||||
MkFormBind getByFormInstanceId(Long formInstanceId);
|
||||
|
||||
/**
|
||||
* 按表单实例id解析业务主键等信息
|
||||
*
|
||||
* @param formInstanceId 表单实例id
|
||||
* @return 绑定 VO
|
||||
*/
|
||||
MkFormBindVO resolveByFormInstanceId(Long formInstanceId);
|
||||
|
||||
/**
|
||||
* 解析或生成表单实例id:无当前绑定则新建;当前流程已审批通过则新建;否则复用
|
||||
*
|
||||
* @param bizType 业务类型
|
||||
* @param bizId 业务主键
|
||||
* @return 本次应使用的表单实例id
|
||||
*/
|
||||
Long resolveOrCreateFormInstanceId(String bizType, Long bizId);
|
||||
|
||||
/**
|
||||
* 回写流程实例id到当前绑定
|
||||
*
|
||||
* @param formInstanceId 表单实例id
|
||||
* @param processInstanceId 流程实例id
|
||||
*/
|
||||
void updateProcessInstanceId(Long formInstanceId, String processInstanceId);
|
||||
}
|
||||
+78
-18
@@ -25,6 +25,7 @@ import org.springblade.process.pojo.entity.BusinessProcess;
|
||||
import org.springblade.process.pojo.enums.TodoStatus;
|
||||
import org.springblade.process.pojo.vo.*;
|
||||
import org.springblade.process.service.IBusinessProcessService;
|
||||
import org.springblade.process.service.IMkFormBindService;
|
||||
import org.springblade.system.pojo.entity.User;
|
||||
import org.springblade.system.service.IUserService;
|
||||
import org.springblade.thirdparty.mk.config.MKProperties;
|
||||
@@ -72,6 +73,7 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
private final IUserService userService;
|
||||
private final ICustomerArchiveClient customerArchiveClient;
|
||||
private final IMkProcessClient mkProcessClient;
|
||||
private final IMkFormBindService mkFormBindService;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
@@ -129,7 +131,6 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
@Override
|
||||
public String processSubmit(MKProcessCreateDTO param) {
|
||||
AssertUtils.notNull(param, "提交流程参数不能为空");
|
||||
AssertUtils.notBlank(param.getFormInstanceId(), "表单实例id不能为空");
|
||||
AssertUtils.notBlank(param.getTemplateCode(), "模板编码不能为空");
|
||||
// 前端拿到的手机号可能经 @Sensitive 脱敏(如 137****8880),这里从库取真实手机号覆盖
|
||||
String loginName = resolveCurrentUserPhone();
|
||||
@@ -138,36 +139,39 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
param.setLoginName(loginName);
|
||||
String bizType = param.getBizType();
|
||||
|
||||
Long bizId;
|
||||
try {
|
||||
bizId = Long.valueOf(param.getFormInstanceId());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ServiceException("表单实例id格式不正确");
|
||||
}
|
||||
Long bizId = resolveBizIdFromSubmitParam(param);
|
||||
Long formInstanceId = mkFormBindService.resolveOrCreateFormInstanceId(bizType, bizId);
|
||||
String formInstanceIdText = String.valueOf(formInstanceId);
|
||||
param.setFormInstanceId(formInstanceIdText);
|
||||
|
||||
BusinessProcess businessProcess = this.getOne(Wrappers.<BusinessProcess>lambdaQuery()
|
||||
.eq(BusinessProcess::getBizId, bizId)
|
||||
.orderByDesc(BusinessProcess::getUpdateTime)
|
||||
.last("limit 1")
|
||||
);
|
||||
// 已有流程实例且 MK 仍能查到详情时,不再删除、不再重新创建提交
|
||||
if (businessProcess != null && StringUtil.isNotBlank(businessProcess.getProcessInstanceId())) {
|
||||
if (businessProcess != null && StringUtil.isNotBlank(businessProcess.getProcessInstanceId())
|
||||
&& Objects.equals(formInstanceId, businessProcess.getFormInstanceId())) {
|
||||
String existingProcessInstanceId = businessProcess.getProcessInstanceId();
|
||||
Object existingProcessInfo = this.getProcessInfo(existingProcessInstanceId, loginName);
|
||||
if (hasProcessInfoData(existingProcessInfo)) {
|
||||
log.info("MK流程实例已存在,跳过创建并提交流程 formInstanceId={} processInstanceId={}",
|
||||
param.getFormInstanceId(), existingProcessInstanceId);
|
||||
log.info("MK流程实例已存在,跳过创建并提交流程 bizId={} formInstanceId={} processInstanceId={}",
|
||||
bizId, formInstanceIdText, existingProcessInstanceId);
|
||||
businessProcess.setApproveStatus(ApproveStatusEnum.APPROVING.getValue());
|
||||
if (StringUtil.isNotBlank(param.getSubject())) {
|
||||
businessProcess.setSubject(param.getSubject());
|
||||
}
|
||||
businessProcess.setPromoterLoginName(loginName);
|
||||
businessProcess.setFormInstanceId(formInstanceId);
|
||||
this.updateById(businessProcess);
|
||||
this.getCurrentNodes(existingProcessInstanceId, loginName);
|
||||
this.syncBizFromProcessInfo(bizType, param.getFormInstanceId(), existingProcessInfo);
|
||||
this.syncBizFromProcessInfo(bizType, String.valueOf(bizId), existingProcessInfo);
|
||||
return existingProcessInstanceId;
|
||||
}
|
||||
}
|
||||
|
||||
MKProcessCreateDTO mkParam = new MKProcessCreateDTO();
|
||||
mkParam.setFormInstanceId(param.getFormInstanceId());
|
||||
mkParam.setFormInstanceId(formInstanceIdText);
|
||||
mkParam.setSubject(param.getSubject());
|
||||
mkParam.setSubmitIdentity(loginName);
|
||||
mkParam.setLoginName(loginName);
|
||||
@@ -197,15 +201,35 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
businessProcess.setSubmitTime(new Date());
|
||||
}
|
||||
}
|
||||
businessProcess.setFormInstanceId(formInstanceId);
|
||||
businessProcess.setProcessInstanceId(processInstanceId);
|
||||
businessProcess.setApproveStatus(ApproveStatusEnum.APPROVING.getValue());
|
||||
businessProcess.setIsCompleted(0);
|
||||
businessProcess.setCompleteTime(null);
|
||||
this.saveOrUpdate(businessProcess);
|
||||
mkFormBindService.updateProcessInstanceId(formInstanceId, processInstanceId);
|
||||
this.getCurrentNodes(processInstanceId, loginName);
|
||||
Object processInfo = this.getProcessInfo(processInstanceId, loginName);
|
||||
this.syncBizFromProcessInfo(bizType, param.getFormInstanceId(), processInfo);
|
||||
this.syncBizFromProcessInfo(bizType, String.valueOf(bizId), processInfo);
|
||||
return processInstanceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从提交参数解析业务主键:优先 bizId,兼容旧调用把业务id放在 formInstanceId
|
||||
*/
|
||||
private Long resolveBizIdFromSubmitParam(MKProcessCreateDTO param) {
|
||||
String bizIdText = param.getBizId();
|
||||
if (StringUtil.isBlank(bizIdText)) {
|
||||
bizIdText = param.getFormInstanceId();
|
||||
}
|
||||
AssertUtils.notBlank(bizIdText, "业务id不能为空");
|
||||
try {
|
||||
return Long.valueOf(bizIdText);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ServiceException("业务id格式不正确");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMkProcessInstance(String bizId) {
|
||||
AssertUtils.notBlank(bizId, "业务id不能为空");
|
||||
@@ -217,11 +241,16 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
}
|
||||
BusinessProcess businessProcess = this.getOne(Wrappers.<BusinessProcess>lambdaQuery()
|
||||
.eq(BusinessProcess::getBizId, id)
|
||||
.orderByDesc(BusinessProcess::getUpdateTime)
|
||||
.last("limit 1")
|
||||
);
|
||||
if (businessProcess == null || StringUtil.isBlank(businessProcess.getProcessInstanceId())) {
|
||||
return false;
|
||||
}
|
||||
// 审批通过后允许再次提交新表单实例,视为当前无有效待办流程
|
||||
if (Objects.equals(ApproveStatusEnum.APPROVED.getValue(), businessProcess.getApproveStatus())) {
|
||||
return false;
|
||||
}
|
||||
String loginName = businessProcess.getPromoterLoginName();
|
||||
if (StringUtil.isBlank(loginName)) {
|
||||
loginName = resolveCurrentUserPhone();
|
||||
@@ -257,18 +286,20 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean processDelete(String formInstanceId) {
|
||||
AssertUtils.notBlank(formInstanceId, "表单实例id不能为空");
|
||||
AssertUtils.notBlank(formInstanceId, "业务id不能为空");
|
||||
Long bizId;
|
||||
try {
|
||||
bizId = Long.valueOf(formInstanceId);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ServiceException("表单实例id格式不正确");
|
||||
throw new ServiceException("业务id格式不正确");
|
||||
}
|
||||
BusinessProcess businessProcess = this.getOne(Wrappers.<BusinessProcess>lambdaQuery()
|
||||
.eq(BusinessProcess::getBizId, bizId)
|
||||
.orderByDesc(BusinessProcess::getUpdateTime)
|
||||
.last("limit 1")
|
||||
);
|
||||
if (businessProcess == null || StringUtil.isBlank(businessProcess.getProcessInstanceId())) {
|
||||
log.warn("客商驳回后删除流程跳过,未找到流程实例 formInstanceId={}", formInstanceId);
|
||||
log.warn("驳回后删除流程跳过,未找到流程实例 bizId={}", bizId);
|
||||
return true;
|
||||
}
|
||||
String loginName = businessProcess.getPromoterLoginName();
|
||||
@@ -276,8 +307,8 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
loginName = resolveCurrentUserPhone();
|
||||
}
|
||||
AssertUtils.notBlank(loginName, "当前用户手机号为空,无法删除审核流");
|
||||
log.info("调用mk processDelete processInstanceId={} loginName={} formInstanceId={}",
|
||||
businessProcess.getProcessInstanceId(), loginName, formInstanceId);
|
||||
log.info("调用mk processDelete processInstanceId={} loginName={} bizId={} formInstanceId={}",
|
||||
businessProcess.getProcessInstanceId(), loginName, bizId, businessProcess.getFormInstanceId());
|
||||
boolean deleted = mkService.processDelete(businessProcess.getProcessInstanceId(), loginName);
|
||||
if (!deleted) {
|
||||
throw new ServiceException("删除MK流程失败");
|
||||
@@ -285,6 +316,35 @@ public class BusinessProcessServiceImpl extends ServiceImpl<BusinessProcessMappe
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MkFormBindVO resolveByFormInstanceId(Long formInstanceId) {
|
||||
AssertUtils.notNull(formInstanceId, "表单实例id不能为空");
|
||||
MkFormBindVO bindVO = mkFormBindService.resolveByFormInstanceId(formInstanceId);
|
||||
if (bindVO != null) {
|
||||
return bindVO;
|
||||
}
|
||||
// 兼容未迁移历史:formInstanceId 曾等于 bizId
|
||||
BusinessProcess businessProcess = this.getOne(Wrappers.<BusinessProcess>lambdaQuery()
|
||||
.eq(BusinessProcess::getBizId, formInstanceId)
|
||||
.last("limit 1")
|
||||
);
|
||||
if (businessProcess == null) {
|
||||
businessProcess = this.getOne(Wrappers.<BusinessProcess>lambdaQuery()
|
||||
.eq(BusinessProcess::getFormInstanceId, formInstanceId)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
if (businessProcess == null) {
|
||||
return null;
|
||||
}
|
||||
MkFormBindVO fallback = new MkFormBindVO();
|
||||
fallback.setBizId(businessProcess.getBizId());
|
||||
fallback.setFormInstanceId(businessProcess.getFormInstanceId() != null
|
||||
? businessProcess.getFormInstanceId() : businessProcess.getBizId());
|
||||
fallback.setProcessInstanceId(businessProcess.getProcessInstanceId());
|
||||
return fallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> getCurrentNodes(String processInstanceId, String loginName) {
|
||||
if (StringUtils.isBlank(processInstanceId)) {
|
||||
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.process.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.log.utils.AssertUtils;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.process.mapper.BusinessProcessMapper;
|
||||
import org.springblade.process.mapper.MkFormBindMapper;
|
||||
import org.springblade.process.pojo.entity.BusinessProcess;
|
||||
import org.springblade.process.pojo.entity.MkFormBind;
|
||||
import org.springblade.process.pojo.enums.ApproveStatusEnum;
|
||||
import org.springblade.process.pojo.vo.MkFormBindVO;
|
||||
import org.springblade.process.service.IMkFormBindService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* MK表单实例绑定表 服务实现类
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class MkFormBindServiceImpl extends ServiceImpl<MkFormBindMapper, MkFormBind> implements IMkFormBindService {
|
||||
|
||||
private final BusinessProcessMapper businessProcessMapper;
|
||||
|
||||
@Override
|
||||
public MkFormBind getCurrentBind(String bizType, Long bizId) {
|
||||
AssertUtils.notNull(bizId, "业务id不能为空");
|
||||
MkFormBind bind = null;
|
||||
if (StringUtil.isNotBlank(bizType)) {
|
||||
bind = this.getOne(Wrappers.<MkFormBind>lambdaQuery()
|
||||
.eq(MkFormBind::getBizType, bizType)
|
||||
.eq(MkFormBind::getBizId, bizId)
|
||||
.eq(MkFormBind::getIsCurrent, 1)
|
||||
.orderByDesc(MkFormBind::getCreateTime)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
if (bind == null) {
|
||||
// 兼容历史迁移数据 biz_type 为空,或未传 bizType
|
||||
bind = this.getOne(Wrappers.<MkFormBind>lambdaQuery()
|
||||
.eq(MkFormBind::getBizId, bizId)
|
||||
.eq(MkFormBind::getIsCurrent, 1)
|
||||
.orderByDesc(MkFormBind::getCreateTime)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
return bind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MkFormBind getByFormInstanceId(Long formInstanceId) {
|
||||
AssertUtils.notNull(formInstanceId, "表单实例id不能为空");
|
||||
return this.getOne(Wrappers.<MkFormBind>lambdaQuery()
|
||||
.eq(MkFormBind::getFormInstanceId, formInstanceId)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MkFormBindVO resolveByFormInstanceId(Long formInstanceId) {
|
||||
MkFormBind bind = this.getByFormInstanceId(formInstanceId);
|
||||
if (bind == null) {
|
||||
return null;
|
||||
}
|
||||
MkFormBindVO vo = new MkFormBindVO();
|
||||
vo.setBizId(bind.getBizId());
|
||||
vo.setBizType(bind.getBizType());
|
||||
vo.setFormInstanceId(bind.getFormInstanceId());
|
||||
vo.setProcessInstanceId(bind.getProcessInstanceId());
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Long resolveOrCreateFormInstanceId(String bizType, Long bizId) {
|
||||
AssertUtils.notNull(bizId, "业务id不能为空");
|
||||
MkFormBind current = this.getCurrentBind(bizType, bizId);
|
||||
if (current == null) {
|
||||
return this.createNewBind(bizType, bizId);
|
||||
}
|
||||
BusinessProcess businessProcess = businessProcessMapper.selectOne(Wrappers.<BusinessProcess>lambdaQuery()
|
||||
.eq(BusinessProcess::getBizId, bizId)
|
||||
.orderByDesc(BusinessProcess::getUpdateTime)
|
||||
.last("limit 1")
|
||||
);
|
||||
boolean approvedPass = businessProcess != null
|
||||
&& Objects.equals(ApproveStatusEnum.APPROVED.getValue(), businessProcess.getApproveStatus());
|
||||
if (approvedPass) {
|
||||
log.info("审核通过后再次提交,生成新表单实例 bizType={} bizId={} oldFormInstanceId={}",
|
||||
bizType, bizId, current.getFormInstanceId());
|
||||
this.lambdaUpdate()
|
||||
.eq(MkFormBind::getBizId, bizId)
|
||||
.eq(MkFormBind::getIsCurrent, 1)
|
||||
.set(MkFormBind::getIsCurrent, 0)
|
||||
.set(MkFormBind::getUpdateTime, new Date())
|
||||
.update();
|
||||
return this.createNewBind(bizType, bizId);
|
||||
}
|
||||
log.info("复用当前表单实例 bizType={} bizId={} formInstanceId={}",
|
||||
bizType, bizId, current.getFormInstanceId());
|
||||
if (StringUtil.isNotBlank(bizType) && StringUtil.isBlank(current.getBizType())) {
|
||||
current.setBizType(bizType);
|
||||
current.setUpdateTime(new Date());
|
||||
this.updateById(current);
|
||||
}
|
||||
return current.getFormInstanceId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProcessInstanceId(Long formInstanceId, String processInstanceId) {
|
||||
AssertUtils.notNull(formInstanceId, "表单实例id不能为空");
|
||||
this.lambdaUpdate()
|
||||
.eq(MkFormBind::getFormInstanceId, formInstanceId)
|
||||
.set(MkFormBind::getProcessInstanceId, processInstanceId)
|
||||
.set(MkFormBind::getUpdateTime, new Date())
|
||||
.update();
|
||||
}
|
||||
|
||||
private Long createNewBind(String bizType, Long bizId) {
|
||||
Long formInstanceId = IdWorker.getId();
|
||||
MkFormBind bind = new MkFormBind();
|
||||
bind.setId(IdWorker.getId());
|
||||
bind.setTenantId(StringUtil.isBlank(AuthUtil.getTenantId()) ? "000000" : AuthUtil.getTenantId());
|
||||
bind.setBizType(StringUtil.isBlank(bizType) ? "" : bizType);
|
||||
bind.setBizId(bizId);
|
||||
bind.setFormInstanceId(formInstanceId);
|
||||
bind.setIsCurrent(1);
|
||||
bind.setCreateTime(new Date());
|
||||
bind.setUpdateTime(new Date());
|
||||
boolean saved = this.save(bind);
|
||||
if (!saved) {
|
||||
throw new ServiceException("保存表单实例绑定失败");
|
||||
}
|
||||
log.info("创建表单实例绑定 bizType={} bizId={} formInstanceId={}", bizType, bizId, formInstanceId);
|
||||
return formInstanceId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user