1.添加生成压缩包方法

master
862857010@qq.com 1 year ago
parent 40e549e74c
commit dbba662368
  1. 12
      ruoyi-system/pom.xml
  2. 22
      ruoyi-system/src/main/java/com/ruoyi/system/controller/IndividualMemberController.java
  3. 20
      ruoyi-system/src/main/java/com/ruoyi/system/controller/UnitMemberController.java
  4. 7
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/IndividualMemberMapper.java
  5. 7
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/UnitMemberMapper.java
  6. 9
      ruoyi-system/src/main/java/com/ruoyi/system/service/IIndividualMemberService.java
  7. 16
      ruoyi-system/src/main/java/com/ruoyi/system/service/IUnitMemberService.java
  8. 25
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IndividualMemberServiceImpl.java
  9. 28
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UnitMemberServiceImpl.java
  10. 73
      ruoyi-system/src/main/java/com/ruoyi/system/util/ziputil/ZipFilesUtils.java
  11. 6
      ruoyi-system/src/main/resources/mapper/system/IndividualMemberMapper.xml
  12. 9
      ruoyi-system/src/main/resources/mapper/system/UnitMemberMapper.xml

@ -14,6 +14,18 @@
<description>
system系统模块
</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>

@ -1,5 +1,6 @@
package com.ruoyi.system.controller;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
@ -103,7 +104,7 @@ public class IndividualMemberController extends BaseController
/**
* 修改个人会员
*/
@PreAuthorize("@ss.hasPermi('system:personalmember:edit')")
@PreAuthorize("@ss.hasPermi('system:personalmember:check')")
@Log(title = "个人会员", businessType = BusinessType.UPDATE)
@PostMapping("personalCheckFile")
public AjaxResult personalCheckFile (@RequestBody IndividualMember individualMember) {
@ -121,4 +122,23 @@ public class IndividualMemberController extends BaseController
{
return toAjax(individualMemberService.deleteIndividualMemberByIds(ids));
}
/**
* 个人会员批量导出文档
* @param response
* @param ids
* @return
* @throws IOException
*/
@Log(title = "个人会员", businessType = BusinessType.EXPORT)
@GetMapping("/personalExport/{ids}")
public AjaxResult personalExport(HttpServletResponse response,@PathVariable Long[] ids) throws IOException {
String res=individualMemberService.personalExport(ids);
if(res.equals("导出失败")){
return AjaxResult.error(res);
}else {
return AjaxResult.success(res);
}
}
}

@ -1,5 +1,6 @@
package com.ruoyi.system.controller;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
@ -110,7 +111,7 @@ public class UnitMemberController extends BaseController
return toAjax(unitMemberService.deleteUnitMemberByIds(ids));
}
@PreAuthorize("@ss.hasPermi('system:member:edit')")
@PreAuthorize("@ss.hasPermi('system:member:check')")
@Log(title = "单位会员", businessType = BusinessType.UPDATE)
@PostMapping("/check")
public AjaxResult check(@RequestBody UnitMember unitMember) throws Exception {
@ -118,4 +119,21 @@ public class UnitMemberController extends BaseController
return toAjax(unitMemberService.check(unitMember));
}
/**
* 批量导出单位会员
* @param response
* @param ids
* @return
* @throws IOException
*/
@Log(title = "单位会员", businessType = BusinessType.EXPORT)
@GetMapping("/unitBatchExport/{ids}")
public AjaxResult unitBatchExport(HttpServletResponse response,@PathVariable Long[] ids) throws IOException {
String res=unitMemberService.batchExport(ids);
if(res.equals("导出失败")){
return AjaxResult.error(res);
}else {
return AjaxResult.success(res);
}
}
}

@ -58,4 +58,11 @@ public interface IndividualMemberMapper
* @return 结果
*/
public int deleteIndividualMemberByIds(Long[] ids);
/**
* 获取个人文档url
* @param ids
* @return
*/
List<String> getPersonalExport(Long[] ids);
}

