维修数据大屏统计

This commit is contained in:
PQZ 2024-10-21 17:03:33 +08:00
parent 374a82a78d
commit 2c253b024f
7 changed files with 613 additions and 0 deletions

View File

@ -0,0 +1,139 @@
package cn.iocoder.yudao.module.base.controller.admin;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.base.service.RepairStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@Tag(name = "维修数据统计")
@RestController
@RequestMapping("/repair/statistics")
@Validated
public class RepairStatisticsController {
@Resource
private RepairStatisticsService statisticsService;
/**
* 客户来源分析饼图
*
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
* @author PQZ
* @date 16:15 2024/10/21
**/
@GetMapping("/customerSource")
@Operation(summary = "客户来源分析饼图")
public CommonResult<?> customerSource() {
return CommonResult.success(statisticsService.customerSource());
}
/**
* 月工单金额走势折线图
*
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
* @author PQZ
* @date 16:15 2024/10/21
**/
@GetMapping("/ticketMainAmount")
@Operation(summary = "月工单金额走势")
public CommonResult<?> ticketMainAmount() {
return CommonResult.success(statisticsService.ticketMain("amount"));
}
/**
* 月工单数量走势折线图
*
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
* @author PQZ
* @date 16:15 2024/10/21
**/
@GetMapping("/ticketMainCount")
@Operation(summary = "月工单数量走势")
public CommonResult<?> ticketMainCount() {
return CommonResult.success(statisticsService.ticketMain("count"));
}
/**
* 支付渠道统计柱状图
*
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
* @author PQZ
* @date 16:15 2024/10/21
**/
@GetMapping("/ticketMainPayWay")
@Operation(summary = "支付渠道统计")
public CommonResult<?> ticketMainPayWay() {
return CommonResult.success(statisticsService.ticketMain("payWay"));
}
/**
* 维修类型相关统计分析饼图
*
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
* @author PQZ
* @date 16:15 2024/10/21
**/
@GetMapping("/ticketMainPayWay")
@Operation(summary = "维修类型相关统计分析饼图")
public CommonResult<?> repairTypeStatistics() {
return CommonResult.success(statisticsService.repairTypeStatistics());
}
/**
* 工单总数今日工单工单总金额今日工单金额
*
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
* @author PQZ
* @date 16:15 2024/10/21
**/
@GetMapping("/ticketStatistics")
@Operation(summary = "工单总数、今日工单、工单总金额、今日工单金额")
public CommonResult<?> ticketStatistics() {
return CommonResult.success(statisticsService.ticketStatistics());
}
/**
* 工单状态数量统计
*
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
* @author PQZ
* @date 16:15 2024/10/21
**/
@GetMapping("/ticketStatusCount")
@Operation(summary = "工单状态数量统计")
public CommonResult<?> ticketStatusCount() {
return CommonResult.success(statisticsService.ticketStatusCount());
}
/**
* 今日工单
*
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
* @author PQZ
* @date 16:15 2024/10/21
**/
@GetMapping("/listTicketToday")
@Operation(summary = "今日工单")
public CommonResult<?> listTicketToday() {
return CommonResult.success(statisticsService.listTicketToday());
}
/**
* 维修工人排行
*
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
* @author PQZ
* @date 16:15 2024/10/21
**/
@GetMapping("/listWorks")
@Operation(summary = "维修工人排行")
public CommonResult<?> listWorks() {
return CommonResult.success(statisticsService.listWorks());
}
}

View File

