88e030b7
王彪总
init project
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/**
* 优惠券计算命令类
*
* 功能:根据费用信息计算适用的优惠券规则,主要用于缴费时计算可用的优惠券
* 通过查询费用配置对应的优惠规则,并获取规则下的优惠产品信息
*
* 主要业务流程:
* 1. 验证请求参数完整性
* 2. 查询费用基本信息
* 3. 根据费用配置查询适用的优惠规则
* 4. 根据优惠规则查询对应的优惠产品
* 5. 返回优惠产品列表给前端
*
* @author 吴学文
* @version 1.0
* @since 2024
*/
package com.java110.acct.cmd.coupon;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.doc.annotation.*;
import com.java110.dto.coupon.CouponRuleCppsDto;
import com.java110.dto.coupon.CouponRuleFeeDto;
import com.java110.dto.fee.FeeDto;
import com.java110.intf.acct.ICouponRuleCppsV1InnerServiceSMO;
import com.java110.intf.acct.ICouponRuleFeeV1InnerServiceSMO;
import com.java110.intf.fee.IFeeInnerServiceSMO;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.DateUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
/**
* API文档注解 - 优惠券计算接口
* 提供缴费时计算可用优惠券的功能
*/
@Java110CmdDoc(title = "根据费用计算优惠券",
description = "缴费时计算费用 是否有优惠券",
httpMethod = "get",
url = "http://{ip}:{port}/app/coupon.computePayFeeCoupon",
resource = "acctDoc",
author = "吴学文",
serviceCode = "coupon.computePayFeeCoupon"
)
/**
* 请求参数文档注解
* 定义接口需要的三个核心参数
*/
@Java110ParamsDoc(params = {
@Java110ParamDoc(name = "feeId", length = 30, remark = "费用ID"),
@Java110ParamDoc(name = "cycle", length = 30, remark = "缴费周期"),
|
9750b443
王彪总
fix(config): 更新配置...
|
63
|
@Java110ParamDoc(name = "communityId", length = 30, remark = "项目ID"),
|
88e030b7
王彪总
init project
|
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
})
/**
* 响应参数文档注解
* 定义接口返回的数据结构
*/
@Java110ResponseDoc(
params = {
@Java110ParamDoc(name = "code", type = "int", length = 11, defaultValue = "0", remark = "返回编号,0 成功 其他失败"),
@Java110ParamDoc(name = "msg", type = "String", length = 250, defaultValue = "成功", remark = "描述"),
@Java110ParamDoc(name = "data", type = "Array", remark = "有效数据"),
@Java110ParamDoc(parentNodeName = "data",name = "userId", type = "String", remark = "用户ID"),
@Java110ParamDoc(parentNodeName = "data",name = "token", type = "String", remark = "临时票据"),
}
)
/**
* 请求响应示例文档注解
* 提供接口调用示例
*/
@Java110ExampleDoc(
reqBody="{'feeId':'123123','cycle':'1','communityId':'123123'}",
resBody="{'code':0,'msg':'成功','data':{'userId':'123123','token':'123213'}}"
)
/**
* 命令注解 - 注册服务代码
*/
@Java110Cmd(serviceCode = "coupon.computePayFeeCoupon")
public class ComputePayFeeCouponCmd extends Cmd {
/**
* 优惠规则费用服务接口 - 用于查询费用对应的优惠规则
*/
@Autowired
private ICouponRuleFeeV1InnerServiceSMO couponRuleFeeV1InnerServiceSMOImpl;
/**
* 优惠规则产品服务接口 - 用于查询规则对应的优惠产品
*/
@Autowired
private ICouponRuleCppsV1InnerServiceSMO couponRuleCppsV1InnerServiceSMOImpl;
/**
* 费用服务接口 - 用于查询费用基本信息
*/
@Autowired
private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
/**
* 参数验证方法
*
* 验证请求参数是否包含必要的字段,确保后续业务逻辑能够正常执行
|
9750b443
王彪总
fix(config): 更新配置...
|
117
|
* 主要验证费用ID、项目ID和缴费周期三个关键参数
|
88e030b7
王彪总
init project
|
118
119
120
121
122
123
124
125
126
127
|
*
* @param event 命令事件对象,包含请求相关信息
* @param context 命令数据流上下文,用于获取和设置请求响应数据
* @param reqJson 请求的JSON数据对象
* @throws CmdException 当参数验证失败时抛出命令异常
*/
@Override
public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
// 验证费用ID参数是否存在
Assert.hasKeyAndValue(reqJson,"feeId","未包含费用");
|
9750b443
王彪总
fix(config): 更新配置...
|
128
129
|
// 验证项目ID参数是否存在
Assert.hasKeyAndValue(reqJson,"communityId","未包含项目");
|
88e030b7
王彪总
init project
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
// 验证缴费周期参数是否存在
Assert.hasKeyAndValue(reqJson,"cycles","未包含缴费周期");
}
/**
* 执行优惠券计算命令
*
* 根据费用信息查询适用的优惠券规则,并返回优惠产品信息
* 主要流程:
* 1. 查询费用基本信息
* 2. 根据费用配置查询优惠规则
* 3. 根据优惠规则查询优惠产品
* 4. 返回优惠产品列表
*
* @param event 命令事件对象
* @param context 命令数据流上下文
* @param reqJson 请求的JSON数据对象
* @throws CmdException 命令执行异常
* @throws ParseException 数据解析异常
*/
@Override
public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
// 构建费用查询条件
FeeDto feeDto = new FeeDto();
feeDto.setFeeId(reqJson.getString("feeId"));
// 查询费用信息
List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
// 验证费用存在且唯一
Assert.listOnlyOne(feeDtos,"费用不存在");
// 构建优惠规则查询条件
CouponRuleFeeDto couponRuleFeeDto = new CouponRuleFeeDto();
// 设置费用配置ID - 用于关联优惠规则
couponRuleFeeDto.setFeeConfigId(feeDtos.get(0).getConfigId());
// 设置当前时间,用于判断优惠规则是否在有效期内
couponRuleFeeDto.setCurTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
|
9750b443
王彪总
fix(config): 更新配置...
|
167
|
// 设置项目ID - 限定优惠规则适用范围
|
88e030b7
王彪总
init project
|
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
couponRuleFeeDto.setCommunityId(reqJson.getString("communityId"));
// 设置缴费周期 - 用于匹配周期相关的优惠规则
couponRuleFeeDto.setCycle(reqJson.getString("cycles"));
// 查询适用的优惠规则
List<CouponRuleFeeDto> couponRuleFeeDtos = couponRuleFeeV1InnerServiceSMOImpl.queryCouponRuleFees(couponRuleFeeDto);
// 如果没有找到适用的优惠规则,返回空数组
if(couponRuleFeeDtos == null || couponRuleFeeDtos.size()<1){
context.setResponseEntity(ResultVo.createResponseEntity(new JSONArray()));
return ;
}
// 收集所有适用的规则ID
List<String> ruleIds = new ArrayList<>();
for(CouponRuleFeeDto tmpCouponRuleFeeDto: couponRuleFeeDtos){
ruleIds.add(tmpCouponRuleFeeDto.getRuleId());
}
// 构建优惠产品查询条件
CouponRuleCppsDto couponRuleCppsDto = new CouponRuleCppsDto();
// 设置规则ID数组 - 查询这些规则对应的优惠产品
couponRuleCppsDto.setRuleIds(ruleIds.toArray(new String[ruleIds.size()]));
// 查询优惠产品信息
List<CouponRuleCppsDto> couponRuleCppsDtos = couponRuleCppsV1InnerServiceSMOImpl.queryCouponRuleCppss(couponRuleCppsDto);
// 如果没有找到优惠产品,返回空数组
if(couponRuleCppsDtos == null || couponRuleCppsDtos.size() < 1){
context.setResponseEntity(ResultVo.createResponseEntity(new JSONArray()));
return ;
}
// 返回查询到的优惠产品列表
context.setResponseEntity(ResultVo.createResponseEntity(couponRuleCppsDtos));
}
}
|