Browse Source

[feat]

1、修改预警统计接口
pull/1/head
杨威 4 months ago
parent
commit
faae138e99
  1. 7
      dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java
  2. 9
      dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlert.java
  3. 6
      dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java
  4. 8
      dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java
  5. 2
      dk-modules/business/src/main/java/org/dromara/business/service/BusinessAlertStatisticsService.java
  6. 1
      dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java
  7. 23
      dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java
  8. 35
      dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java
  9. 189
      dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml

7
dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java

@ -26,6 +26,13 @@ public class BusinessAlertStatisticsController extends BaseController {
private final BusinessAlertStatisticsService statisticsService;
@Operation(summary="panel看板数据", description="panel看板数据")
@GetMapping(value = "/panel/count")
public R<List<StatObj>> countPanelAlert(BusinessAlertBo businessAlertBo) {
return R.ok(statisticsService.countPanelAlert(businessAlertBo));
}
//饼图显示每个月根据部门
@Operation(summary="根据月份显示预警个数", description="根据月份显示预警个数")

9
dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlert.java

@ -1,18 +1,15 @@
package org.dromara.business.domain;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import org.dromara.business.handler.AlertTypeHandler;
import org.dromara.common.core.enums.BusinessStatusEnum;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.common.translation.annotation.Translation;
import org.dromara.common.translation.constant.TransConstant;
import java.util.Date;
import java.io.Serial;
import java.util.Date;
import java.util.List;
/**

6
dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java

@ -19,9 +19,8 @@ import java.util.List;
* @date 2025-02-27
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = BusinessAlert.class, reverseConvertGenerate = false)
public class BusinessAlertBo extends BaseEntity {
public class BusinessAlertBo {
/**
* 任务轮id
*/
@ -215,4 +214,7 @@ public class BusinessAlertBo extends BaseEntity {
List<String> dateList;
private String createTime;
}

8
dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java

@ -29,6 +29,8 @@ public interface BusinessAlertMapper extends BaseMapperPlus<BusinessAlert, Busin
Page<BusinessAlert> pageAlertTodo(Page<BusinessAlert> page, QueryWrapper<BusinessAlert> ew);
Page<BusinessAlert> pageBusinessAlertCancel(Page<BusinessAlert> build, QueryWrapper<BusinessAlert> ew);
@DataPermission(
@DataColumn(key = "deptName", value = "ba.dept_id")
)
@ -53,4 +55,10 @@ public interface BusinessAlertMapper extends BaseMapperPlus<BusinessAlert, Busin
@DataColumn(key = "deptName", value = "ba.dept_id")
)
List<Map<String, Object>> countAlertCompare(@Param("param")BusinessAlertBo businessAlertBo);
@DataPermission(
@DataColumn(key = "deptName", value = "ba.dept_id")
)
List<Map<String, Object>> countPanelAlert(BusinessAlertBo businessAlertBo);
}

2
dk-modules/business/src/main/java/org/dromara/business/service/BusinessAlertStatisticsService.java

@ -17,4 +17,6 @@ public interface BusinessAlertStatisticsService {
List<StatObj> countDepartAlertStatus(BusinessAlertBo businessAlertBo);
List<Map<String, Object>> countAlertCompare(BusinessAlertBo businessAlertBo);
List<StatObj> countPanelAlert(BusinessAlertBo businessAlertBo);
}

1
dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java

