组织列表、组织权限、部门管理接口入参检查完善

This commit is contained in:
gaoqr
2024-10-14 16:37:42 +08:00
parent 84c52409f2
commit b2f0e05564
17 changed files with 86 additions and 37 deletions
@@ -1,19 +1,24 @@
package com.cf.imes.module.system.controller.admin.notice.vo;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.module.system.validation.system.common.CommonStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.Size;
@Schema(description = "管理后台 - 通知公告分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class NoticePageReqVO extends PageParam {
@Schema(description = "通知公告名称,模糊匹配", example = "晨丰")
@Size(max = 50, message = "公告标题不能超过50个字符")
private String title;
@Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
@CommonStatus
private Integer status;
}
@@ -1,13 +1,13 @@
package com.cf.imes.module.system.controller.admin.organ;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.excel.core.util.ExcelUtils;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
import com.cf.imes.module.system.api.user.dto.OrganAdminUserRespDTO;
import com.cf.imes.module.system.controller.admin.organ.vo.organ.*;
import com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO;
@@ -29,9 +29,11 @@ import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.framework.common.pojo.CommonResult.success;
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertList;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.ORGAN_NOT_EXISTS;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.TENANT_PACKAGE_NOT_EXISTS;
@Tag(name = "管理后台 - 组织")
@RestController
@@ -95,10 +97,17 @@ public class OrganController {
@PreAuthorize("@ss.hasPermission('organizationLIst:query')")
public CommonResult<OrganRespVO> getOrgan(@RequestParam("id") Long id) {
OrganizationDO organ = organService.getOrgan(id);
if (ObjectUtil.isNull(organ)) {
throw exception(ORGAN_NOT_EXISTS);
}
TenantPackageDO tenantPackageDO = tenantPackageMapper.selectById(organ.getPackageId());
OrganRespVO bean = BeanUtils.toBean(organ, OrganRespVO.class);
bean.setPackageName(Objects.isNull(tenantPackageDO)? "": tenantPackageDO.getName());
return success(bean);
if (ObjectUtil.isNotNull(tenantPackageDO)) {
OrganRespVO bean = BeanUtils.toBean(organ, OrganRespVO.class);
bean.setPackageName(Objects.isNull(tenantPackageDO) ? "" : tenantPackageDO.getName());
return success(bean);
} else {
throw exception(TENANT_PACKAGE_NOT_EXISTS);
}
}
@GetMapping("/page")
@@ -1,15 +1,14 @@
package com.cf.imes.module.system.controller.admin.organ.vo.organ;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.validation.Mobile;
import com.cf.imes.module.system.validation.system.common.CommonStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
import javax.validation.constraints.Size;
@Schema(description = "管理后台 - 组织分页 Request VO")
@Data
@@ -18,21 +17,22 @@ import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH
public class OrganPageReqVO extends PageParam {
@Schema(description = "组织名", example = "晨丰")
@Size(max = 30, message = "组织名长度不能超过30个字符")
private String name;
@Schema(description = "联系人", example = "晨丰")
@Size(max = 30, message = "联系人长度不能超过30个字符")
private String contactName;
@Schema(description = "联系手机", example = "15601691300")
@Mobile
@Size(max = 11, message = "联系手机长度不能超过11个字符")
private String contactMobile;
@Schema(description = "组织状态(0正常 1停用)", example = "1")
@CommonStatus
private Integer status;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@Schema(description = "创建时间")
private LocalDateTime[] createTime;
/**
* 拼音首字母
*/
@@ -1,9 +1,9 @@
package com.cf.imes.module.system.controller.admin.organ.vo.organ;
import com.cf.imes.framework.common.validation.Mobile;
import com.cf.imes.module.system.validation.system.common.CommonStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
@@ -19,23 +19,27 @@ public class OrganSaveReqVO {
@Schema(description = "组织名", requiredMode = Schema.RequiredMode.REQUIRED, example = "晨丰")
@NotNull(message = "组织名不能为空")
@Length(min = 1, max = 30, message = "组织名长度不能超过30个字符")
@Size(min = 1, max = 30, message = "组织名长度不能超过30个字符")
private String name;
@Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "晨丰")
@NotNull(message = "联系人不能为空")
@Size(min = 1, max = 30, message = "联系人长度不能超过30个字符")
private String contactName;
@Schema(description = "联系手机", example = "15601691300")
@Mobile
@NotNull(message = "联系人手机不能为空")
@Size(max = 11, message = "联系人手机长度不能超过11个字符")
private String contactMobile;
@Schema(description = "组织状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "组织状态")
@CommonStatus
private Integer status;
@Schema(description = "绑定域名", example = "https://www.cf.com")
@Size(max = 256, message = "绑定域名长度不能超过256个字符")
private String website;
@Schema(description = "组织套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@@ -58,20 +62,22 @@ public class OrganSaveReqVO {
private String username;
@Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
@Size(min = 4, max = 16, message = "密码长度为 4-16 位")
private String password;
@Schema(description = "是否大型组织")
private Boolean large;
@Schema(description = "组织编号")
@Size(max = 50, message = "组织编号长度不能超过50个字符")
private String code;
@Schema(description = "地址")
@Size(max = 255, message = "地址长度不能超过255个字符")
private String address;
@Schema(description = "备注")
@Length(min = 0, max = 200, message = "备注不可太")
@Size(max = 200, message = "备注长度不能超过200个字符")
private String remark;
}
@@ -1,12 +1,14 @@
package com.cf.imes.module.system.controller.admin.organ.vo.packages;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.module.system.validation.system.common.CommonStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@@ -18,12 +20,15 @@ import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH
public class TenantPackagePageReqVO extends PageParam {
@Schema(description = "套餐名", example = "VIP")
@Size(max = 30, message = "套餐名长度不能超过30个字符")
private String name;
@Schema(description = "状态", example = "1")
@CommonStatus
private Integer status;
@Schema(description = "备注", example = "")
@Size(max = 256, message = "备注长度不能超过256个字符")
private String remark;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@@ -1,13 +1,12 @@
package com.cf.imes.module.system.controller.admin.organ.vo.packages;
import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.validation.InEnum;
import com.cf.imes.module.system.validation.system.common.CommonStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Set;
@Schema(description = "管理后台 - 组织套餐创建/修改 Request VO")
@@ -19,19 +18,22 @@ public class TenantPackageSaveReqVO {
@Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "VIP")
@NotEmpty(message = "套餐名不能为空")
@Length(min = 1, max = 30, message = "套餐名长度不能超过30个字符")
@Size(min = 1, max = 30, message = "套餐名长度不能超过30个字符")
private String name;
@Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
@CommonStatus
private Integer status;
@Schema(description = "备注", example = "")
@Size(max = 256, message = "备注长度不能超过256个字符")
private String remark;
@Schema(description = "关联的菜单编号", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "关联的菜单编号不能为空")
// todo 目前可用菜单数量大概在两百出头,暂时设置为300,后期扩展可以调整
@Size(max = 300, message = "关联的菜单编号数量不能超过300")
private Set<Long> menuIds;
}
@@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Collections;
import java.util.Set;
@@ -16,6 +17,7 @@ public class PermissionAssignUserRoleReqVO {
private Long userId;
@Schema(description = "角色编号列表", example = "1,3,5")
@Size(max = 20, message = "角色编号数量不能超过 20 个")
private Set<Long> roleIds = Collections.emptySet(); // 兜底
@Schema(description = "组织id")
@@ -1,6 +1,7 @@
package com.cf.imes.module.system.controller.admin.user;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageParam;
@@ -47,9 +48,11 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.framework.common.pojo.CommonResult.success;
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertList;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS;
@Tag(name = "管理后台 - 用户")
@RestController
@@ -153,6 +156,9 @@ public class UserController {
@PreAuthorize("@ss.hasAnyPermissions('system:user:query','base:user:query')")
public CommonResult<UserRespVO> getUser(@RequestParam("id") Long id) {
AdminUserDO user = userService.getUser(id);
if (ObjectUtil.isNull(user)) {
throw exception(USER_NOT_EXISTS);
}
// 拼接数据
DeptDO dept = deptService.getDept(user.getDeptId());
return success(UserConvert.INSTANCE.convert(user, dept));
@@ -1,6 +1,8 @@
package com.cf.imes.module.system.controller.admin.user.vo.user;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.validation.Mobile;
import com.cf.imes.module.system.validation.system.common.CommonStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -8,6 +10,7 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@@ -20,15 +23,16 @@ import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH
public class UserPageReqVO extends PageParam {
@Schema(description = "用户昵称")
@Size(max = 30, message = "用户昵称长度不能超过30个字符")
private String nickname;
@Schema(description = "用户账号,模糊匹配", example = "chenfeng")
private String username;
@Schema(description = "手机号码,模糊匹配", example = "chenfeng")
@Mobile
@Size(max = 11, message = "手机号码长度不能超过11个字符")
private String mobile;
@Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
@CommonStatus
private Integer status;
@Schema(description = "创建时间", example = "[2022-07-01 00:00:00, 2022-07-01 23:59:59]")
@@ -1,11 +1,10 @@
package com.cf.imes.module.system.controller.admin.user.vo.user;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.validation.Mobile;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.cf.imes.module.system.validation.system.common.CommonStatus;
import com.cf.imes.module.system.validation.system.user.Sex;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.*;
import java.util.Set;
@@ -19,20 +18,25 @@ public class UserSaveReqVO {
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "晨丰")
@Size(max = 30, message = "用户昵称长度不能超过30个字符")
@NotBlank(message = "用户姓名不能为空")
private String nickname;
@Schema(description = "备注", example = "我是一个用户")
@Size(max = 256, message = "备注长度不能超过256个字符")
private String remark;
@Schema(description = "部门ID", example = "我是一个用户")
@NotNull(message = "部门编号不能为空")
private Long deptId;
@Schema(description = "岗位编号数组", example = "1")
@Size(max = 20, message = "岗位数量不能超过 20 个")
private Set<Long> postIds;
@Schema(description = "用户邮箱", example = "chenfeng@cf.com")
@Email(message = "邮箱格式不正确")
@Size(max = 50, message = "邮箱长度不能超过 50 个字符")
@NotBlank(message = "邮箱不能为空")
private String email;
@Schema(description = "手机号码", example = "15601691300")
@@ -41,19 +45,22 @@ public class UserSaveReqVO {
private String mobile;
@Schema(description = "用户性别,参见 SexEnum 枚举类", example = "1")
@Sex
private Integer sex;
@Schema(description = "用户头像", example = "https://www.cf.com/xxx.png")
@Size(max = 512, message = "用户头像存储地址不能超过 512 个字符")
private String avatar;
// ========== 仅【创建】时,需要传递的字段 ==========
@Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
@Size(min = 4, max = 16, message = "密码长度为 4-16 位")
private String password;
@Schema(description = "帐号状态(0正常 1停用)")
@NotNull(message = "账号状态不能空")
@CommonStatus
private Integer status;
private Long organId;
@@ -1,7 +1,6 @@
package com.cf.imes.module.system.controller.admin.user.vo.user;
import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.validation.InEnum;
import com.cf.imes.module.system.validation.system.common.CommonStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -17,7 +16,7 @@ public class UserUpdateStatusReqVO {
@Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
@CommonStatus
private Integer status;
}
@@ -30,7 +30,6 @@ public interface OrganMapper extends BaseMapperX<OrganizationDO> {
.likeIfPresent(OrganizationDO::getContactName, reqVO.getContactName())
.likeIfPresent(OrganizationDO::getContactMobile, reqVO.getContactMobile())
.eqIfPresent(OrganizationDO::getStatus, reqVO.getStatus())
.betweenIfPresent(OrganizationDO::getCreateTime, reqVO.getCreateTime())
.and(CharSequenceUtil.isNotBlank(reqVO.getName()), wrapper ->{
wrapper.or(Boolean.TRUE).like(OrganizationDO::getName, reqVO.getName());
wrapper.or(CharSequenceUtil.isNotBlank(reqVO.getPyAll())).like(OrganizationDO::getPinyinFull, reqVO.getPyAll());
@@ -77,8 +77,7 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
lambdaQueryWrapperX.eqIfPresent(AdminUserDO::getOrganId, loginUser.getOrganId());
}
return selectPage(reqVO, lambdaQueryWrapperX
.likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername())
.likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile())
.likeIfPresent(AdminUserDO::getUsername, reqVO.getMobile())
.eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus())
.betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime())
.inIfPresent(AdminUserDO::getDeptId, deptIds)
@@ -320,6 +320,10 @@ public class OrganServiceImpl implements OrganService {
if(CharSequenceUtil.isNotBlank(pageReqVO.getName())) {
pageReqVO.setPyFirstChar(PinYinUtils.convertFirstChar(pageReqVO.getName()));
pageReqVO.setPyAll(PinYinUtils.convertToPinyin(pageReqVO.getName()).replace(" ", ""));
} else {
// 避免name为空外部传入拼音查询字段
pageReqVO.setPyFirstChar(null);
pageReqVO.setPyAll(null);
}
return organMapper.selectPage(pageReqVO);
}
@@ -393,6 +393,10 @@ public class AdminUserServiceImpl implements AdminUserService {
if (StringUtils.isNotBlank(reqVO.getNickname())) {
reqVO.setPyFirstChar(PinYinUtils.convertFirstChar(reqVO.getNickname()));
reqVO.setPyAll(PinYinUtils.convertToPinyin(reqVO.getNickname()).replace(" ", ""));
} else {
// 避免name为空外部传入拼音查询字段
reqVO.setPyFirstChar(null);
reqVO.setPyAll(null);
}
PageResult<AdminUserDO> adminUserDOPageResult = userMapper.selectPage(reqVO, getDeptCondition(reqVO.getDeptId()));
@@ -309,7 +309,6 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
reqVO.setContactName("");
reqVO.setContactMobile("1560");
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24));
// 调用
PageResult<OrganizationDO> pageResult = tenantService.getOrganPage(reqVO);
@@ -339,7 +339,6 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
AdminUserDO dbUser = initGetUserPageData();
// 准备参数
UserPageReqVO reqVO = new UserPageReqVO();
reqVO.setUsername("tu");
reqVO.setMobile("1560");
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24));