Pu Zhibing
2025-01-22 2f30ea680b7867cc42681d8eff7b55f5fdf15201
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingBillServiceImpl.java
@@ -7,6 +7,7 @@
import com.ruoyi.chargingPile.api.dto.GetSiteListDTO;
import com.ruoyi.chargingPile.api.feignClient.ChargingGunClient;
import com.ruoyi.chargingPile.api.feignClient.ChargingPileClient;
import com.ruoyi.chargingPile.api.feignClient.PartnerClient;
import com.ruoyi.chargingPile.api.feignClient.SiteClient;
import com.ruoyi.chargingPile.api.model.Site;
import com.ruoyi.chargingPile.api.model.TChargingGun;
@@ -78,6 +79,8 @@
    private TChargingOrderRefundService chargingOrderRefundService;
    @Resource
    private TokenService tokenService;
    @Resource
    private PartnerClient partnerClient;
    @Override
@@ -99,12 +102,10 @@
            startTime2 = split[1];
        }
        Long userId = tokenService.getLoginUser().getUserid();
        // 查询当前登陆人按钮权限
        SysUser sysUser = sysUserClient.getSysUser(tokenService.getLoginUser().getUserid()).getData();
        Integer roleType = sysUser.getRoleType();
        List<Integer> siteIds = new ArrayList<>();
        if (dto.getType() == 1){
            siteIds.add(0);
            dto.setSiteIds(siteIds);
        }else{
            //如果没传siteId,获取当前登陆人所有的siteIds
            if (dto.getSiteId()==null){
                if (userId != null){
@@ -118,9 +119,24 @@
            }
            if (siteIds.isEmpty()){
                siteIds.add(-1);
            }else{
                if (roleType == 2){
                    List<Integer> integers = new ArrayList<>();
                    for (Integer siteId : siteIds) {
                        // 校验有没有这个站点的权限
                        List<Boolean> t1= partnerClient.getAccountMenu(sysUser.getObjectId(),siteId).getData();
                        Boolean b = t1.get(1);
                        if (b){
                            integers.add(siteId);
                        }
                    }
                    siteIds = integers;
                }
            }
            if (siteIds.isEmpty())siteIds.add(-1);
            dto.setSiteIds(siteIds);
        }
        PageInfo<ChargingBillListVO> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize());
        PageInfo<ChargingBillListVO> pageInfo1 = new PageInfo<>(1,9999999);
