|
@@ -30,7 +30,6 @@ import cn.hutool.core.lang.tree.TreeUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.PhoneUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.metadata.data.WriteCellData;
|
|
@@ -51,13 +50,12 @@ import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
|
|
import vip.xiaonuo.biz.core.enums.BizBuildInEnum;
|
|
|
import vip.xiaonuo.biz.core.enums.BizDataTypeEnum;
|
|
|
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
|
|
import vip.xiaonuo.biz.modular.org.service.BizOrgService;
|
|
|
-import vip.xiaonuo.biz.modular.position.entity.BizPosition;
|
|
|
-import vip.xiaonuo.biz.modular.position.service.BizPositionService;
|
|
|
import vip.xiaonuo.biz.modular.user.entity.BizUser;
|
|
|
import vip.xiaonuo.biz.modular.user.enums.BizRoleCategoryEnum;
|
|
|
import vip.xiaonuo.biz.modular.user.enums.BizUserStatusEnum;
|
|
@@ -114,8 +112,8 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
@Resource
|
|
|
private BizOrgService bizOrgService;
|
|
|
|
|
|
- @Resource
|
|
|
- private BizPositionService bizPositionService;
|
|
|
+// @Resource
|
|
|
+// private BizUploadImage uploadImage;
|
|
|
|
|
|
@Override
|
|
|
public Page<BizUser> page(BizUserPageParam bizUserPageParam) {
|
|
@@ -151,13 +149,28 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public void add(BizUserAddParam bizUserAddParam) {
|
|
|
- checkParam(bizUserAddParam);
|
|
|
- BizUser bizUser = BeanUtil.toBean(bizUserAddParam, BizUser.class);
|
|
|
- if(ObjectUtil.isEmpty(bizUser.getAvatar())) {
|
|
|
- // 设置默认头像
|
|
|
- bizUser.setAvatar(CommonAvatarUtil.generateImg(bizUser.getName()));
|
|
|
- }
|
|
|
+ public void add(String empNo, String account, String name, String orgId, String departmentId, String workLocationId, String nickname, String gender, String homeAddress, String detailAddress, String idCardNumber, String phone, String emergencyPhone, String entryDate, MultipartFile avatar) throws IOException {
|
|
|
+ checkParam(empNo,account,phone,orgId);
|
|
|
+ BizUser bizUser = new BizUser();
|
|
|
+ bizUser.setEmpNo(empNo);
|
|
|
+ bizUser.setAccount(account);
|
|
|
+ bizUser.setName(name);
|
|
|
+ bizUser.setOrgId(orgId);
|
|
|
+ bizUser.setDepartmentId(departmentId);
|
|
|
+ bizUser.setWorkLocationId(workLocationId);
|
|
|
+ bizUser.setNickname(nickname);
|
|
|
+ bizUser.setGender(gender);
|
|
|
+ bizUser.setHomeAddress(homeAddress);
|
|
|
+ bizUser.setDetailAddress(detailAddress);
|
|
|
+ bizUser.setIdCardNumber(idCardNumber);
|
|
|
+ bizUser.setPhone(phone);
|
|
|
+ bizUser.setEmergencyPhone(emergencyPhone);
|
|
|
+ bizUser.setEntryDate(entryDate);
|
|
|
+// String avatarUrl = uploadImage.getImageCom(avatar);
|
|
|
+// if (avatarUrl.equals("上传失败")){
|
|
|
+// throw new CommonException("图片上传失败!");
|
|
|
+// }
|
|
|
+// bizUser.setAvatar(avatarUrl);
|
|
|
// 设置密码
|
|
|
bizUser.setPassword(CommonCryptogramUtil.doHashValue(devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_PASSWORD_KEY)));
|
|
|
// 设置状态
|
|
@@ -168,92 +181,102 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
CommonDataChangeEventCenter.doAddWithData(BizDataTypeEnum.USER.getValue(), JSONUtil.createArray().put(bizUser));
|
|
|
}
|
|
|
|
|
|
- private void checkParam(BizUserAddParam bizUserAddParam) {
|
|
|
+ private void checkParam(String empNo, String account, String phone, String orgId) {
|
|
|
// 校验数据范围
|
|
|
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
|
|
if(ObjectUtil.isNotEmpty(loginUserDataScope)) {
|
|
|
- if(!loginUserDataScope.contains(bizUserAddParam.getOrgId())) {
|
|
|
- throw new CommonException("您没有权限在该机构下增加人员,机构id:{}", bizUserAddParam.getOrgId());
|
|
|
+ if(!loginUserDataScope.contains(orgId)) {
|
|
|
+ throw new CommonException("您没有权限在该机构下增加人员,机构id:{}", orgId);
|
|
|
}
|
|
|
} else {
|
|
|
- throw new CommonException("您没有权限在该机构下增加人员,机构id:{}", bizUserAddParam.getOrgId());
|
|
|
+ throw new CommonException("您没有权限在该机构下增加人员,机构id:{}", orgId);
|
|
|
}
|
|
|
if (this.count(new LambdaQueryWrapper<BizUser>()
|
|
|
- .eq(BizUser::getAccount, bizUserAddParam.getAccount())) > 0) {
|
|
|
- throw new CommonException("存在重复的账号,账号为:{}", bizUserAddParam.getAccount());
|
|
|
+ .eq(BizUser::getEmpNo, empNo)) > 0) {
|
|
|
+ throw new CommonException("存在重复的工号,工号为:{}", empNo);
|
|
|
}
|
|
|
- if(ObjectUtil.isNotEmpty(bizUserAddParam.getPhone())) {
|
|
|
- if(!PhoneUtil.isMobile(bizUserAddParam.getPhone())) {
|
|
|
- throw new CommonException("手机号码:{}格式错误", bizUserAddParam.getPhone());
|
|
|
- }
|
|
|
- if (this.count(new LambdaQueryWrapper<BizUser>()
|
|
|
- .eq(BizUser::getPhone, CommonCryptogramUtil.doSm4CbcEncrypt(bizUserAddParam.getPhone()))) > 0) {
|
|
|
- throw new CommonException("存在重复的手机号,手机号为:{}", bizUserAddParam.getPhone());
|
|
|
- }
|
|
|
+ if (this.count(new LambdaQueryWrapper<BizUser>()
|
|
|
+ .eq(BizUser::getAccount, account)) > 0) {
|
|
|
+ throw new CommonException("存在重复的账号,账号为:{}", account);
|
|
|
}
|
|
|
- if(ObjectUtil.isNotEmpty(bizUserAddParam.getEmail())) {
|
|
|
- if(!CommonEmailUtil.isEmail(bizUserAddParam.getEmail())) {
|
|
|
- throw new CommonException("邮箱:{}格式错误", bizUserAddParam.getEmail());
|
|
|
+ if(ObjectUtil.isNotEmpty(phone)) {
|
|
|
+ if(!PhoneUtil.isMobile(phone)) {
|
|
|
+ throw new CommonException("手机号码:{}格式错误", phone);
|
|
|
}
|
|
|
if (this.count(new LambdaQueryWrapper<BizUser>()
|
|
|
- .eq(BizUser::getEmail, bizUserAddParam.getEmail())) > 0) {
|
|
|
- throw new CommonException("存在重复的邮箱,邮箱为:{}", bizUserAddParam.getEmail());
|
|
|
+ .eq(BizUser::getPhone, CommonCryptogramUtil.doSm4CbcEncrypt(phone))) > 0) {
|
|
|
+ throw new CommonException("存在重复的手机号,手机号为:{}",phone);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public void edit(BizUserEditParam bizUserEditParam) {
|
|
|
- BizUser bizUser = this.queryEntity(bizUserEditParam.getId());
|
|
|
- checkParam(bizUserEditParam);
|
|
|
- boolean updateSuperAdminAccount = bizUser.getAccount().equals(BizBuildInEnum.BUILD_IN_USER_ACCOUNT.getValue()) &&
|
|
|
- !bizUserEditParam.getAccount().equals(BizBuildInEnum.BUILD_IN_USER_ACCOUNT.getValue());
|
|
|
+ public void edit(String id, String empNo, String account, String name, String orgId, String departmentId, String workLocationId, String nickname, String gender, String homeAddress, String detailAddress, String idCardNumber, String phone, String emergencyPhone, String entryDate, MultipartFile avatar) throws IOException {
|
|
|
+ BizUser bizUser = this.queryEntity(id);
|
|
|
+ checkParam(id,empNo,account,phone,orgId);
|
|
|
+ boolean updateSuperAdminAccount = account.equals(BizBuildInEnum.BUILD_IN_USER_ACCOUNT.getValue()) &&
|
|
|
+ !account.equals(BizBuildInEnum.BUILD_IN_USER_ACCOUNT.getValue());
|
|
|
if(updateSuperAdminAccount) {
|
|
|
throw new CommonException("不可修改系统内置超管人员账号");
|
|
|
}
|
|
|
- BeanUtil.copyProperties(bizUserEditParam, bizUser);
|
|
|
+ bizUser.setEmpNo(empNo);
|
|
|
+ bizUser.setAccount(account);
|
|
|
+ bizUser.setName(name);
|
|
|
+ bizUser.setOrgId(orgId);
|
|
|
+ bizUser.setDepartmentId(departmentId);
|
|
|
+ bizUser.setWorkLocationId(workLocationId);
|
|
|
+ bizUser.setNickname(nickname);
|
|
|
+ bizUser.setGender(gender);
|
|
|
+ bizUser.setHomeAddress(homeAddress);
|
|
|
+ bizUser.setDetailAddress(detailAddress);
|
|
|
+ bizUser.setIdCardNumber(idCardNumber);
|
|
|
+ bizUser.setPhone(phone);
|
|
|
+ bizUser.setEmergencyPhone(emergencyPhone);
|
|
|
+ bizUser.setEntryDate(entryDate);
|
|
|
+// if (ObjectUtil.isNotEmpty(avatar)){
|
|
|
+// String avatarUrl = uploadImage.getImageCom(avatar);
|
|
|
+// if (avatarUrl.equals("上传失败")){
|
|
|
+// throw new CommonException("图片上传失败!");
|
|
|
+// }
|
|
|
+// bizUser.setAvatar(avatarUrl);
|
|
|
+// }
|
|
|
+
|
|
|
this.updateById(bizUser);
|
|
|
|
|
|
// 发布更新事件
|
|
|
CommonDataChangeEventCenter.doUpdateWithData(BizDataTypeEnum.USER.getValue(), JSONUtil.createArray().put(bizUser));
|
|
|
}
|
|
|
|
|
|
- private void checkParam(BizUserEditParam bizUserEditParam) {
|
|
|
+ private void checkParam(String id, String empNo, String account, String phone, String orgId) {
|
|
|
// 校验数据范围
|
|
|
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
|
|
if(ObjectUtil.isNotEmpty(loginUserDataScope)) {
|
|
|
- if(!loginUserDataScope.contains(bizUserEditParam.getOrgId())) {
|
|
|
- throw new CommonException("您没有权限编辑该机构下的人员,机构id:{}", bizUserEditParam.getOrgId());
|
|
|
+ if(!loginUserDataScope.contains(orgId)) {
|
|
|
+ throw new CommonException("您没有权限编辑该机构下的人员,机构id:{}", orgId);
|
|
|
}
|
|
|
} else {
|
|
|
- if(!bizUserEditParam.getId().equals(StpUtil.getLoginIdAsString())) {
|
|
|
- throw new CommonException("您没有权限编辑该机构下的人员,机构id:{}", bizUserEditParam.getOrgId());
|
|
|
+ if(!id.equals(StpUtil.getLoginIdAsString())) {
|
|
|
+ throw new CommonException("您没有权限编辑该机构下的人员,机构id:{}", orgId);
|
|
|
}
|
|
|
}
|
|
|
if (this.count(new LambdaQueryWrapper<BizUser>()
|
|
|
- .eq(BizUser::getAccount, bizUserEditParam.getAccount())
|
|
|
- .ne(BizUser::getId, bizUserEditParam.getId())) > 0) {
|
|
|
- throw new CommonException("存在重复的账号,账号为:{}", bizUserEditParam.getAccount());
|
|
|
+ .eq(BizUser::getEmpNo, empNo).eq(BizUser::getOrgId,orgId).ne(BizUser::getId,id)) > 0) {
|
|
|
+ throw new CommonException("存在重复的工号,工号为:{}", empNo);
|
|
|
}
|
|
|
- if(ObjectUtil.isNotEmpty(bizUserEditParam.getPhone())) {
|
|
|
- if(!PhoneUtil.isMobile(bizUserEditParam.getPhone())) {
|
|
|
- throw new CommonException("手机号码:{}格式错误", bizUserEditParam.getPhone());
|
|
|
- }
|
|
|
- if (this.count(new LambdaQueryWrapper<BizUser>()
|
|
|
- .eq(BizUser::getPhone, CommonCryptogramUtil.doSm4CbcEncrypt(bizUserEditParam.getPhone()))
|
|
|
- .ne(BizUser::getId, bizUserEditParam.getId())) > 0) {
|
|
|
- throw new CommonException("存在重复的手机号,手机号为:{}", bizUserEditParam.getPhone());
|
|
|
- }
|
|
|
+ if (this.count(new LambdaQueryWrapper<BizUser>()
|
|
|
+ .eq(BizUser::getAccount, account)
|
|
|
+ .ne(BizUser::getId, id)) > 0) {
|
|
|
+ throw new CommonException("存在重复的账号,账号为:{}", account);
|
|
|
}
|
|
|
- if(ObjectUtil.isNotEmpty(bizUserEditParam.getEmail())) {
|
|
|
- if(!CommonEmailUtil.isEmail(bizUserEditParam.getEmail())) {
|
|
|
- throw new CommonException("邮箱:{}格式错误", bizUserEditParam.getEmail());
|
|
|
+ if(ObjectUtil.isNotEmpty(phone)) {
|
|
|
+ if(!PhoneUtil.isMobile(phone)) {
|
|
|
+ throw new CommonException("手机号码:{}格式错误", phone);
|
|
|
}
|
|
|
if (this.count(new LambdaQueryWrapper<BizUser>()
|
|
|
- .eq(BizUser::getEmail, bizUserEditParam.getEmail())
|
|
|
- .ne(BizUser::getId, bizUserEditParam.getId())) > 0) {
|
|
|
- throw new CommonException("存在重复的邮箱,邮箱为:{}", bizUserEditParam.getEmail());
|
|
|
+ .eq(BizUser::getPhone, CommonCryptogramUtil.doSm4CbcEncrypt(phone))
|
|
|
+ .ne(BizUser::getId, id)) > 0) {
|
|
|
+ throw new CommonException("存在重复的手机号,手机号为:{}", phone);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -282,24 +305,6 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
throw new CommonException("您没有权限删除这些机构下的人员,机构id:{}", userOrgIdList);
|
|
|
}
|
|
|
}
|
|
|
- // 清除【将这些人员作为主管】的信息
|
|
|
- this.update(new LambdaUpdateWrapper<BizUser>().in(BizUser::getDirectorId, bizUserIdList).set(BizUser::getDirectorId, null));
|
|
|
-
|
|
|
- // 清除【将这些人员作为兼任岗位的主管】的信息
|
|
|
- this.list(new LambdaQueryWrapper<BizUser>() .isNotNull(BizUser::getPositionJson)).forEach(bizUser -> {
|
|
|
- List<JSONObject> handledJsonObjectList = JSONUtil.toList(JSONUtil.parseArray(bizUser.getPositionJson()),
|
|
|
- JSONObject.class).stream().peek(jsonObject -> {
|
|
|
- String directorId = jsonObject.getStr("directorId");
|
|
|
- if (ObjectUtil.isNotEmpty(directorId) && bizUserIdList.contains(directorId)) {
|
|
|
- jsonObject.remove("directorId");
|
|
|
- }
|
|
|
- }).collect(Collectors.toList());
|
|
|
- this.update(new LambdaUpdateWrapper<BizUser>().eq(BizUser::getId, bizUser.getId())
|
|
|
- .set(BizUser::getPositionJson, JSONUtil.toJsonStr(handledJsonObjectList)));
|
|
|
- });
|
|
|
-
|
|
|
- // 清除【将这些人员作为主管】的机构的主管信息
|
|
|
- bizOrgService.update(new LambdaUpdateWrapper<BizOrg>().in(BizOrg::getDirectorId, bizUserIdList).set(BizOrg::getDirectorId, null));
|
|
|
|
|
|
// 执行删除
|
|
|
this.removeByIds(bizUserIdList);
|
|
@@ -560,16 +565,6 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
ImageEntity imageEntity = new ImageEntity(ImgUtil.toBytes(ImgUtil.toImage(StrUtil
|
|
|
.split(avatarBase64, StrUtil.COMMA).get(1)), ImgUtil.IMAGE_TYPE_PNG), 120, 160);
|
|
|
map.put("avatar", imageEntity);
|
|
|
- if(ObjectUtil.isNotEmpty(bizUser.getBirthday())) {
|
|
|
- try {
|
|
|
- // 年龄
|
|
|
- long age = cn.hutool.core.date.DateUtil.betweenYear(cn.hutool.core.date.DateUtil.parseDate(bizUser.getBirthday()), DateTime.now(), true);
|
|
|
- if(age != 0) {
|
|
|
- map.put("age", age + "岁");
|
|
|
- }
|
|
|
- } catch (Exception ignored) {
|
|
|
- }
|
|
|
- }
|
|
|
// 导出时间
|
|
|
map.put("exportDateTime", DateUtil.format(DateTime.now(), DatePattern.CHINESE_DATE_PATTERN));
|
|
|
// 生成doc
|
|
@@ -654,29 +649,6 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
return bizOrgService.page(CommonPageRequest.defaultPage(), lambdaQueryWrapper);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Page<BizPosition> positionSelector(BizUserSelectorPositionParam bizUserSelectorPositionParam) {
|
|
|
- LambdaQueryWrapper<BizPosition> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- // 校验数据范围
|
|
|
- List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
|
|
- if(ObjectUtil.isNotEmpty(loginUserDataScope)) {
|
|
|
- lambdaQueryWrapper.in(BizPosition::getOrgId, loginUserDataScope);
|
|
|
- } else {
|
|
|
- return new Page<>();
|
|
|
- }
|
|
|
- // 查询部分字段
|
|
|
- lambdaQueryWrapper.select(BizPosition::getId, BizPosition::getOrgId, BizPosition::getName,
|
|
|
- BizPosition::getCategory, BizPosition::getSortCode);
|
|
|
- if(ObjectUtil.isNotEmpty(bizUserSelectorPositionParam.getOrgId())) {
|
|
|
- lambdaQueryWrapper.eq(BizPosition::getOrgId, bizUserSelectorPositionParam.getOrgId());
|
|
|
- }
|
|
|
- if(ObjectUtil.isNotEmpty(bizUserSelectorPositionParam.getSearchKey())) {
|
|
|
- lambdaQueryWrapper.like(BizPosition::getName, bizUserSelectorPositionParam.getSearchKey());
|
|
|
- }
|
|
|
- lambdaQueryWrapper.orderByAsc(BizPosition::getSortCode);
|
|
|
- return bizPositionService.page(CommonPageRequest.defaultPage(), lambdaQueryWrapper);
|
|
|
- }
|
|
|
-
|
|
|
@SuppressWarnings("ALL")
|
|
|
@Override
|
|
|
public Page<BizUserRoleResult> roleSelector(BizUserSelectorRoleParam bizUserSelectorRoleParam) {
|
|
@@ -716,7 +688,7 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
return new Page<>();
|
|
|
}
|
|
|
// 只查询部分字段
|
|
|
- lambdaQueryWrapper.select(BizUser::getId, BizUser::getAvatar, BizUser::getOrgId, BizUser::getPositionId, BizUser::getAccount,
|
|
|
+ lambdaQueryWrapper.select(BizUser::getId, BizUser::getAvatar, BizUser::getOrgId, BizUser::getAccount,
|
|
|
BizUser::getName, BizUser::getSortCode, BizUser::getGender, BizUser::getEntryDate);
|
|
|
if (ObjectUtil.isNotEmpty(bizUserSelectorUserParam.getOrgId())) {
|
|
|
// 如果机构id不为空,则查询该机构及其子机构下的所有人
|