大家好!我是程序员一帆,感谢您阅读本文,欢迎一键三连哦。

💞当前专栏:Java毕业设计

精彩专栏推荐👇🏻👇🏻👇🏻

🎀 Python毕业设计
🌎微信小程序毕业设计

开发运行环境

  • 开发语言:Java
  • 框架:springboot
  • JDK版本:JDK1.8
  • 服务器:tomcat7
  • 数据库:mysql 5.7
  • 数据库工具:Navicat12
  • 开发软件:eclipse/myeclipse/idea
  • Maven包:Maven3.3.9
  • 浏览器:谷歌浏览器

演示视频

springboot基于深度学习的饮食计划推荐与交流分享

论文目录

【如需全文或源码请按文末获取联系】
在这里插入图片描述
在这里插入图片描述

一、项目简介

该平台以Java语言为基础,采用Spring Boot框架构建,结合Spark强大的数据处理能力以及决策树算法的精准预测,为用户提供全方位的饮食健康管理服务。
用户在主页可快速浏览平台功能。通过注册登录进入个人中心,完善健康数据,如身高、体重、运动习惯等,平台据此生成个性化的饮食计划。在食物信息模块,用户能查询各类食物的营养成分,还能通过食物类别预测功能,借助深度学习算法,快速识别食物类别。饮食计划数据模块记录用户每日饮食执行情况,便于回顾调整。健康食谱提供丰富多样且营养均衡的食谱,满足不同口味需求。营养建议和健康目标模块,根据用户健康数据和饮食执行情况,动态调整,助力用户达成健康目标。排行榜则激发用户积极性,增加互动性。MySQL数据库保障数据安全稳定存储,系统管理模块实现后台高效运维。

二、系统设计

2.1软件功能模块设计

在本系统的功能结构设计中,我们采用了模块化的方法,将整个系统划分为两个主要部分:管理员模块和用户模块。
在这里插入图片描述

2.2数据库设计

本系统的整体E-R实体属性如图4-2所示。
在这里插入图片描述

三、系统项目部分截图

3.1系统前台功能实现

该平台的前台功能丰富多样,首页为用户提供了平台的整体概览和导航入口。用户可以在“食物信息”模块查询各类食物的营养成分和健康价值,获取饮食知识。在“饮食计划”模块,用户会收到根据自身健康数据生成的个性化饮食建议,帮助合理安排每日饮食。“健康食谱”提供丰富多样的健康菜谱,满足不同口味需求。“排行榜”展示用户健康成就,激发参与热情。“科普知识”模块则提供健康饮食相关的科普文章,提升用户健康意识。系统首页页面如图5-1所示:
在这里插入图片描述

3.2管理员功能实现

管理员主页面作为系统控制中心,提供全面的管理功能。页面通常详细列出所有管理模块,包括主页、用户、食物信息、饮食计划、健康数据、营养建议、健康目标、健康食谱、排行榜、饮食计划数据、食物类别预测、系统管理、个人中心等,确保管理员能够高效地进行日常管理工作。整个页面布局清晰,功能模块化,便于管理员快速定位和操作。管理员主页界面如图5-4所示:
在这里插入图片描述

管理员在食物信息模块中拥有强大的管理权限。点击进入后,可通过输入食物名称、烹饪时间、食材或烹饪方式等信息进行精准查询,快速定位所需食物。查询结果页面展示食物列表,管理员可在此添加新食物条目,完善平台食物数据库;也可删除不符合要求或过时的食物信息,保持数据的准确性和时效性。管理员还能查看每种食物的详细信息,包括营养成分、烹饪步骤等,并可对这些详细内容进行修改或删除操作,确保平台提供的食物信息始终准确、可靠且符合用户需求。食物信息界面如图5-5所示:
在这里插入图片描述
看板为管理员提供了全面的可视化数据概览。通过食物词云直观展示热门食物,食物类别统计呈现各类食物占比,烹饪难度统计帮助了解用户偏好。饮食计划数据展示计划执行情况,碳水化合物、热量、蛋白质、脂肪统计为营养分析提供依据,预测食物类别则显示模型预测结果。这些数据助力管理员精准把握平台运营状况,优化内容与服务。看板界面如图5-11所示:
在这里插入图片描述