@ -22,6 +22,7 @@ public interface IBusinessAlertService {
TableDataInfo<BusinessAlert> pageBusinessAlertAll(BusinessAlertBo bo, PageQuery pageQuery);
TableDataInfo<BusinessAlert> pageBusinessAlertCancel(BusinessAlertBo bo, PageQuery pageQuery);
/**
* 新增预警任务
*

23
dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java

@ -127,6 +127,23 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
return TableDataInfo.build(page);
}
/**
* 查询已忽略预警
* @param bo
* @param pageQuery
* @return
*/
@Override
public TableDataInfo<BusinessAlert> pageBusinessAlertCancel(BusinessAlertBo bo, PageQuery pageQuery) {
bo.setHandleType(BusinessStatusEnum.CANCEL.getStatus());
QueryWrapper<BusinessAlert> wrapper = buildQueryWrapper(bo);
Page<BusinessAlert> page = this.baseMapper.pageBusinessAlertCancel(pageQuery.build(), wrapper);
return TableDataInfo.build(page);
}
/**
* 查询当前用户已完成预警
* @param bo
@ -179,6 +196,8 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
}
/**
* 构建wrapper
* @param bo
@ -187,12 +206,16 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
private QueryWrapper<BusinessAlert> buildQueryWrapper(BusinessAlertBo bo) {
QueryWrapper<BusinessAlert> wrapper = new QueryWrapper<>();
//排除状态为验证状态预警
wrapper.ne("ba.handle_type", BusinessStatusEnum.VERIFY.getStatus());
if (ObjectUtil.isNotEmpty(bo.getAlertTypeList())){
wrapper.in("ba.alert_type", bo.getAlertTypeList());
}
if (ObjectUtil.isNotEmpty(bo.getHandleType())){
wrapper.eq("ba.handle_type", bo.getHandleType());
}
wrapper.orderByAsc("ba.create_time");

35
dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java

@ -8,6 +8,7 @@ import org.dromara.business.domain.model.StatObj;
import org.dromara.business.mapper.BusinessAlertMapper;
import org.dromara.business.service.BusinessAlertStatisticsService;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.api.RemoteDeptService;
import org.dromara.system.api.domain.vo.RemoteDeptVo;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,6 +18,7 @@ import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
*
@ -38,13 +40,11 @@ public class BusinessAlertStatisticsServiceImpl implements BusinessAlertStatisti
*/
@Override
public List<StatObj> countMonthAlert(BusinessAlertBo businessAlertBo) {
if (ObjectUtil.isEmpty(businessAlertBo.getDeptId())){
throw new ServiceException("部门【id】为空");
}
if (ObjectUtil.isNotEmpty(businessAlertBo.getDeptId())){
List<RemoteDeptVo> remoteDeptVoList = remoteDeptService.selectListByParentId(businessAlertBo.getDeptId());
List<Long> departIdList = remoteDeptVoList.stream().map(RemoteDeptVo::getDeptId).toList();
businessAlertBo.setDeptIdList(departIdList);
}
List<Map<String, Object>> mapList = baseMapper.listMonthAlert(businessAlertBo);
@ -55,6 +55,13 @@ public class BusinessAlertStatisticsServiceImpl implements BusinessAlertStatisti
@Override
public List<StatObj>countDepartAlert(BusinessAlertBo businessAlertBo) {
if (ObjectUtil.isNotEmpty(LoginHelper.getDeptId())){
List<RemoteDeptVo> remoteDeptVoList = remoteDeptService.selectListByParentId(LoginHelper.getDeptId() + "");
businessAlertBo.setDeptIdList(remoteDeptVoList.stream().map(RemoteDeptVo::getDeptId).toList());
}else {
//TODO
}
List<Map<String, Object>> mapList = baseMapper.listDepartAlert(businessAlertBo);
return mapList.stream().map(data -> new StatObj(data.get("deptName") + "", Long.parseLong(data.get("total") + ""),"deptId",data.get("deptId"))).collect(Collectors.toList());
@ -70,7 +77,8 @@ public class BusinessAlertStatisticsServiceImpl implements BusinessAlertStatisti
List.of(
new StatObj("total", map.get("total")),
new StatObj("todoCount", map.get("todoCount")),
new StatObj("finishCount", map.get("finishCount"))
new StatObj("finishCount", map.get("finishCount")),
new StatObj("cancelCount", map.get("cancelCount"))
)
))
.collect(Collectors.toList());
@ -87,7 +95,8 @@ public class BusinessAlertStatisticsServiceImpl implements BusinessAlertStatisti
List.of(
new StatObj("total", map.get("total")),
new StatObj("todoCount", map.get("todoCount")),
new StatObj("finishCount", map.get("finishCount"))
new StatObj("finishCount", map.get("finishCount")),
new StatObj("cancelCount", map.get("cancelCount"))
),"deptId",map.get("deptId")
))
.collect(Collectors.toList());
@ -108,6 +117,20 @@ public class BusinessAlertStatisticsServiceImpl implements BusinessAlertStatisti
return mapList;
}
@Override
public List<StatObj> countPanelAlert(BusinessAlertBo businessAlertBo) {
List<Map<String, Object>> mapList = baseMapper.countPanelAlert(businessAlertBo);
return mapList.stream()
.flatMap(map -> Stream.of(
new StatObj("total", map.get("total")),
new StatObj("todoCount", map.get("todoCount")),
new StatObj("finishCount", map.get("finishCount")),
new StatObj("cancelCount", map.get("cancelCount"))
))
.collect(Collectors.toList());
}
private List<String> buildDateList(BusinessAlertBo businessAlertBo) {
List<String> resultList = new ArrayList<>();
String currentYear = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));

189
dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml

@ -4,6 +4,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.business.mapper.BusinessAlertMapper">
<sql id="searchSql">
and ba.handle_type != 'verify'
<if test="param.createTime != null and param.createTime != ''">
and DATE_FORMAT(ba.create_time,'%Y-%m') = DATE_FORMAT(#{param.createTime},'%Y-%m')
</if>
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
</sql>
<select id="pageBusinessAlert" resultType="org.dromara.business.domain.BusinessAlert">
select
ba.*,
@ -14,6 +27,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
${ew.getCustomSqlSegment}
</select>
<select id="pageBusinessAlertCancel" resultType="org.dromara.business.domain.BusinessAlert">
select
ba.*,
b.flow_status flowStatus,
b.business_id businessId
from dk_business.business_alert ba
left join dk_workflow.flow_instance b on ba.id = b.business_id
${ew.getCustomSqlSegment}
</select>
<select id="pageAlertFinish" resultType="org.dromara.business.domain.BusinessAlert">
select
ba.*,
@ -45,142 +68,81 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="listMonthAlert" resultType="java.util.Map">
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 0 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -11 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 0 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 1 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -10 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 1 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 2 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -9 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 2 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 3 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -8 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 3 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 4 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -7 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 4 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 5 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -6 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 5 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 6 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -5 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 6 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 7 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -4 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 7 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 8 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -3 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 8 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 9 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -2 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 9 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 10 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -1 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 10 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
union all
SELECT DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 11 MONTH), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
SELECT DATE_FORMAT(CURDATE(), '%Y-%m') AS dateMonth,count(1) total from business_alert ba
where DATE_FORMAT(ba.create_time, '%Y-%m' ) = DATE_FORMAT(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-01-01'), INTERVAL 11 MONTH), '%Y-%m')
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<include refid="searchSql"></include>
</select>
<select id="listDepartAlert" resultType="java.util.Map">
select ba.dept_name deptName, ba.dept_id deptId,count(1) total
from business_alert ba
where 1=1
<if test="param.createTime != null and param.createTime != ''">
and DATE_FORMAT(ba.create_time,'%Y-%m') = DATE_FORMAT(#{param.createTime},'%Y-%m')
</if>
<include refid="searchSql"></include>
GROUP BY ba.dept_name,ba.dept_id
</select>
<select id="listMonthAlertStatus" resultType="java.util.Map">
WITH RECURSIVE months AS (
SELECT MAKEDATE(YEAR(NOW()), 1) AS dateMonth
SELECT LAST_DAY(DATE_SUB(NOW(), INTERVAL 11 MONTH)) AS dateMonth
UNION ALL
SELECT DATE_ADD(dateMonth, INTERVAL 1 MONTH)
SELECT LAST_DAY(DATE_ADD(dateMonth, INTERVAL 1 MONTH))
FROM months
WHERE <![CDATA[ dateMonth < LAST_DAY(MAKEDATE(YEAR(NOW()), 1) + INTERVAL 10 MONTH) ]]>
WHERE <![CDATA[ dateMonth < LAST_DAY(NOW()) ]]>
)
SELECT
DATE_FORMAT(m.dateMonth, '%Y-%m') AS dateMonth,
COALESCE(COUNT(ba.id), 0) AS total,
COALESCE(SUM(ba.handle_type = 'waiting'), 0) AS todoCount,
COALESCE(SUM(ba.handle_type = 'finish'), 0) AS finishCount
IFNULL(COUNT(ba.id), 0) AS total,
IFNULL(SUM(ba.handle_type = 'waiting'), 0) AS todoCount,
IFNULL(SUM(ba.handle_type = 'finish'), 0) AS finishCount,
IFNULL(SUM( ba.handle_type = 'cancel' ),0) AS cancelCount
FROM months m
LEFT JOIN business_alert ba
ON DATE_FORMAT(ba.create_time, '%Y-%m') = DATE_FORMAT(m.dateMonth, '%Y-%m')
<include refid="searchSql"></include>
GROUP BY m.dateMonth
ORDER BY m.dateMonth
</select>
@ -190,25 +152,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ba.dept_name deptName,
ba.dept_id deptId,
count( 1 ) total,
SUM( handle_type = 'waiting' ) AS todoCount,
SUM( handle_type = 'finish' ) AS finishCount
IFNULL(SUM( handle_type = 'waiting' ),0) AS todoCount,
IFNULL(SUM( handle_type = 'finish' ),0) AS finishCount,
IFNULL(SUM( ba.handle_type = 'cancel' ),0) AS cancelCount
FROM
business_alert ba
where 1=1
<if test="param.createTime != null and param.createTime != ''">
and DATE_FORMAT(ba.create_time,'%Y-%m') = DATE_FORMAT(#{param.createTime},'%Y-%m')
</if>
<include refid="searchSql"></include>
GROUP BY
ba.dept_name,ba.dept_id
</select>
<select id="countAlertCompare" resultType="java.util.Map">
WITH RECURSIVE months AS (
SELECT MAKEDATE(COALESCE(#{param.year}, YEAR(NOW())), 1) AS dateMonth
SELECT LAST_DAY(
IFNULL(
MAKEDATE(#{param.year}, 1),
DATE_SUB(NOW(), INTERVAL 11 MONTH)
)
) AS dateMonth
UNION ALL
SELECT DATE_ADD(dateMonth, INTERVAL 1 MONTH)
SELECT LAST_DAY(DATE_ADD(dateMonth, INTERVAL 1 MONTH))
FROM months
WHERE <![CDATA[ dateMonth < MAKEDATE(COALESCE(#{param.year}, YEAR(NOW())), 1) + INTERVAL 11 MONTH ]]>
WHERE <![CDATA[ dateMonth < LAST_DAY(
IFNULL(
MAKEDATE(#{param.year}, 1) + INTERVAL 11 MONTH,
NOW()
)
)]]>
),
param_departments AS (
SELECT dept_id, dept_name,tenant_id
@ -237,13 +208,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
DATE_FORMAT(md.dateMonth, '%Y-%m') AS date,
COUNT(DISTINCT ba.id) AS total,
IFNULL(SUM( ba.handle_type = 'waiting' ),0) AS todoCount,
IFNULL(SUM( ba.handle_type = 'finish' ),0) AS finishCount
IFNULL(SUM( ba.handle_type = 'finish' ),0) AS finishCount,
IFNULL(SUM( ba.handle_type = 'cancel' ),0) AS cancelCount
FROM month_department md
LEFT JOIN business_alert ba
ON md.dept_id = ba.dept_id
AND DATE_FORMAT(ba.create_time, '%Y-%m') = DATE_FORMAT(md.dateMonth, '%Y-%m')
AND ba.handle_type != 'verify'
GROUP BY md.dept_id, md.dateMonth, md.dept_name
ORDER BY md.dept_id, md.dateMonth
</select>
<select id="countPanelAlert" resultType="java.util.Map">
select COUNT(DISTINCT ba.id) AS total,
IFNULL(SUM( ba.handle_type = 'waiting' ),0) AS todoCount,
IFNULL(SUM( ba.handle_type = 'finish' ),0) AS finishCount,
IFNULL(SUM( ba.handle_type = 'cancel' ),0) AS cancelCount
from business_alert ba
where 1=1
<include refid="searchSql"></include>
</select>
</mapper>

Loading…
Cancel
Save