wuxw
2024-12-05 919e2989808dd97ba32b4478dbe95851c70fbce5
service-fee/src/main/java/com/java110/fee/cmd/returnPayFee/UpdateReturnPayFeeCmd.java
@@ -22,15 +22,11 @@
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.factory.CommunitySettingFactory;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.dto.fee.*;
import com.java110.dto.room.RoomDto;
import com.java110.dto.account.AccountDto;
import com.java110.dto.fee.FeeDetailDto;
import com.java110.dto.fee.FeeDto;
import com.java110.dto.fee.FeeDiscountDto;
import com.java110.dto.fee.FeeDiscountRuleDto;
import com.java110.dto.fee.FeeDiscountSpecDto;
import com.java110.dto.fee.FeeReceiptDetailDto;
import com.java110.dto.wechat.OnlinePayDto;
import com.java110.dto.owner.OwnerCarDto;
import com.java110.dto.owner.OwnerDto;
@@ -41,6 +37,7 @@
import com.java110.dto.user.UserDto;
import com.java110.intf.acct.IAccountDetailInnerServiceSMO;
import com.java110.intf.acct.IAccountInnerServiceSMO;
import com.java110.intf.acct.IOnlinePayRefundV1InnerServiceSMO;
import com.java110.intf.acct.IOnlinePayV1InnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.intf.fee.*;
@@ -54,17 +51,16 @@
import com.java110.po.fee.PayFeePo;
import com.java110.po.fee.FeeReceiptPo;
import com.java110.po.fee.FeeReceiptDetailPo;
import com.java110.po.onlinePayRefund.OnlinePayRefundPo;
import com.java110.po.wechat.OnlinePayPo;
import com.java110.po.payFee.PayFeeDetailDiscountPo;
import com.java110.po.payFee.ReturnPayFeePo;
import com.java110.utils.exception.CmdException;
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.utils.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.listener.ListenerUtils;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
@@ -153,6 +149,12 @@
    @Autowired
    private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
    @Autowired
    private IOnlinePayRefundV1InnerServiceSMO onlinePayRefundV1InnerServiceSMOImpl;
    @Autowired
    private IPayFeeConfigV1InnerServiceSMO payFeeConfigV1InnerServiceSMOImpl;
    private static final String SPEC_RATE = "89002020980015"; //赠送月份