@@ -137,7 +153,15 @@
        BigDecimal chargingCapacityTotal = new BigDecimal("0");
        BigDecimal discountTotal = new BigDecimal("0");
        int orderCount = 0;
        for (ChargingBillListVO chargingBillListVO : list) {
            if (roleType==2){
                List<Boolean> data = partnerClient.getAccountMenu(sysUser.getObjectId(), chargingBillListVO.getSiteId()).getData();
                chargingBillListVO.setAuthDownLoad(data.get(0));
                if (chargingBillListVO.getType()==1){
                    continue;
                }
            }
            String temp = "";
            String temp1 = "";
            switch (chargingBillListVO.getType()){
@@ -164,22 +188,18 @@
            chargingBillListVO.setUid(chargingBillListVO.getId().toString());
            // 根据账单的出账时间 查询上个月的充电订单
//            LocalDateTime localDate = chargingBillListVO.getBillTime().minusMonths(1);
            // todo 临时修改为查询昨天的充电订单
            LocalDateTime localDate = chargingBillListVO.getBillTime().minusDays(1);
            LocalDateTime localDate = chargingBillListVO.getBillTime().minusMonths(1);
//            LocalDateTime localDate = chargingBillListVO.getBillTime().minusDays(1);
            // 账单周期
            chargingBillListVO.setBillWeek(localDate.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM")));
            // 获取 LocalDate 对象
            LocalDate date = localDate.toLocalDate();
//            // 获取该月份的第一天
//            LocalDate firstDayOfMonth = date.withDayOfMonth(1);
//            // 获取该月份的最后一天
//            LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
            // todo 临时修改为查询昨天凌晨00:00:00 到 23:59:59
            LocalDateTime firstDayOfMonth = LocalDateTime.of(date, LocalTime.MIN);
            LocalDateTime lastDayOfMonth = LocalDateTime.of(date, LocalTime.MAX);
            LocalDate firstDayOfMonth = date.withDayOfMonth(1);
            // 获取该月份的最后一天
            LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
            QueryWrapper<TChargingOrder> eq = new QueryWrapper<TChargingOrder>()
                    .between("create_time", firstDayOfMonth, lastDayOfMonth)
                    .between("pay_time", firstDayOfMonth.atTime(0, 0, 0), lastDayOfMonth.atTime(23, 59, 59))
                    .eq("status", 5)
                    .eq("recharge_payment_status", 2);
            if (chargingBillListVO.getType() == 2) {
@@ -379,7 +399,10 @@
        BigDecimal bigDecimal = new BigDecimal("0");
        int i = 0;
        for (ChargingBillListVO chargingBillListVO : list1) {
            if (!siteIds.contains(chargingBillListVO.getSiteId())){
            if (chargingBillListVO.getSiteId()!=0&&!siteIds.contains(chargingBillListVO.getSiteId())){
                continue;
            }
            if (chargingBillListVO.getType()==1){
                continue;
            }
            i++;
@@ -390,20 +413,15 @@
            chargingBillVO.setBillWeek(billTime.minusMonths(1).format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM")));
            chargingBillListVO.setUid(chargingBillListVO.getId().toString());
//            LocalDateTime localDate = chargingBillListVO.getBillTime().minusMonths(1);
            // todo 临时修改为查询昨天的充电订单
            LocalDateTime localDate = chargingBillListVO.getBillTime().minusDays(1);
            LocalDateTime localDate = chargingBillListVO.getBillTime().minusMonths(1);
            // 账单周期
            chargingBillListVO.setBillWeek(localDate.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM")));
            // 获取 LocalDate 对象
            LocalDate date = localDate.toLocalDate();
//            // 获取该月份的第一天
//            LocalDate firstDayOfMonth = date.withDayOfMonth(1);
//            // 获取该月份的最后一天
//            LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
            // todo 临时修改为查询昨天凌晨00:00:00 到 23:59:59
            LocalDateTime firstDayOfMonth = LocalDateTime.of(date, LocalTime.MIN);
            LocalDateTime lastDayOfMonth = LocalDateTime.of(date, LocalTime.MAX);
            // 获取该月份的第一天
            LocalDate firstDayOfMonth = date.withDayOfMonth(1);
            // 获取该月份的最后一天
            LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
            QueryWrapper<TChargingOrder> eq = new QueryWrapper<TChargingOrder>()
                    .between("create_time", firstDayOfMonth, lastDayOfMonth)
                    .eq("status", 5)
@@ -487,6 +505,7 @@
        return chargingBillVO;
    }
    @Override
    public ChargingBillVO chargingBillList(ChargingListQuery dto) {
        if (dto.getState()!=null){
@@ -507,12 +526,11 @@
        PageInfo<ChargingBillListVO> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize());
        PageInfo<ChargingBillListVO> pageInfo1 = new PageInfo<>(1,9999999);
        Long userId = tokenService.getLoginUser().getUserid();
        // 查询当前登陆人按钮权限
        SysUser sysUser = sysUserClient.getSysUser(tokenService.getLoginUser().getUserid()).getData();
        Integer roleType = sysUser.getRoleType();
        //如果没传siteId,获取当前登陆人所有的siteIds
        List<Integer> siteIds = new ArrayList<>();
        if (dto.getType() == 1){
            siteIds.add(0);
            dto.setSiteIds(siteIds);
        }else{
            //如果没传siteId,获取当前登陆人所有的siteIds
            if (dto.getSiteId()==null){
                if (userId != null){
@@ -526,9 +544,30 @@
            }
            if (siteIds.isEmpty()){
                siteIds.add(-1);
            }else{
                if (roleType == 2){
                    List<Integer> integers = new ArrayList<>();
                    for (Integer siteId : siteIds) {
                        // 校验有没有这个站点的权限
                        List<Boolean> t1= partnerClient.getChargingBillMenu(sysUser.getObjectId(),siteId).getData();
                        Boolean b = t1.get(1);
                        if (b){
                            integers.add(siteId);
                        }
                    }
                    siteIds = integers;
                }
            }
            dto.setSiteIds(siteIds);
        if (roleType==1){
            siteIds.add(0);
        }
        if (siteIds.isEmpty()){
            siteIds.add(-1);
        }
            dto.setSiteIds(siteIds);
        List<ChargingBillListVO> list = this.baseMapper.chargingBillList(pageInfo,dto,startTime1,startTime2);
        List<ChargingBillListVO> list1 = this.baseMapper.chargingBillList(pageInfo1,dto,startTime1,startTime2);
        BigDecimal paymentAmountTotal = new BigDecimal("0");
@@ -541,15 +580,29 @@
        BigDecimal discountTotal = new BigDecimal("0");
        BigDecimal refundAmountTotal = new BigDecimal("0");
        int orderCount = 0;
        // 查询当前登陆人按钮权限
        SysUser sysUser = sysUserClient.getSysUser(tokenService.getLoginUser().getUserid()).getData();
        Integer roleType = sysUser.getRoleType();
        Integer objectId = sysUser.getObjectId();
        R<Integer> admin = sysUserClient.isAdmin(tokenService.getLoginUser().getUserid());
        if(roleType == 2){
            // 合作商 判断有没有这个站点的按钮权限
        }
        List<ChargingBillListVO> chargingBillListVOS = new ArrayList<>();
        for (ChargingBillListVO chargingBillListVO : list) {
            if (roleType==2 && chargingBillListVO.getSiteId()!=0){
                chargingBillListVOS.add(chargingBillListVO);
            }
            if (roleType ==1 && (siteIds.contains(chargingBillListVO.getSiteId())|| chargingBillListVO.getSiteId()==0)){
                chargingBillListVOS.add(chargingBillListVO);
            }
        }
        for (ChargingBillListVO chargingBillListVO : chargingBillListVOS) {
            if (chargingBillListVO.getSiteId()!=0&&!siteIds.contains(chargingBillListVO.getSiteId())){
                continue;
            }
            if (roleType == 2){
                // 校验有没有这个站点的权限
                List<Boolean> t1= partnerClient.getChargingBillMenu(sysUser.getObjectId(),chargingBillListVO.getSiteId()).getData();
                chargingBillListVO.setAuthDownLoad(t1.get(0));
                if (chargingBillListVO.getSiteId()==0){
                    continue;
                }
            }
            String temp = "";
            String temp1 = "";
            switch (chargingBillListVO.getType()){
@@ -576,22 +629,18 @@
            chargingBillListVO.setUid(chargingBillListVO.getId().toString());
            // 根据账单的出账时间 查询上个月的充电订单
//            LocalDateTime localDate = chargingBillListVO.getBillTime().minusMonths(1);
            // todo 临时修改为查询昨天的充电订单
            LocalDateTime localDate = chargingBillListVO.getBillTime().minusDays(1);
            LocalDateTime localDate = chargingBillListVO.getBillTime().minusMonths(1);
//            LocalDateTime localDate = chargingBillListVO.getBillTime().minusDays(1);
            // 账单周期
            chargingBillListVO.setBillWeek(localDate.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM")));
            // 获取 LocalDate 对象
            LocalDate date = localDate.toLocalDate();
//            // 获取该月份的第一天
//            LocalDate firstDayOfMonth = date.withDayOfMonth(1);
//            // 获取该月份的最后一天
//            LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
            // todo 临时修改为查询昨天凌晨00:00:00 到 23:59:59
            LocalDateTime firstDayOfMonth = LocalDateTime.of(date, LocalTime.MIN);
            LocalDateTime lastDayOfMonth = LocalDateTime.of(date, LocalTime.MAX);
            LocalDate firstDayOfMonth = date.withDayOfMonth(1);
            // 获取该月份的最后一天
            LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
            QueryWrapper<TChargingOrder> eq = new QueryWrapper<TChargingOrder>()
                    .between("create_time", firstDayOfMonth, lastDayOfMonth)
                    .between("pay_time", firstDayOfMonth.atTime(0, 0, 0), lastDayOfMonth.atTime(23, 59, 59))
                    .eq("status", 5)
                    .eq("recharge_payment_status", 2);
            if (chargingBillListVO.getType() == 2) {
@@ -773,8 +822,13 @@
            chargingBillListVO.setChargingSecond(chargingSecond);
        }
        for (ChargingBillListVO chargingBillListVO : list1) {
            if (!siteIds.contains(chargingBillListVO.getSiteId())){
            if (chargingBillListVO.getSiteId()!=0&&!siteIds.contains(chargingBillListVO.getSiteId())){
                continue;
            }
            if (roleType == 2){
                if (chargingBillListVO.getSiteId()==0){
                    continue;
                }
            }
            LocalDateTime billTime = chargingBillListVO.getBillTime();
            // 将其转化为yyyy-MM格式字符串
@@ -784,20 +838,18 @@
            chargingBillListVO.setUid(chargingBillListVO.getId().toString());
            // 根据账单的出账时间 查询上个月的充电订单
//            LocalDateTime localDate = chargingBillListVO.getBillTime().minusMonths(1);
            // todo 临时修改为查询昨天的充电订单
            LocalDateTime localDate = chargingBillListVO.getBillTime().minusDays(1);
            LocalDateTime localDate = chargingBillListVO.getBillTime().minusMonths(1);
//            LocalDateTime localDate = chargingBillListVO.getBillTime().minusDays(1);
            // 账单周期
            chargingBillListVO.setBillWeek(localDate.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM")));
            // 获取 LocalDate 对象
            LocalDate date = localDate.toLocalDate();
//            // 获取该月份的第一天
//            LocalDate firstDayOfMonth = date.withDayOfMonth(1);
//            // 获取该月份的最后一天
//            LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
            // todo 临时修改为查询昨天凌晨00:00:00 到 23:59:59
            LocalDateTime firstDayOfMonth = LocalDateTime.of(date, LocalTime.MIN);
            LocalDateTime lastDayOfMonth = LocalDateTime.of(date, LocalTime.MAX);
            LocalDate firstDayOfMonth = date.withDayOfMonth(1);
            // 获取该月份的最后一天
            LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
//            LocalDateTime firstDayOfMonth = LocalDateTime.of(date, LocalTime.MIN);
//            LocalDateTime lastDayOfMonth = LocalDateTime.of(date, LocalTime.MAX);
            QueryWrapper<TChargingOrder> eq = new QueryWrapper<TChargingOrder>()
                    .between("create_time", firstDayOfMonth, lastDayOfMonth)
                    .eq("status", 5)
@@ -873,17 +925,21 @@
        chargingBillVO.setCommissionAmount(commissionAmountTotal.setScale(2, BigDecimal.ROUND_DOWN));
        chargingBillVO.setSharingAmount(sharingAmountTotal.setScale(2, BigDecimal.ROUND_DOWN));
        chargingBillVO.setDiscount(discountTotal.setScale(2, BigDecimal.ROUND_DOWN));
        pageInfo.setRecords(list);
        pageInfo.setRecords(chargingBillListVOS);
        chargingBillVO.setList(pageInfo);
        return chargingBillVO;
    }
    public static void main(String[] args) {
        int i = 8 % 20;
        System.err.println(i);
        LocalDateTime now = LocalDateTime.now();
        // 将时间转化为字符串 只保留年月日 格式为yyyy-MM-dd
        String format = now.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(1);
        // 获取 LocalDate 对象
        LocalDate date = localDateTime.toLocalDate();
//            // 获取该月份的第一天
        LocalDate firstDayOfMonth = date.withDayOfMonth(1);
        // 获取该月份的最后一天
        LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
        System.err.println(firstDayOfMonth);
        System.err.println(lastDayOfMonth);
    }
}