xuhy
2024-12-13 a50c7d1497d7f707b79597553d9db978ba7e9dd5
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TIndexMenuController.java
@@ -19,8 +19,10 @@
import oshi.driver.mac.net.NetStat;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
 * <p>
@@ -80,19 +82,16 @@
    public R getByProvinceName() {
        List<TRegion> list1 = regionService.lambdaQuery().groupBy(TRegion::getProvinceName).list();
        for (TRegion tRegion : list1) {
        List<TRegion> list = regionService.lambdaQuery().eq(TRegion::getProvinceName, tRegion.getProvinceName()).list();
        List<Integer> regionIds = new ArrayList<>();
        list.forEach(region -> regionIds.add(region.getId()));
        if (!regionIds.isEmpty()) {
            Long count = consultationService.lambdaQuery().in(TConsultation::getRegionId, regionIds).count();
            tRegion.setCount(count);
        }else {
            tRegion.setCount(0L);
        }
            List<TRegion> list = regionService.lambdaQuery().eq(TRegion::getProvinceName, tRegion.getProvinceName()).list();
            List<Integer> regionIds = new ArrayList<>();
            list.forEach(region -> regionIds.add(region.getId()));
            if (!regionIds.isEmpty()) {
                Long count = consultationService.lambdaQuery().in(TConsultation::getRegionId, regionIds)
                        .in(TConsultation::getClassificationId,Arrays.asList(1,2,3)).count();
                tRegion.setCount(count);
            }else {
                tRegion.setCount(0L);
            }
        }
        return R.ok(list1);
@@ -133,22 +132,51 @@
        Long userId = tokenService.getLoginUser().getUserId();
        TUserChange one = changeService.lambdaQuery().eq(TUserChange::getUserId, userId).orderByDesc(TUserChange::getCreateTime).last("limit 1").one();
        List<TConsultation> notices = new ArrayList<>();
        if (one!=null){
            List<TUserChangeDetail> list = changeDetailService.lambdaQuery().eq(TUserChangeDetail::getChangeId, one.getId()).list();
            for (TUserChangeDetail tUserChangeDetail : list) {
                List<TConsultation> list1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId,type).eq(TConsultation::getRegionId,tUserChangeDetail.getRegionId()).eq(TConsultation::getMajorId, tUserChangeDetail.getMajorId()).eq(TConsultation::getLevel, tUserChangeDetail.getLevelId()).list();
                notices.addAll(list1);
            }
            notices.sort(Comparator.comparing(TConsultation::getCreateTime).reversed());
        }else {
            // 创建 LambdaQueryWrapper 并设置查询条件
        }
        List<TConsultation> list1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId,type).last("ORDER BY RAND() LIMIT 16").list();
        notices.addAll(list1);
        if (notices.size() > 16) {
            // 只保留前 16 条记录
            notices = new ArrayList<>(notices.subList(0, 16));
        if (type==1){
            if (one!=null){
                List<TUserChangeDetail> list = changeDetailService.lambdaQuery().eq(TUserChangeDetail::getChangeId, one.getId()).list();
                for (TUserChangeDetail tUserChangeDetail : list) {
                    List<TConsultation> list1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId,type)
                            .eq(TConsultation::getRegionId,tUserChangeDetail.getRegionId())
                            .eq(TConsultation::getMajorId, tUserChangeDetail.getMajorId())
                            .eq(TConsultation::getLevel, tUserChangeDetail.getLevelId())
                            .eq(TConsultation::getIsRecommend,1)
                            .orderByDesc(TConsultation::getClassificationSort,TConsultation::getCreateTime).list();
                    notices.addAll(list1);
                }
                notices.sort(Comparator.comparing(TConsultation::getCreateTime).reversed());
            }else {
                // 创建 LambdaQueryWrapper 并设置查询条件
            }
            List<TConsultation> list1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId,type).eq(TConsultation::getIsRecommend,1).last("ORDER BY RAND() LIMIT 16").list();
            notices.addAll(list1);
            if (notices.size() > 16) {
                // 只保留前 16 条记录
                notices = new ArrayList<>(notices.subList(0, 16));
            }
        }else {
            if (one!=null){
                List<TUserChangeDetail> list = changeDetailService.lambdaQuery().eq(TUserChangeDetail::getChangeId, one.getId()).list();
                for (TUserChangeDetail tUserChangeDetail : list) {
                    List<TConsultation> list1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId,type)
                            .eq(TConsultation::getRegionId,tUserChangeDetail.getRegionId())
                            .eq(TConsultation::getMajorId, tUserChangeDetail.getMajorId())
                            .eq(TConsultation::getLevel, tUserChangeDetail.getLevelId()).list();
                    notices.addAll(list1);
                }
                notices.sort(Comparator.comparing(TConsultation::getCreateTime).reversed());
            }else {
                // 创建 LambdaQueryWrapper 并设置查询条件
            }
            List<TConsultation> list1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId,type).last("ORDER BY RAND() LIMIT 16").list();
            notices.addAll(list1);
            if (notices.size() > 16) {
                // 只保留前 16 条记录
                notices = new ArrayList<>(notices.subList(0, 16));
            }
        }
        return R.ok(notices);
    }
