修改交易统计图

This commit is contained in:
liuwu 2024-03-04 16:48:38 +08:00
parent a76d95e089
commit 5c37fc10dc
3 changed files with 54 additions and 31 deletions

View File

@ -1,5 +1,6 @@
package com.cyx.web.base.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.cyx.common.core.controller.BaseController;
import com.cyx.common.core.domain.AjaxResult;
@ -26,6 +27,7 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@Controller
@RequestMapping("/base/index")
@ -135,17 +137,32 @@ public class BigScreenController extends BaseController {
@ResponseBody
public AjaxResult tradeEcharts(TAmentTrade tAmentTrade) {
AtomicInteger yearCount = new AtomicInteger();
AtomicInteger allCount = new AtomicInteger();
AtomicReference<Double> yearMoney = new AtomicReference<>(0.0000);
AtomicReference<Double> allMoney = new AtomicReference<>(0.0000);
int monthCount = 0;
double monthMoney = 0.0000;
JSONObject object = new JSONObject();
List<Map<String, Object>> list = tAmentTradeService.tradeEcharts(tAmentTrade);
String year = DateUtils.parseDateToStr("YYYY", new Date());
String month = DateUtils.parseDateToStr("YYYY-MM", new Date());
Map<String, String> tradeMap = new TreeMap<>();
JSONArray typeArray = new JSONArray();
JSONArray dataArray = new JSONArray();
String month = DateUtils.parseDateToStr("YYYY-MM", new Date());
List<Map<String, Object>> listMon = list.stream().filter(v->month.equals(v.get("month").toString())).collect(Collectors.toList());
List<Map<String, Object>> listYear = list.stream().filter(v->(v.get("month").toString().contains(year))).collect(Collectors.toList());
// 按照 category 分组并对每个分组的 amount 求和
Map<String, Double> allTrade = list.stream()
.collect(Collectors.groupingBy(s->s.get("type").toString(), Collectors.summingDouble(s->Double.parseDouble(s.get("trade").toString()))));
Map<String, Double> monTrade = listMon.stream()
.collect(Collectors.groupingBy(s->s.get("type").toString(), Collectors.summingDouble(s->Double.parseDouble(s.get("trade").toString()))));
Map<String, Double> yearTrade = listYear.stream()
.collect(Collectors.groupingBy(s->s.get("type").toString(), Collectors.summingDouble(s->Double.parseDouble(s.get("trade").toString()))));
list.forEach(l -> {
String month1 = l.get("month").toString();
allMoney.updateAndGet(v -> v + Double.parseDouble(l.get("trade").toString()));
allCount.addAndGet(Integer.parseInt(l.get("count").toString()));
if (month1.equals(month)){
typeArray.add(l.get("type"));
}
@ -153,9 +170,10 @@ public class BigScreenController extends BaseController {
array.forEach(a -> {
Map<String, Object> m = (Map<String, Object>) a;
tradeMap.put(m.get("label").toString(), m.get("label").toString());
yearCount.addAndGet(Integer.parseInt(m.get("count").toString()));
yearMoney.updateAndGet(v -> new Double((double) (v + Double.parseDouble(m.get("trade").toString()))));
if (month1.contains(month)){
yearCount.addAndGet(Integer.parseInt(m.get("count").toString()));
yearMoney.updateAndGet(v -> v + Double.parseDouble(m.get("trade").toString()));
}
});
});
// 所有小分类
@ -194,8 +212,13 @@ public class BigScreenController extends BaseController {
object.put("monthMoney", monthMoney);
object.put("yearCount", yearCount);
object.put("yearMoney", yearMoney);
object.put("allCount", allCount);
object.put("allMoney", allMoney);
object.put("type", typeArray);
object.put("data", dataArray);
object.put("allTrade", JSON.parseObject(JSON.toJSONString(allTrade)));
object.put("yearTrade", JSON.parseObject(JSON.toJSONString(yearTrade)));
object.put("monTrade", JSON.parseObject(JSON.toJSONString(monTrade)));
return AjaxResult.success(object);
}

View File

@ -110,8 +110,8 @@
<span class="trade_month_money" style="margin-left: 20px">当月累计交易额0万元</span>
</div>
<div style="margin: 1% 0;color: #fff;font-size: 12px;width: 100%;text-align: center">
<span class="trade_all_num">全年累计交易数0</span>
<span class="trade_all_money" style="margin-left: 20px">全年累计交易额0万元</span>
<span class="trade_year_num">全年累计交易数0</span>
<span class="trade_year_money" style="margin-left: 20px">全年累计交易额0万元</span>
</div>
<div style="margin: 1% 0;color: #fff;font-size: 12px;width: 100%;text-align: center">
<span class="trade_all_num">历年累计交易数0</span>
@ -764,8 +764,10 @@
let _allNumData = _data.data;
$('.trade_month_num').text('当月累计交易数:'+_data.monthCount);
$('.trade_month_money').text('当月累计交易额:'+_data.monthMoney.toFixed(4)+'万元');
$('.trade_all_num').text('全年累计交易数:'+_data.yearCount);
$('.trade_all_money').text('全年累计交易额:'+_data.yearMoney.toFixed(4)+'万元');
$('.trade_year_num').text('当年累计交易数:'+_data.yearCount);
$('.trade_year_money').text('当年累计交易额:'+_data.yearMoney.toFixed(4)+'万元');
$('.trade_all_num').text('历年累计交易数:'+_data.allCount);
$('.trade_all_money').text('历年累计交易额:'+_data.allMoney.toFixed(4)+'万元');
_data.data.forEach(item => {
_sData.push({
name: item.name,
@ -779,14 +781,28 @@
})
})
//加载饼状图
loadCirCleData('center_footer_chart')
loadCirCleData(_data,'center_footer_chart')
}
})
}
//加载饼状图
function loadCirCleData(dom){
function loadCirCleData(data,dom){
let chart = echarts.init(document.getElementById(dom));
var source = []
source.push(['', '', 'Price', 'Year'])
var json = data.allTrade;
for (let key in json) {
source.push([key, Number(json[key]).toFixed(4), Number(json[key]).toFixed(4), 'all'])
}
var json1 = data.yearTrade;
for (let key in json1) {
source.push([key, json1[key], Number(json1[key]).toFixed(4), 'all'])
}
var json2 = data.monTrade;
for (let key in json2) {
source.push([key, json2[key], Number(json2[key]).toFixed(4), 'all'])
}
let option = {
title:[
{
@ -829,42 +845,30 @@
},
dataset: [
{
source: [
['', 'Sales', 'Price', 'Year'],
['工程招投标', 235, 5, 2011],
['政府采购', 341, 25, 2011],
['产权交易', 122, 29, 2011],
['工程招投标', 255, 7, 2012],
['政府采购', 241, 27, 2012],
['产权交易', 102, 34, 2012],
['工程招投标', 395, 4, 2013],
['政府采购', 281, 31, 2013],
['产权交易', 92, 39, 2013],
]
source: source
},
{
transform: {
type: 'filter',
config: { dimension: 'Year', value: 2011 }
config: { dimension: 'Year', value: 'mon' }
}
},
{
transform: {
type: 'filter',
config: { dimension: 'Year', value: 2012 }
config: { dimension: 'Year', value: 'year' }
}
},
{
transform: {
type: 'filter',
config: { dimension: 'Year', value: 2013 }
config: { dimension: 'Year', value: 'all' }
}
}
],
series: [
{
type: 'pie',
name:'2022',
radius: 50,
center: ['50%', '25%'],
datasetIndex: 1,

View File

@ -33,7 +33,7 @@
where id = #{id}
</select>
<select id="tradeEcharts" resultType="map">
<select id="tradeEcharts" parameterType="TAmentTrade" resultType="map">
SELECT
month_of 'month',
type,
@ -42,10 +42,6 @@
GROUP_CONCAT( '{"label":"', trade_type, '","trade":', trade_mony, ',"count":', trade_count, '}' ) json
FROM
t_ament_trade
WHERE 1=1
<if test="year != null and year != ''">
AND DATE_FORMAT(month_of, '%Y') = #{year}
</if>
GROUP BY
month_of,
type