添加图表优化图表显示逻辑
This commit is contained in:
parent
27f8920217
commit
a6e928d2b7
|
@ -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<ChatDomain> dataList = chatMapper.pyline();
|
||||
List<BigDecimal> moneyIncomeList = new ArrayList<>();
|
||||
List<BigDecimal> expenditureList = new ArrayList<>();
|
||||
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());
|
||||
@GetMapping("/PolylineChart")
|
||||
public String polylineChart(Model model, ChatDomain chatDomainAger) {
|
||||
List<ChatDomain> dataList = chatMapper.pyline(chatDomainAger);
|
||||
List<BigDecimal> moneyIncomeList = new ArrayList<>();
|
||||
List<BigDecimal> expenditureList = new ArrayList<>();
|
||||
Set<Integer> 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<Integer> monthList = new ArrayList<>(monthSet);
|
||||
Collections.sort(monthList);
|
||||
|
||||
model.addAttribute("moneyIncomeList", moneyIncomeList);
|
||||
model.addAttribute("expenditureList", expenditureList);
|
||||
model.addAttribute("monthList", monthList);
|
||||
|
||||
// 如果返回的是页面,则不需要添加@ResponseBody注解
|
||||
return "polyline";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<ChatDomain> 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<ChatDomain> pyline(ChatDomain chatDomain);
|
||||
}
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue