Commit 4bbf8e5d authored by chenzhao's avatar chenzhao

资料下载

parent 4ca91033
......@@ -11,6 +11,7 @@ import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.hygf.api.Enum.BusinessTypeEnum;
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.TaskModelDto;
import com.yeejoin.amos.boot.module.hygf.api.util.JsonUtils;
import com.yeejoin.amos.boot.module.hygf.biz.feign.TaskV2FeignService;
......@@ -32,7 +33,12 @@ import java.lang.reflect.Modifier;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
/**
* 公共服务实现类
*
......@@ -48,7 +54,8 @@ public class CommonServiceImpl {
private RedisUtils redisUtils;
@Value("classpath:/json/urlInfo.json")
private Resource urlInfo;
@Autowired
SurveyInformationServiceImpl surveyInformationServiceImpl;
private static final String regionRedis = "app_region_redis";
@Autowired
RedisUtils redisUtil;
......@@ -403,4 +410,61 @@ public class CommonServiceImpl {
}
return jsonArray;
}
public void downZiliao(String surveyInformationId, String peasantHouseholdId, String processInstanceId) {
SurveyInfoAllDto returnDto = surveyInformationServiceImpl.querySurveyInfo(surveyInformationId, peasantHouseholdId, processInstanceId, null);
// 读取Excel模板
String templatePath = "path/to/informationTemp.xlsx";
String outputPath = "path/to/filled_informationTemp.xlsx";
Workbook workbook = null;
try (FileInputStream fis = new FileInputStream(templatePath)) {
workbook = new XSSFWorkbook(fis);
// 处理第一个工作表
Sheet firstSheet = workbook.getSheetAt(0);
fillSheet(firstSheet, returnDto.getSurveyInformation());
// 处理第二个工作表
Sheet secondSheet = workbook.getSheetAt(1);
fillSheet(secondSheet, returnDto.getSurveyDetails());
// 写入到新的Excel文件中
try (FileOutputStream fos = new FileOutputStream(outputPath)) {
workbook.write(fos);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 辅助方法用来填充工作表。
*
* @param sheet 要填充的工作表
* @param data 数据源
*/
private void fillSheet(Sheet sheet, Object data) {
// 遍历每一行
for (Row row : sheet) {
// 遍历每一个单元格
for (Cell cell : row) {
if (cell.getCellType() == CellType.STRING) {
String cellValue = cell.getStringCellValue();
try {
// 尝试获取字段值
Field field = data.getClass().getDeclaredField(cellValue);
field.setAccessible(true); // 设置为可访问私有字段
Object value = field.get(data);
if (value != null) {
cell.setCellValue(value.toString());
}
} catch (NoSuchFieldException | IllegalAccessException e) {
// 忽略不存在的字段
}
}
}
}
}
}
\ 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