柱状图展示异步统计数据

PC端

 APP端

 Controller层

package com.cnpc.dj.party.controller;import com.alibaba.fastjson.JSONObject;
import com.cnpc.dj.common.JsonResult;
import com.cnpc.dj.common.context.BaseContextHandler;
import com.cnpc.dj.common.utils.DateUtils;
import com.cnpc.dj.party.common.ReturnExamEnum;
import com.cnpc.dj.party.service.GridDataStatisticService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/dataStatistic")
public class GridDataStatisticController {@Autowiredprivate GridDataStatisticService gridDataStatisticService ;@PostMapping("/doStatisticForGrid")public JsonResult<?> doStatisticForGrid(@RequestBody JSONObject requestBody) {// 检查入参合法性.BigDecimal orgId = requestBody.getBigDecimal("orgId");if (Objects.isNull(orgId)) {return JsonResult.error(ReturnExamEnum.GRID_ILLEGAL_ARGUMENT, "必要参数<orgId>未填写");}BigDecimal tenantId = BaseContextHandler.getDecimalTenantId();long beginTime = System.currentTimeMillis();log.info("\n[ {} ][ 网格员 - 数据统计任务 ]: 开始所有任务(当前租户ID: {} ).", DateUtils.format(new Date(beginTime), "yyyy年MM月dd日 HH时mm分ss秒 SSS毫秒"), tenantId);// 创建统计结果容器.JSONObject result = new JSONObject();// 创建异步统计任务: 调用各统计方法.CompletableFuture<?> task1 = gridDataStatisticService.gridNumberAsyncStatistic(tenantId, orgId, result);CompletableFuture<?> task2 = gridDataStatisticService.gridPersonNumberAsyncStatistic(tenantId, orgId, result);// 等待, 直到所有任务执行完毕.CompletableFuture.allOf(task1,task2).join();long endTime = System.currentTimeMillis();log.info("\n[ {} ][ 网格员 - 数据统计任务 ]: 所有任务完成, 总计耗时 {} 毫秒.", DateUtils.format(new Date(endTime), "yyyy年MM月dd日 HH时mm分ss秒 SSS毫秒"), endTime - beginTime);// 返回统计结果.return JsonResult.success(result);}
}

Service层 

package com.cnpc.dj.party.service;import com.alibaba.fastjson.JSONObject;
import com.cnpc.dj.common.utils.DateUtils;
import com.cnpc.dj.party.common.EChartsResult;
import com.cnpc.dj.party.common.KeyValuePair;
import com.cnpc.dj.party.repository.GridDataStatisticMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;@Service
@Slf4j
public class GridDataStatisticService {@Autowiredprivate GridDataStatisticMapper gridDataStatisticMapper;private static String convert(long timeMillis) {return DateUtils.format(new Date(timeMillis), "yyyy年MM月dd日 HH时mm分ss秒 SSS毫秒");}/*** 获取网格信息* @param orgId 入参: 组织ID.* @return 统计结果.*/@Asyncpublic CompletableFuture<?> gridNumberAsyncStatistic(BigDecimal tenantId, BigDecimal orgId, JSONObject parent) {long t0 = System.currentTimeMillis();log.info("\n[ {} ][ 网格情况 ][ 网格数量统计 ]: 任务开始.", convert(t0));// 查询数据库, 获取原始数据List<KeyValuePair<BigDecimal>> list = gridDataStatisticMapper.statisticGrid(tenantId, orgId);long t1 = System.currentTimeMillis();log.info("\n[ {} ][ 网格情况 ][ 网格数量统计 ]: 原始数据查询成功: 本步耗时 {} 毫秒, 总计耗时 {} 毫秒.", convert(t1),t1 - t0,t1 - t0);// 初始化查询结果容器.// 初始化查询结果容器.管理类,科研类,生产经营类,项目建设类,生产作业类,网格总数String[] mapEntry = {"Manage", "Scientific", "ProductionOperation", "ProjectBuild","FlowHomework", "GridTotal"};EChartsResult result = new EChartsResult();result.init(null, mapEntry, null);BigDecimal gridTotal = BigDecimal.ZERO;// 处理原始数据, 填充查询结果容器.for (KeyValuePair<BigDecimal> item : list) {if (Objects.nonNull(item.getKey())) {switch (item.getKey()) {case "1":result.addToMap(mapEntry[0], item.getValue());gridTotal = gridTotal.add(item.getValue());break;case "2":result.addToMap(mapEntry[1], item.getValue());gridTotal = gridTotal.add(item.getValue());break;case "3":result.addToMap(mapEntry[2], item.getValue());gridTotal = gridTotal.add(item.getValue());break;case "4":result.addToMap(mapEntry[3], item.getValue());gridTotal = gridTotal.add(item.getValue());break;default:result.addToMap(mapEntry[4], item.getValue());gridTotal = gridTotal.add(item.getValue());}}}result.addToMap(mapEntry[5], gridTotal);// 返回查询结果.parent.put("GridStatistic", result.getMap());long t2 = System.currentTimeMillis();log.info("\n[ {} ][ 网格情况 ][ 网格数量统计 ]: 数据处理完成, 任务结束: 本步耗时 {} 毫秒, 总计耗时 {} 毫秒.", convert(t2), t2 - t1,t2 - t0);return CompletableFuture.completedFuture(parent);}/*** 获取网格人员信息* @param orgId 入参: 组织ID.* @return 统计结果.*/@Asyncpublic CompletableFuture<?> gridPersonNumberAsyncStatistic(BigDecimal tenantId, BigDecimal orgId, JSONObject parent) {long t0 = System.currentTimeMillis();log.info("\n[ {} ][ 网格人员情况 ][ 网格人数统计 ]: 任务开始.", convert(t0));// 查询数据库, 获取原始数据List<KeyValuePair<BigDecimal>> list = gridDataStatisticMapper.statisticGridPerson(tenantId, orgId);long t1 = System.currentTimeMillis();log.info("\n[ {} ][ 网格人员情况 ][ 网格人数统计 ]: 原始数据查询成功: 本步耗时 {} 毫秒, 总计耗时 {} 毫秒.", convert(t1),t1 - t0,t1 - t0);// 初始化查询结果容器.// 初始化查询结果容器.管理类,科研类,生产经营类,项目建设类,生产作业类,网格人员总数String[] mapEntry = {"Manage", "Scientific", "ProductionOperation", "ProjectBuild","FlowHomework", "GridPersonTotal"};EChartsResult result = new EChartsResult();result.init(null, mapEntry, null);BigDecimal gridTotal = BigDecimal.ZERO;// 处理原始数据, 填充查询结果容器.for (KeyValuePair<BigDecimal> item : list) {if (Objects.nonNull(item.getKey())) {switch (item.getKey()) {case "1":result.addToMap(mapEntry[0], item.getValue());gridTotal = gridTotal.add(item.getValue());break;case "2":result.addToMap(mapEntry[1], item.getValue());gridTotal = gridTotal.add(item.getValue());break;case "3":result.addToMap(mapEntry[2], item.getValue());gridTotal = gridTotal.add(item.getValue());break;case "4":result.addToMap(mapEntry[3], item.getValue());gridTotal = gridTotal.add(item.getValue());break;default:result.addToMap(mapEntry[4], item.getValue());gridTotal = gridTotal.add(item.getValue());}}}result.addToMap(mapEntry[5], gridTotal);// 返回查询结果.parent.put("GridPersonStatistic", result.getMap());long t2 = System.currentTimeMillis();log.info("\n[ {} ][ 网格人员情况 ][ 网格人数统计 ]: 数据处理完成, 任务结束: 本步耗时 {} 毫秒, 总计耗时 {} 毫秒.", convert(t2), t2 - t1,t2 - t0);return CompletableFuture.completedFuture(parent);}
}

Mapper层

package com.cnpc.dj.party.repository;import com.cnpc.dj.party.common.KeyValuePair;
import org.apache.ibatis.annotations.Mapper;import java.math.BigDecimal;
import java.util.List;@Mapper
public interface GridDataStatisticMapper {/*** 统计网格数量* @param tenantId* @param orgId* @return K V*/List<KeyValuePair<BigDecimal>> statisticGrid(BigDecimal tenantId, BigDecimal orgId);/*** 统计网格人数* @param tenantId* @param orgId* @return K V*/List<KeyValuePair<BigDecimal>> statisticGridPerson(BigDecimal tenantId, BigDecimal orgId);
}

