Browse Source

1、附件上传工作

master
pengwei 5 months ago
parent
commit
9c5dae2df5
  1. 2
      src/main/java/com/biutag/supervision/config/InterceptorConfig.java
  2. 76
      src/main/java/com/biutag/supervision/controller/books/NegativeBookController.java
  3. 2
      src/main/java/com/biutag/supervision/controller/datav/DataVSupervisionNotifyController.java
  4. 8
      src/main/java/com/biutag/supervision/controller/supervise/SuperviseReportController.java
  5. 5
      src/main/java/com/biutag/supervision/mapper/NegativeMapper.java
  6. 3
      src/main/java/com/biutag/supervision/mapper/SuperviseReportMapper.java
  7. 2
      src/main/java/com/biutag/supervision/pojo/param/SuperviseReportQueryParam.java
  8. 3
      src/main/java/com/biutag/supervision/pojo/vo/NegativeAuditExportVo.java
  9. 2
      src/main/java/com/biutag/supervision/pojo/vo/SuperviseReportVo.java
  10. 12
      src/main/java/com/biutag/supervision/service/DataMailService.java
  11. 27
      src/main/java/com/biutag/supervision/service/SuperviseReportService.java
  12. 121
      src/main/java/com/biutag/supervision/util/DownloadAndZip.java
  13. 7
      src/main/resources/mapper/SuperviseReportMapper.xml

2
src/main/java/com/biutag/supervision/config/InterceptorConfig.java

