Compare commits
5 Commits
main
...
Branch/yzp
| Author | SHA1 | Date |
|---|---|---|
|
|
875bc6ed59 | 1 year ago |
|
|
45f0aed4b7 | 1 year ago |
|
|
d68964cad7 | 1 year ago |
|
|
0f41b6b56c | 1 year ago |
|
|
b29fad2c32 | 1 year ago |
@ -1,10 +0,0 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Zeppelin 忽略的文件
|
||||
/ZeppelinRemoteNotebooks/
|
||||
@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<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="springcache-demo" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="springcache-demo" options="-parameters" />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<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>
|
||||
</component>
|
||||
</project>
|
||||
@ -1,12 +0,0 @@
|
||||
<?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_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,53 +0,0 @@
|
||||
package com.itheima.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
|
||||
/**
|
||||
* 生成接口文档配置
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Docket docket(){
|
||||
log.info("准备生成接口文档...");
|
||||
|
||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||
.title("接口文档")
|
||||
.version("2.0")
|
||||
.description("接口文档")
|
||||
.build();
|
||||
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo)
|
||||
.select()
|
||||
//指定生成接口需要扫描的包
|
||||
.apis(RequestHandlerSelectors.basePackage("com.itheima.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
|
||||
return docket;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置静态资源映射
|
||||
* @param registry
|
||||
*/
|
||||
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
log.info("开始设置静态资源映射...");
|
||||
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
package com.itheima.mapper;
|
||||
|
||||
import com.itheima.entity.User;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper{
|
||||
|
||||
@Insert("insert into user(name,age) values (#{name},#{age})")
|
||||
@Options(useGeneratedKeys = true,keyProperty = "id")
|
||||
void insert(User user);
|
||||
|
||||
@Delete("delete from user where id = #{id}")
|
||||
void deleteById(Long id);
|
||||
|
||||
@Delete("delete from user")
|
||||
void deleteAll();
|
||||
|
||||
@Select("select * from user where id = #{id}")
|
||||
User getById(Long id);
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
# 定义服务的配置项
|
||||
server:
|
||||
# 设置服务的端口号为8888
|
||||
port: 8888
|
||||
spring:
|
||||
# 数据源配置
|
||||
datasource:
|
||||
# 配置Druid连接池
|
||||
druid:
|
||||
# 指定JDBC驱动类名
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# 指定数据库连接URL
|
||||
url: jdbc:mysql://localhost:3306/spring_cache_demo?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||
# 指定数据库用户名
|
||||
username: root
|
||||
# 指定数据库密码
|
||||
password: root
|
||||
# Redis配置
|
||||
redis:
|
||||
# 指定Redis服务器地址
|
||||
host: localhost
|
||||
# 指定Redis服务器端口
|
||||
port: 6379
|
||||
# 指定Redis密码
|
||||
password: 123456
|
||||
# 指定Redis数据库索引
|
||||
database: 1
|
||||
# 日志配置
|
||||
logging:
|
||||
# 设置日志级别
|
||||
level:
|
||||
# 设置com.itheima包下的mapper日志级别为debug
|
||||
com:
|
||||
itheima:
|
||||
mapper: debug
|
||||
# 设置com.itheima包下的service日志级别为info
|
||||
service: info
|
||||
# 设置com.itheima包下的controller日志级别为info
|
||||
controller: info
|
||||
@ -1,21 +0,0 @@
|
||||
server:
|
||||
port: 8888
|
||||
spring:
|
||||
datasource:
|
||||
druid:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/spring_cache_demo?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: root
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
password: 123456
|
||||
database: 1
|
||||
logging:
|
||||
level:
|
||||
com:
|
||||
itheima:
|
||||
mapper: debug
|
||||
service: info
|
||||
controller: info
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
package com.sky.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 订单取消数据传输对象
|
||||
*/
|
||||
@Data
|
||||
public class OrdersCancelDTO implements Serializable {
|
||||
|
||||
// 订单ID
|
||||
private Long id;
|
||||
|
||||
// 订单取消原因
|
||||
private String cancelReason;
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.sky.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class OrdersPaymentDTO implements Serializable {
|
||||
//订单号
|
||||
private String orderNumber;
|
||||
|
||||
//付款方式
|
||||
private Integer payMethod;
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.sky.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 订单拒绝数据传输对象
|
||||
*/
|
||||
@Data
|
||||
public class OrdersRejectionDTO implements Serializable {
|
||||
|
||||
// 订单ID
|
||||
private Long id;
|
||||
|
||||
// 订单拒绝原因
|
||||
private String rejectionReason;
|
||||
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.sky.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class OrdersSubmitDTO implements Serializable {
|
||||
//地址簿id
|
||||
private Long addressBookId;
|
||||
//付款方式
|
||||
private int payMethod;
|
||||
//备注
|
||||
private String remark;
|
||||
//预计送达时间
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime estimatedDeliveryTime;
|
||||
//配送状态 1立即送出 0选择具体时间
|
||||
private Integer deliveryStatus;
|
||||
//餐具数量
|
||||
private Integer tablewareNumber;
|
||||
//餐具数量状态 1按餐量提供 0选择具体数量
|
||||
private Integer tablewareStatus;
|
||||
//打包费
|
||||
private Integer packAmount;
|
||||
//总金额
|
||||
private BigDecimal amount;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.sky.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class PasswordEditDTO implements Serializable {
|
||||
|
||||
//员工id
|
||||
private Long empId;
|
||||
|
||||
//旧密码
|
||||
private String oldPassword;
|
||||
|
||||
//新密码
|
||||
private String newPassword;
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.sky.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 购物车数据传输对象
|
||||
*/
|
||||
@Data
|
||||
public class ShoppingCartDTO implements Serializable {
|
||||
|
||||
// 菜品ID
|
||||
private Long dishId;
|
||||
|
||||
// 套餐ID
|
||||
private Long setmealId;
|
||||
|
||||
// 菜品口味
|
||||
private String dishFlavor;
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.sky.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* C端用户登录数据传输对象
|
||||
*/
|
||||
@Data
|
||||
public class UserLoginDTO implements Serializable {
|
||||
|
||||
// 登录凭证(如微信登录时的授权码)
|
||||
private String code;
|
||||
|
||||
}
|
||||
@ -0,0 +1,132 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>sky-take-out</artifactId>
|
||||
<groupId>com.sky</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>sky-server</artifactId>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sky</groupId>
|
||||
<artifactId>sky-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sky</groupId>
|
||||
<artifactId>sky-pojo</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- poi -->
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,82 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.entity.AddressBook;
|
||||
import com.sky.mapper.AddressBookMapper;
|
||||
import com.sky.service.AddressBookService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class AddressBookServiceImpl implements AddressBookService {
|
||||
|
||||
@Autowired
|
||||
private AddressBookMapper addressBookMapper;
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
* @param addressBook
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<AddressBook> list(AddressBook addressBook) {
|
||||
return addressBookMapper.list(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增地址
|
||||
* @param addressBook
|
||||
*/
|
||||
@Override
|
||||
public void save(AddressBook addressBook) {
|
||||
addressBook.setUserId(BaseContext.getCurrentId());
|
||||
addressBook.setIsDefault(0);
|
||||
addressBookMapper.insert(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AddressBook getById(Long id) {
|
||||
return addressBookMapper.getById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id修改地址
|
||||
* @param addressBook
|
||||
*/
|
||||
@Override
|
||||
public void update(AddressBook addressBook) {
|
||||
addressBookMapper.update(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认地址
|
||||
* @param addressBook
|
||||
*/
|
||||
@Override
|
||||
public void setDefault(AddressBook addressBook) {
|
||||
//1、将当前用户的所有地址修改为非默认地址 update address_book set is_default = ? where user_id = ?
|
||||
addressBook.setIsDefault(0);
|
||||
addressBook.setUserId(BaseContext.getCurrentId());
|
||||
addressBookMapper.updateIsDefaultByUserId(addressBook);
|
||||
|
||||
//2、将当前地址改为默认地址 update address_book set is_default = ? where id = ?
|
||||
addressBook.setIsDefault(1);
|
||||
addressBookMapper.update(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id删除地址
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void deleteById(Long id) {
|
||||
addressBookMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,231 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.DishFlavor;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.entity.SetmealDish;
|
||||
import com.sky.exception.DeletionNotAllowedException;
|
||||
import com.sky.mapper.DishFlavorMapper;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DishServiceImpl implements DishService {
|
||||
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
|
||||
@Autowired
|
||||
private DishFlavorMapper dishFlavorMapper;
|
||||
|
||||
@Autowired
|
||||
private SetmealDishMapper setmealDishMapper;
|
||||
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
|
||||
/**
|
||||
* 新增菜品
|
||||
* @param dishDTO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveWithFlavor(DishDTO dishDTO) {
|
||||
Dish dish = new Dish();
|
||||
BeanUtils.copyProperties(dishDTO, dish);
|
||||
|
||||
// 向菜品表插入1条数据
|
||||
dishMapper.insert(dish);
|
||||
|
||||
// 获取insert语句生成的主键值
|
||||
Long dishId = dish.getId();
|
||||
|
||||
List<DishFlavor> flavors = dishDTO.getFlavors();
|
||||
if (flavors != null && flavors.size() > 0) {
|
||||
flavors.forEach(dishFlavor -> dishFlavor.setDishId(dishId));
|
||||
// 向口味表插入n条数据
|
||||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param dishPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO) {
|
||||
PageHelper.startPage(dishPageQueryDTO.getPage(), dishPageQueryDTO.getPageSize());
|
||||
Page<DishVO> page=dishMapper.pageQuery(dishPageQueryDTO);
|
||||
return new PageResult(page.getTotal(), page.getResult());
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品批量删除
|
||||
* @param ids
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteBatch(List<Long> ids) {
|
||||
// 判断当前菜品是否能够删除---是否存在起售中的菜品??
|
||||
ids.forEach(id->{
|
||||
Dish dish = dishMapper.getById(id);
|
||||
if (dish.getStatus() == StatusConstant.ENABLE) {
|
||||
// 当前菜品处于起售中,不能删除
|
||||
throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
|
||||
}
|
||||
});
|
||||
|
||||
// 判断当前菜品是否能够删除---是否被套餐关联了??
|
||||
List<Long> setmealIds = setmealDishMapper.getSetmealIdsByDishIds(ids);
|
||||
if (setmealIds != null && setmealIds.size() > 0) {
|
||||
// 当前菜品被套餐关联了,不能删除
|
||||
throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
|
||||
}
|
||||
|
||||
// 删除菜品表中的菜品数据
|
||||
ids.forEach(id->{
|
||||
dishMapper.deleteById(id);
|
||||
|
||||
// 删除菜单关联的口味数据
|
||||
dishFlavorMapper.deleteByDishId(id);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询菜品
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public DishVO getByIdWithFlavor(Long id) {
|
||||
// 根据id查询菜品数据
|
||||
Dish dish = dishMapper.getById(id);
|
||||
|
||||
// 根据菜品id查询口味数据
|
||||
List<DishFlavor> dishFlavorList = dishFlavorMapper.getByDishId(id);
|
||||
|
||||
// 将查询到的数据封装到vo
|
||||
DishVO dishVO = new DishVO();
|
||||
BeanUtils.copyProperties(dish, dishVO);
|
||||
dishVO.setFlavors(dishFlavorList);
|
||||
|
||||
return dishVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改菜品
|
||||
* @param dishDTO
|
||||
*/
|
||||
@Override
|
||||
public void updateWithFlavor(DishDTO dishDTO) {
|
||||
Dish dish = new Dish();
|
||||
BeanUtils.copyProperties(dishDTO, dish);
|
||||
|
||||
// 修改菜品基本信息
|
||||
dishMapper.update(dish);
|
||||
|
||||
// 删除原有的口味信息
|
||||
dishFlavorMapper.deleteByDishId(dishDTO.getId());
|
||||
|
||||
// 重新插入口味数据
|
||||
List<DishFlavor> flavors = dishDTO.getFlavors();
|
||||
if (flavors != null && flavors.size() > 0) {
|
||||
flavors.forEach(dishFlavor -> dishFlavor.setDishId(dishDTO.getId()));
|
||||
|
||||
// 向口味表插入n条数据
|
||||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Dish> list(Long categoryId) {
|
||||
Dish dish = Dish.builder()
|
||||
.categoryId(categoryId)
|
||||
.status(StatusConstant.ENABLE)
|
||||
.build();
|
||||
return dishMapper.list(dish);
|
||||
}
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<DishVO> listWithFlavor(Dish dish) {
|
||||
List<Dish> dishList = dishMapper.list(dish);
|
||||
|
||||
ArrayList<DishVO> dishVOArrayList = new ArrayList<>();
|
||||
|
||||
dishList.forEach(d->{
|
||||
DishVO dishVO = new DishVO();
|
||||
BeanUtils.copyProperties(d, dishVO);
|
||||
|
||||
// 根据菜品id查询对应的口味
|
||||
List<DishFlavor> flavors = dishFlavorMapper.getByDishId(d.getId());
|
||||
|
||||
dishVO.setFlavors(flavors);
|
||||
dishVOArrayList.add(dishVO);
|
||||
});
|
||||
|
||||
return dishVOArrayList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品起售停售
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
Dish dish = Dish.builder()
|
||||
.id(id)
|
||||
.status(status)
|
||||
.build();
|
||||
dishMapper.update(dish);
|
||||
|
||||
if (status == StatusConstant.DISABLE) {
|
||||
// 如果是停售操作,还需要将包含当前菜品的套餐也停售
|
||||
List<Long> dishIds = new ArrayList<>();
|
||||
dishIds.add(id);
|
||||
// select setmeal_id from setmeal_dish where dish_id in (?,?,?)
|
||||
List<Long> setmealIds = setmealDishMapper.getSetmealIdsByDishIds(dishIds);
|
||||
if (setmealIds != null && setmealIds.size() > 0) {
|
||||
for (Long setmealId : setmealIds) {
|
||||
Setmeal setmeal = Setmeal.builder()
|
||||
.id(setmealId)
|
||||
.status(StatusConstant.DISABLE)
|
||||
.build();
|
||||
setmealMapper.update(setmeal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue