初始化版本完成报表完成
This commit is contained in:
@@ -6,7 +6,7 @@ import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class DayLine implements Serializable {
|
||||
private String month;
|
||||
private String date;
|
||||
private AccBillType accBillType;
|
||||
private Double money;
|
||||
}
|
||||
|
||||
@@ -34,5 +34,7 @@ public interface AccBillMapper extends BaseMapper<AccBill> {
|
||||
|
||||
List<AccExpendDTO> groupList(String userId, String startDate, String endDate);
|
||||
|
||||
List<DayLine> lineChartDay(String loginUserId, String rangeDate);
|
||||
List<DayLine> lineChartDay(String userId, String startDate, String endDate);
|
||||
|
||||
List<DayLine> lineChartMonth(String userId, List<String> latestMonth);
|
||||
}
|
||||
|
||||
@@ -92,10 +92,20 @@
|
||||
order by a.date desc
|
||||
</select>
|
||||
|
||||
<select id="lineChartDay" resultType="com.quinn.common.wx.DayLine ">
|
||||
<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>
|
||||
|
||||
<select id="lineChartMonth" resultType="com.quinn.common.wx.DayLine">
|
||||
select DATE_FORMAT(t.date,'%Y-%m') "date",t.bill_type "accBillType",sum(money) "money" from qn_acc_bill t
|
||||
where t.user_id = #{userId}
|
||||
and DATE_FORMAT(t.date,'%Y-%m') in
|
||||
<foreach collection="latestMonth" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
group by t.bill_type,DATE_FORMAT( t.date, '%Y-%m' )
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -10,9 +10,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -98,16 +96,101 @@ public class AccBillServiceImpl extends ServiceImpl<AccBillMapper, AccBill> impl
|
||||
|
||||
@Override
|
||||
public Map lineChart(String loginUserId, String rangeDate) {
|
||||
Map<String,List<Double>> result = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 统计当月每天的收支走势图
|
||||
*/
|
||||
String startDate = rangeDate + "-01";
|
||||
String endDate = rangeDate + "-31";
|
||||
List<DayLine> dayLines = accBillMapper.lineChartDay(loginUserId, rangeDate);
|
||||
List<DayLine> dayLines = accBillMapper.lineChartDay(loginUserId, startDate,endDate);
|
||||
Map<String, Double> expends = new HashMap<>();
|
||||
Map<String, Double> incomes = new HashMap<>();
|
||||
Map<String, Double> transfers = new HashMap<>();
|
||||
Map<String, Double> repayments = new HashMap<>();
|
||||
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));
|
||||
expends = dayLines.stream().filter(x -> AccBillType.EXPEND.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getDate, DayLine::getMoney, (k1, k2) -> k1));
|
||||
incomes = dayLines.stream().filter(x -> AccBillType.INCOME.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getDate, DayLine::getMoney, (k1, k2) -> k1));
|
||||
transfers = dayLines.stream().filter(x -> AccBillType.TRANSFER.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getDate, DayLine::getMoney, (k1, k2) -> k1));
|
||||
repayments = dayLines.stream().filter(x -> AccBillType.REPAYMENT.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getDate, DayLine::getMoney, (k1, k2) -> k1));
|
||||
}
|
||||
List<String> eachDay = QuinnUtils.getEachDay(rangeDate);
|
||||
return null;
|
||||
List<Double> lineDayExpend = new ArrayList<>();
|
||||
List<Double> lineDayIncome = new ArrayList<>();
|
||||
List<Double> lineDayTransfer = new ArrayList<>();
|
||||
List<Double> lineDayRepayment = new ArrayList<>();
|
||||
for (String date : eachDay) {
|
||||
if (expends.get(date) == null){
|
||||
lineDayExpend.add(0.0);
|
||||
}else {
|
||||
lineDayExpend.add(expends.get(date));
|
||||
}
|
||||
if (incomes.get(date) == null){
|
||||
lineDayIncome.add(0.0);
|
||||
}else {
|
||||
lineDayIncome.add(incomes.get(date));
|
||||
}
|
||||
if (transfers.get(date) == null){
|
||||
lineDayTransfer.add(0.0);
|
||||
}else {
|
||||
lineDayTransfer.add(transfers.get(date));
|
||||
}
|
||||
if (repayments.get(date) == null){
|
||||
lineDayRepayment.add(0.0);
|
||||
}else {
|
||||
lineDayRepayment.add(repayments.get(date));
|
||||
}
|
||||
}
|
||||
result.put("lineDayExpend",lineDayExpend);
|
||||
result.put("lineDayIncome",lineDayIncome);
|
||||
result.put("lineDayTransfer",lineDayTransfer);
|
||||
result.put("lineDayRepayment",lineDayRepayment);
|
||||
|
||||
/**
|
||||
* 统计近六个月的收支走势图
|
||||
*/
|
||||
List<String> latestMonth = QuinnUtils.getLatestMonth(rangeDate);
|
||||
List<DayLine> monthLine = accBillMapper.lineChartMonth(loginUserId, latestMonth);
|
||||
Map<String, Double> expendMap = new HashMap<>();
|
||||
Map<String, Double> incomeMap = new HashMap<>();
|
||||
Map<String, Double> transferMap = new HashMap<>();
|
||||
Map<String, Double> repaymentMap = new HashMap<>();
|
||||
if (!CollectionUtils.isEmpty(monthLine)){
|
||||
expendMap = monthLine.stream().filter(x -> AccBillType.EXPEND.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getDate, DayLine::getMoney, (k1, k2) -> k1));
|
||||
incomeMap = monthLine.stream().filter(x -> AccBillType.INCOME.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getDate, DayLine::getMoney, (k1, k2) -> k1));
|
||||
transferMap = monthLine.stream().filter(x -> AccBillType.TRANSFER.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getDate, DayLine::getMoney, (k1, k2) -> k1));
|
||||
repaymentMap = monthLine.stream().filter(x -> AccBillType.REPAYMENT.equals(x.getAccBillType())).collect(Collectors.toMap(DayLine::getDate, DayLine::getMoney, (k1, k2) -> k1));
|
||||
}
|
||||
List<Double> lineMonthExpend = new ArrayList<>();
|
||||
List<Double> lineMonthIncome = new ArrayList<>();
|
||||
List<Double> lineMonthTransfer = new ArrayList<>();
|
||||
List<Double> lineMonthRepayment = new ArrayList<>();
|
||||
for (String date : latestMonth) {
|
||||
if (expendMap.get(date) == null){
|
||||
lineMonthExpend.add(0.0);
|
||||
}else {
|
||||
lineMonthExpend.add(expendMap.get(date));
|
||||
}
|
||||
if (incomeMap.get(date) == null){
|
||||
lineMonthIncome.add(0.0);
|
||||
}else {
|
||||
lineMonthIncome.add(incomeMap.get(date));
|
||||
}
|
||||
if (transferMap.get(date) == null){
|
||||
lineMonthTransfer.add(0.0);
|
||||
}else {
|
||||
lineMonthTransfer.add(transferMap.get(date));
|
||||
}
|
||||
if (repaymentMap.get(date) == null){
|
||||
lineMonthRepayment.add(0.0);
|
||||
}else {
|
||||
lineMonthRepayment.add(repaymentMap.get(date));
|
||||
}
|
||||
}
|
||||
result.put("lineMonthExpend",lineMonthExpend);
|
||||
result.put("lineMonthIncome",lineMonthIncome);
|
||||
result.put("lineMonthTransfer",lineMonthTransfer);
|
||||
result.put("lineMonthRepayment",lineMonthRepayment);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,17 +54,28 @@ public class QuinnUtils {
|
||||
}
|
||||
|
||||
public static List<String> getEachDay(String rangeDate){
|
||||
String viewStrFromDate = getViewStrFromDate(new Date());
|
||||
int max = 32;
|
||||
int cYear = Integer.parseInt(viewStrFromDate.substring(0,4));
|
||||
int cMonth = Integer.parseInt(viewStrFromDate.substring(5,7));
|
||||
int cDay = Integer.parseInt(viewStrFromDate.substring(8));
|
||||
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);
|
||||
if (year == cYear && month == cMonth) {
|
||||
max = cDay;
|
||||
}
|
||||
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 > max) {
|
||||
break;
|
||||
}
|
||||
if (i < 10){
|
||||
result.add(rangeDate + "-0" + i);
|
||||
}else {
|
||||
@@ -74,6 +85,9 @@ public class QuinnUtils {
|
||||
}
|
||||
if (month == 4 || month == 6 || month == 9 || month == 11){
|
||||
for (int i = 1; i <= 30; i++){
|
||||
if (i > max) {
|
||||
break;
|
||||
}
|
||||
if (i < 10){
|
||||
result.add(rangeDate + "-0" + i);
|
||||
}else {
|
||||
@@ -83,6 +97,9 @@ public class QuinnUtils {
|
||||
}
|
||||
if (month == 2){
|
||||
for (int i = 1; i <= (isRunN ? 29 : 28); i++){
|
||||
if (i > max) {
|
||||
break;
|
||||
}
|
||||
if (i < 10){
|
||||
result.add(rangeDate + "-0" + i);
|
||||
}else {
|
||||
|
||||
Reference in New Issue
Block a user