作者 王勇

修改增加用户,编辑用户的分组校验;

查询用户列表的结果集中取消掉密码
... ... @@ -11,6 +11,8 @@ import com.tianbo.warehouse.model.UserRole;
import com.tianbo.warehouse.security.CustomUserDetailService;
import com.tianbo.warehouse.security.filter.JwtTokenUtil;
import com.tianbo.warehouse.service.UserService;
import com.tianbo.warehouse.service.validated.InsertUser;
import com.tianbo.warehouse.service.validated.UpdateUser;
import com.tianbo.warehouse.util.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
... ... @@ -20,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
... ... @@ -68,7 +71,7 @@ public class UserController {
@LogAnnotation(moduleName = "用户管理",operate = "用户编辑")
@PutMapping("/edit")
public ResultJson updateUserById(@RequestBody @Valid USERS user){
public ResultJson updateUserById(@Validated(UpdateUser.class) @RequestBody USERS user){
int i = userService.updateByPrimaryKeySelective(user);
ResultJson resultJson = new ResultJson();
return i==1 ? new ResultJson("200","success") :new ResultJson("500","update faild");
... ... @@ -86,7 +89,7 @@ public class UserController {
@UserPasswordMd5
@LogAnnotation(moduleName = "用户管理",operate = "用户添加")
@PostMapping("/add")
public ResultJson addUser(@RequestBody @Valid USERS user, HttpServletRequest request, HttpServletResponse response, BindingResult bindingResult){
public ResultJson addUser(@RequestBody @Validated(InsertUser.class) USERS user, HttpServletRequest request, HttpServletResponse response, BindingResult bindingResult){
if (bindingResult.hasErrors()){
String s = bindingResult.toString();
... ...
... ... @@ -2,6 +2,8 @@ package com.tianbo.warehouse.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.tianbo.warehouse.service.validated.InsertUser;
import com.tianbo.warehouse.service.validated.UpdateUser;
import com.tianbo.warehouse.validate.CheckUserExist;
import org.hibernate.validator.constraints.Length;
import org.springframework.security.core.GrantedAuthority;
... ... @@ -18,17 +20,17 @@ public class USERS implements UserDetails {
private static final long serialVersionUID = 1L;
@DecimalMin("1")
@DecimalMin(value = "1",groups={InsertUser.class, UpdateUser.class})
private Integer userId;
@NotBlank(message="用户名不能为空")
@Length(min = 5, max = 11, message = "username 长度必须在 {min} - {max} 之间")
@CheckUserExist(message = "用户已存在")
@NotBlank(message="用户名不能为空",groups={InsertUser.class, UpdateUser.class})
@Length(min = 5, max = 11, message = "username 长度必须在 {min} - {max} 之间",groups={InsertUser.class, UpdateUser.class})
@CheckUserExist(message = "用户已存在",groups=InsertUser.class)
private String username;
@NotNull
@NotBlank(message="密码不能为空")
@Length(min = 6, max = 22, message = "密码 长度必须在 {min} - {max} 之间")
@NotNull(message="密码不能为null",groups=InsertUser.class)
@NotBlank(message="密码不能为空",groups=InsertUser.class)
@Length(min = 6, max = 22, message = "密码 长度必须在 {min} - {max} 之间",groups=InsertUser.class)
private String password;
private Date birthday;
... ... @@ -275,4 +277,4 @@ public class USERS implements UserDetails {
}
return auths;
}
}
\ No newline at end of file
}
... ...
package com.tianbo.warehouse.service.validated;
/**
* @author 子诚
* Description:
* 时间:2020/5/11 10:32
*/
public interface InsertUser {
}
... ...
package com.tianbo.warehouse.service.validated;
/**
* @author 子诚
* Description:
* 时间:2020/5/11 10:33
*/
public interface UpdateUser {
}
... ...
... ... @@ -40,7 +40,7 @@
user_id, username, birthday, sex, address, state, mobilePhone,userFace, realName, email, age
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
select
<include refid="Base_Column_List" />
from users
where user_id = #{userId,jdbcType=INTEGER}
... ... @@ -53,7 +53,9 @@
</select>
<select id="selectAllUser" resultMap="BaseResultMap" parameterType="com.tianbo.warehouse.model.USERS" >
select
<include refid="Base_Column_List" />
<!-- <include refid="Base_Column_List" />-->
user_id, username, birthday, sex, address, state, mobilePhone, creatTime,
updateTime, userFace, realName, email, age,company_id
from users
WHERE 1=1
<if test=" username != null" >
... ... @@ -68,14 +70,14 @@
where user_id = #{userId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.tianbo.warehouse.model.USERS" >
insert into users (user_id, username, password,
birthday, sex, address,
state, mobilePhone, creatTime,
insert into users (user_id, username, password,
birthday, sex, address,
state, mobilePhone, creatTime,
updateTime, userFace, realName,
email, age)
values (#{userId,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{birthday,jdbcType=TIMESTAMP}, #{sex,jdbcType=CHAR}, #{address,jdbcType=VARCHAR},
#{state,jdbcType=BIT}, #{mobilephone,jdbcType=VARCHAR}, #{creattime,jdbcType=TIMESTAMP},
values (#{userId,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{birthday,jdbcType=TIMESTAMP}, #{sex,jdbcType=CHAR}, #{address,jdbcType=VARCHAR},
#{state,jdbcType=BIT}, #{mobilephone,jdbcType=VARCHAR}, #{creattime,jdbcType=TIMESTAMP},
#{updatetime,jdbcType=TIMESTAMP}, #{userface,jdbcType=VARCHAR}, #{realname,jdbcType=VARCHAR},
#{email,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER})
</insert>
... ... @@ -228,4 +230,4 @@
age = #{age,jdbcType=INTEGER}
where user_id = #{userId,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
</mapper>
... ...