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);
|
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();
|
}
|
|
|
@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 = 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());
|
Set<Long> cacheSet = redisCache.getCacheSet("INFORMATION:" + userId);
|
for (TInformation notice : notices) {
|
notice.setIsCollect(cacheSet.contains(notice.getId())?1:0);
|
}
|
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);
|
}
|
|
|
}
|