@ -0,0 +1,99 @@
package cn.iocoder.yudao.module.base.mapper;
import cn.iocoder.yudao.module.base.vo.RepairStatisticsVO;
import cn.iocoder.yudao.module.base.vo.RepairTicketStatisticsVO;
import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsRespVO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 维修数据统计
*
* @author pqz
*/
@Mapper
public interface RepairStatisticsMapper {
/**
* 客户来源统计
*
* @return java.util.List<cn.iocoder.yudao.module.base.vo.RepairStatisticsVO>
* @author PQZ
* @date 13:57 2024/10/21
**/
List<RepairStatisticsVO> customerSource();
/**
* 月工单数量走势
*
* @return java.util.List<cn.iocoder.yudao.module.base.vo.RepairStatisticsVO>
* @author PQZ
* @date 14:25 2024/10/21
**/
List<RepairStatisticsVO> ticketCountTrend();
/**
* 月工单金额走势
*
* @return java.util.List<cn.iocoder.yudao.module.base.vo.RepairStatisticsVO>
* @author PQZ
* @date 14:31 2024/10/21
**/
List<RepairStatisticsVO> ticketAmountTrend();
/**
* 按照支付方式统计
*
* @return java.util.List<cn.iocoder.yudao.module.base.vo.RepairStatisticsVO>
* @author PQZ
* @date 14:41 2024/10/21
**/
List<RepairStatisticsVO> paymentWay();
/**
* 维修方式统计饼图
*
* @return java.util.List<cn.iocoder.yudao.module.base.vo.RepairStatisticsVO>
* @author PQZ
* @date 14:52 2024/10/21
**/
List<RepairStatisticsVO> repairTypeStatistics();
/**
* 工单总数今日工单工单总金额今日工单金额
*
* @return cn.iocoder.yudao.module.base.vo.RepairTicketStatisticsVO
* @author PQZ
* @date 15:31 2024/10/21
**/
RepairTicketStatisticsVO ticketStatistics();
/**
* 工单状态数量统计
*
* @return java.util.List<cn.iocoder.yudao.module.base.vo.RepairStatisticsVO>
* @author PQZ
* @date 15:44 2024/10/21
**/
List<RepairStatisticsVO> ticketStatusCount();
/**
* 今日工单
*
* @return java.util.List<cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsRespVO>
* @author PQZ
* @date 15:50 2024/10/21
**/
List<DlRepairTicketsRespVO> listTicketToday();
/**
* 维修工人排行
* @author PQZ
* @date 16:13 2024/10/21
* @return java.util.List<cn.iocoder.yudao.module.base.vo.RepairStatisticsVO>
**/
List<RepairStatisticsVO> listWorks();
}

View File

@ -0,0 +1,85 @@
package cn.iocoder.yudao.module.base.service;
import cn.iocoder.yudao.module.base.vo.RepairStatisticsVO;
import cn.iocoder.yudao.module.base.vo.RepairTicketStatisticsVO;
import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsRespVO;
import java.util.List;
import java.util.Map;
/**
* 维修数据统计
*
* @author pqz
*/
public interface RepairStatisticsService {
/**
* 客户来源分析饼图
*
* @return java.util.List<cn.iocoder.yudao.module.base.vo.RepairStatisticsVO>
* @author PQZ
* @date 14:01 2024/10/21
**/
List<RepairStatisticsVO> customerSource();
/**
* 月工单数量金额走势支付渠道统计
* @author PQZ
* @date 14:32 2024/10/21
* @param type 'amount:金额count数量'payWay支付渠道
* @return java.util.Map<java.lang.String,java.lang.Object>
**/
Map<String, Object> ticketMain(String type);
/**
* 维修类型相关统计分析饼图
*
* @return java.util.Map<java.lang.String, java.lang.String>
* @author PQZ
* @date 13:25 2024/10/21
**/
List<RepairStatisticsVO> repairTypeStatistics();
/**
* 工单总数今日工单工单总金额今日工单金额
*
* @return java.util.Map<java.lang.String, java.lang.String>
* @author PQZ
* @date 13:23 2024/10/21
**/
RepairTicketStatisticsVO ticketStatistics();
/**
* 工单状态数量统计
*
* @return java.util.Map<java.lang.String, java.lang.String>
* @author PQZ
* @date 13:28 2024/10/21
**/
List<RepairStatisticsVO> ticketStatusCount();
/**
* 今日工单
*
* @return java.util.List<com.alibaba.fastjson.JSONObject>
* @author PQZ
* @date 13:25 2024/10/21
**/
List<DlRepairTicketsRespVO> listTicketToday();
/**
* 维修工人排行
*
* @return java.util.List<com.alibaba.fastjson.JSONObject>
* @author PQZ
* @date 13:26 2024/10/21
**/
List<RepairStatisticsVO> listWorks();
}

