java110
2023-04-23 d6eacbd54ee7111972a04e13d50a7d1f77dfd105
service-acct/src/main/java/com/java110/acct/cmd/integral/ComputePayFeeIntegralCmd.java
@@ -1,20 +1,15 @@
package com.java110.acct.cmd.integral;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.acct.smo.impl.IntegralRuleConfigV1InnerServiceSMOImpl;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.smo.IComputeFeeSMO;
import com.java110.doc.annotation.*;
import com.java110.dto.couponRuleCpps.CouponRuleCppsDto;
import com.java110.dto.couponRuleFee.CouponRuleFeeDto;
import com.java110.dto.fee.FeeDto;
import com.java110.dto.integralRuleConfig.IntegralRuleConfigDto;
import com.java110.dto.integralRuleFee.IntegralRuleFeeDto;
import com.java110.intf.acct.ICouponRuleCppsV1InnerServiceSMO;
import com.java110.intf.acct.ICouponRuleFeeV1InnerServiceSMO;
import com.java110.dto.integral.IntegralRuleConfigDto;
import com.java110.dto.integral.IntegralRuleFeeDto;
import com.java110.intf.acct.IIntegralRuleConfigV1InnerServiceSMO;
import com.java110.intf.acct.IIntegralRuleFeeV1InnerServiceSMO;
import com.java110.intf.fee.IFeeInnerServiceSMO;
@@ -24,7 +19,6 @@
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
@@ -70,6 +64,9 @@
    @Autowired
    private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
    @Autowired
    private IComputeFeeSMO computeFeeSMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
@@ -98,7 +95,7 @@
        List<IntegralRuleFeeDto> integralRuleFeeDtos = integralRuleFeeV1InnerServiceSMOImpl.queryIntegralRuleFees(integralRuleFeeDto);
        if(integralRuleFeeDtos == null || integralRuleFeeDtos.size()<1){
            context.setResponseEntity(ResultVo.createResponseEntity(new JSONArray()));
            context.setResponseEntity(ResultVo.createResponseEntity(0));
            return ;
        }
@@ -112,7 +109,7 @@
        List<IntegralRuleConfigDto> integralRuleConfigDtos = integralRuleConfigV1InnerServiceSMOImpl.queryIntegralRuleConfigs(integralRuleConfigDto);
        if(integralRuleConfigDtos == null || integralRuleConfigDtos.size() < 1){
            context.setResponseEntity(ResultVo.createResponseEntity(new JSONArray()));
            context.setResponseEntity(ResultVo.createResponseEntity(0));
            return ;
        }
@@ -125,39 +122,10 @@
        long quantity = 0;
        for(IntegralRuleConfigDto integralRuleConfigDto:integralRuleConfigDtos){
            quantity += computeOneIntegralQuantity(integralRuleConfigDto,reqJson);
            quantity += computeFeeSMOImpl.computeOneIntegralQuantity(integralRuleConfigDto,reqJson);
        }
        return quantity;
    }
    /**
     * 计算计算积分
     * @param integralRuleConfigDto
     * @return
     */
    private long computeOneIntegralQuantity(IntegralRuleConfigDto integralRuleConfigDto,JSONObject reqJson) {
       String computingFormula = integralRuleConfigDto.getComputingFormula();
       BigDecimal amountDec = null;
       long amount = 0;
       if(IntegralRuleConfigDto.COMPUTING_FORMULA_AREA.equals(computingFormula)){ //面积乘以单价
           BigDecimal areaDec = new BigDecimal(Double.parseDouble(reqJson.getString("area")));
           BigDecimal squarePriceDec = new BigDecimal(Double.parseDouble(integralRuleConfigDto.getSquarePrice()));
           amountDec = areaDec.multiply(squarePriceDec).setScale(2,BigDecimal.ROUND_HALF_UP);
       }else if(IntegralRuleConfigDto.COMPUTING_FORMULA_MONEY.equals(computingFormula)){ // 金额乘以单价
           BigDecimal aDec = new BigDecimal(Double.parseDouble(reqJson.getString("amount")));
           BigDecimal squarePriceDec = new BigDecimal(Double.parseDouble(integralRuleConfigDto.getSquarePrice()));
           amountDec = aDec.multiply(squarePriceDec).setScale(2,BigDecimal.ROUND_HALF_UP);
       }else if(IntegralRuleConfigDto.COMPUTING_FORMULA_FIXED.equals(computingFormula)){ // 固定积分
           amountDec = new BigDecimal(Double.parseDouble(integralRuleConfigDto.getAdditionalAmount()));
       }else{
           amountDec = new BigDecimal(0);
       }
       if(IntegralRuleConfigDto.SCALE_UP.equals(integralRuleConfigDto.getScale())){
           amount = new Double(Math.ceil(amountDec.doubleValue())).longValue();
       }else{
           amount = new Double(Math.floor(amountDec.doubleValue())).longValue();
       }
       return amount;
    }
}