jialh
1 天以前 dd6687b118561100e1677e88a9c2f5842a54c531
service-fee/src/main/java/com/java110/fee/cmd/fee/PayFeeConfirmCmd.java
@@ -3,52 +3,55 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.AbstractServiceCmdListener;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.dto.account.AccountDto;
import com.java110.dto.app.AppDto;
import com.java110.dto.couponUser.CouponUserDto;
import com.java110.dto.coupon.CouponUserDto;
import com.java110.dto.fee.FeeAttrDto;
import com.java110.dto.fee.FeeConfigDto;
import com.java110.dto.fee.FeeDetailDto;
import com.java110.dto.fee.FeeDto;
import com.java110.dto.feeDiscount.ComputeDiscountDto;
import com.java110.dto.fee.ComputeDiscountDto;
import com.java110.dto.owner.OwnerCarDto;
import com.java110.dto.parking.ParkingSpaceApplyDto;
import com.java110.dto.repair.RepairDto;
import com.java110.dto.repair.RepairUserDto;
import com.java110.fee.bmo.fee.IFeeBMO;
import com.java110.fee.bmo.fee.IFinishFeeNotify;
import com.java110.intf.acct.IAccountInnerServiceSMO;
import com.java110.intf.acct.ICouponUserDetailV1InnerServiceSMO;
import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
import com.java110.intf.community.IRepairUserInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.intf.community.*;
import com.java110.intf.fee.*;
import com.java110.intf.user.IOwnerCarInnerServiceSMO;
import com.java110.po.accountDetail.AccountDetailPo;
import com.java110.po.applyRoomDiscount.ApplyRoomDiscountPo;
import com.java110.po.account.AccountDetailPo;
import com.java110.po.room.ApplyRoomDiscountPo;
import com.java110.po.car.OwnerCarPo;
import com.java110.po.couponUser.CouponUserPo;
import com.java110.po.couponUserDetail.CouponUserDetailPo;
import com.java110.po.coupon.CouponUserPo;
import com.java110.po.coupon.CouponUserDetailPo;
import com.java110.po.fee.FeeAccountDetailPo;
import com.java110.po.owner.RepairPoolPo;
import com.java110.po.owner.RepairUserPo;
import com.java110.po.payFeeDetailDiscount.PayFeeDetailDiscountPo;
import com.java110.po.parking.ParkingSpaceApplyPo;
import com.java110.po.payFee.PayFeeDetailDiscountPo;
import com.java110.utils.cache.CommonCache;
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 com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Java110Cmd(serviceCode = "fee.payFeeConfirm")
public class PayFeeConfirmCmd extends AbstractServiceCmdListener {
public class PayFeeConfirmCmd extends Cmd {
    @Autowired
    private IFeeBMO feeBMOImpl;
@@ -87,16 +90,23 @@
    @Autowired
    private IPayFeeDetailDiscountNewV1InnerServiceSMO payFeeDetailDiscountNewV1InnerServiceSMOImpl;
    @Autowired
    private IRepairPoolNewV1InnerServiceSMO repairPoolNewV1InnerServiceSMOImpl;
    private IRepairPoolV1InnerServiceSMO repairPoolNewV1InnerServiceSMOImpl;
    @Autowired
    private IRepairUserNewV1InnerServiceSMO repairUserNewV1InnerServiceSMOImpl;
    private IRepairUserV1InnerServiceSMO repairUserNewV1InnerServiceSMOImpl;
    @Autowired
    private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
    @Autowired
    private ICouponUserDetailV1InnerServiceSMO couponUserDetailV1InnerServiceSMOImpl;
    @Autowired
    private IParkingSpaceApplyV1InnerServiceSMO parkingSpaceApplyV1InnerServiceSMOImpl;
    @Autowired
    private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
    @Autowired
    private IFeeAccountDetailServiceSMO feeAccountDetailServiceSMOImpl;
    @Autowired
    private IFinishFeeNotify finishFeeNotifyImpl;
    //默认序列
    protected static final int DEFAULT_SEQ = 1;
@@ -107,13 +117,21 @@
    }
    @Override
    @Java110Transactional
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        String paramIn = CommonCache.getAndRemoveValue("payFeePre" + reqJson.getString("oId"));
        JSONObject paramObj = JSONObject.parseObject(paramIn);
        String appId = paramObj.getString("appId");
        if (AppDto.WECHAT_MINA_OWNER_APP_ID.equals(appId)) {  //微信小程序支付
        if (reqJson.containsKey("custEndTimeUse")){
            paramObj.put("custEndTimeUse",reqJson.getString("custEndTimeUse"));
        }
        if (reqJson.containsKey("receivedAmount")){
            paramObj.put("receivedAmount",reqJson.getString("receivedAmount"));
        }
        if (reqJson.containsKey("remark")){
            paramObj.put("primeRate", "6");
            paramObj.put("remark", reqJson.getString("remark"));
        } else if (AppDto.WECHAT_MINA_OWNER_APP_ID.equals(appId)) {  //微信小程序支付
            paramObj.put("primeRate", "6");
            paramObj.put("remark", "线上小程序支付");
        } else if (AppDto.WECHAT_OWNER_APP_ID.equals(appId)) {  //微信公众号支付
@@ -123,9 +141,11 @@
            paramObj.put("primeRate", "6");
            paramObj.put("remark", "线上小程序支付");
        }
        paramObj.put("detailId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId));
        //处理现金账户
        dealAccount(paramObj);
        //处理 优惠折扣
        addDiscount(paramObj);
@@ -137,67 +157,14 @@
        feeBMOImpl.addFeePreDetail(paramObj);
        feeBMOImpl.modifyPreFee(paramObj);
        dealOwnerCartEndTime(paramObj);
        //todo 为停车费单独处理
        finishFeeNotifyImpl.updateCarEndTime(paramObj.getString("feeId"), paramObj.getString("communityId"));
        //判断是否有派单属性ID
        FeeAttrDto feeAttrDto = new FeeAttrDto();
        feeAttrDto.setCommunityId(paramObj.getString("communityId"));
        feeAttrDto.setFeeId(paramObj.getString("feeId"));
        feeAttrDto.setSpecCd(FeeAttrDto.SPEC_CD_REPAIR);
        List<FeeAttrDto> feeAttrDtos = feeAttrInnerServiceSMOImpl.queryFeeAttrs(feeAttrDto);
        //修改 派单状态
        if (feeAttrDtos != null && feeAttrDtos.size() > 0) {
            RepairPoolPo repairPoolPo = new RepairPoolPo();
            repairPoolPo.setRepairId(feeAttrDtos.get(0).getValue());
            repairPoolPo.setCommunityId(paramObj.getString("communityId"));
            repairPoolPo.setState(RepairDto.STATE_APPRAISE);
            int flag = repairPoolNewV1InnerServiceSMOImpl.updateRepairPoolNew(repairPoolPo);
            if (flag < 1) {
                throw new CmdException("更新微信派单池信息失败");
            }
        }
        //修改报修派单状态
        if (feeAttrDtos != null && feeAttrDtos.size() > 0) {
        //todo 修改报修单
        finishFeeNotifyImpl.updateRepair(paramObj.getString("feeId"), paramObj.getString("communityId"), paramObj.getString("receivedAmount"));
            RepairUserDto repairUserDto = new RepairUserDto();
            repairUserDto.setRepairId(feeAttrDtos.get(0).getValue());
            repairUserDto.setState(RepairUserDto.STATE_PAY_FEE);
            //查询待支付状态的记录
            List<RepairUserDto> repairUserDtoList = repairUserInnerServiceSMO.queryRepairUsers(repairUserDto);
            Assert.listOnlyOne(repairUserDtoList, "信息错误!");
            RepairUserPo repairUserPo = new RepairUserPo();
            repairUserPo.setRuId(repairUserDtoList.get(0).getRuId());
            repairUserPo.setState(RepairUserDto.STATE_FINISH_PAY_FEE);
            //如果是待评价状态,就更新结束时间
            repairUserPo.setEndTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
            DecimalFormat df = new DecimalFormat("0.00");
            BigDecimal payment_amount = new BigDecimal(paramObj.getString("receivableAmount"));
            repairUserPo.setContext("已支付" + df.format(payment_amount) + "元");
            int flag = repairUserNewV1InnerServiceSMOImpl.updateRepairUserNew(repairUserPo);
            if (flag < 1) {
                throw new CmdException("更新微信派单池信息失败");
            }
            //新增待评价状态
            RepairUserPo repairUser = new RepairUserPo();
            repairUser.setRuId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_ruId));
            repairUser.setStartTime(repairUserPo.getEndTime());
            repairUser.setState(RepairUserDto.STATE_EVALUATE);
            repairUser.setContext("待评价");
            repairUser.setCommunityId(paramObj.getString("communityId"));
            repairUser.setCreateTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
            repairUser.setRepairId(repairUserDtoList.get(0).getRepairId());
            repairUser.setStaffId(repairUserDtoList.get(0).getStaffId());
            repairUser.setStaffName(repairUserDtoList.get(0).getStaffName());
            repairUser.setPreStaffId(repairUserDtoList.get(0).getStaffId());
            repairUser.setPreStaffName(repairUserDtoList.get(0).getStaffName());
            repairUser.setPreRuId(repairUserDtoList.get(0).getRuId());
            repairUser.setRepairEvent("auditUser");
            repairUser.setbId("-1");
            flag = repairUserNewV1InnerServiceSMOImpl.saveRepairUserNew(repairUser);
            if (flag < 1) {
                throw new CmdException("更新微信派单池信息失败");
            }
        }
        //todo 租金延期房屋结束时间
        finishFeeNotifyImpl.updateRoomEndTime(paramObj.getString("feeId"), paramObj.getString("communityId"));
        //查询 pay_fee_detail 是否缴费
        FeeDetailDto feeDetailDto = new FeeDetailDto();
@@ -207,9 +174,12 @@
            //获取bId
            String bId = feeDetailDtoList.get(0).getbId();
            //获取优惠
            List<ComputeDiscountDto> computeDiscountDtos = (List<ComputeDiscountDto>) paramObj.get("computeDiscountDtos");
            if (computeDiscountDtos != null) {
                for (ComputeDiscountDto computeDiscountDto : computeDiscountDtos) {
            //List<ComputeDiscountDto> computeDiscountDtos = (List<ComputeDiscountDto>) paramObj.get("computeDiscountDtos");
            JSONArray computeDiscountDtos = paramObj.getJSONArray("computeDiscountDtos");
            ComputeDiscountDto computeDiscountDto = null;
            if (!ListUtil.isNull(computeDiscountDtos)) {
                for (int accountIndex = 0; accountIndex < computeDiscountDtos.size(); accountIndex++) {
                    computeDiscountDto = BeanConvertUtil.covertBean(computeDiscountDtos.getJSONObject(accountIndex), ComputeDiscountDto.class);
                    if (!StringUtil.isEmpty(computeDiscountDto.getArdId())) {
                        ApplyRoomDiscountPo applyRoomDiscountPo = new ApplyRoomDiscountPo();
                        //将业务id更新到空置房优惠里面
@@ -222,49 +192,111 @@
                    }
                }
            }
        }
        //回调判断 车位申请表是否有数据,有数据则刷新申请表状态为 3003 完成状态即可
        //判断车辆是否已经有申请单
        ParkingSpaceApplyDto parkingSpaceApplyDto = new ParkingSpaceApplyDto();
        parkingSpaceApplyDto.setFeeId(paramObj.getString("feeId"));
        parkingSpaceApplyDto.setState("2002");//审核中
        List<ParkingSpaceApplyDto> parkingSpaceApplyDtos = parkingSpaceApplyV1InnerServiceSMOImpl.queryParkingSpaceApplys(parkingSpaceApplyDto);
        if (!ListUtil.isNull(parkingSpaceApplyDtos)) {
            ParkingSpaceApplyPo parkingSpaceApplyPo = new ParkingSpaceApplyPo();
            parkingSpaceApplyPo.setApplyId(parkingSpaceApplyDtos.get(0).getApplyId());
            parkingSpaceApplyPo.setState("3003");
            int flag = parkingSpaceApplyV1InnerServiceSMOImpl.updateParkingSpaceApply(parkingSpaceApplyPo);
            if (flag < 1) {
                throw new CmdException("更新车位申请表状态失败");
            }
        }
        cmdDataFlowContext.setResponseEntity(ResultVo.success());
    }
    private void dealAccount(JSONObject paramObj) {
        if (!paramObj.containsKey("deductionAmount") || paramObj.getDouble("deductionAmount") <= 0) {
        JSONArray accountDtos = paramObj.getJSONArray("selectUserAccount");
        if(ListUtil.isNull(accountDtos)){
            return;
        }
        BigDecimal deductionAmount = new BigDecimal(paramObj.getDouble("deductionAmount"));
        JSONArray accountDtos = paramObj.getJSONArray("selectUserAccount");
        BigDecimal amount = null;
        AccountDto accountDto = null;
        String accountRemark = "";
        String pointRemark = "";
        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);
            }
            int flag = accountInnerServiceSMOImpl.withholdAccount(accountDetailPo);
            if (!StringUtil.isEmpty(accountDto.getAcctType()) && accountDto.getAcctType().equals("2003")) { //2003 现金账户 2004 积分账户
                //获取现金账户抵扣金额
                BigDecimal cashMoney = new BigDecimal(0.0);
                if (!StringUtil.isEmpty(paramObj.getString("cashMoney"))) {
                    String cashMoney1 = paramObj.getString("cashMoney");
                    cashMoney = new BigDecimal(cashMoney1);
                    if (cashMoney.compareTo(BigDecimal.ZERO) > 0) {
                        accountRemark = "现金账户抵扣" + String.format("%.2f", cashMoney) + "元";
                    }
                }
                int i = cashMoney.compareTo(BigDecimal.ZERO);
                if (i > 0) {
                    BigDecimal amount = new BigDecimal(Double.parseDouble(accountDto.getAmount())); //现金账户余额
                    AccountDetailPo accountDetailPo = new AccountDetailPo();
                    accountDetailPo.setAcctId(accountDto.getAcctId());
                    accountDetailPo.setObjId(accountDto.getObjId());
                    accountDetailPo.setObjType(accountDto.getObjType());
                    accountDetailPo.setAmount(String.valueOf(cashMoney));
                    int flag = accountInnerServiceSMOImpl.withholdAccount(accountDetailPo);
                    if (flag < 1) {
                        throw new CmdException("现金账户扣款失败!");
                    }
                    // 现金账户扣款记录,生成抵扣明细记录
                    FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
                    feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
                    feeAccountDetailPo.setDetailId(paramObj.getString("detailId"));
                    feeAccountDetailPo.setCommunityId(paramObj.getString("communityId"));
                    feeAccountDetailPo.setState("1002"); //1001 无抵扣 1002 现金账户抵扣 1003 积分账户抵扣 1004 优惠券抵扣
                    feeAccountDetailPo.setAmount(String.valueOf(cashMoney)); //现金抵扣金额
                    feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
                }
            if (flag < 1) {
                throw new CmdException("扣款失败");
            } else if (!StringUtil.isEmpty(accountDto.getAcctType()) && accountDto.getAcctType().equals("2004")) { //积分账户
                //获取积分账户抵扣的积分数
                BigDecimal pointsMoney = new BigDecimal(0.0);
                BigDecimal pointsMoneyNow = new BigDecimal(0.0);
                if (!StringUtil.isEmpty(paramObj.getString("pointsMoney"))) {
                    String pointsMoney1 = paramObj.getString("pointsMoney");
                    pointsMoney = new BigDecimal(pointsMoney1);
                    String pointsMoneyNow1 = paramObj.getString("pointsMoneyNow");
                    pointsMoneyNow = new BigDecimal(pointsMoneyNow1);
                    if (pointsMoneyNow.compareTo(BigDecimal.ZERO) > 0) {
                        pointRemark = "积分账户抵扣" + String.format("%.2f", pointsMoneyNow) + "元";
                    }
                }
                int i = pointsMoney.compareTo(BigDecimal.ZERO);
                if (i > 0) {
                    BigDecimal amount = new BigDecimal(Double.parseDouble(accountDto.getAmount())); //积分账户积分数
                    AccountDetailPo accountDetailPo = new AccountDetailPo();
                    accountDetailPo.setAcctId(accountDto.getAcctId());
                    accountDetailPo.setObjId(accountDto.getObjId());
                    accountDetailPo.setObjType(accountDto.getObjType());
                    accountDetailPo.setAmount(String.valueOf(pointsMoney));
                    int flag = accountInnerServiceSMOImpl.withholdAccount(accountDetailPo);
                    if (flag < 1) {
                        throw new CmdException("积分账户扣款失败!");
                    }
                    // 积分账户扣款记录,生成抵扣明细记录
                    FeeAccountDetailPo feeAccountDetailPo = new FeeAccountDetailPo();
                    feeAccountDetailPo.setFadId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fadId));
                    feeAccountDetailPo.setDetailId(paramObj.getString("detailId"));
                    feeAccountDetailPo.setCommunityId(paramObj.getString("communityId"));
                    feeAccountDetailPo.setState("1003"); //1001 无抵扣 1002 现金账户抵扣 1003 积分账户抵扣 1004 优惠券抵扣
                    feeAccountDetailPo.setAmount(String.valueOf(paramObj.getString("pointsMoneyNow"))); //现金抵扣金额
                    feeAccountDetailServiceSMOImpl.saveFeeAccountDetail(feeAccountDetailPo);
                }
            }
        }
        if (deductionAmount.doubleValue() > 0) {
            throw new CmdException("账户金额不足");
        if (!StringUtil.isEmpty(accountRemark) && !StringUtil.isEmpty(pointRemark)) {
            paramObj.put("remark", paramObj.getString("remark") + "," + accountRemark + "," + pointRemark);
        } else {
            paramObj.put("remark", paramObj.getString("remark") + "," + accountRemark + pointRemark);
        }
        paramObj.put("remark", paramObj.getString("remark") + "-现金账户抵扣" + paramObj.getDouble("deductionAmount") + "元");
    }
