From 2d0bd54412c0dbf96b88ce85a509e55ffbdd4390 Mon Sep 17 00:00:00 2001 From: liuxinxin Date: Thu, 16 Feb 2023 10:21:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/user/constant/UserAvailableEnum.java | 18 +++++ .../pmapi/user/controller/UserInfoController.java | 12 +-- .../com/ningdatech/pmapi/user/entity/UserInfo.java | 6 ++ .../pmapi/user/manage/UserInfoManage.java | 86 ++++++++++++++++++++-- .../pmapi/user/model/base/UserRoleInfo.java | 33 --------- .../pmapi/user/model/po/ReqUserDetailEditPO.java | 17 +++-- .../pmapi/user/model/po/ReqUserDetailPO.java | 8 +- .../user/model/po/ReqUserDisableOrEnablePO.java | 30 ++++++++ .../pmapi/user/model/po/ReqUserDisablePO.java | 29 -------- .../pmapi/user/model/po/ReqUserInfoListPO.java | 7 +- .../pmapi/user/model/vo/ResUserDetailVO.java | 7 +- .../ningdatech/pmapi/user/model/vo/UserRoleVO.java | 21 ++++++ 12 files changed, 187 insertions(+), 87 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/constant/UserAvailableEnum.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/model/base/UserRoleInfo.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDisableOrEnablePO.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDisablePO.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/UserRoleVO.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/constant/UserAvailableEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/constant/UserAvailableEnum.java new file mode 100644 index 0000000..70e15c3 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/constant/UserAvailableEnum.java @@ -0,0 +1,18 @@ +package com.ningdatech.pmapi.user.constant; + +/** + * @author liuxinxin + * @date 2023/2/15 下午5:13 + */ + +public enum UserAvailableEnum { + /** + * 启用 + */ + ENABLE, + + /** + * 禁用 + */ + DISABLE +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserInfoController.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserInfoController.java index 4943f54..683d334 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserInfoController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserInfoController.java @@ -4,7 +4,8 @@ package com.ningdatech.pmapi.user.controller; import com.ningdatech.basic.model.PageVo; import com.ningdatech.pmapi.user.manage.UserInfoManage; import com.ningdatech.pmapi.user.model.po.ReqUserDetailEditPO; -import com.ningdatech.pmapi.user.model.po.ReqUserDisablePO; +import com.ningdatech.pmapi.user.model.po.ReqUserDetailPO; +import com.ningdatech.pmapi.user.model.po.ReqUserDisableOrEnablePO; import com.ningdatech.pmapi.user.model.po.ReqUserInfoListPO; import com.ningdatech.pmapi.user.model.vo.ResUserDetailVO; import com.ningdatech.pmapi.user.model.vo.ResUserInfoListVO; @@ -38,14 +39,14 @@ public class UserInfoController { @ApiOperation(value = "用户禁用/启用", notes = "用户禁用/启用") @PostMapping("/disable-enable") - public void disableOrEnable(@Valid @RequestBody ReqUserDisablePO reqUserDisablePO) { - userInfoManage.disableOrEnable(reqUserDisablePO); + public void disableOrEnable(@Valid @RequestBody ReqUserDisableOrEnablePO reqUserDisableOrEnablePO) { + userInfoManage.disableOrEnable(reqUserDisableOrEnablePO); } @ApiOperation(value = "用户详情", notes = "用户详情") @PostMapping("/detail") - public ResUserDetailVO userInfoDetail(@Valid @RequestBody ReqUserInfoListPO reqUserInfoListPO) { - return userInfoManage.userInfoDetail(reqUserInfoListPO); + public ResUserDetailVO userInfoDetail(@Valid @RequestBody ReqUserDetailPO reqUserDetailPO) { + return userInfoManage.userInfoDetail(reqUserDetailPO); } @ApiOperation(value = "用户详情编辑", notes = "用户详情编辑") @@ -54,5 +55,4 @@ public class UserInfoController { userInfoManage.userInfoDetailEdit(reqUserDetailEditPO); } - } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/UserInfo.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/UserInfo.java index 52103cb..791a84f 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/UserInfo.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/UserInfo.java @@ -2,8 +2,10 @@ package com.ningdatech.pmapi.user.entity; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; import java.time.LocalDateTime; @@ -19,6 +21,8 @@ import java.time.LocalDateTime; @TableName("nd_user_info") @Builder @Data +@AllArgsConstructor +@NoArgsConstructor @ApiModel(value = "NdUserInfo对象", description = "") public class UserInfo implements Serializable { @@ -44,4 +48,6 @@ public class UserInfo implements Serializable { private String available; + private String employeeCode; + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java index de80bb9..78cd657 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java @@ -1,23 +1,34 @@ package com.ningdatech.pmapi.user.manage; +import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.model.PageVo; import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; import com.ningdatech.pmapi.organization.service.IDingOrganizationService; +import com.ningdatech.pmapi.sys.model.entity.UserRole; +import com.ningdatech.pmapi.sys.service.IUserRoleService; +import com.ningdatech.pmapi.user.constant.UserAvailableEnum; +import com.ningdatech.pmapi.user.entity.UserInfo; import com.ningdatech.pmapi.user.model.po.ReqUserDetailEditPO; -import com.ningdatech.pmapi.user.model.po.ReqUserDisablePO; +import com.ningdatech.pmapi.user.model.po.ReqUserDetailPO; +import com.ningdatech.pmapi.user.model.po.ReqUserDisableOrEnablePO; import com.ningdatech.pmapi.user.model.po.ReqUserInfoListPO; import com.ningdatech.pmapi.user.model.vo.ResUserDetailVO; import com.ningdatech.pmapi.user.model.vo.ResUserInfoListVO; +import com.ningdatech.pmapi.user.model.vo.UserRoleVO; import com.ningdatech.pmapi.user.service.IUserInfoService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -31,6 +42,7 @@ public class UserInfoManage { private final IDingOrganizationService iDingOrganizationService; private final IDingEmployeeInfoService iDingEmployeeInfoService; private final IUserInfoService iUserInfoService; + private final IUserRoleService iUserRoleService; public PageVo list(ReqUserInfoListPO reqUserInfoListPO) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(DingEmployeeInfo.class) @@ -67,16 +79,78 @@ public class UserInfoManage { return pageVo; } - public void disableOrEnable(ReqUserDisablePO reqUserDisablePO) { - - + public void disableOrEnable(ReqUserDisableOrEnablePO reqUserDisableOrEnablePO) { + Long userId = generateUserId(reqUserDisableOrEnablePO.getEmployeeCode()); + UserInfo userInfo = iUserInfoService.getById(userId); + userInfo.setAvailable(reqUserDisableOrEnablePO.getOperation()); + iUserInfoService.updateById(userInfo); } - public ResUserDetailVO userInfoDetail(ReqUserInfoListPO reqUserInfoListPO) { - return null; + public ResUserDetailVO userInfoDetail(ReqUserDetailPO reqUserDetailPO) { + Long userId = generateUserId(reqUserDetailPO.getEmployeeCode()); + UserInfo userInfo = iUserInfoService.getById(userId); + if (Objects.isNull(userInfo)) { + return null; + } + ResUserDetailVO resUserDetailVO = new ResUserDetailVO(); + + resUserDetailVO.setUserId(userInfo.getId()); + resUserDetailVO.setPhoneNo(userInfo.getMobile()); + resUserDetailVO.setStatus(userInfo.getAvailable()); + resUserDetailVO.setUserRoleInfoList(new ArrayList<>()); + return resUserDetailVO; } + @Transactional(rollbackFor = Exception.class) public void userInfoDetailEdit(ReqUserDetailEditPO reqUserDetailEditPO) { + Long userId = generateUserId(reqUserDetailEditPO.getEmployeeCode()); + UserInfo userInfo = iUserInfoService.getById(userId); + if (Objects.isNull(userInfo)) { + return; + } + userInfo.setMobile(reqUserDetailEditPO.getPhoneNo()); + userInfo.setAvailable(reqUserDetailEditPO.getStatus()); + iUserInfoService.updateById(userInfo); + + List userRoleInfoList = reqUserDetailEditPO.getUserRoleInfoList(); + iUserRoleService.remove(Wrappers.lambdaQuery(UserRole.class).eq(UserRole::getUserId, userId)); + if (CollUtil.isNotEmpty(userRoleInfoList)) { + List userRoleList = userRoleInfoList.stream().map(r -> { + UserRole saveRecord = new UserRole(); + saveRecord.setRoleId(r.getId()); + saveRecord.setUserId(userId); + return saveRecord; + }).collect(Collectors.toList()); + iUserRoleService.saveBatch(userRoleList); + } + + } + + private Long generateUserId(String employeeCode) { + UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) + .eq(UserInfo::getEmployeeCode, employeeCode)); + if (Objects.isNull(userInfo)) { + List dingEmployeeInfoList = iDingEmployeeInfoService.list(Wrappers.lambdaQuery(DingEmployeeInfo.class) + .eq(DingEmployeeInfo::getMainJob, "true")); + if (CollUtil.isEmpty(dingEmployeeInfoList)) { + throw new BizException("员工账号不存在"); + } + DingEmployeeInfo dingEmployeeInfo = dingEmployeeInfoList.get(0); + userInfo = UserInfo.builder() + .accountId(dingEmployeeInfo.getAccountId()) + .username(dingEmployeeInfo.getEmployeeName()) + .realName(dingEmployeeInfo.getEmployeeName()) + .available(UserAvailableEnum.DISABLE.name()) + .createBy(-1L) + .updateBy(-1L) + .createOn(LocalDateTime.now()) + .updateOn(LocalDateTime.now()) + .build(); + iUserInfoService.save(userInfo); + } + return userInfo.getId(); } + + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/base/UserRoleInfo.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/base/UserRoleInfo.java deleted file mode 100644 index e5450dc..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/base/UserRoleInfo.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.ningdatech.pmapi.user.model.base; - -import com.baomidou.mybatisplus.annotation.TableField; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import javax.validation.constraints.Size; - -import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE; - -/** - * @author liuxinxin - * @date 2022/8/22 下午4:12 - */ -@Data -@ApiModel("用户角色信息") -public class UserRoleInfo { - - @ApiModelProperty(value = "名称") - private String name; - - @ApiModelProperty(value = "枚举code") - private String code; - - @ApiModelProperty(value = "描述") - @Size(max = 100, message = "描述长度不能超过100") - @TableField(value = "describe", condition = LIKE) - private String describe; - - @ApiModelProperty(value = "排序") - private Integer roleSort; -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDetailEditPO.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDetailEditPO.java index cc35679..fd3c895 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDetailEditPO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDetailEditPO.java @@ -1,10 +1,11 @@ package com.ningdatech.pmapi.user.model.po; -import com.ningdatech.pmapi.user.model.base.UserRoleInfo; +import com.ningdatech.pmapi.user.model.vo.UserRoleVO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import javax.validation.constraints.NotBlank; import java.util.List; /** @@ -12,18 +13,24 @@ import java.util.List; * @date 2023/2/15 上午8:43 */ @Data -@ApiModel("获取用户详情编辑请求") +@ApiModel("用户详情编辑请求") public class ReqUserDetailEditPO { @ApiModelProperty("userId") private Long userId; + @NotBlank(message = "浙政钉 用户编码 不能为空") + @ApiModelProperty("浙政钉 用户编码") + private String employeeCode; + + @NotBlank(message = "用户手机号不能为空") @ApiModelProperty("手机号") private String phoneNo; - @ApiModelProperty("状态 启用/禁用") - private Boolean status; + @NotBlank(message = "状态不能为空") + @ApiModelProperty("状态 启用 ENABLE/禁用 DISABLE") + private String status; @ApiModelProperty("用户角色信息列表") - private List userRoleInfoList; + private List userRoleInfoList; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDetailPO.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDetailPO.java index c162e0b..0cb0b7e 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDetailPO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDetailPO.java @@ -4,7 +4,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import javax.validation.constraints.NotNull; +import javax.validation.constraints.NotBlank; /** * @author liuxinxin @@ -14,7 +14,11 @@ import javax.validation.constraints.NotNull; @ApiModel("获取用户详情请求") public class ReqUserDetailPO { - @NotNull(message = "用户id 不能为空") @ApiModelProperty("用户id") private Long userId; + + @NotBlank(message = "浙政钉 用户编码 不能为空") + @ApiModelProperty("浙政钉 用户编码") + private String employeeCode; + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDisableOrEnablePO.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDisableOrEnablePO.java new file mode 100644 index 0000000..fe5466a --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDisableOrEnablePO.java @@ -0,0 +1,30 @@ +package com.ningdatech.pmapi.user.model.po; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @author liuxinxin + * @date 2023/2/13 上午9:31 + */ + +@Data +@ApiModel("用户禁用/启用 PO") +public class ReqUserDisableOrEnablePO { + + @ApiModelProperty("用户id") + private Long userId; + + @NotBlank(message = "浙政钉 用户编码 不能为空") + @ApiModelProperty("浙政钉 用户编码") + private String employeeCode; + + @NotBlank(message = "操作 不能为空") + @ApiModelProperty("操作 启用 ENABLE/禁用 DISABLE") + private String operation; + + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDisablePO.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDisablePO.java deleted file mode 100644 index 96196fb..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserDisablePO.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.ningdatech.pmapi.user.model.po; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import javax.validation.constraints.NotBlank; - -/** - * @author liuxinxin - * @date 2023/2/13 上午9:31 - */ - -@Data -@ApiModel("用户禁用/启用 PO") -public class ReqUserDisablePO { - - @ApiModelProperty("用户id") - private Long userId; - - @NotBlank(message = "浙政钉 用户编码 不能为空") - @ApiModelProperty("浙政钉 用户编码") - private String employeeCode; - - @NotBlank(message = "浙政钉 用户编码 不能为空") - @ApiModelProperty("操作 true: 启用 / false 禁用") - private Boolean operation; - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserInfoListPO.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserInfoListPO.java index 9706f1e..9b2ff6d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserInfoListPO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/po/ReqUserInfoListPO.java @@ -1,7 +1,7 @@ package com.ningdatech.pmapi.user.model.po; import com.ningdatech.basic.model.PagePo; -import com.ningdatech.pmapi.sys.model.entity.Role; +import com.ningdatech.pmapi.user.model.vo.UserRoleVO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -28,8 +28,11 @@ public class ReqUserInfoListPO extends PagePo { @ApiModelProperty("所属区域") private Long regionId; + @ApiModelProperty("所属区域名称") + private Long regionName; + @ApiModelProperty("用户角色") - private List userRoleList; + private List userRoleList; @ApiModelProperty("状态") private String status; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserDetailVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserDetailVO.java index e040015..7b65b6a 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserDetailVO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/ResUserDetailVO.java @@ -1,6 +1,5 @@ package com.ningdatech.pmapi.user.model.vo; -import com.ningdatech.pmapi.user.model.base.UserRoleInfo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -21,9 +20,9 @@ public class ResUserDetailVO { @ApiModelProperty("手机号") private String phoneNo; - @ApiModelProperty("状态 启用/禁用") - private Boolean status; + @ApiModelProperty("状态 启用 ENABLE/禁用 DISABLE") + private String status; @ApiModelProperty("用户角色信息列表") - private List userRoleInfoList; + private List userRoleInfoList; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/UserRoleVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/UserRoleVO.java new file mode 100644 index 0000000..50cc474 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/model/vo/UserRoleVO.java @@ -0,0 +1,21 @@ +package com.ningdatech.pmapi.user.model.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author liuxinxin + * @date 2023/2/15 下午5:47 + */ + +@Data +@ApiModel("用户角色VO") +public class UserRoleVO { + + @ApiModelProperty(value = "角色id") + private Long id; + + @ApiModelProperty(value = "名称") + private String name; +}