Commit 6e2070d1 by wangjian

2025-08-06 规范建设 V5

parent 77ee1bfe
......@@ -7,20 +7,20 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.servlet.http.HttpServletResponse;
import com.qianhe.common.config.RuoYiConfig;
import com.qianhe.common.constant.Constants;
import com.qianhe.common.exception.BusinessException;
import com.qianhe.common.utils.StringUtils;
import com.qianhe.common.utils.ip.IpUtils;
import com.qianhe.domain.GgFjb;
import com.qianhe.domain.SjZdsc;
import com.qianhe.service.IGgFjbService;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.qianhe.common.annotation.Log;
import com.qianhe.common.core.controller.BaseController;
import com.qianhe.common.core.domain.AjaxResult;
import com.qianhe.common.enums.BusinessType;
import com.qianhe.domain.SjZdsc;
import com.qianhe.service.ISjZdscService;
import com.qianhe.common.utils.poi.ExcelUtil;
import com.qianhe.common.core.page.TableDataInfo;
......@@ -112,13 +112,13 @@ public class SjZdscController extends BaseController
/**
* 批量导出 中原-维修-单台设备审批列表
* 批量导出
* 导出zip
*/
@RequestMapping(value = "/exportZip", method = {RequestMethod.GET, RequestMethod.POST})
public void exportZip(HttpServletResponse response, String ids) throws IOException
public void exportZip(HttpServletResponse response, @RequestBody SjZdsc sjZdsc) throws IOException
{
Long id = Long.parseLong(ids);
Long id = Long.parseLong(sjZdsc.getIds());
SjZdsc en = sjZdscService.selectSjZdscById(id);
String zdmc = en.getZdmc();
String bb = en.getBb();
......@@ -127,9 +127,10 @@ public class SjZdscController extends BaseController
String ip = IpUtils.getIpAddr();
// 设置响应头
response.setContentType("application/zip");
// response.setContentType("application/zip");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(zdmc + " " + bb + ".zip", "UTF-8"));
response.setCharacterEncoding("UTF-8");
// Workbook exl = null;
// OutputStream out = null;
......@@ -137,42 +138,84 @@ public class SjZdscController extends BaseController
// 创建ZIP输出流
try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
// 临时变量用于验证是否有有效文件被添加
boolean hasValidFile = false;
for(GgFjb fj:fjs) {
String fjlj = fj.getFJDZ();//附件路径
String fjmc = fj.getFJMC();//附件名称
String wzfwlj = ip + fjlj;//完整路径
String localPath = RuoYiConfig.getProfile();
String downloadPath = localPath + StringUtils.substringAfter(fjlj, Constants.RESOURCE_PREFIX);
// 1. 验证文件存在性和可读性
File file = new File(downloadPath);
if (!file.exists()) {
System.out.println("文件不存在: {}" + downloadPath);
continue;
}
if (!file.canRead()) {
System.out.println("文件不可读: {}" + downloadPath);
continue;
}
if (file.length() == 0) {
System.out.println("文件为空: {}" + downloadPath);
continue;
}
// 从文件路径读取字节数组
byte[] fileBytes = null;
try (InputStream in = new FileInputStream(wzfwlj);
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
// 2. 读取文件内容(改进版)
byte[] fileBytes;
try (FileInputStream fis = new FileInputStream(file)) {
fileBytes = new byte[(int) file.length()];
int bytesRead = fis.read(fileBytes);
// 验证读取的字节数是否与文件大小一致
if (bytesRead != file.length()) {
System.out.println("文件读取不完整,预期: {},实际: {}" + file.length() + bytesRead);
continue;
}
fileBytes = out.toByteArray();
} catch (FileNotFoundException e) {
throw new BusinessException("文件不存在: " + wzfwlj);
} catch (IOException e) {
throw new BusinessException("读取文件失败: " + wzfwlj);
hasValidFile = true;
} catch (Exception e) {
System.out.println("读取文件异常: {}" + downloadPath + e);
continue;
}
// 创建ZIP条目
ZipEntry entry = new ZipEntry(fjmc);
// 3. 处理文件名(避免特殊字符)
String safeFileName = fjmc.replaceAll("[\\\\/:*?\"<>|]", "_");
ZipEntry entry = new ZipEntry(safeFileName);
zos.putNextEntry(entry);
// 写入PDF文件到ZIP条目
// 4. 写入文件内容(带验证)
zos.write(fileBytes);
zos.flush(); // 强制刷新
zos.closeEntry();
}
}catch (Exception e){
e.getMessage();
throw new BusinessException("导出Excel失败,请联系网站管理员!");
}finally {
// 5. 确保至少有一个有效文件被添加
if (!hasValidFile) {
throw new BusinessException("没有可导出的有效文件");
}
// 6. 完成ZIP文件(关键步骤)
zos.finish();
response.flushBuffer(); // 确保所有数据发送到客户端
} catch (BusinessException e) {
System.out.println("导出业务异常" + e);
throw e;
} catch (Exception e) {
System.out.println("导出ZIP文件异常" + e);
throw new BusinessException("导出文件失败,请联系管理员");
}
}
/**
* 批量提交
*/
@PostMapping(value = "/pltj")
public AjaxResult pltj(@RequestBody SjZdsc sjZdsc)
{
sjZdsc.setZt("1");
return success(sjZdscService.pltj(sjZdsc));
}
}
......@@ -57,4 +57,7 @@ public class SjZdsc extends BaseEntity
//查询出的结果
private String deptName;//单位名称
//传入参数
private String ids;//
}
......@@ -68,5 +68,6 @@ public interface GgFjbMapper
public int deleteFjByYwid(GgFjb ggFjb);
public int insertFj(GgFjb zbZbjcxxfjb);
List<GgFjb> selectFj(@Param("id") Long id, @Param("mkmc") String mkmc);
List<GgFjb> selectFjByMk(@Param("mkmc") String mkmc);
}
......@@ -42,6 +42,7 @@ public interface SjZdscMapper
* @return 结果
*/
public int updateSjZdsc(SjZdsc sjZdsc);
public int plxg(SjZdsc sjZdsc);
/**
* 删除基层三册
......
......@@ -64,6 +64,7 @@ public interface IGgFjbService
public int batchSaveFj(String businessId, String fjlx, String mkmc, String fileListStr);
List<GgFjb> selectFj(Long id, String mkmc);
List<GgFjb> selectFjByMk(String mkmc);
int deleteFjByYwid(GgFjb ggFjb);
}
package com.qianhe.service;
import java.util.List;
import com.qianhe.domain.SjZdsc;
/**
......@@ -58,4 +59,5 @@ public interface ISjZdscService
* @return 结果
*/
public int deleteSjZdscById(Long id);
public int pltj(SjZdsc sjBzxx);
}
......@@ -135,6 +135,10 @@ public class GgFjbServiceImpl implements IGgFjbService
return ggFjbMapper.selectFj(id,mkmc);
}
@Override
public List<GgFjb> selectFjByMk(String mkmc) {
return ggFjbMapper.selectFjByMk(mkmc);
}
@Override
public int deleteFjByYwid(GgFjb fj) {
return ggFjbMapper.deleteFjByYwid(fj);
}
......
......@@ -6,7 +6,9 @@ import java.util.stream.Collectors;
import com.qianhe.common.annotation.DataScope;
import com.qianhe.common.utils.DateUtils;
import com.qianhe.common.utils.SecurityUtils;
import com.qianhe.domain.GgFjb;
import com.qianhe.domain.SjZdsc;
import com.qianhe.service.IGgFjbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -60,7 +62,26 @@ public class SjZdscServiceImpl implements ISjZdscService
@DataScope(deptAlias = "d")
public List<SjZdsc> selectSjZdscList(SjZdsc sjZdsc)
{
return sjZdscMapper.selectSjZdscList(sjZdsc);
List<SjZdsc> rl = sjZdscMapper.selectSjZdscList(sjZdsc);
//查询附件
List<GgFjb> fjlistAll = fjbService.selectFjByMk("基层三册");
for(SjZdsc rt:rl){
Long id = rt.getId();
String ids = String.valueOf(id);
List<GgFjb> fjlist = fjlistAll.stream().filter(e->e.getYWID().equals(ids)).collect(Collectors.toList());
Map<String, List<GgFjb>> map = fjlist.stream().collect(Collectors.groupingBy(GgFjb::getFJLX));
if(map.get("基层三册")!=null){
List<GgFjb> fileData = map.get("基层三册").stream().collect(Collectors.toList());
rt.setFileList1(fileData);
}
}
return rl;
}
/**
......@@ -112,4 +133,14 @@ public class SjZdscServiceImpl implements ISjZdscService
{
return sjZdscMapper.deleteSjZdscById(id);
}
@Override
public int pltj(SjZdsc sjZdsc)
{
sjZdsc.setUpdateBy(SecurityUtils.getUsername());
sjZdsc.setUpdateTime(DateUtils.getNowDate());
return sjZdscMapper.plxg(sjZdsc);
}
}
......@@ -120,10 +120,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
</insert>
<delete id="deleteFjByYwid" parameterType="GgFjb">
delete from gg_fjb where YWID = #{SFBM} AND FJLX =#{FJLX} AND MKMC =#{MKMC}
delete from gg_fjb where YWID = #{YWID} AND FJLX =#{FJLX} AND MKMC =#{MKMC}
</delete>
<select id="selectFj" resultMap="GgFjbResult">
select * from gg_fjb where YWID = #{id} and MKMC = #{mkmc};
</select>
<select id="selectFjByMk" resultMap="GgFjbResult">
select * from gg_fjb where MKMC = #{mkmc};
</select>
</mapper>
\ No newline at end of file
......@@ -126,6 +126,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where find_in_set(id, #{ids}))
where find_in_set(id, #{ids})
</update>
</mapper>
\ No newline at end of file
......@@ -106,4 +106,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<update id="plxg" parameterType="SjBzxx">
update sj_zdsc
<trim prefix="SET" suffixOverrides=",">
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="lx != null">lx = #{lx},</if>
<if test="zdmc != null">zdmc = #{zdmc},</if>
<if test="bb != null">bb = #{bb},</if>
<if test="fjms != null">fjms = #{fjms},</if>
<if test="zt != null">zt = #{zt},</if>
<if test="xzcs != null">xzcs = #{xzcs},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where find_in_set(id, #{ids})
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment