Browse Source

数据权限功能提交

master
parent
commit
0854d8e7f7
  1. 20
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/dhc/DhcAreaController.java
  2. 26
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/DhcDataAuthController.java
  3. 26
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java
  4. 14
      ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelect.java
  5. 10
      ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/DhcArea.java
  6. 121
      ruoyi-plan/src/main/java/com/ruoyi/dhc/domain/DhcDataAuth.java
  7. 93
      ruoyi-plan/src/main/java/com/ruoyi/dhc/service/impl/DhcDataAuthServiceImpl.java
  8. 201
      ruoyi-system/src/main/java/com/ruoyi/dhc/domain/DhcDataAuth.java
  9. 77
      ruoyi-system/src/main/java/com/ruoyi/dhc/domain/DhcDataAuthDetail.java
  10. 30
      ruoyi-system/src/main/java/com/ruoyi/dhc/mapper/DhcDataAuthMapper.java
  11. 2
      ruoyi-system/src/main/java/com/ruoyi/dhc/service/IDhcDataAuthService.java
  12. 129
      ruoyi-system/src/main/java/com/ruoyi/dhc/service/impl/DhcDataAuthServiceImpl.java
  13. 64
      ruoyi-system/src/main/resources/mapper/system/DhcDataAuthMapper.xml
  14. 29
      sql/基础功能.sql

20
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dhc/DhcAreaController.java

@ -13,7 +13,10 @@ import org.springframework.security.access.prepost.PreAuthorize; @@ -13,7 +13,10 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 区域Controller
@ -130,4 +133,21 @@ public class DhcAreaController extends BaseController @@ -130,4 +133,21 @@ public class DhcAreaController extends BaseController
{
return success(dhcAreaService.selectAreaTreeList(area));
}
/**
* 查询区域信息
*/
@GetMapping("/queryAreaMaplist")
public List<Map<String, String>>queryAreaMaplist(DhcArea dhcArea)
{
List<DhcArea> list = dhcAreaService.selectDhcAreaList(dhcArea);
List<Map<String, String>> mapList = new ArrayList<>();
for (DhcArea model : list) {
Map<String, String> map = new HashMap<>();
map.put("value", model.getAreaCode());
map.put("label", model.getAreaName());
mapList.add(map);
}
return mapList;
}
}

26
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dhc/DhcDataAuthController.java → ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/DhcDataAuthController.java

