feat: 新增了资产授权功能

资产授权功能包括,数据源分别给部门和用户的授权,数据源下的表分别给部门和用户的授权,以及给父级部门授权时,也会给此部门所有自己部门授权,取消授权也一样,用户授权也实现了,用户只能查看已授权的数据源和数据源下的表信息
master
yaoxin 2024-04-26 17:53:15 +08:00
parent ba27959f19
commit 0960b70277
20 changed files with 1431 additions and 11 deletions

View File

@ -84,11 +84,24 @@ public class SysDept extends BaseEntity {
*/
private String parentName;
/**
*
*/
private Boolean isAuth=false;
/**
*
*/
private List<SysDept> children = new ArrayList<SysDept>();
public Boolean getAuth() {
return isAuth;
}
public void setAuth(Boolean auth) {
isAuth = auth;
}
public Long getDeptId () {
return deptId;
}

View File

@ -96,6 +96,11 @@ public class SysUser extends BaseEntity {
*/
private String delFlag;
/**
*
*/
private Boolean isAuth = false;
/**
* IP
*/
@ -122,6 +127,8 @@ public class SysUser extends BaseEntity {
*/
private List<SysRole> roles;
/**
*
*/
@ -137,6 +144,14 @@ public class SysUser extends BaseEntity {
*/
private Long roleId;
public Boolean getAuth() {
return isAuth;
}
public void setAuth(Boolean auth) {
isAuth = auth;
}
public SysUser (Long userId) {
this.userId = userId;
}

View File

@ -0,0 +1,118 @@
package com.muyu.etl.controller;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.etl.domain.SourceAccredit;
import com.muyu.etl.domain.req.AssetAccreditReq;
import com.muyu.etl.domain.req.SourceAccreditReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.etl.domain.AssetAccredit;
import com.muyu.etl.service.IAssetAccreditService;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.page.TableDataInfo;
/**
* Controller
*
* @author ruoyi
* @date 2024-04-25
*/
@RestController
@RequestMapping("/assetAccredit")
public class AssetAccreditController extends BaseController
{
@Autowired
private IAssetAccreditService assetAccreditService;
/**
*
*/
@GetMapping("/list")
public Result<TableDataInfo<AssetAccredit>> list(AssetAccredit assetAccredit)
{
startPage();
List<AssetAccredit> list = assetAccreditService.selectAssetAccreditList(assetAccredit);
return getDataTable(list);
}
/**
*
*/
@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, AssetAccredit assetAccredit)
{
List<AssetAccredit> list = assetAccreditService.selectAssetAccreditList(assetAccredit);
ExcelUtil<AssetAccredit> util = new ExcelUtil<AssetAccredit>(AssetAccredit.class);
util.exportExcel(response, list, "【请填写功能名称】数据");
}
/**
*
*/
@GetMapping(value = "/{id}")
public Result getInfo(@PathVariable("id") Long id)
{
return success(assetAccreditService.selectAssetAccreditById(id));
}
/**
* id
*/
@GetMapping(value = "/GetAssetAccreditByDataAssetId")
public Result getAssetAccreditByDataAssetId(@RequestParam("id") Long id)
{
return assetAccreditService.getAssetAccreditByDataAssetId(id);
}
/**
*
*/
@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
@PostMapping
public Result add(@RequestBody AssetAccreditReq assetAccreditReq)
{
return assetAccreditService.insertAssetAccredit(assetAccreditReq);
}
/**
*
*/
@Log(title = "授权删除", businessType = BusinessType.INSERT)
@PostMapping("/DeleteAssetAccreditByAssetIds")
public Result deleteSourceAccreditBySourceIds(@RequestBody AssetAccreditReq assetAccreditReq)
{
return assetAccreditService.deleteAssetAccreditByAssetIds(assetAccreditReq);
}
/**
*
*/
@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
@PutMapping
public Result edit(@RequestBody AssetAccredit assetAccredit)
{
return toAjax(assetAccreditService.updateAssetAccredit(assetAccredit));
}
/**
*
*/
@Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public Result remove(@PathVariable Long[] ids)
{
return toAjax(assetAccreditService.deleteAssetAccreditByIds(ids));
}
}

View File

@ -0,0 +1,118 @@
package com.muyu.etl.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.muyu.etl.domain.req.SourceAccreditReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.etl.domain.SourceAccredit;
import com.muyu.etl.service.ISourceAccreditService;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.page.TableDataInfo;
/**
* Controller
*
* @author ruoyi
* @date 2024-04-25
*/
@RestController
@RequestMapping("/sourceAccredit")
public class SourceAccreditController extends BaseController
{
@Autowired
private ISourceAccreditService sourceAccreditService;
/**
*
*/
@RequiresPermissions("system:accredit:list")
@GetMapping("/list")
public Result<TableDataInfo<SourceAccredit>> list(SourceAccredit sourceAccredit)
{
startPage();
List<SourceAccredit> list = sourceAccreditService.selectSourceAccreditList(sourceAccredit);
return getDataTable(list);
}
/**
*
*/
@RequiresPermissions("system:accredit:export")
@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SourceAccredit sourceAccredit)
{
List<SourceAccredit> list = sourceAccreditService.selectSourceAccreditList(sourceAccredit);
ExcelUtil<SourceAccredit> util = new ExcelUtil<SourceAccredit>(SourceAccredit.class);
util.exportExcel(response, list, "【请填写功能名称】数据");
}
/**
*
*/
@RequiresPermissions("system:accredit:query")
@GetMapping(value = "/{id}")
public Result getInfo(@PathVariable("id") Long id)
{
return success(sourceAccreditService.selectSourceAccreditById(id));
}
/**
* id
*/
@GetMapping(value = "/GetSourceAccreditByDataSourceId")
public Result getSourceAccreditByDataSourceId(@RequestParam("id") Long id)
{
return sourceAccreditService.getSourceAccreditByDataSourceId(id);
}
/**
*
*/
@RequiresPermissions("system:accredit:add")
@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
@PostMapping
public Result add(@RequestBody SourceAccreditReq sourceAccreditReq)
{
return sourceAccreditService.insertSourceAccredit(sourceAccreditReq);
}
/**
*
*/
@Log(title = "授权删除", businessType = BusinessType.INSERT)
@PostMapping("/DeleteSourceAccreditBySourceIds")
public Result deleteSourceAccreditBySourceIds(@RequestBody SourceAccreditReq sourceAccreditReq)
{
return sourceAccreditService.deleteSourceAccreditBySourceIds(sourceAccreditReq);
}
/**
*
*/
@RequiresPermissions("system:accredit:edit")
@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
@PutMapping
public Result edit(@RequestBody SourceAccredit sourceAccredit)
{
return toAjax(sourceAccreditService.updateSourceAccredit(sourceAccredit));
}
/**
*
*/
@RequiresPermissions("system:accredit:remove")
@Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public Result remove(@PathVariable Long[] ids)
{
return toAjax(sourceAccreditService.deleteSourceAccreditByIds(ids));
}
}

View File

@ -0,0 +1,86 @@
package com.muyu.etl.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
/**
* asset_accredit
*
* @author ruoyi
* @date 2024-04-25
*/
public class AssetAccredit extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id;
/** 部门id */
@Excel(name = "部门id")
private Long deptId;
/** 数据表id */
@Excel(name = "数据表id")
private Long dataAssetId;
/** 用户id */
@Excel(name = "用户id")
private Long userId;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setDeptId(Long deptId)
{
this.deptId = deptId;
}
public Long getDeptId()
{
return deptId;
}
public void setDataAssetId(Long dataAssetId)
{
this.dataAssetId = dataAssetId;
}
public Long getDataAssetId()
{
return dataAssetId;
}
public void setUserId(Long userId)
{
this.userId = userId;
}
public Long getUserId()
{
return userId;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("deptId", getDeptId())
.append("dataAssetId", getDataAssetId())
.append("userId", getUserId())
.append("remark", getRemark())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.toString();
}
}

View File

@ -0,0 +1,85 @@
package com.muyu.etl.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
/**
* source_accredit
*
* @author ruoyi
* @date 2024-04-25
*/
public class SourceAccredit extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id;
/** 部门id */
@Excel(name = "部门id")
private Long deptId;
/** 数据源id */
@Excel(name = "数据源id")
private Long dataSourceId;
/** 用户id */
@Excel(name = "用户id")
private Long userId;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public Long getDeptId() {
return deptId;
}
public void setDeptId(Long deptId) {
this.deptId = deptId;
}
public Long getDataSourceId() {
return dataSourceId;
}
public void setDataSourceId(Long dataSourceId) {
this.dataSourceId = dataSourceId;
}
public void setUserId(Long userId)
{
this.userId = userId;
}
public Long getUserId()
{
return userId;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("deptId", getDeptId())
.append("dataSourceId", getDataSourceId())
.append("userId", getUserId())
.append("remark", getRemark())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.toString();
}
}

