From b6ec30ea7a8f493aa930e8efb05e5bc528b1da5c Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 12 十二月 2025 15:13:02 +0800
Subject: [PATCH] yys BI大屏接口修改
---
src/main/resources/mapper/production/SalesLedgerWorkMapper.xml | 2
src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml | 2
src/main/java/com/ruoyi/account/service/impl/AccountExpenseServiceImpl.java | 103 +++++++++++++++++++------
src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java | 106 +++++++++++++++++---------
4 files changed, 149 insertions(+), 64 deletions(-)
diff --git a/src/main/java/com/ruoyi/account/service/impl/AccountExpenseServiceImpl.java b/src/main/java/com/ruoyi/account/service/impl/AccountExpenseServiceImpl.java
index a3c775f..6017793 100644
--- a/src/main/java/com/ruoyi/account/service/impl/AccountExpenseServiceImpl.java
+++ b/src/main/java/com/ruoyi/account/service/impl/AccountExpenseServiceImpl.java
@@ -24,8 +24,10 @@
import java.math.BigDecimal;
import java.time.DayOfWeek;
import java.time.LocalDate;
+import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
+import java.util.stream.Collectors;
@AllArgsConstructor
@Service
@@ -115,38 +117,87 @@
@Override
public Map<String, List<String>> analysis() {
- // 鑾峰彇鏈懆鐨勬椂闂磋寖鍥�
- LocalDate startOfWeek = LocalDate.now().with(DayOfWeek.MONDAY);
- LocalDate endOfWeek = LocalDate.now().with(DayOfWeek.SUNDAY);
+ // 鑾峰彇鏈�杩戝洓涓湀锛堝綋鍓嶆湀 + 鍓�3涓湀锛夌殑鏃堕棿鑼冨洿
+ LocalDate today = LocalDate.now();
+ DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM"); // 骞存湀鏍煎紡鍖栧櫒
Map<String, List<String>> result = new HashMap<>();
- List<String> days = new ArrayList<>();
- List<String> totalIncomeList = new ArrayList<>();
- List<String> totalExpenseList = new ArrayList<>();
- List<String> netIncomeList = new ArrayList<>();
- // 鏍规嵁鏃堕棿鑼冨洿寰幆鏌ヨ姣忎竴澶╃殑鎬绘敹鍏ワ紝鎬绘敮鍑�,鍑�鏀跺叆锛堟�绘敹鍏�-鎬绘敮鍑猴級
- for (LocalDate date = startOfWeek; date.isBefore(endOfWeek) || date.isEqual(endOfWeek); date = date.plusDays(1)) {
- BigDecimal totalIncome = accountIncomeMapper.selectList(Wrappers.<AccountIncome>lambdaQuery()
- .eq(AccountIncome::getInputTime, date.toString()))
- .stream()
- .map(AccountIncome::getIncomeMoney)
- .filter(Objects::nonNull)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
- BigDecimal totalExpense = accountExpenseMapper.selectList(Wrappers.<AccountExpense>lambdaQuery()
- .eq(AccountExpense::getInputTime, date.toString()))
- .stream()
- .map(AccountExpense::getExpenseMoney)
- .filter(Objects::nonNull)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
+ List<String> months = new ArrayList<>(); // 瀛樺偍骞存湀锛堝 2025-12銆�2025-11锛�
+ List<String> totalIncomeList = new ArrayList<>(); // 姣忔湀鎬绘敹鍏�
+ List<String> totalExpenseList = new ArrayList<>(); // 姣忔湀鎬绘敮鍑�
+ List<String> netIncomeList = new ArrayList<>(); // 姣忔湀鍑�鏀跺叆锛堟敹鍏�-鏀嚭锛�
+
+ // 姝ラ1锛氳绠楄繎4涓湀鐨勫勾鏈堝垪琛紙褰撳墠鏈堛�佸墠1鏈堛�佸墠2鏈堛�佸墠3鏈堬級
+ List<String> targetMonths = new ArrayList<>();
+ for (int i = 0; i < 4; i++) {
+ LocalDate currentMonth = today.minusMonths(i);
+ String monthStr = currentMonth.format(monthFormatter);
+ targetMonths.add(monthStr);
+ }
+ // 鍙嶈浆鍒楄〃锛岀‘淇濋『搴忎负銆屽墠3鏈� 鈫� 褰撳墠鏈堛�嶏紙鍙�夛紝鎸夐渶姹傝皟鏁撮『搴忥級
+ Collections.reverse(targetMonths);
+
+ // 姝ラ2锛氫竴娆℃�ф煡璇㈣繎4涓湀鎵�鏈夋敹鍏ユ暟鎹紝鎸夆�滃勾鏈堚�濆垎缁勬眹鎬�
+ LocalDate fourMonthsAgo = today.minusMonths(3).withDayOfMonth(1); // 杩�4涓湀璧峰鏃ワ紙鍓�3鏈�1鍙凤級
+ LocalDate currentMonthEnd = today.withDayOfMonth(today.lengthOfMonth()); // 褰撳墠鏈堢粨鏉熸棩
+ ZoneId zoneId = ZoneId.of("Asia/Shanghai");
+ // 鏌ヨ杩�4涓湀鎵�鏈夋敹鍏�
+ List<AccountIncome> allIncomes = accountIncomeMapper.selectList(
+ Wrappers.<AccountIncome>lambdaQuery()
+ .ge(AccountIncome::getIncomeDate, fourMonthsAgo.toString()) // 澶т簬绛変簬璧峰鏃�
+ .le(AccountIncome::getIncomeDate, currentMonthEnd.toString()) // 灏忎簬绛変簬缁撴潫鏃�
+ );
+
+ // 鏀跺叆鎸夆�滃勾鏈堚�濆垎缁勬眹鎬伙紙key锛氬勾鏈堝瓧绗︿覆锛寁alue锛氬綋鏈堟�绘敹鍏ワ級
+ Map<String, BigDecimal> monthlyIncomeMap = allIncomes.stream()
+ .filter(income -> income.getIncomeMoney() != null) // 杩囨护绌洪噾棰�
+ .collect(Collectors.groupingBy(
+ income -> {
+ // 灏嗚緭鍏ユ椂闂达紙瀛楃涓诧級杞崲涓篖ocalDate锛屽啀鏍煎紡鍖栦负骞存湀
+ LocalDate inputDate = income.getIncomeDate().toInstant().atZone(zoneId).toLocalDate();
+ return inputDate.format(monthFormatter);
+ },
+ Collectors.reducing(BigDecimal.ZERO, AccountIncome::getIncomeMoney, BigDecimal::add)
+ ));
+
+ // 姝ラ3锛氫竴娆℃�ф煡璇㈣繎4涓湀鎵�鏈夋敮鍑烘暟鎹紝鎸夆�滃勾鏈堚�濆垎缁勬眹鎬�
+ List<AccountExpense> allExpenses = accountExpenseMapper.selectList(
+ Wrappers.<AccountExpense>lambdaQuery()
+ .ge(AccountExpense::getExpenseDate, fourMonthsAgo.toString())
+ .le(AccountExpense::getExpenseDate, currentMonthEnd.toString())
+ );
+
+ // 鏀嚭鎸夆�滃勾鏈堚�濆垎缁勬眹鎬�
+ Map<String, BigDecimal> monthlyExpenseMap = allExpenses.stream()
+ .filter(expense -> expense.getExpenseMoney() != null) // 杩囨护绌洪噾棰�
+ .collect(Collectors.groupingBy(
+ expense -> {
+ LocalDate inputDate = expense.getExpenseDate().toInstant().atZone(zoneId).toLocalDate();
+ return inputDate.format(monthFormatter);
+ },
+ Collectors.reducing(BigDecimal.ZERO, AccountExpense::getExpenseMoney, BigDecimal::add)
+ ));
+
+ // 姝ラ4锛氬惊鐜�4涓洰鏍囨湀浠斤紝濉厖缁熻鏁版嵁锛堟棤鏁版嵁鏃堕粯璁や负0锛�
+ for (String month : targetMonths) {
+ // 褰撴湀鎬绘敹鍏ワ紙鏃犳暟鎹垯涓�0锛�
+ BigDecimal totalIncome = monthlyIncomeMap.getOrDefault(month, BigDecimal.ZERO);
+ // 褰撴湀鎬绘敮鍑猴紙鏃犳暟鎹垯涓�0锛�
+ BigDecimal totalExpense = monthlyExpenseMap.getOrDefault(month, BigDecimal.ZERO);
+ // 褰撴湀鍑�鏀跺叆锛堟敹鍏� - 鏀嚭锛�
BigDecimal netIncome = totalIncome.subtract(totalExpense);
- days.add(date.toString());
+
+ // 濉厖鍒楄〃
+ months.add(month);
totalIncomeList.add(totalIncome.toString());
totalExpenseList.add(totalExpense.toString());
netIncomeList.add(netIncome.toString());
}
- result.put("days", days); // 澶�
- result.put("totalIncome", totalIncomeList); // 鏀跺叆
- result.put("totalExpense", totalExpenseList); // 鏀嚭
- result.put("netIncome", netIncomeList); // 鍑�鏀跺叆
+
+ // 缁勮缁撴灉
+ result.put("days", months); // 骞存湀锛堝 ["2025-09", "2025-10", "2025-11", "2025-12"]锛�
+ result.put("totalIncome", totalIncomeList); // 瀵瑰簲鏈堜唤鎬绘敹鍏�
+ result.put("totalExpense", totalExpenseList); // 瀵瑰簲鏈堜唤鎬绘敮鍑�
+ result.put("netIncome", netIncomeList); // 瀵瑰簲鏈堜唤鍑�鏀跺叆
return result;
}
diff --git a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
index 1dddeb8..0f822dd 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -44,6 +44,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
+import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
@@ -270,50 +271,83 @@
@Override
public QualityStatisticsDto qualityStatistics() {
- // 鑾峰彇涓�鍛ㄦ暟鎹�
- // 鑾峰彇褰撳墠鏃堕棿
+ // 鑾峰彇杩戝洓涓湀鏁版嵁锛堝線鍓嶆帹涓変釜鏈堬紝鍏�4涓畬鏁存湀浠斤級
LocalDate today = LocalDate.now();
- // 鑾峰彇鏈懆鍛ㄤ竴
- LocalDate startOfWeek = today.with(DayOfWeek.MONDAY);
- // 鑾峰彇鏈懆鍛ㄦ棩
- LocalDate endOfWeek = today.with(DayOfWeek.SUNDAY);
- LambdaQueryWrapper<QualityInspect> qualityInspectLambdaQueryWrapper = new LambdaQueryWrapper<>();
- qualityInspectLambdaQueryWrapper.ge(QualityInspect::getCheckTime, startOfWeek)
- .gt(QualityInspect::getCheckTime, endOfWeek);
- List<QualityInspect> qualityInspects = qualityStatisticsMapper.selectList(qualityInspectLambdaQueryWrapper);
+ // 瀹氫箟鏃ユ湡鏍煎紡鍖栧櫒锛堢敤浜庢樉绀衡�滃勾鏈堚�濇牸寮忥級
+ DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
+
QualityStatisticsDto qualityStatisticsDto = new QualityStatisticsDto();
- qualityStatisticsDto.setSupplierNum(qualityInspects.stream().filter(item -> item.getInspectType().equals(0)).map(QualityInspect::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add));
- qualityStatisticsDto.setProcessNum(qualityInspects.stream().filter(item -> item.getInspectType().equals(1)).map(QualityInspect::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add));
- qualityStatisticsDto.setFactoryNum(qualityInspects.stream().filter(item -> item.getInspectType().equals(2)).map(QualityInspect::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add));
List<QualityStatisticsItem> qualityStatisticsItems = new ArrayList<>();
- for (int j = 1; j < 8; j++) {
- LocalDate endTime = startOfWeek.plusDays(j);
- LocalDate startTime = endTime.minusDays(1);
- QualityStatisticsItem qualityStatisticsItem = new QualityStatisticsItem();
- qualityStatisticsItem.setDate(startTime.toString());
- qualityStatisticsItem.setSupplierNum(qualityInspects.stream()
- .filter(item -> item.getInspectType().equals(0) && "涓嶅悎鏍�".equals(item.getCheckResult())
- && (startTime.isEqual(item.getCheckTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()) || startTime.isAfter(item.getCheckTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()))
- && endTime.isBefore(item.getCheckTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()))
+
+ BigDecimal supplierNum = new BigDecimal(0);
+ BigDecimal factoryNum = new BigDecimal(0);
+ BigDecimal processNum = new BigDecimal(0);
+ // 寰幆4娆★紝鍒嗗埆缁熻杩�4涓湀鐨勬暟鎹紙褰撳墠鏈堛�佸墠1涓湀銆佸墠2涓湀銆佸墠3涓湀锛�
+ for (int i = 3; i >= 0; i--) {
+ // 璁$畻褰撳墠寰幆瀵瑰簲鐨勬湀浠斤紙i=0锛氬綋鍓嶆湀锛宨=1锛氬墠1涓湀锛屼互姝ょ被鎺級
+ LocalDate currentMonth = today.minusMonths(i);
+ // 褰撴湀鐨勫紑濮嬫棩鏈燂紙姣忔湀1鍙凤級
+ LocalDate monthStart = currentMonth.withDayOfMonth(1);
+ // 褰撴湀鐨勭粨鏉熸棩鏈燂紙姣忔湀鏈�鍚庝竴澶╋級
+ LocalDate monthEnd = currentMonth.withDayOfMonth(currentMonth.lengthOfMonth());
+
+ // 鏋勫缓褰撴湀鐨勬煡璇㈡潯浠讹紙濡傛灉鎯充竴娆℃�ф煡鍏�4涓湀鏁版嵁鍐嶅唴瀛樼瓫閫夛紝鍙紭鍖栦负鍏堟煡鍏ㄥ啀寰幆绛涢�夛級
+ LambdaQueryWrapper<QualityInspect> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.ge(QualityInspect::getCheckTime, monthStart)
+ .le(QualityInspect::getCheckTime, monthEnd); // 绛涢�夊綋鏈堟暟鎹�
+ List<QualityInspect> monthInspects = qualityStatisticsMapper.selectList(queryWrapper);
+ BigDecimal reduce = monthInspects.stream()
+ .filter(inspect -> inspect.getInspectType().equals(0))
.map(QualityInspect::getQuantity)
- .reduce(BigDecimal.ZERO, BigDecimal::add)
- );
- qualityStatisticsItem.setFactoryNum(qualityInspects.stream()
- .filter(item -> item.getInspectType().equals(1) && "涓嶅悎鏍�".equals(item.getCheckResult())
- && (startTime.isEqual(item.getCheckTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()) || startTime.isAfter(item.getCheckTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()))
- && endTime.isBefore(item.getCheckTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()))
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ supplierNum = supplierNum.add(reduce);
+ BigDecimal reduce1 = monthInspects.stream()
+ .filter(inspect -> inspect.getInspectType().equals(1))
.map(QualityInspect::getQuantity)
- .reduce(BigDecimal.ZERO, BigDecimal::add)
- );
- qualityStatisticsItem.setProcessNum(qualityInspects.stream()
- .filter(item -> item.getInspectType().equals(2) && "涓嶅悎鏍�".equals(item.getCheckResult())
- && (startTime.isEqual(item.getCheckTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()) || startTime.isAfter(item.getCheckTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()))
- && endTime.isBefore(item.getCheckTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()))
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ processNum= processNum.add(reduce1);
+ BigDecimal reduce2 = monthInspects.stream()
+ .filter(inspect -> inspect.getInspectType().equals(2))
.map(QualityInspect::getQuantity)
- .reduce(BigDecimal.ZERO, BigDecimal::add));
- qualityStatisticsItems.add(qualityStatisticsItem);
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ factoryNum = factoryNum.add(reduce2);
+
+ // 鏋勫缓褰撴湀缁熻椤�
+ QualityStatisticsItem item = new QualityStatisticsItem();
+ item.setDate(monthStart.format(monthFormatter)); // 鏃ユ湡鏄剧ず涓衡�滃勾鏈堚�濓紙濡� 2025-10锛�
+
+ // 1. 渚涘簲鍟嗘楠岋紙绫诲瀷0锛�- 鍚堟牸鏁伴噺
+ BigDecimal supplierQualified = monthInspects.stream()
+ .filter(inspect -> inspect.getInspectType().equals(0)
+ && "鍚堟牸".equals(inspect.getCheckResult()))
+ .map(QualityInspect::getQuantity)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ item.setSupplierNum(supplierQualified);
+
+ // 2. 宸ュ簭妫�楠岋紙绫诲瀷1锛�- 鍚堟牸鏁伴噺
+ BigDecimal processQualified = monthInspects.stream()
+ .filter(inspect -> inspect.getInspectType().equals(1)
+ && "鍚堟牸".equals(inspect.getCheckResult()))
+ .map(QualityInspect::getQuantity)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ item.setProcessNum(processQualified);
+
+ // 3. 宸ュ巶妫�楠岋紙绫诲瀷2锛�- 鍚堟牸鏁伴噺
+ BigDecimal factoryQualified = monthInspects.stream()
+ .filter(inspect -> inspect.getInspectType().equals(2)
+ && "鍚堟牸".equals(inspect.getCheckResult()))
+ .map(QualityInspect::getQuantity)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ item.setFactoryNum(factoryQualified);
+
+ qualityStatisticsItems.add(item);
}
+ // 缁熻杩�4涓湀鎬绘暟鎹紙鎵�鏈夋湀浠芥眹鎬伙級
+ qualityStatisticsDto.setProcessNum(processNum);
+ qualityStatisticsDto.setSupplierNum(supplierNum);
+ qualityStatisticsDto.setFactoryNum(factoryNum);
qualityStatisticsDto.setItem(qualityStatisticsItems);
+
return qualityStatisticsDto;
}
diff --git a/src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml b/src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml
index 29b88f2..ea766e6 100644
--- a/src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml
+++ b/src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml
@@ -48,6 +48,6 @@
</if>
</where>
group by t4.id
- order by t4.update_time desc
+ order by t4.scheduling_date desc
</select>
</mapper>
diff --git a/src/main/resources/mapper/production/SalesLedgerWorkMapper.xml b/src/main/resources/mapper/production/SalesLedgerWorkMapper.xml
index 9629868..d8dcd22 100644
--- a/src/main/resources/mapper/production/SalesLedgerWorkMapper.xml
+++ b/src/main/resources/mapper/production/SalesLedgerWorkMapper.xml
@@ -54,6 +54,6 @@
AND t4.scheduling_date <= DATE_FORMAT(#{salesLedgerDto.entryDateEnd},'%Y-%m-%d')
</if>
</where>
- order by t4.update_time desc
+ order by t4.scheduling_date desc
</select>
</mapper>
\ No newline at end of file
--
Gitblit v1.9.3