@ -1,7 +1,13 @@ @@ -1,7 +1,13 @@
package com.ruoyi.web.controller.dhc;
package com.ruoyi.web.controller.system;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.dhc.domain.DhcDataAuth;
import com.ruoyi.dhc.service.IDhcDataAuthService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -16,8 +22,6 @@ import com.ruoyi.common.annotation.Log; @@ -16,8 +22,6 @@ import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dhc.domain.DhcDataAuth;
import com.ruoyi.dhc.service.IDhcDataAuthService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
@ -25,10 +29,10 @@ import com.ruoyi.common.core.page.TableDataInfo; @@ -25,10 +29,10 @@ import com.ruoyi.common.core.page.TableDataInfo;
* 数据权限Controller
*
* @author ruoyi
* @date 2024-07-30
* @date 2024-08-01
*/
@RestController
@RequestMapping("/dhc/auth")
@RequestMapping("/dhc/authData")
public class DhcDataAuthController extends BaseController
{
@Autowired
@ -37,7 +41,7 @@ public class DhcDataAuthController extends BaseController @@ -37,7 +41,7 @@ public class DhcDataAuthController extends BaseController
/**
* 查询数据权限列表
*/
@PreAuthorize("@ss.hasPermi('dhc:auth:list')")
@PreAuthorize("@ss.hasPermi('dhc:authData:list')")
@GetMapping("/list")
public TableDataInfo list(DhcDataAuth dhcDataAuth)
{
@ -49,7 +53,7 @@ public class DhcDataAuthController extends BaseController @@ -49,7 +53,7 @@ public class DhcDataAuthController extends BaseController
/**
* 导出数据权限列表
*/
@PreAuthorize("@ss.hasPermi('dhc:auth:export')")
@PreAuthorize("@ss.hasPermi('dhc:authData:export')")
@Log(title = "数据权限", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, DhcDataAuth dhcDataAuth)
@ -62,7 +66,7 @@ public class DhcDataAuthController extends BaseController @@ -62,7 +66,7 @@ public class DhcDataAuthController extends BaseController
/**
* 获取数据权限详细信息
*/
@PreAuthorize("@ss.hasPermi('dhc:auth:query')")
@PreAuthorize("@ss.hasPermi('dhc:authData:query')")
@GetMapping(value = "/{dataAuthId}")
public AjaxResult getInfo(@PathVariable("dataAuthId") Long dataAuthId)
{
@ -72,7 +76,7 @@ public class DhcDataAuthController extends BaseController @@ -72,7 +76,7 @@ public class DhcDataAuthController extends BaseController
/**
* 新增数据权限
*/
@PreAuthorize("@ss.hasPermi('dhc:auth:add')")
@PreAuthorize("@ss.hasPermi('dhc:authData:add')")
@Log(title = "数据权限", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody DhcDataAuth dhcDataAuth)
@ -83,7 +87,7 @@ public class DhcDataAuthController extends BaseController @@ -83,7 +87,7 @@ public class DhcDataAuthController extends BaseController
/**
* 修改数据权限
*/
@PreAuthorize("@ss.hasPermi('dhc:auth:edit')")
@PreAuthorize("@ss.hasPermi('dhc:authData:edit')")
@Log(title = "数据权限", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody DhcDataAuth dhcDataAuth)
@ -94,7 +98,7 @@ public class DhcDataAuthController extends BaseController @@ -94,7 +98,7 @@ public class DhcDataAuthController extends BaseController
/**
* 删除数据权限
*/
@PreAuthorize("@ss.hasPermi('dhc:auth:remove')")
@PreAuthorize("@ss.hasPermi('dhc:authData:remove')")
@Log(title = "数据权限", businessType = BusinessType.DELETE)
@DeleteMapping("/{dataAuthIds}")
public AjaxResult remove(@PathVariable Long[] dataAuthIds)

26
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java

@ -4,10 +4,8 @@ import java.util.List; @@ -4,10 +4,8 @@ import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.dhc.service.ISysDeptService;
import com.ruoyi.dhc.service.ISysPostService;
import com.ruoyi.dhc.service.ISysRoleService;
import com.ruoyi.dhc.service.ISysUserService;
import com.ruoyi.dhc.domain.DhcDataAuth;
import com.ruoyi.dhc.service.*;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
@ -54,6 +52,9 @@ public class SysUserController extends BaseController @@ -54,6 +52,9 @@ public class SysUserController extends BaseController
@Autowired
private ISysPostService postService;
@Autowired
private IDhcDataAuthService dhcDataAuthService;
/**
* 获取用户列表
*/
@ -254,4 +255,21 @@ public class SysUserController extends BaseController @@ -254,4 +255,21 @@ public class SysUserController extends BaseController
{
return success(deptService.selectDeptTreeList(dept));
}
/**
* 查询数据权限列表
*/
@PreAuthorize("@ss.hasPermi('system:user:query')")
@GetMapping("/authData/{userId}")
public AjaxResult authData(@PathVariable("userId") Long userId)
{
AjaxResult ajax = AjaxResult.success();
SysUser user = userService.selectUserById(userId);
DhcDataAuth dhcDataAuth = new DhcDataAuth();
dhcDataAuth.setUserId(userId);
List<DhcDataAuth> list = dhcDataAuthService.selectDhcDataAuthList(dhcDataAuth);
ajax.put("user", user);
ajax.put("authData", list);
return ajax;
}
}

14
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelect.java

@ -21,6 +21,9 @@ public class TreeSelect implements Serializable @@ -21,6 +21,9 @@ public class TreeSelect implements Serializable
/** 节点ID */
private Long id;
/** 节点ID */
private Long value;
/** 节点名称 */
private String label;
@ -36,6 +39,7 @@ public class TreeSelect implements Serializable @@ -36,6 +39,7 @@ public class TreeSelect implements Serializable
public TreeSelect(SysDept dept)
{
this.id = dept.getDeptId();
this.value = dept.getDeptId();
this.label = dept.getDeptName();
this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
@ -43,6 +47,7 @@ public class TreeSelect implements Serializable @@ -43,6 +47,7 @@ public class TreeSelect implements Serializable
public TreeSelect(SysMenu menu)
{
this.id = menu.getMenuId();
this.value = menu.getMenuId();
this.label = menu.getMenuName();
this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
@ -50,6 +55,7 @@ public class TreeSelect implements Serializable @@ -50,6 +55,7 @@ public class TreeSelect implements Serializable
public TreeSelect(DhcArea area)
{
this.id = area.getAreaId();
this.value = area.getAreaId();
this.label = area.getAreaName();
this.children = area.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
@ -82,4 +88,12 @@ public class TreeSelect implements Serializable @@ -82,4 +88,12 @@ public class TreeSelect implements Serializable
{
this.children = children;
}
public Long getValue() {
return value;
}
public void setValue(Long value) {
this.value = value;
}
}

10
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/DhcArea.java

@ -63,9 +63,19 @@ public class DhcArea extends BaseEntity @@ -63,9 +63,19 @@ public class DhcArea extends BaseEntity
/** 父区域名称 */
private String parentName;
private boolean isEdit = false;
/** 子部门 */
private List<DhcArea> children = new ArrayList<DhcArea>();
public boolean isEdit() {
return isEdit;
}
public void setEdit(boolean edit) {
isEdit = edit;
}
public String getProductLineCode() {
return productLineCode;
}

121
ruoyi-plan/src/main/java/com/ruoyi/dhc/domain/DhcDataAuth.java

@ -1,121 +0,0 @@ @@ -1,121 +0,0 @@
package com.ruoyi.dhc.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 数据权限对象 dhc_data_auth
*
* @author ruoyi
* @date 2024-07-30
*/
public class DhcDataAuth extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 数据权限ID */
private Long dataAuthId;
/** 部门ID */
@Excel(name = "部门ID")
private Long deptId;
/** 权限控制点 */
@Excel(name = "权限控制点")
private String authNode;
/** 产品线编码 */
@Excel(name = "产品线编码")
private String productLineCode;
/** 区域类型 */
@Excel(name = "区域类型")
private String areaType;
/** 区域编码 */
@Excel(name = "区域编码")
private String areaCodes;
/** 区域名称 */
@Excel(name = "区域名称")
private String areaNames;
public void setDataAuthId(Long dataAuthId)
{
this.dataAuthId = dataAuthId;
}
public Long getDataAuthId()
{
return dataAuthId;
}
public void setDeptId(Long deptId)
{
this.deptId = deptId;
}
public Long getDeptId()
{
return deptId;
}
public void setAuthNode(String authNode)
{
this.authNode = authNode;
}
public String getAuthNode()
{
return authNode;
}
public void setProductLineCode(String productLineCode)
{
this.productLineCode = productLineCode;
}
public String getProductLineCode()
{
return productLineCode;
}
public void setAreaType(String areaType)
{
this.areaType = areaType;
}
public String getAreaType()
{
return areaType;
}
public void setAreaCodes(String areaCodes)
{
this.areaCodes = areaCodes;
}
public String getAreaCodes()
{
return areaCodes;
}
public void setAreaNames(String areaNames)
{
this.areaNames = areaNames;
}
public String getAreaNames()
{
return areaNames;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("dataAuthId", getDataAuthId())
.append("deptId", getDeptId())
.append("authNode", getAuthNode())
.append("productLineCode", getProductLineCode())
.append("areaType", getAreaType())
.append("areaCodes", getAreaCodes())
.append("areaNames", getAreaNames())
.toString();
}
}

93
ruoyi-plan/src/main/java/com/ruoyi/dhc/service/impl/DhcDataAuthServiceImpl.java

@ -1,93 +0,0 @@ @@ -1,93 +0,0 @@
package com.ruoyi.dhc.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.dhc.mapper.DhcDataAuthMapper;
import com.ruoyi.dhc.domain.DhcDataAuth;
import com.ruoyi.dhc.service.IDhcDataAuthService;
/**
* 数据权限Service业务层处理
*
* @author ruoyi
* @date 2024-07-30
*/
@Service
public class DhcDataAuthServiceImpl implements IDhcDataAuthService
{
@Autowired
private DhcDataAuthMapper dhcDataAuthMapper;
/**
* 查询数据权限
*
* @param dataAuthId 数据权限主键
* @return 数据权限
*/
@Override
public DhcDataAuth selectDhcDataAuthByDataAuthId(Long dataAuthId)
{
return dhcDataAuthMapper.selectDhcDataAuthByDataAuthId(dataAuthId);
}
/**
* 查询数据权限列表
*
* @param dhcDataAuth 数据权限
* @return 数据权限
*/
@Override
public List<DhcDataAuth> selectDhcDataAuthList(DhcDataAuth dhcDataAuth)
{
return dhcDataAuthMapper.selectDhcDataAuthList(dhcDataAuth);
}
/**
* 新增数据权限
*
* @param dhcDataAuth 数据权限
* @return 结果
*/
@Override
public int insertDhcDataAuth(DhcDataAuth dhcDataAuth)
{
return dhcDataAuthMapper.insertDhcDataAuth(dhcDataAuth);
}
/**
* 修改数据权限
*
* @param dhcDataAuth 数据权限
* @return 结果
*/
@Override
public int updateDhcDataAuth(DhcDataAuth dhcDataAuth)
{
return dhcDataAuthMapper.updateDhcDataAuth(dhcDataAuth);
}
/**
* 批量删除数据权限
*
* @param dataAuthIds 需要删除的数据权限主键
* @return 结果
*/
@Override
public int deleteDhcDataAuthByDataAuthIds(Long[] dataAuthIds)
{
return dhcDataAuthMapper.deleteDhcDataAuthByDataAuthIds(dataAuthIds);
}
/**
* 删除数据权限信息
*
* @param dataAuthId 数据权限主键
* @return 结果
*/
@Override
public int deleteDhcDataAuthByDataAuthId(Long dataAuthId)
{
return dhcDataAuthMapper.deleteDhcDataAuthByDataAuthId(dataAuthId);
}
}

201
ruoyi-system/src/main/java/com/ruoyi/dhc/domain/DhcDataAuth.java

@ -0,0 +1,201 @@ @@ -0,0 +1,201 @@
package com.ruoyi.dhc.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import java.util.List;
/**
* 数据权限对象 dhc_data_auth
*
* @author ruoyi
* @date 2024-08-01
*/
public class DhcDataAuth extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 数据权限ID */
private Long dataAuthId;
/** 用户ID */
private Long userId;
/** 部门ID */
@Excel(name = "部门ID")
private Long deptId;
/** 权限控制点 */
@Excel(name = "部门树ID")
private String deptAllId;
/** 权限控制点 */
@Excel(name = "部门树名称")
private String deptAllName;
/** 权限控制点 */
@Excel(name = "权限控制点")
private String authNode;
/** 产品线编码 */
@Excel(name = "产品线编码")
private String productLineCode;
/** 区域类型 */
@Excel(name = "区域类型")
private String areaType;
/** 类型(0区域 1.客户) */
private String detailType;
/** 数据权限明细 */
List<DhcDataAuthDetail> detailList;
List<String> detailCodes;
List<Long> deptIds;
private String detailNames;
private boolean editFlag;
private List<Long> dataAuthIds;
public List<Long> getDataAuthIds() {
return dataAuthIds;
}
public void setDataAuthIds(List<Long> dataAuthIds) {
this.dataAuthIds = dataAuthIds;
}
public boolean getEditFlag() {
return editFlag;
}
public void setEditFlag(boolean editFlag) {
this.editFlag = editFlag;
}
public List<Long> getDeptIds() {
return deptIds;
}
public void setDeptIds(List<Long> deptIds) {
this.deptIds = deptIds;
}
public String getDetailNames() {
return detailNames;
}
public void setDetailNames(String detailNames) {
this.detailNames = detailNames;
}
public String getDeptAllId() {
return deptAllId;
}
public void setDeptAllId(String deptAllId) {
this.deptAllId = deptAllId;
}
public String getDeptAllName() {
return deptAllName;
}
public void setDeptAllName(String deptAllName) {
this.deptAllName = deptAllName;
}
public List<String> getDetailCodes() {
return detailCodes;
}
public void setDetailCodes(List<String> detailCodes) {
this.detailCodes = detailCodes;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getDetailType() {
return detailType;
}
public void setDetailType(String detailType) {
this.detailType = detailType;
}
public List<DhcDataAuthDetail> getDetailList() {
return detailList;
}
public void setDetailList(List<DhcDataAuthDetail> detailList) {
this.detailList = detailList;
}
public void setDataAuthId(Long dataAuthId)
{
this.dataAuthId = dataAuthId;
}
public Long getDataAuthId()
{
return dataAuthId;
}
public void setDeptId(Long deptId)
{
this.deptId = deptId;
}
public Long getDeptId()
{
return deptId;
}
public void setAuthNode(String authNode)
{
this.authNode = authNode;
}
public String getAuthNode()
{
return authNode;
}
public void setProductLineCode(String productLineCode)
{
this.productLineCode = productLineCode;
}
public String getProductLineCode()
{
return productLineCode;
}
public void setAreaType(String areaType)
{
this.areaType = areaType;
}
public String getAreaType()
{
return areaType;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("dataAuthId", getDataAuthId())
.append("deptId", getDeptId())
.append("authNode", getAuthNode())
.append("productLineCode", getProductLineCode())
.append("areaType", getAreaType())
.toString();
}
}

77
ruoyi-system/src/main/java/com/ruoyi/dhc/domain/DhcDataAuthDetail.java

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
package com.ruoyi.dhc.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 数据权限明细对象 dhc_data_auth_detail
*
* @author ruoyi
* @date 2024-08-01
*/
public class DhcDataAuthDetail extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 数据权限ID */
private Long dataAuthId;
/** 类型(0区域 1.客户) */
private String detailType;
/** 权限明细编码 */
private String detailCode;
/** 权限明细名称 */
@Excel(name = "权限明细名称")
private String detailName;
public void setDataAuthId(Long dataAuthId)
{
this.dataAuthId = dataAuthId;
}
public Long getDataAuthId()
{
return dataAuthId;
}
public void setDetailType(String detailType)
{
this.detailType = detailType;
}
public String getDetailType()
{
return detailType;
}
public void setDetailCode(String detailCode)
{
this.detailCode = detailCode;
}
public String getDetailCode()
{
return detailCode;
}
public void setDetailName(String detailName)
{
this.detailName = detailName;
}
public String getDetailName()
{
return detailName;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("dataAuthId", getDataAuthId())
.append("detailType", getDetailType())
.append("detailCode", getDetailCode())
.append("detailName", getDetailName())
.toString();
}
}

30
ruoyi-plan/src/main/java/com/ruoyi/dhc/mapper/DhcDataAuthMapper.java → ruoyi-system/src/main/java/com/ruoyi/dhc/mapper/DhcDataAuthMapper.java

@ -1,13 +1,15 @@ @@ -1,13 +1,15 @@
package com.ruoyi.dhc.mapper;
import java.util.List;
import com.ruoyi.dhc.domain.DhcDataAuth;
import com.ruoyi.dhc.domain.DhcDataAuthDetail;
import java.util.List;
/**
* 数据权限Mapper接口
*
* @author ruoyi
* @date 2024-07-30
* @date 2024-08-01
*/
public interface DhcDataAuthMapper
{
@ -58,4 +60,28 @@ public interface DhcDataAuthMapper @@ -58,4 +60,28 @@ public interface DhcDataAuthMapper
* @return 结果
*/
public int deleteDhcDataAuthByDataAuthIds(Long[] dataAuthIds);
/**
* 批量删除数据权限明细
*
* @param dhcDataAuth 需要删除的数据主键集合
* @return 结果
*/
public int deleteDataAuthDetailByDataAuthIds(DhcDataAuth dhcDataAuth);
/**
* 批量新增数据权限明细
*
* @param list 数据权限明细列表
* @return 结果
*/
public int batchAddDataAuthDetail(List<DhcDataAuthDetail> list);
/**
* 查询数据权限明细
*
* @param dhcDataAuth 数据权限明细列表
* @return 结果
*/
public List<DhcDataAuthDetail> selectDhcDataAuthDetailList(DhcDataAuth dhcDataAuth);
}

2
ruoyi-plan/src/main/java/com/ruoyi/dhc/service/IDhcDataAuthService.java → ruoyi-system/src/main/java/com/ruoyi/dhc/service/IDhcDataAuthService.java

@ -7,7 +7,7 @@ import com.ruoyi.dhc.domain.DhcDataAuth; @@ -7,7 +7,7 @@ import com.ruoyi.dhc.domain.DhcDataAuth;
* 数据权限Service接口
*
* @author ruoyi
* @date 2024-07-30
* @date 2024-08-01
*/
public interface IDhcDataAuthService
{

129
ruoyi-system/src/main/java/com/ruoyi/dhc/service/impl/DhcDataAuthServiceImpl.java

@ -0,0 +1,129 @@ @@ -0,0 +1,129 @@
package com.ruoyi.dhc.service.impl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.dhc.domain.DhcDataAuth;
import com.ruoyi.dhc.domain.DhcDataAuthDetail;
import com.ruoyi.dhc.mapper.DhcDataAuthMapper;
import com.ruoyi.dhc.service.IDhcDataAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* 数据权限Service业务层处理
*
* @author ruoyi
* @date 2024-08-01
*/
@Service
public class DhcDataAuthServiceImpl implements IDhcDataAuthService
{
@Autowired
private DhcDataAuthMapper dhcDataAuthMapper;
/**
* 查询数据权限
*
* @param dataAuthId 数据权限主键
* @return 数据权限
*/
@Override
public DhcDataAuth selectDhcDataAuthByDataAuthId(Long dataAuthId)
{
return dhcDataAuthMapper.selectDhcDataAuthByDataAuthId(dataAuthId);
}
/**
* 查询数据权限列表
*
* @param dhcDataAuth 数据权限
* @return 数据权限
*/
@Override
public List<DhcDataAuth> selectDhcDataAuthList(DhcDataAuth dhcDataAuth)
{ List<DhcDataAuth> list = dhcDataAuthMapper.selectDhcDataAuthList(dhcDataAuth);
list.forEach(item->{
item.setDetailType("0");
List<DhcDataAuthDetail> detailList = dhcDataAuthMapper.selectDhcDataAuthDetailList(item);
String[] array = item.getDeptAllId().split("/");
List<Long> deptIds = new ArrayList<>();
for (String deptId : array) {
deptIds.add(Long.valueOf(deptId));
}
item.setDeptIds(deptIds);
item.setDetailList(detailList);
item.setEditFlag(false);
item.setDetailCodes(detailList.stream().map(model->{return model.getDetailCode();}).collect(Collectors.toList()));
item.setDetailNames(StringUtils.join(detailList.stream().map(model->{return model.getDetailName();}).collect(Collectors.toList()),"/"));
});
return list;
}
/**
* 新增数据权限
*
* @param dhcDataAuth 数据权限
* @return 结果
*/
@Override
public int insertDhcDataAuth(DhcDataAuth dhcDataAuth)
{
if (dhcDataAuth.getDataAuthId() != null) {
dhcDataAuthMapper.deleteDhcDataAuthByDataAuthId(dhcDataAuth.getDataAuthId());
dhcDataAuthMapper.deleteDataAuthDetailByDataAuthIds(dhcDataAuth);
}
int count = dhcDataAuthMapper.insertDhcDataAuth(dhcDataAuth);
dhcDataAuth.getDetailList().forEach(item->{
item.setDataAuthId(dhcDataAuth.getDataAuthId());
});
dhcDataAuthMapper.batchAddDataAuthDetail(dhcDataAuth.getDetailList());
return count;
}
/**
* 修改数据权限
*
* @param dhcDataAuth 数据权限
* @return 结果
*/
@Override
public int updateDhcDataAuth(DhcDataAuth dhcDataAuth)
{
dhcDataAuthMapper.deleteDataAuthDetailByDataAuthIds(dhcDataAuth);
dhcDataAuthMapper.batchAddDataAuthDetail(dhcDataAuth.getDetailList());
return dhcDataAuthMapper.updateDhcDataAuth(dhcDataAuth);
}
/**
* 批量删除数据权限
*
* @param dataAuthIds 需要删除的数据权限主键
* @return 结果
*/
@Override
public int deleteDhcDataAuthByDataAuthIds(Long[] dataAuthIds)
{ DhcDataAuth dhcDataAuth = new DhcDataAuth();
dhcDataAuth.setDataAuthIds(new ArrayList<>(Arrays.asList(dataAuthIds)));
dhcDataAuthMapper.deleteDataAuthDetailByDataAuthIds(dhcDataAuth);
return dhcDataAuthMapper.deleteDhcDataAuthByDataAuthIds(dataAuthIds);
}
/**
* 删除数据权限信息
*
* @param dataAuthId 数据权限主键
* @return 结果
*/
@Override
public int deleteDhcDataAuthByDataAuthId(Long dataAuthId)
{
DhcDataAuth dhcDataAuth = new DhcDataAuth();
dhcDataAuth.setDataAuthId(dataAuthId);
dhcDataAuthMapper.deleteDataAuthDetailByDataAuthIds(dhcDataAuth);
return dhcDataAuthMapper.deleteDhcDataAuthByDataAuthId(dataAuthId);
}
}

64
ruoyi-plan/src/main/resources/mapper/dhc/DhcDataAuthMapper.xml → ruoyi-system/src/main/resources/mapper/system/DhcDataAuthMapper.xml

@ -6,27 +6,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -6,27 +6,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="DhcDataAuth" id="DhcDataAuthResult">
<result property="dataAuthId" column="data_auth_id" />
<result property="userId" column="user_id" />
<result property="deptId" column="dept_id" />
<result property="authNode" column="auth_node" />
<result property="productLineCode" column="product_line_code" />
<result property="areaType" column="area_type" />
<result property="areaCodes" column="area_codes" />
<result property="areaNames" column="area_names" />
<result property="deptAllId" column="dept_all_id" />
<result property="deptAllName" column="dept_all_Name" />
</resultMap>
<resultMap type="DhcDataAuthDetail" id="DhcDataAuthDetailResult">
<result property="dataAuthId" column="data_auth_id" />
<result property="detailType" column="detail_type" />
<result property="detailCode" column="detail_code" />
<result property="detailName" column="detail_name" />
</resultMap>
<sql id="selectDhcDataAuthVo">
select data_auth_id, dept_id, auth_node, product_line_code, area_type, area_codes, area_names from dhc_data_auth
select data_auth_id, user_id, dept_id, auth_node, product_line_code, area_type,b.dept_all_id,dept_all_Name from dhc_data_auth
</sql>
<select id="selectDhcDataAuthList" parameterType="DhcDataAuth" resultMap="DhcDataAuthResult">
<include refid="selectDhcDataAuthVo"/>
<where>
select data_auth_id, user_id, dept_id, auth_node, product_line_code, area_type,dept_all_id,dept_all_Name from dhc_data_auth
<where>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="deptId != null "> and dept_id = #{deptId}</if>
<if test="authNode != null and authNode != ''"> and auth_node = #{authNode}</if>
<if test="productLineCode != null and productLineCode != ''"> and product_line_code = #{productLineCode}</if>
<if test="areaType != null and areaType != ''"> and area_type = #{areaType}</if>
<if test="areaCodes != null and areaCodes != ''"> and area_codes = #{areaCodes}</if>
<if test="areaNames != null and areaNames != ''"> and area_names = #{areaNames}</if>
</where>
</select>
@ -38,32 +45,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -38,32 +45,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertDhcDataAuth" parameterType="DhcDataAuth" useGeneratedKeys="true" keyProperty="dataAuthId">
insert into dhc_data_auth
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">user_id,</if>
<if test="deptId != null">dept_id,</if>
<if test="deptAllId != null and deptAllId != ''">dept_all_id,</if>
<if test="deptAllName != null and deptAllName != ''">dept_all_Name,</if>
<if test="authNode != null and authNode != ''">auth_node,</if>
<if test="productLineCode != null and productLineCode != ''">product_line_code,</if>
<if test="areaType != null and areaType != ''">area_type,</if>
<if test="areaCodes != null and areaCodes != ''">area_codes,</if>
<if test="areaNames != null and areaNames != ''">area_names,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">#{userId},</if>
<if test="deptId != null">#{deptId},</if>
<if test="deptAllId != null and deptAllId != ''">#{deptAllId},</if>
<if test="deptAllName != null and deptAllName != ''">#{deptAllName},</if>
<if test="authNode != null and authNode != ''">#{authNode},</if>
<if test="productLineCode != null and productLineCode != ''">#{productLineCode},</if>
<if test="areaType != null and areaType != ''">#{areaType},</if>
<if test="areaCodes != null and areaCodes != ''">#{areaCodes},</if>
<if test="areaNames != null and areaNames != ''">#{areaNames},</if>
</trim>
</insert>
<update id="updateDhcDataAuth" parameterType="DhcDataAuth">
update dhc_data_auth
<trim prefix="SET" suffixOverrides=",">
<if test="userId != null">user_id = #{userId},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="deptAllId != null and deptAllId != ''">dept_all_id = #{deptAllId},</if>
<if test="deptAllName != null and deptAllName != ''">dept_all_Name = #{deptAllName},</if>
<if test="authNode != null and authNode != ''">auth_node = #{authNode},</if>
<if test="productLineCode != null and productLineCode != ''">product_line_code = #{productLineCode},</if>
<if test="areaType != null and areaType != ''">area_type = #{areaType},</if>
<if test="areaCodes != null and areaCodes != ''">area_codes = #{areaCodes},</if>
<if test="areaNames != null and areaNames != ''">area_names = #{areaNames},</if>
</trim>
where data_auth_id = #{dataAuthId}
</update>
@ -78,4 +88,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -78,4 +88,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{dataAuthId}
</foreach>
</delete>
<delete id="deleteDataAuthDetailByDataAuthIds" parameterType="DhcDataAuth">
delete from dhc_data_auth_detail
<where>
<if test="dataAuthId != null "> and data_auth_id = #{dataAuthId}</if>
<if test="detailType != null and detailType != ''"> and detail_type = #{detailType}</if>
<if test="detailList != null and detailList.size() &gt; 0">
and detail_code in
<foreach item="detailCode" collection="detailList" open="(" separator="," close=")">
#{detailCode}
</foreach>
</if>
<if test="dataAuthIds != null and dataAuthIds.size() &gt; 0">
and data_auth_id in
<foreach item="dataAuthId" collection="dataAuthIds" open="(" separator="," close=")">
#{dataAuthId}
</foreach>
</if>
</where>
</delete>
<insert id="batchAddDataAuthDetail">
insert into dhc_data_auth_detail(data_auth_id, detail_type, detail_code, detail_name) values
<foreach item="item" index="index" collection="list" separator=",">
(#{item.dataAuthId},#{item.detailType},#{item.detailCode},#{item.detailName})
</foreach>
</insert>
<select id="selectDhcDataAuthDetailList" parameterType="DhcDataAuth" resultMap="DhcDataAuthDetailResult">
select detail_code,detail_name from dhc_data_auth_detail where data_auth_id = #{dataAuthId} and detail_type = #{detailType}
</select>
</mapper>

29
sql/基础功能.sql

@ -4,16 +4,29 @@ @@ -4,16 +4,29 @@
drop table if exists dhc_data_auth;
create table dhc_data_auth (
data_auth_id bigint NOT NULL auto_increment COMMENT '数据权限ID',
user_id bigint(20) NOT NULL comment '用户ID',
dept_id bigint(20) NOT NULL comment '部门ID',
dept_all_id varchar(1000) NOT NULL comment '部门树ID',
dept_all_Name varchar(1000) NOT NULL comment '部门树名称',
auth_node varchar(32) NOT NULL comment '权限控制点',
product_line_code varchar(32) NOT NULL comment '产品线编码',
area_type varchar(32) default '' NOT NULL comment '区域类型',
area_codes varchar(1000) default '' NOT NULL comment '区域编码',
area_names varchar(2000) default '' NOT NULL comment '区域名称',
primary key (data_auth_id)
) engine=innodb auto_increment=1 comment = '数据权限表';
-- ----------------------------
-- 2、数据权限明细表
-- ----------------------------
drop table if exists dhc_data_auth_datail;
create table dhc_data_auth_detail (
data_auth_id bigint NOT NULL COMMENT '数据权限ID',
detail_type char(1) NOT NULL comment '类型(0区域 1.客户)',
detail_code varchar(32) NOT NULL comment '权限明细编码',
detail_name varchar(64) NOT NULL comment '权限明细名称',
primary key (data_auth_id, detail_type, detail_code)
) engine=innodb auto_increment=1 comment = '数据权限明细表';
-- ----------------------------
-- 2、产品线-区域类型-区域层级关系表
-- 3、产品线-区域类型-区域层级关系表
-- ----------------------------
drop table if exists dhc_product_line_area;
create table dhc_product_line_area (
@ -23,7 +36,7 @@ create table dhc_product_line_area ( @@ -23,7 +36,7 @@ create table dhc_product_line_area (
primary key (product_line_code,area_type,area_level)
) engine=innodb auto_increment=1 comment = '产品线-区域类型-区域层级关系表';
-- ----------------------------
-- 3、区域表
-- 4、区域表
-- ----------------------------
drop table if exists dhc_area;
create table dhc_area (
@ -46,7 +59,7 @@ create table dhc_area ( @@ -46,7 +59,7 @@ create table dhc_area (
) engine=innodb auto_increment=1 comment = '区域表';
-- ----------------------------
-- 4、国家表
-- 5、国家表
-- ----------------------------
drop table if exists dhc_country;
create table dhc_country (
@ -65,7 +78,7 @@ create table dhc_country ( @@ -65,7 +78,7 @@ create table dhc_country (
primary key (country_id)
) engine=innodb auto_increment=1 comment = '国家表';
-- ----------------------------
-- 5、生产基地与产品线关系表
-- 6、生产基地与产品线关系表
-- ----------------------------
drop table if exists dhc_production_base_line;
create table dhc_production_base_line (
@ -74,7 +87,7 @@ create table dhc_production_base_line ( @@ -74,7 +87,7 @@ create table dhc_production_base_line (
primary key (product_line_code,production_base_code)
) engine=innodb auto_increment=1 comment = '生产基地与产品线关系表';
-- ----------------------------
-- 6、品牌表
-- 7、品牌表
-- ----------------------------
drop table if exists dhc_brand;
create table dhc_brand (
@ -89,7 +102,7 @@ create table dhc_brand ( @@ -89,7 +102,7 @@ create table dhc_brand (
primary key (brand_id)
) engine=innodb auto_increment=1 comment = '品牌表';
-- ----------------------------
-- 7、供应商信息表
-- 8、供应商信息表
-- ----------------------------
drop table if exists dhc_supplier;
create table dhc_supplier (

Loading…
Cancel
Save