|
|
|
|
@ -1,19 +1,27 @@
|
|
|
|
|
package com.biutag.lan.service; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
|
import com.alibaba.excel.write.builder.ExcelWriterBuilder; |
|
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.biutag.entity.system.Dept; |
|
|
|
|
import com.biutag.lan.domain.*; |
|
|
|
|
import com.biutag.lan.domain.vo.LedgerExcel; |
|
|
|
|
import com.biutag.lan.mapper.*; |
|
|
|
|
import com.biutag.lan.validate.system.DataSearchValidate; |
|
|
|
|
import com.biutag.mapper.system.DeptMapper; |
|
|
|
|
import jakarta.annotation.Resource; |
|
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.OutputStream; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
@ -359,4 +367,98 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
|
|
|
|
|
return headerlist; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void exportdata(HttpServletResponse response, DataSearchValidate dataSearchValidate) throws IOException { |
|
|
|
|
List<List<String>> head = new ArrayList<>(); |
|
|
|
|
List<String> headLevelOne = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
head.add(List.of("局长信箱即接即办信件三率统计","单位名称")); |
|
|
|
|
head.add(List.of("局长信箱即接即办信件三率统计","信件总量")); |
|
|
|
|
head.add(List.of("局长信箱即接即办信件三率统计","办结数")); |
|
|
|
|
head.add(List.of("局长信箱即接即办信件三率统计","办结率")); |
|
|
|
|
head.add(List.of("局长信箱即接即办信件三率统计","解决数")); |
|
|
|
|
head.add(List.of("局长信箱即接即办信件三率统计","解决率")); |
|
|
|
|
head.add(List.of("局长信箱即接即办信件三率统计","满意数")); |
|
|
|
|
head.add(List.of("局长信箱即接即办信件三率统计","满意率")); |
|
|
|
|
head.add(List.of("局长信箱即接即办信件三率统计","总得分")); |
|
|
|
|
List<Map<String,Object>> list = new ArrayList<>(); |
|
|
|
|
List<List<Object>> data1 = new ArrayList<>(); |
|
|
|
|
list = list(new Page<>(1, 10000),dataSearchValidate).getRecords(); |
|
|
|
|
for (Map<String ,Object> item : list){ |
|
|
|
|
data1.add(Arrays.asList(item.get("cname"), item.get("total"),item.get("completed"),item.get("crate"),item.get("resolved"),item.get("rate"),item.get("satisfied"),item.get("srate"),item.get("score"))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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).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."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void exportsource(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."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |