44323
2024-05-22 57145eb45c9b339eecc97a5037c60c2f8da8f8fd
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.constant.RedisConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.redis.service.RedisService;
@@ -65,9 +66,9 @@
    @PostMapping("/vipInfo")
    @ApiOperation(value = "会员中心-获取会员说明、当前登录用户是否为会员、会员购买规格", tags = {"家长端-个人中心"})
    public AjaxResult<List<VipInfoVO>> vipInfo() {
    public R<List<VipInfoVO>> vipInfo() {
        if (tokenService.getLoginUser1() == null) {
            return AjaxResult.tokenError("登录失效", new Object());
            throw new GlobalException("登录失效!");
        }
        List<VipInfoVO> vipInfoVOS = new ArrayList<>();
        List<TVipSet> data = managementClient.getVipSet1().getData();
@@ -92,7 +93,7 @@
            vipInfoVO.setAmount(datum.getAmount());
            vipInfoVOS.add(vipInfoVO);
        }
        return AjaxResult.ok(vipInfoVOS);
        return R.ok(vipInfoVOS);
    }
    @Autowired
@@ -308,38 +309,38 @@
    @PostMapping("/getPage")
    @ApiOperation(value = "获取注意事项", tags = {"家长端-注意事项"})
    public AjaxResult<String> getPage() {
    public R<String> getPage() {
        List<TPage> data = managementClient.getPage1().getData();
        for (TPage datum : data) {
            if (datum.getType() == 4) {
                return AjaxResult.success(datum.getImg());
                return R.ok(datum.getImg());
            }
        }
        return AjaxResult.success();
        return R.ok();
    }
    @PostMapping("/parentPage")
    @ApiOperation(value = "平板", tags = {"家长端-启动页"})
    public AjaxResult<String> parentPage() {
    public R<String> parentPage() {
        List<TPage> data = managementClient.getPage1().getData();
        for (TPage datum : data) {
            if (datum.getType() == 3) {
                return AjaxResult.success(datum.getImg());
                return R.ok(datum.getImg());
            }
        }
        return AjaxResult.success();
        return R.ok();
    }
    @PostMapping("/parentPage1")
    @ApiOperation(value = "手机", tags = {"家长端-启动页"})
    public AjaxResult<String> parentPage1() {
    public R<String> parentPage1() {
        List<TPage> data = managementClient.getPage1().getData();
        for (TPage datum : data) {
            if (datum.getType() == 2) {
                return AjaxResult.success(datum.getImg());
                return R.ok(datum.getImg());
            }
        }
        return AjaxResult.success();
        return R.ok();
    }
    @PostMapping("/getProtocol")
@@ -347,28 +348,28 @@
    @ApiImplicitParams({
            @ApiImplicitParam(value = "类型 1用户 2隐私 3注销", name = "type", dataType = "string", required = true),
    })
    public AjaxResult<String> getProtocol(Integer type) {
    public R<String> getProtocol(Integer type) {
        String data = managementClient.agreement1(type).getData();
        return AjaxResult.success(data);
        return R.ok(data);
    }
    @PostMapping("/useGuide")
    @ApiOperation(value = "使用指南", tags = {"家长端-使用指南"})
    public AjaxResult<PageInfo<TUseGuide>> useGuide(@RequestBody UseGuideQuery query) {
    public R<PageInfo<TUseGuide>> useGuide(@RequestBody UseGuideQuery query) {
        PageInfo<TUseGuide> data = managementClient.useGuide1(query).getData();
        return AjaxResult.success(data);
        return R.ok(data);
    }
    @PostMapping("/feedBack")
    @ApiOperation(value = "反馈", tags = {"家长端-意见反馈"})
    public AjaxResult feedBack(@RequestBody TFeedback dto) {
    public R<String> feedBack(@RequestBody TFeedback dto) {
        if (tokenService.getLoginUser1() == null) {
            return AjaxResult.tokenError("登录失效", new Object());
            throw new GlobalException("登录失效!");
        }
        LoginUserParent loginUser1 = tokenService.getLoginUser1();
        dto.setUserId(loginUser1.getUserid());
        managementClient.addFeedBack(dto);
        return AjaxResult.success("反馈成功");
        return R.ok("反馈成功");
    }
    @PostMapping("/parentLogin")
@@ -377,25 +378,25 @@
            @ApiImplicitParam(value = "手机号", name = "phone", dataType = "string", required = true),
            @ApiImplicitParam(value = "验证码", name = "phoneCode", dataType = "string", required = true)
    })
    public AjaxResult login(String phone, String phoneCode) {
    public R<Map<String,Object>> login(String phone, String phoneCode) {
        TUser tUser1 = userService.getOne(new QueryWrapper<TUser>()
                .ne("state", 3)
                .eq("phone", phone));
        if (tUser1 != null) {
            if (tUser1.getState() == 2) {
                return AjaxResult.error("登录失败,您的账号已被冻结!");
                throw new GlobalException("登录失败,您的账号已被冻结!");
            }
        } else {
            // 手机验证码校验
            Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
            if (null == redisPhoneCode) {
                return AjaxResult.error("登录失败,手机验证码已过期!");
                throw new GlobalException("登录失败,手机验证码已过期!");
            } else {
                // redis 验证码的value 为 code:时间戳
                String rCodeAndTime = String.valueOf(redisPhoneCode);
                String rCode = rCodeAndTime.split(":")[0];
                if (!rCode.equalsIgnoreCase(phoneCode)) {
                    return AjaxResult.error("登录失败,手机验证码输入有误!");
                    throw new GlobalException("登录失败,手机验证码输入有误!");
                } else {
                    tUser1 = getUser(phone);
                    userService.save(tUser1);
@@ -410,7 +411,7 @@
        HashMap<String, Object> map = new HashMap<>();
        map.put("token", tokenService.createToken1(loginUserParent));
        // 获取登录token
        return AjaxResult.success(map);
        return R.ok(map);
    }
    /**
@@ -420,7 +421,7 @@
     */
    @PostMapping("/studyLogin")
    @ApiOperation(value = "学习端-登录", tags = {"学习端-登录"})
    public AjaxResult studyLogin(@RequestBody @Validated RegisterPhoneRequest phoneRequest) {
    public R<Map<String,Object>> studyLogin(@RequestBody @Validated RegisterPhoneRequest phoneRequest) {
        String phone = phoneRequest.getPhone();
        String phoneCode = phoneRequest.getPhoneCode();
        TUser user = userService.getOne(new QueryWrapper<TUser>()
@@ -428,19 +429,19 @@
                .eq("phone", phone));
        if (user != null) {
            if (user.getState() == 2) {
                return AjaxResult.error("登录失败,您的账号已被冻结!");
                throw new GlobalException("登录失败,您的账号已被冻结!");
            }
        } else {
            // 手机验证码校验
            Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
            if (null == redisPhoneCode) {
                return AjaxResult.error("登录失败,手机验证码已过期!");
                throw new GlobalException("登录失败,手机验证码已过期!");
            } else {
                // redis 验证码的value 为 code:时间戳
                String rCodeAndTime = String.valueOf(redisPhoneCode);
                String rCode = rCodeAndTime.split(":")[0];
                if (!rCode.equalsIgnoreCase(phoneCode)) {
                    return AjaxResult.error("登录失败,手机验证码输入有误!");
                    throw new GlobalException("登录失败,手机验证码输入有误!");
                } else {
                    user = getUser(phone);
                    userService.save(user);
@@ -456,7 +457,7 @@
        HashMap<String, Object> map = new HashMap<>();
        map.put("token", tokenService.createTokenStudy(loginUserParent));
        // 获取登录token
        return AjaxResult.success(map);
        return R.ok(map);
    }
    private TUser getUser(String phone) {
@@ -481,8 +482,8 @@
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号", name = "phone", dataType = "string", required = true),
    })
    public AjaxResult sendPhoneCode(@RequestParam String phone) {
        return userService.phoneCode(phone) ? AjaxResult.success() : AjaxResult.error();
    public R sendPhoneCode(@RequestParam String phone) {
        return userService.phoneCode(phone) ? R.ok() : R.fail();
    }
    /**
@@ -490,7 +491,7 @@
     */
    @GetMapping("/shareInfo")
    @ApiOperation(value = "微信分享信息", tags = {"微信分享信息"})
    public AjaxResult shareInfo() {
    public R<TSysSet> shareInfo() {
        // 分享信息
        TSysSet data = managementClient.shareInfo().getData();
        Integer userid = tokenService.getLoginUserStudy().getUserid();
@@ -508,7 +509,7 @@
            record.setUserId(userid);
            userShareService.save(record);
        }
        return AjaxResult.success();
        return R.ok(data);
    }
    /**
@@ -527,9 +528,9 @@
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
    })
    public AjaxResult deleteUser() {
    public R<String> deleteUser() {
        if (tokenService.getLoginUser1() == null) {
            return AjaxResult.tokenError("登录失效");
            throw new GlobalException("登录失效!");
        }
        Integer userid = tokenService.getLoginUser1().getUserid();
        TUser tUser = userService.getById(userid);
@@ -538,7 +539,7 @@
        userService.updateById(tUser);
        userService.removeById(tUser);
        return AjaxResult.success("注销成功");
        return R.ok("注销成功");
    }
    @PostMapping("/logout")
@@ -546,9 +547,9 @@
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
    })
    public AjaxResult logout(HttpServletRequest request) {
    public R<String> logout(HttpServletRequest request) {
        if (tokenService.getLoginUser1() == null) {
            return AjaxResult.tokenError("登录失效");
            throw new GlobalException("登录失效!");
        }
        String token = SecurityUtils.getToken(request);
        if (com.ruoyi.common.core.utils.StringUtils.isNotEmpty(token)) {
@@ -556,7 +557,7 @@
            AuthUtil.logoutByToken1(token);
        }
        // todo 清除token
        return AjaxResult.success("退出登录成功");
        return R.ok("退出登录成功");
    }
    @PostMapping("/updateUserInfo")
@@ -567,7 +568,7 @@
            @ApiImplicitParam(name = "phone", value = "电话 改什么就只传什么"),
            @ApiImplicitParam(name = "headImg", value = "头像 改什么就只传什么"),
    })
    public AjaxResult updateUserInfo(String name, String phone, String headImg) {
    public R<String> updateUserInfo(String name, String phone, String headImg) {
        // todo 获取用户id
        Integer userid = tokenService.getLoginUser1().getUserid();
        TUser byId = userService.getById(userid);
@@ -582,13 +583,13 @@
//            }
            if (phone.equals(byId.getPhone())) {
                return AjaxResult.error("更换的手机号不能和原手机号相同");
                return R.fail("更换的手机号不能和原手机号相同!");
            }
            List<TUser> list = userService.list(new QueryWrapper<TUser>()
                    .eq("phone", phone)
                    .ne("state", 3));
            if (list.size() > 0) {
                return AjaxResult.error("更换的手机号已被使用", new Object());
                return R.fail("更换的手机号已被使用!");
            }
            byId.setPhone(phone);
        }
@@ -596,7 +597,7 @@
            byId.setHeadImg(headImg);
        }
        userService.saveOrUpdate(byId);
        return AjaxResult.success("修改成功");
        return R.ok("修改成功");
    }
    @ResponseBody