基于SpringBoot+Redis的前后端分离外卖项目-苍穹外卖(四)

news2024/9/22 11:28:35

编辑员工和分类模块功能开发

    • 1. 编辑员工
      • 1.1 需求分析与设计
        • 1.1.1 产品原型
        • 1.1.2 接口设计
      • 1.2 代码开发
        • 1.2.1 回显员工信息功能
        • 1.2.2 修改员工信息功能
      • 1.3 功能测试
    • 2. 分类模块功能开发
      • 2.1 需求分析与设计
        • 2.1.1 产品原型
        • 2.1.2 接口设计
        • 2.1.3 表设计
      • 2.2 代码实现
        • 2.2.1 Mapper层
        • 2.2.2 Service层
        • 2.2.3 Controller层
      • 2.3 功能测试

1. 编辑员工

1.1 需求分析与设计

1.1.1 产品原型

在员工管理列表页面点击 “编辑” 按钮,跳转到编辑页面,在编辑页面回显员工信息并进行修改,最后点击 “保存” 按钮完成编辑操作。

修改页面原型

注:点击修改时,数据应该正常回显到修改页面。

在这里插入图片描述

1.1.2 接口设计

根据上述原型图分析,编辑员工功能涉及到两个接口:

  • 根据id查询员工信息
  • 编辑员工信息

1). 根据id查询员工信息
在这里插入图片描述
在这里插入图片描述

2). 编辑员工信息

在这里插入图片描述
在这里插入图片描述

注:因为是修改功能,请求方式可设置为PUT。

1.2 代码开发

1.2.1 回显员工信息功能

1). Controller层

在 EmployeeController 中创建 getById 方法:

	/**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询员工信息")
    public Result<Employee> getById(@PathVariable Long id){
        Employee employee = employeeService.getById(id);
        return Result.success(employee);
    }

2). Service层接口

在 EmployeeService 接口中声明 getById 方法:

    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    Employee getById(Long id);

3). Service层实现类

在 EmployeeServiceImpl 中实现 getById 方法:

 	/**
     * 根据id查询员工
     *
     * @param id
     * @return
     */
    public Employee getById(Long id) {
        Employee employee = employeeMapper.getById(id);
        employee.setPassword("****");
        return employee;
    }

4). Mapper层

在 EmployeeMapper 接口中声明 getById 方法:

	/**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    @Select("select * from employee where id = #{id}")
    Employee getById(Long id);
1.2.2 修改员工信息功能

1). Controller层

在 EmployeeController 中创建 update 方法:

	/**
     * 编辑员工信息
     * @param employeeDTO
     * @return
     */
    @PutMapping
    @ApiOperation("编辑员工信息")
    public Result update(@RequestBody EmployeeDTO employeeDTO){
        log.info("编辑员工信息:{}", employeeDTO);
        employeeService.update(employeeDTO);
        return Result.success();
    }

2). Service层接口

在 EmployeeService 接口中声明 update 方法:

    /**
     * 编辑员工信息
     * @param employeeDTO
     */
    void update(EmployeeDTO employeeDTO);

3). Service层实现类

在 EmployeeServiceImpl 中实现 update 方法:

 	/**
     * 编辑员工信息
     *
     * @param employeeDTO
     */
    public void update(EmployeeDTO employeeDTO) {
        Employee employee = new Employee();
        BeanUtils.copyProperties(employeeDTO, employee);

        employee.setUpdateTime(LocalDateTime.now());
        employee.setUpdateUser(BaseContext.getCurrentId());

        employeeMapper.update(employee);
    }

1.3 功能测试

进入到员工列表查询。

在这里插入图片描述

对员工姓名为杰克的员工数据修改,点击修改,数据已回显。

在这里插入图片描述

修改后,点击保存。

在这里插入图片描述

2. 分类模块功能开发

2.1 需求分析与设计

2.1.1 产品原型

后台系统中可以管理分类信息,分类包括两种类型,分别是 菜品分类套餐分类

菜品分类相关功能。

