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.time.LocalDate;
import java.util.*;
/**
*
* 首页订单设置 前端控制器
*
*
* @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() {
List 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 list1 = regionService.lambdaQuery().groupBy(TRegion::getProvinceName).list();
for (TRegion tRegion : list1) {
List list = regionService.lambdaQuery().eq(TRegion::getProvinceName, tRegion.getProvinceName()).list();
List 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);
}
}
return R.ok(list1);
}
@ApiOperation(value = "定制推荐-申报通知",tags = {"web-首页"})
@PostMapping(value = "/notice/list")
public R> 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 notices = new ArrayList<>();
if (one!=null){
List list = changeDetailService.lambdaQuery().eq(TUserChangeDetail::getChangeId, one.getId()).list();
for (TUserChangeDetail tUserChangeDetail : list) {
List 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 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> 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 notices = new ArrayList<>();
if (one!=null){
List list = changeDetailService.lambdaQuery().eq(TUserChangeDetail::getChangeId, one.getId()).list();
for (TUserChangeDetail tUserChangeDetail : list) {
List 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 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 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> recommend() {
List 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();
Object cacheObject = redisCache.getCacheObject("ALLERT:"+userId);
if (cacheObject!=null){
return R.ok(cacheObject);
}else {
return R.ok(false);
}
}
@ApiOperation(value = "数据统计",tags = {"后台-统计"})
@PostMapping(value = "/count")
public R 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().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);
return R.ok(manageCountDto);
}
@ApiOperation(value = "用户增长数",tags = {"后台-统计"})
@PostMapping(value = "/user/up")
public R userup() {
List