From c2614ad5c7d1e27fae68e52cd058af363464cdb4 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期六, 21 五月 2022 23:16:38 +0800
Subject: [PATCH] 优化代码
---
service-acct/src/main/java/com/java110/acct/smo/impl/ShopVipAccountInnerServiceSMOImpl.java | 131 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 131 insertions(+), 0 deletions(-)
diff --git a/service-acct/src/main/java/com/java110/acct/smo/impl/ShopVipAccountInnerServiceSMOImpl.java b/service-acct/src/main/java/com/java110/acct/smo/impl/ShopVipAccountInnerServiceSMOImpl.java
index 4d32bb2..ca5fbe7 100644
--- a/service-acct/src/main/java/com/java110/acct/smo/impl/ShopVipAccountInnerServiceSMOImpl.java
+++ b/service-acct/src/main/java/com/java110/acct/smo/impl/ShopVipAccountInnerServiceSMOImpl.java
@@ -1,17 +1,28 @@
package com.java110.acct.smo.impl;
+import com.java110.acct.dao.IShopVipAccountDetailServiceDao;
import com.java110.acct.dao.IShopVipAccountServiceDao;
+import com.java110.core.annotation.Java110Transactional;
import com.java110.core.base.smo.BaseServiceSMO;
+import com.java110.core.factory.GenerateCodeFactory;
import com.java110.dto.PageDto;
+import com.java110.dto.account.AccountDto;
+import com.java110.dto.accountDetail.AccountDetailDto;
import com.java110.dto.shopVipAccount.ShopVipAccountDto;
import com.java110.intf.acct.IShopVipAccountInnerServiceSMO;
+import com.java110.po.account.AccountPo;
+import com.java110.po.accountDetail.AccountDetailPo;
import com.java110.po.shopVipAccount.ShopVipAccountPo;
+import com.java110.po.shopVipAccountDetail.ShopVipAccountDetailPo;
+import com.java110.utils.lock.DistributedLock;
import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
+import java.math.BigDecimal;
import java.util.List;
/**
@@ -25,6 +36,8 @@
@RestController
public class ShopVipAccountInnerServiceSMOImpl extends BaseServiceSMO implements IShopVipAccountInnerServiceSMO {
+ @Autowired
+ private IShopVipAccountDetailServiceDao shopVipAccountDetailServiceDaoImpl;
@Autowired
private IShopVipAccountServiceDao shopVipAccountServiceDaoImpl;
@@ -80,4 +93,122 @@
public void setShopVipAccountServiceDaoImpl(IShopVipAccountServiceDao shopVipAccountServiceDaoImpl) {
this.shopVipAccountServiceDaoImpl = shopVipAccountServiceDaoImpl;
}
+
+ /**
+ * 棰勫瓨鎺ュ彛
+ *
+ * @param accountDetailPo
+ * @return
+ */
+ @Override
+ @Java110Transactional
+ public int prestoreAccount(@RequestBody ShopVipAccountDetailPo accountDetailPo) {
+
+ if (StringUtil.isEmpty(accountDetailPo.getVipAcctId())) {
+ throw new IllegalArgumentException("璐︽埛ID涓虹┖");
+ }
+ //寮�濮嬫灧閿�
+ String requestId = DistributedLock.getLockUUID();
+ String key = accountDetailPo.getVipAcctId();
+ ShopVipAccountDto accountDto = null;
+ List<ShopVipAccountDto> accounts = null;
+ int flag;
+ try {
+ DistributedLock.waitGetDistributedLock(key, requestId);
+ accountDto = new ShopVipAccountDto();
+ accountDto.setShopId(accountDetailPo.getShopId());
+ accountDto.setVipAcctId(accountDetailPo.getVipAcctId());
+ accounts = BeanConvertUtil.covertBeanList(shopVipAccountServiceDaoImpl.getShopVipAccountInfo(BeanConvertUtil.beanCovertMap(accountDto)), ShopVipAccountDto.class);
+ if (accounts == null || accounts.size() < 1) {
+ throw new IllegalArgumentException("璐︽埛涓嶅瓨鍦�");
+ }
+ //鍦ㄨ处鎴峰鍔�
+ double amount = Double.parseDouble(accounts.get(0).getAmount());
+ BigDecimal amountBig = new BigDecimal(amount);
+ amount = amountBig.add(new BigDecimal(accountDetailPo.getAmount())).doubleValue();
+ ShopVipAccountPo accountPo = new ShopVipAccountPo();
+ accountPo.setShopId(accountDetailPo.getShopId());
+ accountPo.setVipAcctId(accountDetailPo.getVipAcctId());
+ accountPo.setAmount(amount + "");
+ flag = shopVipAccountServiceDaoImpl.updateShopVipAccountInfo(BeanConvertUtil.beanCovertMap(accountPo));
+ if (flag < 1) {
+ throw new IllegalArgumentException("鏇存柊璐︽埛澶辫触");
+ }
+ } finally {
+ DistributedLock.releaseDistributedLock(requestId, key);
+ }
+ accountDetailPo.setDetailType(AccountDetailDto.DETAIL_TYPE_IN);
+ if(StringUtil.isEmpty(accountDetailPo.getDetailId())) {
+ accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
+ }
+ if(StringUtil.isEmpty(accountDetailPo.getOrderId())){
+ accountDetailPo.setOrderId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_orderId));
+ }
+ if(StringUtil.isEmpty(accountDetailPo.getRelAcctId())){
+ accountDetailPo.setRelAcctId("-1");
+ }
+
+ //淇濆瓨浜ゆ槗鏄庣粏
+ return shopVipAccountDetailServiceDaoImpl.saveShopVipAccountDetailInfo(BeanConvertUtil.beanCovertMap(accountDetailPo));
+ }
+
+ /**
+ * 鎵f鎺ュ彛
+ *
+ * @param accountDetailPo
+ * @return
+ */
+ @Override
+ @Java110Transactional
+ public int withholdAccount(@RequestBody ShopVipAccountDetailPo accountDetailPo) {
+
+ if (StringUtil.isEmpty(accountDetailPo.getVipAcctId())) {
+ throw new IllegalArgumentException("璐︽埛ID涓虹┖");
+ }
+ //寮�濮嬫灧閿�
+ String requestId = DistributedLock.getLockUUID();
+ String key = accountDetailPo.getVipAcctId();
+ ShopVipAccountDto accountDto = null;
+ List<ShopVipAccountDto> accounts = null;
+ int flag;
+ try {
+ DistributedLock.waitGetDistributedLock(key, requestId);
+ accountDto = new ShopVipAccountDto();
+ accountDto.setShopId(accountDetailPo.getShopId());
+ accountDto.setVipAcctId(accountDetailPo.getVipAcctId());
+ accounts = BeanConvertUtil.covertBeanList(shopVipAccountServiceDaoImpl.getShopVipAccountInfo(BeanConvertUtil.beanCovertMap(accountDto)), ShopVipAccountDto.class);
+ if (accounts == null || accounts.size() < 1) {
+ throw new IllegalArgumentException("璐︽埛涓嶅瓨鍦�");
+ }
+ //鍦ㄨ处鎴峰鍔�
+ double amount = Double.parseDouble(accounts.get(0).getAmount());
+ BigDecimal amountBig = new BigDecimal(amount);
+ amount = amountBig.subtract(new BigDecimal(accountDetailPo.getAmount())).doubleValue();
+ if(amount < 0){
+ throw new IllegalArgumentException("浣欓涓嶈冻");
+ }
+ ShopVipAccountPo accountPo = new ShopVipAccountPo();
+ accountPo.setShopId(accountDetailPo.getShopId());
+ accountPo.setVipAcctId(accountDetailPo.getVipAcctId());
+ accountPo.setAmount(amount + "");
+ flag = shopVipAccountServiceDaoImpl.updateShopVipAccountInfo(BeanConvertUtil.beanCovertMap(accountPo));
+ if (flag < 1) {
+ throw new IllegalArgumentException("鏇存柊璐︽埛澶辫触");
+ }
+ } finally {
+ DistributedLock.releaseDistributedLock(requestId, key);
+ }
+ accountDetailPo.setDetailType(AccountDetailDto.DETAIL_TYPE_OUT);
+ if(StringUtil.isEmpty(accountDetailPo.getDetailId())) {
+ accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
+ }
+ if(StringUtil.isEmpty(accountDetailPo.getOrderId())){
+ accountDetailPo.setOrderId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_orderId));
+ }
+ if(StringUtil.isEmpty(accountDetailPo.getRelAcctId())){
+ accountDetailPo.setRelAcctId("-1");
+ }
+ //淇濆瓨浜ゆ槗鏄庣粏
+ return shopVipAccountDetailServiceDaoImpl.saveShopVipAccountDetailInfo(BeanConvertUtil.beanCovertMap(accountDetailPo));
+ }
}
--
Gitblit v1.8.0