From 58bf55e078089b75f1120a277fc214fdea23d5d5 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期四, 11 十二月 2025 14:36:16 +0800
Subject: [PATCH] yys 修改数据过滤
---
src/main/java/com/ruoyi/production/service/impl/SalesLedgerSchedulingServiceImpl.java | 6 ++-
src/main/java/com/ruoyi/production/service/impl/SalesLedgerProductionAccountingServiceImpl.java | 6 ++
src/main/java/com/ruoyi/account/service/impl/AccountExpenseServiceImpl.java | 103 ++++++++++++++++++++++++++++++++++++++-------------
src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java | 5 ++
4 files changed, 90 insertions(+), 30 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/production/service/impl/SalesLedgerProductionAccountingServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/SalesLedgerProductionAccountingServiceImpl.java
index fdb96a5..49dab8a 100644
--- a/src/main/java/com/ruoyi/production/service/impl/SalesLedgerProductionAccountingServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/SalesLedgerProductionAccountingServiceImpl.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.production.dto.SalesLedgerProductionAccountingDto;
import com.ruoyi.production.mapper.SalesLedgerProductionAccountingMapper;
import com.ruoyi.production.pojo.SalesLedgerProductionAccounting;
@@ -27,7 +28,10 @@
@Override
public IPage<SalesLedgerProductionAccountingDto> listPage(Page page, SalesLedgerProductionAccountingDto salesLedgerProductionAccountingDto) {
- salesLedgerProductionAccountingDto.setSchedulingUserId(SecurityUtils.getLoginUser().getUser().getUserId());
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ if(!"admin".equals(loginUser.getUsername())){
+ salesLedgerProductionAccountingDto.setSchedulingUserId(loginUser.getUserId());
+ }
IPage<SalesLedgerProductionAccountingDto> list = salesLedgerProductionAccountingMapper.listPage(page, salesLedgerProductionAccountingDto);
list.getRecords().forEach(item -> {
String[] split = item.getSpecificationModel().split("\\*");
diff --git a/src/main/java/com/ruoyi/production/service/impl/SalesLedgerSchedulingServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/SalesLedgerSchedulingServiceImpl.java
index cfd04c5..427b8cc 100644
--- a/src/main/java/com/ruoyi/production/service/impl/SalesLedgerSchedulingServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/SalesLedgerSchedulingServiceImpl.java
@@ -292,8 +292,10 @@
@Override
public IPage<SalesLedgerSchedulingProcessDto> listPageProcess(Page page, SalesLedgerSchedulingProcessDto salesLedgerSchedulingDto) {
- Long userId = SecurityUtils.getLoginUser().getUserId();
- salesLedgerSchedulingDto.setProductionUserId(userId);
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ if(!"admin".equals(loginUser.getUsername())){
+ salesLedgerSchedulingDto.setProductionUserId(loginUser.getUserId());
+ }
IPage<SalesLedgerSchedulingProcessDto> list = salesLedgerSchedulingMapper.listPageProcess(page, salesLedgerSchedulingDto);
// Set<Long> collect = list.getRecords().stream().map(SalesLedgerSchedulingProcessDto::getId).collect(Collectors.toSet());
// if(CollectionUtils.isEmpty(collect)) return list;
diff --git a/src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java
index 44e505f..79cda63 100644
--- a/src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java
@@ -57,7 +57,10 @@
@Override
public IPage<SalesLedgerWorkDto> listPage(Page page, SalesLedgerWorkDto salesLedgerWorkDto) {
- salesLedgerWorkDto.setProductionUserId(SecurityUtils.getLoginUser().getUserId());
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ if(!"admin".equals(loginUser.getUsername())){
+ salesLedgerWorkDto.setProductionUserId(loginUser.getUserId());
+ }
IPage<SalesLedgerWorkDto> iPage = salesLedgerWorkMapper.listPage(page, salesLedgerWorkDto);
List<Loss> losses = lossMapper.selectList(null);
if(!CollectionUtils.isEmpty(losses)){
--
Gitblit v1.9.3