From 7c36caa1b7bb37633e95b0934957b2b75a34a621 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期日, 04 九月 2022 18:39:10 +0800
Subject: [PATCH] 优化代码
---
service-api/src/main/java/com/java110/api/smo/payment/impl/ToPaySMOImpl.java | 197 ++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 179 insertions(+), 18 deletions(-)
diff --git a/service-api/src/main/java/com/java110/api/smo/payment/impl/ToPaySMOImpl.java b/service-api/src/main/java/com/java110/api/smo/payment/impl/ToPaySMOImpl.java
index 8c2c9d7..ff2e568 100644
--- a/service-api/src/main/java/com/java110/api/smo/payment/impl/ToPaySMOImpl.java
+++ b/service-api/src/main/java/com/java110/api/smo/payment/impl/ToPaySMOImpl.java
@@ -2,26 +2,33 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
-import com.java110.core.context.IPageData;
-import com.java110.core.context.PageData;
-import com.java110.dto.app.AppDto;
-import com.java110.dto.owner.OwnerAppUserDto;
-import com.java110.dto.smallWeChat.SmallWeChatDto;
import com.java110.api.properties.WechatAuthProperties;
import com.java110.api.smo.AppAbstractComponentSMO;
import com.java110.api.smo.payment.IToPaySMO;
import com.java110.api.smo.payment.adapt.IPayAdapt;
+import com.java110.core.context.IPageData;
+import com.java110.core.context.PageData;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.log.LoggerFactory;
+import com.java110.dto.app.AppDto;
+import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.intf.acct.IAccountDetailInnerServiceSMO;
+import com.java110.intf.acct.IAccountInnerServiceSMO;
+import com.java110.intf.fee.IFeeAccountDetailServiceSMO;
+import com.java110.po.account.AccountPo;
+import com.java110.po.accountDetail.AccountDetailPo;
+import com.java110.po.feeAccountDetail.FeeAccountDetailPo;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.constant.CommonConstant;
-import com.java110.utils.constant.ServiceConstant;
import com.java110.utils.constant.WechatConstant;
import com.java110.utils.factory.ApplicationContextFactory;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.StringUtil;
+import com.java110.vo.ResultVo;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
@@ -29,6 +36,7 @@
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
+import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -36,8 +44,8 @@
@Service("toPaySMOImpl")
public class ToPaySMOImpl extends AppAbstractComponentSMO implements IToPaySMO {
- private static final Logger logger = LoggerFactory.getLogger(AppAbstractComponentSMO.class);
+ private static final Logger logger = LoggerFactory.getLogger(AppAbstractComponentSMO.class);
@Autowired
private RestTemplate restTemplate;
@@ -45,9 +53,17 @@
@Autowired
private RestTemplate outRestTemplate;
-
@Autowired
private WechatAuthProperties wechatAuthProperties;
+
+ @Autowired
+ private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
+
+ @Autowired
+ private IAccountDetailInnerServiceSMO accountDetailInnerServiceSMOImpl;
+
+ @Autowired
+ private IFeeAccountDetailServiceSMO feeAccountDetailServiceSMOImpl;
@Override
public ResponseEntity<String> toPay(IPageData pd) {
@@ -69,7 +85,7 @@
@Override
protected ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) throws Exception {
- ResponseEntity responseEntity = null;
+ ResponseEntity<String> responseEntity = null;
SmallWeChatDto smallWeChatDto = getSmallWechat(pd, paramIn);
@@ -91,21 +107,165 @@
}
JSONObject orderInfo = JSONObject.parseObject(responseEntity.getBody().toString());
String orderId = orderInfo.getString("oId");
+ String feeName = orderInfo.getString("feeName");
double money = Double.parseDouble(orderInfo.getString("receivedAmount"));
- //闇�瑕佸垽鏂噾棰濇槸鍚� == 0 绛変簬0 鐩存帴鎺夌即璐归�氱煡鎺ュ彛
+ //闇�瑕佸垽鏂噾棰濇槸鍚� == 0 绛変簬0 鐩存帴璋冪即璐归�氱煡鎺ュ彛
if (money <= 0) {
JSONObject paramOut = new JSONObject();
paramOut.put("oId", orderId);
String urlOut = "fee.payFeeConfirm";
- responseEntity = this.callCenterService(getHeaders("-1",pd.getAppId()), paramOut.toJSONString(), urlOut, HttpMethod.POST);
+ responseEntity = this.callCenterService(getHeaders("-1", pd.getAppId()), paramOut.toJSONString(), urlOut, HttpMethod.POST);
JSONObject param = new JSONObject();
if (responseEntity.getStatusCode() != HttpStatus.OK) {
- param.put("code","101");
- param.put("msg","鎵h垂涓�0鍥炶皟澶辫触");
+ param.put("code", "101");
+ param.put("msg", "鎵h垂涓�0鍥炶皟澶辫触");
return new ResponseEntity(JSONObject.toJSONString(param), HttpStatus.OK);
}
- param.put("code","100");
- param.put("msg","鎵h垂涓�0鍥炶皟鎴愬姛");
+ JSONObject result = JSONObject.parseObject(responseEntity.getBody());
+ if (ResultVo.CODE_OK != result.getInteger("code")) {
+ return responseEntity;
+ }
+ // 鍚村鏂� 杩欎釜浠g爜鍐欑殑鏈夐棶棰� 宸茬粡鍦� payFeeConfirm 杩欓噷澶勭悊杩囩幇閲戜簡 杩欓噷杩樺鐞嗕竴閬� 閫昏緫涓婃湁闂 锛岃绉绘鍒� fee.payFeeConfirm 涓鐞�
+// if (paramIn.containsKey("selectUserAccount") && !StringUtil.isEmpty(paramIn.getString("selectUserAccount"))) {
+// String selectUserAccount = paramIn.getString("selectUserAccount");
+// JSONArray params = JSONArray.parseArray(selectUserAccount);
+// for (int paramIndex = 0; paramIndex < params.size(); paramIndex++) {
+// JSONObject paramObj = params.getJSONObject(paramIndex);
+// if (!StringUtil.isEmpty(paramObj.getString("acctType")) && paramObj.getString("acctType").equals("2004")) { //绉垎璐︽埛
+// //璐︽埛閲戦
+// BigDecimal amount = new BigDecimal(paramObj.getString("amount"));
+// //鑾峰彇鏈�澶ф姷鎵gН鍒�
+// BigDecimal maximumNumber = new BigDecimal(paramObj.getString("maximumNumber"));
+// //鑾峰彇绉垎鎶垫墸姣斾緥
+// BigDecimal deductionProportion = new BigDecimal(paramObj.getString("deductionProportion"));
+// int flag = amount.compareTo(maximumNumber);
+// BigDecimal redepositAmount = new BigDecimal("0.00");
+// BigDecimal integralAmount = new BigDecimal("0.00");
+// if (flag == 1) { //璐︽埛绉垎澶т簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+// redepositAmount = maximumNumber;
+// integralAmount = amount.subtract(maximumNumber);
+// }
+// if (flag > -1) { //璐︽埛绉垎澶т簬绛変簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤鏈�澶т娇鐢ㄧН鍒嗘姷鎵�
+// redepositAmount = maximumNumber;
+// integralAmount = amount.subtract(maximumNumber);
+// }
+// if (flag == -1) { //璐︽埛绉垎灏忎簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤璐︽埛绉垎鎶垫墸
+// redepositAmount = amount;
+// }
+// if (flag < 1) { //璐︽埛绉垎灏忎簬绛変簬鏈�澶т娇鐢ㄧН鍒嗭紝灏辩敤璐︽埛绉垎鎶垫墸
+// redepositAmount = amount;
+// }
+// if (flag == 0) { //璐︽埛绉垎绛変簬鏈�澶т娇鐢ㄧН鍒�
+// redepositAmount = amount;
+// }
+// //鏇存柊璐︽埛淇℃伅
+// AccountPo accountPo = new AccountPo();
+// accountPo.setAcctId(paramObj.getString("acctId"));
+// accountPo.setAmount(integralAmount.toString());
+// accountInnerServiceSMOImpl.updateAccount(accountPo);
+// //鐢熸垚璐︽埛璇︽儏
+// AccountDetailPo accountDetailPo = new AccountDetailPo();
+// accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
+// accountDetailPo.setAcctId(paramObj.getString("acctId"));
+// accountDetailPo.setDetailType("2002"); //1001 杞叆 2002 杞嚭
+// accountDetailPo.setRelAcctId("-1");
+// accountDetailPo.setAmount(redepositAmount.toString());
+// accountDetailPo.setObjType("6006"); //6006 涓汉 7007 鍟嗘埛
+// accountDetailPo.setObjId(paramObj.getString("objId"));
+// accountDetailPo.setOrderId("-1");
+// accountDetailPo.setbId("-1");
+// accountDetailPo.setRemark("鎵嬫満绔Н鍒嗘姷鎵�");
+// accountDetailPo.setCreateTime(new Date());
+// accountDetailInnerServiceSMOImpl.saveAccountDetails(accountDetailPo);
+// //璁$畻绉垎鎹㈢畻鐨勯噾棰�
+// BigDecimal divide = redepositAmount.divide(deductionProportion);
+// BigDecimal deductionAmount = new BigDecimal(paramIn.getString("deductionAmount"));
+// //璁$畻瀹炰粯閲戦
+// int flag2 = divide.compareTo(deductionAmount);
+// BigDecimal subtract = new BigDecimal("0.00");
+// //鐢熸垚鎶垫墸鏄庣粏璁板綍
+// FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+// if (flag2 == -1) { //绉垎鎹㈢畻閲戦灏忎簬搴斾粯閲戦
+// subtract = deductionAmount.subtract(divide);
+// BigDecimal multiply = divide.multiply(deductionProportion);
+// feeAccountDetailPo.setAmount(multiply.toString()); //绉垎鎶垫墸閲戦
+// } else if (flag < 1) { //绉垎鎹㈢畻閲戦灏忎簬绛変簬搴斾粯閲戦
+// subtract = deductionAmount.subtract(divide);
+// BigDecimal multiply = divide.multiply(deductionProportion);
+// feeAccountDetailPo.setAmount(multiply.toString()); //绉垎鎶垫墸閲戦
+// } else {
+// BigDecimal multiply = deductionAmount.multiply(deductionProportion);
+// feeAccountDetailPo.setAmount(multiply.toString()); //绉垎鎶垫墸閲戦
+// }
+// paramIn.put("receivedMoney", subtract);
+//// payFeeDetailPo.setReceivedAmount(subtract.toString());
+// feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+// feeAccountDetailPo.setDetailId(accountDetailPo.getDetailId());
+// feeAccountDetailPo.setCommunityId(paramObj.getString("communityId"));
+// feeAccountDetailPo.setState("1003"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+// feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+// } else if (!StringUtil.isEmpty(paramObj.getString("acctType")) && paramObj.getString("acctType").equals("2003")) { //鐜伴噾璐︽埛
+// //璐︽埛閲戦
+// BigDecimal amount = new BigDecimal(paramObj.getString("amount"));
+// //鑾峰彇搴旀敹閲戦
+// BigDecimal deductionAmount = new BigDecimal("0.00");
+// if (paramIn.containsKey("receivedMoney") && !StringUtil.isEmpty(paramIn.getString("receivedMoney"))) {
+// deductionAmount = new BigDecimal(paramIn.getString("receivedMoney"));
+// } else {
+// deductionAmount = new BigDecimal(paramIn.getString("deductionAmount"));
+// }
+// int flag = amount.compareTo(deductionAmount);
+// BigDecimal redepositAmount = new BigDecimal("0.00");
+// BigDecimal integralAmount = new BigDecimal("0.00");
+// if (flag == 1) { //鐜伴噾璐︽埛澶т簬搴旀敹閲戦锛屽氨鐢ㄥ簲鏀堕噾棰濇姷鎵�
+// redepositAmount = deductionAmount;
+// integralAmount = amount.subtract(deductionAmount);
+// }
+// if (flag > -1) { //鐜伴噾璐︽埛澶т簬绛変簬搴旀敹閲戦锛屽氨鐢ㄥ簲鏀堕噾棰濇姷鎵�
+// redepositAmount = deductionAmount;
+// integralAmount = amount.subtract(deductionAmount);
+// }
+// if (flag == -1) { //鐜伴噾璐︽埛灏忎簬瀹炴敹閲戦锛屽氨鐢ㄧ幇閲戣处鎴锋姷鎵�
+// redepositAmount = amount;
+// }
+// if (flag < 1) { //鐜伴噾璐︽埛灏忎簬绛変簬搴旀敹閲戦锛屽氨鐢ㄧ幇閲戣处鎴锋姷鎵�
+// redepositAmount = amount;
+// }
+// if (flag == 0) { //鐜伴噾璐︽埛绛変簬搴旀敹閲戦
+// redepositAmount = amount;
+// }
+// //鏇存柊璐︽埛淇℃伅
+// AccountPo accountPo = new AccountPo();
+// accountPo.setAcctId(paramObj.getString("acctId"));
+// accountPo.setAmount(integralAmount.toString());
+// accountInnerServiceSMOImpl.updateAccount(accountPo);
+// //鐢熸垚璐︽埛璇︽儏
+// AccountDetailPo accountDetailPo = new AccountDetailPo();
+// accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
+// accountDetailPo.setAcctId(paramObj.getString("acctId"));
+// accountDetailPo.setDetailType("2002"); //1001 杞叆 2002 杞嚭
+// accountDetailPo.setRelAcctId("-1");
+// accountDetailPo.setAmount(redepositAmount.toString());
+// accountDetailPo.setObjType("6006"); //6006 涓汉 7007 鍟嗘埛
+// accountDetailPo.setObjId(paramObj.getString("objId"));
+// accountDetailPo.setOrderId("-1");
+// accountDetailPo.setbId("-1");
+// accountDetailPo.setRemark("鎵嬫満绔幇閲戣处鎴锋姷鎵�");
+// accountDetailPo.setCreateTime(new Date());
+// accountDetailInnerServiceSMOImpl.saveAccountDetails(accountDetailPo);
+// //鐢熸垚鎶垫墸鏄庣粏璁板綍
+// FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
+// feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
+// feeAccountDetailPo.setDetailId(accountDetailPo.getDetailId());
+// feeAccountDetailPo.setCommunityId(paramIn.getString("communityId"));
+// feeAccountDetailPo.setState("1002"); //1001 鏃犳姷鎵� 1002 鐜伴噾璐︽埛鎶垫墸 1003 绉垎璐︽埛鎶垫墸 1004 浼樻儬鍒告姷鎵�
+// feeAccountDetailPo.setAmount(redepositAmount.toString()); //绉垎鎶垫墸閲戦
+// feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
+// }
+// }
+// }
+ param.put("code", "100");
+ param.put("msg", "鎵h垂涓�0鍥炶皟鎴愬姛");
return new ResponseEntity(JSONObject.toJSONString(param), HttpStatus.OK);
}
String appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA;
@@ -138,13 +298,13 @@
payAdapt = StringUtil.isEmpty(payAdapt) ? DEFAULT_PAY_ADAPT : payAdapt;
//鏀粯閫傞厤鍣�
IPayAdapt tPayAdapt = ApplicationContextFactory.getBean(payAdapt, IPayAdapt.class);
- Map result = tPayAdapt.java110Payment(outRestTemplate, paramIn.getString("feeName"), paramIn.getString("tradeType"), orderId, money, openId, smallWeChatDto);
+ Map result = tPayAdapt.java110Payment(outRestTemplate, feeName, paramIn.getString("tradeType"), orderId, money, openId, smallWeChatDto);
responseEntity = new ResponseEntity(JSONObject.toJSONString(result), HttpStatus.OK);
return responseEntity;
}
- private Map<String, String> getHeaders(String userId,String appId) {
+ private Map<String, String> getHeaders(String userId, String appId) {
Map<String, String> headers = new HashMap<>();
headers.put(CommonConstant.HTTP_APP_ID.toLowerCase(), appId);
headers.put(CommonConstant.HTTP_USER_ID.toLowerCase(), userId);
@@ -153,6 +313,7 @@
headers.put(CommonConstant.HTTP_SIGN.toLowerCase(), "");
return headers;
}
+
private SmallWeChatDto getSmallWechat(IPageData pd, JSONObject paramIn) {
ResponseEntity responseEntity = null;
--
Gitblit v1.8.0