feat(新增): 修改用户

This commit is contained in:
bunny 2024-03-23 23:26:41 +08:00
parent 598e1652a6
commit ca5926e068
12 changed files with 77 additions and 16 deletions

View File

@ -17,6 +17,6 @@ public class MessageConstant {
public static final String PASSWORD_EDIT_FAILED = "密码修改失败";
public static final String ALREADY_EXISTS = "已存在";
public static final String REQUEST_NOT_EMPTY = "请求不为空";
public static final String UPDATE_ID_IS_NOT_EMPTY = "修改id不能为空";
public static final String UPDATE_ID_IS_NOT_EMPTY = "删除id不能为空";
public static final String DELETE_ID_IS_NOT_EMPTY = "修改id不能为空";
}

View File

@ -32,4 +32,11 @@ public class SysUserController {
sysUserService.saveSysUser(sysUser);
return Result.success();
}
@Operation(summary = "修改用户", description = "修改用户信息")
@PutMapping("updateSysUser")
public Result updateSysUser(@RequestBody SysUser sysUser) {
sysUserService.updateSysUser(sysUser);
return Result.success();
}
}

View File

@ -30,4 +30,11 @@ public interface SysUserMapper {
* @param sysUser 系统用户实体类
*/
void save(SysUser sysUser);
/**
* 修改用户
*
* @param sysUser 系统用户实体类
*/
void updateSysUser(SysUser sysUser);
}

View File

@ -38,4 +38,11 @@ public interface SysUserService {
* @param sysUser 系统用户实体类
*/
void saveSysUser(SysUser sysUser);
/**
* 修改用户
*
* @param sysUser 系统用户实体类
*/
void updateSysUser(SysUser sysUser);
}

View File

@ -1,6 +1,7 @@
package com.atguigu.spzx.manger.service.impl;
import com.atguigu.constant.ExceptionConstant;
import com.atguigu.constant.MessageConstant;
import com.atguigu.exception.BunnyException;
import com.atguigu.lib.MD5;
import com.atguigu.spzx.manger.mapper.SysUserMapper;
@ -130,4 +131,15 @@ public class SysUserServiceImpl implements SysUserService {
// 插入数据
sysUserMapper.save(sysUser);
}
/**
* 修改用户
*
* @param sysUser 系统用户实体类
*/
@Override
public void updateSysUser(SysUser sysUser) {
stringEmptyUtil.isEmpty(sysUser.getId(), MessageConstant.UPDATE_ID_IS_NOT_EMPTY);
sysUserMapper.updateSysUser(sysUser);
}
}

View File

@ -12,6 +12,32 @@
values (#{id}, #{userName}, #{password}, #{name}, #{phone}, #{avatar}, #{description}, #{status});
</insert>
<!-- 修改用户 -->
<update id="updateSysUser">
update sys_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="phone != null and phone != ''">
phone = #{phone},
</if>
<if test="description != null and description != ''">
description = #{description},
</if>
<if test="status != null and status != ''">
status = #{status},
</if>
update_time = now()
where id = #{id}
</update>
<!-- 根据username查询用户信息 -->
<select id="selectByUsername" resultType="com.atguigu.spzx.model.entity.system.SysUser">
select

View File

@ -6,20 +6,11 @@
id,username userName ,password,name,phone,avatar,description,status,create_time,update_time,is_deleted
</sql>
<sql id="findPageWhere">
<where>
<if test="keyword != null and keyword != ''">
and username like CONCAT('%',#{keyword},'%')
</if>
<if test="createTimeBegin != null and createTimeBegin != ''">
and create_time >= #{createTimeBegin}
</if>
<if test="createTimeEnd != null and createTimeEnd != ''">
and create_time &lt;= #{createTimeEnd}
</if>
and is_deleted = 0
</where>
</sql>
<!-- 添加用户 -->
<insert id="save">
insert into sys_user (id, username, password, name, phone, avatar, description, status)
values (#{id}, #{userName}, #{password}, #{name}, #{phone}, #{avatar}, #{description}, #{status});
</insert>
<!-- 根据username查询用户信息 -->
<select id="selectByUsername" resultType="com.atguigu.spzx.model.entity.system.SysUser">
@ -34,7 +25,18 @@
select
<include refid="columns"/>
from sys_user
<include refid="findPageWhere"/>
<where>
<if test="keyword != null and keyword != ''">
and username like CONCAT('%',#{keyword},'%')
</if>
<if test="createTimeBegin != null and createTimeBegin != ''">
and create_time >= #{createTimeBegin}
</if>
<if test="createTimeEnd != null and createTimeEnd != ''">
and create_time &lt;= #{createTimeEnd}
</if>
and is_deleted = 0
</where>
order by id desc
</select>
</mapper>