fix: 查询性能优化。
This commit is contained in:
@@ -2137,136 +2137,119 @@ public class StatisticAnalysisImpl implements IStatisticAnalysisService {
|
||||
List<AccountsDealRecordVo> queryList =new ArrayList<>();
|
||||
|
||||
if("1".equals(analysisDto.getType())){
|
||||
//日列表
|
||||
List <String> staticsTimeList=new ArrayList<>();
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList
|
||||
) {
|
||||
if (null != vo.getDealCategory()) {
|
||||
//日列表 - 优化版本:使用Map避免嵌套循环,预先格式化日期
|
||||
Map<String, Double> amountMap = new LinkedHashMap<>();
|
||||
Map<String, StringBuilder> detailsMap = new LinkedHashMap<>();
|
||||
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList) {
|
||||
// 预先格式化日期,避免重复格式化
|
||||
String dayString=dateFormat.format(vo.getCreateTime());
|
||||
String timeString=dateFormatSecond.format(vo.getCreateTime());
|
||||
|
||||
// 获取字典标签(仅在需要时)
|
||||
if (null != vo.getDealCategory() && !analysisDto.getDataType().equals("5")) {
|
||||
vo.setDealCategoryName(DictUtils.getDictLabel("deal_category", vo.getDealCategory().toString()));
|
||||
}
|
||||
String dayString=dateFormat.format(vo.getCreateTime());
|
||||
|
||||
if(!staticsTimeList.contains(dayString)){
|
||||
staticsTimeList.add(dayString);
|
||||
}
|
||||
}
|
||||
// 初始化Map
|
||||
amountMap.putIfAbsent(dayString, 0.0);
|
||||
detailsMap.putIfAbsent(dayString, new StringBuilder());
|
||||
|
||||
for (String staticsTime :staticsTimeList
|
||||
) {
|
||||
double actualCreditBillDay=0;
|
||||
String details="";
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList
|
||||
) {
|
||||
String dayString=dateFormat.format(vo.getCreateTime());
|
||||
|
||||
if(staticsTime.equals(dayString)){
|
||||
String remark="";
|
||||
if(vo.getRemark()!=null&&StringUtils.isNotEmpty(vo.getRemark())){
|
||||
remark+=",备注:"+vo.getRemark();
|
||||
remark=",备注:"+vo.getRemark();
|
||||
}
|
||||
|
||||
if(vo.getDealType().equals("1")){
|
||||
if(analysisDto.getDataType().equals("5")){
|
||||
if(vo.getDealCategory().equals("2")){
|
||||
actualCreditBillDay+=vo.getAmount();
|
||||
details+=vo.getAccountName()+"于"+dateFormatSecond.format(vo.getCreateTime())+"交易盈利"+vo.getAmount()+remark+";<br/>";
|
||||
amountMap.put(dayString, amountMap.get(dayString) + vo.getAmount());
|
||||
detailsMap.get(dayString).append(vo.getAccountName()).append("于").append(timeString)
|
||||
.append("交易盈利").append(vo.getAmount()).append(remark).append(";<br/>");
|
||||
}
|
||||
} else {
|
||||
actualCreditBillDay+=vo.getAmount();
|
||||
|
||||
details+=vo.getAccountName()+"于"+dateFormatSecond.format(vo.getCreateTime())+"因交易类别【"+vo.getDealCategoryName()+"】收入"+vo.getAmount()+remark+";<br/>";
|
||||
amountMap.put(dayString, amountMap.get(dayString) + vo.getAmount());
|
||||
detailsMap.get(dayString).append(vo.getAccountName()).append("于").append(timeString)
|
||||
.append("因交易类别【").append(vo.getDealCategoryName()).append("】收入")
|
||||
.append(vo.getAmount()).append(remark).append(";<br/>");
|
||||
}
|
||||
|
||||
}
|
||||
if(vo.getDealType().equals("2")){
|
||||
if(analysisDto.getDataType().equals("5")){
|
||||
if(vo.getDealCategory().equals("2")){
|
||||
actualCreditBillDay-=vo.getAmount();
|
||||
details+=vo.getAccountName()+"于"+dateFormatSecond.format(vo.getCreateTime())+"交易亏损"+vo.getAmount()+remark+";<br/>";
|
||||
amountMap.put(dayString, amountMap.get(dayString) - vo.getAmount());
|
||||
detailsMap.get(dayString).append(vo.getAccountName()).append("于").append(timeString)
|
||||
.append("交易亏损").append(vo.getAmount()).append(remark).append(";<br/>");
|
||||
}
|
||||
} else {
|
||||
actualCreditBillDay-=vo.getAmount();
|
||||
details+=vo.getAccountName()+"于"+dateFormatSecond.format(vo.getCreateTime())+"因交易类别【"+vo.getDealCategoryName()+"】支出"+vo.getAmount()+remark+";<br/>";
|
||||
amountMap.put(dayString, amountMap.get(dayString) - vo.getAmount());
|
||||
detailsMap.get(dayString).append(vo.getAccountName()).append("于").append(timeString)
|
||||
.append("因交易类别【").append(vo.getDealCategoryName()).append("】支出")
|
||||
.append(vo.getAmount()).append(remark).append(";<br/>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// 转换为结果列表
|
||||
for (Map.Entry<String, Double> entry : amountMap.entrySet()) {
|
||||
AccountsDealRecordVo analysisVo=new AccountsDealRecordVo();
|
||||
analysisVo.setAmount(actualCreditBillDay);
|
||||
analysisVo.setRemark(staticsTime);
|
||||
analysisVo.setName(details);
|
||||
analysisVo.setAmount(entry.getValue());
|
||||
analysisVo.setRemark(entry.getKey());
|
||||
analysisVo.setName(detailsMap.get(entry.getKey()).toString());
|
||||
queryList.add(analysisVo);
|
||||
}
|
||||
|
||||
//年查询
|
||||
}
|
||||
else if("2".equals(analysisDto.getType())){
|
||||
//月列表
|
||||
List <String> staticsTimeList=new ArrayList<>();
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList
|
||||
) {
|
||||
//月列表 - 优化版本:使用Map避免嵌套循环
|
||||
Map<String, Double> monthAmountMap = new LinkedHashMap<>();
|
||||
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList) {
|
||||
// 预先格式化并截取月份,避免重复操作
|
||||
String monthString=dateFormat.format(vo.getCreateTime()).substring(0,7);
|
||||
|
||||
if(!staticsTimeList.contains(monthString)){
|
||||
staticsTimeList.add(monthString);
|
||||
}
|
||||
}
|
||||
monthAmountMap.putIfAbsent(monthString, 0.0);
|
||||
|
||||
for (String staticsTime :staticsTimeList
|
||||
) {
|
||||
double actualCreditBillMonth=0;
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList
|
||||
) {
|
||||
String monthString=dateFormat.format(vo.getCreateTime()).substring(0,7);
|
||||
|
||||
if(staticsTime.equals(monthString)){
|
||||
if(vo.getDealType().equals("1")){
|
||||
actualCreditBillMonth+=vo.getAmount();
|
||||
monthAmountMap.put(monthString, monthAmountMap.get(monthString) + vo.getAmount());
|
||||
}
|
||||
if(vo.getDealType().equals("2")){
|
||||
actualCreditBillMonth-=vo.getAmount();
|
||||
}
|
||||
monthAmountMap.put(monthString, monthAmountMap.get(monthString) - vo.getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
// 转换为结果列表
|
||||
for (Map.Entry<String, Double> entry : monthAmountMap.entrySet()) {
|
||||
AccountsDealRecordVo analysisVo=new AccountsDealRecordVo();
|
||||
analysisVo.setAmount(actualCreditBillMonth);
|
||||
analysisVo.setRemark(staticsTime);
|
||||
analysisVo.setAmount(entry.getValue());
|
||||
analysisVo.setRemark(entry.getKey());
|
||||
queryList.add(analysisVo);
|
||||
}
|
||||
|
||||
//年查询
|
||||
}else if("3".equals(analysisDto.getType())){
|
||||
List <String> staticsTimeList=new ArrayList<>();
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList
|
||||
) {
|
||||
//年列表 - 优化版本:使用Map避免嵌套循环
|
||||
Map<String, Double> yearAmountMap = new LinkedHashMap<>();
|
||||
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList) {
|
||||
// 预先格式化并截取年份,避免重复操作
|
||||
String yearString=dateFormat.format(vo.getCreateTime()).substring(0,4);
|
||||
|
||||
if(!staticsTimeList.contains(yearString)){
|
||||
staticsTimeList.add(yearString);
|
||||
}
|
||||
}
|
||||
yearAmountMap.putIfAbsent(yearString, 0.0);
|
||||
|
||||
for (String staticsTime :staticsTimeList
|
||||
) {
|
||||
double actualCreditBillYear=0;
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList
|
||||
) {
|
||||
String yearString=dateFormat.format(vo.getCreateTime()).substring(0,4);
|
||||
if(staticsTime.equals(yearString)){
|
||||
if(vo.getDealType().equals("1")){
|
||||
actualCreditBillYear+=vo.getAmount();
|
||||
yearAmountMap.put(yearString, yearAmountMap.get(yearString) + vo.getAmount());
|
||||
}
|
||||
if(vo.getDealType().equals("2")){
|
||||
actualCreditBillYear-=vo.getAmount();
|
||||
yearAmountMap.put(yearString, yearAmountMap.get(yearString) - vo.getAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
AccountsDealRecordVo analysisVo=new AccountsDealRecordVo();
|
||||
analysisVo.setAmount(actualCreditBillYear);
|
||||
analysisVo.setRemark(staticsTime);
|
||||
queryList.add(analysisVo);
|
||||
|
||||
// 转换为结果列表
|
||||
for (Map.Entry<String, Double> entry : yearAmountMap.entrySet()) {
|
||||
AccountsDealRecordVo analysisVo=new AccountsDealRecordVo();
|
||||
analysisVo.setAmount(entry.getValue());
|
||||
analysisVo.setRemark(entry.getKey());
|
||||
queryList.add(analysisVo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2639,58 +2622,36 @@ public class StatisticAnalysisImpl implements IStatisticAnalysisService {
|
||||
//年查询
|
||||
}
|
||||
else if("2".equals(analysisDto.getType())){
|
||||
//月列表
|
||||
List <String> staticsTimeList=new ArrayList<>();
|
||||
for (AccountsDealRecordVo vo:accountsDateList
|
||||
) {
|
||||
//月列表 - 优化版本:使用Map避免嵌套循环
|
||||
Map<String, Double> monthAmountMap = new LinkedHashMap<>();
|
||||
|
||||
for (AccountsDealRecordVo vo:accountsDateList) {
|
||||
String monthString=vo.getDateStr().substring(0,7);
|
||||
if(!staticsTimeList.contains(monthString)){
|
||||
staticsTimeList.add(monthString);
|
||||
}
|
||||
}
|
||||
for (String staticsTime :staticsTimeList
|
||||
) {
|
||||
double actualCreditBillMonth=0;
|
||||
for (AccountsDealRecordVo vo:accountsDateList
|
||||
) {
|
||||
String monthString=vo.getDateStr().substring(0,7);
|
||||
if(staticsTime.equals(monthString)){
|
||||
actualCreditBillMonth+=vo.getAmount();
|
||||
}
|
||||
monthAmountMap.put(monthString, monthAmountMap.getOrDefault(monthString, 0.0) + vo.getAmount());
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Double> entry : monthAmountMap.entrySet()) {
|
||||
AccountsDealRecordVo analysisVo=new AccountsDealRecordVo();
|
||||
analysisVo.setAmount(actualCreditBillMonth);
|
||||
analysisVo.setRemark(staticsTime);
|
||||
analysisVo.setAmount(entry.getValue());
|
||||
analysisVo.setRemark(entry.getKey());
|
||||
queryList.add(analysisVo);
|
||||
}
|
||||
|
||||
//年查询
|
||||
}else if("3".equals(analysisDto.getType())){
|
||||
List <String> staticsTimeList=new ArrayList<>();
|
||||
for (AccountsDealRecordVo vo:accountsDateList
|
||||
) {
|
||||
String yearString=vo.getDateStr().substring(0,4);
|
||||
//年列表 - 优化版本:使用Map避免嵌套循环
|
||||
Map<String, Double> yearAmountMap = new LinkedHashMap<>();
|
||||
|
||||
if(!staticsTimeList.contains(yearString)){
|
||||
staticsTimeList.add(yearString);
|
||||
}
|
||||
for (AccountsDealRecordVo vo:accountsDateList) {
|
||||
String yearString=vo.getDateStr().substring(0,4);
|
||||
yearAmountMap.put(yearString, yearAmountMap.getOrDefault(yearString, 0.0) + vo.getAmount());
|
||||
}
|
||||
|
||||
for (String staticsTime :staticsTimeList
|
||||
) {
|
||||
double actualCreditBillYear=0;
|
||||
for (AccountsDealRecordVo vo:accountsDateList
|
||||
) {
|
||||
String yearString=vo.getDateStr().substring(0,4);
|
||||
if(staticsTime.equals(yearString)){
|
||||
actualCreditBillYear+=vo.getAmount();
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Double> entry : yearAmountMap.entrySet()) {
|
||||
AccountsDealRecordVo analysisVo=new AccountsDealRecordVo();
|
||||
analysisVo.setAmount(actualCreditBillYear);
|
||||
analysisVo.setRemark(staticsTime);
|
||||
analysisVo.setAmount(entry.getValue());
|
||||
analysisVo.setRemark(entry.getKey());
|
||||
queryList.add(analysisVo);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2905,41 +2866,30 @@ public class StatisticAnalysisImpl implements IStatisticAnalysisService {
|
||||
dealDto.setType("5");
|
||||
dealDto.setDealCategory("2");
|
||||
List<AccountsDealRecordVo> accountsDealRecordVoList=accountsDealRecordMapper.selectAccountsDealRecordList(dealDto);
|
||||
//日列表
|
||||
List <String> staticsTimeList=new ArrayList<>();
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList
|
||||
) {
|
||||
//日列表 - 优化版本:使用Map避免嵌套循环
|
||||
Map<String, Double> investAmountMap = new LinkedHashMap<>();
|
||||
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList) {
|
||||
String dayString=sdf.format(vo.getCreateTime());
|
||||
|
||||
if(!staticsTimeList.contains(dayString)){
|
||||
staticsTimeList.add(dayString);
|
||||
}
|
||||
}
|
||||
for (String staticsTime :staticsTimeList
|
||||
) {
|
||||
double investAmount=0;
|
||||
for (AccountsDealRecordVo vo:accountsDealRecordVoList
|
||||
) {
|
||||
String dayString=sdf.format(vo.getCreateTime());
|
||||
investAmountMap.putIfAbsent(dayString, 0.0);
|
||||
|
||||
if(staticsTime.equals(dayString)){
|
||||
if(vo.getDealType().equals("1")){
|
||||
if(vo.getDealCategory().equals("2")){
|
||||
investAmount+=vo.getAmount();
|
||||
investAmountMap.put(dayString, investAmountMap.get(dayString) + vo.getAmount());
|
||||
}
|
||||
|
||||
}
|
||||
if(vo.getDealType().equals("2")){
|
||||
if(vo.getDealCategory().equals("2")){
|
||||
investAmount-=vo.getAmount();
|
||||
investAmountMap.put(dayString, investAmountMap.get(dayString) - vo.getAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Double> entry : investAmountMap.entrySet()) {
|
||||
AccountCalendarVo billDate = new AccountCalendarVo();
|
||||
billDate.setStart(staticsTime);
|
||||
billDate.setTitle("投资收益:"+decimalFormat.format(investAmount));
|
||||
billDate.setStart(entry.getKey());
|
||||
billDate.setTitle("投资收益:"+decimalFormat.format(entry.getValue()));
|
||||
billDate.setType(6);
|
||||
billDate.setColor("purple");
|
||||
list.add(billDate);
|
||||
@@ -2951,32 +2901,18 @@ public class StatisticAnalysisImpl implements IStatisticAnalysisService {
|
||||
posDto.setStartTime(analysisDto.getStartTime());
|
||||
posDto.setType("1");
|
||||
List<AccountsTransferRecordVo> transferList=accountsTransferRecordMapper.selectAccountsTransferRecordList(posDto);
|
||||
//日列表
|
||||
List <String> posTimeList=new ArrayList<>();
|
||||
for (AccountsTransferRecordVo vo:transferList
|
||||
) {
|
||||
//日列表 - 优化版本:使用Map避免嵌套循环
|
||||
Map<String, Double> posAmountMap = new LinkedHashMap<>();
|
||||
|
||||
for (AccountsTransferRecordVo vo:transferList) {
|
||||
String dayString=sdf.format(vo.getCreateTime());
|
||||
|
||||
if(!posTimeList.contains(dayString)){
|
||||
posTimeList.add(dayString);
|
||||
}
|
||||
posAmountMap.put(dayString, posAmountMap.getOrDefault(dayString, 0.0) + vo.getAmount());
|
||||
}
|
||||
|
||||
for (String staticsTime :posTimeList
|
||||
) {
|
||||
double posAmount=0;
|
||||
|
||||
for (AccountsTransferRecordVo vo:transferList
|
||||
) {
|
||||
String dayString=sdf.format(vo.getCreateTime());
|
||||
if(staticsTime.equals(dayString)){
|
||||
posAmount+=vo.getAmount();
|
||||
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Double> entry : posAmountMap.entrySet()) {
|
||||
AccountCalendarVo billDate = new AccountCalendarVo();
|
||||
billDate.setStart(staticsTime);
|
||||
billDate.setTitle("POS机刷卡:"+decimalFormat.format(posAmount));
|
||||
billDate.setStart(entry.getKey());
|
||||
billDate.setTitle("POS机刷卡:"+decimalFormat.format(entry.getValue()));
|
||||
billDate.setType(7);
|
||||
list.add(billDate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user