zhanghl
2025-04-22 d2d8db6a6f66f3b646e395a7a2a4822ce68d5b47
角色-部门表增加 部门组织编码
已修改6个文件
69 ■■■■ 文件已修改
aps-common/aps-common-datascope/src/main/java/com/aps/common/datascope/aspect/DataScopeAspect.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-system/src/main/java/com/aps/system/domain/SysRoleDept.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-system/src/main/java/com/aps/system/mapper/SysDeptMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-system/src/main/java/com/aps/system/service/impl/SysRoleServiceImpl.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-system/src/main/resources/mapper/system/SysDeptMapper.xml 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-common/aps-common-datascope/src/main/java/com/aps/common/datascope/aspect/DataScopeAspect.java
@@ -118,7 +118,7 @@
                break;
            }
            else if (DATA_SCOPE_CUSTOM.equals(dataScope))
            {
            {   /*自定义数据权限*/
                if (scopeCustomIds.size() > 1)
                {
                    // 多个自定数据权限使用in查询,避免多次拼接。
@@ -130,15 +130,15 @@
                }
            }
            else if (DATA_SCOPE_DEPT.equals(dataScope))
            {
            {    /*本部门数据权限*/
                sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
            }
            else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
            {
            {    /*本部门以及以下数据权限*/
                sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", deptAlias, user.getDeptId(), user.getDeptId()));
            }
            else if (DATA_SCOPE_SELF.equals(dataScope))
            {
            {   /*仅本人数据权限*/
                if (StringUtils.isNotBlank(userAlias))
                {
                    sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
aps-modules/aps-system/src/main/java/com/aps/system/domain/SysRoleDept.java
@@ -16,6 +16,10 @@
    /** 部门ID */
    private Long deptId;
    /**部门组织编码*/
    private String deptOrgCode;
    public Long getRoleId()
    {
        return roleId;
@@ -36,11 +40,20 @@
        this.deptId = deptId;
    }
    public String getDeptOrgCode() {
        return deptOrgCode;
    }
    public void setDeptOrgCode(String deptOrgCode) {
        this.deptOrgCode = deptOrgCode;
    }
    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("roleId", getRoleId())
            .append("deptId", getDeptId())
                .append("deptOrgCode", getDeptOrgCode())
            .toString();
    }
}
aps-modules/aps-system/src/main/java/com/aps/system/mapper/SysDeptMapper.java
@@ -115,4 +115,6 @@
     * @return 结果
     */
    public int deleteDeptById(Long deptId);
    List<SysDept>  selectDeptListByIdList(List<Long> deptIdList);
}
aps-modules/aps-system/src/main/java/com/aps/system/service/impl/SysRoleServiceImpl.java
@@ -1,10 +1,9 @@
package com.aps.system.service.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import com.aps.system.api.domain.SysDept;
import com.aps.system.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -19,10 +18,6 @@
import com.aps.system.domain.SysRoleDept;
import com.aps.system.domain.SysRoleMenu;
import com.aps.system.domain.SysUserRole;
import com.aps.system.mapper.SysRoleDeptMapper;
import com.aps.system.mapper.SysRoleMapper;
import com.aps.system.mapper.SysRoleMenuMapper;
import com.aps.system.mapper.SysUserRoleMapper;
import com.aps.system.service.ISysRoleService;
/**
@@ -45,6 +40,8 @@
    @Autowired
    private SysRoleDeptMapper roleDeptMapper;
    @Autowired
    private SysDeptMapper deptMapper;
    /**
     * 根据条件分页查询角色数据
     * 
@@ -320,12 +317,21 @@
        int rows = 1;
        // 新增角色与部门(数据权限)管理
        List<SysRoleDept> list = new ArrayList<SysRoleDept>();
        for (Long deptId : role.getDeptIds())
        Long[] deptIds = role.getDeptIds();
        List<SysDept> sysDepts = deptMapper.selectDeptListByIdList(Arrays.asList(deptIds));
        for (Long deptId : deptIds)
        {
            SysRoleDept rd = new SysRoleDept();
            rd.setRoleId(role.getRoleId());
            rd.setDeptId(deptId);
            list.add(rd);
            Optional<SysDept> first = sysDepts.stream().filter(sysDept -> sysDept.getDeptId().equals(deptId)).findFirst();
            if(first.isPresent()){
                SysDept sysDept = first.get();
                SysRoleDept rd = new SysRoleDept();
                rd.setRoleId(role.getRoleId());
                rd.setDeptId(deptId);
                rd.setDeptOrgCode(sysDept.getOrgCode());
                list.add(rd);
            }
        }
        if (list.size() > 0)
        {
aps-modules/aps-system/src/main/resources/mapper/system/SysDeptMapper.xml
@@ -159,5 +159,13 @@
    <delete id="deleteDeptById" parameterType="Long">
        update sys_dept set del_flag = '2' where dept_id = #{deptId}
    </delete>
    <select id="selectDeptListByIdList" parameterType="Long" resultMap="SysDeptResult">
        <include refid="selectDeptVo"/>
        where d.del_flag = '0' and dept_id in
        <foreach collection="deptIdList" item="deptId" open="(" separator="," close=")">
            #{deptId}
        </foreach>
        order by d.parent_id, d.order_num
    </select>
</mapper> 
aps-modules/aps-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml
@@ -25,9 +25,9 @@
     </delete>
    
    <insert id="batchRoleDept">
        insert into sys_role_dept(role_id, dept_id) values
        insert into sys_role_dept(role_id, dept_id,dept_org_code) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.roleId},#{item.deptId})
            (#{item.roleId},#{item.deptId},#{item.deptOrgCode})
        </foreach>
    </insert>