Browse Source

信件类别小类统计

master
laishajiang 2 years ago
parent
commit
ea50831006
  1. 9
      mailbox-lan/src/main/java/com/biutag/lan/controller/DataController.java
  2. 2
      mailbox-lan/src/main/java/com/biutag/lan/mapper/DataMapper.java
  3. 166
      mailbox-lan/src/main/java/com/biutag/lan/service/DataService.java
  4. 34
      mailbox-lan/src/main/resources/mapper/DataMapper.xml

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

@ -44,11 +44,16 @@ public class DataController {
@NotPower
@GetMapping("listForCategory")
public AjaxResult<Page<Map<String, Object>> > listForCategory(Page page, @Validated DataSearchValidate searchValidate) {
public AjaxResult<Page<Map<String, Object>> > listForCategory(Page page,DataSearchValidate searchValidate) {
Page<Map<String, Object>> list = dataService.listForCategory(page, searchValidate);
return AjaxResult.success(list);
}
@NotPower
@GetMapping("listForCategoryHeader")
public AjaxResult<List<Map<String, Object>> > listForCategoryHeader(DataSearchValidate searchValidate) {
List<Map<String, Object>> list = dataService.listForCategoryHeader(searchValidate);
return AjaxResult.success(list);
}
@NotPower
@GetMapping("getsourcelist")
public AjaxResult<Page<Map<String, Object>> > getsourcelist(Page page, @Validated DataSearchValidate searchValidate) {

2
mailbox-lan/src/main/java/com/biutag/lan/mapper/DataMapper.java

@ -20,7 +20,7 @@ public interface DataMapper extends BaseMapper<Mail> {
List<Map<String, Object>> getThirdList(Page page,@Param("searchStartTime") String searchStartTime,@Param("searchEndTime") String searchEndTime,@Param("deptId") String deptId);
List<Map<String, Object>> selectMailCategoryWithCount(@Param("deptId") String deptId,@Param("deptName") String deptName,@Param("searchStartTime") String searchStartTime,@Param("searchEndTime") String searchEndTime);
List<Map<String, Object>> selectMailCategoryWithCount(@Param("deptId") String deptId,@Param("deptName") String deptName,@Param("searchStartTime") String searchStartTime,@Param("searchEndTime") String searchEndTime,@Param("categorylevel") String categorylevel);
List<Map<String, Object>> selectMailFirstCategoryWithCount(@Param("searchStartTime") String searchStartTime,@Param("searchEndTime") String searchEndTime);

166
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<DataMapper, Mail> {
public Page<Map<String, Object>> listForCategory(Page page, DataSearchValidate searchValidate) {
List<Dept> deptslist = null;
List<Map<String,Object>> list = new ArrayList<>();
List<Map<String,Object>> datalist = new ArrayList<>();
if (searchValidate.getEasydept()==null||searchValidate.getEasydept().equals("1")){
List<Map<String,Object>> categorylist = baseMapper.selectMailFirstCategoryWithCount(searchValidate.getSearchStartTime(),searchValidate.getSearchEndTime());
list.add(getCategoryCountMap(categorylist));
List<Map<String,Object>> 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<Map<String,Object>> categorylistforsecond = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
list.add(getCategoryCountMap(categorylistforsecond));
List<Map<String,Object>> 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<Map<String,Object>> categorylist = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
list.add(getCategoryCountMap(categorylist));
List<Map<String,Object>> 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<Map<String,Object>> categorylist = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
list.add(getCategoryCountMap(categorylist));
List<Map<String,Object>> 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<Map<String,Object>> categorylist = baseMapper.selectMailThreeCategoryWithCount(deptItem.getId().toString(),deptItem.getName(),searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
list.add(getCategoryCountMap(categorylist));
List<Map<String,Object>> categorylist_three = baseMapper.selectMailThreeCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime());
datalist.add(getCategoryDataMap(categorylist_three));
}
}
}
Page<Map<String, Object>> 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<String, Object> getCategoryDataMap(List<Map<String, Object>> categorylist) {
Map<String,Object> 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<String,Object> item :categorylist){
map.put("countrate"+item.get("key"),item.get("countrate"));
map.put("sumcount"+item.get("key"),item.get("sumcount"));
}
return map;
}
private List<Map<String, Object>> getSortList(List<Map<String, Object>> list) {
private List<Map<String, Object>> getCategorySortList(List<Map<String, Object>> list) {
Collections.sort(list, new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> 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<Map<String, Object>> getSourceSortList(List<Map<String, Object>> list) {
Collections.sort(list, new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> 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<Map<String, Object>> getsourcelist(Page page, DataSearchValidate searchValidate) {
@ -171,7 +188,7 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
}
}
Page<Map<String, Object>> 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<DataMapper, Mail> {
}
public Map<String,Object> getCategoryCountMap(List<Map<String,Object>> categorylist){
int keycount = 1;
Map<String,Object> map = new HashMap<>();
for (Map<String,Object> 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<Map<String,Object>> getCategoryHeaderMap(List<Map<String,Object>> fathercategorylist,List<Map<String,Object>> firstchildren,List<Map<String,Object>> secondchildren){
List<Map<String,Object>> list = new ArrayList<>();
List<Map<String,Object>> firstchildrenlist = new ArrayList<>();
Map<String,Object> map1 = new HashMap<>();
Map<String,Object> 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<String,Object> item :fathercategorylist){
Map<String,Object> father_map = new HashMap<>();
List<Map<String,Object>> children = new ArrayList<>();
father_map.put("label",item.get("name"));
father_map.put("key",item.get("key"));
father_map.put("children",new ArrayList<Map<String, Object>>());
list.add(father_map);
}
for (Map<String,Object> item :firstchildren){
Map<String,Object> firstchildren_map = new HashMap<>();
firstchildren_map.put("label",item.get("name"));
firstchildren_map.put("key",item.get("key"));
firstchildren_map.put("children",new ArrayList<Map<String, Object>>());
for (Map<String,Object> father_item :list){
if (item.get("parent_key").equals(father_item.get("key"))){
((List<Map<String,Object>>)father_item.get("children")).add(firstchildren_map);
}
}
firstchildrenlist.add(firstchildren_map);
}
return map;
}
for (Map<String,Object> father_item :list){
if (father_item.get("children")!=null&&((List<Map<String,Object>>)father_item.get("children")).size()==0){
Map<String,Object> data_map1 = new HashMap<>();
Map<String,Object> 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<Map<String,Object>>)father_item.get("children")).add(data_map1);
((List<Map<String,Object>>)father_item.get("children")).add(data_map2);
}
}
for (Map<String,Object> item :secondchildren){
Map<String,Object> secondchildren_map = new HashMap<>();
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("key"));
data_map2.put("label","占比");
data_map2.put("prop","countrate"+item.get("key"));
List<Map<String,Object>> 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<String,Object> father_item :firstchildrenlist){
if (item.get("parent_key").equals(father_item.get("key"))){
((List<Map<String,Object>>)father_item.get("children")).add(secondchildren_map);
}
}
}
for (Map<String,Object> father_item :firstchildrenlist){
if (father_item.get("children")!=null&&((List<Map<String,Object>>)father_item.get("children")).size()==0){
Map<String,Object> data_map1 = new HashMap<>();
Map<String,Object> 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<Map<String,Object>>)father_item.get("children")).add(data_map1);
((List<Map<String,Object>>)father_item.get("children")).add(data_map2);
}
}
return list;
}
public Map<String,Object> getSourceCountMap(List<Map<String,Object>> categorylist){
int keycount = 1;
@ -208,4 +292,18 @@ public class DataService extends ServiceImpl<DataMapper, Mail> {
}
return map;
}
public List<Map<String, Object>> listForCategoryHeader(DataSearchValidate searchValidate) {
List<Dept> deptslist = null;
List<Map<String,Object>> headerlist = new ArrayList<>();
Wrapper wrapper2 = new QueryWrapper<>().eq("level",2);
deptslist = deptMapper.selectList(wrapper2);
Dept deptItem =deptslist.get(0);
List<Map<String,Object>> categorylist1 = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime(),"1");
List<Map<String,Object>> categorylist2 = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime(),"2");
List<Map<String,Object>> categorylist3 = baseMapper.selectMailCategoryWithCount(deptItem.getId().toString(),deptItem.getName(), searchValidate.getSearchStartTime(), searchValidate.getSearchEndTime(),"3");
headerlist = getCategoryHeaderMap(categorylist1,categorylist2,categorylist3);
return headerlist;
}
}