View File

@ -0,0 +1,21 @@
package com.muyu.etl.domain.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @ClassName AccreditModel
* @Description
* @Author Xin.Yao
* @Date 2024/4/26 9:09
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AccreditModel {
private List<Long> userAccreditModelIds;
private List<Long> deptAccreditModelIds;
}

View File

@ -0,0 +1,24 @@
package com.muyu.etl.domain.req;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* @ClassName SourceAccreditReq
* @Description
* @Author Xin.Yao
* @Date 2024/4/26 15:19
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class AssetAccreditReq {
private List<Long> deptIds;
private Long userId;
private Long dataAssetId;
}

View File

@ -0,0 +1,24 @@
package com.muyu.etl.domain.req;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* @ClassName SourceAccreditReq
* @Description
* @Author Xin.Yao
* @Date 2024/4/26 15:19
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class SourceAccreditReq {
private List<Long> deptIds;
private Long userId;
private Long dataSourceId;
}

View File

@ -0,0 +1,73 @@
package com.muyu.etl.mapper;
import java.util.List;
import com.muyu.etl.domain.AssetAccredit;
import com.muyu.etl.domain.SourceAccredit;
import org.apache.ibatis.annotations.Param;
/**
* Mapper
*
* @author ruoyi
* @date 2024-04-25
*/
public interface AssetAccreditMapper
{
/**
*
*
* @param id
* @return
*/
public AssetAccredit selectAssetAccreditById(Long id);
/**
*
*
* @param assetAccredit
* @return
*/
public List<AssetAccredit> selectAssetAccreditList(AssetAccredit assetAccredit);
/**
*
*
* @param assetAccredit
* @return
*/
public int insertAssetAccredit(AssetAccredit assetAccredit);
/**
*
*
* @param assetAccredit
* @return
*/
public int updateAssetAccredit(AssetAccredit assetAccredit);
/**
*
*
* @param id
* @return
*/
public int deleteAssetAccreditById(Long id);
/**
*
*
* @param ids
* @return
*/
public int deleteAssetAccreditByIds(Long[] ids);
void deleteAssetAccreditByAssetIds(@Param("assetIds") List<Long> assetIds);
List<AssetAccredit> getAssetAccreditByDataAssetId(@Param("id") Long id);
List<AssetAccredit> getAssetAccreditByUserId(@Param("id") Long id);
void deleteAssetAccreditByDeptUser(@Param("deptIds") List<Long> deptIds, @Param("userId") Long userId, @Param("dataAssetId") Long dataAssetId);
void insertBatchAssetAccredit(@Param("assetAccredits") List<AssetAccredit> assetAccredits);
}

