电子档案

This commit is contained in:
mashuai 2024-12-27 17:06:55 +08:00
parent b686d92f9d
commit eb3cc94fbb
14 changed files with 1122 additions and 2 deletions

View File

@ -0,0 +1,49 @@
package com.bonus.common.biz.config;
import com.bonus.common.biz.domain.FileInfo;
import java.io.*;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* 文件压缩工具类
* @Author ma_sh
* @create 2024/12/27 15:56
*/
public class FileCompressor {
/**
* 将多个文件压缩成ZIP文件
* @param files 要压缩的文件列表
* @param zipFilePath 目标ZIP文件路径
* @throws IOException
*/
public static void zipFiles(List<FileInfo> files, String zipFilePath) throws IOException {
try (FileOutputStream fos = new FileOutputStream(zipFilePath);
ZipOutputStream zipOut = new ZipOutputStream(fos)) {
// 遍历每个文件
for (FileInfo fileInfo : files) {
File file = new File(fileInfo.getFilePath());
// 确保文件存在
if (!file.exists()) {
throw new FileNotFoundException("File not found: " + fileInfo.getFilePath());
}
// 添加文件到ZIP
try (FileInputStream fis = new FileInputStream(file)) {
ZipEntry zipEntry = new ZipEntry(fileInfo.getFileName());
zipOut.putNextEntry(zipEntry);
// 将文件内容写入ZIP文件
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
}
zipOut.closeEntry();
}
}
}
}
}

View File

@ -0,0 +1,16 @@
package com.bonus.common.biz.domain;
import lombok.Data;
/**
* 文件信息
* @Author ma_sh
* @create 2024/12/27 15:56
*/
@Data
public class FileInfo {
private String fileName;
private String filePath;
}

View File

@ -29,6 +29,9 @@ public class LeaseApplyInfo extends BaseEntity{
/** ID */
private Long id;
@ApiModelProperty(value = "登录用户id")
private Long userId;
@ApiModelProperty(value = "申请时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "申请时间", width = 20, dateFormat = "yyyy-MM-dd HH:mm:ss")

View File

@ -0,0 +1,161 @@
package com.bonus.material.archives.controller;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.archives.domain.ArchivesDetails;
import com.bonus.material.archives.domain.ArchivesInfo;
import com.bonus.material.archives.domain.ArchivesVo;
import com.bonus.material.archives.service.ArchivesService;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 电子档案管理接口
* @Author ma_sh
* @create 2024/12/26 9:25
*/
@Api(tags = "电子档案管理接口")
@RestController
@RequestMapping("/archives")
public class ArchivesController extends BaseController {
@Resource
private ArchivesService archivesService;
/**
* 获取电子档案分类树
* @param archiveInfo
* @return
*/
@ApiOperation(value = "获取电子档案分类树")
//@PreventRepeatSubmit
//@RequiresPermissions("archives:type:list")
@GetMapping("/getTypeList")
public AjaxResult getTypeList(ArchivesInfo archiveInfo)
{
return archivesService.getTypeList(archiveInfo);
}
/**
* 获取电子档案详情信息
* @param archivesDetails
* @return
*/
@ApiOperation(value = "获取电子档案详情信息")
//@PreventRepeatSubmit
//@RequiresPermissions("archives:type:list")
@GetMapping("/getDetailsList")
public AjaxResult getDetailsList(ArchivesDetails archivesDetails)
{
startPage();
List<ArchivesDetails> list = archivesService.getDetailsList(archivesDetails);
return AjaxResult.success(getDataTable(list));
}
/**
* 新增电子档案分类树
* @param archiveInfo
* @return
*/
@ApiOperation(value = "新增电子档案分类树")
@PreventRepeatSubmit
//@RequiresPermissions("archives:type:add")
@PostMapping("/add")
public AjaxResult add(@RequestBody ArchivesInfo archiveInfo)
{
return archivesService.add(archiveInfo);
}
/**
* 新增电子档案右侧类型
* @param archivesVo
* @return
*/
@ApiOperation(value = "新增电子档案右侧类型")
@PreventRepeatSubmit
//@RequiresPermissions("archives:type:add")
@PostMapping("/addDetails")
public AjaxResult addDetails(@RequestBody ArchivesVo archivesVo)
{
return archivesService.addDetails(archivesVo);
}
/**
* 修改电子档案分类树
* @param archiveInfo
* @return
*/
@ApiOperation(value = "修改电子档案分类树")
@PreventRepeatSubmit
//@RequiresPermissions("archives:type:update")
@PostMapping("/update")
public AjaxResult update(@RequestBody ArchivesInfo archiveInfo)
{
return archivesService.edit(archiveInfo);
}
/**
* 修改电子档案右侧详情
* @param archivesDetails
* @return
*/
@ApiOperation(value = "修改电子档案右侧详情")
@PreventRepeatSubmit
//@RequiresPermissions("archives:type:update")
@PostMapping("/updateDetails")
public AjaxResult updateDetails(@RequestBody ArchivesDetails archivesDetails)
{
return archivesService.updateDetails(archivesDetails);
}
/**
* 删除电子档案分类树
* @param archiveInfo
* @return
*/
@ApiOperation(value = "删除电子档案分类树")
@PreventRepeatSubmit
//@RequiresPermissions("archives:type:delete")
@PostMapping("/deleteById")
public AjaxResult deleteById(@RequestBody ArchivesInfo archiveInfo)
{
return archivesService.deleteById(archiveInfo);
}
/**
* 删除电子档案右侧详情
* @param archivesVo
* @return
*/
@ApiOperation(value = "删除电子档案右侧详情")
@PreventRepeatSubmit
//@RequiresPermissions("archives:type:delete")
@PostMapping("/deleteByDetails")
public AjaxResult deleteByDetails(@RequestBody ArchivesVo archivesVo)
{
return archivesService.deleteByDetails(archivesVo);
}
/**
* 下载电子档案右侧详情
* @param archivesVo
* @return
*/
@ApiOperation(value = "下载电子档案右侧详情")
@PreventRepeatSubmit
//@RequiresPermissions("archives:type:download")
@PostMapping("/download")
public void download(@RequestBody ArchivesVo archivesVo, HttpServletRequest request, HttpServletResponse response)
{
archivesService.download(archivesVo, request, response);
}
}

View File

@ -0,0 +1,60 @@
package com.bonus.material.archives.domain;
import com.bonus.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 档案详情表
* @Author ma_sh
* @create 2024/12/26 13:49
*/
@Data
public class ArchivesDetails extends BaseEntity {
@ApiModelProperty(value = "id")
private Long detailsId;
@ApiModelProperty(value = "档案分类id")
private Long infoId;
@ApiModelProperty(value = "父级id")
private Long parentId;
@ApiModelProperty(value = "层级")
private String level;
@ApiModelProperty(value = "文档名称")
private String docName;
@ApiModelProperty(value = "文档类型")
private String docType;
@ApiModelProperty(value = "文档地址")
private String docUrl;
@ApiModelProperty(value = "文档大小")
private String docSize;
@ApiModelProperty(value = "年度")
@JsonFormat(pattern = "yyyy")
private Date year;
@ApiModelProperty(value = "机具类型id")
private Long typeId;
@ApiModelProperty(value = "删除标志0代表存在 1代表删除")
private String delFlag;
@ApiModelProperty(value = "关键字")
private String keyWord;
@ApiModelProperty(value="开始时间")
private String startTime;
@ApiModelProperty(value="结束时间")
private String endTime;
}

View File

@ -0,0 +1,29 @@
package com.bonus.material.archives.domain;
import com.bonus.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 档案分类表
* @Author ma_sh
* @create 2024/12/26 9:29
*/
@Data
public class ArchivesInfo extends BaseEntity {
@ApiModelProperty(value = "infoId")
private Long infoId;
@ApiModelProperty(value = "档案名称")
private String archivesName;
@ApiModelProperty(value = "父级id")
private Long parentId;
@ApiModelProperty(value = "层级")
private String level;
@ApiModelProperty(value = "关键字")
private String keyWord;
}

View File

@ -0,0 +1,20 @@
package com.bonus.material.archives.domain;
import lombok.Data;
import java.util.List;
/**
*
* @Author ma_sh
* @create 2024/12/27 14:05
*/
@Data
public class ArchivesVo {
private ArchivesDetails archivesDetails;
private List<ArchivesDetails> archivesDetailsList;
private List<Long> detailsIdList;
}

View File

@ -0,0 +1,99 @@
package com.bonus.material.archives.mapper;
import com.bonus.common.biz.domain.TreeNode;
import com.bonus.material.archives.domain.ArchivesDetails;
import com.bonus.material.archives.domain.ArchivesInfo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Author ma_sh
* @create 2024/12/26 9:27
*/
public interface ArchivesMapper {
/**
* 获取电子档案分类树
* @param archiveInfo
* @return
*/
List<TreeNode> getTypeList(ArchivesInfo archiveInfo);
/**
* 根据名称查询电子档案分类
* @param archiveInfo
* @return
*/
ArchivesInfo selectByName(ArchivesInfo archiveInfo);
/**
* 新增电子档案分类
* @param archiveInfo
* @return
*/
int insertInfo(ArchivesInfo archiveInfo);
/**
* 修改电子档案分类
* @param archiveInfo
* @return
*/
int updateInfo(ArchivesInfo archiveInfo);
/**
* 根据id查询电子档案分类
* @param archiveInfo
* @return
*/
List<ArchivesInfo> getListById(ArchivesInfo archiveInfo);
/**
* 删除电子档案分类
* @param archiveInfo
* @return
*/
int deleteInfo(ArchivesInfo archiveInfo);
/**
* 获取电子档案详情
* @param archivesDetails
* @return
*/
List<ArchivesDetails> selectDetailsList(ArchivesDetails archivesDetails);
/**
* 根据名称查询电子档案详情
* @param archivesDetails
* @return
*/
ArchivesDetails selectDetailsByName(ArchivesDetails archivesDetails);
/**
* 新增电子档案详情
* @param archivesDetails
* @return
*/
int insertDetails(ArchivesDetails archivesDetails);
/**
* 修改电子档案右侧类型
* @param archivesDetails
* @return
*/
int updateDetails(ArchivesDetails archivesDetails);
/**
* 删除电子档案右侧类型
* @param archivesDetails
* @return
*/
int deleteDetails(ArchivesDetails archivesDetails);
/**
* 下载电子档案右侧详情
* @param detailsIdList
* @return
*/
List<ArchivesDetails> selectDetails(@Param("list") List<Long> detailsIdList);
}

View File

@ -0,0 +1,84 @@
package com.bonus.material.archives.service;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.archives.domain.ArchivesDetails;
import com.bonus.material.archives.domain.ArchivesInfo;
import com.bonus.material.archives.domain.ArchivesVo;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 电子档案管理Service接口
* @Author ma_sh
* @create 2024/12/26 9:25
*/
public interface ArchivesService {
/**
* 获取电子档案分类树
* @param archiveInfo
* @return
*/
AjaxResult getTypeList(ArchivesInfo archiveInfo);
/**
* 新增电子档案分类树
* @param archiveInfo
* @return
*/
AjaxResult add(ArchivesInfo archiveInfo);
/**
* 修改电子档案分类树
* @param archiveInfo
* @return
*/
AjaxResult edit(ArchivesInfo archiveInfo);
/**
* 删除电子档案分类树
* @param archiveInfo
* @return
*/
AjaxResult deleteById(ArchivesInfo archiveInfo);
/**
* 获取电子档案详情信息
* @param archivesDetails
* @return
*/
List<ArchivesDetails> getDetailsList(ArchivesDetails archivesDetails);
/**
* 新增电子档案右侧类型
* @param archivesVo
* @return
*/
AjaxResult addDetails(ArchivesVo archivesVo);
/**
* 修改电子档案右侧详情
* @param archivesDetails
* @return
*/
AjaxResult updateDetails(ArchivesDetails archivesDetails);
/**
* 删除电子档案右侧详情
* @param archivesVo
* @return
*/
AjaxResult deleteByDetails(ArchivesVo archivesVo);
/**
* 下载电子档案右侧详情
* @param archivesVo
*
* @param request
* @param response
* @return
*/
void download(ArchivesVo archivesVo, HttpServletRequest request, HttpServletResponse response);
}

View File

@ -0,0 +1,375 @@
package com.bonus.material.archives.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.bonus.common.biz.config.FileCompressor;
import com.bonus.common.biz.domain.FileInfo;
import com.bonus.common.biz.domain.TreeBuild;
import com.bonus.common.biz.domain.TreeNode;
import com.bonus.common.biz.enums.HttpCodeEnum;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.archives.domain.ArchivesDetails;
import com.bonus.material.archives.domain.ArchivesInfo;
import com.bonus.material.archives.domain.ArchivesVo;
import com.bonus.material.archives.mapper.ArchivesMapper;
import com.bonus.material.archives.service.ArchivesService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* 电子档案管理接口实现类
* @Author ma_sh
* @create 2024/12/26 9:26
*/
@Service
@Slf4j
public class ArchivesServiceImpl implements ArchivesService {
@Resource
private ArchivesMapper archivesMapper;
/**
* 获取电子档案分类树
* @param archiveInfo
* @return
*/
@Override
public AjaxResult getTypeList(ArchivesInfo archiveInfo) {
List<TreeNode> groupList = new ArrayList<>();
List<TreeNode> list = new ArrayList<>();
try {
list = archivesMapper.getTypeList(archiveInfo);
if (CollectionUtils.isNotEmpty(list)) {
// 创建树形结构数据集合作为参数
TreeBuild treeBuild = new TreeBuild(list);
// 原查询结果转换树形结构
groupList = treeBuild.buildTree();
}
} catch (Exception e) {
log.error("电子档案分类树-查询失败", e);
}
return AjaxResult.success(groupList);
}
/**
* 新增电子档案分类
* @param archiveInfo
* @return
*/
@Override
public AjaxResult add(ArchivesInfo archiveInfo) {
// 根据类型名称和上级id查询同级下名称不能重复
archiveInfo.setParentId(archiveInfo.getInfoId() != null ? archiveInfo.getInfoId() : 0L);
ArchivesInfo info = archivesMapper.selectByName(archiveInfo);
if (info != null) {
return AjaxResult.error(HttpCodeEnum.NAME_DUPLICATE.getCode(), HttpCodeEnum.NAME_DUPLICATE.getMsg());
}
archiveInfo.setCreateTime(DateUtils.getNowDate());
archiveInfo.setCreateBy(SecurityUtils.getUsername());
archiveInfo.setParentId(archiveInfo.getInfoId() != null ? archiveInfo.getInfoId() : 0L);
archiveInfo.setLevel((StringUtils.isNotBlank(archiveInfo.getLevel())) ? String.valueOf(Integer.parseInt(archiveInfo.getLevel()) + 1) : "1");
int result = archivesMapper.insertInfo(archiveInfo);
if (result > 0) {
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
}
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
/**
* 修改电子档案分类树
* @param archiveInfo
* @return
*/
@Override
public AjaxResult edit(ArchivesInfo archiveInfo) {
// 根据类型名称和上级id查询同级下名称不能重复
archiveInfo.setParentId(archiveInfo.getInfoId() != null ? archiveInfo.getInfoId() : 0L);
ArchivesInfo info = archivesMapper.selectByName(archiveInfo);
if (info != null && !archiveInfo.getInfoId().equals(info.getInfoId())) {
return AjaxResult.error(HttpCodeEnum.NAME_DUPLICATE.getCode(), HttpCodeEnum.NAME_DUPLICATE.getMsg());
}
archiveInfo.setUpdateTime(DateUtils.getNowDate());
archiveInfo.setUpdateBy(SecurityUtils.getUsername());
int result = archivesMapper.updateInfo(archiveInfo);
if (result > 0) {
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
}
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
/**
* 删除电子档案分类树
* @param archiveInfo
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult deleteById(ArchivesInfo archiveInfo) {
// 根据id查询判断是否有子节点有则不能删除
List<ArchivesDetails> detailsList = new ArrayList<>();
List<ArchivesInfo> list = archivesMapper.getListById(archiveInfo);
if (CollectionUtil.isEmpty(list)) {
ArchivesDetails archivesDetails = new ArchivesDetails();
archivesDetails.setInfoId(archiveInfo.getInfoId());
detailsList = archivesMapper.selectDetailsList(archivesDetails);
}
if (CollectionUtils.isNotEmpty(list) || CollectionUtils.isNotEmpty(detailsList)) {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "该分类下有子分类,无法删除");
}
int result = archivesMapper.deleteInfo(archiveInfo);
if (result > 0) {
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
}
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
/**
* 获取电子档案详情信息
* @param archivesDetails
* @return
*/
@Override
public List<ArchivesDetails> getDetailsList(ArchivesDetails archivesDetails) {
return archivesMapper.selectDetailsList(archivesDetails);
}
/**
* 新增电子档案右侧类型
* @param archivesVo
* @return
*/
@Override
public AjaxResult addDetails(ArchivesVo archivesVo) {
// 根据类型名称和上级id查询同级下名称不能重复
int result = 0;
// 如果只有单条数据
if (archivesVo.getArchivesDetails() != null) {
ArchivesDetails archivesDetails = archivesVo.getArchivesDetails();
if (isNameDuplicate(archivesDetails)) {
return AjaxResult.error(HttpCodeEnum.NAME_DUPLICATE.getCode(), HttpCodeEnum.NAME_DUPLICATE.getMsg());
}
prepareArchivesDetails(archivesDetails);
archivesDetails.setDocType("文件夹");
result = archivesMapper.insertDetails(archivesDetails);
// 如果插入成功返回成功响应
if (result > 0) {
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
}
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
// 如果有多条数据
if (CollectionUtils.isNotEmpty(archivesVo.getArchivesDetailsList())) {
// 检查是否有重复名称
for (ArchivesDetails archivesDetails : archivesVo.getArchivesDetailsList()) {
if (isNameDuplicate(archivesDetails)) {
return AjaxResult.error(HttpCodeEnum.NAME_DUPLICATE.getCode(), HttpCodeEnum.NAME_DUPLICATE.getMsg());
}
}
// 插入所有不重复的档案详情
for (ArchivesDetails archivesDetails : archivesVo.getArchivesDetailsList()) {
prepareArchivesDetails(archivesDetails);
result += archivesMapper.insertDetails(archivesDetails);
}
}
// 根据插入结果返回响应
return result > 0
? AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result)
: AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
/**
* 处理通用逻辑
* @param archivesDetails
*/
private void prepareArchivesDetails(ArchivesDetails archivesDetails) {
archivesDetails.setCreateBy(SecurityUtils.getUsername());
archivesDetails.setCreateTime(DateUtils.getNowDate());
archivesDetails.setParentId(archivesDetails.getDetailsId() != null ? archivesDetails.getDetailsId() : 0L);
archivesDetails.setLevel(StringUtils.isNotBlank(archivesDetails.getLevel())
? String.valueOf(Integer.parseInt(archivesDetails.getLevel()) + 1)
: "1");
}
/**
* 检查档案名称是否重复
* @param archivesDetails
* @return
*/
private boolean isNameDuplicate(ArchivesDetails archivesDetails) {
ArchivesDetails info = archivesMapper.selectDetailsByName(archivesDetails);
return info != null;
}
/**
* 修改电子档案右侧类型
* @param archivesDetails
* @return
*/
@Override
public AjaxResult updateDetails(ArchivesDetails archivesDetails) {
// 根据类型名称和上级id查询同级下名称不能重复
ArchivesDetails info = archivesMapper.selectDetailsByName(archivesDetails);
if (info != null && !archivesDetails.getDetailsId().equals(info.getDetailsId())) {
return AjaxResult.error(HttpCodeEnum.NAME_DUPLICATE.getCode(), HttpCodeEnum.NAME_DUPLICATE.getMsg());
}
archivesDetails.setUpdateBy(SecurityUtils.getUsername());
archivesDetails.setUpdateTime(DateUtils.getNowDate());
int result = archivesMapper.updateDetails(archivesDetails);
if (result > 0) {
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
}
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
/**
* 删除电子档案右侧类型
* @param archivesVo
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult deleteByDetails(ArchivesVo archivesVo) {
// 判断是否有子节点,有则不能删除
if (CollectionUtils.isNotEmpty(archivesVo.getArchivesDetailsList())) {
for (ArchivesDetails archivesDetails : archivesVo.getArchivesDetailsList()) {
List<ArchivesDetails> list = archivesMapper.selectDetailsList(archivesDetails);
if (CollectionUtils.isNotEmpty(list)) {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "该文件下有子文件,无法删除");
}
int result = archivesMapper.deleteDetails(archivesDetails);
if (result > 0) {
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
}
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
}
return AjaxResult.error(HttpCodeEnum.TO_PARAM_NULL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
}
/**
* 下载电子档案右侧详情
* @param archivesVo
* @return
*/
@Override
public void download(ArchivesVo archivesVo, HttpServletRequest request, HttpServletResponse response) {
try {
// 根据id查询详情
List<ArchivesDetails> list = archivesMapper.selectDetails(archivesVo.getDetailsIdList());
// 提取文件信息
List<FileInfo> fileInfos = extractFileInfos(list);
if (fileInfos.isEmpty()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "No files found to download.");
return;
}
// 创建临时ZIP文件路径
String zipFilePath = createTempZipFile(fileInfos);
// 设置响应头
setResponseHeaders(response);
// 将ZIP文件流返回给客户端
sendZipFileToClient(zipFilePath, response);
// 删除临时文件
deleteTempZipFile(zipFilePath);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 从档案详情中提取文件信息
* @param detailsList
* @return
*/
private List<FileInfo> extractFileInfos(List<ArchivesDetails> detailsList) {
List<FileInfo> fileInfos = new ArrayList<>();
if (detailsList != null && !detailsList.isEmpty()) {
for (ArchivesDetails archivesDetails : detailsList) {
if (archivesDetails.getDocUrl() != null && !archivesDetails.getDocUrl().isEmpty()) {
FileInfo fileInfo = new FileInfo();
fileInfo.setFileName(archivesDetails.getDocName());
fileInfo.setFilePath(archivesDetails.getDocUrl());
fileInfos.add(fileInfo);
}
}
}
return fileInfos;
}
/**
* 创建临时ZIP文件
* @param fileInfos
* @return
* @throws IOException
*/
private String createTempZipFile(List<FileInfo> fileInfos) throws IOException {
String tempZipFilePath = "temp_files.zip";
try {
FileCompressor.zipFiles(fileInfos, tempZipFilePath);
} catch (IOException e) {
throw new IOException("Error creating ZIP file", e);
}
return tempZipFilePath;
}
/**
* 设置HTTP响应头
* @param response
*/
private void setResponseHeaders(HttpServletResponse response) {
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=files.zip");
}
/**
* 将生成的ZIP文件流返回给客户端
* @param zipFilePath
* @param response
* @throws IOException
*/
private void sendZipFileToClient(String zipFilePath, HttpServletResponse response) throws IOException {
Path zipPath = Paths.get(zipFilePath);
try (BufferedInputStream bis = new BufferedInputStream(Files.newInputStream(zipPath));
OutputStream os = response.getOutputStream()) {
byte[] buffer = new byte[8192]; // 使用更大的缓冲区
int bytesRead;
while ((bytesRead = bis.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
throw new IOException("Error sending ZIP file to client", e);
}
}
/**
* 删除临时ZIP文件
* @param zipFilePath
*/
private void deleteTempZipFile(String zipFilePath) {
try {
Path path = Paths.get(zipFilePath);
if (Files.exists(path)) {
Files.delete(path);
}
} catch (IOException e) {
System.err.println("Failed to delete temporary ZIP file: " + e.getMessage());
}
}
}

View File

@ -29,6 +29,8 @@ public class MaCodeVo {
private String typeName;
private String typeModelName;
@ApiModelProperty(value = "机具外观判断")
private String apDetection;

View File

@ -975,9 +975,10 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService {
String name = maMachineMap.get(maCodeVo.getMaStatus());
maCodeVo.setMaStatusName(StringUtils.isBlank(name) ? "" : name);
}
}
return AjaxResult.success(list);
}
return AjaxResult.error(HttpCodeEnum.SYSTEM_ERROR.getCode(), "编码检索为空");
}
/**
* app查询单个类型设备编码

View File

@ -0,0 +1,221 @@
<?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.bonus.material.archives.mapper.ArchivesMapper">
<select id="getTypeList" resultType="com.bonus.common.biz.domain.TreeNode">
select info_id as id, archives_name as label, parent_id as parentId,
level as level
from archives_record_info
where del_flag = '0'
<if test="keyWord != null and keyWord != ''">
and archives_name like concat('%', #{keyWord}, '%')
</if>
</select>
<select id="selectByName" resultType="com.bonus.material.archives.domain.ArchivesInfo">
select info_id as infoId,
archives_name as archivesName,
parent_id as parentId,
level as level
from archives_record_info
where archives_name = #{archivesName}
and parent_id = #{parentId}
and del_flag = '0'
</select>
<select id="getListById" resultType="com.bonus.material.archives.domain.ArchivesInfo">
SELECT
info_id as infoId,
archives_name AS label,
parent_id AS parentId,
level AS level
FROM
archives_record_info
WHERE
del_flag = '0' and parent_id = #{infoId}
</select>
<select id="selectDetailsList" resultType="com.bonus.material.archives.domain.ArchivesDetails">
select
details_id as detailsId,
info_id as infoId,
parent_id as parentId,
level as level,
doc_name as docName,
doc_type as docType,
doc_url as docUrl,
doc_size as docSize,
type_id as typeId,
YEAR(create_time) as year,
create_by as createBy,
create_time as createTime,
update_by as updateBy,
update_time as updateTime
FROM
archives_record_details
WHERE
del_flag = '0'
<if test="infoId != null">
and (info_id = #{infoId} and level = '1')
</if>
<if test="detailsId != null">
and parent_id = #{detailsId}
</if>
<if test="keyWord != null and keyWord != ''">
and (
doc_name like concat('%', #{keyWord}, '%') or
doc_type like concat('%', #{keyWord}, '%') or
create_by like concat('%', #{keyWord}, '%') or
)
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
<![CDATA[and DATE_FORMAT( update_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime} ]]>
</if>
</select>
<select id="selectDetailsByName" resultType="com.bonus.material.archives.domain.ArchivesDetails">
select
details_id as detailsId,
info_id as infoId,
doc_name as docName,
doc_type as docType,
doc_url as docUrl,
doc_size as docSize,
type_id as typeId,
YEAR(create_time) as year,
create_by as createBy,
create_time as createTime,
update_by as updateBy,
update_time as updateTime
FROM
archives_record_details
WHERE
del_flag = '0'
and doc_name = #{docName}
<if test="infoId != null">
and info_id = #{infoId}
</if>
<if test="detailsId != null">
and parent_id = #{detailsId}
</if>
</select>
<select id="selectDetails" resultType="com.bonus.material.archives.domain.ArchivesDetails">
select
details_id as detailsId,
info_id as infoId,
parent_id as parentId,
level as level,
doc_name as docName,
doc_type as docType,
doc_url as docUrl,
doc_size as docSize,
type_id as typeId,
YEAR(create_time) as year,
create_by as createBy,
create_time as createTime,
update_by as updateBy,
update_timeas updateTime
FROM
archives_record_details
WHERE
del_flag = '0'
and details_id in
<foreach item="id" collection="list" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<insert id="insertInfo">
insert into archives_record_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="archivesName != null and archivesName != ''">archives_name,</if>
<if test="parentId != null">parent_id,</if>
<if test="level != null and level != ''">level,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
del_flag
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="archivesName != null and archivesName != ''">#{archivesName},</if>
<if test="parentId != null">#{parentId},</if>
<if test="level != null and level != ''">#{level},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
0
</trim>
</insert>
<insert id="insertDetails">
insert into archives_record_details
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="infoId != null">info_id,</if>
<if test="parentId != null">parent_id,</if>
<if test="level != null and level != ''">level,</if>
<if test="docName != null and docName != ''">doc_name,</if>
<if test="docType != null and docType != ''">doc_type,</if>
<if test="docUrl != null and docUrl != ''">doc_url,</if>
<if test="docSize != null and docSize != ''">doc_size,</if>
<if test="typeId != null">type_id,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="createTime != null">update_time,</if>
del_flag
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="infoId != null">#{infoId},</if>
<if test="parentId != null">#{parentId},</if>
<if test="level != null and level != ''">#{level},</if>
<if test="docName != null and docName != ''">#{docName},</if>
<if test="docType != null and docType != ''">#{docType},</if>
<if test="docUrl != null and docUrl != ''">#{docUrl},</if>
<if test="docSize != null and docSize != ''">#{docSize},</if>
<if test="typeId != null">#{typeId},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="createTime != null">#{createTime},</if>
0
</trim>
</insert>
<update id="updateInfo">
update archives_record_info
<trim prefix="SET" suffixOverrides=",">
<if test="archivesName != null and archivesName != ''">archives_name = #{archivesName},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="level != null and level != ''">level = #{level},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where info_id = #{infoId}
</update>
<update id="updateDetails">
update archives_record_details
<trim prefix="SET" suffixOverrides=",">
<if test="infoId != null">info_id = #{infoId},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="docName != null and docName != ''">doc_name = #{docName},</if>
<if test="docType != null and docType != ''">doc_type = #{docType},</if>
<if test="docUrl != null and docUrl != ''">doc_url = #{docUrl},</if>
<if test="docSize != null and docSize != ''">doc_size = #{docSize},</if>
<if test="typeId != null">type_id = #{typeId},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where details_id = #{detailsId}
</update>
<delete id="deleteInfo">
update archives_record_info
set del_flag = '1'
where info_id = #{infoId}
</delete>
<delete id="deleteDetails">
update archives_record_details
set del_flag = '1'
where details_id = #{detailsId}
</delete>
</mapper>

View File

@ -377,7 +377,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mm.ma_status AS maStatus,
mt1.type_name AS typeName,
mm.type_id AS typeId,
mt.type_name AS materialName,
mt.type_name AS typeModelName,
mt2.type_name AS materialType,
ba.unit_id AS unitId,
bu.unit_name AS unitName,