06/05 16:47 初始化

This commit is contained in:
zyx 2023-06-05 16:48:29 +08:00
commit 69d3d47348
209 changed files with 41265 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

19
.idea/compiler.xml generated Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="mt_take_out" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="mt_take_out" options="-parameters" />
</option>
</component>
</project>

1081
.idea/easyCodeTableSetting.xml generated Normal file

File diff suppressed because it is too large Load Diff

7
.idea/encodings.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources/application.yml" charset="UTF-8" />
</component>
</project>

20
.idea/jarRepositories.xml generated Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://maven.aliyun.com/repository/public" />
</remote-repository>
</component>
</project>

14
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

124
.idea/uiDesigner.xml generated Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

96
pom.xml Normal file
View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cn.czyx007.mt</groupId>
<artifactId>mt_take_out</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mt_take_out</name>
<description>mt_take_out</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<!--邮箱验证的依赖-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
<version>5.6.133</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableTransactionManagement(proxyTargetClass = true)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1,123 @@
package cn.czyx007.mt.bean;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 地址管理(AddressBook)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:43
*/
@Data
@NoArgsConstructor
@TableName("address_book")
public class AddressBook implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 用户id
*/
private Long userId;
/**
* 收货人
*/
private String consignee;
/**
* 性别 0 1
*/
private Integer sex;
/**
* 手机号
*/
private String phone;
/**
* 省级区划编号
*/
private String provinceCode;
/**
* 省级名称
*/
private String provinceName;
/**
* 市级区划编号
*/
private String cityCode;
/**
* 市级名称
*/
private String cityName;
/**
* 区级区划编号
*/
private String districtCode;
/**
* 区级名称
*/
private String districtName;
/**
* 详细地址
*/
private String detail;
/**
* 标签
*/
private String label;
/**
* 默认 0 1是
*/
private Integer isDefault;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
private Long createUser;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
/**
* 是否删除
*/
private Integer isDeleted;
}

View File

@ -0,0 +1,68 @@
package cn.czyx007.mt.bean;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 菜品及套餐分类(Category)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Data
@NoArgsConstructor
@TableName("category")
public class Category implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 类型 1 菜品分类 2 套餐分类
*/
private Integer type;
/**
* 分类名称
*/
private String name;
/**
* 顺序
*/
private Integer sort;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
private Long createUser;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
}

View File

@ -0,0 +1,98 @@
package cn.czyx007.mt.bean;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 菜品管理(Dish)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Data
@NoArgsConstructor
@TableName("dish")
public class Dish implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 菜品名称
*/
private String name;
/**
* 菜品分类id
*/
private Long categoryId;
/**
* 菜品价格
*/
private Double price;
/**
* 商品码
*/
private String code;
/**
* 图片
*/
private String image;
/**
* 描述信息
*/
private String description;
/**
* 0 停售 1 起售
*/
private Integer status;
/**
* 顺序
*/
private Integer sort;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
private Long createUser;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
/**
* 是否删除
*/
private Integer isDeleted;
}

View File

@ -0,0 +1,73 @@
package cn.czyx007.mt.bean;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 菜品口味关系表(DishFlavor)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Data
@NoArgsConstructor
@TableName("dish_flavor")
public class DishFlavor implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 菜品
*/
private Long dishId;
/**
* 口味名称
*/
private String name;
/**
* 口味数据list
*/
private String value;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
private Long createUser;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
/**
* 是否删除
*/
private Integer isDeleted;
}

View File

@ -0,0 +1,88 @@
package cn.czyx007.mt.bean;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 员工信息(Employee)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Data
@NoArgsConstructor
@TableName("employee")
public class Employee implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 姓名
*/
private String name;
/**
* 用户名
*/
private String username;
/**
* 密码
*/
private String password;
/**
* 手机号
*/
private String phone;
/**
* 性别
*/
private String sex;
/**
* 身份证号
*/
private String idNumber;
/**
* 状态 0:禁用1:正常
*/
private Integer status;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
private Long createUser;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
}

View File

@ -0,0 +1,70 @@
package cn.czyx007.mt.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 订单明细表(OrderDetail)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Data
@NoArgsConstructor
@TableName("order_detail")
public class OrderDetail implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 名字
*/
private String name;
/**
* 图片
*/
private String image;
/**
* 订单id
*/
private Long orderId;
/**
* 菜品id
*/
private Long dishId;
/**
* 套餐id
*/
private Long setmealId;
/**
* 口味
*/
private String dishFlavor;
/**
* 数量
*/
private Integer number;
/**
* 金额
*/
private BigDecimal amount;
}

View File

@ -0,0 +1,85 @@
package cn.czyx007.mt.bean;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 订单表(Orders)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Data
@NoArgsConstructor
@TableName("orders")
public class Orders implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 订单号
*/
private String number;
/**
* 订单状态 1待付款2待派送3已派送4已完成5已取消
*/
private Integer status;
/**
* 下单用户
*/
private Long userId;
/**
* 地址id
*/
private Long addressBookId;
/**
* 下单时间
*/
private LocalDateTime orderTime;
/**
* 结账时间
*/
private LocalDateTime checkoutTime;
/**
* 支付方式 1微信,2支付宝
*/
private Integer payMethod;
/**
* 实收金额
*/
private BigDecimal amount;
/**
* 备注
*/
private String remark;
private String phone;
private String address;
private String userName;
private String consignee;
}

View File

@ -0,0 +1,93 @@
package cn.czyx007.mt.bean;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 套餐(Setmeal)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Data
@NoArgsConstructor
@TableName("setmeal")
public class Setmeal implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 菜品分类id
*/
private Long categoryId;
/**
* 套餐名称
*/
private String name;
/**
* 套餐价格
*/
private Double price;
/**
* 状态 0:停用 1:启用
*/
private Integer status;
/**
* 编码
*/
private String code;
/**
* 描述信息
*/
private String description;
/**
* 图片
*/
private String image;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
private Long createUser;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
/**
* 是否删除
*/
private Integer isDeleted;
}

View File

@ -0,0 +1,88 @@
package cn.czyx007.mt.bean;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 套餐菜品关系(SetmealDish)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Data
@NoArgsConstructor
@TableName("setmeal_dish")
public class SetmealDish implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 套餐id
*/
private Long setmealId;
/**
* 菜品id
*/
private Long dishId;
/**
* 菜品名称 冗余字段
*/
private String name;
/**
* 菜品原价冗余字段
*/
private Double price;
/**
* 份数
*/
private Integer copies;
/**
* 排序
*/
private Integer sort;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
private Long createUser;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
/**
* 是否删除
*/
private Integer isDeleted;
}

View File

@ -0,0 +1,75 @@
package cn.czyx007.mt.bean;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 购物车(ShoppingCart)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:46
*/
@Data
@NoArgsConstructor
@TableName("shopping_cart")
public class ShoppingCart implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 名称
*/
private String name;
/**
* 图片
*/
private String image;
/**
* 主键
*/
private Long userId;
/**
* 菜品id
*/
private Long dishId;
/**
* 套餐id
*/
private Long setmealId;
/**
* 口味
*/
private String dishFlavor;
/**
* 数量
*/
private Integer number;
/**
* 金额
*/
private BigDecimal amount;
/**
* 创建时间
*/
private LocalDateTime createTime;
}

View File

@ -0,0 +1,59 @@
package cn.czyx007.mt.bean;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Data;
/**
* 用户信息(User)表实体类
*
* @author 张宇轩
* @since 2023-05-29 11:08:46
*/
@Data
@NoArgsConstructor
@TableName("user")
public class User implements Serializable {
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 姓名
*/
private String name;
/**
* 手机号
*/
private String phone;
/**
* 性别
*/
private String sex;
/**
* 身份证号
*/
private String idNumber;
/**
* 头像
*/
private String avatar;
/**
* 状态 0:禁用1:正常
*/
private Integer status;
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.common;
/**
* @author : 张宇轩
* @createTime : 2023/5/31 - 9:31
*/
public class CustomException extends RuntimeException{
public CustomException() {
super();
}
public CustomException(String message) {
super(message);
}
}

View File

@ -0,0 +1,33 @@
package cn.czyx007.mt.common;
import cn.czyx007.mt.utils.R;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.sql.SQLIntegrityConstraintViolationException;
/**
* @author : 张宇轩
* @createTime : 2023/5/30 - 9:44
*/
//全局异常处理
@RestControllerAdvice(annotations = {RestController.class, Controller.class})
public class GlobalExceptionHandler {
@ExceptionHandler(SQLIntegrityConstraintViolationException.class)
public R<String> exceptionHandler(SQLIntegrityConstraintViolationException ex){
String msg = ex.getMessage();
String userName = "";
if(msg.contains("Duplicate entry")){
userName = msg.split(" ")[2];
}
return R.error(userName + ":已经存在,无法注册!");
}
@ExceptionHandler(CustomException.class)
public R<String> exceptionHandler(CustomException ex){
return R.error(ex.getMessage());
}
}

View File

@ -0,0 +1,51 @@
package cn.czyx007.mt.common;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
/**
* @author : 张宇轩
* @createTime : 2023/5/30 - 14:21
* 对象映射器:基于jackson将Java对象转为json或者将json转为Java对象
* 将JSON解析为Java对象的过程称为 [从JSON反序列化Java对象]
* 从Java对象生成JSON的过程称为 [序列化Java对象到JSON]
*/
public class JacksonObjectMapper extends ObjectMapper {
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
public JacksonObjectMapper() {
super();
//收到未知属性时不报异常
this.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
//反序列化时属性不存在的兼容处理
this.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
SimpleModule simpleModule = new SimpleModule()
.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)))
.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)))
.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)))
.addSerializer(BigInteger.class, ToStringSerializer.instance)
.addSerializer(Long.class, ToStringSerializer.instance)
.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)))
.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)))
.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)));
//注册功能模块 例如可以添加自定义序列化器和反序列化器
this.registerModule(simpleModule);
}
}