@@ -160,15 +162,18 @@
    public static final String CODE_PREFIX_ID = "10";
    //键(积分账户抵扣比例)
    public static final String DEDUCTION_PROPORTION = "DEDUCTION_PROPORTION";
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "returnFeeId", "returnFeeId不能为空");
        Assert.hasKeyAndValue(reqJson, "state", "state不能为空");
        Assert.hasKeyAndValue(reqJson, "feeId", "feeId不能为空");
        if (reqJson.containsKey("cycles")) {
            String cycles = reqJson.getString("cycles");
            if (!cycles.startsWith("-")) {
                throw new IllegalArgumentException("退费周期必须负数");// 这里必须传入负数,否则费用自动相加不会退费
            double cycles = reqJson.getDouble("cycles");
            if (cycles > 0) {
                throw new CmdException("退费周期必须负数");// 这里必须传入负数,否则费用自动相加不会退费
            }
        }
        FeeDetailDto feeDetailDto = new FeeDetailDto();
@@ -196,6 +201,19 @@
        returnPayFeeDto.setReturnFeeId(reqJson.getString("returnFeeId"));
        List<ReturnPayFeeDto> returnPayFeeDtos = returnPayFeeInnerServiceSMOImpl.queryReturnPayFees(returnPayFeeDto);
        Assert.listOnlyOne(returnPayFeeDtos, "未找到需要修改的活动 或多条数据");
        FeeDto feeDto = new FeeDto();
        feeDto.setFeeId((String) reqJson.get("feeId"));
        List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
        Assert.listOnlyOne(feeDtos, "费用不存在");
        FeeDto feeDto1 = feeDtos.get(0);
        FeeConfigDto feeConfigDto = new FeeConfigDto();
        feeConfigDto.setConfigId(feeDto1.getConfigId());
        feeConfigDto.setCommunityId(feeDto1.getCommunityId());
        List<FeeConfigDto> feeConfigDtos = payFeeConfigV1InnerServiceSMOImpl.queryPayFeeConfigs(feeConfigDto);
        Assert.listOnlyOne(feeConfigDtos, "费用项不存在");
        // todo 修改退款状态
        updateReturnPayFee(reqJson, userDtos.get(0), returnPayFeeDtos.get(0));
@@ -220,11 +238,7 @@
            // todo 修改 缴费记录
            updateFeeDetail(reqJson);
            //修改pay_fee 费用到期时间  以及如果是押金则修改状态为结束收费
            FeeDto feeDto = new FeeDto();
            feeDto.setFeeId((String) reqJson.get("feeId"));
            List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
            Assert.listOnlyOne(feeDtos, "费用不存在");
            FeeDto feeDto1 = feeDtos.get(0);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            reqJson.put("endTime", DateUtil.getFormatTimeString(feeDetailDto.getStartTime(), DateUtil.DATE_FORMATE_STRING_A));
            reqJson.put("amount", feeDto1.getAmount());
@@ -240,8 +254,9 @@
            reqJson.put("configId", feeDto1.getConfigId());
            reqJson.put("payerObjType", feeDto1.getPayerObjType());
            reqJson.put("feeId", feeDto1.getFeeId());
            if ("888800010006".equals(feeDto1.getFeeTypeCds())) {
                reqJson.put("state", "2009001");
            //1003006 周期性费用  2006012 一次性费用  4012024 间接性费用
            if (FeeDto.FEE_FLAG_ONCE.equals(feeConfigDtos.get(0).getFeeFlag())) { //888800010006 押金
                reqJson.put("state", "2009001"); //2007001 收费未开始  2008001 有效  2009001 收费结束
            } else {
                reqJson.put("state", "2008001");
            }
@@ -305,41 +320,77 @@
        }
        for (int index = 0; index < feeAccountDetails.size(); index++) {
            JSONObject param = feeAccountDetails.getJSONObject(index);
            String state = param.getString("state");
            if (!"1002".equals(param.getString("state"))) { //1001 无抵扣 1002 现金账户抵扣 1003 积分账户抵扣 1004 优惠券抵扣
                continue;
            }
            AccountDto accountDto = new AccountDto();
            accountDto.setObjId(ownerId);
            accountDto.setAcctType(AccountDto.ACCT_TYPE_CASH); //2003  现金账户
            List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
            Assert.listOnlyOne(accountDtos, "查询业主现金账户错误!");
            BigDecimal amount = new BigDecimal(accountDtos.get(0).getAmount());
            BigDecimal money = new BigDecimal(param.getString("amount"));
            BigDecimal newAmount = amount.add(money);
            AccountPo accountPo = new AccountPo();
            accountPo.setAcctId(accountDtos.get(0).getAcctId());
            accountPo.setAmount(String.valueOf(newAmount));
            int flag = accountInnerServiceSMOImpl.updateAccount(accountPo);
            if (flag < 1) {
                throw new IllegalArgumentException("更新业主现金账户失败!");
            String returnAmount = param.getString("amount");
            //1001 无抵扣 1002 现金账户抵扣 1003 积分账户抵扣 1004 优惠券抵扣
            if ("1002".equals(param.getString("state"))) {
                accountDto.setAcctType(AccountDto.ACCT_TYPE_CASH); //2003  现金账户
                List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
                Assert.listOnlyOne(accountDtos, "查询业主现金账户错误!");
                BigDecimal amount = new BigDecimal(accountDtos.get(0).getAmount());
                BigDecimal money = new BigDecimal(returnAmount);
                BigDecimal newAmount = amount.add(money);
                AccountPo accountPo = new AccountPo();
                accountPo.setAcctId(accountDtos.get(0).getAcctId());
                accountPo.setAmount(String.valueOf(newAmount));
                int flag = accountInnerServiceSMOImpl.updateAccount(accountPo);
                if (flag < 1) {
                    throw new IllegalArgumentException("更新业主现金账户失败!");
                }
                AccountDetailPo accountDetailPo = new AccountDetailPo();
                accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
                accountDetailPo.setAcctId(accountDtos.get(0).getAcctId());
                accountDetailPo.setDetailType("1001"); //1001 转入 2002 转出
                accountDetailPo.setRelAcctId("-1");
                accountDetailPo.setAmount(returnAmount);
                accountDetailPo.setObjType("6006"); //6006 个人 7007 商户
                accountDetailPo.setObjId(ownerId);
                accountDetailPo.setOrderId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_orderId));
                accountDetailPo.setbId("-1");
                accountDetailPo.setRemark("现金账户退费");
                accountDetailPo.setCreateTime(new Date());
                int i = accountDetailInnerServiceSMOImpl.saveAccountDetails(accountDetailPo);
                if (i < 1) {
                    throw new IllegalArgumentException("保存业主现金账户明细失败!");
                }
            }
            AccountDetailPo accountDetailPo = new AccountDetailPo();
            accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
            accountDetailPo.setAcctId(accountDtos.get(0).getAcctId());
            accountDetailPo.setDetailType("1001"); //1001 转入 2002 转出
            accountDetailPo.setRelAcctId("-1");
            accountDetailPo.setAmount(param.getString("amount"));
            accountDetailPo.setObjType("6006"); //6006 个人 7007 商户
            accountDetailPo.setObjId(ownerId);
            accountDetailPo.setOrderId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_orderId));
            accountDetailPo.setbId("-1");
            accountDetailPo.setRemark("现金账户退费");
            accountDetailPo.setCreateTime(new Date());
            int i = accountDetailInnerServiceSMOImpl.saveAccountDetails(accountDetailPo);
            if (i < 1) {
                throw new IllegalArgumentException("保存业主现金账户明细失败!");
            if ("1003".equals(param.getString("state"))) {
                //积分账户抵扣比例
//                BigDecimal deductionProportion = new BigDecimal(CommunitySettingFactory.getValue(reqJson.getString("communityId"), DEDUCTION_PROPORTION));
//                BigDecimal returnAmount1 = new BigDecimal(returnAmount);
//                BigDecimal money = returnAmount1.multiply(deductionProportion);
//                accountDto.setAcctType(AccountDto.ACCT_TYPE_INTEGRAL); //2004  积分账户
//                List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
//                Assert.listOnlyOne(accountDtos, "查询业主积分账户错误!");
//                BigDecimal amount = new BigDecimal(accountDtos.get(0).getAmount());
//                BigDecimal newAmount = amount.add(money);
//                AccountPo accountPo = new AccountPo();
//                accountPo.setAcctId(accountDtos.get(0).getAcctId());
//                accountPo.setAmount(String.valueOf(newAmount));
//                int flag = accountInnerServiceSMOImpl.updateAccount(accountPo);
//                if (flag < 1) {
//                    throw new IllegalArgumentException("更新业主积分账户失败!");
//                }
//                AccountDetailPo accountDetailPo = new AccountDetailPo();
//                accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
//                accountDetailPo.setAcctId(accountDtos.get(0).getAcctId());
//                accountDetailPo.setDetailType("1001"); //1001 转入 2002 转出
//                accountDetailPo.setRelAcctId("-1");
//                accountDetailPo.setAmount(money.toString());
//                accountDetailPo.setObjType("6006"); //6006 个人 7007 商户
//                accountDetailPo.setObjId(ownerId);
//                accountDetailPo.setOrderId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_orderId));
//                accountDetailPo.setbId("-1");
//                accountDetailPo.setRemark("积分账户退费");
//                accountDetailPo.setCreateTime(new Date());
//                int i = accountDetailInnerServiceSMOImpl.saveAccountDetails(accountDetailPo);
//                if (i < 1) {
//                    throw new IllegalArgumentException("保存业主积分账户明细失败!");
//                }
            }
        }
    }
