chengf
2025-09-22 e8ded5b9dbc884741d7de7a7f4d36b517db3c8db
service-fee/src/main/java/com/java110/fee/cmd/returnPayFee/UpdateReturnPayFeeCmd.java
@@ -22,24 +22,23 @@
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.RoomDto;
import com.java110.dto.fee.*;
import com.java110.dto.payFee.PayFeeAuditDto;
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.feeDiscount.FeeDiscountDto;
import com.java110.dto.feeDiscount.FeeDiscountRuleDto;
import com.java110.dto.feeDiscount.FeeDiscountSpecDto;
import com.java110.dto.onlinePay.OnlinePayDto;
import com.java110.dto.wechat.OnlinePayDto;
import com.java110.dto.owner.OwnerCarDto;
import com.java110.dto.owner.OwnerDto;
import com.java110.dto.owner.OwnerRoomRelDto;
import com.java110.dto.payFeeConfigDiscount.PayFeeConfigDiscountDto;
import com.java110.dto.payFeeDetailDiscount.PayFeeDetailDiscountDto;
import com.java110.dto.returnPayFee.ReturnPayFeeDto;
import com.java110.dto.payFee.PayFeeConfigDiscountDto;
import com.java110.dto.payFee.PayFeeDetailDiscountDto;
import com.java110.dto.payFee.ReturnPayFeeDto;
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.*;
@@ -48,22 +47,22 @@
import com.java110.intf.user.IOwnerRoomRelInnerServiceSMO;
import com.java110.intf.user.IUserV1InnerServiceSMO;
import com.java110.po.account.AccountPo;
import com.java110.po.accountDetail.AccountDetailPo;
import com.java110.po.account.AccountDetailPo;
import com.java110.po.fee.PayFeeDetailPo;
import com.java110.po.fee.PayFeePo;
import com.java110.po.feeReceipt.FeeReceiptPo;
import com.java110.po.feeReceiptDetail.FeeReceiptDetailPo;
import com.java110.po.onlinePay.OnlinePayPo;
import com.java110.po.payFeeDetailDiscount.PayFeeDetailDiscountPo;
import com.java110.po.returnPayFee.ReturnPayFeePo;
import com.java110.po.fee.FeeReceiptPo;
import com.java110.po.fee.FeeReceiptDetailPo;
import com.java110.po.onlinePayRefund.OnlinePayRefundPo;
import com.java110.po.payFee.PayFeeAuditPo;
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;
@@ -152,11 +151,24 @@
    @Autowired
    private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
    @Autowired
    private IOnlinePayRefundV1InnerServiceSMO onlinePayRefundV1InnerServiceSMOImpl;
    @Autowired
    private IPayFeeConfigV1InnerServiceSMO payFeeConfigV1InnerServiceSMOImpl;
    @Autowired
    private IPayFeeAuditInnerServiceSMO payFeeAuditInnerServiceSMOImpl;
    private static final String SPEC_RATE = "89002020980015"; //赠送月份
    private static final String SPEC_MONTH = "89002020980014"; //月份
    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) {
@@ -164,9 +176,9 @@
        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();
@@ -194,6 +206,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));
@@ -207,7 +232,7 @@
            reqJson.put("endTime", DateUtil.getFormatTimeString(feeDetailDto.getEndTime(), DateUtil.DATE_FORMATE_STRING_A));
            reqJson.put("payOrderId", feeDetailDto.getPayOrderId());
            // todo  添加退费明细
            addFeeDetail(reqJson,returnPayFeeDtos.get(0));
            addFeeDetail(reqJson, returnPayFeeDtos.get(0));
            reqJson.put("state", "1100");
            String receivableAmount = (String) reqJson.get("receivableAmount");
            String receivedAmount = (String) reqJson.get("receivedAmount");
@@ -218,11 +243,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());
@@ -238,8 +259,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");
            }
