diff --git a/mailbox-lan/src/main/java/com/biutag/lan/controller/DataController.java b/mailbox-lan/src/main/java/com/biutag/lan/controller/DataController.java index a5bfb4f..9a26d81 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/controller/DataController.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/controller/DataController.java @@ -44,11 +44,16 @@ public class DataController { @NotPower @GetMapping("listForCategory") - public AjaxResult> > listForCategory(Page page, @Validated DataSearchValidate searchValidate) { + public AjaxResult> > listForCategory(Page page,DataSearchValidate searchValidate) { Page> list = dataService.listForCategory(page, searchValidate); return AjaxResult.success(list); } - + @NotPower + @GetMapping("listForCategoryHeader") + public AjaxResult> > listForCategoryHeader(DataSearchValidate searchValidate) { + List> list = dataService.listForCategoryHeader(searchValidate); + return AjaxResult.success(list); + } @NotPower @GetMapping("getsourcelist") public AjaxResult> > getsourcelist(Page page, @Validated DataSearchValidate searchValidate) { diff --git a/mailbox-lan/src/main/java/com/biutag/lan/mapper/DataMapper.java b/mailbox-lan/src/main/java/com/biutag/lan/mapper/DataMapper.java index c13c631..28a985a 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/mapper/DataMapper.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/mapper/DataMapper.java @@ -20,7 +20,7 @@ public interface DataMapper extends BaseMapper { List> getThirdList(Page page,@Param("searchStartTime") String searchStartTime,@Param("searchEndTime") String searchEndTime,@Param("deptId") String deptId); - List> selectMailCategoryWithCount(@Param("deptId") String deptId,@Param("deptName") String deptName,@Param("searchStartTime") String searchStartTime,@Param("searchEndTime") String searchEndTime); + List> selectMailCategoryWithCount(@Param("deptId") String deptId,@Param("deptName") String deptName,@Param("searchStartTime") String searchStartTime,@Param("searchEndTime") String searchEndTime,@Param("categorylevel") String categorylevel); List> selectMailFirstCategoryWithCount(@Param("searchStartTime") String searchStartTime,@Param("searchEndTime") String searchEndTime); diff --git a/mailbox-lan/src/main/java/com/biutag/lan/service/DataService.java b/mailbox-lan/src/main/java/com/biutag/lan/service/DataService.java index 119efb8..68bcb85 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/service/DataService.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/DataService.java @@ -13,6 +13,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import javax.swing.*; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -67,69 +68,85 @@ public class DataService extends ServiceImpl { public Page> listForCategory(Page page, DataSearchValidate searchValidate) { List deptslist = null; - List> list = new ArrayList<>(); + List> datalist = new ArrayList<>(); if (searchValidate.getEasydept()==null||searchValidate.getEasydept().equals("1")){ - List> categorylist = baseMapper.selectMailFirstCategoryWithCount(searchValidate.getSearchStartTime(),searchValidate.getSearchEndTime()); - list.add(getCategoryCountMap(categorylist)); + List> categorylist_first = baseMapper.selectMailFirstCategoryWithCount(searchValidate.getSearchStartTime(),searchValidate.getSearchEndTime()); + datalist.add(getCategoryDataMap(categorylist_first)); Wrapper wrapper2 = new QueryWrapper<>().eq("level",2); deptslist = deptMapper.selectPage(page,wrapper2).getRecords(); for(Dept deptItem :deptslist){ - List> categorylistforsecond = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); - list.add(getCategoryCountMap(categorylistforsecond)); + List> categorylist_second = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime(),null); + datalist.add(getCategoryDataMap(categorylist_second)); } - }else if (searchValidate.getEasydept().equals("2")){ if (searchValidate.getSdept()==null){ Wrapper wrapper2 = new QueryWrapper<>().eq("level",2); deptslist = deptMapper.selectPage(page,wrapper2).getRecords(); for(Dept deptItem :deptslist){ - List> categorylist = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); - list.add(getCategoryCountMap(categorylist)); - + List> categorylist_second = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime(),null); + datalist.add(getCategoryDataMap(categorylist_second)); } - }else{ Wrapper wrapper2 = new QueryWrapper<>().eq("level",2).eq("id",searchValidate.getSdept()); deptslist = deptMapper.selectPage(page,wrapper2).getRecords(); for(Dept deptItem :deptslist){ - List> categorylist = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); - list.add(getCategoryCountMap(categorylist)); - + List> categorylist_second = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime(),null); + datalist.add(getCategoryDataMap(categorylist_second)); } Wrapper wrapper3 = new QueryWrapper<>().eq("level",3).eq("pid",searchValidate.getSdept()); deptslist = deptMapper.selectPage(page,wrapper3).getRecords(); for(Dept deptItem :deptslist){ - List> categorylist = baseMapper.selectMailThreeCategoryWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); - list.add(getCategoryCountMap(categorylist)); - + List> categorylist_three = baseMapper.selectMailThreeCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime()); + datalist.add(getCategoryDataMap(categorylist_three)); } } } Page> dataVoPage = new Page<>(); - dataVoPage.setRecords(getSortList(list)); + dataVoPage.setRecords(getCategorySortList(datalist)); dataVoPage.setTotal(page.getTotal()); dataVoPage.setCurrent(page.getCurrent()); dataVoPage.setSize(page.getSize()); dataVoPage.setPages(page.getPages()); return dataVoPage; + } - + private Map getCategoryDataMap(List> categorylist) { + Map map = new HashMap<>(); + map.put("second_dept_name",categorylist.get(0).get("second_dept_name")); + map.put("allcount",categorylist.get(0).get("allcount")); + for (Map item :categorylist){ + map.put("countrate"+item.get("key"),item.get("countrate")); + map.put("sumcount"+item.get("key"),item.get("sumcount")); + } + return map; } - private List> getSortList(List> list) { + private List> getCategorySortList(List> list) { + Collections.sort(list, new Comparator>() { + @Override + public int compare(Map o1, Map o2) { + // 假设"value"对应的value是可以比较的(例如Integer, Double等) + Comparable value1 = (Comparable) o1.get("allcount"); + Comparable value2 = (Comparable) o2.get("allcount"); + // 按"value"升序排序 + return value2.compareTo(value1); + } + }); + return list; + } + private List> getSourceSortList(List> list) { Collections.sort(list, new Comparator>() { @Override public int compare(Map o1, Map o2) { // 假设"value"对应的value是可以比较的(例如Integer, Double等) Comparable value1 = (Comparable) o1.get("allcount1"); Comparable value2 = (Comparable) o2.get("allcount1"); - // 按"value"升序排序 return value2.compareTo(value1); } }); - return list; + return list; } public Page> getsourcelist(Page page, DataSearchValidate searchValidate) { @@ -171,7 +188,7 @@ public class DataService extends ServiceImpl { } } Page> dataVoPage = new Page<>(); - dataVoPage.setRecords(getSortList(list)); + dataVoPage.setRecords(getSourceSortList(list)); dataVoPage.setTotal(page.getTotal()); dataVoPage.setCurrent(page.getCurrent()); dataVoPage.setSize(page.getSize()); @@ -180,19 +197,86 @@ public class DataService extends ServiceImpl { } - public Map getCategoryCountMap(List> categorylist){ - int keycount = 1; - Map map = new HashMap<>(); - for (Map item :categorylist){ - map.put("countrate"+keycount,item.get("countrate")); - map.put("sumcount"+keycount,item.get("sumcount")); - map.put("name"+keycount,item.get("name")); - map.put("second_dept_name"+keycount,item.get("second_dept_name")); - map.put("allcount"+keycount,item.get("allcount")); - keycount++; + public List> getCategoryHeaderMap(List> fathercategorylist,List> firstchildren,List> secondchildren){ + List> list = new ArrayList<>(); + List> firstchildrenlist = new ArrayList<>(); + Map map1 = new HashMap<>(); + Map map2 = new HashMap<>(); + map1.put("label","单位名称"); + map1.put("prop","second_dept_name"); + map2.put("label","信件总量"); + map2.put("prop","allcount"); + list.add(map1); + list.add(map2); + for (Map item :fathercategorylist){ + Map father_map = new HashMap<>(); + List> children = new ArrayList<>(); + father_map.put("label",item.get("name")); + father_map.put("key",item.get("key")); + father_map.put("children",new ArrayList>()); + list.add(father_map); + } + for (Map item :firstchildren){ + Map firstchildren_map = new HashMap<>(); + firstchildren_map.put("label",item.get("name")); + firstchildren_map.put("key",item.get("key")); + firstchildren_map.put("children",new ArrayList>()); + for (Map father_item :list){ + if (item.get("parent_key").equals(father_item.get("key"))){ + ((List>)father_item.get("children")).add(firstchildren_map); + } + } + firstchildrenlist.add(firstchildren_map); } - return map; - } + for (Map father_item :list){ + if (father_item.get("children")!=null&&((List>)father_item.get("children")).size()==0){ + Map data_map1 = new HashMap<>(); + Map data_map2 = new HashMap<>(); + data_map1.put("label","数量"); + data_map1.put("prop","sumcount"+father_item.get("key")); + data_map2.put("label","占比"); + data_map2.put("prop","countrate"+father_item.get("key")); + ((List>)father_item.get("children")).add(data_map1); + ((List>)father_item.get("children")).add(data_map2); + } + } + + for (Map item :secondchildren){ + Map secondchildren_map = new HashMap<>(); + Map data_map1 = new HashMap<>(); + Map data_map2 = new HashMap<>(); + data_map1.put("label","数量"); + data_map1.put("prop","sumcount"+item.get("key")); + data_map2.put("label","占比"); + data_map2.put("prop","countrate"+item.get("key")); + List> children = new ArrayList<>(); + secondchildren_map.put("label",item.get("name")); + children.add(data_map1); + children.add(data_map2); + secondchildren_map.put("children",children); + for (Map father_item :firstchildrenlist){ + if (item.get("parent_key").equals(father_item.get("key"))){ + ((List>)father_item.get("children")).add(secondchildren_map); + } + } + } + for (Map father_item :firstchildrenlist){ + if (father_item.get("children")!=null&&((List>)father_item.get("children")).size()==0){ + Map data_map1 = new HashMap<>(); + Map data_map2 = new HashMap<>(); + data_map1.put("label","数量"); + data_map1.put("prop","sumcount"+father_item.get("key")); + data_map2.put("label","占比"); + data_map2.put("prop","countrate"+father_item.get("key")); + ((List>)father_item.get("children")).add(data_map1); + ((List>)father_item.get("children")).add(data_map2); + } + } + return list; + } + + + public Map getSourceCountMap(List> categorylist){ int keycount = 1; @@ -208,4 +292,18 @@ public class DataService extends ServiceImpl { } return map; } + + public List> listForCategoryHeader(DataSearchValidate searchValidate) { + List deptslist = null; + List> headerlist = new ArrayList<>(); + Wrapper wrapper2 = new QueryWrapper<>().eq("level",2); + deptslist = deptMapper.selectList(wrapper2); + Dept deptItem =deptslist.get(0); + List> categorylist1 = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime(),"1"); + List> categorylist2 = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime(),"2"); + List> categorylist3 = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime(),"3"); + headerlist = getCategoryHeaderMap(categorylist1,categorylist2,categorylist3); + return headerlist; + } + } \ No newline at end of file diff --git a/mailbox-lan/src/main/resources/mapper/DataMapper.xml b/mailbox-lan/src/main/resources/mapper/DataMapper.xml index d0cffbc..322e8d4 100644 --- a/mailbox-lan/src/main/resources/mapper/DataMapper.xml +++ b/mailbox-lan/src/main/resources/mapper/DataMapper.xml @@ -234,7 +234,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"