34
mailbox-lan/src/main/resources/mapper/DataMapper.xml

@ -234,7 +234,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectMailCategoryWithCount" resultType="java.util.Map">
SELECT
mc.name,
mc.name,mc.key,mc.parent_key,mc.level,
COALESCE(m.second_dept_name, #{deptName}) As second_dept_name,
COALESCE( (SELECT COUNT(1) FROM mail where mail.second_dept_id = #{deptId}
<if test="searchStartTime != null and searchEndTime != null">
@ -246,7 +246,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mail_category mc
LEFT JOIN (
SELECT
mail_first_category AS category,
mail_category AS category,
COUNT(1) AS sumCount,
CONCAT(ROUND(COUNT(1) * 100.0 / (SELECT COUNT(1) FROM mail), 0), '%') AS countRate, mail.second_dept_name,mail.second_dept_id
FROM
@ -258,32 +258,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND mail.create_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if>
GROUP BY
mail_first_category, mail.second_dept_name,mail.second_dept_id
mail_category, mail.second_dept_name,mail.second_dept_id
) m ON mc.name = m.category
WHERE
<if test="categorylevel == 1">
WHERE
mc.level = 1;
</if>
<if test="categorylevel == 2">
WHERE
mc.level = 2;
</if>
<if test="categorylevel == 3">
WHERE
mc.level = 3;
</if>
</select>
<select id="selectMailFirstCategoryWithCount" resultType="java.util.Map">
SELECT mc.name,'长沙市公安局' as second_dept_name, COALESCE((SELECT COUNT(1) FROM mail where 1=1
SELECT mc.name,mc.key,mc.parent_key,mc.level,
'长沙市公安局' as second_dept_name, COALESCE((SELECT COUNT(1) FROM mail where 1=1
<if test="searchStartTime != null and searchEndTime != null">
AND mail.create_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if>), 0) as allcount, COALESCE(m.sumCount, 0) AS sumCount,
COALESCE(m.countRate, '0%') AS countRate
FROM mail_category mc LEFT JOIN ( SELECT mail_first_category AS category, COUNT(1) AS sumCount,
FROM mail_category mc LEFT JOIN ( SELECT mail_category AS category, COUNT(1) AS sumCount,
CONCAT(ROUND(COUNT(1) * 100.0 / (SELECT COUNT(1) FROM mail), 0), '%') AS countRate
FROM mail WHERE 1 = 1
<if test="searchStartTime != null and searchEndTime != null">
AND mail.create_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if>
GROUP BY mail_first_category) m ON mc.name = m.category WHERE mc.level = 1;
GROUP BY mail_category) m ON mc.name = m.category ;
</select>
<select id="selectMailThreeCategoryWithCount" resultType="java.util.Map">
SELECT
mc.name,
mc.name,mc.key,mc.parent_key,mc.level,
COALESCE(m.three_dept_name, #{deptName}) As second_dept_name,
COALESCE( (SELECT COUNT(1) FROM mail where mail.three_dept_id = #{deptId}
<if test="searchStartTime != null and searchEndTime != null">
@ -295,7 +306,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mail_category mc
LEFT JOIN (
SELECT
mail_first_category AS category,
mail_category AS category,
COUNT(1) AS sumCount,
CONCAT(ROUND(COUNT(1) * 100.0 / (SELECT COUNT(1) FROM mail), 0), '%') AS countRate, mail.three_dept_name,mail.three_dept_id
FROM
@ -307,11 +318,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND mail.create_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if>
GROUP BY
mail_first_category, mail.three_dept_name,mail.three_dept_id
mail_category, mail.three_dept_name,mail.three_dept_id
) m ON mc.name = m.category
WHERE
mc.level = 1;
</select>
<select id="selectFirstMailSourceWithCount" resultType="java.util.Map">

Loading…
Cancel
Save