|
@@ -6,6 +6,7 @@ import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.utils.DateUtils;
|
|
import com.ruoyi.common.core.utils.DateUtils;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.common.core.constant.UserConstants;
|
|
import com.ruoyi.common.core.constant.UserConstants;
|
|
@@ -29,6 +30,7 @@ import com.ruoyi.system.service.ISysDeptService;
|
|
|
*
|
|
*
|
|
|
* @author lydgt
|
|
* @author lydgt
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class SysDeptServiceImpl implements ISysDeptService
|
|
public class SysDeptServiceImpl implements ISysDeptService
|
|
|
{
|
|
{
|
|
@@ -362,13 +364,18 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
|
SysDept dept = convertToSysDept(importDTO);
|
|
SysDept dept = convertToSysDept(importDTO);
|
|
|
|
|
|
|
|
// 根据父组织编码和名称查询父部门 ID
|
|
// 根据父组织编码和名称查询父部门 ID
|
|
|
- SysDept parentId = deptMapper.selectDeptByInfo(importDTO.getParentDeptCode(), importDTO.getParentDeptName());
|
|
|
|
|
|
|
+ SysDept parentId = null;
|
|
|
|
|
+ if (StringUtils.isNotBlank(importDTO.getParentDeptCode()) && StringUtils.isNotBlank(importDTO.getParentDeptName())) {
|
|
|
|
|
+ parentId = deptMapper.selectDeptByInfo(importDTO.getParentDeptCode(), importDTO.getParentDeptName());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 设置父部门 ID,如果为 null 则默认为顶级部门(0)
|
|
// 设置父部门 ID,如果为 null 则默认为顶级部门(0)
|
|
|
dept.setParentId(parentId == null ? 0L : parentId.getDeptId());
|
|
dept.setParentId(parentId == null ? 0L : parentId.getDeptId());
|
|
|
|
|
|
|
|
- // 检查部门名称是否唯一
|
|
|
|
|
- if (null != deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId())) {
|
|
|
|
|
|
|
+ if (null != deptMapper.checkDeptCodeUnique(dept.getDeptCode())) {
|
|
|
|
|
+ failureNum++;
|
|
|
|
|
+ failureMsg.append(String.format("%1$s、部门已存在;", dept.getDeptCode()));
|
|
|
|
|
+ } else if (null != deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId())) {
|
|
|
failureNum++;
|
|
failureNum++;
|
|
|
failureMsg.append(String.format("%1$s、部门已存在;", dept.getDeptName()));
|
|
failureMsg.append(String.format("%1$s、部门已存在;", dept.getDeptName()));
|
|
|
} else {
|
|
} else {
|
|
@@ -378,6 +385,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|
|
successMsg.append(String.format("%1$s、导入成功;", dept.getDeptName()));
|
|
successMsg.append(String.format("%1$s、导入成功;", dept.getDeptName()));
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
|
|
+ log.info("导入部门数据异常", e);
|
|
|
failureNum++;
|
|
failureNum++;
|
|
|
String msg = String.format("%1$s、导入失败:%2$s", importDTO.getDeptName(), e.getMessage());
|
|
String msg = String.format("%1$s、导入失败:%2$s", importDTO.getDeptName(), e.getMessage());
|
|
|
failureMsg.append(msg);
|
|
failureMsg.append(msg);
|