View File

@ -0,0 +1,131 @@
package cn.iocoder.yudao.module.base.service.impl;
import cn.iocoder.yudao.module.base.mapper.RepairStatisticsMapper;
import cn.iocoder.yudao.module.base.service.RepairStatisticsService;
import cn.iocoder.yudao.module.base.vo.RepairStatisticsVO;
import cn.iocoder.yudao.module.base.vo.RepairTicketStatisticsVO;
import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsRespVO;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 维修数据统计
*
* @author pqz
*/
@Service
@Validated
public class RepairStatisticsServiceImpl implements RepairStatisticsService {
@Resource
private RepairStatisticsMapper statisticsMapper;
/**
* 客户来源分析饼图
*
* @return java.util.List<cn.iocoder.yudao.module.base.vo.RepairStatisticsVO>
* @author PQZ
* @date 14:01 2024/10/21
**/
@Override
public List<RepairStatisticsVO> customerSource() {
return statisticsMapper.customerSource();
}
/**
* 月工单数量金额走势支付渠道统计
*
* @return java.util.Map<java.lang.String, java.lang.Object>
* @author PQZ
* @date 13:20 2024/10/21
**/
@Override
public Map<String, Object> ticketMain(String type) {
Map<String, Object> result = new HashMap<>();
List<RepairStatisticsVO> tickets;
if ("count".equals(type)) {
//月工单数量走势折线图
tickets = statisticsMapper.ticketCountTrend();
} else if ("amount".equals(type)) {
//月工单金额走势折线图
tickets = statisticsMapper.ticketAmountTrend();
} else {
//支付渠道柱状图
tickets = statisticsMapper.paymentWay();
}
//取出数值
List<Integer> data = tickets.stream().map(RepairStatisticsVO::getValue).collect(Collectors.toList());
//x轴值
List<String> xData = tickets.stream().map(RepairStatisticsVO::getName).collect(Collectors.toList());
result.put("data", data);
result.put("xData", xData);
return result;
}
/**
* 维修类型相关统计分析饼图
*
* @return java.util.Map<java.lang.String, java.lang.String>
* @author PQZ
* @date 13:25 2024/10/21
**/
@Override
public List<RepairStatisticsVO> repairTypeStatistics() {
return statisticsMapper.repairTypeStatistics();
}
/**
* 工单总数今日工单工单总金额今日工单金额
*
* @return java.util.Map<java.lang.String, java.lang.String>
* @author PQZ
* @date 13:23 2024/10/21
**/
@Override
public RepairTicketStatisticsVO ticketStatistics() {
return statisticsMapper.ticketStatistics();
}
/**
* 工单状态数量统计
*
* @return java.util.Map<java.lang.String, java.lang.String>
* @author PQZ
* @date 13:28 2024/10/21
**/
@Override
public List<RepairStatisticsVO> ticketStatusCount() {
return statisticsMapper.ticketStatusCount();
}
/**
* 今日工单
*
* @return java.util.List<com.alibaba.fastjson.JSONObject>
* @author PQZ
* @date 13:25 2024/10/21
**/
@Override
public List<DlRepairTicketsRespVO> listTicketToday() {
return statisticsMapper.listTicketToday();
}
/**
* 维修工人排行
*
* @return java.util.List<com.alibaba.fastjson.JSONObject>
* @author PQZ
* @date 13:26 2024/10/21
**/
@Override
public List<RepairStatisticsVO> listWorks() {
return statisticsMapper.listWorks();
}
}

View File

