🐛 fixed a bug:删除用户再新增报错的问题
This commit is contained in:
1 parent
2acb83b397
commit
078489d2cc
9 files changed
+92
-9
No files matched your search
+2
-2
@@ -19,7 +19,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.config;
|
||||
|
||||
import com.pig4cloud.pigx.common.security.component.PigxResourceServerConfigurerAdapter;
|
||||
import com.pig4cloud.pigx.common.security.component.BaseResourceServerConfigurerAdapter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
@@ -32,7 +32,7 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.E
|
||||
@Configuration
|
||||
@EnableResourceServer
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class ResourceServerConfigurer extends PigxResourceServerConfigurerAdapter {
|
||||
public class ResourceServerConfigurer extends BaseResourceServerConfigurerAdapter {
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests()
|
||||
|
||||
+4
-1
@@ -116,12 +116,15 @@ public class UserController {
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_user_add')")
|
||||
public R<Boolean> user(@RequestBody UserDTO userDto) {
|
||||
SysUser deletedUser = userService.selectDeletedUserByUsername(userDto.getUsername());
|
||||
if ( deletedUser!= null) {
|
||||
userService.deleteSysUserByUsernameAndUserId(userDto.getUsername(),deletedUser.getUserId());
|
||||
}
|
||||
SysUser sysUser = new SysUser();
|
||||
BeanUtils.copyProperties(userDto, sysUser);
|
||||
sysUser.setDelFlag(CommonConstant.STATUS_NORMAL);
|
||||
sysUser.setPassword(ENCODER.encode(userDto.getNewpassword1()));
|
||||
userService.insert(sysUser);
|
||||
|
||||
userDto.getRole().forEach(roleId -> {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(sysUser.getUserId());
|
||||
|
||||
+14
@@ -61,4 +61,18 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
*/
|
||||
UserVO selectUserVoById(Integer id);
|
||||
|
||||
/**
|
||||
* 通过用户名查找已经删除的用户
|
||||
* @param username 用户名
|
||||
* @return 用户对象
|
||||
*/
|
||||
SysUser selectDeletedUserByUsername(@Param("username")String username);
|
||||
|
||||
/**
|
||||
* 根据用户名删除用户(真实删除)
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteSysUserByUsernameAndUserId(@Param("username")String username,@Param("userId")Integer userId);
|
||||
|
||||
}
|
||||
+17
@@ -50,6 +50,7 @@ public interface SysUserService extends IService<SysUser> {
|
||||
*/
|
||||
Page selectWithRolePage(Query query);
|
||||
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
@@ -83,4 +84,20 @@ public interface SysUserService extends IService<SysUser> {
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserVO selectUserVoById(Integer id);
|
||||
|
||||
/**
|
||||
* 通过用户名查找已经删除的用户
|
||||
* @param username 用户名
|
||||
* @return
|
||||
*/
|
||||
SysUser selectDeletedUserByUsername(String username);
|
||||
|
||||
/**
|
||||
* 根据用户名删除用户(真实删除)
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteSysUserByUsernameAndUserId(String username,Integer userId);
|
||||
|
||||
|
||||
}
|
||||
+28
@@ -126,6 +126,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过ID查询用户信息
|
||||
*
|
||||
@@ -137,6 +138,32 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
return sysUserMapper.selectUserVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户名查找已经删除的用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户对象
|
||||
*/
|
||||
@Override
|
||||
public SysUser selectDeletedUserByUsername(String username) {
|
||||
return sysUserMapper.selectDeletedUserByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名删除用户(真实删除)
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteSysUserByUsernameAndUserId(String username,Integer userId) {
|
||||
|
||||
sysUserMapper.deleteSysUserByUsernameAndUserId(username,userId);
|
||||
SysUserRole condition = new SysUserRole();
|
||||
condition.setUserId(userId);
|
||||
sysUserRoleService.delete(new EntityWrapper<>(condition));
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
@@ -190,4 +217,5 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
});
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.pig4cloud.pigx.admin.mapper.SysUserMapper">
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.pig4cloud.pigx.admin.api.entity.SysUser">
|
||||
<resultMap id="baseResultMap" type="com.pig4cloud.pigx.admin.api.entity.SysUser">
|
||||
<id column="user_id" property="userId"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="password" property="password"/>
|
||||
@@ -157,4 +157,25 @@
|
||||
ORDER BY `user`.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectDeletedUserByUsername" resultMap="baseResultMap">
|
||||
SELECT user_id,
|
||||
username,
|
||||
password,
|
||||
phone,
|
||||
avatar,
|
||||
salt,
|
||||
dept_id,
|
||||
wx_openid,
|
||||
qq_openid,
|
||||
create_time,
|
||||
update_time,
|
||||
del_flag
|
||||
FROM sys_user
|
||||
WHERE username = #{username}
|
||||
AND del_flag = 1
|
||||
</select>
|
||||
|
||||
<delete id="deleteSysUserByUsernameAndUserId">
|
||||
DELETE FROM sys_user WHERE username=#{username} AND user_id=#{userId};
|
||||
</delete>
|
||||
</mapper>
|
||||
+2
-2
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.codegen.config;
|
||||
|
||||
import com.pig4cloud.pigx.common.security.component.PigxResourceServerConfigurerAdapter;
|
||||
import com.pig4cloud.pigx.common.security.component.BaseResourceServerConfigurerAdapter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
@@ -33,7 +33,7 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.Res
|
||||
@EnableResourceServer
|
||||
@AllArgsConstructor
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class ResourceServerConfigurer extends PigxResourceServerConfigurerAdapter {
|
||||
public class ResourceServerConfigurer extends BaseResourceServerConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
|
||||
@@ -23,4 +23,4 @@ eureka:
|
||||
defaultZone: http://pig:pig@localhost:1025/eureka/
|
||||
logging:
|
||||
level:
|
||||
root: debug
|
||||
root: info
|
||||
+2
-2
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.daemon.config;
|
||||
|
||||
import com.pig4cloud.pigx.common.security.component.PigxResourceServerConfigurerAdapter;
|
||||
import com.pig4cloud.pigx.common.security.component.BaseResourceServerConfigurerAdapter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
@@ -33,7 +33,7 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.Res
|
||||
@EnableResourceServer
|
||||
@AllArgsConstructor
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class ResourceServerConfigurer extends PigxResourceServerConfigurerAdapter {
|
||||
public class ResourceServerConfigurer extends BaseResourceServerConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
|
||||
Reference in new issue
Block a user