xuhy
2024-12-13 b5bab032e80f0233fdf06a4e8de2599bc6b65e47
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TIndexMenuController.java
@@ -19,6 +19,7 @@
import oshi.driver.mac.net.NetStat;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
@@ -127,10 +128,14 @@
    @ApiOperation(value = "定制推荐-2政策3公示",tags = {"web-首页"})
    @PostMapping(value = "/consultation/list")
    public R<List<TConsultation>> consultationlist(@RequestParam Integer type) {
        //获取当前登录人id
        Long userId = tokenService.getLoginUser().getUserId();
        TUserChange one = changeService.lambdaQuery().eq(TUserChange::getUserId, userId).orderByDesc(TUserChange::getCreateTime).last("limit 1").one();
    public R<List<TConsultation>> consultationlist(@RequestParam Integer type, @RequestParam(required = false) Integer regionId, HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        TUserChange one =null;
        if(StringUtils.isNotEmpty(token)){
            //获取当前登录人id
            Long userId = tokenService.getLoginUser().getUserId();
            one = changeService.lambdaQuery().eq(TUserChange::getUserId, userId).orderByDesc(TUserChange::getCreateTime).last("limit 1").one();
        }
        List<TConsultation> notices = new ArrayList<>();
        if (type==1){
@@ -141,20 +146,27 @@
                            .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 并设置查询条件
                TRegion region = regionService.getById(regionId);
                List<TRegion> regions = regionService.list(Wrappers.lambdaQuery(TRegion.class)
                        .eq(TRegion::getProvinceName, region.getProvinceName()));
                List<Integer> regionIds = regions.stream().map(TRegion::getId).collect(Collectors.toList());
                List<TConsultation> list1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId,type)
                        .in(TConsultation::getRegionId,regionIds)
                        .orderByDesc(TConsultation::getCreateTime,TConsultation::getClassificationSort).list();
                notices.addAll(list1);
                notices.sort(Comparator.comparing(TConsultation::getCreateTime).reversed());
            }
            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) {
//            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() > 2) {
                // 只保留前 16 条记录
                notices = new ArrayList<>(notices.subList(0, 16));
                notices = new ArrayList<>(notices.subList(0, 2));
            }
        }else {
            if (one!=null){
@@ -169,13 +181,21 @@
                notices.sort(Comparator.comparing(TConsultation::getCreateTime).reversed());
            }else {
                // 创建 LambdaQueryWrapper 并设置查询条件
                TRegion region = regionService.getById(regionId);
                List<TRegion> regions = regionService.list(Wrappers.lambdaQuery(TRegion.class)
                        .eq(TRegion::getProvinceName, region.getProvinceName()));
                List<Integer> regionIds = regions.stream().map(TRegion::getId).collect(Collectors.toList());
                List<TConsultation> list1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId,type)
                        .in(TConsultation::getRegionId,regionIds)
                        .orderByDesc(TConsultation::getCreateTime,TConsultation::getClassificationSort).list();
                notices.addAll(list1);
                notices.sort(Comparator.comparing(TConsultation::getCreateTime).reversed());
            }
            List<TConsultation> list1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId,type).last("ORDER BY RAND() LIMIT 16").list();
            notices.addAll(list1);
            if (notices.size() > 16) {
//            List<TConsultation> list1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId,type).last("ORDER BY RAND() LIMIT 16").list();
//            notices.addAll(list1);
            if (notices.size() > 2) {
                // 只保留前 16 条记录
                notices = new ArrayList<>(notices.subList(0, 16));
                notices = new ArrayList<>(notices.subList(0, 2));
            }
        }
        return R.ok(notices);
@@ -214,13 +234,20 @@
    public R allert() {
        Long userId = tokenService.getLoginUser().getUserId();
        TAppUser byId = appUserService.getById(userId);
        Object cacheObject = redisCache.getCacheObject("ALLERT:"+userId);
        Long cacheObject = redisCache.getCacheObject("ALLERT:"+userId);
        if (cacheObject!=null && byId.getIsSetPreference() == 1){
            return R.ok(cacheObject);
            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();
    }
@@ -276,9 +303,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);
    }
@@ -308,6 +333,10 @@
            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);
    }