Browse Source
Merge branch 'milestone-20251016-现金管理' of http://39.101.133.168:8807/huangqizhen/gold-java into lijianlin/feature-202509231533026-现金管理-收款管理
lijianlin/feature-202509231533026-现金管理-收款管理
Merge branch 'milestone-20251016-现金管理' of http://39.101.133.168:8807/huangqizhen/gold-java into lijianlin/feature-202509231533026-现金管理-收款管理
lijianlin/feature-202509231533026-现金管理-收款管理
19 changed files with 67 additions and 1205 deletions
-
70src/main/java/com/example/demo/config/cash/DataInitializer.java
-
92src/main/java/com/example/demo/config/cash/RefundApprovalFlowConfig.java
-
10src/main/java/com/example/demo/controller/cash/CashRefundController.java
-
117src/main/java/com/example/demo/controller/cash/RefundApprovalController.java
-
2src/main/java/com/example/demo/controller/coin/AdminController.java
-
27src/main/java/com/example/demo/domain/DTO/RefundApprovalRequest.java
-
2src/main/java/com/example/demo/domain/entity/Admin.java
-
244src/main/java/com/example/demo/domain/vo/cash/CashRecord.java
-
10src/main/java/com/example/demo/domain/vo/cash/CashRecordDone.java
-
43src/main/java/com/example/demo/domain/vo/cash/Market.java
-
43src/main/java/com/example/demo/domain/vo/cash/RefundApprovalRecord.java
-
84src/main/java/com/example/demo/domain/vo/cash/User.java
-
4src/main/java/com/example/demo/mapper/cash/CashRefundMapper.java
-
173src/main/java/com/example/demo/service/cash/MarketService.java
-
266src/main/java/com/example/demo/service/cash/RefundApprovalService.java
-
12src/main/java/com/example/demo/service/cash/RefundService.java
-
27src/main/java/com/example/demo/serviceImpl/cash/CashRefundServiceImpl.java
-
5src/main/resources/cashMapper/CashRecordMapper.xml
-
41src/main/resources/cashMapper/CashRefundMapper.xml
@ -1,70 +0,0 @@ |
|||
package com.example.demo.config.cash; |
|||
|
|||
|
|||
|
|||
import com.example.demo.domain.vo.cash.Market; |
|||
import com.example.demo.service.cash.MarketService; |
|||
import com.example.demo.service.cash.RefundApprovalService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.boot.CommandLineRunner; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class DataInitializer implements CommandLineRunner { |
|||
|
|||
private final MarketService marketService; |
|||
private final RefundApprovalService refundApprovalService; |
|||
|
|||
@Override |
|||
public void run(String... args) throws Exception { |
|||
// 初始化地区数据 |
|||
initializeMarketData(); |
|||
} |
|||
|
|||
private void initializeMarketData() { |
|||
List<Market> markets = Arrays.asList( |
|||
createMarket(1, "Capt", -1, "Capt-Capt-Capt-Capt", 0), |
|||
createMarket(2, "公司", 1, "Capt-公司-公司-公司", 1), |
|||
createMarket(3, "市场", 1, "Capt-市场部-市场部-市场部", 1), |
|||
createMarket(4, "新加坡", 3, "Capt-市场部-新加坡-新加坡", 2), |
|||
createMarket(5, "马来西亚", 3, "Capt-市场部-马来西亚-马来西亚", 2), |
|||
createMarket(9, "研发部", 2, "Capt-公司-研发部-研发部", 2), |
|||
createMarket(13, "香港", 3, "Capt-市场部-香港-香港", 2), |
|||
createMarket(9999, "总部", 2, "Capt-公司-总部-总部", 2), |
|||
createMarket(24016, "加拿大", 3, "Capt-市场部-加拿大-加拿大", 2), |
|||
createMarket(24018, "泰国", 3, "Capt-市场部-泰国-泰国", 2), |
|||
createMarket(24022, "越南HCM", 3, "Capt-市场部-越南HCM-越南HCM", 2), |
|||
createMarket(24027, "韩国", 3, "Capt-市场部-韩国-韩国", 2), |
|||
createMarket(24028, "深圳运营", 3, "Capt-市场部-深圳运营-深圳运营", 2), |
|||
createMarket(24030, "未知", 3, "Capt-市场部-未知", 2), |
|||
createMarket(24031, "其他", 3, "Capt-市场部-其他", 2), |
|||
createMarket(24032, "市场部", 3, "Capt-市场部-市场部", 2) |
|||
); |
|||
|
|||
marketService.initializeMarkets(markets); |
|||
|
|||
// 为特定市场初始化审批流程 |
|||
refundApprovalService.initializeFlowForMarketName("新加坡"); |
|||
refundApprovalService.initializeFlowForMarketName("马来西亚"); |
|||
refundApprovalService.initializeFlowForMarketName("香港"); |
|||
refundApprovalService.initializeFlowForMarketName("加拿大"); |
|||
refundApprovalService.initializeFlowForMarketName("泰国"); |
|||
refundApprovalService.initializeFlowForMarketName("越南HCM"); |
|||
refundApprovalService.initializeFlowForMarketName("韩国"); |
|||
refundApprovalService.initializeFlowForMarketName("深圳运营"); |
|||
} |
|||
|
|||
private Market createMarket(Integer id, String name, Integer parentId, String treelist, Integer type) { |
|||
Market market = new Market(); |
|||
market.setId(id); |
|||
market.setName(name); |
|||
market.setParentId(parentId); |
|||
market.setTreelist(treelist); |
|||
market.setType(type); |
|||
return market; |
|||
} |
|||
} |
|||
@ -1,92 +0,0 @@ |
|||
package com.example.demo.config.cash; |
|||
|
|||
import com.example.demo.Node.RefundApprovalNode; |
|||
import com.example.demo.domain.vo.cash.User; |
|||
import lombok.Data; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class RefundApprovalFlowConfig { |
|||
private String flowName; |
|||
private List<RefundApprovalNode> nodes; |
|||
|
|||
public RefundApprovalFlowConfig() { |
|||
this.nodes = new ArrayList<>(); |
|||
} |
|||
|
|||
public RefundApprovalFlowConfig(String flowName, List<RefundApprovalNode> nodes) { |
|||
this.flowName = flowName; |
|||
this.nodes = nodes != null ? nodes : new ArrayList<>(); |
|||
} |
|||
|
|||
// 获取用户可见的状态列表(基于角色和地区ID权限) |
|||
public List<Integer> getVisibleStatuses(User user, Integer orderMarketId) { |
|||
List<Integer> visibleStatuses = new ArrayList<>(); |
|||
|
|||
for (RefundApprovalNode node : nodes) { |
|||
if (isNodeVisibleToUser(node, user, orderMarketId)) { |
|||
visibleStatuses.add(node.getLevel()); |
|||
} |
|||
} |
|||
return visibleStatuses; |
|||
} |
|||
|
|||
// 判断节点对用户是否可见(基于角色和地区ID权限) |
|||
public boolean isNodeVisibleToUser(RefundApprovalNode node, User user, Integer orderMarketId) { |
|||
if (node == null || user == null) return false; |
|||
|
|||
// 检查角色权限 |
|||
boolean hasRolePermission = true; |
|||
if (node.getRoles() != null && !node.getRoles().isEmpty()) { |
|||
hasRolePermission = user.hasAnyRole(node.getRoles()); |
|||
} |
|||
|
|||
// 检查地区权限 |
|||
boolean hasMarketPermission = true; |
|||
if (node.getAllowedMarketIds() != null && !node.getAllowedMarketIds().isEmpty()) { |
|||
// 如果节点限制了地区,用户需要在这些地区有权限 |
|||
hasMarketPermission = user.canApproveAnyMarket(node.getAllowedMarketIds()); |
|||
} else if (orderMarketId != null) { |
|||
// 如果节点没有限制地区,但订单有地区,用户需要在该订单地区有权限 |
|||
hasMarketPermission = user.canApproveMarket(orderMarketId); |
|||
} |
|||
|
|||
return hasRolePermission && hasMarketPermission; |
|||
} |
|||
|
|||
// 判断用户是否可以审批某个节点的订单 |
|||
public boolean canUserApproveNode(User user, Integer level, Integer orderMarketId) { |
|||
RefundApprovalNode node = findNodeByLevel(level); |
|||
if (node == null) return false; |
|||
|
|||
return isNodeVisibleToUser(node, user, orderMarketId); |
|||
} |
|||
|
|||
// 根据级别查找节点 |
|||
public RefundApprovalNode findNodeByLevel(Integer level) { |
|||
if (nodes == null) return null; |
|||
return nodes.stream() |
|||
.filter(node -> level.equals(node.getLevel())) |
|||
.findFirst() |
|||
.orElse(null); |
|||
} |
|||
|
|||
// 获取下一个审批节点 |
|||
public RefundApprovalNode getNextNode(Integer currentLevel) { |
|||
if (nodes == null || nodes.isEmpty()) return null; |
|||
|
|||
return nodes.stream() |
|||
.filter(node -> node.getLevel() > currentLevel) |
|||
.min((a, b) -> a.getLevel().compareTo(b.getLevel())) |
|||
.orElse(null); |
|||
} |
|||
|
|||
// 获取所有涉及的市场ID |
|||
public java.util.Set<Integer> getAllInvolvedMarketIds() { |
|||
return nodes.stream() |
|||
.filter(node -> node.getAllowedMarketIds() != null) |
|||
.flatMap(node -> node.getAllowedMarketIds().stream()) |
|||
.collect(java.util.stream.Collectors.toSet()); |
|||
} |
|||
} |
|||
@ -1,117 +0,0 @@ |
|||
package com.example.demo.controller.cash; |
|||
|
|||
|
|||
|
|||
import com.example.demo.domain.DTO.RefundApprovalRequest; |
|||
import com.example.demo.domain.vo.cash.CashRecord; |
|||
import com.example.demo.domain.vo.cash.User; |
|||
import com.example.demo.service.cash.RefundApprovalService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@RestController |
|||
@RequestMapping("/api/refund-approval") |
|||
@RequiredArgsConstructor |
|||
public class RefundApprovalController { |
|||
|
|||
private final RefundApprovalService refundApprovalService; |
|||
|
|||
/** |
|||
* 提交退款审批 |
|||
*/ |
|||
@PostMapping("/submit") |
|||
public Map<String, Object> submitRefundApproval(@RequestBody RefundApprovalRequest request) { |
|||
boolean success = refundApprovalService.submitRefundApproval( |
|||
request.getUser(), |
|||
request.getCashRecord(), |
|||
request.getApprovalResult(), |
|||
request.getComments() |
|||
); |
|||
|
|||
Map<String, Object> response = new HashMap<>(); |
|||
response.put("success", success); |
|||
response.put("message", success ? "退款审批提交成功" : "退款审批提交失败,无权限"); |
|||
response.put("orderStatus", request.getCashRecord().getStatus()); |
|||
response.put("currentLevel", request.getCashRecord().getCurrentApprovalLevel()); |
|||
|
|||
return response; |
|||
} |
|||
|
|||
/** |
|||
* 撤回退款订单(在第一个审批节点前) |
|||
*/ |
|||
@PostMapping("/withdraw") |
|||
public Map<String, Object> withdrawRefundOrder(@RequestBody RefundApprovalRequest request) { |
|||
|
|||
boolean success = refundApprovalService.withdrawRefundOrder(request.getUser(),request.getCashRecord(), request.getWithdrawReason()); |
|||
|
|||
return Map.of( |
|||
"success", success, |
|||
"message", success ? "退款订单撤回成功" : "退款订单撤回失败", |
|||
"orderStatus", request.getCashRecord().getStatus() |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 重新提交撤回的退款订单 |
|||
*/ |
|||
@PostMapping("/resubmit") |
|||
public Map<String, Object> resubmitRefundOrder(@RequestBody RefundApprovalRequest request) { |
|||
|
|||
boolean success = refundApprovalService.resubmitRefundOrder(request.getUser(), request.getCashRecord()); |
|||
|
|||
return Map.of( |
|||
"success", success, |
|||
"message", success ? "退款订单重新提交成功" : "退款订单重新提交失败", |
|||
"orderStatus", request.getCashRecord().getStatus() |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 检查退款审批权限 |
|||
*/ |
|||
@GetMapping("/check-permission") |
|||
public Map<String, Object> checkPermission(@RequestBody RefundApprovalRequest request) { |
|||
|
|||
|
|||
boolean hasPermission = refundApprovalService.canUserApproveOrder(request.getUser(), request.getCashRecord()); |
|||
boolean canWithdraw = refundApprovalService.canUserWithdrawOrder(request.getUser(), request.getCashRecord()); |
|||
List<Integer> visibleStatuses = refundApprovalService.getUserVisibleStatuses(request.getUser(), request.getCashRecord()); |
|||
|
|||
return Map.of( |
|||
"hasApprovalPermission", hasPermission, |
|||
"canWithdraw", canWithdraw, |
|||
"visibleStatuses", visibleStatuses, |
|||
"currentLevel", request.getCashRecord().getCurrentApprovalLevel(), |
|||
"orderStatus", request.getCashRecord().getStatus() |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 获取用户可见的退款审批状态 |
|||
*/ |
|||
@GetMapping("/visible-statuses") |
|||
public List<Integer> getVisibleStatuses(@RequestBody RefundApprovalRequest request) { |
|||
|
|||
|
|||
return refundApprovalService.getUserVisibleStatuses(request.getUser(), request.getCashRecord()); |
|||
} |
|||
|
|||
// // 创建模拟用户(实际项目中应从数据库获取) |
|||
// private User createMockUser(Integer userId) { |
|||
// User user = new User(); |
|||
// user.setId(userId); |
|||
// user.setName("测试用户"); |
|||
// user.setMarket("北京"); |
|||
// user.setMarketId(4); // 假设4是北京的地区ID |
|||
// user.setRoles(Set.of(RefundApprovalService.ROLE_REGIONAL_FINANCE)); |
|||
// user.setManagedMarketIds(Set.of(4)); // 管辖北京地区 |
|||
// user.setManagedMarketNames(Set.of("北京")); |
|||
// return user; |
|||
// } |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
package com.example.demo.domain.DTO; |
|||
|
|||
import com.example.demo.domain.vo.cash.CashRecord; |
|||
import com.example.demo.domain.vo.cash.User; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @program: GOLD |
|||
* @ClassName RefundApprovalRequest |
|||
* @description: |
|||
* @author: huangqizhen |
|||
* @create: 2025−10-14 15:02 |
|||
* @Version 1.0 |
|||
**/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
public class RefundApprovalRequest { |
|||
private User user; |
|||
private CashRecord cashRecord; |
|||
private String approvalResult; |
|||
private String comments; |
|||
private String withdrawReason; |
|||
private List<CashRecord> orders; |
|||
} |
|||
@ -1,244 +0,0 @@ |
|||
package com.example.demo.domain.vo.cash; |
|||
|
|||
import com.alibaba.excel.annotation.ExcelIgnore; |
|||
import com.alibaba.excel.annotation.ExcelProperty; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import lombok.Data; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
public class CashRecord { |
|||
@ExcelProperty("序号") |
|||
private Integer id; |
|||
|
|||
@ExcelProperty("订单类型") |
|||
private Integer orderType; // 1:收款,2:退款 |
|||
|
|||
@ExcelProperty("精网号") |
|||
private Integer jwcode; |
|||
|
|||
@ExcelProperty("姓名") |
|||
private String name; |
|||
|
|||
@ExcelProperty("所属地区") |
|||
private String market; |
|||
|
|||
@ExcelProperty("活动名称") |
|||
private String activity; |
|||
|
|||
@ExcelProperty("金币订单号") |
|||
private String orderCode; |
|||
|
|||
@ExcelProperty("银行流水订单号") |
|||
private String bankCode; |
|||
|
|||
@ExcelProperty("商品名称") |
|||
private String goodsName; |
|||
|
|||
@ExcelProperty("产品数量") |
|||
private Integer goodNum; |
|||
|
|||
@ExcelProperty("币种") |
|||
private String paymentCurrency; |
|||
|
|||
@ExcelProperty("金额") |
|||
private BigDecimal paymentAmount; |
|||
|
|||
@ExcelProperty("到账币种") |
|||
private String receivedCurrency; |
|||
|
|||
@ExcelProperty("到账金额") |
|||
private BigDecimal receivedAmount; |
|||
|
|||
@ExcelProperty("手续费") |
|||
private BigDecimal handlingCharge; |
|||
|
|||
@ExcelProperty("支付方式") |
|||
private String payType; |
|||
|
|||
@ExcelProperty("到账地区") |
|||
private String receivedMarket; |
|||
|
|||
@ExcelProperty("付款日期") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
|||
private Date payTime; |
|||
|
|||
@ExcelProperty("到账日期") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
|||
private Date receivedTime; |
|||
|
|||
@ExcelIgnore |
|||
private Integer auditId; |
|||
|
|||
@ExcelProperty("订单状态") |
|||
private Integer status; |
|||
|
|||
@ExcelIgnore |
|||
private Integer submitterId; |
|||
|
|||
@ExcelProperty("转账凭证") |
|||
private String voucher; |
|||
|
|||
@ExcelProperty("备注") |
|||
private String remark; |
|||
|
|||
@ExcelProperty("驳回理由") |
|||
private String rejectReason; |
|||
|
|||
@ExcelProperty("退款理由") |
|||
private String refundReason; |
|||
|
|||
@ExcelProperty("退款方式") |
|||
private Integer refundModel; |
|||
|
|||
@ExcelProperty("退款执行人") |
|||
private Integer executor; |
|||
|
|||
@ExcelProperty("退款途径") |
|||
private String refundChannels; |
|||
|
|||
@ExcelProperty("退款日期") |
|||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/Shanghai") |
|||
private Date refundTime; |
|||
|
|||
@ExcelProperty("退款备注") |
|||
private String refundRemark; |
|||
|
|||
@ExcelProperty("退款截图") |
|||
private String refundVoucher; |
|||
|
|||
@ExcelProperty("创建时间") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
|||
private Date createTime; |
|||
|
|||
@ExcelProperty("更新时间") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
|||
private Date updateTime; |
|||
|
|||
@ExcelProperty("审核时间") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
|||
private Date auditTime; |
|||
|
|||
@ExcelProperty("收款备注") |
|||
private String receivedRemark; |
|||
|
|||
@ExcelIgnore |
|||
private Integer marketId; // 关联market表的id |
|||
|
|||
|
|||
@ExcelIgnore |
|||
private Integer receivedMarketId; // 到账地区ID |
|||
|
|||
// 获取订单的主要地区ID(用于审批权限判断) |
|||
public Integer getPrimaryMarketId() { |
|||
return marketId != null ? marketId : (receivedMarketId != null ? receivedMarketId : null); |
|||
} |
|||
|
|||
// 获取订单的主要地区名称 |
|||
public String getPrimaryMarketName() { |
|||
return market != null ? market : (receivedMarket != null ? receivedMarket : null); |
|||
} |
|||
|
|||
// 退款状态常量 |
|||
public static final Integer STATUS_REFUND_REGIONAL_FINANCE_PENDING = 10; // 地区财务待审核 |
|||
public static final Integer STATUS_REFUND_WITHDRAWN = 11; // 手动撤回待编辑提交 |
|||
public static final Integer STATUS_REFUND_REGIONAL_FINANCE_REJECTED = 12; // 地区财务驳回 |
|||
public static final Integer STATUS_REFUND_REGIONAL_MANAGER_PENDING = 20; // 地区负责人待审核 |
|||
public static final Integer STATUS_REFUND_REGIONAL_MANAGER_REJECTED = 22; // 地区负责人驳回 |
|||
public static final Integer STATUS_REFUND_HEADQUARTERS_FINANCE_PENDING = 30; // 总部财务待审核 |
|||
public static final Integer STATUS_REFUND_HEADQUARTERS_FINANCE_REJECTED = 32; // 总部财务驳回 |
|||
public static final Integer STATUS_REFUND_EXECUTOR_PENDING = 40; // 执行人待处理 |
|||
public static final Integer STATUS_REFUND_COMPLETED = 41; // 执行人已处理,退款结束 |
|||
|
|||
// 获取当前审批级别(只处理退款订单) |
|||
public Integer getCurrentApprovalLevel() { |
|||
if (!isRefundOrder()) { |
|||
return 0; |
|||
} |
|||
|
|||
switch (status) { |
|||
case 10: return 1; // 地区财务待审核 |
|||
case 11: return 0; // 手动撤回待编辑提交 |
|||
case 12: return -1; // 地区财务驳回 |
|||
case 20: return 2; // 地区负责人待审核 |
|||
case 22: return -2; // 地区负责人驳回 |
|||
case 30: return 3; // 总部财务待审核 |
|||
case 32: return -3; // 总部财务驳回 |
|||
case 40: return 4; // 执行人待处理 |
|||
case 41: return 5; // 退款结束 |
|||
default: return 0; |
|||
} |
|||
} |
|||
|
|||
// 检查是否为退款订单 |
|||
public boolean isRefundOrder() { |
|||
return orderType != null && orderType == 2; |
|||
} |
|||
|
|||
// 检查是否可以撤回(只有在地区财务待审核状态可以撤回) |
|||
public boolean canWithdraw() { |
|||
return isRefundOrder() && status != null && status == STATUS_REFUND_REGIONAL_FINANCE_PENDING; |
|||
} |
|||
|
|||
// 检查是否可以重新提交(只有在撤回状态可以重新提交) |
|||
public boolean canResubmit() { |
|||
return isRefundOrder() && status != null && status == STATUS_REFUND_WITHDRAWN; |
|||
} |
|||
|
|||
// 检查是否在审批流程中 |
|||
public boolean isInApprovalProcess() { |
|||
return isRefundOrder() && status != null && |
|||
(status == STATUS_REFUND_REGIONAL_FINANCE_PENDING || |
|||
status == STATUS_REFUND_REGIONAL_MANAGER_PENDING || |
|||
status == STATUS_REFUND_HEADQUARTERS_FINANCE_PENDING || |
|||
status == STATUS_REFUND_EXECUTOR_PENDING); |
|||
} |
|||
|
|||
// 获取下一个状态 |
|||
public Integer getNextStatus(boolean approved) { |
|||
if (!isRefundOrder()) { |
|||
return status; |
|||
} |
|||
|
|||
if (!approved) { |
|||
// 驳回状态 |
|||
switch (status) { |
|||
case 10: return STATUS_REFUND_REGIONAL_FINANCE_REJECTED; |
|||
case 20: return STATUS_REFUND_REGIONAL_MANAGER_REJECTED; |
|||
case 30: return STATUS_REFUND_HEADQUARTERS_FINANCE_REJECTED; |
|||
default: return status; |
|||
} |
|||
} |
|||
|
|||
// 审批通过状态 |
|||
switch (status) { |
|||
case 10: return STATUS_REFUND_REGIONAL_MANAGER_PENDING; |
|||
case 20: return STATUS_REFUND_HEADQUARTERS_FINANCE_PENDING; |
|||
case 30: return STATUS_REFUND_EXECUTOR_PENDING; |
|||
case 40: return STATUS_REFUND_COMPLETED; |
|||
default: return status; |
|||
} |
|||
} |
|||
|
|||
// 撤回订单 |
|||
public boolean withdraw() { |
|||
if (!canWithdraw()) { |
|||
return false; |
|||
} |
|||
this.status = STATUS_REFUND_WITHDRAWN; |
|||
this.updateTime = new Date(); |
|||
return true; |
|||
} |
|||
|
|||
// 重新提交订单 |
|||
public boolean resubmit() { |
|||
if (!canResubmit()) { |
|||
return false; |
|||
} |
|||
this.status = STATUS_REFUND_REGIONAL_FINANCE_PENDING; |
|||
this.updateTime = new Date(); |
|||
return true; |
|||
} |
|||
} |
|||
@ -1,43 +0,0 @@ |
|||
package com.example.demo.domain.vo.cash; |
|||
|
|||
import lombok.Data; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
public class Market { |
|||
private Integer id; |
|||
private String name; // 地区名称 |
|||
private Integer parentId; // 父级ID |
|||
private Date createTime; // 创建时间 |
|||
private String treelist; // 树形路径 |
|||
private Integer type; // 等级类型 |
|||
|
|||
// 获取地区层级 |
|||
public Integer getLevel() { |
|||
if (treelist == null) return 0; |
|||
String[] levels = treelist.split("-"); |
|||
return levels.length - 1; // 减去根节点 |
|||
} |
|||
|
|||
// 判断是否为根节点 |
|||
public boolean isRoot() { |
|||
return parentId == -1; |
|||
} |
|||
|
|||
// 判断是否为市场部节点 |
|||
public boolean isMarketDepartment() { |
|||
return parentId != null && parentId == 3; // 市场部的父ID是3 |
|||
} |
|||
|
|||
// 判断是否为具体市场(叶子节点) |
|||
public boolean isSpecificMarket() { |
|||
return type != null && type == 2; // 等级类型为2的是具体市场 |
|||
} |
|||
|
|||
// 获取根节点名称 |
|||
public String getRootName() { |
|||
if (treelist == null) return null; |
|||
String[] levels = treelist.split("-"); |
|||
return levels.length > 0 ? levels[0] : null; |
|||
} |
|||
} |
|||
@ -1,43 +0,0 @@ |
|||
package com.example.demo.domain.vo.cash; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import lombok.Data; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
public class RefundApprovalRecord { |
|||
private Integer id; |
|||
private Integer cashRecordId; |
|||
private Integer approvalLevel; |
|||
private String approvalNode; |
|||
private Integer approverId; |
|||
private String approverName; |
|||
private String approvalResult; // APPROVED, REJECTED |
|||
private String comments; |
|||
|
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
|||
private Date approvalTime; |
|||
|
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
|||
private Date createTime; |
|||
|
|||
// 撤回记录相关字段 |
|||
private Boolean isWithdrawal = false; |
|||
private Integer withdrawnBy; |
|||
private String withdrawReason; |
|||
|
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
|||
private Date withdrawTime; |
|||
|
|||
public RefundApprovalRecord() {} |
|||
|
|||
public RefundApprovalRecord(Integer cashRecordId, Integer approvalLevel, String approvalNode, |
|||
Integer approverId, String approverName) { |
|||
this.cashRecordId = cashRecordId; |
|||
this.approvalLevel = approvalLevel; |
|||
this.approvalNode = approvalNode; |
|||
this.approverId = approverId; |
|||
this.approverName = approverName; |
|||
this.createTime = new Date(); |
|||
} |
|||
} |
|||
@ -1,84 +0,0 @@ |
|||
package com.example.demo.domain.vo.cash; |
|||
|
|||
import lombok.Data; |
|||
import java.util.HashSet; |
|||
import java.util.Set; |
|||
|
|||
@Data |
|||
public class User { |
|||
private Integer id; |
|||
private String name; |
|||
private Integer marketId; // 关联market表的id |
|||
private String market; // 地区名称 |
|||
private Set<String> roles = new HashSet<>(); |
|||
private Set<Integer> managedMarketIds = new HashSet<>(); // 管辖的地区ID列表 |
|||
private Set<String> managedMarketNames = new HashSet<>(); // 管辖的地区名称列表 |
|||
|
|||
// 角色权限检查 |
|||
public boolean hasRole(String role) { |
|||
return roles != null && roles.contains(role); |
|||
} |
|||
|
|||
public boolean hasAnyRole(Set<String> requiredRoles) { |
|||
if (roles == null || requiredRoles == null) return false; |
|||
return requiredRoles.stream().anyMatch(roles::contains); |
|||
} |
|||
|
|||
// 地区权限检查 - 基于地区ID |
|||
public boolean canApproveMarket(Integer targetMarketId) { |
|||
if (targetMarketId == null) return false; |
|||
|
|||
// 优先检查管辖地区ID列表 |
|||
if (managedMarketIds != null && !managedMarketIds.isEmpty()) { |
|||
return managedMarketIds.contains(targetMarketId); |
|||
} |
|||
|
|||
// 如果没有管辖地区列表,使用单个marketId字段 |
|||
return targetMarketId.equals(this.marketId); |
|||
} |
|||
|
|||
public boolean canApproveAnyMarket(Set<Integer> targetMarketIds) { |
|||
if (targetMarketIds == null || targetMarketIds.isEmpty()) return false; |
|||
|
|||
if (managedMarketIds != null && !managedMarketIds.isEmpty()) { |
|||
return targetMarketIds.stream().anyMatch(managedMarketIds::contains); |
|||
} |
|||
|
|||
return targetMarketIds.contains(this.marketId); |
|||
} |
|||
|
|||
// 地区权限检查 - 基于地区名称(向后兼容) |
|||
public boolean canApproveMarketByName(String targetMarketName) { |
|||
if (targetMarketName == null) return false; |
|||
|
|||
if (managedMarketNames != null && !managedMarketNames.isEmpty()) { |
|||
return managedMarketNames.contains(targetMarketName); |
|||
} |
|||
|
|||
return targetMarketName.equals(this.market); |
|||
} |
|||
|
|||
// 获取用户的所有管辖地区ID |
|||
public Set<Integer> getAllManagedMarketIds() { |
|||
Set<Integer> allMarketIds = new HashSet<>(); |
|||
if (managedMarketIds != null && !managedMarketIds.isEmpty()) { |
|||
allMarketIds.addAll(managedMarketIds); |
|||
} |
|||
if (marketId != null) { |
|||
allMarketIds.add(marketId); |
|||
} |
|||
return allMarketIds; |
|||
} |
|||
|
|||
// 获取用户的所有管辖地区名称 |
|||
public Set<String> getAllManagedMarketNames() { |
|||
Set<String> allMarketNames = new HashSet<>(); |
|||
if (managedMarketNames != null && !managedMarketNames.isEmpty()) { |
|||
allMarketNames.addAll(managedMarketNames); |
|||
} |
|||
if (market != null) { |
|||
allMarketNames.add(market); |
|||
} |
|||
return allMarketNames; |
|||
} |
|||
} |
|||
@ -1,173 +0,0 @@ |
|||
package com.example.demo.service.cash; |
|||
|
|||
|
|||
import com.example.demo.domain.vo.cash.Market; |
|||
import com.example.demo.domain.vo.cash.User; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.*; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Slf4j |
|||
@Service |
|||
public class MarketService { |
|||
|
|||
// 地区数据缓存 |
|||
private final Map<Integer, Market> marketCache = new ConcurrentHashMap<>(); |
|||
private final Map<String, Integer> marketNameToIdCache = new ConcurrentHashMap<>(); |
|||
private final Map<Integer, List<Market>> childrenCache = new ConcurrentHashMap<>(); |
|||
|
|||
// 初始化地区数据(实际项目中应从数据库加载) |
|||
public void initializeMarkets(List<Market> markets) { |
|||
marketCache.clear(); |
|||
marketNameToIdCache.clear(); |
|||
childrenCache.clear(); |
|||
|
|||
for (Market market : markets) { |
|||
marketCache.put(market.getId(), market); |
|||
marketNameToIdCache.put(market.getName(), market.getId()); |
|||
} |
|||
|
|||
// 构建父子关系 |
|||
for (Market market : markets) { |
|||
Integer parentId = market.getParentId(); |
|||
if (!childrenCache.containsKey(parentId)) { |
|||
childrenCache.put(parentId, new ArrayList<>()); |
|||
} |
|||
childrenCache.get(parentId).add(market); |
|||
} |
|||
|
|||
log.info("地区数据初始化完成,共加载{}个地区", markets.size()); |
|||
} |
|||
|
|||
// 根据ID获取地区 |
|||
public Market getMarketById(Integer id) { |
|||
return marketCache.get(id); |
|||
} |
|||
|
|||
// 根据名称获取地区 |
|||
public Market getMarketByName(String name) { |
|||
Integer id = marketNameToIdCache.get(name); |
|||
return id != null ? marketCache.get(id) : null; |
|||
} |
|||
|
|||
// 根据名称获取地区ID |
|||
public Integer getMarketIdByName(String name) { |
|||
return marketNameToIdCache.get(name); |
|||
} |
|||
|
|||
// 获取所有子地区(包括所有后代) |
|||
public List<Market> getAllChildren(Integer parentId) { |
|||
List<Market> allChildren = new ArrayList<>(); |
|||
List<Market> directChildren = childrenCache.get(parentId); |
|||
|
|||
if (directChildren != null) { |
|||
allChildren.addAll(directChildren); |
|||
for (Market child : directChildren) { |
|||
allChildren.addAll(getAllChildren(child.getId())); |
|||
} |
|||
} |
|||
|
|||
return allChildren; |
|||
} |
|||
|
|||
// 获取所有子地区ID(包括所有后代) |
|||
public Set<Integer> getAllChildrenIds(Integer parentId) { |
|||
return getAllChildren(parentId).stream() |
|||
.map(Market::getId) |
|||
.collect(Collectors.toSet()); |
|||
} |
|||
|
|||
// 获取所有子地区名称(包括所有后代) |
|||
public Set<String> getAllChildrenNames(Integer parentId) { |
|||
return getAllChildren(parentId).stream() |
|||
.map(Market::getName) |
|||
.collect(Collectors.toSet()); |
|||
} |
|||
|
|||
// 获取直接子地区 |
|||
public List<Market> getDirectChildren(Integer parentId) { |
|||
return childrenCache.getOrDefault(parentId, new ArrayList<>()); |
|||
} |
|||
|
|||
// 获取市场部下的所有具体市场 |
|||
public List<Market> getSpecificMarketsUnderMarketDepartment() { |
|||
List<Market> specificMarkets = new ArrayList<>(); |
|||
|
|||
// 市场部的ID是3 |
|||
List<Market> marketDepartmentChildren = getDirectChildren(3); |
|||
for (Market market : marketDepartmentChildren) { |
|||
if (market.isSpecificMarket()) { |
|||
specificMarkets.add(market); |
|||
} |
|||
} |
|||
|
|||
return specificMarkets; |
|||
} |
|||
|
|||
// 获取市场部下的所有具体市场ID |
|||
public Set<Integer> getSpecificMarketIdsUnderMarketDepartment() { |
|||
return getSpecificMarketsUnderMarketDepartment().stream() |
|||
.map(Market::getId) |
|||
.collect(Collectors.toSet()); |
|||
} |
|||
|
|||
// 获取用户管辖的所有具体市场ID(包括子地区) |
|||
public Set<Integer> getUserManagedSpecificMarketIds(User user) { |
|||
Set<Integer> allSpecificMarketIds = new HashSet<>(); |
|||
|
|||
Set<Integer> userMarketIds = user.getAllManagedMarketIds(); |
|||
for (Integer marketId : userMarketIds) { |
|||
Market market = getMarketById(marketId); |
|||
if (market != null && market.isSpecificMarket()) { |
|||
allSpecificMarketIds.add(marketId); |
|||
} else { |
|||
// 如果不是具体市场,获取其下的所有具体市场 |
|||
allSpecificMarketIds.addAll(getAllChildrenIds(marketId).stream() |
|||
.filter(id -> { |
|||
Market child = getMarketById(id); |
|||
return child != null && child.isSpecificMarket(); |
|||
}) |
|||
.collect(Collectors.toSet())); |
|||
} |
|||
} |
|||
|
|||
return allSpecificMarketIds; |
|||
} |
|||
|
|||
// 验证地区是否存在 |
|||
public boolean marketExists(Integer marketId) { |
|||
return marketCache.containsKey(marketId); |
|||
} |
|||
|
|||
// 验证地区名称是否存在 |
|||
public boolean marketNameExists(String marketName) { |
|||
return marketNameToIdCache.containsKey(marketName); |
|||
} |
|||
|
|||
// 获取所有地区 |
|||
public List<Market> getAllMarkets() { |
|||
return new ArrayList<>(marketCache.values()); |
|||
} |
|||
|
|||
// 获取所有具体市场(叶子节点) |
|||
public List<Market> getAllSpecificMarkets() { |
|||
return marketCache.values().stream() |
|||
.filter(Market::isSpecificMarket) |
|||
.collect(Collectors.toList()); |
|||
} |
|||
|
|||
// 根据地区ID获取完整路径 |
|||
public String getMarketFullPath(Integer marketId) { |
|||
Market market = marketCache.get(marketId); |
|||
return market != null ? market.getTreelist() : null; |
|||
} |
|||
|
|||
// 根据地区名称获取完整路径 |
|||
public String getMarketFullPathByName(String marketName) { |
|||
Integer marketId = marketNameToIdCache.get(marketName); |
|||
return marketId != null ? getMarketFullPath(marketId) : null; |
|||
} |
|||
} |
|||
@ -1,266 +0,0 @@ |
|||
package com.example.demo.service.cash; |
|||
|
|||
|
|||
import com.example.demo.Node.RefundApprovalNode; |
|||
import com.example.demo.config.cash.RefundApprovalFlowConfig; |
|||
import com.example.demo.domain.vo.cash.CashRecord; |
|||
import com.example.demo.domain.vo.cash.Market; |
|||
import com.example.demo.domain.vo.cash.RefundApprovalRecord; |
|||
import com.example.demo.domain.vo.cash.User; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.*; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Slf4j |
|||
@Service |
|||
public class RefundApprovalService { |
|||
|
|||
private final MarketService marketService; |
|||
|
|||
// 退款审批流程配置缓存 |
|||
private static final Map<String, RefundApprovalFlowConfig> REFUND_APPROVAL_FLOW_CONFIG = new ConcurrentHashMap<>(); |
|||
|
|||
// 角色定义 |
|||
public static final String ROLE_REGIONAL_FINANCE = "REGIONAL_FINANCE"; |
|||
public static final String ROLE_REGIONAL_MANAGER = "REGIONAL_MANAGER"; |
|||
public static final String ROLE_HEADQUARTERS_FINANCE = "HEADQUARTERS_FINANCE"; |
|||
public static final String ROLE_EXECUTOR = "EXECUTOR"; |
|||
public static final String ROLE_SUBMITTER = "SUBMITTER"; |
|||
|
|||
public RefundApprovalService(MarketService marketService) { |
|||
this.marketService = marketService; |
|||
initializeRefundFlowConfigs(); |
|||
} |
|||
|
|||
// 初始化退款审批流程配置(基于地区ID) |
|||
private void initializeRefundFlowConfigs() { |
|||
// 获取市场部下的所有具体市场ID |
|||
Set<Integer> specificMarketIds = marketService.getSpecificMarketIdsUnderMarketDepartment(); |
|||
|
|||
// 为每个具体市场创建审批流程 |
|||
for (Integer marketId : specificMarketIds) { |
|||
Market market = marketService.getMarketById(marketId); |
|||
if (market != null) { |
|||
List<RefundApprovalNode> flowNodes = createRefundFlowForMarket(market); |
|||
REFUND_APPROVAL_FLOW_CONFIG.put(marketId.toString(), |
|||
new RefundApprovalFlowConfig(market.getName() + "退款审批流程", flowNodes)); |
|||
} |
|||
} |
|||
|
|||
// 创建通用审批流程(用于没有特定配置的市场) |
|||
List<RefundApprovalNode> commonRefundFlow = createCommonRefundFlow(); |
|||
REFUND_APPROVAL_FLOW_CONFIG.put("COMMON", new RefundApprovalFlowConfig("通用退款审批流程", commonRefundFlow)); |
|||
|
|||
log.info("退款审批流程配置初始化完成,共配置{}个流程", REFUND_APPROVAL_FLOW_CONFIG.size()); |
|||
} |
|||
|
|||
private List<RefundApprovalNode> createRefundFlowForMarket(Market market) { |
|||
Set<Integer> marketAndChildrenIds = new HashSet<>(); |
|||
marketAndChildrenIds.add(market.getId()); |
|||
marketAndChildrenIds.addAll(marketService.getAllChildrenIds(market.getId())); |
|||
|
|||
List<RefundApprovalNode> nodes = new ArrayList<>(); |
|||
nodes.add(new RefundApprovalNode("地区财务审核", 1, new String[]{ROLE_REGIONAL_FINANCE}, marketAndChildrenIds, true)); |
|||
nodes.add(new RefundApprovalNode("地区负责人审核", 2, new String[]{ROLE_REGIONAL_MANAGER}, marketAndChildrenIds, true)); |
|||
nodes.add(new RefundApprovalNode("总部财务审核", 3, new String[]{ROLE_HEADQUARTERS_FINANCE}, null, true)); // 总部不限制地区 |
|||
nodes.add(new RefundApprovalNode("执行人处理", 4, new String[]{ROLE_EXECUTOR}, null, true)); // 执行人不限制地区 |
|||
|
|||
return nodes; |
|||
} |
|||
|
|||
private List<RefundApprovalNode> createCommonRefundFlow() { |
|||
List<RefundApprovalNode> nodes = new ArrayList<>(); |
|||
nodes.add(new RefundApprovalNode("地区财务审核", 1, new String[]{ROLE_REGIONAL_FINANCE}, null, true)); |
|||
nodes.add(new RefundApprovalNode("地区负责人审核", 2, new String[]{ROLE_REGIONAL_MANAGER}, null, true)); |
|||
nodes.add(new RefundApprovalNode("总部财务审核", 3, new String[]{ROLE_HEADQUARTERS_FINANCE}, null, true)); |
|||
nodes.add(new RefundApprovalNode("执行人处理", 4, new String[]{ROLE_EXECUTOR}, null, true)); |
|||
|
|||
return nodes; |
|||
} |
|||
|
|||
// 获取适合订单的审批流程(基于地区ID) |
|||
private RefundApprovalFlowConfig getSuitableFlowConfig(CashRecord cashRecord) { |
|||
Integer marketId = cashRecord.getPrimaryMarketId(); |
|||
if (marketId != null) { |
|||
// 优先根据具体地区ID获取流程 |
|||
RefundApprovalFlowConfig specificConfig = REFUND_APPROVAL_FLOW_CONFIG.get(marketId.toString()); |
|||
if (specificConfig != null) { |
|||
return specificConfig; |
|||
} |
|||
|
|||
// 如果该市场没有特定配置,查找父级市场的配置 |
|||
Market market = marketService.getMarketById(marketId); |
|||
if (market != null && market.getParentId() != null) { |
|||
RefundApprovalFlowConfig parentConfig = REFUND_APPROVAL_FLOW_CONFIG.get(market.getParentId().toString()); |
|||
if (parentConfig != null) { |
|||
return parentConfig; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 默认返回通用流程 |
|||
return REFUND_APPROVAL_FLOW_CONFIG.get("COMMON"); |
|||
} |
|||
|
|||
// 获取用户有权限审批的订单状态(基于地区ID) |
|||
public List<Integer> getUserVisibleStatuses(User user, CashRecord cashRecord) { |
|||
if (!cashRecord.isRefundOrder()) { |
|||
return new ArrayList<>(); |
|||
} |
|||
|
|||
RefundApprovalFlowConfig flowConfig = getSuitableFlowConfig(cashRecord); |
|||
if (flowConfig != null) { |
|||
return flowConfig.getVisibleStatuses(user, cashRecord.getPrimaryMarketId()); |
|||
} |
|||
|
|||
log.warn("未找到适合订单地区{}的退款审批流程配置", cashRecord.getPrimaryMarketId()); |
|||
return new ArrayList<>(); |
|||
} |
|||
|
|||
// 检查用户是否有权限审批指定订单(基于地区ID) |
|||
public boolean canUserApproveOrder(User user, CashRecord cashRecord) { |
|||
if (!cashRecord.isRefundOrder() || !cashRecord.isInApprovalProcess()) { |
|||
return false; |
|||
} |
|||
|
|||
RefundApprovalFlowConfig flowConfig = getSuitableFlowConfig(cashRecord); |
|||
if (flowConfig != null) { |
|||
return flowConfig.canUserApproveNode(user, cashRecord.getCurrentApprovalLevel(), cashRecord.getPrimaryMarketId()); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
// 检查用户是否可以撤回订单(只有提交人可以在第一个审批节点前撤回) |
|||
public boolean canUserWithdrawOrder(User user, CashRecord cashRecord) { |
|||
if (!cashRecord.isRefundOrder()) { |
|||
return false; |
|||
} |
|||
|
|||
// 只有订单提交人才能撤回 |
|||
boolean isSubmitter = cashRecord.getSubmitterId() != null && |
|||
cashRecord.getSubmitterId().equals(user.getId()); |
|||
|
|||
return isSubmitter && cashRecord.canWithdraw(); |
|||
} |
|||
|
|||
// 提交退款审批 |
|||
public boolean submitRefundApproval(User user, CashRecord cashRecord, String approvalResult, String comments) { |
|||
if (!canUserApproveOrder(user, cashRecord)) { |
|||
log.warn("用户{}没有权限审批退款订单{}", user.getId(), cashRecord.getId()); |
|||
return false; |
|||
} |
|||
|
|||
// 创建审批记录 |
|||
RefundApprovalRecord record = new RefundApprovalRecord(); |
|||
record.setCashRecordId(cashRecord.getId()); |
|||
record.setApprovalLevel(cashRecord.getCurrentApprovalLevel()); |
|||
record.setApproverId(user.getId()); |
|||
record.setApproverName(user.getName()); |
|||
record.setApprovalResult(approvalResult); |
|||
record.setComments(comments); |
|||
record.setApprovalTime(new Date()); |
|||
|
|||
// 更新订单状态 |
|||
boolean approved = "APPROVED".equals(approvalResult); |
|||
Integer nextStatus = cashRecord.getNextStatus(approved); |
|||
cashRecord.setStatus(nextStatus); |
|||
cashRecord.setUpdateTime(new Date()); |
|||
cashRecord.setAuditId(user.getId()); |
|||
cashRecord.setAuditTime(new Date()); |
|||
|
|||
if (!approved) { |
|||
cashRecord.setRejectReason(comments); |
|||
} |
|||
|
|||
log.info("用户{}审批退款订单{},结果:{},新状态:{}", |
|||
user.getName(), cashRecord.getId(), approvalResult, nextStatus); |
|||
return true; |
|||
} |
|||
|
|||
// 撤回退款订单(在第一个审批节点前) |
|||
public boolean withdrawRefundOrder(User user, CashRecord cashRecord, String withdrawReason) { |
|||
if (!canUserWithdrawOrder(user, cashRecord)) { |
|||
log.warn("用户{}不能撤回退款订单{}", user.getId(), cashRecord.getId()); |
|||
return false; |
|||
} |
|||
|
|||
// 创建撤回记录 |
|||
RefundApprovalRecord record = new RefundApprovalRecord(); |
|||
record.setCashRecordId(cashRecord.getId()); |
|||
record.setApprovalLevel(cashRecord.getCurrentApprovalLevel()); |
|||
record.setApproverId(user.getId()); |
|||
record.setApproverName(user.getName()); |
|||
record.setIsWithdrawal(true); |
|||
record.setWithdrawnBy(user.getId()); |
|||
record.setWithdrawReason(withdrawReason); |
|||
record.setWithdrawTime(new Date()); |
|||
|
|||
// 更新订单状态为撤回 |
|||
boolean success = cashRecord.withdraw(); |
|||
if (success) { |
|||
cashRecord.setUpdateTime(new Date()); |
|||
log.info("用户{}撤回退款订单{},原因:{}", user.getName(), cashRecord.getId(), withdrawReason); |
|||
} |
|||
|
|||
return success; |
|||
} |
|||
|
|||
// 重新提交撤回的退款订单 |
|||
public boolean resubmitRefundOrder(User user, CashRecord cashRecord) { |
|||
if (!cashRecord.canResubmit()) { |
|||
log.warn("退款订单{}不能重新提交", cashRecord.getId()); |
|||
return false; |
|||
} |
|||
|
|||
// 检查用户是否是原提交人 |
|||
boolean isSubmitter = cashRecord.getSubmitterId() != null && |
|||
cashRecord.getSubmitterId().equals(user.getId()); |
|||
if (!isSubmitter) { |
|||
log.warn("用户{}不是订单{}的提交人,不能重新提交", user.getId(), cashRecord.getId()); |
|||
return false; |
|||
} |
|||
|
|||
boolean success = cashRecord.resubmit(); |
|||
if (success) { |
|||
cashRecord.setUpdateTime(new Date()); |
|||
log.info("用户{}重新提交退款订单{}", user.getName(), cashRecord.getId()); |
|||
} |
|||
|
|||
return success; |
|||
} |
|||
|
|||
// 获取下一个审批节点信息 |
|||
public RefundApprovalNode getNextApprovalNode(CashRecord cashRecord) { |
|||
RefundApprovalFlowConfig flowConfig = getSuitableFlowConfig(cashRecord); |
|||
if (flowConfig != null) { |
|||
return flowConfig.getNextNode(cashRecord.getCurrentApprovalLevel()); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
// 动态添加退款审批流程配置 |
|||
public void addRefundFlowConfig(String marketId, RefundApprovalFlowConfig flowConfig) { |
|||
REFUND_APPROVAL_FLOW_CONFIG.put(marketId, flowConfig); |
|||
log.info("成功添加地区{}的退款审批流程配置:{}", marketId, flowConfig.getFlowName()); |
|||
} |
|||
|
|||
// 获取所有退款审批流程配置 |
|||
public Map<String, RefundApprovalFlowConfig> getAllRefundFlowConfigs() { |
|||
return new HashMap<>(REFUND_APPROVAL_FLOW_CONFIG); |
|||
} |
|||
|
|||
// 根据地区名称初始化审批流程配置 |
|||
public void initializeFlowForMarketName(String marketName) { |
|||
Market market = marketService.getMarketByName(marketName); |
|||
if (market != null) { |
|||
List<RefundApprovalNode> flowNodes = createRefundFlowForMarket(market); |
|||
REFUND_APPROVAL_FLOW_CONFIG.put(market.getId().toString(), |
|||
new RefundApprovalFlowConfig(market.getName() + "退款审批流程", flowNodes)); |
|||
log.info("为地区{}初始化退款审批流程配置", marketName); |
|||
} |
|||
} |
|||
} |
|||
@ -1,5 +0,0 @@ |
|||
<?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="com.example.demo.mapper.cash.CashRecordMapper"> |
|||
|
|||
</mapper> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue