优化用户的查询逻辑,针对逻辑删除

This commit is contained in:
jishenghua 2024-12-10 22:07:21 +08:00
parent 196aac12f3
commit 5ea6c63c32
4 changed files with 15 additions and 14 deletions

View File

@ -172,10 +172,9 @@ public class BusinessConstants {
public static final byte USER_NOT_MANAGER = 1; public static final byte USER_NOT_MANAGER = 1;
/** /**
* 用户状态 * 用户状态
* 0正常1删除2封禁 * 0正常2封禁
* */ * */
public static final byte USER_STATUS_NORMAL = 0; public static final byte USER_STATUS_NORMAL = 0;
public static final byte USER_STATUS_DELETE = 1;
public static final byte USER_STATUS_BANNED = 2; public static final byte USER_STATUS_BANNED = 2;
/** /**
* 日志操作 * 日志操作

View File

@ -26,7 +26,7 @@ public interface UserMapperEx {
List<User> getUserListByUserNameOrLoginName(@Param("userName") String userName, List<User> getUserListByUserNameOrLoginName(@Param("userName") String userName,
@Param("loginName") String loginName); @Param("loginName") String loginName);
int batDeleteOrUpdateUser(@Param("ids") String ids[], @Param("status") byte status); int batDeleteOrUpdateUser(@Param("ids") String[] ids);
List<TreeNodeEx> getNodeTree(); List<TreeNodeEx> getNodeTree();
List<TreeNodeEx> getNextNodeTree(Map<String, Object> parameterMap); List<TreeNodeEx> getNextNodeTree(Map<String, Object> parameterMap);

View File

@ -287,9 +287,9 @@ public class UserService {
} }
logService.insertLog("用户", sb.toString(), logService.insertLog("用户", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
String idsArray[]=ids.split(","); String[] idsArray =ids.split(",");
try{ try{
result=userMapperEx.batDeleteOrUpdateUser(idsArray,BusinessConstants.USER_STATUS_DELETE); result=userMapperEx.batDeleteOrUpdateUser(idsArray);
}catch(Exception e){ }catch(Exception e){
JshException.writeFail(logger, e); JshException.writeFail(logger, e);
} }
@ -412,7 +412,7 @@ public class UserService {
List<User> list = null; List<User> list = null;
try { try {
UserExample example = new UserExample(); UserExample example = new UserExample();
example.createCriteria().andLoginNameEqualTo(loginName).andStatusNotEqualTo(BusinessConstants.USER_STATUS_DELETE); example.createCriteria().andLoginNameEqualTo(loginName).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
list = userMapper.selectByExample(example); list = userMapper.selectByExample(example);
if (null != list && list.size() == 0) { if (null != list && list.size() == 0) {
return ExceptionCodeConstants.UserExceptionCode.USER_NOT_EXIST; return ExceptionCodeConstants.UserExceptionCode.USER_NOT_EXIST;
@ -438,7 +438,7 @@ public class UserService {
try { try {
UserExample example = new UserExample(); UserExample example = new UserExample();
example.createCriteria().andLoginNameEqualTo(loginName).andPasswordEqualTo(password) example.createCriteria().andLoginNameEqualTo(loginName).andPasswordEqualTo(password)
.andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL); .andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
list = userMapper.selectByExample(example); list = userMapper.selectByExample(example);
if (null != list && list.size() == 0) { if (null != list && list.size() == 0) {
return ExceptionCodeConstants.UserExceptionCode.USER_PASSWORD_ERROR; return ExceptionCodeConstants.UserExceptionCode.USER_PASSWORD_ERROR;
@ -452,7 +452,8 @@ public class UserService {
public User getUserByLoginName(String loginName)throws Exception { public User getUserByLoginName(String loginName)throws Exception {
UserExample example = new UserExample(); UserExample example = new UserExample();
example.createCriteria().andLoginNameEqualTo(loginName).andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL); example.createCriteria().andLoginNameEqualTo(loginName).andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<User> list=null; List<User> list=null;
try{ try{
list= userMapper.selectByExample(example); list= userMapper.selectByExample(example);
@ -468,10 +469,10 @@ public class UserService {
public int checkIsNameExist(Long id, String name)throws Exception { public int checkIsNameExist(Long id, String name)throws Exception {
UserExample example = new UserExample(); UserExample example = new UserExample();
List <Byte> userStatus=new ArrayList<Byte>(); List<Byte> userStatus = new ArrayList<>();
userStatus.add(BusinessConstants.USER_STATUS_DELETE); userStatus.add(BusinessConstants.USER_STATUS_NORMAL);
userStatus.add(BusinessConstants.USER_STATUS_BANNED); example.createCriteria().andIdNotEqualTo(id).andLoginNameEqualTo(name).andStatusIn(userStatus)
example.createCriteria().andIdNotEqualTo(id).andLoginNameEqualTo(name).andStatusNotIn(userStatus); .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<User> list=null; List<User> list=null;
try{ try{
list= userMapper.selectByExample(example); list= userMapper.selectByExample(example);
@ -502,7 +503,8 @@ public class UserService {
public Long getIdByLoginName(String loginName) { public Long getIdByLoginName(String loginName) {
Long userId = 0L; Long userId = 0L;
UserExample example = new UserExample(); UserExample example = new UserExample();
example.createCriteria().andLoginNameEqualTo(loginName).andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL); example.createCriteria().andLoginNameEqualTo(loginName).andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<User> list = userMapper.selectByExample(example); List<User> list = userMapper.selectByExample(example);
if(list!=null) { if(list!=null) {
userId = list.get(0).getId(); userId = list.get(0).getId();

View File

@ -72,7 +72,7 @@
</select> </select>
<update id="batDeleteOrUpdateUser"> <update id="batDeleteOrUpdateUser">
update jsh_user update jsh_user
set status=#{status} set delete_flag = '1'
where id in ( where id in (
<foreach collection="ids" item="id" separator=","> <foreach collection="ids" item="id" separator=",">
#{id} #{id}