Commit b1a8de1f authored by hezhuozhi's avatar hezhuozhi

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

parents a3359699 0b44f14c
...@@ -42,6 +42,11 @@ ...@@ -42,6 +42,11 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId> <artifactId>spring-boot-starter-activemq</artifactId>
<version>2.5.4</version> <version>2.5.4</version>
......
package com.yeejoin.amos.boot.module.hygf.biz.controller; package com.yeejoin.amos.boot.module.hygf.biz.controller;
import com.yeejoin.amos.boot.module.hygf.api.dto.CommerceInfoDto; import com.yeejoin.amos.boot.module.hygf.api.dto.CommerceInfoDto;
import com.yeejoin.amos.boot.module.hygf.biz.service.impl.CommonServiceImpl;
import com.yeejoin.amos.boot.module.hygf.biz.service.impl.FinancingInfoServiceImpl; import com.yeejoin.amos.boot.module.hygf.biz.service.impl.FinancingInfoServiceImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -11,6 +12,8 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation; ...@@ -11,6 +12,8 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -21,6 +24,8 @@ public class CommonController { ...@@ -21,6 +24,8 @@ public class CommonController {
@Autowired @Autowired
FinancingInfoServiceImpl financingInfoService; FinancingInfoServiceImpl financingInfoService;
@Autowired
CommonServiceImpl commonService;
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/selectRegion") @GetMapping(value = "/selectRegion")
...@@ -31,5 +36,24 @@ public class CommonController { ...@@ -31,5 +36,24 @@ public class CommonController {
/**
* 设备信息下载
*
* @return
*/
@GetMapping(value = "/downInformation")
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "资料下载", notes = "资料下载")
public void downList(HttpServletResponse response, @RequestParam(required = false) String surveyInformationId,
@RequestParam(required = false)String peasantHouseholdId,
@RequestParam(required = false)String processInstanceId) throws IOException {
commonService.downZiliao(surveyInformationId,peasantHouseholdId,processInstanceId);
}
} }
...@@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSON; ...@@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams; import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey; import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
...@@ -14,6 +16,7 @@ import com.yeejoin.amos.boot.module.hygf.api.Enum.BusinessTypeEnum; ...@@ -14,6 +16,7 @@ import com.yeejoin.amos.boot.module.hygf.api.Enum.BusinessTypeEnum;
import com.yeejoin.amos.boot.module.hygf.api.Enum.FlowKeyTodoEnum; import com.yeejoin.amos.boot.module.hygf.api.Enum.FlowKeyTodoEnum;
import com.yeejoin.amos.boot.module.hygf.api.Enum.FlowStatusEnum; import com.yeejoin.amos.boot.module.hygf.api.Enum.FlowStatusEnum;
import com.yeejoin.amos.boot.module.hygf.api.dto.SurveyInfoAllDto; import com.yeejoin.amos.boot.module.hygf.api.dto.SurveyInfoAllDto;
import com.yeejoin.amos.boot.module.hygf.api.dto.SurveyInformationDto;
import com.yeejoin.amos.boot.module.hygf.api.dto.TaskModelDto; import com.yeejoin.amos.boot.module.hygf.api.dto.TaskModelDto;
import com.yeejoin.amos.boot.module.hygf.api.dto.WorkflowResultDto; import com.yeejoin.amos.boot.module.hygf.api.dto.WorkflowResultDto;
import com.yeejoin.amos.boot.module.hygf.api.util.JsonUtils; import com.yeejoin.amos.boot.module.hygf.api.util.JsonUtils;
...@@ -24,7 +27,10 @@ import com.yeejoin.amos.feign.systemctl.Systemctl; ...@@ -24,7 +27,10 @@ import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.RegionModel; import com.yeejoin.amos.feign.systemctl.model.RegionModel;
import com.yeejoin.amos.feign.systemctl.model.TaskV2Model; import com.yeejoin.amos.feign.systemctl.model.TaskV2Model;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -33,15 +39,21 @@ import org.springframework.core.io.Resource; ...@@ -33,15 +39,21 @@ import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.io.FileInputStream; import java.io.*;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* 公共服务实现类 * 公共服务实现类
...@@ -66,6 +78,11 @@ public class CommonServiceImpl { ...@@ -66,6 +78,11 @@ public class CommonServiceImpl {
@Autowired @Autowired
private AmosRequestContext amosRequestContext; private AmosRequestContext amosRequestContext;
private static final String BASE_INFO_FOLDER = "基本信息";
private static final String ZIP_FILE_PATH = "基本信息.zip";
private static final String TEMP_DIR_NAME = "temp";
private static final String TEMPLATE_FILE_PATH = "F:\\work\\amos-boot-zx-biz\\amos-boot-system-jxiop\\amos-boot-module-hygf-biz\\src\\main\\resources\\templates\\test.xlsx"; // 模版文件路径
private static String toQueryParams2(JSONObject jsonObject) { private static String toQueryParams2(JSONObject jsonObject) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Set<String> keys = jsonObject.keySet(); Set<String> keys = jsonObject.keySet();
...@@ -424,22 +441,20 @@ public class CommonServiceImpl { ...@@ -424,22 +441,20 @@ public class CommonServiceImpl {
return jsonArray; return jsonArray;
} }
public void downZiliao(String surveyInformationId, String peasantHouseholdId, String processInstanceId) { public void downZiliao(String surveyInformationId, String peasantHouseholdId, String processInstanceId) throws IOException {
SurveyInfoAllDto returnDto = surveyInformationServiceImpl.querySurveyInfo(surveyInformationId, peasantHouseholdId, processInstanceId, null); SurveyInfoAllDto returnDto = surveyInformationServiceImpl.querySurveyInfo(surveyInformationId, peasantHouseholdId, processInstanceId, null);
// 读取Excel模板
String templatePath = "path/to/informationTemp.xlsx"; String templatePath = "F:\\work\\amos-boot-zx-biz\\amos-boot-system-jxiop\\amos-boot-module-hygf-biz\\src\\main\\resources\\templates\\test.xlsx";
String outputPath = "path/to/filled_informationTemp.xlsx"; String outputPath = returnDto.getSurveyInformation().getOwnersName()+".xlsx";
Workbook workbook = null; Workbook workbook = null;
try (FileInputStream fis = new FileInputStream(templatePath)) { try (FileInputStream fis = new FileInputStream(templatePath)) {
workbook = new XSSFWorkbook(fis); workbook = new XSSFWorkbook(fis);
// 处理第一个工作表
Sheet firstSheet = workbook.getSheetAt(0); Sheet firstSheet = workbook.getSheetAt(0);
fillSheet(firstSheet, returnDto.getSurveyInformation()); fillSheet(firstSheet, returnDto.getSurveyInformation());
// 处理第二个工作表
Sheet secondSheet = workbook.getSheetAt(1); Sheet secondSheet = workbook.getSheetAt(1);
fillSheet(secondSheet, returnDto.getSurveyDetails()); fillSheet(secondSheet, returnDto.getSurveyDetails());
...@@ -450,34 +465,246 @@ public class CommonServiceImpl { ...@@ -450,34 +465,246 @@ public class CommonServiceImpl {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
List<String> urls = extractUrls(returnDto.getSurveyInformation());
downloadAndZipImages(returnDto.getSurveyInformation());
} }
/**
* 辅助方法用来填充工作表。
*
* @param sheet 要填充的工作表
* @param data 数据源
*/
private void fillSheet(Sheet sheet, Object data) { private void fillSheet(Sheet sheet, Object data) {
// 遍历每一行
for (Row row : sheet) { int startRow = 1;
// 遍历每一个单元格 for (int i = 0; i < sheet.getLastRowNum() + 1; i++) {
Row row = sheet.getRow(i);
if (row != null && i >= startRow) {
for (Cell cell : row) { for (Cell cell : row) {
if (cell.getCellType() == CellType.STRING) { if (cell.getCellType() == CellType.STRING) {
String cellValue = cell.getStringCellValue(); String cellValue = cell.getStringCellValue();
String fieldName = removePlaceholders(cellValue);
setCellValue(cell, fieldName, data);
}
}
}
}
}
private String removePlaceholders(String fieldValue) {
return fieldValue.replaceAll("[{}]", "");
}
private void setCellValue(Cell cell, String fieldName, Object data) {
if (data instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, String> dataMap = (Map<String, String>) data;
if (dataMap.containsKey(fieldName)) {
cell.setCellValue(dataMap.get(fieldName));
} else {
cell.setCellValue("");
}
} else if (data instanceof List) {
@SuppressWarnings("unchecked")
List<Map<String, String>> dataList = (List<Map<String, String>>) data;
int rowIndex = cell.getRowIndex();
if (rowIndex >= 0 && rowIndex < dataList.size()) {
Map<String, String> rowData = dataList.get(rowIndex);
if (rowData.containsKey(fieldName)) {
cell.setCellValue(rowData.get(fieldName));
} else {
cell.setCellValue("");
}
} else {
cell.setCellValue("");
}
} else {
try { try {
// 尝试获取字段值 Field field = data.getClass().getDeclaredField(fieldName);
Field field = data.getClass().getDeclaredField(cellValue);
field.setAccessible(true); // 设置为可访问私有字段 field.setAccessible(true); // 设置为可访问私有字段
Object value = field.get(data); Object value = field.get(data);
if (value != null) { if (value != null) {
cell.setCellValue(value.toString()); cell.setCellValue(value.toString());
} else {
cell.setCellValue("");
} }
} catch (NoSuchFieldException | IllegalAccessException e) { } catch (NoSuchFieldException | IllegalAccessException e) {
// 忽略不存在的字段 cell.setCellValue("");
}
}
}
public static void downloadAndZipImages(SurveyInformationDto surveyInfo) throws IOException {
Path templateDir = Paths.get(TEMPLATE_FILE_PATH).getParent();
System.out.println("模版文件所在目录是: " + templateDir);
Path tempDir = Files.createTempDirectory(TEMP_DIR_NAME);
try {
Files.createDirectories(tempDir.resolve(BASE_INFO_FOLDER));
System.out.println("Temporary directory created at: " + tempDir);
} catch (IOException e) {
e.printStackTrace();
return;
}
Path baseInfoPath = tempDir.resolve(BASE_INFO_FOLDER);
try {
Files.createDirectories(baseInfoPath);
System.out.println("Base info directory created at: " + baseInfoPath);
} catch (IOException e) {
e.printStackTrace();
return;
}
List<Field> listFields = getAllListFields(surveyInfo.getClass());
for (Field field : listFields) {
try {
@SuppressWarnings("unchecked")
List<Object> list = (List<Object>) FieldUtils.readField(field, surveyInfo, true); // 读取字段值
for (Object item : list) {
if (item instanceof Map) {
Map<String, Object> map = (Map<String, Object>) item;
if (map.containsKey("url") && map.get("url") instanceof String) {
String imageUrl = "http://47.92.234.253:8088"+(String) map.get("url");
downloadAndSaveImage(imageUrl, baseInfoPath);
}
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
createZipFile(baseInfoPath, ZIP_FILE_PATH);
cleanup(tempDir);
}
private static void downloadAndSaveImage(String imageUrl, Path savePath) {
try (InputStream in = new URL(imageUrl).openStream()) {
String fileName = imageUrl.substring(imageUrl.lastIndexOf('/') + 1);
Path imagePath = savePath.resolve(fileName);
FileUtils.copyInputStreamToFile(in, imagePath.toFile());
} catch (IOException e) {
e.printStackTrace();
}
}
private static void createZipFile(Path folderPath, String zipFilePath) {
try (FileOutputStream fos = new FileOutputStream(zipFilePath);
ZipOutputStream zos = new ZipOutputStream(fos)) {
addFolderToZip("", folderPath, zos);
} catch (IOException e) {
e.printStackTrace();
}
}
private static void addFolderToZip(String relativePath, Path folderPath, ZipOutputStream zos) throws IOException {
if (!Files.exists(folderPath)) {
return;
}
Files.walk(folderPath).forEach(filePath -> {
try {
String entryName = relativePath + folderPath.relativize(filePath).toString();
ZipEntry zipEntry = new ZipEntry(entryName);
zos.putNextEntry(zipEntry);
try (FileInputStream fis = new FileInputStream(filePath.toFile())) {
IOUtils.copy(fis, zos);
}
zos.closeEntry();
} catch (IOException e) {
e.printStackTrace();
}
});
}
private static 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;
}
public static List<String> extractUrls(SurveyInformationDto surveyInfo) {
List<String> urls = new ArrayList<>();
// 获取所有类型为List<Object>的字段
List<Field> listFields = getAllListFields(surveyInfo.getClass());
for (Field field : listFields) {
try {
@SuppressWarnings("unchecked")
List<Object> list = (List<Object>) FieldUtils.readField(field, surveyInfo, true);
// 从List<Object>中提取url值
for (Object item : list) {
if (item instanceof Map) {
Map<String, Object> map = (Map<String, Object>) item;
if (map.containsKey("url") && map.get("url") instanceof String) {
urls.add("http://47.92.234.253:8088"+(String) map.get("url"));
}
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return urls;
}
private static List<Field> getAllListFields(Class<?> clazz) {
List<Field> fields = new ArrayList<>();
Class<?> currentClass = clazz;
while (currentClass != null) {
for (Field field : currentClass.getDeclaredFields()) {
if (List.class.isAssignableFrom(field.getType())) {
fields.add(field);
} }
} }
currentClass = currentClass.getSuperclass();
}
return fields;
}
} }
\ No newline at end of file
}
\ No newline at end of file
...@@ -769,38 +769,38 @@ public class SurveyInformationServiceImpl ...@@ -769,38 +769,38 @@ public class SurveyInformationServiceImpl
} }
surveyInfoAllDto.setAcceptanceCheck(acceptanceCheck); surveyInfoAllDto.setAcceptanceCheck(acceptanceCheck);
if (!StringUtils.isEmpty(processInstanceId)) { // if (!StringUtils.isEmpty(processInstanceId)) {
try { // try {
Map<String, Object> flowLoggerMap = workflowFeignClient.getFlowLogger(processInstanceId).getResult(); // Map<String, Object> flowLoggerMap = workflowFeignClient.getFlowLogger(processInstanceId).getResult();
List<LinkedHashMap> flowLogger = (List<LinkedHashMap>) flowLoggerMap.get("flowLogger"); // List<LinkedHashMap> flowLogger = (List<LinkedHashMap>) flowLoggerMap.get("flowLogger");
if (flowLogger.size() > 0) { // if (flowLogger.size() > 0) {
Collections.reverse(flowLogger); // Collections.reverse(flowLogger);
} // }
List<LinkedHashMap> flowLoggernew = new ArrayList<>(); // List<LinkedHashMap> flowLoggernew = new ArrayList<>();
for (LinkedHashMap linkedHashMap : flowLogger) { // for (LinkedHashMap linkedHashMap : flowLogger) {
if (linkedHashMap.get("operateDate") != null // if (linkedHashMap.get("operateDate") != null
&& !linkedHashMap.get("operateDate").toString().isEmpty()) { // && !linkedHashMap.get("operateDate").toString().isEmpty()) {
LinkedHashMap linke = new LinkedHashMap(); // LinkedHashMap linke = new LinkedHashMap();
linke.put("approvalStatue", linkedHashMap.get("approvalStatue").toString()); // linke.put("approvalStatue", linkedHashMap.get("approvalStatue").toString());
// 审核意见 // // 审核意见
List<LinkedHashMap> approvalSuggestion = (List<LinkedHashMap>) linkedHashMap // List<LinkedHashMap> approvalSuggestion = (List<LinkedHashMap>) linkedHashMap
.get("approvalSuggestion"); // .get("approvalSuggestion");
if (approvalSuggestion != null && !approvalSuggestion.isEmpty()) { // if (approvalSuggestion != null && !approvalSuggestion.isEmpty()) {
linke.put("approvalSuggestion", approvalSuggestion.get(0).get("message")); // linke.put("approvalSuggestion", approvalSuggestion.get(0).get("message"));
} // }
linke.put("taskName", linkedHashMap.get("taskName").toString()); // linke.put("taskName", linkedHashMap.get("taskName").toString());
linke.put("operator", linkedHashMap.get("operator").toString()); // linke.put("operator", linkedHashMap.get("operator").toString());
linke.put("operateDate", linkedHashMap.get("operateDate").toString()); // linke.put("operateDate", linkedHashMap.get("operateDate").toString());
flowLoggernew.add(linke); // flowLoggernew.add(linke);
} // }
} // }
LoggerDto loggerDto = new LoggerDto(); // LoggerDto loggerDto = new LoggerDto();
loggerDto.setLogger(flowLoggernew); // loggerDto.setLogger(flowLoggernew);
surveyInfoAllDto.setOrderTracking(loggerDto); // surveyInfoAllDto.setOrderTracking(loggerDto);
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
return surveyInfoAllDto; return surveyInfoAllDto;
......
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