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();
@@ -189,7 +201,28 @@
        Assert.listOnlyOne(userDtos, "用户不存在");
        FeeDetailDto feeDetailDto = (FeeDetailDto) reqJson.get("feeDetailDto");
        updateReturnPayFee(reqJson, userDtos.get(0));
        ReturnPayFeeDto returnPayFeeDto = new ReturnPayFeeDto();
        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));
        //退费审核通过
        if ("1100".equals(reqJson.getString("state"))) {
            //判断退费周期是否为负数如果不是 抛出异常
@@ -198,7 +231,8 @@
            reqJson.put("startTime", DateUtil.getFormatTimeString(feeDetailDto.getStartTime(), DateUtil.DATE_FORMATE_STRING_A));
            reqJson.put("endTime", DateUtil.getFormatTimeString(feeDetailDto.getEndTime(), DateUtil.DATE_FORMATE_STRING_A));
            reqJson.put("payOrderId", feeDetailDto.getPayOrderId());
            addFeeDetail(reqJson);
            // todo  添加退费明细
            addFeeDetail(reqJson, returnPayFeeDtos.get(0));
            reqJson.put("state", "1100");
            String receivableAmount = (String) reqJson.get("receivableAmount");
            String receivedAmount = (String) reqJson.get("receivedAmount");
@@ -206,13 +240,10 @@
            reqJson.put("receivableAmount", unum(receivableAmount));
            reqJson.put("receivedAmount", unum(receivedAmount));
            reqJson.put("createTime", reqJson.get("payTime"));
            // 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());
@@ -228,11 +259,13 @@
            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");
            }
            //todo 费用退回去
            updateFee(reqJson);
            reqJson.put("feeName", feeDto1.getFeeName());
//            dealFeeReceipt(reqJson);
@@ -241,131 +274,17 @@
            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()));
                addPayFeeDetailDiscountTwo(reqJson, discountJson);
            }
            //判读是否有赠送规则优惠
            PayFeeConfigDiscountDto payFeeConfigDiscountDto = new PayFeeConfigDiscountDto();
            payFeeConfigDiscountDto.setConfigId(reqJson.getString("configId"));
            List<PayFeeConfigDiscountDto> payFeeConfigDiscountDtos = payFeeConfigDiscountInnerServiceSMOImpl.queryPayFeeConfigDiscounts(payFeeConfigDiscountDto);
            if (payFeeConfigDiscountDtos != null && payFeeConfigDiscountDtos.size() > 0) {
                for (PayFeeConfigDiscountDto payFeeConfigDiscount : payFeeConfigDiscountDtos) {
                    FeeDiscountDto feeDiscountDto = new FeeDiscountDto();
                    feeDiscountDto.setDiscountId(payFeeConfigDiscount.getDiscountId());
                    List<FeeDiscountDto> feeDiscountDtos = feeDiscountInnerServiceSMOImpl.queryFeeDiscounts(feeDiscountDto);
                    Assert.listOnlyOne(feeDiscountDtos, "查询打折优惠表错误");
                    FeeDiscountRuleDto feeDiscountRuleDto = new FeeDiscountRuleDto();
                    feeDiscountRuleDto.setRuleId(feeDiscountDtos.get(0).getRuleId());
                    List<FeeDiscountRuleDto> feeDiscountRuleDtos = feeDiscountRuleInnerServiceSMOImpl.queryFeeDiscountRules(feeDiscountRuleDto);
                    Assert.listOnlyOne(feeDiscountRuleDtos, "查询规则表错误");
                    //获取实现方式
                    String beanImpl = feeDiscountRuleDtos.get(0).getBeanImpl();
                    if (!StringUtil.isEmpty(beanImpl) && beanImpl.equals("reductionMonthFeeRule")) { //赠送规则
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        Calendar cal = Calendar.getInstance();
                        //获取缴费开始时间
                        Date startTime = DateUtil.getDateFromStringA(reqJson.getString("startTime"));
                        FeeDiscountSpecDto feeDiscountSpecDto = new FeeDiscountSpecDto();
                        feeDiscountSpecDto.setDiscountId(payFeeConfigDiscount.getDiscountId());
                        feeDiscountSpecDto.setSpecId(SPEC_RATE); //赠送规则
                        //查询打折规格
                        List<FeeDiscountSpecDto> feeDiscountSpecDtos = feeDiscountSpecInnerServiceSMOImpl.queryFeeDiscountSpecs(feeDiscountSpecDto);
                        Assert.listOnlyOne(feeDiscountSpecDtos, "查询打折规格表错误!");
                        //获取赠送月份
                        String specValue = feeDiscountSpecDtos.get(0).getSpecValue();
                        BigDecimal value = new BigDecimal(specValue);
                        FeeDiscountSpecDto feeDiscountSpec = new FeeDiscountSpecDto();
                        feeDiscountSpec.setDiscountId(payFeeConfigDiscount.getDiscountId());
                        feeDiscountSpec.setSpecId(SPEC_MONTH); //月份
                        List<FeeDiscountSpecDto> feeDiscountSpecs = feeDiscountSpecInnerServiceSMOImpl.queryFeeDiscountSpecs(feeDiscountSpec);
                        Assert.listOnlyOne(feeDiscountSpecs, "查询打折规格表错误!");
                        //获取月份
                        BigDecimal discountMonth = new BigDecimal(feeDiscountSpecs.get(0).getSpecValue());
                        //获取周期
                        BigDecimal cycle = new BigDecimal(reqJson.getString("cycles"));
                        int flag = discountMonth.compareTo(cycle);
                        if (flag == 1) { //月份discountMonth大于周期cycle,无法享受赠送规则
                            continue;
                        }
//                        FeeDto feeDto2 = new FeeDto();
//                        feeDto2.setFeeId(feeDtos.get(0).getFeeId());
//                        List<FeeDto> fees = feeInnerServiceSMOImpl.queryFees(feeDto2);
//                        Assert.listOnlyOne(fees, "查询费用表错误");
                        int monthNum = cycle.add(value).intValue();
                        //获取费用开始时间
                        Date endTime = feeDtos.get(0).getEndTime();
//                        if (endTime.equals(startTime)) {
//                            continue;
//                        }
                        cal.setTime(endTime);
                        cal.add(Calendar.MONTH, -monthNum);
                        PayFeePo payFeePo = new PayFeePo();
                        payFeePo.setFeeId(feeDtos.get(0).getFeeId());
                        payFeePo.setEndTime(simpleDateFormat.format(cal.getTime()));
                        feeInnerServiceSMOImpl.updateFee(payFeePo);
                    }
                }
            }
            //检查是否现金账户抵扣
            String feeAccountDetailDtoList = reqJson.getString("feeAccountDetailDtoList");
            JSONArray feeAccountDetails = JSONArray.parseArray(feeAccountDetailDtoList);
            if (feeAccountDetails != null && feeAccountDetails.size() > 0) {
                String ownerId = "";
                if (!StringUtil.isEmpty(reqJson.getString("payerObjType")) && reqJson.getString("payerObjType").equals("3333")) { //房屋
                    OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
                    ownerRoomRelDto.setRoomId(reqJson.getString("payerObjId"));
                    List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
                    Assert.listOnlyOne(ownerRoomRelDtos, "查询业主房屋关系表错误!");
                    ownerId = ownerRoomRelDtos.get(0).getOwnerId();
                } else if (!StringUtil.isEmpty(reqJson.getString("payerObjType")) && reqJson.getString("payerObjType").equals("6666")) { //车辆
                    OwnerCarDto ownerCarDto = new OwnerCarDto();
                    ownerCarDto.setMemberId(reqJson.getString("payerObjId"));
                    List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
                    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 优惠券抵扣
                        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("保存业主现金账户明细失败!");
                        }
                    }
                }
            }
            //提交线上退费
            //todo 判读是否有赠送规则优惠
            returnCoupon(reqJson, feeDtos);
            //todo 检查是否现金账户抵扣
            returnAccount(reqJson);
            //todo 提交线上退费
            returnOnlinePayMoney(feeDetailDto);
        }
        //不通过
