package com.xinquan.system.controller;
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
import com.xinquan.common.core.constant.CacheConstants;
|
import com.xinquan.common.core.domain.R;
|
import com.xinquan.common.core.exception.ServiceException;
|
import com.xinquan.common.core.utils.DateUtils;
|
import com.xinquan.common.core.utils.WebUtils;
|
import com.xinquan.common.core.utils.page.BeanUtils;
|
import com.xinquan.common.core.utils.page.PageDTO;
|
import com.xinquan.common.core.web.domain.BaseModel;
|
import com.xinquan.common.log.annotation.Log;
|
import com.xinquan.common.log.enums.BusinessType;
|
import com.xinquan.common.redis.service.RedisService;
|
import com.xinquan.common.security.utils.SecurityUtils;
|
import com.xinquan.course.api.domain.Course;
|
import com.xinquan.course.api.domain.CourseCategory;
|
import com.xinquan.course.api.domain.CourseDTO;
|
import com.xinquan.course.api.feign.RemoteCourseService;
|
import com.xinquan.meditation.api.feign.RemoteMeditationService;
|
import com.xinquan.order.api.domain.Order;
|
import com.xinquan.order.api.domain.vo.HomeDto;
|
import com.xinquan.order.api.feign.RemoteOrderService;
|
import com.xinquan.system.api.domain.SysUser;
|
import com.xinquan.system.api.domain.vo.HomeVO;
|
import com.xinquan.system.domain.Banner;
|
import com.xinquan.system.domain.Turn;
|
import com.xinquan.system.domain.Version;
|
import com.xinquan.system.domain.export.HomeExport;
|
import com.xinquan.system.service.BannerService;
|
import com.xinquan.system.service.ISysUserService;
|
import com.xinquan.system.service.TurnService;
|
import com.xinquan.user.api.feign.RemoteAppUserService;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.poi.ss.usermodel.Workbook;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.servlet.ServletOutputStream;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.net.URLEncoder;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 用户信息表 前端控制器
|
* </p>
|
*
|
* @author mitao
|
* @since 2024-08-21
|
*/
|
@RestController
|
@RequestMapping("/system/home")
|
public class HomeController {
|
|
@Resource
|
private BannerService bannerService;
|
@Resource
|
private RemoteCourseService remoteCourseService;
|
@Resource
|
private RemoteAppUserService remoteAppUserService;
|
@Resource
|
private RemoteMeditationService remoteMeditationService;
|
@Resource
|
private RemoteOrderService remoteOrderService;
|
@Resource
|
private ISysUserService sysUserService;
|
@Resource
|
private RedisService redisService;
|
@Resource
|
private TurnService turnService;
|
@GetMapping("/getTurn")
|
@ApiOperation(value = "IOS获取是否跳转三方支付", tags = "IOS获取是否跳转三方支付")
|
public R getTurn() {
|
Turn one = turnService.getOne(null);
|
if (one.getIsTurn()==1){
|
return R.ok(true);
|
}else{
|
return R.ok(false);
|
}
|
}
|
|
|
|
@GetMapping("/updatePassword")
|
@ApiOperation(value = "管理后台-修改密码", tags = "管理后台-修改密码")
|
@Log(title = "【修改密码】修改密码", businessType = BusinessType.UPDATE)
|
|
public R updatePassword(String userName,String password) {
|
SysUser one = sysUserService.lambdaQuery()
|
.eq(SysUser::getUserType, "00")
|
.eq(SysUser::getDelFlag, "0")
|
.eq(SysUser::getUserName, userName).one();
|
|
if (one!=null){
|
// if (one.getStatus().equals("1")){
|
// return R.fail("账号已被冻结");
|
// }
|
one.setPassword(SecurityUtils.encryptPassword(password));
|
sysUserService.updateById(one);
|
return R.ok();
|
}
|
return R.fail("修改失败,账号不存在");
|
}
|
@PostMapping("/homeStatistics")
|
@ApiOperation(value = "首页统计",tags = "管理后台-首页统计")
|
public R<HomeVO> bannerList(@RequestBody HomeDto homeDto) {
|
HomeVO homeVO = new HomeVO();
|
// homeVO.setOrderMoney();
|
// homeVO.setOrderCount();
|
// homeVO.setOrderList();
|
// homeVO.setOrderTimeList();
|
// 查询用户总数、非会员数、月卡会员数、季卡会员数、年卡会员数
|
String data = remoteAppUserService.getUserCount().getData();
|
if (data!=null){
|
String[] split = data.split(",");
|
homeVO.setUserCount(split[0]);
|
homeVO.setNoVip(split[1]);
|
homeVO.setVipMonth(split[2]);
|
homeVO.setVipQuarter(split[3]);
|
homeVO.setVipYear(split[4]);
|
}
|
// 查询课程总数 免费、会员免费、单独收费、线下课程数
|
String data1 = remoteCourseService.getCourseCount().getData();
|
if (data1!=null){
|
String[] split = data1.split(",");
|
homeVO.setCourseCount(split[0]);
|
homeVO.setCourseFree(split[1]);
|
homeVO.setCourseVip(split[2]);
|
homeVO.setCoursePay(split[3]);
|
homeVO.setCourseOffOnline(split[4]);
|
}
|
// 查询疗愈总数 免费、会员免费、单独收费
|
String data2 = remoteMeditationService.getMeditationCount().getData();
|
if (data2!=null){
|
String[] split = data2.split(",");
|
homeVO.setMeditationCount(split[0]);
|
homeVO.setMeditationFree(split[1]);
|
homeVO.setMeditationVip(split[2]);
|
homeVO.setMeditationPay(split[3]);
|
}
|
String data3 = remoteMeditationService.getQuestionCount().getData();
|
if (data3!=null){
|
homeVO.setQuestionRecord(data3);
|
}
|
String data4 = remoteAppUserService.getPrizeRecordCount().getData();
|
if (data4!=null){
|
homeVO.setPrizeRecord(data4);
|
}
|
// 查询用户总数列表变化趋势
|
Map<String, Object> data5 = remoteAppUserService.getUserListCount().getData();
|
homeVO.setUserList(data5);
|
// 查询时间范围内的订单列表 课程 疗愈 会员
|
if (!StringUtils.hasLength(homeDto.getTime())){
|
homeDto.setTime("1");
|
}
|
if (homeDto.getTimeType()==null){
|
homeDto.setTimeType(5);
|
}
|
|
List<Order> data6 = remoteOrderService.getOrderList(homeDto.getStatus(), homeDto.getTimeType(), homeDto.getTime()).getData();
|
homeVO.setOrderCount(data6.size()+"");
|
BigDecimal bigDecimal = new BigDecimal("0");
|
for (Order order : data6) {
|
if (order.getRealPayAmount()!=null){
|
bigDecimal= bigDecimal.add(order.getRealPayAmount());
|
}
|
}
|
homeVO.setOrderMoney(bigDecimal+"");
|
Map<String, Object> x = new HashMap<>();
|
Map<String, Object> x1 = new HashMap<>();
|
Map<String, Object> x2 = new HashMap<>();
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d");
|
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
|
Calendar calendar = Calendar.getInstance();
|
switch (homeDto.getTimeType()){
|
case 1:
|
// 年
|
x.put("1",0);
|
x.put("2",0);
|
x.put("3",0);
|
x.put("4",0);
|
x.put("5",0);
|
x.put("6",0);
|
x.put("7",0);
|
x.put("8",0);
|
x.put("9",0);
|
x.put("10",0);
|
x.put("11",0);
|
x.put("12",0);
|
|
x1.put("1",0);
|
x1.put("2",0);
|
x1.put("3",0);
|
x1.put("4",0);
|
x1.put("5",0);
|
x1.put("6",0);
|
x1.put("7",0);
|
x1.put("8",0);
|
x1.put("9",0);
|
x1.put("10",0);
|
x1.put("11",0);
|
x1.put("12",0);
|
|
x2.put("1",0);
|
x2.put("2",0);
|
x2.put("3",0);
|
x2.put("4",0);
|
x2.put("5",0);
|
x2.put("6",0);
|
x2.put("7",0);
|
x2.put("8",0);
|
x2.put("9",0);
|
x2.put("10",0);
|
x2.put("11",0);
|
x2.put("12",0);
|
break;
|
case 2:
|
// 获取当前日期格式为 yyyy-MM-dd
|
Date date = new Date();
|
String format = simpleDateFormat.format(date);
|
x.put(format,0);
|
x1.put(format,0);
|
x2.put(format,0);
|
break;
|
case 3:
|
// 周
|
// 获取本周7天 格式为dd
|
|
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
|
for (int i = 1; i <= 7; i++) {
|
Date time = calendar.getTime();
|
String format1 = simpleDateFormat.format(time);
|
x.put(format1,0);
|
x1.put(format1,0);
|
x2.put(format1,0);
|
calendar.add(Calendar.DAY_OF_WEEK, 1);
|
}
|
break;
|
case 4:
|
// 月
|
// 获取本月31天 格式为dd
|
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
for (int i = 1; i <= 31; i++) {
|
Date time = calendar.getTime();
|
String format1 = simpleDateFormat.format(time);
|
x.put(format1,0);
|
x1.put(format1,0);
|
x2.put(format1,0);
|
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
}
|
break;
|
case 5:
|
String startTime = null;
|
String endTime = null;
|
if (org.springframework.util.StringUtils.hasLength(homeDto.getTime())){
|
String[] split = homeDto.getTime().split(" - ");
|
startTime = split[0];
|
endTime = split[1];
|
// 将其转化为LocalDate
|
LocalDate startLocalDate = LocalDate.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
LocalDate endLocalDate = LocalDate.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
// 将startLocalDate到endLocalDate之间的每一天的日期,包括startLocalDate和endLocalDate
|
List<LocalDate> localDates = new ArrayList<>();
|
while (!startLocalDate.isAfter(endLocalDate)) {
|
// 将startLocalDate转化为格式为yyyy-MM-dd格式字符串
|
String format1 = startLocalDate.format(DateTimeFormatter.ofPattern("d"));
|
x.put(format1,0);
|
x1.put(format1,0);
|
x2.put(format1,0);
|
localDates.add(startLocalDate);
|
startLocalDate = startLocalDate.plusDays(1);
|
|
}
|
}
|
|
break;
|
}
|
// if (StringUtils.hasLength(homeDto.getTime())&&(!homeDto.getTime().equals("1"))){
|
// List<LocalDate> localDates = generateDateList(homeDto.getTime());
|
// for (LocalDate localDate : localDates) {
|
// x.put(localDate+"",0);
|
// x1.put(localDate+"",0);
|
// x2.put(localDate+"",0);
|
// }
|
//
|
// }
|
for (Order order : data6) {
|
int value = order.getCreateTime().getMonth().getValue();
|
int value1 = order.getCreateTime().getDayOfMonth();
|
LocalDateTime createTime = order.getCreateTime();
|
LocalDate localDate = createTime.toLocalDate();
|
switch (order.getOrderFrom()){
|
case 1:
|
switch (homeDto.getTimeType()){
|
case 1:
|
// 获取订单月份
|
if (StringUtils.hasLength(homeDto.getTime())&&x.get(value+"")!=null){
|
x.put(value+"",(int)x.get(value+"")+1);
|
}
|
break;
|
case 2:
|
Date date = new Date();
|
String format = simpleDateFormat.format(date);
|
if (StringUtils.hasLength(homeDto.getTime())&&x.get(value1+"")!=null){
|
x.put(value1+"",(int)x.get(value1+"")+1);
|
}
|
break;
|
case 3:
|
if (StringUtils.hasLength(homeDto.getTime())&&x.get(value1+"")!=null){
|
x.put(value1+"",(int)x.get(value1+"")+1);
|
}
|
break;
|
case 4:
|
if (StringUtils.hasLength(homeDto.getTime())&&x.get(value1+"")!=null){
|
x.put(value1+"",(int)x.get(value1+"")+1);
|
}
|
break;
|
case 5:
|
if (StringUtils.hasLength(homeDto.getTime())&&x.get(value1+"")!=null){
|
x.put(value1+"",(int)x.get(value1+"")+1);
|
}
|
break;
|
}
|
break;
|
case 2:
|
switch (homeDto.getTimeType()){
|
case 1:
|
// 获取订单月份
|
if (StringUtils.hasLength(homeDto.getTime())&&x1.get(value+"")!=null){
|
x1.put(value+"",(int)x1.get(value+"")+1);
|
}
|
break;
|
case 2:
|
Date date = new Date();
|
String format = simpleDateFormat.format(date);
|
if (StringUtils.hasLength(homeDto.getTime())&&x1.get(value1+"")!=null){
|
x1.put(value1+"",(int)x1.get(value1+"")+1);
|
|
}
|
break;
|
case 3:
|
if (StringUtils.hasLength(homeDto.getTime())&&x1.get(value1+"")!=null){
|
x1.put(value1+"",(int)x1.get(value1+"")+1);
|
}
|
break;
|
case 4:
|
if (StringUtils.hasLength(homeDto.getTime())&&x1.get(value1+"")!=null){
|
x1.put(value1+"",(int)x1.get(value1+"")+1);
|
}
|
break;
|
case 5:
|
if (StringUtils.hasLength(homeDto.getTime())&&x1.get(value1+"")!=null){
|
x1.put(value1+"",(int)x1.get(value1+"")+1);
|
}
|
break;
|
}
|
break;
|
case 3:
|
switch (homeDto.getTimeType()){
|
case 1:
|
// 获取订单月份
|
if (StringUtils.hasLength(homeDto.getTime())&&x2.get(value+"")!=null){
|
x2.put(value+"",(int)x2.get(value+"")+1);
|
}
|
break;
|
case 2:
|
Date date = new Date();
|
String format = simpleDateFormat.format(date);
|
if (StringUtils.hasLength(homeDto.getTime())&&x2.get(value1+"")!=null){
|
x2.put(value1+"",(int)x2.get(value1+"")+1);
|
|
}
|
break;
|
case 3:
|
if (StringUtils.hasLength(homeDto.getTime())&&x2.get(value1+"")!=null){
|
|
x2.put(value1+"",(int)x2.get(value1+"")+1);
|
}
|
break;
|
case 4:
|
if (StringUtils.hasLength(homeDto.getTime())&&x2.get(value1+"")!=null){
|
|
x2.put(value1+"",(int)x2.get(value1+"")+1);
|
}
|
break;
|
case 5:
|
if (StringUtils.hasLength(homeDto.getTime())&&x2.get(value1+"")!=null){
|
x2.put(value1+"",(int)x2.get(value1+"")+1);
|
}
|
break;
|
}
|
break;
|
}
|
}
|
|
// 对x的key值进行从小到大排序
|
Map<String, Object> sortedMap = new TreeMap<>(Comparator.reverseOrder());
|
sortedMap.putAll(x);
|
Map<String, Object> sortedMap1 = new TreeMap<>(Comparator.reverseOrder());
|
sortedMap1.putAll(x1);
|
Map<String, Object> sortedMap2 = new TreeMap<>(Comparator.reverseOrder());
|
sortedMap2.putAll(x2);
|
homeVO.setOrderMeditationList(sortedMap);
|
homeVO.setOrderCourseList(sortedMap1);
|
homeVO.setOrderVipList(sortedMap2);
|
return R.ok(homeVO);
|
}
|
public static List<LocalDate> generateDateList(String dateRange) {
|
// 定义日期格式
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
// 解析日期范围字符串
|
String[] dates = dateRange.split(" - ");
|
LocalDate startDate = LocalDate.parse(dates[0], formatter);
|
LocalDate endDate = LocalDate.parse(dates[1], formatter);
|
|
// 创建日期列表
|
List<LocalDate> dateList = new ArrayList<>();
|
for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
|
dateList.add(date);
|
}
|
|
return dateList;
|
}
|
@PutMapping("/homeStatisticsExport")
|
@ApiOperation(value = "首页统计-导出",tags = "管理后台-首页统计")
|
public void homeStatisticsExport() {
|
HomeVO homeVO = new HomeVO();
|
// 查询用户总数、非会员数、月卡会员数、季卡会员数、年卡会员数
|
String data = remoteAppUserService.getUserCount().getData();
|
if (data!=null){
|
String[] split = data.split(",");
|
homeVO.setUserCount(split[0]);
|
homeVO.setNoVip(split[1]);
|
homeVO.setVipMonth(split[2]);
|
homeVO.setVipQuarter(split[3]);
|
homeVO.setVipYear(split[4]);
|
}
|
// 查询课程总数 免费、会员免费、单独收费、线下课程数
|
String data1 = remoteCourseService.getCourseCount().getData();
|
if (data1!=null){
|
String[] split = data1.split(",");
|
homeVO.setCourseCount(split[0]);
|
homeVO.setCourseFree(split[1]);
|
homeVO.setCourseVip(split[2]);
|
homeVO.setCoursePay(split[3]);
|
homeVO.setCourseOffOnline(split[4]);
|
}
|
// 查询疗愈总数 免费、会员免费、单独收费
|
String data2 = remoteMeditationService.getMeditationCount().getData();
|
if (data2!=null){
|
String[] split = data2.split(",");
|
homeVO.setMeditationCount(split[0]);
|
homeVO.setMeditationFree(split[1]);
|
homeVO.setMeditationVip(split[2]);
|
homeVO.setMeditationPay(split[3]);
|
}
|
String data3 = remoteMeditationService.getQuestionCount().getData();
|
if (data3!=null){
|
homeVO.setQuestionRecord(data3);
|
}
|
String data4 = remoteAppUserService.getPrizeRecordCount().getData();
|
if (data4!=null){
|
homeVO.setPrizeRecord(data4);
|
}
|
|
|
HomeExport homeExport = new HomeExport();
|
BeanUtils.copyProperties(homeVO, homeExport);
|
if (data1!=null){
|
String[] split = data1.split(",");
|
homeVO.setCourseCount(split[0]);
|
homeVO.setCourseFree(split[1]);
|
homeVO.setCourseVip(split[2]);
|
homeVO.setCoursePay(split[3]);
|
homeVO.setCourseOffOnline(split[4]);
|
Integer i = Integer.valueOf(homeExport.getCourseCount());
|
Integer i1 = Integer.valueOf(split[4]);
|
}
|
List<HomeExport> homeExports = new ArrayList<>();
|
homeExports.add(homeExport);
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), HomeExport.class, homeExports);
|
HttpServletResponse response = WebUtils.response();
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding("utf-8");
|
ServletOutputStream outputStream = null;
|
try {
|
String fileName = URLEncoder.encode("首页统计导出.xls", "utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
response.setHeader("Pragma", "no-cache");
|
response.setHeader("Cache-Control", "no-cache");
|
outputStream = response.getOutputStream();
|
workbook.write(outputStream);
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
try {
|
outputStream.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
@PostMapping("/cateList")
|
@ApiOperation(value = "课程分类下拉选择列表-不分页",tags = "管理后台banner")
|
|
public R<List<CourseCategory>> cateList() {
|
List<CourseCategory> data = remoteCourseService.cateList().getData();
|
return R.ok(data);
|
}
|
@GetMapping("/courseList")
|
@ApiOperation(value = "选择课程-分页",tags = "管理后台banner")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = false, dataType = "Integer"),
|
@ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = false, dataType = "Integer"),
|
@ApiImplicitParam(value = "课程类型1线上2线下", name = "courseType", required = false, dataType = "Integer"),
|
@ApiImplicitParam(value = "课程分类id", name = "cateId", required = false, dataType = "Long"),
|
@ApiImplicitParam(value = "课程标题", name = "courseTitle", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "导师名称", name = "tutor", required = false, dataType = "String"),
|
})
|
public R<PageDTO<Course>> courseList(
|
Integer pageCurr,
|
Integer pageSize,
|
Integer courseType,
|
Long cateId,
|
String courseTitle,
|
|
String tutor
|
) {
|
CourseDTO courseDTO = new CourseDTO();
|
courseDTO.setPageCurr(pageCurr);
|
courseDTO.setPageSize(pageSize);
|
courseDTO.setCourseType(courseType);
|
courseDTO.setCateId(cateId);
|
courseDTO.setCourseTitle(courseTitle);
|
courseDTO.setTutor(tutor);
|
PageDTO<Course> data = remoteCourseService.courseList(courseDTO).getData();
|
return R.ok(data);
|
}
|
@PostMapping("/deleteBatch")
|
@ApiOperation(value = "批量删除banner",tags = "管理后台banner")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "ids", name = "ids", required = true, dataType = "String"),
|
})
|
@Log(title = "【banner】批量删除banner", businessType = BusinessType.DELETE)
|
|
public R deleteBatch(
|
@RequestParam(value = "ids") String ids)
|
{
|
List<Long> list = Arrays.asList(ids.split(",")).stream().map(Long::valueOf).collect(Collectors.toList());
|
bannerService.removeBatchByIds(list);
|
return R.ok();
|
}
|
@PostMapping("/addBanner")
|
@ApiOperation(value = "添加banner",tags = "管理后台banner")
|
@Log(title = "【banner】添加", businessType = BusinessType.INSERT)
|
|
public R addBanner(@RequestBody Banner banner)
|
{
|
bannerService.save(banner);
|
return R.ok();
|
}
|
@PostMapping("/updateBanner")
|
@ApiOperation(value = "修改banner",tags = "管理后台banner")
|
@Log(title = "【banner】修改", businessType = BusinessType.UPDATE)
|
|
public R updateBanner(@RequestBody Banner banner)
|
{
|
bannerService.updateById(banner);
|
return R.ok();
|
}
|
@PostMapping("/bannerDetail")
|
@ApiOperation(value = "查看详情",tags = "管理后台banner")
|
|
public R<Banner> bannerDetail(String uid)
|
{
|
Banner byId = bannerService.getById(uid);
|
if (byId.getCourseId()!=null){
|
Course data = remoteCourseService.getCourseById(byId.getCourseId()).getData();
|
if (data!=null){
|
byId.setCourseTitle(data.getCourseTitle());
|
byId.setCoverUrl(data.getCoverUrl());
|
byId.setTutor(data.getTutor());
|
byId.setPrice(data.getGeneralPrice());
|
if (data.getCateId()!=null){
|
CourseCategory data1 = remoteCourseService.getCategoryById(data.getCateId().toString()).getData();
|
byId.setCate(data1.getName());
|
}
|
}
|
}
|
return R.ok(byId);
|
}
|
|
}
|