1、销售应收明细汇总修改
This commit is contained in:
parent
d6db22bc49
commit
9c43b3d94f
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -19,6 +19,8 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.sql.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.stream.Collectors;
|
||||
@ -998,6 +1000,56 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
||||
hasMore = pageData.size() == PAGE_SIZE;
|
||||
pageNo++;
|
||||
} while (hasMore);
|
||||
//每月1号删除上月去年同期去除每月最后一天的数据,删除当月去年同期全量数据后新增当月去年同期全量数据,
|
||||
// 每月1号执行的任务
|
||||
LocalDate now = LocalDate.now();
|
||||
int dayOfMonth = now.getDayOfMonth();
|
||||
|
||||
if (dayOfMonth == 1) {
|
||||
try {
|
||||
LOGGER.info("开始执行每月1号的特殊数据处理任务");
|
||||
|
||||
// 计算时间范围
|
||||
LocalDate lastYearMonthDate = now.minusYears(1).minusMonths(1);
|
||||
int lastYearMonthValue = lastYearMonthDate.getMonthValue();
|
||||
int lastyear = lastYearMonthDate.getYear();
|
||||
|
||||
// 1. 删除当月去年同期全量数据
|
||||
String deleteCurrentMonthLastYearSql = "DELETE FROM " + hzb +
|
||||
" WHERE YEAR = " + lastyear +
|
||||
" AND MONTH = " + lastYearMonthValue;
|
||||
int update = DBSql.update(deleteCurrentMonthLastYearSql);
|
||||
LOGGER.info("已删除去年同期({}-{})的全量数据,删除了{}条数据", lastyear, lastYearMonthValue,update);
|
||||
|
||||
// 2. 新增当月去年同期数据
|
||||
// 去年日期
|
||||
LocalDate minusYears = now.minusYears(1);
|
||||
// 计算去年同期第一天(当月第一天)
|
||||
LocalDate firstDayOfLastYearMonth = minusYears.withDayOfMonth(1);
|
||||
// 计算去年下个月第一天
|
||||
LocalDate firstDayOfNextMonthLastYear = minusYears.plusMonths(1).withDayOfMonth(1);
|
||||
// 格式化日期为字符串(根据数据库格式要求调整)
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
String lastYearFirstDayStr = firstDayOfLastYearMonth.format(formatter);
|
||||
String lastYearNextMonthFirstDayStr = firstDayOfNextMonthLastYear.format(formatter);
|
||||
//删除清空去年同期数据
|
||||
int update1 = DBSql.update("DELETE FROM " + hzb +
|
||||
" WHERE YEAR = " + firstDayOfLastYearMonth.getYear() +
|
||||
" AND MONTH = " + firstDayOfLastYearMonth.getMonthValue());
|
||||
LOGGER.info("先清空{}去年同期数{}",lastYearFirstDayStr,update1);
|
||||
// 构建插入SQL(注意:需确保字段匹配且处理可能的主键冲突)
|
||||
String insertCurrentMonthLastYearSql = "INSERT INTO " + targetTable +
|
||||
" SELECT * FROM " + targetTable +
|
||||
" WHERE " + targetTimeField + " >= '" + lastYearFirstDayStr +
|
||||
"' AND " + targetTimeField + " < '" + lastYearNextMonthFirstDayStr + "'";
|
||||
// 执行插入操作
|
||||
DBSql.update(insertCurrentMonthLastYearSql);
|
||||
LOGGER.info("{}已新增当月去年同期数据",lastYearFirstDayStr);
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("每月1号任务执行失败: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
LOGGER.error("汇总数据失败 [汇总表={}, 第几页={}]: {}",
|
||||
hzb, PAGE_SIZE, e.getMessage(), e);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user