java110 лет назад: 5
Родитель
Сommit
2550d851ad

+ 4 - 3
java110-db/src/main/resources/mapper/acct/ShopVipAccountServiceDaoImplMapper.xml

@@ -70,9 +70,7 @@
         <if test="acctType !=null and acctType != ''">
             , t.acct_type= #{acctType}
         </if>
-        <if test="shopId !=null and shopId != ''">
-            , t.shop_id= #{shopId}
-        </if>
+
         <if test="acctName !=null and acctName != ''">
             , t.acct_name= #{acctName}
         </if>
@@ -83,6 +81,9 @@
         <if test="vipAcctId !=null and vipAcctId != ''">
             and t.vip_acct_id= #{vipAcctId}
         </if>
+        <if test="shopId !=null and shopId != ''">
+            and t.shop_id= #{shopId}
+        </if>
 
     </update>
 

+ 4 - 0
java110-interface/src/main/java/com/java110/intf/acct/IShopVipAccountDetailInnerServiceSMO.java

@@ -2,6 +2,7 @@ package com.java110.intf.acct;
 
 import com.java110.config.feign.FeignConfiguration;
 import com.java110.dto.shopVipAccountDetail.ShopVipAccountDetailDto;
+import com.java110.po.accountDetail.AccountDetailPo;
 import com.java110.po.shopVipAccountDetail.ShopVipAccountDetailPo;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -50,4 +51,7 @@ public interface IShopVipAccountDetailInnerServiceSMO {
      */
     @RequestMapping(value = "/queryShopVipAccountDetailsCount", method = RequestMethod.POST)
     int queryShopVipAccountDetailsCount(@RequestBody ShopVipAccountDetailDto shopVipAccountDetailDto);
+
+
+
 }

+ 17 - 0
java110-interface/src/main/java/com/java110/intf/acct/IShopVipAccountInnerServiceSMO.java

@@ -3,6 +3,7 @@ package com.java110.intf.acct;
 import com.java110.config.feign.FeignConfiguration;
 import com.java110.dto.shopVipAccount.ShopVipAccountDto;
 import com.java110.po.shopVipAccount.ShopVipAccountPo;
+import com.java110.po.shopVipAccountDetail.ShopVipAccountDetailPo;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -50,4 +51,20 @@ public interface IShopVipAccountInnerServiceSMO {
      */
     @RequestMapping(value = "/queryShopVipAccountsCount", method = RequestMethod.POST)
     int queryShopVipAccountsCount(@RequestBody ShopVipAccountDto shopVipAccountDto);
+
+    /**
+     * 预存金额
+     * @param accountDetailPo
+     * @return
+     */
+    @RequestMapping(value = "/prestoreAccount", method = RequestMethod.POST)
+    int prestoreAccount(@RequestBody ShopVipAccountDetailPo accountDetailPo);
+
+    /**
+     * 扣款金额
+     * @param accountDetailPo
+     * @return
+     */
+    @RequestMapping(value = "/withholdAccount", method = RequestMethod.POST)
+    int withholdAccount(@RequestBody ShopVipAccountDetailPo accountDetailPo);
 }

+ 1 - 1
service-acct/src/main/java/com/java110/acct/dao/IShopVipAccountDetailServiceDao.java

