当前位置:   article > 正文

基于SSM实现个性化健康饮食推荐系统_基于ssm框架健康饮食推荐系统

基于ssm框架健康饮食推荐系统

项目编号:BS-XX-123

一,项目简介

本项目基于SSM框架开发实现了一针对个人体质情况进行日常食谱推荐的信息化管理系统。系统分为前端信息展示页面和后台信息管理操作,用户登陆前端系统,可以查看相关饮食信息,热点资讯等,并可以对个人的体质信息进行相应的管理操作,也可以根据系统推荐的饮食方案来进行查看,并可以在线查看美食介绍的相关视频。后台管理操作主要包含用户管理、饮食方案管理,用户饮食方案定制,资讯信息管理,反馈管理,轮插图管理等相关功能。系统整个体功能完整,结构清晰,适合做毕业设计和课程设计使用。

二,环境介绍

语言环境:Java:  jdk1.8

数据库:Mysql: mysql5.7

应用服务器:Tomcat:  tomcat8.5.31

开发工具:IDEA或eclipse

后台开发技术:SSM框架

前端开发技术:JSP+BootStrap+Jquery+Echart等

三,系统展示

前端页面功能展示:

健康饮食

饮食详情:可在线播放美食介绍视频

在线反馈

个人中心

个人后台管理

管理员登陆操作:

用户管理

饮食分类管理:

健康饮食管理

饮食方案推荐:

意见反馈管理

轮播图管理

资讯管理

四,核心代码展示

  1. package com.controller;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.ArrayList;
  7. import java.util.Calendar;
  8. import java.util.Date;
  9. import java.util.HashMap;
  10. import java.util.List;
  11. import java.util.Map;
  12. import javax.servlet.http.HttpServletRequest;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.json.JSONObject;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.web.bind.annotation.PathVariable;
  17. import org.springframework.web.bind.annotation.RequestBody;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RequestParam;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import com.annotation.IgnoreAuth;
  22. import com.baidu.aip.face.AipFace;
  23. import com.baidu.aip.face.MatchRequest;
  24. import com.baidu.aip.util.Base64Util;
  25. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  26. import com.entity.ConfigEntity;
  27. import com.service.CommonService;
  28. import com.service.ConfigService;
  29. import com.utils.BaiduUtil;
  30. import com.utils.FileUtil;
  31. import com.utils.R;
  32. /**
  33. * 通用接口
  34. */
  35. @RestController
  36. public class CommonController{
  37. @Autowired
  38. private CommonService commonService;
  39. private static AipFace client = null;
  40. @Autowired
  41. private ConfigService configService;
  42. /**
  43. * 获取table表中的column列表(联动接口)
  44. * @param table
  45. * @param column
  46. * @return
  47. */
  48. @RequestMapping("/option/{tableName}/{columnName}")
  49. @IgnoreAuth
  50. public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,String level,String parent) {
  51. Map<String, Object> params = new HashMap<String, Object>();
  52. params.put("table", tableName);
  53. params.put("column", columnName);
  54. if(StringUtils.isNotBlank(level)) {
  55. params.put("level", level);
  56. }
  57. if(StringUtils.isNotBlank(parent)) {
  58. params.put("parent", parent);
  59. }
  60. List<String> data = commonService.getOption(params);
  61. return R.ok().put("data", data);
  62. }
  63. /**
  64. * 根据table中的column获取单条记录
  65. * @param table
  66. * @param column
  67. * @return
  68. */
  69. @RequestMapping("/follow/{tableName}/{columnName}")
  70. @IgnoreAuth
  71. public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) {
  72. Map<String, Object> params = new HashMap<String, Object>();
  73. params.put("table", tableName);
  74. params.put("column", columnName);
  75. params.put("columnValue", columnValue);
  76. Map<String, Object> result = commonService.getFollowByOption(params);
  77. return R.ok().put("data", result);
  78. }
  79. /**
  80. * 修改table表的sfsh状态
  81. * @param table
  82. * @param map
  83. * @return
  84. */
  85. @RequestMapping("/sh/{tableName}")
  86. public R sh(@PathVariable("tableName") String tableName, @RequestBody Map<String, Object> map) {
  87. map.put("table", tableName);
  88. commonService.sh(map);
  89. return R.ok();
  90. }
  91. /**
  92. * 获取需要提醒的记录数
  93. * @param tableName
  94. * @param columnName
  95. * @param type 1:数字 2:日期
  96. * @param map
  97. * @return
  98. */
  99. @RequestMapping("/remind/{tableName}/{columnName}/{type}")
  100. @IgnoreAuth
  101. public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
  102. @PathVariable("type") String type,@RequestParam Map<String, Object> map) {
  103. map.put("table", tableName);
  104. map.put("column", columnName);
  105. map.put("type", type);
  106. if(type.equals("2")) {
  107. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  108. Calendar c = Calendar.getInstance();
  109. Date remindStartDate = null;
  110. Date remindEndDate = null;
  111. if(map.get("remindstart")!=null) {
  112. Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
  113. c.setTime(new Date());
  114. c.add(Calendar.DAY_OF_MONTH,remindStart);
  115. remindStartDate = c.getTime();
  116. map.put("remindstart", sdf.format(remindStartDate));
  117. }
  118. if(map.get("remindend")!=null) {
  119. Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
  120. c.setTime(new Date());
  121. c.add(Calendar.DAY_OF_MONTH,remindEnd);
  122. remindEndDate = c.getTime();
  123. map.put("remindend", sdf.format(remindEndDate));
  124. }
  125. }
  126. int count = commonService.remindCount(map);
  127. return R.ok().put("count", count);
  128. }
  129. /**
  130. * 单列求和
  131. */
  132. @RequestMapping("/cal/{tableName}/{columnName}")
  133. @IgnoreAuth
  134. public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
  135. Map<String, Object> params = new HashMap<String, Object>();
  136. params.put("table", tableName);
  137. params.put("column", columnName);
  138. Map<String, Object> result = commonService.selectCal(params);
  139. return R.ok().put("data", result);
  140. }
  141. /**
  142. * 分组统计
  143. */
  144. @RequestMapping("/group/{tableName}/{columnName}")
  145. @IgnoreAuth
  146. public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
  147. Map<String, Object> params = new HashMap<String, Object>();
  148. params.put("table", tableName);
  149. params.put("column", columnName);
  150. List<Map<String, Object>> result = commonService.selectGroup(params);
  151. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  152. for(Map<String, Object> m : result) {
  153. for(String k : m.keySet()) {
  154. if(m.get(k) instanceof Date) {
  155. m.put(k, sdf.format((Date)m.get(k)));
  156. }
  157. }
  158. }
  159. return R.ok().put("data", result);
  160. }
  161. /**
  162. * (按值统计)
  163. */
  164. @RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}")
  165. @IgnoreAuth
  166. public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) {
  167. Map<String, Object> params = new HashMap<String, Object>();
  168. params.put("table", tableName);
  169. params.put("xColumn", xColumnName);
  170. params.put("yColumn", yColumnName);
  171. List<Map<String, Object>> result = commonService.selectValue(params);
  172. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  173. for(Map<String, Object> m : result) {
  174. for(String k : m.keySet()) {
  175. if(m.get(k) instanceof Date) {
  176. m.put(k, sdf.format((Date)m.get(k)));
  177. }
  178. }
  179. }
  180. return R.ok().put("data", result);
  181. }
  182. /**
  183. * (按值统计)时间统计类型
  184. */
  185. @IgnoreAuth
  186. @RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}/{timeStatType}")
  187. public R valueDay(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType) {
  188. Map<String, Object> params = new HashMap<String, Object>();
  189. params.put("table", tableName);
  190. params.put("xColumn", xColumnName);
  191. params.put("yColumn", yColumnName);
  192. params.put("timeStatType", timeStatType);
  193. List<Map<String, Object>> result = commonService.selectTimeStatValue(params);
  194. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  195. for(Map<String, Object> m : result) {
  196. for(String k : m.keySet()) {
  197. if(m.get(k) instanceof Date) {
  198. m.put(k, sdf.format((Date)m.get(k)));
  199. }
  200. }
  201. }
  202. return R.ok().put("data", result);
  203. }
  204. /**
  205. * 人脸比对
  206. *
  207. * @param face1 人脸1
  208. * @param face2 人脸2
  209. * @return
  210. */
  211. @RequestMapping("/matchFace")
  212. @IgnoreAuth
  213. public R matchFace(String face1, String face2,HttpServletRequest request) {
  214. if(client==null) {
  215. /*String AppID = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "AppID")).getValue();*/
  216. String APIKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "APIKey")).getValue();
  217. String SecretKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "SecretKey")).getValue();
  218. String token = BaiduUtil.getAuth(APIKey, SecretKey);
  219. if(token==null) {
  220. return R.error("请在配置管理中正确配置APIKey和SecretKey");
  221. }
  222. client = new AipFace(null, APIKey, SecretKey);
  223. client.setConnectionTimeoutInMillis(2000);
  224. client.setSocketTimeoutInMillis(60000);
  225. }
  226. JSONObject res = null;
  227. try {
  228. File file1 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face1);
  229. File file2 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face2);
  230. String img1 = Base64Util.encode(FileUtil.FileToByte(file1));
  231. String img2 = Base64Util.encode(FileUtil.FileToByte(file2));
  232. MatchRequest req1 = new MatchRequest(img1, "BASE64");
  233. MatchRequest req2 = new MatchRequest(img2, "BASE64");
  234. ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
  235. requests.add(req1);
  236. requests.add(req2);
  237. res = client.match(requests);
  238. System.out.println(res.get("result"));
  239. } catch (FileNotFoundException e) {
  240. e.printStackTrace();
  241. return R.error("文件不存在");
  242. } catch (IOException e) {
  243. e.printStackTrace();
  244. }
  245. return R.ok().put("score", com.alibaba.fastjson.JSONObject.parse(res.getJSONObject("result").get("score").toString()));
  246. }
  247. }

  1. package com.controller;
  2. import java.util.Arrays;
  3. import java.util.Map;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.web.bind.annotation.PathVariable;
  6. import org.springframework.web.bind.annotation.PostMapping;
  7. import org.springframework.web.bind.annotation.RequestBody;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestParam;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import com.annotation.IgnoreAuth;
  12. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  13. import com.entity.ConfigEntity;
  14. import com.service.ConfigService;
  15. import com.utils.MPUtil;
  16. import com.utils.PageUtils;
  17. import com.utils.R;
  18. import com.utils.ValidatorUtils;
  19. /**
  20. * 登录相关
  21. */
  22. @RequestMapping("config")
  23. @RestController
  24. public class ConfigController{
  25. @Autowired
  26. private ConfigService configService;
  27. /**
  28. * 列表
  29. */
  30. @RequestMapping("/page")
  31. public R page(@RequestParam Map<String, Object> params,ConfigEntity config){
  32. EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>();
  33. PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params));
  34. return R.ok().put("data", page);
  35. }
  36. /**
  37. * 列表
  38. */
  39. @IgnoreAuth
  40. @RequestMapping("/list")
  41. public R list(@RequestParam Map<String, Object> params,ConfigEntity config){
  42. EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>();
  43. PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params));
  44. return R.ok().put("data", page);
  45. }
  46. /**
  47. * 信息
  48. */
  49. @RequestMapping("/info/{id}")
  50. public R info(@PathVariable("id") String id){
  51. ConfigEntity config = configService.selectById(id);
  52. return R.ok().put("data", config);
  53. }
  54. /**
  55. * 详情
  56. */
  57. @IgnoreAuth
  58. @RequestMapping("/detail/{id}")
  59. public R detail(@PathVariable("id") String id){
  60. ConfigEntity config = configService.selectById(id);
  61. return R.ok().put("data", config);
  62. }
  63. /**
  64. * 根据name获取信息
  65. */
  66. @RequestMapping("/info")
  67. public R infoByName(@RequestParam String name){
  68. ConfigEntity config = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
  69. return R.ok().put("data", config);
  70. }
  71. /**
  72. * 保存
  73. */
  74. @PostMapping("/save")
  75. public R save(@RequestBody ConfigEntity config){
  76. // ValidatorUtils.validateEntity(config);
  77. configService.insert(config);
  78. return R.ok();
  79. }
  80. /**
  81. * 修改
  82. */
  83. @RequestMapping("/update")
  84. public R update(@RequestBody ConfigEntity config){
  85. // ValidatorUtils.validateEntity(config);
  86. configService.updateById(config);//全部更新
  87. return R.ok();
  88. }
  89. /**
  90. * 删除
  91. */
  92. @RequestMapping("/delete")
  93. public R delete(@RequestBody Long[] ids){
  94. configService.deleteBatchIds(Arrays.asList(ids));
  95. return R.ok();
  96. }
  97. }

  1. package com.controller;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.Date;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import org.apache.commons.io.FileUtils;
  8. import org.apache.commons.io.IOUtils;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestParam;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import org.springframework.web.multipart.MultipartFile;
  15. import com.annotation.IgnoreAuth;
  16. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  17. import com.entity.ConfigEntity;
  18. import com.entity.EIException;
  19. import com.service.ConfigService;
  20. import com.utils.R;
  21. /**
  22. * 上传文件映射表
  23. */
  24. @RestController
  25. @RequestMapping("file")
  26. @SuppressWarnings({"unchecked","rawtypes"})
  27. public class FileController{
  28. @Autowired
  29. private ConfigService configService;
  30. /**
  31. * 上传文件
  32. */
  33. @RequestMapping("/upload")
  34. public R upload(@RequestParam("file") MultipartFile file, String type,HttpServletRequest request) throws Exception {
  35. if (file.isEmpty()) {
  36. throw new EIException("上传文件不能为空");
  37. }
  38. String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
  39. String fileName = new Date().getTime()+"."+fileExt;
  40. File dest = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName);
  41. file.transferTo(dest);
  42. /**
  43. * 如果使用idea或者eclipse重启项目,发现之前上传的图片或者文件丢失,将下面一行代码注释打开
  44. * 请将以下的"D:\\ssmpiv99\\src\\main\\webapp\\upload"替换成你本地项目的upload路径,
  45. * 并且项目路径不能存在中文、空格等特殊字符
  46. */
  47. //FileUtils.copyFile(dest, new File("D:\\ssmpiv99\\src\\main\\webapp\\upload"+"/"+fileName)); /**修改了路径以后请将该行最前面的//注释去掉**/
  48. if(StringUtils.isNotBlank(type) && type.equals("1")) {
  49. ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
  50. if(configEntity==null) {
  51. configEntity = new ConfigEntity();
  52. configEntity.setName("faceFile");
  53. configEntity.setValue(fileName);
  54. } else {
  55. configEntity.setValue(fileName);
  56. }
  57. configService.insertOrUpdate(configEntity);
  58. }
  59. return R.ok().put("file", fileName);
  60. }
  61. /**
  62. * 下载文件
  63. */
  64. @IgnoreAuth
  65. @RequestMapping("/download")
  66. public void download(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) {
  67. try {
  68. File file = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName);
  69. if (file.exists()) {
  70. response.reset();
  71. response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName+"\"");
  72. response.setHeader("Cache-Control", "no-cache");
  73. response.setHeader("Access-Control-Allow-Credentials", "true");
  74. response.setContentType("application/octet-stream; charset=UTF-8");
  75. IOUtils.write(FileUtils.readFileToByteArray(file), response.getOutputStream());
  76. }
  77. } catch (IOException e) {
  78. e.printStackTrace();
  79. }
  80. }
  81. }

五,项目总结

   整个项目功能结构完整清晰,前后端交互流流畅,系统运行无BUG,适合做毕业设计使用。

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

闽ICP备14008679号