View File

@ -0,0 +1,33 @@
package cn.czyx007.mt.common;
import cn.czyx007.mt.utils.BaseContext;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author : 张宇轩
* @createTime : 2023/5/30 - 15:18
*/
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
log.info("insertFil: {}", metaObject.toString());
metaObject.setValue("createTime", LocalDateTime.now());
metaObject.setValue("updateTime", LocalDateTime.now());
metaObject.setValue("createUser", BaseContext.getCurrentId());
metaObject.setValue("updateUser", BaseContext.getCurrentId());
}
@Override
public void updateFill(MetaObject metaObject) {
log.info("updateFill: {}", metaObject.toString());
metaObject.setValue("updateTime", LocalDateTime.now());
metaObject.setValue("updateUser", BaseContext.getCurrentId());
}
}

View File

@ -0,0 +1,22 @@
package cn.czyx007.mt.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author : 张宇轩
* @createTime : 2023/5/30 - 10:42
*/
//这个类是MybatisPlus的配置类
@Configuration //该注解表示这个类是一个配置类
public class MybatisPlusConfig {
@Bean //该注解加在方法上表示该方法返回的实例交给spring管理
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}

View File

@ -0,0 +1,38 @@
package cn.czyx007.mt.config;
import cn.czyx007.mt.common.JacksonObjectMapper;
import cn.czyx007.mt.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Arrays;
import java.util.List;
/**
* @author : 张宇轩
* @createTime : 2023/5/29 - 15:28
*/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
//添加拦截器
@Override
public void addInterceptors(InterceptorRegistry registry) {
//定义不被拦截的路径
List<String> list = Arrays.asList(
"/employee/login", "/employee/logout",
"/user/sendMsg", "/user/login", "/user/loginout",
"/backend/**", "/front/**");
registry.addInterceptor(new LoginInterceptor())
.addPathPatterns("/**").excludePathPatterns(list);
}
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
messageConverter.setObjectMapper(new JacksonObjectMapper());
converters.add(0, messageConverter);
}
}

View File

@ -0,0 +1,81 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.AddressBook;
import cn.czyx007.mt.service.AddressBookService;
import cn.czyx007.mt.utils.BaseContext;
import cn.czyx007.mt.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.util.List;
/**
* 地址管理(AddressBook)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("addressBook")
public class AddressBookController {
/**
* 服务对象
*/
@Autowired
private AddressBookService addressBookService;
//查询当前登录用户的所有地址信息
@GetMapping("/list")
public R<List<AddressBook>> list(){
LambdaQueryWrapper<AddressBook> lqw = new LambdaQueryWrapper<>();
lqw.eq(AddressBook::getUserId, BaseContext.getCurrentId());
List<AddressBook> bookList = addressBookService.list(lqw);
return R.success(bookList);
}
//添加收货地址
@PostMapping
public R<String> add(@RequestBody AddressBook addressBook){
addressBook.setUserId(BaseContext.getCurrentId());
addressBookService.save(addressBook);
return R.success("地址保存成功");
}
//设置默认地址
@PutMapping("/default")
public R<String> defaultAddress(@RequestBody AddressBook addressBook){
addressBookService.defaultAddress(addressBook);
return R.success("设置默认地址成功!");
}
//查询默认地址
@GetMapping("/default")
public R<AddressBook> getDefaultAddress(){
LambdaQueryWrapper<AddressBook> lqw = new LambdaQueryWrapper<>();
lqw.eq(AddressBook::getUserId, BaseContext.getCurrentId()).eq(AddressBook::getIsDefault, 1);
return R.success(addressBookService.getOne(lqw));
}
//根据id获取地址信息
@GetMapping("/{id}")
public R<AddressBook> getAddressById(@PathVariable("id") Long id){
AddressBook addressBook = addressBookService.getById(id);
return R.success(addressBook);
}
//修改地址
@PutMapping
public R<String> updateAddress(@RequestBody AddressBook addressBook){
addressBookService.updateById(addressBook);
return R.success("地址修改成功!");
}
@DeleteMapping
public R<String> deleteAddress(@RequestParam("ids") Long ids){
addressBookService.removeById(ids);
return R.success("地址删除成功");
}
}

View File

@ -0,0 +1,72 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.Category;
import cn.czyx007.mt.bean.Employee;
import cn.czyx007.mt.service.CategoryService;
import cn.czyx007.mt.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.util.List;
/**
* 菜品及套餐分类(Category)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("category")
public class CategoryController {
/**
* 服务对象
*/
@Autowired
private CategoryService categoryService;
//添加菜品套餐的分类信息
@PostMapping
public R<String> add(@RequestBody Category category){
categoryService.save(category);
return R.success("添加成功!");
}
//分页查询员工信息
@GetMapping("/page")
public R<IPage<Category>> page(@RequestParam Integer page,
@RequestParam Integer pageSize){
IPage<Category> iPage = new Page<>(page, pageSize);
QueryWrapper<Category> lqw = new QueryWrapper<>();
lqw.lambda().orderByDesc(Category::getUpdateTime);
categoryService.page(iPage, lqw);
return R.success(iPage);
}
@PutMapping
public R<String> update(@RequestBody Category category){
categoryService.updateById(category);
return R.success("修改成功!");
}
@DeleteMapping
public R<String> removeById(@RequestParam("id") Long cateId){
//删除分类信息
categoryService.removeCateById(cateId);
return R.success("删除分类信息成功");
}
@GetMapping("/list")
public R<List<Category>> list(@RequestParam(required = false) Integer type){
LambdaQueryWrapper<Category> lqw = new LambdaQueryWrapper<>();
lqw.eq(type!=null, Category::getType, type).orderByDesc(Category::getUpdateTime);
List<Category> categoryList = categoryService.list(lqw);
return R.success(categoryList);
}
}

View File

@ -0,0 +1,26 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.utils.COSUploadUtils;
import cn.czyx007.mt.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
* @author : 张宇轩
* @createTime : 2023/5/31 - 11:47
*/
@Slf4j
@RestController
@RequestMapping("common")
public class CommonController {
@PostMapping("/upload")
public R<String> upload(MultipartFile file){
log.info("file: {}", file);
String filename = file.getOriginalFilename();
log.info("上传文件的名称:{}", filename);
return COSUploadUtils.uploadImage(file);
}
}

View File

