|
|
|
@ -1,364 +1,701 @@
|
|
|
|
|
package com.controller;
|
|
|
|
|
|
|
|
|
|
// 导入处理文件操作的类
|
|
|
|
|
import java.io.File;
|
|
|
|
|
// 导入文件未找到异常类
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
// 导入输入输出异常类
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
// 导入用于格式化日期的类
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
// 导入常用的集合类
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
// 导入Servlet请求相关类
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
// 导入阿里巴巴的JSON处理类
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
// 导入自定义的字符串工具类
|
|
|
|
|
import com.utils.StringUtil;
|
|
|
|
|
// 导入Apache Commons提供的字符串工具类
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
// 导入JSON对象类
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
// 导入日志记录器接口
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
// 导入日志记录器工厂类
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
// 导入Spring的自动注入注解
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
// 导入Spring用于获取资源的工具类
|
|
|
|
|
import org.springframework.util.ResourceUtils;
|
|
|
|
|
// 导入Spring的路径变量注解
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
// 导入Spring的请求体注解
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
// 导入Spring的请求映射注解
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
// 导入Spring的请求参数注解
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
// 导入Spring的RESTful控制器注解
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
// 导入自定义的忽略权限注解类
|
|
|
|
|
import com.annotation.IgnoreAuth;
|
|
|
|
|
// 导入百度AI开放平台的人脸识别客户端类
|
|
|
|
|
import com.baidu.aip.face.AipFace;
|
|
|
|
|
// 导入百度AI开放平台的人脸比对请求类
|
|
|
|
|
import com.baidu.aip.face.MatchRequest;
|
|
|
|
|
// 导入百度AI开放平台的Base64编码工具类
|
|
|
|
|
import com.baidu.aip.util.Base64Util;
|
|
|
|
|
// 导入MyBatis-Plus的实体包装器类
|
|
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
|
|
// 导入MyBatis-Plus的查询包装器接口
|
|
|
|
|
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 {
|
|
|
|
|
// 日志记录器,用于记录当前控制器类的日志信息
|
|
|
|
|
public class CommonController{
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
|
|
|
|
|
// 自动注入通用服务类,用于处理通用业务逻辑
|
|
|
|
|
@Autowired
|
|
|
|
|
private CommonService commonService;
|
|
|
|
|
|
|
|
|
|
// 自动注入配置服务类,用于处理配置相关业务逻辑
|
|
|
|
|
@Autowired
|
|
|
|
|
private ConfigService configService;
|
|
|
|
|
|
|
|
|
|
// 静态变量,存储百度人脸识别客户端实例,初始化为null
|
|
|
|
|
private static AipFace client = null;
|
|
|
|
|
|
|
|
|
|
// 静态变量,存储百度地图API的AK(应用密钥),初始化为null
|
|
|
|
|
private static String BAIDU_DITU_AK = null;
|
|
|
|
|
|
|
|
|
|
// 处理获取位置信息的请求,根据经纬度获取城市信息
|
|
|
|
|
@RequestMapping("/location")
|
|
|
|
|
public R location(String lng, String lat) {
|
|
|
|
|
// 如果BAIDU_DITU_AK尚未初始化
|
|
|
|
|
if (BAIDU_DITU_AK == null) {
|
|
|
|
|
// 从配置表中查询名称为"baidu_ditu_ak"的配置项的值
|
|
|
|
|
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) {
|
|
|
|
|
if(BAIDU_DITU_AK==null) {
|
|
|
|
|
return R.error("请在配置管理中正确配置baidu_ditu_ak");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 调用百度工具类的方法,根据AK、经度和纬度获取城市信息
|
|
|
|
|
Map<String, String> map = BaiduUtil.getCityByLonLat(BAIDU_DITU_AK, lng, lat);
|
|
|
|
|
// 返回成功响应,并将获取到的城市信息封装在"data"属性中
|
|
|
|
|
return R.ok().put("data", map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 人脸比对
|
|
|
|
|
* @param face1 人脸1的相关信息(可能是文件名等)
|
|
|
|
|
* @param face2 人脸2的相关信息(可能是文件名等)
|
|
|
|
|
* @return 响应结果对象,包含比对结果数据
|
|
|
|
|
* @param face1 人脸1
|
|
|
|
|
* @param face2 人脸2
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/matchFace")
|
|
|
|
|
public R matchFace(String face1, String face2, HttpServletRequest request) {
|
|
|
|
|
// 如果百度人脸识别客户端尚未初始化
|
|
|
|
|
if (client == null) {
|
|
|
|
|
if(client==null) {
|
|
|
|
|
/*String AppID = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "AppID")).getValue();*/
|
|
|
|
|
// 从配置表中查询名称为"APIKey"的配置项的值
|
|
|
|
|
String APIKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "APIKey")).getValue();
|
|
|
|
|
// 从配置表中查询名称为"SecretKey"的配置项的值
|
|
|
|
|
String SecretKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "SecretKey")).getValue();
|
|
|
|
|
// 使用APIKey和SecretKey获取访问令牌
|
|
|
|
|
String token = BaiduUtil.getAuth(APIKey, SecretKey);
|
|
|
|
|
// 如果获取令牌失败,返回错误响应
|
|
|
|
|
if (token == null) {
|
|
|
|
|
if(token==null) {
|
|
|
|
|
return R.error("请在配置管理中正确配置APIKey和SecretKey");
|
|
|
|
|
}
|
|
|
|
|
// 初始化百度人脸识别客户端
|
|
|
|
|
client = new AipFace(null, APIKey, SecretKey);
|
|
|
|
|
// 设置连接超时时间为2000毫秒
|
|
|
|
|
client.setConnectionTimeoutInMillis(2000);
|
|
|
|
|
// 设置套接字超时时间为60000毫秒
|
|
|
|
|
client.setSocketTimeoutInMillis(60000);
|
|
|
|
|
}
|
|
|
|
|
// 用于存储人脸比对结果的JSONObject对象,初始化为null
|
|
|
|
|
JSONObject res = null;
|
|
|
|
|
try {
|
|
|
|
|
// 根据请求中的face1信息,构建人脸1的文件对象
|
|
|
|
|
File file1 = new File(request.getSession().getServletContext().getRealPath("/upload") + "/" + face1);
|
|
|
|
|
// 根据请求中的face2信息,构建人脸2的文件对象
|
|
|
|
|
File file2 = new File(request.getSession().getServletContext().getRealPath("/upload") + "/" + face2);
|
|
|
|
|
// 将人脸1的文件内容转换为Base64编码的字符串
|
|
|
|
|
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));
|
|
|
|
|
// 将人脸2的文件内容转换为Base64编码的字符串
|
|
|
|
|
String img2 = Base64Util.encode(FileUtil.FileToByte(file2));
|
|
|
|
|
// 创建人脸1的比对请求对象
|
|
|
|
|
MatchRequest req1 = new MatchRequest(img1, "BASE64");
|
|
|
|
|
// 创建人脸2的比对请求对象
|
|
|
|
|
MatchRequest req2 = new MatchRequest(img2, "BASE64");
|
|
|
|
|
// 创建存储比对请求的ArrayList
|
|
|
|
|
ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
|
|
|
|
|
// 将人脸1的请求添加到请求列表中
|
|
|
|
|
requests.add(req1);
|
|
|
|
|
// 将人脸2的请求添加到请求列表中
|
|
|
|
|
requests.add(req2);
|
|
|
|
|
// 调用百度人脸识别客户端的match方法进行人脸比对,并获取结果
|
|
|
|
|
res = client.match(requests);
|
|
|
|
|
// 打印比对结果中的"result"部分(可能是比对的详细信息)
|
|
|
|
|
System.out.println(res.get("result"));
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
// 捕获文件未找到异常,打印异常堆栈信息
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
// 返回错误响应,提示文件不存在
|
|
|
|
|
return R.error("文件不存在");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// 捕获输入输出异常,打印异常堆栈信息
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
// 将比对结果中的"result"部分解析为JSON对象,并封装在响应结果中返回
|
|
|
|
|
return R.ok().put("data", com.alibaba.fastjson.JSONObject.parse(res.get("result").toString()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取table表中的column列表(联动接口)
|
|
|
|
|
* @return 响应结果对象,包含获取到的列数据列表
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/option/{tableName}/{columnName}")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证的注解
|
|
|
|
|
public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, String level, String parent) {
|
|
|
|
|
// 创建用于存储请求参数的Map对象
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,String level,String parent) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
// 将表名添加到参数Map中
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
// 将列名添加到参数Map中
|
|
|
|
|
params.put("column", columnName);
|
|
|
|
|
// 如果level参数不为空,将其添加到参数Map中
|
|
|
|
|
if (StringUtils.isNotBlank(level)) {
|
|
|
|
|
if(StringUtils.isNotBlank(level)) {
|
|
|
|
|
params.put("level", level);
|
|
|
|
|
}
|
|
|
|
|
// 如果parent参数不为空,将其添加到参数Map中
|
|
|
|
|
if (StringUtils.isNotBlank(parent)) {
|
|
|
|
|
if(StringUtils.isNotBlank(parent)) {
|
|
|
|
|
params.put("parent", parent);
|
|
|
|
|
}
|
|
|
|
|
// 调用通用服务类的方法,根据参数获取列数据列表
|
|
|
|
|
List<String> data = commonService.getOption(params);
|
|
|
|
|
// 返回成功响应,并将获取到的列数据列表封装在"data"属性中
|
|
|
|
|
return R.ok().put("data", data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据table中的column获取单条记录
|
|
|
|
|
* @return 响应结果对象,包含获取到的单条记录数据
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/follow/{tableName}/{columnName}")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证的注解
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) {
|
|
|
|
|
// 创建用于存储请求参数的Map对象
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
// 将表名添加到参数Map中
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
// 将列名添加到参数Map中
|
|
|
|
|
params.put("column", columnName);
|
|
|
|
|
// 将列值添加到参数Map中
|
|
|
|
|
params.put("columnValue", columnValue);
|
|
|
|
|
// 调用通用服务类的方法,根据参数获取单条记录数据
|
|
|
|
|
Map<String, Object> result = commonService.getFollowByOption(params);
|
|
|
|
|
// 返回成功响应,并将获取到的单条记录数据封装在"data"属性中
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改table表的sfsh状态
|
|
|
|
|
* @param map 包含表名和其他相关参数的Map对象
|
|
|
|
|
* @return 响应结果对象,表示操作是否成功
|
|
|
|
|
* @param map
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/sh/{tableName}")
|
|
|
|
|
public R sh(@PathVariable("tableName") String tableName, @RequestBody Map<String, Object> map) {
|
|
|
|
|
// 将表名添加到参数Map中
|
|
|
|
|
map.put("table", tableName);
|
|
|
|
|
// 调用通用服务类的方法,执行修改sfsh状态的操作
|
|
|
|
|
commonService.sh(map);
|
|
|
|
|
// 返回成功响应
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取需要提醒的记录数
|
|
|
|
|
* @param tableName 表名
|
|
|
|
|
* @param columnName 列名
|
|
|
|
|
* @param type 类型(1:数字 2:日期)
|
|
|
|
|
* @param map 包含其他相关参数的Map对象
|
|
|
|
|
* @return 响应结果对象,包含需要提醒的记录数
|
|
|
|
|
* @param tableName
|
|
|
|
|
* @param columnName
|
|
|
|
|
* @param type 1:数字 2:日期
|
|
|
|
|
* @param map
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/remind/{tableName}/{columnName}/{type}")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证的注解
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
|
|
|
|
|
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
|
|
|
|
|
// 将表名添加到参数Map中
|
|
|
|
|
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
|
|
|
|
|
map.put("table", tableName);
|
|
|
|
|
// 将列名添加到参数Map中
|
|
|
|
|
map.put("column", columnName);
|
|
|
|
|
// 将类型添加到参数Map中
|
|
|
|
|
map.put("type", type);
|
|
|
|
|
|
|
|
|
|
// 如果类型为日期("2")
|
|
|
|
|
if (type.equals("2")) {
|
|
|
|
|
// 创建日期格式化对象,格式为"yyyy-MM-dd"
|
|
|
|
|
if(type.equals("2")) {
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
// 获取日历实例
|
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
|
// 用于存储提醒开始日期,初始化为null
|
|
|
|
|
Date remindStartDate = null;
|
|
|
|
|
// 用于存储提醒结束日期,初始化为null
|
|
|
|
|
Date remindEndDate = null;
|
|
|
|
|
// 如果参数Map中包含"remindstart"(提醒开始时间间隔)
|
|
|
|
|
if (map.get("remindstart") != null) {
|
|
|
|
|
// 将"remindstart"转换为整数
|
|
|
|
|
if(map.get("remindstart")!=null) {
|
|
|
|
|
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
|
|
|
|
|
// 设置日历时间为当前日期
|
|
|
|
|
c.setTime(new Date());
|
|
|
|
|
// 根据提醒开始时间间隔,计算提醒开始日期
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH, remindStart);
|
|
|
|
|
// 获取计算后的提醒开始日期
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH,remindStart);
|
|
|
|
|
remindStartDate = c.getTime();
|
|
|
|
|
// 将提醒开始日期格式化为字符串,并更新参数Map中的"remindstart"值
|
|
|
|
|
map.put("remindstart", sdf.format(remindStartDate));
|
|
|
|
|
}
|
|
|
|
|
// 如果参数Map中包含"remindend"(提醒结束时间间隔)
|
|
|
|
|
if (map.get("remindend") != null) {
|
|
|
|
|
// 将"remindend"转换为整数
|
|
|
|
|
if(map.get("remindend")!=null) {
|
|
|
|
|
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
|
|
|
|
|
// 设置日历时间为当前日期
|
|
|
|
|
c.setTime(new Date());
|
|
|
|
|
// 根据提醒结束时间间隔,计算提醒结束日期
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH, remindEnd);
|
|
|
|
|
// 获取计算后的提醒结束日期
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH,remindEnd);
|
|
|
|
|
remindEndDate = c.getTime();
|
|
|
|
|
// 将提醒结束日期格式化为字符串,并更新参数Map中的"remindend"值
|
|
|
|
|
map.put("remindend", sdf.format(remindEndDate));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 调用通用服务类的方法,根据参数获取需要提醒的记录数
|
|
|
|
|
int count = commonService.remindCount(map);
|
|
|
|
|
// 返回成功响应,并将记录数封装在"count"属性中
|
|
|
|
|
return R.ok().put("count", count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 图表统计
|
|
|
|
|
* 圖表统计
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth // 忽略权限验证的注解
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/group/{tableName}")
|
|
|
|
|
public R group1(@PathVariable("tableName") String tableName, @RequestParam Map<String, Object> params) {
|
|
|
|
|
// 将表名添加到参数Map中,键为"table1"
|
|
|
|
|
public R group1(@PathVariable("tableName") String tableName, @RequestParam Map<String,Object> params) {
|
|
|
|
|
params.put("table1", tableName);
|
|
|
|
|
// 调用通用服务类的方法,进行图表统计并获取结果
|
|
|
|
|
List<Map<String, Object>> result = commonService.chartBoth(params);
|
|
|
|
|
// 返回成功响应,并将统计结果封装在"data"属性中
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 单列求和
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/cal/{tableName}/{columnName}")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证的注解
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
|
|
|
|
|
// 创建用于存储请求参数的Map对象
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
// 将表名添加到参数Map中
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
//将列名添加到参数Map中
|
|
|
|
|
params.put("column", columnName);
|
|
|
|
|
// 调用通用服务类的方法,进行单列求和并获取结果
|
|
|
|
|
Map<String, Object> result = commonService.selectCal(params);
|
|
|
|
|
// 返回成功响应,并将求和结果封装在"data"属性中
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分组统计
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/group/{tableName}/{columnName}")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证的注解
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
|
|
|
|
|
// 创建用于存储请求参数的Map对象
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
// 将表名添加到参数Map中
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
// 将列名添加到参数Map中
|
|
|
|
|
params.put("column", columnName);
|
|
|
|
|
// 调用通用服务类的方法,进行分组统计并获取结果
|
|
|
|
|
List<Map<String, Object>> result = commonService.selectGroup(params);
|
|
|
|
|
// 返回成功响应,并将统计结果封装在"data"属性中
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* (按值统计)
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证的注解
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) {
|
|
|
|
|
// 创建用于存储请求参数的Map对象
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
// 将表名添加到参数Map中
|
|
|
|
|
params.put("table", tableName);
|
|
|
|
|
// 将x轴列名添加到参数Map中
|
|
|
|
|
params.put("xColumn", xColumnName);
|
|
|
|
|
//将y轴列名添加到参数Map中
|
|
|
|
|
params.put("yColumn", yColumnName);
|
|
|
|
|
// 调用通用服务类的
|
|
|
|
|
List<Map<String, Object>> result = commonService.selectValue(params);
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询字典表的分组求和
|
|
|
|
|
* tableName 表名
|
|
|
|
|
* groupColumn 分组字段
|
|
|
|
|
* sumCloum 统计字段
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/newSelectGroupSum")
|
|
|
|
|
public R newSelectGroupSum(@RequestParam Map<String,Object> params) {
|
|
|
|
|
logger.debug("newSelectGroupSum:,,Controller:{},,params:{}",this.getClass().getName(),params);
|
|
|
|
|
List<Map<String, Object>> result = commonService.newSelectGroupSum(params);
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
tableName 查询表
|
|
|
|
|
condition1 条件1
|
|
|
|
|
condition1Value 条件1值
|
|
|
|
|
average 计算平均评分
|
|
|
|
|
取值
|
|
|
|
|
有值 Number(res.data.value.toFixed(1))
|
|
|
|
|
无值 if(res.data){}
|
|
|
|
|
* */
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/queryScore")
|
|
|
|
|
public R queryScore(@RequestParam Map<String, Object> params) {
|
|
|
|
|
logger.debug("queryScore:,,Controller:{},,params:{}",this.getClass().getName(),params);
|
|
|
|
|
Map<String, Object> queryScore = commonService.queryScore(params);
|
|
|
|
|
return R.ok().put("data", queryScore);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询字典表的分组统计总条数
|
|
|
|
|
* tableName 表名
|
|
|
|
|
* groupColumn 分组字段
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/newSelectGroupCount")
|
|
|
|
|
public R newSelectGroupCount(@RequestParam Map<String,Object> params) {
|
|
|
|
|
logger.debug("newSelectGroupCount:,,Controller:{},,params:{}",this.getClass().getName(),params);
|
|
|
|
|
List<Map<String, Object>> result = commonService.newSelectGroupCount(params);
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当前表的日期分组求和
|
|
|
|
|
* tableName 表名
|
|
|
|
|
* groupColumn 分组字段
|
|
|
|
|
* sumCloum 统计字段
|
|
|
|
|
* dateFormatType 日期格式化类型 1:年 2:月 3:日
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/newSelectDateGroupSum")
|
|
|
|
|
public R newSelectDateGroupSum(@RequestParam Map<String,Object> params) {
|
|
|
|
|
logger.debug("newSelectDateGroupSum:,,Controller:{},,params:{}",this.getClass().getName(),params);
|
|
|
|
|
String dateFormatType = String.valueOf(params.get("dateFormatType"));
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 1查询字典表的分组统计总条数
|
|
|
|
|
* tableName 表名
|
|
|
|
|
* groupColumn 分组字段
|
|
|
|
|
* dateFormatType 日期格式化类型 1:年 2:月 3:日
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/newSelectDateGroupCount")
|
|
|
|
|
public R newSelectDateGroupCount(@RequestParam Map<String,Object> params) {
|
|
|
|
|
logger.debug("newSelectDateGroupCount:,,Controller:{},,params:{}",this.getClass().getName(),params);
|
|
|
|
|
String dateFormatType = String.valueOf(params.get("dateFormatType"));
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 饼状图
|
|
|
|
|
* -- 饼状图 查询当前表
|
|
|
|
|
-- 查询字典表【月】
|
|
|
|
|
-- 统计 -- 查询某个月的每个类型的订单销售数量
|
|
|
|
|
-- 求和 -- 查询某个月的每个类型的订单销售额
|
|
|
|
|
-- 查询某个字符串【月】
|
|
|
|
|
-- 统计 -- 查询某个月的每个员工的订单销售数量
|
|
|
|
|
-- 求和 -- 查询某个月的每个员工的订单销售额
|
|
|
|
|
-- 查询时间【年】
|
|
|
|
|
-- 统计 -- 查询每个月的订单销售数量
|
|
|
|
|
-- 求和 -- 查询每个月的订单销售额
|
|
|
|
|
-- 饼状图 查询级联表
|
|
|
|
|
-- 查询字典表
|
|
|
|
|
-- 统计 -- 查询某个月的每个类型的订单销售数量
|
|
|
|
|
-- 求和 -- 查询某个月的每个类型的订单销售额
|
|
|
|
|
-- 查询某个字符串
|
|
|
|
|
-- 统计 -- 查询某个月的每个员工的订单销售数量
|
|
|
|
|
-- 求和 -- 查询某个月的每个员工的订单销售额
|
|
|
|
|
-- 查询时间
|
|
|
|
|
-- 统计 -- 统计每个月的订单销售数量
|
|
|
|
|
-- 求和 -- 查询每个月的订单销售额
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 柱状图
|
|
|
|
|
-- 柱状图 查询当前表
|
|
|
|
|
-- 某个【年,月】
|
|
|
|
|
-- 当前表 2 级联表 1
|
|
|
|
|
-- 统计
|
|
|
|
|
-- 【日期,字符串,下拉框】
|
|
|
|
|
-- 求和
|
|
|
|
|
-- 【日期,字符串,下拉框】
|
|
|
|
|
-- 柱状图 查询级联表
|
|
|
|
|
-- 某个【年,月】
|
|
|
|
|
-- 统计
|
|
|
|
|
-- 【日期,字符串,下拉框】
|
|
|
|
|
-- 求和
|
|
|
|
|
-- 【日期,字符串,下拉框】
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 柱状图求和
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/barSum")
|
|
|
|
|
public R barSum(@RequestParam Map<String,Object> params) {
|
|
|
|
|
logger.debug("barSum方法:,,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{//包含第二列
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 柱状图统计
|
|
|
|
|
*/
|
|
|
|
|
@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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|