@@ -185,13 +213,21 @@
    @PostMapping(value = "/allert")
    public R allert() {
        Long userId = tokenService.getLoginUser().getUserId();
        Object cacheObject = redisCache.getCacheObject("ALLERT:"+userId);
        if (cacheObject!=null){
            return R.ok(cacheObject);
        TAppUser byId = appUserService.getById(userId);
        Long cacheObject = redisCache.getCacheObject("ALLERT:"+userId);
        if (cacheObject!=null && byId.getIsSetPreference() == 1){
            return R.ok(cacheObject == 1);
        }else {
            return R.ok(false);
        }
    }
    @ApiOperation(value = "取消顶部提示",tags = {"web-取消顶部提示"})
    @PostMapping(value = "/cancelAllert")
    public R cancelAllert() {
        Long userId = tokenService.getLoginUser().getUserId();
        redisCache.deleteObject("ALLERT:"+userId);
        return R.ok();
    }
@@ -204,7 +240,7 @@
        Long payCount = courseCount -courseFreeCount;
        Long recordsCount = generatedRecordsService.lambdaQuery().count();
        Long infoCount = informationService.lambdaQuery().count();
        Long infoFreeCount = informationService.lambdaQuery().count();
        Long infoFreeCount = informationService.lambdaQuery().eq(TInformation::getInformationPrice,new BigDecimal(0)).count();
        Long infoPayCount = infoCount-infoFreeCount;
        ManageCountDto manageCountDto = new ManageCountDto();
        manageCountDto.setUserCount(userCount);
@@ -214,6 +250,7 @@
        manageCountDto.setRecordsCount(recordsCount);
        manageCountDto.setInfoFreeCount(infoFreeCount);
        manageCountDto.setInfoPayCount(infoPayCount);
        manageCountDto.setInfoCount(infoCount);
        return R.ok(manageCountDto);
    }
@@ -246,9 +283,7 @@
    @ApiOperation(value = "订单统计1",tags = {"后台-统计"})
    @PostMapping(value = "/order/count1")
    public R<List<Map<String,String>>> ordercount1(@RequestBody OrderCountQuery orderCountQuery) {
        List<Map<String,String>> map = new ArrayList<>();
            map = indexMenuService.count1(orderCountQuery.getStartDate(),orderCountQuery.getEndDate(),orderCountQuery.getPaymentStatus(),orderCountQuery.getDayType());
        List<Map<String,String>> map = indexMenuService.count1(orderCountQuery.getStartDate(),orderCountQuery.getEndDate(),orderCountQuery.getPaymentStatus(),orderCountQuery.getDayType());
        return R.ok(map);
    }
@@ -277,6 +312,11 @@
            // 只保留前 16 条记录
            notices = new ArrayList<>(notices.subList(0, 16));
        }
        notices = notices.stream().distinct().collect(Collectors.toList());
        Set<Long> cacheSet = redisCache.getCacheSet("INFORMATION:" + userId);
        for (TInformation notice : notices) {
            notice.setIsCollect(cacheSet.contains(notice.getId())?1:0);
        }
        return R.ok(notices);
    }