liu
3 天以前 9aa810eae18397cc5e452feedbe453800d9aaa5c
yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/employee/HrmEmployeeServiceImpl.java
@@ -104,9 +104,15 @@
        deptApi.validateDeptList(Collections.singleton(createReqVO.getDeptId()));
        // 2. 校验岗位
        postApi.validPostList(createReqVO.getPostIds());
        // 3. 校验手机号是否已存在
        if (employeeMapper.selectByPhone(createReqVO.getPhone()) != null) {
            throw exception(EMPLOYEE_PHONE_EXISTS);
        // 3. 校验手机号是否已存在(**包含已删除档案**:uk_phone 唯一索引不区分 deleted,
        //    只查未删除记录会漏判,导致写库时抛唯一约束异常,前端显示“系统异常”)
        if (createReqVO.getPhone() != null) {
            HrmEmployeeDO existPhone = employeeMapper.selectByPhoneIgnoreDeleted(createReqVO.getPhone());
            if (existPhone != null) {
                throw existPhone.getDeleted() != null && existPhone.getDeleted()
                        ? exception(EMPLOYEE_PHONE_OCCUPIED_BY_DELETED, createReqVO.getPhone())
                        : exception(EMPLOYEE_PHONE_EXISTS);
            }
        }
        // 4. 同步创建系统用户
        AdminUserCreateReqDTO userCreateReqDTO = new AdminUserCreateReqDTO();
@@ -186,10 +192,14 @@
        deptApi.validateDeptList(Collections.singleton(updateReqVO.getDeptId()));
        // 校验岗位
        postApi.validPostList(updateReqVO.getPostIds());
        // 校验手机号是否已存在(如果手机号有变更)
        if (!Objects.equals(employee.getPhone(), updateReqVO.getPhone())
                && employeeMapper.selectByPhone(updateReqVO.getPhone()) != null) {
            throw exception(EMPLOYEE_PHONE_EXISTS);
        // 校验手机号是否已存在(如果手机号有变更;**包含已删除档案**,原因见 createEmployee)
        if (!Objects.equals(employee.getPhone(), updateReqVO.getPhone()) && updateReqVO.getPhone() != null) {
            HrmEmployeeDO existPhone = employeeMapper.selectByPhoneIgnoreDeleted(updateReqVO.getPhone());
            if (existPhone != null && !Objects.equals(existPhone.getId(), updateReqVO.getId())) {
                throw existPhone.getDeleted() != null && existPhone.getDeleted()
                        ? exception(EMPLOYEE_PHONE_OCCUPIED_BY_DELETED, updateReqVO.getPhone())
                        : exception(EMPLOYEE_PHONE_EXISTS);
            }
        }
        // 更新员工主表
        HrmEmployeeDO updateObj = BeanUtils.toBean(updateReqVO, HrmEmployeeDO.class);