无关风月
2024-12-31 0c51a577db337520452022d9d6a22b720ef858d4
xinquan-modules/xinquan-system/src/main/java/com/xinquan/system/controller/HomeController.java
@@ -3,10 +3,16 @@
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.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;
@@ -15,10 +21,15 @@
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;
@@ -35,6 +46,9 @@
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;
@@ -60,6 +74,43 @@
    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 = "管理后台-修改密码")
    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) {
@@ -112,9 +163,10 @@
        if (!StringUtils.hasLength(homeDto.getTime())){
            homeDto.setTime("1");
        }
        if(homeDto.getTimeType() == null){
            homeDto.setTimeType(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");
@@ -127,7 +179,7 @@
        Map<String, Object> x = new HashMap<>();
        Map<String, Object> x1 = new HashMap<>();
        Map<String, Object> x2 = new HashMap<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d");
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        switch (homeDto.getTimeType()){
@@ -184,14 +236,14 @@
                // 周
                // 获取本周7天 格式为dd
                calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
                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_MONTH, 1);
                    calendar.add(Calendar.DAY_OF_WEEK, 1);
                }
                break;
            case 4:
@@ -207,28 +259,76 @@
                    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:
                            // 获取订单月份
                            x.put(value+"",(int)x.get(value+"")+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);
                            x.put(format,(int)x.get(format)+1);
                            if (StringUtils.hasLength(homeDto.getTime())&&x.get(value1+"")!=null){
                                x.put(value1+"",(int)x.get(value1+"")+1);
                            }
                            break;
                        case 3:
                            x.put(value1+"",(int)x.get(value1+"")+1);
                            if (StringUtils.hasLength(homeDto.getTime())&&x.get(value1+"")!=null){
                                x.put(value1+"",(int)x.get(value1+"")+1);
                            }
                            break;
                        case 4:
                            x.put(value1+"",(int)x.get(value1+"")+1);
                            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;
@@ -236,18 +336,32 @@
                    switch (homeDto.getTimeType()){
                        case 1:
                            // 获取订单月份
                            x1.put(value+"",(int)x1.get(value+"")+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);
                            x1.put(format,(int)x1.get(format)+1);
                            if (StringUtils.hasLength(homeDto.getTime())&&x1.get(value1+"")!=null){
                                x1.put(value1+"",(int)x1.get(value1+"")+1);
                            }
                            break;
                        case 3:
                            x1.put(value1+"",(int)x1.get(value1+"")+1);
                            if (StringUtils.hasLength(homeDto.getTime())&&x1.get(value1+"")!=null){
                                x1.put(value1+"",(int)x1.get(value1+"")+1);
                            }
                            break;
                        case 4:
                            x1.put(value1+"",(int)x1.get(value1+"")+1);
                            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;
@@ -255,33 +369,40 @@
                    switch (homeDto.getTimeType()){
                        case 1:
                            // 获取订单月份
                            x2.put(value+"",(int)x2.get(value+"")+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);
                            x2.put(format,(int)x2.get(format)+1);
                            if (StringUtils.hasLength(homeDto.getTime())&&x2.get(value1+"")!=null){
                                x2.put(value1+"",(int)x2.get(value1+"")+1);
                            }
                            break;
                        case 3:
                            x2.put(value1+"",(int)x2.get(value1+"")+1);
                            if (StringUtils.hasLength(homeDto.getTime())&&x2.get(value1+"")!=null){
                                x2.put(value1+"",(int)x2.get(value1+"")+1);
                            }
                            break;
                        case 4:
                            x2.put(value1+"",(int)x2.get(value1+"")+1);
                            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;
            }
        }
        switch (homeDto.getTimeType()){
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                break;
        }
        // 对x的key值进行从小到大排序
        Map<String, Object> sortedMap = new TreeMap<>(Comparator.reverseOrder());
        sortedMap.putAll(x);
@@ -294,14 +415,27 @@
        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();
//        homeVO.setOrderMoney();
//        homeVO.setOrderCount();
//        homeVO.setOrderList();
//        homeVO.setOrderTimeList();
        // 查询用户总数、非会员数、月卡会员数、季卡会员数、年卡会员数
        String data = remoteAppUserService.getUserCount().getData();
        if (data!=null){
@@ -343,6 +477,16 @@
        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);