From 3ec17c725657641c94ed5b5b71d4e8337fa24e98 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 18:56:01 +0800 Subject: [PATCH 1/2] =?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/ChatController.java | 165 +++++++++--------- .../java/com/controller/CommonController.java | 2 +- .../java/com/controller/UsersController.java | 4 +- 3 files changed, 88 insertions(+), 83 deletions(-) diff --git a/src/main/java/com/controller/ChatController.java b/src/main/java/com/controller/ChatController.java index 4de29d2..72929cd 100644 --- a/src/main/java/com/controller/ChatController.java +++ b/src/main/java/com/controller/ChatController.java @@ -1,5 +1,4 @@ - -ppackage com.controller; +package com.controller; import java.io.File; import java.math.BigDecimal; @@ -70,36 +69,37 @@ public class ChatController { /** * 后端列表 * 处理获取在线咨询后端列表数据的请求 - * @param params 包含请求参数的 Map,如分页参数、排序参数等 + * + * @param params 包含请求参数的 Map,如分页参数、排序参数等 * @param request HttpServletRequest 对象,包含请求的相关信息 * @return R 类型的响应对象,封装了请求处理的结果 */ @RequestMapping("/page") - public R page(@RequestParam Map params, HttpServletRequest request){ + public R page(@RequestParam Map params, HttpServletRequest request) { // 记录调试日志,输出方法名、控制器类名和请求参数 - logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + logger.debug("page方法:,,Controller:{},,params:{}", this.getClass().getName(), JSONObject.toJSONString(params)); // 获取当前用户的角色信息 String role = String.valueOf(request.getSession().getAttribute("role")); // 这个条件永远为 false,这里的代码逻辑可能有误,正常不会进入此分支 - if(false) - return R.error(511,"永不会进入"); + if (false) + return R.error(511, "永不会进入"); // 如果用户角色是 "用户",则将用户 ID 添加到请求参数中 - else if("用户".equals(role)) - params.put("yonghuId",request.getSession().getAttribute("userId")); + else if ("用户".equals(role)) + params.put("yonghuId", request.getSession().getAttribute("userId")); // 如果用户角色是 "医生",则将医生 ID 添加到请求参数中 - else if("医生".equals(role)) - params.put("yishengId",request.getSession().getAttribute("userId")); + else if ("医生".equals(role)) + params.put("yishengId", request.getSession().getAttribute("userId")); // 如果请求参数中没有指定排序字段,则默认按 id 排序 - if(params.get("orderBy")==null || params.get("orderBy")==""){ - params.put("orderBy","id"); + if (params.get("orderBy") == null || params.get("orderBy") == "") { + params.put("orderBy", "id"); } // 调用 ChatService 的 queryPage 方法获取分页数据 PageUtils page = chatService.queryPage(params); // 将分页数据中的列表转换为 ChatView 类型的列表 - List list =(List)page.getList(); + List list = (List) page.getList(); // 遍历列表,对每个 ChatView 对象进行字典表数据转换 - for(ChatView c:list){ + for (ChatView c : list) { dictionaryService.dictionaryConvert(c, request); } // 返回成功响应,并将分页数据封装在 data 属性中 @@ -109,28 +109,29 @@ public class ChatController { /** * 后端详情 * 处理获取在线咨询后端详情数据的请求 - * @param id 要查询的在线咨询记录的 ID + * + * @param id 要查询的在线咨询记录的 ID * @param request HttpServletRequest 对象,包含请求的相关信息 * @return R 类型的响应对象,封装了请求处理的结果 */ @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id, HttpServletRequest request){ + public R info(@PathVariable("id") Long id, HttpServletRequest request) { // 记录调试日志,输出方法名、控制器类名和要查询的 ID - logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); + logger.debug("info方法:,,Controller:{},,id:{}", this.getClass().getName(), id); // 根据 ID 查询在线咨询记录 ChatEntity chat = chatService.selectById(id); // 如果查询到记录 - if(chat !=null){ + if (chat != null) { // 将 ChatEntity 转换为 ChatView ChatView view = new ChatView(); // 使用 BeanUtils 将 ChatEntity 的属性复制到 ChatView 中 - BeanUtils.copyProperties( chat , view ); + BeanUtils.copyProperties(chat, view); // 级联查询用户信息 YonghuEntity yonghu = yonghuService.selectById(chat.getYonghuId()); // 如果查询到用户信息 - if(yonghu != null){ + if (yonghu != null) { // 将用户信息的部分属性复制到 ChatView 中,并排除指定字段 - BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"}); + BeanUtils.copyProperties(yonghu, view, new String[]{"id", "createTime", "insertTime", "updateTime"}); // 设置 ChatView 中的用户 ID view.setYonghuId(yonghu.getId()); } @@ -139,9 +140,9 @@ public class ChatController { dictionaryService.dictionaryConvert(view, request); // 返回成功响应,并将处理后的 ChatView 数据封装在 data 属性中 return R.ok().put("data", view); - }else { + } else { // 如果未查询到记录,返回错误响应 - return R.error(511,"查不到数据"); + return R.error(511, "查不到数据"); } } @@ -149,22 +150,23 @@ public class ChatController { /** * 后端保存 * 处理保存在线咨询记录的请求 - * @param chat 要保存的在线咨询实体对象 + * + * @param chat 要保存的在线咨询实体对象 * @param request HttpServletRequest 对象,包含请求的相关信息 * @return R 类型的响应对象,封装了请求处理的结果 */ @RequestMapping("/save") - public R save(@RequestBody ChatEntity chat, HttpServletRequest request){ + public R save(@RequestBody ChatEntity chat, HttpServletRequest request) { // 记录调试日志,输出方法名、控制器类名和要保存的 ChatEntity 对象 - logger.debug("save方法:,,Controller:{},,chat:{}",this.getClass().getName(),chat.toString()); + logger.debug("save方法:,,Controller:{},,chat:{}", this.getClass().getName(), chat.toString()); // 获取当前用户的角色信息 String role = String.valueOf(request.getSession().getAttribute("role")); // 这个条件永远为 false,这里的代码逻辑可能有误,正常不会进入此分支 - if(false) - return R.error(511,"永远不会进入"); + if (false) + return R.error(511, "永远不会进入"); // 如果用户角色是 "用户",则设置在线咨询记录的用户 ID - else if("用户".equals(role)) + else if ("用户".equals(role)) chat.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); // 创建查询条件,检查是否已存在相同数据 @@ -173,38 +175,38 @@ public class ChatController { .eq("chat_issue", chat.getChatIssue()) .eq("chat_reply", chat.getChatReply()) .eq("zhuangtai_types", chat.getZhuangtaiTypes()) - .eq("chat_types", chat.getChatTypes()) - ; + .eq("chat_types", chat.getChatTypes()); // 记录查询条件的 SQL 片段日志 - logger.info("sql语句:"+queryWrapper.getSqlSegment()); + logger.info("sql语句:" + queryWrapper.getSqlSegment()); // 根据查询条件查询是否已存在相同数据 ChatEntity chatEntity = chatService.selectOne(queryWrapper); // 如果不存在相同数据 - if(chatEntity==null){ + if (chatEntity == null) { // 设置插入时间为当前时间 chat.setInsertTime(new Date()); // 插入在线咨询记录 chatService.insert(chat); // 返回成功响应 return R.ok(); - }else { + } else { // 如果存在相同数据,返回错误响应 - return R.error(511,"表中有相同数据"); + return R.error(511, "表中有相同数据"); } } /** * 后端修改 * 处理修改在线咨询记录的请求 - * @param chat 要修改的在线咨询实体对象 + * + * @param chat 要修改的在线咨询实体对象 * @param request HttpServletRequest 对象,包含请求的相关信息 * @return R 类型的响应对象,封装了请求处理的结果 */ @RequestMapping("/update") - public R update(@RequestBody ChatEntity chat, HttpServletRequest request){ + public R update(@RequestBody ChatEntity chat, HttpServletRequest request) { // 记录调试日志,输出方法名、控制器类名和要修改的 ChatEntity 对象 - logger.debug("update方法:,,Controller:{},,chat:{}",this.getClass().getName(),chat.toString()); + logger.debug("update方法:,,Controller:{},,chat:{}", this.getClass().getName(), chat.toString()); // 获取当前用户的角色信息 String role = String.valueOf(request.getSession().getAttribute("role")); @@ -215,41 +217,41 @@ public class ChatController { // 创建查询条件,检查是否已存在相同数据(排除当前要修改的记录) Wrapper queryWrapper = new EntityWrapper() - .notIn("id",chat.getId()) + .notIn("id", chat.getId()) .andNew() .eq("yonghu_id", chat.getYonghuId()) .eq("chat_issue", chat.getChatIssue()) .eq("chat_reply", chat.getChatReply()) .eq("zhuangtai_types", chat.getZhuangtaiTypes()) - .eq("chat_types", chat.getChatTypes()) - ; + .eq("chat_types", chat.getChatTypes()); // 记录查询条件的 SQL 片段日志 - logger.info("sql语句:"+queryWrapper.getSqlSegment()); + logger.info("sql语句:" + queryWrapper.getSqlSegment()); // 根据查询条件查询是否已存在相同数据 ChatEntity chatEntity = chatService.selectOne(queryWrapper); // 如果不存在相同数据 - if(chatEntity==null){ + if (chatEntity == null) { // 根据 ID 更新在线咨询记录 chatService.updateById(chat); // 返回成功响应 return R.ok(); - }else { + } else { // 如果存在相同数据,返回错误响应 - return R.error(511,"表中有相同数据"); + return R.error(511, "表中有相同数据"); } } /** * 删除 * 处理删除在线咨询记录的请求 + * * @param ids 要删除的在线咨询记录的 ID 数组 * @return R 类型的响应对象,封装了请求处理的结果 */ @RequestMapping("/delete") - public R delete(@RequestBody Integer[] ids){ + public R delete(@RequestBody Integer[] ids) { // 记录调试日志,输出方法名、控制器类名和要删除的 ID 数组 - logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); + logger.debug("delete:,,Controller:{},,ids:{}", this.getClass().getName(), ids.toString()); // 批量删除在线咨询记录 chatService.deleteBatchIds(Arrays.asList(ids)); // 返回成功响应 @@ -259,49 +261,50 @@ public class ChatController { /** * 批量上传 * 处理批量插入在线咨询记录的请求,从 Excel 文件中读取数据并插入 + * * @param fileName 上传的 Excel 文件的文件名 * @return R 类型的响应对象,封装了请求处理的结果 */ @RequestMapping("/batchInsert") - public R save( String fileName){ + public R save(String fileName) { // 记录调试日志,输出方法名、控制器类名和文件名 - logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); + logger.debug("batchInsert方法:,,Controller:{},,fileName:{}", this.getClass().getName(), fileName); try { // 创建用于存储上传的在线咨询实体对象的列表 List chatList = new ArrayList<>(); // 创建用于存储要查询的字段的 Map - Map> seachFields= new HashMap<>(); + Map> seachFields = new HashMap<>(); // 获取当前时间 Date date = new Date(); // 获取文件名的后缀位置 int lastIndexOf = fileName.lastIndexOf("."); // 如果没有找到后缀 - if(lastIndexOf == -1){ + if (lastIndexOf == -1) { // 返回错误响应,提示文件没有后缀 - return R.error(511,"该文件没有后缀"); - }else{ + return R.error(511, "该文件没有后缀"); + } else { // 获取文件后缀 String suffix = fileName.substring(lastIndexOf); // 如果后缀不是.xls - if(!".xls".equals(suffix)){ + if (!".xls".equals(suffix)) { // 返回错误响应,提示只支持.xls 后缀的 Excel 文件 - return R.error(511,"只支持后缀为xls的excel文件"); - }else{ + return R.error(511, "只支持后缀为xls的excel文件"); + } else { // 获取文件的 URL URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 创建文件对象 File file = new File(resource.getFile()); // 如果文件不存在 - if(!file.exists()){ + if (!file.exists()) { // 返回错误响应,提示找不到上传文件 - return R.error(511,"找不到上传文件,请联系管理员"); - }else{ + return R.error(511, "找不到上传文件,请联系管理员"); + } else { // 从 Excel 文件中读取数据 List> dataList = PoiUtil.poiImport(file.getPath()); // 删除第一行(通常是表头) dataList.remove(0); // 遍历数据列表 - for(List data:dataList){ + for (List data : dataList) { // 创建在线咨询实体对象 ChatEntity chatEntity = new ChatEntity(); @@ -317,34 +320,35 @@ public class ChatController { } } } - }catch (Exception e){ + } catch (Exception e) { // 如果发生异常,返回错误响应,提示批量插入数据异常 - return R.error(511,"批量插入数据异常,请联系管理员"); + return R.error(511, "批量插入数据异常,请联系管理员"); } } /** * 前端列表 * 处理获取在线咨询前端列表数据的请求,此方法忽略权限验证 - * @param params 包含请求参数的 Map,如分页参数、排序参数等 + * + * @param params 包含请求参数的 Map,如分页参数、排序参数等 * @param request HttpServletRequest 对象,包含请求的相关信息 * @return R 类型的响应对象,封装了请求处理的结果 */ @IgnoreAuth @RequestMapping("/list") - public R list(@RequestParam Map params, HttpServletRequest request){ + public R list(@RequestParam Map params, HttpServletRequest request) { // 记录调试日志,输出方法名、控制器类名和请求参数 - logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); + logger.debug("list方法:,,Controller:{},,params:{}", this.getClass().getName(), JSONObject.toJSONString(params)); // 如果没有指定排序字段,就默认按 id 倒序排序 - if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){ - params.put("orderBy","id"); + if (StringUtil.isEmpty(String.valueOf(params.get("orderBy")))) { + params.put("orderBy", "id"); } // 调用 ChatService 的 queryPage 方法获取分页数据 PageUtils page = chatService.queryPage(params); // 将分页数据中的列表转换为 ChatView 类型的列表 - List list =(List)page.getList(); + List list = (List) page.getList(); // 遍历列表,对每个 ChatView 对象进行字典表数据转换 - for(ChatView c:list) + for (ChatView c : list) dictionaryService.dictionaryConvert(c, request); // 返回成功响应,并将分页数据封装在 data 属性中 return R.ok().put("data", page); @@ -353,29 +357,30 @@ public class ChatController { /** * 前端详情 * 处理获取在线咨询前端详情数据的请求 - * @param id 要查询的在线咨询记录的 ID + * + * @param id 要查询的在线咨询记录的 ID * @param request HttpServletRequest 对象,包含请求的相关信息 * @return R 类型的响应对象,封装了请求处理的结果 */ @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id, HttpServletRequest request){ + public R detail(@PathVariable("id") Long id, HttpServletRequest request) { // 记录调试日志,输出方法名、控制器类名和要查询的 ID - logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); + logger.debug("detail方法:,,Controller:{},,id:{}", this.getClass().getName(), id); // 根据 ID 查询在线咨询记录 ChatEntity chat = chatService.selectById(id); // 如果查询到记录 - if(chat !=null){ + if (chat != null) { // 将 ChatEntity 转换为 ChatView ChatView view = new ChatView(); // 使用 BeanUtils 将 ChatEntity 的属性复制到 ChatView 中 - BeanUtils.copyProperties( chat , view ); + BeanUtils.copyProperties(chat, view); // 级联查询用户信息 YonghuEntity yonghu = yonghuService.selectById(chat.getYonghuId()); // 如果查询到用户信息 - if(yonghu != null){ + if (yonghu != null) { // 将用户信息的部分属性复制到 ChatView 中,并排除指定字段 - BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"}); + BeanUtils.copyProperties(yonghu, view, new String[]{"id", "createDate"}); // 设置 ChatView 中的用户 ID view.setYonghuId(yonghu.getId()); } @@ -384,10 +389,10 @@ public class ChatController { dictionaryService.dictionaryConvert(view, request); // 返回成功响应,并将处理后的 ChatView 数据封装在 data 属性中 return R.ok().put("data", view); - }else { + } else { // 如果未查询到记录,返回错误响应 - return R.error(511,"查不到数据"); + return R.error(511, "查不到数据"); } } +} -/** \ No newline at end of file diff --git a/src/main/java/com/controller/CommonController.java b/src/main/java/com/controller/CommonController.java index 569a58f..0f0b910 100644 --- a/src/main/java/com/controller/CommonController.java +++ b/src/main/java/com/controller/CommonController.java @@ -40,7 +40,7 @@ import com.utils.R; * 通用接口 */ @RestController -public class CommonController{ +public class CommonController{ private static final Logger logger = LoggerFactory.getLogger(CommonController.class); @Autowired private CommonService commonService; diff --git a/src/main/java/com/controller/UsersController.java b/src/main/java/com/controller/UsersController.java index b0105d2..2b15447 100644 --- a/src/main/java/com/controller/UsersController.java +++ b/src/main/java/com/controller/UsersController.java @@ -58,7 +58,7 @@ public class UsersController { /** * 注册 - */111 + */ @IgnoreAuth @PostMapping(value = "/register") public R register(@RequestBody UsersEntity user){ @@ -72,7 +72,7 @@ public class UsersController { /** * 退出 - */43242 + */ @GetMapping(value = "logout") public R logout(HttpServletRequest request) { request.getSession().invalidate(); From 9e5de09591efc76576b253ca5aacd13bc7c784a8 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:16:34 +0800 Subject: [PATCH 2/2] =?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 | 720 ++++++++++-------- .../classes/front/front/pages/home/home.html | 411 ++++++---- 2 files changed, 667 insertions(+), 464 deletions(-) diff --git a/src/main/java/com/controller/CommonController.java b/src/main/java/com/controller/CommonController.java index 0f0b910..ec44fea 100644 --- a/src/main/java/com/controller/CommonController.java +++ b/src/main/java/com/controller/CommonController.java @@ -35,504 +35,557 @@ 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); + // 注入CommonService,处理通用业务逻辑 @Autowired private CommonService commonService; - + // 注入ConfigService,用于配置信息的操作 @Autowired private ConfigService configService; - + // 百度人脸识别客户端 private static AipFace client = null; - + // 百度地图AK(Access Key) private static String BAIDU_DITU_AK = null; - + + /** + * 根据经纬度获取城市信息 + * @param lng 经度 + * @param lat 纬度 + * @return 返回包含城市信息的结果对象 + */ @RequestMapping("/location") - public R location(String lng,String lat) { - if(BAIDU_DITU_AK==null) { + public R location(String lng, String lat) { + // 如果BAIDU_DITU_AK为空,从配置中获取 + 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"); } } + // 调用百度工具类获取城市信息 Map map = BaiduUtil.getCityByLonLat(BAIDU_DITU_AK, lng, lat); + // 返回包含城市信息的结果对象 return R.ok().put("data", map); } - + /** * 人脸比对 * @param face1 人脸1 * @param face2 人脸2 - * @return + * @param request HttpServletRequest对象 + * @return 返回人脸比对结果 */ @RequestMapping("/matchFace") public R matchFace(String face1, String face2, HttpServletRequest request) { - if(client==null) { - /*String AppID = configService.selectOne(new EntityWrapper().eq("name", "AppID")).getValue();*/ + // 如果客户端未初始化,进行初始化 + if (client == null) { + // 获取APIKey和SecretKey String APIKey = configService.selectOne(new EntityWrapper().eq("name", "APIKey")).getValue(); String SecretKey = configService.selectOne(new EntityWrapper().eq("name", "SecretKey")).getValue(); + // 获取访问令牌 String token = BaiduUtil.getAuth(APIKey, SecretKey); - if(token==null) { + // 如果令牌获取失败,返回错误信息 + if (token == null) { return R.error("请在配置管理中正确配置APIKey和SecretKey"); } + // 初始化AipFace客户端 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); + // 获取人脸图片文件 + File file1 = new File(request.getSession().getServletContext().getRealPath("/upload") + "/" + face1); + File file2 = new File(request.getSession().getServletContext().getRealPath("/upload") + "/" + face2); + // 将文件转换为Base64编码的字符串 String img1 = Base64Util.encode(FileUtil.FileToByte(file1)); String img2 = Base64Util.encode(FileUtil.FileToByte(file2)); + // 创建MatchRequest对象 MatchRequest req1 = new MatchRequest(img1, "BASE64"); MatchRequest req2 = new MatchRequest(img2, "BASE64"); + // 创建请求列表 ArrayList requests = new ArrayList(); 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) { + // 处理IO异常 e.printStackTrace(); - } + } + // 返回包含比对结果的数据对象 return R.ok().put("data", com.alibaba.fastjson.JSONObject.parse(res.get("result").toString())); } - /** * 获取table表中的column列表(联动接口) - * @return + * @param tableName 表名 + * @param columnName 列名 + * @param level 层级 + * @param parent 父级 + * @return 返回包含列列表的结果对象 */ @RequestMapping("/option/{tableName}/{columnName}") @IgnoreAuth - public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,String level,String parent) { + public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, String level, String parent) { + // 创建参数Map Map params = new HashMap(); params.put("table", tableName); params.put("column", columnName); - if(StringUtils.isNotBlank(level)) { + // 如果层级不为空,添加到参数Map中 + if (StringUtils.isNotBlank(level)) { params.put("level", level); } - if(StringUtils.isNotBlank(parent)) { + // 如果父级不为空,添加到参数Map中 + if (StringUtils.isNotBlank(parent)) { params.put("parent", parent); } + // 调用CommonService获取列列表 List data = commonService.getOption(params); + // 返回包含列列表的结果对象 return R.ok().put("data", data); } - /** * 根据table中的column获取单条记录 - * @return + * @param tableName 表名 + * @param columnName 列名 + * @param columnValue 列值 + * @return 返回包含单条记录的结果对象 */ @RequestMapping("/follow/{tableName}/{columnName}") @IgnoreAuth public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) { + // 创建参数Map Map params = new HashMap(); params.put("table", tableName); params.put("column", columnName); params.put("columnValue", columnValue); + // 调用CommonService获取单条记录 Map result = commonService.getFollowByOption(params); + // 返回包含单条记录的结果对象 return R.ok().put("data", result); } - /** * 修改table表的sfsh状态 - * @param map - * @return + * @param tableName 表名 + * @param map 包含修改信息的Map + * @return 返回操作结果 */ @RequestMapping("/sh/{tableName}") public R sh(@PathVariable("tableName") String tableName, @RequestBody Map map) { + // 将表名添加到参数Map中 map.put("table", tableName); + // 调用CommonService进行状态修改 commonService.sh(map); + // 返回操作成功结果 return R.ok(); } - /** * 获取需要提醒的记录数 - * @param tableName - * @param columnName - * @param type 1:数字 2:日期 - * @param map - * @return + * @param tableName 表名 + * @param columnName 列名 + * @param type 类型,1:数字 2:日期 + * @param map 包含查询条件的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 map) { + public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, + @PathVariable("type") String type, @RequestParam Map map) { + // 将表名、列名、类型添加到参数Map中 map.put("table", tableName); map.put("column", columnName); map.put("type", type); - - if(type.equals("2")) { + + // 如果类型为日期 + 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) { + // 如果提醒开始日期不为空 + 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.setTime(new Date()); + // 计算提醒开始日期 + c.add(Calendar.DAY_OF_MONTH, remindStart); remindStartDate = c.getTime(); + // 将提醒开始日期格式化后添加到参数Map中 map.put("remindstart", sdf.format(remindStartDate)); } - if(map.get("remindend")!=null) { + // 如果提醒结束日期不为空 + 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中 map.put("remindend", sdf.format(remindEndDate)); } } - + // 调用CommonService获取提醒记录数 int count = commonService.remindCount(map); + // 返回包含提醒记录数的结果对象 return R.ok().put("count", count); } - /** * 圖表统计 + * @param tableName 表名 + * @param params 包含查询参数的Map + * @return 返回包含统计结果的结果对象 */ @IgnoreAuth @RequestMapping("/group/{tableName}") - public R group1(@PathVariable("tableName") String tableName, @RequestParam Map params) { + public R group1(@PathVariable("tableName") String tableName, @RequestParam Map params) { + // 将表名添加到参数Map中 params.put("table1", tableName); + // 调用CommonService进行图表统计 List> result = commonService.chartBoth(params); + // 返回包含统计结果的结果对象 return R.ok().put("data", result); } - - /** * 单列求和 + * @param tableName 表名 + * @param columnName 列名 + * @return 返回包含求和结果的结果对象 */ @RequestMapping("/cal/{tableName}/{columnName}") @IgnoreAuth public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) { + // 创建参数Map Map params = new HashMap(); params.put("table", tableName); params.put("column", columnName); + // 调用CommonService进行单列求和 Map result = commonService.selectCal(params); + // 返回包含求和结果的结果对象 return R.ok().put("data", result); } - /** * 分组统计 + * @param tableName 表名 + * @param columnName 列名 + * @return 返回包含分组统计结果的结果对象 */ @RequestMapping("/group/{tableName}/{columnName}") @IgnoreAuth public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) { + // 创建参数Map Map params = new HashMap(); params.put("table", tableName); params.put("column", columnName); + // 调用CommonService进行分组统计 List> result = commonService.selectGroup(params); + // 返回包含分组统计结果的结果对象 return R.ok().put("data", result); } - /** * (按值统计) + * @param tableName 表名 + * @param yColumnName y轴列名 + * @param xColumnName x轴列名 + * @return 返回包含按值统计结果的结果对象 */ @RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}") @IgnoreAuth public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) { + // 创建参数Map Map params = new HashMap(); params.put("table", tableName); params.put("xColumn", xColumnName); params.put("yColumn", yColumnName); + // 调用CommonService进行按值统计 List> result = commonService.selectValue(params); + // 返回包含按值统计结果的结果对象 return R.ok().put("data", result); } - - - /** * 查询字典表的分组求和 - * tableName 表名 - * groupColumn 分组字段 - * sumCloum 统计字段 - * @return + * @param params 包含查询参数的Map + * @return 返回包含分组求和结果的结果对象 */ @RequestMapping("/newSelectGroupSum") - public R newSelectGroupSum(@RequestParam Map params) { - logger.debug("newSelectGroupSum:,,Controller:{},,params:{}",this.getClass().getName(),params); + public R newSelectGroupSum(@RequestParam Map params) { + // 记录日志 + logger.debug("newSelectGroupSum:,,Controller:{},,params:{}", this.getClass().getName(), params); + // 调用CommonService进行字典表分组求和 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); - } - + * 查询平均评分 + * @param params 包含查询参数的Map + * @return 返回包含平均评分结果的结果对象 + */ + @IgnoreAuth + @RequestMapping("/queryScore") + public R queryScore(@RequestParam Map params) { + // 记录日志 + logger.debug("queryScore:,,Controller:{},,params:{}", this.getClass().getName(), params); + // 调用CommonService查询平均评分 + Map queryScore = commonService.queryScore(params); + // 返回包含平均评分结果的结果对象 + return R.ok().put("data", queryScore); + } /** * 查询字典表的分组统计总条数 - * tableName 表名 - * groupColumn 分组字段 - * @return + * @param params 包含查询参数的Map + * @return 返回包含分组统计总条数结果的结果对象 */ @RequestMapping("/newSelectGroupCount") - public R newSelectGroupCount(@RequestParam Map params) { - logger.debug("newSelectGroupCount:,,Controller:{},,params:{}",this.getClass().getName(),params); + public R newSelectGroupCount(@RequestParam Map params) { + // 记录日志 + logger.debug("newSelectGroupCount:,,Controller:{},,params:{}", this.getClass().getName(), params); + // 调用CommonService进行字典表分组统计总条数 List> result = commonService.newSelectGroupCount(params); + // 返回包含分组统计总条数结果的结果对象 return R.ok().put("data", result); } /** * 当前表的日期分组求和 - * tableName 表名 - * groupColumn 分组字段 - * sumCloum 统计字段 - * dateFormatType 日期格式化类型 1:年 2:月 3:日 - * @return + * @param params 包含查询参数的Map + * @return 返回包含日期分组求和结果的结果对象 */ @RequestMapping("/newSelectDateGroupSum") - public R newSelectDateGroupSum(@RequestParam Map params) { - logger.debug("newSelectDateGroupSum:,,Controller:{},,params:{}",this.getClass().getName(),params); + 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)){ + // 根据日期格式化类型设置日期格式 + if ("1".equals(dateFormatType)) { params.put("dateFormat", "%Y"); - }else if("2".equals(dateFormatType)){ + } else if ("2".equals(dateFormatType)) { params.put("dateFormat", "%Y-%m"); - }else if("3".equals(dateFormatType)){ + } else if ("3".equals(dateFormatType)) { params.put("dateFormat", "%Y-%m-%d"); - }else{ - R.error("日期格式化不正确"); + } else { + // 日期格式化类型不正确,返回错误信息 + return R.error("日期格式化不正确"); } + // 调用CommonService进行日期分组求和 List> result = commonService.newSelectDateGroupSum(params); + // 返回包含日期分组求和结果的结果对象 return R.ok().put("data", result); } - /** - * 1查询字典表的分组统计总条数 - * tableName 表名 - * groupColumn 分组字段 - * dateFormatType 日期格式化类型 1:年 2:月 3:日 - * @return + * 查询字典表的日期分组统计总条数 + * @param params 包含查询参数的Map + * @return 返回包含日期分组统计总条数结果的结果对象 */ @RequestMapping("/newSelectDateGroupCount") - public R newSelectDateGroupCount(@RequestParam Map params) { - logger.debug("newSelectDateGroupCount:,,Controller:{},,params:{}",this.getClass().getName(),params); + 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)){ + // 根据日期格式化类型设置日期格式 + if ("1".equals(dateFormatType)) { params.put("dateFormat", "%Y"); - }else if("2".equals(dateFormatType)){ + } else if ("2".equals(dateFormatType)) { params.put("dateFormat", "%Y-%m"); - }else if("3".equals(dateFormatType)){ + } else if ("3".equals(dateFormatType)) { params.put("dateFormat", "%Y-%m-%d"); - }else{ - R.error("日期格式化类型不正确"); + } else { + // 日期格式化类型不正确,返回错误信息 + return R.error("日期格式化类型不正确"); } + // 调用CommonService进行日期分组统计总条数 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; - } + /** + * 柱状图求和 + * @param params 包含查询参数的Map + * @return 返回包含柱状图求和结果的结果对象 + */ + @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 = ""; + + // 处理当前表 + 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(",")); + // 处理当前表日期 + if (StringUtil.isNotEmpty(String.valueOf(thisTable.get("date")))) { + thisTable.put("date", String.valueOf(thisTable.get("date")).split(",")); one = "thisDate0"; } - if(isJoinTableFlag){//级联表日期 + // 处理级联表日期 + 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(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 (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){//级联表字符串 + // 处理级联表字符串 + 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(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 (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){//级联表类型 + // 处理级联表类型 + 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"; + 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"; } } - } } + // 调用CommonService进行柱状图求和 List> result = commonService.barSum(params); - List xAxis = new ArrayList<>();//报表x轴 - List> yAxis = new ArrayList<>();//y轴 - List legend = new ArrayList<>();//标题 + // 报表x轴 + List xAxis = new ArrayList<>(); + // y轴 + List> yAxis = new ArrayList<>(); + // 标题 + List legend = new ArrayList<>(); - if(StringUtil.isEmpty(two)){//不包含第二列 + // 如果不包含第二列 + if (StringUtil.isEmpty(two)) { List yAxis0 = new ArrayList<>(); yAxis.add(yAxis0); legend.add("数值"); - for(Map map :result){ + 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{//包含第二列 + } else { + // 包含第二列 Map> dataMap = new LinkedHashMap<>(); - if(StringUtil.isNotEmpty(two)){ - for(Map map :result){ + 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 (!legend.contains(twoValue)) { + legend.add(twoValue); } - if(dataMap.containsKey(oneValue)){ - dataMap.get(oneValue).put(twoValue,value); - }else{ + if (dataMap.containsKey(oneValue)) { + dataMap.get(oneValue).put(twoValue, value); + } else { HashMap oneData = new HashMap<>(); - oneData.put(twoValue,value); - dataMap.put(oneValue,oneData); + oneData.put(twoValue, value); + dataMap.put(oneValue, oneData); } - } } - for(int i =0; i()); } Set keys = dataMap.keySet(); - for(String key:keys){ + 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)))){ + if (StringUtil.isNotEmpty(map.get(legend.get(i)))) { data.add(map.get(legend.get(i))); - }else{ + } else { data.add("0"); } } @@ -540,151 +593,168 @@ public class CommonController{ System.out.println(); } + // 创建结果Map Map resultMap = new HashMap<>(); - resultMap.put("xAxis",xAxis); - resultMap.put("yAxis",yAxis); - resultMap.put("legend",legend); + 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; - } + * 柱状图统计 + * @param params 包含查询参数的Map + * @return 返回包含柱状图统计结果的结果对象 + */ + @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 = ""; + + // 处理当前表 + 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(",")); + // 处理当前表日期 + if (StringUtil.isNotEmpty(String.valueOf(thisTable.get("date")))) { + thisTable.put("date", String.valueOf(thisTable.get("date")).split(",")); one = "thisDate0"; } - if(isJoinTableFlag){//级联表日期 + // 处理级联表日期 + 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(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 (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){//级联表字符串 + // 处理级联表字符串 + 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(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 (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){//级联表类型 + // 处理级联表类型 + 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"; + 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"; } } - } } + // 调用CommonService进行柱状图统计 List> result = commonService.barCount(params); - List xAxis = new ArrayList<>();//报表x轴 - List> yAxis = new ArrayList<>();//y轴 - List legend = new ArrayList<>();//标题 + // 报表x轴 + List xAxis = new ArrayList<>(); + // y轴 + List> yAxis = new ArrayList<>(); + // 标题 + List legend = new ArrayList<>(); - if(StringUtil.isEmpty(two)){//不包含第二列 + // 如果不包含第二列 + if (StringUtil.isEmpty(two)) { List yAxis0 = new ArrayList<>(); yAxis.add(yAxis0); legend.add("数值"); - for(Map map :result){ + 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{//包含第二列 + } else { + // 包含第二列 Map> dataMap = new LinkedHashMap<>(); - if(StringUtil.isNotEmpty(two)){ - for(Map map :result){ + 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 (!legend.contains(twoValue)) { + legend.add(twoValue); } - if(dataMap.containsKey(oneValue)){ - dataMap.get(oneValue).put(twoValue,value); - }else{ + if (dataMap.containsKey(oneValue)) { + dataMap.get(oneValue).put(twoValue, value); + } else { HashMap oneData = new HashMap<>(); - oneData.put(twoValue,value); - dataMap.put(oneValue,oneData); + oneData.put(twoValue, value); + dataMap.put(oneValue, oneData); } - } } - for(int i =0; i()); } Set keys = dataMap.keySet(); - for(String key:keys){ + 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)))){ + if (StringUtil.isNotEmpty(map.get(legend.get(i)))) { data.add(map.get(legend.get(i))); - }else{ + } else { data.add("0"); } } @@ -692,10 +762,12 @@ public class CommonController{ System.out.println(); } + // 创建结果Map Map resultMap = new HashMap<>(); - resultMap.put("xAxis",xAxis); - resultMap.put("yAxis",yAxis); - resultMap.put("legend",legend); + resultMap.put("xAxis", xAxis); + resultMap.put("yAxis", yAxis); + resultMap.put("legend", legend); + // 返回包含柱状图统计结果的结果对象 return R.ok().put("data", resultMap); - } -} + } +} \ No newline at end of file diff --git a/target/classes/front/front/pages/home/home.html b/target/classes/front/front/pages/home/home.html index 8e89589..267d0bf 100644 --- a/target/classes/front/front/pages/home/home.html +++ b/target/classes/front/front/pages/home/home.html @@ -1,25 +1,41 @@ + + 首页 + + + + + + + + + + + + + - + +
+