@ -58,4 +58,11 @@ public interface UnitMemberMapper
* @return 结果
*/
public int deleteUnitMemberByIds(Long[] ids);
/**
* 获取导出压缩包文件
* @param ids
* @return
*/
public List<String> getBatchExportFile(Long[] ids);
}

@ -1,5 +1,6 @@
package com.ruoyi.system.service;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import com.ruoyi.system.domain.IndividualMember;
@ -60,4 +61,12 @@ public interface IIndividualMemberService
* @return 结果
*/
public int deleteIndividualMemberById(Long id);
/**
* 个人会员批量导出文档
* @param ids
* @return
* @throws IOException
*/
String personalExport(Long[] ids) throws IOException;
}

@ -1,5 +1,6 @@
package com.ruoyi.system.service;
import java.io.IOException;
import java.util.List;
import com.ruoyi.system.domain.UnitMember;
@ -42,6 +43,13 @@ public interface IUnitMemberService
* @return 结果
*/
public int updateUnitMember(UnitMember unitMember) throws Exception;
/**
* 审核
* @param unitMember
* @return
* @throws Exception
*/
public int check(UnitMember unitMember) throws Exception;
/**
@ -59,4 +67,12 @@ public interface IUnitMemberService
* @return 结果
*/
public int deleteUnitMemberById(Long id);
/**
* 批量导出单位会员
* @param ids
* @return
* @throws IOException
*/
String batchExport(Long[] ids) throws IOException;
}

@ -1,5 +1,6 @@
package com.ruoyi.system.service.impl;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@ -7,12 +8,14 @@ import java.time.format.DateTimeParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.UnitMember;
import com.ruoyi.system.util.GenerateDocxUtil;
import com.ruoyi.system.util.ziputil.ZipFilesUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -31,6 +34,8 @@ public class IndividualMemberServiceImpl implements IIndividualMemberService
{
// private String rootPath="/Users/liangjiawei/Downloads/worddocx/";
// private String docxPath="/Users/liangjiawei/Downloads/worddocx/file/";
private String path = "/Users/liangjiawei/Downloads";
// private static String path = "/upload/file";
private String rootPath="/upload/file/upload/worddocx/";
private String docxPath="/upload/file/upload/worddocx/file/";
@Autowired
@ -268,4 +273,24 @@ public class IndividualMemberServiceImpl implements IIndividualMemberService
{
return individualMemberMapper.deleteIndividualMemberById(id);
}
/**
* 个人会员批量导出文档
* @param ids
* @return
* @throws IOException
*/
@Override
public String personalExport(Long[] ids) throws IOException {
List<String> fileList=individualMemberMapper.getPersonalExport(ids);
List<String> updatedFileList = fileList.stream()
.map(item -> path + item)
.collect(Collectors.toList());
try {
ZipFilesUtils.compressFiles(updatedFileList,docxPath+"/zip/单位会员.zip");
return "/worddocx/file/zip/"+"个人会员.zip";
}catch (Exception e){
return "导出失败";
}
}
}

@ -1,14 +1,17 @@
package com.ruoyi.system.service.impl;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.RegionMapper;
import com.ruoyi.system.service.IRegionService;
import com.ruoyi.system.util.GenerateDocxUtil;
import com.ruoyi.system.util.ziputil.ZipFilesUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -25,11 +28,12 @@ import com.ruoyi.system.service.IUnitMemberService;
@Service
public class UnitMemberServiceImpl implements IUnitMemberService
{
// private String rootPath="/Users/liangjiawei/Downloads/worddocx/";
// private String docxPath="/Users/liangjiawei/Downloads/worddocx/file/";
private String rootPath="/upload/file/upload/worddocx/";
private String docxPath="/upload/file/upload/worddocx/file/";
private String rootPath="/Users/liangjiawei/Downloads/worddocx/";
private String docxPath="/Users/liangjiawei/Downloads/worddocx/file/";
private String path = "/Users/liangjiawei/Downloads";
// private static String path = "/upload/file";
// private String rootPath="/upload/file/upload/worddocx/";
// private String docxPath="/upload/file/upload/worddocx/file/";
@Autowired
private UnitMemberMapper unitMemberMapper;
@Autowired
@ -193,4 +197,18 @@ public class UnitMemberServiceImpl implements IUnitMemberService
{
return unitMemberMapper.deleteUnitMemberById(id);
}
@Override
public String batchExport(Long[] ids) throws IOException {
List<String> fileList=unitMemberMapper.getBatchExportFile(ids);
List<String> updatedFileList = fileList.stream()
.map(item -> path + item)
.collect(Collectors.toList());
try {
ZipFilesUtils.compressFiles(updatedFileList,docxPath+"/zip/单位会员.zip");
return "/worddocx/file/zip/"+"单位会员.zip";
}catch (Exception e){
return "导出失败";
}
}
}

