From 42e51e2755b876b6a7302de1b35c45cf5c318e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=A0=C3=A7=C2=9Acqq?= <你的2870787453@qq.com> Date: Tue, 29 Apr 2025 19:03:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/controller/CommonController.java | 657 +++++++++++++----- 1 file changed, 497 insertions(+), 160 deletions(-) diff --git a/src/main/java/com/controller/CommonController.java b/src/main/java/com/controller/CommonController.java index 9592370..7ad285c 100644 --- a/src/main/java/com/controller/CommonController.java +++ b/src/main/java/com/controller/CommonController.java @@ -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().eq("name", "baidu_ditu_ak")).getValue(); - // 如果查询结果为空,返回错误响应 - if (BAIDU_DITU_AK == null) { + if(BAIDU_DITU_AK==null) { return R.error("请在配置管理中正确配置baidu_ditu_ak"); } } - // 调用百度工具类的方法,根据AK、经度和纬度获取城市信息 Map 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().eq("name", "AppID")).getValue();*/ - // 从配置表中查询名称为"APIKey"的配置项的值 String APIKey = configService.selectOne(new EntityWrapper().eq("name", "APIKey")).getValue(); - // 从配置表中查询名称为"SecretKey"的配置项的值 String SecretKey = configService.selectOne(new EntityWrapper().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 requests = new ArrayList(); - // 将人脸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 params = new HashMap(); - // 将表名添加到参数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 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 params = new HashMap(); - // 将表名添加到参数Map中 params.put("table", tableName); - // 将列名添加到参数Map中 params.put("column", columnName); - // 将列值添加到参数Map中 params.put("columnValue", columnValue); - // 调用通用服务类的方法,根据参数获取单条记录数据 Map 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 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 map) { - // 将表名添加到参数Map中 + @PathVariable("type") String type,@RequestParam Map 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 params) { - // 将表名添加到参数Map中,键为"table1" + public R group1(@PathVariable("tableName") String tableName, @RequestParam Map params) { params.put("table1", tableName); - // 调用通用服务类的方法,进行图表统计并获取结果 List> 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 params = new HashMap(); - // 将表名添加到参数Map中 params.put("table", tableName); - //将列名添加到参数Map中 params.put("column", columnName); - // 调用通用服务类的方法,进行单列求和并获取结果 Map 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 params = new HashMap(); - // 将表名添加到参数Map中 params.put("table", tableName); - // 将列名添加到参数Map中 params.put("column", columnName); - // 调用通用服务类的方法,进行分组统计并获取结果 List> 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 params = new HashMap(); - // 将表名添加到参数Map中 params.put("table", tableName); - // 将x轴列名添加到参数Map中 params.put("xColumn", xColumnName); - //将y轴列名添加到参数Map中 params.put("yColumn", yColumnName); - // 调用通用服务类的 \ No newline at end of file + List> result = commonService.selectValue(params); + return R.ok().put("data", result); + } + + + + + /** + * 查询字典表的分组求和 + * tableName 表名 + * groupColumn 分组字段 + * sumCloum 统计字段 + * @return + */ + @RequestMapping("/newSelectGroupSum") + public R newSelectGroupSum(@RequestParam Map params) { + logger.debug("newSelectGroupSum:,,Controller:{},,params:{}",this.getClass().getName(),params); + List> 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 params) { + logger.debug("queryScore:,,Controller:{},,params:{}",this.getClass().getName(),params); + Map queryScore = commonService.queryScore(params); + return R.ok().put("data", queryScore); + } + + + /** + * 查询字典表的分组统计总条数 + * tableName 表名 + * groupColumn 分组字段 + * @return + */ + @RequestMapping("/newSelectGroupCount") + public R newSelectGroupCount(@RequestParam Map params) { + logger.debug("newSelectGroupCount:,,Controller:{},,params:{}",this.getClass().getName(),params); + List> 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 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> 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 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> result = commonService.newSelectDateGroupCount(params); + return R.ok().put("data", result); + } +/** + * 饼状图 + * -- 饼状图 查询当前表 + -- 查询字典表【月】 + -- 统计 -- 查询某个月的每个类型的订单销售数量 + -- 求和 -- 查询某个月的每个类型的订单销售额 + -- 查询某个字符串【月】 + -- 统计 -- 查询某个月的每个员工的订单销售数量 + -- 求和 -- 查询某个月的每个员工的订单销售额 + -- 查询时间【年】 + -- 统计 -- 查询每个月的订单销售数量 + -- 求和 -- 查询每个月的订单销售额 + -- 饼状图 查询级联表 + -- 查询字典表 + -- 统计 -- 查询某个月的每个类型的订单销售数量 + -- 求和 -- 查询某个月的每个类型的订单销售额 + -- 查询某个字符串 + -- 统计 -- 查询某个月的每个员工的订单销售数量 + -- 求和 -- 查询某个月的每个员工的订单销售额 + -- 查询时间 + -- 统计 -- 统计每个月的订单销售数量 + -- 求和 -- 查询每个月的订单销售额 + */ + + +/** + * 柱状图 + -- 柱状图 查询当前表 + -- 某个【年,月】 + -- 当前表 2 级联表 1 + -- 统计 + -- 【日期,字符串,下拉框】 + -- 求和 + -- 【日期,字符串,下拉框】 + -- 柱状图 查询级联表 + -- 某个【年,月】 + -- 统计 + -- 【日期,字符串,下拉框】 + -- 求和 + -- 【日期,字符串,下拉框】 + */ + + /** + * 柱状图求和 + */ + @RequestMapping("/barSum") + public R barSum(@RequestParam Map 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 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 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 joinTable = (Map) 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 joinTable = (Map) 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 joinTable = (Map) 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> result = commonService.barSum(params); + + List xAxis = new ArrayList<>();//报表x轴 + List> yAxis = new ArrayList<>();//y轴 + List legend = new ArrayList<>();//标题 + + if(StringUtil.isEmpty(two)){//不包含第二列 + List yAxis0 = new ArrayList<>(); + yAxis.add(yAxis0); + legend.add("数值"); + for(Map map :result){ + String oneValue = String.valueOf(map.get(one)); + String value = String.valueOf(map.get("value")); + xAxis.add(oneValue); + yAxis0.add(value); + } + }else{//包含第二列 + Map> dataMap = new LinkedHashMap<>(); + if(StringUtil.isNotEmpty(two)){ + for(Map 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 oneData = new HashMap<>(); + oneData.put(twoValue,value); + dataMap.put(oneValue,oneData); + } + + } + } + + for(int i =0; i()); + } + + Set keys = dataMap.keySet(); + for(String key:keys){ + xAxis.add(key); + HashMap map = dataMap.get(key); + for(int i =0; i 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 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 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 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 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 joinTable = (Map) 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 joinTable = (Map) 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 joinTable = (Map) 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> result = commonService.barCount(params); + + List xAxis = new ArrayList<>();//报表x轴 + List> yAxis = new ArrayList<>();//y轴 + List legend = new ArrayList<>();//标题 + + if(StringUtil.isEmpty(two)){//不包含第二列 + List yAxis0 = new ArrayList<>(); + yAxis.add(yAxis0); + legend.add("数值"); + for(Map map :result){ + String oneValue = String.valueOf(map.get(one)); + String value = String.valueOf(map.get("value")); + xAxis.add(oneValue); + yAxis0.add(value); + } + }else{//包含第二列 + Map> dataMap = new LinkedHashMap<>(); + if(StringUtil.isNotEmpty(two)){ + for(Map 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 oneData = new HashMap<>(); + oneData.put(twoValue,value); + dataMap.put(oneValue,oneData); + } + + } + } + + for(int i =0; i()); + } + + Set keys = dataMap.keySet(); + for(String key:keys){ + xAxis.add(key); + HashMap map = dataMap.get(key); + for(int i =0; i 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 resultMap = new HashMap<>(); + resultMap.put("xAxis",xAxis); + resultMap.put("yAxis",yAxis); + resultMap.put("legend",legend); + return R.ok().put("data", resultMap); + } +}