项目编号:BS-GX-051
一,环境介绍
语言环境:Java: jdk1.8
数据库:Mysql: mysql5.7
应用服务器:Tomcat: tomcat8.5.31
开发工具:IDEA或eclipse
开发技术:Springboot+Vue
二,项目简介
本文主要介绍校园意见箱系统的开发与实现。意见箱作为一个传统记名或不记名的沟通的载体,在社会上存在由来己久,在古代它被悬于木桩之上,人们将自己的意见置于木箱之中,由此来收集人们对某些事情或某些人的意见。这个收集意见的方式在现在社会同样被大量应用,只不过利用新兴的网络和信息化技术将它换了一种方式来进行实现,比如现在的问卷调查表等也是一种意见的收集方式,这种方式大部分是匿名的,可以很好的保护人们的隐私。
对于本次设计的校园意见箱来讲,也主要是通过信息化技术为载体,来实现一个收集校内学生意见和建议的平台。它通过WEB的形式来体现,学生们可以登陆意见箱平台系统,在线参与问卷调查,提交自己对某些事务的意见和建议,这些调查和意见的收集都是匿名的,学生不必担心自己隐私被泄漏, 同时意见箱系统也提供了一个在线交流的平台,学生可以在线进行讨论互动,可以查看新闻信息和公告信息等,相当于设计了一个综合性的校园意见箱平台。
本课题的开发与实现主要运用JAVA开发技术,采用前后端分离的方式来开发实现,前端采用VUE技术来设计系统的前端界面与人机交互,后台采用Springboot框架集成Mybatis-plus框架来开发实现,数据库采用Mysql数据库,开发工具使用IDEA和VSCODE来进行开发实现。整个系统实用性很强,界面简洁大方。
本课题是校园意见箱系统,经过查阅大量的参考文献,参考同类的意见箱系统和调查问卷系统,同时走访高校的学校领导和大量的学生,进行了系统的功能性需求分析。经过分析确定系统的用户主要分为前端使用用户和后台管理用户两类,前端用户的主要功能包含有:用户在线注册与登陆、平台发布的新闻的信息浏览、公告信息的查看、调查问卷的参与、在线意见的提交、在线互动交流的实现以及个人中心管理。具体的系统功能结构图如下图3.1所示:
图3.1 前端用户功能
意见箱后台管理用户的主要功能包含有:用户信息管理模块、个人信息管理模块、交流论坛数据管理、意见箱信息管理、调查问卷信息管理、问卷题库管理、问卷记录查看、公告管理、新闻管理等。
图3.2 后台用户功能
三,系统展示
前端用户进入校园意见箱平台后可以在线进行注册,填写相关信息后提交到服务器平台,系统基于前后端分离的模式开发实现,前端用户的数据通过异步请求以JSON的数据格式传输到服务器,服务器接受数据后进行解析,然后使用Mybatis-plus框架的保存方法将数据保存至数据库表 yonghu 表中,下面展示用户注册的基本界面,如图3.1所示:
图3.1 用户注册
后台功能展示
其它略
四,核心代码展示
package com.controller;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSON;
import com.utils.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.annotation.IgnoreAuth;
import com.baidu.aip.face.AipFace;
import com.baidu.aip.face.MatchRequest;
import com.baidu.aip.util.Base64Util;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.ConfigEntity;
import com.service.CommonService;
import com.service.ConfigService;
import com.utils.BaiduUtil;
import com.utils.FileUtil;
import com.utils.R;
/**
* 通用接口
*/
@RestController
public class CommonController{
private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
@Autowired
private CommonService commonService;
@Autowired
private ConfigService configService;
private static AipFace client = null;
private static String BAIDU_DITU_AK = null;
@RequestMapping("/location")
public R location(String lng,String lat) {
if(BAIDU_DITU_AK==null) {
BAIDU_DITU_AK = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "baidu_ditu_ak")).getValue();
if(BAIDU_DITU_AK==null) {
return R.error("请在配置管理中正确配置baidu_ditu_ak");
}
}
Map<String, String> map = BaiduUtil.getCityByLonLat(BAIDU_DITU_AK, lng, lat);
return R.ok().put("data", map);
}
/**
* 人脸比对
*
* @param face1 人脸1
* @param face2 人脸2
* @return
*/
@RequestMapping("/matchFace")
public R matchFace(String face1, String face2, HttpServletRequest request) {
if(client==null) {
/*String AppID = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "AppID")).getValue();*/
String APIKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "APIKey")).getValue();
String SecretKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "SecretKey")).getValue();
String token = BaiduUtil.getAuth(APIKey, SecretKey);
if(token==null) {
return R.error("请在配置管理中正确配置APIKey和SecretKey");
}
client = new AipFace(null, APIKey, SecretKey);
client.setConnectionTimeoutInMillis(2000);
client.setSocketTimeoutInMillis(60000);
}
JSONObject res = null;
try {
File file1 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face1);
File file2 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face2);
String img1 = Base64Util.encode(FileUtil.FileToByte(file1));
String img2 = Base64Util.encode(FileUtil.FileToByte(file2));
MatchRequest req1 = new MatchRequest(img1, "BASE64");
MatchRequest req2 = new MatchRequest(img2, "BASE64");
ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
requests.add(req1);
requests.add(req2);
res = client.match(requests);
System.out.println(res.get("result"));
} catch (FileNotFoundException e) {
e.printStackTrace();
return R.error("文件不存在");
} catch (IOException e) {
e.printStackTrace();
}
return R.ok().put("data", com.alibaba.fastjson.JSONObject.parse(res.get("result").toString()));
}
/**
* 获取table表中的column列表(联动接口)
* @return
*/
@RequestMapping("/option/{tableName}/{columnName}")
@IgnoreAuth
public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,String level,String parent) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("table", tableName);
params.put("column", columnName);
if(StringUtils.isNotBlank(level)) {
params.put("level", level);
}
if(StringUtils.isNotBlank(parent)) {
params.put("parent", parent);
}
List<String> data = commonService.getOption(params);
return R.ok().put("data", data);
}
/**
* 根据table中的column获取单条记录
* @return
*/
@RequestMapping("/follow/{tableName}/{columnName}")
@IgnoreAuth
public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("table", tableName);
params.put("column", columnName);
params.put("columnValue", columnValue);
Map<String, Object> result = commonService.getFollowByOption(params);
return R.ok().put("data", result);
}
/**
* 修改table表的sfsh状态
* @param map
* @return
*/
@RequestMapping("/sh/{tableName}")
public R sh(@PathVariable("tableName") String tableName, @RequestBody Map<String, Object> map) {
map.put("table", tableName);
commonService.sh(map);
return R.ok();
}
/**
* 获取需要提醒的记录数
* @param tableName
* @param columnName
* @param type 1:数字 2:日期
* @param map
* @return
*/
@RequestMapping("/remind/{tableName}/{columnName}/{type}")
@IgnoreAuth
public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("table", tableName);
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
int count = commonService.remindCount(map);
return R.ok().put("count", count);
}
/**
* 圖表统计
*/
@IgnoreAuth
@RequestMapping("/group/{tableName}")
public R group1(@PathVariable("tableName") String tableName, @RequestParam Map<String,Object> params) {
params.put("table1", tableName);
List<Map<String, Object>> result = commonService.chartBoth(params);
return R.ok().put("data", result);
}
/**
* 单列求和
*/
@RequestMapping("/cal/{tableName}")
@IgnoreAuth
public R cal(@PathVariable("tableName") String tableName,Integer examquestionId) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("table", tableName);
params.put("examquestionId", examquestionId);
List<Map<String, Object>> result = commonService.selectCal(params);
return R.ok().put("data", result);
}
/**
* 分组统计
*/
@RequestMapping("/group/{tableName}/{columnName}")
@IgnoreAuth
public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("table", tableName);
params.put("column", columnName);
List<Map<String, Object>> result = commonService.selectGroup(params);
return R.ok().put("data", result);
}
/**
* (按值统计)
*/
@RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}")
@IgnoreAuth
public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("table", tableName);
params.put("xColumn", xColumnName);
params.put("yColumn", yColumnName);
List<Map<String, Object>> result = commonService.selectValue(params);
return R.ok().put("data", result);
}
/**
* 下面为新加的
*
*
*
*/
/**
* 查询字典表的分组求和
* @param tableName 表名
* @param groupColumn 分组字段
* @param sumCloum 统计字段
* @return
*/
@RequestMapping("/sum/group/{tableName}/{groupColumn}/{sumCloum}")
@IgnoreAuth
public R newSelectGroupSum(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn, @PathVariable("sumCloum") String sumCloum) {
logger.debug("newSelectGroupSum:,,Controller:{},,tableName:{},groupColumn:{},sumCloum:{}",this.getClass().getName(),tableName,groupColumn,sumCloum);
Map<String, Object> params = new HashMap<String, Object>();
params.put("tableName", tableName);
params.put("groupColumn", groupColumn);
params.put("sumColumn", sumCloum);
List<Map<String, Object>> result = commonService.newSelectGroupSum(params);
return R.ok().put("data", result);
}
/**
* 查询字典表的分组统计总条数
* @param tableName 表名
* @param groupColumn 分组字段
* @return
*/
@RequestMapping("/count/group/{tableName}/{groupColumn}")
@IgnoreAuth
public R newSelectGroupCount(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn) {
logger.debug("newSelectGroupCount:,,Controller:{},,tableName:{},groupColumn:{}",this.getClass().getName(),tableName,groupColumn);
Map<String, Object> params = new HashMap<String, Object>();
params.put("tableName", tableName);
params.put("groupColumn", groupColumn);
List<Map<String, Object>> result = commonService.newSelectGroupCount(params);
return R.ok().put("data", result);
}
/**
* 当前表的日期分组求和
* @param tableName 表名
* @param groupColumn 分组字段
* @param sumCloum 统计字段
* @param dateFormatType 日期格式化类型 1:年 2:月 3:日
* @return
*/
@RequestMapping("/sum/group/{tableName}/{groupColumn}/{sumCloum}/{dateFormatType}")
@IgnoreAuth
public R newSelectDateGroupSum(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn, @PathVariable("sumCloum") String sumCloum, @PathVariable("dateFormatType") String dateFormatType) {
logger.debug("newSelectDateGroupSum:,,Controller:{},,tableName:{},groupColumn:{},sumCloum:{},dateFormatType:{}",this.getClass().getName(),tableName,groupColumn,sumCloum,dateFormatType);
Map<String, Object> params = new HashMap<String, Object>();
params.put("tableName", tableName);
params.put("groupColumn", groupColumn);
params.put("sumColumn", sumCloum);
if("1".equals(dateFormatType)){
params.put("dateFormat", "%Y");
}else if("2".equals(dateFormatType)){
params.put("dateFormat", "%Y-%m");
}else if("3".equals(dateFormatType)){
params.put("dateFormat", "%Y-%m-%d");
}else{
R.error("日期格式化不正确");
}
List<Map<String, Object>> result = commonService.newSelectDateGroupSum(params);
return R.ok().put("data", result);
}
/**
*
* 查询字典表的分组统计总条数
* @param tableName 表名
* @param groupColumn 分组字段
* @param dateFormatType 日期格式化类型 1:年 2:月 3:日
* @return
*/
@RequestMapping("/count/group/{tableName}/{groupColumn}/{dateFormatType}")
@IgnoreAuth
public R newSelectDateGroupCount(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn, @PathVariable("dateFormatType") String dateFormatType) {
logger.debug("newSelectDateGroupCount:,,Controller:{},,tableName:{},groupColumn:{},dateFormatType:{}",this.getClass().getName(),tableName,groupColumn,dateFormatType);
Map<String, Object> params = new HashMap<String, Object>();
params.put("tableName", tableName);
params.put("groupColumn", groupColumn);
if("1".equals(dateFormatType)){
params.put("dateFormat", "%Y");
}else if("2".equals(dateFormatType)){
params.put("dateFormat", "%Y-%m");
}else if("3".equals(dateFormatType)){
params.put("dateFormat", "%Y-%m-%d");
}else{
R.error("日期格式化类型不正确");
}
List<Map<String, Object>> result = commonService.newSelectDateGroupCount(params);
return R.ok().put("data", result);
}
/**
* 字段加数字
* @param tableName 表名
* @param id id
* @param column 字段
* @param number 数量
* @return
*/
@RequestMapping("/plus/{tableName}/{id}/{column}/{number}")
public R plusCloumNumber(@PathVariable("tableName") String tableName, @PathVariable("id") Integer id, @PathVariable("column") String column, @PathVariable("number") String number) {
logger.debug("plusCloumNumber:,,Controller:{},,tableName:{},id:{},column:{},number:{}",this.getClass().getName(),tableName,id,column,number);
Map<String, Object> params = new HashMap<String, Object>();
params.put("tableName", tableName);
params.put("id", id);
params.put("column", column);
params.put("number", number);
int i = commonService.plusCloumNumber(params);
if(i>0){
return R.ok();
}
return R.error("添加失败");
}
/**
* 字段减数字
* @param tableName
* @param id
* @param column
* @param number
* @return
*/
@RequestMapping("/reduce/{tableName}/{id}/{column}/{number}")
public R reduceCloumNumber(@PathVariable("tableName") String tableName, @PathVariable("id") Integer id, @PathVariable("column") String column, @PathVariable("number") String number) {
logger.debug("reduceCloumNumber:,,Controller:{},,tableName:{},id:{},column:{},number:{}",this.getClass().getName(),tableName,id,column,number);
Map<String, Object> params = new HashMap<String, Object>();
params.put("tableName", tableName);
params.put("id", id);
params.put("column", column);
params.put("number", number);
int i = commonService.reduceCloumNumber(params);
if(i>0){
return R.ok();
}
return R.error("添加失败");
}
@RequestMapping("/update/{tableName}/{id}/{column}/{value}")
public R updateCloumValue(@PathVariable("tableName") String tableName, @PathVariable("id") Integer id, @PathVariable("column") String column, @PathVariable("value") String value) {
logger.debug("updateCloumValue:,,Controller:{},,tableName:{},id:{},column:{},number:{}",this.getClass().getName(),tableName,id,column,value);
Map<String, Object> params = new HashMap<String, Object>();
params.put("tableName", tableName);
params.put("id", id);
params.put("column", column);
params.put("value", value);
int i = commonService.updateCloumValue(params);
if(i>0){
return R.ok();
}
return R.error("添加失败");
}
//李东鹏
/**
* 饼状图
* -- 饼状图 查询当前表
-- 查询字典表【月】
-- 统计 -- 查询某个月的每个类型的订单销售数量
-- 求和 -- 查询某个月的每个类型的订单销售额
-- 查询某个字符串【月】
-- 统计 -- 查询某个月的每个员工的订单销售数量
-- 求和 -- 查询某个月的每个员工的订单销售额
-- 查询时间【年】
-- 统计 -- 查询每个月的订单销售数量
-- 求和 -- 查询每个月的订单销售额
-- 饼状图 查询级联表
-- 查询字典表
-- 统计 -- 查询某个月的每个类型的订单销售数量
-- 求和 -- 查询某个月的每个类型的订单销售额
-- 查询某个字符串
-- 统计 -- 查询某个月的每个员工的订单销售数量
-- 求和 -- 查询某个月的每个员工的订单销售额
-- 查询时间
-- 统计 -- 统计每个月的订单销售数量
-- 求和 -- 查询每个月的订单销售额
*/
/**
* 柱状图
-- 柱状图 查询当前表
-- 某个【年,月】
-- 当前表 2 级联表 1
-- 统计
-- 【日期,字符串,下拉框】
-- 求和
-- 【日期,字符串,下拉框】
-- 柱状图 查询级联表
-- 某个【年,月】
-- 统计
-- 【日期,字符串,下拉框】
-- 求和
-- 【日期,字符串,下拉框】
*/
/**
* 柱状图求和
*/
@RequestMapping("/barSum")
public R barSum(@RequestParam Map<String,Object> params) {
logger.debug("CommonController方法:,,Controller:{},,params:{}",this.getClass().getName(), com.alibaba.fastjson.JSONObject.toJSONString(params));
Boolean isJoinTableFlag = false;//是否有级联表相关
String one = "";//第一优先
String two = "";//第二优先
//处理thisTable和joinTable 处理内容是把json字符串转为Map并把带有,的切割为数组
//当前表
Map<String,Object> thisTable = JSON.parseObject(String.valueOf(params.get("thisTable")),Map.class);
params.put("thisTable",thisTable);
//级联表
String joinTableString = String.valueOf(params.get("joinTable"));
if(StringUtil.isNotEmpty(joinTableString)) {
Map<String, Object> joinTable = JSON.parseObject(joinTableString, Map.class);
params.put("joinTable", joinTable);
isJoinTableFlag = true;
}
if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("date")))){//当前表日期
thisTable.put("date",String.valueOf(thisTable.get("date")).split(","));
one = "thisDate0";
}
if(isJoinTableFlag){//级联表日期
Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("date")))){
joinTable.put("date",String.valueOf(joinTable.get("date")).split(","));
if(StringUtil.isEmpty(one)){
one ="joinDate0";
}else{
if(StringUtil.isEmpty(two)){
two ="joinDate0";
}
}
}
}
if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("string")))){//当前表字符串
thisTable.put("string",String.valueOf(thisTable.get("string")).split(","));
if(StringUtil.isEmpty(one)){
one ="thisString0";
}else{
if(StringUtil.isEmpty(two)){
two ="thisString0";
}
}
}
if(isJoinTableFlag){//级联表字符串
Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("string")))){
joinTable.put("string",String.valueOf(joinTable.get("string")).split(","));
if(StringUtil.isEmpty(one)){
one ="joinString0";
}else{
if(StringUtil.isEmpty(two)){
two ="joinString0";
}
}
}
}
if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("types")))){//当前表类型
thisTable.put("types",String.valueOf(thisTable.get("types")).split(","));
if(StringUtil.isEmpty(one)){
one ="thisTypes0";
}else{
if(StringUtil.isEmpty(two)){
two ="thisTypes0";
}
}
}
if(isJoinTableFlag){//级联表类型
Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("types")))){
joinTable.put("types",String.valueOf(joinTable.get("types")).split(","));
if(StringUtil.isEmpty(one)){
one ="joinTypes0";
}else{
if(StringUtil.isEmpty(two)){
two ="joinTypes0";
}
}
}
}
List<Map<String, Object>> result = commonService.barSum(params);
List<String> xAxis = new ArrayList<>();//报表x轴
List<List<String>> yAxis = new ArrayList<>();//y轴
List<String> legend = new ArrayList<>();//标题
if(StringUtil.isEmpty(two)){//不包含第二列
List<String> yAxis0 = new ArrayList<>();
yAxis.add(yAxis0);
legend.add("数值");
for(Map<String, Object> map :result){
String oneValue = String.valueOf(map.get(one));
String value = String.valueOf(map.get("value"));
xAxis.add(oneValue);
yAxis0.add(value);
}
}else{//包含第二列
List<String> yAxis0 = new ArrayList<>();
List<String> yAxis1 = new ArrayList<>();
yAxis.add(yAxis0);
yAxis.add(yAxis1);
Map<String, HashMap<String, String>> dataMap = new LinkedHashMap<>();
if(StringUtil.isNotEmpty(two)){
for(Map<String, Object> map :result){
String oneValue = String.valueOf(map.get(one));
String twoValue = String.valueOf(map.get(two));
String value = String.valueOf(map.get("value"));
if(!legend.contains(twoValue)){
legend.add(twoValue);//添加完成后 就是最全的第二列的类型
}
if(dataMap.containsKey(oneValue)){
dataMap.get(oneValue).put(twoValue,value);
}else{
HashMap<String, String> oneData = new HashMap<>();
oneData.put(twoValue,value);
dataMap.put(oneValue,oneData);
}
}
}
Set<String> keys = dataMap.keySet();
for(String key:keys){
xAxis.add(key);
HashMap<String, String> map = dataMap.get(key);
for(int i =0; i<legend.size(); i++){
List<String> data = yAxis.get(i);
if(StringUtil.isNotEmpty(map.get(legend.get(i)))){
data.add(map.get(legend.get(i)));
}else{
data.add("0");
}
}
}
System.out.println();
}
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("xAxis",xAxis);
resultMap.put("yAxis",yAxis);
resultMap.put("legend",legend);
return R.ok().put("data", resultMap);
}
/**
* 柱状图统计
*/
@RequestMapping("/barCount")
public R barCount(@RequestParam Map<String,Object> params) {
logger.debug("barCount方法:,,Controller:{},,params:{}",this.getClass().getName(), com.alibaba.fastjson.JSONObject.toJSONString(params));
Boolean isJoinTableFlag = false;//是否有级联表相关
String one = "";//第一优先
String two = "";//第二优先
//处理thisTable和joinTable 处理内容是把json字符串转为Map并把带有,的切割为数组
//当前表
Map<String,Object> thisTable = JSON.parseObject(String.valueOf(params.get("thisTable")),Map.class);
params.put("thisTable",thisTable);
//级联表
String joinTableString = String.valueOf(params.get("joinTable"));
if(StringUtil.isNotEmpty(joinTableString)) {
Map<String, Object> joinTable = JSON.parseObject(joinTableString, Map.class);
params.put("joinTable", joinTable);
isJoinTableFlag = true;
}
if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("date")))){//当前表日期
thisTable.put("date",String.valueOf(thisTable.get("date")).split(","));
one = "thisDate0";
}
if(isJoinTableFlag){//级联表日期
Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("date")))){
joinTable.put("date",String.valueOf(joinTable.get("date")).split(","));
if(StringUtil.isEmpty(one)){
one ="joinDate0";
}else{
if(StringUtil.isEmpty(two)){
two ="joinDate0";
}
}
}
}
if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("string")))){//当前表字符串
thisTable.put("string",String.valueOf(thisTable.get("string")).split(","));
if(StringUtil.isEmpty(one)){
one ="thisString0";
}else{
if(StringUtil.isEmpty(two)){
two ="thisString0";
}
}
}
if(isJoinTableFlag){//级联表字符串
Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("string")))){
joinTable.put("string",String.valueOf(joinTable.get("string")).split(","));
if(StringUtil.isEmpty(one)){
one ="joinString0";
}else{
if(StringUtil.isEmpty(two)){
two ="joinString0";
}
}
}
}
if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("types")))){//当前表类型
thisTable.put("types",String.valueOf(thisTable.get("types")).split(","));
if(StringUtil.isEmpty(one)){
one ="thisTypes0";
}else{
if(StringUtil.isEmpty(two)){
two ="thisTypes0";
}
}
}
if(isJoinTableFlag){//级联表类型
Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("types")))){
joinTable.put("types",String.valueOf(joinTable.get("types")).split(","));
if(StringUtil.isEmpty(one)){
one ="joinTypes0";
}else{
if(StringUtil.isEmpty(two)){
two ="joinTypes0";
}
}
}
}
List<Map<String, Object>> result = commonService.barCount(params);
List<String> xAxis = new ArrayList<>();//报表x轴
List<List<String>> yAxis = new ArrayList<>();//y轴
List<String> legend = new ArrayList<>();//标题
if(StringUtil.isEmpty(two)){//不包含第二列
List<String> yAxis0 = new ArrayList<>();
yAxis.add(yAxis0);
legend.add("数值");
for(Map<String, Object> map :result){
String oneValue = String.valueOf(map.get(one));
String value = String.valueOf(map.get("value"));
xAxis.add(oneValue);
yAxis0.add(value);
}
}else{//包含第二列
Map<String, HashMap<String, String>> dataMap = new LinkedHashMap<>();
if(StringUtil.isNotEmpty(two)){
for(Map<String, Object> map :result){
String oneValue = String.valueOf(map.get(one));
String twoValue = String.valueOf(map.get(two));
String value = String.valueOf(map.get("value"));
if(!legend.contains(twoValue)){
legend.add(twoValue);//添加完成后 就是最全的第二列的类型
}
if(dataMap.containsKey(oneValue)){
dataMap.get(oneValue).put(twoValue,value);
}else{
HashMap<String, String> oneData = new HashMap<>();
oneData.put(twoValue,value);
dataMap.put(oneValue,oneData);
}
}
}
for(int i =0; i<legend.size(); i++){
yAxis.add(new ArrayList<String>());
}
Set<String> keys = dataMap.keySet();
for(String key:keys){
xAxis.add(key);
HashMap<String, String> map = dataMap.get(key);
for(int i =0; i<legend.size(); i++){
List<String> data = yAxis.get(i);
if(StringUtil.isNotEmpty(map.get(legend.get(i)))){
data.add(map.get(legend.get(i)));
}else{
data.add("0");
}
}
}
System.out.println();
}
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("xAxis",xAxis);
resultMap.put("yAxis",yAxis);
resultMap.put("legend",legend);
return R.ok().put("data", resultMap);
}
}
五,相关作品展示
基于Java开发、Python开发、PHP开发、C#开发等相关语言开发的实战项目
基于Nodejs、Vue等前端技术开发的前端实战项目
基于微信小程序和安卓APP应用开发的相关作品
基于51单片机等嵌入式物联网开发应用
基于各类算法实现的AI智能应用
基于大数据实现的各类数据管理和推荐系统