java110
2021-12-30 818f57f0a4a1000f0b5af3e1d26079abcf25f131
优化优惠券抵扣
3个文件已修改
86 ■■■■■ 已修改文件
java110-utils/src/main/java/com/java110/utils/util/BeanConvertUtil.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeConfirmCmd.java 63 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-utils/src/main/java/com/java110/utils/util/BeanConvertUtil.java
@@ -1,6 +1,7 @@
package com.java110.utils.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
@@ -183,6 +184,17 @@
        return JSONObject.parseObject(JSONObject.toJSONString(orgBean));
    }
    /**
     * bean转换为map对象
     *
     * @param orgBean 原始bean
     * @return map对象
     */
    public static JSONArray beanCovertJSONArray(Object orgBean) {
        return JSONArray.parseArray(JSONArray.toJSONString(orgBean));
    }
    /**
     * bean集合转换为map对象集合
service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeConfirmCmd.java
@@ -3,7 +3,6 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.DataFlowContext;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.AbstractServiceCmdListener;
import com.java110.core.event.cmd.CmdEvent;
@@ -16,10 +15,8 @@
import com.java110.dto.fee.FeeDto;
import com.java110.dto.feeDiscount.ComputeDiscountDto;
import com.java110.dto.owner.OwnerCarDto;
import com.java110.dto.payFeeDetailDiscount.PayFeeDetailDiscountDto;
import com.java110.dto.repair.RepairDto;
import com.java110.dto.repair.RepairUserDto;
import com.java110.entity.order.Orders;
import com.java110.fee.bmo.fee.IFeeBMO;
import com.java110.intf.acct.IAccountInnerServiceSMO;
import com.java110.intf.acct.ICouponUserDetailV1InnerServiceSMO;
@@ -37,8 +34,6 @@
import com.java110.po.owner.RepairUserPo;
import com.java110.po.payFeeDetailDiscount.PayFeeDetailDiscountPo;
import com.java110.utils.cache.CommonCache;
import com.java110.utils.constant.BusinessTypeConstant;
import com.java110.utils.constant.CommonConstant;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
@@ -46,8 +41,6 @@
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.math.BigDecimal;
import java.text.DecimalFormat;
@@ -237,53 +230,59 @@
    private void dealAccount(JSONObject paramObj) {
        if(!paramObj.containsKey("deductionAmount") || paramObj.getDouble("deductionAmount") <=0){
            return ;
        if (!paramObj.containsKey("deductionAmount") || paramObj.getDouble("deductionAmount") <= 0) {
            return;
        }
        BigDecimal deductionAmount = new BigDecimal(paramObj.getDouble("deductionAmount"));
        List<AccountDto> accountDtos = (List<AccountDto>) paramObj.get("selectUserAccount");
        JSONArray accountDtos = paramObj.getJSONArray("selectUserAccount");
        BigDecimal amount = null;
        for(AccountDto accountDto : accountDtos){
        AccountDto accountDto = null;
        for (int accountIndex = 0; accountIndex < accountDtos.size(); accountIndex++) {
            accountDto = BeanConvertUtil.covertBean(accountDtos.getJSONObject(accountIndex), AccountDto.class);
            amount = new BigDecimal(Double.parseDouble(accountDto.getAmount()));
            AccountDetailPo accountDetailPo = new AccountDetailPo();
            accountDetailPo.setAcctId(accountDto.getAcctId());
            accountDetailPo.setObjId(accountDto.getObjId());
            if(amount.doubleValue()< deductionAmount.doubleValue()){
                accountDetailPo.setAmount(amount.doubleValue()+"");
                deductionAmount = deductionAmount.subtract(amount).setScale(2,BigDecimal.ROUND_HALF_UP);
            }else{
                accountDetailPo.setAmount(deductionAmount.doubleValue()+"");
                deductionAmount = deductionAmount.subtract(deductionAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
            if (amount.doubleValue() < deductionAmount.doubleValue()) {
                accountDetailPo.setAmount(amount.doubleValue() + "");
                deductionAmount = deductionAmount.subtract(amount).setScale(2, BigDecimal.ROUND_HALF_UP);
            } else {
                accountDetailPo.setAmount(deductionAmount.doubleValue() + "");
                deductionAmount = deductionAmount.subtract(deductionAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
            }
            int flag = accountInnerServiceSMOImpl.withholdAccount(accountDetailPo);
            if(flag < 1){
                throw  new CmdException("扣款失败");
            if (flag < 1) {
                throw new CmdException("扣款失败");
            }
        }
        if(deductionAmount.doubleValue()>0){
        if (deductionAmount.doubleValue() > 0) {
            throw new CmdException("账户金额不足");
        }
        paramObj.put("remark", paramObj.getString("remark") + "-现金账户抵扣" + paramObj.getDouble("deductionAmount") + "元");
    }
    private void modifyCouponUser(JSONObject paramObj) {
        if(!paramObj.containsKey("couponPrice") || paramObj.getDouble("couponPrice")<=0){
            return ;
        if (!paramObj.containsKey("couponPrice") || paramObj.getDouble("couponPrice") <= 0) {
            return;
        }
        FeeDto feeInfo = (FeeDto) paramObj.get("feeInfo");
        List<CouponUserDto> couponUserDtos = (List<CouponUserDto>) paramObj.get("couponUserDtos");
        CouponUserDto couponUserDto = null;
        for (CouponUserDto couponUser : couponUserDtos) {
        JSONArray couponUserDtos = paramObj.getJSONArray("couponUserDtos");
        CouponUserDto couponUser = null;
        for (int accountIndex = 0; accountIndex < couponUserDtos.size(); accountIndex++) {
            couponUser = BeanConvertUtil.covertBean(couponUserDtos.getJSONObject(accountIndex), CouponUserDto.class);
            couponUserDto = new CouponUserDto();
            couponUserDto.setCouponId(couponUser.getCouponId());
            couponUserDto.setState(CouponUserDto.COUPON_STATE_RUN);
            List<CouponUserDto> couponUserDtos1 = couponUserV1InnerServiceSMOImpl.queryCouponUsers(couponUserDto);
            if(couponUserDtos1==null || couponUserDtos1.size()<1){
            if (couponUserDtos1 == null || couponUserDtos1.size() < 1) {
                throw new CmdException("优惠券被使用");
            }
            CouponUserPo couponUserPo = new CouponUserPo();
@@ -308,15 +307,19 @@
            }
        }
        paramObj.put("remark", paramObj.getString("remark") + "-优惠劵抵扣" + paramObj.getDouble("couponPrice") + "元");
    }
    private void addDiscount(JSONObject paramObj) {
        if (!paramObj.containsKey("discountPrice") || paramObj.getDouble("discountPrice") <=0) {
            return ;
        if (!paramObj.containsKey("discountPrice") || paramObj.getDouble("discountPrice") <= 0) {
            return;
        }
        List<ComputeDiscountDto> computeDiscountDtos = (List<ComputeDiscountDto>) paramObj.get("computeDiscountDtos");
        for (ComputeDiscountDto computeDiscountDto : computeDiscountDtos) {
        JSONArray computeDiscountDtos = paramObj.getJSONArray("computeDiscountDtos");
        ComputeDiscountDto computeDiscountDto = null;
        for (int accountIndex = 0; accountIndex < computeDiscountDtos.size(); accountIndex++) {
            computeDiscountDto = BeanConvertUtil.covertBean(computeDiscountDtos.getJSONObject(accountIndex), ComputeDiscountDto.class);
            if (computeDiscountDto.getDiscountPrice() <= 0) {
                continue;
            }
service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeePreCmd.java
@@ -24,6 +24,7 @@
import com.java110.utils.exception.CmdException;
import com.java110.utils.exception.ListenerExecuteException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -203,11 +204,11 @@
        deductionAmount = totalAccountAmount.subtract(new BigDecimal(deductionAmount)).doubleValue();
        if(deductionAmount < 0){
            reqJson.put("deductionAmount",totalAccountAmount.doubleValue());
            reqJson.put("selectUserAccount",accountDtos);
            reqJson.put("selectUserAccount",BeanConvertUtil.beanCovertJSONArray(accountDtos));
            return totalAccountAmount.doubleValue();
        }
        reqJson.put("deductionAmount",deductionAmount);
        reqJson.put("selectUserAccount",accountDtos);
        reqJson.put("selectUserAccount",BeanConvertUtil.beanCovertJSONArray(accountDtos));
        return deductionAmount;
    }
@@ -218,7 +219,7 @@
        if (couponList == null || couponList.size() < 1) {
            paramObj.put("couponPrice", couponPrice.doubleValue());
            paramObj.put("couponUserDtos", new ArrayList<CouponUserDto>()); //这里考虑空
            paramObj.put("couponUserDtos", new JSONArray()); //这里考虑空
            return couponPrice.doubleValue();
        }
        for (int couponIndex = 0; couponIndex < couponList.size(); couponIndex++) {
@@ -238,7 +239,7 @@
            }
        }
        paramObj.put("couponPrice", couponPrice.doubleValue());
        paramObj.put("couponUserDtos", couponUserDtos);
        paramObj.put("couponUserDtos", BeanConvertUtil.beanCovertJSONArray(couponUserDtos) );
        return couponPrice.doubleValue();
    }
@@ -271,7 +272,7 @@
            discountPrice = discountPrice.add(new BigDecimal(computeDiscountDto.getDiscountPrice()));
        }
        paramObj.put("discountPrice",discountPrice.doubleValue());
        paramObj.put("computeDiscountDtos", computeDiscountDtos);
        paramObj.put("computeDiscountDtos", BeanConvertUtil.beanCovertJSONArray(computeDiscountDtos));
        return discountPrice.doubleValue();
    }
}