Browse Source

信件分类统计大类型

master
laishajiang 2 years ago
parent
commit
a1061b1170
  1. 13
      mailbox-lan/src/main/java/com/biutag/lan/controller/DataController.java
  2. 7
      mailbox-lan/src/main/java/com/biutag/lan/mapper/DataMapper.java
  3. 134
      mailbox-lan/src/main/java/com/biutag/lan/service/DataService.java
  4. 176
      mailbox-lan/src/main/resources/mapper/DataMapper.xml

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

@ -10,10 +10,7 @@ import com.biutag.lan.config.AdminThreadLocal;
import com.biutag.lan.domain.Notice; import com.biutag.lan.domain.Notice;
import com.biutag.lan.domain.Work; import com.biutag.lan.domain.Work;
import com.biutag.lan.domain.bo.MailQuery; import com.biutag.lan.domain.bo.MailQuery;
import com.biutag.lan.domain.vo.DataVo; import com.biutag.lan.domain.vo.*;
import com.biutag.lan.domain.vo.NoticeTotalVo;
import com.biutag.lan.domain.vo.NoticeVo;
import com.biutag.lan.domain.vo.WorkVo;
import com.biutag.lan.flow.FlowNameEnum; import com.biutag.lan.flow.FlowNameEnum;
import com.biutag.lan.service.DataService; import com.biutag.lan.service.DataService;
import com.biutag.lan.service.NoticeService; import com.biutag.lan.service.NoticeService;
@ -26,6 +23,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map; import java.util.Map;
@RequiredArgsConstructor @RequiredArgsConstructor
@ -44,4 +42,11 @@ public class DataController {
return AjaxResult.success(list); return AjaxResult.success(list);
} }
@NotPower
@GetMapping("listForCategory")
public AjaxResult<Page<Map<String, Object>> > listForCategory(Page page, @Validated DataSearchValidate searchValidate) {
Page<Map<String, Object>> list = dataService.listForCategory(page, searchValidate);
return AjaxResult.success(list);
}
} }

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

@ -20,5 +20,12 @@ 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>> getThirdList(Page page,@Param("searchStartTime") String searchStartTime,@Param("searchEndTime") String searchEndTime,@Param("deptId") String deptId);
List<Map<String, Object>> selectMailCategoryWithCount(@Param("dept_level") String dept_level,@Param("deptId") String deptId,@Param("deptName") String deptName);
List<Map<String, Object>> selectMailFirstCategoryWithCount();
List<Map<String, Object>> selectMailThreeCategoryWithCount(@Param("dept_level") String dept_level,@Param("deptId") String deptId,@Param("deptName") String deptName);
} }

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