@ -47,7 +47,7 @@ public class InterceptorConfig implements WebMvcConfigurer {
.excludePathPatterns("/common/**")
.excludePathPatterns("/app/**")
// excel导出
.excludePathPatterns("/data/petitionComplaint12337/export/result","/sampling/export/samplingPoling", "/negative/books/export/**","/data/petitionComplaint/export/**","/confinement/export")
.excludePathPatterns("/data/petitionComplaint12337/export/result","/err","/sampling/export/samplingPoling", "/negative/books/export/**","/data/petitionComplaint/export/**","/confinement/export")
.excludePathPatterns(List.of("/doc.html", "/webjars/**", "/favicon.ico", "/v3/api-docs/**"));
registry.addInterceptor(new ApiInterceptor())
.addPathPatterns("/api/jwdc/**");

76
src/main/java/com/biutag/supervision/controller/books/NegativeBookController.java

@ -1,7 +1,9 @@
package com.biutag.supervision.controller.books;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.stream.CollectorUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.metadata.data.ImageData;
@ -16,7 +18,9 @@ import com.biutag.supervision.pojo.entity.*;
import com.biutag.supervision.pojo.param.NegativeQueryParam;
import com.biutag.supervision.pojo.vo.*;
import com.biutag.supervision.service.*;
import com.biutag.supervision.util.DownloadAndZip;
import com.biutag.supervision.util.ImgUtils;
import dm.jdbc.util.FileUtil;
import dm.jdbc.util.StringUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
@ -26,13 +30,12 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@ -323,9 +326,10 @@ public class NegativeBookController {
List<NegativeBlame> negativeBlames = emptyFlag ? new ArrayList<>() : blameService.listByNegativeIds(negativeIds);
List<NegativeProblemRelation> problemRelations = emptyFlag ? new ArrayList<>() : negativeProblemRelationService.list(negativeIds);
List<NegativeFile> negativeFiles = emptyFlag ? new ArrayList<>() : negativeFileService.listByNegativeIds(negativeIds);
List<NegativeAuditExportVo> list = pages.getRecords().stream().map(item -> {
List<NegativeAuditExportVo> list = pages.getRecords().stream().map((item) -> {
NegativeAuditExportVo vo = new NegativeAuditExportVo();
BeanUtil.copyProperties(item, vo);
vo.setProblems(problemRelations.stream()
.filter(problem -> StrUtil.isNotBlank(problem.getOneLevelContent()) && StrUtil.isNotBlank(problem.getTwoLevelContent()) && StrUtil.isNotBlank(problem.getThreeLevelContentOther()))
.map(problem -> String.format("%s / %s / %s", problem.getOneLevelContent(), problem.getTwoLevelContent(), problem.getThreeLevelContentOther()))
@ -364,4 +368,62 @@ public class NegativeBookController {
EasyExcel.write(response.getOutputStream(), NegativeAuditExportVo.class).inMemory(Boolean.TRUE).sheet("审计监督数据台账").doWrite(list);
}
@GetMapping("export/auditFile")
public void auditFile(NegativeQueryParam param,HttpServletResponse response) throws IOException{
param.setCurrent(1);
param.setSize(100000);
Page<Negative> pages = negativeBookService.auditPage(param);
List<String> negativeIds = pages.getRecords().stream().map(Negative::getId).toList();
boolean emptyFlag = negativeIds.isEmpty();
List<NegativeFile> negativeFiles = emptyFlag ? new ArrayList<>() : negativeFileService.listByNegativeIds(negativeIds);
if (!CollectionUtil.isNotEmpty(negativeFiles)) {
log.info("无附件");
return;
}
Map<String,List<NegativeFile>> maps= negativeFiles.stream().collect(Collectors.groupingBy(NegativeFile::getNegtiveId));
List<String> folderNames = new ArrayList<>();
// 临时保存下载的文件
String tempDir = "downloads";
maps.keySet().forEach(s->{
//问题名称
String serialNumber =String.valueOf(negativeIds.indexOf(s) +1);
//问题附件
List<NegativeFile> fileUrls = maps.get(s);
try {
Files.createDirectories(Paths.get(tempDir));
folderNames.add(serialNumber);
// 下载文件
for (int i = 0; i < fileUrls.size(); i++) {
String savePath = tempDir + "/"+fileUrls.get(i).getFileName();
DownloadAndZip.downloadFile( fileService.download(fileUrls.get(i).getFilePath()), savePath);
// 移动文件到对应文件夹
DownloadAndZip.moveFileToFolder(savePath, serialNumber);
// 删除临时文件
Path path = Paths.get(savePath);
if(Files.exists(path)){
Files.delete(path);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
});
// 打包文件夹成zip
String zipFilePath = "downloads/审计问题附件.zip";
Path zipPath = Paths.get(zipFilePath);
DownloadAndZip.zipFolders(new ArrayList<>(new HashSet<>(folderNames)), zipFilePath);
// 去除重复文件夹名称
//下载压缩包
String zipName = "审计问题附件.zip";
DownloadAndZip.doGet(response,zipFilePath,zipName);
log.info("压缩包下载完成---压缩包路径:"+zipFilePath);
//删除压缩包
if(Files.exists(zipPath)){
}
}
}

2
src/main/java/com/biutag/supervision/controller/datav/DataVSupervisionNotifyController.java

@ -151,7 +151,7 @@ public class DataVSupervisionNotifyController {
endTime = DateUtil.endOfDay(endTime);
//地图数据
List<SuperviseMapIconVo> superviseTempMapVoList = negativeMapper.getSupervisionMapIconInfo(beginTime, endTime);
//todo 有问题
JSONObject data = new JSONObject().fluentPut("superviseTempMapVoList", superviseTempMapVoList);
return Result.success(data);
}

8
src/main/java/com/biutag/supervision/controller/supervise/SuperviseReportController.java

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.biutag.supervision.pojo.Result;
import com.biutag.supervision.pojo.entity.Negative;
import com.biutag.supervision.pojo.entity.SuperviseReport;
import com.biutag.supervision.pojo.entity.SuperviseReportFile;
import com.biutag.supervision.pojo.param.SupRiskPersonalQueryParam;
@ -35,6 +36,13 @@ public class SuperviseReportController {
Result<Page<SuperviseReportVo>> queryPage(SuperviseReportQueryParam queryParam){
return Result.success(service.page(queryParam));
}
/**
* 根据报告获取问题列表
* */
@GetMapping("/negativePage")
Result<Page<Negative>> negativePage(SuperviseReportQueryParam queryParam){
return Result.success(service.negativePage(queryParam));
}
/**
* 编辑
* */

5
src/main/java/com/biutag/supervision/mapper/NegativeMapper.java

@ -300,7 +300,7 @@ public interface NegativeMapper extends BaseMapper<Negative> {
"sd.short_name AS `name`, " +
"sd.id AS departId, " +
"COUNT(DISTINCT ng.id) as total, "+
"COUNT( DISTINCT ng.id AND ng.checkStatus <> 3 ) AS discoverProblem, " +
"COUNT(DISTINCT CASE WHEN ng.checkStatus <> 3 THEN ng.id END) AS discoverProblem, " +
"COUNT( DISTINCT IF(ng.processing_status='completed', ng.id, NULL) ) AS completionProblem, " +
"COUNT( DISTINCT ng.involveDepartId) AS relativeOrg, " +
"COUNT( DISTINCT nb.blameName ) AS relativePer, " +
@ -889,7 +889,8 @@ public interface NegativeMapper extends BaseMapper<Negative> {
"csd.dept_name AS policeName, " +
"csd.dept_pid, " +
"csd.dept_id AS departId, " +
"COUNT( DISTINCT ng.id) AS discoverProblem, " +
"COUNT( DISTINCT ng.id) AS total," +
"COUNT( DISTINCT CASE WHEN ng.checkStatus <> 3 THEN ng.id END) AS discoverProblem, " +
"COUNT(DISTINCT IF(ng.processing_status='completed', ng.id, NULL) ) AS completionProblem, " +
"COUNT(DISTINCT ng.involveDepartId) AS relativeOrg, " +
"COUNT( DISTINCT nb.blameName ) AS relativePer, " +

3
src/main/java/com/biutag/supervision/mapper/SuperviseReportMapper.java

@ -7,8 +7,9 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.biutag.supervision.pojo.entity.Sampling;
import com.biutag.supervision.pojo.entity.SuperviseReport;
import com.biutag.supervision.pojo.vo.SuperviseReportVo;
import org.apache.ibatis.annotations.Param;
public interface SuperviseReportMapper extends BaseMapper<SuperviseReport> {
Page<SuperviseReport> queryPage(@Param("page") Page<SuperviseReport> page, @Param(Constants.WRAPPER) QueryWrapper<SuperviseReport> queryWrapper);
Page<SuperviseReportVo> queryPage(@Param("page") Page<SuperviseReport> page, @Param(Constants.WRAPPER) QueryWrapper<SuperviseReport> queryWrapper);
}

2
src/main/java/com/biutag/supervision/pojo/param/SuperviseReportQueryParam.java

@ -10,4 +10,6 @@ public class SuperviseReportQueryParam extends BasePage{
private String reportName;
//创建用户
private String crtUser;
private String id;
}

3
src/main/java/com/biutag/supervision/pojo/vo/NegativeAuditExportVo.java

@ -16,6 +16,9 @@ import java.time.LocalDateTime;
@Data
public class NegativeAuditExportVo implements Serializable {
@ExcelProperty("序号")
private int indexNumber;
// 业务类别名称
@ExcelProperty("业务类别")
private String businessTypeName;

2
src/main/java/com/biutag/supervision/pojo/vo/SuperviseReportVo.java

@ -26,6 +26,8 @@ public class SuperviseReportVo {
private String crtUser;
//创建人警号
private String crtEmpNo;
//督察问题数
private int superviseNumber;
//附件清单
private List<SuperviseReportFile> files;
}

12
src/main/java/com/biutag/supervision/service/DataMailService.java

@ -188,10 +188,11 @@ public class DataMailService extends ServiceImpl<DataPetitionComplaintMapper, Da
System.out.println("公安部信访数量:" + policeMail);
// 12337信访
QueryWrapper<DataPetition12337> queryWrapper12337 = new QueryWrapper<>();
queryWrapper12337.eq("second_depart_id", departId);
queryWrapper12337.between("create_time", beginTime, endTime);
Long numberMail = dataPetition12337Mapper.selectCount(queryWrapper12337);
// QueryWrapper<DataPetition12337> queryWrapper12337 = new QueryWrapper<>();
// queryWrapper12337.eq("second_depart_id", departId);
// queryWrapper12337.between("create_time", beginTime, endTime);
// Long numberMail = dataPetition12337Mapper.selectCount(queryWrapper12337);
Long numberMail = negativeService.count(new LambdaQueryWrapper<Negative>().between(Negative::getCrtTime,beginTime,endTime).eq(Negative::getHandleSecondDepartId,departId).eq(Negative::getProblemSourcesCode,ProblemSourcesEnum.XF12337.getValue()));
temp.setNumberMail(numberMail);
// 局长信箱
@ -242,7 +243,8 @@ public class DataMailService extends ServiceImpl<DataPetitionComplaintMapper, Da
Long policeTotal = dataPetitionComplaintMapper.selectPoliceMailBySourceCode(beginTime, endTime, GABXF.getValue(), policeDepartId);
Long commissionerTotal = getSubOneCommissionerTotal(beginTime, endTime, re); // 局长信箱
// 查询12337 数据
Long numTotal = dataPetition12337Mapper.select12337PoliceMailBySourceCode(beginTime, endTime, departId);
// Long numTotal = dataPetition12337Mapper.select12337PoliceMailBySourceCode(beginTime, endTime, departId);
Long numTotal = negativeService.count(new LambdaQueryWrapper<Negative>().between(Negative::getCrtTime,beginTime,endTime).eq(Negative::getHandleSecondDepartId,departId).eq(Negative::getProblemSourcesCode,ProblemSourcesEnum.XF12337.getValue()));
Long total = countryTotal + policeTotal + commissionerTotal + numTotal;
re.setCountryTotal(countryTotal.toString());
re.setPoliceTotal(policeTotal.toString());

27
src/main/java/com/biutag/supervision/service/SuperviseReportService.java

@ -34,6 +34,8 @@ public class SuperviseReportService extends ServiceImpl<SuperviseReportMapper, S
private final SupDepartService departService;
private final SuperviseReportFileService superviseReportFileService;
private final NegativeService negativeService;
/**
* 分页查询
* */
@ -50,26 +52,29 @@ public class SuperviseReportService extends ServiceImpl<SuperviseReportMapper, S
}
//查询条件
queryWrapper.like(StrUtil.isNotEmpty(queryParam.getReportName()),"t.report_name",queryParam.getReportName())
.like(StrUtil.isNotEmpty(queryParam.getCrtUser()),"t.crt_user",queryParam.getCrtUser());
.like(StrUtil.isNotEmpty(queryParam.getCrtUser()),"t.crt_user",queryParam.getCrtUser())
.groupBy("t.id");
Page<SuperviseReport> page= baseMapper.queryPage(Page.of(queryParam.getCurrent(), queryParam.getSize()), queryWrapper);
List<SuperviseReportVo> listData = new ArrayList<>();
Page<SuperviseReportVo> page= baseMapper.queryPage(Page.of(queryParam.getCurrent(), queryParam.getSize()), queryWrapper);
page.getRecords().forEach(s->{
SuperviseReportVo vo =new SuperviseReportVo();
BeanUtil.copyProperties(s,vo);
listData.add(vo);
});
Page<SuperviseReportVo> voPage = new Page<>(page.getCurrent(),page.getSize(),page.getTotal());
listData.forEach(s->{
List<SuperviseReportFile> files= superviseReportFileService.list(new LambdaQueryWrapper<SuperviseReportFile>().eq(SuperviseReportFile::getSuperviseId,s.getId()));
if(CollectionUtil.isNotEmpty(files)){
s.setFiles(files);
}
});
voPage.setRecords(listData);
return voPage;
return page;
}
public Page<Negative> negativePage(SuperviseReportQueryParam param){
LambdaQueryWrapper<Negative> queryWrapper=new LambdaQueryWrapper<>();
queryWrapper.eq(Negative::getReportId,param.getId());
queryWrapper.orderByAsc(Negative::getUpdTime);
Page<Negative> page = negativeService.page(Page.of(param.getCurrent(), param.getSize()), queryWrapper);
return page;
}
/**
* 保存或修改
* */

121
src/main/java/com/biutag/supervision/util/DownloadAndZip.java

@ -0,0 +1,121 @@
package com.biutag.supervision.util;
import com.biutag.supervision.service.FileService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class DownloadAndZip {
// 下载文件并保存到指定目录
public static void downloadFile(InputStream inputStream, String savePath) throws IOException {
try (
FileOutputStream outputStream = new FileOutputStream(savePath)) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
}
}
// 将文件移动到指定文件夹
public static void moveFileToFolder(String sourcePath, String folderName) throws IOException {
Path source = Paths.get(sourcePath);
Path targetFolder = Paths.get("downloads/" + folderName);
Path target = targetFolder.resolve(source.getFileName());
// 创建目标文件夹(如果不存在)
if (!Files.exists(targetFolder)) {
Files.createDirectories(targetFolder);
}
// 移动文件
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
}
// 将多个文件夹打包成zip
public static void zipFolders(List<String> folderNames, String zipFilePath) throws IOException {
try (FileOutputStream fos = new FileOutputStream(zipFilePath);
ZipOutputStream zos = new ZipOutputStream(fos)) {
for (String folderName : folderNames) {
Path folderPath = Paths.get("downloads/" + folderName);
zipFolder(folderPath, folderName, zos);
}
}
}
public static void doGet(HttpServletResponse response,String filePath,String zipName) throws IOException {
// 从请求参数中获取文件路径(这里假设文件路径是通过请求参数传递的,实际应用中可能需要更安全的方式)
if (filePath == null || filePath.isEmpty()) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "File path is required");
return;
}
// 校验文件路径的合法性(这里只是简单示例,实际应用中需要更严格的校验)
File file = new File(filePath);
if (!file.exists() || !file.isFile()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found");
return;
}
// 获取MIME类型
String mimeType = "application/octet-stream";
// 设置响应内容类型
response.setContentType(mimeType);
response.setContentLength((int) file.length());
// 设置Content-Disposition头以提示浏览器下载文件
String headerKey = "Content-Disposition";
String headerValue = String.format("attachment; filename=\"%s\"", URLEncoder.encode(zipName, "UTF-8"));
response.setHeader(headerKey, headerValue);
// 读取文件内容并写入响应输出流
try (FileInputStream inputStream = new FileInputStream(file);
OutputStream outputStream = response.getOutputStream()) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
}
}
private static void zipFolder(Path folderPath, String parentFolderName, ZipOutputStream zos) throws IOException {
for (File file : folderPath.toFile().listFiles()) {
Path filePath = folderPath.resolve(file.getName());
if (Files.isDirectory(filePath)) {
zipFolder(filePath, parentFolderName + "/" + file.getName(), zos);
} else {
try (FileInputStream fis = new FileInputStream(filePath.toFile())) {
ZipEntry zipEntry = new ZipEntry(parentFolderName + "/" + file.getName());
zos.putNextEntry(zipEntry);
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
}
}
}
}
}

7
src/main/resources/mapper/SuperviseReportMapper.xml

@ -4,10 +4,11 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.biutag.supervision.mapper.SuperviseReportMapper">
<select id="queryPage" resultType="com.biutag.supervision.pojo.entity.SuperviseReport">
select t.*
<select id="queryPage" resultType="com.biutag.supervision.pojo.vo.SuperviseReportVo">
select t.*,count(ng.id) as superviseNumber
from supervise_report as t
${ew.getCustomSqlSegment}
left join negative ng on t.id = ng.report_id
${ew.getCustomSqlSegment}
</select>

Loading…
Cancel
Save