添加应用子库功能接口
parent
ec04dde752
commit
5e5a87e564
@ -0,0 +1,59 @@
|
||||
package com.supervision.knowsub.controller.system;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.supervision.knowsub.service.ApplicationSubLibraryService;
|
||||
import com.supervision.knowsub.vo.sublibrary.SubLibraryReqVo;
|
||||
import com.supervision.knowsub.vo.sublibrary.SubLibraryResVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* 应用子库管理
|
||||
*/
|
||||
@Tag(name = "应用子库管理")
|
||||
@RestController
|
||||
@RequestMapping("/applicationSubLibrary")
|
||||
@RequiredArgsConstructor
|
||||
public class ApplicationSubLibraryController {
|
||||
|
||||
|
||||
private final ApplicationSubLibraryService applicationSubLibraryService;
|
||||
|
||||
@Operation(summary = "增加应用子库")
|
||||
@PostMapping("/save")
|
||||
public String saveSubLibrary(@RequestBody SubLibraryReqVo subLibraryReqVo) {
|
||||
|
||||
return applicationSubLibraryService.saveSubLibrary(subLibraryReqVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改应用子库")
|
||||
@PostMapping("/update")
|
||||
public void updateSubLibrary(@RequestBody SubLibraryReqVo subLibraryReqVo) {
|
||||
|
||||
applicationSubLibraryService.updateSubLibrary(subLibraryReqVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除应用子库")
|
||||
@DeleteMapping("/delete")
|
||||
public Boolean deleteSubLibrary(@Parameter(name = "id") @RequestParam(name="id") String id) {
|
||||
|
||||
return applicationSubLibraryService.deleteSubLibrary(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询应用子库")
|
||||
@GetMapping("/list")
|
||||
public IPage<SubLibraryResVo> listSubLibrary(@Parameter(name = "baseName",description = "应用子库名") @RequestParam(required = false) String baseName,
|
||||
@Parameter(name = "baseCode",description = "应用库code") @RequestParam(required = false) String baseCode,
|
||||
@Parameter(name = "pageNum",description = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@Parameter(name = "pageSize",description = "每页大小") @RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
|
||||
SubLibraryReqVo subLibraryReqVo = new SubLibraryReqVo();
|
||||
subLibraryReqVo.setBaseCode(baseCode);
|
||||
subLibraryReqVo.setBaseName(baseName);
|
||||
return applicationSubLibraryService.listSubLibrary(subLibraryReqVo,pageNum,pageSize);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.supervision.knowsub.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.supervision.knowsub.vo.sublibrary.SubLibraryReqVo;
|
||||
import com.supervision.knowsub.vo.sublibrary.SubLibraryResVo;
|
||||
|
||||
|
||||
public interface ApplicationSubLibraryService {
|
||||
String saveSubLibrary(SubLibraryReqVo subLibraryReqVo);
|
||||
|
||||
void updateSubLibrary(SubLibraryReqVo subLibraryReqVo);
|
||||
|
||||
Boolean deleteSubLibrary(String id);
|
||||
|
||||
IPage<SubLibraryResVo> listSubLibrary(SubLibraryReqVo subLibraryReqVo,Integer pageNum,Integer pageSize);
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package com.supervision.knowsub.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.supervision.knowsub.model.SystemBase;
|
||||
import com.supervision.knowsub.model.SystemBaseDeptRelation;
|
||||
import com.supervision.knowsub.service.ApplicationSubLibraryService;
|
||||
import com.supervision.knowsub.service.SystemBaseDeptRelationService;
|
||||
import com.supervision.knowsub.service.SystemBaseService;
|
||||
import com.supervision.knowsub.vo.sublibrary.SubLibraryReqVo;
|
||||
import com.supervision.knowsub.vo.sublibrary.SubLibraryResVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ApplicationSubLibraryServiceImpl implements ApplicationSubLibraryService {
|
||||
|
||||
private final SystemBaseService systemBaseService;
|
||||
|
||||
|
||||
private final SystemBaseDeptRelationService systemBaseDeptRelationService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String saveSubLibrary(SubLibraryReqVo subLibraryReqVo) {
|
||||
|
||||
Assert.notEmpty(subLibraryReqVo.getBaseCode(), "子库编码不能为空");
|
||||
Assert.notEmpty(subLibraryReqVo.getBaseName(), "子库名称不能为空");
|
||||
Assert.notEmpty(subLibraryReqVo.getDeptIds(), "关联部门不能为空");
|
||||
|
||||
Long count = systemBaseService.lambdaQuery().eq(SystemBase::getBaseCode, subLibraryReqVo.getBaseCode()).count();
|
||||
Assert.isTrue(count == 0, "子库编码已存在");
|
||||
|
||||
// 保存应用子库信息
|
||||
SystemBase systemBase = new SystemBase();
|
||||
systemBase.setBaseCode(subLibraryReqVo.getBaseCode());
|
||||
systemBase.setBaseName(subLibraryReqVo.getBaseName());
|
||||
systemBaseService.save(systemBase);
|
||||
|
||||
// 保存应用子库管理部门信息
|
||||
systemBaseDeptRelationService.saveBatch(subLibraryReqVo.getDeptIds().stream().map(deptId -> {
|
||||
SystemBaseDeptRelation systemBaseDeptRelation = new SystemBaseDeptRelation();
|
||||
systemBaseDeptRelation.setBaseId(systemBase.getId());
|
||||
systemBaseDeptRelation.setDeptId(deptId);
|
||||
return systemBaseDeptRelation;
|
||||
}).toList());
|
||||
|
||||
return systemBase.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateSubLibrary(SubLibraryReqVo subLibraryReqVo) {
|
||||
|
||||
Assert.notEmpty(subLibraryReqVo.getBaseCode(), "子库编码不能为空");
|
||||
Assert.notEmpty(subLibraryReqVo.getBaseName(), "子库名称不能为空");
|
||||
Assert.notEmpty(subLibraryReqVo.getDeptIds(), "关联部门不能为空");
|
||||
|
||||
SystemBase dbSystemBase = systemBaseService.getById(subLibraryReqVo.getId());
|
||||
Assert.isTrue(Objects.nonNull(dbSystemBase), "子库不存在");
|
||||
if (!StrUtil.equals(dbSystemBase.getBaseCode(), subLibraryReqVo.getBaseCode())){
|
||||
// 子库编码修改
|
||||
Long count = systemBaseService.lambdaQuery().eq(SystemBase::getBaseCode, subLibraryReqVo.getBaseCode()).count();
|
||||
Assert.isTrue(count == 0, "子库编码已存在");
|
||||
}
|
||||
|
||||
|
||||
// 更新应用子库信息
|
||||
SystemBase systemBase = new SystemBase();
|
||||
systemBase.setId(subLibraryReqVo.getId());
|
||||
systemBase.setBaseName(subLibraryReqVo.getBaseName());
|
||||
systemBase.setBaseCode(subLibraryReqVo.getBaseCode());
|
||||
systemBaseService.updateById(systemBase);
|
||||
|
||||
// 更新应用子库管理部门信息(先删除再新增)
|
||||
systemBaseDeptRelationService.lambdaUpdate().eq(SystemBaseDeptRelation::getBaseId, systemBase.getId()).remove();
|
||||
systemBaseDeptRelationService.saveBatch(subLibraryReqVo.getDeptIds().stream().map(deptId -> {
|
||||
SystemBaseDeptRelation systemBaseDeptRelation = new SystemBaseDeptRelation();
|
||||
systemBaseDeptRelation.setBaseId(systemBase.getId());
|
||||
systemBaseDeptRelation.setDeptId(deptId);
|
||||
return systemBaseDeptRelation;
|
||||
}).toList());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deleteSubLibrary(String id) {
|
||||
Assert.notEmpty(id, "子库id不能为空");
|
||||
systemBaseService.removeById(id);
|
||||
systemBaseDeptRelationService.lambdaUpdate().eq(SystemBaseDeptRelation::getBaseId, id).remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<SubLibraryResVo> listSubLibrary(SubLibraryReqVo subLibraryReqVo,Integer pageNum,Integer pageSize) {
|
||||
|
||||
// todo: 部门名称 待补充
|
||||
return systemBaseService.listSubLibrary(subLibraryReqVo, pageNum, pageSize);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.supervision.knowsub.vo.sublibrary;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeptInfo {
|
||||
@Schema(description = "部门id")
|
||||
private String deptId;
|
||||
@Schema(description = "部门名称")
|
||||
private String deptName;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.supervision.knowsub.vo.sublibrary;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用子库
|
||||
*/
|
||||
@Data
|
||||
public class SubLibraryReqVo {
|
||||
|
||||
|
||||
@Schema(description = "子库id")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "子库名称")
|
||||
private String baseName;
|
||||
|
||||
@Schema(description = "子库编码")
|
||||
private String baseCode;
|
||||
|
||||
@Schema(description = "关联部门id")
|
||||
private List<String> deptIds;
|
||||
|
||||
}
|
Loading…
Reference in New Issue