@ -1,26 +1,21 @@
package com.biutag.lan.service; package com.biutag.lan.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biutag.constants.AppConstants; import com.biutag.entity.system.Dept;
import com.biutag.enums.RoleEnum;
import com.biutag.lan.config.AdminThreadLocal;
import com.biutag.lan.domain.*; import com.biutag.lan.domain.*;
import com.biutag.lan.domain.vo.DataVo; import com.biutag.lan.domain.vo.DataCategoryVo;
import com.biutag.lan.domain.vo.NoticeVo;
import com.biutag.lan.mapper.*; import com.biutag.lan.mapper.*;
import com.biutag.lan.validate.system.DataSearchValidate; import com.biutag.lan.validate.system.DataSearchValidate;
import com.biutag.lan.validate.system.NoticeSearchValidate;
import com.biutag.mapper.setting.DictDataMapper;
import com.biutag.mapper.system.DeptMapper; import com.biutag.mapper.system.DeptMapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.time.format.DateTimeFormatter; import java.util.ArrayList;
import java.util.LinkedList; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -31,11 +26,12 @@ import java.util.stream.Stream;
@Service @Service
public class DataService extends ServiceImpl<DataMapper, Mail> { public class DataService extends ServiceImpl<DataMapper, Mail> {
@Resource
private MailCategoryMapper mailCategoryMapper;
@Resource @Resource
private DataMapper dataMapper; private DataMapper dataMapper;
@Resource
private DeptMapper deptMapper;
public Page<Map<String, Object>> list(Page page, @Validated DataSearchValidate searchValidate){ public Page<Map<String, Object>> list(Page page, @Validated DataSearchValidate searchValidate){
List<Map<String, Object>> combinedList = null; List<Map<String, Object>> combinedList = null;
List<Map<String, Object>> mapfirst = null; List<Map<String, Object>> mapfirst = null;
@ -84,5 +80,115 @@ 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<>();
if (searchValidate.getEasydept()==null||searchValidate.getEasydept().equals("1")){
List<Map<String,Object>> categorylist = baseMapper.selectMailFirstCategoryWithCount();
int keycount = 1;
Map<String,Object> map = new HashMap<>();
for (Map<String,Object> item :categorylist){
System.out.println(item);
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++;
}
list.add(map);
Wrapper wrapper2 = new QueryWrapper<>().eq("level",2);
deptslist = deptMapper.selectPage(page,wrapper2).getRecords();
for(Dept deptItem :deptslist){
List<Map<String,Object>> categorylistforsecond = baseMapper.selectMailCategoryWithCount(searchValidate.getEasydept(),deptItem.getId().toString(),deptItem.getName());
int count = 1;
Map<String,Object> mapforsecond = new HashMap<>();
for (Map<String,Object> item :categorylistforsecond){
System.out.println(item);
mapforsecond.put("countrate"+count,item.get("countrate"));
mapforsecond.put("sumcount"+count,item.get("sumcount"));
mapforsecond.put("name"+count,item.get("name"));
mapforsecond.put("second_dept_name"+count,item.get("second_dept_name"));
mapforsecond.put("allcount"+count,item.get("allcount"));
count++;
}
list.add(mapforsecond);
}
}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(searchValidate.getEasydept(),deptItem.getId().toString(),deptItem.getName());
int count = 1;
Map<String,Object> map = new HashMap<>();
for (Map<String,Object> item :categorylist){
System.out.println(item);
map.put("countrate"+count,item.get("countrate"));
map.put("sumcount"+count,item.get("sumcount"));
map.put("name"+count,item.get("name"));
map.put("second_dept_name"+count,item.get("second_dept_name"));
map.put("allcount"+count,item.get("allcount"));
count++;
}
list.add(map);
}
}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(searchValidate.getEasydept(),deptItem.getId().toString(),deptItem.getName());
int count = 1;
Map<String,Object> map = new HashMap<>();
for (Map<String,Object> item :categorylist){
System.out.println(item);
map.put("countrate"+count,item.get("countrate"));
map.put("sumcount"+count,item.get("sumcount"));
map.put("name"+count,item.get("name"));
map.put("second_dept_name"+count,item.get("second_dept_name"));
map.put("allcount"+count,item.get("allcount"));
count++;
}
list.add(map);
}
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(searchValidate.getEasydept(),deptItem.getId().toString(),deptItem.getName());
int count = 1;
Map<String,Object> map = new HashMap<>();
for (Map<String,Object> item :categorylist){
System.out.println(item);
map.put("countrate"+count,item.get("countrate"));
map.put("sumcount"+count,item.get("sumcount"));
map.put("name"+count,item.get("name"));
map.put("second_dept_name"+count,item.get("second_dept_name"));
map.put("allcount"+count,item.get("allcount"));
count++;
}
list.add(map);
}
}
}
Page<Map<String, Object>> dataVoPage = new Page<>();
dataVoPage.setRecords(list);
dataVoPage.setTotal(page.getTotal());
dataVoPage.setCurrent(page.getCurrent());
dataVoPage.setSize(page.getSize());
dataVoPage.setPages(page.getPages());
return dataVoPage;
}
} }

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

