资料中心
parent
18cf4b4469
commit
5c8f2bf8f7
|
|
@ -0,0 +1,83 @@
|
|||
package com.gunshi.project.ss.controller;
|
||||
|
||||
|
||||
import com.gunshi.core.result.R;
|
||||
import com.gunshi.project.ss.entity.so.DocCenterPageSo;
|
||||
import com.gunshi.project.ss.model.DocCenter;
|
||||
import com.gunshi.project.ss.model.FileAssociations;
|
||||
import com.gunshi.project.ss.service.DocCategoryService;
|
||||
import com.gunshi.project.ss.service.DocCenterService;
|
||||
import com.gunshi.project.ss.service.FileAssociationsService;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "资料中心")
|
||||
@RestController
|
||||
@RequestMapping(value = "/docCenter")
|
||||
public class DocCenterController extends AbstractCommonFileController {
|
||||
|
||||
@Autowired
|
||||
private DocCenterService docCenterService;
|
||||
|
||||
@Autowired
|
||||
private FileAssociationsService fileService;
|
||||
|
||||
|
||||
|
||||
@Operation(description = "分页查询")
|
||||
@PostMapping("/page")
|
||||
public R<Page<DocCenter>> pageInfo(@RequestBody DocCenterPageSo pageSo){
|
||||
Page<DocCenter> res = docCenterService.pageInfo(pageSo);
|
||||
// List<DocCenter> records = res.getRecords();
|
||||
// if(!records.isEmpty()){
|
||||
// for (DocCenter record : records) {
|
||||
// List<FileAssociations> files = fileService.getFiles(record.getBusinessName(), record.getId().toString());
|
||||
// record.setFiles(files);
|
||||
// }
|
||||
// }
|
||||
return R.ok(res);
|
||||
}
|
||||
|
||||
@Operation(description = "新增")
|
||||
@PostMapping("/insert")
|
||||
public DocCenter insert(@RequestBody DocCenter docCenter){
|
||||
boolean flag = docCenterService.saveData(docCenter);
|
||||
// if(flag){
|
||||
// fileService.saveFile(docCenter.getFiles(), docCenter.getBusinessName(), docCenter.getId().toString());
|
||||
// }
|
||||
return docCenter;
|
||||
}
|
||||
|
||||
@Operation(description = "删除")
|
||||
@GetMapping("/delete/{id}")
|
||||
public R<Boolean> delete(@PathVariable("id") Integer id){
|
||||
DocCenter center = docCenterService.deleteById(id);
|
||||
// if(center != null){
|
||||
// fileService.deleteFile(center.getBusinessName(), center.getId().toString());
|
||||
// }
|
||||
return R.ok(true);
|
||||
}
|
||||
|
||||
|
||||
@Operation(description = "修改")
|
||||
@PostMapping("/edit")
|
||||
public DocCenter edit(@RequestBody DocCenter docCenter){
|
||||
boolean flag = docCenterService.updateData(docCenter);
|
||||
// if(flag){
|
||||
// fileService.saveFile(docCenter.getFiles(), docCenter.getBusinessName(), docCenter.getId().toString());
|
||||
// }
|
||||
return docCenter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroupId() {
|
||||
return "doccenter";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.gunshi.project.ss.entity.so;
|
||||
|
||||
|
||||
import com.gunshi.db.dto.PageSo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "分页查询对象")
|
||||
public class DocCenterPageSo {
|
||||
|
||||
@NotNull(message = "分页参数不能为空")
|
||||
@Schema(description = "分页参数")
|
||||
private PageSo pageSo;
|
||||
|
||||
@Schema(description = "档案名称")
|
||||
private String docName;
|
||||
|
||||
@Schema(description = "档案密级 0公开 1秘密 2机密")
|
||||
private Integer secretLevel;
|
||||
|
||||
@Schema(description = "资料类别ID 只传三级")
|
||||
private Long docCategoryId;
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,47 @@ package com.gunshi.project.ss.mapper;
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.gunshi.project.ss.model.DocCategory;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DocCategoryMapper extends BaseMapper<DocCategory> {
|
||||
|
||||
|
||||
/**
|
||||
* 递归查询节点路径(MySQL 8.0+)
|
||||
* @param leafId 叶子节点ID
|
||||
* @return 从根节点到叶子节点的路径
|
||||
*/
|
||||
@Select("""
|
||||
WITH RECURSIVE category_path AS (
|
||||
SELECT
|
||||
id,
|
||||
category_name,
|
||||
parent_id,
|
||||
level,
|
||||
category_code,
|
||||
1 as depth,
|
||||
id::text as path_ids -- 使用 ::text 转换
|
||||
FROM doc_category
|
||||
WHERE id = #{leafId}
|
||||
UNION ALL
|
||||
SELECT
|
||||
c.id,
|
||||
c.category_name,
|
||||
c.parent_id,
|
||||
c.level,
|
||||
c.category_code,
|
||||
cp.depth + 1,
|
||||
c.id || '>' || cp.path_ids -- 使用 || 操作符
|
||||
FROM doc_category c
|
||||
INNER JOIN category_path cp ON c.id = cp.parent_id
|
||||
)
|
||||
SELECT id, category_name, parent_id, level, category_code, depth, path_ids
|
||||
FROM category_path
|
||||
ORDER BY depth DESC;
|
||||
""")
|
||||
List<DocCategory> findCategoryPathRecursive(@Param("leafId") Long docCategoryId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.gunshi.project.ss.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.gunshi.project.ss.model.DocCategory;
|
||||
import com.gunshi.project.ss.model.DocCenter;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface DocCenterMapper extends BaseMapper<DocCenter> {
|
||||
}
|
||||
|
|
@ -6,11 +6,14 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import com.gunshi.project.ss.common.validate.markers.Update;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -36,10 +39,11 @@ public class DocCenter {
|
|||
|
||||
@TableField("doc_category_id")
|
||||
@Schema(description = "资料类别id")
|
||||
private Integer docCategoryId;
|
||||
private Long docCategoryId;
|
||||
|
||||
@TableField("group_id")
|
||||
@Schema(description = "组id - 用于替换档案时")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long groupId;
|
||||
|
||||
@TableField("doc_number")
|
||||
|
|
@ -49,7 +53,7 @@ public class DocCenter {
|
|||
|
||||
@TableField("doc_version")
|
||||
@Schema(description = "档案版本")
|
||||
private Integer docVersion;
|
||||
private BigDecimal docVersion;
|
||||
|
||||
@TableField("create_time")
|
||||
@Schema(description = "创建时间")
|
||||
|
|
@ -90,6 +94,7 @@ public class DocCenter {
|
|||
private List<FileAssociations> files;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "操作日志列表")
|
||||
private List<DocOperateLog> logs;
|
||||
@Schema(description = "一级资料类别代码")
|
||||
private List<String> CategoryCodes;
|
||||
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.gunshi.project.ss.entity.vo.UserRoleVo;
|
||||
import com.gunshi.project.ss.mapper.DocCategoryMapper;
|
||||
import com.gunshi.project.ss.model.DocCategory;
|
||||
import com.gunshi.project.ss.model.DocCenter;
|
||||
import com.gunshi.project.ss.model.DocPermissionConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -29,6 +30,9 @@ public class DocCategoryService extends ServiceImpl<DocCategoryMapper, DocCatego
|
|||
@Autowired
|
||||
private DocPermissionConfigService docPermissionConfigService;
|
||||
|
||||
@Autowired
|
||||
private DocCenterService docCenterService;
|
||||
|
||||
|
||||
|
||||
public DocCategory tree() {
|
||||
|
|
@ -119,6 +123,7 @@ public class DocCategoryService extends ServiceImpl<DocCategoryMapper, DocCatego
|
|||
permissions.stream().forEach(item -> {item.setCategoryId(docCategory.getId());});
|
||||
docPermissionConfigService.saveBatch(permissions);
|
||||
//TODO 同步更新所有关联档案的档案号(这里不用该,我到时候直接递归查上来然后进行拼接即可)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -142,9 +147,23 @@ public class DocCategoryService extends ServiceImpl<DocCategoryMapper, DocCatego
|
|||
}
|
||||
}else{
|
||||
//TODO 三级类目,如果关联有档案,则无法删除
|
||||
Long count = docCenterService.lambdaQuery().eq(DocCenter::getDocCategoryId, id).count();
|
||||
if(count > 0){
|
||||
throw new IllegalArgumentException("对不起,该类目一下关联有档案,无法删除");
|
||||
}
|
||||
}
|
||||
docPermissionConfigService.deleteByDocCategoryId(docCategory.getId());
|
||||
this.baseMapper.deleteById(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据叶子节点,查询树的一整条路径
|
||||
* @param docCategoryId
|
||||
* @return
|
||||
*/
|
||||
public List<DocCategory> findCategoryPathRecursive(Long docCategoryId) {
|
||||
List<DocCategory> res = this.baseMapper.findCategoryPathRecursive(docCategoryId);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,177 @@
|
|||
package com.gunshi.project.ss.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.project.ss.entity.so.DocCenterPageSo;
|
||||
import com.gunshi.project.ss.mapper.DocCenterMapper;
|
||||
import com.gunshi.project.ss.model.DocCategory;
|
||||
import com.gunshi.project.ss.model.DocCenter;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class DocCenterService extends ServiceImpl<DocCenterMapper, DocCenter> {
|
||||
|
||||
@Autowired
|
||||
private DocCategoryService docCategoryService;
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
public Page<DocCenter> pageInfo(DocCenterPageSo pageSo){
|
||||
LambdaQueryWrapper<DocCenter> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DocCenter::getDocCategoryId,pageSo.getDocCategoryId());
|
||||
if(StringUtils.isNotEmpty(pageSo.getDocName())){
|
||||
queryWrapper.like(DocCenter::getDocName,pageSo.getDocName());
|
||||
}
|
||||
if(pageSo.getSecretLevel() != null){
|
||||
queryWrapper.eq(DocCenter::getSecretLevel,pageSo.getSecretLevel());
|
||||
}
|
||||
queryWrapper.orderByDesc(DocCenter::getCreateTime);
|
||||
Page<DocCenter> docCenterPage = this.baseMapper.selectPage(pageSo.getPageSo().toPage(), queryWrapper);
|
||||
for (DocCenter record : docCenterPage.getRecords()) {
|
||||
if(record.getUserId() != null){
|
||||
SysUser sysUser = sysUserMapper.selectUserById(record.getUserId());
|
||||
if(sysUser != null){
|
||||
record.setUserName(sysUser.getNickName());
|
||||
}
|
||||
}
|
||||
List<DocCategory> categoryPathRecursive = docCategoryService.findCategoryPathRecursive(record.getDocCategoryId());
|
||||
List<String> categoryCodes = new ArrayList<>();
|
||||
for (DocCategory docCategory : categoryPathRecursive) {
|
||||
categoryCodes.add(docCategory.getCategoryCode());
|
||||
}
|
||||
categoryCodes.add(record.getDocNumber());
|
||||
record.setCategoryCodes(categoryCodes);
|
||||
}
|
||||
return docCenterPage;
|
||||
}
|
||||
|
||||
public boolean saveData(DocCenter docCenter) {
|
||||
if(StringUtils.isBlank(docCenter.getBusinessName())){
|
||||
throw new IllegalArgumentException("请传业务名称");
|
||||
}
|
||||
Long count = lambdaQuery().eq(DocCenter::getDocCategoryId, docCenter.getDocCategoryId()).count();
|
||||
count++;
|
||||
// 将 count 转换为字符串,前面补0,保持至少4位数字
|
||||
String countStr = String.format("%04d", count);
|
||||
docCenter.setDocNumber(countStr);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
docCenter.setCreateTime(now);
|
||||
if(docCenter.getReplaceId() != null){
|
||||
//如果替换档案ID不为null,废弃原档案
|
||||
DocCenter one = lambdaQuery().eq(DocCenter::getId, docCenter.getReplaceId()).one();
|
||||
if(one == null){
|
||||
throw new IllegalArgumentException("对不起,被替换的档案ID不存在");
|
||||
}
|
||||
//获取同一组有多少个版本
|
||||
List<DocCenter> list = lambdaQuery().eq(DocCenter::getGroupId, one.getGroupId())
|
||||
.orderByDesc(DocCenter::getDocVersion)
|
||||
.list();
|
||||
//设置分组id
|
||||
docCenter.setGroupId(one.getGroupId());
|
||||
docCenter.setDocVersion(new BigDecimal(list.size()).add(BigDecimal.ONE));
|
||||
//设置状态为已废除
|
||||
one.setIsAbolish(1);
|
||||
//设置废止时间(为替换档案的新增时间)
|
||||
one.setAbolishTime(now);
|
||||
updateById(one);
|
||||
}else{
|
||||
docCenter.setGroupId(IdWorker.getId());
|
||||
docCenter.setDocVersion(BigDecimal.ONE);
|
||||
docCenter.setIsAbolish(0);
|
||||
docCenter.setAbolishTime(null);
|
||||
}
|
||||
boolean save = this.save(docCenter);
|
||||
return save;
|
||||
}
|
||||
|
||||
public DocCenter deleteById(Integer id) {
|
||||
DocCenter center = this.baseMapper.selectById(id);
|
||||
if(center == null) return null;
|
||||
//根据组id查询版本号比他大的数据,然后这些数据的版本全部降1
|
||||
List<DocCenter> versionGe = lambdaQuery().eq(DocCenter::getGroupId, center.getGroupId())
|
||||
.ge(DocCenter::getDocVersion,center.getDocVersion().add(BigDecimal.ONE))
|
||||
.orderByAsc(DocCenter::getDocVersion)
|
||||
.list();
|
||||
for (DocCenter docCenter : versionGe) {
|
||||
docCenter.setDocVersion( docCenter.getDocVersion().subtract(BigDecimal.ONE) );
|
||||
}
|
||||
//如果删除的版本为第一版
|
||||
if(center.getDocVersion().compareTo(BigDecimal.ONE) == 0 && versionGe.size() > 0){
|
||||
//那么第二版的替换版本设置为空
|
||||
DocCenter second = versionGe.get(0);
|
||||
second.setReplaceId(null);
|
||||
}
|
||||
//查询版本比它小的数据
|
||||
List<DocCenter> versionLe = lambdaQuery().eq(DocCenter::getGroupId, center.getGroupId())
|
||||
.le(DocCenter::getDocVersion, center.getDocVersion().subtract(BigDecimal.ONE))
|
||||
.orderByDesc(DocCenter::getDocVersion).list();
|
||||
//如果是中间版本
|
||||
if(versionLe.size() > 0 && versionGe.size() > 0){
|
||||
//第一个必它大的版本
|
||||
DocCenter versionBig1 = versionGe.get(0);
|
||||
//第一个比它小的版本
|
||||
DocCenter versionSmall1 = versionLe.get(0);
|
||||
versionBig1.setReplaceId(versionSmall1.getId());
|
||||
} else if(versionLe.size() > 0){
|
||||
//如果删除的是最新的版本的数据
|
||||
DocCenter versionSmall1 = versionLe.get(0);
|
||||
versionSmall1.setIsAbolish(0);
|
||||
versionSmall1.setAbolishTime(null);
|
||||
}
|
||||
removeById(id);
|
||||
if(versionGe.size() > 0){
|
||||
updateBatchById(versionGe);
|
||||
}
|
||||
if(versionLe.size() > 0){
|
||||
updateBatchById(versionLe);
|
||||
}
|
||||
return center;
|
||||
}
|
||||
|
||||
public boolean updateData(DocCenter docCenter) {
|
||||
DocCenter one = lambdaQuery().eq(DocCenter::getId, docCenter.getId()).one();
|
||||
if(one == null){
|
||||
return false;
|
||||
}
|
||||
//获取替换id
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if(docCenter.getReplaceId() != null){
|
||||
//如果替换档案ID不为null,废弃原档案
|
||||
DocCenter replaceOne = lambdaQuery().eq(DocCenter::getId, docCenter.getReplaceId()).one();
|
||||
if(replaceOne == null){
|
||||
throw new IllegalArgumentException("对不起,被替换的档案ID不存在");
|
||||
}
|
||||
//获取同一组有多少个版本
|
||||
List<DocCenter> list = lambdaQuery().eq(DocCenter::getGroupId, replaceOne.getGroupId())
|
||||
.orderByDesc(DocCenter::getDocVersion)
|
||||
.list();
|
||||
//设置分组id
|
||||
docCenter.setGroupId(replaceOne.getGroupId());
|
||||
docCenter.setDocVersion(new BigDecimal(list.size()).add(BigDecimal.ONE));
|
||||
//设置状态为已废除
|
||||
replaceOne.setIsAbolish(1);
|
||||
//设置废止时间(为替换档案的新增时间)
|
||||
replaceOne.setAbolishTime(now);
|
||||
updateById(replaceOne);
|
||||
}
|
||||
boolean flag = updateById(docCenter);
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue