无关风月
2024-08-20 f237a61c412870933f47316a011237cd538de9bc
guns-admin/src/main/java/com/stylefeng/guns/modular/api/UserController.java
@@ -5,6 +5,7 @@
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.stylefeng.guns.modular.system.dao.UserBlackMapper;
import com.stylefeng.guns.modular.system.dto.*;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
@@ -20,6 +21,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.paths.AbstractPathProvider;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -86,9 +88,12 @@
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
    })
    public ResultUtil<PeopleListVO> peopleList() {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        PeopleListVO peopleListVO = new PeopleListVO();
        peopleListVO.setUserName(appUserService.getAppUser().getName());
        AppUser appUser = appUserService.getAppUser();
        Integer inviteUserId = appUser.getInviteUserId();
        if (inviteUserId!=null){
            AppUser appUser1 = appUser.selectById(inviteUserId);
@@ -127,14 +132,22 @@
    })
    public ResultUtil getBindingUserName(String code) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        if (code.equals(appUser.getCode())){
            return ResultUtil.errorInvite("不能绑定自己",null);
            return ResultUtil.errorInvite("不能绑定自己","");
        }
        AppUser code1 = appUserService.selectOne(new EntityWrapper<AppUser>()
                .eq("code", code));
        if (code1 == null){
            return ResultUtil.errorInvite("邀请码无效",null);
            return ResultUtil.errorInvite("邀请码无效","");
        }
//        else{
//            if (code1.getInviteUserId().equals(appUser.getId())){
//                return ResultUtil.error("邀请失败,当前邀请用户为您的邀请人", null);
//            }
//        }
        return ResultUtil.success(code1.getName());
    }
    @ResponseBody
@@ -146,13 +159,21 @@
    })
    public ResultUtil updateBankCard(String code) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        AppUser code1 = appUserService.selectOne(new EntityWrapper<AppUser>()
                .eq("code", code));
        if (code1 == null){
            return ResultUtil.errorInvite("邀请码无效",null);
            return ResultUtil.errorInvite("邀请码无效","");
        }
        if (code.equals(appUser.getCode())){
            return ResultUtil.error("不能绑定自己");
        }
        if (code1.getInviteUserId()!=null){
            if (code1.getInviteUserId().equals(appUser.getId())){
                return ResultUtil.error("邀请失败,当前邀请用户为您的邀请人", null);
            }
        }
        appUser.setInviteUserId(code1.getId());
        appUserService.updateById(appUser);
@@ -169,6 +190,9 @@
    })
    public ResultUtil Withdrawal(BigDecimal money) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        if (!StringUtils.hasLength(appUser.getBankCard())){
            return ResultUtil.error("提现失败 请先绑定银行卡");
        }
@@ -203,6 +227,9 @@
    public ResultUtil updateBankCard(String accountName, String bankCard,String bankName,String bankPhone,String bankCardImg) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        appUser.setBankCard(bankCard);
        appUser.setAccountName(accountName);
        appUser.setBankName(bankName);
@@ -212,6 +239,71 @@
            return ResultUtil.success(appUser);
        }
        appUserService.updateById(appUser);
        return ResultUtil.success();
    }
    @Autowired
    private UserBlackMapper userBlackMapper;
    @ResponseBody
    @PostMapping("/base/appUser/blackList")
    @ApiOperation(value = "拉黑列表", tags = {"2.0新增"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int"),
    })
    public ResultUtil<List<BlackListVO>> blackList(Integer pageNum,Integer pageSize) {
        List<BlackListVO> res = new ArrayList<>();
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        List<UserBlack> userId = userBlackService.selectList(new EntityWrapper<UserBlack>()
                .eq("userId", appUser.getId()));
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
        for (UserBlack userBlack : userId) {
            AppUser appUser1 = appUserService.selectById(userBlack.getBlackUserId());
            if (appUser1 != null){
                BlackListVO blackListVO = new BlackListVO();
                blackListVO.setId(appUser1.getId());
                blackListVO.setHeadImg(appUser1.getHeadImg());
                blackListVO.setName(appUser1.getName());
                String format = simpleDateFormat.format(userBlack.getInsertTime());
                res.add(blackListVO);
            }
        }
        List<BlackListVO> findVOS = testing4(res.size(), pageNum, pageSize, res);
        return ResultUtil.success(findVOS);
    }
    @Autowired
    private IUserBlackService userBlackService;
    @ResponseBody
    @PostMapping("/base/appUser/black")
    @ApiOperation(value = "拉黑/取消拉黑操作", tags = {"2.0新增"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
            @ApiImplicitParam(value = "被拉黑用户id", name = "id", dataType = "string" ),
    })
    public ResultUtil black(Integer id) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        UserBlack userBlack = userBlackService.selectOne(new EntityWrapper<UserBlack>()
                .eq("userId", appUser.getId())
                .eq("blackUserId", id));
        // 执行取消拉黑操作
        if (userBlack!=null){
            userBlackService.deleteById(userBlack.getId());
        }else{
            // 执行新增拉黑操作
            userBlack = new UserBlack();
            userBlack.setInsertTime(new Date());
            userBlack.setUserId(appUser.getId());
            userBlack.setBlackUserId(id);
            userBlackService.insert(userBlack);
        }
        return ResultUtil.success();
    }
@@ -241,6 +333,10 @@
    })
    public ResultUtil<AppUser> updateBankCard() {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        return ResultUtil.success(appUserService.getAppUser());
    }
@@ -254,6 +350,9 @@
        List<CouponVO> res = new ArrayList<>();
        req.setPageNum((req.getPageNum() - 1) * req.getPageSize());
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        req.setUserId(appUser.getId());
        List<CouponReceive> couponReceives = couponReceiveService.getList(req);
        for (CouponReceive couponReceive : couponReceives) {
@@ -286,6 +385,9 @@
    })
    public ResultUtil<List<WithdtawalVO>> withdrawal(Integer year,Integer month,Integer pageNum,Integer pageSize) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        List<WithdtawalVO> withdtawalVOS = new ArrayList<>();
        Wrapper<Withdrawal> eq1 = new EntityWrapper<Withdrawal>()
                .eq("userId", appUser.getId());
@@ -357,6 +459,10 @@
    public ResultUtil<WalletVO> wallet(Integer year,Integer month,Integer pageNum,Integer pageSize) {
        WalletVO walletVO = new WalletVO();
        List<UserDetailVO> detail = new ArrayList<>();
        AppUser appUser3 = appUserService.getAppUser();
        if (appUser3 == null){
            return ResultUtil.tokenErr("登录失效");
        }
        Integer id = appUserService.getAppUser().getId();
        BigDecimal balance = appUserService.getAppUser().getBalance();
        walletVO.setBalance(balance);
@@ -509,6 +615,484 @@
        walletVO.setDetails(testing);
        return ResultUtil.success(walletVO);
    }
    @ResponseBody
    @PostMapping("/base/appUser/appleWallet")
    @ApiOperation(value = "苹果佣金列表(提现 好友消费 佣金 充值 平台红包)", tags = {"我的"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
            @ApiImplicitParam(value = "年", name = "year", dataType = "int"),
            @ApiImplicitParam(value = "月", name = "month", dataType = "int"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int"),
            @ApiImplicitParam(value = "类型 1=提现 2=好友消费 3=佣金 4=充值 5=平台红包", name = "type"),
    })
    public ResultUtil<WalletVO> appleWallet(Integer year,Integer month,Integer pageNum,Integer pageSize,String type) {
        WalletVO walletVO = new WalletVO();
        List<UserDetailVO> detail = new ArrayList<>();
        AppUser appUser3 = appUserService.getAppUser();
        if (appUser3 == null){
            return ResultUtil.tokenErr("登录失效");
        }
        Integer id = appUserService.getAppUser().getId();
        BigDecimal balance = appUserService.getAppUser().getBalance();
        walletVO.setBalance(balance);
        if (!StringUtils.hasLength(type)){
            // 查询全部
            Wrapper<Recharge> eq1 = new EntityWrapper<Recharge>()
                    .eq("userId", id)
                    .eq("state", 2);
            // 如果传递了年份和月份,则添加时间条件
            if (year != null && month != null) {
                LocalDate startDate = LocalDate.of(year, month, 1);
                LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                eq1.ge("insertTime", startDate).le("insertTime", endDate);
            }
            // 查询充值记录
            List<Recharge> recharges = rechargeService.selectList(eq1);
            for (Recharge recharge : recharges) {
                UserDetailVO userDetailVO = new UserDetailVO();
                userDetailVO.setAmount("+"+recharge.getAmount().toString());
                userDetailVO.setType("充值");
                userDetailVO.setInsertTime1(recharge.getInsertTime());
                SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                String format1 = format.format(recharge.getInsertTime());
                userDetailVO.setInsertTime(format1);
                detail.add(userDetailVO);
            }
            // 查询购课记录 只查询钱包支付的
            Wrapper<OrderCourse> eq2 = new EntityWrapper<OrderCourse>()
                    .eq("userId", id)
//                .eq("payType", 3)
                    .eq("state", 2);
            // 如果传递了年份和月份,则添加时间条件
            if (year != null && month != null) {
                LocalDate startDate = LocalDate.of(year, month, 1);
                LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                eq2.ge("insertTime", startDate).le("insertTime", endDate);
            }
//        List<OrderCourse> orderCourses = orderCourseService.selectList(eq2);
//        for (OrderCourse orderCours : orderCourses) {
//            UserDetailVO userDetailVO = new UserDetailVO();
//            userDetailVO.setAmount("-"+orderCours.getRealMoney());
//            userDetailVO.setType("购买课程");
//            userDetailVO.setInsertTime1(orderCours.getInsertTime());
//            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
//            String format1 = format.format(orderCours.getInsertTime());
//            userDetailVO.setInsertTime(format1);
//            detail.add(userDetailVO);
//        }
            Wrapper<Order> eq = new EntityWrapper<Order>()
                    .eq("userId", id)
//                .eq("payType", 3)
                    .eq("state", 2);
            // 如果传递了年份和月份,则添加时间条件
            if (year != null && month != null) {
                LocalDate startDate = LocalDate.of(year, month, 1);
                LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                eq.ge("insertTime", startDate).le("insertTime", endDate);
            }
//        List<Order> orders = orderService.selectList(eq);
            // 查询购买套餐记录 只查询钱包支付的
//        for (Order order : orders) {
//            UserDetailVO userDetailVO = new UserDetailVO();
//            userDetailVO.setAmount("-"+order.getRealMoney());
//            userDetailVO.setType("购买套餐");
//            userDetailVO.setInsertTime1(order.getInsertTime());
//            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
//            String format1 = format.format(order.getInsertTime());
//            userDetailVO.setInsertTime(format1);
//            detail.add(userDetailVO);
//        }
            // 查询提现记录
            Wrapper<Withdrawal> eq3 = new EntityWrapper<Withdrawal>()
                    .eq("userId", id);
            // 如果传递了年份和月份,则添加时间条件
            if (year != null && month != null) {
                LocalDate startDate = LocalDate.of(year, month, 1);
                LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                eq3.ge("insertTime", startDate).le("insertTime", endDate);
            }
            List<Withdrawal> withdrawals = withdrawalService.selectList(eq3);
            for (Withdrawal withdrawal : withdrawals) {
                UserDetailVO userDetailVO = new UserDetailVO();
                switch (withdrawal.getState()){
                    case 1:
                        userDetailVO.setAmount("-"+withdrawal.getAmount());
                        userDetailVO.setType("提现");
                        break;
                    case 2:
                        userDetailVO.setAmount("-"+withdrawal.getAmount());
                        userDetailVO.setType("提现");
                        break;
                    case 3:
                        userDetailVO.setAmount("+"+withdrawal.getAmount());
                        userDetailVO.setType("提现失败");
                        break;
                }
                userDetailVO.setInsertTime1(withdrawal.getInsertTime());
                SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                String format1 = format.format(withdrawal.getInsertTime());
                userDetailVO.setInsertTime(format1);
                detail.add(userDetailVO);
            }
            // 查询是否有邀请过用户 获得消费奖励
            Wrapper<Invite> eq4 = new EntityWrapper<Invite>()
                    .eq("giftUserId", id);
            // 如果传递了年份和月份,则添加时间条件
            if (year != null && month != null) {
                LocalDate startDate = LocalDate.of(year, month, 1);
                LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                eq4.ge("insertTime", startDate).le("insertTime", endDate);
            }
            eq4.eq("type",1);
            List<Invite> giftUserId = inviteService.selectList(eq4);
            for (Invite invite : giftUserId) {
                UserDetailVO userDetailVO = new UserDetailVO();
                userDetailVO.setAmount("+"+invite.getAmount());
                AppUser appUser = appUserService.selectById(invite.getUserId());
                userDetailVO.setType("好友消费:("+appUser.getName()+"消费了"+invite.getConsume()+"元)");
                userDetailVO.setInsertTime1(invite.getInsertTime());
                SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                String format1 = format.format(invite.getInsertTime());
                userDetailVO.setInsertTime(format1);
                detail.add(userDetailVO);
            }
            // 查询红包发放记录
            Wrapper<RedPackage> eq5 = new EntityWrapper<RedPackage>();
            if (year != null && month != null) {
                LocalDate startDate = LocalDate.of(year, month, 1);
                LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                eq5.ge("insertTime", startDate).le("insertTime", endDate);
            }
            List<RedPackage> redPackages = redPackageService.selectList(eq5);
            for (RedPackage redPackage : redPackages) {
                if (appUserService.getAppUser().getInsertTime().compareTo(redPackage.getInsertTime())>0){
                    continue;
                }
                UserDetailVO userDetailVO = new UserDetailVO();
                userDetailVO.setAmount("+"+redPackage.getAmount());
                userDetailVO.setType("平台红包");
                userDetailVO.setInsertTime1(redPackage.getInsertTime());
                SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                String format1 = format.format(redPackage.getInsertTime());
                userDetailVO.setInsertTime(format1);
                detail.add(userDetailVO);
            }
            List<UserDetailVO> sortedList = detail.stream()
                    .sorted(Comparator.comparing(UserDetailVO::getInsertTime1).reversed())
                    .collect(Collectors.toList());
            List<UserDetailVO> testing = testing(sortedList.size(), pageNum, pageSize, sortedList);
            walletVO.setDetails(testing);
            return ResultUtil.success(walletVO);
        }else{
            String[] split = type.split(",");
            List<String> collect = Arrays.stream(split).collect(Collectors.toList());
            if (collect.contains("1")){
                // 查询提现记录
                Wrapper<Withdrawal> eq3 = new EntityWrapper<Withdrawal>()
                        .eq("userId", id);
                // 如果传递了年份和月份,则添加时间条件
                if (year != null && month != null) {
                    LocalDate startDate = LocalDate.of(year, month, 1);
                    LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                    eq3.ge("insertTime", startDate).le("insertTime", endDate);
                }
                List<Withdrawal> withdrawals = withdrawalService.selectList(eq3);
                for (Withdrawal withdrawal : withdrawals) {
                    UserDetailVO userDetailVO = new UserDetailVO();
                    switch (withdrawal.getState()){
                        case 1:
                            userDetailVO.setAmount("-"+withdrawal.getAmount());
                            userDetailVO.setType("提现");
                            break;
                        case 2:
                            userDetailVO.setAmount("-"+withdrawal.getAmount());
                            userDetailVO.setType("提现");
                            break;
                        case 3:
                            userDetailVO.setAmount("+"+withdrawal.getAmount());
                            userDetailVO.setType("提现失败");
                            break;
                    }
                    userDetailVO.setInsertTime1(withdrawal.getInsertTime());
                    SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                    String format1 = format.format(withdrawal.getInsertTime());
                    userDetailVO.setInsertTime(format1);
                    detail.add(userDetailVO);
                }
            }
            if (collect.contains("2")){
                // 查询是否有邀请过用户 获得消费奖励
                Wrapper<Invite> eq4 = new EntityWrapper<Invite>()
                        .eq("giftUserId", id);
                // 如果传递了年份和月份,则添加时间条件
                if (year != null && month != null) {
                    LocalDate startDate = LocalDate.of(year, month, 1);
                    LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                    eq4.ge("insertTime", startDate).le("insertTime", endDate);
                }
                eq4.eq("type",1);
                List<Invite> giftUserId = inviteService.selectList(eq4);
                for (Invite invite : giftUserId) {
                    UserDetailVO userDetailVO = new UserDetailVO();
                    userDetailVO.setAmount("+"+invite.getAmount());
                    AppUser appUser = appUserService.selectById(invite.getUserId());
                    userDetailVO.setType("好友消费:("+appUser.getName()+"消费了"+invite.getConsume()+"元)");
                    userDetailVO.setInsertTime1(invite.getInsertTime());
                    SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                    String format1 = format.format(invite.getInsertTime());
                    userDetailVO.setInsertTime(format1);
                    detail.add(userDetailVO);
                }
            }
            if (collect.contains("3")){
// 查询是否有邀请过用户 获得消费奖励
                Wrapper<Invite> eq4 = new EntityWrapper<Invite>()
                        .eq("giftUserId", id);
                // 如果传递了年份和月份,则添加时间条件
                if (year != null && month != null) {
                    LocalDate startDate = LocalDate.of(year, month, 1);
                    LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                    eq4.ge("insertTime", startDate).le("insertTime", endDate);
                }
                eq4.eq("type",1);
                List<Invite> giftUserId = inviteService.selectList(eq4);
                for (Invite invite : giftUserId) {
                    UserDetailVO userDetailVO = new UserDetailVO();
                    userDetailVO.setAmount("+"+invite.getAmount());
                    AppUser appUser = appUserService.selectById(invite.getUserId());
                    userDetailVO.setType("好友消费:("+appUser.getName()+"消费了"+invite.getConsume()+"元)");
                    userDetailVO.setInsertTime1(invite.getInsertTime());
                    SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                    String format1 = format.format(invite.getInsertTime());
                    userDetailVO.setInsertTime(format1);
                    detail.add(userDetailVO);
                }
            }
            if (collect.contains("4")){
                Wrapper<Recharge> eq1 = new EntityWrapper<Recharge>()
                        .eq("userId", id)
                        .eq("state", 2);
                // 如果传递了年份和月份,则添加时间条件
                if (year != null && month != null) {
                    LocalDate startDate = LocalDate.of(year, month, 1);
                    LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                    eq1.ge("insertTime", startDate).le("insertTime", endDate);
                }
                // 查询充值记录
                List<Recharge> recharges = rechargeService.selectList(eq1);
                for (Recharge recharge : recharges) {
                    UserDetailVO userDetailVO = new UserDetailVO();
                    userDetailVO.setAmount("+"+recharge.getAmount().toString());
                    userDetailVO.setType("充值");
                    userDetailVO.setInsertTime1(recharge.getInsertTime());
                    SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                    String format1 = format.format(recharge.getInsertTime());
                    userDetailVO.setInsertTime(format1);
                    detail.add(userDetailVO);
                }
            }
            if (collect.contains("5")){
                // 查询红包发放记录
                Wrapper<RedPackage> eq5 = new EntityWrapper<RedPackage>();
                if (year != null && month != null) {
                    LocalDate startDate = LocalDate.of(year, month, 1);
                    LocalDate endDate = startDate.plusMonths(1).minusDays(1);
                    eq5.ge("insertTime", startDate).le("insertTime", endDate);
                }
                List<RedPackage> redPackages = redPackageService.selectList(eq5);
                for (RedPackage redPackage : redPackages) {
                    if (appUserService.getAppUser().getInsertTime().compareTo(redPackage.getInsertTime())>0){
                        continue;
                    }
                    UserDetailVO userDetailVO = new UserDetailVO();
                    userDetailVO.setAmount("+"+redPackage.getAmount());
                    userDetailVO.setType("平台红包");
                    userDetailVO.setInsertTime1(redPackage.getInsertTime());
                    SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                    String format1 = format.format(redPackage.getInsertTime());
                    userDetailVO.setInsertTime(format1);
                    detail.add(userDetailVO);
                }
            }
            List<UserDetailVO> sortedList = detail.stream()
                    .sorted(Comparator.comparing(UserDetailVO::getInsertTime1).reversed())
                    .collect(Collectors.toList());
            List<UserDetailVO> testing = testing(sortedList.size(), pageNum, pageSize, sortedList);
            walletVO.setDetails(testing);
            return ResultUtil.success(walletVO);
        }
    }
    @ResponseBody
    @PostMapping("/base/appUser/appleWalletCourse")
    @ApiOperation(value = "苹果购课、购买套餐列表", tags = {"我的"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
            @ApiImplicitParam(value = "年", name = "year", dataType = "int"),
            @ApiImplicitParam(value = "月", name = "month", dataType = "int"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int"),
    })
    public ResultUtil<WalletVO> appleWalletCourse(Integer year,Integer month,Integer pageNum,Integer pageSize) {
        WalletVO walletVO = new WalletVO();
        List<UserDetailVO> detail = new ArrayList<>();
        AppUser appUser3 = appUserService.getAppUser();
        if (appUser3 == null){
            return ResultUtil.tokenErr("登录失效");
        }
        Integer id = appUserService.getAppUser().getId();
        BigDecimal balance = appUserService.getAppUser().getBalance();
        walletVO.setBalance(balance);
        Wrapper<Recharge> eq1 = new EntityWrapper<Recharge>()
                .eq("userId", id)
                .eq("state", 2);
        // 如果传递了年份和月份,则添加时间条件
        if (year != null && month != null) {
            LocalDate startDate = LocalDate.of(year, month, 1);
            LocalDate endDate = startDate.plusMonths(1).minusDays(1);
            eq1.ge("insertTime", startDate).le("insertTime", endDate);
        }
        // 查询充值记录
//        List<Recharge> recharges = rechargeService.selectList(eq1);
//        for (Recharge recharge : recharges) {
//            UserDetailVO userDetailVO = new UserDetailVO();
//            userDetailVO.setAmount("+"+recharge.getAmount().toString());
//            userDetailVO.setType("充值");
//            userDetailVO.setInsertTime1(recharge.getInsertTime());
//            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
//            String format1 = format.format(recharge.getInsertTime());
//            userDetailVO.setInsertTime(format1);
//            detail.add(userDetailVO);
//        }
        // 查询购课记录 只查询钱包支付的
        Wrapper<OrderCourse> eq2 = new EntityWrapper<OrderCourse>()
                .eq("userId", id)
//                .eq("payType", 3)
                .eq("state", 2);
        // 如果传递了年份和月份,则添加时间条件
        if (year != null && month != null) {
            LocalDate startDate = LocalDate.of(year, month, 1);
            LocalDate endDate = startDate.plusMonths(1).minusDays(1);
            eq2.ge("insertTime", startDate).le("insertTime", endDate);
        }
        List<OrderCourse> orderCourses = orderCourseService.selectList(eq2);
        for (OrderCourse orderCours : orderCourses) {
            UserDetailVO userDetailVO = new UserDetailVO();
            userDetailVO.setAmount("-"+orderCours.getRealMoney());
            userDetailVO.setType("购买课程");
            userDetailVO.setInsertTime1(orderCours.getInsertTime());
            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
            String format1 = format.format(orderCours.getInsertTime());
            userDetailVO.setInsertTime(format1);
            detail.add(userDetailVO);
        }
        Wrapper<Order> eq = new EntityWrapper<Order>()
                .eq("userId", id)
//                .eq("payType", 3)
                .eq("state", 2);
        // 如果传递了年份和月份,则添加时间条件
        if (year != null && month != null) {
            LocalDate startDate = LocalDate.of(year, month, 1);
            LocalDate endDate = startDate.plusMonths(1).minusDays(1);
            eq.ge("insertTime", startDate).le("insertTime", endDate);
        }
        List<Order> orders = orderService.selectList(eq);
        // 查询购买套餐记录 只查询钱包支付的
        for (Order order : orders) {
            UserDetailVO userDetailVO = new UserDetailVO();
            userDetailVO.setAmount("-"+order.getRealMoney());
            userDetailVO.setType("购买套餐");
            userDetailVO.setInsertTime1(order.getInsertTime());
            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
            String format1 = format.format(order.getInsertTime());
            userDetailVO.setInsertTime(format1);
            detail.add(userDetailVO);
        }
        // 查询提现记录
//        Wrapper<Withdrawal> eq3 = new EntityWrapper<Withdrawal>()
//                .eq("userId", id);
//        // 如果传递了年份和月份,则添加时间条件
//        if (year != null && month != null) {
//            LocalDate startDate = LocalDate.of(year, month, 1);
//            LocalDate endDate = startDate.plusMonths(1).minusDays(1);
//            eq3.ge("insertTime", startDate).le("insertTime", endDate);
//        }
//        List<Withdrawal> withdrawals = withdrawalService.selectList(eq3);
//        for (Withdrawal withdrawal : withdrawals) {
//            UserDetailVO userDetailVO = new UserDetailVO();
//            switch (withdrawal.getState()){
//                case 1:
//                    userDetailVO.setAmount("-"+withdrawal.getAmount());
//                    userDetailVO.setType("提现");
//                    break;
//                case 2:
//                    userDetailVO.setAmount("-"+withdrawal.getAmount());
//                    userDetailVO.setType("提现");
//                    break;
//                case 3:
//                    userDetailVO.setAmount("+"+withdrawal.getAmount());
//                    userDetailVO.setType("提现失败");
//                    break;
//            }
//            userDetailVO.setInsertTime1(withdrawal.getInsertTime());
//            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
//            String format1 = format.format(withdrawal.getInsertTime());
//            userDetailVO.setInsertTime(format1);
//            detail.add(userDetailVO);
//        }
        // 查询是否有邀请过用户 获得消费奖励
//        Wrapper<Invite> eq4 = new EntityWrapper<Invite>()
//                .eq("giftUserId", id);
//        // 如果传递了年份和月份,则添加时间条件
//        if (year != null && month != null) {
//            LocalDate startDate = LocalDate.of(year, month, 1);
//            LocalDate endDate = startDate.plusMonths(1).minusDays(1);
//            eq4.ge("insertTime", startDate).le("insertTime", endDate);
//        }
//        eq4.eq("type",1);
//        List<Invite> giftUserId = inviteService.selectList(eq4);
//        for (Invite invite : giftUserId) {
//            UserDetailVO userDetailVO = new UserDetailVO();
//            userDetailVO.setAmount("+"+invite.getAmount());
//            AppUser appUser = appUserService.selectById(invite.getUserId());
//            userDetailVO.setType("好友消费:("+appUser.getName()+"消费了"+invite.getConsume()+"元)");
//            userDetailVO.setInsertTime1(invite.getInsertTime());
//            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
//            String format1 = format.format(invite.getInsertTime());
//            userDetailVO.setInsertTime(format1);
//            detail.add(userDetailVO);
//        }
        // 查询红包发放记录
//        Wrapper<RedPackage> eq5 = new EntityWrapper<RedPackage>();
//        if (year != null && month != null) {
//            LocalDate startDate = LocalDate.of(year, month, 1);
//            LocalDate endDate = startDate.plusMonths(1).minusDays(1);
//            eq5.ge("insertTime", startDate).le("insertTime", endDate);
//        }
//        List<RedPackage> redPackages = redPackageService.selectList(eq5);
//        for (RedPackage redPackage : redPackages) {
//            if (appUserService.getAppUser().getInsertTime().compareTo(redPackage.getInsertTime())>0){
//                continue;
//            }
//            UserDetailVO userDetailVO = new UserDetailVO();
//            userDetailVO.setAmount("+"+redPackage.getAmount());
//            userDetailVO.setType("平台红包");
//            userDetailVO.setInsertTime1(redPackage.getInsertTime());
//            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
//            String format1 = format.format(redPackage.getInsertTime());
//            userDetailVO.setInsertTime(format1);
//            detail.add(userDetailVO);
//        }
        List<UserDetailVO> sortedList = detail.stream()
                .sorted(Comparator.comparing(UserDetailVO::getInsertTime1).reversed())
                .collect(Collectors.toList());
        List<UserDetailVO> testing = testing(sortedList.size(), pageNum, pageSize, sortedList);
        walletVO.setDetails(testing);
        return ResultUtil.success(walletVO);
    }
    public static List<UserDetailVO> testing(long total, long current, long size, List<UserDetailVO> str){
        List<UserDetailVO> result = new ArrayList<>();
        //获取初始化分页结构
@@ -540,6 +1124,9 @@
    })
    public ResultUtil changeConstellation(String consName ) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        appUser.setConstellation(consName);
        appUserService.updateById(appUser);
        return ResultUtil.success();
@@ -585,6 +1172,9 @@
        int month = currentDate.getMonthValue();
        int day = currentDate.getDayOfMonth();
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        if (!StringUtils.hasLength(appUser.getConstellation())){
            // 根据月份和日期确定星座
            consName = getZodiacSign(month, day);
@@ -609,6 +1199,10 @@
            @ApiImplicitParam(value = "动态id", name = "findId", dataType = "int"),
    })
    public ResultUtil feedBack(Integer findId) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        Find find = findService.selectById(findId);
        find.setIsDelete(1);
        findService.updateById(find);
