From 79c416ea8a72aa9469deb14272135cca8dc01aac Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期三, 16 九月 2026 16:48:01 +0800
Subject: [PATCH] feat(crm): 退费单/销户申请审核通过后禁止修改和删除
---
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/refund/CrmRefundServiceImpl.java | 210 ++++++++++++++++++----------------------------------
1 files changed, 72 insertions(+), 138 deletions(-)
diff --git a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/refund/CrmRefundServiceImpl.java b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/refund/CrmRefundServiceImpl.java
index 9f8b733..9d3adad 100644
--- a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/refund/CrmRefundServiceImpl.java
+++ b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/refund/CrmRefundServiceImpl.java
@@ -1,12 +1,10 @@
package cn.iocoder.yudao.module.crm.service.refund;
-import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-import cn.iocoder.yudao.module.crm.controller.admin.refund.vo.CrmRefundAuditReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.refund.vo.CrmRefundPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.refund.vo.CrmRefundRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.refund.vo.CrmRefundSaveReqVO;
@@ -14,56 +12,45 @@
import cn.iocoder.yudao.module.crm.dal.dataobject.refund.CrmRefundDO;
import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
import cn.iocoder.yudao.module.crm.dal.mysql.refund.CrmRefundMapper;
-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.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
-import cn.iocoder.yudao.module.bpm.service.definition.BpmCategoryService;
-import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
+import cn.iocoder.yudao.module.system.api.approval.ApprovalConfigApi;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
-import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
-import static cn.iocoder.yudao.module.crm.util.CrmAuditStatusUtils.convertBpmResultToAuditStatus;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Service
@Validated
@Slf4j
public class CrmRefundServiceImpl implements CrmRefundService {
- private static final Integer AUDIT_DRAFT = 0;
- private static final Integer AUDIT_PASS = 20;
-
/**
- * BPM 閫�璐瑰鎵瑰垎绫荤紪鐮�
+ * CRM 閫�璐瑰崟瀹℃壒鐨勪笟鍔$被鍨嬬紪鐮�
+ *
+ * 涓� system_approval_config.biz_type 瀵瑰簲锛屽鎵逛汉鍦ㄣ�岀郴缁熺鐞� - 瀹℃壒閰嶇疆銆嶄腑缁存姢銆�
*/
- private static final String REFUND_APPROVE_CATEGORY_CODE = "refund_approve";
+ private static final String REFUND_APPROVE_BIZ_TYPE = "refund_approve";
@Resource
private CrmRefundMapper refundMapper;
@Resource
private CrmCustomerMapper customerMapper;
@Resource
- private BpmProcessInstanceApi bpmProcessInstanceApi;
+ private AdminUserApi adminUserApi;
@Resource
- private BpmCategoryService bpmCategoryService;
- @Resource
- private BpmProcessDefinitionService bpmProcessDefinitionService;
+ private ApprovalConfigApi approvalConfigApi;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -83,9 +70,7 @@
if (createReqVO.getApplyTime() == null) {
createReqVO.setApplyTime(LocalDateTime.now());
}
- if (createReqVO.getAuditStatus() == null) {
- createReqVO.setAuditStatus(AUDIT_DRAFT);
- }
+ createReqVO.setAuditStatus(CrmAuditStatusEnum.DRAFT.getStatus()); // 榛樿涓烘湭鎻愪氦鐘舵��
CrmRefundDO entity = BeanUtils.toBean(createReqVO, CrmRefundDO.class);
refundMapper.insert(entity);
return entity.getId();
@@ -93,19 +78,23 @@
@Override
public void updateRefund(CrmRefundSaveReqVO updateReqVO) {
- CrmRefundDO exists = refundMapper.selectById(updateReqVO.getId());
- if (exists == null) {
- throw exception(ErrorCodeConstants.CRM_REFUND_NOT_EXISTS);
+ // 1. 鏍¢獙瀛樺湪 + 瀹℃牳閫氳繃鐨勯��璐瑰崟涓嶅厑璁镐慨鏀�
+ CrmRefundDO refund = validateRefundExists(updateReqVO.getId());
+ if (ObjUtil.equal(refund.getAuditStatus(), CrmAuditStatusEnum.APPROVE.getStatus())) {
+ throw exception(ErrorCodeConstants.CRM_REFUND_UPDATE_FAIL_APPROVE);
}
+ // 2. 鏇存柊閫�璐瑰崟
CrmRefundDO entity = BeanUtils.toBean(updateReqVO, CrmRefundDO.class);
+ entity.setAuditStatus(null); // 瀹℃壒鐘舵�佸彧鑳界敱鎻愪氦/瀹℃牳鍙樻洿
refundMapper.updateById(entity);
}
@Override
public void deleteRefund(Long id) {
- CrmRefundDO exists = refundMapper.selectById(id);
- if (exists == null) {
- throw exception(ErrorCodeConstants.CRM_REFUND_NOT_EXISTS);
+ // 鏍¢獙瀛樺湪 + 瀹℃牳閫氳繃鐨勯��璐瑰崟涓嶅厑璁稿垹闄�
+ CrmRefundDO refund = validateRefundExists(id);
+ if (ObjUtil.equal(refund.getAuditStatus(), CrmAuditStatusEnum.APPROVE.getStatus())) {
+ throw exception(ErrorCodeConstants.CRM_REFUND_DELETE_FAIL_APPROVE);
}
refundMapper.deleteById(id);
}
@@ -127,128 +116,73 @@
}
@Override
- public void auditRefund(CrmRefundAuditReqVO auditReqVO) {
- CrmRefundDO exists = refundMapper.selectById(auditReqVO.getId());
- if (exists == null) {
- throw exception(ErrorCodeConstants.CRM_REFUND_NOT_EXISTS);
+ @Transactional(rollbackFor = Exception.class)
+ public void submitRefund(Long id) {
+ // 1. 鏍¢獙瀛樺湪 + 鍙彁浜ょ姸鎬侊紙鏈彁浜� / 瀹℃牳涓嶉�氳繃锛�
+ CrmRefundDO refund = validateRefundExists(id);
+ if (ObjUtil.notEqual(refund.getAuditStatus(), CrmAuditStatusEnum.DRAFT.getStatus())
+ && ObjUtil.notEqual(refund.getAuditStatus(), CrmAuditStatusEnum.REJECT.getStatus())) {
+ throw exception(ErrorCodeConstants.CRM_REFUND_SUBMIT_FAIL_NOT_EDITABLE);
}
- CrmRefundDO update = new CrmRefundDO();
- update.setId(exists.getId());
- update.setAuditStatus(auditReqVO.getAuditStatus());
- if (StrUtil.isNotBlank(auditReqVO.getRemark())) {
- update.setRemark(auditReqVO.getRemark());
- }
- refundMapper.updateById(update);
+
+ // 2. 鏍¢獙瀹℃壒閰嶇疆宸插惎鐢ㄤ笖閰嶇疆浜嗘湁鏁堝鎵逛汉锛堟湭閰嶇疆鏃舵姏鍑哄甫鏄庣‘鎻愮ず鐨勪笟鍔″紓甯革級
+ approvalConfigApi.validateApprovalEnabledAndGetApprovers(REFUND_APPROVE_BIZ_TYPE);
+
+ // 3. 鐘舵�佺疆涓哄鎵逛腑锛屽苟娓呯┖涓婁竴杞鏍哥粨鏋滐紝閬垮厤娈嬬暀銆屽鏍镐笉閫氳繃銆嶇殑鍘熷洜
+ refundMapper.submitAndResetAuditInfo(id, CrmAuditStatusEnum.PROCESS.getStatus());
}
@Override
- public void submitRefund(Long id, String processDefinitionKey, Long userId) {
- // 1. 鏍¢獙閫�璐瑰崟鏄惁鍦ㄨ崏绋跨姸鎬�
- CrmRefundDO refund = refundMapper.selectById(id);
- if (refund == null) {
- throw exception(ErrorCodeConstants.CRM_REFUND_NOT_EXISTS);
- }
- if (ObjUtil.notEqual(refund.getAuditStatus(), CrmAuditStatusEnum.DRAFT.getStatus())) {
- throw exception(ErrorCodeConstants.CRM_REFUND_SUBMIT_FAIL_NOT_DRAFT);
- }
-
- // 2. 鏍¢獙閫�璐瑰鎵瑰垎绫诲拰娴佺▼瀹氫箟鏄惁瀛樺湪锛屼笖浼犲叆鐨勬祦绋嬪畾涔夊浜庢縺娲荤姸鎬�
- validateRefundApproveCategoryAndProcessDefinition();
- ProcessDefinition processDefinition = bpmProcessDefinitionService.getActiveProcessDefinition(processDefinitionKey);
- if (processDefinition == null) {
- throw exception(ErrorCodeConstants.CRM_REFUND_BPM_PROCESS_DEFINITION_NOT_EXISTS);
- }
-
- // 3. 鍒涘缓閫�璐瑰鎵规祦绋嬪疄渚�
- String processInstanceId = bpmProcessInstanceApi.createProcessInstance(userId,
- new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(processDefinitionKey)
- .setBusinessKey(String.valueOf(id)));
-
- // 4. 鏇存柊閫�璐瑰崟娴佺▼缂栧彿涓庡鎵圭姸鎬�
- refundMapper.updateById(new CrmRefundDO().setId(id).setProcessInstanceId(processInstanceId)
- .setAuditStatus(CrmAuditStatusEnum.PROCESS.getStatus()));
+ public Set<Long> getRefundApproverUserIds() {
+ return approvalConfigApi.getApproverUserIds(REFUND_APPROVE_BIZ_TYPE);
}
@Override
- public void updateRefundAuditStatus(Long id, Integer bpmResult) {
- // 1.1 鏍¢獙閫�璐瑰崟鏄惁瀛樺湪
- CrmRefundDO refund = refundMapper.selectById(id);
- if (refund == null) {
- throw exception(ErrorCodeConstants.CRM_REFUND_NOT_EXISTS);
- }
- // 1.2 鍙湁瀹℃壒涓紝鍙互鏇存柊瀹℃壒缁撴灉
+ @Transactional(rollbackFor = Exception.class)
+ public void auditRefund(Long id, Boolean pass, String reviewRemark) {
+ // 1. 鏍¢獙瀛樺湪
+ CrmRefundDO refund = validateRefundExists(id);
+ // 2. 鏍¢獙澶勪簬瀹℃壒涓姸鎬�
if (ObjUtil.notEqual(refund.getAuditStatus(), CrmAuditStatusEnum.PROCESS.getStatus())) {
- log.error("[updateRefundAuditStatus][refund({}) 涓嶅浜庡鎵逛腑锛屾棤娉曟洿鏂板鎵圭粨鏋�({})]", refund.getId(), bpmResult);
- throw exception(ErrorCodeConstants.CRM_REFUND_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS);
+ throw exception(ErrorCodeConstants.CRM_REFUND_AUDIT_FAIL_NOT_PROCESS);
}
-
- // 2. 鏇存柊閫�璐瑰崟瀹℃壒缁撴灉
- Integer auditStatus = convertBpmResultToAuditStatus(bpmResult);
- refundMapper.updateById(new CrmRefundDO().setId(id).setAuditStatus(auditStatus));
+ // 3. 鏍¢獙褰撳墠鐧诲綍鐢ㄦ埛鏄涓氬姟绫诲瀷鐨勫鎵逛汉锛堟垨绛撅細浠讳竴浜哄潎鍙鏍革級
+ Long userId = getLoginUserId();
+ approvalConfigApi.validateApprover(REFUND_APPROVE_BIZ_TYPE, userId);
+ // 4. 瀹℃牳涓嶉�氳繃锛氬繀椤诲~鍐欏師鍥狅紝鐘舵�佺疆涓哄鏍镐笉閫氳繃锛岄��鍥炴彁浜や汉淇敼鍚庡彲閲嶆柊鎻愪氦
+ if (!Boolean.TRUE.equals(pass)) {
+ if (StrUtil.isBlank(reviewRemark)) {
+ throw exception(ErrorCodeConstants.CRM_REFUND_AUDIT_REJECT_REASON_REQUIRED);
+ }
+ refundMapper.auditRefund(id, CrmAuditStatusEnum.REJECT.getStatus(),
+ userId, getUserNickname(userId), reviewRemark);
+ return;
+ }
+ // 5. 瀹℃牳閫氳繃锛氳褰曞鏍镐汉涓庡鏍告剰瑙侊紝鐘舵�佺疆涓哄鏍搁�氳繃
+ refundMapper.auditRefund(id, CrmAuditStatusEnum.APPROVE.getStatus(),
+ userId, getUserNickname(userId), reviewRemark);
}
- @Override
- public List<Map<String, Object>> getRefundApproveProcessDefinitionList() {
- // 1. 鏍¢獙閫�璐瑰鎵瑰垎绫诲拰娴佺▼瀹氫箟鏄惁瀛樺湪
- validateRefundApproveCategoryAndProcessDefinition();
-
- // 2. 鑾峰彇鍒嗙被涓嬬殑娴佺▼瀹氫箟淇℃伅
- List<BpmProcessDefinitionInfoDO> definitionInfoList = bpmProcessDefinitionService
- .getProcessDefinitionInfoListByCategory(REFUND_APPROVE_CATEGORY_CODE);
-
- // 3. 鑾峰彇娴佺▼瀹氫箟璇︽儏
- Set<String> processDefinitionIds = convertSet(definitionInfoList, BpmProcessDefinitionInfoDO::getProcessDefinitionId);
- List<ProcessDefinition> processDefinitions = bpmProcessDefinitionService.getProcessDefinitionList(processDefinitionIds);
-
- // 4. 杩囨护锛氬彧淇濈暀婵�娲荤姸鎬侊紝涓旂浉鍚� key 鍙繚鐣欐渶鏂扮増鏈�
- Map<String, ProcessDefinition> latestVersionMap = new HashMap<>();
- for (ProcessDefinition pd : processDefinitions) {
- if (pd.isSuspended()) {
- continue;
- }
- ProcessDefinition existing = latestVersionMap.get(pd.getKey());
- if (existing == null || pd.getVersion() > existing.getVersion()) {
- latestVersionMap.put(pd.getKey(), pd);
- }
+ private CrmRefundDO validateRefundExists(Long id) {
+ CrmRefundDO refund = refundMapper.selectById(id);
+ if (refund == null) {
+ throw exception(ErrorCodeConstants.CRM_REFUND_NOT_EXISTS);
}
-
- // 5. 杩斿洖娴佺▼瀹氫箟鍒楄〃
- List<Map<String, Object>> result = new ArrayList<>();
- for (ProcessDefinition pd : latestVersionMap.values()) {
- Map<String, Object> item = new HashMap<>();
- item.put("id", pd.getId());
- item.put("key", pd.getKey());
- item.put("name", pd.getName());
- item.put("version", pd.getVersion());
- result.add(item);
- }
- return result;
+ return refund;
}
/**
- * 鏍¢獙 BPM 閫�璐瑰鎵瑰垎绫诲拰娴佺▼瀹氫箟鏄惁瀛樺湪
+ * 鑾峰彇鐢ㄦ埛鏄电О
+ *
+ * @param userId 鐢ㄦ埛缂栧彿
+ * @return 鏄电О锛岀敤鎴蜂笉瀛樺湪鏃惰繑鍥� null
*/
- private void validateRefundApproveCategoryAndProcessDefinition() {
- // 1. 鏍¢獙鍒嗙被鏄惁瀛樺湪
- Map<String, ?> categoryMap = bpmCategoryService.getCategoryMap(Collections.singletonList(REFUND_APPROVE_CATEGORY_CODE));
- if (!categoryMap.containsKey(REFUND_APPROVE_CATEGORY_CODE)) {
- throw exception(ErrorCodeConstants.CRM_REFUND_BPM_PROCESS_DEFINITION_NOT_EXISTS);
+ private String getUserNickname(Long userId) {
+ if (userId == null) {
+ return null;
}
-
- // 2. 鏍¢獙鍒嗙被涓嬫槸鍚︽湁鍙敤鐨勬祦绋嬪畾涔�
- List<BpmProcessDefinitionInfoDO> definitionInfoList = bpmProcessDefinitionService
- .getProcessDefinitionInfoListByCategory(REFUND_APPROVE_CATEGORY_CODE);
- if (CollUtil.isEmpty(definitionInfoList)) {
- throw exception(ErrorCodeConstants.CRM_REFUND_BPM_PROCESS_DEFINITION_NOT_EXISTS);
- }
-
- // 3. 鏍¢獙鏄惁鏈夋縺娲荤姸鎬佺殑娴佺▼瀹氫箟
- Set<String> processDefinitionIds = convertSet(definitionInfoList, BpmProcessDefinitionInfoDO::getProcessDefinitionId);
- List<ProcessDefinition> processDefinitions = bpmProcessDefinitionService.getProcessDefinitionList(processDefinitionIds);
- boolean hasActiveDefinition = processDefinitions.stream().anyMatch(pd -> !pd.isSuspended());
- if (!hasActiveDefinition) {
- throw exception(ErrorCodeConstants.CRM_REFUND_BPM_PROCESS_DEFINITION_NOT_EXISTS);
- }
+ AdminUserRespDTO user = adminUserApi.getUser(userId);
+ return user == null ? null : user.getNickname();
}
private String generateRefundNo() {
@@ -256,4 +190,4 @@
+ RandomUtil.randomNumbers(4);
}
-}
\ No newline at end of file
+}
--
Gitblit v1.9.3