xuhy
2024-12-11 0a1533fd30ec1a2f4624ccda4ff11f2535ea8a46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import com.ruoyi.web.controller.query.ConsultationQuery;
import com.ruoyi.web.controller.query.OrderCountQuery;
import com.ruoyi.web.controller.query.dto.CountTotalDto;
import com.ruoyi.web.controller.query.dto.ManageCountDto;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
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>
 * 首页订单设置 前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-09-19
 */
@RestController
@RequestMapping("/t-index-menu")
public class TIndexMenuController {
 
    @Resource
    private TIndexMenuService indexMenuService;
    @Resource
    private TConsultationService consultationService;
    @Resource
    private TokenService tokenService;
    @Resource
    private TUserChangeService changeService;
    @Resource
    private TUserChangeDetailService changeDetailService;
    @Resource
    private TDeclareNoticeService declareNoticeService;
 
    @Resource
    private TCommitteeService committeeService;
 
    @Resource
    private TAppUserService appUserService;
    @Resource
    private TRegionService regionService;
    @Resource
    private TCourseService courseService;
    @Resource
    private TGeneratedRecordsService generatedRecordsService;
    @Resource
    private TInformationService informationService;
 
 
    @ApiOperation(value = "列表",tags = {"web-顶部菜单","后台-系统设置-首页菜单设置"})
    @PostMapping(value = "/list")
    public R<List<TIndexMenu>> list() {
        List<TIndexMenu> list = indexMenuService.lambdaQuery().orderByDesc(TIndexMenu::getMenuSort).list();
        return R.ok(list);
    }
    @ApiOperation(value = "编辑",tags = "后台-系统设置-首页菜单设置")
    @PostMapping(value = "/edit")
    public R edit(@RequestBody TIndexMenu indexMenu) {
        indexMenuService.updateById(indexMenu);
        return R.ok();
    }
 
