Commit b7b16715 authored by hezhuozhi's avatar hezhuozhi

Merge remote-tracking branch 'origin/developer_bw' into developer_bw

parents 68528d71 1025c13c
...@@ -55,7 +55,7 @@ public class CommonController { ...@@ -55,7 +55,7 @@ public class CommonController {
commonService.downZiliao(surveyInformationId,peasantHouseholdIds,processInstanceId,response); commonService.downZiliao(surveyInformationId,peasantHouseholdIds,processInstanceId,response);
System.out.println("zip下载成功");
} }
/** /**
......
...@@ -66,8 +66,6 @@ public class AcceptanceCheckServiceImpl extends BaseService<AcceptanceCheckDto,A ...@@ -66,8 +66,6 @@ public class AcceptanceCheckServiceImpl extends BaseService<AcceptanceCheckDto,A
FinancingInfoServiceImpl financingInfoService; FinancingInfoServiceImpl financingInfoService;
@Autowired @Autowired
FinancingAuditingServiceImpl financingAuditingService; FinancingAuditingServiceImpl financingAuditingService;
@Autowired
CommonServiceImpl commonService;
public Page<AcceptanceCheckDto> selectPage(Long regionCompanyId, Long amosDealerId, int current, int size, public Page<AcceptanceCheckDto> selectPage(Long regionCompanyId, Long amosDealerId, int current, int size,
......
...@@ -26,6 +26,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -26,6 +26,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.util.MapHelper; import org.apache.activemq.util.MapHelper;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.reflect.FieldUtils;
...@@ -63,6 +64,8 @@ import java.util.concurrent.ExecutionException; ...@@ -63,6 +64,8 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
...@@ -505,6 +508,35 @@ public class CommonServiceImpl { ...@@ -505,6 +508,35 @@ public class CommonServiceImpl {
return jsonArray; return jsonArray;
} }
public static Path createUniqueDirectory(Path baseDir, String baseName) {
Path dirPath = baseDir.resolve(baseName);
// 检查目录是否存在
if (Files.exists(dirPath)) {
// 如果目录存在,则尝试创建带有数字后缀的目录
int counter = 1;
while (true) {
String newName = baseName + "_" + counter;
dirPath = baseDir.resolve(newName);
if (!Files.exists(dirPath)) {
break; // 找到了一个新的名称,退出循环
}
counter++;
}
}
// 创建目录
try {
Files.createDirectories(dirPath);
return dirPath;
} catch (IOException e) {
System.err.println("Failed to create directory: " + dirPath);
e.printStackTrace();
return null;
}
}
public void downZiliao(String surveyInformationId, List<String> peasantHouseholdIds, String processInstanceId, HttpServletResponse response) throws IOException { public void downZiliao(String surveyInformationId, List<String> peasantHouseholdIds, String processInstanceId, HttpServletResponse response) throws IOException {
String fileName = ""; String fileName = "";
String redisKey = ""; String redisKey = "";
...@@ -548,7 +580,9 @@ public class CommonServiceImpl { ...@@ -548,7 +580,9 @@ public class CommonServiceImpl {
Path templateDir = Paths.get(TEMPLATE_FILE_PATH).getParent(); Path templateDir = Paths.get(TEMPLATE_FILE_PATH).getParent();
System.out.println("模版文件所在目录是: " + templateDir); System.out.println("模版文件所在目录是: " + templateDir);
Path tempDir =ziLiaoDir.resolve(returnDto.getSurveyInformation().getOwnersName());
Path tempDir = createUniqueDirectory(ziLiaoDir, returnDto.getSurveyInformation().getOwnersName());
String wenjianjia = tempDir.toString().replace("\\","/");
try { try {
Files.createDirectories(tempDir); // 创建临时目录 Files.createDirectories(tempDir); // 创建临时目录
System.out.println("Temporary directory created at: " + tempDir); System.out.println("Temporary directory created at: " + tempDir);
...@@ -556,10 +590,11 @@ public class CommonServiceImpl { ...@@ -556,10 +590,11 @@ public class CommonServiceImpl {
e.printStackTrace(); e.printStackTrace();
return; return;
} }
String templatePath = "templates/informationTemp.xlsx"; String templatePath = "templates/informationTemp.xlsx";
//String templatePath = "F:\\work\\amos-boot-zx-biz\\amos-boot-system-jxiop\\amos-boot-module-hygf-biz\\src\\main\\resources\\templates\\informationTemp.xlsx"; //String templatePath = "F:\\work\\amos-boot-zx-biz\\amos-boot-system-jxiop\\amos-boot-module-hygf-biz\\src\\main\\resources\\templates\\informationTemp.xlsx";
// String outputPath = "F:\\work\\amos-boot-zx-biz\\amos-boot-system-jxiop\\amos-boot-module-hygf-biz\\src\\main\\resources\\templates\\temp\\"+returnDto.getSurveyInformation().getOwnersName()+".xlsx"; // String outputPath = "F:\\work\\amos-boot-zx-biz\\amos-boot-system-jxiop\\amos-boot-module-hygf-biz\\src\\main\\resources\\templates\\temp\\"+returnDto.getSurveyInformation().getOwnersName()+".xlsx";
String outputPath ="批量资料/"+ returnDto.getSurveyInformation().getOwnersName()+"/"+returnDto.getSurveyInformation().getOwnersName()+".xlsx"; String outputPath =wenjianjia+"/"+returnDto.getSurveyInformation().getOwnersName()+".xlsx";
Workbook workbook = null; Workbook workbook = null;
try ( InputStream fis = new ClassPathResource(templatePath).getInputStream()){ try ( InputStream fis = new ClassPathResource(templatePath).getInputStream()){
...@@ -622,22 +657,29 @@ public class CommonServiceImpl { ...@@ -622,22 +657,29 @@ public class CommonServiceImpl {
current = current + 15 ; current = current + 15 ;
redisUtils.set(redisKey, MapBuilder.<String, Object>create() redisUtils.set(redisKey, MapBuilder.<String, Object>create()
.put("value", current).build()); .put("value", current).build());
List<HygfRectificationOrder> areaOrdersCon = Optional.ofNullable(returnDto.getPowerStationConstructionData().getAreaOrders()) List<HygfRectificationOrder> areaOrdersCon =new ArrayList<>();
.orElse(new ArrayList<>()); if (ObjectUtils.isNotEmpty(returnDto.getHygfOnGrid())) {
addNonNullList(areaOrdersCon, returnDto.getPowerStationConstructionData().getDesignOrders()); areaOrdersCon = Optional.ofNullable(returnDto.getPowerStationConstructionData().getAreaOrders())
addNonNullList(areaOrdersCon, returnDto.getPowerStationConstructionData().getEngineeringOrders()); .orElse(new ArrayList<>());
addNonNullList(areaOrdersCon, returnDto.getPowerStationConstructionData().getDesignOrders());
addNonNullList(areaOrdersCon, returnDto.getPowerStationConstructionData().getEngineeringOrders());
}
// 主方法或代码块 // 主方法或代码块
List<HygfRectificationOrder> areaOrders = Optional.ofNullable(returnDto.getHygfOnGrid().getAreaOrders()) List<HygfRectificationOrder> areaOrders =new ArrayList<>();
.orElse(new ArrayList<>()); if (ObjectUtils.isNotEmpty(returnDto.getHygfOnGrid())) {
addNonNullList(areaOrders, returnDto.getHygfOnGrid().getDesignOrders()); areaOrders = Optional.ofNullable(returnDto.getHygfOnGrid().getAreaOrders())
addNonNullList(areaOrders, returnDto.getHygfOnGrid().getEngineeringOrders()); .orElse(new ArrayList<>());
addNonNullList(areaOrders, returnDto.getHygfOnGrid().getDesignOrders());
List<HygfRectificationOrder> areaOrdersAcc = Optional.ofNullable(returnDto.getAcceptanceCheck().getAreaOrders()) addNonNullList(areaOrders, returnDto.getHygfOnGrid().getEngineeringOrders());
.orElse(new ArrayList<>()); }
addNonNullList(areaOrders, returnDto.getAcceptanceCheck().getLegalOrders()); List<HygfRectificationOrder> areaOrdersAcc = new ArrayList<>();
addNonNullList(areaOrders, returnDto.getAcceptanceCheck().getFinanceOrders()); if (ObjectUtils.isNotEmpty(returnDto.getAcceptanceCheck())){
addNonNullList(areaOrders, returnDto.getAcceptanceCheck().getPropertyOrders()); areaOrdersAcc = Optional.ofNullable(returnDto.getAcceptanceCheck().getAreaOrders())
.orElse(new ArrayList<>());
addNonNullList(areaOrdersAcc, returnDto.getAcceptanceCheck().getLegalOrders());
addNonNullList(areaOrdersAcc, returnDto.getAcceptanceCheck().getFinanceOrders());
addNonNullList(areaOrdersAcc, returnDto.getAcceptanceCheck().getPropertyOrders());
}
List<Future<?>> futures = new ArrayList<>(); List<Future<?>> futures = new ArrayList<>();
String finalRedisKey = redisKey; String finalRedisKey = redisKey;
...@@ -724,9 +766,10 @@ public class CommonServiceImpl { ...@@ -724,9 +766,10 @@ public class CommonServiceImpl {
e.printStackTrace(); e.printStackTrace();
} }
})); }));
futures.add(executorService.submit(() -> { List<HygfRectificationOrder> finalAreaOrdersCon = areaOrdersCon;
futures.add(executorService.submit(() -> {
try { try {
downloadAndZipImages(areaOrdersCon,"施工信息整改单附件",tempDir,urlPath); downloadAndZipImages(finalAreaOrdersCon,"施工信息整改单附件",tempDir,urlPath);
if (!finalRedisKey.contains(",")){ if (!finalRedisKey.contains(",")){
Map<String, Object> map = (Map<String, Object>) redisUtils.get(finalRedisKey); Map<String, Object> map = (Map<String, Object>) redisUtils.get(finalRedisKey);
Integer currentNum = (Integer) map.get("value")+7; Integer currentNum = (Integer) map.get("value")+7;
...@@ -752,9 +795,10 @@ public class CommonServiceImpl { ...@@ -752,9 +795,10 @@ public class CommonServiceImpl {
e.printStackTrace(); e.printStackTrace();
} }
})); }));
futures.add(executorService.submit(() -> { List<HygfRectificationOrder> finalAreaOrders = areaOrders;
futures.add(executorService.submit(() -> {
try { try {
downloadAndZipImages(areaOrders,"并网信息整改单附件",tempDir,urlPath); downloadAndZipImages(finalAreaOrders,"并网信息整改单附件",tempDir,urlPath);
if (!finalRedisKey.contains(",")){ if (!finalRedisKey.contains(",")){
Map<String, Object> map = (Map<String, Object>) redisUtils.get(finalRedisKey); Map<String, Object> map = (Map<String, Object>) redisUtils.get(finalRedisKey);
Integer currentNum = (Integer) map.get("value")+7; Integer currentNum = (Integer) map.get("value")+7;
...@@ -780,9 +824,10 @@ public class CommonServiceImpl { ...@@ -780,9 +824,10 @@ public class CommonServiceImpl {
e.printStackTrace(); e.printStackTrace();
} }
})); }));
futures.add(executorService.submit(() -> { List<HygfRectificationOrder> finalAreaOrdersAcc = areaOrdersAcc;
futures.add(executorService.submit(() -> {
try { try {
downloadAndZipImages(areaOrdersAcc,"验收信息整改单附件",tempDir,urlPath); downloadAndZipImages(finalAreaOrdersAcc,"验收信息整改单附件",tempDir,urlPath);
if (!finalRedisKey.contains(",")){ if (!finalRedisKey.contains(",")){
Map<String, Object> map = (Map<String, Object>) redisUtils.get(finalRedisKey); Map<String, Object> map = (Map<String, Object>) redisUtils.get(finalRedisKey);
Integer currentNum = (Integer) map.get("value")+7; Integer currentNum = (Integer) map.get("value")+7;
...@@ -818,7 +863,6 @@ public class CommonServiceImpl { ...@@ -818,7 +863,6 @@ public class CommonServiceImpl {
} }
String encodedFilename = ""; String encodedFilename = "";
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
if (peasantHouseholdIds.size() > 1){ if (peasantHouseholdIds.size() > 1){
fileName = "批量资料"; fileName = "批量资料";
...@@ -833,15 +877,15 @@ public class CommonServiceImpl { ...@@ -833,15 +877,15 @@ public class CommonServiceImpl {
redisUtils.set(redisKey, MapBuilder.<String, Object>create() redisUtils.set(redisKey, MapBuilder.<String, Object>create()
.put("value", 100).build()); .put("value", 100).build());
// response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + encodedFilename);
cleanup(ziLiaoDir); cleanup(ziLiaoDir);
} }
private void fillSheet(Sheet sheet, Object data) { private void fillSheet(Sheet sheet, Object data) {
if (Objects.isNull(data)){
return;
}
int startRow = 1; int startRow = 1;
for (int i = 0; i < sheet.getLastRowNum() + 1; i++) { for (int i = 0; i < sheet.getLastRowNum() + 1; i++) {
Row row = sheet.getRow(i); Row row = sheet.getRow(i);
...@@ -1274,6 +1318,9 @@ public class CommonServiceImpl { ...@@ -1274,6 +1318,9 @@ public class CommonServiceImpl {
} }
public static void downloadAndZipImages(Object obj,String fileName, Path tempDir,String urlPath) throws IOException { public static void downloadAndZipImages(Object obj,String fileName, Path tempDir,String urlPath) throws IOException {
if (ObjectUtils.isEmpty(obj)){
return;
}
Path baseInfoPath = tempDir.resolve(fileName); Path baseInfoPath = tempDir.resolve(fileName);
try { try {
Files.createDirectories(baseInfoPath); Files.createDirectories(baseInfoPath);
...@@ -1407,25 +1454,25 @@ public class CommonServiceImpl { ...@@ -1407,25 +1454,25 @@ public class CommonServiceImpl {
// }); // });
} }
@Async //@Async
void cleanup(Path tempDir) { //void cleanup(Path tempDir) {
try { // try {
Files.walk(tempDir).sorted(Comparator.reverseOrder()).forEach(path -> { // Files.walk(tempDir).sorted(Comparator.reverseOrder()).forEach(path -> {
try { // try {
Files.delete(path); // Files.delete(path);
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
}); // });
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
//
private static String extractFileNameFromUrl(String url) { // private static String extractFileNameFromUrl(String url) {
String fileName = url.substring(url.lastIndexOf('/') + 1); // String fileName = url.substring(url.lastIndexOf('/') + 1);
return fileName; // return fileName;
} // }
...@@ -1659,7 +1706,28 @@ void cleanup(Path tempDir) { ...@@ -1659,7 +1706,28 @@ void cleanup(Path tempDir) {
// } // }
} }
@Async
public void cleanup(Path tempDir) {
try (Stream<Path> paths = Files.walk(tempDir)) {
List<Path> filesToDelete = paths.sorted(Comparator.reverseOrder())
.collect(Collectors.toList());
// 分批删除文件
int batchSize = 100; // 根据实际情况调整批次大小
for (int i = 0; i < filesToDelete.size(); i += batchSize) {
List<Path> batch = filesToDelete.subList(i, Math.min(i + batchSize, filesToDelete.size()));
batch.forEach(file -> {
try {
Files.delete(file);
} catch (IOException e) {
e.printStackTrace();
}
});
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static List<Map<String, Object>> convertList(List<Object> objectList) { public static List<Map<String, Object>> convertList(List<Object> objectList) {
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
...@@ -1713,10 +1781,13 @@ void cleanup(Path tempDir) { ...@@ -1713,10 +1781,13 @@ void cleanup(Path tempDir) {
List<Map<String, String>> items = (List<Map<String, String>>) stringStringMap.get("items"); List<Map<String, String>> items = (List<Map<String, String>>) stringStringMap.get("items");
List<String> values = new ArrayList<>(); List<String> values = new ArrayList<>();
int startNum = 1; int startNum = 1;
for (Map<String, String> item : items) { if (CollectionUtil.isNotEmpty(items)){
values.add(startNum++ +"."+item.get("value")+"。") ; for (Map<String, String> item : items) {
values.add(startNum++ +"."+item.get("value")+"。") ;
}
urls.add(stringStringMap.get("type")+":"+ String.join("",values));
} }
urls.add(stringStringMap.get("type")+":"+ String.join("",values));
} }
map.put("rectificationIdeas",String.join(",",urls)); map.put("rectificationIdeas",String.join(",",urls));
} }
...@@ -1781,7 +1852,7 @@ void cleanup(Path tempDir) { ...@@ -1781,7 +1852,7 @@ void cleanup(Path tempDir) {
List<ConstructionGirdRecords> getConstructionRecordsBasic (String peasantHouseholdId) { List<ConstructionGirdRecords> getConstructionRecordsBasic (String peasantHouseholdId) {
// 施工自审操作记录 // 施工自审操作记录
LambdaQueryWrapper<ConstructionGirdRecords> up5 = new LambdaQueryWrapper<ConstructionGirdRecords>(); LambdaQueryWrapper<ConstructionGirdRecords> up5 = new LambdaQueryWrapper<ConstructionGirdRecords>();
up5.eq(ConstructionGirdRecords::getWorkOrderPowerStationId, peasantHouseholdId); up5.eq(ConstructionGirdRecords::getPeasantHouseholdId, peasantHouseholdId);
up5.orderByAsc(ConstructionGirdRecords::getRecDate); up5.orderByAsc(ConstructionGirdRecords::getRecDate);
return constructionGirdRecordsMapper.selectList(up5); return constructionGirdRecordsMapper.selectList(up5);
} }
......
...@@ -76,8 +76,6 @@ public class FinancingInfoServiceImpl extends BaseService<FinancingInfoDto, Fina ...@@ -76,8 +76,6 @@ public class FinancingInfoServiceImpl extends BaseService<FinancingInfoDto, Fina
@Autowired @Autowired
private PowerStationEngineeringInfoMapper powerStationEngineeringInfoMapper; private PowerStationEngineeringInfoMapper powerStationEngineeringInfoMapper;
@Autowired @Autowired
private CommonServiceImpl commonService;
@Autowired
private AcceptanceCheckServiceImpl acceptanceCheckService; private AcceptanceCheckServiceImpl acceptanceCheckService;
@Autowired @Autowired
private AcceptanceCheckAuditingServiceImpl acceptanceCheckAuditingService; private AcceptanceCheckAuditingServiceImpl acceptanceCheckAuditingService;
......
...@@ -23,6 +23,7 @@ import javafx.beans.binding.MapBinding; ...@@ -23,6 +23,7 @@ import javafx.beans.binding.MapBinding;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -45,7 +46,6 @@ public class RectificationOrderAuditingServiceImpl extends BaseService<Rectifica ...@@ -45,7 +46,6 @@ public class RectificationOrderAuditingServiceImpl extends BaseService<Rectifica
@Autowired @Autowired
private WorkFlowService workFlowService; private WorkFlowService workFlowService;
@Autowired @Autowired
CommonServiceImpl commonService;
private static final String PROCESSKEY = "RectificationAudit"; private static final String PROCESSKEY = "RectificationAudit";
......
...@@ -36,6 +36,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -36,6 +36,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.component.emq.EmqKeeper; import org.typroject.tyboot.component.emq.EmqKeeper;
......
...@@ -40,6 +40,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -40,6 +40,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -141,6 +142,7 @@ public class UnitInfoServiceImpl extends BaseService<UnitInfoDto,UnitInfo,UnitIn ...@@ -141,6 +142,7 @@ public class UnitInfoServiceImpl extends BaseService<UnitInfoDto,UnitInfo,UnitIn
@Autowired @Autowired
WorkFlowService workFlowService; WorkFlowService workFlowService;
@Autowired @Autowired
@Lazy
CommonServiceImpl commonService; CommonServiceImpl commonService;
@Autowired @Autowired
AmosRequestContext amosRequestContext; AmosRequestContext amosRequestContext;
......
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