From 683594b8a427f6fa9fe9547dc73ba9affb9c15c8 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Tue, 6 Jun 2023 20:01:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=96=99=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/handler/GlobalResponseHandler.java | 3 +- .../controller/DocumentationController.java | 44 ++++++++ .../filemanage/manage/DocumentationManage.java | 121 +++++++++++++++++++++ .../mapper/DocumentationGroupMapper.java | 16 +++ .../filemanage/mapper/DocumentationGroupMapper.xml | 5 + .../model/dto/DocumentationGroupSaveDTO.java | 22 ++++ .../filemanage/model/dto/DocumentationSaveDTO.java | 29 +++++ .../filemanage/model/entity/Documentation.java | 7 +- .../model/entity/DocumentationGroup.java | 4 +- .../filemanage/model/vo/DocumentationGroupVO.java | 33 ++++++ .../pmapi/filemanage/model/vo/DocumentationVO.java | 4 +- .../service/IDocumentationGroupService.java | 9 ++ .../impl/DocumentationGroupServiceImpl.java | 20 ++++ 13 files changed, 310 insertions(+), 7 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/filemanage/mapper/DocumentationGroupMapper.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/filemanage/mapper/DocumentationGroupMapper.xml create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/dto/DocumentationGroupSaveDTO.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/dto/DocumentationSaveDTO.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/vo/DocumentationGroupVO.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/filemanage/service/IDocumentationGroupService.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/filemanage/service/impl/DocumentationGroupServiceImpl.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/handler/GlobalResponseHandler.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/handler/GlobalResponseHandler.java index 66c5f0f..4bae14f 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/handler/GlobalResponseHandler.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/handler/GlobalResponseHandler.java @@ -27,7 +27,8 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; "com.ningdatech.pmapi.expert.controller", "com.ningdatech.pmapi.sms.controller", "com.ningdatech.pmapi.workbench.controller", - "com.ningdatech.pmapi.ding.controller" + "com.ningdatech.pmapi.ding.controller", + "com.ningdatech.pmapi.filemanage.controller" }) public class GlobalResponseHandler implements ResponseBodyAdvice { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/controller/DocumentationController.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/controller/DocumentationController.java index ff762d1..3bf7fa9 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/controller/DocumentationController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/controller/DocumentationController.java @@ -2,11 +2,17 @@ package com.ningdatech.pmapi.filemanage.controller; import com.ningdatech.basic.model.PageVo; import com.ningdatech.pmapi.filemanage.manage.DocumentationManage; +import com.ningdatech.pmapi.filemanage.model.dto.DocumentationGroupSaveDTO; +import com.ningdatech.pmapi.filemanage.model.dto.DocumentationSaveDTO; import com.ningdatech.pmapi.filemanage.model.param.DocumentationListParam; +import com.ningdatech.pmapi.filemanage.model.vo.DocumentationGroupVO; import com.ningdatech.pmapi.filemanage.model.vo.DocumentationVO; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.List; /** * @Classname DocumentationController @@ -18,12 +24,50 @@ import org.springframework.web.bind.annotation.*; @AllArgsConstructor @Api(tags = "档案管理-资料文档控制器") @RequestMapping("/api/v1/file-manage/documentation") +@Validated public class DocumentationController { private final DocumentationManage documentationManage; + @GetMapping("/group/list") + @ApiOperation(value = "分组列表", notes = "分组列表") + public List groupList(){ + return documentationManage.groupList(); + } + + @PostMapping("/group/add") + @ApiOperation(value = "分组添加", notes = "分组添加") + public String addGroup(@Validated @RequestBody DocumentationGroupSaveDTO dto){ + return documentationManage.addGroup(dto); + } + + @PostMapping("/group/delete/{id}") + @ApiOperation(value = "分组删除", notes = "分组删除") + public String deleteGroup(@PathVariable Long id){ + return documentationManage.deleteGroup(id); + } + @GetMapping("/list") + @ApiOperation(value = "文档列表", notes = "文档列表") public PageVo list(@ModelAttribute DocumentationListParam param){ return documentationManage.list(param); } + + @GetMapping("/detail/{id}") + @ApiOperation(value = "文档详情", notes = "文档详情") + public DocumentationVO detail(@PathVariable Long id){ + return documentationManage.detail(id); + } + + @PostMapping("/add") + @ApiOperation(value = "文档添加", notes = "文档添加") + public String addDoc(@Validated @RequestBody DocumentationSaveDTO dto){ + return documentationManage.addDoc(dto); + } + + @PostMapping("/delete/{id}") + @ApiOperation(value = "文档删除", notes = "文档删除") + public String deleteDoc(@PathVariable Long id){ + return documentationManage.deleteDoc(id); + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/manage/DocumentationManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/manage/DocumentationManage.java index fa9f83a..5b95a09 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/manage/DocumentationManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/manage/DocumentationManage.java @@ -3,15 +3,28 @@ package com.ningdatech.pmapi.filemanage.manage; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ningdatech.basic.exception.BizException; +import com.ningdatech.basic.function.VUtils; import com.ningdatech.basic.model.PageVo; +import com.ningdatech.file.entity.File; +import com.ningdatech.file.service.FileService; +import com.ningdatech.pmapi.filemanage.model.dto.DocumentationGroupSaveDTO; +import com.ningdatech.pmapi.filemanage.model.dto.DocumentationSaveDTO; import com.ningdatech.pmapi.filemanage.model.entity.Documentation; +import com.ningdatech.pmapi.filemanage.model.entity.DocumentationGroup; import com.ningdatech.pmapi.filemanage.model.param.DocumentationListParam; +import com.ningdatech.pmapi.filemanage.model.vo.DocumentationGroupVO; import com.ningdatech.pmapi.filemanage.model.vo.DocumentationVO; +import com.ningdatech.pmapi.filemanage.service.IDocumentationGroupService; import com.ningdatech.pmapi.filemanage.service.IDocumentationService; +import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; +import com.ningdatech.pmapi.user.util.LoginUserUtil; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -29,6 +42,20 @@ public class DocumentationManage { private final IDocumentationService documentationService; + private final IDocumentationGroupService documentationGroupService; + + private final FileService fileService; + + /** + * + * @return + */ + public List groupList() { + List list = documentationGroupService.list(); + + return list.stream().map(g -> BeanUtil.copyProperties(g,DocumentationGroupVO.class)).collect(Collectors.toList()); + } + /** * 文档列表 * @param param @@ -49,4 +76,98 @@ public class DocumentationManage { return PageVo.of(vos,page.getTotal()); } + + /** + * 增加分组 + * @param dto + * @return + */ + public String addGroup(DocumentationGroupSaveDTO dto) { + UserInfoDetails user = LoginUserUtil.loginUserDetail(); + if(documentationGroupService.count(Wrappers.lambdaQuery(DocumentationGroup.class) + .eq(DocumentationGroup::getName,dto.getName())) > 0){ + throw new BizException("此分组名 已经存在"); + } + + DocumentationGroup documentationGroup = BeanUtil.copyProperties(dto, DocumentationGroup.class); + documentationGroup.setCreateBy(user.getRealName()); + documentationGroup.setCreateOn(LocalDateTime.now()); + if(documentationGroupService.save(documentationGroup)){ + return "添加成功"; + } + return "添加失败"; + } + + /** + * 删除分组 同时删除文档 + * @param id + * @return + */ + @Transactional + public String deleteGroup(Long id) { + DocumentationGroup group = documentationGroupService.getById(id); + VUtils.isTrue(Objects.isNull(group)).throwMessage("该分组不存在!"); + + // + documentationService.remove(Wrappers.lambdaQuery(Documentation.class) + .eq(Documentation::getGroupId, id)); + documentationGroupService.removeById(id); + + return "删除成功"; + } + + /** + * 上传文档 + * @param dto + * @return + */ + public String addDoc(DocumentationSaveDTO dto) { + UserInfoDetails user = LoginUserUtil.loginUserDetail(); + + Long fileId = dto.getFileId(); + File file = fileService.getById(fileId); + + VUtils.isTrue(Objects.isNull(file)).throwMessage("该文件不存在!"); + + DocumentationGroup group = documentationGroupService.getById(dto.getGroupId()); + + VUtils.isTrue(Objects.isNull(group)).throwMessage("分组不存在!"); + + Documentation documentation = new Documentation(); + documentation.setCreateBy(user.getRealName()); + documentation.setCreateOn(LocalDateTime.now()); + documentation.setSize(Objects.nonNull(file.getSize()) ? file.getSize()/1000L : 0L); + documentation.setFileId(fileId); + documentation.setGroupId(dto.getGroupId()); + documentation.setFileName(file.getOriginalFileName()); + if(documentationService.save(documentation)){ + documentation.setSort(documentation.getId().intValue()); + documentationService.updateById(documentation); + } + + return "添加成功"; + } + + /** + * 删除文档 + * @param id + * @return + */ + public String deleteDoc(Long id) { + Documentation doc = documentationService.getById(id); + VUtils.isTrue(Objects.isNull(doc)).throwMessage("该文档不存在!"); + + if(documentationService.removeById(id)){ + return "删除成功"; + } + return "删除失败"; + } + + public DocumentationVO detail(Long id) { + Documentation doc = documentationService.getById(id); + if(Objects.isNull(doc)){ + return null; + } + return BeanUtil.copyProperties(doc,DocumentationVO.class); + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/mapper/DocumentationGroupMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/mapper/DocumentationGroupMapper.java new file mode 100644 index 0000000..bdf415e --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/mapper/DocumentationGroupMapper.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.filemanage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ningdatech.pmapi.filemanage.model.entity.DocumentationGroup; + +/** + *

+ * Mapper 接口 + *

+ * + * @author CMM + * @since 2023-02-27 + */ +public interface DocumentationGroupMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/mapper/DocumentationGroupMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/mapper/DocumentationGroupMapper.xml new file mode 100644 index 0000000..2d4547b --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/mapper/DocumentationGroupMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/dto/DocumentationGroupSaveDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/dto/DocumentationGroupSaveDTO.java new file mode 100644 index 0000000..e0763fa --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/dto/DocumentationGroupSaveDTO.java @@ -0,0 +1,22 @@ +package com.ningdatech.pmapi.filemanage.model.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @Classname Documentation + * @Description + * @Date 2023/6/6 14:41 + * @Author PoffyZhang + */ +@Data +@ApiModel(value = "DocumentationGroupSaveDTO", description = "DocumentationGroupSaveDTO") +public class DocumentationGroupSaveDTO { + + @ApiModelProperty("分组名") + private String name; + + @ApiModelProperty("排序") + private Integer sort; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/dto/DocumentationSaveDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/dto/DocumentationSaveDTO.java new file mode 100644 index 0000000..2f66359 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/dto/DocumentationSaveDTO.java @@ -0,0 +1,29 @@ +package com.ningdatech.pmapi.filemanage.model.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * @Classname Documentation + * @Description + * @Date 2023/6/6 14:41 + * @Author PoffyZhang + */ +@Data +@ApiModel(value = "DocumentationSaveDTO", description = "DocumentationSaveDTO") +public class DocumentationSaveDTO { + + @ApiModelProperty("文档分类ID") + @NotNull(message = "请传分组ID") + private Long groupId; + + @ApiModelProperty("文档ID") + @NotNull(message = "请传文档ID") + private Long fileId; + + @ApiModelProperty("排序") + private Integer sort; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/entity/Documentation.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/entity/Documentation.java index c837051..5162484 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/entity/Documentation.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/entity/Documentation.java @@ -28,10 +28,10 @@ public class Documentation { private String fileName; @ApiModelProperty("上传人") - private String creatBy; + private String createBy; @ApiModelProperty("上传时间") - private LocalDateTime creatOn; + private LocalDateTime createOn; @ApiModelProperty("文档大小 kb") private Long size; @@ -39,6 +39,9 @@ public class Documentation { @ApiModelProperty("文档分类ID") private Long groupId; + @ApiModelProperty("文档ID") + private Long fileId; + @ApiModelProperty("排序") private Integer sort; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/entity/DocumentationGroup.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/entity/DocumentationGroup.java index 466721f..f76cf45 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/entity/DocumentationGroup.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/entity/DocumentationGroup.java @@ -25,10 +25,10 @@ public class DocumentationGroup { private Long id; @ApiModelProperty("上传人") - private String creatBy; + private String createBy; @ApiModelProperty("上传时间") - private LocalDateTime creatOn; + private LocalDateTime createOn; @ApiModelProperty("分组名") private String name; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/vo/DocumentationGroupVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/vo/DocumentationGroupVO.java new file mode 100644 index 0000000..a46e229 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/vo/DocumentationGroupVO.java @@ -0,0 +1,33 @@ +package com.ningdatech.pmapi.filemanage.model.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * @Classname Documentation + * @Description + * @Date 2023/6/6 14:41 + * @Author PoffyZhang + */ +@Data +@ApiModel(value = "nd_documentation_group", description = "资料文档分组") +public class DocumentationGroupVO { + + @ApiModelProperty("主键") + private Long id; + + @ApiModelProperty("上传人") + private String createBy; + + @ApiModelProperty("上传时间") + private LocalDateTime createOn; + + @ApiModelProperty("分组名") + private String name; + + @ApiModelProperty("排序") + private Integer sort; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/vo/DocumentationVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/vo/DocumentationVO.java index 97d7a8b..1f21de0 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/vo/DocumentationVO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/model/vo/DocumentationVO.java @@ -23,10 +23,10 @@ public class DocumentationVO { private String fileName; @ApiModelProperty("上传人") - private String creatBy; + private String createBy; @ApiModelProperty("上传时间") - private LocalDateTime creatOn; + private LocalDateTime createOn; @ApiModelProperty("文档大小 kb") private Long size; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/service/IDocumentationGroupService.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/service/IDocumentationGroupService.java new file mode 100644 index 0000000..61a0786 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/service/IDocumentationGroupService.java @@ -0,0 +1,9 @@ +package com.ningdatech.pmapi.filemanage.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ningdatech.pmapi.filemanage.model.entity.DocumentationGroup; + +public interface IDocumentationGroupService extends IService { + + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/service/impl/DocumentationGroupServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/service/impl/DocumentationGroupServiceImpl.java new file mode 100644 index 0000000..35c59b6 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/filemanage/service/impl/DocumentationGroupServiceImpl.java @@ -0,0 +1,20 @@ +package com.ningdatech.pmapi.filemanage.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ningdatech.pmapi.filemanage.mapper.DocumentationGroupMapper; +import com.ningdatech.pmapi.filemanage.model.entity.DocumentationGroup; +import com.ningdatech.pmapi.filemanage.service.IDocumentationGroupService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author Poffy + * @since 2023-02-13 + */ +@Service +public class DocumentationGroupServiceImpl extends ServiceImpl implements IDocumentationGroupService { + +}