View File

@ -66,4 +66,6 @@ public interface DataAssetMapper
List<DataAsset> selectDataAssetBatchId(@Param("longs") List<Long> longs);
List<DataAsset> getDataAssetList(@Param("ids") Long[] ids);
List<DataAsset> getDataAssetByAssetId(@Param("assetIds") List<Long> assetIds);
}

View File

@ -0,0 +1,72 @@
package com.muyu.etl.mapper;
import java.util.List;
import com.muyu.etl.domain.SourceAccredit;
import org.apache.ibatis.annotations.Param;
/**
* Mapper
*
* @author ruoyi
* @date 2024-04-25
*/
public interface SourceAccreditMapper
{
/**
*
*
* @param id
* @return
*/
public SourceAccredit selectSourceAccreditById(Long id);
/**
*
*
* @param sourceAccredit
* @return
*/
public List<SourceAccredit> selectSourceAccreditList(SourceAccredit sourceAccredit);
/**
*
*
* @param sourceAccredit
* @return
*/
public int insertSourceAccredit(SourceAccredit sourceAccredit);
/**
*
*
* @param sourceAccredit
* @return
*/
public int updateSourceAccredit(SourceAccredit sourceAccredit);
/**
*
*
* @param id
* @return
*/
public int deleteSourceAccreditById(Long id);
/**
*
*
* @param ids
* @return
*/
public int deleteSourceAccreditByIds(Long[] ids);
void deleteSourceAccreditBySourceIds(@Param("sourceIds") List<Long> sourceIds);
List<SourceAccredit> getSourceAccreditByDataSourceId(@Param("id") Long id);
List<SourceAccredit> getSourceAccreditByUserId(@Param("id") Long id);
void insertBatchSourceAccredit(@Param("sourceAccredits") List<SourceAccredit> sourceAccredits);
void deleteSourceAccreditByDeptUser(@Param("deptIds") List<Long> deptIds, @Param("userId") Long userId, @Param("dataSourceId") Long dataSourceId);
}

View File

@ -0,0 +1,68 @@
package com.muyu.etl.service;
import java.util.List;
import com.muyu.common.core.domain.Result;
import com.muyu.etl.domain.AssetAccredit;
import com.muyu.etl.domain.req.AssetAccreditReq;
/**
* Service
*
* @author ruoyi
* @date 2024-04-25
*/
public interface IAssetAccreditService
{
/**
*
*
* @param id
* @return
*/
public AssetAccredit selectAssetAccreditById(Long id);
/**
*
*
* @param assetAccredit
* @return
*/
public List<AssetAccredit> selectAssetAccreditList(AssetAccredit assetAccredit);
/**
*
*
* @param assetAccreditReq
* @return
*/
public Result insertAssetAccredit(AssetAccreditReq assetAccreditReq);
/**
*
*
* @param assetAccredit
* @return
*/
public int updateAssetAccredit(AssetAccredit assetAccredit);
/**
*
*
* @param ids
* @return
*/
public int deleteAssetAccreditByIds(Long[] ids);
/**
*
*
* @param id
* @return
*/
public int deleteAssetAccreditById(Long id);
Result getAssetAccreditByDataAssetId(Long id);
Result deleteAssetAccreditByAssetIds(AssetAccreditReq assetAccreditReq);
}

