mirror of https://gitee.com/stylefeng/roses
【7.6.0】【sys】【user】完善更新用户状态接口
parent
fe2b70c884
commit
d129a0cc0d
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.sys.api.enums;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.sys.api.exception.SysException;
|
||||
import cn.stylefeng.roses.kernel.sys.api.exception.enums.UserExceptionEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 用户状态的枚举
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2020/10/20 18:19
|
||||
*/
|
||||
@Getter
|
||||
public enum UserStatusEnum {
|
||||
|
||||
/**
|
||||
* 启用
|
||||
*/
|
||||
ENABLE(1, "启用"),
|
||||
|
||||
/**
|
||||
* 禁用
|
||||
*/
|
||||
DISABLE(2, "禁用"),
|
||||
|
||||
/**
|
||||
* 冻结
|
||||
*/
|
||||
FREEZE(3, "冻结");
|
||||
|
||||
private final Integer code;
|
||||
|
||||
private final String message;
|
||||
|
||||
UserStatusEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* code转化为enum
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2020/10/21 9:29
|
||||
*/
|
||||
public static UserStatusEnum toEnum(Integer code) {
|
||||
for (UserStatusEnum userStatusEnum : UserStatusEnum.values()) {
|
||||
if (userStatusEnum.getCode().equals(code)) {
|
||||
return userStatusEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取code对应的message
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2020/10/21 9:29
|
||||
*/
|
||||
public static String getCodeMessage(Integer code) {
|
||||
UserStatusEnum userStatusEnum = toEnum(code);
|
||||
if (userStatusEnum != null) {
|
||||
return userStatusEnum.getMessage();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查请求参数的状态是否正确
|
||||
*
|
||||
* @author stylefeng
|
||||
* @since 2020/4/30 22:43
|
||||
*/
|
||||
public static void validateUserStatus(Integer code) {
|
||||
if (code == null) {
|
||||
throw new ServiceException(UserExceptionEnum.REQUEST_USER_STATUS_EMPTY);
|
||||
}
|
||||
if (ENABLE.getCode().equals(code) || DISABLE.getCode().equals(code) || FREEZE.getCode().equals(code)) {
|
||||
return;
|
||||
}
|
||||
throw new SysException(UserExceptionEnum.REQUEST_USER_STATUS_ERROR, code);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.stylefeng.roses.kernel.sys.api.enums;
|
||||
package cn.stylefeng.roses.kernel.sys.api.exception.enums;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
|
@ -11,7 +11,7 @@ import lombok.Getter;
|
|||
* @date 2023/06/10 21:23
|
||||
*/
|
||||
@Getter
|
||||
public enum HrOrganizationExceptionEnum implements AbstractExceptionEnum {
|
||||
public enum OrgExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* 查询结果不存在
|
||||
|
@ -33,7 +33,7 @@ public enum HrOrganizationExceptionEnum implements AbstractExceptionEnum {
|
|||
*/
|
||||
private final String userTip;
|
||||
|
||||
HrOrganizationExceptionEnum(String errorCode, String userTip) {
|
||||
OrgExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.sys.api.exception.enums;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 基础核心业务的异常枚举
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2023-06-10 20:50:43
|
||||
*/
|
||||
@Getter
|
||||
public enum SysExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* 查询不到对应基础核心业务
|
||||
*/
|
||||
CANT_FIND_SYS(RuleConstants.BUSINESS_ERROR_TYPE_CODE + SysConstants.SYS_EXCEPTION_STEP_CODE + "01", "查询不到对应基础核心业务,具体信息:{}");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
*/
|
||||
private final String errorCode;
|
||||
|
||||
/**
|
||||
* 提示用户信息
|
||||
*/
|
||||
private final String userTip;
|
||||
|
||||
SysExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package cn.stylefeng.roses.kernel.sys.api.exception.enums;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 组织机构信息异常相关枚举
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2023/06/10 21:23
|
||||
*/
|
||||
@Getter
|
||||
public enum UserExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* 请求状态值为空
|
||||
*/
|
||||
REQUEST_USER_STATUS_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "请求状态值为空"),
|
||||
|
||||
/**
|
||||
* 请求状值为非正确状态值
|
||||
*/
|
||||
REQUEST_USER_STATUS_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10002", "请求状态值不合法,用户状态参数不合法,参数值:{}");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
*/
|
||||
private final String errorCode;
|
||||
|
||||
/**
|
||||
* 提示用户信息
|
||||
*/
|
||||
private final String userTip;
|
||||
|
||||
UserExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,7 @@ import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
|||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.rule.tree.factory.DefaultTreeBuildFactory;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveOrgCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.HrOrganizationExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.exception.enums.OrgExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.factory.OrganizationFactory;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.mapper.HrOrganizationMapper;
|
||||
|
@ -152,7 +152,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
private HrOrganization queryHrOrganization(HrOrganizationRequest hrOrganizationRequest) {
|
||||
HrOrganization hrOrganization = this.getById(hrOrganizationRequest.getOrgId());
|
||||
if (ObjectUtil.isEmpty(hrOrganization)) {
|
||||
throw new ServiceException(HrOrganizationExceptionEnum.HR_ORGANIZATION_NOT_EXISTED);
|
||||
throw new ServiceException(OrgExceptionEnum.HR_ORGANIZATION_NOT_EXISTED);
|
||||
}
|
||||
return hrOrganization;
|
||||
}
|
||||
|
|
|
@ -99,4 +99,16 @@ public class SysUserController {
|
|||
return new SuccessResponseData<>(sysUserService.findPage(sysUserRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户状态
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/12 10:58
|
||||
*/
|
||||
@PostResource(name = "修改用户状态", path = "/sysUser/updateStatus")
|
||||
public ResponseData<?> updateStatus(@RequestBody @Validated(SysUserRequest.updateStatus.class) SysUserRequest sysUserRequest) {
|
||||
sysUserService.updateStatus(sysUserRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class SysUserRequest extends BaseRequest {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "主键不能为空", groups = {edit.class, delete.class})
|
||||
@NotNull(message = "主键不能为空", groups = {edit.class, delete.class, updateStatus.class})
|
||||
@ChineseDescription("主键")
|
||||
private Long userId;
|
||||
|
||||
|
@ -106,7 +106,7 @@ public class SysUserRequest extends BaseRequest {
|
|||
* 状态:1-正常,2-冻结
|
||||
*/
|
||||
@ChineseDescription("状态:1-正常,2-冻结")
|
||||
@NotNull(message = "状态不能为空", groups = {add.class, edit.class})
|
||||
@NotNull(message = "状态不能为空", groups = {add.class, edit.class, updateStatus.class})
|
||||
private Integer statusFlag;
|
||||
|
||||
/**
|
||||
|
|
|
@ -78,4 +78,13 @@ public interface SysUserService extends IService<SysUser> {
|
|||
* @date 2023/06/10 21:26
|
||||
*/
|
||||
PageResult<SysUser> findPage(SysUserRequest sysUserRequest);
|
||||
|
||||
/**
|
||||
* 修改用户状态
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/12 10:59
|
||||
*/
|
||||
void updateStatus(SysUserRequest sysUserRequest);
|
||||
|
||||
}
|
|
@ -9,7 +9,7 @@ import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
|||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveOrgCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveUserCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.HrOrganizationExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.exception.enums.OrgExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserOrg;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.enums.SysUserOrgExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.mapper.SysUserOrgMapper;
|
||||
|
@ -93,7 +93,7 @@ public class SysUserOrgServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUser
|
|||
queryWrapper.in(SysUserOrg::getOrgId, beRemovedOrgIdList);
|
||||
long count = this.count(queryWrapper);
|
||||
if (count > 0) {
|
||||
throw new ServiceException(HrOrganizationExceptionEnum.DELETE_ORGANIZATION_ERROR);
|
||||
throw new ServiceException(OrgExceptionEnum.DELETE_ORGANIZATION_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
|||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysUserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveUserCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.UserStatusEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUser;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.enums.SysUserExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.mapper.SysUserMapper;
|
||||
|
@ -21,6 +22,7 @@ import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserRequest;
|
|||
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserOrgService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -137,6 +139,21 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
return PageResultFactory.createPageResult(sysUserPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(SysUserRequest sysUserRequest) {
|
||||
|
||||
// 校验状态传值是否正确
|
||||
Integer statusFlag = sysUserRequest.getStatusFlag();
|
||||
UserStatusEnum.validateUserStatus(statusFlag);
|
||||
|
||||
// 更新用户状态
|
||||
LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(SysUser::getStatusFlag, sysUserRequest.getStatusFlag());
|
||||
updateWrapper.eq(SysUser::getUserId, sysUserRequest.getUserId());
|
||||
this.update(updateWrapper);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUser> findList(SysUserRequest sysUserRequest) {
|
||||
LambdaQueryWrapper<SysUser> wrapper = this.createWrapper(sysUserRequest);
|
||||
|
|
Loading…
Reference in New Issue