@@ -384,6 +303,147 @@
        }
    }
    private void returnAccount(JSONObject reqJson) {
        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();
            ownerRoomRelDto.setRoomId(reqJson.getString("payerObjId"));
            List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
            Assert.listOnlyOne(ownerRoomRelDtos, "查询业主房屋关系表错误!");
            ownerId = ownerRoomRelDtos.get(0).getOwnerId();
        } else if (FeeDto.PAYER_OBJ_TYPE_CAR.equals(reqJson.getString("payerObjType"))) { //车辆
            OwnerCarDto ownerCarDto = new OwnerCarDto();
            ownerCarDto.setMemberId(reqJson.getString("payerObjId"));
            List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
            Assert.listOnlyOne(ownerCarDtos, "查询业主车辆错误!");
            ownerId = ownerCarDtos.get(0).getOwnerId();
        }
        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) {
        PayFeeConfigDiscountDto payFeeConfigDiscountDto = new PayFeeConfigDiscountDto();
        payFeeConfigDiscountDto.setConfigId(reqJson.getString("configId"));
        List<PayFeeConfigDiscountDto> payFeeConfigDiscountDtos = payFeeConfigDiscountInnerServiceSMOImpl.queryPayFeeConfigDiscounts(payFeeConfigDiscountDto);
        if (payFeeConfigDiscountDtos == null || payFeeConfigDiscountDtos.size() < 1) {
            return;
        }
        for (PayFeeConfigDiscountDto payFeeConfigDiscount : payFeeConfigDiscountDtos) {
            FeeDiscountDto feeDiscountDto = new FeeDiscountDto();
            feeDiscountDto.setDiscountId(payFeeConfigDiscount.getDiscountId());
            List<FeeDiscountDto> feeDiscountDtos = feeDiscountInnerServiceSMOImpl.queryFeeDiscounts(feeDiscountDto);
            //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, "查询规则表错误");
            if (feeDiscountRuleDtos == null || feeDiscountRuleDtos.size() < 1) {
                continue;
            }
            //获取实现方式
            String beanImpl = feeDiscountRuleDtos.get(0).getBeanImpl();
            if (!"reductionMonthFeeRule".equals(beanImpl)) { //赠送规则
                continue;
            }
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar cal = Calendar.getInstance();
            //获取缴费开始时间
            Date startTime = DateUtil.getDateFromStringA(reqJson.getString("startTime"));
            FeeDiscountSpecDto feeDiscountSpecDto = new FeeDiscountSpecDto();
            feeDiscountSpecDto.setDiscountId(payFeeConfigDiscount.getDiscountId());
            feeDiscountSpecDto.setSpecId(SPEC_RATE); //赠送规则
            //查询打折规格
            List<FeeDiscountSpecDto> feeDiscountSpecDtos = feeDiscountSpecInnerServiceSMOImpl.queryFeeDiscountSpecs(feeDiscountSpecDto);
            // Assert.listOnlyOne(feeDiscountSpecDtos, "查询打折规格表错误!");
            if (feeDiscountSpecDtos == null || feeDiscountSpecDtos.size() < 1) {
                continue;
            }
            //获取赠送月份
            String specValue = feeDiscountSpecDtos.get(0).getSpecValue();
            BigDecimal value = new BigDecimal(specValue);
            FeeDiscountSpecDto feeDiscountSpec = new FeeDiscountSpecDto();
            feeDiscountSpec.setDiscountId(payFeeConfigDiscount.getDiscountId());
            feeDiscountSpec.setSpecId(SPEC_MONTH); //月份
            List<FeeDiscountSpecDto> feeDiscountSpecs = feeDiscountSpecInnerServiceSMOImpl.queryFeeDiscountSpecs(feeDiscountSpec);
            Assert.listOnlyOne(feeDiscountSpecs, "查询打折规格表错误!");
            //获取月份
            BigDecimal discountMonth = new BigDecimal(feeDiscountSpecs.get(0).getSpecValue());
            //获取周期
            BigDecimal cycle = new BigDecimal(reqJson.getString("cycles"));
            int flag = discountMonth.compareTo(cycle);
            if (flag == 1) { //月份discountMonth大于周期cycle,无法享受赠送规则
                continue;
            }
            int monthNum = cycle.add(value).intValue();
            //获取费用开始时间
            Date endTime = feeDtos.get(0).getEndTime();
            cal.setTime(endTime);
            cal.add(Calendar.MONTH, -monthNum);
            PayFeePo payFeePo = new PayFeePo();
            payFeePo.setFeeId(feeDtos.get(0).getFeeId());
            payFeePo.setEndTime(simpleDateFormat.format(cal.getTime()));
            feeInnerServiceSMOImpl.updateFee(payFeePo);
        }
    }
    private double unum(String value) {
        double dValue = Double.parseDouble(value);
        return dValue * -1;
@@ -395,13 +455,10 @@
     * @param paramInJson 接口调用放传入入参
     * @return 订单服务能够接受的报文
     */
    public void updateReturnPayFee(JSONObject paramInJson, UserDto userDto) {
        ReturnPayFeeDto returnPayFeeDto = new ReturnPayFeeDto();
        returnPayFeeDto.setReturnFeeId(paramInJson.getString("returnFeeId"));
        List<ReturnPayFeeDto> returnPayFeeDtos = returnPayFeeInnerServiceSMOImpl.queryReturnPayFees(returnPayFeeDto);
        Assert.listOnlyOne(returnPayFeeDtos, "未找到需要修改的活动 或多条数据");
    public void updateReturnPayFee(JSONObject paramInJson, UserDto userDto, ReturnPayFeeDto returnPayFeeDto) {
        JSONObject businessReturnPayFee = new JSONObject();
        businessReturnPayFee.putAll(BeanConvertUtil.beanCovertMap(returnPayFeeDtos.get(0)));
        businessReturnPayFee.putAll(BeanConvertUtil.beanCovertMap(returnPayFeeDto));
        businessReturnPayFee.putAll(paramInJson);
        ReturnPayFeePo returnPayFeePo = BeanConvertUtil.covertBean(businessReturnPayFee, ReturnPayFeePo.class);
        returnPayFeePo.setAuditPersonId(userDto.getUserId());
@@ -421,17 +478,39 @@
        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);
    }
    public void addFeeDetail(JSONObject paramInJson) {
    /**
     * 添加退费单
     *
     * @param paramInJson
     * @param returnPayFeeDto
     */
    public void addFeeDetail(JSONObject paramInJson, ReturnPayFeeDto returnPayFeeDto) {
        JSONObject businessReturnPayFee = new JSONObject();
        businessReturnPayFee.putAll(paramInJson);
        businessReturnPayFee.put("detailId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
        PayFeeDetailPo returnPayFeePo = BeanConvertUtil.covertBean(businessReturnPayFee, PayFeeDetailPo.class);
        returnPayFeePo.setCashierId(returnPayFeeDto.getApplyPersonId());
        returnPayFeePo.setCashierName(returnPayFeeDto.getApplyPersonName());
        int flag = payFeeDetailV1InnerServiceSMOImpl.savePayFeeDetailNew(returnPayFeePo);
        if (flag < 1) {
            throw new CmdException("更新数据失败");
@@ -552,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();
@@ -561,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);
    }
}