xuhy
2025-04-09 d66b806d685672f2f817986e89f69fb09d130f11
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java
@@ -7,11 +7,7 @@
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.DisabledEnum;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.OrderNos;
import com.ruoyi.common.utils.SmsUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.TencentMailUtil;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.dto.BillStatisticsDto;
import com.ruoyi.system.dto.CachPayDto;
@@ -41,6 +37,7 @@
import com.taxi591.bankapi.dto.ChargeBillRequest;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.joda.time.LocalDateTime;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -106,6 +103,12 @@
    public PageInfo<TBillDto> queryPage(TBillQuery query){
        PageInfo<TBill> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        PageInfo<TBillDto> info = tBillMapper.page(pageInfo, query);
        return info;
    }
    public PageInfo<TBillDto> queryPageForApplet(TBillQuery query){
        PageInfo<TBill> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        PageInfo<TBillDto> info = tBillMapper.pageForApplet(pageInfo, query);
        return info;
    }
@@ -183,6 +186,7 @@
                            BigDecimal outstand = presist.getPayableFeesMoney()
                                    .add(save.getPayableFeesPenalty())
                                    .subtract(presist.getPayFeesMoney());
                            save.setOutstandingMoney(outstand);
                        }
                        //处理缴费金额
@@ -569,12 +573,12 @@
    }
    @Override
    public BillStatisticsDto statistics(String busDeptId) {
    public BillStatisticsDto statistics(TBillQuery query) {
        BillStatisticsDto dto = new BillStatisticsDto();
        dto.setRent(getBaseMapper().statisticsAllRent(busDeptId));
        dto.setNopay(getBaseMapper().statisticsNoPay(busDeptId));
        dto.setPayed(getBaseMapper().statisticsPayed(busDeptId));
        dto.setOverdue(getBaseMapper().statisticsOverdue(busDeptId));
        dto.setRent(getBaseMapper().statisticsAllRent(query));
        dto.setNopay(getBaseMapper().statisticsNoPay(query));
        dto.setPayed(getBaseMapper().statisticsPayed(query));
        dto.setOverdue(getBaseMapper().statisticsOverdue(query));
        return dto;
    }
@@ -612,4 +616,53 @@
    public List<TBill> getJiFuBillListByTime(String businessDeptId, Date first, Date last) {
        return baseMapper.getJiFuBillList(businessDeptId,first,last);
    }
    @Override
    public void editAmount(TbillSaveDto bill) {
        String requestId = UUID.fastUUID().toString();
        String lockkey = CacheConstants.BILL_UPDATE_LOCK_KEY + bill.getId();
        boolean isok = redisCache.trylockLoop(lockkey, requestId, 60);
        if (isok){
            try {
                TBill presist = getById(bill.getId());
                TBill save = new TBill();
                save.setId(bill.getId());
                BigDecimal preOutstand = presist.getOutstandingMoney();
                // 如果传入的金额小于0,则是扣减,如果大于0,是增加金额,增加金额只加入欠费金额中
                if (bill.getEditAmount().compareTo(BigDecimal.ZERO)<0
                        && presist.getPayableFeesPenalty().compareTo(BigDecimal.ZERO)>0){
                    BigDecimal prePayableFeesPenalty = presist.getPayableFeesPenalty();
                    //违约金大于调整金额,够减
                    if (prePayableFeesPenalty.compareTo(bill.getEditAmount().abs())>=0){
                        BigDecimal afterPenalty = prePayableFeesPenalty.add(bill.getEditAmount());
                        save.setPayableFeesPenalty(afterPenalty);
                    }else{
                        BigDecimal afterPenalty = BigDecimal.ZERO;
                        save.setPayableFeesPenalty(afterPenalty);
                    }
                }
                BigDecimal afterOutstand = preOutstand.add(bill.getEditAmount());
                save.setOutstandingMoney(afterOutstand);
                updateById(save);
            }finally {
                redisCache.unlock(lockkey,requestId);
            }
        }
        //todo 记录金额修改记录
//        TFlowManagement flow = new TFlowManagement();
//        flow.setPayType(3);
//        flow.setPayer("管理员修改");
//        flow.setBusinessDeptId(presist.getBusinessDeptId());
//        flow.setPayTime(DateUtils.dateToLocalDateTime(new Date()));
//        flow.setSysSerialNumber(OrderNos.getDid(30));
//        flow.setFlowType(1);
//        flow.setPaymentBillId(back.getId());
//        flow.setDeductionMoney(back.getDeductionMoney());
//        flow.setFlowMoney(save.getOutstandingMoney());
//        flow.setRemainingMoney(back.getOutstandingMoney());
//        flow.setPreOutstand(back.getPreOutstand());
//        flow.setCreateBy(SecurityUtils.getUsername());
//        tFlowManagementService.save(flow);
    }
}