预算调整、首页展示
This commit is contained in:
34
src/main/java/com/quinn/common/wx/BillMonthDTO.java
Normal file
34
src/main/java/com/quinn/common/wx/BillMonthDTO.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.quinn.common.wx;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2023-02-07
|
||||
*/
|
||||
@Data
|
||||
public class BillMonthDTO implements Serializable {
|
||||
|
||||
private Double sumExpend;
|
||||
private Double sumIncome;
|
||||
private Double sumTransfer;
|
||||
private Double sumRepayment;
|
||||
|
||||
List<AccBillDTO> accountList;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,18 +1,7 @@
|
||||
package com.quinn.common.wx;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.quinn.pojo.AccBudget;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -29,6 +18,8 @@ public class BudgetDTO extends AccBudget {
|
||||
|
||||
private Double used;
|
||||
|
||||
private Double progress;
|
||||
|
||||
private String expendIcon;
|
||||
|
||||
}
|
||||
|
||||
25
src/main/java/com/quinn/common/wx/IndexDTO.java
Normal file
25
src/main/java/com/quinn/common/wx/IndexDTO.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.quinn.common.wx;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2023-02-09
|
||||
*/
|
||||
@Data
|
||||
public class IndexDTO implements Serializable {
|
||||
|
||||
private Double sumToday = 0.0;
|
||||
|
||||
private Double sumBalance = 0.0;
|
||||
|
||||
private Double sumBudget = 0.0;
|
||||
|
||||
private Double sumUsed = 0.0;
|
||||
}
|
||||
@@ -3,12 +3,14 @@ package com.quinn.controller.wx;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.common.wx.AccBillDTO;
|
||||
import com.quinn.common.wx.AccBillType;
|
||||
import com.quinn.common.wx.BillMonthDTO;
|
||||
import com.quinn.common.wx.ListBillByAccount;
|
||||
import com.quinn.dto.res.ResponseDTO;
|
||||
import com.quinn.pojo.AccBill;
|
||||
import com.quinn.pojo.AccSetting;
|
||||
import com.quinn.service.AccBillService;
|
||||
import com.quinn.service.AccSettingService;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -51,6 +53,36 @@ public class WxBillController extends BaseWxController{
|
||||
return ResponseDTO.ok().setData(accBills);
|
||||
}
|
||||
|
||||
@PostMapping("user/bills/month")
|
||||
public ResponseDTO getMonthBills(HttpServletRequest request,String rangeDate){
|
||||
BillMonthDTO billMonthDTO = new BillMonthDTO();
|
||||
List<AccBillDTO> accBills = accBillService.listBillByDate(getLoginUserId(request),rangeDate);
|
||||
double sumExpend = 0;
|
||||
double sumIncome = 0;
|
||||
double sumTransfer = 0;
|
||||
double sumRepayment = 0;
|
||||
for (AccBillDTO accBill : accBills) {
|
||||
if (AccBillType.INCOME.equals(accBill.getBillType())){
|
||||
sumIncome = sumIncome + accBill.getMoney();
|
||||
}
|
||||
if (AccBillType.EXPEND.equals(accBill.getBillType())){
|
||||
sumExpend = sumExpend + accBill.getMoney();
|
||||
}
|
||||
if (AccBillType.TRANSFER.equals(accBill.getBillType())){
|
||||
sumTransfer = sumTransfer + accBill.getMoney();
|
||||
}
|
||||
if (AccBillType.REPAYMENT.equals(accBill.getBillType())){
|
||||
sumRepayment = sumRepayment + accBill.getMoney();
|
||||
}
|
||||
}
|
||||
billMonthDTO.setSumExpend(sumExpend);
|
||||
billMonthDTO.setSumIncome(sumIncome);
|
||||
billMonthDTO.setSumTransfer(sumTransfer);
|
||||
billMonthDTO.setSumRepayment(sumRepayment);
|
||||
billMonthDTO.setAccountList(accBills);
|
||||
return ResponseDTO.ok().setData(billMonthDTO);
|
||||
}
|
||||
|
||||
@PostMapping("user/bills/account")
|
||||
public ResponseDTO getBillsByBills(HttpServletRequest request, ListBillByAccount listBillByAccount){
|
||||
List<AccBillDTO> accBills = accBillService.listBillByAccount(getLoginUserId(request),listBillByAccount.getSid(),listBillByAccount.getDateRange());
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.common.wx.AccBudgetDTO;
|
||||
import com.quinn.common.wx.BudgetDTO;
|
||||
import com.quinn.common.wx.EditBudget;
|
||||
import com.quinn.common.wx.IndexDTO;
|
||||
import com.quinn.dto.res.ResponseDTO;
|
||||
import com.quinn.pojo.AccBudget;
|
||||
import com.quinn.service.AccBudgetService;
|
||||
@@ -32,11 +33,17 @@ public class WxBudgetController extends BaseWxController{
|
||||
@Resource
|
||||
AccBudgetService accBudgetService;
|
||||
|
||||
@PostMapping("user/budget/index")
|
||||
public ResponseDTO getIndexBudget(HttpServletRequest request){
|
||||
IndexDTO result = accBudgetService.getIndexBudget(getLoginUserId(request));
|
||||
return ResponseDTO.ok().setData(result);
|
||||
}
|
||||
|
||||
@PostMapping("user/budget")
|
||||
public ResponseDTO getBudget(HttpServletRequest request){
|
||||
AccBudgetDTO result = new AccBudgetDTO();
|
||||
List<BudgetDTO> accBills = accBudgetService.getBudget(getLoginUserId(request));
|
||||
List<BudgetDTO> sum = accBills.stream().filter(x -> x.getExpendId() == 1).collect(Collectors.toList());
|
||||
List<BudgetDTO> sum = accBills.stream().filter(x -> x.getExpendId() == -1).collect(Collectors.toList());
|
||||
if (sum != null && sum.size() > 0){
|
||||
BudgetDTO budgetDTO = sum.get(0);
|
||||
result.setSumBudget(budgetDTO.getBudget());
|
||||
@@ -44,6 +51,18 @@ public class WxBudgetController extends BaseWxController{
|
||||
result.setSumBalance(budgetDTO.getBudget() - budgetDTO.getUsed());
|
||||
}
|
||||
List<BudgetDTO> list = accBills.stream().filter(x -> x.getExpendId() != -1).collect(Collectors.toList());
|
||||
if (list != null && list.size() > 0){
|
||||
list.forEach(x->{
|
||||
double progress = 0;
|
||||
try{
|
||||
progress = x.getUsed() / x.getBudget();
|
||||
progress = Math.floor(progress * 10000) / 100;
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
x.setProgress(progress);
|
||||
});
|
||||
}
|
||||
result.setPayTypeList(list);
|
||||
return ResponseDTO.ok().setData(result);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.quinn.mapper;
|
||||
|
||||
import com.quinn.common.wx.BudgetDTO;
|
||||
import com.quinn.common.wx.IndexDTO;
|
||||
import com.quinn.pojo.AccBudget;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
@@ -17,4 +18,6 @@ import java.util.List;
|
||||
public interface AccBudgetMapper extends BaseMapper<AccBudget> {
|
||||
|
||||
List<BudgetDTO> getBudget(String userId, String startDate, String endDate);
|
||||
|
||||
IndexDTO getIndexBudget(String userId, String todayDate, String startDate, String endDate);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,35 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.quinn.mapper.AccBudgetMapper">
|
||||
<select id="getBudget" resultType="com.quinn.common.wx.BudgetDTO">
|
||||
select a.id,b.id "expendId",IFNULL(a.budget,0) "budget",b.user_id,a.gmt_create,
|
||||
select a.id "id",b.id "expendId",IFNULL(a.budget,0) "budget",b.user_id "userId",a.gmt_create "gmtCreate",
|
||||
IFNULL(
|
||||
(select sum(money) from qn_acc_bill c where c.money_type = a.expend_id and c.user_id = #{userId} and c.date <![CDATA[ >= ]]> #{startDate} and c.date <![CDATA[ <= ]]> #{endDate})
|
||||
,0) "used",
|
||||
b.icon "expendIcon"
|
||||
b.icon "expendIcon",
|
||||
b.name "expendName"
|
||||
from qn_acc_budget a right join qn_acc_setting b on a.expend_id = b.id
|
||||
where b.user_id = #{userId}
|
||||
where b.user_id = #{userId} and b.setting_type = 'EXPEND_SETTING'
|
||||
union all
|
||||
select id "id",expend_id "expendId",IFNULL(budget,0) "budget",user_id "userId",gmt_create "gmtCreate",
|
||||
IFNULL(
|
||||
(select sum(money) from qn_acc_bill c where c.bill_type = 'EXPEND' and c.user_id = #{userId} and c.date <![CDATA[ >= ]]> #{startDate} and c.date <![CDATA[ <= ]]> #{endDate})
|
||||
,0) "used",
|
||||
null,null from qn_acc_budget where user_id = #{userId} and expend_id = -1
|
||||
</select>
|
||||
|
||||
<select id="getIndexBudget" resultType="com.quinn.common.wx.IndexDTO">
|
||||
select
|
||||
IFNULL(
|
||||
(select sum(money) from qn_acc_bill c where c.bill_type = 'EXPEND' and c.user_id = #{userId} and c.date = #{todayDate})
|
||||
,0) "sumToday",
|
||||
IFNULL(
|
||||
(select sum(balance) from qn_acc_setting where user_id = #{userId} and (setting_type = 'CASH_SETTING' or setting_type = 'OWE_SETTING'))
|
||||
,0) "sumBalance",
|
||||
IFNULL(
|
||||
(select budget from qn_acc_budget where user_id = #{userId} and expend_id = -1)
|
||||
,0) "sumBudget",
|
||||
IFNULL(
|
||||
(select sum(money) from qn_acc_bill c where c.bill_type = 'EXPEND' and c.user_id = #{userId} and c.date <![CDATA[ >= ]]> #{startDate} and c.date <![CDATA[ <= ]]> #{endDate})
|
||||
,0) "sumUsed"
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.quinn.service;
|
||||
|
||||
import com.quinn.common.wx.BudgetDTO;
|
||||
import com.quinn.common.wx.IndexDTO;
|
||||
import com.quinn.pojo.AccBudget;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
@@ -17,4 +18,6 @@ import java.util.List;
|
||||
public interface AccBudgetService extends IService<AccBudget> {
|
||||
|
||||
List<BudgetDTO> getBudget(String userId);
|
||||
|
||||
IndexDTO getIndexBudget(String userId);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.quinn.service.impl;
|
||||
|
||||
import com.quinn.common.wx.BudgetDTO;
|
||||
import com.quinn.common.wx.IndexDTO;
|
||||
import com.quinn.pojo.AccBudget;
|
||||
import com.quinn.mapper.AccBudgetMapper;
|
||||
import com.quinn.service.AccBudgetService;
|
||||
@@ -33,4 +34,12 @@ public class AccBudgetServiceImpl extends ServiceImpl<AccBudgetMapper, AccBudget
|
||||
String endDate = viewStrFromDate.substring(0,7) + "-31";
|
||||
return accBudgetMapper.getBudget(userId,startDate,endDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexDTO getIndexBudget(String userId) {
|
||||
String todayDate = QuinnUtils.getViewStrFromDate(new Date());
|
||||
String startDate = todayDate.substring(0,7) + "-01";
|
||||
String endDate = todayDate.substring(0,7) + "-31";
|
||||
return accBudgetMapper.getIndexBudget(userId,todayDate,startDate,endDate);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user