@ -16,14 +16,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from dept a left join mail_mark b on a.id = b.second_dept_id from dept a left join mail_mark b on a.id = b.second_dept_id
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if> </if>
where a.level = '2' where a.level = '2'
<if test="deptId != null">
and a.id = #{deptId} group by a.name,a.sort
</if>
group by a.name,a.sort
order by crateNumber desc order by crateNumber desc
) t1 ) t1
join join
@ -34,13 +32,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END) sum SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END) sum
from dept a left join mail_mark b on a.id = b.second_dept_id from dept a left join mail_mark b on a.id = b.second_dept_id
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if> </if>
where a.level = '2' where a.level = '2'
<if test="deptId != null">
and a.id = #{deptId}
</if>
group by a.name) t order by rateNumber desc group by a.name) t order by rateNumber desc
) t2 on t1.cname = t2.rname ) t2 on t1.cname = t2.rname
@ -55,13 +51,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
CONCAT(srateNumber,'%') srate CONCAT(srateNumber,'%') srate
from dept a left join mail_mark b on a.id = b.second_dept_id from dept a left join mail_mark b on a.id = b.second_dept_id
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if> </if>
where a.level = '2' where a.level = '2'
<if test="deptId != null">
and a.id = #{deptId}
</if>
group by a.name group by a.name
order by srateNumber desc order by srateNumber desc
) t4 on t3.cname = t4.sname ORDER BY score desc ,sort ) t4 on t3.cname = t4.sname ORDER BY score desc ,sort
@ -70,58 +64,58 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getFirstAllList" resultType="java.util.Map" > <select id="getFirstAllList" resultType="java.util.Map" >
SELECT *, (CAST(REPLACE(crate, '%', '') AS NUMERIC) * 0.5 + SELECT *, (CAST(REPLACE(crate, '%', '') AS NUMERIC) * 0.5 +
CAST(REPLACE(srate, '%', '') AS NUMERIC) * 0.3 + CAST(REPLACE(srate, '%', '') AS NUMERIC) * 0.3 +
CAST(REPLACE(rate, '%', '') AS NUMERIC) * 0.2) AS score,'长沙市公安局' as cname FROM CAST(REPLACE(rate, '%', '') AS NUMERIC) * 0.2) AS score,'长沙市公安局' as cname FROM
( (
( (
select select
ROUND(sum(COALESCE(b.completed, 0))*100/count(1),0) crateNumber, ROUND(sum(COALESCE(b.completed, 0))*100/count(1),0) crateNumber,
CONCAT(ROUND(SUM(COALESCE(b.completed, 0))*100 / NULLIF(COUNT(1), 0),0),'%') AS cRate, CONCAT(ROUND(SUM(COALESCE(b.completed, 0))*100 / NULLIF(COUNT(1), 0),0),'%') AS cRate,
SUM(COALESCE(b.completed, 0)) AS completed, SUM(COALESCE(b.completed, 0)) AS completed,
COUNT(1) AS cSum, COUNT(1) AS cSum,
(SELECT COUNT(*) FROM mail_mark b where 1=1 (SELECT COUNT(*) FROM mail_mark b where 1=1
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D')
</if>) AS total </if>) AS total
from mail_mark b left join dept a on a.id=b.second_dept_id where 1=1 from mail_mark b left join dept a on a.id=b.second_dept_id where 1=1
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if> </if>
) t1 ) t1
join join
( (
select CONCAT(ROUND(sum(COALESCE(b.resolved, 0))*100/SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END),0),'%') Rate, select CONCAT(ROUND(sum(COALESCE(b.resolved, 0))*100/SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END),0),'%') Rate,
SUM(COALESCE(b.resolved, 0)) resolved,SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END) rSum, SUM(COALESCE(b.resolved, 0)) resolved,SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END) rSum,
(SELECT COUNT(*) FROM mail_mark b where 1=1 (SELECT COUNT(*) FROM mail_mark b where 1=1
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if>) AS total2 </if>) AS total2
from mail_mark b left join dept a on a.id=b.second_dept_id where 1=1 from mail_mark b left join dept a on a.id=b.second_dept_id where 1=1
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if> </if>
) t2 on t1.total = t2.total2 ) t2 on t1.total = t2.total2
) t3 JOIN ) t3 JOIN
( (
select select
CONCAT(ROUND(SUM(COALESCE(b.satisfied, 0))*100 / NULLIF(SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END), 0),0),'%') AS sRate, CONCAT(ROUND(SUM(COALESCE(b.satisfied, 0))*100 / NULLIF(SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END), 0),0),'%') AS sRate,
SUM(COALESCE(b.satisfied, 0)) AS satisfied, SUM(COALESCE(b.satisfied, 0)) AS satisfied,
SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END) AS Sum, SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END) AS Sum,
(SELECT COUNT(*) FROM mail_mark b where 1=1 (SELECT COUNT(*) FROM mail_mark b where 1=1
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if>) AS total3 </if>) AS total3
from mail_mark b left join dept a on a.id=b.second_dept_id where 1=1 from mail_mark b left join dept a on a.id=b.second_dept_id where 1=1
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if> </if>
) t4 on t3.total2 = t4.total3 ) t4 on t3.total2 = t4.total3
</select> </select>
@ -135,15 +129,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
CONCAT(crateNumber,'%') crate, CONCAT(crateNumber,'%') crate,
SUM(COALESCE(b.completed, 0)) completed,count(1) csum SUM(COALESCE(b.completed, 0)) completed,count(1) csum
from dept a left join mail_mark b on a.id = b.three_dept_id from dept a left join mail_mark b on a.id = b.second_dept_id
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if> </if>
where a.level = '3' where a.level = '3'
<if test="deptId != null"> <if test="deptId != null">
and a.pid = #{deptId} and a.pid = #{deptId} or a.id = #{deptId}
</if> </if>
group by a.name,a.sort group by a.name,a.sort
order by crateNumber desc order by crateNumber desc
@ -154,14 +148,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from from
(select a.name, SUM(COALESCE(b.resolved, 0)) resolved, (select a.name, SUM(COALESCE(b.resolved, 0)) resolved,
SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END) sum SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END) sum
from dept a left join mail_mark b on a.id = b.three_dept_id from dept a left join mail_mark b on a.id = b.second_dept_id
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if> </if>
where a.level = '3' where a.level = '3'
<if test="deptId != null"> <if test="deptId != null">
and a.pid = #{deptId} and a.pid = #{deptId} or a.id = #{deptId}
</if> </if>
group by a.name) t order by rateNumber desc group by a.name) t order by rateNumber desc
@ -175,17 +169,87 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END) sum, SUM(CASE WHEN b.completed = '1' THEN 1 ELSE 0 END) sum,
CASE WHEN sum = 0 THEN 0 ELSE ROUND(sum(COALESCE(b.satisfied, 0))*100/sum,0) END srateNumber, CASE WHEN sum = 0 THEN 0 ELSE ROUND(sum(COALESCE(b.satisfied, 0))*100/sum,0) END srateNumber,
CONCAT(srateNumber,'%') srate CONCAT(srateNumber,'%') srate
from dept a left join mail_mark b on a.id = b.three_dept_id from dept a left join mail_mark b on a.id = b.second_dept_id
<if test="searchStartTime != null and searchEndTime != null"> <if test="searchStartTime != null and searchEndTime != null">
AND b.completion_time BETWEEN #{searchStartTime} AND (to_date(#{searchEndTime}) + interval '1 D') AND b.completion_time BETWEEN #{searchStartTime} AND #{searchEndTime}
</if> </if>
where a.level = '3' where a.level = '3'
<if test="deptId != null"> <if test="deptId != null">
and a.pid = #{deptId} and a.pid = #{deptId} or a.id = #{deptId}
</if> </if>
group by a.name group by a.name
order by srateNumber desc order by srateNumber desc
) t4 on t3.cname = t4.sname ORDER BY score desc ,sort ) t4 on t3.cname = t4.sname ORDER BY score desc ,sort
</select> </select>
<select id="selectMailCategoryWithCount" resultType="java.util.Map">
SELECT
mc.name,
COALESCE(m.second_dept_name, #{deptName}) As second_dept_name,
COALESCE(m.allcount, 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,
CONCAT(ROUND(COUNT(1) * 100.0 / (SELECT COUNT(1) FROM mail), 0), '%') AS countRate, mail.second_dept_name,mail.second_dept_id, (SELECT COUNT(1) FROM mail where mail.second_dept_id = #{deptId}) as allcount
FROM
mail
WHERE
1 = 1
and mail.second_dept_id = #{deptId}
GROUP BY
mail_first_category, mail.second_dept_name,mail.second_dept_id
) m ON mc.name = m.category
WHERE
mc.level = 1;
</select>
<select id="selectMailFirstCategoryWithCount" resultType="java.util.Map">
SELECT mc.name,'长沙市公安局' as second_dept_name, COALESCE(m.allcount, 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,
CONCAT(ROUND(COUNT(1) * 100.0 / (SELECT COUNT(1) FROM mail), 0), '%') AS countRate,(SELECT COUNT(1) FROM mail) as allcount
FROM mail WHERE 1 = 1 GROUP BY mail_first_category) m ON mc.name = m.category WHERE mc.level = 1;
</select>
<select id="selectMailThreeCategoryWithCount" resultType="java.util.Map">
SELECT
mc.name,
COALESCE(m.three_dept_name, #{deptName}) As second_dept_name,
COALESCE(m.allcount, 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,
CONCAT(ROUND(COUNT(1) * 100.0 / (SELECT COUNT(1) FROM mail), 0), '%') AS countRate, mail.three_dept_name,mail.three_dept_id, (SELECT COUNT(1) FROM mail where mail.three_dept_id = #{deptId}) as allcount
FROM
mail
WHERE
1 = 1
and mail.three_dept_id = #{deptId}
GROUP BY
mail_first_category, mail.three_dept_name,mail.three_dept_id
) m ON mc.name = m.category
WHERE
mc.level = 1;
</select>
</mapper> </mapper>

Loading…
Cancel
Save