View File

@ -0,0 +1,68 @@
package com.muyu.etl.service;
import java.util.List;
import com.muyu.common.core.domain.Result;
import com.muyu.etl.domain.SourceAccredit;
import com.muyu.etl.domain.req.SourceAccreditReq;
/**
* Service
*
* @author ruoyi
* @date 2024-04-25
*/
public interface ISourceAccreditService
{
/**
*
*
* @param id
* @return
*/
public SourceAccredit selectSourceAccreditById(Long id);
/**
*
*
* @param sourceAccredit
* @return
*/
public List<SourceAccredit> selectSourceAccreditList(SourceAccredit sourceAccredit);
/**
*
*
* @param sourceAccreditReq
* @return
*/
public Result insertSourceAccredit(SourceAccreditReq sourceAccreditReq);
/**
*
*
* @param sourceAccredit
* @return
*/
public int updateSourceAccredit(SourceAccredit sourceAccredit);
/**
*
*
* @param ids
* @return
*/
public int deleteSourceAccreditByIds(Long[] ids);
/**
*
*
* @param id
* @return
*/
public int deleteSourceAccreditById(Long id);
Result getSourceAccreditByDataSourceId(Long id);
Result deleteSourceAccreditBySourceIds(SourceAccreditReq sourceAccreditReq);
}

View File

@ -0,0 +1,145 @@
package com.muyu.etl.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.etl.domain.SourceAccredit;
import com.muyu.etl.domain.model.AccreditModel;
import com.muyu.etl.domain.req.AssetAccreditReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.muyu.etl.mapper.AssetAccreditMapper;
import com.muyu.etl.domain.AssetAccredit;
import com.muyu.etl.service.IAssetAccreditService;
/**
* Service
*
* @author ruoyi
* @date 2024-04-25
*/
@Service
public class AssetAccreditServiceImpl implements IAssetAccreditService
{
@Autowired
private AssetAccreditMapper assetAccreditMapper;
/**
*
*
* @param id
* @return
*/
@Override
public AssetAccredit selectAssetAccreditById(Long id)
{
return assetAccreditMapper.selectAssetAccreditById(id);
}
/**
*
*
* @param assetAccredit
* @return
*/
@Override
public List<AssetAccredit> selectAssetAccreditList(AssetAccredit assetAccredit)
{
return assetAccreditMapper.selectAssetAccreditList(assetAccredit);
}
/**
*
*
* @param assetAccreditReq
* @return
*/
@Override
public Result insertAssetAccredit(AssetAccreditReq assetAccreditReq)
{
deleteAssetAccreditByAssetIds(assetAccreditReq);
List<AssetAccredit> assetAccredits = new ArrayList<>();
if (assetAccreditReq.getUserId() != null){
AssetAccredit assetAccredit = new AssetAccredit();
assetAccredit.setDataAssetId(assetAccreditReq.getDataAssetId());
assetAccredit.setUserId(assetAccreditReq.getUserId());
assetAccredit.setCreateBy(SecurityUtils.getUsername());
assetAccredit.setCreateTime(new Date());
assetAccredits.add(assetAccredit);
}else{
assetAccredits=assetAccreditReq.getDeptIds().stream().map(deptId -> {
AssetAccredit assetAccredit = new AssetAccredit();
assetAccredit.setDataAssetId(assetAccreditReq.getDataAssetId());
assetAccredit.setDeptId(deptId);
assetAccredit.setCreateBy(SecurityUtils.getUsername());
assetAccredit.setCreateTime(new Date());
return assetAccredit;
}).toList();
}
assetAccreditMapper.insertBatchAssetAccredit(assetAccredits);
return Result.success();
}
/**
*
*
* @param assetAccredit
* @return
*/
@Override
public int updateAssetAccredit(AssetAccredit assetAccredit)
{
assetAccredit.setUpdateTime(DateUtils.getNowDate());
return assetAccreditMapper.updateAssetAccredit(assetAccredit);
}
/**
*
*
* @param ids
* @return
*/
@Override
public int deleteAssetAccreditByIds(Long[] ids)
{
return assetAccreditMapper.deleteAssetAccreditByIds(ids);
}
/**
*
*
* @param id
* @return
*/
@Override
public int deleteAssetAccreditById(Long id)
{
return assetAccreditMapper.deleteAssetAccreditById(id);
}
@Override
public Result getAssetAccreditByDataAssetId(Long id) {
List<AssetAccredit> assetAccreditList = assetAccreditMapper.getAssetAccreditByDataAssetId(id);
List<Long> userAccreditIds = assetAccreditList.stream().map(AssetAccredit::getUserId).filter(Objects::nonNull).toList();
List<Long> deptAccreditIds = assetAccreditList.stream().map(AssetAccredit::getDeptId).filter(Objects::nonNull).toList();
AccreditModel accreditModel = new AccreditModel();
accreditModel.setDeptAccreditModelIds(deptAccreditIds);
accreditModel.setUserAccreditModelIds(userAccreditIds);
return Result.success(accreditModel);
}
@Override
public Result deleteAssetAccreditByAssetIds(AssetAccreditReq assetAccreditReq) {
if (assetAccreditReq.getUserId() != null){
assetAccreditMapper.deleteAssetAccreditByDeptUser(null,assetAccreditReq.getUserId(),assetAccreditReq.getDataAssetId());
}else{
assetAccreditMapper.deleteAssetAccreditByDeptUser(assetAccreditReq.getDeptIds(),null,assetAccreditReq.getDataAssetId());
}
return null;
}
}

View File

@ -3,10 +3,13 @@ package com.muyu.etl.service.impl;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.util.stream.Stream;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.common.system.domain.SysRole;
import com.muyu.etl.domain.*;
import com.muyu.etl.domain.Dictionary;
import com.muyu.etl.domain.custom.*;
@ -72,8 +75,23 @@ public class DataSourceServiceImpl implements IDataSourceService
@Override
public List<DataSource> selectDataSourceList(DataSource dataSource)
{
List<DataSource> dataSourceList = new ArrayList<DataSource>();
List<DataSource> dataSources = dataSourceMapper.selectDataSourceList(dataSource);
return dataSources;
List<SysRole> roles = SecurityUtils.getLoginUser().getSysUser().getRoles();
if (roles.get(0).getRoleId()==1){
dataSourceList = dataSources;
}else{
ArrayList<Long> longs1 = new ArrayList<>();
List<Long> sourceIds = sourceAccreditMapper.getSourceAccreditByUserId(SecurityUtils.getUserId()).stream().map(SourceAccredit::getDataSourceId).filter(Objects::nonNull).toList();
List<Long> assetIds = assetAccreditMapper.getAssetAccreditByUserId(SecurityUtils.getUserId()).stream().map(AssetAccredit::getDataAssetId).filter(Objects::nonNull).toList();
if (!assetIds.isEmpty()){
List<Long> longs = dataAssetMapper.getDataAssetByAssetId(assetIds).stream().map(DataAsset::getDataSourceId).toList();
longs1.addAll(longs);
}
longs1.addAll(sourceIds);
dataSourceList = dataSources.stream().filter(dataSourceInfo -> longs1.contains(dataSourceInfo.getId())).toList();
}
return dataSourceList;
}
/**
@ -458,8 +476,16 @@ public class DataSourceServiceImpl implements IDataSourceService
public Result dataAssetList(DataSource dataSource) {
DataAsset dataAsset = new DataAsset();
dataAsset.setDataSourceId(dataSource.getId());
List<DataAsset> dataAssetList = new ArrayList<>();
List<DataAsset> dataAssets = dataAssetMapper.selectDataAssetList(dataAsset);
return Result.success(dataAssets);
List<SysRole> roles = SecurityUtils.getLoginUser().getSysUser().getRoles();
if (roles.get(0).getRoleId()==1){
dataAssetList = dataAssets;
}else{
List<Long> assetIds = assetAccreditMapper.getAssetAccreditByUserId(SecurityUtils.getUserId()).stream().map(AssetAccredit::getDataAssetId).filter(Objects::nonNull).toList();
dataAssetList = dataAssets.stream().filter(dataAssetInfo -> assetIds.contains(dataAssetInfo.getId())).toList();
}
return Result.success(dataAssetList);
}
@Override
@ -486,18 +512,45 @@ public class DataSourceServiceImpl implements IDataSourceService
@Override
public Result statistics() {
//查询所有数据源
List<DataSource> dataSourceList = new ArrayList<>();
List<DataSource> dataSources = dataSourceMapper.selectDataSourceList(new DataSource());
List<SysRole> roles = SecurityUtils.getLoginUser().getSysUser().getRoles();
List<Long> assetIds;
if (roles.get(0).getRoleId()==1){
assetIds = new ArrayList<>();
dataSourceList = dataSources;
}else{
ArrayList<Long> longs1 = new ArrayList<>();
List<Long> sourceIds = sourceAccreditMapper.getSourceAccreditByUserId(SecurityUtils.getUserId()).stream().map(SourceAccredit::getDataSourceId).filter(Objects::nonNull).toList();
assetIds = assetAccreditMapper.getAssetAccreditByUserId(SecurityUtils.getUserId()).stream().map(AssetAccredit::getDataAssetId).filter(Objects::nonNull).toList();
if (!assetIds.isEmpty()){
List<Long> longs = dataAssetMapper.getDataAssetByAssetId(assetIds).stream().map(DataAsset::getDataSourceId).toList();
longs1.addAll(longs);
}
longs1.addAll(sourceIds);
dataSourceList = dataSources.stream().filter(dataSourceInfo -> longs1.contains(dataSourceInfo.getId())).toList();
}
//获取所有数据源的主键
List<Long> longs = dataSources.stream().map(dataSource -> dataSource.getId()).toList();
List<DataAsset> dataAssetList=dataAssetMapper.selectDataAssetBatchId(longs);
List<Long> longs = dataSourceList.stream().map(dataSource -> dataSource.getId()).toList();
Statistics statistics = new Statistics();
statistics.setDataAsset(Long.valueOf(dataSources.size()));
long sum1;
long sum2=0;
sum1 = dataAssetList.stream().mapToLong(dataAsset -> Long.valueOf(dataAsset.getFields())).sum();
sum2 = dataAssetList.stream().mapToLong(dataAsset -> Long.valueOf(dataAsset.getTableCount())).sum();
statistics.setAssetModel(sum1);
statistics.setDataModel(sum2);
if (!longs.isEmpty()){
List<DataAsset> dataAssetList=dataAssetMapper.selectDataAssetBatchId(longs);
if (roles.get(0).getRoleId()!=1){
dataAssetList = dataAssetList.stream().filter(dataAsset -> assetIds.contains(dataAsset.getId())).toList();
}
statistics.setDataAsset(Long.valueOf(dataSourceList.size()));
long sum1;
long sum2=0;
sum1 = dataAssetList.stream().mapToLong(dataAsset -> Long.valueOf(dataAsset.getFields())).sum();
sum2 = dataAssetList.stream().mapToLong(dataAsset -> Long.valueOf(dataAsset.getTableCount())).sum();
statistics.setAssetModel(sum1);
statistics.setDataModel(sum2);
}else{
statistics.setAssetModel(0L);
statistics.setDataModel(0L);
}
return Result.success(statistics);
}
}

View File

@ -0,0 +1,147 @@
package com.muyu.etl.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.SysUser;
import com.muyu.etl.domain.model.AccreditModel;
import com.muyu.etl.domain.req.SourceAccreditReq;
import com.muyu.etl.feign.SysUserFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.muyu.etl.mapper.SourceAccreditMapper;
import com.muyu.etl.domain.SourceAccredit;
import com.muyu.etl.service.ISourceAccreditService;
/**
* Service
*
* @author ruoyi
* @date 2024-04-25
*/
@Service
public class SourceAccreditServiceImpl implements ISourceAccreditService
{
@Autowired
private SourceAccreditMapper sourceAccreditMapper;
/**
*
*
* @param id
* @return
*/
@Override
public SourceAccredit selectSourceAccreditById(Long id)
{
return sourceAccreditMapper.selectSourceAccreditById(id);
}
/**
*
*
* @param sourceAccredit
* @return
*/
@Override
public List<SourceAccredit> selectSourceAccreditList(SourceAccredit sourceAccredit)
{
return sourceAccreditMapper.selectSourceAccreditList(sourceAccredit);
}
/**
*
*
* @param sourceAccreditReq
* @return
*/
@Override
public Result insertSourceAccredit(SourceAccreditReq sourceAccreditReq)
{
deleteSourceAccreditBySourceIds(sourceAccreditReq);
List<SourceAccredit> sourceAccredits = new ArrayList<>();
if (sourceAccreditReq.getUserId() != null){
SourceAccredit sourceAccredit = new SourceAccredit();
sourceAccredit.setDataSourceId(sourceAccreditReq.getDataSourceId());
sourceAccredit.setUserId(sourceAccreditReq.getUserId());
sourceAccredit.setCreateBy(SecurityUtils.getUsername());
sourceAccredit.setCreateTime(new Date());
sourceAccredits.add(sourceAccredit);
}else{
sourceAccredits=sourceAccreditReq.getDeptIds().stream().map(deptId -> {
SourceAccredit sourceAccredit = new SourceAccredit();
sourceAccredit.setDataSourceId(sourceAccreditReq.getDataSourceId());
sourceAccredit.setDeptId(deptId);
sourceAccredit.setCreateBy(SecurityUtils.getUsername());
sourceAccredit.setCreateTime(new Date());
return sourceAccredit;
}).toList();
}
sourceAccreditMapper.insertBatchSourceAccredit(sourceAccredits);
return Result.success();
}
/**
*
*
* @param sourceAccredit
* @return
*/
@Override
public int updateSourceAccredit(SourceAccredit sourceAccredit)
{
sourceAccredit.setUpdateTime(DateUtils.getNowDate());
return sourceAccreditMapper.updateSourceAccredit(sourceAccredit);
}
/**
*
*
* @param ids
* @return
*/
@Override
public int deleteSourceAccreditByIds(Long[] ids)
{
return sourceAccreditMapper.deleteSourceAccreditByIds(ids);
}
/**
*
*
* @param id
* @return
*/
@Override
public int deleteSourceAccreditById(Long id)
{
return sourceAccreditMapper.deleteSourceAccreditById(id);
}
@Override
public Result getSourceAccreditByDataSourceId(Long id) {
List<SourceAccredit> sourceAccreditList = sourceAccreditMapper.getSourceAccreditByDataSourceId(id);
List<Long> userAccreditIds = sourceAccreditList.stream().map(SourceAccredit::getUserId).filter(Objects::nonNull).toList();
List<Long> deptAccreditIds = sourceAccreditList.stream().map(SourceAccredit::getDeptId).filter(Objects::nonNull).toList();
AccreditModel accreditModel = new AccreditModel();
accreditModel.setDeptAccreditModelIds(deptAccreditIds);
accreditModel.setUserAccreditModelIds(userAccreditIds);
return Result.success(accreditModel);
}
@Override
public Result deleteSourceAccreditBySourceIds(SourceAccreditReq sourceAccreditReq) {
if (sourceAccreditReq.getUserId() != null){
sourceAccreditMapper.deleteSourceAccreditByDeptUser(null,sourceAccreditReq.getUserId(),sourceAccreditReq.getDataSourceId());
}else{
sourceAccreditMapper.deleteSourceAccreditByDeptUser(sourceAccreditReq.getDeptIds(),null,sourceAccreditReq.getDataSourceId());
}
return Result.success();
}
}