@ -0,0 +1,168 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.*;
import cn.czyx007.mt.common.CustomException;
import cn.czyx007.mt.dto.DishDTO;
import cn.czyx007.mt.service.*;
import cn.czyx007.mt.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/**
* 菜品管理(Dish)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("dish")
public class DishController {
/**
* 服务对象
*/
@Autowired
private DishService dishService;
@Autowired
private CategoryService categoryService;
@Autowired
private SetmealDishService setmealDishService;
@Autowired
private DishFlavorService dishFlavorService;
//保存菜品和口味信息
@PostMapping
public R<String> saveDishFlavor(@RequestBody DishDTO dishDTO){
dishService.saveDishFlavor(dishDTO);
return R.success("菜品保存成功!");
}
//分页查询员工信息
@GetMapping("/page")
public R<IPage<DishDTO>> page(@RequestParam Integer page,
@RequestParam Integer pageSize,
@RequestParam(required = false) String name){
//这个iPageDto才是最后封装返回的分页数据
Page<DishDTO> iPageDto = new Page<>(page, pageSize);
Page<Dish> iPage = new Page<>(page, pageSize);
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.like(!StringUtils.isEmpty(name), Dish::getName, name).orderByDesc(Dish::getUpdateTime);
dishService.page(iPage, lqw);
//对象复制操作把iPage中的分页数据(页数总条数等)复制给iPageDto具体的菜品数据不复制
BeanUtils.copyProperties(iPage, iPageDto, "records");
//构建菜品数据封装到PageDto中
List<Dish> dishList = iPage.getRecords();
//把dishList转换为dishDtoList
List<DishDTO> dishDTOList = dishList.stream().map(dish -> {
//构建新的DishDTO对象
DishDTO dishDTO = new DishDTO();
//把dish复制给dishDIO
BeanUtils.copyProperties(dish, dishDTO);
//获取categoryName设置到DishDTo中
Category category = categoryService.getById(dish.getCategoryId());
dishDTO.setCategoryName( category.getName());
return dishDTO;
}).collect(Collectors.toList());
//设置dishDTOList到iPageDto
iPageDto.setRecords(dishDTOList);
return R.success(iPageDto);
}
@PostMapping("/status/{status}")
public R<String> setStatus(@PathVariable("status") Integer status,
@RequestParam List<Long> ids){
LambdaUpdateWrapper<Dish> luw = new LambdaUpdateWrapper<>();
luw.set(Dish::getStatus, status).set(Dish::getUpdateTime, LocalDateTime.now()).in(Dish::getId, ids);
dishService.update(luw);
return R.success("停售成功");
}
@DeleteMapping
public R<String> delete(@RequestParam List<Long> ids){
LambdaQueryWrapper<Dish> qw = new LambdaQueryWrapper<>();
qw.in(Dish::getId, ids).eq(Dish::getStatus, 1);
long cnt = dishService.count(qw);
if(cnt > 0){
throw new CustomException("存在起售的菜品,不能删除");
}
for (Long id : ids) {
LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
lqw.eq(SetmealDish::getDishId, id);
long count = setmealDishService.count(lqw);
if (count > 0) {
throw new CustomException("存在包含该菜品的套餐,无法删除");
}
}
for(Long id: ids) {
LambdaUpdateWrapper<DishFlavor> luw = new LambdaUpdateWrapper<>();
luw.eq(DishFlavor::getDishId, id);
dishFlavorService.remove(luw);
dishService.removeById(id);
}
return R.success("删除成功");
}
//根据菜品id查询菜品和口味的信息
@GetMapping("/{dishId}")
public R<DishDTO> getDIshFlavorById(@PathVariable("dishId") Long dishId){
DishDTO dishDTO = new DishDTO();
//查询菜品信息
Dish dish = dishService.getById(dishId);
BeanUtils.copyProperties(dish, dishDTO);
//查询当前菜品下的口味信息
LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
lqw.eq(DishFlavor::getDishId, dishId);
List<DishFlavor> dishFlavorList = dishFlavorService.list(lqw);
//把口味的集合放入DishDTO
dishDTO.setFlavors(dishFlavorList);
return R.success(dishDTO);
}
@PutMapping
public R<String> updateDishFlavor(@RequestBody DishDTO dishDTO){
dishService.updateDishFlavor(dishDTO);
return R.success("修改菜品信息成功");
}
//根据分类的id查询当前分类下的所有菜品信息
// @GetMapping("/list")
// private R<List<Dish>> list(@RequestParam("categoryId") Long categoryId){
// LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
// lqw.eq(categoryId!=null, Dish::getCategoryId, categoryId)
// .eq(Dish::getStatus, 1)
// .orderByDesc(Dish::getUpdateTime);
// List<Dish> dishList = dishService.list(lqw);
// return R.success(dishList);
// }
@GetMapping("/list")
private R<List<DishDTO>> list(Dish dish){
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId, dish.getCategoryId())
//status为空时对应后台页面非空则对应客户端页面
.eq(dish.getStatus()!=null, Dish::getStatus, dish.getStatus())
.orderByDesc(Dish::getSort).orderByDesc(Dish::getUpdateTime);
List<Dish> dishList = dishService.list(lqw);
List<DishDTO> dishDTOList = dishList.stream().map(item -> {
DishDTO dishDTO = new DishDTO();
BeanUtils.copyProperties(item, dishDTO);
//封装口味数据
LambdaQueryWrapper<DishFlavor> qw = new LambdaQueryWrapper<>();
qw.eq(DishFlavor::getDishId, item.getId());
List<DishFlavor> dishFlavorList = dishFlavorService.list(qw);
dishDTO.setFlavors(dishFlavorList);
return dishDTO;
}).collect(Collectors.toList());
return R.success(dishDTOList);
}
}

View File

@ -0,0 +1,27 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.DishFlavor;
import cn.czyx007.mt.service.DishFlavorService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
/**
* 菜品口味关系表(DishFlavor)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("dishFlavor")
public class DishFlavorController {
/**
* 服务对象
*/
@Autowired
private DishFlavorService dishFlavorService;
}

View File

@ -0,0 +1,115 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.Employee;
import cn.czyx007.mt.service.EmployeeService;
import cn.czyx007.mt.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
/**
* 员工信息(Employee)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("employee")
public class EmployeeController {
/**
* 服务对象
*/
@Autowired
private EmployeeService employeeService;
//用户登录
@PostMapping("/login")
public R<Employee> login(@RequestBody Employee employee, HttpSession session){
//加密前端提交的密码
String pwd = DigestUtils.md5DigestAsHex(employee.getPassword().getBytes());
//根据提交的用户名查询数据库
LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();
lqw.eq(Employee::getUsername, employee.getUsername());
Employee emp = employeeService.getOne(lqw);
//若没有查询到则返回登录失败结果
if (emp == null) {
return R.error("用户名不存在");
}
//密码比对不一致则返回登录失败结果
if (!emp.getPassword().equals(pwd)){
return R.error("密码错误");
}
//查看员工状态若为已禁用则返回员工已禁用结果
if (emp.getStatus() == 0){
return R.error("用户已经禁用,无法登录!");
}
//登录成功将员工id存入session并返回登录成功结果
session.setAttribute("employee", emp.getId());
return R.success(emp);
}
//退出登录
@PostMapping("/logout")
R<String> logout(HttpSession session){
//把当前登录用户的id从session中移除
session.removeAttribute("employee");
return R.success("退出成功");
}
@PostMapping
public R<String> addEmployee(@RequestBody Employee employee, HttpSession session){
//1.默认密码123456
employee.setPassword(DigestUtils.md5DigestAsHex(("123456").getBytes()));
//2.status有默认值1
//3.创建时间
employee.setCreateTime(LocalDateTime.now());
//4.更新时间
employee.setUpdateTime(LocalDateTime.now());
//5.创建人
Long id = (Long) session.getAttribute("employee");
employee.setCreateUser(id);
//6.更新人
employee.setUpdateUser(id);
employeeService.save(employee);
return R.success("添加成功");
}
//分页查询员工信息
@GetMapping("/page")
public R<IPage<Employee>> page(@RequestParam Integer page,
@RequestParam Integer pageSize,
@RequestParam(required = false) String name){
IPage<Employee> iPage = new Page<>(page, pageSize);
LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();
lqw.like(!StringUtils.isEmpty(name), Employee::getName, name).orderByDesc(Employee::getUpdateTime);
employeeService.page(iPage, lqw);
return R.success(iPage);
}
//修改员工状态
@PutMapping
public R<String> updateEmployee(HttpSession session, @RequestBody Employee employee){
//获取当前线程id
long id = Thread.currentThread().getId();
Long userId = (Long) session.getAttribute("employee");
employee.setUpdateTime(LocalDateTime.now());
employee.setUpdateUser(userId);
//mybatisplus只会更新非空字段
employeeService.updateById(employee);
return R.success("状态修改成功!");
}
@GetMapping("/{id}")
public R<Employee> getEmployeeById(@PathVariable("id") Long userId){
Employee employee = employeeService.getById(userId);
return R.success(employee);
}
}

View File

@ -0,0 +1,27 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.OrderDetail;
import cn.czyx007.mt.service.OrderDetailService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
/**
* 订单明细表(OrderDetail)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("orderDetail")
public class OrderDetailController {
/**
* 服务对象
*/
@Autowired
private OrderDetailService orderDetailService;
}

View File

@ -0,0 +1,83 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.Category;
import cn.czyx007.mt.bean.Orders;
import cn.czyx007.mt.bean.Setmeal;
import cn.czyx007.mt.dto.OrdersDTO;
import cn.czyx007.mt.dto.SetmealDTO;
import cn.czyx007.mt.service.OrdersService;
import cn.czyx007.mt.utils.BaseContext;
import cn.czyx007.mt.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/**
* 订单表(Orders)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("order")
public class OrdersController {
/**
* 服务对象
*/
@Autowired
private OrdersService ordersService;
@GetMapping("/page")
public R<IPage<Orders>> page(@RequestParam Integer page,
@RequestParam Integer pageSize,
@RequestParam(required = false) String number,
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@RequestParam(required = false) LocalDateTime beginTime,
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@RequestParam(required = false) LocalDateTime endTime){
Page<Orders> ordersPage = new Page<>(page, pageSize);
LambdaQueryWrapper<Orders> lqw = new LambdaQueryWrapper<>();
lqw.like(number!=null, Orders::getNumber, number)
.gt(beginTime!=null, Orders::getOrderTime, beginTime)
.lt(endTime!=null, Orders::getOrderTime, endTime);
ordersService.page(ordersPage, lqw);
return R.success(ordersPage);
}
@PutMapping
public R<String> setStatus(@RequestBody Orders orders){
LambdaUpdateWrapper<Orders> luw = new LambdaUpdateWrapper<>();
luw.eq(Orders::getId, orders.getId()).set(Orders::getStatus, orders.getStatus());
ordersService.update(luw);
return R.success("状态更改成功!");
}
//下单操作
@PostMapping("/submit")
public R<String> addOrder(@RequestBody Orders orders){
ordersService.addOrder(orders);
return R.success("下单成功");
}
//查看订单
@GetMapping("/userPage")
public R<Page<OrdersDTO>> page(@RequestParam Integer page,
@RequestParam Integer pageSize){
LambdaQueryWrapper<Orders> lqw = new LambdaQueryWrapper<>();
lqw.eq(Orders::getUserId, BaseContext.getCurrentId()).orderByDesc(Orders::getOrderTime);
Page<OrdersDTO> dtoPage = ordersService.getUserPage(page, pageSize, lqw);
return R.success(dtoPage);
}
}