@@ -272,9 +304,12 @@
        if (!paramObj.containsKey("couponPrice") || paramObj.getDouble("couponPrice") <= 0) {
            return;
        }
        FeeDto feeInfo = (FeeDto) paramObj.get("feeInfo");
        //FeeDto feeInfo = (FeeDto) paramObj.get("feeInfo");
        CouponUserDto couponUserDto = null;
        JSONArray couponUserDtos = paramObj.getJSONArray("couponUserDtos");
        if(ListUtil.isNull(couponUserDtos)){
            return ;
        }
        CouponUserDto couponUser = null;
        for (int accountIndex = 0; accountIndex < couponUserDtos.size(); accountIndex++) {
            couponUser = BeanConvertUtil.covertBean(couponUserDtos.getJSONObject(accountIndex), CouponUserDto.class);
@@ -298,8 +333,8 @@
            couponUserDetailPo.setUserId(couponUser.getUserId());
            couponUserDetailPo.setCouponName(couponUser.getCouponName());
            couponUserDetailPo.setUserName(couponUser.getUserName());
            couponUserDetailPo.setObjId(feeInfo.getFeeId());
            couponUserDetailPo.setObjType(feeInfo.getFeeTypeCd());
            couponUserDetailPo.setObjId(paramObj.getString("feeId"));
            couponUserDetailPo.setObjType(paramObj.getString("feeTypeCd"));
            couponUserDetailPo.setOrderId(paramObj.getString("oId"));
            fage = couponUserDetailV1InnerServiceSMOImpl.saveCouponUserDetail(couponUserDetailPo);
            if (fage < 1) {
@@ -317,6 +352,9 @@
            return;
        }
        JSONArray computeDiscountDtos = paramObj.getJSONArray("computeDiscountDtos");
        if(ListUtil.isNull(computeDiscountDtos)){
            return;
        }
        ComputeDiscountDto computeDiscountDto = null;
        for (int accountIndex = 0; accountIndex < computeDiscountDtos.size(); accountIndex++) {
            computeDiscountDto = BeanConvertUtil.covertBean(computeDiscountDtos.getJSONObject(accountIndex), ComputeDiscountDto.class);
@@ -341,29 +379,5 @@
        }
    }
    private void dealOwnerCartEndTime(JSONObject paramObj) {
        //为停车费单独处理
        if (paramObj.containsKey("carPayerObjType")
                && FeeDto.PAYER_OBJ_TYPE_CAR.equals(paramObj.getString("carPayerObjType"))) {
            Date feeEndTime = (Date) paramObj.get("carFeeEndTime");
            OwnerCarDto ownerCarDto = new OwnerCarDto();
            ownerCarDto.setCommunityId(paramObj.getString("communityId"));
            ownerCarDto.setCarId(paramObj.getString("carPayerObjId"));
            List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
            //车位费用续租
            if (ownerCarDtos != null) {
                for (OwnerCarDto tmpOwnerCarDto : ownerCarDtos) {
                    if (tmpOwnerCarDto.getEndTime().getTime() < feeEndTime.getTime()) {
                        OwnerCarPo ownerCarPo = new OwnerCarPo();
                        ownerCarPo.setMemberId(tmpOwnerCarDto.getMemberId());
                        ownerCarPo.setEndTime(DateUtil.getFormatTimeString(feeEndTime, DateUtil.DATE_FORMATE_STRING_A));
                        int fage = ownerCarNewV1InnerServiceSMOImpl.updateOwnerCarNew(ownerCarPo);
                        if (fage < 1) {
                            throw new CmdException("更新费用信息失败");
                        }
                    }
                }
            }
        }
    }
}