@@ -252,7 +274,7 @@
            payFeeDetailDiscountDto.setCommunityId(feeDto1.getCommunityId());
            payFeeDetailDiscountDto.setDetailId(reqJson.getString("detailId"));
            List<PayFeeDetailDiscountDto> payFeeDetailDiscountDtos = payFeeDetailDiscountInnerServiceSMOImpl.queryPayFeeDetailDiscounts(payFeeDetailDiscountDto);
            if (payFeeDetailDiscountDtos != null && payFeeDetailDiscountDtos.size() > 0) {
            if (!ListUtil.isNull(payFeeDetailDiscountDtos)) {
                JSONObject discountJson = new JSONObject();
                discountJson.put("discountId", payFeeDetailDiscountDtos.get(0).getDiscountId());
                discountJson.put("discountPrice", unum(payFeeDetailDiscountDtos.get(0).getDiscountPrice()));
@@ -282,11 +304,22 @@
    }
    private void returnAccount(JSONObject reqJson) {
        String feeAccountDetailDtoList = reqJson.getString("feeAccountDetailDtoList");
        JSONArray feeAccountDetails = JSONArray.parseArray(feeAccountDetailDtoList);
        if (feeAccountDetails == null || feeAccountDetails.size() < 1) {
        FeeDetailDto feeDetailDto = new FeeDetailDto();
        feeDetailDto.setDetailId(reqJson.getString("detailId"));
        List<FeeDetailDto> feeDetailDtos = feeDetailInnerServiceSMOImpl.queryFeeDetails(feeDetailDto);
        if (ListUtil.isNull(feeDetailDtos)) {
            return;
        }
        String acctAmountStr = feeDetailDtos.get(0).getAcctAmount();
        if (StringUtil.isEmpty(acctAmountStr)) {
            return;
        }
        double acctAmount = Double.parseDouble(acctAmountStr);
        if (acctAmount <= 0) {
            return;
        }
        String ownerId = "";
        if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(reqJson.getString("payerObjType"))) { //房屋
            OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
@@ -301,44 +334,42 @@
            Assert.listOnlyOne(ownerCarDtos, "查询业主车辆错误!");
            ownerId = ownerCarDtos.get(0).getOwnerId();
        }
        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("更新业主现金账户失败!");
            }
            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("保存业主现金账户明细失败!");
            }
        AccountDto accountDto = new AccountDto();
        accountDto.setObjId(ownerId);
        //1001 无抵扣 1002 现金账户抵扣 1003 积分账户抵扣 1004 优惠券抵扣
        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(acctAmount + "");
        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(acctAmount + "");
        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("保存业主现金账户明细失败!");
        }
    }
    private void returnCoupon(JSONObject reqJson, List<FeeDto> feeDtos) {
@@ -352,11 +383,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)) { //赠送规则
@@ -371,7 +408,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);
@@ -438,18 +478,33 @@
        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("更新数据失败");
        }
        // todo 将收据删除
        FeeReceiptDetailDto feeReceiptDetailDto = new FeeReceiptDetailDto();
        feeReceiptDetailDto.setDetailId(returnPayFeePo.getDetailId());
        feeReceiptDetailDto.setCommunityId(returnPayFeePo.getCommunityId());
        int count = feeReceiptDetailInnerServiceSMOImpl.queryFeeReceiptDetailsCount(feeReceiptDetailDto);
        if (count != 1) {
            return;
        }
        FeeReceiptDetailPo feeReceiptDetailPo = new FeeReceiptDetailPo();
        feeReceiptDetailPo.setDetailId(returnPayFeePo.getDetailId());
        feeReceiptDetailPo.setCommunityId(returnPayFeePo.getCommunityId());
        feeReceiptDetailInnerServiceSMOImpl.deleteFeeReceiptDetail(feeReceiptDetailPo);
    }
    /**
     * 添加退费单
     *
     * @param paramInJson
     * @param returnPayFeeDto
     */
    public void addFeeDetail(JSONObject paramInJson,ReturnPayFeeDto returnPayFeeDto) {
    public void addFeeDetail(JSONObject paramInJson, ReturnPayFeeDto returnPayFeeDto) {
        JSONObject businessReturnPayFee = new JSONObject();
        businessReturnPayFee.putAll(paramInJson);
        businessReturnPayFee.put("detailId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
@@ -576,7 +631,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();
@@ -585,5 +640,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);
    }
}