四、部分核心代码

package com.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.*;
import java.lang.*;
import java.math.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import com.utils.ValidatorUtils;
import com.utils.DeSensUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth;

import com.entity.DietplanEntity;
import com.entity.view.DietplanView;

import com.service.DietplanService;
import com.service.TokenService;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.MPUtil;
import com.utils.MapUtils;
import com.utils.CommonUtil;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.web.multipart.MultipartFile;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

/**
 * 饮食计划数据
 * 后端接口
 * @author 
 * @email 
 * @date 2025-03-21 08:53:19
 */
@RestController
@RequestMapping("/dietplan")
public class DietplanController {
    @Autowired
    private DietplanService dietplanService;






    



    /**
     * 后台列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params,DietplanEntity dietplan,
		HttpServletRequest request){
        //设置查询条件
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();


        //查询结果
		PageUtils page = dietplanService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, dietplan), params), params));
        Map<String, String> deSens = new HashMap<>();
        //给需要脱敏的字段脱敏
        DeSensUtil.desensitize(page,deSens);
        return R.ok().put("data", page);
    }
    
    /**
     * 前台列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,DietplanEntity dietplan, 
		HttpServletRequest request){
        //设置查询条件
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();

        //查询结果
		PageUtils page = dietplanService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, dietplan), params), params));
        Map<String, String> deSens = new HashMap<>();
        //给需要脱敏的字段脱敏
        DeSensUtil.desensitize(page,deSens);
        return R.ok().put("data", page);
    }



	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( DietplanEntity dietplan){
       	EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
      	ew.allEq(MPUtil.allEQMapPre( dietplan, "dietplan")); 
        return R.ok().put("data", dietplanService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(DietplanEntity dietplan){
        EntityWrapper< DietplanEntity> ew = new EntityWrapper< DietplanEntity>();
 		ew.allEq(MPUtil.allEQMapPre( dietplan, "dietplan")); 
		DietplanView dietplanView =  dietplanService.selectView(ew);
		return R.ok("查询饮食计划数据成功").put("data", dietplanView);
    }
	
    /**
     * 后台详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        DietplanEntity dietplan = dietplanService.selectById(id);
        Map<String, String> deSens = new HashMap<>();
        //给需要脱敏的字段脱敏
        DeSensUtil.desensitize(dietplan,deSens);
        return R.ok().put("data", dietplan);
    }

    /**
     * 前台详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        DietplanEntity dietplan = dietplanService.selectById(id);
        Map<String, String> deSens = new HashMap<>();
        //给需要脱敏的字段脱敏
        DeSensUtil.desensitize(dietplan,deSens);
        return R.ok().put("data", dietplan);
    }
    



    /**
     * 后台保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DietplanEntity dietplan, HttpServletRequest request){
        //ValidatorUtils.validateEntity(dietplan);
        dietplanService.insert(dietplan);
        return R.ok().put("data",dietplan.getId());
    }
    
    /**
     * 前台保存
     */
    @RequestMapping("/add")
    public R add(@RequestBody DietplanEntity dietplan, HttpServletRequest request){
        //ValidatorUtils.validateEntity(dietplan);
        dietplanService.insert(dietplan);
        return R.ok().put("data",dietplan.getId());
    }





    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    public R update(@RequestBody DietplanEntity dietplan, HttpServletRequest request){
        //ValidatorUtils.validateEntity(dietplan);
        //全部更新
        dietplanService.updateById(dietplan);
        return R.ok();
    }



    

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        dietplanService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
    