 Mapper.xml层

<?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="com.cnpc.dj.party.repository.GridDataStatisticMapper"><resultMap id="KeyValuePair" type="com.cnpc.dj.party.common.KeyValuePair"><result column="K" property="key" jdbcType="VARCHAR" javaType="java.lang.String"/><result column="V" property="value" jdbcType="INTEGER" javaType="java.math.BigDecimal"/></resultMap><select id="statisticGrid" parameterType="java.math.BigDecimal" resultMap="KeyValuePair">SELECT G.GRID_CLASS k,COUNT(*)     vFROM ZHONGHY_ONLINE_ANSWERS.DJ_GRID GWHERE G.IS_DELETE = '0'AND  G.ORG_CODE IN (SELECT o.ORG_CODEFROM ZHONGHY_BASIC_INFO.DJ_ORG OWHERE o.is_delete = '0'AND o.is_del_org = '0'AND o.tenant_id = #{tenantId, jdbcType=DECIMAL}AND !REGEXP_LIKE(o.org_code, '^(000.001|000.002)')CONNECT BY PRIOR o.id = o.parent_idSTART WITH o.id = #{orgId, jdbcType=DECIMAL})GROUP BY G.GRID_CLASSORDER BY G.GRID_CLASS</select><select id="statisticGridPerson" parameterType="java.math.BigDecimal" resultMap="KeyValuePair">SELECT G.GRID_CLASS k,COUNT(*)     vFROM ZHONGHY_ONLINE_ANSWERS.DJ_GRID_RANGE RLEFT JOIN ZHONGHY_ONLINE_ANSWERS.DJ_GRID GON R.GRID_ID = G.ID AND R.IS_DELETE = '0'WHERE G.IS_DELETE = '0'AND G.ORG_CODE IN (SELECT o.ORG_CODEFROM ZHONGHY_BASIC_INFO.DJ_ORG OWHERE o.is_delete = '0'AND o.is_del_org = '0'AND o.tenant_id = #{tenantId, jdbcType=DECIMAL}AND !REGEXP_LIKE(o.org_code, '^(000.001|000.002)')CONNECT BY PRIOR o.id = o.parent_idSTART WITH o.id = #{orgId, jdbcType=DECIMAL})GROUP BY G.GRID_CLASSORDER BY G.GRID_CLASS</select>
</mapper>

  公共类EChartsResult

package com.cnpc.dj.party.common;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.math.BigDecimal;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedList;/*** 陕西信合 - 数据统计.*/
public class EChartsResult {public static final Comparator<? super Entry> VALUE_ASC = Comparator.comparing(Entry::getValue);public static final Comparator<? super Entry> VALUE_DESC = (Entry o1, Entry o2) -> o2.getValue().compareTo(o1.getValue());private Comparator<? super Entry> comparator;private LinkedHashMap<String, Entry> entryMap;private LinkedHashMap<String, BigDecimal> valueMap;private BigDecimal total;public void init(String[] names, String[] keys, Comparator<? super Entry> comparator) {// 初始化EntryMapif (names != null && names.length > 0) {this.entryMap = new LinkedHashMap<>(names.length);for (String name : names) {this.entryMap.put(name, new Entry(name, BigDecimal.ZERO, null));}}// 初始化ValueMapif (keys != null && keys.length > 0) {this.valueMap = new LinkedHashMap<>(keys.length);for (String key : keys) {this.valueMap.put(key, BigDecimal.ZERO);}}// 设置Comparatorthis.comparator = comparator;}public void setComparator(Comparator<? super Entry> comparator) {this.comparator = comparator;}public void addToList(String name, BigDecimal value) {if (this.entryMap == null) {this.entryMap = new LinkedHashMap<>();}if (this.entryMap.containsKey(name)) {this.entryMap.get(name).addValue(value);} else {this.entryMap.put(name, new Entry(name, value, null));}}public void addToMap(String key, BigDecimal value) {if (this.valueMap == null) {this.valueMap = new LinkedHashMap<>();}this.valueMap.put(key, this.valueMap.containsKey(key)? this.valueMap.get(key).add(value): value);}public void calculate() {this.calculateTotal();this.calculatePercent();}public void calculate(BigDecimal total) {this.calculateTotal();this.calculatePercent(total);}private void calculateTotal() {if (this.entryMap != null) {// 初始化Total.this.total = BigDecimal.ZERO;// 累加求和.for (Entry entry : this.entryMap.values()) {this.total = this.total.add(entry.getValue());}}}private void calculatePercent() {if (this.entryMap != null) {// 若Total未初始化, 则先计算Total.if (this.total == null) {this.calculateTotal();}// 遍历EntryMap的所有项目, 计算百分比.this.entryMap.values().forEach(entry -> entry.calculatePercent(this.total));}}private void calculatePercent(BigDecimal total) {if (this.entryMap != null) {// 遍历EntryMap的所有项目, 计算百分比.this.entryMap.values().forEach(entry -> entry.calculatePercent(total));}}public void buildMap() {this.calculate();LinkedList<Entry> list = this.getList();if (list != null) {for (Entry entry : list) {this.addToMap(entry.getName(), entry.getValue());this.addToMap(entry.getName() + "Percent", entry.getPercent());}this.addToMap("Total", this.total);}}public LinkedList<Entry> getList() {if (this.entryMap != null) {LinkedList<Entry> list = new LinkedList<>(this.entryMap.values());if (this.comparator != null) {list.sort(this.comparator);}return list;}return null;}public LinkedHashMap<String, BigDecimal> getMap() {return this.valueMap;}public BigDecimal getTotal() {return this.total;}/*** ECharts 统计列表项.** @author wangzijie05@cnpc.com.cn* @since 2019-03-15*/@Data@NoArgsConstructor@AllArgsConstructorpublic class Entry {private String name;private BigDecimal value;private BigDecimal percent;void addValue(BigDecimal augend) {this.value = this.value.add(augend);}void calculatePercent(BigDecimal total) {if (BigDecimal.ZERO.equals(total)) {this.percent = BigDecimal.ZERO;} else {this.percent = this.value.abs().divide(total, 10, BigDecimal.ROUND_HALF_UP);}}}
}

 公共类KeyValuePair

package com.cnpc.dj.party.common;import lombok.Data;@Data
public class KeyValuePair<T> {private String key;private T value;}

 postman测试

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/642201.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

js的算法-交换排序(快速排序)

快速排序 基本思想 快速排序的基本思想是基于分治法的&#xff1a;在待排序表L【1...n】中任意取一个元素p 作为枢轴&#xff08;或基准&#xff0c;通常取首元素&#xff09;。通过一趟排序将待排序表划分为独立的两部分L【1...k-1】和L【k1...n】;这样的话&#xff0c;L【1…

【视觉论文】VIT - Vision Transformers

论文&#xff1a;AN IMAGE IS WORTH 16X16 WORDS: TRANSFORMERS FOR IMAGE RECOGNITION AT SCALE 链接&#xff1a;https://arxiv.org/abs/2010.11929 很多人博主都写烂了的论文&#xff0c;我到现在才真正翻开论文看&#xff0c;21年的工作&#xff0c;正好是刚毕业那年&…

分析 MyBatis/MyBatis-Plus 慢 SQL 的分析组件 --SQL 慢镜️‍♀️

大家好&#xff01;我是聪ζ&#x1f331;我做了一个分析 MyBatis/MyBatis-Plus 慢 SQL 的分析组件 --SQL 慢镜&#x1f575;️‍♀️ GitHub仓库地址&#x1f680;: https://github.com/lhccong/sql-slow-mirror 点点 star 我的朋友们✨ 背景&#x1f9ca;&#xff1a; 大家…

使用autocannon和0x对网站进行性能分析(node)

npm i autocannon -g autocannon -c 100 -d 5 -p 10 http://localhost:3000/ 0x -o app.js 火焰图是根据程序的栈的状态对出现函数的采样数据统计而得&#xff0c;宽度代表函数运行一次所需的时长、高度代表栈的层数、颜色深度代表函数在采样中出现的频率&#xff0c;因此宽度…

Python-GEE遥感云大数据分析、管理与可视化

原文链接&#xff1a;Python-GEE遥感云大数据分析、管理与可视化https://mp.weixin.qq.com/s?__bizMzUzNTczMDMxMg&mid2247601238&idx2&sn6b0557cf61451eaff65f025d648da869&chksmfa820db1cdf584a76de953b96519704177e6206d4ecd47a2f2fabbcac2f7ea619b0bce184…

标准版/开源版 移动端新增页面使用文档

在标准版开发的实际使用中&#xff0c;随着用户移动端的产品和信息内容不断增多&#xff0c;新增页面来展示对应的产品详情、模块等内容。针对一些概念或者步骤较多的内容&#xff0c;可以新增子页面构建多级模块结构&#xff0c;帮助用户快速定位。 下面就如何新增页面做一讲…

2024深圳杯数学建模挑战赛B题:批量工件并行切割下料问题思路代码成品论文分析

更新完整代码和成品完整论文 《2024深圳杯&东三省数学建模思路代码成品论文》↓↓↓ https://www.yuque.com/u42168770/qv6z0d/zx70edxvbv7rheu7?singleDoc# 问题重述 深圳杯数学建模挑战赛2024B题&#xff1a;批量工件并行切割下料问题 板材切割下料是工程机械领域重要…

qmt教程1---qmt安装,提供下载链接

以前写的qmt不太完善现在重新好好的学习一下qmt&#xff0c;重新封装qmt&#xff0c;使用方便 1第一步下载qmt 点击安装 下一步 下一步 默认路径&#xff0c;安装完成 2登录qmt&#xff0c;选择行情加交易&#xff0c;选择极简模式 登录情况 我把qmt上线了 比如我们获取一分钟…

利用ollama和open-webui本地部署通义千问Qwen1.5-7B-Chat模型

目录 1 安装ollama 2 安装open-webui 2.1 镜像下载 3 配置ollama的模型转换工具环境 3.1 下载ollama源码 3.2 下载ollama子模块 3.3 创建ollama虚拟环境 3.4 安装依赖 3.5 编译量化工具 7 创建ollama模型 8 运行模型 参考文献&#xff1a; 1 安装ollama curl -fsSL …

算法训练营day15

一、层序遍历 参考链接7.2 二叉树遍历 - Hello 算法 (hello-algo.com) 层序遍历本质上属于广度优先遍历&#xff0c;也称广度优先搜索&#xff0c; BFS通常借助队列的先入先出的特性实现 参考链接102. 二叉树的层序遍历 - 力扣&#xff08;LeetCode&#xff09; 像这种较为…

2SD1666 封装TO-220F 实物拍摄 功能介绍

2SD1666 是一款 NPN 硅晶体管&#xff0c;适合于低频和音频放大以及开关应用。以下是它的主要功能和参数的详细介绍&#xff1a;功能:低频放大: 适用于音频放大器和其他低频放大应用。 开关: 可用于电源开关和电机控制等应用。 主要参数:极限工作电压 (VCEO): 60V 最大电流允许…

MySQL的创建用户以及用户权限

使用语言 MySQL 使用工具 Navicat Premium 16 代码能力快速提升小方法&#xff0c;看完代码自己敲一遍&#xff0c;十分有用 拖动表名到查询文件中就可以直接把名字拉进来中括号&#xff0c;就代表可写可不写 目录 1.创建用户 1.1 工具创建用户 1.2 脚本创建用户 1.2.…