宏源权限
This commit is contained in:
parent
0ae56376ec
commit
eb5850e99f
|
|
@ -56,6 +56,7 @@ public class SysDictData extends BaseEntity
|
|||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
|
||||
public Long getDictCode()
|
||||
{
|
||||
return dictCode;
|
||||
|
|
|
|||
|
|
@ -61,6 +61,9 @@ public class BaseEntity implements Serializable
|
|||
private String missionSource;//权限字符
|
||||
|
||||
|
||||
private Long companyId;//公司id `
|
||||
|
||||
|
||||
|
||||
public String getMissionSource(String missionSource) {
|
||||
return missionSource;
|
||||
|
|
@ -164,4 +167,12 @@ public class BaseEntity implements Serializable
|
|||
{
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public Long getCompanyId() {
|
||||
return companyId;
|
||||
}
|
||||
|
||||
public void setCompanyId(Long companyId) {
|
||||
this.companyId = companyId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.bonus.common.log.annotation.SysLog;
|
|||
import com.bonus.common.log.enums.OperaType;
|
||||
import com.bonus.common.security.annotation.InnerAuth;
|
||||
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
|
@ -51,6 +52,8 @@ public class SysDictDataController extends BaseController
|
|||
@SysLog(title = "字典管理", businessType = OperaType.QUERY,logType = 0,module = "系统管理->字典管理")
|
||||
public TableDataInfo list(SysDictData dictData) {
|
||||
try{
|
||||
Long deptId = dictDataService.getUserDeptId();
|
||||
dictData.setCompanyId(deptId);
|
||||
startPage();
|
||||
List<SysDictData> list = dictDataService.selectDictDataList(dictData);
|
||||
return getDataTable(list);
|
||||
|
|
@ -114,6 +117,8 @@ public class SysDictDataController extends BaseController
|
|||
public AjaxResult add(@Validated @RequestBody SysDictData dict) {
|
||||
try{
|
||||
dict.setCreateBy(SecurityUtils.getUsername());
|
||||
Long deptId = dictDataService.getUserDeptId();
|
||||
dict.setCompanyId(deptId);
|
||||
return toAjax(dictDataService.insertDictData(dict));
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
|
|
@ -152,4 +157,17 @@ public class SysDictDataController extends BaseController
|
|||
}
|
||||
return error("系统错误");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户部门id
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取用户部门id")
|
||||
@GetMapping("/getUserDeptId")
|
||||
public AjaxResult getUserDeptId() {
|
||||
Long deptId = dictDataService.getUserDeptId();
|
||||
return AjaxResult.success(deptId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,9 @@ public class SysUserController extends BaseController {
|
|||
@Autowired
|
||||
private ISysLogService sysLogService;
|
||||
|
||||
@Autowired
|
||||
private ISysDictDataService dictDataService;
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*/
|
||||
|
|
@ -528,6 +531,8 @@ public class SysUserController extends BaseController {
|
|||
@PostMapping("/deptUserTree")
|
||||
public AjaxResult deptUserTree(@RequestBody SysUser sysUser) {
|
||||
try {
|
||||
Long deptId = dictDataService.getUserDeptId();
|
||||
sysUser.setCompanyId(deptId);
|
||||
return success(deptService.selectDeptUserTree(sysUser));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public interface SysDeptMapper
|
|||
* @param roleIds 角色列表
|
||||
* @return 部门树信息集合
|
||||
*/
|
||||
public List<SysDept> selectDeptUserList(@Param("roleIds") Long[] roleIds);
|
||||
public List<SysDept> selectDeptUserList(@Param("roleIds") Long[] roleIds,@Param("companyId") Long companyId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询部门树信息
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package com.bonus.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.bonus.system.api.domain.SysDept;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.bonus.system.api.domain.SysDictData;
|
||||
|
||||
|
|
@ -94,4 +97,8 @@ public interface SysDictDataMapper
|
|||
public int updateDictDataType(@Param("oldDictType") String oldDictType, @Param("newDictType") String newDictType);
|
||||
|
||||
int getdictDatasInfo(String dictType);
|
||||
|
||||
SysUser getUserDeptId(Long userId);
|
||||
|
||||
SysDept getDeptIdByUserId(Long deptId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,4 +57,6 @@ public interface ISysDictDataService
|
|||
* @return 结果
|
||||
*/
|
||||
public int updateDictData(SysDictData dictData);
|
||||
|
||||
Long getUserDeptId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
@DataScope(deptAlias = "d")
|
||||
public List<TreeSelect> selectDeptUserTree(SysUser sysUser)
|
||||
{
|
||||
List<SysDept> depts = deptMapper.selectDeptUserList(sysUser.getRoleIds());
|
||||
List<SysDept> depts = deptMapper.selectDeptUserList(sysUser.getRoleIds(),sysUser.getCompanyId());
|
||||
for (int i = 0; i < 5; i++) {
|
||||
depts = getFilterDepts(depts);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import java.util.Objects;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.system.api.domain.SysDept;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bonus.common.security.utils.DictUtils;
|
||||
|
|
@ -142,4 +145,33 @@ public class SysDictDataServiceImpl implements ISysDictDataService
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户部门id
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Long getUserDeptId() {
|
||||
Long userId = SecurityUtils.getLoginUser().getUserid();
|
||||
SysUser sysUser = dictDataMapper.getUserDeptId(userId);
|
||||
if (sysUser != null) {
|
||||
//获取祖籍部门id
|
||||
SysDept sysDept = dictDataMapper.getDeptIdByUserId(sysUser.getDeptId());
|
||||
if (sysDept != null && sysDept.getAncestors() != null) {
|
||||
String ancestors = sysDept.getAncestors();
|
||||
String[] ancestorArray = ancestors.split(",");
|
||||
|
||||
// 计算逗号数量(数组长度-1)
|
||||
int commaCount = ancestorArray.length - 1;
|
||||
|
||||
// 根据逗号数量决定取哪个值
|
||||
if (commaCount == 2) { // 两个逗号,如 "0,100,101"
|
||||
// 取最后一个数据
|
||||
sysUser.setDeptId(Long.valueOf(ancestorArray[ancestorArray.length - 1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sysUser.getDeptId();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
WHERE
|
||||
d.del_flag = '0'
|
||||
AND d.STATUS = '0'
|
||||
|
||||
<if test="companyId != null and companyId != 0">
|
||||
AND (find_in_set(#{companyId}, ancestors) or dept_id = #{companyId} or dept_id = 100)
|
||||
</if>
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
|
|
@ -142,6 +144,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="companyId != null and companyId != 0">
|
||||
AND (find_in_set(#{companyId}, ancestors) or sd.dept_id = #{companyId} or sd.dept_id = 100)
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectDeptListByRoleId" resultType="Long">
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null and status != ''">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
<if test="companyId != null ">
|
||||
AND company_id = #{companyId}
|
||||
</if>
|
||||
</where>
|
||||
order by dict_sort asc
|
||||
</select>
|
||||
|
|
@ -63,6 +66,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
select count(1) from sys_dict_type where dict_type=#{dictType} and status = '0'
|
||||
</select>
|
||||
|
||||
<select id="getUserDeptId" resultType="com.bonus.system.api.domain.SysUser">
|
||||
SELECT
|
||||
su.dept_id AS deptId
|
||||
FROM
|
||||
sys_user su
|
||||
WHERE
|
||||
su.user_id = #{userId}
|
||||
</select>
|
||||
<select id="getDeptIdByUserId" resultType="com.bonus.system.api.domain.SysDept">
|
||||
SELECT
|
||||
sd.dept_id AS deptId,
|
||||
sd.parent_id AS parentId,
|
||||
sd.ancestors AS ancestors
|
||||
FROM
|
||||
sys_dept sd
|
||||
WHERE
|
||||
sd.dept_id = #{deptId}
|
||||
</select>
|
||||
|
||||
<delete id="deleteDictDataById" parameterType="Long">
|
||||
delete from sys_dict_data where dict_code = #{dictCode}
|
||||
</delete>
|
||||
|
|
@ -108,7 +130,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null">status,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
create_time
|
||||
create_time,
|
||||
<if test="companyId != null ">company_id</if>
|
||||
)values(
|
||||
<if test="dictSort != null">#{dictSort},</if>
|
||||
<if test="dictLabel != null and dictLabel != ''">#{dictLabel},</if>
|
||||
|
|
@ -120,7 +143,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null">#{status},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate()
|
||||
sysdate(),
|
||||
<if test="companyId != null ">#{companyId}</if>
|
||||
)
|
||||
</insert>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue