Commit 2be39ea2 authored by liuyang's avatar liuyang

用户管理增删改查功能完成

parent e2cc387a
...@@ -15,6 +15,7 @@ public enum ResultEnum implements BaseResponseEnum { ...@@ -15,6 +15,7 @@ public enum ResultEnum implements BaseResponseEnum {
ACCOUNT_EXIST("14010","用户名已存在"); ACCOUNT_EXIST("14010","用户名已存在");
private String value; private String value;
private String text; private String text;
......
...@@ -6,11 +6,13 @@ import com.qkdata.biz.sys.model.QueryUserModel; ...@@ -6,11 +6,13 @@ import com.qkdata.biz.sys.model.QueryUserModel;
import com.qkdata.biz.sys.model.SysUserDTO; import com.qkdata.biz.sys.model.SysUserDTO;
import com.qkdata.biz.sys.model.SysUserModel; import com.qkdata.biz.sys.model.SysUserModel;
import com.qkdata.biz.sys.service.SysUserService; import com.qkdata.biz.sys.service.SysUserService;
import com.qkdata.common.base.exception.BusinessException;
import com.qkdata.common.base.model.PageDTO; import com.qkdata.common.base.model.PageDTO;
import com.qkdata.common.constants.AddGroup; import com.qkdata.common.constants.AddGroup;
import com.qkdata.common.constants.UpdateGroup; import com.qkdata.common.constants.UpdateGroup;
import com.qkdata.common.util.UserContext; import com.qkdata.common.util.UserContext;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -72,4 +74,22 @@ public class SysUserController { ...@@ -72,4 +74,22 @@ public class SysUserController {
sysUserService.updatePassword(UserContext.getUser(), form.getPassword(), form.getNewPassword()); sysUserService.updatePassword(UserContext.getUser(), form.getPassword(), form.getNewPassword());
} }
/**
* 删除用户
*/
@PostMapping("/delete")
@RequiresPermissions("sys:user:delete")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void delete(@RequestBody Long[] userIds){
if(ArrayUtils.contains(userIds, 1L)){
throw new BusinessException("系统管理员不能删除");
}
if(ArrayUtils.contains(userIds, UserContext.getUserId())){
throw new BusinessException("当前用户不能删除");
}
sysUserService.deleteBatch(userIds);
}
} }
...@@ -14,4 +14,5 @@ public interface SysUserMapper extends Mapper<SysUserPO> { ...@@ -14,4 +14,5 @@ public interface SysUserMapper extends Mapper<SysUserPO> {
List<SysUserDTO> selectByCondition(QueryUserModel queryUserModel); List<SysUserDTO> selectByCondition(QueryUserModel queryUserModel);
void deleteByIds(Long[] ids);
} }
...@@ -9,4 +9,6 @@ public interface SysUserRoleMapper extends Mapper<SysUserRolePO> { ...@@ -9,4 +9,6 @@ public interface SysUserRoleMapper extends Mapper<SysUserRolePO> {
List<Long> queryRoleIdList(Long userId); List<Long> queryRoleIdList(Long userId);
void deleteByUserId(Long userId); void deleteByUserId(Long userId);
void deleteByUserIds(Long[] userIds);
} }
...@@ -38,4 +38,8 @@ public class SysUserRoleService extends BaseServiceImpl<SysUserRolePO,Long> { ...@@ -38,4 +38,8 @@ public class SysUserRoleService extends BaseServiceImpl<SysUserRolePO,Long> {
} }
} }
} }
public void deleteByUserIds(Long[] userIds) {
sysUserRoleMapper.deleteByUserIds(userIds);
}
} }
...@@ -8,7 +8,6 @@ import com.qkdata.biz.sys.model.QueryUserModel; ...@@ -8,7 +8,6 @@ import com.qkdata.biz.sys.model.QueryUserModel;
import com.qkdata.biz.sys.model.SysUserDTO; import com.qkdata.biz.sys.model.SysUserDTO;
import com.qkdata.biz.sys.model.SysUserModel; import com.qkdata.biz.sys.model.SysUserModel;
import com.qkdata.biz.sys.repository.SysUserMapper; import com.qkdata.biz.sys.repository.SysUserMapper;
import com.qkdata.biz.sys.repository.SysUserRoleMapper;
import com.qkdata.common.base.exception.BusinessException; import com.qkdata.common.base.exception.BusinessException;
import com.qkdata.common.base.model.PageDTO; import com.qkdata.common.base.model.PageDTO;
import com.qkdata.common.base.service.impl.BaseServiceImpl; import com.qkdata.common.base.service.impl.BaseServiceImpl;
...@@ -83,4 +82,10 @@ public class SysUserService extends BaseServiceImpl<SysUserPO,Long> { ...@@ -83,4 +82,10 @@ public class SysUserService extends BaseServiceImpl<SysUserPO,Long> {
sysUserRoleService.saveOrUpdate(po.getId(),sysUserModel.getRoleIdList()); sysUserRoleService.saveOrUpdate(po.getId(),sysUserModel.getRoleIdList());
} }
@Transactional
public void deleteBatch(Long[] ids) {
sysUserMapper.deleteByIds(ids);
sysUserRoleService.deleteByUserIds(ids);
}
} }
...@@ -33,6 +33,7 @@ public class BusinessException extends RuntimeException { ...@@ -33,6 +33,7 @@ public class BusinessException extends RuntimeException {
public BusinessException(String message) { public BusinessException(String message) {
super(message); super(message);
this.message = message;
} }
public BusinessException(Throwable cause) { public BusinessException(Throwable cause) {
......
...@@ -24,5 +24,11 @@ ...@@ -24,5 +24,11 @@
</if> </if>
order by create_at desc order by create_at desc
</select> </select>
<delete id="deleteByIds">
delete from sys_user where id in
<foreach collection="array" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
</mapper> </mapper>
\ No newline at end of file
...@@ -16,4 +16,11 @@ ...@@ -16,4 +16,11 @@
<select id="queryRoleIdList" resultType="long"> <select id="queryRoleIdList" resultType="long">
select role_id from sys_user_role where user_id = #{userId} select role_id from sys_user_role where user_id = #{userId}
</select> </select>
<delete id="deleteByUserIds">
delete from sys_user_role where user_id in
<foreach collection="array" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</delete>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment