|
|
@@ -279,42 +279,10 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
|
|
|
*/
|
|
|
@Override
|
|
|
public List<IncomeAndExpenseVo> getIncomeAndExpense(IncomeAndExpenseParam param){
|
|
|
- log.info("查询收支明细记录:param=[{}]", JSONUtil.toJsonStr(param));
|
|
|
- // 处理月份筛选参数
|
|
|
- String createTimeStart = param.getCreateTimeStart();
|
|
|
- String createTimeEnd = param.getCreateTimeEnd();
|
|
|
- String userId = baseController.getUserId();
|
|
|
- param.setUserId(userId);
|
|
|
- param.setSystemCode(baseController.getSystemCode());
|
|
|
- if (param.getMonth() != null && !param.getMonth().isEmpty()) {
|
|
|
- // 如果传入了月份参数,计算该月的开始和结束时间
|
|
|
- String monthStr = param.getMonth();
|
|
|
- DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
- YearMonth yearMonth = YearMonth.parse(monthStr, monthFormatter);
|
|
|
- LocalDateTime monthStart = yearMonth.atDay(1).atStartOfDay();
|
|
|
- LocalDateTime monthEnd = yearMonth.atEndOfMonth().atTime(23, 59, 59, 999999999);
|
|
|
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- createTimeStart = monthStart.format(formatter);
|
|
|
- createTimeEnd = monthEnd.format(formatter);
|
|
|
- param.setCreateTimeStart(createTimeStart);
|
|
|
- param.setCreateTimeEnd(createTimeEnd);
|
|
|
- }
|
|
|
- if (createTimeStart != null && !createTimeStart.isEmpty()) {
|
|
|
- log.info("createTimeStart=[{}]", createTimeStart);
|
|
|
- if(StrUtil.length(createTimeStart) < "2026-07-15 23:59:59".length()){
|
|
|
- createTimeStart += " 00:00:00";
|
|
|
- }
|
|
|
- }
|
|
|
- if (createTimeEnd != null && !createTimeEnd.isEmpty()) {
|
|
|
- log.info("createTimeEnd=[{}]",createTimeEnd);
|
|
|
- if(StrUtil.length(createTimeEnd) < "2026-07-15 23:59:59".length()){
|
|
|
- createTimeEnd += " 23:59:59";
|
|
|
- }
|
|
|
- }
|
|
|
- param.setCreateTimeStart(createTimeStart);
|
|
|
- param.setCreateTimeEnd(createTimeEnd);
|
|
|
- List<IncomeAndExpenseList> recordsWithOutParam = sysAmountAuditingService.getIncomeAndExpense(new IncomeAndExpenseParam(param.getUserId(),param.getSystemCode()));
|
|
|
+ log.info("查询收支明细记录:param=[{}]", JSONUtil.toJsonStr(param));
|
|
|
+ String key = this.populateParam(param);
|
|
|
+ //List<IncomeAndExpenseList> recordsWithOutParam = sysAmountAuditingService.getIncomeAndExpense(new IncomeAndExpenseParam(param.getUserId(),param.getSystemCode()));
|
|
|
List<IncomeAndExpenseList> allRecords = sysAmountAuditingService.getIncomeAndExpense(param);
|
|
|
allRecords = allRecords.stream().peek(action->{
|
|
|
if("0".equals(action.getStatus())){
|
|
|
@@ -364,20 +332,17 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
|
|
|
|
|
|
// 按月份分组统计
|
|
|
Map<String, IncomeAndExpenseVo.IncomeAndExpense> monthSummaryMap = new TreeMap<>(Collections.reverseOrder());
|
|
|
- for (IncomeAndExpenseList record : recordsWithOutParam) {
|
|
|
+ for (IncomeAndExpenseList record : allRecords) {
|
|
|
if (record.getCreateTime() == null) continue;
|
|
|
- // 获取月份(格式:yyyy-MM)
|
|
|
- String month = record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
|
|
-
|
|
|
// 获取或创建月度汇总对象
|
|
|
- IncomeAndExpenseVo.IncomeAndExpense summary = monthSummaryMap.get(month);
|
|
|
+ IncomeAndExpenseVo.IncomeAndExpense summary = monthSummaryMap.get(key);
|
|
|
if (summary == null) {
|
|
|
summary = new IncomeAndExpenseVo.IncomeAndExpense();
|
|
|
- summary.setMonth(month);
|
|
|
+ summary.setMonth(key);
|
|
|
summary.setIncome(BigDecimal.ZERO);
|
|
|
summary.setExpense(BigDecimal.ZERO);
|
|
|
summary.setBalance(BigDecimal.ZERO);
|
|
|
- monthSummaryMap.put(month, summary);
|
|
|
+ monthSummaryMap.put(key, summary);
|
|
|
}
|
|
|
|
|
|
// 更新收入或支出
|
|
|
@@ -424,7 +389,12 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
|
|
|
|
|
|
// 筛选当前月份的明细记录
|
|
|
List<IncomeAndExpenseVo.IncomeAndExpenseList> monthRecords = allRecords.stream()
|
|
|
- .filter(record -> entry.getKey().equals(record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM"))))
|
|
|
+ .filter(record -> {
|
|
|
+ if(StrUtil.isEmpty(entry.getKey())){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return entry.getKey().equals(record.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM")));
|
|
|
+ })
|
|
|
.map(action->{
|
|
|
IncomeAndExpenseVo.IncomeAndExpenseList a = new IncomeAndExpenseVo.IncomeAndExpenseList();
|
|
|
BeanUtils.copyProperties(action,a);
|
|
|
@@ -437,6 +407,59 @@ public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper,
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 对查询参数进行预处理
|
|
|
+ *
|
|
|
+ * @author lipf
|
|
|
+ * @date 2026/8/6 9:51
|
|
|
+ */
|
|
|
+ private String populateParam(IncomeAndExpenseParam param){
|
|
|
+ String key = "-";
|
|
|
+ if(StrUtil.isEmpty(param.getCreateTimeStart()) && StrUtil.isEmpty(param.getCreateTimeEnd())){
|
|
|
+ //key= "全量汇总数据";
|
|
|
+ key = "";
|
|
|
+ }else{
|
|
|
+ key = String.format("%s到%s",Objects.toString(param.getCreateTimeStart(),""),Objects.toString(param.getCreateTimeEnd(),""));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理月份筛选参数
|
|
|
+ String createTimeStart = param.getCreateTimeStart();
|
|
|
+ String createTimeEnd = param.getCreateTimeEnd();
|
|
|
+ String userId = baseController.getUserId();
|
|
|
+ param.setUserId(userId);
|
|
|
+ param.setSystemCode(baseController.getSystemCode());
|
|
|
+ if (param.getMonth() != null && !param.getMonth().isEmpty()) {
|
|
|
+ // 如果传入了月份参数,计算该月的开始和结束时间
|
|
|
+ String monthStr = param.getMonth();
|
|
|
+ DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
+ YearMonth yearMonth = YearMonth.parse(monthStr, monthFormatter);
|
|
|
+ LocalDateTime monthStart = yearMonth.atDay(1).atStartOfDay();
|
|
|
+ LocalDateTime monthEnd = yearMonth.atEndOfMonth().atTime(23, 59, 59, 999999999);
|
|
|
+
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ createTimeStart = monthStart.format(formatter);
|
|
|
+ createTimeEnd = monthEnd.format(formatter);
|
|
|
+ param.setCreateTimeStart(createTimeStart);
|
|
|
+ param.setCreateTimeEnd(createTimeEnd);
|
|
|
+ key= String.format("%d-%02d", yearMonth.getYear(), yearMonth.getMonthValue());
|
|
|
+ }
|
|
|
+ if (createTimeStart != null && !createTimeStart.isEmpty()) {
|
|
|
+ log.info("createTimeStart=[{}]", createTimeStart);
|
|
|
+ if(StrUtil.length(createTimeStart) < "2026-07-15 23:59:59".length()){
|
|
|
+ createTimeStart += " 00:00:00";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (createTimeEnd != null && !createTimeEnd.isEmpty()) {
|
|
|
+ log.info("createTimeEnd=[{}]",createTimeEnd);
|
|
|
+ if(StrUtil.length(createTimeEnd) < "2026-07-15 23:59:59".length()){
|
|
|
+ createTimeEnd += " 23:59:59";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ param.setCreateTimeStart(createTimeStart);
|
|
|
+ param.setCreateTimeEnd(createTimeEnd);
|
|
|
+ return key;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<IncomeAndExpenseVo> getIncomeAndExpenseOld(IncomeAndExpenseParam param) {
|
|
|
log.info("查询收支明细记录:param=[{}]", JSONUtil.toJsonStr(param));
|