package com.gkhy.safePlatform.account.service.impl;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.gkhy.safePlatform.account.entity.schedule.GroupInfoDO;
|
import com.gkhy.safePlatform.account.entity.schedule.GroupStrategyUserTimeTableInfo;
|
import com.gkhy.safePlatform.account.entity.schedule.GroupStrategyUserTimeTableInfoDO;
|
import com.gkhy.safePlatform.account.entity.user.PositionInfoDO;
|
import com.gkhy.safePlatform.account.enums.*;
|
import com.gkhy.safePlatform.account.enums.schedule.TimeTypeEnum;
|
import com.gkhy.safePlatform.account.model.dto.req.AccountAddReqDTO;
|
import com.gkhy.safePlatform.account.model.dto.req.AccountModReqDTO;
|
import com.gkhy.safePlatform.account.entity.enterprise.DepartmentInfo;
|
import com.gkhy.safePlatform.account.entity.user.RoleInfo;
|
import com.gkhy.safePlatform.account.entity.user.UserInfoDO;
|
import com.gkhy.safePlatform.account.model.dto.req.AccountPwdForgetReqDTO;
|
import com.gkhy.safePlatform.account.model.dto.resp.*;
|
import com.gkhy.safePlatform.account.model.query.AccountQuery;
|
import com.gkhy.safePlatform.account.model.query.UserScheduleQuery;
|
import com.gkhy.safePlatform.account.model.query.db.AccountDBQuery;
|
import com.gkhy.safePlatform.account.model.query.db.UserScheduleDBQuery;
|
import com.gkhy.safePlatform.account.service.AccountService;
|
import com.gkhy.safePlatform.account.service.baseService.*;
|
import com.gkhy.safePlatform.account.entity.user.UserInfo;
|
import com.gkhy.safePlatform.account.utils.IdCardUtil;
|
import com.gkhy.safePlatform.account.utils.PasswordUtil;
|
import com.gkhy.safePlatform.account.utils.RegexUtil;
|
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
|
import com.gkhy.safePlatform.commons.enums.E;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.enums.UserTypeEnum;
|
import com.gkhy.safePlatform.commons.exception.AusinessException;
|
import com.gkhy.safePlatform.commons.exception.BusinessException;
|
import com.gkhy.safePlatform.commons.query.PageQuery;
|
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
|
import com.gkhy.safePlatform.commons.utils.StringUtils;
|
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
|
import org.redisson.api.RLock;
|
import org.redisson.api.RedissonClient;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.util.*;
|
import java.util.concurrent.TimeUnit;
|
|
@Service
|
public class AccountServiceImpl implements AccountService {
|
|
@Autowired
|
private UserInfoService userInfoService;
|
@Autowired
|
private RoleInfoService roleInfoService;
|
@Autowired
|
private PositionInfoService positionInfoService;
|
@Autowired
|
private DepartmentInfoService departmentInfoService;
|
@Autowired
|
private GroupInfoService groupInfoService;
|
@Autowired
|
private GroupMemberInfoService groupMemberInfoService;
|
@Autowired
|
private GroupStrategyUserTimeTableInfoService groupStrategyUserTimeTableInfoService;
|
@Autowired
|
private RedissonClient redissonClient;
|
|
@Override
|
public UserInfo getCurrentUserInfoByUsername(String username) {
|
return userInfoService.getUserByUsername(username);
|
}
|
|
/**
|
* @Description: 根据userId 获取用户个人性息
|
*/
|
@Override
|
public PersonalDetailRespDTO getPersonalAccountByUserId(Long userId) {
|
// 用户
|
UserInfo userInfo = userInfoService.getUserByUserId(userId);
|
// 角色
|
PersonalDetailRoleRespDTO role = null;
|
if (userInfo.getRoleId() != null) {
|
RoleInfo roleInfo = roleInfoService.getRoleInfoById(userInfo.getRoleId());
|
if (roleInfo != null) {
|
role = new PersonalDetailRoleRespDTO();
|
role.setRoleId(roleInfo.getId());
|
role.setRoleCode(roleInfo.getCode());
|
role.setRoleName(roleInfo.getName());
|
role.setRoleInfo(roleInfo.getInfo());
|
}
|
}
|
|
|
//部门
|
PersonalDetailDepRespDTO dep = null;
|
if (userInfo.getDepId() != null) {
|
DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(userInfo.getDepId());
|
if (departmentInfo != null) {
|
dep = new PersonalDetailDepRespDTO();
|
dep.setDepId(departmentInfo.getId());
|
dep.setDepInfo(departmentInfo.getInfo());
|
dep.setDepName(departmentInfo.getName());
|
dep.setDepLevel(departmentInfo.getLevel());
|
DepartmentLevelEnum levelEnum = DepartmentLevelEnum.parse(departmentInfo.getLevel());
|
if (levelEnum != null) {
|
dep.setDepLevelDesc(levelEnum.value);
|
}
|
}
|
|
}
|
|
// 获取角色信息
|
// roleInfoService.get
|
return new PersonalDetailRespDTO(
|
userInfo.getUid(),
|
userInfo.getUsername(),
|
userInfo.getRealName(),
|
userInfo.getType(),
|
userInfo.getStatus(),
|
userInfo.getPhone(),
|
userInfo.getEmail(),
|
role,
|
dep
|
);
|
}
|
|
/**
|
* @Description: 新增用户
|
*/
|
@Override
|
@Transactional
|
public void addAccount(ContextCacheUser currentUser, AccountAddReqDTO accountAddDto) {
|
|
// // 身份证判空
|
// if (StringUtils.isBlank(accountAddDto.getIdentify())) {
|
// throw new AusinessException(E.DATA_PARAM_NULL,"身份证不可为空");
|
// }
|
// 身份证合法
|
String identify = accountAddDto.getIdentify();
|
if (StringUtils.isNotBlank(identify)) {
|
identify = identify.trim();
|
if (!IdCardUtil.strongVerifyIdNumber(identify)) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"身份证校验非法");
|
}
|
}
|
// 手机校验
|
if (StringUtils.isBlank(accountAddDto.getPhone())) {
|
throw new AusinessException(E.DATA_PARAM_NULL,"手机号不能为空");
|
}
|
// 手机规则
|
if (!RegexUtil.isMobile(accountAddDto.getPhone().trim())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "手机号校验非法");
|
}
|
if (accountAddDto.getType() == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "用户类型不能为空");
|
}
|
UserTypeEnum userTypeEnum = UserTypeEnum.parse(accountAddDto.getType());
|
if (userTypeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "用户类型非法");
|
}
|
// 无法创建type 为1 的管理员类型
|
if (userTypeEnum == UserTypeEnum.ADMIN) {
|
throw new AusinessException(E.DATA_OPERATION_NO_PERMISSION, "当前用户没有创建该用户类型权限");
|
}
|
// // 邮箱校验
|
// if (StringUtils.isBlank(accountAddDto.getEmail())) {
|
// throw new AusinessException(E.DATA_PARAM_NULL,"邮箱不能为空");
|
// }
|
// 邮箱规则
|
String email = accountAddDto.getEmail();
|
if (StringUtils.isNotBlank(email)) {
|
email = email.trim();
|
if (!RegexUtil.isEmail(accountAddDto.getEmail().trim())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "邮箱校验非法");
|
}
|
}
|
|
if (StringUtils.isBlank(accountAddDto.getPassword())) {
|
throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_PASSWORD_NULL);
|
}
|
// todo 密码 格式校验
|
|
if (accountAddDto.getGender() == null) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "性别不可为空");
|
}
|
if (StringUtils.isBlank(accountAddDto.getRealName())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "真实姓名不可为空");
|
}
|
if (accountAddDto.getExpireTime() == null) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "过期时间不可为空");
|
}
|
if (accountAddDto.getStatus() == null) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "用户状态不可为空");
|
}
|
if (accountAddDto.getRoleId() == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (accountAddDto.getDepId() == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (accountAddDto.getPositionId() == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
// 状态区间
|
UserStatusEnum userStatus= UserStatusEnum.parse(accountAddDto.getStatus());
|
if (userStatus == null) {
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "用户状态参数非法");
|
}
|
// 性别区间
|
GenderEnum gender = GenderEnum.parse(accountAddDto.getGender());
|
if (gender == null) {
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "性别参数非法");
|
}
|
// 过期时间转换
|
Calendar instance = Calendar.getInstance();
|
instance.setTime(accountAddDto.getExpireTime());
|
instance.set(Calendar.HOUR_OF_DAY,23);
|
instance.set(Calendar.MINUTE,59);
|
instance.set(Calendar.SECOND,59);
|
|
// 手机号重复
|
long count;
|
count = userInfoService.countByPhone(accountAddDto.getPhone().trim());
|
if (count > 0) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "手机号已被占用");
|
}
|
// // 身份证重复
|
// count = userInfoService.countByIdentify(identify);
|
// if (count > 0) {
|
// throw new AusinessException(E.DATA_DATABASE_EXIST,"身份证已经存在");
|
// }
|
// // 邮箱重复
|
// count = userInfoService.countByEmail(accountAddDto.getEmail());
|
// if (count > 0) {
|
// throw new AusinessException(E.DATA_DATABASE_EXIST,"邮箱已经存在");
|
// }
|
|
// 角色判断
|
RoleInfo roleInfo = roleInfoService.getRoleInfoById(accountAddDto.getRoleId());
|
if (roleInfo == null) {
|
throw new BusinessException(ResultCodes.CLIENT_ROLE_NOT_EXIST);
|
}
|
if (roleInfo.getStatus() != RoleStatusEnum.ENABLED.getCode()) {
|
throw new BusinessException(ResultCodes.CLIENT_ROLE_DISABLED);
|
}
|
// 部门判断
|
DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(accountAddDto.getDepId());
|
if (departmentInfo == null) {
|
throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
|
}
|
if (!departmentInfo.getStatus().equals(DepartmentStatusEnum.ENABLED.getCode())) {
|
throw new BusinessException(ResultCodes.CLIENT_DEP_DISABLED);
|
}
|
if (departmentInfo.getLevel().equals(DepartmentLevelEnum.COMPANY.code)) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "人员无法从属于总部门");
|
}
|
|
// 岗位判断
|
PositionInfoDO positionInfoDO = positionInfoService.getPositionInfoById(accountAddDto.getPositionId());
|
if (positionInfoDO == null) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "岗位不存在");
|
}
|
if (!positionInfoDO.getStatus().equals(PositionStatusEnum.ENABLED.getCode())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "岗位不存在");
|
}
|
RLock lock = redissonClient.getLock("LOCK_USER_ADD");
|
try {
|
lock.lock(3, TimeUnit.SECONDS);
|
// username 生成
|
String realName = accountAddDto.getRealName().trim();
|
count = userInfoService.countByRealName(realName);
|
String username = realName;
|
if (count > 0) {
|
username = username + count;
|
}
|
// 盐和密码生成
|
String salt = PasswordUtil.makeSalt();
|
String hash = PasswordUtil.makePassword(accountAddDto.getPassword().trim(), salt);
|
// 1.用户新增
|
UserInfo userInfo = new UserInfo();
|
userInfo.setType(userTypeEnum.getCode());
|
userInfo.setSalt(salt);
|
userInfo.setHash(hash);
|
userInfo.setGender(gender.getCode());
|
userInfo.setUsername(username);
|
userInfo.setRealName(realName);
|
userInfo.setIdentify(identify);
|
userInfo.setPhone(accountAddDto.getPhone());
|
userInfo.setEmail(email);
|
userInfo.setExpireTime(instance.getTime());
|
userInfo.setGmtCreate(new Date());
|
userInfo.setDepId(accountAddDto.getDepId());
|
userInfo.setStatus(userStatus.getCode());
|
userInfo.setPhone(accountAddDto.getPhone());
|
userInfo.setEmail(accountAddDto.getEmail());
|
userInfo.setRoleId(accountAddDto.getRoleId());
|
userInfo.setPositionId(accountAddDto.getPositionId());
|
userInfoService.saveUserInfo(userInfo);
|
lock.unlock();
|
}catch (BusinessException e){
|
e.printStackTrace();
|
throw new BusinessException(e.getCode(),e.getMessage());
|
}catch (Exception e) {
|
e.printStackTrace();
|
throw new BusinessException(ResultCodes.SERVER_ADD_ERROR);
|
}finally {
|
if (lock.isLocked()) {
|
lock.unlock();
|
}
|
}
|
|
|
|
}
|
|
|
/**
|
* @Description: 修改账户信息
|
*/
|
@Override
|
@Transactional
|
public void modAccount(ContextCacheUser currentUser, AccountModReqDTO accountModDto) {
|
|
if (accountModDto.getUid() == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
UserInfo userInfo = userInfoService.getUserByUserId(accountModDto.getUid());
|
if (userInfo == null) {
|
throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
|
}
|
assert userInfo.getStatus() != null;
|
UserStatusEnum status = UserStatusEnum.parse(userInfo.getStatus());
|
if (status != UserStatusEnum.VALID) {
|
throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
|
}
|
// 新建更新对象
|
UserInfo userEntity = new UserInfo();
|
userEntity.setUid(accountModDto.getUid());
|
|
// *用户类型
|
if (accountModDto.getType() != null) {
|
UserTypeEnum userTypeEnum = UserTypeEnum.parse(accountModDto.getType());
|
if (userTypeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "用户类型非法");
|
}
|
if (userTypeEnum == UserTypeEnum.ADMIN) {
|
throw new AusinessException(E.DATA_OPERATION_NO_PERMISSION, "当前用户没有创建该用户类型权限");
|
}
|
userEntity.setType(userTypeEnum.getCode());
|
}
|
|
// 真实姓名
|
String realName = accountModDto.getRealName();
|
if (StringUtils.isNotBlank(realName)
|
&& !realName.trim().equals(userInfo.getRealName())) {
|
userEntity.setRealName(realName.trim());
|
long count = userInfoService.countByRealName(realName.trim());
|
String username = realName.trim();
|
if (count > 0) {
|
username = username + count;
|
}
|
userEntity.setUsername(username);
|
}
|
|
//身份证校验
|
String identify = accountModDto.getIdentify();
|
if (StringUtils.isNotBlank(identify)
|
&& !identify.trim().equals(userInfo.getIdentify())) {
|
if (!IdCardUtil.strongVerifyIdNumber(identify.trim())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"身份证校验非法");
|
}
|
UserInfo userByIdentify = userInfoService.getUserInfoByIdentify(identify.trim());
|
if (userByIdentify != null && !userByIdentify.getUid().equals(userInfo.getUid())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST,"身份证已经存在");
|
}
|
userEntity.setIdentify(identify.trim());
|
}
|
|
// todo 校验密码
|
// 检验手机号
|
if (StringUtils.isNotBlank(accountModDto.getPhone())
|
&& !accountModDto.getPhone().trim().equals(userInfo.getPhone())) {
|
String phone = accountModDto.getPhone().trim();
|
if (!RegexUtil.isMobile(phone)) {
|
// 手机校验
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "手机校验非法");
|
}
|
UserInfo userInfoByPhone = userInfoService.getUserInfoByPhone(phone);
|
if (userInfoByPhone != null && !userInfoByPhone.getUid().equals(userInfo.getUid())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "手机号已被占用");
|
}
|
userEntity.setPhone(phone);
|
}
|
// 邮箱
|
if (StringUtils.isNotBlank(accountModDto.getEmail())) {
|
String email = accountModDto.getEmail().trim();
|
if (!RegexUtil.isEmail(email)) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "邮箱校验非法");
|
}
|
UserInfo userInfoByEmail = userInfoService.getUserInfoByEmail(email);
|
if (userInfoByEmail != null && !userInfoByEmail.getUid().equals(userInfo.getUid())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "邮箱已被占用");
|
}
|
userEntity.setEmail(email);
|
}
|
|
|
// 部门判断
|
if (accountModDto.getDepId() != null) {
|
DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(accountModDto.getDepId());
|
if (departmentInfo == null) {
|
throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
|
}
|
if (departmentInfo.getLevel().equals(DepartmentLevelEnum.COMPANY.code)) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "人员无法从属于总部门");
|
}
|
userEntity.setDepId(accountModDto.getDepId());
|
}
|
|
// 角色判断
|
if (accountModDto.getRoleId() != null) {
|
RoleInfo roleInfo = roleInfoService.getRoleInfoById(accountModDto.getRoleId());
|
if (roleInfo == null) {
|
throw new BusinessException(ResultCodes.CLIENT_ROLE_NOT_EXIST);
|
}
|
userEntity.setRoleId(accountModDto.getRoleId());
|
}
|
|
// 岗位判断
|
if (accountModDto.getPositionId() != null) {
|
PositionInfoDO positionInfoDO = positionInfoService.getPositionInfoById(accountModDto.getPositionId());
|
if (positionInfoDO == null) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "岗位不存在");
|
}
|
if (!positionInfoDO.getStatus().equals(PositionStatusEnum.ENABLED.getCode())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "岗位不存在");
|
}
|
userEntity.setPositionId(accountModDto.getPositionId());
|
}
|
|
|
// 密码
|
if (StringUtils.isNotBlank(accountModDto.getPassword())) {
|
String password = accountModDto.getPassword().trim();
|
// todo 格式校验
|
// 重置盐
|
String salt = PasswordUtil.makeSalt();
|
String hash = PasswordUtil.makePassword(password, salt);
|
userEntity.setHash(hash);
|
userEntity.setSalt(salt);
|
}
|
|
// 用户状态
|
if (accountModDto.getStatus() != null) {
|
// 状态区间
|
UserStatusEnum userStatus = UserStatusEnum.parse(accountModDto.getStatus());
|
if (userStatus == null) {
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "用户状态参数非法");
|
}
|
userEntity.setStatus(userStatus.getCode() );
|
}
|
// 过期时间
|
if (accountModDto.getExpireTime() != null) {
|
Calendar instance = Calendar.getInstance();
|
instance.setTime(accountModDto.getExpireTime());
|
instance.set(Calendar.HOUR_OF_DAY,23);
|
instance.set(Calendar.MINUTE,59);
|
instance.set(Calendar.SECOND,59);
|
userEntity.setExpireTime(instance.getTime());
|
}
|
// 性别
|
if (accountModDto.getGender() != null) {
|
// 性别区间
|
GenderEnum gender = GenderEnum.parse(accountModDto.getGender());
|
if (gender == null) {
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "性别参数非法");
|
}
|
userEntity.setGender(gender.getCode());
|
}
|
|
|
userEntity.setGmtModified(new Date());
|
userInfoService.updateUserInfo(userEntity);
|
|
|
}
|
|
@Override
|
public SearchResultVO<List<UserDetailRespDTO>> listAccountByPage(Long userId, PageQuery<AccountQuery> pageQuery) {
|
;
|
AccountDBQuery accountDBQuery = new AccountDBQuery();
|
if (pageQuery.getSearchParams() != null) {
|
BeanUtils.copyProperties(pageQuery.getSearchParams(), accountDBQuery);
|
}
|
|
|
Page<UserInfoDO> page = new Page<>(pageQuery.getPageIndex(), pageQuery.getPageSize());
|
List<UserInfoDO> users = userInfoService.listPage(page,accountDBQuery);
|
// 准备工作
|
List<UserDetailRespDTO> userDetails = new ArrayList<>(users.size());
|
Map<Long, UserDepartmentRespDTO> depPool = new HashMap<>();
|
Map<Long, UserRoleRespDTO> rolePool = new HashMap<>();
|
Map<Long, UserPositionRespDTO> positionPool = new HashMap<>();
|
UserDepartmentRespDTO dep;
|
UserRoleRespDTO role;
|
UserPositionRespDTO position;
|
// 数据整合
|
if (users.size() > 0) {
|
for (UserInfoDO user : users) {
|
UserDetailRespDTO userDetail = new UserDetailRespDTO();
|
BeanUtils.copyProperties(user, userDetail);
|
// 部门
|
if (userDetail.getDepId() != null) {
|
if (!depPool.containsKey(userDetail.getDepId())) {
|
DepartmentInfo depInfo = departmentInfoService.getDepartmentInfoById(userDetail.getDepId());
|
if (depInfo != null ) {
|
dep = new UserDepartmentRespDTO();
|
dep.setDepId(depInfo.getId());
|
dep.setDepName(depInfo.getName());
|
dep.setDepLevel(depInfo.getLevel());
|
depPool.put(dep.getDepId(), dep);
|
|
}
|
}
|
dep = depPool.get(userDetail.getDepId());
|
// 设置部门
|
userDetail.setDepartment(dep);
|
}
|
// 角色
|
if (userDetail.getRoleId() != null) {
|
if (!rolePool.containsKey(userDetail.getRoleId())) {
|
RoleInfo roleInfo = roleInfoService.getById(userDetail.getRoleId());
|
if (roleInfo != null) {
|
role = new UserRoleRespDTO();
|
role.setRoleId(roleInfo.getId());
|
role.setRoleCode(roleInfo.getCode());
|
role.setRoleName(roleInfo.getName());
|
rolePool.put(role.getRoleId(), role);
|
}
|
}
|
role = rolePool.get(userDetail.getRoleId());
|
// 设置角色
|
userDetail.setRole(role);
|
}
|
|
|
// 岗位
|
if (userDetail.getPositionId() != null) {
|
if (!positionPool.containsKey(userDetail.getPositionId())) {
|
PositionInfoDO positionInfoDO = positionInfoService.getPositionInfoById(userDetail.getPositionId());
|
if (positionInfoDO != null) {
|
position = new UserPositionRespDTO();
|
position.setPositionId(positionInfoDO.getId());
|
position.setPositionCode(positionInfoDO.getCode());
|
position.setPositionName(positionInfoDO.getName());
|
positionPool.put(positionInfoDO.getId(), position);
|
}
|
}
|
position = positionPool.get(userDetail.getPositionId());
|
// 设置岗位
|
userDetail.setPosition(position);
|
}
|
|
userDetails.add(userDetail);
|
}
|
}
|
|
return new SearchResultVO<>(
|
true,
|
page.getCurrent(),
|
page.getSize(),
|
page.getPages(),
|
page.getTotal(),
|
userDetails,
|
ResultCodes.OK);
|
|
}
|
|
|
/**
|
* @Description: 获取部门下用户信息
|
*/
|
@Override
|
public List<DepUserInfoRespDTO> getDepUserList(Long userId, Long depId) {
|
;
|
if (depId == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(depId);
|
if (departmentInfo == null) {
|
throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
|
}
|
List<UserInfoDO> data = userInfoService.getDepUserList(depId);
|
return BeanCopyUtils.copyBeanList(data, DepUserInfoRespDTO.class);
|
}
|
|
@Override
|
@Transactional
|
public void delAccount(ContextCacheUser currentUser, Long uid) {
|
if (uid == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
UserInfo userInfo = userInfoService.getUserByUserId(uid);
|
if (userInfo == null) {
|
throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
|
}
|
assert userInfo.getStatus() != null;
|
if (!currentUser.getType().equals(UserTypeEnum.ADMIN.getCode())) {
|
throw new AusinessException(E.DATA_OPERATION_NO_PERMISSION, "不好意思,当前用户没有删除权限");
|
}
|
if (currentUser.getType().equals(userInfo.getType())) {
|
throw new AusinessException(E.DATA_OPERATION_NO_PERMISSION, "同类型人员不能操作删除");
|
}
|
|
UserStatusEnum statusEnum = UserStatusEnum.parse(userInfo.getStatus());
|
if (statusEnum == UserStatusEnum.ABANDONED) {
|
throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_DELETE);
|
}
|
|
UserInfo user = new UserInfo();
|
user.setUid(userInfo.getUid());
|
user.setStatus(UserStatusEnum.ABANDONED.getCode());
|
user.setGmtModified(new Date());
|
userInfoService.updateUserInfo(user);
|
}
|
|
@Override
|
public List<UserTimeTableRespDTO> getUserScheduleInfo(ContextCacheUser currentUser, UserScheduleQuery userScheduleQuery) {
|
;
|
if (userScheduleQuery.getStartTime() == null || userScheduleQuery.getEndTime() == null) {
|
throw new AusinessException(E.DATA_PARAM_NULL,"时间不能为空");
|
}
|
if (userScheduleQuery.getStartTime().after(userScheduleQuery.getEndTime())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"时间区间非法");
|
}
|
if (userScheduleQuery.getUid() == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
UserInfo userInfo = userInfoService.getUserByUserId(userScheduleQuery.getUid());
|
if (userInfo == null) {
|
throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
|
}
|
if (!userInfo.getStatus().equals(UserStatusEnum.VALID.getCode())) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "用户不存在");
|
}
|
|
UserScheduleDBQuery userScheduleDBQuery = new UserScheduleDBQuery();
|
// 查询对象
|
BeanUtils.copyProperties(userScheduleQuery, userScheduleDBQuery);
|
List<UserTimeTableRespDTO> result = new ArrayList<>();
|
List<GroupStrategyUserTimeTableInfoDO> userTimeTableInfos = groupStrategyUserTimeTableInfoService.getUserTimeTableInfoDOs(userScheduleDBQuery);
|
|
if (userTimeTableInfos.size() > 0) {
|
TimeTypeEnum typeEnum;
|
Map<LocalDate,UserTimeTableRespDTO> dayPool = new HashMap<>();
|
GroupStrategyUserTimeTableInfoDO userTimeTableInfo;
|
UserTimeTableDetailRespDTO userTimeTableDetailInfo;
|
for (int j = 0; j < userTimeTableInfos.size(); j++) {
|
userTimeTableInfo = userTimeTableInfos.get(j);
|
userTimeTableDetailInfo = new UserTimeTableDetailRespDTO();
|
userTimeTableDetailInfo.setStartTime(userTimeTableInfo.getStartTime());
|
userTimeTableDetailInfo.setEndTime(userTimeTableInfo.getEndTime());
|
userTimeTableDetailInfo.setType(userTimeTableInfo.getType());
|
typeEnum = TimeTypeEnum.parse(userTimeTableInfo.getType());
|
if (typeEnum != null) {
|
userTimeTableDetailInfo.setTypeDesc(typeEnum.getValue());
|
}
|
|
// 区分开
|
if (!dayPool.containsKey(userTimeTableInfo.getSpecificDate())) {
|
UserTimeTableRespDTO userTimeTableRespDTO = new UserTimeTableRespDTO();
|
userTimeTableRespDTO.setDay(userTimeTableInfo.getSpecificDate());
|
|
userTimeTableRespDTO.setTimeDetails(Collections.singletonList(userTimeTableDetailInfo));
|
dayPool.put(userTimeTableInfo.getSpecificDate(), userTimeTableRespDTO);
|
}else{
|
UserTimeTableRespDTO userTimeTableRespDTOS = dayPool.get(userTimeTableInfo.getSpecificDate());
|
userTimeTableRespDTOS.getTimeDetails().add(userTimeTableDetailInfo);
|
}
|
}
|
|
// 整合
|
result.addAll(dayPool.values());
|
}
|
|
|
return result;
|
}
|
|
@Override
|
public UserGroupTimTableRespDTO getUserGroupWorkSchedule(Long uid,LocalDate startTime,LocalDate endTime) {
|
// ;
|
// // 获取
|
// if (uid == null) {
|
// throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
|
// }
|
// UserGroupTimTableRespDTO res = new UserGroupTimTableRespDTO();
|
// UserInfo userInfo = userInfoService.getUserByUserId(uid);
|
// if (userInfo != null) {
|
// res.setUid(userInfo.getUid());
|
// res.setRealName(userInfo.getRealName());
|
// res.setUsername(userInfo.getUsername());
|
// res.setPhone(userInfo.getPhone());
|
// }
|
//
|
// List<GroupInfoDO> groupInfo = groupMemberInfoService.listGroupInfoByUserId(uid);
|
// if (groupInfo != null) {
|
// res.setGroupId(groupInfo.getId());
|
// res.setGroupName(groupInfo.getName());
|
// }
|
// LocalDateTime startDateTime = startTime.atStartOfDay();
|
// LocalDateTime endDateTime = startTime.atTime(23, 59, 59);
|
// List<GroupStrategyUserTimeTableInfoDO> dbData = groupStrategyUserTimeTableInfoService.listUserTimeTable(uid, startDateTime,endDateTime,TimeTypeEnum.WORK.getCode());
|
// List<UserTimeTableDetailRespDTO> result = new ArrayList<>(dbData.size());
|
// if (dbData.size() > 0) {
|
// UserTimeTableDetailRespDTO respDTO;
|
// for (GroupStrategyUserTimeTableInfoDO userTimeTableInfoDO : dbData) {
|
// respDTO = new UserTimeTableDetailRespDTO();
|
// respDTO.setStartTime(userTimeTableInfoDO.getStartTime());
|
// respDTO.setEndTime(userTimeTableInfoDO.getEndTime());
|
// respDTO.setType(userTimeTableInfoDO.getType());
|
// TimeTypeEnum timeTypeEnum = TimeTypeEnum.parse(userTimeTableInfoDO.getType());
|
// if (timeTypeEnum != null) {
|
// respDTO.setTypeDesc(timeTypeEnum.getValue());
|
// }
|
// result.add(respDTO);
|
// }
|
// }
|
// res.setTimeDetails(result);
|
return null;
|
}
|
|
@Override
|
public UserInfoRespDTO getUserInfoByUid(Long uid) {
|
UserInfo userInfo = userInfoService.getUserByUserId(uid);
|
if (userInfo == null) {
|
throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
|
}else{
|
UserInfoRespDTO result = new UserInfoRespDTO();
|
BeanUtils.copyProperties(userInfo, result);
|
return result;
|
}
|
|
|
}
|
|
@Override
|
public List<UserListRespDTO> getUserList(Long uid) {
|
List<UserInfoDO> dbData = userInfoService.listAllUser();
|
List<UserListRespDTO> result = new ArrayList<>(dbData.size());
|
UserListRespDTO respDTO;
|
for (UserInfoDO userInfoDO : dbData) {
|
respDTO = new UserListRespDTO();
|
respDTO.setUid(userInfoDO.getUid());
|
respDTO.setUsername(userInfoDO.getUsername());
|
respDTO.setRealName(userInfoDO.getRealName());
|
respDTO.setStatus(userInfoDO.getStatus());
|
respDTO.setPhone(userInfoDO.getPhone());
|
respDTO.setEmail(userInfoDO.getEmail());
|
result.add(respDTO);
|
}
|
return result;
|
}
|
|
@Override
|
public List<UserInfoRespDTO> listUserByUids(List<Long> uids) {
|
if (uids != null && uids.size() > 50) {
|
throw new BusinessException(ResultCodes.SERVER_SELECT_OVER_SIZE);
|
}
|
List<UserInfoDO> dbData = userInfoService.listUserByUids(uids);
|
List<UserInfoRespDTO> results = new ArrayList<>(dbData.size());
|
UserInfoRespDTO respDTO;
|
for (UserInfoDO userInfoDO : dbData) {
|
respDTO = new UserInfoRespDTO();
|
respDTO.setUid(userInfoDO.getUid());
|
respDTO.setUuid(userInfoDO.getUuid());
|
respDTO.setUsername(userInfoDO.getUsername());
|
respDTO.setRealName(userInfoDO.getRealName());
|
respDTO.setGender(userInfoDO.getGender());
|
respDTO.setType(userInfoDO.getType());
|
respDTO.setStatus(userInfoDO.getStatus());
|
respDTO.setPhone(userInfoDO.getPhone());
|
respDTO.setIdentify(userInfoDO.getIdentify());
|
respDTO.setEmail(userInfoDO.getEmail());
|
respDTO.setDepId(userInfoDO.getDepId());
|
respDTO.setRoleId(userInfoDO.getRoleId());
|
respDTO.setPositionId(userInfoDO.getPositionId());
|
results.add(respDTO);
|
}
|
|
return results;
|
}
|
|
@Override
|
public List<UserInfoRespDTO> listUserByRealName(String realName) {
|
List<UserInfoDO> dbData = userInfoService.listUserByRealName(realName);
|
List<UserInfoRespDTO> result = new ArrayList<>(dbData.size());
|
if (dbData.size() > 0) {
|
UserInfoRespDTO respDTO;
|
for (UserInfoDO userInfoDO : dbData) {
|
respDTO = new UserInfoRespDTO();
|
respDTO.setUid(userInfoDO.getUid());
|
respDTO.setUuid(userInfoDO.getUuid());
|
respDTO.setUsername(userInfoDO.getUsername());
|
respDTO.setRealName(userInfoDO.getRealName());
|
respDTO.setGender(userInfoDO.getGender());
|
respDTO.setType(userInfoDO.getType());
|
respDTO.setStatus(userInfoDO.getStatus());
|
respDTO.setPhone(userInfoDO.getPhone());
|
respDTO.setIdentify(userInfoDO.getIdentify());
|
respDTO.setEmail(userInfoDO.getEmail());
|
respDTO.setDepId(userInfoDO.getDepId());
|
respDTO.setRoleId(userInfoDO.getRoleId());
|
respDTO.setPositionId(userInfoDO.getPositionId());
|
result.add(respDTO);
|
}
|
}
|
return result;
|
}
|
|
@Override
|
public void pwdForget(AccountPwdForgetReqDTO reqDTO) {
|
if (StringUtils.isBlank(reqDTO.getRealName())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "姓名不能为空");
|
}
|
if (StringUtils.isBlank(reqDTO.getIdentify())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "身份证号不能为空");
|
}
|
if (StringUtils.isBlank(reqDTO.getPhone())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "手机号不能为空");
|
}
|
if (StringUtils.isBlank(reqDTO.getPassword())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "新密码不能为空");
|
}
|
if (StringUtils.isBlank(reqDTO.getRePassword())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "新密码确认不能为空");
|
}
|
// 两次密码填写
|
String newPassword = reqDTO.getPassword().trim();
|
if (!newPassword.equals(reqDTO.getRePassword().trim())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "两次密码填写不一致");
|
}
|
// 身份证号强校验
|
String identify = reqDTO.getIdentify().trim();
|
if (!IdCardUtil.strongVerifyIdNumber(identify)) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "身份证校验非法");
|
}
|
// 手机号强校验
|
String phone = reqDTO.getPhone().trim();
|
if (!RegexUtil.isMobile(phone)) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "手机号校验非法");
|
}
|
// todo 密码强校验
|
|
// 根据身份证获取用户
|
UserInfo thisUser = userInfoService.getUserInfoByIdentify(identify);
|
if (thisUser == null) {
|
throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
|
}
|
if (thisUser.getType().equals(UserTypeEnum.ADMIN.getCode())) {
|
throw new AusinessException(E.DATA_OPERATION_NO_PERMISSION, "用户不存在");
|
}
|
// 对比姓名
|
if (!thisUser.getRealName().equals(reqDTO.getRealName().trim())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "姓名不符合身份证");
|
}
|
// 对比手机号
|
if (!thisUser.getPhone().equals(phone)) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "手机号不符合身份证所绑定的手机号");
|
}
|
|
// exc
|
// 重置盐
|
String salt = PasswordUtil.makeSalt();
|
String hash = PasswordUtil.makePassword(newPassword, salt);
|
userInfoService.updatePassword(thisUser.getUid(), salt, hash);
|
}
|
|
|
}
|