【WX】账单报表
This commit is contained in:
35
src/main/java/com/quinn/common/wx/AccExpendDTO.java
Normal file
35
src/main/java/com/quinn/common/wx/AccExpendDTO.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author limqsh
|
||||||
|
* @since 2023-02-07
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AccExpendDTO implements Serializable {
|
||||||
|
|
||||||
|
private Integer expendId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "金额")
|
||||||
|
private Double money;
|
||||||
|
|
||||||
|
private String moneyName;
|
||||||
|
|
||||||
|
private String moneyIcon;
|
||||||
|
|
||||||
|
private Double progress;
|
||||||
|
}
|
||||||
12
src/main/java/com/quinn/common/wx/DayLine.java
Normal file
12
src/main/java/com/quinn/common/wx/DayLine.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package com.quinn.common.wx;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DayLine implements Serializable {
|
||||||
|
private String month;
|
||||||
|
private AccBillType accBillType;
|
||||||
|
private Double money;
|
||||||
|
}
|
||||||
11
src/main/java/com/quinn/common/wx/SearchExpend.java
Normal file
11
src/main/java/com/quinn/common/wx/SearchExpend.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package com.quinn.common.wx;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SearchExpend implements Serializable {
|
||||||
|
private Integer expendId;
|
||||||
|
private String rangeDate;
|
||||||
|
}
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
package com.quinn.controller.wx;
|
package com.quinn.controller.wx;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.quinn.common.wx.AccBillDTO;
|
import com.quinn.common.wx.*;
|
||||||
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.dto.res.ResponseDTO;
|
||||||
import com.quinn.pojo.AccBill;
|
import com.quinn.pojo.AccBill;
|
||||||
import com.quinn.pojo.AccSetting;
|
import com.quinn.pojo.AccSetting;
|
||||||
@@ -53,6 +50,43 @@ public class WxBillController extends BaseWxController{
|
|||||||
return ResponseDTO.ok().setData(accBills);
|
return ResponseDTO.ok().setData(accBills);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("user/bills/group/detail")
|
||||||
|
public ResponseDTO groupDetail(HttpServletRequest request, SearchExpend searchExpend){
|
||||||
|
Map result = new HashMap();
|
||||||
|
List<AccBillDTO> accBills = accBillService.groupDetailList(getLoginUserId(request),searchExpend.getExpendId(),searchExpend.getRangeDate());
|
||||||
|
double sumMoney = 0;
|
||||||
|
for (AccBillDTO accBill : accBills) {
|
||||||
|
sumMoney = sumMoney + accBill.getMoney();
|
||||||
|
}
|
||||||
|
result.put("sumMoney",sumMoney);
|
||||||
|
result.put("billList",accBills);
|
||||||
|
return ResponseDTO.ok().setData(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("user/bills/group/list")
|
||||||
|
public ResponseDTO groupList(HttpServletRequest request,String rangeDate){
|
||||||
|
List<AccExpendDTO> accBills = accBillService.groupList(getLoginUserId(request),rangeDate);
|
||||||
|
return ResponseDTO.ok().setData(accBills);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("user/bills/line/chart")
|
||||||
|
public ResponseDTO lineChart(HttpServletRequest request,String rangeDate){
|
||||||
|
Map result = accBillService.lineChart(getLoginUserId(request),rangeDate);
|
||||||
|
return ResponseDTO.ok().setData(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("user/bills/expend/order")
|
||||||
|
public ResponseDTO getExpendOrderBills(HttpServletRequest request,String rangeDate){
|
||||||
|
List<AccBillDTO> accBills = accBillService.listExpendBillOrder(getLoginUserId(request),rangeDate);
|
||||||
|
return ResponseDTO.ok().setData(accBills);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("user/bills/income/order")
|
||||||
|
public ResponseDTO getIncomeOrderBills(HttpServletRequest request,String rangeDate){
|
||||||
|
List<AccBillDTO> accBills = accBillService.listIncomeBillOrder(getLoginUserId(request),rangeDate);
|
||||||
|
return ResponseDTO.ok().setData(accBills);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("user/bills/month")
|
@PostMapping("user/bills/month")
|
||||||
public ResponseDTO getMonthBills(HttpServletRequest request,String rangeDate){
|
public ResponseDTO getMonthBills(HttpServletRequest request,String rangeDate){
|
||||||
BillMonthDTO billMonthDTO = new BillMonthDTO();
|
BillMonthDTO billMonthDTO = new BillMonthDTO();
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.quinn.mapper;
|
package com.quinn.mapper;
|
||||||
|
|
||||||
import com.quinn.common.wx.AccBillDTO;
|
import com.quinn.common.wx.AccBillDTO;
|
||||||
|
import com.quinn.common.wx.AccExpendDTO;
|
||||||
|
import com.quinn.common.wx.DayLine;
|
||||||
import com.quinn.pojo.AccBill;
|
import com.quinn.pojo.AccBill;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
@@ -27,4 +29,10 @@ public interface AccBillMapper extends BaseMapper<AccBill> {
|
|||||||
List<AccBillDTO> listIncomeBillOrder(String userId, String startDate, String endDate);
|
List<AccBillDTO> listIncomeBillOrder(String userId, String startDate, String endDate);
|
||||||
|
|
||||||
List<AccBillDTO> listExpendBillOrder(String userId, String startDate, String endDate);
|
List<AccBillDTO> listExpendBillOrder(String userId, String startDate, String endDate);
|
||||||
|
|
||||||
|
List<AccBillDTO> groupDetailList(String userId, Integer expendId, String startDate, String endDate);
|
||||||
|
|
||||||
|
List<AccExpendDTO> groupList(String userId, String startDate, String endDate);
|
||||||
|
|
||||||
|
List<DayLine> lineChartDay(String loginUserId, String rangeDate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,4 +74,28 @@
|
|||||||
from qn_acc_bill a where a.id = #{sid}
|
from qn_acc_bill a where a.id = #{sid}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="groupList" resultType="com.quinn.common.wx.AccExpendDTO">
|
||||||
|
select a.money_type "expendId",sum(a.money) "money",b.`name` "moneyName",b.icon "moneyIcon" from qn_acc_bill a,qn_acc_setting b where a.money_type = b.id and b.setting_type = 'EXPEND_SETTING'
|
||||||
|
and b.user_id = #{userId} and a.date <![CDATA[ >= ]]> #{startDate} and a.date <![CDATA[ <= ]]> #{endDate}
|
||||||
|
group by a.money_type
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="groupDetailList" resultType="com.quinn.common.wx.AccBillDTO">
|
||||||
|
select id,bill_type "billType",money,balance,
|
||||||
|
from_account "fromAccount",(select name from qn_acc_setting b where b.id = a.from_account) "fromAccountName",
|
||||||
|
account "account",(select name from qn_acc_setting b where b.id = a.account) "accountName",
|
||||||
|
a.money_type "moneyType",
|
||||||
|
(select name from qn_acc_setting b where b.id = a.money_type) "moneyName",
|
||||||
|
(select icon from qn_acc_setting b where b.id = a.money_type) "moneyIcon",
|
||||||
|
DATE_FORMAT(a.date,'%Y-%m-%d') date
|
||||||
|
from qn_acc_bill a where a.user_id = #{userId} and a.money_type = #{expendId} and a.date <![CDATA[ >= ]]> #{startDate} and a.date <![CDATA[ <= ]]> #{endDate}
|
||||||
|
order by a.date desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="lineChartDay" resultType="com.quinn.common.wx.DayLine ">
|
||||||
|
select t.date "date",t.bill_type "accBillType",sum(money) "money" from qn_acc_bill t
|
||||||
|
where t.user_id = #{userId} and t.date <![CDATA[ >= ]]> #{startDate} and t.date <![CDATA[ <= ]]> #{endDate}
|
||||||
|
group by t.bill_type,t.date order by t.date
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.quinn.service;
|
package com.quinn.service;
|
||||||
|
|
||||||
import com.quinn.common.wx.AccBillDTO;
|
import com.quinn.common.wx.AccBillDTO;
|
||||||
|
import com.quinn.common.wx.AccExpendDTO;
|
||||||
import com.quinn.pojo.AccBill;
|
import com.quinn.pojo.AccBill;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -22,4 +24,10 @@ public interface AccBillService extends IService<AccBill> {
|
|||||||
List<AccBillDTO> listIncomeBillOrder(String userId,String rangeDate);
|
List<AccBillDTO> listIncomeBillOrder(String userId,String rangeDate);
|
||||||
List<AccBillDTO> listExpendBillOrder(String userId,String rangeDate);
|
List<AccBillDTO> listExpendBillOrder(String userId,String rangeDate);
|
||||||
AccBillDTO getAccBill(Integer sid);
|
AccBillDTO getAccBill(Integer sid);
|
||||||
|
|
||||||
|
List<AccBillDTO> groupDetailList(String userId, Integer expendId, String rangeDate);
|
||||||
|
|
||||||
|
List<AccExpendDTO> groupList(String userId, String rangeDate);
|
||||||
|
|
||||||
|
Map lineChart(String loginUserId, String rangeDate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
package com.quinn.service.impl;
|
package com.quinn.service.impl;
|
||||||
|
|
||||||
import com.quinn.common.wx.AccBillDTO;
|
import com.quinn.common.wx.*;
|
||||||
import com.quinn.pojo.AccBill;
|
import com.quinn.pojo.AccBill;
|
||||||
import com.quinn.mapper.AccBillMapper;
|
import com.quinn.mapper.AccBillMapper;
|
||||||
import com.quinn.service.AccBillService;
|
import com.quinn.service.AccBillService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.quinn.utils.QuinnUtils;
|
import com.quinn.utils.QuinnUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -63,4 +66,48 @@ public class AccBillServiceImpl extends ServiceImpl<AccBillMapper, AccBill> impl
|
|||||||
public AccBillDTO getAccBill(Integer sid) {
|
public AccBillDTO getAccBill(Integer sid) {
|
||||||
return accBillMapper.getAccBill(sid);
|
return accBillMapper.getAccBill(sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AccBillDTO> groupDetailList(String userId, Integer expendId, String rangeDate) {
|
||||||
|
String startDate = rangeDate + "-01";
|
||||||
|
String endDate = rangeDate + "-31";
|
||||||
|
return accBillMapper.groupDetailList(userId,expendId,startDate,endDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AccExpendDTO> groupList(String userId, String rangeDate) {
|
||||||
|
String startDate = rangeDate + "-01";
|
||||||
|
String endDate = rangeDate + "-31";
|
||||||
|
List<AccExpendDTO> accExpendDTOS = accBillMapper.groupList(userId, startDate, endDate);
|
||||||
|
double sumMoney = 0;
|
||||||
|
for (AccExpendDTO e : accExpendDTOS) {
|
||||||
|
sumMoney = sumMoney + e.getMoney();
|
||||||
|
}
|
||||||
|
for (AccExpendDTO d : accExpendDTOS) {
|
||||||
|
double progress = 0;
|
||||||
|
try{
|
||||||
|
progress = d.getMoney() / sumMoney;
|
||||||
|
progress = Math.floor(progress * 10000) / 100;
|
||||||
|
}catch (Exception e){
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
d.setProgress(progress);
|
||||||
|
}
|
||||||
|
return accExpendDTOS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map lineChart(String loginUserId, String rangeDate) {
|
||||||
|
String startDate = rangeDate + "-01";
|
||||||
|
String endDate = rangeDate + "-31";
|
||||||
|
List<DayLine> dayLines = accBillMapper.lineChartDay(loginUserId, rangeDate);
|
||||||
|
if (!CollectionUtils.isEmpty(dayLines)){
|
||||||
|
Map<String, Double> expends = dayLines.stream().filter(x -> AccBillType.EXPEND.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getMonth, DayLine::getMoney, (k1, k2) -> k1));
|
||||||
|
Map<String, Double> incomes = dayLines.stream().filter(x -> AccBillType.INCOME.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getMonth, DayLine::getMoney, (k1, k2) -> k1));
|
||||||
|
Map<String, Double> transfers = dayLines.stream().filter(x -> AccBillType.TRANSFER.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getMonth, DayLine::getMoney, (k1, k2) -> k1));
|
||||||
|
Map<String, Double> repayments = dayLines.stream().filter(x -> AccBillType.REPAYMENT.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getMonth, DayLine::getMoney, (k1, k2) -> k1));
|
||||||
|
}
|
||||||
|
List<String> eachDay = QuinnUtils.getEachDay(rangeDate);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class QuinnUtils {
|
public class QuinnUtils {
|
||||||
|
|
||||||
@@ -19,6 +16,7 @@ public class QuinnUtils {
|
|||||||
private final static SimpleDateFormat sdfm = new SimpleDateFormat( "yyyyMMddHHmmss");
|
private final static SimpleDateFormat sdfm = new SimpleDateFormat( "yyyyMMddHHmmss");
|
||||||
private final static SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMdd");
|
private final static SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMdd");
|
||||||
private final static SimpleDateFormat sdfv = new SimpleDateFormat( "yyyy-MM-dd");
|
private final static SimpleDateFormat sdfv = new SimpleDateFormat( "yyyy-MM-dd");
|
||||||
|
private final static SimpleDateFormat sdfMonth = new SimpleDateFormat( "yyyy-MM");
|
||||||
|
|
||||||
public static String getUuid(){
|
public static String getUuid(){
|
||||||
return UUID.randomUUID().toString().replaceAll("-","");
|
return UUID.randomUUID().toString().replaceAll("-","");
|
||||||
@@ -40,6 +38,61 @@ public class QuinnUtils {
|
|||||||
return sdfv.format(date);
|
return sdfv.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getLatestMonth(String rangeDate){
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
for (int i=0 ; i < 6; i++){
|
||||||
|
Date date = new Date();
|
||||||
|
try {
|
||||||
|
date = sdfMonth.parse(rangeDate);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
date.setMonth(date.getMonth() + i - 5 );
|
||||||
|
result.add(sdfMonth.format(date));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getEachDay(String rangeDate){
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
String mothText = rangeDate.substring(5);
|
||||||
|
String yearText = rangeDate.substring(0,4);
|
||||||
|
int month = Integer.parseInt(mothText);
|
||||||
|
int year = Integer.parseInt(yearText);
|
||||||
|
boolean isRunN = false;
|
||||||
|
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
|
||||||
|
isRunN = true;
|
||||||
|
}
|
||||||
|
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
|
||||||
|
for (int i = 1; i <= 31; i++){
|
||||||
|
if (i < 10){
|
||||||
|
result.add(rangeDate + "-0" + i);
|
||||||
|
}else {
|
||||||
|
result.add(rangeDate + "-" + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (month == 4 || month == 6 || month == 9 || month == 11){
|
||||||
|
for (int i = 1; i <= 30; i++){
|
||||||
|
if (i < 10){
|
||||||
|
result.add(rangeDate + "-0" + i);
|
||||||
|
}else {
|
||||||
|
result.add(rangeDate + "-" + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (month == 2){
|
||||||
|
for (int i = 1; i <= (isRunN ? 29 : 28); i++){
|
||||||
|
if (i < 10){
|
||||||
|
result.add(rangeDate + "-0" + i);
|
||||||
|
}else {
|
||||||
|
result.add(rangeDate + "-" + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getCode(){
|
public static String getCode(){
|
||||||
int length = 6;
|
int length = 6;
|
||||||
//随机数
|
//随机数
|
||||||
|
|||||||
Reference in New Issue
Block a user