fix: 日常支出统计,代码提交。

This commit is contained in:
tianyongbao
2024-07-16 14:39:50 +08:00
parent c9db02cc26
commit 538765b2c2
6 changed files with 129 additions and 2 deletions

View File

@@ -123,7 +123,12 @@ public class StatisticAnalysisController {
return AjaxResult.success(resultMap);
}
@ApiOperation("日常支出统计分析")
@GetMapping("/dailyExpensesAnalysis")
public Map<String,Object> getDailyExpensesAnalysis(AnalysisDto analysisDto){
Map<String, Object> resultMap = iStatisticAnalysisService.getDailyExpensesAnalysis(analysisDto);
return AjaxResult.success(resultMap);
}

View File

@@ -47,4 +47,8 @@ public class AnalysisDto extends BaseEntity implements Serializable
@ApiModelProperty(value="交易类别")
private String dealCategory;
/** 交易类别 */
@ApiModelProperty(value="交易子类别")
private String childCategory;
}

View File

@@ -30,4 +30,12 @@ public interface StatisticAnalysisMapper {
@DataScope(businessAlias = "a")
public List<AccountsDealRecordVo> selectAccountsOutInList(AccountsDealRecordDto accountsDealRecordDto);
/**
* 查询收支记录
*
* @param accountsDealRecordDto
* @return 收支集合
*/
@DataScope(businessAlias = "a")
public List<AccountsDealRecordVo> selectDailyExpensesList(AccountsDealRecordDto accountsDealRecordDto);
}

View File

@@ -38,4 +38,6 @@ public interface IStatisticAnalysisService {
public Map<String, Object> getAccountsOutInAnalysis(AnalysisDto analysisDto);
public Map<String, Object> getDailyExpensesAnalysis(AnalysisDto analysisDto);
}

View File

@@ -2203,4 +2203,89 @@ public class StatisticAnalysisImpl implements IStatisticAnalysisService {
return map;
}
@Override
public Map<String, Object> getDailyExpensesAnalysis(AnalysisDto analysisDto) {
//返回数据
HashMap<String, Object> map = new HashMap<>();
DecimalFormat decimalFormat = new DecimalFormat("#.###");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dateFormatSecond = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat formatterMonth = new SimpleDateFormat("yyyy-MM");
//月查询
if(analysisDto.getType().equals("2")){
if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
String endTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),0));
String startTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-24));
analysisDto.setStartTime(startTime);
analysisDto.setEndTime(endTime);
}else {
analysisDto.setStartTime(analysisDto.getStartTime()+"-01");
if(analysisDto.getEndTime().equals(formatterMonth.format(new Date()))){
SimpleDateFormat sdf = new SimpleDateFormat("dd");
analysisDto.setEndTime(analysisDto.getEndTime()+"-"+sdf.format(new Date()));
}else {
analysisDto.setEndTime(analysisDto.getEndTime()+"-31");
}
}
//年查询
}else if(analysisDto.getType().equals("3")){
if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
String endTime=dateFormat.format(DateUtils.getNowDate());
String startTime=dateFormat.format(DateUtils.addYears(DateUtils.getNowDate(),-5));
analysisDto.setStartTime(startTime);
analysisDto.setEndTime(endTime);
}else {
analysisDto.setStartTime(analysisDto.getStartTime()+"-01-01");
SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
if(analysisDto.getEndTime().equals(sdfYear.format(new Date()))){
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
analysisDto.setEndTime(analysisDto.getEndTime()+"-"+sdf.format(new Date()));
}else {
analysisDto.setEndTime(analysisDto.getEndTime()+"-12-31");
}
}
}
AccountsDealRecordDto dto=new AccountsDealRecordDto();
//获取数据
dto.setEndTime(analysisDto.getEndTime());
dto.setStartTime(analysisDto.getStartTime());
dto.setAccountId(analysisDto.getId());
dto.setChildCategory(analysisDto.getChildCategory());
List<AccountsDealRecordVo> accountsDealRecordVoList=statisticAnalysisMapper.selectDailyExpensesList(dto);
for (AccountsDealRecordVo vo:accountsDealRecordVoList
){
if (null != vo.getChildCategory()) {
vo.setName(DictUtils.getDictLabel("daily_expenses", vo.getChildCategory().toString()));
}else{
vo.setName("未分类");
}
}
ArrayList<Map<String, Object>> acccountsList = new ArrayList<>();
ArrayList<Map<String, Object>> tableAccountsList = new ArrayList<>();
for (AccountsDealRecordVo vo:accountsDealRecordVoList
) {
Map<String, Object> datamap = new HashMap<>();
datamap.put("time", vo.getName());
datamap.put("value", decimalFormat.format(vo.getAmount()));
tableAccountsList.add(datamap);
}
Collections.reverse(accountsDealRecordVoList);
for (AccountsDealRecordVo vo:accountsDealRecordVoList
) {
Map<String, Object> datamap = new HashMap<>();
datamap.put("time", vo.getName());
datamap.put("value", decimalFormat.format(vo.getAmount()));
acccountsList.add(datamap);
}
//列表
map.put("acccountsList",acccountsList);
map.put("tableAccountsList",tableAccountsList);
return map;
}
}

View File

@@ -67,6 +67,7 @@
<result property="accountName" column="account_name" />
<result property="transferRecordId" column="transfer_record_id" />
<result property="currentBalance" column="current_balance" />
<result property="childCategory" column="child_category" />
</resultMap>
<select id="selectAccountsOutInList" parameterType="AccountsDealRecordDto" resultMap="AccountsDealRecordResult">
@@ -151,5 +152,27 @@
${params.dataScope}
order by a.create_time desc
</select>
<select id="selectDailyExpensesList" parameterType="AccountsDealRecordDto" resultMap="AccountsDealRecordResult">
select
sum(a.amount) as amount ,
a.child_category
from
accounts_deal_record a
<where>
a.deal_category = '1'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(a.create_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(a.create_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="accountId != null and accountId != ''"> and a.account_id = #{accountId}</if>
<if test="childCategory != null and childCategory != ''"> and a.child_category = #{childCategory}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by
a.child_category
order by a.child_category asc
</select>
</mapper>