新增接口

This commit is contained in:
LittleBoy 2023-03-31 11:00:34 +08:00
parent c941c0d22a
commit eea5a0e1a6
12 changed files with 153 additions and 24 deletions

Binary file not shown.

View File

@ -6,7 +6,6 @@
-- -------------------------------------------------------- -- --------------------------------------------------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */; /*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
@ -81,6 +80,7 @@ CREATE TABLE IF NOT EXISTS `food_category` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '食品分类编号', `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '食品分类编号',
`title` varchar(200) DEFAULT NULL COMMENT '分类标题', `title` varchar(200) DEFAULT NULL COMMENT '分类标题',
`sort` int(3) DEFAULT '0' COMMENT '排序', `sort` int(3) DEFAULT '0' COMMENT '排序',
`cover` varchar(200) DEFAULT NULL COMMENT '分类图片',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`state` tinyint(2) DEFAULT '1' COMMENT '状态', `state` tinyint(2) DEFAULT '1' COMMENT '状态',

View File

@ -1,14 +1,32 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="分类名称" prop="title"> <el-form-item label="分类标题" prop="title">
<el-input <el-input
v-model="queryParams.title" v-model="queryParams.title"
placeholder="请输入分类名称" placeholder="请输入分类标题"
clearable clearable
@keyup.enter.native="handleQuery" @keyup.enter.native="handleQuery"
/> />
</el-form-item> </el-form-item>
<el-form-item label="排序" prop="sort">
<el-input
v-model="queryParams.sort"
placeholder="请输入排序"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="状态" prop="state">
<el-select v-model="queryParams.state" placeholder="请选择状态" clearable>
<el-option
v-for="dict in dict.type.data_state"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
@ -63,14 +81,21 @@
<el-table v-loading="loading" :data="categoryList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="categoryList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column label="编号" align="center" prop="id" /> <el-table-column label="食品分类编号" align="center" prop="id" />
<el-table-column label="分类名称" align="center" prop="title" /> <el-table-column label="分类标题" align="center" prop="title" />
<el-table-column label="排序" align="center" prop="sort" /> <el-table-column label="排序" align="center" prop="sort" />
<el-table-column label="分类图片" align="center" prop="cover" width="100">
<template slot-scope="scope">
<image-preview :src="scope.row.cover" :width="50" :height="50"/>
</template>
</el-table-column>
<el-table-column label="更新时间" align="center" prop="updateTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="state"> <el-table-column label="状态" align="center" prop="state">
<template slot-scope="scope"> <template slot-scope="scope">
<!-- <el-tag>
{{ scope.row.state == 0 ?'删除':'正常' }}
</el-tag> -->
<dict-tag :options="dict.type.data_state" :value="scope.row.state"/> <dict-tag :options="dict.type.data_state" :value="scope.row.state"/>
</template> </template>
</el-table-column> </el-table-column>
@ -94,7 +119,7 @@
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination <pagination
v-show="total>0" v-show="total>0"
:total="total" :total="total"
@ -106,12 +131,25 @@
<!-- 添加或修改食品分类对话框 --> <!-- 添加或修改食品分类对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="分类名称" prop="title"> <el-form-item label="分类标题" prop="title">
<el-input v-model="form.title" placeholder="请输入分类名称" /> <el-input v-model="form.title" placeholder="请输入分类标题" />
</el-form-item> </el-form-item>
<el-form-item label="排序" prop="sort"> <el-form-item label="排序" prop="sort">
<el-input v-model="form.sort" placeholder="请输入排序" /> <el-input v-model="form.sort" placeholder="请输入排序" />
</el-form-item> </el-form-item>
<el-form-item label="分类图片" prop="cover">
<image-upload :limit="1" v-model="form.cover"/>
</el-form-item>
<el-form-item label="状态" prop="state">
<el-select v-model="form.state" placeholder="请选择状态">
<el-option
v-for="dict in dict.type.data_state"
:key="dict.value"
:label="dict.label"
:value="parseInt(dict.value)"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="备注" prop="remark"> <el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" /> <el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item> </el-form-item>
@ -129,6 +167,7 @@ import { listCategory, getCategory, delCategory, addCategory, updateCategory } f
export default { export default {
name: "Category", name: "Category",
dicts: ['data_state'],
data() { data() {
return { return {
// //
@ -154,6 +193,8 @@ export default {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
title: null, title: null,
sort: null,
state: null,
}, },
// //
form: {}, form: {},
@ -162,7 +203,6 @@ export default {
} }
}; };
}, },
dicts:['data_state'],
created() { created() {
this.getList(); this.getList();
}, },
@ -187,6 +227,7 @@ export default {
id: null, id: null,
title: null, title: null,
sort: null, sort: null,
cover: null,
createTime: null, createTime: null,
updateTime: null, updateTime: null,
state: null, state: null,

View File

@ -16,8 +16,8 @@
<el-form-item label="价格" prop="price"> <el-form-item label="价格" prop="price">
<el-input v-model="queryParams.price" placeholder="请输入价格" clearable @keyup.enter.native="handleQuery" /> <el-input v-model="queryParams.price" placeholder="请输入价格" clearable @keyup.enter.native="handleQuery" />
</el-form-item> </el-form-item>
<el-form-item label="售卖区域(匹配收货地址,null表示不限制)" prop="area"> <el-form-item label="售卖区域" prop="area">
<el-input v-model="queryParams.area" placeholder="请输入售卖区域(匹配收货地址,null表示不限制)" clearable <el-input v-model="queryParams.area" placeholder="请选择售卖区域" clearable
@keyup.enter.native="handleQuery" /> @keyup.enter.native="handleQuery" />
</el-form-item> </el-form-item>
<el-form-item label="创建时间"> <el-form-item label="创建时间">
@ -72,7 +72,8 @@
<el-table-column label="优惠" align="center" prop="coupon" /> <el-table-column label="优惠" align="center" prop="coupon" />
<el-table-column label="价格" align="center" prop="price" /> <el-table-column label="价格" align="center" prop="price" />
<el-table-column label="排序" align="center" prop="sort" /> <el-table-column label="排序" align="center" prop="sort" />
<el-table-column label="售卖区域(匹配收货地址,null表示不限制)" align="center" prop="area" /> <!-- (匹配收货地址,null表示不限制)-->
<el-table-column label="售卖区域" align="center" prop="area" />
<el-table-column label="是否推荐" align="center" prop="recommend" /> <el-table-column label="是否推荐" align="center" prop="recommend" />
<el-table-column label="已售出数量" align="center" prop="saleCount" /> <el-table-column label="已售出数量" align="center" prop="saleCount" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180"> <el-table-column label="创建时间" align="center" prop="createTime" width="180">

View File

@ -0,0 +1,26 @@
package com.waimai.api;
import com.waimai.common.annotation.Anonymous;
import com.waimai.common.core.domain.R;
import com.waimai.web.admin.domain.FoodCategory;
import com.waimai.web.admin.service.IFoodCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/api/category")
@Anonymous
public class Category {
@Autowired
private IFoodCategoryService foodCategoryService;
@RequestMapping
public R<List<FoodCategory>> selectAll() {
return R.ok(
foodCategoryService.selectFoodCategoryList(new FoodCategory())
);
}
}

View File

@ -0,0 +1,40 @@
package com.waimai.api;
import com.waimai.common.annotation.Anonymous;
import com.waimai.common.core.controller.BaseController;
import com.waimai.common.core.domain.R;
import com.waimai.web.admin.domain.Food;
import com.waimai.web.admin.service.IFoodService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
@Anonymous
@RequestMapping("/api/food")
public class FoodsApiController {
@Resource
private IFoodService foodService;
/**
* 推荐食品
*
* @return
*/
@RequestMapping("/recommend")
public R<List<Food>> recommend() {
return R.ok(foodService.selectFoodList(new Food()));
}
@RequestMapping("/category/{cid}")
public R<List<Food>> selectByCategory(@PathVariable("cid") Long cid) {
Food food = new Food();
food.setCid(cid);
return R.ok(foodService.selectFoodList(food));
}
}

