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 @@ + + + + + +