@@ -624,8 +1218,12 @@
            @ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int")
    })
    public ResultUtil<List<FindVO>> myFind(Integer pageNum,Integer pageSize) {
        Integer id = appUserService.getAppUser().getId();
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        Integer id = appUserService.getAppUser().getId();
        List<String> strings = new ArrayList<>();
        strings.add("insertTime");
        List<Find> finds = findService.selectList(new EntityWrapper<Find>()
@@ -649,6 +1247,27 @@
        }
        List<FindVO> findVOS = testing3(res.size(), pageNum, pageSize, res);
        return ResultUtil.success(findVOS);
    }
    public static List<BlackListVO> testing4(long total, long current, long size, List<BlackListVO> str){
        List<BlackListVO> result = new ArrayList<>();
        //获取初始化分页结构
        com.stylefeng.guns.modular.system.util.Page<BlackListVO> page = new Page().getPage(total, size, current - 1);
        //获取集合下标初始值
        long startIndex = page.getStartIndex();
        //获取集合下标结束值
        long endInddex = 0;
        if(startIndex + page.getCurrent() >= total || size > total){
            endInddex = total;
        }else {
            endInddex = Math.min(startIndex + page.getSize(), total);
        }
        //如果输入的开始查询下标大于集合大小,则查询为空值
        if(startIndex > total){
            result = Collections.emptyList();
        }else{
            result = str.subList((int)startIndex,(int)endInddex);
        }
        return result;
    }
    public static List<FindVO> testing3(long total, long current, long size, List<FindVO> str){
        List<FindVO> result = new ArrayList<>();
@@ -679,6 +1298,10 @@
            @ApiImplicitParam(name = "title", value = "标题"),
    })
    public ResultUtil<List<UseGuide>> useGuide(String title) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        EntityWrapper<UseGuide> wrapper = new EntityWrapper<>();
        List<String> strings = new ArrayList<>();
        strings.add("sort");