新增菜品分类:当我们在后台系统中添加菜品时需要选择一个菜品分类,在移动端也会按照菜品分类来展示对应的菜品。

菜品分类分页查询:系统中的分类很多的时候,如果在一个页面中全部展示出来会显得比较乱,不便于查看,所以一般的系统中都会以分页的方式来展示列表数据。

根据id删除菜品分类:在分类管理列表页面,可以对某个分类进行删除操作。需要注意的是当分类关联了菜品或者套餐时,此分类不允许删除。

修改菜品分类:在分类管理列表页面点击修改按钮,弹出修改窗口,在修改窗口回显分类信息并进行修改,最后点击确定按钮完成修改操作。

启用禁用菜品分类:在分类管理列表页面,可以对某个分类进行启用或者禁用操作。

分类类型查询:当点击分类类型下拉框时,从数据库中查询所有的菜品分类数据进行展示。

分类管理原型:

在这里插入图片描述

业务规则:

  • 分类名称必须是唯一的
  • 分类按照类型可以分为菜品分类和套餐分类
  • 新添加的分类状态默认为“禁用”
2.1.2 接口设计

根据上述原型图分析,菜品分类模块共涉及6个接口。

  • 新增分类
  • 分类分页查询
  • 根据id删除分类
  • 修改分类
  • 启用禁用分类
  • 根据类型查询分类

接下来,详细地分析每个接口。

1). 新增分类

在这里插入图片描述
在这里插入图片描述

2). 分类分页查询

在这里插入图片描述
在这里插入图片描述

3). 根据id删除分类

在这里插入图片描述

4). 修改分类

在这里插入图片描述
在这里插入图片描述

5). 启用禁用分类

在这里插入图片描述
在这里插入图片描述

6). 根据类型查询分类

在这里插入图片描述
在这里插入图片描述

2.1.3 表设计

category表结构:

字段名数据类型说明备注
idbigint主键自增
namevarchar(32)分类名称唯一
typeint分类类型1菜品分类 2套餐分类
sortint排序字段用于分类数据的排序
statusint状态1启用 0禁用
create_timedatetime创建时间
update_timedatetime最后修改时间
create_userbigint创建人id
update_userbigint最后修改人id

2.2 代码实现

2.2.1 Mapper层

DishMapper.java

package com.sky.mapper;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

}

SetmealMapper.java

package com.sky.mapper;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

}

CategoryMapper.java

package com.sky.mapper;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /**
     * 插入数据
     * @param category
     */
    @Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user)" +
            " VALUES" +
            " (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void insert(Category category);

    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 根据id删除分类
     * @param id
     */
    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据id修改分类
     * @param category
     */
    void update(Category category);

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    List<Category> findByType(Integer type);
}

