Browse Source

信件来源统计

master
laishajiang 2 years ago
parent
commit
fd6dbcbac7
  1. 6
      mailbox-lan/src/main/java/com/biutag/lan/controller/DataController.java
  2. 114
      mailbox-lan/src/main/java/com/biutag/lan/service/DataService.java

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

@ -61,6 +61,12 @@ public class DataController {
Page<Map<String, Object>> list = dataService.getsourcelist(page, searchValidate); Page<Map<String, Object>> list = dataService.getsourcelist(page, searchValidate);
return AjaxResult.success(list); return AjaxResult.success(list);
} }
@NotPower
@GetMapping("listForSourceHeader")
public AjaxResult<List<Map<String, Object>> > listForSourceHeader(DataSearchValidate searchValidate) {
List<Map<String, Object>> list = dataService.listForSourceHeader(searchValidate);
return AjaxResult.success(list);
}
@NotPower @NotPower
@PostMapping("exportdata") @PostMapping("exportdata")

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

@ -157,6 +157,17 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
return map; return map;
} }
private Map<String, Object> getSourceDataMap(List<Map<String, Object>> sourcelist) {
Map<String,Object> map = new HashMap<>();
map.put("second_dept_name",sourcelist.get(0).get("second_dept_name"));
map.put("allcount",sourcelist.get(0).get("allcount"));
for (Map<String,Object> item :sourcelist){
map.put("countrate"+item.get("source"),item.get("countrate"));
map.put("sumcount"+item.get("source"),item.get("sumcount"));
}
return map;
}
private List<Map<String, Object>> getCategorySortList(List<Map<String, Object>> list) { private List<Map<String, Object>> getCategorySortList(List<Map<String, Object>> list) {
Collections.sort(list, new Comparator<Map<String, Object>>() { Collections.sort(list, new Comparator<Map<String, Object>>() {
@Override @Override
@ -170,13 +181,14 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
}); });
return list; return list;
} }
private List<Map<String, Object>> getSourceSortList(List<Map<String, Object>> list) { private List<Map<String, Object>> getSourceSortList(List<Map<String, Object>> list) {
Collections.sort(list, new Comparator<Map<String, Object>>() { Collections.sort(list, new Comparator<Map<String, Object>>() {
@Override @Override
public int compare(Map<String, Object> o1, Map<String, Object> o2) { public int compare(Map<String, Object> o1, Map<String, Object> o2) {
// 假设"value"对应的value是可以比较的(例如Integer, Double等) // 假设"value"对应的value是可以比较的(例如Integer, Double等)
Comparable value1 = (Comparable) o1.get("allcount1"); Comparable value1 = (Comparable) o1.get("allcount");
Comparable value2 = (Comparable) o2.get("allcount1"); Comparable value2 = (Comparable) o2.get("allcount");
// 按"value"升序排序 // 按"value"升序排序
return value2.compareTo(value1); return value2.compareTo(value1);
} }
@ -189,12 +201,12 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
List<Map<String,Object>> list = new ArrayList<>(); List<Map<String,Object>> list = new ArrayList<>();
if (searchValidate.getEasydept()==null||searchValidate.getEasydept().equals("1")){ if (searchValidate.getEasydept()==null||searchValidate.getEasydept().equals("1")){
List<Map<String,Object>> categorylist = baseMapper.selectFirstMailSourceWithCount(searchValidate.getSearchStartTime(),searchValidate.getSearchEndTime()); List<Map<String,Object>> categorylist = baseMapper.selectFirstMailSourceWithCount(searchValidate.getSearchStartTime(),searchValidate.getSearchEndTime());
list.add(getSourceCountMap(categorylist)); list.add(getSourceDataMap(categorylist));
Wrapper wrapper2 = new QueryWrapper<>().eq("level",2); Wrapper wrapper2 = new QueryWrapper<>().eq("level",2);
deptslist = deptMapper.selectPage(page,wrapper2).getRecords(); deptslist = deptMapper.selectPage(page,wrapper2).getRecords();
for(Dept deptItem :deptslist){ for(Dept deptItem :deptslist){
List<Map<String,Object>> categorylistforsecond = baseMapper.selectSecondMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); List<Map<String,Object>> categorylistforsecond = baseMapper.selectSecondMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
list.add(getSourceCountMap(categorylistforsecond)); list.add(getSourceDataMap(categorylistforsecond));
} }
}else if (searchValidate.getEasydept().equals("2")){ }else if (searchValidate.getEasydept().equals("2")){
if (searchValidate.getSdept()==null){ if (searchValidate.getSdept()==null){
@ -202,8 +214,7 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
deptslist = deptMapper.selectPage(page,wrapper2).getRecords(); deptslist = deptMapper.selectPage(page,wrapper2).getRecords();
for(Dept deptItem :deptslist){ for(Dept deptItem :deptslist){
List<Map<String,Object>> categorylist = baseMapper.selectSecondMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); List<Map<String,Object>> categorylist = baseMapper.selectSecondMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
list.add(getSourceDataMap(categorylist));
list.add(getSourceCountMap(categorylist));
} }
}else{ }else{
@ -211,13 +222,13 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
deptslist = deptMapper.selectPage(page,wrapper2).getRecords(); deptslist = deptMapper.selectPage(page,wrapper2).getRecords();
for(Dept deptItem :deptslist){ for(Dept deptItem :deptslist){
List<Map<String,Object>> categorylist = baseMapper.selectSecondMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); List<Map<String,Object>> categorylist = baseMapper.selectSecondMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
list.add(getSourceCountMap(categorylist)); list.add(getSourceDataMap(categorylist));
} }
Wrapper wrapper3 = new QueryWrapper<>().eq("level",3).eq("pid",searchValidate.getSdept()); Wrapper wrapper3 = new QueryWrapper<>().eq("level",3).eq("pid",searchValidate.getSdept());
deptslist = deptMapper.selectPage(page,wrapper3).getRecords(); deptslist = deptMapper.selectPage(page,wrapper3).getRecords();
for(Dept deptItem :deptslist){ for(Dept deptItem :deptslist){
List<Map<String,Object>> categorylist = baseMapper.selectThreeMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); List<Map<String,Object>> categorylist = baseMapper.selectThreeMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
list.add(getSourceCountMap(categorylist)); list.add(getSourceDataMap(categorylist));
} }
} }
}else if (searchValidate.getEasydept().equals("3")){ }else if (searchValidate.getEasydept().equals("3")){
@ -233,7 +244,7 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
deptslist = deptMapper.selectPage(page,wrapper2).getRecords(); deptslist = deptMapper.selectPage(page,wrapper2).getRecords();
for(Dept deptItem :deptslist){ for(Dept deptItem :deptslist){
List<Map<String,Object>> categorylistforsecond = baseMapper.selectSecondMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); List<Map<String,Object>> categorylistforsecond = baseMapper.selectSecondMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
list.add(getSourceCountMap(categorylistforsecond)); list.add(getSourceDataMap(categorylistforsecond));
} }
}else if (searchValidate.getEasydept().equals("4")){ }else if (searchValidate.getEasydept().equals("4")){
Wrapper wrapper2 = new QueryWrapper<>().eq("level",2).and(wrapper -> wrapper Wrapper wrapper2 = new QueryWrapper<>().eq("level",2).and(wrapper -> wrapper
@ -245,7 +256,7 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
deptslist = deptMapper.selectPage(page,wrapper2).getRecords(); deptslist = deptMapper.selectPage(page,wrapper2).getRecords();
for(Dept deptItem :deptslist){ for(Dept deptItem :deptslist){
List<Map<String,Object>> categorylistforsecond = baseMapper.selectSecondMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); List<Map<String,Object>> categorylistforsecond = baseMapper.selectSecondMailSourceWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
list.add(getSourceCountMap(categorylistforsecond)); list.add(getSourceDataMap(categorylistforsecond));
} }
} }
Page<Map<String, Object>> dataVoPage = new Page<>(); Page<Map<String, Object>> dataVoPage = new Page<>();
@ -336,22 +347,34 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
return list; return list;
} }
public List<Map<String,Object>> getSourceHeaderMap(List<Map<String,Object>> sourcelist){
List<Map<String,Object>> list = new ArrayList<>();
List<Map<String,Object>> firstchildrenlist = new ArrayList<>();
public Map<String,Object> getSourceCountMap(List<Map<String,Object>> categorylist){ Map<String,Object> map1 = new HashMap<>();
int keycount = 1; Map<String,Object> map2 = new HashMap<>();
Map<String,Object> map = new HashMap<>(); map1.put("label","单位名称");
for (Map<String,Object> item :categorylist){ map1.put("prop","second_dept_name");
map.put("source"+keycount,item.get("source")); map2.put("label","信件总量");
map.put("countrate"+keycount,item.get("countrate")); map2.put("prop","allcount");
map.put("sumcount"+keycount,item.get("sumcount")); list.add(map1);
map.put("name"+keycount,item.get("name")); list.add(map2);
map.put("second_dept_name"+keycount,item.get("second_dept_name")); for (Map<String,Object> item :sourcelist){
map.put("allcount"+keycount,item.get("allcount")); Map<String,Object> father_map = new HashMap<>();
keycount++; List<Map<String,Object>> children = new ArrayList<>();
father_map.put("label",item.get("name"));
father_map.put("key",item.get("source"));
Map<String,Object> data_map1 = new HashMap<>();
Map<String,Object> data_map2 = new HashMap<>();
data_map1.put("label","数量");
data_map1.put("prop","sumcount"+item.get("source"));
data_map2.put("label","占比");
data_map2.put("prop","countrate"+item.get("source"));
children.add(data_map1);
children.add(data_map2);
father_map.put("children",children);
list.add(father_map);
} }
return map; return list;
} }
public List<Map<String, Object>> listForCategoryHeader(DataSearchValidate searchValidate) { public List<Map<String, Object>> listForCategoryHeader(DataSearchValidate searchValidate) {
@ -367,6 +390,14 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
return headerlist; return headerlist;
} }
public List<Map<String, Object>> listForSourceHeader(DataSearchValidate searchValidate) {
List<Map<String,Object>> headerlist = new ArrayList<>();
List<Map<String,Object>> sourcelist = baseMapper.selectFirstMailSourceWithCount(searchValidate.getSearchStartTime(),searchValidate.getSearchEndTime());
headerlist = getSourceHeaderMap(sourcelist);
return headerlist;
}
public void exportdata(HttpServletResponse response, DataSearchValidate dataSearchValidate) throws IOException { public void exportdata(HttpServletResponse response, DataSearchValidate dataSearchValidate) throws IOException {
List<List<String>> head = new ArrayList<>(); List<List<String>> head = new ArrayList<>();
List<String> headLevelOne = new ArrayList<>(); List<String> headLevelOne = new ArrayList<>();
@ -407,37 +438,35 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
} }
public void exportsource(HttpServletResponse response, DataSearchValidate dataSearchValidate) throws IOException { public void exportsource(HttpServletResponse response, DataSearchValidate dataSearchValidate) throws IOException {
List<List<String>> head = new ArrayList<>(); List<List<String>> head = new ArrayList<>();
List<Map<String,Object>> headerlist = new ArrayList<>();
List<Map<String,Object>> list = new ArrayList<>(); List<Map<String,Object>> list = new ArrayList<>();
List<List<Object>> data1 = new ArrayList<>(); List<List<Object>> data1 = new ArrayList<>();
List<String> variables = new ArrayList<>(); List<String> variables = new ArrayList<>();
headerlist = listForSourceHeader(dataSearchValidate);
list = getsourcelist(new Page<>(1, 10000),dataSearchValidate).getRecords(); list = getsourcelist(new Page<>(1, 10000),dataSearchValidate).getRecords();
System.out.println(list); System.out.println(list);
Map<String ,Object> item_one = list.get(0); 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("局长信箱即接即办信件来源统计","单位名称","单位名称"));
head.add(List.of("局长信箱即接即办信件来源统计","信件总量","信件总量")); head.add(List.of("局长信箱即接即办信件来源统计","信件总量","信件总量"));
for (int i = 0;i<variables.size();i++){ for(int father = 2;father<headerlist.size();father++){
head.add(List.of("局长信箱即接即办信件来源统计",variables.get(i),"数量")); for (int firstchildren = 0;firstchildren<((List<Map<String,Object>>)headerlist.get(father).get("children")).size();firstchildren++){
head.add(List.of("局长信箱即接即办信件来源统计",variables.get(i),"占比")); List<String> stringList = new ArrayList<>();
stringList.add("局长信箱即接即办信件来源统计");
stringList.add(headerlist.get(father).get("label").toString());
stringList.add(((List<Map<String,Object>>) headerlist.get(father).get("children")).get(firstchildren).get("label").toString());
variables.add(((List<Map<String,Object>>)headerlist.get(father).get("children")).get(firstchildren).get("prop").toString());
head.add(stringList);
}
} }
for (Map<String ,Object> item : list){ for (Map<String ,Object> item : list){
List<Object> list_item = new ArrayList<>(); List<Object> list_item = new ArrayList<>();
list_item.add(item.get("second_dept_name1")); list_item.add(item.get("second_dept_name"));
list_item.add(item.get("allcount1")); list_item.add(item.get("allcount"));
for (int i = 0;i<variables.size();i++){ for (int i = 0;i<variables.size();i++){
list_item.add(item.get("sumcount"+(i + 1))); list_item.add(item.get(variables.get(i)));
list_item.add(item.get("countrate"+(i + 1)));
} }
data1.add(list_item); data1.add(list_item);
} }
@ -554,4 +583,5 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
} }
} }
} }
Loading…
Cancel
Save