View File

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.etl.mapper.AssetAccreditMapper">
<resultMap type="com.muyu.etl.domain.AssetAccredit" id="AssetAccreditResult">
<result property="id" column="id" />
<result property="deptId" column="dept_id" />
<result property="dataAssetId" column="data_asset_id" />
<result property="userId" column="user_id" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectAssetAccreditVo">
select id, dept_id, data_asset_id, user_id, remark, create_by, create_time, update_by, update_time from asset_accredit
</sql>
<select id="selectAssetAccreditList" parameterType="com.muyu.etl.domain.AssetAccredit" resultMap="AssetAccreditResult">
<include refid="selectAssetAccreditVo"/>
<where>
<if test="deptId != null "> and dept_id = #{deptId}</if>
<if test="dataAssetId != null "> and data_asset_id = #{dataAssetId}</if>
<if test="userId != null "> and user_id = #{userId}</if>
</where>
</select>
<select id="selectAssetAccreditById" parameterType="Long" resultMap="AssetAccreditResult">
<include refid="selectAssetAccreditVo"/>
where id = #{id}
</select>
<select id="getAssetAccreditByDataAssetId" resultType="com.muyu.etl.domain.AssetAccredit">
<include refid="selectAssetAccreditVo"></include>
<where>
and data_asset_id = #{id}
</where>
</select>
<select id="getAssetAccreditByUserId" resultType="com.muyu.etl.domain.AssetAccredit">
<include refid="selectAssetAccreditVo"></include>
<where>
and user_id = #{id}
</where>
</select>
<insert id="insertAssetAccredit" parameterType="com.muyu.etl.domain.AssetAccredit" useGeneratedKeys="true" keyProperty="id">
insert into asset_accredit
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deptId != null">dept_id,</if>
<if test="dataAssetId != null">data_asset_id,</if>
<if test="userId != null">user_id,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deptId != null">#{deptId},</if>
<if test="dataAssetId != null">#{dataAssetId},</if>
<if test="userId != null">#{userId},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<insert id="insertBatchAssetAccredit">
insert into asset_accredit
<trim prefix="(" suffix=")">
dept_id,
data_asset_id,
user_id,
create_by,
create_time
</trim>
values
<foreach collection="assetAccredits" item="assetAccredit" separator=",">
(
<if test="assetAccredit.deptId !=null">#{assetAccredit.deptId},</if>
<if test="assetAccredit.deptId ==null">null,</if>
#{assetAccredit.dataAssetId},
<if test="assetAccredit.userId !=null">#{assetAccredit.userId},</if>
<if test="assetAccredit.userId ==null">null,</if>
#{assetAccredit.createBy},
#{assetAccredit.createTime}
)
</foreach>
</insert>
<update id="updateAssetAccredit" parameterType="com.muyu.etl.domain.AssetAccredit">
update asset_accredit
<trim prefix="SET" suffixOverrides=",">
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="dataAssetId != null">data_asset_id = #{dataAssetId},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteAssetAccreditById" parameterType="Long">
delete from asset_accredit where id = #{id}
</delete>
<delete id="deleteAssetAccreditByIds" parameterType="String">
delete from asset_accredit where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="deleteAssetAccreditByAssetIds">
delete from asset_accredit where data_asset_id in
<foreach item="assetId" collection="assetIds" open="(" separator="," close=")">
#{assetId}
</foreach>
</delete>
<delete id="deleteAssetAccreditByDeptUser">
delete from asset_accredit where
data_asset_id = #{dataAssetId}
<if test="userId !=null">
and user_id = #{userId}
</if>
<if test="deptIds != null">
and dept_id in
<foreach item="deptId" collection="deptIds" open="(" separator="," close=")">
#{deptId}
</foreach>
</if>
</delete>
</mapper>

