提交 ee8ffa62 编写于 作者: F fengyw

feat: 用户输入参数校验,并过滤手机号

上级 e77e23d2
package com.roncoo.education.user.feign.interfaces.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
......@@ -18,40 +14,20 @@ import java.time.LocalDateTime;
*/
@Data
@Accessors(chain = true)
@ApiModel(description = "ADMIN-用户信息查看")
public class UsersVO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
private Long id;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
private LocalDateTime gmtCreate;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "修改时间")
private LocalDateTime gmtModified;
@ApiModelProperty(value = "状态(1:正常,0:禁用)")
private Integer statusId;
@ApiModelProperty(value = "手机号码")
private String mobile;
@ApiModelProperty(value = "昵称")
private String nickname;
@ApiModelProperty(value = "用户性别(1男,2女,3保密)")
private Integer userSex;
@ApiModelProperty(value = "用户年龄")
private Integer userAge;
@ApiModelProperty(value = "用户头像")
private String userHead;
@ApiModelProperty(value = "备注")
private String remark;
}
......@@ -56,6 +56,7 @@ public class AdminUserCourseCommentBiz extends BaseBiz {
if (StringUtils.hasText(req.getCommentText())) {
c.andCommentTextLike(PageUtil.like(req.getCommentText()));
}
example.setOrderByClause("id desc");
Page<UserCourseComment> page = dao.page(req.getPageCurrent(), req.getPageSize(), example);
Page<AdminUserCourseCommentPageResp> respPage = PageUtil.transform(page, AdminUserCourseCommentPageResp.class);
if (CollUtil.isNotEmpty(respPage.getList())) {
......
......@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
/**
......@@ -51,7 +52,7 @@ public class AuthUserCourseCommentController {
*/
@ApiOperation(value = "课程评论添加", notes = "用户进行课程评论")
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<String> add(@RequestBody AuthUserCourseCommentReq req) {
public Result<String> add(@RequestBody @Valid AuthUserCourseCommentReq req) {
return biz.add(req);
}
......
......@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
......@@ -28,6 +29,7 @@ public class AuthUserCourseCommentReq implements Serializable {
@ApiModelProperty(value = "评论ID,被评论的ID", required = false)
private Long commentId;
@NotBlank(message = "请填写评论内容")
@ApiModelProperty(value = "评论内容")
private String commentText;
}
package com.roncoo.education.course.service.biz;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.roncoo.education.common.core.base.Page;
import com.roncoo.education.common.core.base.PageUtil;
import com.roncoo.education.common.core.base.Result;
......@@ -146,7 +148,12 @@ public class CourseBiz extends BaseBiz {
List<Long> userIds = userCourseCommentPage.getList().stream().map(UserCourseComment::getUserId).collect(Collectors.toList());
Map<Long, UsersVO> usersVOMap = feignUsers.listByIds(userIds);
for (CourseCommentResp commentResp : resp.getList()) {
commentResp.setUsersVO(usersVOMap.get(commentResp.getUserId()));
UsersVO usersVO = usersVOMap.get(commentResp.getUserId());
usersVO.setMobile(DesensitizedUtil.mobilePhone(usersVO.getMobile()));
if (StrUtil.isBlank(usersVO.getNickname())) {
usersVO.setNickname(usersVO.getMobile());
}
commentResp.setUsersVO(usersVO);
}
}
return Result.success(resp);
......
......@@ -2,6 +2,7 @@ package com.roncoo.education.user.service.api.biz;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.roncoo.education.common.cache.CacheRedis;
......@@ -129,6 +130,8 @@ public class ApiUsersBiz extends BaseBiz {
user.setMobile(mobile);
user.setMobileSalt(IdUtil.simpleUUID());
user.setMobilePsw(DigestUtil.sha1Hex(user.getMobileSalt() + password));
// 默认8位随机字符串
user.setNickname(RandomUtil.randomString(8));
userDao.save(user);
return user;
}
......
......@@ -9,6 +9,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
/**
......@@ -37,7 +38,7 @@ public class AuthUsersController {
@ApiOperation(value = "更新接口", notes = "更新当前用户的基本信息")
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public Result<String> update(@RequestBody AuthUsersReq req) {
public Result<String> update(@RequestBody @Valid AuthUsersReq req) {
return biz.update(req);
}
......
......@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
......@@ -22,12 +24,15 @@ public class AuthUsersReq implements Serializable {
private static final long serialVersionUID = 1L;
@NotBlank(message = "请填写昵称")
@ApiModelProperty(value = "昵称")
private String nickname;
@NotNull(message = "请选择性别")
@ApiModelProperty(value = "用户性别(1男,2女,3保密)")
private Integer userSex;
@NotNull(message = "请填写年龄")
@ApiModelProperty(value = "用户年龄")
private Integer userAge;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册