添加图表优化图表显示逻辑

This commit is contained in:
Strange 2024-03-03 21:28:45 +08:00
parent 27f8920217
commit a6e928d2b7
4 changed files with 84 additions and 26 deletions

View File

@ -10,8 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.*;
import java.util.List;
@Controller @Controller
@Anonymous @Anonymous
@ -22,25 +21,33 @@ public class chat {
private ChatMapper chatMapper; private ChatMapper chatMapper;
@GetMapping("/PolylineChat") @GetMapping("/PolylineChart")
// @ResponseBody public String polylineChart(Model model, ChatDomain chatDomainAger) {
public String Polyline(Model model){ List<ChatDomain> dataList = chatMapper.pyline(chatDomainAger);
List<ChatDomain> dataList = chatMapper.pyline(); List<BigDecimal> moneyIncomeList = new ArrayList<>();
List<BigDecimal> moneyIncomeList = new ArrayList<>(); List<BigDecimal> expenditureList = new ArrayList<>();
List<BigDecimal> expenditureList = new ArrayList<>(); Set<Integer> monthSet = new HashSet<>();
List<Integer> 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());
// 使用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()); monthSet.add(chatDomain.getMonth());
} });
model.addAttribute("moneyIncomeList",moneyIncomeList);
model.addAttribute("expenditureList",expenditureList); // 将Set转换为List并排序
return "/polyline"; List<Integer> monthList = new ArrayList<>(monthSet);
Collections.sort(monthList);
model.addAttribute("moneyIncomeList", moneyIncomeList);
model.addAttribute("expenditureList", expenditureList);
model.addAttribute("monthList", monthList);
// 如果返回的是页面则不需要添加@ResponseBody注解
return "polyline";
} }
} }

View File

@ -11,6 +11,37 @@ public class ChatDomain {
private Integer kind; 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() { public Integer getId() {
return id; return id;
} }

View File

@ -10,10 +10,10 @@ import java.util.List;
@Mapper @Mapper
public interface ChatMapper { public interface ChatMapper {
@Select("SELECT SUM(money) AS total_money, month ,kind \n" + // @Select("SELECT SUM(money) AS total_money, month ,kind \n" +
"FROM accounttb \n" + // "FROM accounttb \n" +
"WHERE `month` IS NOT NULL\n" + // "WHERE `month` IS NOT NULL\n" +
"GROUP BY month,kind \n" + // "GROUP BY month,kind \n" +
"ORDER BY month;\n") // "ORDER BY month;\n")
public List<ChatDomain> pyline(); public List<ChatDomain> pyline(ChatDomain chatDomain);
} }

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.app.system.mapper.ChatMapper">
<select id="pyline" resultType="com.ruoyi.app.system.domain.ChatDomain">
SELECT SUM(money) AS total_money, month, kind
FROM accounttb
WHERE `month` IS NOT NULL
<if test="Year != null">
AND `year` = #{Year}
</if>
<if test="startMonth != null and endMonth != null">
AND `month` BETWEEN #{startMonth} AND #{endMonth}
</if>
GROUP BY month, kind
ORDER BY month;
</select>
</mapper>