From 74e332504d98caaf8fab951d7d24be762b169f49 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期三, 25 三月 2026 14:15:14 +0800
Subject: [PATCH] 销售金额
---
jyz-base-start/src/main/java/com/tievd/jyz/service/impl/OilRecordServiceImpl.java | 195 ++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 184 insertions(+), 11 deletions(-)
diff --git a/jyz-base-start/src/main/java/com/tievd/jyz/service/impl/OilRecordServiceImpl.java b/jyz-base-start/src/main/java/com/tievd/jyz/service/impl/OilRecordServiceImpl.java
index d9dbd53..3cdf8f9 100644
--- a/jyz-base-start/src/main/java/com/tievd/jyz/service/impl/OilRecordServiceImpl.java
+++ b/jyz-base-start/src/main/java/com/tievd/jyz/service/impl/OilRecordServiceImpl.java
@@ -154,13 +154,18 @@
public List<Map> statisOrgTopVolume(DataStatisReqVo param) {
return oilRecordMapper.statisOrgTopVolume(param);
}
+
+ @Override
+ public List<Map> statisOilFreqCompare(DataStatisReqVo param) {
+ return oilRecordMapper.statisOilFreqCompare(param);
+ }
@Override
public JSONObject statFan(DataStatisReqVo param) {
JSONObject res;
List<StatDataTableVo> dataList = new ArrayList<>();
Function<StatDataTableVo, ?> xfunc = null;
- Function<StatDataTableVo, Integer> barfunc = null;
+ Function<StatDataTableVo, ?> barfunc = null;
switch(param.getType()) {
case 1 :
dataList = oilRecordMapper.statFanByModel(param);
@@ -182,6 +187,16 @@
xfunc = StatDataTableVo::getOilPosition;
barfunc = StatDataTableVo::getOilVolume;
break;
+ case 5 :
+ dataList = oilRecordMapper.statFanByOilType(param);
+ xfunc = StatDataTableVo::getOilType;
+ barfunc = StatDataTableVo::getOilVolume;
+ break;
+ case 6 :
+ dataList = oilRecordMapper.statFanByOilType(param);
+ xfunc = StatDataTableVo::getOilType;
+ barfunc = StatDataTableVo::getTotalAmount;
+ break;
}
res = dataTransLists(dataList, xfunc, barfunc, null, "", "");
return res;
@@ -193,8 +208,8 @@
JSONObject res;
List<StatDataTableVo> dataList;
Function<StatDataTableVo, ?> xfunc;
- Function<StatDataTableVo, Integer> barfunc;
- Function<StatDataTableVo, Integer> linefunc;
+ Function<StatDataTableVo, ?> barfunc;
+ Function<StatDataTableVo, ?> linefunc;
String barName = "";
String lineName = "";
if (param.getType() == 1) {
@@ -204,12 +219,26 @@
linefunc = StatDataTableVo::getCarCount;
barName = "鍔犳补鏁�";
lineName = "杞︽祦閲�";
- } else {
+ } else if (param.getType() == 2) {
dataList = oilRecordMapper.statFanByPosition(param);
xfunc = StatDataTableVo::getOilPosition;
barfunc = StatDataTableVo::getOilCount;
linefunc = StatDataTableVo::getOilVolume;
barName = "鍔犳补鏁�";
+ lineName = "娌瑰搧閿�閲�";
+ } else if (param.getType() == 3) {
+ dataList = oilRecordMapper.statFanByOilType(param);
+ xfunc = StatDataTableVo::getOilType;
+ barfunc = StatDataTableVo::getOilVolume;
+ linefunc = StatDataTableVo::getTotalAmount;
+ barName = "娌瑰搧閿�閲�";
+ lineName = "閿�鍞噾棰�";
+ } else {
+ dataList = oilRecordMapper.statFanByOilType(param);
+ xfunc = StatDataTableVo::getOilType;
+ barfunc = StatDataTableVo::getTotalAmount;
+ linefunc = StatDataTableVo::getOilVolume;
+ barName = "閿�鍞噾棰�";
lineName = "娌瑰搧閿�閲�";
}
res = dataTransLists(dataList, xfunc, barfunc, linefunc, barName, lineName);
@@ -231,6 +260,7 @@
.minus(timeUnit.value(), ChronoUnit.valueOf(timeUnit.name()))
.with(timeUnit.initField(), 1);
LocalDateTime timeLimitRight = LocalDateTime.now().with(timeUnit.initField(), 1);
+ log.info("鎵撳嵃鏃堕棿寮�濮�: {}, 鎵撳嵃鏃堕棿缁撴潫: {}", timeLimit.toString(), timeLimitRight.toString());
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<OilRecord>()
.ge(OilRecord::getStartTime, timeLimit.toString())
.le(OilRecord::getStartTime, timeLimitRight.toString())
@@ -258,6 +288,7 @@
statVo.addAppearCount(1);
if (record.getBehavior().intValue() == SystemConstant.BEHAVIOR_TYPE_OIL) statVo.addOilCount(1);
if (record.getBehavior().intValue() == SystemConstant.BEHAVIOR_TYPE_OIL) statVo.addOilVolume(record.getOilVolume());
+ if (record.getBehavior().intValue() == SystemConstant.BEHAVIOR_TYPE_OIL) statVo.addTotalAmount(record.getTotalAmount());
statVo.addSumSpand(record.getSpandTime());
}
@@ -363,6 +394,136 @@
res.put("lineData", lineDatas);
return res;
}
+
+ @Override
+ public List<Map<String, Object>> statTrendDetail(DataStatisReqVo param) {
+ if (param.getTrendType() == null || param.getTimeUnit() == null || param.getStatTime() == null) {
+ return new ArrayList<>();
+ }
+ DataStatisReqVo.TrendType trendType = param.getTrendType();
+ DataStatisReqVo.StatUnit timeUnit = param.getTimeUnit();
+ LocalDateTime[] timeRange = getTrendTimeRange(timeUnit);
+ LocalDateTime timeLimit = timeRange[0];
+ LocalDateTime timeLimitRight = timeRange[1];
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern(timeUnit.statFormat());
+ String statTime = param.getStatTime();
+ List<Map<String, Object>> detailList = new ArrayList<>();
+
+ if (trendType == DataStatisReqVo.TrendType.TRAFFIC) {
+ LambdaQueryWrapper<TrafficFlow> wrapper = new LambdaQueryWrapper<TrafficFlow>()
+ .ge(TrafficFlow::getCaptureTime, timeLimit.toString())
+ .le(TrafficFlow::getCaptureTime, timeLimitRight.toString())
+ .likeRight(TrafficFlow::getOrgCode, param.getOrgCode())
+ .orderByDesc(TrafficFlow::getCaptureTime);
+ List<TrafficFlow> list = trafficFlowMapper.selectList(wrapper);
+ for (TrafficFlow trafficFlow : list) {
+ if (!matchStatTime(trafficFlow.getCaptureTime().toLocalDateTime(), formatter, statTime)) {
+ continue;
+ }
+ Map<String, Object> row = new LinkedHashMap<>();
+ row.put("id", trafficFlow.getId());
+ row.put("captureTime", trafficFlow.getCaptureTime());
+ row.put("carCount", trafficFlow.getCarCount());
+ row.put("modelCode", trafficFlow.getModelCode());
+ row.put("cameraCode", trafficFlow.getCameraCode());
+ detailList.add(row);
+ }
+ return detailList;
+ }
+
+ if (trendType == DataStatisReqVo.TrendType.CLIENT || trendType == DataStatisReqVo.TrendType.LOSE_CLIENT) {
+ LambdaQueryWrapper<OilStatis> wrapper = new LambdaQueryWrapper<OilStatis>()
+ .ge(OilStatis::getUpdateTimeSelf, timeLimit.toString())
+ .le(OilStatis::getUpdateTimeSelf, timeLimitRight.toString())
+ .likeRight(OilStatis::getOrgCode, param.getOrgCode())
+ .orderByDesc(OilStatis::getUpdateTimeSelf);
+ List<OilStatis> list = oilStaticMapper.selectList(wrapper);
+ for (OilStatis oilStatis : list) {
+ if (!matchStatTime(oilStatis.getUpdateTimeSelf().toLocalDateTime(), formatter, statTime)) {
+ continue;
+ }
+ if (trendType == DataStatisReqVo.TrendType.CLIENT
+ && param.getSeriesName() != null
+ && !param.getSeriesName().equals(oilStatis.getClientName())) {
+ continue;
+ }
+ if (trendType == DataStatisReqVo.TrendType.LOSE_CLIENT
+ && (oilStatis.getClientId() == null || oilStatis.getClientId() != SystemConstant.LOSE_CLIENT_ID)) {
+ continue;
+ }
+ Map<String, Object> row = new LinkedHashMap<>();
+ row.put("id", oilStatis.getId());
+ row.put("updateTimeSelf", oilStatis.getUpdateTimeSelf());
+ row.put("licenseNum", oilStatis.getLicenseNum());
+ row.put("clientName", oilStatis.getClientName());
+ row.put("oilCount", oilStatis.getOilCount());
+ row.put("oilSum", oilStatis.getOilSum());
+ detailList.add(row);
+ }
+ return detailList;
+ }
+
+ LambdaQueryWrapper<OilRecord> wrapper = new LambdaQueryWrapper<OilRecord>()
+ .ge(OilRecord::getStartTime, timeLimit.toString())
+ .le(OilRecord::getStartTime, timeLimitRight.toString())
+ .likeRight(OilRecord::getOrgCode, param.getOrgCode())
+ .orderByDesc(OilRecord::getStartTime);
+ List<OilRecord> records = this.list(wrapper);
+ for (OilRecord oilRecord : records) {
+ if (!matchStatTime(oilRecord.getStartTime().toLocalDateTime(), formatter, statTime)) {
+ continue;
+ }
+ if (trendType == DataStatisReqVo.TrendType.OIL
+ && (oilRecord.getBehavior() == null || oilRecord.getBehavior().intValue() != SystemConstant.BEHAVIOR_TYPE_OIL)) {
+ continue;
+ }
+ if (trendType == DataStatisReqVo.TrendType.OIL_vOLUME
+ && (oilRecord.getBehavior() == null || oilRecord.getBehavior().intValue() != SystemConstant.BEHAVIOR_TYPE_OIL)) {
+ continue;
+ }
+ if (trendType == DataStatisReqVo.TrendType.SALES_AMOUNT
+ && (oilRecord.getBehavior() == null || oilRecord.getBehavior().intValue() != SystemConstant.BEHAVIOR_TYPE_OIL)) {
+ continue;
+ }
+ Map<String, Object> row = new LinkedHashMap<>();
+ row.put("id", oilRecord.getId());
+ row.put("startTime", oilRecord.getStartTime());
+ row.put("licenseNum", oilRecord.getLicenseNum());
+ row.put("behavior", oilRecord.getBehavior());
+ row.put("behaviorText", behaviorText(oilRecord.getBehavior()));
+ row.put("oilPosition", oilRecord.getOilPosition());
+ row.put("oilVolume", oilRecord.getOilVolume());
+ row.put("totalAmount", oilRecord.getTotalAmount());
+ row.put("spandTime", oilRecord.getSpandTime());
+ detailList.add(row);
+ }
+ return detailList;
+ }
+
+ private LocalDateTime[] getTrendTimeRange(DataStatisReqVo.StatUnit timeUnit) {
+ LocalDateTime timeLimit = LocalDateTime.now()
+ .minus(timeUnit.value(), ChronoUnit.valueOf(timeUnit.name()))
+ .with(timeUnit.initField(), 1);
+ LocalDateTime timeLimitRight = LocalDateTime.now().with(timeUnit.initField(), 1);
+ return new LocalDateTime[]{timeLimit, timeLimitRight};
+ }
+
+ private boolean matchStatTime(LocalDateTime time, DateTimeFormatter formatter, String statTime) {
+ return formatter.format(time).equals(statTime);
+ }
+
+ private String behaviorText(Byte behavior) {
+ if (behavior == null) {
+ return "";
+ }
+ if (behavior.intValue() == SystemConstant.BEHAVIOR_TYPE_OIL) {
+ return "鍔犳补";
+ }
+ if (behavior.intValue() == SystemConstant.BEHAVIOR_TYPE_TMP) {
+ return "鍋滈潬";
+ }
+ return behavior.toString();
+ }
private <E> JSONObject dataTransLists(
List<E> dataList,
@@ -372,16 +533,21 @@
String barName,
String lineName) {
List xDatas = new ArrayList();
- List<Integer> barDatas = new ArrayList<>();
+ List<Object> barDatas = new ArrayList<>();
List lineDatas = new ArrayList<>();
- int sum = 0;
+ double sum = 0;
for (E statVo : dataList) {
Object xData = "";
- int barData = 0;
+ Object barData = 0;
Object lineData = 0;
try {
xData = xDataMapper.apply(statVo);
- barData = Integer.valueOf(barDataMapper.apply(statVo).toString());
+ Object barValue = barDataMapper.apply(statVo);
+ if (barValue instanceof java.math.BigDecimal) {
+ barData = ((java.math.BigDecimal) barValue).doubleValue();
+ } else {
+ barData = Integer.valueOf(barValue.toString());
+ }
if (lineDataMapper != null) lineData = lineDataMapper.apply(statVo);
} catch (Exception e) {
e.printStackTrace();
@@ -391,11 +557,18 @@
xDatas.add(xData);
barDatas.add(barData);
lineDatas.add(lineData);
- sum += barData;
+ if (barData instanceof Number) {
+ sum += ((Number) barData).doubleValue();
+ }
}
if (lineDataMapper == null) {
- int finalSum = sum;
- lineDatas = barDatas.stream().map(n -> n*100/ finalSum).collect(Collectors.toList());
+ double finalSum = sum;
+ lineDatas = barDatas.stream().map(n -> {
+ if (n instanceof Number) {
+ return ((Number) n).doubleValue() * 100 / finalSum;
+ }
+ return 0;
+ }).collect(Collectors.toList());
}
JSONObject res = new JSONObject();
res.put("xData", xDatas);
--
Gitblit v1.8.0