Jelajahi Sumber

feat: 组织机构导入增加编码校验;

hanchaolong 21 jam lalu
induk
melakukan
e61b3bbef8

+ 8 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java

@@ -77,6 +77,14 @@ public interface SysDeptMapper
      */
     public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId);
 
+    /**
+     * 校验部门编码是否唯一
+     *
+     * @param deptCode 部门编码
+     * @return 结果
+     */
+    public SysDept checkDeptCodeUnique(@Param("deptCode") String deptCode);
+
     /**
      * 新增部门信息
      * 

+ 8 - 3
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@@ -362,13 +362,18 @@ public class SysDeptServiceImpl implements ISysDeptService
                 SysDept dept = convertToSysDept(importDTO);
 
                 // 根据父组织编码和名称查询父部门 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)
                 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++;
                     failureMsg.append(String.format("%1$s、部门已存在;", dept.getDeptName()));
                 } else {

+ 5 - 0
jd-logistics-modules/jd-logistics-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -95,6 +95,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	    <include refid="selectDeptVo"/>
 		where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
 	</select>
+
+	<select id="checkDeptCodeUnique" resultMap="SysDeptResult">
+	    <include refid="selectDeptVo"/>
+		where dept_code=#{deptCode} and del_flag = '0' limit 1
+	</select>
     
     <insert id="insertDept" parameterType="SysDept">
  		insert into sys_dept(