    @ApiOperation(value = "根据省名字获取悬停框内统计数",tags = {"web-政策数据中心"})
    @PostMapping(value = "/getByProvinceName/count")
    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)
                        .in(TConsultation::getClassificationId,Arrays.asList(1,2,3)).count();
                tRegion.setCount(count);
            }else {
                tRegion.setCount(0L);
            }
        }
        return R.ok(list1);
 
    }
 
 
    @ApiOperation(value = "定制推荐-申报通知",tags = {"web-首页"})
    @PostMapping(value = "/notice/list")
    public R<List<TDeclareNotice>> noticelist(@RequestBody ConsultationQuery informationQuery) {
        //获取当前登录人id
        Long userId = tokenService.getLoginUser().getUserId();
        TUserChange one = changeService.lambdaQuery().eq(TUserChange::getUserId, userId).orderByDesc(TUserChange::getCreateTime).last("limit 1").one();
        List<TDeclareNotice> notices = new ArrayList<>();
        if (one!=null){
                List<TUserChangeDetail> list = changeDetailService.lambdaQuery().eq(TUserChangeDetail::getChangeId, one.getId()).list();
            for (TUserChangeDetail tUserChangeDetail : list) {
                List<TDeclareNotice> list1 = declareNoticeService.lambdaQuery().eq(TDeclareNotice::getRegionId,tUserChangeDetail.getRegionId()).eq(TDeclareNotice::getMajorId, tUserChangeDetail.getMajorId()).eq(TDeclareNotice::getLevel, tUserChangeDetail.getLevelId()).list();
                notices.addAll(list1);
            }
            notices.sort(Comparator.comparing(TDeclareNotice::getCreateTime).reversed());
        }else {
            // 创建 LambdaQueryWrapper 并设置查询条件
            List<TDeclareNotice> list1 = declareNoticeService.lambdaQuery()
                    .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);
    }
 
    @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();
        List<TConsultation> notices = new ArrayList<>();
 
        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);
    }
 
 
 
 
    @ApiOperation(value = "全国政策数据",tags = {"web-首页"})
    @PostMapping(value = "/total/count")
    public R<CountTotalDto> totalcount() {
        Long count1 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId, 1).count();
        Long count2 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId, 2).count();
        Long count3 = consultationService.lambdaQuery().eq(TConsultation::getClassificationId, 3).count();
        CountTotalDto countTotalDto = new CountTotalDto();
        countTotalDto.setNoticeCount(count1);
        countTotalDto.setFileCount(count2);
        countTotalDto.setInfoCount(count3);
        Long count4 = committeeService.lambdaQuery().count();
        countTotalDto.setCommitteeCount(count4);
        return R.ok(countTotalDto);
    }
 
    @ApiOperation(value = "全国政策数据下方通知公告",tags = {"web-首页"})
    @PostMapping(value = "/notice/recommend")
    public R<List<TConsultation>> recommend() {
        List<TConsultation> list = consultationService.lambdaQuery().eq(TConsultation::getClassificationId, 1).orderByDesc(TConsultation::getIsRecommend).orderByDesc(TConsultation::getCreateTime).last("limit 9").list();
 
        return R.ok(list);
    }
 
    @Resource
    private RedisCache redisCache;
    @ApiOperation(value = "顶部提示",tags = {"web-顶部弹窗"})
    @PostMapping(value = "/allert")
    public R allert() {
        Long userId = tokenService.getLoginUser().getUserId();
        TAppUser byId = appUserService.getById(userId);
        Object cacheObject = redisCache.getCacheObject("ALLERT:"+userId);
 
        if (cacheObject!=null && byId.getIsSetPreference() == 1){
            return R.ok(cacheObject);
        }else {
            return R.ok(false);
        }
    }
 
 
    @ApiOperation(value = "数据统计",tags = {"后台-统计"})
    @PostMapping(value = "/count")
    public R<ManageCountDto> count() {
        Long userCount = appUserService.lambdaQuery().count();
        Long courseCount = courseService.lambdaQuery().count();
        Long courseFreeCount = courseService.lambdaQuery().eq(TCourse::getCoursePrice,0).count();
        Long payCount = courseCount -courseFreeCount;
        Long recordsCount = generatedRecordsService.lambdaQuery().count();
        Long infoCount = 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);
        manageCountDto.setCourseCount(courseCount);
        manageCountDto.setCourseFreeCount(courseFreeCount);
        manageCountDto.setPayCount(payCount);
        manageCountDto.setRecordsCount(recordsCount);
        manageCountDto.setInfoFreeCount(infoFreeCount);
        manageCountDto.setInfoPayCount(infoPayCount);
        manageCountDto.setInfoCount(infoCount);
        return R.ok(manageCountDto);
    }
 
 
    @ApiOperation(value = "用户增长数",tags = {"后台-统计"})
    @PostMapping(value = "/user/up")
    public R userup() {
               List<Map<String,String>> userUp =   indexMenuService.userUp();
               return R.ok(userUp);}
 
    @ApiOperation(value = "订单统计",tags = {"后台-统计"})
    @PostMapping(value = "/order/count")
    public R<List<Map<String,String>>> ordercount(@RequestBody OrderCountQuery orderCountQuery) {
        List<Map<String,String>> map = new ArrayList<>();
        if (orderCountQuery.getDayType()==1){
            map =indexMenuService.dayCount(orderCountQuery.getPaymentStatus());
        }else if (orderCountQuery.getDayType()==2){
            map =indexMenuService.weekCount(orderCountQuery.getPaymentStatus());
        }else if (orderCountQuery.getDayType()==3){
            map =indexMenuService.monthCount(orderCountQuery.getPaymentStatus());
        }else if (orderCountQuery.getDayType()==4){
            map = indexMenuService.yearCount(orderCountQuery.getPaymentStatus());
        }else {
            map = indexMenuService.searchDayCount(orderCountQuery.getStartDate(),orderCountQuery.getEndDate(),orderCountQuery.getPaymentStatus());
        }
            return R.ok(map);
    }
 
 
    @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());
 
        return R.ok(map);
    }
 
 
 
    @ApiOperation(value = "推荐资料",tags = {"web-首页"})
    @PostMapping(value = "/information/list")
    public R<List<TInformation>> information() {
        //获取当前登录人id
        Long userId = tokenService.getLoginUser().getUserId();
        TUserChange one = changeService.lambdaQuery().eq(TUserChange::getUserId, userId).orderByDesc(TUserChange::getCreateTime).last("limit 1").one();
        List<TInformation> notices = new ArrayList<>();
        if (one!=null){
            List<TUserChangeDetail> list = changeDetailService.lambdaQuery().eq(TUserChangeDetail::getChangeId, one.getId()).list();
            for (TUserChangeDetail tUserChangeDetail : list) {
                List<TInformation> list1 = informationService.lambdaQuery().eq(TInformation::getRegionId,tUserChangeDetail.getRegionId()).eq(TInformation::getMajorId, tUserChangeDetail.getMajorId()).eq(TInformation::getLevel, tUserChangeDetail.getLevelId()).list();
                notices.addAll(list1);
            }
            notices.sort(Comparator.comparing(TInformation::getCreateTime).reversed());
        }
            // 创建 LambdaQueryWrapper 并设置查询条件
            List<TInformation> list1 = informationService.lambdaQuery().last("ORDER BY RAND() LIMIT 16").list();
            notices.addAll(list1);
 
        if (notices.size() > 16) {
            // 只保留前 16 条记录
            notices = new ArrayList<>(notices.subList(0, 16));
        }
        notices = notices.stream().distinct().collect(Collectors.toList());
        return R.ok(notices);
    }
 
 
    @ApiOperation(value = "推荐课程",tags = {"web-首页"})
    @PostMapping(value = "/course/list")
    public R<List<TCourse>> course() {
        //获取当前登录人id
        Long userId = tokenService.getLoginUser().getUserId();
        TUserChange one = changeService.lambdaQuery().eq(TUserChange::getUserId, userId).orderByDesc(TUserChange::getCreateTime).last("limit 1").one();
        List<TCourse> notices = new ArrayList<>();
        if (one!=null){
            List<TUserChangeDetail> list = changeDetailService.lambdaQuery().eq(TUserChangeDetail::getChangeId, one.getId()).list();
            for (TUserChangeDetail tUserChangeDetail : list) {
                List<TCourse> list1 = courseService.lambdaQuery().eq(TCourse::getRegionId,tUserChangeDetail.getRegionId()).eq(TCourse::getMajorId, tUserChangeDetail.getMajorId()).eq(TCourse::getLevel, tUserChangeDetail.getLevelId()).list();
                notices.addAll(list1);
            }
            notices.sort(Comparator.comparing(TCourse::getCreateTime).reversed());
        }else {
            // 创建 LambdaQueryWrapper 并设置查询条件
 
        }
        List<TCourse> list1 = courseService.lambdaQuery().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);
    }
 
 
}