From a6e928d2b7eca051d5e5e23187cf7e0acbdc568b Mon Sep 17 00:00:00 2001 From: Strange <3304393868@qq.com> Date: Sun, 3 Mar 2024 21:28:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=BE=E8=A1=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=9B=BE=E8=A1=A8=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/web/controller/chart/chat.java | 47 +++++++++++-------- .../ruoyi/app/system/domain/ChatDomain.java | 31 ++++++++++++ .../ruoyi/app/system/mapper/ChatMapper.java | 12 ++--- .../resources/mapper/system/ChartMapper.xml | 20 ++++++++ 4 files changed, 84 insertions(+), 26 deletions(-) create mode 100644 RuoYi-Vue/ruoyi-homejizhang/src/main/resources/mapper/system/ChartMapper.xml diff --git a/RuoYi-Vue/ruoyi-admin/src/main/java/com/ruoyi/web/controller/chart/chat.java b/RuoYi-Vue/ruoyi-admin/src/main/java/com/ruoyi/web/controller/chart/chat.java index adb4d61..1f28f37 100644 --- a/RuoYi-Vue/ruoyi-admin/src/main/java/com/ruoyi/web/controller/chart/chat.java +++ b/RuoYi-Vue/ruoyi-admin/src/main/java/com/ruoyi/web/controller/chart/chat.java @@ -10,8 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; +import java.util.*; @Controller @Anonymous @@ -22,25 +21,33 @@ public class chat { private ChatMapper chatMapper; - @GetMapping("/PolylineChat") -// @ResponseBody - public String Polyline(Model model){ - List dataList = chatMapper.pyline(); - List moneyIncomeList = new ArrayList<>(); - List expenditureList = new ArrayList<>(); - List monthList = new ArrayList<>(); - for (ChatDomain chatDomain:dataList){ - if (chatDomain.getKind()==0){ - moneyIncomeList.add(chatDomain.getTotal_money()); - } - if (chatDomain.getKind()==1){ - expenditureList.add(chatDomain.getTotal_money()); + @GetMapping("/PolylineChart") + public String polylineChart(Model model, ChatDomain chatDomainAger) { + List dataList = chatMapper.pyline(chatDomainAger); + List moneyIncomeList = new ArrayList<>(); + List expenditureList = new ArrayList<>(); + Set monthSet = new HashSet<>(); + // 使用Java 8的Stream API来处理数据 + dataList.forEach(chatDomain -> { + if (chatDomain.getKind() == 0) { + moneyIncomeList.add(chatDomain.getTotal_money()); + } else if (chatDomain.getKind() == 1) { + expenditureList.add(chatDomain.getTotal_money()); } - monthList.add(chatDomain.getMonth()); - } - model.addAttribute("moneyIncomeList",moneyIncomeList); - model.addAttribute("expenditureList",expenditureList); - return "/polyline"; + monthSet.add(chatDomain.getMonth()); + }); + + // 将Set转换为List,并排序 + List monthList = new ArrayList<>(monthSet); + Collections.sort(monthList); + + model.addAttribute("moneyIncomeList", moneyIncomeList); + model.addAttribute("expenditureList", expenditureList); + model.addAttribute("monthList", monthList); + + // 如果返回的是页面,则不需要添加@ResponseBody注解 + return "polyline"; } + } diff --git a/RuoYi-Vue/ruoyi-homejizhang/src/main/java/com/ruoyi/app/system/domain/ChatDomain.java b/RuoYi-Vue/ruoyi-homejizhang/src/main/java/com/ruoyi/app/system/domain/ChatDomain.java index 09e68ec..c573c79 100644 --- a/RuoYi-Vue/ruoyi-homejizhang/src/main/java/com/ruoyi/app/system/domain/ChatDomain.java +++ b/RuoYi-Vue/ruoyi-homejizhang/src/main/java/com/ruoyi/app/system/domain/ChatDomain.java @@ -11,6 +11,37 @@ public class ChatDomain { private Integer kind; + + private Integer Year; + + private Integer startMonth; + + private Integer endMoth; + + public Integer getStartMoth() { + return startMonth; + } + + public void setStartMoth(Integer startMoth) { + this.startMonth = startMoth; + } + + public Integer getEndMoth() { + return endMoth; + } + + public void setEndMoth(Integer endMoth) { + this.endMoth = endMoth; + } + + public Integer getYear() { + return Year; + } + + public void setYear(Integer year) { + Year = year; + } + public Integer getId() { return id; } diff --git a/RuoYi-Vue/ruoyi-homejizhang/src/main/java/com/ruoyi/app/system/mapper/ChatMapper.java b/RuoYi-Vue/ruoyi-homejizhang/src/main/java/com/ruoyi/app/system/mapper/ChatMapper.java index e088baa..ce64b5e 100644 --- a/RuoYi-Vue/ruoyi-homejizhang/src/main/java/com/ruoyi/app/system/mapper/ChatMapper.java +++ b/RuoYi-Vue/ruoyi-homejizhang/src/main/java/com/ruoyi/app/system/mapper/ChatMapper.java @@ -10,10 +10,10 @@ import java.util.List; @Mapper public interface ChatMapper { - @Select("SELECT SUM(money) AS total_money, month ,kind \n" + - "FROM accounttb \n" + - "WHERE `month` IS NOT NULL\n" + - "GROUP BY month,kind \n" + - "ORDER BY month;\n") - public List pyline(); +// @Select("SELECT SUM(money) AS total_money, month ,kind \n" + +// "FROM accounttb \n" + +// "WHERE `month` IS NOT NULL\n" + +// "GROUP BY month,kind \n" + +// "ORDER BY month;\n") + public List pyline(ChatDomain chatDomain); } diff --git a/RuoYi-Vue/ruoyi-homejizhang/src/main/resources/mapper/system/ChartMapper.xml b/RuoYi-Vue/ruoyi-homejizhang/src/main/resources/mapper/system/ChartMapper.xml new file mode 100644 index 0000000..cea25b6 --- /dev/null +++ b/RuoYi-Vue/ruoyi-homejizhang/src/main/resources/mapper/system/ChartMapper.xml @@ -0,0 +1,20 @@ + + + + + +