当前位置:   article > 正文

基于springboot校园二手书交易管理系统源码和论文

基于springboot校园二手书交易管理系统源码和论文

在Internet高速发展的今天,我们生活的各个领域都涉及到计算机的应用,其中包括乐校园二手书交易管理系统的网络应用,在外国二手书交易管理系统已经是很普遍的方式,不过国内的管理系统可能还处于起步阶段。乐校园二手书交易管理系统具有二手书交易管理功能的选择。乐校园二手书交易管理系统采用java技术,基于springboot框架,mysql数据库进行开发,实现了首页、个人中心、用户管理、卖家用户管理、图书分类管理、二手图书管理、求购图书管理、求购回复管理、留言反馈、系统管理、订单管理等内容进行管理,本系统具有良好的兼容性和适应性,为用户提供更多的乐校园二手书交易信息,也提供了良好的平台,从而提高系统的核心竞争力。

本文首先介绍了设计的背景与研究目的,其次介绍系统相关技术,重点叙述了系统功能分析以及详细设计,最后总结了系统的开发心得。

关键词:java技术;二手书交易;mysql

基于springboot校园二手书交易管理系统源码和论文355

基于springboot校园二手书交易管理系统源码和论文


Abstract

In the rapid development of the Internet today, all areas of our life are involved in computer applications, including le Campus second-hand book trading management system network application, in foreign second-hand book trading management system is a very common way, but the domestic management system may still be in its infancy. Le campus second-hand book trading management system has the choice of second-hand book trading management function. Le Campus second-hand book trading management system using Java technology, based on springboot framework, mysql database development, Implements the home page, personal center, user management, user management, books classification management seller, second-hand books management, purchasing books management, purchasing management responses, message feedback management, system management, order management, and other content, this system has good compatibility and adaptability, to provide users with more second-hand book trade information, also provide a good platform, Thus improve the core competitiveness of the system.

This paper first introduces the design background and research purpose, then introduces the system related technology, focuses on the system function analysis and detailed design, and finally summarizes the development experience of the system.

Key words: Java technology; Second-hand book trade; mysql

  1. package com.controller;
  2. import java.io.File;
  3. import java.math.BigDecimal;
  4. import java.net.URL;
  5. import java.text.SimpleDateFormat;
  6. import com.alibaba.fastjson.JSONObject;
  7. import java.util.*;
  8. import org.springframework.beans.BeanUtils;
  9. import javax.servlet.http.HttpServletRequest;
  10. import org.springframework.web.context.ContextLoader;
  11. import javax.servlet.ServletContext;
  12. import com.service.TokenService;
  13. import com.utils.*;
  14. import java.lang.reflect.InvocationTargetException;
  15. import com.service.DictionaryService;
  16. import org.apache.commons.lang3.StringUtils;
  17. import com.annotation.IgnoreAuth;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Controller;
  22. import org.springframework.web.bind.annotation.*;
  23. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  24. import com.baomidou.mybatisplus.mapper.Wrapper;
  25. import com.entity.*;
  26. import com.entity.view.*;
  27. import com.service.*;
  28. import com.utils.PageUtils;
  29. import com.utils.R;
  30. import com.alibaba.fastjson.*;
  31. /**
  32. * 公告资讯
  33. * 后端接口
  34. * @author
  35. * @email
  36. */
  37. @RestController
  38. @Controller
  39. @RequestMapping("/news")
  40. public class NewsController {
  41. private static final Logger logger = LoggerFactory.getLogger(NewsController.class);
  42. private static final String TABLE_NAME = "news";
  43. @Autowired
  44. private NewsService newsService;
  45. @Autowired
  46. private TokenService tokenService;
  47. @Autowired
  48. private DictionaryService dictionaryService;//字典
  49. @Autowired
  50. private ForumService forumService;//论坛
  51. @Autowired
  52. private HuodongService huodongService;//活动
  53. @Autowired
  54. private HuodongCollectionService huodongCollectionService;//活动收藏
  55. @Autowired
  56. private HuodongLiuyanService huodongLiuyanService;//活动留言
  57. @Autowired
  58. private HuodongYuyueService huodongYuyueService;//活动报名
  59. @Autowired
  60. private SucaiService sucaiService;//图片素材
  61. @Autowired
  62. private SucaiCollectionService sucaiCollectionService;//图片素材收藏
  63. @Autowired
  64. private SucaiLiuyanService sucaiLiuyanService;//图片素材留言
  65. @Autowired
  66. private SucaishipinService sucaishipinService;//视频素材
  67. @Autowired
  68. private SucaishipinCollectionService sucaishipinCollectionService;//视频素材收藏
  69. @Autowired
  70. private SucaishipinLiuyanService sucaishipinLiuyanService;//视频素材留言
  71. @Autowired
  72. private YonghuService yonghuService;//用户
  73. @Autowired
  74. private UsersService usersService;//管理员
  75. /**
  76. * 后端列表
  77. */
  78. @RequestMapping("/page")
  79. public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
  80. logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
  81. String role = String.valueOf(request.getSession().getAttribute("role"));
  82. if(false)
  83. return R.error(511,"永不会进入");
  84. else if("用户".equals(role))
  85. params.put("yonghuId",request.getSession().getAttribute("userId"));
  86. CommonUtil.checkMap(params);
  87. PageUtils page = newsService.queryPage(params);
  88. //字典表数据转换
  89. List<NewsView> list =(List<NewsView>)page.getList();
  90. for(NewsView c:list){
  91. //修改对应字典表字段
  92. dictionaryService.dictionaryConvert(c, request);
  93. }
  94. return R.ok().put("data", page);
  95. }
  96. /**
  97. * 后端详情
  98. */
  99. @RequestMapping("/info/{id}")
  100. public R info(@PathVariable("id") Long id, HttpServletRequest request){
  101. logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
  102. NewsEntity news = newsService.selectById(id);
  103. if(news !=null){
  104. //entity转view
  105. NewsView view = new NewsView();
  106. BeanUtils.copyProperties( news , view );//把实体数据重构到view中
  107. //修改对应字典表字段
  108. dictionaryService.dictionaryConvert(view, request);
  109. return R.ok().put("data", view);
  110. }else {
  111. return R.error(511,"查不到数据");
  112. }
  113. }
  114. /**
  115. * 后端保存
  116. */
  117. @RequestMapping("/save")
  118. public R save(@RequestBody NewsEntity news, HttpServletRequest request){
  119. logger.debug("save方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString());
  120. String role = String.valueOf(request.getSession().getAttribute("role"));
  121. if(false)
  122. return R.error(511,"永远不会进入");
  123. Wrapper<NewsEntity> queryWrapper = new EntityWrapper<NewsEntity>()
  124. .eq("news_name", news.getNewsName())
  125. .eq("news_types", news.getNewsTypes())
  126. ;
  127. logger.info("sql语句:"+queryWrapper.getSqlSegment());
  128. NewsEntity newsEntity = newsService.selectOne(queryWrapper);
  129. if(newsEntity==null){
  130. news.setInsertTime(new Date());
  131. news.setCreateTime(new Date());
  132. newsService.insert(news);
  133. return R.ok();
  134. }else {
  135. return R.error(511,"表中有相同数据");
  136. }
  137. }
  138. /**
  139. * 后端修改
  140. */
  141. @RequestMapping("/update")
  142. public R update(@RequestBody NewsEntity news, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
  143. logger.debug("update方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString());
  144. NewsEntity oldNewsEntity = newsService.selectById(news.getId());//查询原先数据
  145. String role = String.valueOf(request.getSession().getAttribute("role"));
  146. // if(false)
  147. // return R.error(511,"永远不会进入");
  148. if("".equals(news.getNewsPhoto()) || "null".equals(news.getNewsPhoto())){
  149. news.setNewsPhoto(null);
  150. }
  151. newsService.updateById(news);//根据id更新
  152. return R.ok();
  153. }
  154. /**
  155. * 删除
  156. */
  157. @RequestMapping("/delete")
  158. public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
  159. logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
  160. List<NewsEntity> oldNewsList =newsService.selectBatchIds(Arrays.asList(ids));//要删除的数据
  161. newsService.deleteBatchIds(Arrays.asList(ids));
  162. return R.ok();
  163. }
  164. /**
  165. * 批量上传
  166. */
  167. @RequestMapping("/batchInsert")
  168. public R save( String fileName, HttpServletRequest request){
  169. logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
  170. Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
  171. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  172. try {
  173. List<NewsEntity> newsList = new ArrayList<>();//上传的东西
  174. Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
  175. Date date = new Date();
  176. int lastIndexOf = fileName.lastIndexOf(".");
  177. if(lastIndexOf == -1){
  178. return R.error(511,"该文件没有后缀");
  179. }else{
  180. String suffix = fileName.substring(lastIndexOf);
  181. if(!".xls".equals(suffix)){
  182. return R.error(511,"只支持后缀为xls的excel文件");
  183. }else{
  184. URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
  185. File file = new File(resource.getFile());
  186. if(!file.exists()){
  187. return R.error(511,"找不到上传文件,请联系管理员");
  188. }else{
  189. List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
  190. dataList.remove(0);//删除第一行,因为第一行是提示
  191. for(List<String> data:dataList){
  192. //循环
  193. NewsEntity newsEntity = new NewsEntity();
  194. // newsEntity.setNewsName(data.get(0)); //公告标题 要改的
  195. // newsEntity.setNewsTypes(Integer.valueOf(data.get(0))); //公告类型 要改的
  196. // newsEntity.setNewsPhoto("");//详情和图片
  197. // newsEntity.setInsertTime(date);//时间
  198. // newsEntity.setNewsContent("");//详情和图片
  199. // newsEntity.setCreateTime(date);//时间
  200. newsList.add(newsEntity);
  201. //把要查询是否重复的字段放入map中
  202. }
  203. //查询是否重复
  204. newsService.insertBatch(newsList);
  205. return R.ok();
  206. }
  207. }
  208. }
  209. }catch (Exception e){
  210. e.printStackTrace();
  211. return R.error(511,"批量插入数据异常,请联系管理员");
  212. }
  213. }
  214. /**
  215. * 前端列表
  216. */
  217. @IgnoreAuth
  218. @RequestMapping("/list")
  219. public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
  220. logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
  221. CommonUtil.checkMap(params);
  222. PageUtils page = newsService.queryPage(params);
  223. //字典表数据转换
  224. List<NewsView> list =(List<NewsView>)page.getList();
  225. for(NewsView c:list)
  226. dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
  227. return R.ok().put("data", page);
  228. }
  229. /**
  230. * 前端详情
  231. */
  232. @RequestMapping("/detail/{id}")
  233. public R detail(@PathVariable("id") Long id, HttpServletRequest request){
  234. logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
  235. NewsEntity news = newsService.selectById(id);
  236. if(news !=null){
  237. //entity转view
  238. NewsView view = new NewsView();
  239. BeanUtils.copyProperties( news , view );//把实体数据重构到view中
  240. //修改对应字典表字段
  241. dictionaryService.dictionaryConvert(view, request);
  242. return R.ok().put("data", view);
  243. }else {
  244. return R.error(511,"查不到数据");
  245. }
  246. }
  247. /**
  248. * 前端保存
  249. */
  250. @RequestMapping("/add")
  251. public R add(@RequestBody NewsEntity news, HttpServletRequest request){
  252. logger.debug("add方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString());
  253. Wrapper<NewsEntity> queryWrapper = new EntityWrapper<NewsEntity>()
  254. .eq("news_name", news.getNewsName())
  255. .eq("news_types", news.getNewsTypes())
  256. // .notIn("news_types", new Integer[]{102})
  257. ;
  258. logger.info("sql语句:"+queryWrapper.getSqlSegment());
  259. NewsEntity newsEntity = newsService.selectOne(queryWrapper);
  260. if(newsEntity==null){
  261. news.setInsertTime(new Date());
  262. news.setCreateTime(new Date());
  263. newsService.insert(news);
  264. return R.ok();
  265. }else {
  266. return R.error(511,"表中有相同数据");
  267. }
  268. }
  269. }
  1. package com.controller;
  2. import java.io.*;
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.text.SimpleDateFormat;
  7. import java.util.*;
  8. import javax.servlet.http.HttpServletRequest;
  9. import com.alibaba.fastjson.JSON;
  10. import com.utils.StringUtil;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.json.JSONObject;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.beans.factory.annotation.Value;
  17. import org.springframework.util.ResourceUtils;
  18. import org.springframework.web.bind.annotation.PathVariable;
  19. import org.springframework.web.bind.annotation.RequestBody;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21. import org.springframework.web.bind.annotation.RequestParam;
  22. import org.springframework.web.bind.annotation.RestController;
  23. import com.annotation.IgnoreAuth;
  24. import com.baidu.aip.face.AipFace;
  25. import com.baidu.aip.face.MatchRequest;
  26. import com.baidu.aip.util.Base64Util;
  27. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  28. import com.baomidou.mybatisplus.mapper.Wrapper;
  29. import com.entity.ConfigEntity;
  30. import com.service.CommonService;
  31. import com.service.ConfigService;
  32. import com.utils.BaiduUtil;
  33. import com.utils.FileUtil;
  34. import com.utils.R;
  35. /**
  36. * 通用接口
  37. */
  38. @RestController
  39. public class CommonController {
  40. private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
  41. @Autowired
  42. private CommonService commonService;
  43. /**
  44. * Java代码实现MySQL数据库导出
  45. *
  46. * @param mysqlUrl MySQL安装路径
  47. * @param hostIP MySQL数据库所在服务器地址IP
  48. * @param userName 进入数据库所需要的用户名
  49. * @param hostPort 数据库端口
  50. * @param password 进入数据库所需要的密码
  51. * @param savePath 数据库文件保存路径
  52. * @param fileName 数据库导出文件文件名
  53. * @param databaseName 要导出的数据库名
  54. * @return 返回true表示导出成功,否则返回false。
  55. */
  56. @IgnoreAuth
  57. @RequestMapping("/beifen")
  58. public R beifen(String mysqlUrl, String hostIP, String userName, String hostPort, String password, String savePath, String fileName, String databaseName) {
  59. File saveFile = new File(savePath);
  60. if (!saveFile.exists()) {// 如果目录不存在 
  61. saveFile.mkdirs();// 创建文件夹 
  62. }
  63. if (!savePath.endsWith(File.separator)) {
  64. savePath = savePath + File.separator;
  65. }
  66. PrintWriter printWriter = null;
  67. BufferedReader bufferedReader = null;
  68. try {
  69. Runtime runtime = Runtime.getRuntime();
  70. String cmd = mysqlUrl + "mysqldump -h" + hostIP + " -u" + userName + " -P" + hostPort + " -p" + password + " " + databaseName;
  71. runtime.exec(cmd);
  72. Process process = runtime.exec(cmd);
  73. InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream(), "utf8");
  74. bufferedReader = new BufferedReader(inputStreamReader);
  75. printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(savePath + fileName), "utf8"));
  76. String line;
  77. while ((line = bufferedReader.readLine()) != null) {
  78. printWriter.println(line);
  79. }
  80. printWriter.flush();
  81. } catch (Exception e) {
  82. e.printStackTrace();
  83. return R.error("备份数据出错");
  84. } finally {
  85. try {
  86. if (bufferedReader != null) {
  87. bufferedReader.close();
  88. }
  89. if (printWriter != null) {
  90. printWriter.close();
  91. }
  92. } catch (Exception e) {
  93. e.printStackTrace();
  94. }
  95. }
  96. return R.ok();
  97. }
  98. /**
  99. * Java实现MySQL数据库导入
  100. *
  101. * @param mysqlUrl MySQL安装路径
  102. * @param hostIP MySQL数据库所在服务器地址IP
  103. * @param userName 进入数据库所需要的用户名
  104. * @param hostPort 数据库端口
  105. * @param password 进入数据库所需要的密码
  106. * @param savePath 数据库文件保存路径
  107. * @param fileName 数据库导出文件文件名
  108. * @param databaseName 要导出的数据库名
  109. */
  110. @IgnoreAuth
  111. @RequestMapping("/huanyuan")
  112. public R huanyuan(String mysqlUrl, String hostIP, String userName, String hostPort, String password, String savePath, String fileName, String databaseName) {
  113. try {
  114. Runtime rt = Runtime.getRuntime();
  115. Process child1 = rt.exec(mysqlUrl+"mysql.exe -h" + hostIP + " -u" + userName + " -P" + hostPort + " -p" + password + " " + databaseName);
  116. OutputStream out = child1.getOutputStream();//控制台的输入信息作为输出流
  117. String inStr;
  118. StringBuffer sb = new StringBuffer("");
  119. String outStr;
  120. BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(savePath+"/"+fileName), "utf-8"));
  121. while ((inStr = br.readLine()) != null) {
  122. sb.append(inStr + "\r\n");
  123. }
  124. outStr = sb.toString();
  125. OutputStreamWriter writer = new OutputStreamWriter(out, "utf8");
  126. writer.write(outStr);
  127. // 注:这里如果用缓冲方式写入文件的话,会导致中文乱码,用flush()方法则可以避免
  128. writer.flush();
  129. out.close();
  130. br.close();
  131. writer.close();
  132. } catch (Exception e) {
  133. e.printStackTrace();
  134. return R.error("数据导入出错");
  135. }
  136. return R.ok();
  137. }
  138. /**
  139. * 饼状图求和
  140. * @return
  141. */
  142. @RequestMapping("/pieSum")
  143. public R pieSum(@RequestParam Map<String,Object> params) {
  144. logger.debug("饼状图求和:,,Controller:{},,params:{}",this.getClass().getName(),params);
  145. List<Map<String, Object>> result = commonService.pieSum(params);
  146. return R.ok().put("data", result);
  147. }
  148. /**
  149. * 饼状图统计
  150. * @return
  151. */
  152. @RequestMapping("/pieCount")
  153. public R pieCount(@RequestParam Map<String,Object> params) {
  154. logger.debug("饼状图统计:,,Controller:{},,params:{}",this.getClass().getName(),params);
  155. List<Map<String, Object>> result = commonService.pieCount(params);
  156. return R.ok().put("data", result);
  157. }
  158. /**
  159. * 柱状图求和单列
  160. * @return
  161. */
  162. @RequestMapping("/barSumOne")
  163. public R barSumOne(@RequestParam Map<String,Object> params) {
  164. logger.debug("柱状图求和单列:,,Controller:{},,params:{}",this.getClass().getName(),params);
  165. List<Map<String, Object>> result = commonService.barSumOne(params);
  166. List<String> xAxis = new ArrayList<>();//报表x轴
  167. List<List<String>> yAxis = new ArrayList<>();//y轴
  168. List<String> legend = new ArrayList<>();//标题
  169. List<String> yAxis0 = new ArrayList<>();
  170. yAxis.add(yAxis0);
  171. legend.add("");
  172. for(Map<String, Object> map :result){
  173. String oneValue = String.valueOf(map.get("name"));
  174. String value = String.valueOf(map.get("value"));
  175. xAxis.add(oneValue);
  176. yAxis0.add(value);
  177. }
  178. Map<String, Object> resultMap = new HashMap<>();
  179. resultMap.put("xAxis",xAxis);
  180. resultMap.put("yAxis",yAxis);
  181. resultMap.put("legend",legend);
  182. return R.ok().put("data", resultMap);
  183. }
  184. /**
  185. * 柱状图统计单列
  186. * @return
  187. */
  188. @RequestMapping("/barCountOne")
  189. public R barCountOne(@RequestParam Map<String,Object> params) {
  190. logger.debug("柱状图统计单列:,,Controller:{},,params:{}",this.getClass().getName(),params);
  191. List<Map<String, Object>> result = commonService.barCountOne(params);
  192. List<String> xAxis = new ArrayList<>();//报表x轴
  193. List<List<String>> yAxis = new ArrayList<>();//y轴
  194. List<String> legend = new ArrayList<>();//标题
  195. List<String> yAxis0 = new ArrayList<>();
  196. yAxis.add(yAxis0);
  197. legend.add("");
  198. for(Map<String, Object> map :result){
  199. String oneValue = String.valueOf(map.get("name"));
  200. String value = String.valueOf(map.get("value"));
  201. xAxis.add(oneValue);
  202. yAxis0.add(value);
  203. }
  204. Map<String, Object> resultMap = new HashMap<>();
  205. resultMap.put("xAxis",xAxis);
  206. resultMap.put("yAxis",yAxis);
  207. resultMap.put("legend",legend);
  208. return R.ok().put("data", resultMap);
  209. }
  210. /**
  211. * 柱状图统计双列
  212. * @return
  213. */
  214. @RequestMapping("/barSumTwo")
  215. public R barSumTwo(@RequestParam Map<String,Object> params) {
  216. logger.debug("柱状图统计双列:,,Controller:{},,params:{}",this.getClass().getName(),params);
  217. List<Map<String, Object>> result = commonService.barSumTwo(params);
  218. List<String> xAxis = new ArrayList<>();//报表x轴
  219. List<List<String>> yAxis = new ArrayList<>();//y轴
  220. List<String> legend = new ArrayList<>();//标题
  221. Map<String, HashMap<String, String>> dataMap = new LinkedHashMap<>();
  222. for(Map<String, Object> map :result){
  223. String name1Value = String.valueOf(map.get("name1"));
  224. String name2Value = String.valueOf(map.get("name2"));
  225. String value = String.valueOf(map.get("value"));
  226. if(!legend.contains(name2Value)){
  227. legend.add(name2Value);//添加完成后 就是最全的第二列的类型
  228. }
  229. if(dataMap.containsKey(name1Value)){
  230. dataMap.get(name1Value).put(name2Value,value);
  231. }else{
  232. HashMap<String, String> name1Data = new HashMap<>();
  233. name1Data.put(name2Value,value);
  234. dataMap.put(name1Value,name1Data);
  235. }
  236. }
  237. for(int i =0; i<legend.size(); i++){
  238. yAxis.add(new ArrayList<String>());
  239. }
  240. Set<String> keys = dataMap.keySet();
  241. for(String key:keys){
  242. xAxis.add(key);
  243. HashMap<String, String> map = dataMap.get(key);
  244. for(int i =0; i<legend.size(); i++){
  245. List<String> data = yAxis.get(i);
  246. if(StringUtil.isNotEmpty(map.get(legend.get(i)))){
  247. data.add(map.get(legend.get(i)));
  248. }else{
  249. data.add("0");
  250. }
  251. }
  252. }
  253. System.out.println();
  254. Map<String, Object> resultMap = new HashMap<>();
  255. resultMap.put("xAxis",xAxis);
  256. resultMap.put("yAxis",yAxis);
  257. resultMap.put("legend",legend);
  258. return R.ok().put("data", resultMap);
  259. }
  260. /**
  261. * 柱状图统计双列
  262. * @return
  263. */
  264. @RequestMapping("/barCountTwo")
  265. public R barCountTwo(@RequestParam Map<String,Object> params) {
  266. logger.debug("柱状图统计双列:,,Controller:{},,params:{}",this.getClass().getName(),params);
  267. List<Map<String, Object>> result = commonService.barCountTwo(params);
  268. List<String> xAxis = new ArrayList<>();//报表x轴
  269. List<List<String>> yAxis = new ArrayList<>();//y轴
  270. List<String> legend = new ArrayList<>();//标题
  271. Map<String, HashMap<String, String>> dataMap = new LinkedHashMap<>();
  272. for(Map<String, Object> map :result){
  273. String name1Value = String.valueOf(map.get("name1"));
  274. String name2Value = String.valueOf(map.get("name2"));
  275. String value = String.valueOf(map.get("value"));
  276. if(!legend.contains(name2Value)){
  277. legend.add(name2Value);//添加完成后 就是最全的第二列的类型
  278. }
  279. if(dataMap.containsKey(name1Value)){
  280. dataMap.get(name1Value).put(name2Value,value);
  281. }else{
  282. HashMap<String, String> name1Data = new HashMap<>();
  283. name1Data.put(name2Value,value);
  284. dataMap.put(name1Value,name1Data);
  285. }
  286. }
  287. for(int i =0; i<legend.size(); i++){
  288. yAxis.add(new ArrayList<String>());
  289. }
  290. Set<String> keys = dataMap.keySet();
  291. for(String key:keys){
  292. xAxis.add(key);
  293. HashMap<String, String> map = dataMap.get(key);
  294. for(int i =0; i<legend.size(); i++){
  295. List<String> data = yAxis.get(i);
  296. if(StringUtil.isNotEmpty(map.get(legend.get(i)))){
  297. data.add(map.get(legend.get(i)));
  298. }else{
  299. data.add("0");
  300. }
  301. }
  302. }
  303. System.out.println();
  304. Map<String, Object> resultMap = new HashMap<>();
  305. resultMap.put("xAxis",xAxis);
  306. resultMap.put("yAxis",yAxis);
  307. resultMap.put("legend",legend);
  308. return R.ok().put("data", resultMap);
  309. }
  310. /**
  311. tableName 查询表
  312. condition1 条件1
  313. condition1Value 条件1
  314. average 计算平均评分
  315. 取值
  316. 有值 Number(res.data.value.toFixed(1))
  317. 无值 if(res.data){}
  318. * */
  319. @IgnoreAuth
  320. @RequestMapping("/queryScore")
  321. public R queryScore(@RequestParam Map<String, Object> params) {
  322. logger.debug("queryScore:,,Controller:{},,params:{}",this.getClass().getName(),params);
  323. Map<String, Object> queryScore = commonService.queryScore(params);
  324. return R.ok().put("data", queryScore);
  325. }
  326. /**
  327. * 查询字典表的分组统计总条数
  328. * tableName 表名
  329. * groupColumn 分组字段
  330. * @return
  331. */
  332. @RequestMapping("/newSelectGroupCount")
  333. public R newSelectGroupCount(@RequestParam Map<String,Object> params) {
  334. logger.debug("newSelectGroupCount:,,Controller:{},,params:{}",this.getClass().getName(),params);
  335. List<Map<String, Object>> result = commonService.newSelectGroupCount(params);
  336. return R.ok().put("data", result);
  337. }
  338. /**
  339. * 查询字典表的分组求和
  340. * tableName 表名
  341. * groupColumn 分组字段
  342. * sumCloum 统计字段
  343. * @return
  344. */
  345. @RequestMapping("/newSelectGroupSum")
  346. public R newSelectGroupSum(@RequestParam Map<String,Object> params) {
  347. logger.debug("newSelectGroupSum:,,Controller:{},,params:{}",this.getClass().getName(),params);
  348. List<Map<String, Object>> result = commonService.newSelectGroupSum(params);
  349. return R.ok().put("data", result);
  350. }
  351. /**
  352. * 柱状图求和 老的
  353. */
  354. @RequestMapping("/barSum")
  355. public R barSum(@RequestParam Map<String,Object> params) {
  356. logger.debug("barSum方法:,,Controller:{},,params:{}",this.getClass().getName(), com.alibaba.fastjson.JSONObject.toJSONString(params));
  357. Boolean isJoinTableFlag = false;//是否有级联表相关
  358. String one = "";//第一优先
  359. String two = "";//第二优先
  360. //处理thisTable和joinTable 处理内容是把json字符串转为Map并把带有,的切割为数组
  361. //当前表
  362. Map<String,Object> thisTable = JSON.parseObject(String.valueOf(params.get("thisTable")),Map.class);
  363. params.put("thisTable",thisTable);
  364. //级联表
  365. String joinTableString = String.valueOf(params.get("joinTable"));
  366. if(StringUtil.isNotEmpty(joinTableString)) {
  367. Map<String, Object> joinTable = JSON.parseObject(joinTableString, Map.class);
  368. params.put("joinTable", joinTable);
  369. isJoinTableFlag = true;
  370. }
  371. if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("date")))){//当前表日期
  372. thisTable.put("date",String.valueOf(thisTable.get("date")).split(","));
  373. one = "thisDate0";
  374. }
  375. if(isJoinTableFlag){//级联表日期
  376. Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
  377. if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("date")))){
  378. joinTable.put("date",String.valueOf(joinTable.get("date")).split(","));
  379. if(StringUtil.isEmpty(one)){
  380. one ="joinDate0";
  381. }else{
  382. if(StringUtil.isEmpty(two)){
  383. two ="joinDate0";
  384. }
  385. }
  386. }
  387. }
  388. if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("string")))){//当前表字符串
  389. thisTable.put("string",String.valueOf(thisTable.get("string")).split(","));
  390. if(StringUtil.isEmpty(one)){
  391. one ="thisString0";
  392. }else{
  393. if(StringUtil.isEmpty(two)){
  394. two ="thisString0";
  395. }
  396. }
  397. }
  398. if(isJoinTableFlag){//级联表字符串
  399. Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
  400. if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("string")))){
  401. joinTable.put("string",String.valueOf(joinTable.get("string")).split(","));
  402. if(StringUtil.isEmpty(one)){
  403. one ="joinString0";
  404. }else{
  405. if(StringUtil.isEmpty(two)){
  406. two ="joinString0";
  407. }
  408. }
  409. }
  410. }
  411. if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("types")))){//当前表类型
  412. thisTable.put("types",String.valueOf(thisTable.get("types")).split(","));
  413. if(StringUtil.isEmpty(one)){
  414. one ="thisTypes0";
  415. }else{
  416. if(StringUtil.isEmpty(two)){
  417. two ="thisTypes0";
  418. }
  419. }
  420. }
  421. if(isJoinTableFlag){//级联表类型
  422. Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
  423. if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("types")))){
  424. joinTable.put("types",String.valueOf(joinTable.get("types")).split(","));
  425. if(StringUtil.isEmpty(one)){
  426. one ="joinTypes0";
  427. }else{
  428. if(StringUtil.isEmpty(two)){
  429. two ="joinTypes0";
  430. }
  431. }
  432. }
  433. }
  434. List<Map<String, Object>> result = commonService.barSum(params);
  435. List<String> xAxis = new ArrayList<>();//报表x轴
  436. List<List<String>> yAxis = new ArrayList<>();//y轴
  437. List<String> legend = new ArrayList<>();//标题
  438. if(StringUtil.isEmpty(two)){//不包含第二列
  439. List<String> yAxis0 = new ArrayList<>();
  440. yAxis.add(yAxis0);
  441. legend.add("");
  442. for(Map<String, Object> map :result){
  443. String oneValue = String.valueOf(map.get(one));
  444. String value = String.valueOf(map.get("value"));
  445. xAxis.add(oneValue);
  446. yAxis0.add(value);
  447. }
  448. }else{//包含第二列
  449. Map<String, HashMap<String, String>> dataMap = new LinkedHashMap<>();
  450. if(StringUtil.isNotEmpty(two)){
  451. for(Map<String, Object> map :result){
  452. String oneValue = String.valueOf(map.get(one));
  453. String twoValue = String.valueOf(map.get(two));
  454. String value = String.valueOf(map.get("value"));
  455. if(!legend.contains(twoValue)){
  456. legend.add(twoValue);//添加完成后 就是最全的第二列的类型
  457. }
  458. if(dataMap.containsKey(oneValue)){
  459. dataMap.get(oneValue).put(twoValue,value);
  460. }else{
  461. HashMap<String, String> oneData = new HashMap<>();
  462. oneData.put(twoValue,value);
  463. dataMap.put(oneValue,oneData);
  464. }
  465. }
  466. }
  467. for(int i =0; i<legend.size(); i++){
  468. yAxis.add(new ArrayList<String>());
  469. }
  470. Set<String> keys = dataMap.keySet();
  471. for(String key:keys){
  472. xAxis.add(key);
  473. HashMap<String, String> map = dataMap.get(key);
  474. for(int i =0; i<legend.size(); i++){
  475. List<String> data = yAxis.get(i);
  476. if(StringUtil.isNotEmpty(map.get(legend.get(i)))){
  477. data.add(map.get(legend.get(i)));
  478. }else{
  479. data.add("0");
  480. }
  481. }
  482. }
  483. System.out.println();
  484. }
  485. Map<String, Object> resultMap = new HashMap<>();
  486. resultMap.put("xAxis",xAxis);
  487. resultMap.put("yAxis",yAxis);
  488. resultMap.put("legend",legend);
  489. return R.ok().put("data", resultMap);
  490. }
  491. /**
  492. * 柱状图统计 老的
  493. */
  494. @RequestMapping("/barCount")
  495. public R barCount(@RequestParam Map<String,Object> params) {
  496. logger.debug("barCount方法:,,Controller:{},,params:{}",this.getClass().getName(), com.alibaba.fastjson.JSONObject.toJSONString(params));
  497. Boolean isJoinTableFlag = false;//是否有级联表相关
  498. String one = "";//第一优先
  499. String two = "";//第二优先
  500. //处理thisTable和joinTable 处理内容是把json字符串转为Map并把带有,的切割为数组
  501. //当前表
  502. Map<String,Object> thisTable = JSON.parseObject(String.valueOf(params.get("thisTable")),Map.class);
  503. params.put("thisTable",thisTable);
  504. //级联表
  505. String joinTableString = String.valueOf(params.get("joinTable"));
  506. if(StringUtil.isNotEmpty(joinTableString)) {
  507. Map<String, Object> joinTable = JSON.parseObject(joinTableString, Map.class);
  508. params.put("joinTable", joinTable);
  509. isJoinTableFlag = true;
  510. }
  511. if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("date")))){//当前表日期
  512. thisTable.put("date",String.valueOf(thisTable.get("date")).split(","));
  513. one = "thisDate0";
  514. }
  515. if(isJoinTableFlag){//级联表日期
  516. Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
  517. if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("date")))){
  518. joinTable.put("date",String.valueOf(joinTable.get("date")).split(","));
  519. if(StringUtil.isEmpty(one)){
  520. one ="joinDate0";
  521. }else{
  522. if(StringUtil.isEmpty(two)){
  523. two ="joinDate0";
  524. }
  525. }
  526. }
  527. }
  528. if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("string")))){//当前表字符串
  529. thisTable.put("string",String.valueOf(thisTable.get("string")).split(","));
  530. if(StringUtil.isEmpty(one)){
  531. one ="thisString0";
  532. }else{
  533. if(StringUtil.isEmpty(two)){
  534. two ="thisString0";
  535. }
  536. }
  537. }
  538. if(isJoinTableFlag){//级联表字符串
  539. Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
  540. if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("string")))){
  541. joinTable.put("string",String.valueOf(joinTable.get("string")).split(","));
  542. if(StringUtil.isEmpty(one)){
  543. one ="joinString0";
  544. }else{
  545. if(StringUtil.isEmpty(two)){
  546. two ="joinString0";
  547. }
  548. }
  549. }
  550. }
  551. if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("types")))){//当前表类型
  552. thisTable.put("types",String.valueOf(thisTable.get("types")).split(","));
  553. if(StringUtil.isEmpty(one)){
  554. one ="thisTypes0";
  555. }else{
  556. if(StringUtil.isEmpty(two)){
  557. two ="thisTypes0";
  558. }
  559. }
  560. }
  561. if(isJoinTableFlag){//级联表类型
  562. Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
  563. if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("types")))){
  564. joinTable.put("types",String.valueOf(joinTable.get("types")).split(","));
  565. if(StringUtil.isEmpty(one)){
  566. one ="joinTypes0";
  567. }else{
  568. if(StringUtil.isEmpty(two)){
  569. two ="joinTypes0";
  570. }
  571. }
  572. }
  573. }
  574. List<Map<String, Object>> result = commonService.barCount(params);
  575. List<String> xAxis = new ArrayList<>();//报表x轴
  576. List<List<String>> yAxis = new ArrayList<>();//y轴
  577. List<String> legend = new ArrayList<>();//标题
  578. if(StringUtil.isEmpty(two)){//不包含第二列
  579. List<String> yAxis0 = new ArrayList<>();
  580. yAxis.add(yAxis0);
  581. legend.add("");
  582. for(Map<String, Object> map :result){
  583. String oneValue = String.valueOf(map.get(one));
  584. String value = String.valueOf(map.get("value"));
  585. xAxis.add(oneValue);
  586. yAxis0.add(value);
  587. }
  588. }else{//包含第二列
  589. Map<String, HashMap<String, String>> dataMap = new LinkedHashMap<>();
  590. if(StringUtil.isNotEmpty(two)){
  591. for(Map<String, Object> map :result){
  592. String oneValue = String.valueOf(map.get(one));
  593. String twoValue = String.valueOf(map.get(two));
  594. String value = String.valueOf(map.get("value"));
  595. if(!legend.contains(twoValue)){
  596. legend.add(twoValue);//添加完成后 就是最全的第二列的类型
  597. }
  598. if(dataMap.containsKey(oneValue)){
  599. dataMap.get(oneValue).put(twoValue,value);
  600. }else{
  601. HashMap<String, String> oneData = new HashMap<>();
  602. oneData.put(twoValue,value);
  603. dataMap.put(oneValue,oneData);
  604. }
  605. }
  606. }
  607. for(int i =0; i<legend.size(); i++){
  608. yAxis.add(new ArrayList<String>());
  609. }
  610. Set<String> keys = dataMap.keySet();
  611. for(String key:keys){
  612. xAxis.add(key);
  613. HashMap<String, String> map = dataMap.get(key);
  614. for(int i =0; i<legend.size(); i++){
  615. List<String> data = yAxis.get(i);
  616. if(StringUtil.isNotEmpty(map.get(legend.get(i)))){
  617. data.add(map.get(legend.get(i)));
  618. }else{
  619. data.add("0");
  620. }
  621. }
  622. }
  623. System.out.println();
  624. }
  625. Map<String, Object> resultMap = new HashMap<>();
  626. resultMap.put("xAxis",xAxis);
  627. resultMap.put("yAxis",yAxis);
  628. resultMap.put("legend",legend);
  629. return R.ok().put("data", resultMap);
  630. }
  631. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/57248?site
推荐阅读
相关标签
  

闽ICP备14008679号