View File

@ -9,23 +9,27 @@ import com.waimai.common.core.domain.BaseEntity;
* 食品分类对象 food_category * 食品分类对象 food_category
* *
* @author callmeyan * @author callmeyan
* @date 2023-03-24 * @date 2023-03-31
*/ */
public class FoodCategory extends BaseEntity public class FoodCategory extends BaseEntity
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 编号 */ /** 食品分类编号 */
private Long id; private Long id;
/** 分类名称 */ /** 分类标题 */
@Excel(name = "分类名称") @Excel(name = "分类标题")
private String title; private String title;
/** 排序 */ /** 排序 */
@Excel(name = "排序") @Excel(name = "排序")
private Integer sort; private Integer sort;
/** 分类图片 */
@Excel(name = "分类图片")
private String cover;
/** 状态 */ /** 状态 */
@Excel(name = "状态") @Excel(name = "状态")
private Integer state; private Integer state;
@ -57,6 +61,15 @@ public class FoodCategory extends BaseEntity
{ {
return sort; return sort;
} }
public void setCover(String cover)
{
this.cover = cover;
}
public String getCover()
{
return cover;
}
public void setState(Integer state) public void setState(Integer state)
{ {
this.state = state; this.state = state;
@ -73,6 +86,7 @@ public class FoodCategory extends BaseEntity
.append("id", getId()) .append("id", getId())
.append("title", getTitle()) .append("title", getTitle())
.append("sort", getSort()) .append("sort", getSort())
.append("cover", getCover())
.append("createTime", getCreateTime()) .append("createTime", getCreateTime())
.append("updateTime", getUpdateTime()) .append("updateTime", getUpdateTime())
.append("state", getState()) .append("state", getState())

View File

@ -6,9 +6,9 @@ spring:
druid: druid:
# 主库数据源 # 主库数据源
master: master:
url: jdbc:mysql://localhost:3306/waimai_sys?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://localhost:3307/waimai_sys?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: root
password: root password: 123456
# 从库数据源 # 从库数据源
slave: slave:
# 从数据源开关/默认关闭 # 从数据源开关/默认关闭

View File

@ -97,7 +97,7 @@ token:
# 令牌密钥 # 令牌密钥
secret: abcdefghijklmnopqrstuvwxyz secret: abcdefghijklmnopqrstuvwxyz
# 令牌有效期默认30分钟 # 令牌有效期默认30分钟
expireTime: 30 expireTime: 300
# MyBatis配置 # MyBatis配置
mybatis: mybatis:

View File

@ -8,6 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="id" column="id" /> <result property="id" column="id" />
<result property="title" column="title" /> <result property="title" column="title" />
<result property="sort" column="sort" /> <result property="sort" column="sort" />
<result property="cover" column="cover" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="state" column="state" /> <result property="state" column="state" />
@ -15,13 +16,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectFoodCategoryVo"> <sql id="selectFoodCategoryVo">
select id, title, sort, create_time, update_time, state, remark from food_category select id, title, sort, cover, create_time, update_time, state, remark from food_category
</sql> </sql>
<select id="selectFoodCategoryList" parameterType="FoodCategory" resultMap="FoodCategoryResult"> <select id="selectFoodCategoryList" parameterType="FoodCategory" resultMap="FoodCategoryResult">
<include refid="selectFoodCategoryVo"/> <include refid="selectFoodCategoryVo"/>
<where> <where>
<if test="title != null and title != ''"> and title like concat('%', #{title}, '%')</if> <if test="title != null and title != ''"> and title like concat('%', #{title}, '%')</if>
<if test="sort != null "> and sort = #{sort}</if>
<if test="state != null "> and state = #{state}</if>
</where> </where>
</select> </select>
@ -35,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="title != null">title,</if> <if test="title != null">title,</if>
<if test="sort != null">sort,</if> <if test="sort != null">sort,</if>
<if test="cover != null">cover,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if> <if test="updateTime != null">update_time,</if>
<if test="state != null">state,</if> <if test="state != null">state,</if>
@ -43,6 +47,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null">#{title},</if> <if test="title != null">#{title},</if>
<if test="sort != null">#{sort},</if> <if test="sort != null">#{sort},</if>
<if test="cover != null">#{cover},</if>
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if> <if test="updateTime != null">#{updateTime},</if>
<if test="state != null">#{state},</if> <if test="state != null">#{state},</if>
@ -55,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="title != null">title = #{title},</if> <if test="title != null">title = #{title},</if>
<if test="sort != null">sort = #{sort},</if> <if test="sort != null">sort = #{sort},</if>
<if test="cover != null">cover = #{cover},</if>
<if test="createTime != null">create_time = #{createTime},</if> <if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if> <if test="updateTime != null">update_time = #{updateTime},</if>
<if test="state != null">state = #{state},</if> <if test="state != null">state = #{state},</if>

View File

@ -32,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql> </sql>
<select id="selectFoodList" parameterType="Food" resultMap="FoodResult"> <select id="selectFoodList" parameterType="Food" resultMap="FoodResult">
<include refid="selectFoodVo"/> select id, cid, title, cover, description, coupon, coupon_start_time, coupon_end_time, price, sort, area, recommend, recommend_start_time, recommend_end_time, sale_count, create_time, update_time, state, remark from food
<where> <where>
<if test="cid != null "> and cid = #{cid}</if> <if test="cid != null "> and cid = #{cid}</if>
<if test="title != null and title != ''"> and title like concat('%', #{title}, '%')</if> <if test="title != null and title != ''"> and title like concat('%', #{title}, '%')</if>

View File

@ -112,6 +112,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
.authorizeRequests() .authorizeRequests()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/register", "/captchaImage").permitAll() .antMatchers("/login", "/register", "/captchaImage").permitAll()
.antMatchers("/api/**").permitAll()
// 静态资源可匿名访问 // 静态资源可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()