Compare commits
28 Commits
b7a4d3ecbd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d11ada62c | |||
| 333fa769cc | |||
| f68ed79b7f | |||
| 28cb22928f | |||
| 79587613d8 | |||
| 7bfbd10b9d | |||
| 96c6308c52 | |||
| cf18e8bd82 | |||
| 4734a67b59 | |||
| ea8347d6b9 | |||
| 762b45a207 | |||
| 0b77bc7d70 | |||
| 7747190fd9 | |||
| aac5b7c677 | |||
| e3966a999a | |||
| 0ee1f57c72 | |||
| 8a78e0ffb9 | |||
| e99e5a8aed | |||
|
|
5334ef8454 | ||
|
|
ac346a870c | ||
|
|
add28bfa5d | ||
|
|
1e2aec636a | ||
|
|
a65c9e0c69 | ||
|
|
e223fbb1a8 | ||
|
|
5419e321c8 | ||
|
|
22e629b6e1 | ||
|
|
b6c3de2165 | ||
|
|
77804a0aba |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -3,4 +3,6 @@
|
|||||||
*.iml
|
*.iml
|
||||||
*.class
|
*.class
|
||||||
*Test.java
|
*Test.java
|
||||||
**/test/
|
**/test/
|
||||||
|
resources/application-dev.properties
|
||||||
|
/sky-server/src/main/resources/application-dev.properties
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package com.sky.constant;
|
|||||||
* 公共字段自动填充相关常量
|
* 公共字段自动填充相关常量
|
||||||
*/
|
*/
|
||||||
public class AutoFillConstant {
|
public class AutoFillConstant {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实体类中的方法名称
|
* 实体类中的方法名称
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,19 +5,57 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author SLHAF
|
||||||
|
*/
|
||||||
@Component
|
@Component
|
||||||
@ConfigurationProperties(prefix = "sky.wechat")
|
@ConfigurationProperties(prefix = "sky.wechat")
|
||||||
@Data
|
@Data
|
||||||
public class WeChatProperties {
|
public class WeChatProperties {
|
||||||
|
|
||||||
private String appid; //小程序的appid
|
/**
|
||||||
private String secret; //小程序的秘钥
|
小程序的appid
|
||||||
private String mchid; //商户号
|
*/
|
||||||
private String mchSerialNo; //商户API证书的证书序列号
|
private String appid;
|
||||||
private String privateKeyFilePath; //商户私钥文件
|
|
||||||
private String apiV3Key; //证书解密的密钥
|
/**
|
||||||
private String weChatPayCertFilePath; //平台证书
|
* 小程序的秘钥
|
||||||
private String notifyUrl; //支付成功的回调地址
|
*/
|
||||||
private String refundNotifyUrl; //退款成功的回调地址
|
private String secret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商户号
|
||||||
|
*/
|
||||||
|
private String mchid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商户API证书的证书序列号
|
||||||
|
*/
|
||||||
|
private String mchSerialNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商户私钥文件
|
||||||
|
*/
|
||||||
|
private String privateKeyFilePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 证书解密的密钥
|
||||||
|
*/
|
||||||
|
private String apiV3Key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 平台证书
|
||||||
|
*/
|
||||||
|
private String weChatPayCertFilePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* “支付成功”的回调地址
|
||||||
|
*/
|
||||||
|
private String notifyUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* “退款成功”的回调地址
|
||||||
|
*/
|
||||||
|
private String refundNotifyUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.io.Serializable;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 后端统一返回结果
|
* 后端统一返回结果
|
||||||
|
* @author SLHAF
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.Signature;
|
import java.security.Signature;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
@@ -188,7 +189,7 @@ public class WeChatPayUtil {
|
|||||||
byte[] message = signMessage.getBytes();
|
byte[] message = signMessage.getBytes();
|
||||||
|
|
||||||
Signature signature = Signature.getInstance("SHA256withRSA");
|
Signature signature = Signature.getInstance("SHA256withRSA");
|
||||||
signature.initSign(PemUtil.loadPrivateKey(new FileInputStream(new File(weChatProperties.getPrivateKeyFilePath()))));
|
signature.initSign(PemUtil.loadPrivateKey(Files.newInputStream(new File(weChatProperties.getPrivateKeyFilePath()).toPath())));
|
||||||
signature.update(message);
|
signature.update(message);
|
||||||
String packageSign = Base64.getEncoder().encodeToString(signature.sign());
|
String packageSign = Base64.getEncoder().encodeToString(signature.sign());
|
||||||
|
|
||||||
|
|||||||
@@ -115,6 +115,16 @@
|
|||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
<artifactId>poi-ooxml</artifactId>
|
<artifactId>poi-ooxml</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.pagehelper</groupId>
|
||||||
|
<artifactId>pagehelper</artifactId>
|
||||||
|
<version>6.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -3,10 +3,15 @@ package com.sky;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author SLHAF
|
||||||
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableTransactionManagement //开启注解方式的事务管理
|
@EnableTransactionManagement //开启注解方式的事务管理
|
||||||
|
@EnableCaching
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SkyApplication {
|
public class SkyApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.sky.context.BaseContext;
|
|||||||
import com.sky.enumeration.OperationType;
|
import com.sky.enumeration.OperationType;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.Signature;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.sky.utils.AliOssUtil;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Conditional;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.sky.config;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
|
public class RedisConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
|
||||||
|
log.info("开始创建Redis模板对象");
|
||||||
|
RedisTemplate redisTemplate = new RedisTemplate<>();
|
||||||
|
//设置连接工厂对象
|
||||||
|
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||||
|
//设置序列化器
|
||||||
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
// redisTemplate.setValueSerializer(new StringRedisSerializer());
|
||||||
|
return redisTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package com.sky.config;
|
package com.sky.config;
|
||||||
|
|
||||||
import com.sky.interceptor.JwtTokenAdminInterceptor;
|
import com.sky.interceptor.JwtTokenAdminInterceptor;
|
||||||
|
import com.sky.interceptor.JwtTokenUserInterceptor;
|
||||||
import com.sky.json.JacksonObjectMapper;
|
import com.sky.json.JacksonObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter;
|
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
@@ -23,6 +23,7 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置类,注册web层相关组件
|
* 配置类,注册web层相关组件
|
||||||
|
* @author SLHAF
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -30,17 +31,25 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
||||||
|
@Autowired
|
||||||
|
private JwtTokenUserInterceptor jwtTokenUserInterceptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册自定义拦截器
|
* 注册自定义拦截器
|
||||||
*
|
*
|
||||||
* @param registry
|
* @param registry
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void addInterceptors(InterceptorRegistry registry) {
|
protected void addInterceptors(InterceptorRegistry registry) {
|
||||||
log.info("开始注册自定义拦截器...");
|
log.info("开始注册自定义拦截器...");
|
||||||
registry.addInterceptor(jwtTokenAdminInterceptor)
|
registry.addInterceptor(jwtTokenAdminInterceptor)
|
||||||
.addPathPatterns("/admin/**")
|
.addPathPatterns("/admin/**")
|
||||||
.excludePathPatterns("/admin/employee/login");
|
.excludePathPatterns("/admin/employee/login");
|
||||||
|
|
||||||
|
registry.addInterceptor(jwtTokenUserInterceptor)
|
||||||
|
.addPathPatterns("/user/**")
|
||||||
|
.excludePathPatterns("/user/user/login")
|
||||||
|
.excludePathPatterns("/user/shop/status");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,8 +57,8 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public Docket docket() {
|
public Docket docketAdmin() {
|
||||||
log.info("准备生成接口文档...");
|
log.info("准备生成Admin接口文档...");
|
||||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||||
.title("苍穹外卖项目接口文档")
|
.title("苍穹外卖项目接口文档")
|
||||||
.version("2.0")
|
.version("2.0")
|
||||||
@@ -57,20 +66,41 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||||||
.build();
|
.build();
|
||||||
//指定版本
|
//指定版本
|
||||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.groupName("管理端接口")
|
||||||
//上文设置的信息
|
//上文设置的信息
|
||||||
.apiInfo(apiInfo)
|
.apiInfo(apiInfo)
|
||||||
.select()
|
.select()
|
||||||
//指定生成接口需要扫描的包
|
//指定生成接口需要扫描的包
|
||||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller"))
|
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin"))
|
||||||
|
.paths(PathSelectors.any())
|
||||||
|
.build();
|
||||||
|
return docket;
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Docket docketUser() {
|
||||||
|
log.info("准备生成User接口文档...");
|
||||||
|
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||||
|
.title("苍穹外卖项目接口文档")
|
||||||
|
.version("2.0")
|
||||||
|
.description("苍穹外卖项目接口文档")
|
||||||
|
.build();
|
||||||
|
//指定版本
|
||||||
|
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.groupName("用户端接口")
|
||||||
|
//上文设置的信息
|
||||||
|
.apiInfo(apiInfo)
|
||||||
|
.select()
|
||||||
|
//指定生成接口需要扫描的包
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.user"))
|
||||||
.paths(PathSelectors.any())
|
.paths(PathSelectors.any())
|
||||||
.build();
|
.build();
|
||||||
return docket;
|
return docket;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置静态资源映射
|
* 设置静态资源映射
|
||||||
* @param registry
|
* @param registry
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
log.info("开始设置静态资源映射...");
|
log.info("开始设置静态资源映射...");
|
||||||
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.sky.controller.admin;
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
|
import com.sky.constant.MessageConstant;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import com.sky.utils.AliOssUtil;
|
import com.sky.utils.AliOssUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -7,7 +8,6 @@ import io.swagger.annotations.ApiOperation;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -43,7 +43,7 @@ public class CommonController {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("文件上传失败: " + e);
|
log.error("文件上传失败: " + e);
|
||||||
}
|
}
|
||||||
return null;
|
return Result.error(MessageConstant.UPLOAD_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
|
import com.sky.dto.DishDTO;
|
||||||
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
|
import com.sky.entity.Dish;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.DishService;
|
||||||
|
import com.sky.vo.DishVO;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/dish")
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "菜品相关接口")
|
||||||
|
public class DishController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DishService dishService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增菜品
|
||||||
|
*
|
||||||
|
* @param dishDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("新增菜品")
|
||||||
|
public Result save(@RequestBody DishDTO dishDTO) {
|
||||||
|
log.info("新增菜品: {}", dishDTO);
|
||||||
|
dishService.saveWithFlavor(dishDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
*
|
||||||
|
* @param pageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperation("菜品分页查询")
|
||||||
|
public Result<PageResult> page(DishPageQueryDTO pageQueryDTO) {
|
||||||
|
log.info("菜品分页查询: {}", pageQueryDTO);
|
||||||
|
PageResult pageResult = dishService.pageQuery(pageQueryDTO);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除菜品
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping
|
||||||
|
@ApiOperation("批量删除菜品")
|
||||||
|
public Result delete(@RequestParam List<Long> ids){
|
||||||
|
log.info("批量删除菜品: {}",ids);
|
||||||
|
dishService.deleteBatch(ids);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询菜品
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
@ApiOperation("根据id查询菜品")
|
||||||
|
public Result<DishVO> getById(@PathVariable Long id) {
|
||||||
|
log.info("根据id查询菜品: {}",id);
|
||||||
|
DishVO dishVO = dishService.getByIdWithFlavor(id);
|
||||||
|
return Result.success(dishVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改菜品
|
||||||
|
* @param dishDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
@ApiOperation("修改菜品")
|
||||||
|
public Result update(@RequestBody DishDTO dishDTO) {
|
||||||
|
log.info("修改菜品: {}",dishDTO);
|
||||||
|
dishService.updateWithFlavor(dishDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("根据分类id查询菜品")
|
||||||
|
public Result<List> list(Long categoryId){
|
||||||
|
log.info("根据分类id查询菜品: {}",categoryId);
|
||||||
|
List<Dish> dishes = dishService.selectByCategoryId(categoryId);
|
||||||
|
return Result.success(dishes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/status/{status}")
|
||||||
|
@ApiOperation("菜品起售停售")
|
||||||
|
public Result startOrStop(@PathVariable Integer status,Long id){
|
||||||
|
log.info("菜品起售停售: 状态:{},ID:{}",status,id);
|
||||||
|
dishService.startOrStop(status,id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,6 +43,7 @@ public class EmployeeController {
|
|||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
@ApiOperation(value = "员工登录")
|
@ApiOperation(value = "员工登录")
|
||||||
public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
|
public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
|
||||||
|
// System.out.println(Thread.currentThread().getName());
|
||||||
log.info("员工登录:{}", employeeLoginDTO);
|
log.info("员工登录:{}", employeeLoginDTO);
|
||||||
|
|
||||||
Employee employee = employeeService.login(employeeLoginDTO);
|
Employee employee = employeeService.login(employeeLoginDTO);
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
|
import com.sky.dto.*;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.OrderService;
|
||||||
|
import com.sky.vo.OrderStatisticsVO;
|
||||||
|
import com.sky.vo.OrderVO;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController("adminOrderController")
|
||||||
|
@RequestMapping("/admin/order")
|
||||||
|
@Api(tags = "Order-Controller")
|
||||||
|
@Slf4j
|
||||||
|
public class OrderController {
|
||||||
|
@Autowired
|
||||||
|
private OrderService orderService;
|
||||||
|
|
||||||
|
@GetMapping("/conditionSearch")
|
||||||
|
public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
|
||||||
|
PageResult pageResult = orderService.pageQuery(ordersPageQueryDTO);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/statistics")
|
||||||
|
public Result<OrderStatisticsVO> statistics() {
|
||||||
|
log.info("order overview");
|
||||||
|
OrderStatisticsVO orderStatisticsVO = orderService.statistics();
|
||||||
|
return Result.success(orderStatisticsVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/details/{id}")
|
||||||
|
public Result<OrderVO> details(@PathVariable Long id) {
|
||||||
|
log.info("check order details: {}",id);
|
||||||
|
OrderVO orderVO = orderService.details(id);
|
||||||
|
return Result.success(orderVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/confirm")
|
||||||
|
public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
|
||||||
|
log.info("order confirm: {}",ordersConfirmDTO);
|
||||||
|
orderService.confirm(ordersConfirmDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/rejection")
|
||||||
|
public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
|
||||||
|
log.info("order rejection: {}",ordersRejectionDTO);
|
||||||
|
orderService.rejection(ordersRejectionDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/complete/{id}")
|
||||||
|
public Result complete(@PathVariable Long id){
|
||||||
|
log.info("complete order: {}",id);
|
||||||
|
orderService.complete(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/cancel")
|
||||||
|
public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
|
||||||
|
log.info("order cancel: {}",ordersCancelDTO);
|
||||||
|
orderService.cancelFromAdmin(ordersCancelDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/delivery/{id}")
|
||||||
|
public Result delivery(@PathVariable Long id){
|
||||||
|
log.info("order delivery: {}",id);
|
||||||
|
orderService.delivery(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
|
import com.sky.dto.SetmealDTO;
|
||||||
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.SetmealService;
|
||||||
|
import com.sky.vo.SetmealVO;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/setmeal")
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "套餐相关接口")
|
||||||
|
public class SetmealController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SetmealService setmealService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐分页查询
|
||||||
|
* @param setmealPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperation("套餐分页查询")
|
||||||
|
public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO){
|
||||||
|
log.info("套餐分页查询: {}",setmealPageQueryDTO);
|
||||||
|
PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增套餐
|
||||||
|
* @param setmealDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("新增套餐")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")
|
||||||
|
public Result insert(@RequestBody SetmealDTO setmealDTO){
|
||||||
|
log.info("新增套餐: {}",setmealDTO);
|
||||||
|
setmealService.insert(setmealDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除套餐
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping
|
||||||
|
@ApiOperation("批量删除套餐")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||||
|
public Result delete(@RequestParam List<Long> ids){
|
||||||
|
log.info("批量删除套餐: {}",ids);
|
||||||
|
setmealService.deleteBatch(ids);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询套餐
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
@ApiOperation("根据id查询套餐")
|
||||||
|
public Result<SetmealVO> getById(@PathVariable Long id){
|
||||||
|
log.info("根据id查询套餐: {}",id);
|
||||||
|
SetmealVO setmealVO = setmealService.getByIdWithSetmealDishes(id);
|
||||||
|
return Result.success(setmealVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改套餐
|
||||||
|
* @param setmealDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
@ApiOperation("修改套餐")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||||
|
public Result update(@RequestBody SetmealDTO setmealDTO){
|
||||||
|
log.info("修改套餐: {}",setmealDTO);
|
||||||
|
setmealService.updateWithSetmealDishes(setmealDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐起售停售
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/status/{status}")
|
||||||
|
@ApiOperation("套餐起售停售")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||||
|
public Result startOrStop(@PathVariable Integer status,Long id){
|
||||||
|
log.info("套餐起售停售: 状态:{},ID:{}",status,id);
|
||||||
|
setmealService.startOrStop(status,id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@RestController("adminShopController")
|
||||||
|
@RequestMapping("/admin/shop")
|
||||||
|
@Api(tags = "店铺操作接口")
|
||||||
|
@Slf4j
|
||||||
|
public class ShopController {
|
||||||
|
|
||||||
|
private static final String KEY = "SHOP_STATUS";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@PutMapping("/{status}")
|
||||||
|
@ApiOperation("设置营业状态")
|
||||||
|
public Result setStatus(@PathVariable String status) {
|
||||||
|
log.info("设置店铺营业状态为: {}",status.equals("1") ? "营业中":"打烊中");
|
||||||
|
redisTemplate.opsForValue().set(KEY, status);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/status")
|
||||||
|
@ApiOperation("获取营业状态")
|
||||||
|
public Result<Integer> getStatus(){
|
||||||
|
int status = Integer.parseInt((String) Objects.requireNonNull(redisTemplate.opsForValue().get(KEY)));
|
||||||
|
log.info("获取到营业状态为: {}", status == 1 ? "营业中" : "打烊中");
|
||||||
|
return Result.success(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package com.sky.controller.notify;
|
||||||
|
|
||||||
|
import com.alibaba.druid.support.json.JSONUtils;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.sky.properties.WeChatProperties;
|
||||||
|
import com.sky.service.OrderService;
|
||||||
|
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付回调相关接口
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/notify")
|
||||||
|
@Slf4j
|
||||||
|
public class PayNotifyController {
|
||||||
|
@Autowired
|
||||||
|
private OrderService orderService;
|
||||||
|
@Autowired
|
||||||
|
private WeChatProperties weChatProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付成功回调
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
*/
|
||||||
|
@RequestMapping("/paySuccess")
|
||||||
|
public void paySuccessNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
//读取数据
|
||||||
|
String body = readData(request);
|
||||||
|
log.info("支付成功回调:{}", body);
|
||||||
|
|
||||||
|
//数据解密
|
||||||
|
String plainText = decryptData(body);
|
||||||
|
log.info("解密后的文本:{}", plainText);
|
||||||
|
|
||||||
|
JSONObject jsonObject = JSON.parseObject(plainText);
|
||||||
|
String outTradeNo = jsonObject.getString("out_trade_no");//商户平台订单号
|
||||||
|
String transactionId = jsonObject.getString("transaction_id");//微信支付交易号
|
||||||
|
|
||||||
|
log.info("商户平台订单号:{}", outTradeNo);
|
||||||
|
log.info("微信支付交易号:{}", transactionId);
|
||||||
|
|
||||||
|
//业务处理,修改订单状态、来单提醒
|
||||||
|
orderService.paySuccess(outTradeNo);
|
||||||
|
|
||||||
|
//给微信响应
|
||||||
|
responseToWeixin(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取数据
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private String readData(HttpServletRequest request) throws Exception {
|
||||||
|
BufferedReader reader = request.getReader();
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
String line = null;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
if (result.length() > 0) {
|
||||||
|
result.append("\n");
|
||||||
|
}
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据解密
|
||||||
|
*
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private String decryptData(String body) throws Exception {
|
||||||
|
JSONObject resultObject = JSON.parseObject(body);
|
||||||
|
JSONObject resource = resultObject.getJSONObject("resource");
|
||||||
|
String ciphertext = resource.getString("ciphertext");
|
||||||
|
String nonce = resource.getString("nonce");
|
||||||
|
String associatedData = resource.getString("associated_data");
|
||||||
|
|
||||||
|
AesUtil aesUtil = new AesUtil(weChatProperties.getApiV3Key().getBytes(StandardCharsets.UTF_8));
|
||||||
|
//密文解密
|
||||||
|
String plainText = aesUtil.decryptToString(associatedData.getBytes(StandardCharsets.UTF_8),
|
||||||
|
nonce.getBytes(StandardCharsets.UTF_8),
|
||||||
|
ciphertext);
|
||||||
|
|
||||||
|
return plainText;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给微信响应
|
||||||
|
* @param response
|
||||||
|
*/
|
||||||
|
private void responseToWeixin(HttpServletResponse response) throws Exception{
|
||||||
|
response.setStatus(200);
|
||||||
|
HashMap<Object, Object> map = new HashMap<>();
|
||||||
|
map.put("code", "SUCCESS");
|
||||||
|
map.put("message", "SUCCESS");
|
||||||
|
response.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
|
||||||
|
response.getOutputStream().write(JSONUtils.toJSONString(map).getBytes(StandardCharsets.UTF_8));
|
||||||
|
response.flushBuffer();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
import com.sky.entity.AddressBook;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.AddressBookService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user/addressBook")
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "AddressBook-Controller")
|
||||||
|
public class AddressBookController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AddressBookService addressBookService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add a new address
|
||||||
|
* @param addressBook
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public Result add(@RequestBody AddressBook addressBook){
|
||||||
|
log.info("add new address book");
|
||||||
|
addressBookService.addAddressBook(addressBook);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list address of current user
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
public Result<List<AddressBook>> list(){
|
||||||
|
log.info("list address of current user");
|
||||||
|
List<AddressBook> list = addressBookService.listAddress();
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list default address of current user
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/default")
|
||||||
|
public Result<AddressBook> listDefault(){
|
||||||
|
log.info("list default address of current user");
|
||||||
|
AddressBook addressBook = addressBookService.listDefault();
|
||||||
|
return Result.success(addressBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list by addressId
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Result<AddressBook> listByAddressId(@PathVariable Long id){
|
||||||
|
log.info("list address by id: {}", id);
|
||||||
|
AddressBook addressBook = addressBookService.listByAddressId(id);
|
||||||
|
return Result.success(addressBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update address
|
||||||
|
* @param addressBook
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
public Result updateAddress(@RequestBody AddressBook addressBook){
|
||||||
|
log.info("update address");
|
||||||
|
addressBookService.updateAddress(addressBook);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping
|
||||||
|
public Result deleteAddress(Long id){
|
||||||
|
log.info("delete address");
|
||||||
|
addressBookService.deleteAddress(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/default")
|
||||||
|
public Result setDefault(@RequestBody AddressBook addressBook){
|
||||||
|
log.info("set default address");
|
||||||
|
addressBookService.setDefault(addressBook);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
import com.sky.entity.Category;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.CategoryService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController("UserCategoeyController")
|
||||||
|
@RequestMapping("/user/category")
|
||||||
|
@Api(tags = "Category")
|
||||||
|
@Slf4j
|
||||||
|
public class CategoryController {
|
||||||
|
@Autowired
|
||||||
|
private CategoryService categoryService;
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("category list")
|
||||||
|
public Result<List<Category>> list(Integer type){
|
||||||
|
log.info("user category list: {}",type);
|
||||||
|
List<Category> list = categoryService.list(type);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.DishService;
|
||||||
|
import com.sky.vo.DishVO;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController("UserDishController")
|
||||||
|
@RequestMapping("/user/dish")
|
||||||
|
@Api(tags = "UserDish")
|
||||||
|
@Slf4j
|
||||||
|
public class DishController {
|
||||||
|
@Autowired
|
||||||
|
private DishService dishService;
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
public Result<List<DishVO>> list(Long categoryId) {
|
||||||
|
log.info("select dishes by categoryId {}", categoryId);
|
||||||
|
return Result.success(dishService.getDishVoByCategoryId(categoryId));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
import com.sky.dto.OrdersPaymentDTO;
|
||||||
|
import com.sky.dto.OrdersSubmitDTO;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.OrderService;
|
||||||
|
import com.sky.vo.OrderPaymentVO;
|
||||||
|
import com.sky.vo.OrderSubmitVO;
|
||||||
|
import com.sky.vo.OrderVO;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController("userOrderController")
|
||||||
|
@RequestMapping("/user/order")
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "Order-Controller")
|
||||||
|
public class OrderController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderService orderService;
|
||||||
|
|
||||||
|
@PostMapping("/submit")
|
||||||
|
public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
|
||||||
|
log.info("order submit: {}", ordersSubmitDTO);
|
||||||
|
OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
|
||||||
|
return Result.success(orderSubmitVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单支付
|
||||||
|
*
|
||||||
|
* @param ordersPaymentDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/payment")
|
||||||
|
@ApiOperation("订单支付")
|
||||||
|
public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
|
||||||
|
log.info("订单支付:{}", ordersPaymentDTO);
|
||||||
|
OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
|
||||||
|
log.info("生成预支付交易单:{}", orderPaymentVO);
|
||||||
|
return Result.success(orderPaymentVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/historyOrders")
|
||||||
|
public Result<PageResult> historyOrders(Integer page, Integer pageSize, Integer status) {
|
||||||
|
log.info("查询历史订单");
|
||||||
|
PageResult pageResult = orderService.getHistoryOrders(page, pageSize, status);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/orderDetail/{id}")
|
||||||
|
public Result<OrderVO> orderDetail(@PathVariable Long id) {
|
||||||
|
log.info("check order detail: {}", id);
|
||||||
|
OrderVO orderVO = orderService.getOrderDetailById(id);
|
||||||
|
return Result.success(orderVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/cancel/{id}")
|
||||||
|
public Result cancel(@PathVariable Long id) {
|
||||||
|
log.info("cancel order: {}", id);
|
||||||
|
orderService.cancelByUser(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/repetition/{id}")
|
||||||
|
public Result repetition(@PathVariable Long id) {
|
||||||
|
log.info("repetition order: {}", id);
|
||||||
|
orderService.repetition(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sky.entity.Setmeal;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.SetmealService;
|
||||||
|
import com.sky.service.ShoppingCartService;
|
||||||
|
import com.sky.vo.DishItemVO;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController("UserSetmealController")
|
||||||
|
@RequestMapping("/user/setmeal")
|
||||||
|
@Api(tags = "UserSetmeal")
|
||||||
|
@Slf4j
|
||||||
|
public class SetmealController {
|
||||||
|
@Autowired
|
||||||
|
private SetmealService setmealService;
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("select setmeal by categoryId")
|
||||||
|
@Cacheable(cacheNames = "setmealCache",key = "#categoryId")
|
||||||
|
public Result<List<Setmeal>> list(Integer categoryId){
|
||||||
|
log.info("select setmeal by categoryId :{}", categoryId);
|
||||||
|
List<Setmeal> setmealList = setmealService.selectSetmealByCategoryId(categoryId);
|
||||||
|
return Result.success(setmealList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/dish/{id}")
|
||||||
|
@ApiOperation("select dishes by setmealId")
|
||||||
|
public Result<List<DishItemVO>> getDishBySetmealId(@PathVariable Long id){
|
||||||
|
log.info("select dishes by setmealId :{}", id);
|
||||||
|
return Result.success(setmealService.getDishBySetmealId(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author SLHAF
|
||||||
|
*/
|
||||||
|
@RestController("userShopController")
|
||||||
|
@RequestMapping("/user/shop")
|
||||||
|
@Api(tags = "店铺操作接口")
|
||||||
|
@Slf4j
|
||||||
|
public class ShopController {
|
||||||
|
|
||||||
|
private static final String KEY = "SHOP_STATUS";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@GetMapping("/status")
|
||||||
|
@ApiOperation("获取营业状态")
|
||||||
|
public Result<Integer> getStatus(){
|
||||||
|
int status = Integer.parseInt((String) Objects.requireNonNull(redisTemplate.opsForValue().get(KEY)));
|
||||||
|
log.info("获取到营业状态为: {}", status == 1 ? "营业中" : "打烊中");
|
||||||
|
return Result.success(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
import com.sky.dto.ShoppingCartDTO;
|
||||||
|
import com.sky.entity.ShoppingCart;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.ShoppingCartService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user/shoppingCart")
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "ShoppingCart-Controller")
|
||||||
|
public class ShoppingCartController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ShoppingCartService shoppingCartService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an item into the shopping cart.
|
||||||
|
*
|
||||||
|
* @param shoppingCartDTO The data transfer object encapsulating the details of the item to be added.
|
||||||
|
* Includes 'dishId' for individual dishes, 'setmealId' for set meals, and 'dishFlavor' to specify dish flavors if applicable.
|
||||||
|
* @return A {@link Result} indicating the outcome of the operation, with a success code and no specific data content.
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
@ApiOperation("add into shopping cart")
|
||||||
|
public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
|
||||||
|
log.info("add into shopping cart, details: {}",shoppingCartDTO);
|
||||||
|
shoppingCartService.addIntoShoppingCart(shoppingCartDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list the shopping cart of current user
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("list shopping cart")
|
||||||
|
public Result<List<ShoppingCart>> list(){
|
||||||
|
log.info("list shopping cart");
|
||||||
|
List<ShoppingCart> list = shoppingCartService.listShoppingCart();
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean shopping cart
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/clean")
|
||||||
|
@ApiOperation("clean the shopping cart")
|
||||||
|
public Result clean(){
|
||||||
|
log.info("clean shopping cart");
|
||||||
|
shoppingCartService.cleanShoppingCart();
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* subtract an item from the shopping cart
|
||||||
|
* @param shoppingCartDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/sub")
|
||||||
|
@ApiOperation("subtract an item from the shopping cart")
|
||||||
|
public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
|
||||||
|
shoppingCartService.subtractFromShoppingCart(shoppingCartDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.sky.controller.user;
|
||||||
|
|
||||||
|
import com.sky.constant.JwtClaimsConstant;
|
||||||
|
import com.sky.dto.UserLoginDTO;
|
||||||
|
import com.sky.entity.User;
|
||||||
|
import com.sky.properties.JwtProperties;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.UserService;
|
||||||
|
import com.sky.utils.JwtUtil;
|
||||||
|
import com.sky.vo.UserLoginVO;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author SLHAF
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user/user")
|
||||||
|
@Api(tags = "用户相关接口")
|
||||||
|
@Slf4j
|
||||||
|
public class UserController {
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
@Autowired
|
||||||
|
private JwtProperties jwtProperties;
|
||||||
|
|
||||||
|
@PostMapping("/login")
|
||||||
|
@ApiOperation("微信登录")
|
||||||
|
public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO){
|
||||||
|
// System.out.println(Thread.currentThread().getName());
|
||||||
|
log.info("微信用户登录: {}",userLoginDTO.getCode());
|
||||||
|
|
||||||
|
//微信登录
|
||||||
|
User user = userService.wxLogin(userLoginDTO);
|
||||||
|
|
||||||
|
//生成jwt
|
||||||
|
HashMap<String, Object> claims = new HashMap<>();
|
||||||
|
claims.put(JwtClaimsConstant.USER_ID,user.getId());
|
||||||
|
String token = JwtUtil.createJWT(jwtProperties.getUserSecretKey(), jwtProperties.getUserTtl(), claims);
|
||||||
|
UserLoginVO userLoginVO = UserLoginVO.builder()
|
||||||
|
.id(user.getId())
|
||||||
|
.openid(user.getOpenid())
|
||||||
|
.token(token)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return Result.success(userLoginVO);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@@ -30,9 +31,9 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor {
|
|||||||
* @param response
|
* @param response
|
||||||
* @param handler
|
* @param handler
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||||
//判断当前拦截到的是Controller的方法还是其他资源
|
//判断当前拦截到的是Controller的方法还是其他资源
|
||||||
if (!(handler instanceof HandlerMethod)) {
|
if (!(handler instanceof HandlerMethod)) {
|
||||||
//当前拦截到的不是动态方法,直接放行
|
//当前拦截到的不是动态方法,直接放行
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.sky.interceptor;
|
||||||
|
|
||||||
|
import com.sky.constant.JwtClaimsConstant;
|
||||||
|
import com.sky.context.BaseContext;
|
||||||
|
import com.sky.properties.JwtProperties;
|
||||||
|
import com.sky.utils.JwtUtil;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jwt令牌校验的拦截器
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class JwtTokenUserInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JwtProperties jwtProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验jwt
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @param response
|
||||||
|
* @param handler
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||||
|
//判断当前拦截到的是Controller的方法还是其他资源
|
||||||
|
if (!(handler instanceof HandlerMethod)) {
|
||||||
|
//当前拦截到的不是动态方法,直接放行
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//1、从请求头中获取令牌
|
||||||
|
String token = request.getHeader(jwtProperties.getUserTokenName());
|
||||||
|
|
||||||
|
//2、校验令牌
|
||||||
|
try {
|
||||||
|
log.info("jwt校验:{}", token);
|
||||||
|
Claims claims = JwtUtil.parseJWT(jwtProperties.getUserSecretKey(), token);
|
||||||
|
Long userId = Long.valueOf(claims.get(JwtClaimsConstant.USER_ID).toString());
|
||||||
|
BaseContext.setCurrentId(userId);
|
||||||
|
log.info("当前用户id:{}", userId);
|
||||||
|
//3、通过,放行
|
||||||
|
return true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
//4、不通过,响应 401 状态码
|
||||||
|
response.setStatus(401);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.sky.entity.AddressBook;
|
||||||
|
import org.apache.ibatis.annotations.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface AddressBookMapper {
|
||||||
|
|
||||||
|
@Insert("insert into sky_take_out.address_book(user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) " +
|
||||||
|
"values (#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
|
||||||
|
void insert(AddressBook addressBook);
|
||||||
|
|
||||||
|
List<AddressBook> list(AddressBook addressBook);
|
||||||
|
|
||||||
|
void update(AddressBook addressBook);
|
||||||
|
|
||||||
|
@Delete("delete from sky_take_out.address_book where id = #{id}")
|
||||||
|
void deleteById(Long id);
|
||||||
|
|
||||||
|
@Update("update sky_take_out.address_book set is_default = 0 where user_id = #{userId}")
|
||||||
|
void updateNotDefault(Long userId);
|
||||||
|
|
||||||
|
@Update("update sky_take_out.address_book set is_default = 1 where id = #{id}")
|
||||||
|
void updateDefault(Long id);
|
||||||
|
|
||||||
|
@Select("select * from sky_take_out.address_book where id = #{addressBookId}")
|
||||||
|
AddressBook getById(Long addressBookId);
|
||||||
|
}
|
||||||
@@ -30,4 +30,7 @@ public interface CategoryMapper {
|
|||||||
|
|
||||||
@Select("select * from category where type = #{type}")
|
@Select("select * from category where type = #{type}")
|
||||||
List<Category> selectByType(Integer type);
|
List<Category> selectByType(Integer type);
|
||||||
|
|
||||||
|
@Select("select * from category")
|
||||||
|
List<Category> selectCategory();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.sky.entity.DishFlavor;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface DishFlavorMapper {
|
||||||
|
/**
|
||||||
|
* 批量插入口味数据
|
||||||
|
* @param flavors
|
||||||
|
*/
|
||||||
|
void insertBatch(List<DishFlavor> flavors);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据菜品ID删除对应的口味
|
||||||
|
* @param dishId
|
||||||
|
*/
|
||||||
|
@Delete("delete from dish_flavor where dish_id = #{dishId}")
|
||||||
|
void deleteByDishId(Long dishId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据菜品id集合批量删除口味数据
|
||||||
|
* @param dishIds
|
||||||
|
*/
|
||||||
|
void deleteByDishIds(List<Long> dishIds);
|
||||||
|
|
||||||
|
@Select("select * from dish_flavor where dish_id = #{dishId}")
|
||||||
|
List<DishFlavor> getByDishId(Long dishId);
|
||||||
|
}
|
||||||
@@ -1,8 +1,19 @@
|
|||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.sky.annotation.AutoFill;
|
||||||
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
|
import com.sky.entity.Dish;
|
||||||
|
import com.sky.enumeration.OperationType;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.vo.DishItemVO;
|
||||||
|
import com.sky.vo.DishVO;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DishMapper {
|
public interface DishMapper {
|
||||||
|
|
||||||
@@ -14,4 +25,53 @@ public interface DishMapper {
|
|||||||
@Select("select count(id) from dish where category_id = #{categoryId}")
|
@Select("select count(id) from dish where category_id = #{categoryId}")
|
||||||
Integer countByCategoryId(Long categoryId);
|
Integer countByCategoryId(Long categoryId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入菜品数据
|
||||||
|
* @param dish
|
||||||
|
*/
|
||||||
|
@AutoFill(OperationType.INSERT)
|
||||||
|
void insert(Dish dish);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
* @param pageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page<DishVO> pageQuery(DishPageQueryDTO pageQueryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查找菜品
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select * from dish where id = #{id}")
|
||||||
|
Dish selectById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除菜品
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Delete("delete from dish where id = #{id}")
|
||||||
|
void deleteById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据菜品ids集合批量删除菜品
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
void deleteByIds(List<Long> ids);
|
||||||
|
|
||||||
|
@AutoFill(OperationType.UPDATE)
|
||||||
|
void update(Dish dish);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select * from dish where category_id = #{categoryId} and status = 1")
|
||||||
|
List<Dish> selectByCategoryId(Long categoryId);
|
||||||
|
|
||||||
|
List<Dish> selectByDishIdsAndStatusDisable(List<Long> dishIds);
|
||||||
|
|
||||||
|
List<DishItemVO> selectDishBySetmealId(Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.sky.enumeration.OperationType;
|
|||||||
import org.apache.ibatis.annotations.Insert;
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface EmployeeMapper {
|
public interface EmployeeMapper {
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.sky.entity.OrderDetail;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface OrderDetailMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* insert order details into table order_detail
|
||||||
|
* @param orderDetails
|
||||||
|
*/
|
||||||
|
void insertBatch(List<OrderDetail> orderDetails);
|
||||||
|
|
||||||
|
List<OrderDetail> getByOrderId(Long orderId);
|
||||||
|
}
|
||||||
43
sky-server/src/main/java/com/sky/mapper/OrderMapper.java
Normal file
43
sky-server/src/main/java/com/sky/mapper/OrderMapper.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.sky.dto.OrdersPageQueryDTO;
|
||||||
|
import com.sky.entity.Orders;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface OrderMapper {
|
||||||
|
|
||||||
|
void insert(Orders orders);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单号查询订单
|
||||||
|
*
|
||||||
|
* @param orderNumber
|
||||||
|
*/
|
||||||
|
@Select("select * from orders where number = #{orderNumber}")
|
||||||
|
Orders getByNumber(String orderNumber);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改订单信息
|
||||||
|
*
|
||||||
|
* @param orders
|
||||||
|
*/
|
||||||
|
void update(Orders orders);
|
||||||
|
|
||||||
|
@Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
|
||||||
|
void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);
|
||||||
|
|
||||||
|
Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
|
||||||
|
|
||||||
|
@Select("select * from orders where id = #{id}")
|
||||||
|
Orders getById(Long id);
|
||||||
|
|
||||||
|
@Select("select count(*) from orders where status = #{status}")
|
||||||
|
int countStatus(Integer status);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.sky.entity.Dish;
|
||||||
|
import com.sky.entity.SetmealDish;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface SetmealDishMapper {
|
||||||
|
/**
|
||||||
|
* 根据菜品id查询套餐id
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<Long> getSetmealIdsByDishIds(List<Long> ids);
|
||||||
|
|
||||||
|
void insertBatch(List<SetmealDish> setmealDishes);
|
||||||
|
|
||||||
|
void deleteBySetmealIds(List<Long> setmealIds);
|
||||||
|
|
||||||
|
@Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
|
||||||
|
List<SetmealDish> selectBySetmealId(Long setmealId);
|
||||||
|
|
||||||
|
@Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
|
||||||
|
void deleteBySetmealId(Long setmealId);
|
||||||
|
|
||||||
|
@Select("select * from setmeal_dish where dish_id = #{dishId}")
|
||||||
|
List<SetmealDish> selectByDishId(Long dishId);
|
||||||
|
}
|
||||||
@@ -1,8 +1,15 @@
|
|||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.sky.annotation.AutoFill;
|
||||||
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
|
import com.sky.entity.Setmeal;
|
||||||
|
import com.sky.enumeration.OperationType;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SetmealMapper {
|
public interface SetmealMapper {
|
||||||
|
|
||||||
@@ -14,4 +21,19 @@ public interface SetmealMapper {
|
|||||||
@Select("select count(id) from setmeal where category_id = #{categoryId}")
|
@Select("select count(id) from setmeal where category_id = #{categoryId}")
|
||||||
Integer countByCategoryId(Long id);
|
Integer countByCategoryId(Long id);
|
||||||
|
|
||||||
|
Page<Setmeal> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||||
|
|
||||||
|
@AutoFill(OperationType.INSERT)
|
||||||
|
void insert(Setmeal setmeal);
|
||||||
|
|
||||||
|
@Select("select * from setmeal where id = #{id}")
|
||||||
|
Setmeal selectById(Long id);
|
||||||
|
|
||||||
|
void deleteBatch(List<Long> ids);
|
||||||
|
|
||||||
|
@AutoFill(OperationType.UPDATE)
|
||||||
|
void update(Setmeal setmeal);
|
||||||
|
|
||||||
|
@Select("select * from setmeal where category_id = #{categoryId}")
|
||||||
|
List<Setmeal> selectByCategoryId(Integer categoryId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.sky.entity.ShoppingCart;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ShoppingCartMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a list of shopping carts based on a given ShoppingCart instance.
|
||||||
|
* This method is typically used to fetch carts matching specific criteria
|
||||||
|
* encapsulated within the provided ShoppingCart object.
|
||||||
|
*
|
||||||
|
* @param shoppingCart An instance of ShoppingCart containing criteria
|
||||||
|
* for the search. The fields within this object may be
|
||||||
|
* used to filter or customize the retrieval of shopping carts.
|
||||||
|
* @return A list of ShoppingCart instances that match the criteria specified
|
||||||
|
* in the input ShoppingCart object. If no carts match, an empty list is returned.
|
||||||
|
*/
|
||||||
|
List<ShoppingCart> list(ShoppingCart shoppingCart);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the item number by item's id
|
||||||
|
* @param shoppingCart
|
||||||
|
*/
|
||||||
|
@Update("update sky_take_out.shopping_cart set number = #{number} where id = #{id}")
|
||||||
|
void updateNumberById(ShoppingCart shoppingCart);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* insert a new item into the shopping cart
|
||||||
|
* @param shoppingCart
|
||||||
|
*/
|
||||||
|
@Insert("insert into sky_take_out.shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
|
||||||
|
"values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
|
||||||
|
void insert(ShoppingCart shoppingCart);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean shopping cart
|
||||||
|
* @param userId
|
||||||
|
*/
|
||||||
|
@Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
|
||||||
|
void clean(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete the item that number is 0 from the shopping cart
|
||||||
|
* @param shoppingCart
|
||||||
|
*/
|
||||||
|
void delete(ShoppingCart shoppingCart);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete shopping cart by user id
|
||||||
|
* @param userId
|
||||||
|
*/
|
||||||
|
@Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
|
||||||
|
void deleteByUserId(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* insert all the shopping cart data
|
||||||
|
* @param shoppingCartList
|
||||||
|
*/
|
||||||
|
void insertBatch(List<ShoppingCart> shoppingCartList);
|
||||||
|
}
|
||||||
26
sky-server/src/main/java/com/sky/mapper/UserMapper.java
Normal file
26
sky-server/src/main/java/com/sky/mapper/UserMapper.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.sky.entity.User;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据openid查询用户
|
||||||
|
* @param openid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select * from user where openid = #{openid}")
|
||||||
|
User getByOpenid(String openid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入数据
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
|
void insert(User user);
|
||||||
|
|
||||||
|
@Select("select * from sky_take_out.user where id = #{userId}")
|
||||||
|
User getById(Long userId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.entity.AddressBook;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface AddressBookService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new address book
|
||||||
|
* @param addressBook
|
||||||
|
*/
|
||||||
|
void addAddressBook(AddressBook addressBook);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list address of current user
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<AddressBook> listAddress();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* show default address
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AddressBook listDefault();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list by address id
|
||||||
|
* @param addressId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AddressBook listByAddressId(Long addressId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update address
|
||||||
|
* @param addressBook
|
||||||
|
*/
|
||||||
|
void updateAddress(AddressBook addressBook);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete address
|
||||||
|
*/
|
||||||
|
void deleteAddress(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set default address
|
||||||
|
* @param addressBook
|
||||||
|
*/
|
||||||
|
void setDefault(AddressBook addressBook);
|
||||||
|
}
|
||||||
62
sky-server/src/main/java/com/sky/service/DishService.java
Normal file
62
sky-server/src/main/java/com/sky/service/DishService.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.dto.DishDTO;
|
||||||
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
|
import com.sky.entity.Dish;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.vo.DishVO;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface DishService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增菜品
|
||||||
|
* @param dishDTO
|
||||||
|
*/
|
||||||
|
void saveWithFlavor(DishDTO dishDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
* @param pageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult pageQuery(DishPageQueryDTO pageQueryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品批量删除
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
void deleteBatch(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询菜品及口味
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
DishVO getByIdWithFlavor(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改菜品基本信息(及口味)
|
||||||
|
* @param dishDTO
|
||||||
|
*/
|
||||||
|
void updateWithFlavor(DishDTO dishDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<Dish> selectByCategoryId(Long categoryId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void startOrStop(Integer status, Long id);
|
||||||
|
|
||||||
|
List<DishVO> getDishVoByCategoryId(Long categoryId);
|
||||||
|
}
|
||||||
110
sky-server/src/main/java/com/sky/service/OrderService.java
Normal file
110
sky-server/src/main/java/com/sky/service/OrderService.java
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.dto.*;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.vo.*;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface OrderService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* submit order
|
||||||
|
* @param ordersSubmitDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单支付
|
||||||
|
* @param ordersPaymentDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付成功,修改订单状态
|
||||||
|
* @param outTradeNo
|
||||||
|
*/
|
||||||
|
void paySuccess(String outTradeNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取历史订单
|
||||||
|
* (page query for user)
|
||||||
|
* @param page
|
||||||
|
* @param pageSize
|
||||||
|
* @param status
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult getHistoryOrders(Integer page, Integer pageSize, Integer status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get order detail by order id
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderVO getOrderDetailById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cancel order by user
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void cancelByUser(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* repeat order by order id
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void repetition(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* page query for admin
|
||||||
|
* @param ordersPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* order overview
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderStatisticsVO statistics();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check order details
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderVO details(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* confirm order
|
||||||
|
* @param ordersConfirmDTO
|
||||||
|
*/
|
||||||
|
void confirm(OrdersConfirmDTO ordersConfirmDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reject order
|
||||||
|
* @param ordersRejectionDTO
|
||||||
|
*/
|
||||||
|
void rejection(OrdersRejectionDTO ordersRejectionDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cancel order by admin
|
||||||
|
* @param ordersCancelDTO
|
||||||
|
*/
|
||||||
|
void cancelFromAdmin(OrdersCancelDTO ordersCancelDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delivery order
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void delivery(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* complete order
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void complete(Long id);
|
||||||
|
}
|
||||||
58
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
58
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.dto.SetmealDTO;
|
||||||
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
|
import com.sky.entity.Setmeal;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.vo.DishItemVO;
|
||||||
|
import com.sky.vo.SetmealVO;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface SetmealService {
|
||||||
|
/**
|
||||||
|
* 套餐分页查询
|
||||||
|
* @param setmealPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增套餐
|
||||||
|
* @param setmealDTO
|
||||||
|
*/
|
||||||
|
void insert(SetmealDTO setmealDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除套餐
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
void deleteBatch(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询套餐(及关联菜品)
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SetmealVO getByIdWithSetmealDishes(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改套餐
|
||||||
|
* @param setmealDTO
|
||||||
|
*/
|
||||||
|
void updateWithSetmealDishes(SetmealDTO setmealDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐起售停售
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void startOrStop(Integer status, Long id);
|
||||||
|
|
||||||
|
List<Setmeal> selectSetmealByCategoryId(Integer categoryId);
|
||||||
|
|
||||||
|
List<DishItemVO> getDishBySetmealId(Long id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.dto.ShoppingCartDTO;
|
||||||
|
import com.sky.entity.ShoppingCart;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface ShoppingCartService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a setmeal or dish to the shopping cart.
|
||||||
|
*
|
||||||
|
* @param shoppingCartDTO The data transfer object containing details of the item to be added to the shopping cart.
|
||||||
|
* It includes dishId, setmealId, and dishFlavor necessary for identifying and customizing the item.
|
||||||
|
*/
|
||||||
|
void addIntoShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list shopping cart of current user
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<ShoppingCart> listShoppingCart();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean shopping cart
|
||||||
|
*/
|
||||||
|
void cleanShoppingCart();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* subtract an item from the shopping cart
|
||||||
|
* @param shoppingCartDTO
|
||||||
|
*/
|
||||||
|
void subtractFromShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||||
|
}
|
||||||
19
sky-server/src/main/java/com/sky/service/UserService.java
Normal file
19
sky-server/src/main/java/com/sky/service/UserService.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.dto.UserLoginDTO;
|
||||||
|
import com.sky.entity.User;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author SLHAF
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public interface UserService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信登录
|
||||||
|
* @param userLoginDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
User wxLogin(UserLoginDTO userLoginDTO);
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class AddressBookServiceImpl implements AddressBookService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AddressBookMapper addressBookMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addAddressBook(AddressBook addressBook) {
|
||||||
|
Long userId = BaseContext.getCurrentId();
|
||||||
|
addressBook.setUserId(userId);
|
||||||
|
List<AddressBook> list = addressBookMapper.list(addressBook);
|
||||||
|
addressBook.setIsDefault(0);
|
||||||
|
addressBookMapper.insert(addressBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list address of current user
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<AddressBook> listAddress() {
|
||||||
|
Long userId = BaseContext.getCurrentId();
|
||||||
|
AddressBook addressBook = AddressBook.builder()
|
||||||
|
.userId(userId)
|
||||||
|
.build();
|
||||||
|
return addressBookMapper.list(addressBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* show default address
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AddressBook listDefault() {
|
||||||
|
AddressBook addressBook = AddressBook.builder()
|
||||||
|
.userId(BaseContext.getCurrentId())
|
||||||
|
.isDefault(1)
|
||||||
|
.build();
|
||||||
|
List<AddressBook> list = addressBookMapper.list(addressBook);
|
||||||
|
if (list != null && !list.isEmpty()) {
|
||||||
|
return list.get(0);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AddressBook listByAddressId(Long addressId) {
|
||||||
|
AddressBook addressBook = AddressBook.builder()
|
||||||
|
.id(addressId)
|
||||||
|
.build();
|
||||||
|
List<AddressBook> list = addressBookMapper.list(addressBook);
|
||||||
|
return list.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateAddress(AddressBook addressBook) {
|
||||||
|
addressBookMapper.update(addressBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteAddress(Long id) {
|
||||||
|
addressBookMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void setDefault(AddressBook addressBook) {
|
||||||
|
//set all the address of current user not default
|
||||||
|
Long userId = BaseContext.getCurrentId();
|
||||||
|
addressBookMapper.updateNotDefault(userId);
|
||||||
|
//set current address default
|
||||||
|
addressBookMapper.updateDefault(addressBook.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import com.github.pagehelper.Page;
|
|||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.sky.constant.MessageConstant;
|
import com.sky.constant.MessageConstant;
|
||||||
import com.sky.constant.StatusConstant;
|
import com.sky.constant.StatusConstant;
|
||||||
import com.sky.context.BaseContext;
|
|
||||||
import com.sky.dto.CategoryDTO;
|
import com.sky.dto.CategoryDTO;
|
||||||
import com.sky.dto.CategoryPageQueryDTO;
|
import com.sky.dto.CategoryPageQueryDTO;
|
||||||
import com.sky.entity.Category;
|
import com.sky.entity.Category;
|
||||||
@@ -18,8 +17,6 @@ import org.springframework.beans.BeanUtils;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -129,7 +126,12 @@ public class CategoryServiceImpl implements CategoryService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Category> list(Integer type) {
|
public List<Category> list(Integer type) {
|
||||||
List<Category> list = categoryMapper.selectByType(type);
|
List<Category> categoryList;
|
||||||
return list;
|
if (type == null){
|
||||||
|
categoryList = categoryMapper.selectCategory();
|
||||||
|
}else {
|
||||||
|
categoryList = categoryMapper.selectByType(type);
|
||||||
|
}
|
||||||
|
return categoryList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,254 @@
|
|||||||
|
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.service.SetmealService;
|
||||||
|
import com.sky.vo.DishVO;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class DishServiceImpl implements DishService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DishMapper dishMapper;
|
||||||
|
@Autowired
|
||||||
|
private DishFlavorMapper dishFlavorMapper;
|
||||||
|
@Autowired
|
||||||
|
private SetmealDishMapper setmealDishMapper;
|
||||||
|
@Autowired
|
||||||
|
private SetmealMapper setmealMapper;
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增菜品
|
||||||
|
*
|
||||||
|
* @param dishDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void saveWithFlavor(DishDTO dishDTO) {
|
||||||
|
//向菜品表插入数据(一条)
|
||||||
|
Dish dish = new Dish();
|
||||||
|
BeanUtils.copyProperties(dishDTO, dish);
|
||||||
|
dishMapper.insert(dish);
|
||||||
|
|
||||||
|
//获取Insert语句生成的主键值
|
||||||
|
Long id = dish.getId();
|
||||||
|
|
||||||
|
//向口味表插入N条数据
|
||||||
|
List<DishFlavor> flavors = dishDTO.getFlavors();
|
||||||
|
if (flavors != null && !flavors.isEmpty()) {
|
||||||
|
//遍历flavors,插入id
|
||||||
|
flavors.forEach(dishFlavor -> dishFlavor.setDishId(id));
|
||||||
|
//批量插入
|
||||||
|
dishFlavorMapper.insertBatch(flavors);
|
||||||
|
}
|
||||||
|
|
||||||
|
//clear redis cache
|
||||||
|
String key = "dish_"+dishDTO.getCategoryId();
|
||||||
|
cleanCache(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
*
|
||||||
|
* @param pageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult pageQuery(DishPageQueryDTO pageQueryDTO) {
|
||||||
|
//设置分页
|
||||||
|
PageHelper.startPage(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||||
|
Page<DishVO> page = dishMapper.pageQuery(pageQueryDTO);
|
||||||
|
return new PageResult(page.getTotal(), page.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品批量删除
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void deleteBatch(List<Long> ids) {
|
||||||
|
//判断菜品是否能够删除
|
||||||
|
//是否有起售中菜品
|
||||||
|
for (Long id : ids) {
|
||||||
|
Dish dish = dishMapper.selectById(id);
|
||||||
|
if (dish.getStatus().equals(StatusConstant.ENABLE)) {
|
||||||
|
throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//是否关联套餐
|
||||||
|
List<Long> setmealIds = setmealDishMapper.getSetmealIdsByDishIds(ids);
|
||||||
|
if (setmealIds != null && !setmealIds.isEmpty()) {
|
||||||
|
throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
|
||||||
|
}
|
||||||
|
//删除菜品
|
||||||
|
/*for (Long id : ids) {
|
||||||
|
dishMapper.deleteById(id);
|
||||||
|
//删除菜品口味
|
||||||
|
dishFlavorMapper.deleteByDishId(id);
|
||||||
|
}*/
|
||||||
|
dishMapper.deleteByIds(ids);
|
||||||
|
dishFlavorMapper.deleteByDishIds(ids);
|
||||||
|
|
||||||
|
//clear all the dish cache in redis
|
||||||
|
cleanCache("dish_*");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询菜品及口味
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DishVO getByIdWithFlavor(Long id) {
|
||||||
|
//根据id查询菜品
|
||||||
|
Dish dish = dishMapper.selectById(id);
|
||||||
|
|
||||||
|
//根据菜品id查询口味
|
||||||
|
List<DishFlavor> dishFlavors = dishFlavorMapper.getByDishId(id);
|
||||||
|
|
||||||
|
//封装到DishVO对象
|
||||||
|
DishVO dishVO = new DishVO();
|
||||||
|
BeanUtils.copyProperties(dish, dishVO);
|
||||||
|
dishVO.setFlavors(dishFlavors);
|
||||||
|
|
||||||
|
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.isEmpty()) {
|
||||||
|
//设置dishId
|
||||||
|
flavors.forEach(dishFlavor -> dishFlavor.setDishId(dish.getId()));
|
||||||
|
//插入新的口味数据
|
||||||
|
dishFlavorMapper.insertBatch(flavors);
|
||||||
|
}
|
||||||
|
|
||||||
|
//clear redis cache
|
||||||
|
cleanCache("dish_*");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Dish> selectByCategoryId(Long categoryId) {
|
||||||
|
return dishMapper.selectByCategoryId(categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
* @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.equals(StatusConstant.DISABLE)) {
|
||||||
|
//检查是否有关联的套餐
|
||||||
|
List<SetmealDish> setmealDishes = setmealDishMapper.selectByDishId(id);
|
||||||
|
if (setmealDishes != null && !setmealDishes.isEmpty()) {
|
||||||
|
Setmeal setmeal = new Setmeal();
|
||||||
|
for (SetmealDish setmealDish : setmealDishes) {
|
||||||
|
setmeal.setId(setmealDish.getSetmealId());
|
||||||
|
setmeal.setStatus(status);
|
||||||
|
setmealMapper.update(setmeal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanCache("dish_*");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DishVO> getDishVoByCategoryId(Long categoryId) {
|
||||||
|
List<DishVO> dishVOList;
|
||||||
|
|
||||||
|
//construct key in redis: dish_{categoryId}
|
||||||
|
String key = "dish_"+categoryId;
|
||||||
|
|
||||||
|
//check if dish data exists in redis
|
||||||
|
ValueOperations valueOperations = redisTemplate.opsForValue();
|
||||||
|
dishVOList = (List<DishVO>) valueOperations.get(key);
|
||||||
|
|
||||||
|
if (dishVOList != null && !dishVOList.isEmpty()) {
|
||||||
|
//if exists,return dish data
|
||||||
|
return dishVOList;
|
||||||
|
}else {
|
||||||
|
//if not exists
|
||||||
|
List<Dish> dishes = dishMapper.selectByCategoryId(categoryId);
|
||||||
|
dishVOList = new ArrayList<>();
|
||||||
|
for (Dish dish : dishes) {
|
||||||
|
DishVO dishVO = new DishVO();
|
||||||
|
BeanUtils.copyProperties(dish, dishVO);
|
||||||
|
dishVO.setFlavors(dishFlavorMapper.getByDishId(dish.getId()));
|
||||||
|
dishVOList.add(dishVO);
|
||||||
|
}
|
||||||
|
valueOperations.set(key, dishVOList);
|
||||||
|
return dishVOList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanCache(String pattern) {
|
||||||
|
//clear redis cache
|
||||||
|
Set keys = redisTemplate.keys(pattern);
|
||||||
|
redisTemplate.delete(keys);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import com.github.pagehelper.PageHelper;
|
|||||||
import com.sky.constant.MessageConstant;
|
import com.sky.constant.MessageConstant;
|
||||||
import com.sky.constant.PasswordConstant;
|
import com.sky.constant.PasswordConstant;
|
||||||
import com.sky.constant.StatusConstant;
|
import com.sky.constant.StatusConstant;
|
||||||
import com.sky.context.BaseContext;
|
|
||||||
import com.sky.dto.EmployeeDTO;
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.dto.EmployeePageQueryDTO;
|
import com.sky.dto.EmployeePageQueryDTO;
|
||||||
@@ -21,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|||||||
@@ -0,0 +1,327 @@
|
|||||||
|
package com.sky.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.sky.constant.MessageConstant;
|
||||||
|
import com.sky.context.BaseContext;
|
||||||
|
import com.sky.dto.*;
|
||||||
|
import com.sky.entity.*;
|
||||||
|
import com.sky.exception.AddressBookBusinessException;
|
||||||
|
import com.sky.exception.ShoppingCartBusinessException;
|
||||||
|
import com.sky.mapper.*;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.service.OrderService;
|
||||||
|
import com.sky.utils.WeChatPayUtil;
|
||||||
|
import com.sky.vo.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
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.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class OrderServiceImpl implements OrderService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderMapper orderMapper;
|
||||||
|
@Autowired
|
||||||
|
private AddressBookMapper addressBookMapper;
|
||||||
|
@Autowired
|
||||||
|
private ShoppingCartMapper shoppingCartMapper;
|
||||||
|
@Autowired
|
||||||
|
private OrderDetailMapper orderDetailMapper;
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
@Autowired
|
||||||
|
private WeChatPayUtil weChatPayUtil;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO) {
|
||||||
|
//handle exception situation(address book is empty, shopping cart is empty)
|
||||||
|
AddressBook addressBook = addressBookMapper.getById(ordersSubmitDTO.getAddressBookId());
|
||||||
|
if (addressBook == null) {
|
||||||
|
throw new AddressBookBusinessException(MessageConstant.ADDRESS_BOOK_IS_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
Long userId = BaseContext.getCurrentId();
|
||||||
|
ShoppingCart shoppingCart = new ShoppingCart();
|
||||||
|
shoppingCart.setUserId(userId);
|
||||||
|
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||||
|
if (list == null || list.isEmpty()) {
|
||||||
|
throw new ShoppingCartBusinessException(MessageConstant.SHOPPING_CART_IS_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
//insert data into orders table
|
||||||
|
Orders orders = new Orders();
|
||||||
|
BeanUtils.copyProperties(ordersSubmitDTO, orders);
|
||||||
|
orders.setUserId(userId);
|
||||||
|
orders.setOrderTime(LocalDateTime.now());
|
||||||
|
orders.setPayStatus(Orders.UN_PAID);
|
||||||
|
orders.setStatus(Orders.PENDING_PAYMENT);
|
||||||
|
orders.setNumber(userId + "-" + System.currentTimeMillis());
|
||||||
|
orders.setPhone(addressBook.getPhone());
|
||||||
|
orders.setUserName(addressBook.getConsignee());
|
||||||
|
orders.setConsignee(addressBook.getConsignee());
|
||||||
|
orders.setAddress(addressBook.getDetail());
|
||||||
|
|
||||||
|
orderMapper.insert(orders);
|
||||||
|
|
||||||
|
//insert data into data_detail table
|
||||||
|
List<OrderDetail> orderDetails = new ArrayList<>();
|
||||||
|
for (ShoppingCart cart : list) {
|
||||||
|
OrderDetail orderDetail = new OrderDetail();
|
||||||
|
BeanUtils.copyProperties(cart, orderDetail);
|
||||||
|
orderDetail.setOrderId(orders.getId());
|
||||||
|
orderDetails.add(orderDetail);
|
||||||
|
}
|
||||||
|
orderDetailMapper.insertBatch(orderDetails);
|
||||||
|
|
||||||
|
//clear the shopping cart of current user
|
||||||
|
shoppingCartMapper.deleteByUserId(userId);
|
||||||
|
|
||||||
|
//construct OrderSubmitVO
|
||||||
|
return OrderSubmitVO.builder()
|
||||||
|
.id(orders.getId())
|
||||||
|
.orderTime(orders.getOrderTime())
|
||||||
|
.orderNumber(orders.getNumber())
|
||||||
|
.orderAmount(orders.getAmount())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单支付
|
||||||
|
*
|
||||||
|
* @param ordersPaymentDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception {
|
||||||
|
// 当前登录用户id
|
||||||
|
|
||||||
|
/*Long userId = BaseContext.getCurrentId();
|
||||||
|
User user = userMapper.getById(userId);
|
||||||
|
|
||||||
|
//调用微信支付接口,生成预支付交易单
|
||||||
|
JSONObject jsonObject = weChatPayUtil.pay(
|
||||||
|
ordersPaymentDTO.getOrderNumber(), //商户订单号
|
||||||
|
new BigDecimal(0.01), //支付金额,单位 元
|
||||||
|
"苍穹外卖订单", //商品描述
|
||||||
|
user.getOpenid() //微信用户的openid
|
||||||
|
);
|
||||||
|
|
||||||
|
if (jsonObject.getString("code") != null && jsonObject.getString("code").equals("ORDERPAID")) {
|
||||||
|
throw new OrderBusinessException("该订单已支付");
|
||||||
|
}*/
|
||||||
|
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("code", "ORDERPAID");
|
||||||
|
|
||||||
|
OrderPaymentVO vo = jsonObject.toJavaObject(OrderPaymentVO.class);
|
||||||
|
vo.setPackageStr(jsonObject.getString("package"));
|
||||||
|
|
||||||
|
//为替代微信支付成功后的数据库订单状态更新,多定义一个方法进行修改
|
||||||
|
|
||||||
|
Integer OrderPaidStatus = Orders.PAID; //支付状态,已支付
|
||||||
|
|
||||||
|
Integer OrderStatus = Orders.TO_BE_CONFIRMED; //订单状态,待接单
|
||||||
|
|
||||||
|
|
||||||
|
//发现没有将支付时间 check_out属性赋值,所以在这里更新
|
||||||
|
|
||||||
|
LocalDateTime check_out_time = LocalDateTime.now();
|
||||||
|
|
||||||
|
|
||||||
|
Long orderId = orderMapper.getByNumber(ordersPaymentDTO.getOrderNumber()).getId();
|
||||||
|
orderMapper.updateStatus(OrderStatus, OrderPaidStatus, check_out_time, orderId);
|
||||||
|
|
||||||
|
return new OrderPaymentVO();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付成功,修改订单状态
|
||||||
|
*
|
||||||
|
* @param outTradeNo
|
||||||
|
*/
|
||||||
|
public void paySuccess(String outTradeNo) {
|
||||||
|
|
||||||
|
// 根据订单号查询订单
|
||||||
|
Orders ordersDB = orderMapper.getByNumber(outTradeNo);
|
||||||
|
|
||||||
|
// 根据订单id更新订单的状态、支付方式、支付状态、结账时间
|
||||||
|
Orders orders = Orders.builder()
|
||||||
|
.id(ordersDB.getId())
|
||||||
|
.status(Orders.TO_BE_CONFIRMED)
|
||||||
|
.payStatus(Orders.PAID)
|
||||||
|
.checkoutTime(LocalDateTime.now())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult getHistoryOrders(Integer page, Integer pageSize, Integer status) {
|
||||||
|
Long userId = BaseContext.getCurrentId();
|
||||||
|
PageHelper.startPage(page, pageSize);
|
||||||
|
OrdersPageQueryDTO ordersPageQueryDTO = new OrdersPageQueryDTO();
|
||||||
|
ordersPageQueryDTO.setUserId(userId);
|
||||||
|
ordersPageQueryDTO.setStatus(status);
|
||||||
|
|
||||||
|
Page<Orders> ordersPage = orderMapper.pageQuery(ordersPageQueryDTO);
|
||||||
|
List<OrderVO> list = new ArrayList<>();
|
||||||
|
if (ordersPage != null && ordersPage.getTotal() > 0) {
|
||||||
|
for (Orders order : ordersPage) {
|
||||||
|
List<OrderDetail> orderDetails = orderDetailMapper.getByOrderId(order.getId());
|
||||||
|
OrderVO orderVO = new OrderVO();
|
||||||
|
orderVO.setOrderDetailList(orderDetails);
|
||||||
|
BeanUtils.copyProperties(order, orderVO);
|
||||||
|
list.add(orderVO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new PageResult(list.size(), list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderVO getOrderDetailById(Long id) {
|
||||||
|
OrderVO orderVO = new OrderVO();
|
||||||
|
Orders orders = orderMapper.getById(id);
|
||||||
|
BeanUtils.copyProperties(orders, orderVO);
|
||||||
|
orderVO.setOrderDetailList(orderDetailMapper.getByOrderId(orderVO.getId()));
|
||||||
|
return orderVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancelByUser(Long id) {
|
||||||
|
Orders orders = new Orders();
|
||||||
|
orders.setId(id);
|
||||||
|
orders.setStatus(Orders.CANCELLED);
|
||||||
|
orders.setCancelTime(LocalDateTime.now());
|
||||||
|
orders.setPayStatus(Orders.REFUND);
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void repetition(Long id) {
|
||||||
|
//get information of order detail
|
||||||
|
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(id);
|
||||||
|
//construct shopping cart
|
||||||
|
List<ShoppingCart> shoppingCartList = new ArrayList<>();
|
||||||
|
for (OrderDetail orderDetail : orderDetailList) {
|
||||||
|
ShoppingCart shoppingCart = new ShoppingCart();
|
||||||
|
shoppingCart.setName(orderDetail.getName());
|
||||||
|
shoppingCart.setImage(orderDetail.getImage());
|
||||||
|
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||||
|
shoppingCart.setDishId(orderDetail.getDishId());
|
||||||
|
shoppingCart.setSetmealId(orderDetail.getSetmealId());
|
||||||
|
shoppingCart.setDishFlavor(orderDetail.getDishFlavor());
|
||||||
|
shoppingCart.setNumber(orderDetail.getNumber());
|
||||||
|
shoppingCart.setAmount(orderDetail.getAmount());
|
||||||
|
shoppingCart.setCreateTime(LocalDateTime.now());
|
||||||
|
shoppingCartList.add(shoppingCart);
|
||||||
|
}
|
||||||
|
shoppingCartMapper.insertBatch(shoppingCartList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult pageQuery(OrdersPageQueryDTO ordersPageQueryDTO) {
|
||||||
|
PageHelper.startPage(ordersPageQueryDTO.getPage(), ordersPageQueryDTO.getPageSize());
|
||||||
|
Page<Orders> ordersPage = orderMapper.pageQuery(ordersPageQueryDTO);
|
||||||
|
List<OrderVO> list = new ArrayList<>();
|
||||||
|
for (Orders orders : ordersPage) {
|
||||||
|
OrderVO orderVO = new OrderVO();
|
||||||
|
BeanUtils.copyProperties(orders, orderVO);
|
||||||
|
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(orders.getId());
|
||||||
|
StringBuilder orderDishes = new StringBuilder();
|
||||||
|
for (OrderDetail orderDetail : orderDetailList) {
|
||||||
|
orderDishes.append(orderDetail.getName()).append(",");
|
||||||
|
}
|
||||||
|
orderVO.setOrderDishes(orderDishes.substring(0, orderDishes.length() - 1));
|
||||||
|
list.add(orderVO);
|
||||||
|
}
|
||||||
|
return new PageResult(list.size(), list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderStatisticsVO statistics() {
|
||||||
|
int confirmed = orderMapper.countStatus(Orders.CONFIRMED);
|
||||||
|
int deliveryInProgress = orderMapper.countStatus(Orders.DELIVERY_IN_PROGRESS);
|
||||||
|
int toBeConfirmed = orderMapper.countStatus(Orders.TO_BE_CONFIRMED);
|
||||||
|
OrderStatisticsVO orderStatisticsVO = new OrderStatisticsVO();
|
||||||
|
orderStatisticsVO.setConfirmed(confirmed);
|
||||||
|
orderStatisticsVO.setDeliveryInProgress(deliveryInProgress);
|
||||||
|
orderStatisticsVO.setToBeConfirmed(toBeConfirmed);
|
||||||
|
return orderStatisticsVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderVO details(Long id) {
|
||||||
|
Orders orders = orderMapper.getById(id);
|
||||||
|
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(orders.getId());
|
||||||
|
StringBuilder orderDishes = new StringBuilder();
|
||||||
|
for (OrderDetail orderDetail : orderDetailList) {
|
||||||
|
orderDishes.append(orderDetail.getName()).append(",");
|
||||||
|
}
|
||||||
|
OrderVO orderVO = new OrderVO();
|
||||||
|
BeanUtils.copyProperties(orders, orderVO);
|
||||||
|
orderVO.setOrderDetailList(orderDetailList);
|
||||||
|
orderVO.setOrderDishes(orderDishes.substring(0, orderDishes.length() - 1));
|
||||||
|
return orderVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void confirm(OrdersConfirmDTO ordersConfirmDTO) {
|
||||||
|
Orders orders = Orders.builder()
|
||||||
|
.id(ordersConfirmDTO.getId())
|
||||||
|
.status(Orders.CONFIRMED)
|
||||||
|
.build();
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rejection(OrdersRejectionDTO ordersRejectionDTO) {
|
||||||
|
Orders orders = Orders.builder()
|
||||||
|
.id(ordersRejectionDTO.getId())
|
||||||
|
.rejectionReason(ordersRejectionDTO.getRejectionReason())
|
||||||
|
.payStatus(Orders.REFUND)
|
||||||
|
.build();
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancelFromAdmin(OrdersCancelDTO ordersCancelDTO) {
|
||||||
|
Orders orders = Orders.builder()
|
||||||
|
.id(ordersCancelDTO.getId())
|
||||||
|
.cancelReason(ordersCancelDTO.getCancelReason())
|
||||||
|
.cancelTime(LocalDateTime.now())
|
||||||
|
.status(Orders.CANCELLED)
|
||||||
|
.payStatus(Orders.REFUND)
|
||||||
|
.build();
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delivery(Long id) {
|
||||||
|
Orders orders = Orders.builder()
|
||||||
|
.id(id)
|
||||||
|
.status(Orders.DELIVERY_IN_PROGRESS)
|
||||||
|
.build();
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Long id) {
|
||||||
|
Orders orders = Orders.builder()
|
||||||
|
.id(id)
|
||||||
|
.status(Orders.COMPLETED)
|
||||||
|
.build();
|
||||||
|
orderMapper.update(orders);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
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.SetmealDTO;
|
||||||
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
|
import com.sky.entity.Dish;
|
||||||
|
import com.sky.entity.Setmeal;
|
||||||
|
import com.sky.entity.SetmealDish;
|
||||||
|
import com.sky.exception.DeletionNotAllowedException;
|
||||||
|
import com.sky.mapper.DishMapper;
|
||||||
|
import com.sky.mapper.SetmealDishMapper;
|
||||||
|
import com.sky.mapper.SetmealMapper;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.SetmealService;
|
||||||
|
import com.sky.vo.DishItemVO;
|
||||||
|
import com.sky.vo.SetmealVO;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SetmealServiceImpl implements SetmealService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SetmealMapper setmealMapper;
|
||||||
|
@Autowired
|
||||||
|
private SetmealDishMapper setmealDishMapper;
|
||||||
|
@Autowired
|
||||||
|
private DishMapper dishMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐分页查询
|
||||||
|
*
|
||||||
|
* @param setmealPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||||
|
//设置分页
|
||||||
|
PageHelper.startPage(setmealPageQueryDTO.getPage(), setmealPageQueryDTO.getPageSize());
|
||||||
|
Page<Setmeal> page = setmealMapper.pageQuery(setmealPageQueryDTO);
|
||||||
|
return new PageResult(page.getTotal(), page.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增套餐
|
||||||
|
*
|
||||||
|
* @param setmealDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void insert(SetmealDTO setmealDTO) {
|
||||||
|
//插入套餐信息
|
||||||
|
Setmeal setmeal = new Setmeal();
|
||||||
|
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||||
|
setmealMapper.insert(setmeal);
|
||||||
|
|
||||||
|
//插入套餐包含菜品的信息
|
||||||
|
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||||
|
//设置setmealId
|
||||||
|
setmealDishes.forEach(setmealDish -> setmealDish.setSetmealId(setmeal.getId()));
|
||||||
|
setmealDishMapper.insertBatch(setmealDishes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除套餐
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void deleteBatch(List<Long> ids) {
|
||||||
|
//查看套餐是否有在售状态
|
||||||
|
for (Long id : ids) {
|
||||||
|
Setmeal setmeal = setmealMapper.selectById(id);
|
||||||
|
if (setmeal.getStatus().equals(StatusConstant.ENABLE)) {
|
||||||
|
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//批量删除套餐(动态SQL)
|
||||||
|
//删除setmeal数据
|
||||||
|
setmealMapper.deleteBatch(ids);
|
||||||
|
//删除setmeal_dish数据
|
||||||
|
setmealDishMapper.deleteBySetmealIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询套餐(及关联菜品)
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SetmealVO getByIdWithSetmealDishes(Long id) {
|
||||||
|
SetmealVO setmealVO = new SetmealVO();
|
||||||
|
//查询基本套餐信息
|
||||||
|
Setmeal setmeal = setmealMapper.selectById(id);
|
||||||
|
BeanUtils.copyProperties(setmeal, setmealVO);
|
||||||
|
//查询对应菜品信息
|
||||||
|
List<SetmealDish> setmealDishes = setmealDishMapper.selectBySetmealId(id);
|
||||||
|
setmealVO.setSetmealDishes(setmealDishes);
|
||||||
|
return setmealVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改套餐
|
||||||
|
*
|
||||||
|
* @param setmealDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void updateWithSetmealDishes(SetmealDTO setmealDTO) {
|
||||||
|
//更新setmeal基本数据
|
||||||
|
Setmeal setmeal = new Setmeal();
|
||||||
|
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||||
|
setmealMapper.update(setmeal);
|
||||||
|
|
||||||
|
//更新setmeal_dish数据
|
||||||
|
//删除原setmeal_dish相关数据
|
||||||
|
setmealDishMapper.deleteBySetmealId(setmealDTO.getId());
|
||||||
|
//添加setmeal_id
|
||||||
|
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||||
|
setmealDishes.forEach(setmealDish -> setmealDish.setSetmealId(setmealDTO.getId()));
|
||||||
|
//插入新的数据
|
||||||
|
setmealDishMapper.insertBatch(setmealDTO.getSetmealDishes());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐起售停售
|
||||||
|
*
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void startOrStop(Integer status, Long id) {
|
||||||
|
//看是否为起售,如果为起售,需要判断其关联的菜品有停售状态
|
||||||
|
if (status.equals(StatusConstant.ENABLE)) {
|
||||||
|
/*
|
||||||
|
获取其关联的菜品信息--setmeal_dish--setmealDishes--遍历->getDishId
|
||||||
|
先把dishId放到一个集合中,批量查询该dish_id对应且status为0的菜品信息
|
||||||
|
如果查询到,则抛出删除失败异常
|
||||||
|
如果没有,则进行下一步,改变状态
|
||||||
|
*/
|
||||||
|
List<SetmealDish> setmealDishes = setmealDishMapper.selectBySetmealId(id);
|
||||||
|
List<Long> dishIds = new ArrayList<>();
|
||||||
|
setmealDishes.forEach(setmealDish -> dishIds.add(setmealDish.getDishId()));
|
||||||
|
List<Dish> dishes = dishMapper.selectByDishIdsAndStatusDisable(dishIds);
|
||||||
|
if (dishes != null && !dishes.isEmpty()){
|
||||||
|
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ENABLE_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//不为起售则直接更改状态
|
||||||
|
Setmeal setmeal = Setmeal.builder()
|
||||||
|
.status(status)
|
||||||
|
.id(id)
|
||||||
|
.build();
|
||||||
|
setmealMapper.update(setmeal);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Setmeal> selectSetmealByCategoryId(Integer categoryId) {
|
||||||
|
return setmealMapper.selectByCategoryId(categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DishItemVO> getDishBySetmealId(Long id) {
|
||||||
|
return dishMapper.selectDishBySetmealId(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package com.sky.service.impl;
|
||||||
|
|
||||||
|
import com.sky.context.BaseContext;
|
||||||
|
import com.sky.dto.ShoppingCartDTO;
|
||||||
|
import com.sky.entity.Dish;
|
||||||
|
import com.sky.entity.Setmeal;
|
||||||
|
import com.sky.entity.ShoppingCart;
|
||||||
|
import com.sky.mapper.DishMapper;
|
||||||
|
import com.sky.mapper.SetmealMapper;
|
||||||
|
import com.sky.mapper.ShoppingCartMapper;
|
||||||
|
import com.sky.service.ShoppingCartService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class ShoppingCartServiceImpl implements ShoppingCartService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ShoppingCartMapper shoppingCartMapper;
|
||||||
|
@Autowired
|
||||||
|
private DishMapper dishMapper;
|
||||||
|
@Autowired
|
||||||
|
private SetmealMapper setmealMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an item to the shopping cart.
|
||||||
|
*
|
||||||
|
* @param shoppingCartDTO The data transfer object containing details of the item to be added.
|
||||||
|
* It includes the dish ID, setmeal ID, and dish flavor if applicable.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addIntoShoppingCart(ShoppingCartDTO shoppingCartDTO) {
|
||||||
|
//check the item if exists in the shopping cart
|
||||||
|
//fix properties
|
||||||
|
ShoppingCart shoppingCart = new ShoppingCart();
|
||||||
|
BeanUtils.copyProperties(shoppingCartDTO, shoppingCart);
|
||||||
|
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||||
|
|
||||||
|
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||||
|
|
||||||
|
if (list != null && !list.isEmpty()){
|
||||||
|
//if exists
|
||||||
|
ShoppingCart cart = list.get(0);
|
||||||
|
cart.setNumber(cart.getNumber() +1);
|
||||||
|
shoppingCartMapper.updateNumberById(cart);
|
||||||
|
}else {
|
||||||
|
//if not,fix the rest properties: name, amount, image
|
||||||
|
//check the item to be added is of dish or set meal
|
||||||
|
Long dishId = shoppingCartDTO.getDishId();
|
||||||
|
if (dishId != null){
|
||||||
|
Dish dish = dishMapper.selectById(dishId);
|
||||||
|
shoppingCart.setName(dish.getName());
|
||||||
|
shoppingCart.setImage(dish.getImage());
|
||||||
|
shoppingCart.setAmount(dish.getPrice());
|
||||||
|
}else {
|
||||||
|
Long setmealId = shoppingCartDTO.getSetmealId();
|
||||||
|
Setmeal setmeal = setmealMapper.selectById(setmealId);
|
||||||
|
shoppingCart.setName(setmeal.getName());
|
||||||
|
shoppingCart.setImage(setmeal.getImage());
|
||||||
|
shoppingCart.setAmount(setmeal.getPrice());
|
||||||
|
}
|
||||||
|
shoppingCart.setNumber(1);
|
||||||
|
shoppingCart.setCreateTime(LocalDateTime.now());
|
||||||
|
|
||||||
|
shoppingCartMapper.insert(shoppingCart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list shopping cart
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<ShoppingCart> listShoppingCart() {
|
||||||
|
ShoppingCart shoppingCart = ShoppingCart.builder()
|
||||||
|
.userId(BaseContext.getCurrentId())
|
||||||
|
.build();
|
||||||
|
return shoppingCartMapper.list(shoppingCart);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean shopping cart
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void cleanShoppingCart() {
|
||||||
|
Long userId = BaseContext.getCurrentId();
|
||||||
|
shoppingCartMapper.clean(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* subtract an item from the shopping cart
|
||||||
|
* @param shoppingCartDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void subtractFromShoppingCart(ShoppingCartDTO shoppingCartDTO) {
|
||||||
|
//construct an object that contains the basic properties : userId, set meal/dish id, dish flavor
|
||||||
|
ShoppingCart shoppingCart = new ShoppingCart();
|
||||||
|
BeanUtils.copyProperties(shoppingCartDTO, shoppingCart);
|
||||||
|
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||||
|
|
||||||
|
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
shoppingCart = list.get(0);
|
||||||
|
//check the number of shopping cart
|
||||||
|
if (shoppingCart.getNumber() > 1) {
|
||||||
|
shoppingCart.setNumber(shoppingCart.getNumber() - 1);
|
||||||
|
shoppingCartMapper.updateNumberById(shoppingCart);
|
||||||
|
} else {
|
||||||
|
shoppingCartMapper.delete(shoppingCart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.sky.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.sky.constant.MessageConstant;
|
||||||
|
import com.sky.dto.UserLoginDTO;
|
||||||
|
import com.sky.entity.User;
|
||||||
|
import com.sky.exception.LoginFailedException;
|
||||||
|
import com.sky.mapper.UserMapper;
|
||||||
|
import com.sky.properties.WeChatProperties;
|
||||||
|
import com.sky.service.UserService;
|
||||||
|
import com.sky.utils.HttpClientUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author SLHAF
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信接口服务地址
|
||||||
|
*/
|
||||||
|
public static final String WX_LOGIN = "https://api.weixin.qq.com/sns/jscode2session";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WeChatProperties weChatProperties;
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User wxLogin(UserLoginDTO userLoginDTO) {
|
||||||
|
//调用微信接口获取openid
|
||||||
|
String openid = getOpenid(userLoginDTO.getCode());
|
||||||
|
|
||||||
|
//判断openid是否为空,为空表示登录失败,则抛出异常
|
||||||
|
if (openid == null) {
|
||||||
|
throw new LoginFailedException(MessageConstant.LOGIN_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断当前用户是否为新用户
|
||||||
|
User user = userMapper.getByOpenid(openid);
|
||||||
|
|
||||||
|
//如果是新用户,自动完成注册
|
||||||
|
if (user == null) {
|
||||||
|
user = User.builder()
|
||||||
|
.openid(openid)
|
||||||
|
.createTime(LocalDateTime.now())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
userMapper.insert(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
//返回用户对象
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用接口,获取用户openid
|
||||||
|
* @param code
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getOpenid(String code) {
|
||||||
|
HashMap<String, String> map = new HashMap<>();
|
||||||
|
map.put("appid", weChatProperties.getAppid());
|
||||||
|
map.put("secret", weChatProperties.getSecret());
|
||||||
|
map.put("js_code", code);
|
||||||
|
map.put("grant_type", "authorization_code");
|
||||||
|
String json = HttpClientUtil.doGet(WX_LOGIN, map);
|
||||||
|
JSONObject jsonObject = JSON.parseObject(json);
|
||||||
|
return jsonObject.getString("openid");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
sky.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
|
||||||
sky.datasource.host=localhost
|
|
||||||
sky.datasource.port=3306
|
|
||||||
sky.datasource.database=sky_take_out
|
|
||||||
sky.datasource.username=root
|
|
||||||
sky.datasource.password=Slhaf20041205
|
|
||||||
sky.alioss.access-key-id=LTAI5tKXHfExEucGsrbQvTqo
|
|
||||||
sky.alioss.access-key-secret=FkSXUC0mctKx6Gkyygin3Pyj35xYej
|
|
||||||
sky.alioss.bucket-name=sky-take-out-slhaf
|
|
||||||
sky.alioss.endpoint=oss-cn-beijing.aliyuncs.com
|
|
||||||
spring.servlet.multipart.max-file-size=10MB
|
|
||||||
spring.servlet.multipart.max-request-size=10MB
|
|
||||||
@@ -5,18 +5,41 @@ spring.datasource.druid.driver-class-name=${sky.datasource.driver-class-name}
|
|||||||
spring.datasource.druid.url=jdbc:mysql://${sky.datasource.host}:${sky.datasource.port}/${sky.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
spring.datasource.druid.url=jdbc:mysql://${sky.datasource.host}:${sky.datasource.port}/${sky.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||||
spring.datasource.druid.username=${sky.datasource.username}
|
spring.datasource.druid.username=${sky.datasource.username}
|
||||||
spring.datasource.druid.password=${sky.datasource.password}
|
spring.datasource.druid.password=${sky.datasource.password}
|
||||||
|
|
||||||
|
spring.redis.host=${spring.redis.host}
|
||||||
|
spring.redis.port=${spring.redis.port}
|
||||||
|
#spring.redis.password=${spring.redis.password}
|
||||||
|
spring.redis.database=${spring.redis.database}
|
||||||
|
|
||||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||||
mybatis.type-aliases-package=com.sky.entity
|
mybatis.type-aliases-package=com.sky.entity
|
||||||
mybatis.configuration.map-underscore-to-camel-case=true
|
mybatis.configuration.map-underscore-to-camel-case=true
|
||||||
|
|
||||||
logging.level.com.sky.mapper=debug
|
logging.level.com.sky.mapper=debug
|
||||||
logging.level.com.sky.service=info
|
logging.level.com.sky.service=info
|
||||||
logging.level.com.sky.controller=info
|
logging.level.com.sky.controller=info
|
||||||
|
|
||||||
sky.jwt.admin-secret-key=itcast
|
sky.jwt.admin-secret-key=itcast
|
||||||
sky.jwt.admin-ttl=7200000
|
sky.jwt.admin-ttl=7200000
|
||||||
sky.jwt.admin-token-name=token
|
sky.jwt.admin-token-name=token
|
||||||
|
sky.jwt.user-secret-key=itheima
|
||||||
|
sky.jwt.user-ttl=7200000
|
||||||
|
sky.jwt.user-token-name=authentication
|
||||||
|
|
||||||
sky.alioss.endpoint=${sky.alioss.endpoint}
|
sky.alioss.endpoint=${sky.alioss.endpoint}
|
||||||
sky.alioss.bucket-name=${sky.alioss.bucket-name}
|
sky.alioss.bucket-name=${sky.alioss.bucket-name}
|
||||||
sky.alioss.access-key-id=${sky.alioss.access-key-id}
|
sky.alioss.access-key-id=${sky.alioss.access-key-id}
|
||||||
sky.alioss.access-key-secret=${sky.alioss.access-key-secret}
|
sky.alioss.access-key-secret=${sky.alioss.access-key-secret}
|
||||||
|
|
||||||
spring.servlet.multipart.max-file-size=${spring.servlet.multipart.max-file-size}
|
spring.servlet.multipart.max-file-size=${spring.servlet.multipart.max-file-size}
|
||||||
spring.servlet.multipart.max-request-size=${spring.servlet.multipart.max-request-size}
|
spring.servlet.multipart.max-request-size=${spring.servlet.multipart.max-request-size}
|
||||||
|
|
||||||
|
sky.wechat.appid=${sky.wechat.appid}
|
||||||
|
sky.wechat.secret=${sky.wechat.secret}
|
||||||
|
sky.wechat.mchid=${sky.wechat.mchid}
|
||||||
|
sky.wechat.mch-serial-no=${sky.wechat.mch-serial-no}
|
||||||
|
sky.wechat.private-key-file-path=${sky.wechat.private-key-file-path}
|
||||||
|
sky.wechat.api-v3-key=${sky.wechat.api-v3-key}
|
||||||
|
sky.wechat.we-chat-pay-cert-file-path=${sky.wechat.we-chat-pay-cert-file-path}
|
||||||
|
sky.wechat.notify-url=${sky.wechat.notify-url}
|
||||||
|
sky.wechat.refund-notify-url=${sky.wechat.refund-notify-url}
|
||||||
39
sky-server/src/main/resources/mapper/AddressBookMapper.xml
Normal file
39
sky-server/src/main/resources/mapper/AddressBookMapper.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sky.mapper.AddressBookMapper">
|
||||||
|
<update id="update">
|
||||||
|
update sky_take_out.address_book
|
||||||
|
set city_name = #{cityName},
|
||||||
|
city_code = #{cityCode},
|
||||||
|
consignee = #{consignee},
|
||||||
|
detail = #{detail},
|
||||||
|
district_code = #{districtCode},
|
||||||
|
district_name = #{districtName},
|
||||||
|
label = #{label},
|
||||||
|
phone = #{phone},
|
||||||
|
province_code = #{provinceCode},
|
||||||
|
province_name = #{provinceName},
|
||||||
|
sex = #{sex},
|
||||||
|
<if test="isDefault != null">
|
||||||
|
is_default = #{isDefault},
|
||||||
|
</if>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="list" resultType="com.sky.entity.AddressBook">
|
||||||
|
select * from sky_take_out.address_book
|
||||||
|
<where>
|
||||||
|
<if test="userId != null">
|
||||||
|
and user_id = #{userId}
|
||||||
|
</if>
|
||||||
|
<if test="isDefault != null">
|
||||||
|
and is_default = #{isDefault}
|
||||||
|
</if>
|
||||||
|
<if test="id != null">
|
||||||
|
and id = #{id}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
19
sky-server/src/main/resources/mapper/DishFlavorMapper.xml
Normal file
19
sky-server/src/main/resources/mapper/DishFlavorMapper.xml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sky.mapper.DishFlavorMapper">
|
||||||
|
|
||||||
|
<insert id="insertBatch">
|
||||||
|
insert into dish_flavor (dish_id, name, value) VALUES
|
||||||
|
<foreach collection="flavors" item="df" separator=",">
|
||||||
|
(#{df.dishId},#{df.name},#{df.value})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
<delete id="deleteByDishIds">
|
||||||
|
delete from dish_flavor where dish_id in
|
||||||
|
<foreach collection="dishIds" item="dishId" separator="," open="(" close=")">
|
||||||
|
#{dishId}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
||||||
64
sky-server/src/main/resources/mapper/DishMapper.xml
Normal file
64
sky-server/src/main/resources/mapper/DishMapper.xml
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sky.mapper.DishMapper">
|
||||||
|
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user,
|
||||||
|
update_user)
|
||||||
|
values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{status}, #{createTime}, #{updateTime},
|
||||||
|
#{createUser}, #{updateUser})
|
||||||
|
</insert>
|
||||||
|
<update id="update">
|
||||||
|
update dish
|
||||||
|
<set>
|
||||||
|
<if test="name != null">name = #{name},</if>
|
||||||
|
<if test="categoryId != null">category_id = #{categoryId},</if>
|
||||||
|
<if test="price != null">price = #{price},</if>
|
||||||
|
<if test="image != null">image = #{image},</if>
|
||||||
|
<if test="description != null">description = #{description},</if>
|
||||||
|
<if test="status != null">status = #{status},</if>
|
||||||
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
|
<if test="updateUser != null">update_user = #{updateUser},</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
<delete id="deleteByIds">
|
||||||
|
delete from dish where id in
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
<select id="pageQuery" resultType="com.sky.vo.DishVO">
|
||||||
|
select dish.*, category.name as categoryName
|
||||||
|
from dish
|
||||||
|
left outer join category
|
||||||
|
on dish.category_id = category.id
|
||||||
|
<where>
|
||||||
|
<if test="name != null">
|
||||||
|
and dish.name like concat('%',#{name},'%')
|
||||||
|
</if>
|
||||||
|
<if test="categoryId != null">
|
||||||
|
and dish.category_id = #{categoryId}
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
and dish.status = #{status}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by dish.create_time desc
|
||||||
|
</select>
|
||||||
|
<select id="selectByDishIdsAndStatusDisable" resultType="com.sky.entity.Dish">
|
||||||
|
select * from dish where id in
|
||||||
|
<foreach collection="dishIds" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
and status = 0
|
||||||
|
</select>
|
||||||
|
<select id="selectDishBySetmealId" resultType="com.sky.vo.DishItemVO">
|
||||||
|
select copies,description,image,d.name
|
||||||
|
from sky_take_out.setmeal_dish s
|
||||||
|
join dish d on d.id = s.dish_id
|
||||||
|
where s.setmeal_id = #{id}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
17
sky-server/src/main/resources/mapper/OrderDetailMapper.xml
Normal file
17
sky-server/src/main/resources/mapper/OrderDetailMapper.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sky.mapper.OrderDetailMapper">
|
||||||
|
|
||||||
|
<insert id="insertBatch">
|
||||||
|
insert into sky_take_out.order_detail(name, image, order_id, dish_id, setmeal_id, dish_flavor, number, amount)
|
||||||
|
VALUES
|
||||||
|
<foreach collection="orderDetails" item="orderDetail" separator=",">
|
||||||
|
(#{orderDetail.name},#{orderDetail.image},#{orderDetail.orderId},#{orderDetail.dishId},#{orderDetail.setmealId},#{orderDetail.dishFlavor},#{orderDetail.number},#{orderDetail.amount})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
<select id="getByOrderId" resultType="com.sky.entity.OrderDetail">
|
||||||
|
select * from sky_take_out.order_detail where order_id = #{orderId}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
72
sky-server/src/main/resources/mapper/OrderMapper.xml
Normal file
72
sky-server/src/main/resources/mapper/OrderMapper.xml
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sky.mapper.OrderMapper">
|
||||||
|
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into sky_take_out.orders(number, status, user_id, address_book_id, order_time, checkout_time, pay_method,
|
||||||
|
pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason,
|
||||||
|
rejection_reason, cancel_time, estimated_delivery_time, delivery_status,
|
||||||
|
delivery_time, pack_amount, tableware_number, tableware_status)
|
||||||
|
VALUES (#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime}, #{payMethod},
|
||||||
|
#{payStatus}, #{amount}, #{remark}, #{phone}, #{address}, #{userName}, #{consignee}, #{cancelReason},
|
||||||
|
#{rejectionReason}, #{cancelTime}, #{estimatedDeliveryTime}, #{deliveryStatus}, #{deliveryTime},
|
||||||
|
#{packAmount}, #{tablewareNumber}, #{tablewareStatus})
|
||||||
|
</insert>
|
||||||
|
<update id="update" parameterType="com.sky.entity.Orders">
|
||||||
|
update orders
|
||||||
|
<set>
|
||||||
|
<if test="cancelReason != null and cancelReason!='' ">
|
||||||
|
cancel_reason=#{cancelReason},
|
||||||
|
</if>
|
||||||
|
<if test="rejectionReason != null and rejectionReason!='' ">
|
||||||
|
rejection_reason=#{rejectionReason},
|
||||||
|
</if>
|
||||||
|
<if test="cancelTime != null">
|
||||||
|
cancel_time=#{cancelTime},
|
||||||
|
</if>
|
||||||
|
<if test="payStatus != null">
|
||||||
|
pay_status=#{payStatus},
|
||||||
|
</if>
|
||||||
|
<if test="payMethod != null">
|
||||||
|
pay_method=#{payMethod},
|
||||||
|
</if>
|
||||||
|
<if test="checkoutTime != null">
|
||||||
|
checkout_time=#{checkoutTime},
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
status = #{status},
|
||||||
|
</if>
|
||||||
|
<if test="deliveryTime != null">
|
||||||
|
delivery_time = #{deliveryTime}
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
<select id="pageQuery" resultType="com.sky.entity.Orders">
|
||||||
|
select * from orders
|
||||||
|
<where>
|
||||||
|
<if test="number != null">
|
||||||
|
and number like concat('%',#{number},'%')
|
||||||
|
</if>
|
||||||
|
<if test="phone != null">
|
||||||
|
and phone like concat('%',#{number},'%')
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
and status = #{status}
|
||||||
|
</if>
|
||||||
|
<if test="beginTime != null">
|
||||||
|
and order_time >= #{beginTime}
|
||||||
|
</if>
|
||||||
|
<if test="endTime != null">
|
||||||
|
and order_time <= #{endTime}
|
||||||
|
</if>
|
||||||
|
<if test="userId != null">
|
||||||
|
and user_id = #{userId}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by order_time desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
26
sky-server/src/main/resources/mapper/SetmealDishMapper.xml
Normal file
26
sky-server/src/main/resources/mapper/SetmealDishMapper.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sky.mapper.SetmealDishMapper">
|
||||||
|
<insert id="insertBatch">
|
||||||
|
insert into setmeal_dish (setmeal_id, dish_id, name, price, copies)
|
||||||
|
values
|
||||||
|
<foreach collection="setmealDishes" item="sd" separator=",">
|
||||||
|
(#{sd.setmealId},#{sd.dishId},#{sd.name},#{sd.price},#{sd.copies})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
<delete id="deleteBySetmealIds">
|
||||||
|
delete from setmeal_dish where setmeal_id in
|
||||||
|
<foreach collection="setmealIds" item="setmealId" separator="," open="(" close=")">
|
||||||
|
#{setmealId}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="getSetmealIdsByDishIds" resultType="java.lang.Long">
|
||||||
|
select setmeal_id from setmeal_dish where dish_id in
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
41
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
41
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sky.mapper.SetmealMapper">
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into setmeal(category_id, name, price, status, description, image, create_time, update_time, create_user,
|
||||||
|
update_user)
|
||||||
|
VALUES (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime},
|
||||||
|
#{createUser}, #{updateUser})
|
||||||
|
</insert>
|
||||||
|
<update id="update">
|
||||||
|
update setmeal
|
||||||
|
<set>
|
||||||
|
<if test="categoryId != null">category_id = #{categoryId},</if>
|
||||||
|
<if test="description != null">description = #{description},</if>
|
||||||
|
<if test="image != null">image = #{image},</if>
|
||||||
|
<if test="name != null">name = #{name},</if>
|
||||||
|
<if test="price != null">price = #{price},</if>
|
||||||
|
<if test="status != null">status = #{status},</if>
|
||||||
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
|
<if test="updateUser != null">update_user = #{updateUser},</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
<delete id="deleteBatch">
|
||||||
|
delete from setmeal where id in
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="pageQuery" resultType="com.sky.entity.Setmeal">
|
||||||
|
select * from setmeal
|
||||||
|
<where>
|
||||||
|
<if test="name != null">and name like concat('%',name,'%')</if>
|
||||||
|
<if test="categoryId != null">and category_id = #{categoryId}</if>
|
||||||
|
<if test="status != null">and status = #{status}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
48
sky-server/src/main/resources/mapper/ShoppingCartMapper.xml
Normal file
48
sky-server/src/main/resources/mapper/ShoppingCartMapper.xml
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sky.mapper.ShoppingCartMapper">
|
||||||
|
<insert id="insertBatch">
|
||||||
|
insert into sky_take_out.shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number,
|
||||||
|
amount, create_time) values
|
||||||
|
<foreach collection="shoppingCartList" item="s" separator=",">
|
||||||
|
(#{s.name},#{s.image},#{s.userId},#{s.dishId},#{s.setmealId},#{s.dishFlavor},#{s.number},#{s.amount},#{s.createTime})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
<delete id="delete">
|
||||||
|
delete from sky_take_out.shopping_cart
|
||||||
|
<where>
|
||||||
|
<if test="userId != null">
|
||||||
|
and user_id = #{userId}
|
||||||
|
</if>
|
||||||
|
<if test="setmealId != null">
|
||||||
|
and setmeal_id = #{setmealId}
|
||||||
|
</if>
|
||||||
|
<if test="dishId!= null">
|
||||||
|
and dish_id = #{dishId}
|
||||||
|
</if>
|
||||||
|
<if test="dishFlavor != null">
|
||||||
|
and dish_flavor = #{dishFlavor}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="list" resultType="com.sky.entity.ShoppingCart">
|
||||||
|
select * from sky_take_out.shopping_cart
|
||||||
|
<where>
|
||||||
|
<if test="userId != null">
|
||||||
|
and user_id = #{userId}
|
||||||
|
</if>
|
||||||
|
<if test="setmealId != null">
|
||||||
|
and setmeal_id = #{setmealId}
|
||||||
|
</if>
|
||||||
|
<if test="dishId!= null">
|
||||||
|
and dish_id = #{dishId}
|
||||||
|
</if>
|
||||||
|
<if test="dishFlavor != null">
|
||||||
|
and dish_flavor = #{dishFlavor}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
11
sky-server/src/main/resources/mapper/UserMapper.xml
Normal file
11
sky-server/src/main/resources/mapper/UserMapper.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sky.mapper.UserMapper">
|
||||||
|
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into user(openid, name, phone, sex, id_number, avatar, create_time)
|
||||||
|
values (#{openid}, #{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime})
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user