Skip to content

Commit

Permalink
用户id修改
Browse files Browse the repository at this point in the history
  • Loading branch information
angui57 committed Dec 8, 2023
1 parent 1b5181b commit 046f3c8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
public class UserController {
@Autowired
private UserService userService;
@Autowired
private SystemService systemService;

/**
* @author zhuxinyu 2023-11-28
* 用户登录
Expand Down Expand Up @@ -76,10 +75,10 @@ public String userSelect(HttpServletRequest httpServletRequest, @RequestParam Lo
*/
@PostMapping("/update")
@ApiOperation("修改用户通过id")
public String userUpdate(HttpServletRequest httpServletRequest, @RequestBody User user) throws IOException{
public String userUpdate(HttpServletRequest httpServletRequest, @RequestBody UserUpdateBo userUpdateBo ) throws IOException{
String token = httpServletRequest.getHeader("Cookie");

return JSONArray.toJSONString(userService.userUpdate(user,token.substring(6)));
return JSONArray.toJSONString(userService.userUpdate(userUpdateBo,token.substring(6)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.example.filesystem.mapper;

import com.example.filesystem.pojo.User;
import com.example.filesystem.pojo.bo.UserAddBo;
import com.example.filesystem.pojo.bo.UserFindAllBo;
import com.example.filesystem.pojo.bo.UserPagingToGetDataBo;
import com.example.filesystem.pojo.bo.UserRegBo;
import com.example.filesystem.pojo.bo.*;
import com.example.filesystem.pojo.vo.UserFindAllVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
Expand Down Expand Up @@ -50,10 +47,10 @@ public interface UserMapper {
/**
* @author zhuxinyu 2023-11-28
* 通过id修改用户
* @param user
* @param userUpdateBo
* @return
*/
Long userUpdate(User user);
Long userUpdate(UserUpdateBo userUpdateBo);

/**
* @author zhuxinyu 2023-11-28
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
package com.example.filesystem.pojo.bo;

import com.example.filesystem.pojo.User;

import java.io.Serializable;

/**
* 2023-11-28 zhuxinyu
* 用户修改实体类
*/
public class UserUpdateBo implements Serializable {
private String token;
private User user;//用户User
private Long id;
private Long grade;
private String org;
public UserUpdateBo(){

}

public UserUpdateBo(String token, User user) {
this.token = token;
this.user = user;
public UserUpdateBo(Long id, Long grade, String org) {
this.id = id;
this.grade = grade;
this.org = org;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getToken() {
return token;
public Long getGrade() {
return grade;
}

public void setToken(String token) {
this.token = token;
public void setGrade(Long grade) {
this.grade = grade;
}

public User getUser() {
return user;
public String getOrg() {
return org;
}

public void setUser(User user) {
this.user = user;
public void setOrg(String org) {
this.org = org;
}

@Override
public String toString() {
return "UserUpdateBo{" +
"token='" + token + '\'' +
", user=" + user +
"id=" + id +
", grade=" + grade +
", org='" + org + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public interface UserService {
/**
* @author zhuxinyu 2023-11-28
* 用户更新
* @param user
* @param userUpdateBo
* @return
*/
ResponseVo userUpdate(User user , String token) throws IOException;
ResponseVo userUpdate(UserUpdateBo userUpdateBo , String token) throws IOException;

/**
* @author zhuxinyu 2023-11-28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,26 @@ public ResponseVo userSelect(Long id , String token) {
/**
* @author zhuxinyu 2023-11-28
* 用户更新
* @param user
* @param userUpdateBo
* @return
*/
@Override
public ResponseVo userUpdate(User user , String token) {
public ResponseVo userUpdate(UserUpdateBo userUpdateBo , String token) {
systemService.auth(token);
String userIdOfStr = (String) ThreadLocalUtil.mapThreadLocalOfJWT.get().get("userinfo").get("id");
Long userId = Long.valueOf(userIdOfStr);

if(userId == null || userId == 0L){
return new ResponseVo("token解析失败",null,"0x501");
}
user.setId(userId);
user.setUpdateBy(userId);
user.setUpdateTime(new Date());
Long aLong = userMapper.userUpdate(user);
userUpdateBo.setId(userId);
Long aLong = userMapper.userUpdate(userUpdateBo);

if(aLong == null || aLong.longValue() == 0L){
return new ResponseVo("修改失败",null,"0x500");
}

return new ResponseVo("修改成功",user.getId(),"0x200");
return new ResponseVo("修改成功",userId,"0x200");
}

/**
Expand Down
25 changes: 2 additions & 23 deletions WebServer/src/main/resources/mybatis/mapper/UserMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,15 @@
<update id="userUpdate" parameterType="com.example.filesystem.pojo.User">
update user
<set>
<if test="username != null and username != ''">
username = #{username},
</if>
<if test="password != null and password != ''">
password = #{password},
</if>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="grade != null and grade != ''">
grade = #{grade},
</if>
<if test="org != null and org != ''">
org = #{org},
</if>
<if test="role != null ">
role = #{role},
</if>
<if test="true">
update_by = #{updateBy},update_time = #{updateTime},
</if>
<if test="status != null and status != ''">
status = #{status},
</if>
<if test="delFlag != null and delFlag != ''">
del_flag = #{delFlag}
</if>
</set>
where
id = #{id}
where
id=#{id}
</update>


Expand Down

0 comments on commit 046f3c8

Please sign in to comment.