@ -0,0 +1,13 @@
package cn.iocoder.yudao.module.base.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
@Schema(description = "数据统计VO")
@Data
@ToString(callSuper = true)
public class RepairStatisticsVO {
String name;
Integer value;
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.base.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
@Schema(description = "数据统计VO")
@Data
@ToString(callSuper = true)
public class RepairTicketStatisticsVO {
/**工单总数量*/
Integer totalCount;
/**工单总金额*/
Double totalAmount;
/**工单今日数量*/
Integer todayCount;
/**工单今日金额*/
Double todayAmount;
}

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.base.mapper.RepairStatisticsMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<select id="customerSource" resultType="cn.iocoder.yudao.module.base.vo.RepairStatisticsVO">
SELECT
COALESCE(sdd.label, '未知') AS name,
COUNT(bcm.id) AS vale
FROM
base_customer_main bcm
LEFT JOIN system_dict_data sdd ON bcm.data_from = sdd.value AND sdd.dict_type = 'cus_data_from' AND sdd.deleted = 0
WHERE
bcm.deleted = 0
GROUP BY
bcm.data_from
ORDER BY
bcm.create_time
</select>
<select id="ticketCountTrend" resultType="cn.iocoder.yudao.module.base.vo.RepairStatisticsVO">
SELECT
DATE_FORMAT(create_time, '%Y-%m') AS name,
COUNT(*) AS value
FROM
dl_repair_tickets
WHERE
create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
GROUP BY
name
ORDER BY
name
</select>
<select id="ticketAmountTrend" resultType="cn.iocoder.yudao.module.base.vo.RepairStatisticsVO">
SELECT
DATE_FORMAT(create_time, '%Y-%m') AS name,
SUM(total_price) AS value
FROM
dl_repair_tickets
WHERE
create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
GROUP BY
name
ORDER BY
name
</select>
<select id="paymentWay" resultType="cn.iocoder.yudao.module.base.vo.RepairStatisticsVO">
SELECT
COALESCE(sdd.label, '未知') AS name,
COUNT(roi.id)
FROM
repair_order_info roi
LEFT JOIN system_dict_data sdd ON roi.pay_type = sdd.value AND sdd.dict_type = 'repair_pay_type' AND sdd.deleted = 0
WHERE
roi.deleted = 0
GROUP BY roi.pay_type
ORDER BY roi.create_time
</select>
<select id="repairTypeStatistics" resultType="cn.iocoder.yudao.module.base.vo.RepairStatisticsVO">
SELECT
COALESCE(sdd.label, '未知') AS `name`,
COUNT( drt.id ) AS `value`
FROM
dl_repair_tickets drt
LEFT JOIN system_dict_data sdd ON drt.repair_type = sdd.value AND sdd.dict_type = 'repair_type' AND sdd.deleted = 0
WHERE
drt.deleted = 0
GROUP BY
drt.repair_type
ORDER BY
drt.create_time
</select>
<select id="ticketStatistics" resultType="cn.iocoder.yudao.module.base.vo.RepairTicketStatisticsVO">
SELECT
COUNT( drt.id ) AS totalCount,
SUM( drt.total_price ) AS totalAmount,
COUNT( CASE WHEN DATE ( drt.create_time ) = CURDATE() THEN 1 END ) AS todayCount,
SUM( CASE WHEN DATE ( drt.create_time ) = CURDATE() THEN drt.total_price ELSE 0 END ) AS todayAmount
FROM
dl_repair_tickets drt
WHERE
drt.deleted = 0
</select>
<select id="ticketStatusCount" resultType="cn.iocoder.yudao.module.base.vo.RepairStatisticsVO">
SELECT
sdd.label AS `name`,
COUNT(drt.id) AS `value`
FROM
system_dict_data sdd
LEFT JOIN
dl_repair_tickets drt ON drt.tickets_status = sdd.`value`
WHERE
sdd.dict_type = 'repair_tickets_status'
AND sdd.deleted = 0
GROUP BY
sdd.value
ORDER BY
sdd.value
</select>
<select id="listTicketToday" resultType="cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsRespVO">
SELECT
drt.*
FROM
dl_repair_tickets drt
WHERE
drt.deleted = 0
AND DATE ( drt.create_time ) = CURDATE()
ORDER BY
drt.create_time DESC
</select>
<select id="listWorks" resultType="cn.iocoder.yudao.module.base.vo.RepairStatisticsVO">
SELECT
drw.user_name AS `name`,
COUNT(drr.id) AS `value`
FROM
dl_repair_worker drw
LEFT JOIN dl_repair_records drr ON drw.user_id = drr.deal_user_id AND drr.deleted = 0
WHERE drr.type = 'sgwczj'
GROUP BY drw.user_id,drr.ticket_id
ORDER BY value DESC
</select>
</mapper>