分组管理数据分离

This commit is contained in:
ll
2026-03-04 11:29:36 +08:00
parent 48d82ce7c0
commit 5abf1cbff4
4 changed files with 33 additions and 0 deletions

View File

@@ -69,6 +69,10 @@ public class BasSheepGroupController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody BasSheepGroup basSheepGroup)
{
// 👇 新增这两行赋值语句
basSheepGroup.setDeptId(getDeptId());
basSheepGroup.setUserId(getUserId());
return toAjax(basSheepGroupService.insertBasSheepGroup(basSheepGroup));
}

View File

@@ -42,4 +42,24 @@ public class BasSheepGroup extends TreeEntity
private Integer isLeaf;
// 新增数据隔离字段
/** 用户编号 */
private Long userId;
/** 部门编号 */
private Long deptId;
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getDeptId() {
return deptId;
}
public void setDeptId(Long deptId) {
this.deptId = deptId;
}
}

View File

@@ -1,5 +1,6 @@
package com.zhyc.module.base.service.impl;
import com.zhyc.common.annotation.DataScope;
import com.zhyc.common.exception.ServiceException;
import com.zhyc.common.utils.DateUtils;
import com.zhyc.module.base.domain.BasSheepGroup;
@@ -45,6 +46,7 @@ public class BasSheepGroupServiceImpl implements IBasSheepGroupService
// {
// return basSheepGroupMapper.selectBasSheepGroupList(basSheepGroup);
// }
@DataScope(deptAlias = "g", userAlias = "g")
@Override
public List<BasSheepGroup> selectBasSheepGroupList(BasSheepGroup basSheepGroup) {
List<BasSheepGroup> groups = basSheepGroupMapper.selectBasSheepGroupList(basSheepGroup);
@@ -122,6 +124,7 @@ public class BasSheepGroupServiceImpl implements IBasSheepGroupService
return basSheepGroupMapper.deleteBasSheepGroupByGroupId(groupId);
}
@DataScope(deptAlias = "g", userAlias = "g")
@Override
public List<BasSheepGroup> selectLeafNodes() {
List<BasSheepGroup> leafNodes = basSheepGroupMapper.selectLeafNodes();

View File

@@ -47,6 +47,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where>
<if test="groupName != null and groupName != ''"> and group_name like concat('%', #{groupName}, '%')</if>
<if test="status != null and status != ''"> and status = #{status}</if>
${params.dataScope}
</where>ORDER BY g.group_id <!-- 确保正确排序 -->
</select>
@@ -68,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE child.parent_id = g.group_id) > 0 THEN 0 ELSE 1 END) AS is_leaf
FROM bas_sheep_group g
WHERE g.status = '0'
${params.dataScope}
HAVING is_leaf = 1
</select>
@@ -87,6 +89,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="userId != null">user_id,</if>
<if test="deptId != null">dept_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="parentId != null">#{parentId},</if>
@@ -97,6 +101,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="userId != null">#{userId},</if>
<if test="deptId != null">#{deptId},</if>
</trim>
</insert>