    /**
    * 文件导入
    */
    @RequestMapping("/importExcel")
    public R importExcel(@RequestParam("file") MultipartFile file){
        try {
            //获取输入流
            InputStream inputStream = file.getInputStream();
            //创建读取工作簿
            Workbook workbook = WorkbookFactory.create(inputStream);
            //获取工作表
            Sheet sheet = workbook.getSheetAt(0);
            //获取总行
            int rowTotal=sheet.getPhysicalNumberOfRows();
            if(rowTotal > 1) {
                //获取单元格
                for (int i = 1; i < rowTotal; i++) {
                    Row row = sheet.getRow(i);
                    DietplanEntity dietplanEntity =new DietplanEntity();
                    dietplanEntity.setId(new Date().getTime());
                    String foodnames = CommonUtil.getCellValue(row.getCell(0));
                    dietplanEntity.setFoodnames(foodnames);
                    String foodcategory = CommonUtil.getCellValue(row.getCell(1));
                    dietplanEntity.setFoodcategory(foodcategory);
                    String recipesteps = CommonUtil.getCellValue(row.getCell(2));
                    dietplanEntity.setRecipesteps(recipesteps);
                    String requiredingredients = CommonUtil.getCellValue(row.getCell(3));
                    dietplanEntity.setRequiredingredients(requiredingredients);
                    String requiredseasonings = CommonUtil.getCellValue(row.getCell(4));
                    dietplanEntity.setRequiredseasonings(requiredseasonings);
                    String cooking = CommonUtil.getCellValue(row.getCell(5));
                    dietplanEntity.setCooking(cooking);
                    String cookingdifficulty = CommonUtil.getCellValue(row.getCell(6));
                    dietplanEntity.setCookingdifficulty(cookingdifficulty);
                    String heat = CommonUtil.getCellValue(row.getCell(7));
                    dietplanEntity.setHeat(Double.parseDouble(heat));
                    String protein = CommonUtil.getCellValue(row.getCell(8));
                    dietplanEntity.setProtein(Double.parseDouble(protein));
                    String fat = CommonUtil.getCellValue(row.getCell(9));
                    dietplanEntity.setFat(Double.parseDouble(fat));
                    String carbohydrate = CommonUtil.getCellValue(row.getCell(10));
                    dietplanEntity.setCarbohydrate(Double.parseDouble(carbohydrate));
                    String vitamin = CommonUtil.getCellValue(row.getCell(11));
                    dietplanEntity.setVitamin(vitamin);
                    String mineral = CommonUtil.getCellValue(row.getCell(12));
                    dietplanEntity.setMineral(mineral);
                    String user = CommonUtil.getCellValue(row.getCell(13));
                    dietplanEntity.setUser(user);
                    String usercomments = CommonUtil.getCellValue(row.getCell(14));
                    dietplanEntity.setUsercomments(usercomments);
                    String userrating = CommonUtil.getCellValue(row.getCell(15));
                    dietplanEntity.setUserrating(Double.parseDouble(userrating));
                    String keyword = CommonUtil.getCellValue(row.getCell(16));
                    dietplanEntity.setKeyword(keyword);
                    //向数据库中添加新对象
                    dietplanService.insert(dietplanEntity);//方法
                }
            }
            inputStream.close();
        } catch (InvalidFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return R.ok("导入成功");
    }

    /**
     * (按值统计)
     */
    @RequestMapping("/value/{xColumnName}/{yColumnName}")
    public R value(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName,HttpServletRequest request) throws IOException {
        //读取文件,如果文件存在,则优先返回文件内容
        java.nio.file.Path path = java.nio.file.Paths.get("value_dietplan_" + xColumnName + "_" + yColumnName + "_timeType.json");
        if(java.nio.file.Files.exists(path)) {
            String content = new String(java.nio.file.Files.readAllBytes(path), java.nio.charset.StandardCharsets.UTF_8);
            return R.ok().put("data", (new org.json.JSONArray(content)).toList());
        }
        //构建查询统计条件
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("xColumn", xColumnName);
        params.put("yColumn", yColumnName);
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
            //获取结果
        List<Map<String, Object>> result = dietplanService.selectValue(params, ew);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(Map<String, Object> m : result) {
            for(String k : m.keySet()) {
                if(m.get(k) instanceof Date) {
                    m.put(k, sdf.format((Date)m.get(k)));
                }
            }
        }
        Collections.sort(result, (map1, map2) -> {
            // 假设 total 总是存在并且是数值类型
            Number total1 = (Number) map1.get("total");
            Number total2 = (Number) map2.get("total");
            if(total1==null)
            {
                total1 = 0;
            }
            if(total2==null)
            {
                total2 = 0;
            }
            return Double.compare(total2.doubleValue(), total1.doubleValue());
        });
        return R.ok().put("data", result);
    }
    
    /**
     * (按值统计(多))
     */
    @RequestMapping("/valueMul/{xColumnName}")
    public R valueMul(@PathVariable("xColumnName") String xColumnName,@RequestParam String yColumnNameMul,HttpServletRequest request)  throws IOException {
        //读取文件,如果文件存在,则优先返回文件内容
        java.nio.file.Path path = java.nio.file.Paths.get("value_dietplan_" + xColumnName + "_" + yColumnNameMul + "_timeType.json");
        if(java.nio.file.Files.exists(path)) {
            String content = new String(java.nio.file.Files.readAllBytes(path), java.nio.charset.StandardCharsets.UTF_8);
            return R.ok().put("data", (new org.json.JSONArray(content)).toList());
        }
        String[] yColumnNames = yColumnNameMul.split(",");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("xColumn", xColumnName);
        List<List<Map<String, Object>>> result2 = new ArrayList<List<Map<String,Object>>>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //构建查询统计条件
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
        for(int i=0;i<yColumnNames.length;i++) {
            params.put("yColumn", yColumnNames[i]);
            List<Map<String, Object>> result = dietplanService.selectValue(params, ew);
            for(Map<String, Object> m : result) {
                for(String k : m.keySet()) {
                    if(m.get(k) instanceof Date) {
                        m.put(k, sdf.format((Date)m.get(k)));
                    }
                }
            }
            result2.add(result);
        }
        return R.ok().put("data", result2);
    }
    
    /**
     * (按值统计)时间统计类型
     */
    @RequestMapping("/value/{xColumnName}/{yColumnName}/{timeStatType}")
    public R valueDay(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType,HttpServletRequest request) throws IOException {
        //读取文件,如果文件存在,则优先返回文件内容
        java.nio.file.Path path = java.nio.file.Paths.get("value_dietplan_" + xColumnName + "_" + yColumnName + "_"+timeStatType+".json");
        if(java.nio.file.Files.exists(path)) {
            String content = new String(java.nio.file.Files.readAllBytes(path), java.nio.charset.StandardCharsets.UTF_8);
            return R.ok().put("data", (new org.json.JSONArray(content)).toList());
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("xColumn", xColumnName);
        params.put("yColumn", yColumnName);
        params.put("timeStatType", timeStatType);
        //构建查询统计条件
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
        List<Map<String, Object>> result = dietplanService.selectTimeStatValue(params, ew);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(Map<String, Object> m : result) {
            for(String k : m.keySet()) {
                if(m.get(k) instanceof Date) {
                    m.put(k, sdf.format((Date)m.get(k)));
                }
            }
        }
        return R.ok().put("data", result);
    }
    
    /**
     * (按值统计)时间统计类型(多)
     */
    @RequestMapping("/valueMul/{xColumnName}/{timeStatType}")
    public R valueMulDay(@PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType,@RequestParam String yColumnNameMul,HttpServletRequest request) throws IOException
    {
        //读取文件,如果文件存在,则优先返回文件内容
        java.nio.file.Path path = java.nio.file.Paths.get("value_dietplan_" + xColumnName + "_" + yColumnNameMul + "_" + timeStatType + ".json");
        if (java.nio.file.Files.exists(path)) {
            String content = new String(java.nio.file.Files.readAllBytes(path), java.nio.charset.StandardCharsets.UTF_8);
            return R.ok().put("data", (new org.json.JSONArray(content)).toList());
        }
        String[] yColumnNames = yColumnNameMul.split(",");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("xColumn", xColumnName);
        params.put("timeStatType", timeStatType);
        List<List<Map<String, Object>>> result2 = new ArrayList<List<Map<String,Object>>>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //构建查询统计条件
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
        for(int i=0;i<yColumnNames.length;i++) {
            params.put("yColumn", yColumnNames[i]);
            List<Map<String, Object>> result = dietplanService.selectTimeStatValue(params, ew);
            for(Map<String, Object> m : result) {
                for(String k : m.keySet()) {
                    if(m.get(k) instanceof Date) {
                        m.put(k, sdf.format((Date)m.get(k)));
                    }
                }
            }
            result2.add(result);
        }
        return R.ok().put("data", result2);
    }
    
    /**
     * 分组统计
     */
    @RequestMapping("/group/{columnName}")
    public R group(@PathVariable("columnName") String columnName,HttpServletRequest request) throws IOException {
        //读取文件,如果文件存在,则优先返回文件内容
        java.nio.file.Path path = java.nio.file.Paths.get("group_dietplan_" + columnName + "_timeType.json");
        if(java.nio.file.Files.exists(path)){
            String content = new String(java.nio.file.Files.readAllBytes(path), java.nio.charset.StandardCharsets.UTF_8);
            return R.ok().put("data", (new org.json.JSONArray(content)).toList());
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("column", columnName);
        //构建查询统计条件
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
        List<Map<String, Object>> result = dietplanService.selectGroup(params, ew);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(Map<String, Object> m : result) {
            for(String k : m.keySet()) {
                if(m.get(k) instanceof Date) {
                    m.put(k, sdf.format((Date)m.get(k)));
                }
            }
        }
        return R.ok().put("data", result);
    }    

    /**
     * 分段统计
     */
    @RequestMapping("/sectionStat/heat")
    @IgnoreAuth
    public R heatSectionStat(HttpServletRequest request) {
        Map<String, Object> params = new HashMap<String, Object>();
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
        List<Map<String, Object>> result = dietplanService.heatSectionStat(params, ew);
        return R.ok().put("data", result);
    }
    /**
     * 分段统计
     */
    @RequestMapping("/sectionStat/protein")
    @IgnoreAuth
    public R proteinSectionStat(HttpServletRequest request) {
        Map<String, Object> params = new HashMap<String, Object>();
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
        List<Map<String, Object>> result = dietplanService.proteinSectionStat(params, ew);
        return R.ok().put("data", result);
    }
    /**
     * 分段统计
     */
    @RequestMapping("/sectionStat/fat")
    @IgnoreAuth
    public R fatSectionStat(HttpServletRequest request) {
        Map<String, Object> params = new HashMap<String, Object>();
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
        List<Map<String, Object>> result = dietplanService.fatSectionStat(params, ew);
        return R.ok().put("data", result);
    }
    /**
     * 分段统计
     */
    @RequestMapping("/sectionStat/carbohydrate")
    @IgnoreAuth
    public R carbohydrateSectionStat(HttpServletRequest request) {
        Map<String, Object> params = new HashMap<String, Object>();
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
        List<Map<String, Object>> result = dietplanService.carbohydrateSectionStat(params, ew);
        return R.ok().put("data", result);
    }



    /**
     * 总数量
     */
    @RequestMapping("/count")
    public R count(@RequestParam Map<String, Object> params,DietplanEntity dietplan, HttpServletRequest request){
        EntityWrapper<DietplanEntity> ew = new EntityWrapper<DietplanEntity>();
        int count = dietplanService.selectCount(MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, dietplan), params), params));
        return R.ok().put("data", count);
    }

}

获取源码或论文

如需对应的论文或源码,以及其他定制需求,也可以下方微❤联系。

Logo

码道开发者社区,聚焦华为云码道 CodeArts 代码智能体,沉淀 Agent、Skill、鸿蒙开发实战内容,供开发者查阅资料、交流技术、分享工程实践

更多推荐