From 0b3ff378a9faaf9d7a4831b7f0de67378fe0dfea Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 30 五月 2023 12:20:15 +0800
Subject: [PATCH] optimize 统计
---
service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java | 110 ++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 92 insertions(+), 18 deletions(-)
diff --git a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java
index 3033616..88b55b2 100644
--- a/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java
+++ b/service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java
@@ -4,17 +4,23 @@
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
-import com.java110.core.event.cmd.AbstractServiceCmdListener;
+import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.log.LoggerFactory;
import com.java110.core.smo.IComputeFeeSMO;
import com.java110.dto.account.AccountDto;
-import com.java110.dto.couponUser.CouponUserDto;
+import com.java110.dto.community.CommunityDto;
+import com.java110.dto.couponPool.CouponUserDto;
+import com.java110.dto.fee.FeeAttrDto;
+import com.java110.dto.fee.FeeConfigDto;
import com.java110.dto.fee.FeeDetailDto;
import com.java110.dto.fee.FeeDto;
-import com.java110.dto.feeDiscount.ComputeDiscountDto;
+import com.java110.dto.fee.ComputeDiscountDto;
+import com.java110.intf.acct.IAccountDetailInnerServiceSMO;
import com.java110.intf.acct.IAccountInnerServiceSMO;
import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
+import com.java110.intf.community.ICommunityV1InnerServiceSMO;
import com.java110.intf.community.IRepairUserInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.intf.fee.*;
@@ -27,7 +33,6 @@
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import org.slf4j.Logger;
-import com.java110.core.log.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -36,6 +41,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -50,9 +56,9 @@
* // modify by 寮犱笁 at 2021-09-12 绗�10琛屽湪鏌愮鍦烘櫙涓嬪瓨鍦ㄦ煇绉峛ug 闇�瑕佷慨澶嶏紝娉ㄩ噴10鑷�20琛� 鍔犲叆 20琛岃嚦30琛�
*/
@Java110Cmd(serviceCode = "fee.payFeePre")
-public class PayFeePreCmd extends AbstractServiceCmdListener {
- private static Logger logger = LoggerFactory.getLogger(PayFeePreCmd.class);
+public class PayFeePreCmd extends Cmd {
+ private static Logger logger = LoggerFactory.getLogger(PayFeePreCmd.class);
@Autowired
private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
@@ -83,11 +89,21 @@
@Autowired
private IComputeFeeSMO computeFeeSMOImpl;
+
@Autowired
private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
@Autowired
private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
+
+ @Autowired
+ private ICommunityV1InnerServiceSMO communityV1InnerServiceSMOImpl;
+
+ @Autowired
+ private IAccountDetailInnerServiceSMO accountDetailInnerServiceSMOImpl;
+
+ @Autowired
+ private IFeeAccountDetailServiceSMO feeAccountDetailServiceSMOImpl;
@Override
public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
@@ -102,14 +118,56 @@
Assert.hasLength(reqJson.getString("receivedAmount"), "瀹炴敹閲戦涓嶈兘涓虹┖");
Assert.hasLength(reqJson.getString("feeId"), "璐圭敤ID涓嶈兘涓虹┖");
Assert.hasLength(reqJson.getString("appId"), "appId涓嶈兘涓虹┖");
+
+
+ //鍒ゆ柇鏄惁 璐圭敤鐘舵�佷负缂磋垂缁撴潫
+ FeeDto feeDto = new FeeDto();
+ feeDto.setFeeId(reqJson.getString("feeId"));
+ feeDto.setCommunityId(reqJson.getString("communityId"));
+ List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
+
+ Assert.listOnlyOne(feeDtos, "浼犲叆璐圭敤ID閿欒");
+
+ feeDto = feeDtos.get(0);
+
+ if (FeeDto.STATE_FINISH.equals(feeDto.getState())) {
+ throw new IllegalArgumentException("鏀惰垂宸茬粡缁撴潫锛屼笉鑳藉啀缂磋垂");
+ }
+
+ Date endTime = feeDto.getEndTime();
+
+ FeeConfigDto feeConfigDto = new FeeConfigDto();
+ feeConfigDto.setConfigId(feeDto.getConfigId());
+ feeConfigDto.setCommunityId(reqJson.getString("communityId"));
+ List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
+
+ if (feeConfigDtos != null && feeConfigDtos.size() == 1) {
+ try {
+ Date configEndTime = DateUtil.getDateFromString(feeConfigDtos.get(0).getEndTime(), DateUtil.DATE_FORMATE_STRING_A);
+ configEndTime = DateUtil.stepDay(configEndTime, 5);
+
+ Date newDate = DateUtil.stepMonth(endTime, reqJson.getInteger("cycles"));
+
+ if (newDate.getTime() > configEndTime.getTime()) {
+ throw new IllegalArgumentException("缂磋垂鍛ㄦ湡瓒呰繃 缂磋垂缁撴潫鏃堕棿");
+ }
+
+ } catch (Exception e) {
+ logger.error("姣旇緝璐圭敤鏃ユ湡澶辫触", e);
+ }
+ }
+
}
@Override
public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
logger.debug("ServiceDataFlowEvent : {}", event);
+ String userId = cmdDataFlowContext.getReqHeaders().get("user-id");
+
String appId = cmdDataFlowContext.getReqHeaders().get("app-id");
reqJson.put("appId", appId);
+ reqJson.put("userId",userId);
FeeDto feeDto = new FeeDto();
feeDto.setFeeId(reqJson.getString("feeId"));
@@ -151,10 +209,35 @@
}
paramOut.put("receivedAmount", receivedAmount);
+ String feeName = getObjName(feeDto);
+ paramOut.put("feeName", feeName);
+
ResponseEntity<String> responseEntity = new ResponseEntity<>(paramOut.toJSONString(), HttpStatus.OK);
reqJson.putAll(paramOut);
CommonCache.setValue("payFeePre" + paramOut.getString("oId"), reqJson.toJSONString(), 24 * 60 * 60);
cmdDataFlowContext.setResponseEntity(responseEntity);
+ }
+
+ private String getObjName(FeeDto feeDto) {
+ //鏌ヨ灏忓尯鍚嶇О
+ CommunityDto communityDto = new CommunityDto();
+ communityDto.setCommunityId(feeDto.getCommunityId());
+ List<CommunityDto> communityDtos = communityV1InnerServiceSMOImpl.queryCommunitys(communityDto);
+
+ Assert.listOnlyOne(communityDtos, "灏忓尯涓嶅瓨鍦�");
+
+ List<FeeAttrDto> feeAttrDtos = feeDto.getFeeAttrDtos();
+ if (feeAttrDtos == null || feeAttrDtos.size() < 1) {
+ return communityDtos.get(0).getName() + "-" + feeDto.getFeeName();
+ }
+
+ for (FeeAttrDto feeAttrDto : feeAttrDtos) {
+ if (FeeAttrDto.SPEC_CD_PAY_OBJECT_NAME.equals(feeAttrDto.getSpecCd())) {
+ return communityDtos.get(0).getName() + "-" + feeAttrDto.getValue() + "-" + feeDto.getFeeName();
+ }
+ }
+
+ return communityDtos.get(0).getName() + "-" + feeDto.getFeeName();
}
/**
@@ -198,20 +281,11 @@
return 0.0;
}
- BigDecimal totalAccountAmount = new BigDecimal(0);
- for (AccountDto tmpAccountDto : accountDtos) {
- totalAccountAmount = totalAccountAmount.add(new BigDecimal(tmpAccountDto.getAmount()));
- }
+ BigDecimal money = new BigDecimal(0);
- double tmpDeductionAmount = totalAccountAmount.subtract(new BigDecimal(deductionAmount)).doubleValue();
- if (tmpDeductionAmount < 0) {
- reqJson.put("deductionAmount", totalAccountAmount.doubleValue());
- reqJson.put("selectUserAccount", BeanConvertUtil.beanCovertJSONArray(accountDtos));
- return totalAccountAmount.doubleValue();
- }
- reqJson.put("deductionAmount", deductionAmount);
+ reqJson.put("deductionAmount", money.doubleValue());
reqJson.put("selectUserAccount", BeanConvertUtil.beanCovertJSONArray(accountDtos));
- return deductionAmount;
+ return money.doubleValue();
}
private double checkCouponUser(JSONObject paramObj) {
--
Gitblit v1.8.0