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 {
commonService.downZiliao(surveyInformationId,peasantHouseholdIds,processInstanceId,response);
System.out.println("zip下载成功");
}
/**
......
......@@ -66,8 +66,6 @@ public class AcceptanceCheckServiceImpl extends BaseService<AcceptanceCheckDto,A
FinancingInfoServiceImpl financingInfoService;
@Autowired
FinancingAuditingServiceImpl financingAuditingService;
@Autowired
CommonServiceImpl commonService;
public Page<AcceptanceCheckDto> selectPage(Long regionCompanyId, Long amosDealerId, int current, int size,
......
......@@ -26,6 +26,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.util.MapHelper;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
......@@ -63,6 +64,8 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
......@@ -505,6 +508,35 @@ public class CommonServiceImpl {
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 {
String fileName = "";
String redisKey = "";
......@@ -548,7 +580,9 @@ public class CommonServiceImpl {
Path templateDir = Paths.get(TEMPLATE_FILE_PATH).getParent();
System.out.println("模版文件所在目录是: " + templateDir);
Path tempDir =ziLiaoDir.resolve(returnDto.getSurveyInformation().getOwnersName());
Path tempDir = createUniqueDirectory(ziLiaoDir, returnDto.getSurveyInformation().getOwnersName());
String wenjianjia = tempDir.toString().replace("\\","/");
try {
Files.createDirectories(tempDir); // 创建临时目录
System.out.println("Temporary directory created at: " + tempDir);
......@@ -556,10 +590,11 @@ public class CommonServiceImpl {
e.printStackTrace();
return;
}
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 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;
try ( InputStream fis = new ClassPathResource(templatePath).getInputStream()){
......@@ -622,22 +657,29 @@ public class CommonServiceImpl {
current = current + 15 ;
redisUtils.set(redisKey, MapBuilder.<String, Object>create()
.put("value", current).build());
List<HygfRectificationOrder> areaOrdersCon = Optional.ofNullable(returnDto.getPowerStationConstructionData().getAreaOrders())
.orElse(new ArrayList<>());
addNonNullList(areaOrdersCon, returnDto.getPowerStationConstructionData().getDesignOrders());
addNonNullList(areaOrdersCon, returnDto.getPowerStationConstructionData().getEngineeringOrders());
List<HygfRectificationOrder> areaOrdersCon =new ArrayList<>();
if (ObjectUtils.isNotEmpty(returnDto.getHygfOnGrid())) {
areaOrdersCon = Optional.ofNullable(returnDto.getPowerStationConstructionData().getAreaOrders())
.orElse(new ArrayList<>());
addNonNullList(areaOrdersCon, returnDto.getPowerStationConstructionData().getDesignOrders());
addNonNullList(areaOrdersCon, returnDto.getPowerStationConstructionData().getEngineeringOrders());
}
// 主方法或代码块
List<HygfRectificationOrder> areaOrders = Optional.ofNullable(returnDto.getHygfOnGrid().getAreaOrders())
.orElse(new ArrayList<>());
addNonNullList(areaOrders, returnDto.getHygfOnGrid().getDesignOrders());
addNonNullList(areaOrders, returnDto.getHygfOnGrid().getEngineeringOrders());
List<HygfRectificationOrder> areaOrdersAcc = Optional.ofNullable(returnDto.getAcceptanceCheck().getAreaOrders())
.orElse(new ArrayList<>());
addNonNullList(areaOrders, returnDto.getAcceptanceCheck().getLegalOrders());
addNonNullList(areaOrders, returnDto.getAcceptanceCheck().getFinanceOrders());
addNonNullList(areaOrders, returnDto.getAcceptanceCheck().getPropertyOrders());
List<HygfRectificationOrder> areaOrders =new ArrayList<>();
if (ObjectUtils.isNotEmpty(returnDto.getHygfOnGrid())) {
areaOrders = Optional.ofNullable(returnDto.getHygfOnGrid().getAreaOrders())
.orElse(new ArrayList<>());
addNonNullList(areaOrders, returnDto.getHygfOnGrid().getDesignOrders());
addNonNullList(areaOrders, returnDto.getHygfOnGrid().getEngineeringOrders());
}
List<HygfRectificationOrder> areaOrdersAcc = new ArrayList<>();
if (ObjectUtils.isNotEmpty(returnDto.getAcceptanceCheck())){
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<>();
String finalRedisKey = redisKey;
......@@ -724,9 +766,10 @@ public class CommonServiceImpl {
e.printStackTrace();
}
}));
futures.add(executorService.submit(() -> {
List<HygfRectificationOrder> finalAreaOrdersCon = areaOrdersCon;
futures.add(executorService.submit(() -> {
try {
downloadAndZipImages(areaOrdersCon,"施工信息整改单附件",tempDir,urlPath);
downloadAndZipImages(finalAreaOrdersCon,"施工信息整改单附件",tempDir,urlPath);
if (!finalRedisKey.contains(",")){
Map<String, Object> map = (Map<String, Object>) redisUtils.get(finalRedisKey);
Integer currentNum = (Integer) map.get("value")+7;
......@@ -752,9 +795,10 @@ public class CommonServiceImpl {
e.printStackTrace();
}
}));
futures.add(executorService.submit(() -> {
List<HygfRectificationOrder> finalAreaOrders = areaOrders;
futures.add(executorService.submit(() -> {
try {
downloadAndZipImages(areaOrders,"并网信息整改单附件",tempDir,urlPath);
downloadAndZipImages(finalAreaOrders,"并网信息整改单附件",tempDir,urlPath);
if (!finalRedisKey.contains(",")){
Map<String, Object> map = (Map<String, Object>) redisUtils.get(finalRedisKey);
Integer currentNum = (Integer) map.get("value")+7;
......@@ -780,9 +824,10 @@ public class CommonServiceImpl {
e.printStackTrace();
}
}));
futures.add(executorService.submit(() -> {
List<HygfRectificationOrder> finalAreaOrdersAcc = areaOrdersAcc;
futures.add(executorService.submit(() -> {
try {
downloadAndZipImages(areaOrdersAcc,"验收信息整改单附件",tempDir,urlPath);
downloadAndZipImages(finalAreaOrdersAcc,"验收信息整改单附件",tempDir,urlPath);
if (!finalRedisKey.contains(",")){
Map<String, Object> map = (Map<String, Object>) redisUtils.get(finalRedisKey);
Integer currentNum = (Integer) map.get("value")+7;
......@@ -818,7 +863,6 @@ public class CommonServiceImpl {
}
String encodedFilename = "";
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
if (peasantHouseholdIds.size() > 1){
fileName = "批量资料";
......@@ -833,15 +877,15 @@ public class CommonServiceImpl {
redisUtils.set(redisKey, MapBuilder.<String, Object>create()
.put("value", 100).build());
// response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + encodedFilename);
cleanup(ziLiaoDir);
}
private void fillSheet(Sheet sheet, Object data) {
if (Objects.isNull(data)){
return;
}
int startRow = 1;
for (int i = 0; i < sheet.getLastRowNum() + 1; i++) {
Row row = sheet.getRow(i);
......@@ -1274,6 +1318,9 @@ public class CommonServiceImpl {
}
public static void downloadAndZipImages(Object obj,String fileName, Path tempDir,String urlPath) throws IOException {
if (ObjectUtils.isEmpty(obj)){
return;
}
Path baseInfoPath = tempDir.resolve(fileName);
try {
Files.createDirectories(baseInfoPath);
......@@ -1407,25 +1454,25 @@ public class CommonServiceImpl {
// });
}
@Async
void cleanup(Path tempDir) {
try {
Files.walk(tempDir).sorted(Comparator.reverseOrder()).forEach(path -> {
try {
Files.delete(path);
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
private static String extractFileNameFromUrl(String url) {
String fileName = url.substring(url.lastIndexOf('/') + 1);
return fileName;
}
//@Async
//void cleanup(Path tempDir) {
// try {
// Files.walk(tempDir).sorted(Comparator.reverseOrder()).forEach(path -> {
// try {
// Files.delete(path);
// } catch (IOException e) {
// e.printStackTrace();
// }
// });
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// private static String extractFileNameFromUrl(String url) {
// String fileName = url.substring(url.lastIndexOf('/') + 1);
// return fileName;
// }
......@@ -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) {
List<Map<String, Object>> result = new ArrayList<>();
......@@ -1713,10 +1781,13 @@ void cleanup(Path tempDir) {
List<Map<String, String>> items = (List<Map<String, String>>) stringStringMap.get("items");
List<String> values = new ArrayList<>();
int startNum = 1;
for (Map<String, String> item : items) {
values.add(startNum++ +"."+item.get("value")+"。") ;
if (CollectionUtil.isNotEmpty(items)){
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));
}
......@@ -1781,7 +1852,7 @@ void cleanup(Path tempDir) {
List<ConstructionGirdRecords> getConstructionRecordsBasic (String peasantHouseholdId) {
// 施工自审操作记录
LambdaQueryWrapper<ConstructionGirdRecords> up5 = new LambdaQueryWrapper<ConstructionGirdRecords>();
up5.eq(ConstructionGirdRecords::getWorkOrderPowerStationId, peasantHouseholdId);
up5.eq(ConstructionGirdRecords::getPeasantHouseholdId, peasantHouseholdId);
up5.orderByAsc(ConstructionGirdRecords::getRecDate);
return constructionGirdRecordsMapper.selectList(up5);
}
......
......@@ -76,8 +76,6 @@ public class FinancingInfoServiceImpl extends BaseService<FinancingInfoDto, Fina
@Autowired
private PowerStationEngineeringInfoMapper powerStationEngineeringInfoMapper;
@Autowired
private CommonServiceImpl commonService;
@Autowired
private AcceptanceCheckServiceImpl acceptanceCheckService;
@Autowired
private AcceptanceCheckAuditingServiceImpl acceptanceCheckAuditingService;
......
......@@ -23,6 +23,7 @@ import javafx.beans.binding.MapBinding;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
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.rdbms.service.BaseService;
import org.springframework.stereotype.Service;
......@@ -45,7 +46,6 @@ public class RectificationOrderAuditingServiceImpl extends BaseService<Rectifica
@Autowired
private WorkFlowService workFlowService;
@Autowired
CommonServiceImpl commonService;
private static final String PROCESSKEY = "RectificationAudit";
......
......@@ -36,6 +36,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.component.emq.EmqKeeper;
......
......@@ -40,6 +40,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
......@@ -141,6 +142,7 @@ public class UnitInfoServiceImpl extends BaseService<UnitInfoDto,UnitInfo,UnitIn
@Autowired
WorkFlowService workFlowService;
@Autowired
@Lazy
CommonServiceImpl commonService;
@Autowired
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