@@ -354,11 +405,17 @@
            FeeDiscountDto feeDiscountDto = new FeeDiscountDto();
            feeDiscountDto.setDiscountId(payFeeConfigDiscount.getDiscountId());
            List<FeeDiscountDto> feeDiscountDtos = feeDiscountInnerServiceSMOImpl.queryFeeDiscounts(feeDiscountDto);
            Assert.listOnlyOne(feeDiscountDtos, "查询打折优惠表错误");
            //Assert.listOnlyOne(feeDiscountDtos, "查询打折优惠表错误");
            if (feeDiscountDtos == null || feeDiscountDtos.size() < 1) {
                continue;
            }
            FeeDiscountRuleDto feeDiscountRuleDto = new FeeDiscountRuleDto();
            feeDiscountRuleDto.setRuleId(feeDiscountDtos.get(0).getRuleId());
            List<FeeDiscountRuleDto> feeDiscountRuleDtos = feeDiscountRuleInnerServiceSMOImpl.queryFeeDiscountRules(feeDiscountRuleDto);
            Assert.listOnlyOne(feeDiscountRuleDtos, "查询规则表错误");
            //Assert.listOnlyOne(feeDiscountRuleDtos, "查询规则表错误");
            if (feeDiscountRuleDtos == null || feeDiscountRuleDtos.size() < 1) {
                continue;
            }
            //获取实现方式
            String beanImpl = feeDiscountRuleDtos.get(0).getBeanImpl();
            if (!"reductionMonthFeeRule".equals(beanImpl)) { //赠送规则
@@ -373,7 +430,10 @@
            feeDiscountSpecDto.setSpecId(SPEC_RATE); //赠送规则
            //查询打折规格
            List<FeeDiscountSpecDto> feeDiscountSpecDtos = feeDiscountSpecInnerServiceSMOImpl.queryFeeDiscountSpecs(feeDiscountSpecDto);
            Assert.listOnlyOne(feeDiscountSpecDtos, "查询打折规格表错误!");
            // Assert.listOnlyOne(feeDiscountSpecDtos, "查询打折规格表错误!");
            if (feeDiscountSpecDtos == null || feeDiscountSpecDtos.size() < 1) {
                continue;
            }
            //获取赠送月份
            String specValue = feeDiscountSpecDtos.get(0).getSpecValue();
            BigDecimal value = new BigDecimal(specValue);
@@ -440,6 +500,7 @@
        businessReturnPayFee.putAll(BeanConvertUtil.beanCovertMap(feeDetailDtos.get(0)));
        businessReturnPayFee.putAll(paramInJson);
        PayFeeDetailPo returnPayFeePo = BeanConvertUtil.covertBean(businessReturnPayFee, PayFeeDetailPo.class);
        returnPayFeePo.setPrimeRate(feeDetailDtos.get(0).getPrimeRate());
        int flag = payFeeDetailV1InnerServiceSMOImpl.updatePayFeeDetailNew(returnPayFeePo);
        if (flag < 1) {
            throw new CmdException("更新数据失败");
@@ -592,7 +653,7 @@
        OnlinePayDto onlinePayDto = new OnlinePayDto();
        onlinePayDto.setOrderId(feeDetailDto.getPayOrderId());
        List<OnlinePayDto> onlinePayDtos = onlinePayV1InnerServiceSMOImpl.queryOnlinePays(onlinePayDto);
        if (onlinePayDtos == null || onlinePayDtos.size() < 1) {
        if (ListUtil.isNull(onlinePayDtos)) {
            return;
        }
        OnlinePayPo onlinePayPo = new OnlinePayPo();
@@ -601,5 +662,17 @@
        onlinePayPo.setState(OnlinePayDto.STATE_WT);
        onlinePayPo.setRefundFee(feeDetailDto.getReceivedAmount());
        onlinePayV1InnerServiceSMOImpl.updateOnlinePay(onlinePayPo);
        //todo 保存 退费明细
        OnlinePayRefundPo onlinePayRefundPo = new OnlinePayRefundPo();
        onlinePayRefundPo.setPayId(onlinePayDtos.get(0).getPayId());
        onlinePayRefundPo.setRefundId(GenerateCodeFactory.getGeneratorId("11"));
        onlinePayRefundPo.setState(OnlinePayDto.STATE_WT);
        onlinePayRefundPo.setMessage("待退费");
        onlinePayRefundPo.setBusiId(feeDetailDto.getDetailId());
        onlinePayRefundPo.setRefundFee(feeDetailDto.getReceivedAmount());
        onlinePayRefundPo.setCommunityId(feeDetailDto.getCommunityId());
        onlinePayRefundV1InnerServiceSMOImpl.saveOnlinePayRefund(onlinePayRefundPo);
    }
}