CategoryMapper.xml,进入到resources/mapper目录下

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sky.mapper.CategoryMapper">

    <select id="pageQuery" resultType="com.sky.entity.Category">
        select * from category
        <where>
            <if test="name != null and name != ''">
                and name like concat('%',#{name},'%')
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
        </where>
        order by sort asc , create_time desc
    </select>

    <update id="update" parameterType="Category">
        update category
        <set>
            <if test="type != null">
                type = #{type},
            </if>
            <if test="name != null">
                name = #{name},
            </if>
            <if test="sort != null">
                sort = #{sort},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="updateUser != null">
                update_user = #{updateUser}
            </if>
        </set>
        where id = #{id}
    </update>

    <select id="findByType" resultType="Category">
        select * from category
        where status = 1
        <if test="type != null">
            and type = #{type}
        </if>
        order by sort asc,create_time desc
    </select>
</mapper>

2.2.2 Service层

CategoryService.java

package com.sky.service;


public interface CategoryService {

    /**
     * 新增分类
     * @param categoryDTO
     */
    void save(CategoryDTO categoryDTO);

    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 根据id删除分类
     * @param id
     */
    void deleteById(Long id);

    /**
     * 修改分类
     * @param categoryDTO
     */
    void update(CategoryDTO categoryDTO);

    /**
     * 启用、禁用分类
     * @param status
     * @param id
     */
    void startOrStop(Integer status, Long id);

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    List<Category> findByType(Integer type);
}

CategoryServiceImpl.java

@Service
public class CategoryServiceImpl implements CategoryService {
@Autowired
private CategoryMapper categoryMapper;
@Autowired
private SetmealMapper setmealMapper;
@Autowired
private DishMapper dishMapper;
//菜品添加
    @Override
    public void add(CategoryDTO categoryDTO) {
        Category category=new Category();
        BeanUtils.copyProperties(categoryDTO,category);
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        category.setUpdateUser(BaseContext.getCurrentId());
        category.setCreateUser(BaseContext.getCurrentId());
        category.setStatus(StatusConstant.DISABLE);
        categoryMapper.add(category);
    }
   //菜品分页查询
    @Override
    public PageResult page(CategoryPageQueryDTO categoryPageQueryDTO) {

        PageHelper.startPage(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize());
          Page<Category> page= categoryMapper.page(categoryPageQueryDTO);

          PageResult pageResult=new PageResult();
          pageResult.setTotal(page.getTotal());
          pageResult.setRecords( page.getResult());
        return pageResult;
    }
//启用禁用
    @Override
    public void startOrStop(Integer status, Long id) {
        Category category = Category.builder().id(id).status(status).build();

        categoryMapper.update(category);
    }
         //根据类型查询
    @Override
    public List<Category> findByType(Integer type) {

        List<Category> categoryList=categoryMapper.findByType(type);
        return categoryList;
    }
//菜品的删除
    @Override
    public void delete(Long id) {
if (dishMapper.countByCategoryid(id)>0){
throw new DeletionNotAllowedException(MessageConstant.CATEGORY_BE_RELATED_BY_DISH);
}if (setmealMapper.selectCount(id)>0){
    throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
        }
        categoryMapper.delete(id);
    }
  //菜品的修改
    @Override
    public void update( CategoryDTO categoryDTO) {
        Category category=new Category();
        BeanUtils.copyProperties(categoryDTO,category);
        category.setUpdateTime(LocalDateTime.now());
        category.setUpdateUser(BaseContext.getCurrentId());
        categoryMapper.update(category);
    }
}

2.2.3 Controller层

CategoryController.java

package com.sky.controller.admin;


/**
 * 分类管理
 */
@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增分类")
    public Result<String> save(@RequestBody CategoryDTO categoryDTO){
        log.info("新增分类:{}", categoryDTO);
        categoryService.save(categoryDTO);
        return Result.success();
    }

    /**
     * 分类分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分页查询:{}", categoryPageQueryDTO);
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除分类")
    public Result<String> deleteById(Long id){
        log.info("删除分类:{}", id);
        categoryService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改分类")
    public Result<String> update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();
    }

    /**
     * 启用、禁用分类
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用分类")
    public Result<String> startOrStop(@PathVariable("status") Integer status, Long id){
        categoryService.startOrStop(status,id);
        return Result.success();
    }

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(Integer type){
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }
}

2.3 功能测试

重启服务,访问http://localhost:80,进入分类管理

分页查询:

在这里插入图片描述

分类类型:

在这里插入图片描述

启用禁用:

在这里插入图片描述

点击禁用

在这里插入图片描述

修改:

回显

在这里插入图片描述

修改后

在这里插入图片描述

新增:

在这里插入图片描述

点击确定,查询列表

在这里插入图片描述

删除:

在这里插入图片描述

删除后,查询分类列表

在这里插入图片描述
删除成功

后记
👉👉💕💕美好的一天,到此结束,下次继续努力!欲知后续,请看下回分解,写作不易,感谢大家的支持!! 🌹🌹🌹

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1202366.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

CSP模拟

1.3n -1 题目描述 给定一个整数n&#xff0c;只能对n进行以下这几种操作&#xff1a; 1.若n是3的倍数除以3 2.加1 3.减1 求最少多少次操作才能使n变为1&#xff1f; 输入 一行一个整数n 输出 一行一个整数表示答案 样例输入 4 样例输出 2 提示 对于样例1:4-…

亚马逊鲲鹏系统强大的指纹系统可有效防止账号关联

亚马逊鲲鹏系统最新的防指纹技术支持绑定不同的代理IP&#xff0c;可以根据ip创建不同的指纹环境&#xff0c;让账号伪装成来自不同地点、不同设备的流量&#xff0c;每个账号环境隔离开来&#xff0c;实现了完全独立的操作任务&#xff0c;避免了账户指纹关联和操作轨迹关联。…

搜集的升压芯片资料

DC-DC升压芯片,输入电压0.65v/1.5v/1.8v/2v/2.5v/2.7v/3v/3.3v/3.6v/5v/12v/24v航誉微 HUB628是一款超小封装高效率、直流升压稳压电路。输入电压范围可由低2V伏特到24伏特&#xff0c;升压可达28V可调&#xff0c;且内部集成极低RDS内阻100豪欧金属氧化物半导体场效应晶体管的…

桌面云架构讲解(VDI、IDV、VOI/TCI、RDS)

目录 云桌面架构 VDI 虚拟桌面基础架构 IDV 智能桌面虚拟化 VOI/TCI VOI 虚拟系统架构 TCI 透明计算机架构 RDS 远程桌面服务 不同厂商云桌面架构 桌面传输协议 什么是云桌面 桌面云是虚拟化技术成熟后发展起来的一种应用&#xff0c;桌面云通常也称为云桌面、VDI等 …

Swagger3 GET请求,使用对象接收 Query 参数,注解怎么写?

简中互联网上就没一个靠谱的答案&#xff0c;最终翻到了 Github Issue 上才解决&#xff0c;真 TMD…… CSDN 就一坨 shit mountain 解决方案 原文&#xff1a;https://github.com/swagger-api/swagger-core/issues/4177 太长不看&#xff1a; 请求方法参数上加 ParameterObj…

【异步并发编程】使用aiohttp构建Web应用程序

文章目录 1. 写在前面1. 什么是aiohttp&#xff1f;1.1. 什么是异步编程&#xff1f; 2. 安装aiohttp3. 异步HTTP服务器4. 异步请求5. aiohttp REST实例 【作者主页】&#xff1a;吴秋霖 【作者介绍】&#xff1a;Python领域优质创作者、阿里云博客专家、华为云享专家。长期致力…

行情不好,程序员的路在哪里?

最近有人提问&#xff0c;行情不好&#xff0c;程序员的路在哪里&#xff1f;今天的文章从远程工作、市场和流量思维、新技术、自媒体几个维度来讲讲。 远程工作 如果你在二三线城市&#xff0c;机会比较少&#xff0c;可以考虑一下远程工作。找一份美国或欧洲的远程工作&…

开源网安受邀参加网络空间安全合作与发展论坛,为软件开发安全建设献计献策

​11月10日&#xff0c;在广西南宁举办的“2023网络空间安全合作与发展论坛”圆满结束。论坛在中国兵工学会的指导下&#xff0c;以“凝聚网络空间安全学术智慧&#xff0c;赋能数字经济时代四链融合”为主题&#xff0c;邀请了多位专家及企业代表共探讨网络安全发展与数字经济…

助力燃气安全运行:智慧燃气管网背景延展

关键词&#xff1a;城市燃气管网、智慧燃气管网、智慧管网、智慧燃气管网解决方案、智慧燃气 01背景 当前&#xff0c;随着我国城市化进程不断加快&#xff0c;城市燃气管网也不断延伸&#xff0c;运行规模庞大&#xff0c;地下管线复杂&#xff0c;不少城市建设“重地上轻地…

Web后端开发_01

Web后端开发 请求响应 SpringBoot提供了一个非常核心的Servlet 》DispatcherServlet&#xff0c;DispatcherServlet实现了servlet中规范的接口 请求响应&#xff1a; 请求&#xff08;HttpServletRequest&#xff09;&#xff1a;获取请求数据响应&#xff08;HttpServletRe…

2011年09月29日 Go生态洞察:image/draw包的深度解析

&#x1f337;&#x1f341; 博主猫头虎&#xff08;&#x1f405;&#x1f43e;&#xff09;带您 Go to New World✨&#x1f341; &#x1f984; 博客首页——&#x1f405;&#x1f43e;猫头虎的博客&#x1f390; &#x1f433; 《面试题大全专栏》 &#x1f995; 文章图文…

会展服务预约小程序的作用如何

不少场景都会有会展服务需求&#xff0c;比如婚宴、年会、展会等&#xff0c;往往需要租订场地&#xff0c;不同地域不同时间地点等&#xff0c;尤其大城市需求频次较高。 但在实际经营中&#xff0c;会员服务企业面临着一些难题。对多数企业来讲&#xff0c;线上是不可或缺的…

地面沉降监测站可以监测什么?

随着城市化的飞速发展&#xff0c;地面沉降问题日益凸显。为了及时掌握土地沉降情况&#xff0c;确保人们安全&#xff0c;就需要借助地面沉降监测站的力量。 一、实时监测土地沉降 地面沉降监测站的核心功能是实时监测土地沉降。通过高精度GNSS位移监测站和先进的数据分析技术…

使用Java实现一个简单的贪吃蛇小游戏

一. 准备工作 首先获取贪吃蛇小游戏所需要的头部、身体、食物以及贪吃蛇标题等图片。 然后&#xff0c;创建贪吃蛇游戏的Java项目命名为snake_game&#xff0c;并在这个项目里创建一个文件夹命名为images&#xff0c;将图片素材导入文件夹。 再在src文件下创建两个包&#xff0…

性能压测工具:Locust详解

一、Locust介绍 开源性能测试工具https://www.locust.io/&#xff0c;基于Python的性能压测工具&#xff0c;使用Python代码来定义用户行为&#xff0c;模拟百万计的并发用户访问。每个测试用户的行为由您定义&#xff0c;并且通过Web UI实时监控聚集过程。 压力发生器作为性…

在Android上使用Jetpack Compose定制下拉刷新

在Android上使用Jetpack Compose定制下拉刷新 在Jetpack Compose中向LazyList添加下拉刷新非常简单。说真的&#xff0c;只需几行代码。然而&#xff0c;默认的外观和感觉并不是那么令人满意。我们希望做得更好一些&#xff0c;类似于iOS版本&#xff1a;当用户向下拉动列表时…

opencv差值法检测移动物体代码

void CrelaxMyFriendDlg::OnBnClickedOk() {hdc this->GetDC()->GetSafeHdc();// TODO: 在此添加控件通知处理程序代码string addrImg "c:/Users/actorsun/Pictures/";string addrVideo "c:/Users/actorsun/Videos/";string addr addrVideo &qu…

使用阿里云服务器学习Docker

首先我这里选择的系统服务器是CentOS 7.9 64位 因为centos系统里面的安装指令是&#xff1a;yum,而非apt-get. yum install docker -y试着建立一个容器&#xff1a; docker run -d -p 80:80 httpd启动docker的守护进程&#xff1a; sudo systemctl start docker 查看Docke…

基于springboot实现结合疫情情况的婚恋系统【项目源码】计算机毕业设计

基于springboot实现结合疫情情况的婚恋系统演示 SpringBoot框架 SpringBoot是一个全新开源的轻量级框架。基于Spring4.0设计&#xff0c;其不仅继承了Spring框架原来有的优秀特性&#xff0c;而且还通过简化配置文件来进一步简化了Spring应用的整个搭建以及开发过程。另外在原…

人机功能分配困难的原因之一

人机功能分配困难的原因之一是人类与机器都不能同时确定事实与价值的大小。事实是指客观存在的数据、信息和情况&#xff0c;而价值是指对这些事实的评判和喜好。人类和机器在确定功能分配时&#xff0c;都需要考虑到这两个方面。 首先&#xff0c;人类和机器在事实方面的认知能…