@ -0,0 +1,73 @@
package com.ruoyi.system.util.ziputil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* @author liangjiawei
* @createDate 2024/7/25
*/
public class ZipFilesUtils {
// 假设这是根据文件ID查询到的文件路径集合
public static List<String> getFilePathsById() {
// 示例:返回文件路径集合
return List.of(
"/Users/liangjiawei/Downloads/worddocx/file/2-10.docx","/Users/liangjiawei/Downloads/worddocx/file/2-11.docx","/Users/liangjiawei/Downloads/worddocx/file/2-12.docx","/Users/liangjiawei/Downloads/worddocx/file/2-13.docx","/Users/liangjiawei/Downloads/worddocx/file/2-14.docx"
);
}
public static void compressFiles(List<String> filePaths, String zipFilePath) throws IOException {
try (FileOutputStream fos = new FileOutputStream(zipFilePath);
ZipOutputStream zos = new ZipOutputStream(fos)) {
for (String filePath : filePaths) {
File file = new File(filePath);
if (!file.exists()) {
System.out.println("文件不存在: " + filePath);
continue;
}
addFileToZip(file, zos, "");
}
}
}
private static void addFileToZip(File file, ZipOutputStream zos, String parentDir) throws IOException {
if (file.isDirectory()) {
String dirPath = parentDir + file.getName() + File.separator;
zos.putNextEntry(new ZipEntry(dirPath));
zos.closeEntry();
for (File subFile : file.listFiles()) {
addFileToZip(subFile, zos, dirPath);
}
} else {
try (FileInputStream fis = new FileInputStream(file)) {
ZipEntry zipEntry = new ZipEntry(parentDir + file.getName());
zos.putNextEntry(zipEntry);
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
}
}
}
public static void main(String[] args) {
String fileId = "exampleFileId"; // 示例文件ID
String zipFilePath = "/Users/liangjiawei/Downloads/worddocx/file/zip/output.zip"; // 输出压缩文件路径
try {
List<String> filePaths = getFilePathsById();
compressFiles(filePaths, zipFilePath);
System.out.println("压缩成功,文件路径: " + zipFilePath);
} catch (IOException e) {
e.printStackTrace();
System.err.println("压缩失败!");
}
}
}

@ -109,6 +109,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectIndividualMemberVo"/>
where id = #{id}
</select>
<select id="getPersonalExport" resultType="java.lang.String">
select word_url from individual_member where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<insert id="insertIndividualMember" parameterType="IndividualMember" useGeneratedKeys="true" keyProperty="id">
insert into individual_member

@ -117,6 +117,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</select>
<insert id="insertUnitMember" parameterType="UnitMember" useGeneratedKeys="true" keyProperty="id">
insert into unit_member
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -218,8 +219,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="approvalStatus != null">approval_status = #{approvalStatus},</if>
<if test="administrativeApprovalBureau != null">administrative_approval_bureau = #{administrativeApprovalBureau},</if>
<if test="registrationAuthorityProvince != null">registration_authority_province = #{registrationAuthorityProvince},</if>
</trim>
where id = #{id}
</update>
@ -234,4 +233,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<select id="getBatchExportFile" resultType="java.lang.String">
select word_url from unit_member where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

Loading…
Cancel
Save