@@ -26,7 +26,7 @@ public interface IShopVipAccountDetailServiceDao {
      * @param info
      * @throws DAOException DAO异常
      */
-    void saveShopVipAccountDetailInfo(Map info) throws DAOException;
+    int saveShopVipAccountDetailInfo(Map info) throws DAOException;
 
 
 

+ 1 - 1
service-acct/src/main/java/com/java110/acct/dao/IShopVipAccountServiceDao.java

@@ -47,7 +47,7 @@ public interface IShopVipAccountServiceDao {
      * @param info 修改信息
      * @throws DAOException DAO异常
      */
-    void updateShopVipAccountInfo(Map info) throws DAOException;
+    int updateShopVipAccountInfo(Map info) throws DAOException;
 
 
     /**

+ 19 - 22
service-acct/src/main/java/com/java110/acct/dao/impl/ShopVipAccountDetailServiceDaoImpl.java

@@ -1,15 +1,13 @@
 package com.java110.acct.dao.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.java110.acct.dao.IShopVipAccountDetailServiceDao;
+import com.java110.core.base.dao.BaseServiceDao;
 import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.exception.DAOException;
-import com.java110.utils.util.DateUtil;
-import com.java110.core.base.dao.BaseServiceDao;
-import com.java110.acct.dao.IShopVipAccountDetailServiceDao;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
@@ -25,37 +23,34 @@ public class ShopVipAccountDetailServiceDaoImpl extends BaseServiceDao implement
     private static Logger logger = LoggerFactory.getLogger(ShopVipAccountDetailServiceDaoImpl.class);
 
 
-
-
-
     /**
      * 保存会员账户交易信息 到 instance
-     * @param info   bId 信息
+     *
+     * @param info bId 信息
      * @throws DAOException DAO异常
      */
     @Override
-    public void saveShopVipAccountDetailInfo(Map info) throws DAOException {
-        logger.debug("保存会员账户交易信息Instance 入参 info : {}",info);
+    public int saveShopVipAccountDetailInfo(Map info) throws DAOException {
+        logger.debug("保存会员账户交易信息Instance 入参 info : {}", info);
 
-        int saveFlag = sqlSessionTemplate.insert("shopVipAccountDetailServiceDaoImpl.saveShopVipAccountDetailInfo",info);
+        int saveFlag = sqlSessionTemplate.insert("shopVipAccountDetailServiceDaoImpl.saveShopVipAccountDetailInfo", info);
 
-        if(saveFlag < 1){
-            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"保存会员账户交易信息Instance数据失败:"+ JSONObject.toJSONString(info));
-        }
+        return saveFlag;
     }
 
 
     /**
      * 查询会员账户交易信息(instance)
+     *
      * @param info bId 信息
      * @return List<Map>
      * @throws DAOException DAO异常
      */
     @Override
     public List<Map> getShopVipAccountDetailInfo(Map info) throws DAOException {
-        logger.debug("查询会员账户交易信息 入参 info : {}",info);
+        logger.debug("查询会员账户交易信息 入参 info : {}", info);
 
-        List<Map> businessShopVipAccountDetailInfos = sqlSessionTemplate.selectList("shopVipAccountDetailServiceDaoImpl.getShopVipAccountDetailInfo",info);
+        List<Map> businessShopVipAccountDetailInfos = sqlSessionTemplate.selectList("shopVipAccountDetailServiceDaoImpl.getShopVipAccountDetailInfo", info);
 
         return businessShopVipAccountDetailInfos;
     }
@@ -63,28 +58,30 @@ public class ShopVipAccountDetailServiceDaoImpl extends BaseServiceDao implement
 
     /**
      * 修改会员账户交易信息
+     *
      * @param info 修改信息
      * @throws DAOException DAO异常
      */
     @Override
     public void updateShopVipAccountDetailInfo(Map info) throws DAOException {
-        logger.debug("修改会员账户交易信息Instance 入参 info : {}",info);
+        logger.debug("修改会员账户交易信息Instance 入参 info : {}", info);
 
-        int saveFlag = sqlSessionTemplate.update("shopVipAccountDetailServiceDaoImpl.updateShopVipAccountDetailInfo",info);
+        int saveFlag = sqlSessionTemplate.update("shopVipAccountDetailServiceDaoImpl.updateShopVipAccountDetailInfo", info);
 
-        if(saveFlag < 1){
-            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改会员账户交易信息Instance数据失败:"+ JSONObject.toJSONString(info));
+        if (saveFlag < 1) {
+            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR, "修改会员账户交易信息Instance数据失败:" + JSONObject.toJSONString(info));
         }
     }
 
-     /**
+    /**
      * 查询会员账户交易数量
+     *
      * @param info 会员账户交易信息
      * @return 会员账户交易数量
      */
     @Override
     public int queryShopVipAccountDetailsCount(Map info) {
-        logger.debug("查询会员账户交易数据 入参 info : {}",info);
+        logger.debug("查询会员账户交易数据 入参 info : {}", info);
 
         List<Map> businessShopVipAccountDetailInfos = sqlSessionTemplate.selectList("shopVipAccountDetailServiceDaoImpl.queryShopVipAccountDetailsCount", info);
         if (businessShopVipAccountDetailInfos.size() < 1) {

+ 19 - 22
service-acct/src/main/java/com/java110/acct/dao/impl/ShopVipAccountServiceDaoImpl.java

@@ -1,15 +1,13 @@
 package com.java110.acct.dao.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.java110.acct.dao.IShopVipAccountServiceDao;
+import com.java110.core.base.dao.BaseServiceDao;
 import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.exception.DAOException;
-import com.java110.utils.util.DateUtil;
-import com.java110.core.base.dao.BaseServiceDao;
-import com.java110.acct.dao.IShopVipAccountServiceDao;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
@@ -25,37 +23,36 @@ public class ShopVipAccountServiceDaoImpl extends BaseServiceDao implements ISho
     private static Logger logger = LoggerFactory.getLogger(ShopVipAccountServiceDaoImpl.class);
 
 
-
-
-
     /**
      * 保存会员账户信息 到 instance
-     * @param info   bId 信息
+     *
+     * @param info bId 信息
      * @throws DAOException DAO异常
      */
     @Override
     public void saveShopVipAccountInfo(Map info) throws DAOException {
-        logger.debug("保存会员账户信息Instance 入参 info : {}",info);
+        logger.debug("保存会员账户信息Instance 入参 info : {}", info);
 
-        int saveFlag = sqlSessionTemplate.insert("shopVipAccountServiceDaoImpl.saveShopVipAccountInfo",info);
+        int saveFlag = sqlSessionTemplate.insert("shopVipAccountServiceDaoImpl.saveShopVipAccountInfo", info);
 
-        if(saveFlag < 1){
-            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"保存会员账户信息Instance数据失败:"+ JSONObject.toJSONString(info));
+        if (saveFlag < 1) {
+            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR, "保存会员账户信息Instance数据失败:" + JSONObject.toJSONString(info));
         }
     }
 
 
     /**
      * 查询会员账户信息(instance)
+     *
      * @param info bId 信息
      * @return List<Map>
      * @throws DAOException DAO异常
      */
     @Override
     public List<Map> getShopVipAccountInfo(Map info) throws DAOException {
-        logger.debug("查询会员账户信息 入参 info : {}",info);
+        logger.debug("查询会员账户信息 入参 info : {}", info);
 
-        List<Map> businessShopVipAccountInfos = sqlSessionTemplate.selectList("shopVipAccountServiceDaoImpl.getShopVipAccountInfo",info);
+        List<Map> businessShopVipAccountInfos = sqlSessionTemplate.selectList("shopVipAccountServiceDaoImpl.getShopVipAccountInfo", info);
 
         return businessShopVipAccountInfos;
     }
@@ -63,28 +60,28 @@ public class ShopVipAccountServiceDaoImpl extends BaseServiceDao implements ISho
 
     /**
      * 修改会员账户信息
+     *
      * @param info 修改信息
      * @throws DAOException DAO异常
      */
     @Override
-    public void updateShopVipAccountInfo(Map info) throws DAOException {
-        logger.debug("修改会员账户信息Instance 入参 info : {}",info);
+    public int updateShopVipAccountInfo(Map info) throws DAOException {
+        logger.debug("修改会员账户信息Instance 入参 info : {}", info);
 
-        int saveFlag = sqlSessionTemplate.update("shopVipAccountServiceDaoImpl.updateShopVipAccountInfo",info);
+        int saveFlag = sqlSessionTemplate.update("shopVipAccountServiceDaoImpl.updateShopVipAccountInfo", info);
 
-        if(saveFlag < 1){
-            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改会员账户信息Instance数据失败:"+ JSONObject.toJSONString(info));
-        }
+        return saveFlag;
     }
 
-     /**
+    /**
      * 查询会员账户数量
+     *
      * @param info 会员账户信息
      * @return 会员账户数量
      */
     @Override
     public int queryShopVipAccountsCount(Map info) {
-        logger.debug("查询会员账户数据 入参 info : {}",info);
+        logger.debug("查询会员账户数据 入参 info : {}", info);
 
         List<Map> businessShopVipAccountInfos = sqlSessionTemplate.selectList("shopVipAccountServiceDaoImpl.queryShopVipAccountsCount", info);
         if (businessShopVipAccountInfos.size() < 1) {

+ 131 - 0
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 @@ import java.util.List;
 @RestController
 public class ShopVipAccountInnerServiceSMOImpl extends BaseServiceSMO implements IShopVipAccountInnerServiceSMO {
 
+    @Autowired
+    private IShopVipAccountDetailServiceDao shopVipAccountDetailServiceDaoImpl;
     @Autowired
     private IShopVipAccountServiceDao shopVipAccountServiceDaoImpl;
 
@@ -80,4 +93,122 @@ public class ShopVipAccountInnerServiceSMOImpl extends BaseServiceSMO implements
     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));
+    }
+
+    /**
+     * 扣款接口
+     *
+     * @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));
+    }
 }