package com.example.controller;
import cn.hutool.json.JSONObject;
import com.example.common.Result;
import com.example.entity.*;
import com.example.service.*;
import com.example.vo.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/echarts")
public class EchartsController {
@Resource
private AdminInfoService adminInfoService;
@Resource
private UserInfoService userInfoService;
@Resource
private ClassifyInfoService classifyInfoService;
@Resource
private SubClassifyInfoService subClassifyInfoService;
@Resource
private CollectInfoService collectInfoService;
@Resource
private PraiseInfoService praiseInfoService;
@Resource
private NewsInfoService newsInfoService;
@Resource
private MessageInfoService messageInfoService;
@GetMapping("/get/{modelName}")
Result<List<EchartsData>> getEchartsData(@PathVariable String modelName) {
List<EchartsData> list = new ArrayList<>();
switch (modelName) {
case "adminInfo":
List<AdminInfoVo> adminInfoList = adminInfoService.findAll();
List<AdminInfo> adminInfoMaleList = adminInfoList.stream().filter(x -> "男".equals(x.getSex())).collect(Collectors.toList());
Map<String, Integer> adminInfoMap = new HashMap<>(2);
adminInfoMap.put("男", adminInfoMaleList.size());
adminInfoMap.put("女", adminInfoList.size() - adminInfoMaleList.size());
getPieData("管理员", list, adminInfoMap);
getBarData("管理员", list, adminInfoMap);
break;
case "userInfo":
List<UserInfoVo> userInfoList = userInfoService.findAll();
List<UserInfo> userInfoMaleList = userInfoList.stream().filter(x -> "男".equals(x.getSex())).collect(Collectors.toList());
Map<String, Integer> userInfoMap = new HashMap<>(2);
userInfoMap.put("男", userInfoMaleList.size());
userInfoMap.put("女", userInfoList.size() - userInfoMaleList.size());
getPieData("用户", list, userInfoMap);
getBarData("用户", list, userInfoMap);
break;
case "classifyInfo":
List<ClassifyInfoVo> classifyInfoList = classifyInfoService.findAll();
Map<String, Integer> classifyInfoMap = new HashMap<>(2);
for (ClassifyInfo classifyInfo : classifyInfoList) {
Integer value = classifyInfoMap.get(classifyInfo.getName());
if (value != null && value != 0) {
classifyInfoMap.put(classifyInfo.getName(), value + 1);
} else {
classifyInfoMap.put(classifyInfo.getName(), 1);
}
}
getPieData("菜谱大类", list, classifyInfoMap);
getBarData("菜谱大类", list, classifyInfoMap);
break;
case "subClassifyInfo":
List<SubClassifyInfoVo> subClassifyInfoList = subClassifyInfoService.findAll();
Map<String, Integer> subClassifyInfoMap = new HashMap<>(2);
for (SubClassifyInfo subClassifyInfo : subClassifyInfoList) {
Integer value = subClassifyInfoMap.get(subClassifyInfo.getName());
if (value != null && value != 0) {
subClassifyInfoMap.put(subClassifyInfo.getName(), value + 1);
} else {
subClassifyInfoMap.put(subClassifyInfo.getName(), 1);
}
}
getPieData("菜谱小类", list, subClassifyInfoMap);
getBarData("菜谱小类", list, subClassifyInfoMap);
break;
case "collectInfo":
List<CollectInfoVo> collectInfoList = collectInfoService.findAll();
Map<String, Integer> collectInfoMap = new HashMap<>(2);
for (CollectInfo collectInfo : collectInfoList) {
Integer value = collectInfoMap.get(collectInfo.getName());
if (value != null && value != 0) {
collectInfoMap.put(collectInfo.getName(), value + 1);
} else {
collectInfoMap.put(collectInfo.getName(), 1);
}
}
getPieData("收藏", list, collectInfoMap);
getBarData("收藏", list, collectInfoMap);
break;
case "praiseInfo":
List<PraiseInfoVo> praiseInfoList = praiseInfoService.findAll();
Map<String, Integer> praiseInfoMap = new HashMap<>(2);
for (PraiseInfo praiseInfo : praiseInfoList) {
Integer value = praiseInfoMap.get(praiseInfo.getName());
if (value != null && value != 0) {
praiseInfoMap.put(praiseInfo.getName(), value + 1);
} else {
praiseInfoMap.put(praiseInfo.getName(), 1);
}
}
getPieData("笔记点赞", list, praiseInfoMap);
getBarData("笔记点赞", list, praiseInfoMap);
break;
case "newsInfo":
List<NewsInfoVo> newsInfoList = newsInfoService.findAll();
Map<String, Integer> newsInfoMap = new HashMap<>(2);
for (NewsInfo newsInfo : newsInfoList) {
Integer value = newsInfoMap.get(newsInfo.getName());
if (value != null && value != 0) {
newsInfoMap.put(newsInfo.getName(), value + 1);
} else {
newsInfoMap.put(newsInfo.getName(), 1);
}
}
getPieData("饮食资讯", list, newsInfoMap);
getBarData("饮食资讯", list, newsInfoMap);
break;
case "messageInfo":
List<MessageInfoVo> messageInfoList = messageInfoService.findAll();
Map<String, Integer> messageInfoMap = new HashMap<>(2);
for (MessageInfo messageInfo : messageInfoList) {
Integer value = messageInfoMap.get(messageInfo.getName());
if (value != null && value != 0) {
messageInfoMap.put(messageInfo.getName(), value + 1);
} else {
messageInfoMap.put(messageInfo.getName(), 1);
}
}
getPieData("趣味答题", list, messageInfoMap);
getBarData("趣味答题", list, messageInfoMap);
break;
default:
break;
}
return Result.success(list);
}
@GetMapping("/options")
Result<List<Map<String, String>>> getOptions() {
List<Map<String, String>> options = new ArrayList<>();
Map<String, String> optionMap1 = new HashMap<>();
optionMap1.put("value", "adminInfo");
optionMap1.put("label", "管理员信息");
options.add(optionMap1);
Map<String, String> optionMap2 = new HashMap<>();
optionMap2.put("value", "userInfo");
optionMap2.put("label", "用户信息");
options.add(optionMap2);
Map<String, String> optionMap3 = new HashMap<>();
optionMap3.put("value", "classifyInfo");
optionMap3.put("label", "菜谱大类信息");
options.add(optionMap3);
Map<String, String> optionMap4 = new HashMap<>();
optionMap4.put("value", "subClassifyInfo");
optionMap4.put("label", "菜谱小类信息");
options.add(optionMap4);
Map<String, String> optionMap5 = new HashMap<>();
optionMap5.put("value", "collectInfo");
optionMap5.put("label", "收藏信息");
options.add(optionMap5);
Map<String, String> optionMap6 = new HashMap<>();
optionMap6.put("value", "praiseInfo");
optionMap6.put("label", "笔记点赞信息");
options.add(optionMap6);
Map<String, String> optionMap7 = new HashMap<>();
optionMap7.put("value", "newsInfo");
optionMap7.put("label", "饮食资讯信息");
options.add(optionMap7);
Map<String, String> optionMap8 = new HashMap<>();
optionMap8.put("value", "messageInfo");
optionMap8.put("label", "趣味答题信息");
options.add(optionMap8);
return Result.success(options);
}
private void getPieData(String name, List<EchartsData> pieList, Map<String, Integer> dataMap) {
EchartsData pieData = new EchartsData();
EchartsData.Series series = new EchartsData.Series();
Map<String, String> titleMap = new HashMap<>(2);
titleMap.put("text", name + "信息");
pieData.setTitle(titleMap);
series.setName(name + "比例");
series.setType("pie");
series.setRadius("55%");
List<Object> objects = new ArrayList<>();
List<Object> legendList = new ArrayList<>();
for (String key : dataMap.keySet()) {
Integer value = dataMap.get
地球炒蛋
- 粉丝: 4
- 资源: 23
最新资源
- 利用五次多项式实现基于模型预测控制的道算法,可根据程序修改自己的算法 matlab2016b,carsim2018
- 西门子大型PLC程序,博途V13 v14 V15 V16 V17版,CPu1511,屏为1200,外加30台G120变频器PN通讯十ET200远程io,温度pid控制,压力处理,张力控制,收卷控
- simulink直流调速系统的仿真模型 晶闸管-直流电动机开环调速系统,基于Matalab2018a
- 电机马达PMSM电机负载观测转矩前馈simulink 基于Luenberger降阶状态观测器,包含PMSM数学模型,PMSM双闭环PI矢量控制,并添加了前馈控制,采用SVPWM调制
- Java毕设项目:基于spring+mybatis+maven+mysql实现的高校食堂订餐系统【含源码+数据库+毕业论文】
- MATLAB驱动防滑转控制ASR牵引力控制TCS模型 ASR模型 驱动防滑转模型 牵引力控制系统模型 选择PID控制算法以及对照控制算法,共两种控制算法,可进行选择 选择冰路面以及雪路面,共两
- 基于FPGA的点阵屏设计,基于Quartus ii开发,Verilog编程语言,也可移植到vivado开发 1、可以显示多个汉字 2、暂停、启动控制 3、左移右移控制 4、调速控制
- omron欧姆龙CJ CP程序 欧姆龙CP1H-XA,主机搭载CIF串口模块与2从机PC LINK通信控制, X,Y轴模组矩阵取放料控制,托盘升降机提升机控制应用 全自动LCD组装机,欧姆龙触摸
- Java毕设项目:基于spring+mybatis+maven+mysql实现的人力资源管理系统【含源码+数据库+毕业论文】
- OMRON大型PLC CJ2M项目案例,配套昆仑通泰触摸屏程序 包含模拟量称重模块,SCU串行通讯模块,通过CMND指令把Fins协议转为MODBUS RTU 控制32台三菱 D720
- 128W微型车载逆变器方案,包含原理图,PCB图,烧录文件,汇编源代码,注意是汇编语言
- MES机台看板系统 可连接24台机,还可以扩展更多 通过网口直接与PLC直接通讯,包含西门子全系列,倍福PLC,三菱,松下,欧姆龙主流PLC 可以读写PLC里面BOOL,int,字符串,汉字(源码
- No.1004 S7-200 PLC和组态王温室大棚温室 带解释的梯形图程序,接线图原理图图纸,io分配,组态画面
- Python编程项目:Labyrinth迷宫小游戏完整源码分享给需要的同学
- QT界面开发框架,完整资源与代码一套
- 恒压供水plc程序,三菱FX1N.2N系列plc+fx0n3a模拟量模块+昆仑通态tpc7062触摸屏.全套的图纸十程序,完整的注释,适合参考学习
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