刘帅
2026-09-21 620a310bdcfb1d8f1b49bf163413afeb522e1b2f
cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TFinanceController.java
@@ -26,6 +26,7 @@
import com.dsh.guns.core.util.ToolUtil;
import com.dsh.guns.modular.system.model.*;
import com.dsh.guns.modular.system.service.*;
import com.dsh.guns.modular.system.util.ResultUtil;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.beans.factory.annotation.Autowired;
@@ -41,6 +42,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
@@ -76,69 +78,68 @@
    private SiteClient siteClient;
    /**
     * 跳转到充值记录页面
    /*
     * 充值记录功能已下线,保留原实现以便后续恢复。
     *
     * @RequestMapping("/rechargeRecords")
     * public String index(Model model) {
     *     List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
     *     model.addAttribute("list",list);
     *     Integer objectType = UserExt.getUser().getObjectType();
     *     Integer objectId = UserExt.getUser().getObjectId();
     *     model.addAttribute("userType",objectType);
     *     String roleid = UserExt.getUser().getRoleid();
     *     model.addAttribute("objectType",objectType);
     *     return PREFIX + "RechargeRecords.html";
     * }
     *
     * @RequestMapping(value = "/listAll")
     * @ResponseBody
     * public List<RechargeRecordsVO> list(String province, String city, String name, String phone, String time, Integer type) {
     *     RechargeRecordsQuery coachQuery = new RechargeRecordsQuery();
     *     Region provinceCode = regionService.getOne(new QueryWrapper<Region>().eq("code", province));
     *     Region cityCode = regionService.getOne(new QueryWrapper<Region>().eq("code", city));
     *     if (provinceCode != null) {
     *         coachQuery.setProvince(provinceCode.getName());
     *     } else {
     *         coachQuery.setProvince(province);
     *     }
     *     if (cityCode != null) {
     *         coachQuery.setCity(cityCode.getName());
     *     } else {
     *         coachQuery.setCity(city);
     *     }
     *     coachQuery.setName(name);
     *     coachQuery.setPhone(phone);
     *     coachQuery.setTime(time);
     *     coachQuery.setType(type);
     *     return financeClient.rechargeList(coachQuery);
     * }
     *
     * @RequestMapping(value = "/getAmount")
     * @ResponseBody
     * public BigDecimal getAmount(String province, String city, String name, String phone, String time, Integer type) {
     *     RechargeRecordsQuery coachQuery = new RechargeRecordsQuery();
     *     coachQuery.setProvince(province);
     *     coachQuery.setCity(city);
     *     coachQuery.setName(name);
     *     coachQuery.setPhone(phone);
     *     coachQuery.setTime(time);
     *     coachQuery.setType(type);
     *     List<RechargeRecordsVO> rechargeRecordsVOS = financeClient.rechargeList(coachQuery);
     *     BigDecimal total = new BigDecimal("0.00");
     *     for (RechargeRecordsVO rechargeRecordsVO : rechargeRecordsVOS) {
     *         total = total.add(rechargeRecordsVO.getAmount());
     *     }
     *     return total;
     * }
     */
    @RequestMapping("/rechargeRecords")
    public String index(Model model) {
        List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        model.addAttribute("list",list);
        Integer objectType = UserExt.getUser().getObjectType();
        Integer objectId = UserExt.getUser().getObjectId();
        model.addAttribute("userType",objectType);
        String roleid = UserExt.getUser().getRoleid();
        model.addAttribute("objectType",objectType);
        return PREFIX + "RechargeRecords.html";
    }
    /**
     * 获取充值记录
     */
    @RequestMapping(value = "/listAll")
    @ResponseBody
    public List<RechargeRecordsVO> list(String province, String city, String name, String phone,String time,Integer type) {
        RechargeRecordsQuery coachQuery = new RechargeRecordsQuery();
        Region provinceCode = regionService.getOne(new QueryWrapper<Region>().eq("code", province));
        Region cityCode = regionService.getOne(new QueryWrapper<Region>().eq("code", city));
        if (provinceCode!=null){
            coachQuery.setProvince(provinceCode.getName());
        }else{
            coachQuery.setProvince(province);
        }
        if (cityCode!=null){
            coachQuery.setCity(cityCode.getName());
        }else{
            coachQuery.setCity(city);
        }
        coachQuery.setName(name);
        coachQuery.setPhone(phone);
        coachQuery.setTime(time);
        coachQuery.setType(type);
        return financeClient.rechargeList(coachQuery);
    }
    /**
     * 获取充值记录
     */
    @RequestMapping(value = "/getAmount")
    /** 充值记录功能已下线,避免通过历史菜单或直接 URL 继续访问。 */
    @RequestMapping({"/rechargeRecords", "/listAll", "/getAmount"})
    @ResponseBody
    public BigDecimal getAmount(String province, String city, String name, String phone, String time, Integer type) {
        RechargeRecordsQuery coachQuery = new RechargeRecordsQuery();
        coachQuery.setProvince(province);
        coachQuery.setCity(city);
        coachQuery.setName(name);
        coachQuery.setPhone(phone);
        coachQuery.setTime(time);
        coachQuery.setType(type);
        List<RechargeRecordsVO> rechargeRecordsVOS = financeClient.rechargeList(coachQuery);
        BigDecimal total = new BigDecimal("0.00");
        BigDecimal result = new BigDecimal("0.00");
        for (RechargeRecordsVO rechargeRecordsVO : rechargeRecordsVOS) {
            BigDecimal amount = rechargeRecordsVO.getAmount();
            total = total.add(amount); // 将新的值赋给total
            result = result.add(amount); // 将新的值赋给result
        }
        return total;
    public ResultUtil rechargeRecordsUnavailable() {
        return ResultUtil.error("充值记录功能暂不提供");
    }
    /**
     * 获取报名订单统计数据
@@ -304,8 +305,12 @@
            List<Integer> operatorId = storeService.list(new QueryWrapper<TStore>()
                    .eq("operatorId", UserExt.getUser().getObjectId())).stream()
                    .map(TStore::getId).collect(Collectors.toList());
            if (operatorId.isEmpty()){
                operatorId.add(0);
            }
            query.setStoresIds(operatorId);
            competitionQuery.setOperatorId(UserExt.getUser().getObjectId());
            siteBookingQuery.setStoreIds(operatorId);
        }
        if (UserExt.getUser().getObjectType()==3){
@@ -335,6 +340,7 @@
                    TAppUser tAppUser = appUserClient.queryById(vipPayment.getAppUserId());
                    IncomeVO temp = new IncomeVO();
                    temp.setId(vipPayment.getId().toString());
                    temp.setAppUserId(vipPayment.getAppUserId());
                    if (tAppUser!=null){
                        if (tAppUser.getProvince()!=null){
                            temp.setProvince(tAppUser.getProvince());
@@ -348,7 +354,7 @@
                    temp.setStoreName("");
                    temp.setAmount(new BigDecimal(vipPayment.getAmount().toString()));
                    temp.setIncomeType(1);
                    temp.setState(vipPayment.getState());
                    temp.setState(2);
                    temp.setInsertTime(vipPayment.getInsertTime());
                    if (UserExt.getUser().getObjectType()!=1){
                        break;
@@ -366,6 +372,7 @@
                    TAppUser tAppUser = appUserClient.queryById(rechargeRecordsVO.getAppUserId());
                    IncomeVO temp = new IncomeVO();
                    temp.setId(rechargeRecordsVO.getId().toString());
                    temp.setAppUserId(rechargeRecordsVO.getAppUserId());
                    if (tAppUser!=null){
                        if (tAppUser.getProvince()!=null){
                            temp.setProvince(tAppUser.getProvince());
@@ -382,7 +389,7 @@
                        temp.setAmount(rechargeRecordsVO.getAmount());
                    }
                    temp.setIncomeType(2);
                    temp.setState(rechargeRecordsVO.getPayStatus());
                    temp.setState(2);
                    incomeVOS.add(temp);
                }
@@ -397,6 +404,7 @@
                    TAppUser tAppUser = appUserClient.queryById(registerOrderVO.getAppUserId());
                    IncomeVO temp = new IncomeVO();
                    temp.setId(registerOrderVO.getId().toString());
                    temp.setAppUserId(registerOrderVO.getAppUserId());
                    if (tAppUser!=null){
                        if (tAppUser.getProvince()!=null){
                            temp.setProvince(tAppUser.getProvince());
@@ -415,12 +423,9 @@
                        temp.setAmount(registerOrderVO.getMoney());
                    }
                    temp.setIncomeType(3);
                    if (registerOrderVO.getPayStatus() == 1){
                        temp.setState(2);
                    }
                    if (registerOrderVO.getPayStatus() == 2){
                        temp.setState(1);
                    }
                    incomeVOS.add(temp);
                }
            }
@@ -438,8 +443,9 @@
                        if(null == competition1){
                            continue;
                        }
                        if (!competition1.getStoreId().equals("")){
                            String[] split = competition1.getStoreId().split(",");
                        String competitionStoreIds = resolveCompetitionStoreIds(competition, competition1);
                        if (ToolUtil.isNotEmpty(competitionStoreIds)){
                            String[] split = competitionStoreIds.split(",");
                            List<Integer> list = new ArrayList<>();
                            for (String s : split) {
                                list.add(Integer.valueOf(s));
@@ -455,6 +461,7 @@
                            temp.setStoreName(substring);
                        }
                        temp.setId(competition.getId().toString());
                        temp.setAppUserId(competition.getAppUserId());
                        if (tAppUser!=null){
                            if (tAppUser.getProvince()!=null){
                                temp.setProvince(tAppUser.getProvince());
@@ -470,11 +477,9 @@
                            temp.setAmount(new BigDecimal(competition.getAmount().toString()));
                        }
                        temp.setIncomeType(4);
                        if (competition.getPayStatus() == 1){
                            temp.setState(2);
                        }else if (competition.getPayStatus() == 2){
                            temp.setState(1);
                        }
                        incomeVOS.add(temp);
                    }
                }
@@ -484,15 +489,14 @@
                List<SiteBooking> siteBookings = siteClient.listAll(siteBookingQuery);
                for (SiteBooking siteBooking : siteBookings) {
                    IncomeVO temp = new IncomeVO();
                    if (siteBooking.getStatus() == 0 || siteBooking.getStatus() == 5 || siteBooking.getStatus() == 4) {
                        temp.setState(1);
                    } else {
                        temp.setState(2);
                    }
                    TAppUser tAppUser = appUserClient.queryAppUser1(siteBooking.getAppUserId());
                    Store store = storeClient.getStoreById(siteBooking.getStoreId());
                    temp.setId(siteBooking.getId().toString());
                    temp.setAppUserId(siteBooking.getAppUserId());
                    temp.setProvince(siteBooking.getProvince());
                    temp.setCity(siteBooking.getCity());
                    temp.setStoreName(store.getName());
@@ -529,11 +533,16 @@
                    temp.setPhone(worldCupIncomeVO.getPhone());
                    temp.setAmount(new BigDecimal(worldCupIncomeVO.getAmount()));
                    temp.setIncomeType(6);
                    temp.setState(1);
                    temp.setState(2);
                    temp.setInsertTime(simpleDateFormat.parse(worldCupIncomeVO.getPayTime()));
                    incomeVOS.add(temp);
                }
            }
        // 推荐:一行代码解决
        incomeVOS.sort(Comparator.comparing(
                IncomeVO::getInsertTime,
                Comparator.nullsLast(Comparator.reverseOrder())
        ));
        return incomeVOS;
    }
@@ -637,7 +646,7 @@
                temp.setStoreName("");
                temp.setAmount(new BigDecimal(vipPayment.getAmount().toString()));
                temp.setIncomeType(1);
                temp.setState(vipPayment.getState());
                temp.setState(2);
                temp.setInsertTime(vipPayment.getInsertTime());
                if (UserExt.getUser().getObjectType()!=1){
                    break;
@@ -671,8 +680,7 @@
                    temp.setAmount(rechargeRecordsVO.getAmount());
                }
                temp.setIncomeType(2);
                temp.setState(rechargeRecordsVO.getPayStatus());
                temp.setState(2);
                incomeVOS.add(temp);
            }
        }
@@ -686,11 +694,9 @@
                TAppUser tAppUser = appUserClient.queryById(registerOrderVO.getAppUserId());
                IncomeVO temp = new IncomeVO();
                temp.setId(registerOrderVO.getId().toString());
                if (registerOrderVO.getPayStatus()==2) {
                    temp.setState(2);
                } else {
                    temp.setState(1);
                }
                temp.setState(2);
                if (tAppUser!=null){
                    if (tAppUser.getProvince()!=null){
                        temp.setProvince(tAppUser.getProvince());
@@ -709,7 +715,7 @@
                    temp.setAmount(registerOrderVO.getMoney());
                }
                temp.setIncomeType(3);
                temp.setState(registerOrderVO.getPayStatus());
                temp.setState(2);
                incomeVOS.add(temp);
            }
        }
@@ -726,8 +732,9 @@
                    if(null == competition1){
                        continue;
                    }
                    if (!competition1.getStoreId().equals("")){
                        String[] split = competition1.getStoreId().split(",");
                    String competitionStoreIds = resolveCompetitionStoreIds(competition, competition1);
                    if (ToolUtil.isNotEmpty(competitionStoreIds)){
                        String[] split = competitionStoreIds.split(",");
                        List<Integer> list = new ArrayList<>();
                        for (String s : split) {
                            list.add(Integer.valueOf(s));
@@ -742,11 +749,9 @@
                        temp.setStoreName(substring);
                    }
                    if (competition.getPayStatus()==2) {
                        temp.setState(2);
                    } else {
                        temp.setState(1);
                    }
                    temp.setId(competition.getId().toString());
                    if (tAppUser!=null){
                        if (tAppUser.getProvince()!=null){
@@ -763,7 +768,7 @@
                        temp.setAmount(new BigDecimal(competition.getAmount().toString()));
                    }
                    temp.setIncomeType(4);
                    temp.setState(competition.getPayStatus());
                    temp.setState(2);
                    incomeVOS.add(temp);
                }
            }
@@ -772,11 +777,7 @@
            List<SiteBooking> siteBookings = siteClient.listAll(siteBookingQuery);
            for (SiteBooking siteBooking : siteBookings) {
                IncomeVO temp = new IncomeVO();
                if (siteBooking.getStatus() == 0 || siteBooking.getStatus() == 5 || siteBooking.getStatus() == 4) {
                    temp.setState(1);
                } else {
                    temp.setState(2);
                }
                temp.setState(2);
                TAppUser tAppUser = appUserClient.queryAppUser1(siteBooking.getAppUserId());
                Store store = storeClient.getStoreById(siteBooking.getStoreId());
@@ -816,7 +817,7 @@
                temp.setPhone(worldCupIncomeVO.getPhone());
                temp.setAmount(new BigDecimal(worldCupIncomeVO.getAmount()));
                temp.setIncomeType(6);
                temp.setState(1);
                temp.setState(2);
                temp.setInsertTime(simpleDateFormat.parse(worldCupIncomeVO.getPayTime()));
                incomeVOS.add(temp);
            }
@@ -904,10 +905,19 @@
        return coursePackagePaymentClient.listAllRegister(query);
    }
    /**
     * 获取收入记录对应的门店归属;新订单使用下单快照,兼容未回填的历史订单。
     *
     * @param paymentCompetition 活动支付记录
     * @param competition 活动当前信息
     * @return 逗号分隔的门店 ID 列表
     */
    private String resolveCompetitionStoreIds(PaymentCompetition paymentCompetition, Competition competition) {
        if (ToolUtil.isNotEmpty(paymentCompetition.getCompetitionStoreIds())) {
            return paymentCompetition.getCompetitionStoreIds();
        }
        return competition.getStoreId();
    }
}