@@ -699,6 +1322,9 @@
    })
    public ResultUtil setUnit(Integer type) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        appUser.setUnit(type);
        appUserService.updateById(appUser);
        return ResultUtil.success("设置成功");
@@ -714,6 +1340,9 @@
    public ResultUtil setWeight(Integer type ,Double weight) {
        Double temp = 0.0;
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        switch (appUser.getUnit()){
            case 1:
                temp = weight;
@@ -771,6 +1400,10 @@
            @ApiImplicitParam(name = "img", value = "图片地址,多张逗号隔开")
    })
    public ResultUtil feedBack(String content,String img) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        AuditVO content1 = auditUtil.content(content);
        switch (content1.getType()){
            case "terrorism":
@@ -805,6 +1438,9 @@
    public ResultUtil<UserInfoVO> userInfo() {
        UserInfoVO userInfoVO = new UserInfoVO();
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        userInfoVO.setConstellation(appUser.getConstellation());
        BeanUtils.copyProperties(appUser,userInfoVO);
        if (appUser.getConstellation() == null){
@@ -1033,12 +1669,7 @@
        return temp;
    }
    public static void main(String[] args) {
        UserInfoVO userInfoVO = new UserInfoVO();
        BMIVO bmi = getBMI(userInfoVO, 160, 2, 58D);
        System.err.println(bmi);
    }
    private static BMIVO getBMI(UserInfoVO userInfoVO, Integer height,Integer gender, Double temp) {
        String url = "http://apis.juhe.cn/fapig/calculator/weight";
        Map<String, String> params = new HashMap<String, String>();
@@ -1111,8 +1742,14 @@
        }
        return null;
    }
    public static void main(String[] args) {
        UserInfoVO userInfoVO = new UserInfoVO();
        String index = getIndex(80, 1, 3d, 3L);
        System.err.println(index);
    }
    // 获取健康指数
    private String getIndex(Integer height,Integer gender, Double temp,Long age) {
    private static String getIndex(Integer height,Integer gender, Double temp,Long age) {
        String url = "http://apis.juhe.cn/fapig/healthy/bmr";
        Map<String, String> params = new HashMap<String, String>();
        params.put("key", "c28bcb61589b8943ea35887e4fd35afe"); // 在个人中心->我的数据,接口名称上方查看
@@ -1388,6 +2025,10 @@
    })
    public ResultUtil<List<CourseList>> collectCourse(CourseQuery req) {
        req.setPageNum((req.getPageNum() - 1) * req.getPageSize());
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        Integer id = appUserService.getAppUser().getId();
        // 查询用户已收藏的课程ids
        List<Integer> courseIds = collectService.selectList(new EntityWrapper<UserCollect>()
@@ -1397,6 +2038,17 @@
            courseIds.add(-1);
        }
        req.setCourseIds(courseIds);
        List<String> strings = new ArrayList<>();
        if (req.getPositionName1()!=null){
            String positionName1 = req.getPositionName1();
            if (!positionName1.equals("全部")){
                strings.add(req.getPositionName1());
                req.setPositionName(strings);
            }else{
                req.setPositionName(new ArrayList<String>());
            }
        }
        // 查询出收藏的课程 并且将免费的展示在最前面
        List<CourseList> res = courseService.courseSearch(req);
        for (CourseList re : res) {
@@ -1433,6 +2085,10 @@
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
    })
    public ResultUtil updateUserInfo(UpdateAppUserDTO dto) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        if(StringUtils.hasLength(dto.getHeadImg())){
            AuditVO image = auditUtil.image(dto.getHeadImg());
            switch (image.getType()){
@@ -1475,7 +2131,7 @@
            }
        }
        AppUser appUser = appUserService.getAppUser();
        // 根据当前用户所选择的单位 将weight置换成公斤存储
        if (dto.getWeight()!=null){
            // 本次体重
@@ -1532,6 +2188,9 @@
    public ResultUtil<UserInfoVO> getUserInfo() {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        UserInfoVO userInfoVO = new UserInfoVO();
        BeanUtils.copyProperties(appUser,userInfoVO);
        if (appUser.getHeight()!=null && appUser.getGender()!=null &&appUser.getWeight()!=null ){
@@ -1541,6 +2200,7 @@
            System.err.println(appUser.getWeight());
            BMIVO bmi = getBMI(userInfoVO,appUser.getHeight(),appUser.getGender(),appUser.getWeight());
            userInfoVO.setBMI(bmi.getBmi());
            userInfoVO.setBMIInfo(bmi.getMsg());
        }else{
            userInfoVO.setBMI("0");
        }
@@ -1602,6 +2262,10 @@
            @ApiImplicitParam(name = "code", value = "邀请码"),
    })
    public ResultUtil updatePhone(String phone, String code) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        // 原手机号码
        String phone1 = appUserService.getAppUser().getPhone();
        // 判断手机验证码是否匹配
@@ -1631,7 +2295,7 @@
        if (appUsers.size()>0){
            return ResultUtil.error("该手机号已注册");
        }
        AppUser appUser = appUserService.getAppUser();
        appUser.setPhone(phone);
        appUser.setAccount(phone);
        appUserService.updateById(appUser);
@@ -1647,6 +2311,9 @@
    })
    public ResultUtil deleteAppUser( ) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        appUser.setState(3);
        appUserService.updateById(appUser);
        // 清除token
@@ -1662,6 +2329,10 @@
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
    })
    public ResultUtil setAddress(Recipient dto) {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        Integer id = appUserService.getAppUser().getId();
        Recipient userId = recipientService.selectOne(new EntityWrapper<Recipient>()
                .eq("userId", id));
@@ -1684,6 +2355,10 @@
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header")
    })
    public ResultUtil<Recipient> getAddress() {
        AppUser appUser = appUserService.getAppUser();
        if (appUser == null){
            return ResultUtil.tokenErr("登录失效");
        }
        Integer id = appUserService.getAppUser().getId();
        Recipient userId = recipientService.selectOne(new EntityWrapper<Recipient>()
                .eq("userId", id));