Browse Source

信件统计导出

master
laishajiang 2 years ago
parent
commit
1a7511af89
  1. 7
      mailbox-lan/src/main/java/com/biutag/lan/controller/DataController.java
  2. 54
      mailbox-lan/src/main/java/com/biutag/lan/service/DataService.java

7
mailbox-lan/src/main/java/com/biutag/lan/controller/DataController.java

@ -74,5 +74,10 @@ public class DataController {
DataSearchValidate dataSearchValidate = JSON.parseObject(data,DataSearchValidate.class); DataSearchValidate dataSearchValidate = JSON.parseObject(data,DataSearchValidate.class);
dataService.exportsource(response, dataSearchValidate); dataService.exportsource(response, dataSearchValidate);
} }
@NotPower
@PostMapping("exportcategory")
public void exportcategory(HttpServletResponse response, @RequestBody String data) throws IOException {
DataSearchValidate dataSearchValidate = JSON.parseObject(data,DataSearchValidate.class);
dataService.exportcategory(response, dataSearchValidate);
}
} }

54
mailbox-lan/src/main/java/com/biutag/lan/service/DataService.java

@ -461,4 +461,58 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
} }
} }
} }
public void exportcategory(HttpServletResponse response, DataSearchValidate dataSearchValidate) throws IOException {
List<List<String>> head = new ArrayList<>();
List<Map<String,Object>> list = new ArrayList<>();
List<List<Object>> data1 = new ArrayList<>();
List<String> variables = new ArrayList<>();
list = getsourcelist(new Page<>(1, 10000),dataSearchValidate).getRecords();
System.out.println(list);
Map<String ,Object> item_one = list.get(0);
for (Map.Entry<String, Object> entry : item_one.entrySet()) {
// 获取键和值
String key = entry.getKey();
Object value = entry.getValue();
// 打印键和值
if (key.contains("name")&&!key.contains("second_dept_name")){
variables.add(value.toString());
}
}
head.add(List.of("局长信箱即接即办信件来源统计","单位名称","单位名称"));
head.add(List.of("局长信箱即接即办信件来源统计","信件总量","信件总量"));
for (int i = 0;i<variables.size();i++){
head.add(List.of("局长信箱即接即办信件来源统计",variables.get(i),"数量"));
head.add(List.of("局长信箱即接即办信件来源统计",variables.get(i),"占比"));
}
for (Map<String ,Object> item : list){
List<Object> list_item = new ArrayList<>();
list_item.add(item.get("second_dept_name1"));
list_item.add(item.get("allcount1"));
for (int i = 0;i<variables.size();i++){
System.out.println("EEEEEEEEEEEEEEEE"+variables.size());
System.out.println("EEEEEEEEEEEEEEEE"+item.get("countrate"+(i + 1)));
list_item.add(item.get("sumcount"+(i + 1)));
list_item.add(item.get("countrate"+(i + 1)));
}
data1.add(list_item);
}
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("UTF-8");
try (OutputStream out = response.getOutputStream()) {
// 使用EasyExcel写入数据到输出流
ExcelWriter excelWriter = EasyExcel.write(out).build();
WriteSheet writeSheet = EasyExcel.writerSheet("局长信箱即接即办信件三率统计").head(head).automaticMergeHead(true).build();
excelWriter.write(data1, writeSheet);
excelWriter.finish();
} catch (Exception e) {
log.error("Exception occurred while exporting mail data" + e.getMessage(), e);
// 如果response还没有被提交,返回一个错误信息
if (!response.isCommitted()) {
response.reset();
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.getWriter().write("Failed to export data due to an internal error.");
}
}
}
} }
Loading…
Cancel
Save