|
@@ -3,9 +3,11 @@ package cn.iocoder.yudao.module.employee.service.info;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+import cn.iocoder.yudao.framework.security.core.LoginUser;
|
|
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
|
|
import cn.iocoder.yudao.module.employee.controller.admin.info.vo.EmployeeInfoHistorySaveReqVO;
|
|
@@ -19,6 +21,8 @@ import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
|
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
import cn.iocoder.yudao.module.system.service.dept.PostService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
@@ -31,7 +35,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
-import static cn.iocoder.yudao.module.employee.enums.ErrorCodeConstants.EMPLOYEE_INFO_NOT_EXISTS;
|
|
|
+import static cn.iocoder.yudao.module.employee.enums.ErrorCodeConstants.*;
|
|
|
+import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.POST_NOT_FOUND;
|
|
|
|
|
|
/**
|
|
|
* 员工信息 Service 实现类
|
|
@@ -42,6 +47,7 @@ import static cn.iocoder.yudao.module.employee.enums.ErrorCodeConstants.EMPLOYEE
|
|
|
@Validated
|
|
|
public class EmployeeInfoServiceImpl implements EmployeeInfoService {
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(EmployeeInfoServiceImpl.class);
|
|
|
@Resource
|
|
|
private EmployeeInfoMapper infoMapper;
|
|
|
@Resource
|
|
@@ -133,9 +139,32 @@ public class EmployeeInfoServiceImpl implements EmployeeInfoService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @TenantIgnore
|
|
|
public Long createInfo(EmployeeInfoSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
|
+ if(createReqVO.getPostId() != null) {
|
|
|
+ PostDO post = postService.getPost(createReqVO.getPostId());
|
|
|
+ if (post == null) {
|
|
|
+ throw exception(POST_NOT_FOUND);
|
|
|
+ }
|
|
|
+ createReqVO.setPosition(post.getName());
|
|
|
+ }
|
|
|
+ // 检查电话号码是否为空
|
|
|
+ if (createReqVO.getPhone() == null || createReqVO.getPhone().isEmpty()) {
|
|
|
+ throw exception(EMPLOYEE_INFO_PHONE_NOT_NULL);
|
|
|
+ }
|
|
|
+ // 手机号+租户判重
|
|
|
+ EmployeeInfoQueryReqVO reqVO = new EmployeeInfoQueryReqVO();
|
|
|
+ reqVO.setPhone(createReqVO.getPhone());
|
|
|
+ reqVO.setTenantId(createReqVO.getTenantId());
|
|
|
+ EmployeeInfoDO employeeInfoDO = this.getInfo(reqVO);
|
|
|
+ if (employeeInfoDO != null) {
|
|
|
+ throw exception(EMPLOYEE_INFO_PHONE_EXISTS);
|
|
|
+ }
|
|
|
+ // 获取用户信息和租户ID
|
|
|
+ LoginUser user = SecurityFrameworkUtils.getLoginUser();
|
|
|
+ Long tenantId = user != null && user.getTenantId() != null ? user.getTenantId() : 0L;
|
|
|
+ createReqVO.setTenantId(tenantId);
|
|
|
+ createReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
|
|
// 生成id
|
|
|
createReqVO.setInfoId(IdUtil.fastSimpleUUID());
|
|
|
EmployeeInfoDO info = BeanUtils.toBean(createReqVO, EmployeeInfoDO.class);
|
|
@@ -145,21 +174,55 @@ public class EmployeeInfoServiceImpl implements EmployeeInfoService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @TenantIgnore
|
|
|
- public void updateInfo(EmployeeInfoSaveReqVO updateReqVO) {
|
|
|
+ public Integer updateInfo(EmployeeInfoSaveReqVO updateReqVO) {
|
|
|
// 校验存在
|
|
|
validateInfoExists(updateReqVO.getId());
|
|
|
EmployeeInfoDO employeeInfoDO = this.getInfo(updateReqVO.getId());
|
|
|
if (employeeInfoDO == null) {
|
|
|
throw exception(EMPLOYEE_INFO_NOT_EXISTS);
|
|
|
}
|
|
|
+ // 获取用户信息和租户ID
|
|
|
+ LoginUser user = SecurityFrameworkUtils.getLoginUser();
|
|
|
+ Long tenantId = user != null && user.getTenantId() != null ? user.getTenantId() : 0L;
|
|
|
+
|
|
|
+ // 假设 employeeInfoDO 和 updateReqVO 已经被正确定义和初始化
|
|
|
+ String newPhone = updateReqVO.getPhone();
|
|
|
+ String currentPhone = employeeInfoDO.getPhone();
|
|
|
+
|
|
|
+ // 检查新电话号码是否为空
|
|
|
+ if (newPhone == null || newPhone.isEmpty()) {
|
|
|
+ throw exception(EMPLOYEE_INFO_PHONE_NOT_NULL);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果新电话号码不为空,且与当前电话号码不同,则进行判重检查
|
|
|
+ if (!newPhone.equals(currentPhone)) {
|
|
|
+ // 手机号+租户判重
|
|
|
+ EmployeeInfoQueryReqVO reqVO = new EmployeeInfoQueryReqVO();
|
|
|
+ reqVO.setPhone(newPhone);
|
|
|
+ reqVO.setTenantId(tenantId);
|
|
|
+ EmployeeInfoDO infoDO = this.getInfo(reqVO);
|
|
|
+ if (infoDO != null) {
|
|
|
+ // 如果找到了相同的电话号码和租户ID,则抛出异常
|
|
|
+ throw exception(EMPLOYEE_INFO_PHONE_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
EmployeeInfoHistorySaveReqVO historySaveReqVO = BeanUtils.toBean(employeeInfoDO, EmployeeInfoHistorySaveReqVO.class);
|
|
|
historySaveReqVO.setEmployeeId(employeeInfoDO.getId());
|
|
|
historySaveReqVO.setId(null);
|
|
|
employeeInfoHistoryService.createInfoHistory(historySaveReqVO);// 插入历史数据
|
|
|
// 更新
|
|
|
+ if(updateReqVO.getPostId() != null
|
|
|
+ && !updateReqVO.getPostId().equals(employeeInfoDO.getPostId())) {
|
|
|
+ PostDO post = postService.getPost(updateReqVO.getPostId());
|
|
|
+ if (post == null) {
|
|
|
+ throw exception(POST_NOT_FOUND);
|
|
|
+ }
|
|
|
+ employeeInfoDO.setPostId(updateReqVO.getPostId());
|
|
|
+ employeeInfoDO.setPosition(post.getName());
|
|
|
+ }
|
|
|
EmployeeInfoDO updateObj = BeanUtils.toBean(updateReqVO, EmployeeInfoDO.class);
|
|
|
- infoMapper.updateById(updateObj);
|
|
|
+ return infoMapper.updateById(updateObj);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -171,7 +234,6 @@ public class EmployeeInfoServiceImpl implements EmployeeInfoService {
|
|
|
infoMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
|
- @TenantIgnore
|
|
|
private void validateInfoExists(Long id) {
|
|
|
if (infoMapper.selectById(id) == null) {
|
|
|
throw exception(EMPLOYEE_INFO_NOT_EXISTS);
|
|
@@ -179,7 +241,6 @@ public class EmployeeInfoServiceImpl implements EmployeeInfoService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @TenantIgnore
|
|
|
public EmployeeInfoDO getInfo(Long id) {
|
|
|
validateInfoExists(id);
|
|
|
return infoMapper.selectById(id);
|
|
@@ -200,7 +261,6 @@ public class EmployeeInfoServiceImpl implements EmployeeInfoService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @TenantIgnore
|
|
|
public PageResult<EmployeeInfoDO> getInfoPage(EmployeeInfoPageReqVO pageReqVO) {
|
|
|
return infoMapper.selectPage(pageReqVO);
|
|
|
}
|