项目列表相关接口和应用资源与其他资源关联相关接口

This commit is contained in:
liyongbo2 2022-06-24 09:40:23 +08:00
parent b1ff894dae
commit 162e2ec97f
14 changed files with 636 additions and 21 deletions

View File

@ -46,9 +46,11 @@ public class TbProjectContribController {
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "projectName", value = "项目名称", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "resourceName", value = "应用名称", paramType = "query", dataType="String")
})
@RequiresPermissions("project:tbprojectcontrib:page")
// @RequiresPermissions("project:tbprojectcontrib:page")
public Result<PageData<TbProjectContribDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<TbProjectContribDTO> page = tbProjectContribService.page(params);
@ -57,7 +59,7 @@ public class TbProjectContribController {
@GetMapping("{id}")
@ApiOperation("信息")
@RequiresPermissions("project:tbprojectcontrib:info")
// @RequiresPermissions("project:tbprojectcontrib:info")
public Result<TbProjectContribDTO> get(@PathVariable("id") Long id){
TbProjectContribDTO data = tbProjectContribService.get(id);
@ -67,7 +69,7 @@ public class TbProjectContribController {
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@RequiresPermissions("project:tbprojectcontrib:save")
// @RequiresPermissions("project:tbprojectcontrib:save")
public Result save(@RequestBody TbProjectContribDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
@ -80,7 +82,7 @@ public class TbProjectContribController {
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@RequiresPermissions("project:tbprojectcontrib:update")
// @RequiresPermissions("project:tbprojectcontrib:update")
public Result update(@RequestBody TbProjectContribDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
@ -93,7 +95,7 @@ public class TbProjectContribController {
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@RequiresPermissions("project:tbprojectcontrib:delete")
// @RequiresPermissions("project:tbprojectcontrib:delete")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
@ -106,7 +108,7 @@ public class TbProjectContribController {
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@RequiresPermissions("project:tbprojectcontrib:export")
// @RequiresPermissions("project:tbprojectcontrib:export")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<TbProjectContribDTO> list = tbProjectContribService.list(params);

View File

@ -46,9 +46,13 @@ public class TbProjectController {
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "projectName", value = "项目名称", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "applyDep", value = "申请单位", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "respDep", value = "责任处室", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "applyTime", value = "申请日期", paramType = "query", dataType="String")
})
@RequiresPermissions("project:tbproject:page")
// @RequiresPermissions("project:tbproject:page")
public Result<PageData<TbProjectDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<TbProjectDTO> page = tbProjectService.page(params);
@ -57,7 +61,7 @@ public class TbProjectController {
@GetMapping("{id}")
@ApiOperation("信息")
@RequiresPermissions("project:tbproject:info")
// @RequiresPermissions("project:tbproject:info")
public Result<TbProjectDTO> get(@PathVariable("id") Long id){
TbProjectDTO data = tbProjectService.get(id);
@ -67,7 +71,7 @@ public class TbProjectController {
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@RequiresPermissions("project:tbproject:save")
// @RequiresPermissions("project:tbproject:save")
public Result save(@RequestBody TbProjectDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
@ -80,7 +84,7 @@ public class TbProjectController {
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@RequiresPermissions("project:tbproject:update")
// @RequiresPermissions("project:tbproject:update")
public Result update(@RequestBody TbProjectDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
@ -93,7 +97,7 @@ public class TbProjectController {
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@RequiresPermissions("project:tbproject:delete")
// @RequiresPermissions("project:tbproject:delete")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
@ -106,7 +110,7 @@ public class TbProjectController {
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@RequiresPermissions("project:tbproject:export")
// @RequiresPermissions("project:tbproject:export")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<TbProjectDTO> list = tbProjectService.list(params);

View File

@ -46,9 +46,11 @@ public class TbProjectUseController {
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "projectName", value = "项目名称", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "resourceName", value = "应用名称", paramType = "query", dataType="String")
})
@RequiresPermissions("project:tbprojectuse:page")
// @RequiresPermissions("project:tbprojectuse:page")
public Result<PageData<TbProjectUseDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<TbProjectUseDTO> page = tbProjectUseService.page(params);
@ -57,7 +59,7 @@ public class TbProjectUseController {
@GetMapping("{id}")
@ApiOperation("信息")
@RequiresPermissions("project:tbprojectuse:info")
// @RequiresPermissions("project:tbprojectuse:info")
public Result<TbProjectUseDTO> get(@PathVariable("id") Long id){
TbProjectUseDTO data = tbProjectUseService.get(id);
@ -67,7 +69,7 @@ public class TbProjectUseController {
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@RequiresPermissions("project:tbprojectuse:save")
// @RequiresPermissions("project:tbprojectuse:save")
public Result save(@RequestBody TbProjectUseDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
@ -80,7 +82,7 @@ public class TbProjectUseController {
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@RequiresPermissions("project:tbprojectuse:update")
// @RequiresPermissions("project:tbprojectuse:update")
public Result update(@RequestBody TbProjectUseDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
@ -93,7 +95,7 @@ public class TbProjectUseController {
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@RequiresPermissions("project:tbprojectuse:delete")
// @RequiresPermissions("project:tbprojectuse:delete")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
@ -106,7 +108,7 @@ public class TbProjectUseController {
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@RequiresPermissions("project:tbprojectuse:export")
// @RequiresPermissions("project:tbprojectuse:export")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<TbProjectUseDTO> list = tbProjectUseService.list(params);

View File

@ -26,6 +26,12 @@ public class TbProjectContribServiceImpl extends CrudServiceImpl<TbProjectContri
public QueryWrapper<TbProjectContribEntity> getWrapper(Map<String, Object> params){
QueryWrapper<TbProjectContribEntity> wrapper = new QueryWrapper<>();
if(params.containsKey("projectName") && StringUtils.isNotBlank(params.get("projectName").toString())){
wrapper.like("project_name",params.get("projectName"));
}
if(params.containsKey("resourceName") && StringUtils.isNotBlank(params.get("resourceName").toString())){
wrapper.like("resource_name",params.get("resourceName"));
}
return wrapper;
}

View File

@ -26,6 +26,18 @@ public class TbProjectServiceImpl extends CrudServiceImpl<TbProjectDao, TbProjec
public QueryWrapper<TbProjectEntity> getWrapper(Map<String, Object> params){
QueryWrapper<TbProjectEntity> wrapper = new QueryWrapper<>();
if(params.containsKey("projectName") && StringUtils.isNotBlank(params.get("projectName").toString())){
wrapper.like("project_name",params.get("projectName"));
}
if(params.containsKey("applyDep") && StringUtils.isNotBlank(params.get("applyDep").toString())){
wrapper.like("apply_dep",params.get("applyDep"));
}
if(params.containsKey("respDep") && StringUtils.isNotBlank(params.get("respDep").toString())){
wrapper.like("resp_dep",params.get("respDep"));
}
if(params.containsKey("applyTime") && StringUtils.isNotBlank(params.get("applyTime").toString())){
wrapper.apply("DATE_FORMAT(apply_time,'%Y-%m-%d') = {0}",params.get("applyTime").toString());
}
return wrapper;
}

View File

@ -26,6 +26,12 @@ public class TbProjectUseServiceImpl extends CrudServiceImpl<TbProjectUseDao, Tb
public QueryWrapper<TbProjectUseEntity> getWrapper(Map<String, Object> params){
QueryWrapper<TbProjectUseEntity> wrapper = new QueryWrapper<>();
if(params.containsKey("projectName") && StringUtils.isNotBlank(params.get("projectName").toString())){
wrapper.like("project_name",params.get("projectName"));
}
if(params.containsKey("resourceName") && StringUtils.isNotBlank(params.get("resourceName").toString())){
wrapper.like("resource_name",params.get("resourceName"));
}
return wrapper;
}

View File

@ -0,0 +1,146 @@
package io.renren.modules.resource.controller;
import com.alibaba.fastjson.JSONObject;
import io.renren.common.annotation.LogOperation;
import io.renren.common.constant.Constant;
import io.renren.common.page.PageData;
import io.renren.common.utils.ExcelUtils;
import io.renren.common.utils.Result;
import io.renren.common.validator.AssertUtils;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.DefaultGroup;
import io.renren.common.validator.group.UpdateGroup;
import io.renren.modules.resource.dto.TbDataResourceRelDTO;
import io.renren.modules.resource.excel.TbDataResourceRelExcel;
import io.renren.modules.resource.service.TbDataResourceRelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 组件-应用资源关系表
*
* @author Mark sunlightcs@gmail.com
* @since 3.0 2022-06-21
*/
@RestController
@RequestMapping("/dataResourceRel")
@Api(tags="组件-应用资源关系表")
public class TbDataResourceRelController {
@Autowired
private TbDataResourceRelService tbDataResourceRelService;
@GetMapping("/page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
})
// @RequiresPermissions("dataResourceRel:tbdataresourcerel:page")
public Result<PageData<TbDataResourceRelDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<TbDataResourceRelDTO> page = tbDataResourceRelService.page(params);
return new Result<PageData<TbDataResourceRelDTO>>().ok(page);
}
@GetMapping("/select/{id}")
@ApiOperation("信息")
// @RequiresPermissions("dataResourceRel:tbdataresourcerel:info")
public Result<TbDataResourceRelDTO> get(@PathVariable("id") Long id){
TbDataResourceRelDTO data = tbDataResourceRelService.get(id);
return new Result<TbDataResourceRelDTO>().ok(data);
}
@PostMapping("/insert")
@ApiOperation("保存")
@LogOperation("保存")
// @RequiresPermissions("dataResourceRel:tbdataresourcerel:save")
public Result save(@RequestBody TbDataResourceRelDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
tbDataResourceRelService.save(dto);
return new Result();
}
@PutMapping("/ubdate")
@ApiOperation("修改")
@LogOperation("修改")
// @RequiresPermissions("dataResourceRel:tbdataresourcerel:update")
public Result update(@RequestBody TbDataResourceRelDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
tbDataResourceRelService.update(dto);
return new Result();
}
@DeleteMapping("/delete")
@ApiOperation("删除")
@LogOperation("删除")
// @RequiresPermissions("dataResourceRel:tbdataresourcerel:delete")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
tbDataResourceRelService.delete(ids);
return new Result();
}
@GetMapping("/export")
@ApiOperation("导出")
@LogOperation("导出")
// @RequiresPermissions("dataResourceRel:tbdataresourcerel:export")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<TbDataResourceRelDTO> list = tbDataResourceRelService.list(params);
ExcelUtils.exportExcelToTarget(response, null, "组件-应用资源关系表", list, TbDataResourceRelExcel.class);
}
@GetMapping("/queryApplicationRelByResourceId")
@ApiOperation("根据资源id查询应用关联情况")
@LogOperation("根据资源id查询应用关联情况")
public Result queryApplicationRelByResourceId(@RequestParam("referenceId") Long referenceId,
@RequestParam(value = "keyName",required = false) String keyName){
Object data = tbDataResourceRelService.queryApplicationRelByResourceId(referenceId,keyName);
return new Result().ok(data);
}
@GetMapping("/queryResourceRelByKeyId")
@ApiOperation("根据应用id和资源类型查询资源管理情况")
@LogOperation("根据应用id和资源类型查询资源管理情况")
public Result queryResourceRelByKeyId(@RequestParam("keyId") Long keyId,
@RequestParam("type") String type,
@RequestParam(value = "referenceName" ,required = false) String referenceName){
Object data = tbDataResourceRelService.queryResourceRelByKeyId(keyId,type,referenceName);
return new Result().ok(data);
}
@PostMapping("/saveDataResourceRel")
@ApiOperation("保存应用与组件的关联关系")
@LogOperation("保存应用与组件的关联关系")
public Result saveDataResourceRel(@RequestBody JSONObject param){
Object data = tbDataResourceRelService.saveDataResourceRel(param);
return new Result().ok(data);
}
}

View File

@ -0,0 +1,36 @@
package io.renren.modules.resource.dao;
import io.renren.common.dao.BaseDao;
import io.renren.modules.resource.entity.TbDataResourceRelEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 组件-应用资源关系表
*
* @author Mark sunlightcs@gmail.com
* @since 3.0 2022-06-21
*/
@Mapper
public interface TbDataResourceRelDao extends BaseDao<TbDataResourceRelEntity> {
List<Map> getAlreadLinkedApplication(@Param("referenceId") Long referenceId,@Param("keyName") String keyName);
List<Map> getNotLinkedApplication(@Param("referenceId")Long referenceId,@Param("keyName") String keyName);
List<Map> getAlreadLinkedResource(@Param("keyId")Long keyId,@Param("type") String type,@Param("referenceName") String referenceName);
List<Map> getNotLinkedResource(@Param("keyId")Long keyId,@Param("type") String type,@Param("referenceName") String referenceName);
void deleteAllByKeyId(@Param("keyId")Long id, @Param("userId") Long userId,@Param("updateDate") Date updateDate);
void deleteAllByreferenceId(@Param("referenceId")Long id, @Param("userId")Long userId,@Param("updateDate")Date updateDate);
List<Map> getAlreadLinkedProject(@Param("keyId")Long keyId,@Param("projectName") String projectName);
List<Map> getNotLinkedProject(@Param("keyId")Long keyId,@Param("projectName") String projectName);
}

View File

@ -0,0 +1,44 @@
package io.renren.modules.resource.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 组件-应用资源关系表
*
* @author Mark sunlightcs@gmail.com
* @since 3.0 2022-06-21
*/
@Data
@ApiModel(value = "组件-应用资源关系表")
public class TbDataResourceRelDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "应用资源id")
private Long keyId;
@ApiModelProperty(value = "关联id")
private Long referenceId;
@ApiModelProperty(value = "删除标志0:正常1:已删除2:待审核3:审核中9其他")
private Integer delFlag;
@ApiModelProperty(value = "创建人")
private Long creator;
@ApiModelProperty(value = "创建时间")
private Date createDate;
@ApiModelProperty(value = "修改人")
private Long updater;
@ApiModelProperty(value = "修改时间")
private Date updateDate;
@ApiModelProperty(value = "id")
private Long id;
//新增展示字段
@ApiModelProperty(value = "应用资源名称")
private String keyName;
@ApiModelProperty(value = "关联资源名称")
private String referenceName;
}

View File

@ -0,0 +1,62 @@
package io.renren.modules.resource.entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.baomidou.mybatisplus.annotation.*;
import java.util.Date;
/**
* 组件-应用资源关系表
*
* @author Mark sunlightcs@gmail.com
* @since 3.0 2022-06-21
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("tb_data_resource_rel")
public class TbDataResourceRelEntity {
private static final long serialVersionUID = 1L;
/**
* 应用资源id
*/
private Long keyId;
/**
* 关联id
*/
private Long referenceId;
/**
* 删除标志
0:正常
1:已删除
2:待审核
3:审核中
9其他
*/
private Integer delFlag;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
private Long creator;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createDate;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updater;
/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
/**
* id
*/
@TableId
private Long id;
}

View File

@ -0,0 +1,37 @@
package io.renren.modules.resource.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;
import java.util.Date;
/**
* 组件-应用资源关系表
*
* @author Mark sunlightcs@gmail.com
* @since 3.0 2022-06-21
*/
@Data
@ContentRowHeight(20)
@HeadRowHeight(20)
@ColumnWidth(25)
public class TbDataResourceRelExcel {
@ExcelProperty(value = "应用资源id", index = 0)
private Long keyId;
@ExcelProperty(value = "关联id", index = 1)
private Long referenceId;
@ExcelProperty(value = "删除标志0:正常1:已删除2:待审核3:审核中9其他", index = 2)
private Integer delFlag;
@ExcelProperty(value = "创建人", index = 3)
private Long creator;
@ExcelProperty(value = "创建时间", index = 4)
private Date createDate;
@ExcelProperty(value = "修改人", index = 5)
private Long updater;
@ExcelProperty(value = "修改时间", index = 6)
private Date updateDate;
@ExcelProperty(value = "id", index = 7)
private Long id;
}

View File

@ -0,0 +1,23 @@
package io.renren.modules.resource.service;
import com.alibaba.fastjson.JSONObject;
import io.renren.common.service.CrudService;
import io.renren.modules.resource.dto.TbDataResourceRelDTO;
import io.renren.modules.resource.entity.TbDataResourceRelEntity;
import java.util.List;
/**
* 组件-应用资源关系表
*
* @author Mark sunlightcs@gmail.com
* @since 3.0 2022-06-21
*/
public interface TbDataResourceRelService extends CrudService<TbDataResourceRelEntity, TbDataResourceRelDTO> {
Object queryApplicationRelByResourceId(Long referenceId, String keyName);
Object queryResourceRelByKeyId(Long keyId, String type, String referenceName);
Object saveDataResourceRel(JSONObject param);
}

View File

@ -0,0 +1,129 @@
package io.renren.modules.resource.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.constant.Constant;
import io.renren.modules.resource.dao.TbDataResourceRelDao;
import io.renren.modules.resource.dto.TbDataResourceRelDTO;
import io.renren.modules.resource.entity.TbDataResourceRelEntity;
import io.renren.modules.resource.service.TbDataResourceRelService;
import io.renren.modules.security.user.SecurityUser;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* 组件-应用资源关系表
*
* @author Mark sunlightcs@gmail.com
* @since 3.0 2022-06-21
*/
@Service
public class TbDataResourceRelServiceImpl extends CrudServiceImpl<TbDataResourceRelDao, TbDataResourceRelEntity, TbDataResourceRelDTO> implements TbDataResourceRelService {
@Autowired
private TbDataResourceRelDao tbDataResourceRelDao;
@Override
public QueryWrapper<TbDataResourceRelEntity> getWrapper(Map<String, Object> params){
QueryWrapper<TbDataResourceRelEntity> wrapper = new QueryWrapper<>();
return wrapper;
}
@Override
public Object queryApplicationRelByResourceId(Long referenceId, String keyName) {
Map<String,Object> result = new HashMap<>();
//查询已关联的应用
List<Map> alreadLinked = tbDataResourceRelDao.getAlreadLinkedApplication(referenceId,keyName);
//查询未关联的应用
List<Map> notLinked = tbDataResourceRelDao.getNotLinkedApplication(referenceId,keyName);
result.put("alreadLinked",alreadLinked);
result.put("notLinked",notLinked);
return result;
}
@Override
public Object queryResourceRelByKeyId(Long keyId, String type, String referenceName) {
Map<String,Object> result = new HashMap<>();
//查询已关联的应用
List<Map> alreadLinked = new ArrayList<>();
//查询未关联的应用
List<Map> notLinked = new ArrayList<>();
switch (type){
case "项目":
alreadLinked = tbDataResourceRelDao.getAlreadLinkedProject(keyId,referenceName);
notLinked = tbDataResourceRelDao.getNotLinkedProject(keyId,referenceName);
break;
default:
alreadLinked = tbDataResourceRelDao.getAlreadLinkedResource(keyId,type,referenceName);
notLinked = tbDataResourceRelDao.getNotLinkedResource(keyId,type,referenceName);
break;
}
result.put("alreadLinked",alreadLinked);
result.put("notLinked",notLinked);
return result;
}
@Override
@Transactional
public Object saveDataResourceRel(JSONObject param) {
//关联类型1应用资源关联其他资源2其他资源关联应用资源
String linkType = param.getString("linkType");
Long id = param.getLong("id");
List<Long> referenceIds = JSONArray.parseArray(param.getString("referenceIds"),Long.class);
Long userId = SecurityUser.getUser().getId();
switch (linkType){
case "1":
//应用资源关联其他资源
//id为应用资源id即表中的key_idreferenceIds中为表中的reference_id
//先删除所有已关联的内容
tbDataResourceRelDao.deleteAllByKeyId(id,userId,new Date());
//新增关联关系
if(CollectionUtils.isNotEmpty(referenceIds)){
List<TbDataResourceRelEntity> resourceRels = new ArrayList<>();
for(Long referenceId:referenceIds){
TbDataResourceRelEntity resourceRel = new TbDataResourceRelEntity();
resourceRel.setKeyId(id);
resourceRel.setReferenceId(referenceId);
tbDataResourceRelDao.insert(resourceRel);
}
}
break;
case "2":
//其他资源关联应用资源
//id为其他资源id即表中的reference_idreferenceIds中为表中的key_id
//先删除所有已关联的内容
tbDataResourceRelDao.deleteAllByreferenceId(id,userId,new Date());
//新增关联关系
if(CollectionUtils.isNotEmpty(referenceIds)){
List<TbDataResourceRelEntity> resourceRels = new ArrayList<>();
for(Long referenceId:referenceIds){
TbDataResourceRelEntity resourceRel = new TbDataResourceRelEntity();
resourceRel.setKeyId(referenceId);
resourceRel.setReferenceId(id);
tbDataResourceRelDao.insert(resourceRel);
}
}
break;
default:
return "关联类型参数错误,请检查关联类型参数";
}
return null;
}
}

View File

@ -0,0 +1,106 @@
<?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="io.renren.modules.resource.dao.TbDataResourceRelDao">
<resultMap type="io.renren.modules.resource.entity.TbDataResourceRelEntity" id="tbDataResourceRelMap">
<result property="keyId" column="key_id"/>
<result property="referenceId" column="reference_id"/>
<result property="delFlag" column="del_flag"/>
<result property="creator" column="creator"/>
<result property="createDate" column="create_date"/>
<result property="updater" column="updater"/>
<result property="updateDate" column="update_date"/>
<result property="id" column="id"/>
</resultMap>
<select id="getAlreadLinkedApplication" resultType="java.util.Map">
SELECT
tdrr.key_id as id,
tdr.name
FROM tb_data_resource_rel tdrr
left join tb_data_resource tdr on tdrr.key_id = tdr.id
where tdrr.del_flag = 0 and tdr.del_flag = 0
and tdrr.reference_id = #{referenceId}
<if test="keyName != null and keyName != ''">
and tdr.name like CONCAT('%',#{keyName},'%')
</if>
</select>
<select id="getNotLinkedApplication" resultType="java.util.Map">
SELECT
id,
name
FROM tb_data_resource
where del_flag = 0 and type = '应用资源'
and id not in (SELECT key_id FROM tb_data_resource_rel where reference_id = #{referenceId})
<if test="keyName != null and keyName != ''">
and name like CONCAT('%',#{keyName},'%')
</if>
</select>
<select id="getAlreadLinkedResource" resultType="java.util.Map">
SELECT
tdrr.reference_id AS id,
tdr.name
FROM
tb_data_resource_rel tdrr
LEFT JOIN tb_data_resource tdr ON tdrr.reference_id = tdr.id
WHERE
tdrr.del_flag = 0
AND tdr.del_flag = 0
AND tdrr.key_id = #{keyId}
<if test="referenceName != null and referenceName != ''">
AND tdr.name LIKE CONCAT('%',#{referenceName},'%')
</if>
and tdr.type = #{type}
</select>
<select id="getNotLinkedResource" resultType="java.util.Map">
SELECT
id,
name
FROM tb_data_resource
where del_flag = 0 and type = #{type}
and id not in (SELECT reference_id FROM tb_data_resource_rel where key_id = #{keyId})
<if test="referenceName != null and referenceName != ''">
and name like CONCAT('%',#{referenceName},'%')
</if>
</select>
<update id="deleteAllByKeyId">
update tb_data_resource_rel set del_flag = 1,updater = #{userId},update_date = #{updateDate}
where key_id = #{keyId} and del_flag = 0
</update>
<update id="deleteAllByreferenceId">
update tb_data_resource_rel set del_flag = 1,updater = #{userId},update_date = #{updateDate}
where reference_id = #{referenceId} and del_flag = 0
</update>
<select id="getAlreadLinkedProject" resultType="java.util.Map">
SELECT
tdrr.reference_id AS id,
tp.project_name as name
FROM
tb_data_resource_rel tdrr
LEFT JOIN tb_project tp ON tdrr.reference_id = tp.id
WHERE tp.id is not null
and tdrr.del_flag = 0
AND tdrr.key_id = #{keyId}
<if test="projectName != null and projectName != ''">
AND tp.project_name LIKE CONCAT('%',#{projectName},'%')
</if>
</select>
<select id="getNotLinkedProject" resultType="java.util.Map">
SELECT
id,
project_name as name
FROM tb_project
where id not in (SELECT reference_id FROM tb_data_resource_rel where key_id = #{keyId})
<if test="projectName != null and projectName != ''">
and project_name like CONCAT('%',#{projectName},'%')
</if>
</select>
</mapper>