View File

@ -0,0 +1,156 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.*;
import cn.czyx007.mt.common.CustomException;
import cn.czyx007.mt.dto.DishDTO;
import cn.czyx007.mt.dto.SetmealDTO;
import cn.czyx007.mt.dto.SetmealDishDTO;
import cn.czyx007.mt.service.CategoryService;
import cn.czyx007.mt.service.DishService;
import cn.czyx007.mt.service.SetmealDishService;
import cn.czyx007.mt.service.SetmealService;
import cn.czyx007.mt.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/**
* 套餐(Setmeal)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("setmeal")
public class SetmealController {
/**
* 服务对象
*/
@Autowired
private SetmealService setmealService;
@Autowired
private CategoryService categoryService;
@Autowired
private SetmealDishService setmealDishService;
@Autowired
private DishService dishService;
//添加套餐信息
@PostMapping
public R<String> saveSetmealDish(@RequestBody SetmealDTO setmealDTO){
setmealService.saveSetmealDish(setmealDTO);
return R.success("套餐添加成功!");
}
@GetMapping("/page")
public R<IPage<SetmealDTO>> page(@RequestParam Integer page,
@RequestParam Integer pageSize,
@RequestParam(required = false) String name){
IPage<SetmealDTO> setmealDTOIPage = new Page<>();
IPage<Setmeal> iPage = new Page<>(page, pageSize);
LambdaQueryWrapper<Setmeal> lqw = new LambdaQueryWrapper<>();
lqw.like(!StringUtils.isEmpty(name), Setmeal::getName, name);
setmealService.page(iPage, lqw);
BeanUtils.copyProperties(iPage, setmealDTOIPage, "records");
List<SetmealDTO> setmealDTOList = iPage.getRecords().stream().map(setmeal -> {
SetmealDTO setmealDTO = new SetmealDTO();
BeanUtils.copyProperties(setmeal, setmealDTO);
Category category = categoryService.getById(setmeal.getCategoryId());
setmealDTO.setCategoryName(category.getName());
return setmealDTO;
}).collect(Collectors.toList());
setmealDTOIPage.setRecords(setmealDTOList);
return R.success(setmealDTOIPage);
}
@PostMapping("/status/{status}")
public R<String> setStatus(@PathVariable("status") Integer status,
@RequestParam List<Long> ids){
LambdaUpdateWrapper<Setmeal> luw = new LambdaUpdateWrapper<>();
luw.set(Setmeal::getStatus, status).set(Setmeal::getUpdateTime, LocalDateTime.now()).in(Setmeal::getId, ids);
setmealService.update(luw);
return R.success("停售成功");
}
@DeleteMapping
public R<String> delete(@RequestParam List<Long> ids){
LambdaQueryWrapper<Setmeal> qw = new LambdaQueryWrapper<>();
qw.in(Setmeal::getId, ids).eq(Setmeal::getStatus, 1);
long cnt = setmealService.count(qw);
if(cnt > 0){
throw new CustomException("存在起售的套餐,不能删除");
}
for (Long id : ids) {
LambdaUpdateWrapper<SetmealDish> luw = new LambdaUpdateWrapper<>();
luw.eq(SetmealDish::getSetmealId, id);
setmealDishService.remove(luw);
}
setmealService.removeBatchByIds(ids);
return R.success("删除成功");
}
@GetMapping("/{setmealId}")
public R<SetmealDTO> getSetmealById(@PathVariable("setmealId") Long setmealId){
Setmeal setmeal = setmealService.getById(setmealId);
SetmealDTO setmealDTO = new SetmealDTO();
BeanUtils.copyProperties(setmeal, setmealDTO);
LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
lqw.eq(SetmealDish::getSetmealId, setmealId);
List<SetmealDish> setmealDishList = setmealDishService.list(lqw);
setmealDTO.setSetmealDishes(setmealDishList);
return R.success(setmealDTO);
}
@PutMapping
public R<String> update(@RequestBody SetmealDTO setmealDTO){
setmealService.updateSetmealDish(setmealDTO);
return R.success("套餐保存成功!");
}
//根据分类id和状态查询套餐信息
@GetMapping("/list")
// public R<List<Setmeal>> list(@RequestParam("categoryId") Long categoryId, @RequestParam("status") Integer status){
// LambdaQueryWrapper<Setmeal> lqw = new LambdaQueryWrapper<>();
// lqw.eq(Setmeal::getCategoryId, categoryId).eq(Setmeal::getStatus, status);
// List<Setmeal> list = setmealService.list(lqw);
// return R.success(list);
// }
public R<List<Setmeal>> list(Setmeal setmeal){
LambdaQueryWrapper<Setmeal> lqw = new LambdaQueryWrapper<>();
lqw.eq(Setmeal::getCategoryId, setmeal.getCategoryId())
.eq(setmeal.getStatus()!=null, Setmeal::getStatus, setmeal.getStatus())
.orderByDesc(Setmeal::getUpdateTime);
List<Setmeal> setmealList = setmealService.list(lqw);
return R.success(setmealList);
}
//查看套餐详情
@GetMapping("/dish/{id}")
public R<List<SetmealDishDTO>> getSetmealDetail(@PathVariable("id") Long id){
LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
lqw.eq(SetmealDish::getSetmealId, id).orderByDesc(SetmealDish::getUpdateTime);
List<SetmealDish> setmealDishList = setmealDishService.list(lqw);
List<SetmealDishDTO> list = setmealDishList.stream().map(setmealDish -> {
SetmealDishDTO setmealDishDTO = new SetmealDishDTO();
BeanUtils.copyProperties(setmealDish, setmealDishDTO);
Dish dish = dishService.getById(setmealDish.getDishId());
setmealDishDTO.setImage(dish.getImage());
return setmealDishDTO;
}).collect(Collectors.toList());
return R.success(list);
}
}

View File

@ -0,0 +1,53 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.Dish;
import cn.czyx007.mt.bean.SetmealDish;
import cn.czyx007.mt.dto.SetmealDishDTO;
import cn.czyx007.mt.service.DishService;
import cn.czyx007.mt.service.SetmealDishService;
import cn.czyx007.mt.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* 套餐菜品关系(SetmealDish)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("setmealDish")
public class SetmealDishController {
/**
* 服务对象
*/
@Autowired
private SetmealDishService setmealDishService;
@Autowired
private DishService dishService;
//查询套餐详情信息
@GetMapping("/dish/{id}")
public R<List<SetmealDishDTO>> setmealDetail(@PathVariable Long id) {
LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
lqw.eq(SetmealDish::getSetmealId, id)
.orderByDesc(SetmealDish::getUpdateTime);
List<SetmealDish> setmealDishList = setmealDishService.list(lqw);
List<SetmealDishDTO> setmealDishDTOList = setmealDishList.stream().map(setmealDish -> {
SetmealDishDTO setmealDishDTO = new SetmealDishDTO();
BeanUtils.copyProperties(setmealDish, setmealDishDTO);
Dish dish = dishService.getById(setmealDish.getDishId());
setmealDishDTO.setImage(dish.getImage());
return setmealDishDTO;
}).collect(Collectors.toList());
return R.success(setmealDishDTOList);
}
}

View File

@ -0,0 +1,61 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.ShoppingCart;
import cn.czyx007.mt.service.ShoppingCartService;
import cn.czyx007.mt.utils.BaseContext;
import cn.czyx007.mt.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.util.List;
/**
* 购物车(ShoppingCart)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("shoppingCart")
public class ShoppingCartController {
/**
* 服务对象
*/
@Autowired
private ShoppingCartService shoppingCartService;
@GetMapping("/list")
public R<List<ShoppingCart>> list(){
LambdaQueryWrapper<ShoppingCart> lqw = new LambdaQueryWrapper<>();
lqw.eq(ShoppingCart::getUserId, BaseContext.getCurrentId());
return R.success(shoppingCartService.list(lqw));
}
//添加购物车
@PostMapping("/add")
public R<ShoppingCart> add(@RequestBody ShoppingCart shoppingCart){
ShoppingCart cart = shoppingCartService.add(shoppingCart);
return R.success(cart);
}
//减少菜品/套餐数量
@PostMapping("/sub")
public R<ShoppingCart> sub(@RequestBody ShoppingCart cart){
ShoppingCart shoppingCart = shoppingCartService.sub(cart);
return R.success(shoppingCart);
}
//清空购物车
@DeleteMapping("/clean")
public R<String> clean(){
LambdaUpdateWrapper<ShoppingCart> luw = new LambdaUpdateWrapper<>();
luw.eq(ShoppingCart::getUserId, BaseContext.getCurrentId());
shoppingCartService.remove(luw);
return R.success("购物车清空成功");
}
}

View File

@ -0,0 +1,79 @@
package cn.czyx007.mt.controller;
import cn.czyx007.mt.bean.User;
import cn.czyx007.mt.service.UserService;
import cn.czyx007.mt.utils.R;
import cn.czyx007.mt.utils.SendEmailUtils;
import cn.czyx007.mt.utils.ValidateCodeUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.mail.EmailException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Map;
/**
* 用户信息(User)表控制层
*
* @author 张宇轩
* @since 2023-05-29 11:09:40
*/
@RestController
@RequestMapping("user")
@Slf4j
public class UserController {
/**
* 服务对象
*/
@Autowired
private UserService userService;
//发送验证码
@PostMapping("/sendMsg")
public R<String> sendMsg(@RequestBody User user, HttpSession session){
//生成6位随机数字验证码
String code = ValidateCodeUtils.generateValidateCode(6).toString();
log.info("验证码:{}", code);
//发送短信让用户接受验证码
try {
SendEmailUtils.sendAuthCodeEmail(user.getPhone(), code);
//把验证码保存到session
session.setAttribute("code", code);
return R.success("验证码发送成功");
} catch (EmailException e) {
e.printStackTrace();
return R.error("验证码发送失败");
}
}
//用户登录
@PostMapping("/login")
public R<String> login(HttpSession session, @RequestBody Map<String, Object> map){
//获取前端传递的数据
String phone = (String) map.get("phone");
String code = (String) map.get("code");
//将前端传来的code与session中的code比较
Object sessionCode = session.getAttribute("code");
if(code!=null && code.equals(sessionCode)){
//根据手机号查询用户信息
LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
lqw.eq(User::getPhone, phone);
User user = userService.getOne(lqw);
if (user == null) {
//用户不存在注册用户信息
user = new User();
user.setPhone(phone);
user.setStatus(1);
userService.save(user);
}
//将用户id存到session中
session.setAttribute("user", user.getId());
return R.success("用户登录成功");
}
return R.error("验证码错误");
}
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.AddressBook;
import org.apache.ibatis.annotations.Mapper;
/**
* 地址管理(AddressBook)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:43
*/
@Mapper
public interface AddressBookMapper extends BaseMapper<AddressBook> {
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.Category;
import org.apache.ibatis.annotations.Mapper;
/**
* 菜品及套餐分类(Category)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:43
*/
@Mapper
public interface CategoryMapper extends BaseMapper<Category> {
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.DishFlavor;
import org.apache.ibatis.annotations.Mapper;
/**
* 菜品口味关系表(DishFlavor)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Mapper
public interface DishFlavorMapper extends BaseMapper<DishFlavor> {
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.Dish;
import org.apache.ibatis.annotations.Mapper;
/**
* 菜品管理(Dish)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Mapper
public interface DishMapper extends BaseMapper<Dish> {
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.Employee;
import org.apache.ibatis.annotations.Mapper;
/**
* 员工信息(Employee)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Mapper
public interface EmployeeMapper extends BaseMapper<Employee> {
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.OrderDetail;
import org.apache.ibatis.annotations.Mapper;
/**
* 订单明细表(OrderDetail)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Mapper
public interface OrderDetailMapper extends BaseMapper<OrderDetail> {
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.Orders;
import org.apache.ibatis.annotations.Mapper;
/**
* 订单表(Orders)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Mapper
public interface OrdersMapper extends BaseMapper<Orders> {
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.SetmealDish;
import org.apache.ibatis.annotations.Mapper;
/**
* 套餐菜品关系(SetmealDish)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Mapper
public interface SetmealDishMapper extends BaseMapper<SetmealDish> {
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.Setmeal;
import org.apache.ibatis.annotations.Mapper;
/**
* 套餐(Setmeal)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Mapper
public interface SetmealMapper extends BaseMapper<Setmeal> {
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.ShoppingCart;
import org.apache.ibatis.annotations.Mapper;
/**
* 购物车(ShoppingCart)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Mapper
public interface ShoppingCartMapper extends BaseMapper<ShoppingCart> {
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.czyx007.mt.bean.User;
import org.apache.ibatis.annotations.Mapper;
/**
* 用户信息(User)表数据库访问层
*
* @author 张宇轩
* @since 2023-05-29 11:08:46
*/
@Mapper
public interface UserMapper extends BaseMapper<User> {
}

View File

@ -0,0 +1,21 @@
package cn.czyx007.mt.dto;
import cn.czyx007.mt.bean.Dish;
import cn.czyx007.mt.bean.DishFlavor;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @author : 张宇轩
* @createTime : 2023/5/31 - 14:30
*/
@Data
public class DishDTO extends Dish {
//口味的集合
private List<DishFlavor> flavors = new ArrayList<>();
//分类的名称 与前端elementUI的prop属性一致
private String categoryName;
}

View File

@ -0,0 +1,16 @@
package cn.czyx007.mt.dto;
import cn.czyx007.mt.bean.OrderDetail;
import cn.czyx007.mt.bean.Orders;
import lombok.Data;
import java.util.List;
/**
* @author : 张宇轩
* @createTime : 2023/6/5 - 16:15
*/
@Data
public class OrdersDTO extends Orders {
private List<OrderDetail> orderDetails;
}

View File

@ -0,0 +1,19 @@
package cn.czyx007.mt.dto;
import cn.czyx007.mt.bean.Setmeal;
import cn.czyx007.mt.bean.SetmealDish;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @author : 张宇轩
* @createTime : 2023/6/1 - 11:17
*/
@Data
public class SetmealDTO extends Setmeal {
private List<SetmealDish> setmealDishes = new ArrayList<>();
private String categoryName;
}

View File

@ -0,0 +1,13 @@
package cn.czyx007.mt.dto;
import cn.czyx007.mt.bean.SetmealDish;
import lombok.Data;
/**
* @author : 张宇轩
* @createTime : 2023/6/2 - 15:54
*/
@Data
public class SetmealDishDTO extends SetmealDish {
private String image;
}

View File

@ -0,0 +1,50 @@
package cn.czyx007.mt.interceptor;
import cn.czyx007.mt.utils.BaseContext;
import cn.czyx007.mt.utils.R;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author : 张宇轩
* @createTime : 2023/5/29 - 15:23
*/
//自定义拦截器
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
//请求到达控制器之前拦截
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//获取当前线程id
long id = Thread.currentThread().getId();
log.info("LoginInterceptor >> 线程Id: {}", id);
//1.通过请求获取session中的'员工'信息
Object empObj = request.getSession().getAttribute("employee");
//判断是否为空
if (empObj != null) {
log.info("当前员工用户已经登录员工用户id为{}", request.getSession().getAttribute("employee"));
Long empId = (Long) empObj;
//吧userId放入ThreadLocal中
BaseContext.setCurrentId(empId);
return true;
}
//2.通过请求获取session中的'用户'信息
Object userObj = request.getSession().getAttribute("user");
//判断是否为空
if (userObj != null) {
log.info("当前用户已经登录用户id为{}", request.getSession().getAttribute("user"));
Long userId = (Long) userObj;
//吧userId放入ThreadLocal中
BaseContext.setCurrentId(userId);
return true;
}
//响应数据
response.getWriter().write(JSONObject.toJSONString(R.error("NOTLOGIN")));
return false;
}
}

View File

@ -0,0 +1,14 @@
package cn.czyx007.mt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.AddressBook;
/**
* 地址管理(AddressBook)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:43
*/
public interface AddressBookService extends IService<AddressBook> {
void defaultAddress(AddressBook addressBook);
}

View File

@ -0,0 +1,15 @@
package cn.czyx007.mt.service;
import cn.czyx007.mt.common.CustomException;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.Category;
/**
* 菜品及套餐分类(Category)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
public interface CategoryService extends IService<Category> {
void removeCateById(Long cateId);
}

View File

@ -0,0 +1,13 @@
package cn.czyx007.mt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.DishFlavor;
/**
* 菜品口味关系表(DishFlavor)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
public interface DishFlavorService extends IService<DishFlavor> {
}

View File

@ -0,0 +1,17 @@
package cn.czyx007.mt.service;
import cn.czyx007.mt.dto.DishDTO;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.Dish;
/**
* 菜品管理(Dish)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
public interface DishService extends IService<Dish> {
void saveDishFlavor(DishDTO dishDTO);
void updateDishFlavor(DishDTO dishDTO);
}

View File

@ -0,0 +1,13 @@
package cn.czyx007.mt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.Employee;
/**
* 员工信息(Employee)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
public interface EmployeeService extends IService<Employee> {
}

View File

@ -0,0 +1,13 @@
package cn.czyx007.mt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.OrderDetail;
/**
* 订单明细表(OrderDetail)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
public interface OrderDetailService extends IService<OrderDetail> {
}

View File

@ -0,0 +1,19 @@
package cn.czyx007.mt.service;
import cn.czyx007.mt.dto.OrdersDTO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.Orders;
/**
* 订单表(Orders)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
public interface OrdersService extends IService<Orders> {
void addOrder(Orders orders);
Page<OrdersDTO> getUserPage(Integer page, Integer pageSize, LambdaQueryWrapper<Orders> lqw);
}

View File

@ -0,0 +1,13 @@
package cn.czyx007.mt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.SetmealDish;
/**
* 套餐菜品关系(SetmealDish)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
public interface SetmealDishService extends IService<SetmealDish> {
}

View File

@ -0,0 +1,17 @@
package cn.czyx007.mt.service;
import cn.czyx007.mt.dto.SetmealDTO;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.Setmeal;
/**
* 套餐(Setmeal)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
public interface SetmealService extends IService<Setmeal> {
void saveSetmealDish(SetmealDTO setmealDTO);
void updateSetmealDish(SetmealDTO setmealDTO);
}

View File

@ -0,0 +1,16 @@
package cn.czyx007.mt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.ShoppingCart;
/**
* 购物车(ShoppingCart)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
public interface ShoppingCartService extends IService<ShoppingCart> {
ShoppingCart add(ShoppingCart shoppingCart);
ShoppingCart sub(ShoppingCart cart);
}

View File

@ -0,0 +1,13 @@
package cn.czyx007.mt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.czyx007.mt.bean.User;
/**
* 用户信息(User)表服务接口
*
* @author 张宇轩
* @since 2023-05-29 11:08:46
*/
public interface UserService extends IService<User> {
}

View File

@ -0,0 +1,32 @@
package cn.czyx007.mt.service.impl;
import cn.czyx007.mt.utils.BaseContext;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.service.AddressBookService;
import cn.czyx007.mt.dao.AddressBookMapper;
import cn.czyx007.mt.bean.AddressBook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* 地址管理(AddressBook)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:43
*/
@Service
@Transactional
public class AddressBookServiceImpl extends ServiceImpl<AddressBookMapper, AddressBook> implements AddressBookService {
@Override
public void defaultAddress(AddressBook addressBook) {
//把当前登录用户的所有地址的默认值改为0
LambdaUpdateWrapper<AddressBook> luw = new LambdaUpdateWrapper<>();
luw.eq(AddressBook::getUserId, BaseContext.getCurrentId()).set(AddressBook::getIsDefault, 0);
this.update(luw);
//把当前登录用户的当前地址的默认值改为1
LambdaUpdateWrapper<AddressBook> luw1 = new LambdaUpdateWrapper<>();
luw1.eq(AddressBook::getId, addressBook.getId()).set(AddressBook::getIsDefault, 1);
this.update(luw1);
}
}

View File

@ -0,0 +1,51 @@
package cn.czyx007.mt.service.impl;
import cn.czyx007.mt.bean.Dish;
import cn.czyx007.mt.bean.Setmeal;
import cn.czyx007.mt.common.CustomException;
import cn.czyx007.mt.service.DishService;
import cn.czyx007.mt.service.SetmealService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.service.CategoryService;
import cn.czyx007.mt.dao.CategoryMapper;
import cn.czyx007.mt.bean.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* 菜品及套餐分类(Category)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Service
@Transactional
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
@Autowired
private DishService dishService;
@Autowired
private SetmealService setmealService;
@Override
public void removeCateById(Long cateId) {
//判断当前分类下是否有菜品信息如果有则不能删除
LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
lqw.eq(Dish::getCategoryId, cateId);
long dishCount = dishService.count(lqw);
if (dishCount > 0) {
throw new CustomException("当前分类下有菜品信息,不能删除!");
}
//判断当前分类下是否有套餐信息如果有则不能删除
LambdaQueryWrapper<Setmeal> lqw1 = new LambdaQueryWrapper<>();
lqw1.eq(Setmeal::getCategoryId, cateId);
long setmealCount = setmealService.count(lqw1);
if(setmealCount > 0){
throw new CustomException("当前分类下有套餐信息,不能删除!");
}
//删除当前分类信息
this.removeById(cateId);
}
}

View File

@ -0,0 +1,19 @@
package cn.czyx007.mt.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.service.DishFlavorService;
import cn.czyx007.mt.dao.DishFlavorMapper;
import cn.czyx007.mt.bean.DishFlavor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* 菜品口味关系表(DishFlavor)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Service
@Transactional
public class DishFlavorServiceImpl extends ServiceImpl<DishFlavorMapper, DishFlavor> implements DishFlavorService {
}

View File

@ -0,0 +1,58 @@
package cn.czyx007.mt.service.impl;
import cn.czyx007.mt.bean.DishFlavor;
import cn.czyx007.mt.dto.DishDTO;
import cn.czyx007.mt.service.DishFlavorService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.service.DishService;
import cn.czyx007.mt.dao.DishMapper;
import cn.czyx007.mt.bean.Dish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
/**
* 菜品管理(Dish)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Service
@Transactional
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish> implements DishService {
@Autowired
private DishFlavorService dishFlavorService;
@Override
public void saveDishFlavor(DishDTO dishDTO) {
//封装菜品信息保存
this.save(dishDTO);
//封装口味信息
List<DishFlavor> flavorList = dishDTO.getFlavors().stream().map(dishFlavor -> {
dishFlavor.setDishId(dishDTO.getId());
return dishFlavor;
}).collect(Collectors.toList());
//批量保存数据
dishFlavorService.saveBatch(flavorList);
}
@Override
public void updateDishFlavor(DishDTO dishDTO){
//保存修改的菜品信息
this.updateById(dishDTO);
//删除旧口味数据
LambdaUpdateWrapper<DishFlavor> luw = new LambdaUpdateWrapper<>();
luw.eq(DishFlavor::getDishId, dishDTO.getId());
dishFlavorService.remove(luw);
//保存新口味
List<DishFlavor> flavorList = dishDTO.getFlavors().stream().map(dishFlavor -> {
dishFlavor.setDishId(dishDTO.getId());
return dishFlavor;
}).collect(Collectors.toList());
dishFlavorService.saveBatch(flavorList);
}
}

View File

@ -0,0 +1,17 @@
package cn.czyx007.mt.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.service.EmployeeService;
import cn.czyx007.mt.dao.EmployeeMapper;
import cn.czyx007.mt.bean.Employee;
import org.springframework.stereotype.Service;
/**
* 员工信息(Employee)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {
}

View File

@ -0,0 +1,17 @@
package cn.czyx007.mt.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.service.OrderDetailService;
import cn.czyx007.mt.dao.OrderDetailMapper;
import cn.czyx007.mt.bean.OrderDetail;
import org.springframework.stereotype.Service;
/**
* 订单明细表(OrderDetail)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:44
*/
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements OrderDetailService {
}

View File

@ -0,0 +1,114 @@
package cn.czyx007.mt.service.impl;
import cn.czyx007.mt.bean.*;
import cn.czyx007.mt.common.CustomException;
import cn.czyx007.mt.dto.OrdersDTO;
import cn.czyx007.mt.service.*;
import cn.czyx007.mt.utils.BaseContext;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.dao.OrdersMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
* 订单表(Orders)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {
@Autowired
private UserService userService;
@Autowired
private AddressBookService addressBookService;
@Autowired
private ShoppingCartService shoppingCartService;
@Autowired
private OrderDetailService orderDetailService;
@Override
public void addOrder(Orders orders) {
//1.查询用户信息
User user = userService.getById(BaseContext.getCurrentId());
//2.查询地址信息
AddressBook addressBook = addressBookService.getById(orders.getAddressBookId());
//3.保存订单明细的数据
//3-1.生成订单id
long orderId = IdWorker.getId();
//3-2.查询购物车数据
LambdaQueryWrapper<ShoppingCart> lqw = new LambdaQueryWrapper<>();
lqw.eq(ShoppingCart::getUserId, BaseContext.getCurrentId());
List<ShoppingCart> shoppingCartList = shoppingCartService.list(lqw);
if (CollectionUtils.isEmpty(shoppingCartList)) {
throw new CustomException("当前购物车信息为空,无法下单");
}
//3-3.计算总金额-考虑多线程并发安全的问题
//AtomInteger提供了原子性的计算操作
AtomicInteger amount = new AtomicInteger();
//3-4.遍历购物车集合构建订单明细数据
List<OrderDetail> orderDetailList = shoppingCartList.stream().map(cart -> {
//总金额 += 数量*单价
amount.addAndGet(cart.getAmount()
.multiply(new BigDecimal(cart.getNumber())).intValue());
OrderDetail orderDetail = new OrderDetail();
orderDetail.setOrderId(orderId);
BeanUtils.copyProperties(cart, orderDetail);
return orderDetail;
}).collect(Collectors.toList());
//4.封装订单表的数据
Orders order = new Orders();
order.setNumber(String.valueOf(orderId));
order.setStatus(1);
order.setUserId(user.getId());
order.setAddressBookId(orders.getAddressBookId());
order.setOrderTime(LocalDateTime.now());
order.setPayMethod(2);
order.setAmount(new BigDecimal(amount.get()));
order.setRemark(orders.getRemark());
order.setPhone(addressBook.getPhone());
order.setAddress(addressBook.getDetail());
order.setUserName(user.getName());
order.setConsignee(addressBook.getConsignee());
//5.保存订单数据
this.save(order);
//6.保存订单明细苏剧
orderDetailService.saveBatch(orderDetailList);
//7.清空购物车数据
shoppingCartService.remove(lqw);
}
@Override
public Page<OrdersDTO> getUserPage(Integer page, Integer pageSize, LambdaQueryWrapper<Orders> lqw) {
Page<Orders> ordersPage = this.page(new Page<>(page, pageSize), lqw);
List<OrdersDTO> dtoList = ordersPage.getRecords().stream().map(orders -> {
OrdersDTO ordersDTO = new OrdersDTO();
LambdaQueryWrapper<OrderDetail> qw = new LambdaQueryWrapper<>();
qw.eq(OrderDetail::getOrderId, orders.getNumber());
List<OrderDetail> detailList = orderDetailService.list(qw);
BeanUtils.copyProperties(orders, ordersDTO);
ordersDTO.setOrderDetails(detailList);
return ordersDTO;
}).collect(Collectors.toList());
Page<OrdersDTO> dtoPage = new Page<>();
BeanUtils.copyProperties(ordersPage, dtoPage, "records");
dtoPage.setRecords(dtoList);
return dtoPage;
}
}

View File

@ -0,0 +1,17 @@
package cn.czyx007.mt.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.service.SetmealDishService;
import cn.czyx007.mt.dao.SetmealDishMapper;
import cn.czyx007.mt.bean.SetmealDish;
import org.springframework.stereotype.Service;
/**
* 套餐菜品关系(SetmealDish)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Service
public class SetmealDishServiceImpl extends ServiceImpl<SetmealDishMapper, SetmealDish> implements SetmealDishService {
}

View File

@ -0,0 +1,56 @@
package cn.czyx007.mt.service.impl;
import cn.czyx007.mt.bean.SetmealDish;
import cn.czyx007.mt.dto.SetmealDTO;
import cn.czyx007.mt.service.SetmealDishService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.service.SetmealService;
import cn.czyx007.mt.dao.SetmealMapper;
import cn.czyx007.mt.bean.Setmeal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* 套餐(Setmeal)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, Setmeal> implements SetmealService {
@Autowired
private SetmealDishService setmealDishService;
@Override
public void saveSetmealDish(SetmealDTO setmealDTO) {
//保存套餐信息
this.save(setmealDTO);
//保存套餐菜品信息
List<SetmealDish> list = setmealDTO.getSetmealDishes().stream().map(setmealDish -> {
setmealDish.setSetmealId(setmealDTO.getId());
return setmealDish;
}).collect(Collectors.toList());
setmealDishService.saveBatch(list);
}
@Override
public void updateSetmealDish(SetmealDTO setmealDTO) {
//保存套餐信息
this.updateById(setmealDTO);
//清空原有菜品信息
LambdaUpdateWrapper<SetmealDish> luw = new LambdaUpdateWrapper<>();
luw.eq(SetmealDish::getSetmealId, setmealDTO.getId());
setmealDishService.remove(luw);
//保存套餐新菜品信息
List<SetmealDish> list = setmealDTO.getSetmealDishes().stream().map(setmealDish -> {
setmealDish.setSetmealId(setmealDTO.getId());
return setmealDish;
}).collect(Collectors.toList());
setmealDishService.saveBatch(list);
}
}

View File

@ -0,0 +1,72 @@
package cn.czyx007.mt.service.impl;
import cn.czyx007.mt.utils.BaseContext;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.service.ShoppingCartService;
import cn.czyx007.mt.dao.ShoppingCartMapper;
import cn.czyx007.mt.bean.ShoppingCart;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
/**
* 购物车(ShoppingCart)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:45
*/
@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {
@Override
public ShoppingCart add(ShoppingCart shoppingCart) {
//查询当前购物车的菜品/套餐是否在数据库存在
//若存在则number+1否则添加到购物车表中
//1.1.查询当前用户的购物车信息
LambdaQueryWrapper<ShoppingCart> lqw = new LambdaQueryWrapper<>();
lqw.eq(ShoppingCart::getUserId, BaseContext.getCurrentId());
//1.2.判断查询的是菜品还是套餐
Long dishId = shoppingCart.getDishId();
if(dishId != null){
lqw.eq(ShoppingCart::getDishId, dishId);
} else {
lqw.eq(ShoppingCart::getSetmealId, shoppingCart.getSetmealId());
}
//1.3.执行查询
ShoppingCart cart = this.getOne(lqw);
//2 如果存在数量+1
if(cart != null){
cart.setNumber(cart.getNumber()+1);
this.updateById(cart);
} else {
//3 不存在添加到购物车表中
shoppingCart.setCreateTime(LocalDateTime.now());
shoppingCart.setUserId(BaseContext.getCurrentId());
shoppingCart.setNumber(1);
this.save(shoppingCart);
cart = shoppingCart;
}
return cart;
}
@Override
public ShoppingCart sub(ShoppingCart cart) {
//查询菜品/套餐的购物车数据
LambdaQueryWrapper<ShoppingCart> lqw = new LambdaQueryWrapper<>();
lqw.eq(ShoppingCart::getUserId, BaseContext.getCurrentId());
if(cart.getDishId() != null){
lqw.eq(ShoppingCart::getDishId, cart.getDishId());
} else {
lqw.eq(ShoppingCart::getSetmealId, cart.getSetmealId());
}
ShoppingCart shoppingCart = this.getOne(lqw);
//修改数量
if(shoppingCart.getNumber() == 1){
this.removeById(shoppingCart);
}
shoppingCart.setNumber(shoppingCart.getNumber()-1);
this.updateById(shoppingCart);
return shoppingCart;
}
}

View File

@ -0,0 +1,17 @@
package cn.czyx007.mt.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.czyx007.mt.service.UserService;
import cn.czyx007.mt.dao.UserMapper;
import cn.czyx007.mt.bean.User;
import org.springframework.stereotype.Service;
/**
* 用户信息(User)表服务实现类
*
* @author 张宇轩
* @since 2023-05-29 11:08:46
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
}

View File

@ -0,0 +1,24 @@
package cn.czyx007.mt.utils;
/**
* @author : 张宇轩
* @createTime : 2023/5/30 - 15:51
* 基于ThreadLocal封装工具类用户保存和获取当前登录用户id
*/
public class BaseContext {
private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
/**
* 设置值
* @param id
*/
public static void setCurrentId(Long id){
threadLocal.set(id);
}
/**
* 获取值
* @return
*/
public static Long getCurrentId(){
return threadLocal.get();
}
}

View File

@ -0,0 +1,74 @@
package cn.czyx007.mt.utils;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.BasicSessionCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.qcloud.cos.region.Region;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.UUID;
/**
* @author : 张宇轩
* @createTime : 2023/5/31 - 11:08
*/
@Slf4j
public class COSUploadUtils {
private static COSClient cosClient;
private static final String secretId = "";
private static final String secretKey = "";
private static final String regionName = "";
private static void createCOSClient() {
// 1 初始化用户身份信息secretId, secretKey
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
// 2 设置 bucket 的地域, COS 地域的简称请参见
// clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分
Region region = new Region(regionName);
ClientConfig clientConfig = new ClientConfig(region);
// 这里建议设置使用 https 协议
// 5.6.54 版本开始默认使用了 https
clientConfig.setHttpProtocol(HttpProtocol.https);
// 3 生成 cos 客户端
cosClient = new COSClient(cred, clientConfig);
}
//实现图片的上传
public static R uploadImage(MultipartFile file) {
try {
createCOSClient();
//1.重新生成文件的名称-不重复的
String newName = UUID.randomUUID().toString().replace("-", "");
//200b4b6ced284daaaca89ba6ff0f85ae.png
//2.获取原文件的后缀 .png
String oldName = file.getOriginalFilename();
String suffix = oldName.substring(oldName.lastIndexOf("."));
//3.拼接成新的文件的名字
String newFileName = newName + suffix;
//4.实现文件上传
File localFile = File.createTempFile(newName, suffix);
file.transferTo(localFile);
//指定文件将要存放的存储桶
String bucketName = "mt-take-out-1259733126";
// 指定文件上传到 COS 上的路径即对象键例如对象键为 folder/picture.jpg则表示将文件 picture.jpg 上传到 folder 路径下
String key = newFileName;
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
//5.返回域名+图片名让前端能够显示
return R.success("https://"+bucketName+".cos."+regionName+".myqcloud.com/" + newFileName);
} catch (Exception e) {
log.error(e.getMessage());
return R.error("图片上传失败!");
} finally {
cosClient.shutdown();
}
}
}

View File

@ -0,0 +1,34 @@
package cn.czyx007.mt.utils;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
/**
* 通用返回结果服务端响应的数据最终都会封装成此对象
* @param <T>
*/
@Data
public class R<T> {
private Integer code; //编码1成功0和其它数字为失败
private String msg; //错误信息
private T data; //数据
private Map map = new HashMap(); //动态数据
public static <T> R<T> success(T object) {
R<T> r = new R<T>();
r.data = object;
r.code = 1;
return r;
}
public static <T> R<T> error(String msg) {
R r = new R();
r.msg = msg;
r.code = 0;
return r;
}
public R<T> add(String key, Object value) {
this.map.put(key, value);
return this;
}
}

View File

@ -0,0 +1,53 @@
package cn.czyx007.mt.utils;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* @author : 张宇轩
* @createTime : 2023/1/19 - 15:43
*/
@Component
public class SendEmailUtils {
private static String userName;
private static String password;
@Value("${email.userName}")
public void setUserName(String userName) {
SendEmailUtils.userName = userName;
}
@Value("${email.password}")
public void setPassword(String password) {
SendEmailUtils.password = password;
}
/**
* 发送验证码
* @param email 接收邮箱
* @param code 验证码
*/
public static void sendAuthCodeEmail(String email,String code) throws EmailException {
HtmlEmail mail = new HtmlEmail();
/*发送邮件的服务器 126邮箱为smtp.126.com,163邮箱为163.smtp.comQQ为smtp.qq.com*/
mail.setHostName("smtp.qq.com");
/*不设置发送的消息有可能是乱码*/
mail.setCharset("UTF-8");
/*IMAP/SMTP服务的密码 username为你开启发送验证码功能的邮箱号 password为你在qq邮箱获取到的一串字符串*/
mail.setAuthentication(userName, password);
/*发送邮件的邮箱和发件人*/
mail.setFrom(userName, "美食元素");
/*使用安全链接*/
mail.setSSLOnConnect(true);
/*接收的邮箱*/
mail.addTo(email);
/*设置邮件的主题*/
mail.setSubject("登录验证码");
/*设置邮件的内容*/
mail.setMsg("尊敬的用户:你好! 登录验证码为:" + code + "(有效期为一分钟)");
mail.send();//发送
}
}

View File

@ -0,0 +1,43 @@
package cn.czyx007.mt.utils;
import java.util.Random;
/**
* 随机生成验证码工具类
*/
public class ValidateCodeUtils {
/**
* 随机生成验证码
* @param length 长度为4位或者6位
* @return
*/
public static Integer generateValidateCode(int length){
Integer code =null;
if(length == 4){
code = new Random().nextInt(9999);//生成随机数最大为9999
if(code < 1000){
code = code + 1000;//保证随机数为4位数字
}
}else if(length == 6){
code = new Random().nextInt(999999);//生成随机数最大为999999
if(code < 100000){
code = code + 100000;//保证随机数为6位数字
}
}else{
throw new RuntimeException("只能生成4位或6位数字验证码");
}
return code;
}
/**
* 随机生成指定长度字符串验证码
* @param length 长度
* @return
*/
public static String generateValidateCode4String(int length){
Random rdm = new Random();
String hash1 = Integer.toHexString(rdm.nextInt());
String capstr = hash1.substring(0, length);
return capstr;
}
}

View File

@ -0,0 +1,41 @@
spring:
application:
#应用名称 , 可选
name: mt_take_out
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/db_mt?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
username: root
password:
#初始化连接数
initial-size: 1
#最小空闲连接
min-idle: 1
#最大活动连接
max-active: 20
#获取连接时测试是否可用
test-on-borrow: true
#监控页面启动
filter:
wall:
config:
start-transaction-allow: true
mybatis-plus:
configuration:
#在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射 address_book ---> AddressBook
map-underscore-to-camel-case: true
#日志输出
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
id-type: ASSIGN_ID
#用于发送邮箱验证码的账户和密码
email:
#gmail
# userName:
# password:
#qq
userName:
password:

View File

@ -0,0 +1,43 @@
// 查询列表接口
const getCategoryPage = (params) => {
return $axios({
url: '/category/page',
method: 'get',
params
})
}
// 编辑页面反查详情接口
const queryCategoryById = (id) => {
return $axios({
url: `/category/${id}`,
method: 'get'
})
}
// 删除当前列的接口
const deleCategory = (id) => {
return $axios({
url: '/category',
method: 'delete',
params: { id }
})
}
// 修改接口
const editCategory = (params) => {
return $axios({
url: '/category',
method: 'put',
data: { ...params }
})
}
// 新增接口
const addCategory = (params) => {
return $axios({
url: '/category',
method: 'post',
data: { ...params }
})
}

View File

@ -0,0 +1,52 @@
// 查询列表数据
const getSetmealPage = (params) => {
return $axios({
url: '/setmeal/page',
method: 'get',
params
})
}
// 删除数据接口
const deleteSetmeal = (ids) => {
return $axios({
url: '/setmeal',
method: 'delete',
params: { ids }
})
}
// 修改数据接口
const editSetmeal = (params) => {
return $axios({
url: '/setmeal',
method: 'put',
data: { ...params }
})
}
// 新增数据接口
const addSetmeal = (params) => {
return $axios({
url: '/setmeal',
method: 'post',
data: { ...params }
})
}
// 查询详情接口
const querySetmealById = (id) => {
return $axios({
url: `/setmeal/${id}`,
method: 'get'
})
}
// 批量起售禁售
const setmealStatusByStatus = (params) => {
return $axios({
url: `/setmeal/status/${params.status}`,
method: 'post',
params: { ids: params.ids }
})
}

View File

@ -0,0 +1,82 @@
// 查询列表接口
const getDishPage = (params) => {
return $axios({
url: '/dish/page',
method: 'get',
params
})
}
// 删除接口
const deleteDish = (ids) => {
return $axios({
url: '/dish',
method: 'delete',
params: { ids }
})
}
// 修改接口
const editDish = (params) => {
return $axios({
url: '/dish',
method: 'put',
data: { ...params }
})
}
// 新增接口
const addDish = (params) => {
return $axios({
url: '/dish',
method: 'post',
data: { ...params }
})
}
// 查询详情
const queryDishById = (id) => {
return $axios({
url: `/dish/${id}`,
method: 'get'
})
}
// 获取菜品分类列表
const getCategoryList = (params) => {
return $axios({
url: '/category/list',
method: 'get',
params
})
}
// 查菜品列表的接口
const queryDishList = (params) => {
return $axios({
url: '/dish/list',
method: 'get',
params
})
}
// 文件down预览
const commonDownload = (params) => {
return $axios({
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
url: '/common/download',
method: 'get',
params
})
}
// 起售停售---批量起售停售接口
const dishStatusByStatus = (params) => {
return $axios({
url: `/dish/status/${params.status}`,
method: 'post',
params: { ids: params.id }
})
}

View File

@ -0,0 +1,14 @@
function loginApi(data) {
return $axios({
'url': '/employee/login',
'method': 'post',
data
})
}
function logoutApi(){
return $axios({
'url': '/employee/logout',
'method': 'post',
})
}

View File

@ -0,0 +1,42 @@
function getMemberList (params) {
return $axios({
url: '/employee/page',
method: 'get',
params
})
}
// 修改---启用禁用接口
function enableOrDisableEmployee (params) {
return $axios({
url: '/employee',
method: 'put',
data: { ...params }
})
}
// 新增---添加员工
function addEmployee (params) {
return $axios({
url: '/employee',
method: 'post',
data: { ...params }
})
}
// 修改---添加员工
function editEmployee (params) {
return $axios({
url: '/employee',
method: 'put',
data: { ...params }
})
}
// 修改页面反查详情接口
function queryEmployeeById (id) {
return $axios({
url: `/employee/${id}`,
method: 'get'
})
}

View File

@ -0,0 +1,25 @@
// 查询列表页接口
const getOrderDetailPage = (params) => {
return $axios({
url: '/order/page',
method: 'get',
params
})
}
// 查看接口
const queryOrderDetailById = (id) => {
return $axios({
url: `/orderDetail/${id}`,
method: 'get'
})
}
// 取消,派送,完成接口
const editOrderDetail = (params) => {
return $axios({
url: '/order',
method: 'put',
data: { ...params }
})
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Some files were not shown because too many files have changed in this diff Show More