From 8954429263a75e3c7d19db20a60370fca005f2bd Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 08 八月 2023 15:44:49 +0800
Subject: [PATCH] 优化代码
---
service-fee/src/main/java/com/java110/fee/cmd/fee/PayMonthFeeCmd.java | 54 ++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 38 insertions(+), 16 deletions(-)
diff --git a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayMonthFeeCmd.java b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayMonthFeeCmd.java
index 9226f62..db81ebb 100644
--- a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayMonthFeeCmd.java
+++ b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayMonthFeeCmd.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
@@ -28,6 +29,7 @@
import com.java110.po.fee.PayFeePo;
import com.java110.po.owner.RepairPoolPo;
import com.java110.po.owner.RepairUserPo;
+import com.java110.utils.cache.CommonCache;
import com.java110.utils.constant.FeeConfigConstant;
import com.java110.utils.constant.FeeFlagTypeConstant;
import com.java110.utils.constant.ResponseConstant;
@@ -94,6 +96,9 @@
@Autowired
private IRepairInnerServiceSMO repairInnerServiceSMO;
+ @Autowired
+ private IFeeReceiptInnerServiceSMO feeReceiptInnerServiceSMOImpl;
+
@Override
public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
@@ -148,6 +153,7 @@
@Override
+ @Java110Transactional
public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
String userId = context.getReqHeaders().get("user-id");
UserDto userDto = new UserDto();
@@ -155,13 +161,33 @@
List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
Assert.listOnlyOne(userDtos, "鐢ㄦ埛鏈櫥褰�");
+
+ //todo 鐢熸垚鏀舵嵁缂栧彿
+ String receiptCode = feeReceiptInnerServiceSMOImpl.generatorReceiptCode(reqJson.getString("communityId"));
+
List<PayFeeDetailMonthDto> payFeeDetailMonthDtos = (List<PayFeeDetailMonthDto>) reqJson.get("payFeeDetailMonthDtos");
+ Calendar createTimeCal = Calendar.getInstance();
+
+ Map<String, FeeDto> feeDtoMap = new HashMap<>();
JSONArray details = new JSONArray();
for (PayFeeDetailMonthDto payFeeDetailMonthDto : payFeeDetailMonthDtos) {
+ // todo 璐圭敤鍙煡涓�娆℃彁楂� 鏁堢巼
+ if (!feeDtoMap.containsKey(payFeeDetailMonthDto.getFeeId())) {
+ //todo 鏌ヨ璐圭敤鏄惁瀛樺湪
+ FeeDto feeDto = new FeeDto();
+ feeDto.setFeeId(payFeeDetailMonthDto.getFeeId());
+ feeDto.setCommunityId(payFeeDetailMonthDto.getCommunityId());
+ List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
+ if (feeDtos == null || feeDtos.size() != 1) {
+ throw new CmdException("璐圭敤涓嶅瓨鍦�");
+ }
+ feeDtoMap.put(payFeeDetailMonthDto.getFeeId(), feeDtos.get(0));
+ }
+ createTimeCal.add(Calendar.SECOND, 1);
try {
- doMonthFee(payFeeDetailMonthDto, context, userDtos.get(0), reqJson);
+ doMonthFee(payFeeDetailMonthDto, context, userDtos.get(0), reqJson, createTimeCal.getTime(), feeDtoMap,receiptCode);
} catch (Exception e) {
logger.error("澶勭悊寮傚父", e);
throw new CmdException(e.getMessage());
@@ -183,7 +209,7 @@
* @param userDto
* @param reqJson
*/
- private void doMonthFee(PayFeeDetailMonthDto payFeeDetailMonthDto, ICmdDataFlowContext context, UserDto userDto, JSONObject reqJson) {
+ private void doMonthFee(PayFeeDetailMonthDto payFeeDetailMonthDto, ICmdDataFlowContext context, UserDto userDto, JSONObject reqJson, Date createTime, Map<String, FeeDto> feeDtoMap,String receiptCode) {
//todo 璁$畻缁撴潫鏃堕棿
Date startTime = DateUtil.getDateFromStringB(payFeeDetailMonthDto.getCurMonthTime());
Calendar calendar = Calendar.getInstance();
@@ -191,14 +217,6 @@
calendar.add(Calendar.MONTH, 1);
String endTime = DateUtil.getFormatTimeStringB(calendar.getTime());
- //todo 鏌ヨ璐圭敤鏄惁瀛樺湪
- FeeDto feeDto = new FeeDto();
- feeDto.setFeeId(payFeeDetailMonthDto.getFeeId());
- feeDto.setCommunityId(payFeeDetailMonthDto.getCommunityId());
- List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
- if (feeDtos == null || feeDtos.size() != 1) {
- throw new CmdException("璐圭敤涓嶅瓨鍦�");
- }
//鑾峰彇璁㈠崟ID
String oId = Java110TransactionalFactory.getOId();
@@ -216,12 +234,15 @@
}
payFeeDetailPo.setPayOrderId(oId);
payFeeDetailPo.setEndTime(endTime);
-
+ // todo 鎸夋湀浜よ垂鏃� 涓昏鎸夋椂闂撮『搴忔帓搴忔椂 鑳藉鏁撮綈
+ payFeeDetailPo.setCreateTime(DateUtil.getFormatTimeStringA(createTime));
+ //todo 缂撳瓨鏀舵嵁缂栧彿
+ CommonCache.setValue(payFeeDetailPo.getDetailId()+CommonCache.RECEIPT_CODE,receiptCode,CommonCache.DEFAULT_EXPIRETIME_TWO_MIN);
int flag = payFeeDetailNewV1InnerServiceSMOImpl.savePayFeeDetailNew(payFeeDetailPo);
if (flag < 1) {
throw new CmdException("缂磋垂澶辫触");
}
- payFeePo = modifyFee(payFeeDetailMonthDto, reqJson, feeDtos.get(0), endTime);
+ payFeePo = modifyFee(payFeeDetailMonthDto, reqJson, feeDtoMap.get(payFeeDetailMonthDto.getFeeId()), endTime);
flag = payFeeV1InnerServiceSMOImpl.updatePayFee(payFeePo);
if (flag < 1) {
@@ -233,13 +254,13 @@
payFeeDetailMonthDto.setDetailId(payFeeDetailPo.getDetailId());
} finally {
- DistributedLock.releaseDistributedLock(requestId, key);
+ DistributedLock.releaseDistributedLock(key, requestId);
}
//杞﹁締寤舵湡
- updateOwnerCarEndTime(payFeePo, reqJson, feeDtos.get(0));
+ updateOwnerCarEndTime(payFeePo, reqJson, feeDtoMap.get(payFeeDetailMonthDto.getFeeId()));
//澶勭悊鎶ヤ慨鍗�
- doDealRepairOrder(payFeeDetailMonthDto, feeDtos.get(0));
+ doDealRepairOrder(payFeeDetailMonthDto, feeDtoMap.get(payFeeDetailMonthDto.getFeeId()));
}
@@ -363,7 +384,8 @@
for (PayFeeDetailMonthDto tmpFeeDetailMonthDto : feeDetailMonthDtos) {
if (Integer.parseInt(tmpFeeDetailMonthDto.getDetailYear()) <= Integer.parseInt(tmpPayFeeDetailMonthDto.getDetailYear())
&& Integer.parseInt(tmpFeeDetailMonthDto.getDetailMonth()) < Integer.parseInt(tmpPayFeeDetailMonthDto.getDetailMonth())) {
- throw new CmdException("鏈繛缁即璐癸紝璇烽�夋嫨" + tmpFeeDetailMonthDto.getDetailYear() + "-" + tmpFeeDetailMonthDto.getDetailMonth() + " ," + tmpFeeDetailMonthDto.getFeeName());
+ throw new CmdException("鏈繛缁即璐癸紝璇烽�夋嫨" + tmpFeeDetailMonthDto.getDetailYear() + "-" + tmpFeeDetailMonthDto.getDetailMonth()
+ + " ," + tmpPayFeeDetailMonthDto.getFeeName());
}
if (Integer.parseInt(tmpFeeDetailMonthDto.getDetailYear()) == Integer.parseInt(tmpPayFeeDetailMonthDto.getDetailYear())
&& Integer.parseInt(tmpFeeDetailMonthDto.getDetailMonth()) == Integer.parseInt(tmpPayFeeDetailMonthDto.getDetailMonth())) {
--
Gitblit v1.8.0