【7.6.0】【sys】【user】完善更新用户状态接口

pull/55/MERGE
fengshuonan 2023-06-12 11:09:53 +08:00
parent fe2b70c884
commit d129a0cc0d
10 changed files with 199 additions and 70 deletions

View File

@ -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.
*
* GunsAPACHE 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;
}
/**
* codeenum
*
* @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;
}
/**
* codemessage
*
* @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);
}
}

View File

@ -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;
}

View File

@ -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.
*
* GunsAPACHE 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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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<>();
}
}

View File

@ -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;
/**

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);