View File

@ -55,6 +55,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
)
</where>
</select>
<select id="getDataAssetByAssetId" resultType="com.muyu.etl.domain.DataAsset">
<include refid="selectDataAssetVo"></include>
<where>
and id in (
<foreach collection="assetIds" item="id" separator=",">
#{id}
</foreach>
)
</where>
</select>
<insert id="insertDataAsset" parameterType="com.muyu.etl.domain.DataAsset" useGeneratedKeys="true" keyProperty="id">
insert into data_asset

View File

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.etl.mapper.SourceAccreditMapper">
<resultMap type="com.muyu.etl.domain.SourceAccredit" id="SourceAccreditResult">
<result property="id" column="id" />
<result property="deptId" column="dept_id" />
<result property="dataSourceId" column="data_source_id" />
<result property="userId" column="user_id" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectSourceAccreditVo">
select id, dept_id, data_source_id, user_id, remark, create_by, create_time, update_by, update_time from source_accredit
</sql>
<select id="selectSourceAccreditList" parameterType="com.muyu.etl.domain.SourceAccredit" resultMap="SourceAccreditResult">
<include refid="selectSourceAccreditVo"/>
<where>
<if test="deptId != null "> and dept_id = #{deptId}</if>
<if test="dataSourceId != null "> and data_source_id = #{dataSourceId}</if>
<if test="userId != null "> and user_id = #{userId}</if>
</where>
</select>
<select id="selectSourceAccreditById" parameterType="Long" resultMap="SourceAccreditResult">
<include refid="selectSourceAccreditVo"/>
where id = #{id}
</select>
<select id="getSourceAccreditByDataSourceId" resultType="com.muyu.etl.domain.SourceAccredit">
<include refid="selectSourceAccreditVo"></include>
<where>
and data_source_id = #{id}
</where>
</select>
<select id="getSourceAccreditByUserId" resultType="com.muyu.etl.domain.SourceAccredit">
<include refid="selectSourceAccreditVo"></include>
<where>
and user_id = #{id}
</where>
</select>
<insert id="insertSourceAccredit" parameterType="com.muyu.etl.domain.SourceAccredit" useGeneratedKeys="true" keyProperty="id">
insert into source_accredit
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deptId != null">dept_id,</if>
<if test="dataSourceId != null">data_source_id,</if>
<if test="userId != null">user_id,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deptId != null">#{dept_id},</if>
<if test="dataSourceId != null">#{dataSourceId},</if>
<if test="userId != null">#{userId},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<insert id="insertBatchSourceAccredit">
insert into source_accredit
<trim prefix="(" suffix=")">
dept_id,
data_source_id,
user_id,
create_by,
create_time
</trim>
values
<foreach collection="sourceAccredits" item="sourceAccredit" separator=",">
(
<if test="sourceAccredit.deptId !=null">#{sourceAccredit.deptId},</if>
<if test="sourceAccredit.deptId ==null">null,</if>
#{sourceAccredit.dataSourceId},
<if test="sourceAccredit.userId !=null">#{sourceAccredit.userId},</if>
<if test="sourceAccredit.userId ==null">null,</if>
#{sourceAccredit.createBy},
#{sourceAccredit.createTime}
)
</foreach>
</insert>
<update id="updateSourceAccredit" parameterType="com.muyu.etl.domain.SourceAccredit">
update source_accredit
<trim prefix="SET" suffixOverrides=",">
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="dataSourceId != null">data_source_id = #{dataSourceId},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteSourceAccreditById" parameterType="Long">
delete from source_accredit where id = #{id}
</delete>
<delete id="deleteSourceAccreditByIds" parameterType="String">
delete from source_accredit where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="deleteSourceAccreditBySourceIds">
delete from source_accredit where data_source_id in
<foreach item="sourceId" collection="sourceIds" open="(" separator="," close=")">
#{sourceId}
</foreach>
</delete>
<delete id="deleteSourceAccreditByDeptUser">
delete from source_accredit where
data_source_id = #{dataSourceId}
<if test="userId !=null">
and user_id = #{userId}
</if>
<if test="deptIds != null">
and dept_id in
<foreach item="deptId" collection="deptIds" open="(" separator="," close=")">
#{deptId}
</foreach>
</if>
</delete>
</mapper>