├── .gitignore ├── sky-server ├── src │ └── main │ │ ├── resources │ │ ├── template │ │ │ └── 运营数据报表模板.xlsx │ │ ├── application-dev.yml │ │ ├── mapper │ │ │ ├── DishFlavorMapper.xml │ │ │ ├── SetMealDishMapper.xml │ │ │ ├── OrderDetailMapper.xml │ │ │ ├── ShoppingCartMapper.xml │ │ │ ├── EmployeeMapper.xml │ │ │ ├── UserMapper.xml │ │ │ ├── AddressBookMapper.xml │ │ │ ├── CategoryMapper.xml │ │ │ ├── SetMealMapper.xml │ │ │ └── DishMapper.xml │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── sky │ │ ├── service │ │ ├── UserService.java │ │ ├── AddressBookService.java │ │ ├── ShoppingCartService.java │ │ ├── DishService.java │ │ ├── WorkspaceService.java │ │ ├── ReportService.java │ │ ├── CategoryService.java │ │ ├── EmployeeService.java │ │ ├── SetmealService.java │ │ ├── impl │ │ │ ├── AddressBookServiceImpl.java │ │ │ ├── UserServiceImpl.java │ │ │ ├── ShoppingCartServiceImpl.java │ │ │ ├── CategoryServiceImpl.java │ │ │ ├── EmployeeServiceImpl.java │ │ │ └── WorkspaceServiceImpl.java │ │ └── OrderService.java │ │ ├── config │ │ ├── WebSocketConfiguration.java │ │ ├── OssConfiguration.java │ │ ├── RedisConfiguration.java │ │ └── WebMvcConfiguration.java │ │ ├── annotation │ │ └── AutoFill.java │ │ ├── mapper │ │ ├── DishFlavorMapper.java │ │ ├── OrderDetailMapper.java │ │ ├── UserMapper.java │ │ ├── SetMealDishMapper.java │ │ ├── EmployeeMapper.java │ │ ├── ShoppingCartMapper.java │ │ ├── CategoryMapper.java │ │ ├── DishMapper.java │ │ ├── AddressBookMapper.java │ │ ├── SetmealMapper.java │ │ └── OrderMapper.java │ │ ├── SkyApplication.java │ │ ├── controller │ │ ├── user │ │ │ ├── CategoryController.java │ │ │ ├── ShopController.java │ │ │ ├── DishController.java │ │ │ ├── SetmealController.java │ │ │ ├── UserController.java │ │ │ ├── ShoppingCartController.java │ │ │ ├── AddressBookController.java │ │ │ └── OrderController.java │ │ ├── admin │ │ │ ├── ShopController.java │ │ │ ├── CommonController.java │ │ │ ├── WorkSpaceController.java │ │ │ ├── CategoryController.java │ │ │ ├── ReportController.java │ │ │ ├── SetmealController.java │ │ │ ├── OrderController.java │ │ │ ├── DishController.java │ │ │ └── EmployeeController.java │ │ └── notify │ │ │ └── PayNotifyController.java │ │ ├── handler │ │ └── GlobalExceptionHandler.java │ │ ├── task │ │ └── OrderTask.java │ │ ├── websocket │ │ └── WebSocketServer.java │ │ ├── interceptor │ │ ├── JwtTokenAdminInterceptor.java │ │ └── JwtTokenUserInterceptor.java │ │ └── apsect │ │ └── AutoFillAspect.java └── pom.xml ├── sky-common ├── src │ └── main │ │ └── java │ │ └── com │ │ └── sky │ │ ├── constant │ │ ├── PasswordConstant.java │ │ ├── StatusConstant.java │ │ ├── JwtClaimsConstant.java │ │ ├── AutoFillConstant.java │ │ └── MessageConstant.java │ │ ├── exception │ │ ├── OrderBusinessException.java │ │ ├── LoginFailedException.java │ │ ├── DeletionNotAllowedException.java │ │ ├── AddressBookBusinessException.java │ │ ├── ShoppingCartBusinessException.java │ │ ├── PasswordEditFailedException.java │ │ ├── UserNotLoginException.java │ │ ├── BaseException.java │ │ ├── AccountLockedException.java │ │ ├── PasswordErrorException.java │ │ ├── SetmealEnableFailedException.java │ │ └── AccountNotFoundException.java │ │ ├── enumeration │ │ └── OperationType.java │ │ ├── result │ │ ├── PageResult.java │ │ └── Result.java │ │ ├── context │ │ └── BaseContext.java │ │ ├── properties │ │ ├── AliOssProperties.java │ │ ├── JwtProperties.java │ │ └── WeChatProperties.java │ │ ├── utils │ │ ├── JwtUtil.java │ │ └── AliOssUtil.java │ │ └── json │ │ └── JacksonObjectMapper.java └── pom.xml ├── sky-pojo ├── src │ └── main │ │ └── java │ │ └── com │ │ └── sky │ │ ├── dto │ │ ├── UserLoginDTO.java │ │ ├── OrdersCancelDTO.java │ │ ├── ShoppingCartDTO.java │ │ ├── OrdersRejectionDTO.java │ │ ├── OrdersPaymentDTO.java │ │ ├── OrdersConfirmDTO.java │ │ ├── EmployeePageQueryDTO.java │ │ ├── PasswordEditDTO.java │ │ ├── CategoryDTO.java │ │ ├── EmployeeDTO.java │ │ ├── CategoryPageQueryDTO.java │ │ ├── DishPageQueryDTO.java │ │ ├── SetmealPageQueryDTO.java │ │ ├── OrderAmount.java │ │ ├── GoodsSalesDTO.java │ │ ├── EmployeeLoginDTO.java │ │ ├── DataOverViewQueryDTO.java │ │ ├── LocalDateTime2TurpleDTO.java │ │ ├── DishDTO.java │ │ ├── OrdersPageQueryDTO.java │ │ ├── SetmealDTO.java │ │ ├── OrdersSubmitDTO.java │ │ └── OrdersDTO.java │ │ ├── vo │ │ ├── OrderStatisticsVO.java │ │ ├── UserLoginVO.java │ │ ├── DishOverViewVO.java │ │ ├── SetmealOverViewVO.java │ │ ├── SalesTop10ReportVO.java │ │ ├── TurnoverReportVO.java │ │ ├── OrderVO.java │ │ ├── DishItemVO.java │ │ ├── UserReportVO.java │ │ ├── OrderPaymentVO.java │ │ ├── OrderSubmitVO.java │ │ ├── BusinessDataVO.java │ │ ├── OrderOverViewVO.java │ │ ├── EmployeeLoginVO.java │ │ ├── OrderReportVO.java │ │ ├── DishVO.java │ │ └── SetmealVO.java │ │ └── entity │ │ ├── DishFlavor.java │ │ ├── SetmealDish.java │ │ ├── User.java │ │ ├── OrderDetail.java │ │ ├── Category.java │ │ ├── ShoppingCart.java │ │ ├── Employee.java │ │ ├── Dish.java │ │ ├── Setmeal.java │ │ ├── AddressBook.java │ │ └── Orders.java └── pom.xml ├── README.md └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | **/target/ 2 | .idea 3 | *.iml 4 | *.class 5 | *Test.java 6 | **/test/ -------------------------------------------------------------------------------- /sky-server/src/main/resources/template/运营数据报表模板.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hssy252/sky/HEAD/sky-server/src/main/resources/template/运营数据报表模板.xlsx -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/constant/PasswordConstant.java: -------------------------------------------------------------------------------- 1 | package com.sky.constant; 2 | 3 | /** 4 | * 密码常量 5 | */ 6 | public class PasswordConstant { 7 | 8 | public static final String DEFAULT_PASSWORD = "123456"; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/OrderBusinessException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | public class OrderBusinessException extends BaseException { 4 | 5 | public OrderBusinessException(String msg) { 6 | super(msg); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/LoginFailedException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | /** 4 | * 登录失败 5 | */ 6 | public class LoginFailedException extends BaseException{ 7 | public LoginFailedException(String msg){ 8 | super(msg); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/DeletionNotAllowedException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | public class DeletionNotAllowedException extends BaseException { 4 | 5 | public DeletionNotAllowedException(String msg) { 6 | super(msg); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/AddressBookBusinessException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | public class AddressBookBusinessException extends BaseException { 4 | 5 | public AddressBookBusinessException(String msg) { 6 | super(msg); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/ShoppingCartBusinessException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | public class ShoppingCartBusinessException extends BaseException { 4 | 5 | public ShoppingCartBusinessException(String msg) { 6 | super(msg); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/UserLoginDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * C端用户登录 9 | */ 10 | @Data 11 | public class UserLoginDTO implements Serializable { 12 | 13 | private String code; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/constant/StatusConstant.java: -------------------------------------------------------------------------------- 1 | package com.sky.constant; 2 | 3 | /** 4 | * 状态常量,启用或者禁用 5 | */ 6 | public class StatusConstant { 7 | 8 | //启用 9 | public static final Integer ENABLE = 1; 10 | 11 | //禁用 12 | public static final Integer DISABLE = 0; 13 | } 14 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/enumeration/OperationType.java: -------------------------------------------------------------------------------- 1 | package com.sky.enumeration; 2 | 3 | /** 4 | * 数据库操作类型 5 | */ 6 | public enum OperationType { 7 | 8 | /** 9 | * 更新操作 10 | */ 11 | UPDATE, 12 | 13 | /** 14 | * 插入操作 15 | */ 16 | INSERT 17 | 18 | } 19 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/PasswordEditFailedException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | /** 4 | * 密码修改失败异常 5 | */ 6 | public class PasswordEditFailedException extends BaseException{ 7 | 8 | public PasswordEditFailedException(String msg){ 9 | super(msg); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/OrdersCancelDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class OrdersCancelDTO implements Serializable { 9 | 10 | private Long id; 11 | //订单取消原因 12 | private String cancelReason; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/UserNotLoginException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | public class UserNotLoginException extends BaseException { 4 | 5 | public UserNotLoginException() { 6 | } 7 | 8 | public UserNotLoginException(String msg) { 9 | super(msg); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/BaseException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | /** 4 | * 业务异常 5 | */ 6 | public class BaseException extends RuntimeException { 7 | 8 | public BaseException() { 9 | } 10 | 11 | public BaseException(String msg) { 12 | super(msg); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/ShoppingCartDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | import java.io.Serializable; 5 | 6 | @Data 7 | public class ShoppingCartDTO implements Serializable { 8 | 9 | private Long dishId; 10 | private Long setmealId; 11 | private String dishFlavor; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/OrdersRejectionDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class OrdersRejectionDTO implements Serializable { 9 | 10 | private Long id; 11 | 12 | //订单拒绝原因 13 | private String rejectionReason; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/OrdersPaymentDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | import java.io.Serializable; 5 | 6 | @Data 7 | public class OrdersPaymentDTO implements Serializable { 8 | //订单号 9 | private String orderNumber; 10 | 11 | //付款方式 12 | private Integer payMethod; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/OrdersConfirmDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class OrdersConfirmDTO implements Serializable { 9 | 10 | private Long id; 11 | //订单状态 1待付款 2待接单 3 已接单 4 派送中 5 已完成 6 已取消 7 退款 12 | private Integer status; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/AccountLockedException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | /** 4 | * 账号被锁定异常 5 | */ 6 | public class AccountLockedException extends BaseException { 7 | 8 | public AccountLockedException() { 9 | } 10 | 11 | public AccountLockedException(String msg) { 12 | super(msg); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/PasswordErrorException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | /** 4 | * 密码错误异常 5 | */ 6 | public class PasswordErrorException extends BaseException { 7 | 8 | public PasswordErrorException() { 9 | } 10 | 11 | public PasswordErrorException(String msg) { 12 | super(msg); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/SetmealEnableFailedException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | /** 4 | * 套餐启用失败异常 5 | */ 6 | public class SetmealEnableFailedException extends BaseException { 7 | 8 | public SetmealEnableFailedException(){} 9 | 10 | public SetmealEnableFailedException(String msg){ 11 | super(msg); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/exception/AccountNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.sky.exception; 2 | 3 | /** 4 | * 账号不存在异常 5 | */ 6 | public class AccountNotFoundException extends BaseException { 7 | 8 | public AccountNotFoundException() { 9 | } 10 | 11 | public AccountNotFoundException(String msg) { 12 | super(msg); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/EmployeePageQueryDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class EmployeePageQueryDTO implements Serializable { 9 | 10 | //员工姓名 11 | private String name; 12 | 13 | //页码 14 | private int page; 15 | 16 | //每页显示记录数 17 | private int pageSize; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.sky.service; 2 | 3 | import com.sky.dto.UserLoginDTO; 4 | import com.sky.entity.User; 5 | 6 | /** 7 | * 功能简述 8 | * 9 | * @author hssy 10 | * @version 1.0 11 | */ 12 | public interface UserService { 13 | 14 | /** 15 | * 用户微信登录 16 | */ 17 | 18 | User wxLogin(UserLoginDTO userLoginDTO); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/PasswordEditDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class PasswordEditDTO implements Serializable { 9 | 10 | //员工id 11 | private Long empId; 12 | 13 | //旧密码 14 | private String oldPassword; 15 | 16 | //新密码 17 | private String newPassword; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/OrderStatisticsVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.Data; 4 | import java.io.Serializable; 5 | 6 | @Data 7 | public class OrderStatisticsVO implements Serializable { 8 | //待接单数量 9 | private Integer toBeConfirmed; 10 | 11 | //待派送数量 12 | private Integer confirmed; 13 | 14 | //派送中数量 15 | private Integer deliveryInProgress; 16 | } 17 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/constant/JwtClaimsConstant.java: -------------------------------------------------------------------------------- 1 | package com.sky.constant; 2 | 3 | public class JwtClaimsConstant { 4 | 5 | public static final String EMP_ID = "empId"; 6 | public static final String USER_ID = "userId"; 7 | public static final String PHONE = "phone"; 8 | public static final String USERNAME = "username"; 9 | public static final String NAME = "name"; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | sky: 2 | datasource: 3 | driver-class-name: com.mysql.cj.jdbc.Driver 4 | host: localhost 5 | port: 3306 6 | database: sky_take_out 7 | username: root 8 | password: password 9 | 10 | alioss: 11 | endpoint: yourEndpoint 12 | access-key-id: yourAccessKeyId 13 | access-key-secret: yourAccessKeySecret 14 | bucket-name: yourBucketName 15 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/CategoryDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class CategoryDTO implements Serializable { 9 | 10 | //主键 11 | private Long id; 12 | 13 | //类型 1 菜品分类 2 套餐分类 14 | private Integer type; 15 | 16 | //分类名称 17 | private String name; 18 | 19 | //排序 20 | private Integer sort; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/EmployeeDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class EmployeeDTO implements Serializable { 9 | 10 | private Long id; 11 | 12 | private String username; 13 | 14 | private String name; 15 | 16 | private String phone; 17 | 18 | private String sex; 19 | 20 | private String idNumber; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/CategoryPageQueryDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class CategoryPageQueryDTO implements Serializable { 9 | 10 | //页码 11 | private int page; 12 | 13 | //每页记录数 14 | private int pageSize; 15 | 16 | //分类名称 17 | private String name; 18 | 19 | //分类类型 1菜品分类 2套餐分类 20 | private Integer type; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/DishPageQueryDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class DishPageQueryDTO implements Serializable { 9 | 10 | private int page; 11 | 12 | private int pageSize; 13 | 14 | private String name; 15 | 16 | //分类id 17 | private Integer categoryId; 18 | 19 | //状态 0表示禁用 1表示启用 20 | private Integer status; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/SetmealPageQueryDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class SetmealPageQueryDTO implements Serializable { 9 | 10 | private int page; 11 | 12 | private int pageSize; 13 | 14 | private String name; 15 | 16 | //分类id 17 | private Integer categoryId; 18 | 19 | //状态 0表示禁用 1表示启用 20 | private Integer status; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/OrderAmount.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * 功能简述 10 | * 封装mybatis查询不同日期的总额返回的union all结果集 11 | * @author hssy 12 | * @version 1.0 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Builder 18 | public class OrderAmount { 19 | 20 | private Double sum; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/UserLoginVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @Builder 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class UserLoginVO implements Serializable { 15 | 16 | private Long id; 17 | private String openid; 18 | private String token; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/GoodsSalesDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @Builder 14 | public class GoodsSalesDTO implements Serializable { 15 | //商品名称 16 | private String name; 17 | 18 | //销量 19 | private Integer number; 20 | } 21 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/constant/AutoFillConstant.java: -------------------------------------------------------------------------------- 1 | package com.sky.constant; 2 | 3 | /** 4 | * 公共字段自动填充相关常量 5 | */ 6 | public class AutoFillConstant { 7 | /** 8 | * 实体类中的方法名称 9 | */ 10 | public static final String SET_CREATE_TIME = "setCreateTime"; 11 | public static final String SET_UPDATE_TIME = "setUpdateTime"; 12 | public static final String SET_CREATE_USER = "setCreateUser"; 13 | public static final String SET_UPDATE_USER = "setUpdateUser"; 14 | } 15 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/result/PageResult.java: -------------------------------------------------------------------------------- 1 | package com.sky.result; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | /** 11 | * 封装分页查询结果 12 | */ 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class PageResult implements Serializable { 17 | 18 | private long total; //总记录数 19 | 20 | private List records; //当前页数据集合 21 | 22 | } 23 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/context/BaseContext.java: -------------------------------------------------------------------------------- 1 | package com.sky.context; 2 | 3 | public class BaseContext { 4 | 5 | public static ThreadLocal threadLocal = new ThreadLocal<>(); 6 | 7 | public static void setCurrentId(Long id) { 8 | threadLocal.set(id); 9 | } 10 | 11 | public static Long getCurrentId() { 12 | return threadLocal.get(); 13 | } 14 | 15 | public static void removeCurrentId() { 16 | threadLocal.remove(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/EmployeeLoginDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import java.io.Serializable; 8 | 9 | @Data 10 | @ApiModel(description = "员工登录时传递的数据模型") 11 | public class EmployeeLoginDTO implements Serializable { 12 | 13 | @ApiModelProperty("用户名") 14 | private String username; 15 | 16 | @ApiModelProperty("密码") 17 | private String password; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/AddressBookService.java: -------------------------------------------------------------------------------- 1 | package com.sky.service; 2 | 3 | import com.sky.entity.AddressBook; 4 | import java.util.List; 5 | 6 | public interface AddressBookService { 7 | 8 | List list(AddressBook addressBook); 9 | 10 | void save(AddressBook addressBook); 11 | 12 | AddressBook getById(Long id); 13 | 14 | void update(AddressBook addressBook); 15 | 16 | void setDefault(AddressBook addressBook); 17 | 18 | void deleteById(Long id); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/DataOverViewQueryDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.time.LocalDateTime; 10 | 11 | @Data 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class DataOverViewQueryDTO implements Serializable { 16 | 17 | private LocalDateTime begin; 18 | 19 | private LocalDateTime end; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/DishOverViewVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * 菜品总览 12 | */ 13 | @Data 14 | @Builder 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class DishOverViewVO implements Serializable { 18 | // 已启售数量 19 | private Integer sold; 20 | 21 | // 已停售数量 22 | private Integer discontinued; 23 | } 24 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/SetmealOverViewVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * 套餐总览 12 | */ 13 | @Data 14 | @Builder 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class SetmealOverViewVO implements Serializable { 18 | // 已启售数量 19 | private Integer sold; 20 | 21 | // 已停售数量 22 | private Integer discontinued; 23 | } 24 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/properties/AliOssProperties.java: -------------------------------------------------------------------------------- 1 | package com.sky.properties; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @ConfigurationProperties(prefix = "sky.alioss") 9 | @Data 10 | public class AliOssProperties { 11 | 12 | private String endpoint; 13 | private String accessKeyId; 14 | private String accessKeySecret; 15 | private String bucketName; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/LocalDateTime2TurpleDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import java.time.LocalDateTime; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | /** 10 | * 功能简述 11 | * 12 | * @author hssy 13 | * @version 1.0 14 | */ 15 | @Data 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | @Builder 19 | public class LocalDateTime2TurpleDTO { 20 | 21 | private LocalDateTime begin; 22 | 23 | private LocalDateTime end; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/SalesTop10ReportVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @Builder 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class SalesTop10ReportVO implements Serializable { 15 | 16 | //商品名称列表,以逗号分隔,例如:鱼香肉丝,宫保鸡丁,水煮鱼 17 | private String nameList; 18 | 19 | //销量列表,以逗号分隔,例如:260,215,200 20 | private String numberList; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/TurnoverReportVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @Builder 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class TurnoverReportVO implements Serializable { 15 | 16 | //日期,以逗号分隔,例如:2022-10-01,2022-10-02,2022-10-03 17 | private String dateList; 18 | 19 | //营业额,以逗号分隔,例如:406.0,1520.0,75.0 20 | private String turnoverList; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/OrderVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import com.sky.entity.OrderDetail; 4 | import com.sky.entity.Orders; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | import java.io.Serializable; 9 | import java.util.List; 10 | 11 | @Data 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class OrderVO extends Orders implements Serializable { 15 | 16 | //订单菜品信息 17 | private String orderDishes; 18 | 19 | //订单详情 20 | private List orderDetailList; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/config/WebSocketConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.sky.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.socket.server.standard.ServerEndpointExporter; 6 | 7 | /** 8 | * WebSocket配置类,用于注册WebSocket的Bean 9 | */ 10 | @Configuration 11 | public class WebSocketConfiguration { 12 | 13 | @Bean 14 | public ServerEndpointExporter serverEndpointExporter() { 15 | return new ServerEndpointExporter(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/DishItemVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @Builder 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class DishItemVO implements Serializable { 15 | 16 | //菜品名称 17 | private String name; 18 | 19 | //份数 20 | private Integer copies; 21 | 22 | //菜品图片 23 | private String image; 24 | 25 | //菜品描述 26 | private String description; 27 | } 28 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/UserReportVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @Builder 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class UserReportVO implements Serializable { 15 | 16 | //日期,以逗号分隔,例如:2022-10-01,2022-10-02,2022-10-03 17 | private String dateList; 18 | 19 | //用户总量,以逗号分隔,例如:200,210,220 20 | private String totalUserList; 21 | 22 | //新增用户,以逗号分隔,例如:20,21,10 23 | private String newUserList; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/annotation/AutoFill.java: -------------------------------------------------------------------------------- 1 | package com.sky.annotation; 2 | 3 | import com.sky.enumeration.OperationType; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 功能简述 12 | * 13 | * @author hssy 14 | * @version 1.0 15 | */ 16 | 17 | @Target(ElementType.METHOD) 18 | @Documented 19 | @Retention(RetentionPolicy.RUNTIME) 20 | public @interface AutoFill { 21 | //数据库操作类型 Update 和 Insert 22 | OperationType value(); 23 | } 24 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/ShoppingCartService.java: -------------------------------------------------------------------------------- 1 | package com.sky.service; 2 | 3 | import com.sky.dto.ShoppingCartDTO; 4 | import com.sky.entity.ShoppingCart; 5 | import com.sky.result.Result; 6 | import java.util.List; 7 | 8 | /** 9 | * 功能简述 10 | * 11 | * @author hssy 12 | * @version 1.0 13 | */ 14 | public interface ShoppingCartService { 15 | 16 | void add(ShoppingCartDTO shoppingCartDTO); 17 | 18 | List list(); 19 | 20 | void clean(); 21 | 22 | /** 23 | * 删除购物车中一个商品 24 | * @param shoppingCartDTO 25 | */ 26 | void subShoppingCart(ShoppingCartDTO shoppingCartDTO); 27 | } 28 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/OrderPaymentVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.time.LocalDateTime; 10 | 11 | @Data 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class OrderPaymentVO implements Serializable { 16 | 17 | private String nonceStr; //随机字符串 18 | private String paySign; //签名 19 | private String timeStamp; //时间戳 20 | private String signType; //签名算法 21 | private String packageStr; //统一下单接口返回的 prepay_id 参数值 22 | 23 | } 24 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/OrderSubmitVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | import java.time.LocalDateTime; 11 | 12 | @Data 13 | @Builder 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | public class OrderSubmitVO implements Serializable { 17 | //订单id 18 | private Long id; 19 | //订单号 20 | private String orderNumber; 21 | //订单金额 22 | private BigDecimal orderAmount; 23 | //下单时间 24 | private LocalDateTime orderTime; 25 | } 26 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/DishFlavor.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * 菜品口味 12 | */ 13 | @Data 14 | @Builder 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class DishFlavor implements Serializable { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | private Long id; 22 | //菜品id 23 | private Long dishId; 24 | 25 | //口味名称 26 | private String name; 27 | 28 | //口味数据list 29 | private String value; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/BusinessDataVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * 数据概览 12 | */ 13 | @Data 14 | @Builder 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class BusinessDataVO implements Serializable { 18 | 19 | private Double turnover;//营业额 20 | 21 | private Integer validOrderCount;//有效订单数 22 | 23 | private Double orderCompletionRate;//订单完成率 24 | 25 | private Double unitPrice;//平均客单价 26 | 27 | private Integer newUsers;//新增用户数 28 | 29 | } 30 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/DishFlavorMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.sky.entity.DishFlavor; 4 | import java.util.List; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Select; 7 | 8 | /** 9 | * 功能简述 10 | * 11 | * @author hssy 12 | * @version 1.0 13 | */ 14 | @Mapper 15 | public interface DishFlavorMapper { 16 | 17 | /** 18 | * 批量增加数据 19 | * @param flavors 20 | */ 21 | void insertBatch(List flavors); 22 | 23 | void deleteBatchByDishIds(List ids); 24 | 25 | @Select("select * from dish_flavor where dish_id=#{id}") 26 | List getByDishId(Long id); 27 | } 28 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/properties/JwtProperties.java: -------------------------------------------------------------------------------- 1 | package com.sky.properties; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @ConfigurationProperties(prefix = "sky.jwt") 9 | @Data 10 | public class JwtProperties { 11 | 12 | /** 13 | * 管理端员工生成jwt令牌相关配置 14 | */ 15 | private String adminSecretKey; 16 | private long adminTtl; 17 | private String adminTokenName; 18 | 19 | /** 20 | * 用户端微信用户生成jwt令牌相关配置 21 | */ 22 | private String userSecretKey; 23 | private long userTtl; 24 | private String userTokenName; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/OrderOverViewVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * 订单概览数据 12 | */ 13 | @Data 14 | @Builder 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class OrderOverViewVO implements Serializable { 18 | //待接单数量 19 | private Integer waitingOrders; 20 | 21 | //待派送数量 22 | private Integer deliveredOrders; 23 | 24 | //已完成数量 25 | private Integer completedOrders; 26 | 27 | //已取消数量 28 | private Integer cancelledOrders; 29 | 30 | //全部订单 31 | private Integer allOrders; 32 | } 33 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/DishDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import com.sky.entity.DishFlavor; 4 | import lombok.Data; 5 | import java.io.Serializable; 6 | import java.math.BigDecimal; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | @Data 11 | public class DishDTO implements Serializable { 12 | 13 | private Long id; 14 | //菜品名称 15 | private String name; 16 | //菜品分类id 17 | private Long categoryId; 18 | //菜品价格 19 | private BigDecimal price; 20 | //图片 21 | private String image; 22 | //描述信息 23 | private String description; 24 | //0 停售 1 起售 25 | private Integer status; 26 | //口味 27 | private List flavors = new ArrayList<>(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/OrdersPageQueryDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import lombok.Data; 4 | import org.springframework.format.annotation.DateTimeFormat; 5 | 6 | import java.io.Serializable; 7 | import java.time.LocalDateTime; 8 | 9 | @Data 10 | public class OrdersPageQueryDTO implements Serializable { 11 | 12 | private int page; 13 | 14 | private int pageSize; 15 | 16 | private String number; 17 | 18 | private String phone; 19 | 20 | private Integer status; 21 | 22 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 23 | private LocalDateTime beginTime; 24 | 25 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 26 | private LocalDateTime endTime; 27 | 28 | private Long userId; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/SetmealDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import com.sky.entity.SetmealDish; 4 | import lombok.Data; 5 | import java.io.Serializable; 6 | import java.math.BigDecimal; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | @Data 11 | public class SetmealDTO implements Serializable { 12 | 13 | private Long id; 14 | 15 | //分类id 16 | private Long categoryId; 17 | 18 | //套餐名称 19 | private String name; 20 | 21 | //套餐价格 22 | private BigDecimal price; 23 | 24 | //状态 0:停用 1:启用 25 | private Integer status; 26 | 27 | //描述信息 28 | private String description; 29 | 30 | //图片 31 | private String image; 32 | 33 | //套餐菜品关系 34 | private List setmealDishes = new ArrayList<>(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/EmployeeLoginVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.io.Serializable; 11 | 12 | @Data 13 | @Builder 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | @ApiModel(description = "员工登录返回的数据格式") 17 | public class EmployeeLoginVO implements Serializable { 18 | 19 | @ApiModelProperty("主键值") 20 | private Long id; 21 | 22 | @ApiModelProperty("用户名") 23 | private String userName; 24 | 25 | @ApiModelProperty("姓名") 26 | private String name; 27 | 28 | @ApiModelProperty("jwt令牌") 29 | private String token; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/SkyApplication.java: -------------------------------------------------------------------------------- 1 | package com.sky; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cache.annotation.EnableCaching; 7 | import org.springframework.scheduling.annotation.EnableScheduling; 8 | import org.springframework.transaction.annotation.EnableTransactionManagement; 9 | 10 | @SpringBootApplication 11 | @EnableTransactionManagement //开启注解方式的事务管理 12 | @Slf4j 13 | @EnableCaching//开启自动缓存 14 | @EnableScheduling//开启定时任务 15 | public class SkyApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(SkyApplication.class, args); 18 | log.info("server started"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/SetmealDish.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | 11 | /** 12 | * 套餐菜品关系 13 | */ 14 | @Data 15 | @Builder 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class SetmealDish implements Serializable { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | private Long id; 23 | 24 | //套餐id 25 | private Long setmealId; 26 | 27 | //菜品id 28 | private Long dishId; 29 | 30 | //菜品名称 (冗余字段) 31 | private String name; 32 | 33 | //菜品原价 34 | private BigDecimal price; 35 | 36 | //份数 37 | private Integer copies; 38 | } 39 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/mapper/DishFlavorMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | insert into dish_flavor(dish_id, name, value) VALUES 9 | 10 | (#{flavor.dishId},#{flavor.name},#{flavor.value}) 11 | 12 | 13 | 14 | 15 | delete from dish_flavor where dish_id in 16 | 17 | #{id} 18 | 19 | 20 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/OrderReportVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @Builder 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class OrderReportVO implements Serializable { 15 | 16 | //日期,以逗号分隔,例如:2022-10-01,2022-10-02,2022-10-03 17 | private String dateList; 18 | 19 | //每日订单数,以逗号分隔,例如:260,210,215 20 | private String orderCountList; 21 | 22 | //每日有效订单数,以逗号分隔,例如:20,21,10 23 | private String validOrderCountList; 24 | 25 | //订单总数 26 | private Integer totalOrderCount; 27 | 28 | //有效订单数 29 | private Integer validOrderCount; 30 | 31 | //订单完成率 32 | private Double orderCompletionRate; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/properties/WeChatProperties.java: -------------------------------------------------------------------------------- 1 | package com.sky.properties; 2 | 3 | import lombok.Data; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | @ConfigurationProperties(prefix = "sky.wechat") 10 | @Data 11 | public class WeChatProperties { 12 | 13 | private String appid; //小程序的appid 14 | private String secret; //小程序的秘钥 15 | private String mchid; //商户号 16 | private String mchSerialNo; //商户API证书的证书序列号 17 | private String privateKeyFilePath; //商户私钥文件 18 | private String apiV3Key; //证书解密的密钥 19 | private String weChatPayCertFilePath; //平台证书 20 | private String notifyUrl; //支付成功的回调地址 21 | private String refundNotifyUrl; //退款成功的回调地址 22 | 23 | } 24 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/OrderDetailMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.sky.dto.GoodsSalesDTO; 4 | import com.sky.entity.OrderDetail; 5 | import java.time.LocalDateTime; 6 | import java.util.List; 7 | import org.apache.ibatis.annotations.Mapper; 8 | import org.apache.ibatis.annotations.Select; 9 | 10 | /** 11 | * 功能简述 12 | * 13 | * @author hssy 14 | * @version 1.0 15 | */ 16 | @Mapper 17 | public interface OrderDetailMapper { 18 | 19 | void insertBatch(List orderDetailList); 20 | 21 | /** 22 | * 根据订单id查询订单明细 23 | * 24 | * @param orderId 25 | * @return 26 | */ 27 | @Select("select * from order_detail where order_id = #{orderId}") 28 | List getByOrderId(Long orderId); 29 | 30 | 31 | List countTopTenByTimeSpan(LocalDateTime begin, LocalDateTime end); 32 | } 33 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.time.LocalDate; 10 | import java.time.LocalDateTime; 11 | 12 | @Data 13 | @Builder 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | public class User implements Serializable { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | private Long id; 21 | 22 | //微信用户唯一标识 23 | private String openid; 24 | 25 | //姓名 26 | private String name; 27 | 28 | //手机号 29 | private String phone; 30 | 31 | //性别 0 女 1 男 32 | private String sex; 33 | 34 | //身份证号 35 | private String idNumber; 36 | 37 | //头像 38 | private String avatar; 39 | 40 | //注册时间 41 | private LocalDateTime createTime; 42 | } 43 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/mapper/SetMealDishMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | insert into setmeal_dish 8 | (setmeal_id,dish_id,name,price,copies) 9 | values 10 | 11 | (#{sd.setmealId},#{sd.dishId},#{sd.name},#{sd.price},#{sd.copies}) 12 | 13 | 14 | 15 | 16 | 22 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/DishService.java: -------------------------------------------------------------------------------- 1 | package com.sky.service; 2 | 3 | import com.sky.dto.DishDTO; 4 | import com.sky.dto.DishPageQueryDTO; 5 | import com.sky.entity.Dish; 6 | import com.sky.result.PageResult; 7 | import com.sky.vo.DishVO; 8 | import java.util.List; 9 | 10 | /** 11 | * 功能简述 12 | * 13 | * @author hssy 14 | * @version 1.0 15 | */ 16 | public interface DishService { 17 | 18 | void saveWithFlavor(DishDTO dishDTO); 19 | 20 | PageResult pageQuery(DishPageQueryDTO dto); 21 | 22 | void deleteBatch(List ids); 23 | 24 | DishVO getByIdWithFlavor(Long id); 25 | 26 | void updateWithFlavor(DishDTO dishDTO); 27 | 28 | List list(Long categoryId); 29 | 30 | void startOrStop(Integer status, Long id); 31 | 32 | /** 33 | * 条件查询菜品和口味 34 | * 35 | * @param dish 36 | * @return 37 | */ 38 | List listWithFlavor(Dish dish); 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/OrdersSubmitDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.math.BigDecimal; 8 | import java.time.LocalDateTime; 9 | 10 | @Data 11 | public class OrdersSubmitDTO implements Serializable { 12 | //地址簿id 13 | private Long addressBookId; 14 | //付款方式 15 | private int payMethod; 16 | //备注 17 | private String remark; 18 | //预计送达时间 19 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") 20 | private LocalDateTime estimatedDeliveryTime; 21 | //配送状态 1立即送出 0选择具体时间 22 | private Integer deliveryStatus; 23 | //餐具数量 24 | private Integer tablewareNumber; 25 | //餐具数量状态 1按餐量提供 0选择具体数量 26 | private Integer tablewareStatus; 27 | //打包费 28 | private Integer packAmount; 29 | //总金额 30 | private BigDecimal amount; 31 | } 32 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/WorkspaceService.java: -------------------------------------------------------------------------------- 1 | package com.sky.service; 2 | 3 | import com.sky.vo.BusinessDataVO; 4 | import com.sky.vo.DishOverViewVO; 5 | import com.sky.vo.OrderOverViewVO; 6 | import com.sky.vo.SetmealOverViewVO; 7 | import java.time.LocalDate; 8 | import java.time.LocalDateTime; 9 | import java.util.List; 10 | 11 | public interface WorkspaceService { 12 | 13 | /** 14 | * 根据时间段统计营业数据 15 | * @param begin 16 | * @param end 17 | * @return 18 | */ 19 | BusinessDataVO getBusinessData(LocalDateTime begin, LocalDateTime end); 20 | 21 | /** 22 | * 查询订单管理数据 23 | * @return 24 | */ 25 | OrderOverViewVO getOrderOverView(); 26 | 27 | /** 28 | * 查询菜品总览 29 | * @return 30 | */ 31 | DishOverViewVO getDishOverView(); 32 | 33 | /** 34 | * 查询套餐总览 35 | * @return 36 | */ 37 | SetmealOverViewVO getSetmealOverView(); 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/OrderDetail.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | 11 | /** 12 | * 订单明细 13 | */ 14 | @Data 15 | @Builder 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class OrderDetail implements Serializable { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | private Long id; 23 | 24 | //名称 25 | private String name; 26 | 27 | //订单id 28 | private Long orderId; 29 | 30 | //菜品id 31 | private Long dishId; 32 | 33 | //套餐id 34 | private Long setmealId; 35 | 36 | //口味 37 | private String dishFlavor; 38 | 39 | //数量 40 | private Integer number; 41 | 42 | //金额 43 | private BigDecimal amount; 44 | 45 | //图片 46 | private String image; 47 | } 48 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/Category.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import java.io.Serializable; 8 | import java.time.LocalDateTime; 9 | 10 | @Data 11 | @Builder 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class Category implements Serializable { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | private Long id; 19 | 20 | //类型: 1菜品分类 2套餐分类 21 | private Integer type; 22 | 23 | //分类名称 24 | private String name; 25 | 26 | //顺序 27 | private Integer sort; 28 | 29 | //分类状态 0标识禁用 1表示启用 30 | private Integer status; 31 | 32 | //创建时间 33 | private LocalDateTime createTime; 34 | 35 | //更新时间 36 | private LocalDateTime updateTime; 37 | 38 | //创建人 39 | private Long createUser; 40 | 41 | //修改人 42 | private Long updateUser; 43 | } 44 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/result/Result.java: -------------------------------------------------------------------------------- 1 | package com.sky.result; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 后端统一返回结果 9 | * @param 10 | */ 11 | @Data 12 | public class Result implements Serializable { 13 | 14 | private Integer code; //编码:1成功,0和其它数字为失败 15 | private String msg; //错误信息 16 | private T data; //数据 17 | 18 | public static Result success() { 19 | Result result = new Result(); 20 | result.code = 1; 21 | return result; 22 | } 23 | 24 | public static Result success(T object) { 25 | Result result = new Result(); 26 | result.data = object; 27 | result.code = 1; 28 | return result; 29 | } 30 | 31 | public static Result error(String msg) { 32 | Result result = new Result(); 33 | result.msg = msg; 34 | result.code = 0; 35 | return result; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/config/OssConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.sky.config; 2 | 3 | import com.sky.properties.AliOssProperties; 4 | import com.sky.utils.AliOssUtil; 5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * 功能简述 11 | * 12 | * @author hssy 13 | * @version 1.0 14 | */ 15 | 16 | 17 | @Configuration 18 | public class OssConfiguration { 19 | 20 | /** 21 | * 提供aliyunoss工具类 22 | * 23 | * @param aliOssProperties 24 | * @return 25 | */ 26 | @Bean 27 | @ConditionalOnMissingBean 28 | public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties) { 29 | return new AliOssUtil(aliOssProperties.getEndpoint(), 30 | aliOssProperties.getAccessKeyId(), 31 | aliOssProperties.getAccessKeySecret(), 32 | aliOssProperties.getBucketName()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/ShoppingCart.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | import java.time.LocalDateTime; 11 | 12 | /** 13 | * 购物车 14 | */ 15 | @Data 16 | @Builder 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class ShoppingCart implements Serializable { 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | private Long id; 24 | 25 | //名称 26 | private String name; 27 | 28 | //用户id 29 | private Long userId; 30 | 31 | //菜品id 32 | private Long dishId; 33 | 34 | //套餐id 35 | private Long setmealId; 36 | 37 | //口味 38 | private String dishFlavor; 39 | 40 | //数量 41 | private Integer number; 42 | 43 | //金额 44 | private BigDecimal amount; 45 | 46 | //图片 47 | private String image; 48 | 49 | private LocalDateTime createTime; 50 | } 51 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/Employee.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.time.LocalDateTime; 10 | 11 | @Data 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class Employee implements Serializable { 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | private Long id; 20 | 21 | private String username; 22 | 23 | private String name; 24 | 25 | private String password; 26 | 27 | private String phone; 28 | 29 | private String sex; 30 | 31 | private String idNumber; 32 | 33 | private Integer status; 34 | 35 | //@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 36 | private LocalDateTime createTime; 37 | 38 | //@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 39 | private LocalDateTime updateTime; 40 | 41 | private Long createUser; 42 | 43 | private Long updateUser; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/Dish.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import java.io.Serializable; 8 | import java.math.BigDecimal; 9 | import java.time.LocalDateTime; 10 | 11 | /** 12 | * 菜品 13 | */ 14 | @Data 15 | @Builder 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class Dish implements Serializable { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | private Long id; 23 | 24 | //菜品名称 25 | private String name; 26 | 27 | //菜品分类id 28 | private Long categoryId; 29 | 30 | //菜品价格 31 | private BigDecimal price; 32 | 33 | //图片 34 | private String image; 35 | 36 | //描述信息 37 | private String description; 38 | 39 | //0 停售 1 起售 40 | private Integer status; 41 | 42 | private LocalDateTime createTime; 43 | 44 | private LocalDateTime updateTime; 45 | 46 | private Long createUser; 47 | 48 | private Long updateUser; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/Setmeal.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import java.io.Serializable; 8 | import java.math.BigDecimal; 9 | import java.time.LocalDateTime; 10 | 11 | /** 12 | * 套餐 13 | */ 14 | @Data 15 | @Builder 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class Setmeal implements Serializable { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | private Long id; 23 | 24 | //分类id 25 | private Long categoryId; 26 | 27 | //套餐名称 28 | private String name; 29 | 30 | //套餐价格 31 | private BigDecimal price; 32 | 33 | //状态 0:停用 1:启用 34 | private Integer status; 35 | 36 | //描述信息 37 | private String description; 38 | 39 | //图片 40 | private String image; 41 | 42 | private LocalDateTime createTime; 43 | 44 | private LocalDateTime updateTime; 45 | 46 | private Long createUser; 47 | 48 | private Long updateUser; 49 | } 50 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/ReportService.java: -------------------------------------------------------------------------------- 1 | package com.sky.service; 2 | 3 | import com.sky.vo.OrderReportVO; 4 | import com.sky.vo.SalesTop10ReportVO; 5 | import com.sky.vo.TurnoverReportVO; 6 | import com.sky.vo.UserReportVO; 7 | import java.time.LocalDate; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | /** 11 | * 功能简述 12 | * 13 | * @author hssy 14 | * @version 1.0 15 | */ 16 | public interface ReportService { 17 | 18 | /** 19 | * 根据日期查询营业额数据 20 | * @param begin 21 | * @param end 22 | * @return 23 | */ 24 | TurnoverReportVO getTurnoverStatistics(LocalDate begin,LocalDate end); 25 | 26 | /** 27 | * 根据日期统计用户总数和新增量 28 | * @param begin 29 | * @param end 30 | * @return 31 | */ 32 | UserReportVO getUserStatistics(LocalDate begin, LocalDate end); 33 | 34 | OrderReportVO getOrderStatistics(LocalDate begin, LocalDate end); 35 | 36 | SalesTop10ReportVO getTopTenStatistics(LocalDate begin, LocalDate end); 37 | 38 | void exportBusinessData(HttpServletResponse response); 39 | } 40 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/DishVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import com.sky.entity.DishFlavor; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | import java.time.LocalDateTime; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | @Data 15 | @Builder 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class DishVO implements Serializable { 19 | 20 | private Long id; 21 | //菜品名称 22 | private String name; 23 | //菜品分类id 24 | private Long categoryId; 25 | //菜品价格 26 | private BigDecimal price; 27 | //图片 28 | private String image; 29 | //描述信息 30 | private String description; 31 | //0 停售 1 起售 32 | private Integer status; 33 | //更新时间 34 | private LocalDateTime updateTime; 35 | //分类名称 36 | private String categoryName; 37 | //菜品关联的口味 38 | private List flavors = new ArrayList<>(); 39 | 40 | //private Integer copies; 41 | } 42 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/config/RedisConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.sky.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.data.redis.connection.RedisConnectionFactory; 7 | import org.springframework.data.redis.core.RedisTemplate; 8 | import org.springframework.data.redis.serializer.StringRedisSerializer; 9 | 10 | /** 11 | * 功能简述 12 | * 13 | * @author hssy 14 | * @version 1.0 15 | */ 16 | @Configuration 17 | @Slf4j 18 | public class RedisConfiguration { 19 | 20 | @Bean 21 | public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { 22 | log.info("开始创建redis模板类..."); 23 | RedisTemplate redisTemplate = new RedisTemplate(); 24 | //设置key的序列化器,默认为jkdSerializationRedisSerializer 25 | redisTemplate.setKeySerializer(new StringRedisSerializer()); 26 | redisTemplate.setConnectionFactory(redisConnectionFactory); 27 | return redisTemplate; 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/mapper/OrderDetailMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | insert into order_detail (name, image, order_id, dish_id, setmeal_id, dish_flavor, number, amount) 7 | values 8 | 9 | (#{od.name},#{od.image},#{od.orderId} ,#{od.dishId},#{od.setmealId},#{od.dishFlavor},#{od.number},#{od.amount}) 10 | 11 | 12 | 21 | 22 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/vo/SetmealVO.java: -------------------------------------------------------------------------------- 1 | package com.sky.vo; 2 | 3 | import com.sky.entity.SetmealDish; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | import java.time.LocalDateTime; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | @Data 15 | @Builder 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class SetmealVO implements Serializable { 19 | 20 | private Long id; 21 | 22 | //分类id 23 | private Long categoryId; 24 | 25 | //套餐名称 26 | private String name; 27 | 28 | //套餐价格 29 | private BigDecimal price; 30 | 31 | //状态 0:停用 1:启用 32 | private Integer status; 33 | 34 | //描述信息 35 | private String description; 36 | 37 | //图片 38 | private String image; 39 | 40 | //更新时间 41 | private LocalDateTime updateTime; 42 | 43 | //分类名称 44 | private String categoryName; 45 | 46 | //套餐和菜品的关联关系 47 | private List setmealDishes = new ArrayList<>(); 48 | } 49 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.sky.dto.LocalDateTime2TurpleDTO; 4 | import com.sky.entity.User; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import org.apache.ibatis.annotations.Mapper; 8 | import org.apache.ibatis.annotations.Select; 9 | 10 | /** 11 | * 功能简述 12 | * 13 | * @author hssy 14 | * @version 1.0 15 | */ 16 | @Mapper 17 | public interface UserMapper { 18 | 19 | @Select("select * from user where openid=#{openid}") 20 | User getByOpenid(String openid); 21 | 22 | void insert(User user); 23 | 24 | @Select("select * from user where id=#{id}") 25 | User getById(Long userId); 26 | 27 | Integer countByMap(HashMap map); 28 | 29 | /** 30 | * 统计用户每天的新增量 31 | * @param dateList 32 | * @return 33 | */ 34 | List countByDateList(List dateList); 35 | 36 | /** 37 | * 按天统计用户总量 38 | * @param dateList 39 | * @return 40 | */ 41 | List sumByDateList(List dateList); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/SetMealDishMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.sky.entity.SetmealDish; 4 | import java.util.List; 5 | import org.apache.ibatis.annotations.Delete; 6 | import org.apache.ibatis.annotations.Mapper; 7 | import org.apache.ibatis.annotations.Select; 8 | 9 | /** 10 | * 功能简述 11 | * 12 | * @author hssy 13 | * @version 1.0 14 | */ 15 | @Mapper 16 | public interface SetMealDishMapper { 17 | 18 | 19 | /** 20 | * 根据菜品id来查套餐id 21 | * @param ids 22 | * @return 23 | */ 24 | List getSetmealIdsByDishIds(List ids); 25 | 26 | void insertBatch(List setmealDishes); 27 | 28 | /** 29 | * 根据套餐id删除套餐和菜品的关联关系 30 | * @param setmealId 31 | */ 32 | @Delete("delete from setmeal_dish where setmeal_id = #{setmealId}") 33 | void deleteBySetmealId(Long setmealId); 34 | 35 | /** 36 | * 根据套餐id查询套餐和菜品的关联关系 37 | * @param setmealId 38 | * @return 39 | */ 40 | @Select("select * from setmeal_dish where setmeal_id = #{setmealId}") 41 | List getBySetmealId(Long setmealId); 42 | } 43 | -------------------------------------------------------------------------------- /sky-pojo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | sky-take-out 7 | com.sky 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | sky-pojo 12 | 13 | 14 | org.projectlombok 15 | lombok 16 | 17 | 18 | com.fasterxml.jackson.core 19 | jackson-databind 20 | 2.9.2 21 | 22 | 23 | com.github.xiaoymin 24 | knife4j-spring-boot-starter 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/CategoryService.java: -------------------------------------------------------------------------------- 1 | package com.sky.service; 2 | 3 | import com.sky.dto.CategoryDTO; 4 | import com.sky.dto.CategoryPageQueryDTO; 5 | import com.sky.entity.Category; 6 | import com.sky.result.PageResult; 7 | import java.util.List; 8 | 9 | public interface CategoryService { 10 | 11 | /** 12 | * 新增分类 13 | * @param categoryDTO 14 | */ 15 | void save(CategoryDTO categoryDTO); 16 | 17 | /** 18 | * 分页查询 19 | * @param categoryPageQueryDTO 20 | * @return 21 | */ 22 | PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO); 23 | 24 | /** 25 | * 根据id删除分类 26 | * @param id 27 | */ 28 | void deleteById(Long id); 29 | 30 | /** 31 | * 修改分类 32 | * @param categoryDTO 33 | */ 34 | void update(CategoryDTO categoryDTO); 35 | 36 | /** 37 | * 启用、禁用分类 38 | * @param status 39 | * @param id 40 | */ 41 | void startOrStop(Integer status, Long id); 42 | 43 | /** 44 | * 根据类型查询分类 45 | * @param type 46 | * @return 47 | */ 48 | List list(Integer type); 49 | } 50 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/user/CategoryController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.user; 2 | 3 | import com.sky.entity.Category; 4 | import com.sky.result.Result; 5 | import com.sky.service.CategoryService; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiOperation; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | import java.util.List; 13 | 14 | @RestController("userCategoryController") 15 | @RequestMapping("/user/category") 16 | @Api(tags = "C端-分类接口") 17 | public class CategoryController { 18 | 19 | @Autowired 20 | private CategoryService categoryService; 21 | 22 | /** 23 | * 查询分类 24 | * @param type 25 | * @return 26 | */ 27 | @GetMapping("/list") 28 | @ApiOperation("查询分类") 29 | public Result> list(Integer type) { 30 | List list = categoryService.list(type); 31 | return Result.success(list); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Learning of sky take-out 2 | You may know the training company **itheima**(it's hard to leave a comment) 3 | and the project is called a must for Java backend developer to learn(I guess is especially for the **new hand**) 4 | 5 | ## Features 6 | I made some **improvement** based on the raw project,which mainly exists in **Mappers** (For example, I optimized some sql query from O(n) to O(1)). 7 | 8 | And you may browse the **commits history** to better know the different modules of this project and the detailed process when building it. 9 | 10 | ### mapper 11 | If you felt confused when watching the operation in the video that the teacher traversed some lists to do sql query(`IO!`) every iteration,you'll find the improvements in my code. 12 | I used batched operation with `in` keyword in mysql to avoid the behavior mentioned above in the video,especially when the lecturer iterated the id list to send many sql query.Instead,I choosed to send the list as parameter so as to just query once. 13 | And at the end of the course(the module of report),the lecturer still iterated the list to do sql query by date.I used the to union all query with one io cast. 14 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/dto/OrdersDTO.java: -------------------------------------------------------------------------------- 1 | package com.sky.dto; 2 | 3 | import com.sky.entity.OrderDetail; 4 | import lombok.Data; 5 | import java.io.Serializable; 6 | import java.math.BigDecimal; 7 | import java.time.LocalDateTime; 8 | import java.util.List; 9 | 10 | @Data 11 | public class OrdersDTO implements Serializable { 12 | 13 | private Long id; 14 | 15 | //订单号 16 | private String number; 17 | 18 | //订单状态 1待付款,2待派送,3已派送,4已完成,5已取消 19 | private Integer status; 20 | 21 | //下单用户id 22 | private Long userId; 23 | 24 | //地址id 25 | private Long addressBookId; 26 | 27 | //下单时间 28 | private LocalDateTime orderTime; 29 | 30 | //结账时间 31 | private LocalDateTime checkoutTime; 32 | 33 | //支付方式 1微信,2支付宝 34 | private Integer payMethod; 35 | 36 | //实收金额 37 | private BigDecimal amount; 38 | 39 | //备注 40 | private String remark; 41 | 42 | //用户名 43 | private String userName; 44 | 45 | //手机号 46 | private String phone; 47 | 48 | //地址 49 | private String address; 50 | 51 | //收货人 52 | private String consignee; 53 | 54 | private List orderDetails; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/EmployeeService.java: -------------------------------------------------------------------------------- 1 | package com.sky.service; 2 | 3 | import com.sky.dto.EmployeeDTO; 4 | import com.sky.dto.EmployeeLoginDTO; 5 | import com.sky.dto.EmployeePageQueryDTO; 6 | import com.sky.entity.Employee; 7 | import com.sky.result.PageResult; 8 | 9 | public interface EmployeeService { 10 | 11 | /** 12 | * 员工登录 13 | * @param employeeLoginDTO 14 | * @return 15 | */ 16 | Employee login(EmployeeLoginDTO employeeLoginDTO); 17 | 18 | /** 19 | * 新增员工 20 | * @param employeeDTO 21 | */ 22 | void save(EmployeeDTO employeeDTO); 23 | 24 | /** 25 | * 分页查询 26 | * @param employeePageQueryDTO 27 | * @return 28 | */ 29 | PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO); 30 | 31 | /** 32 | * 员工状态改变 33 | * @param status 34 | * @param id 35 | */ 36 | void startOrStop(Integer status, Long id); 37 | 38 | /** 39 | * 根据id查询员工 40 | * @param id 41 | * @return 42 | */ 43 | Employee getById(Long id); 44 | 45 | /** 46 | * 更新员工数据 47 | * @param employeeDTO 48 | */ 49 | void update(EmployeeDTO employeeDTO); 50 | } 51 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/user/ShopController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.user; 2 | 3 | import com.sky.result.Result; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.data.redis.core.RedisTemplate; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | /** 14 | * 功能简述 15 | * 16 | * @author hssy 17 | * @version 1.0 18 | */ 19 | 20 | @RestController("UserShopController") 21 | @RequestMapping("/user/shop") 22 | @Api(tags = "店铺相关接口") 23 | @Slf4j 24 | public class ShopController { 25 | 26 | public static final String KEY = "SHOP_STATUS"; 27 | 28 | @Autowired 29 | private RedisTemplate redisTemplate; 30 | 31 | @GetMapping("/status") 32 | @ApiOperation("显示店铺运营状态") 33 | public Result getStatus() { 34 | log.info("店铺查询状态"); 35 | return Result.success((Integer) redisTemplate.opsForValue().get(KEY)); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/mapper/ShoppingCartMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | insert into shopping_cart 7 | (name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) 8 | values 9 | 10 | (#{sc.name},#{sc.image},#{sc.userId},#{sc.dishId},#{sc.setmealId},#{sc.dishFlavor},#{sc.number},#{sc.amount},#{sc.createTime}) 11 | 12 | 13 | 14 | 24 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/AddressBook.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * 地址簿 12 | */ 13 | @Data 14 | @Builder 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class AddressBook implements Serializable { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | private Long id; 22 | 23 | //用户id 24 | private Long userId; 25 | 26 | //收货人 27 | private String consignee; 28 | 29 | //手机号 30 | private String phone; 31 | 32 | //性别 0 女 1 男 33 | private String sex; 34 | 35 | //省级区划编号 36 | private String provinceCode; 37 | 38 | //省级名称 39 | private String provinceName; 40 | 41 | //市级区划编号 42 | private String cityCode; 43 | 44 | //市级名称 45 | private String cityName; 46 | 47 | //区级区划编号 48 | private String districtCode; 49 | 50 | //区级名称 51 | private String districtName; 52 | 53 | //详细地址 54 | private String detail; 55 | 56 | //标签 57 | private String label; 58 | 59 | //是否默认 0否 1是 60 | private Integer isDefault; 61 | } 62 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/EmployeeMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.sky.annotation.AutoFill; 5 | import com.sky.dto.EmployeePageQueryDTO; 6 | import com.sky.entity.Employee; 7 | import com.sky.enumeration.OperationType; 8 | import org.apache.ibatis.annotations.Insert; 9 | import org.apache.ibatis.annotations.Mapper; 10 | import org.apache.ibatis.annotations.Select; 11 | 12 | @Mapper 13 | public interface EmployeeMapper { 14 | 15 | /** 16 | * 根据用户名查询员工 17 | * @param username 18 | * @return 19 | */ 20 | @Select("select * from employee where username = #{username}") 21 | Employee getByUsername(String username); 22 | 23 | @AutoFill(OperationType.INSERT) 24 | @Insert("insert into employee(name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user) " 25 | + "values " 26 | + "(#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})") 27 | void insert(Employee employee); 28 | 29 | Page selectByPage(EmployeePageQueryDTO employeePageQueryDTO); 30 | 31 | @AutoFill(OperationType.UPDATE) 32 | void update(Employee employee); 33 | 34 | @Select("select * from employee where id=#{id}") 35 | Employee getById(Long id); 36 | } 37 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/constant/MessageConstant.java: -------------------------------------------------------------------------------- 1 | package com.sky.constant; 2 | 3 | /** 4 | * 信息提示常量类 5 | */ 6 | public class MessageConstant { 7 | 8 | public static final String PASSWORD_ERROR = "密码错误"; 9 | public static final String ACCOUNT_NOT_FOUND = "账号不存在"; 10 | public static final String ACCOUNT_LOCKED = "账号被锁定"; 11 | public static final String UNKNOWN_ERROR = "未知错误"; 12 | public static final String USER_NOT_LOGIN = "用户未登录"; 13 | public static final String CATEGORY_BE_RELATED_BY_SETMEAL = "当前分类关联了套餐,不能删除"; 14 | public static final String CATEGORY_BE_RELATED_BY_DISH = "当前分类关联了菜品,不能删除"; 15 | public static final String SHOPPING_CART_IS_NULL = "购物车数据为空,不能下单"; 16 | public static final String ADDRESS_BOOK_IS_NULL = "用户地址为空,不能下单"; 17 | public static final String LOGIN_FAILED = "登录失败"; 18 | public static final String UPLOAD_FAILED = "文件上传失败"; 19 | public static final String SETMEAL_ENABLE_FAILED = "套餐内包含未启售菜品,无法启售"; 20 | public static final String PASSWORD_EDIT_FAILED = "密码修改失败"; 21 | public static final String DISH_ON_SALE = "起售中的菜品不能删除"; 22 | public static final String SETMEAL_ON_SALE = "起售中的套餐不能删除"; 23 | public static final String DISH_BE_RELATED_BY_SETMEAL = "当前菜品关联了套餐,不能删除"; 24 | public static final String ORDER_STATUS_ERROR = "订单状态错误"; 25 | public static final String ORDER_NOT_FOUND = "订单不存在"; 26 | public static final String ALREADY_EXISTS = "已存在"; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/ShoppingCartMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.sky.entity.ShoppingCart; 4 | import java.util.List; 5 | import org.apache.ibatis.annotations.Delete; 6 | import org.apache.ibatis.annotations.Insert; 7 | import org.apache.ibatis.annotations.Mapper; 8 | import org.apache.ibatis.annotations.Update; 9 | 10 | /** 11 | * 功能简述 12 | * 13 | * @author hssy 14 | * @version 1.0 15 | */ 16 | @Mapper 17 | public interface ShoppingCartMapper { 18 | 19 | List list(ShoppingCart shoppingCart); 20 | 21 | @Update("update shopping_cart set number=#{number} where id=#{id}") 22 | void updateNumberById(ShoppingCart shoppingCart); 23 | @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time)" 24 | + "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})") 25 | void insert(ShoppingCart shoppingCart); 26 | 27 | @Delete("delete from shopping_cart where user_id=#{currentId}") 28 | void deleteByUserId(Long currentId); 29 | 30 | /** 31 | * 根据id删除购物车数据 32 | * @param id 33 | */ 34 | @Delete("delete from shopping_cart where id = #{id}") 35 | void deleteById(Long id); 36 | 37 | /** 38 | * 批量插入购物车数据 39 | * 40 | * @param shoppingCartList 41 | */ 42 | void insertBatch(List shoppingCartList); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/mapper/EmployeeMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 14 | 15 | 16 | 17 | update employee 18 | 19 | name = #{name}, 20 | username = #{username}, 21 | password = #{password}, 22 | phone = #{phone}, 23 | sex = #{sex}, 24 | id_number = #{idNumber}, 25 | update_time = #{updateTime}, 26 | update_user = #{updateUser}, 27 | status = #{status}, 28 | 29 | where id = #{id} 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/admin/ShopController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.admin; 2 | 3 | import com.sky.result.Result; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.redis.core.RedisTemplate; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.PutMapping; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | /** 15 | * 功能简述 16 | * 17 | * @author hssy 18 | * @version 1.0 19 | */ 20 | 21 | @RestController("adminShopController") 22 | @RequestMapping("/admin/shop") 23 | @Api(tags = "店铺相关接口") 24 | public class ShopController { 25 | 26 | public static final String KEY="SHOP_STATUS"; 27 | 28 | @Autowired 29 | private RedisTemplate redisTemplate; 30 | 31 | @PutMapping("/{status}") 32 | @ApiOperation("设置店铺运营状态") 33 | public Result setStatus(@PathVariable Integer status){ 34 | redisTemplate.opsForValue().set("SHOP_STATUS",status); 35 | return Result.success(); 36 | } 37 | 38 | @GetMapping("/status") 39 | @ApiOperation("显示店铺运营状态") 40 | public Result getStatus(){ 41 | return Result.success((Integer) redisTemplate.opsForValue().get(KEY)); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | insert into user(openid, name, phone, sex, id_number, avatar, create_time) VALUES (#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime}) 8 | 9 | 20 | 26 | 32 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/SetmealService.java: -------------------------------------------------------------------------------- 1 | package com.sky.service; 2 | 3 | import com.sky.dto.SetmealDTO; 4 | import com.sky.dto.SetmealPageQueryDTO; 5 | import com.sky.entity.Setmeal; 6 | import com.sky.result.PageResult; 7 | import com.sky.vo.DishItemVO; 8 | import com.sky.vo.SetmealVO; 9 | import java.util.List; 10 | 11 | public interface SetmealService { 12 | 13 | /** 14 | * 新增套餐,同时需要保存套餐和菜品的关联关系 15 | * @param setmealDTO 16 | */ 17 | void saveWithDish(SetmealDTO setmealDTO); 18 | 19 | /** 20 | * 分页查询 21 | * @param setmealPageQueryDTO 22 | * @return 23 | */ 24 | PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO); 25 | 26 | /** 27 | * 批量删除套餐 28 | * @param ids 29 | */ 30 | void deleteBatch(List ids); 31 | 32 | /** 33 | * 根据id查询套餐和关联的菜品数据 34 | * @param id 35 | * @return 36 | */ 37 | SetmealVO getByIdWithDish(Long id); 38 | 39 | /** 40 | * 修改套餐 41 | * @param setmealDTO 42 | */ 43 | void update(SetmealDTO setmealDTO); 44 | 45 | /** 46 | * 套餐起售、停售 47 | * @param status 48 | * @param id 49 | */ 50 | void startOrStop(Integer status, Long id); 51 | 52 | 53 | /** 54 | * 条件查询 55 | * @param setmeal 56 | * @return 57 | */ 58 | List list(Setmeal setmeal); 59 | 60 | /** 61 | * 根据id查询菜品选项 62 | * @param id 63 | * @return 64 | */ 65 | List getDishItemById(Long id); 66 | 67 | } 68 | 69 | 70 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/CategoryMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.sky.annotation.AutoFill; 5 | import com.sky.enumeration.OperationType; 6 | import com.sky.dto.CategoryPageQueryDTO; 7 | import com.sky.entity.Category; 8 | import org.apache.ibatis.annotations.Delete; 9 | import org.apache.ibatis.annotations.Insert; 10 | import org.apache.ibatis.annotations.Mapper; 11 | import java.util.List; 12 | 13 | @Mapper 14 | public interface CategoryMapper { 15 | 16 | /** 17 | * 插入数据 18 | * @param category 19 | */ 20 | @AutoFill(OperationType.INSERT) 21 | @Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user)" + 22 | " VALUES" + 23 | " (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})") 24 | void insert(Category category); 25 | 26 | /** 27 | * 分页查询 28 | * @param categoryPageQueryDTO 29 | * @return 30 | */ 31 | Page pageQuery(CategoryPageQueryDTO categoryPageQueryDTO); 32 | 33 | /** 34 | * 根据id删除分类 35 | * @param id 36 | */ 37 | @Delete("delete from category where id = #{id}") 38 | void deleteById(Long id); 39 | 40 | /** 41 | * 根据id修改分类 42 | * @param category 43 | */ 44 | @AutoFill(OperationType.UPDATE) 45 | void update(Category category); 46 | 47 | /** 48 | * 根据类型查询分类 49 | * @param type 50 | * @return 51 | */ 52 | List list(Integer type); 53 | } 54 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/handler/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.sky.handler; 2 | 3 | import com.sky.constant.MessageConstant; 4 | import com.sky.exception.BaseException; 5 | import com.sky.result.Result; 6 | import java.sql.SQLIntegrityConstraintViolationException; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.RestControllerAdvice; 10 | 11 | /** 12 | * 全局异常处理器,处理项目中抛出的业务异常 13 | */ 14 | @RestControllerAdvice 15 | @Slf4j 16 | public class GlobalExceptionHandler { 17 | 18 | /** 19 | * 捕获业务异常 20 | * 21 | * @param ex 22 | * @return 23 | */ 24 | @ExceptionHandler 25 | public Result exceptionHandler(BaseException ex) { 26 | log.error("异常信息:{}", ex.getMessage()); 27 | return Result.error(ex.getMessage()); 28 | } 29 | 30 | /** 31 | * 处理SOL异常 32 | * 33 | * @param ex 34 | * @return 35 | */ 36 | @ExceptionHandler 37 | public Result exceptionHandler(SQLIntegrityConstraintViolationException ex) { 38 | //Duplicate entry 'zhangsan’ for key 'employee.idx username 39 | String message = ex.getMessage(); 40 | if (message.contains("Duplicate entry")) { 41 | String[] split = message.split(" "); 42 | String username = split[2]; 43 | String msg = username + MessageConstant.ALREADY_EXISTS; 44 | return Result.error(msg); 45 | } else { 46 | return Result.error(MessageConstant.UNKNOWN_ERROR); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/mapper/AddressBookMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | 21 | update address_book 22 | 23 | 24 | consignee = #{consignee}, 25 | 26 | 27 | sex = #{sex}, 28 | 29 | 30 | phone = #{phone}, 31 | 32 | 33 | detail = #{detail}, 34 | 35 | 36 | label = #{label}, 37 | 38 | 39 | is_default = #{isDefault}, 40 | 41 | 42 | where id = #{id} 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/DishMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.sky.annotation.AutoFill; 5 | import com.sky.dto.DishPageQueryDTO; 6 | import com.sky.entity.Dish; 7 | import com.sky.enumeration.OperationType; 8 | import com.sky.vo.DishVO; 9 | import java.util.List; 10 | import java.util.Map; 11 | import org.apache.ibatis.annotations.Mapper; 12 | import org.apache.ibatis.annotations.Select; 13 | 14 | @Mapper 15 | public interface DishMapper { 16 | 17 | /** 18 | * 根据分类id查询菜品数量 19 | * @param categoryId 20 | * @return 21 | */ 22 | @Select("select count(id) from dish where category_id = #{categoryId}") 23 | Integer countByCategoryId(Long categoryId); 24 | 25 | 26 | /** 27 | * 插入菜品 28 | * @param dish 29 | */ 30 | @AutoFill(OperationType.INSERT) 31 | void insert(Dish dish); 32 | 33 | Page pageQuery(DishPageQueryDTO dto); 34 | 35 | @Select("select * from dish where id=#{id}") 36 | Dish getById(Long id); 37 | 38 | List queryUnsale(List ids); 39 | 40 | void deleteBatch(List ids); 41 | 42 | @AutoFill(OperationType.UPDATE) 43 | void update(Dish dish); 44 | 45 | List list(Dish dish); 46 | 47 | /** 48 | * 根据套餐id查询菜品 49 | * @param setmealId 50 | * @return 51 | */ 52 | @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}") 53 | List getBySetmealId(Long setmealId); 54 | 55 | /** 56 | * 根据条件统计菜品数量 57 | * @param map 58 | * @return 59 | */ 60 | Integer countByMap(Map map); 61 | } 62 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/AddressBookMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.sky.entity.AddressBook; 4 | import org.apache.ibatis.annotations.*; 5 | import java.util.List; 6 | 7 | @Mapper 8 | public interface AddressBookMapper { 9 | 10 | /** 11 | * 条件查询 12 | * @param addressBook 13 | * @return 14 | */ 15 | List list(AddressBook addressBook); 16 | 17 | /** 18 | * 新增 19 | * @param addressBook 20 | */ 21 | @Insert("insert into address_book" + 22 | " (user_id, consignee, phone, sex, province_code, province_name, city_code, city_name, district_code," + 23 | " district_name, detail, label, is_default)" + 24 | " values (#{userId}, #{consignee}, #{phone}, #{sex}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}," + 25 | " #{districtCode}, #{districtName}, #{detail}, #{label}, #{isDefault})") 26 | void insert(AddressBook addressBook); 27 | 28 | /** 29 | * 根据id查询 30 | * @param id 31 | * @return 32 | */ 33 | @Select("select * from address_book where id = #{id}") 34 | AddressBook getById(Long id); 35 | 36 | /** 37 | * 根据id修改 38 | * @param addressBook 39 | */ 40 | void update(AddressBook addressBook); 41 | 42 | /** 43 | * 根据 用户id修改 是否默认地址 44 | * @param addressBook 45 | */ 46 | @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}") 47 | void updateIsDefaultByUserId(AddressBook addressBook); 48 | 49 | /** 50 | * 根据id删除地址 51 | * @param id 52 | */ 53 | @Delete("delete from address_book where id = #{id}") 54 | void deleteById(Long id); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/mapper/CategoryMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 18 | 19 | 20 | update category 21 | 22 | 23 | type = #{type}, 24 | 25 | 26 | name = #{name}, 27 | 28 | 29 | sort = #{sort}, 30 | 31 | 32 | status = #{status}, 33 | 34 | 35 | update_time = #{updateTime}, 36 | 37 | 38 | update_user = #{updateUser} 39 | 40 | 41 | where id = #{id} 42 | 43 | 44 | 52 | 53 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/admin/CommonController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.admin; 2 | 3 | import com.sky.constant.MessageConstant; 4 | import com.sky.result.Result; 5 | import com.sky.utils.AliOssUtil; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiOperation; 8 | import java.io.IOException; 9 | import java.util.UUID; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | import org.springframework.web.multipart.MultipartFile; 16 | 17 | /** 18 | * 功能简述 19 | * 20 | * @author hssy 21 | * @version 1.0 22 | */ 23 | 24 | @RestController 25 | @RequestMapping("/admin/common") 26 | @Api(tags = "通用上传模块") 27 | @Slf4j 28 | public class CommonController { 29 | 30 | @Autowired 31 | private AliOssUtil aliOssUtil; 32 | 33 | /** 34 | * 文件上传 35 | * 36 | * @param file 37 | * @return 38 | */ 39 | @PostMapping("/upload") 40 | @ApiOperation("文件上传") 41 | public Result upload(MultipartFile file) { 42 | try { 43 | //获取文件原始名 44 | String originalFilename = file.getOriginalFilename(); 45 | //获取文件后缀名 46 | String extension = originalFilename.substring(originalFilename.lastIndexOf(".")); 47 | //获取文件最终名字 48 | String fileName = UUID.randomUUID().toString() + extension; 49 | 50 | //获取访问路径 51 | 52 | String filePath = aliOssUtil.upload(file.getBytes(), fileName); 53 | return Result.success(filePath); 54 | } catch (IOException e) { 55 | log.error("文件上传失败:{}", e); 56 | } 57 | 58 | return Result.error(MessageConstant.UPLOAD_FAILED); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/user/DishController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.user; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.sky.constant.StatusConstant; 5 | import com.sky.entity.Dish; 6 | import com.sky.result.Result; 7 | import com.sky.service.DishService; 8 | import com.sky.vo.DishVO; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiOperation; 11 | import java.util.List; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.data.redis.core.RedisTemplate; 15 | import org.springframework.web.bind.annotation.GetMapping; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | @RestController("userDishController") 20 | @RequestMapping("/user/dish") 21 | @Slf4j 22 | @Api(tags = "C端-菜品浏览接口") 23 | public class DishController { 24 | 25 | @Autowired 26 | private DishService dishService; 27 | 28 | @Autowired 29 | private RedisTemplate redisTemplate; 30 | 31 | /** 32 | * 根据分类id查询菜品 33 | * 34 | * @param categoryId 35 | * @return 36 | */ 37 | @GetMapping("/list") 38 | @ApiOperation("根据分类id查询菜品") 39 | public Result> list(Long categoryId) { 40 | //构造redis中的key来查询分类下的菜单 41 | String key = "dish_" + categoryId; 42 | //如果存在则读取缓存 43 | List list = (List) redisTemplate.opsForValue().get(key); 44 | if (list!=null&&list.size()>0 ){ 45 | return Result.success(list); 46 | } 47 | //如果不存在则查询数据库并构造缓存 48 | Dish dish = new Dish(); 49 | dish.setCategoryId(categoryId); 50 | dish.setStatus(StatusConstant.ENABLE);//查询起售中的菜品 51 | 52 | list = dishService.listWithFlavor(dish); 53 | redisTemplate.opsForValue().set(key,list); 54 | return Result.success(list); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/task/OrderTask.java: -------------------------------------------------------------------------------- 1 | package com.sky.task; 2 | 3 | import com.sky.entity.Orders; 4 | import com.sky.mapper.OrderMapper; 5 | import java.time.LocalDateTime; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.scheduling.annotation.Scheduled; 11 | import org.springframework.stereotype.Component; 12 | 13 | /** 14 | * 功能简述 15 | * 16 | * @author hssy 17 | * @version 1.0 18 | */ 19 | @Component 20 | @Slf4j 21 | public class OrderTask { 22 | 23 | @Autowired 24 | private OrderMapper orderMapper; 25 | 26 | /** 27 | * 检查过期的未支付订单 28 | */ 29 | @Scheduled(cron = "0 * * * * ?")//每分钟 30 | public void processTimeOutOrders() { 31 | LocalDateTime time = LocalDateTime.now().plusMinutes(-15); 32 | List orders = orderMapper.getByStatusAndOrderTimeLT(Orders.PENDING_PAYMENT, time); 33 | if (orders != null && orders.size() != 0) { 34 | List ids = new ArrayList<>(); 35 | orders.forEach((order) -> 36 | ids.add(order.getId()) 37 | ); 38 | orderMapper.updateTimeOutByIds(Orders.CANCELLED, "订单超时,自动取消", LocalDateTime.now(), ids); 39 | } 40 | } 41 | 42 | /** 43 | * 检查一直处于派送中的订单 44 | */ 45 | @Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点 46 | public void processDeliveringOrders() { 47 | LocalDateTime time = LocalDateTime.now().plusMinutes(-60); 48 | List orders = orderMapper.getByStatusAndOrderTimeLT(Orders.DELIVERY_IN_PROGRESS, time); 49 | if (orders != null && orders.size() != 0) { 50 | List ids = new ArrayList<>(); 51 | orders.forEach((order) -> 52 | ids.add(order.getId()) 53 | ); 54 | orderMapper.updateDeliveringByIds(Orders.COMPLETED, ids); 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/user/SetmealController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.user; 2 | 3 | import com.sky.constant.StatusConstant; 4 | import com.sky.entity.Setmeal; 5 | import com.sky.result.Result; 6 | import com.sky.service.SetmealService; 7 | import com.sky.vo.DishItemVO; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.cache.annotation.Cacheable; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.PathVariable; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RestController; 16 | import java.util.List; 17 | 18 | @RestController("userSetmealController") 19 | @RequestMapping("/user/setmeal") 20 | @Api(tags = "C端-套餐浏览接口") 21 | public class SetmealController { 22 | @Autowired 23 | private SetmealService setmealService; 24 | 25 | /** 26 | * 条件查询 27 | * 28 | * @param categoryId 29 | * @return 30 | */ 31 | @GetMapping("/list") 32 | @ApiOperation("根据分类id查询套餐") 33 | @Cacheable(cacheNames = "setMealCache",key = "#categoryId")//key : setMealCache::1 34 | public Result> list(Long categoryId) { 35 | Setmeal setmeal = new Setmeal(); 36 | setmeal.setCategoryId(categoryId); 37 | setmeal.setStatus(StatusConstant.ENABLE); 38 | 39 | List list = setmealService.list(setmeal); 40 | return Result.success(list); 41 | } 42 | 43 | /** 44 | * 根据套餐id查询包含的菜品列表 45 | * 46 | * @param id 47 | * @return 48 | */ 49 | @GetMapping("/dish/{id}") 50 | @ApiOperation("根据套餐id查询包含的菜品列表") 51 | public Result> dishList(@PathVariable("id") Long id) { 52 | List list = setmealService.getDishItemById(id); 53 | return Result.success(list); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/websocket/WebSocketServer.java: -------------------------------------------------------------------------------- 1 | package com.sky.websocket; 2 | 3 | import org.springframework.stereotype.Component; 4 | import javax.websocket.OnClose; 5 | import javax.websocket.OnMessage; 6 | import javax.websocket.OnOpen; 7 | import javax.websocket.Session; 8 | import javax.websocket.server.PathParam; 9 | import javax.websocket.server.ServerEndpoint; 10 | import java.util.Collection; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * WebSocket服务 16 | */ 17 | @Component 18 | @ServerEndpoint("/ws/{sid}") 19 | public class WebSocketServer { 20 | 21 | //存放会话对象 22 | private static Map sessionMap = new HashMap(); 23 | 24 | /** 25 | * 连接建立成功调用的方法 26 | */ 27 | @OnOpen 28 | public void onOpen(Session session, @PathParam("sid") String sid) { 29 | //System.out.println("客户端:" + sid + "建立连接"); 30 | sessionMap.put(sid, session); 31 | } 32 | 33 | /** 34 | * 收到客户端消息后调用的方法 35 | * 36 | * @param message 客户端发送过来的消息 37 | */ 38 | @OnMessage 39 | public void onMessage(String message, @PathParam("sid") String sid) { 40 | //System.out.println("收到来自客户端:" + sid + "的信息:" + message); 41 | } 42 | 43 | /** 44 | * 连接关闭调用的方法 45 | * 46 | * @param sid 47 | */ 48 | @OnClose 49 | public void onClose(@PathParam("sid") String sid) { 50 | //System.out.println("连接断开:" + sid); 51 | sessionMap.remove(sid); 52 | } 53 | 54 | /** 55 | * 群发 56 | * 57 | * @param message 58 | */ 59 | public void sendToAllClient(String message) { 60 | Collection sessions = sessionMap.values(); 61 | for (Session session : sessions) { 62 | try { 63 | //服务器向客户端发送消息 64 | session.getBasicRemote().sendText(message); 65 | } catch (Exception e) { 66 | e.printStackTrace(); 67 | } 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/utils/JwtUtil.java: -------------------------------------------------------------------------------- 1 | package com.sky.utils; 2 | 3 | import io.jsonwebtoken.Claims; 4 | import io.jsonwebtoken.JwtBuilder; 5 | import io.jsonwebtoken.Jwts; 6 | import io.jsonwebtoken.SignatureAlgorithm; 7 | import java.nio.charset.StandardCharsets; 8 | import java.util.Date; 9 | import java.util.Map; 10 | 11 | public class JwtUtil { 12 | /** 13 | * 生成jwt 14 | * 使用Hs256算法, 私匙使用固定秘钥 15 | * 16 | * @param secretKey jwt秘钥 17 | * @param ttlMillis jwt过期时间(毫秒) 18 | * @param claims 设置的信息 19 | * @return 20 | */ 21 | public static String createJWT(String secretKey, long ttlMillis, Map claims) { 22 | // 指定签名的时候使用的签名算法,也就是header那部分 23 | SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; 24 | 25 | // 生成JWT的时间 26 | long expMillis = System.currentTimeMillis() + ttlMillis; 27 | Date exp = new Date(expMillis); 28 | 29 | // 设置jwt的body 30 | JwtBuilder builder = Jwts.builder() 31 | // 如果有私有声明,一定要先设置这个自己创建的私有的声明,这个是给builder的claim赋值,一旦写在标准的声明赋值之后,就是覆盖了那些标准的声明的 32 | .setClaims(claims) 33 | // 设置签名使用的签名算法和签名使用的秘钥 34 | .signWith(signatureAlgorithm, secretKey.getBytes(StandardCharsets.UTF_8)) 35 | // 设置过期时间 36 | .setExpiration(exp); 37 | 38 | return builder.compact(); 39 | } 40 | 41 | /** 42 | * Token解密 43 | * 44 | * @param secretKey jwt秘钥 此秘钥一定要保留好在服务端, 不能暴露出去, 否则sign就可以被伪造, 如果对接多个客户端建议改造成多个 45 | * @param token 加密后的token 46 | * @return 47 | */ 48 | public static Claims parseJWT(String secretKey, String token) { 49 | // 得到DefaultJwtParser 50 | Claims claims = Jwts.parser() 51 | // 设置签名的秘钥 52 | .setSigningKey(secretKey.getBytes(StandardCharsets.UTF_8)) 53 | // 设置需要解析的jwt 54 | .parseClaimsJws(token).getBody(); 55 | return claims; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/interceptor/JwtTokenAdminInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.sky.interceptor; 2 | 3 | import com.sky.constant.JwtClaimsConstant; 4 | import com.sky.context.BaseContext; 5 | import com.sky.properties.JwtProperties; 6 | import com.sky.utils.JwtUtil; 7 | import io.jsonwebtoken.Claims; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Component; 11 | import org.springframework.web.method.HandlerMethod; 12 | import org.springframework.web.servlet.HandlerInterceptor; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | /** 17 | * jwt令牌校验的拦截器 18 | */ 19 | @Component 20 | @Slf4j 21 | public class JwtTokenAdminInterceptor implements HandlerInterceptor { 22 | 23 | @Autowired 24 | private JwtProperties jwtProperties; 25 | 26 | /** 27 | * 校验jwt 28 | * 29 | * @param request 30 | * @param response 31 | * @param handler 32 | * @return 33 | * @throws Exception 34 | */ 35 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 36 | //判断当前拦截到的是Controller的方法还是其他资源 37 | if (!(handler instanceof HandlerMethod)) { 38 | //当前拦截到的不是动态方法,直接放行 39 | return true; 40 | } 41 | 42 | //1、从请求头中获取令牌 43 | String token = request.getHeader(jwtProperties.getAdminTokenName()); 44 | 45 | //2、校验令牌 46 | try { 47 | log.info("jwt校验:{}", token); 48 | Claims claims = JwtUtil.parseJWT(jwtProperties.getAdminSecretKey(), token); 49 | Long empId = Long.valueOf(claims.get(JwtClaimsConstant.EMP_ID).toString()); 50 | log.info("当前员工id:{}", empId); 51 | BaseContext.setCurrentId(empId); 52 | //3、通过,放行 53 | return true; 54 | } catch (Exception ex) { 55 | //4、不通过,响应401状态码 56 | response.setStatus(401); 57 | return false; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/interceptor/JwtTokenUserInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.sky.interceptor; 2 | 3 | import com.sky.constant.JwtClaimsConstant; 4 | import com.sky.context.BaseContext; 5 | import com.sky.properties.JwtProperties; 6 | import com.sky.utils.JwtUtil; 7 | import io.jsonwebtoken.Claims; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.web.method.HandlerMethod; 14 | import org.springframework.web.servlet.HandlerInterceptor; 15 | 16 | /** 17 | * jwt令牌校验的拦截器 18 | */ 19 | @Component 20 | @Slf4j 21 | public class JwtTokenUserInterceptor implements HandlerInterceptor { 22 | 23 | @Autowired 24 | private JwtProperties jwtProperties; 25 | 26 | /** 27 | * 校验jwt 28 | * 29 | * @param request 30 | * @param response 31 | * @param handler 32 | * @return 33 | * @throws Exception 34 | */ 35 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 36 | //判断当前拦截到的是Controller的方法还是其他资源 37 | if (!(handler instanceof HandlerMethod)) { 38 | //当前拦截到的不是动态方法,直接放行 39 | return true; 40 | } 41 | 42 | //1、从请求头中获取令牌 43 | String token = request.getHeader(jwtProperties.getUserTokenName()); 44 | 45 | //2、校验令牌 46 | try { 47 | log.info("jwt校验:{}", token); 48 | Claims claims = JwtUtil.parseJWT(jwtProperties.getUserSecretKey(), token); 49 | Long userId = Long.valueOf(claims.get(JwtClaimsConstant.USER_ID).toString()); 50 | log.info("当前用户id:{}", userId); 51 | BaseContext.setCurrentId(userId); 52 | //3、通过,放行 53 | return true; 54 | } catch (Exception ex) { 55 | //4、不通过,响应401状态码 56 | response.setStatus(401); 57 | return false; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | spring: 5 | profiles: 6 | active: dev 7 | main: 8 | allow-circular-references: true 9 | datasource: 10 | druid: 11 | driver-class-name: ${sky.datasource.driver-class-name} 12 | 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 13 | username: ${sky.datasource.username} 14 | password: ${sky.datasource.password} 15 | redis: 16 | database: ${sky.redis.database} 17 | host: ${sky.redis.host} 18 | port: ${sky.redis.port} 19 | 20 | mybatis: 21 | #mapper配置文件 22 | mapper-locations: classpath:mapper/*.xml 23 | type-aliases-package: com.sky.entity 24 | configuration: 25 | #开启驼峰命名 26 | map-underscore-to-camel-case: true 27 | 28 | logging: 29 | level: 30 | com: 31 | sky: 32 | mapper: debug 33 | service: info 34 | controller: info 35 | 36 | sky: 37 | jwt: 38 | # 设置jwt签名加密时使用的秘钥 39 | admin-secret-key: itcast 40 | # 设置jwt过期时间 41 | admin-ttl: 7200000 42 | # 设置前端传递过来的令牌名称 43 | admin-token-name: token 44 | 45 | user-token-name: authentication 46 | 47 | user-ttl: 7200000 48 | 49 | user-secret-key: ${sky.jwt.key} 50 | 51 | 52 | wechat: 53 | appid: ${sky.wechat.appid} 54 | secret: ${sky.wechat.secret} 55 | mchid: ${sky.dev.wechat.mchid} 56 | mchSerialNo: ${sky.dev.wechat.mchSerialNo} 57 | privateKeyFilePath: ${sky.dev.wechat.privateKeyFilePath} 58 | apiV3Key: ${sky.wechat.apiVersion3Key} 59 | weChatPayCertFilePath: ${sky.dev.wechat.weChatPayCertFilePath} 60 | notifyUrl: ${sky.dev.wechat.notifyUr1} 61 | refundNotifyUrl: ${sky.dev.wechat.refundNotifyUr1} 62 | 63 | alioss: 64 | endpoint: ${sky.alioss.endpoint} 65 | access-key-id: ${sky.alioss.access-key-id} 66 | access-key-secret: ${sky.alioss.access-key-secret} 67 | bucket-name: ${sky.alioss.bucket-name} 68 | 69 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/user/UserController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.user; 2 | 3 | import com.sky.constant.JwtClaimsConstant; 4 | import com.sky.dto.UserLoginDTO; 5 | import com.sky.entity.User; 6 | import com.sky.properties.JwtProperties; 7 | import com.sky.result.Result; 8 | import com.sky.service.UserService; 9 | import com.sky.utils.JwtUtil; 10 | import com.sky.vo.UserLoginVO; 11 | import io.swagger.annotations.Api; 12 | import io.swagger.annotations.ApiOperation; 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | import lombok.extern.slf4j.Slf4j; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.web.bind.annotation.PostMapping; 18 | import org.springframework.web.bind.annotation.RequestBody; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RestController; 21 | 22 | /** 23 | * 功能简述 24 | * 25 | * @author hssy 26 | * @version 1.0 27 | */ 28 | 29 | @RestController 30 | @Slf4j 31 | @Api(tags = "C端用户相关接口") 32 | @RequestMapping("/user/user") 33 | public class UserController { 34 | 35 | @Autowired 36 | private UserService userService; 37 | 38 | @Autowired 39 | private JwtProperties jwtProperties; 40 | 41 | @PostMapping("/login") 42 | @ApiOperation("用户微信登录") 43 | public Result login(@RequestBody UserLoginDTO userLoginDTO) { 44 | log.info("用户的授权码为:{}", userLoginDTO.getCode()); 45 | 46 | //微信登录 47 | User user = userService.wxLogin(userLoginDTO); 48 | 49 | Map claims = new HashMap<>(); 50 | claims.put(JwtClaimsConstant.USER_ID, user.getId()); 51 | 52 | //生成jwt令牌 53 | String jwt = JwtUtil.createJWT(jwtProperties.getUserSecretKey(), jwtProperties.getUserTtl(), claims); 54 | 55 | UserLoginVO userLoginVO = UserLoginVO.builder() 56 | .openid(user.getOpenid()) 57 | .token(jwt) 58 | .id(user.getId()) 59 | .build(); 60 | 61 | return Result.success(userLoginVO); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /sky-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | sky-take-out 7 | com.sky 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | sky-common 12 | 13 | 14 | org.projectlombok 15 | lombok 16 | 17 | 18 | com.alibaba 19 | fastjson 20 | 21 | 22 | commons-lang 23 | commons-lang 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-json 28 | 29 | 30 | io.jsonwebtoken 31 | jjwt 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-configuration-processor 37 | true 38 | 39 | 40 | com.aliyun.oss 41 | aliyun-sdk-oss 42 | 43 | 44 | javax.xml.bind 45 | jaxb-api 46 | 47 | 48 | 49 | com.github.wechatpay-apiv3 50 | wechatpay-apache-httpclient 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/user/ShoppingCartController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.user; 2 | 3 | import com.sky.dto.ShoppingCartDTO; 4 | import com.sky.entity.ShoppingCart; 5 | import com.sky.result.Result; 6 | import com.sky.service.ShoppingCartService; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import java.util.List; 10 | import org.apache.ibatis.annotations.Delete; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.PostMapping; 15 | import org.springframework.web.bind.annotation.RequestBody; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | /** 20 | * 功能简述 21 | * 22 | * @author hssy 23 | * @version 1.0 24 | */ 25 | @RestController 26 | @Api(tags = "C端购物车相关接口") 27 | @RequestMapping("/user/shoppingCart") 28 | public class ShoppingCartController { 29 | 30 | @Autowired 31 | private ShoppingCartService shoppingCartService; 32 | 33 | @PostMapping("/add") 34 | @ApiOperation("添加购物车") 35 | public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){ 36 | shoppingCartService.add(shoppingCartDTO); 37 | return Result.success(); 38 | } 39 | 40 | @GetMapping("/list") 41 | @ApiOperation("查询购物车数据") 42 | public Result> list(){ 43 | return Result.success(shoppingCartService.list()); 44 | } 45 | 46 | 47 | @DeleteMapping("/clean") 48 | @ApiOperation("清除购物车") 49 | public Result clean(){ 50 | shoppingCartService.clean(); 51 | return Result.success(); 52 | } 53 | 54 | /** 55 | * 删除购物车中一个商品 56 | * @param shoppingCartDTO 57 | * @return 58 | */ 59 | @PostMapping("/sub") 60 | @ApiOperation("删除购物车中一个商品") 61 | public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){ 62 | shoppingCartService.subShoppingCart(shoppingCartDTO); 63 | return Result.success(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/SetmealMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.sky.annotation.AutoFill; 5 | import com.sky.dto.SetmealPageQueryDTO; 6 | import com.sky.entity.Setmeal; 7 | import com.sky.enumeration.OperationType; 8 | import com.sky.vo.DishItemVO; 9 | import com.sky.vo.SetmealVO; 10 | import java.util.List; 11 | import java.util.Map; 12 | import org.apache.ibatis.annotations.Delete; 13 | import org.apache.ibatis.annotations.Mapper; 14 | import org.apache.ibatis.annotations.Select; 15 | 16 | @Mapper 17 | public interface SetmealMapper { 18 | 19 | /** 20 | * 根据分类id查询套餐的数量 21 | * @param id 22 | * @return 23 | */ 24 | @Select("select count(id) from setmeal where category_id = #{categoryId}") 25 | Integer countByCategoryId(Long id); 26 | 27 | /** 28 | * 新增套餐 29 | * @param setmeal 30 | */ 31 | @AutoFill(OperationType.INSERT) 32 | void insert(Setmeal setmeal); 33 | 34 | /** 35 | * 分页查询 36 | * @param setmealPageQueryDTO 37 | * @return 38 | */ 39 | Page pageQuery(SetmealPageQueryDTO setmealPageQueryDTO); 40 | 41 | /** 42 | * 根据id查询套餐 43 | * @param id 44 | * @return 45 | */ 46 | @Select("select * from setmeal where id = #{id}") 47 | Setmeal getById(Long id); 48 | 49 | /** 50 | * 根据id删除套餐 51 | * @param setmealId 52 | */ 53 | @Delete("delete from setmeal where id = #{id}") 54 | void deleteById(Long setmealId); 55 | 56 | void update(Setmeal setmeal); 57 | 58 | /** 59 | * 动态条件查询套餐 60 | * @param setmeal 61 | * @return 62 | */ 63 | List list(Setmeal setmeal); 64 | 65 | /** 66 | * 根据套餐id查询菜品选项 67 | * @param setmealId 68 | * @return 69 | */ 70 | @Select("select sd.name, sd.copies, d.image, d.description " + 71 | "from setmeal_dish sd left join dish d on sd.dish_id = d.id " + 72 | "where sd.setmeal_id = #{setmealId}") 73 | List getDishItemBySetmealId(Long setmealId); 74 | 75 | 76 | /** 77 | * 根据条件统计套餐数量 78 | * @param map 79 | * @return 80 | */ 81 | Integer countByMap(Map map); 82 | } 83 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/admin/WorkSpaceController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.admin; 2 | 3 | import com.sky.result.Result; 4 | import com.sky.service.WorkspaceService; 5 | import com.sky.vo.BusinessDataVO; 6 | import com.sky.vo.DishOverViewVO; 7 | import com.sky.vo.OrderOverViewVO; 8 | import com.sky.vo.SetmealOverViewVO; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiOperation; 11 | import lombok.extern.slf4j.Slf4j; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RestController; 16 | import java.time.LocalDateTime; 17 | import java.time.LocalTime; 18 | 19 | /** 20 | * 工作台 21 | */ 22 | @RestController 23 | @RequestMapping("/admin/workspace") 24 | @Slf4j 25 | @Api(tags = "工作台相关接口") 26 | public class WorkSpaceController { 27 | 28 | @Autowired 29 | private WorkspaceService workspaceService; 30 | 31 | /** 32 | * 工作台今日数据查询 33 | * @return 34 | */ 35 | @GetMapping("/businessData") 36 | @ApiOperation("工作台今日数据查询") 37 | public Result businessData(){ 38 | //获得当天的开始时间 39 | LocalDateTime begin = LocalDateTime.now().with(LocalTime.MIN); 40 | //获得当天的结束时间 41 | LocalDateTime end = LocalDateTime.now().with(LocalTime.MAX); 42 | 43 | BusinessDataVO businessDataVO = workspaceService.getBusinessData(begin, end); 44 | return Result.success(businessDataVO); 45 | } 46 | 47 | /** 48 | * 查询订单管理数据 49 | * @return 50 | */ 51 | @GetMapping("/overviewOrders") 52 | @ApiOperation("查询订单管理数据") 53 | public Result orderOverView(){ 54 | return Result.success(workspaceService.getOrderOverView()); 55 | } 56 | 57 | /** 58 | * 查询菜品总览 59 | * @return 60 | */ 61 | @GetMapping("/overviewDishes") 62 | @ApiOperation("查询菜品总览") 63 | public Result dishOverView(){ 64 | return Result.success(workspaceService.getDishOverView()); 65 | } 66 | 67 | /** 68 | * 查询套餐总览 69 | * @return 70 | */ 71 | @GetMapping("/overviewSetmeals") 72 | @ApiOperation("查询套餐总览") 73 | public Result setmealOverView(){ 74 | return Result.success(workspaceService.getSetmealOverView()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/mapper/OrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.mapper; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.sky.dto.LocalDateTime2TurpleDTO; 5 | import com.sky.dto.OrderAmount; 6 | import com.sky.dto.OrdersPageQueryDTO; 7 | import com.sky.entity.Orders; 8 | import com.sky.vo.OrderVO; 9 | import java.time.LocalDate; 10 | import java.time.LocalDateTime; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | import org.apache.ibatis.annotations.Mapper; 15 | import org.apache.ibatis.annotations.Select; 16 | 17 | /** 18 | * 功能简述 19 | * 20 | * @author hssy 21 | * @version 1.0 22 | */ 23 | @Mapper 24 | public interface OrderMapper { 25 | 26 | void insert(Orders orders); 27 | 28 | /** 29 | * 根据订单号查询订单 30 | * @param orderNumber 31 | */ 32 | @Select("select * from orders where number = #{orderNumber}") 33 | Orders getByNumber(String orderNumber); 34 | 35 | /** 36 | * 修改订单信息 37 | * @param orders 38 | */ 39 | void update(Orders orders); 40 | 41 | /** 42 | * 根据订单状态和下单时间查询订单 43 | * @param status 44 | * @param orderTime 45 | * @return 46 | */ 47 | @Select("select * from orders where status=#{status} and order_time<#{orderTime}") 48 | List getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime); 49 | 50 | void updateTimeOutByIds(Integer status,String cancelReason,LocalDateTime cancelTime,List ids); 51 | 52 | void updateDeliveringByIds(Integer status, List ids); 53 | 54 | /** 55 | * 分页条件查询并按下单时间排序 56 | * @param ordersPageQueryDTO 57 | */ 58 | Page pageQuery(OrdersPageQueryDTO ordersPageQueryDTO); 59 | 60 | /** 61 | * 根据id查询订单 62 | * @param id 63 | */ 64 | @Select("select * from orders where id=#{id}") 65 | Orders getById(Long id); 66 | 67 | /** 68 | * 根据状态统计订单数量 69 | * @param status 70 | */ 71 | @Select("select count(id) from orders where status = #{status}") 72 | Integer countStatus(Integer status); 73 | 74 | 75 | Double sumByMap(HashMap map); 76 | 77 | List countSumByDay(List dateList); 78 | 79 | List countOrderNumByDay(List dateList); 80 | 81 | List sumValidNumByDay(List dateList); 82 | 83 | Integer countOrderNumByMap(Map map); 84 | } 85 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/impl/AddressBookServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.sky.service.impl; 2 | 3 | import com.sky.context.BaseContext; 4 | import com.sky.entity.AddressBook; 5 | import com.sky.mapper.AddressBookMapper; 6 | import com.sky.service.AddressBookService; 7 | import java.util.List; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | @Service 14 | @Slf4j 15 | public class AddressBookServiceImpl implements AddressBookService { 16 | 17 | @Autowired 18 | private AddressBookMapper addressBookMapper; 19 | 20 | /** 21 | * 条件查询 22 | * 23 | * @param addressBook 24 | * @return 25 | */ 26 | public List list(AddressBook addressBook) { 27 | return addressBookMapper.list(addressBook); 28 | } 29 | 30 | /** 31 | * 新增地址 32 | * 33 | * @param addressBook 34 | */ 35 | public void save(AddressBook addressBook) { 36 | addressBook.setUserId(BaseContext.getCurrentId()); 37 | addressBook.setIsDefault(0); 38 | addressBookMapper.insert(addressBook); 39 | } 40 | 41 | /** 42 | * 根据id查询 43 | * 44 | * @param id 45 | * @return 46 | */ 47 | public AddressBook getById(Long id) { 48 | AddressBook addressBook = addressBookMapper.getById(id); 49 | return addressBook; 50 | } 51 | 52 | /** 53 | * 根据id修改地址 54 | * 55 | * @param addressBook 56 | */ 57 | public void update(AddressBook addressBook) { 58 | addressBookMapper.update(addressBook); 59 | } 60 | 61 | /** 62 | * 设置默认地址 63 | * 64 | * @param addressBook 65 | */ 66 | @Transactional 67 | public void setDefault(AddressBook addressBook) { 68 | //1、将当前用户的所有地址修改为非默认地址 update address_book set is_default = ? where user_id = ? 69 | addressBook.setIsDefault(0); 70 | addressBook.setUserId(BaseContext.getCurrentId()); 71 | addressBookMapper.updateIsDefaultByUserId(addressBook); 72 | 73 | //2、将当前地址改为默认地址 update address_book set is_default = ? where id = ? 74 | addressBook.setIsDefault(1); 75 | addressBookMapper.update(addressBook); 76 | } 77 | 78 | /** 79 | * 根据id删除地址 80 | * 81 | * @param id 82 | */ 83 | public void deleteById(Long id) { 84 | addressBookMapper.deleteById(id); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.sky.service.impl; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.sky.constant.MessageConstant; 6 | import com.sky.dto.UserLoginDTO; 7 | import com.sky.entity.User; 8 | import com.sky.exception.LoginFailedException; 9 | import com.sky.mapper.UserMapper; 10 | import com.sky.properties.WeChatProperties; 11 | import com.sky.service.UserService; 12 | import com.sky.utils.HttpClientUtil; 13 | import java.time.LocalDateTime; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.stereotype.Service; 18 | 19 | /** 20 | * 功能简述 21 | * 22 | * @author hssy 23 | * @version 1.0 24 | */ 25 | 26 | @Service 27 | public class UserServiceImpl implements UserService { 28 | 29 | private static final String WX_LOGIN = "https://api.weixin.qq.com/sns/jscode2session"; 30 | 31 | @Autowired 32 | private UserMapper userMapper; 33 | 34 | @Autowired 35 | private WeChatProperties weChatProperties; 36 | 37 | @Override 38 | public User wxLogin(UserLoginDTO userLoginDTO) { 39 | //获取openid 40 | String openid = getOpenid(userLoginDTO.getCode()); 41 | //判断openid是否为空,若为空则抛出业务异常 42 | if (openid == null) { 43 | throw new LoginFailedException(MessageConstant.LOGIN_FAILED); 44 | } 45 | //判断用户是否注册过 46 | User user = userMapper.getByOpenid(openid); 47 | //是新用户则自动完成注册 48 | if (user==null){ 49 | user = User.builder() 50 | .openid(openid) 51 | .createTime(LocalDateTime.now()) 52 | .build(); 53 | userMapper.insert(user); 54 | } 55 | 56 | 57 | return user; 58 | } 59 | 60 | /** 61 | * 调用微信接口获取openid 62 | * 63 | * @param code 64 | * @return 65 | */ 66 | private String getOpenid(String code) { 67 | //调用微信接口获取openid 68 | Map map = new HashMap<>(); 69 | map.put("appid", weChatProperties.getAppid()); 70 | map.put("secret", weChatProperties.getSecret()); 71 | map.put("js_code", code); 72 | map.put("grant_type", "authorization_code"); 73 | //获取返回的json字符串 74 | String json = HttpClientUtil.doGet(WX_LOGIN, map); 75 | JSONObject jsonObject = JSON.parseObject(json); 76 | String openid = jsonObject.getString("openid"); 77 | 78 | return openid; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/utils/AliOssUtil.java: -------------------------------------------------------------------------------- 1 | package com.sky.utils; 2 | 3 | import com.aliyun.oss.ClientException; 4 | import com.aliyun.oss.OSS; 5 | import com.aliyun.oss.OSSClientBuilder; 6 | import com.aliyun.oss.OSSException; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.extern.slf4j.Slf4j; 10 | import java.io.ByteArrayInputStream; 11 | 12 | @Data 13 | @AllArgsConstructor 14 | @Slf4j 15 | public class AliOssUtil { 16 | 17 | private String endpoint; 18 | private String accessKeyId; 19 | private String accessKeySecret; 20 | private String bucketName; 21 | 22 | /** 23 | * 文件上传 24 | * 25 | * @param bytes 26 | * @param objectName 27 | * @return 28 | */ 29 | public String upload(byte[] bytes, String objectName) { 30 | 31 | // 创建OSSClient实例。 32 | OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); 33 | 34 | try { 35 | // 创建PutObject请求。 36 | ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(bytes)); 37 | } catch (OSSException oe) { 38 | System.out.println("Caught an OSSException, which means your request made it to OSS, " 39 | + "but was rejected with an error response for some reason."); 40 | System.out.println("Error Message:" + oe.getErrorMessage()); 41 | System.out.println("Error Code:" + oe.getErrorCode()); 42 | System.out.println("Request ID:" + oe.getRequestId()); 43 | System.out.println("Host ID:" + oe.getHostId()); 44 | } catch (ClientException ce) { 45 | System.out.println("Caught an ClientException, which means the client encountered " 46 | + "a serious internal problem while trying to communicate with OSS, " 47 | + "such as not being able to access the network."); 48 | System.out.println("Error Message:" + ce.getMessage()); 49 | } finally { 50 | if (ossClient != null) { 51 | ossClient.shutdown(); 52 | } 53 | } 54 | 55 | //文件访问路径规则 https://BucketName.Endpoint/ObjectName 56 | StringBuilder stringBuilder = new StringBuilder("https://"); 57 | stringBuilder 58 | .append(bucketName) 59 | .append(".") 60 | .append(endpoint) 61 | .append("/") 62 | .append(objectName); 63 | 64 | log.info("文件上传到:{}", stringBuilder.toString()); 65 | 66 | return stringBuilder.toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /sky-pojo/src/main/java/com/sky/entity/Orders.java: -------------------------------------------------------------------------------- 1 | package com.sky.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | import java.time.LocalDateTime; 11 | 12 | /** 13 | * 订单 14 | */ 15 | @Data 16 | @Builder 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class Orders implements Serializable { 20 | 21 | /** 22 | * 订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消 23 | */ 24 | public static final Integer PENDING_PAYMENT = 1; 25 | public static final Integer TO_BE_CONFIRMED = 2; 26 | public static final Integer CONFIRMED = 3; 27 | public static final Integer DELIVERY_IN_PROGRESS = 4; 28 | public static final Integer COMPLETED = 5; 29 | public static final Integer CANCELLED = 6; 30 | 31 | /** 32 | * 支付状态 0未支付 1已支付 2退款 33 | */ 34 | public static final Integer UN_PAID = 0; 35 | public static final Integer PAID = 1; 36 | public static final Integer REFUND = 2; 37 | 38 | private static final long serialVersionUID = 1L; 39 | 40 | private Long id; 41 | 42 | //订单号 43 | private String number; 44 | 45 | //订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消 7退款 46 | private Integer status; 47 | 48 | //下单用户id 49 | private Long userId; 50 | 51 | //地址id 52 | private Long addressBookId; 53 | 54 | //下单时间 55 | private LocalDateTime orderTime; 56 | 57 | //结账时间 58 | private LocalDateTime checkoutTime; 59 | 60 | //支付方式 1微信,2支付宝 61 | private Integer payMethod; 62 | 63 | //支付状态 0未支付 1已支付 2退款 64 | private Integer payStatus; 65 | 66 | //实收金额 67 | private BigDecimal amount; 68 | 69 | //备注 70 | private String remark; 71 | 72 | //用户名 73 | private String userName; 74 | 75 | //手机号 76 | private String phone; 77 | 78 | //地址 79 | private String address; 80 | 81 | //收货人 82 | private String consignee; 83 | 84 | //订单取消原因 85 | private String cancelReason; 86 | 87 | //订单拒绝原因 88 | private String rejectionReason; 89 | 90 | //订单取消时间 91 | private LocalDateTime cancelTime; 92 | 93 | //预计送达时间 94 | private LocalDateTime estimatedDeliveryTime; 95 | 96 | //配送状态 1立即送出 0选择具体时间 97 | private Integer deliveryStatus; 98 | 99 | //送达时间 100 | private LocalDateTime deliveryTime; 101 | 102 | //打包费 103 | private int packAmount; 104 | 105 | //餐具数量 106 | private int tablewareNumber; 107 | 108 | //餐具数量状态 1按餐量提供 0选择具体数量 109 | private Integer tablewareStatus; 110 | } 111 | -------------------------------------------------------------------------------- /sky-common/src/main/java/com/sky/json/JacksonObjectMapper.java: -------------------------------------------------------------------------------- 1 | package com.sky.json; 2 | 3 | import com.fasterxml.jackson.databind.DeserializationFeature; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.fasterxml.jackson.databind.module.SimpleModule; 6 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; 7 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; 8 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; 9 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; 10 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; 11 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; 12 | 13 | import java.time.LocalDate; 14 | import java.time.LocalDateTime; 15 | import java.time.LocalTime; 16 | import java.time.format.DateTimeFormatter; 17 | 18 | import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; 19 | 20 | /** 21 | * 对象映射器:基于jackson将Java对象转为json,或者将json转为Java对象 22 | * 将JSON解析为Java对象的过程称为 [从JSON反序列化Java对象] 23 | * 从Java对象生成JSON的过程称为 [序列化Java对象到JSON] 24 | */ 25 | public class JacksonObjectMapper extends ObjectMapper { 26 | 27 | public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; 28 | //public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; 29 | public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm"; 30 | public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss"; 31 | 32 | public JacksonObjectMapper() { 33 | super(); 34 | //收到未知属性时不报异常 35 | this.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); 36 | 37 | //反序列化时,属性不存在的兼容处理 38 | this.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); 39 | 40 | SimpleModule simpleModule = new SimpleModule() 41 | .addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT))) 42 | .addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT))) 43 | .addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT))) 44 | .addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT))) 45 | .addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT))) 46 | .addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT))); 47 | 48 | //注册功能模块 例如,可以添加自定义序列化器和反序列化器 49 | this.registerModule(simpleModule); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.sky.service; 2 | 3 | import com.sky.dto.OrdersCancelDTO; 4 | import com.sky.dto.OrdersConfirmDTO; 5 | import com.sky.dto.OrdersPageQueryDTO; 6 | import com.sky.dto.OrdersPaymentDTO; 7 | import com.sky.dto.OrdersRejectionDTO; 8 | import com.sky.dto.OrdersSubmitDTO; 9 | import com.sky.result.PageResult; 10 | import com.sky.vo.OrderPaymentVO; 11 | import com.sky.vo.OrderStatisticsVO; 12 | import com.sky.vo.OrderSubmitVO; 13 | import com.sky.vo.OrderVO; 14 | 15 | /** 16 | * 功能简述 17 | * 18 | * @author hssy 19 | * @version 1.0 20 | */ 21 | public interface OrderService { 22 | 23 | OrderSubmitVO submit(OrdersSubmitDTO submitDTO); 24 | 25 | /** 26 | * 订单支付 27 | * 28 | * @param ordersPaymentDTO 29 | * @return 30 | */ 31 | OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception; 32 | 33 | /** 34 | * 支付成功,修改订单状态 35 | * 36 | * @param outTradeNo 37 | */ 38 | void paySuccess(String outTradeNo); 39 | 40 | /** 41 | * 用户端订单分页查询 42 | * 43 | * @param page 44 | * @param pageSize 45 | * @param status 46 | * @return 47 | */ 48 | PageResult pageQuery4User(int page, int pageSize, Integer status); 49 | 50 | /** 51 | * 查询订单详情 52 | * 53 | * @param id 54 | * @return 55 | */ 56 | OrderVO details(Long id); 57 | 58 | /** 59 | * 用户取消订单 60 | * 61 | * @param id 62 | */ 63 | void userCancelById(Long id) throws Exception; 64 | 65 | /** 66 | * 再来一单 67 | * 68 | * @param id 69 | */ 70 | void repetition(Long id); 71 | 72 | 73 | /** 74 | * 条件搜索订单 75 | * 76 | * @param ordersPageQueryDTO 77 | * @return 78 | */ 79 | PageResult conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO); 80 | 81 | /** 82 | * 各个状态的订单数量统计 83 | * 84 | * @return 85 | */ 86 | OrderStatisticsVO statistics(); 87 | 88 | /** 89 | * 接单 90 | * 91 | * @param ordersConfirmDTO 92 | */ 93 | void confirm(OrdersConfirmDTO ordersConfirmDTO); 94 | 95 | /** 96 | * 拒单 97 | * @param ordersRejectionDTO 98 | */ 99 | void rejection(OrdersRejectionDTO ordersRejectionDTO) throws Exception; 100 | 101 | /** 102 | * 取消订单 103 | * @param ordersCancelDTO 104 | */ 105 | void cancel(OrdersCancelDTO ordersCancelDTO) throws Exception; 106 | 107 | /** 108 | * 修改派送状态 109 | * @param id 110 | */ 111 | void delivery(Long id); 112 | 113 | /** 114 | * 修改订单完成状态 115 | * @param id 116 | */ 117 | void complete(Long id); 118 | 119 | void reminder(Long id); 120 | } 121 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/mapper/SetMealMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | insert into setmeal 8 | (category_id, name, price, status, description, image, create_time, update_time, create_user, update_user) 9 | values (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime}, 10 | #{createUser}, #{updateUser}) 11 | 12 | 13 | update setmeal 14 | 15 | category_id=#{categoryId} 16 | name=#{name} 17 | price=#{price} 18 | status=#{status} 19 | description=#{description} 20 | image=#{image} 21 | update_user=#{updateUser} 22 | update_time=#{updateTime} 23 | 24 | where id =#{id} 25 | 26 | 27 | 49 | 50 | 64 | 65 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/admin/CategoryController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.admin; 2 | 3 | import com.sky.dto.CategoryDTO; 4 | import com.sky.dto.CategoryPageQueryDTO; 5 | import com.sky.entity.Category; 6 | import com.sky.result.PageResult; 7 | import com.sky.result.Result; 8 | import com.sky.service.CategoryService; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiOperation; 11 | import lombok.extern.slf4j.Slf4j; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.web.bind.annotation.*; 14 | import java.util.List; 15 | 16 | /** 17 | * 分类管理 18 | */ 19 | @RestController 20 | @RequestMapping("/admin/category") 21 | @Api(tags = "分类相关接口") 22 | @Slf4j 23 | public class CategoryController { 24 | 25 | @Autowired 26 | private CategoryService categoryService; 27 | 28 | /** 29 | * 新增分类 30 | * @param categoryDTO 31 | * @return 32 | */ 33 | @PostMapping 34 | @ApiOperation("新增分类") 35 | public Result save(@RequestBody CategoryDTO categoryDTO){ 36 | log.info("新增分类:{}", categoryDTO); 37 | categoryService.save(categoryDTO); 38 | return Result.success(); 39 | } 40 | 41 | /** 42 | * 分类分页查询 43 | * @param categoryPageQueryDTO 44 | * @return 45 | */ 46 | @GetMapping("/page") 47 | @ApiOperation("分类分页查询") 48 | public Result page(CategoryPageQueryDTO categoryPageQueryDTO){ 49 | log.info("分页查询:{}", categoryPageQueryDTO); 50 | PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO); 51 | return Result.success(pageResult); 52 | } 53 | 54 | /** 55 | * 删除分类 56 | * @param id 57 | * @return 58 | */ 59 | @DeleteMapping 60 | @ApiOperation("删除分类") 61 | public Result deleteById(Long id){ 62 | log.info("删除分类:{}", id); 63 | categoryService.deleteById(id); 64 | return Result.success(); 65 | } 66 | 67 | /** 68 | * 修改分类 69 | * @param categoryDTO 70 | * @return 71 | */ 72 | @PutMapping 73 | @ApiOperation("修改分类") 74 | public Result update(@RequestBody CategoryDTO categoryDTO){ 75 | categoryService.update(categoryDTO); 76 | return Result.success(); 77 | } 78 | 79 | /** 80 | * 启用、禁用分类 81 | * @param status 82 | * @param id 83 | * @return 84 | */ 85 | @PostMapping("/status/{status}") 86 | @ApiOperation("启用禁用分类") 87 | public Result startOrStop(@PathVariable("status") Integer status, Long id){ 88 | categoryService.startOrStop(status,id); 89 | return Result.success(); 90 | } 91 | 92 | /** 93 | * 根据类型查询分类 94 | * @param type 95 | * @return 96 | */ 97 | @GetMapping("/list") 98 | @ApiOperation("根据类型查询分类") 99 | public Result> list(Integer type){ 100 | List list = categoryService.list(type); 101 | return Result.success(list); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/apsect/AutoFillAspect.java: -------------------------------------------------------------------------------- 1 | package com.sky.apsect; 2 | 3 | import com.sky.annotation.AutoFill; 4 | import com.sky.constant.AutoFillConstant; 5 | import com.sky.context.BaseContext; 6 | import com.sky.enumeration.OperationType; 7 | import java.lang.reflect.Method; 8 | import java.time.LocalDateTime; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.aspectj.lang.JoinPoint; 11 | import org.aspectj.lang.annotation.Aspect; 12 | import org.aspectj.lang.annotation.Before; 13 | import org.aspectj.lang.annotation.Pointcut; 14 | import org.aspectj.lang.reflect.MethodSignature; 15 | import org.springframework.stereotype.Component; 16 | 17 | /** 18 | * 功能简述 19 | * 20 | * @author hssy 21 | * @version 1.0 22 | */ 23 | @Aspect 24 | @Component 25 | @Slf4j 26 | public class AutoFillAspect { 27 | 28 | @Pointcut("execution(* com.sky.mapper.*.*(..)) && @annotation(com.sky.annotation.AutoFill)") 29 | public void autoFillPointCut() { 30 | } 31 | 32 | @Before("autoFillPointCut()") 33 | public void autoFill(JoinPoint joinPoint) { 34 | 35 | //获取到当前被栏截的方法上的数据库操作类型 36 | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); 37 | OperationType value = signature.getMethod().getAnnotation(AutoFill.class).value(); 38 | 39 | //获取到当前被拦截的方法的参数--实体对象 40 | Object[] args = joinPoint.getArgs(); 41 | if (args == null || args.length == 0) { 42 | return; 43 | } 44 | Object entity = args[0]; 45 | 46 | //准备赋值的数据 47 | LocalDateTime now = LocalDateTime.now(); 48 | Long currentId = BaseContext.getCurrentId(); 49 | 50 | //根据当前不同的操作类型,为对应的属性通过反射来赋值 51 | if (value == OperationType.INSERT) { 52 | try { 53 | Method setCreateTime = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_CREATE_TIME, LocalDateTime.class); 54 | Method setCreateUser = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_CREATE_USER, Long.class); 55 | Method setUpdateTime = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_TIME, LocalDateTime.class); 56 | Method setUpdateUser = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_USER, Long.class); 57 | setCreateTime.invoke(entity, now); 58 | setUpdateTime.invoke(entity, now); 59 | setCreateUser.invoke(entity, currentId); 60 | setUpdateUser.invoke(entity, currentId); 61 | } catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | 65 | 66 | } else if (value == OperationType.UPDATE) { 67 | try { 68 | Method setUpdateTime = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_TIME, LocalDateTime.class); 69 | Method setUpdateUser = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_USER, Long.class); 70 | setUpdateTime.invoke(entity, now); 71 | setUpdateUser.invoke(entity, currentId); 72 | } catch (Exception e) { 73 | throw new RuntimeException(e); 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /sky-server/src/main/resources/mapper/DishMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user, status) 7 | values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser}, #{status}) 8 | 9 | 10 | delete from dish where id in 11 | 12 | #{id} 13 | 14 | 15 | 16 | 25 | 26 | 32 | 33 | 34 | 49 | 50 | 51 | 52 | update dish 53 | 54 | name=#{name}, 55 | category_id=#{categoryId}, 56 | price=#{price}, 57 | image=#{image}, 58 | description=#{description}, 59 | status=#{status}, 60 | update_time=#{updateTime}, 61 | update_user=#{updateUser}, 62 | 63 | where id=#{id} 64 | 65 | 66 | 77 | 78 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/admin/ReportController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.admin; 2 | 3 | import com.sky.result.Result; 4 | import com.sky.service.ReportService; 5 | import com.sky.vo.OrderReportVO; 6 | import com.sky.vo.SalesTop10ReportVO; 7 | import com.sky.vo.TurnoverReportVO; 8 | import com.sky.vo.UserReportVO; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiOperation; 11 | import java.time.LocalDate; 12 | import javax.servlet.http.HttpServletResponse; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.format.annotation.DateTimeFormat; 15 | import org.springframework.web.bind.annotation.GetMapping; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | /** 20 | * 功能简述 21 | * 22 | * @author hssy 23 | * @version 1.0 24 | */ 25 | 26 | @RestController 27 | @RequestMapping("/admin/report") 28 | @Api(tags = "数据统计相关接口") 29 | public class ReportController { 30 | 31 | @Autowired 32 | private ReportService reportService; 33 | 34 | /** 35 | * 营业额统计 36 | * @param begin 37 | * @param end 38 | * @return 39 | */ 40 | @GetMapping("/turnoverStatistics") 41 | @ApiOperation("返回统计数据") 42 | public Result turnoverStatistics( 43 | @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, 44 | @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){ 45 | return Result.success(reportService.getTurnoverStatistics(begin, end)); 46 | } 47 | 48 | /** 49 | * 用户量统计 50 | * @param begin 51 | * @param end 52 | * @return 53 | */ 54 | @GetMapping("/userStatistics") 55 | @ApiOperation("统计用户数据") 56 | public Result userStatistics( 57 | @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, 58 | @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){ 59 | return Result.success(reportService.getUserStatistics(begin,end)); 60 | } 61 | 62 | /** 63 | * 订单量统计 64 | * @param begin 65 | * @param end 66 | * @return 67 | */ 68 | @GetMapping("/ordersStatistics") 69 | @ApiOperation("统计用户数据") 70 | public Result orderStatistics( 71 | @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, 72 | @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){ 73 | return Result.success(reportService.getOrderStatistics(begin,end)); 74 | } 75 | 76 | /** 77 | * 统计销量前10数据 78 | * @param begin 79 | * @param end 80 | * @return 81 | */ 82 | @GetMapping("/top10") 83 | @ApiOperation("统计销量前10数据") 84 | public Result topTenStatistics( 85 | @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, 86 | @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){ 87 | return Result.success(reportService.getTopTenStatistics(begin,end)); 88 | } 89 | 90 | /** 91 | * 导出近三十天运营数据 92 | */ 93 | @GetMapping("/export") 94 | @ApiOperation("导出数据") 95 | public void export(HttpServletResponse response){ 96 | reportService.exportBusinessData(response); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/user/AddressBookController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.user; 2 | 3 | import com.sky.context.BaseContext; 4 | import com.sky.entity.AddressBook; 5 | import com.sky.result.Result; 6 | import com.sky.service.AddressBookService; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.*; 11 | import java.util.List; 12 | 13 | @RestController 14 | @RequestMapping("/user/addressBook") 15 | @Api(tags = "C端地址簿接口") 16 | public class AddressBookController { 17 | 18 | @Autowired 19 | private AddressBookService addressBookService; 20 | 21 | /** 22 | * 查询当前登录用户的所有地址信息 23 | * 24 | * @return 25 | */ 26 | @GetMapping("/list") 27 | @ApiOperation("查询当前登录用户的所有地址信息") 28 | public Result> list() { 29 | AddressBook addressBook = new AddressBook(); 30 | addressBook.setUserId(BaseContext.getCurrentId()); 31 | List list = addressBookService.list(addressBook); 32 | return Result.success(list); 33 | } 34 | 35 | /** 36 | * 新增地址 37 | * 38 | * @param addressBook 39 | * @return 40 | */ 41 | @PostMapping 42 | @ApiOperation("新增地址") 43 | public Result save(@RequestBody AddressBook addressBook) { 44 | addressBookService.save(addressBook); 45 | return Result.success(); 46 | } 47 | 48 | @GetMapping("/{id}") 49 | @ApiOperation("根据id查询地址") 50 | public Result getById(@PathVariable Long id) { 51 | AddressBook addressBook = addressBookService.getById(id); 52 | return Result.success(addressBook); 53 | } 54 | 55 | /** 56 | * 根据id修改地址 57 | * 58 | * @param addressBook 59 | * @return 60 | */ 61 | @PutMapping 62 | @ApiOperation("根据id修改地址") 63 | public Result update(@RequestBody AddressBook addressBook) { 64 | addressBookService.update(addressBook); 65 | return Result.success(); 66 | } 67 | 68 | /** 69 | * 设置默认地址 70 | * 71 | * @param addressBook 72 | * @return 73 | */ 74 | @PutMapping("/default") 75 | @ApiOperation("设置默认地址") 76 | public Result setDefault(@RequestBody AddressBook addressBook) { 77 | addressBookService.setDefault(addressBook); 78 | return Result.success(); 79 | } 80 | 81 | /** 82 | * 根据id删除地址 83 | * 84 | * @param id 85 | * @return 86 | */ 87 | @DeleteMapping 88 | @ApiOperation("根据id删除地址") 89 | public Result deleteById(Long id) { 90 | addressBookService.deleteById(id); 91 | return Result.success(); 92 | } 93 | 94 | /** 95 | * 查询默认地址 96 | */ 97 | @GetMapping("default") 98 | @ApiOperation("查询默认地址") 99 | public Result getDefault() { 100 | //SQL:select * from address_book where user_id = ? and is_default = 1 101 | AddressBook addressBook = new AddressBook(); 102 | addressBook.setIsDefault(1); 103 | addressBook.setUserId(BaseContext.getCurrentId()); 104 | List list = addressBookService.list(addressBook); 105 | 106 | if (list != null && list.size() == 1) { 107 | return Result.success(list.get(0)); 108 | } 109 | 110 | return Result.error("没有查询到默认地址"); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/user/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.user; 2 | 3 | import com.sky.dto.OrdersPaymentDTO; 4 | import com.sky.dto.OrdersSubmitDTO; 5 | import com.sky.result.PageResult; 6 | import com.sky.result.Result; 7 | import com.sky.service.OrderService; 8 | import com.sky.vo.OrderPaymentVO; 9 | import com.sky.vo.OrderSubmitVO; 10 | import com.sky.vo.OrderVO; 11 | import io.swagger.annotations.Api; 12 | import io.swagger.annotations.ApiOperation; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.PostMapping; 17 | import org.springframework.web.bind.annotation.PutMapping; 18 | import org.springframework.web.bind.annotation.RequestBody; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RestController; 21 | 22 | /** 23 | * 功能简述 24 | * 25 | * @author hssy 26 | * @version 1.0 27 | */ 28 | @RestController("UserOrderController") 29 | @RequestMapping("/user/order") 30 | @Api(tags = "B端用户订单接口") 31 | public class OrderController { 32 | 33 | @Autowired 34 | private OrderService orderService; 35 | 36 | @PostMapping("/submit") 37 | public Result submit(@RequestBody OrdersSubmitDTO submitDTO){ 38 | return Result.success(orderService.submit(submitDTO)); 39 | } 40 | 41 | /** 42 | * 订单支付 43 | * 44 | * @param ordersPaymentDTO 45 | * @return 46 | */ 47 | @PutMapping("/payment") 48 | @ApiOperation("订单支付") 49 | public Result payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception { 50 | 51 | //订单支付 52 | OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO); 53 | //生成预交易订单 54 | return Result.success(orderPaymentVO); 55 | } 56 | 57 | /** 58 | * 历史订单查询 59 | * 60 | * @param page 61 | * @param pageSize 62 | * @param status 订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消 63 | * @return 64 | */ 65 | @GetMapping("/historyOrders") 66 | @ApiOperation("历史订单查询") 67 | public Result page(int page, int pageSize, Integer status) { 68 | PageResult pageResult = orderService.pageQuery4User(page, pageSize, status); 69 | return Result.success(pageResult); 70 | } 71 | 72 | /** 73 | * 查询订单详情 74 | * 75 | * @param id 76 | * @return 77 | */ 78 | @GetMapping("/orderDetail/{id}") 79 | @ApiOperation("查询订单详情") 80 | public Result details(@PathVariable("id") Long id) { 81 | OrderVO orderVO = orderService.details(id); 82 | return Result.success(orderVO); 83 | } 84 | 85 | /** 86 | * 用户取消订单 87 | * 88 | * @return 89 | */ 90 | @PutMapping("/cancel/{id}") 91 | @ApiOperation("取消订单") 92 | public Result cancel(@PathVariable("id") Long id) throws Exception { 93 | orderService.userCancelById(id); 94 | return Result.success(); 95 | } 96 | 97 | /** 98 | * 再来一单 99 | * 100 | * @param id 101 | * @return 102 | */ 103 | @PostMapping("/repetition/{id}") 104 | @ApiOperation("再来一单") 105 | public Result repetition(@PathVariable Long id) { 106 | orderService.repetition(id); 107 | return Result.success(); 108 | } 109 | 110 | @GetMapping("/reminder/{id}") 111 | @ApiOperation("用户催单") 112 | public Result reminder(@PathVariable Long id){ 113 | orderService.reminder(id); 114 | return Result.success(); 115 | } 116 | 117 | 118 | } 119 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/admin/SetmealController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.admin; 2 | 3 | import com.sky.dto.SetmealDTO; 4 | import com.sky.dto.SetmealPageQueryDTO; 5 | import com.sky.result.PageResult; 6 | import com.sky.result.Result; 7 | import com.sky.service.SetmealService; 8 | import com.sky.vo.SetmealVO; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiOperation; 11 | import java.util.List; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.cache.annotation.CacheEvict; 15 | import org.springframework.web.bind.annotation.DeleteMapping; 16 | import org.springframework.web.bind.annotation.GetMapping; 17 | import org.springframework.web.bind.annotation.PathVariable; 18 | import org.springframework.web.bind.annotation.PostMapping; 19 | import org.springframework.web.bind.annotation.PutMapping; 20 | import org.springframework.web.bind.annotation.RequestBody; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.RequestParam; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | 26 | /** 27 | * 套餐管理 28 | */ 29 | @RestController 30 | @RequestMapping("/admin/setmeal") 31 | @Api(tags = "套餐相关接口") 32 | @Slf4j 33 | public class SetmealController { 34 | 35 | @Autowired 36 | private SetmealService setmealService; 37 | 38 | /** 39 | * 新增套餐 40 | * 41 | * @param setmealDTO 42 | * @return 43 | */ 44 | @PostMapping 45 | @ApiOperation("新增套餐") 46 | @CacheEvict(cacheNames = "setMealCache",key = "#setmealDTO.categoryId") 47 | public Result save(@RequestBody SetmealDTO setmealDTO) { 48 | setmealService.saveWithDish(setmealDTO); 49 | return Result.success(); 50 | } 51 | 52 | /** 53 | * 分页查询 54 | * @param setmealPageQueryDTO 55 | * @return 56 | */ 57 | @GetMapping("/page") 58 | @ApiOperation("分页查询") 59 | public Result page(SetmealPageQueryDTO setmealPageQueryDTO) { 60 | PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO); 61 | return Result.success(pageResult); 62 | } 63 | 64 | /** 65 | * 批量删除套餐 66 | * @param ids 67 | * @return 68 | */ 69 | @DeleteMapping 70 | @ApiOperation("批量删除套餐") 71 | @CacheEvict(cacheNames = "setMealCache",allEntries = true) 72 | public Result delete(@RequestParam List ids){ 73 | setmealService.deleteBatch(ids); 74 | return Result.success(); 75 | } 76 | 77 | /** 78 | * 根据id查询套餐,用于修改页面回显数据 79 | * 80 | * @param id 81 | * @return 82 | */ 83 | @GetMapping("/{id}") 84 | @ApiOperation("根据id查询套餐") 85 | public Result getById(@PathVariable Long id) { 86 | SetmealVO setmealVO = setmealService.getByIdWithDish(id); 87 | return Result.success(setmealVO); 88 | } 89 | 90 | /** 91 | * 修改套餐 92 | * 93 | * @param setmealDTO 94 | * @return 95 | */ 96 | @PutMapping 97 | @ApiOperation("修改套餐") 98 | @CacheEvict(cacheNames = "setMealCache",allEntries = true) 99 | public Result update(@RequestBody SetmealDTO setmealDTO) { 100 | setmealService.update(setmealDTO); 101 | return Result.success(); 102 | } 103 | 104 | /** 105 | * 套餐起售停售 106 | * @param status 107 | * @param id 108 | * @return 109 | */ 110 | @PostMapping("/status/{status}") 111 | @ApiOperation("套餐起售停售") 112 | @CacheEvict(cacheNames = "setMealCache",allEntries = true) 113 | public Result startOrStop(@PathVariable Integer status, Long id) { 114 | setmealService.startOrStop(status, id); 115 | return Result.success(); 116 | } 117 | } 118 | 119 | 120 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/admin/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.admin; 2 | 3 | import com.sky.dto.OrdersCancelDTO; 4 | import com.sky.dto.OrdersConfirmDTO; 5 | import com.sky.dto.OrdersPageQueryDTO; 6 | import com.sky.dto.OrdersRejectionDTO; 7 | import com.sky.result.PageResult; 8 | import com.sky.result.Result; 9 | import com.sky.service.OrderService; 10 | import com.sky.vo.OrderStatisticsVO; 11 | import com.sky.vo.OrderVO; 12 | import io.swagger.annotations.Api; 13 | import io.swagger.annotations.ApiOperation; 14 | import lombok.extern.slf4j.Slf4j; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.web.bind.annotation.GetMapping; 17 | import org.springframework.web.bind.annotation.PathVariable; 18 | import org.springframework.web.bind.annotation.PutMapping; 19 | import org.springframework.web.bind.annotation.RequestBody; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RestController; 22 | 23 | /** 24 | * 订单管理 25 | */ 26 | @RestController("adminOrderController") 27 | @RequestMapping("/admin/order") 28 | @Slf4j 29 | @Api(tags = "订单管理接口") 30 | public class OrderController { 31 | 32 | @Autowired 33 | private OrderService orderService; 34 | 35 | /** 36 | * 订单搜索 37 | * 38 | * @param ordersPageQueryDTO 39 | * @return 40 | */ 41 | @GetMapping("/conditionSearch") 42 | @ApiOperation("订单搜索") 43 | public Result conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) { 44 | PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO); 45 | return Result.success(pageResult); 46 | } 47 | 48 | /** 49 | * 各个状态的订单数量统计 50 | * 51 | * @return 52 | */ 53 | @GetMapping("/statistics") 54 | @ApiOperation("各个状态的订单数量统计") 55 | public Result statistics() { 56 | OrderStatisticsVO orderStatisticsVO = orderService.statistics(); 57 | return Result.success(orderStatisticsVO); 58 | } 59 | 60 | /** 61 | * 订单详情 62 | * 63 | * @param id 64 | * @return 65 | */ 66 | @GetMapping("/details/{id}") 67 | @ApiOperation("查询订单详情") 68 | public Result details(@PathVariable("id") Long id) { 69 | OrderVO orderVO = orderService.details(id); 70 | return Result.success(orderVO); 71 | } 72 | 73 | /** 74 | * 接单 75 | * 76 | * @return 77 | */ 78 | @PutMapping("/confirm") 79 | @ApiOperation("接单") 80 | public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) { 81 | orderService.confirm(ordersConfirmDTO); 82 | return Result.success(); 83 | } 84 | 85 | /** 86 | * 拒单 87 | * 88 | * @return 89 | */ 90 | @PutMapping("/rejection") 91 | @ApiOperation("拒单") 92 | public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception { 93 | orderService.rejection(ordersRejectionDTO); 94 | return Result.success(); 95 | } 96 | 97 | /** 98 | * 取消订单 99 | * 100 | * @return 101 | */ 102 | @PutMapping("/cancel") 103 | @ApiOperation("取消订单") 104 | public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception { 105 | orderService.cancel(ordersCancelDTO); 106 | return Result.success(); 107 | } 108 | 109 | /** 110 | * 派送订单 111 | * 112 | * @return 113 | */ 114 | @PutMapping("/delivery/{id}") 115 | @ApiOperation("派送订单") 116 | public Result delivery(@PathVariable("id") Long id) { 117 | orderService.delivery(id); 118 | return Result.success(); 119 | } 120 | 121 | /** 122 | * 完成订单 123 | * 124 | * @return 125 | */ 126 | @PutMapping("/complete/{id}") 127 | @ApiOperation("完成订单") 128 | public Result complete(@PathVariable("id") Long id) { 129 | orderService.complete(id); 130 | return Result.success(); 131 | } 132 | } -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/admin/DishController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.admin; 2 | 3 | import com.sky.dto.DishDTO; 4 | import com.sky.dto.DishPageQueryDTO; 5 | import com.sky.entity.Dish; 6 | import com.sky.result.PageResult; 7 | import com.sky.result.Result; 8 | import com.sky.service.DishService; 9 | import com.sky.vo.DishVO; 10 | import io.swagger.annotations.Api; 11 | import io.swagger.annotations.ApiOperation; 12 | import java.util.List; 13 | import java.util.Set; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.data.redis.core.RedisTemplate; 16 | import org.springframework.web.bind.annotation.DeleteMapping; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import org.springframework.web.bind.annotation.PutMapping; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.RequestParam; 24 | import org.springframework.web.bind.annotation.RestController; 25 | 26 | /** 27 | * 功能简述 菜品相关接口 28 | * 29 | * @author hssy 30 | * @version 1.0 31 | */ 32 | 33 | 34 | @RestController 35 | @RequestMapping("/admin/dish") 36 | @Api(tags = "菜品管理") 37 | public class DishController { 38 | 39 | @Autowired 40 | private DishService dishService; 41 | 42 | @Autowired 43 | private RedisTemplate redisTemplate; 44 | 45 | /** 46 | * 菜品上传 47 | */ 48 | @PostMapping 49 | @ApiOperation("菜品上传") 50 | public Result save(@RequestBody DishDTO dishDTO) { 51 | 52 | dishService.saveWithFlavor(dishDTO); 53 | //更新缓存 54 | cleanCache("dish_" + dishDTO.getCategoryId()); 55 | 56 | return Result.success(); 57 | } 58 | 59 | /** 60 | * 菜品分页查询 61 | * 62 | * @param dto 63 | * @return 64 | */ 65 | @GetMapping("/page") 66 | @ApiOperation("菜品分页查询") 67 | public Result page(DishPageQueryDTO dto) { 68 | PageResult pageResult = dishService.pageQuery(dto); 69 | return Result.success(pageResult); 70 | } 71 | 72 | @PostMapping("/status/{status}") 73 | @ApiOperation("启用或禁用菜品") 74 | public Result startOrStop(@PathVariable("status") Integer status, Long id) { 75 | dishService.startOrStop(status, id); 76 | 77 | cleanCache("dish_*"); 78 | 79 | return Result.success(); 80 | 81 | } 82 | 83 | 84 | @ApiOperation("批量删除菜品") 85 | @DeleteMapping 86 | public Result delete(@RequestParam List ids) { 87 | dishService.deleteBatch(ids); 88 | 89 | //更新缓存 90 | cleanCache("dish_*"); 91 | 92 | return Result.success(); 93 | } 94 | 95 | @ApiOperation("根据id查询菜品") 96 | @GetMapping("/{id}") 97 | public Result getById(@PathVariable Long id) { 98 | DishVO dishVO = dishService.getByIdWithFlavor(id); 99 | return Result.success(dishVO); 100 | } 101 | 102 | @ApiOperation("修改菜品") 103 | @PutMapping 104 | public Result update(@RequestBody DishDTO dishDTO) { 105 | dishService.updateWithFlavor(dishDTO); 106 | 107 | //更新缓存 108 | // Set keys = redisTemplate.keys("dish_*"); 109 | // redisTemplate.delete(keys); 110 | cleanCache("dish_*"); 111 | 112 | return Result.success(); 113 | } 114 | 115 | 116 | /** 117 | * 根据分类id查询菜品 118 | * 119 | * @param categoryId 120 | * @return 121 | */ 122 | @GetMapping("/list") 123 | @ApiOperation("根据分类id查询菜品") 124 | public Result> list(Long categoryId) { 125 | List list = dishService.list(categoryId); 126 | return Result.success(list); 127 | } 128 | 129 | /** 130 | * 清流redis缓存 131 | * 132 | * @param pattern 133 | */ 134 | private void cleanCache(String pattern) { 135 | Set keys = redisTemplate.keys(pattern); 136 | redisTemplate.delete(keys); 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/admin/EmployeeController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.admin; 2 | 3 | import com.sky.constant.JwtClaimsConstant; 4 | import com.sky.dto.EmployeeDTO; 5 | import com.sky.dto.EmployeeLoginDTO; 6 | import com.sky.dto.EmployeePageQueryDTO; 7 | import com.sky.entity.Employee; 8 | import com.sky.properties.JwtProperties; 9 | import com.sky.result.PageResult; 10 | import com.sky.result.Result; 11 | import com.sky.service.EmployeeService; 12 | import com.sky.utils.JwtUtil; 13 | import com.sky.vo.EmployeeLoginVO; 14 | import io.swagger.annotations.ApiOperation; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | import lombok.extern.slf4j.Slf4j; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.web.bind.annotation.GetMapping; 20 | import org.springframework.web.bind.annotation.PathVariable; 21 | import org.springframework.web.bind.annotation.PostMapping; 22 | import org.springframework.web.bind.annotation.PutMapping; 23 | import org.springframework.web.bind.annotation.RequestBody; 24 | import org.springframework.web.bind.annotation.RequestMapping; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | /** 28 | * 员工管理 29 | */ 30 | @RestController 31 | @RequestMapping("/admin/employee") 32 | @Slf4j 33 | public class EmployeeController { 34 | 35 | @Autowired 36 | private EmployeeService employeeService; 37 | @Autowired 38 | private JwtProperties jwtProperties; 39 | 40 | /** 41 | * 登录 42 | * 43 | * @param employeeLoginDTO 44 | * @return 45 | */ 46 | @PostMapping("/login") 47 | @ApiOperation("员工登录") 48 | public Result login(@RequestBody EmployeeLoginDTO employeeLoginDTO) { 49 | log.info("员工登录:{}", employeeLoginDTO); 50 | 51 | Employee employee = employeeService.login(employeeLoginDTO); 52 | 53 | //登录成功后,生成jwt令牌 54 | Map claims = new HashMap<>(); 55 | claims.put(JwtClaimsConstant.EMP_ID, employee.getId()); 56 | String token = JwtUtil.createJWT( 57 | jwtProperties.getAdminSecretKey(), 58 | jwtProperties.getAdminTtl(), 59 | claims); 60 | 61 | EmployeeLoginVO employeeLoginVO = EmployeeLoginVO.builder() 62 | .id(employee.getId()) 63 | .userName(employee.getUsername()) 64 | .name(employee.getName()) 65 | .token(token) 66 | .build(); 67 | 68 | return Result.success(employeeLoginVO); 69 | } 70 | 71 | /** 72 | * 退出 73 | * 74 | * @return 75 | */ 76 | @PostMapping("/logout") 77 | @ApiOperation("员工登出") 78 | public Result logout() { 79 | return Result.success(); 80 | } 81 | 82 | @PostMapping 83 | @ApiOperation("添加员工") 84 | public Result save(@RequestBody EmployeeDTO employeeDTO) { 85 | log.info("新增员工{}", employeeDTO); 86 | employeeService.save(employeeDTO); 87 | return Result.success(); 88 | } 89 | 90 | @GetMapping("/page") 91 | @ApiOperation("员工分页查询") 92 | public Result page(EmployeePageQueryDTO employeePageQueryDTO) { 93 | PageResult pageResult = employeeService.pageQuery(employeePageQueryDTO); 94 | return Result.success(pageResult); 95 | } 96 | 97 | @PostMapping("/status/{status}") 98 | @ApiOperation("员工状态启用禁用") 99 | public Result startOrStop(@PathVariable("status") Integer status, Long id) { 100 | employeeService.startOrStop(status, id); 101 | return Result.success(); 102 | } 103 | 104 | 105 | @GetMapping("{id}") 106 | @ApiOperation("查询员工") 107 | public Result getById(@PathVariable Long id) { 108 | Employee employee = employeeService.getById(id); 109 | return Result.success(employee); 110 | } 111 | 112 | /** 113 | * 编员工信息 114 | * 115 | * @param employeeDTO 116 | * @return 117 | */ 118 | @PutMapping 119 | @ApiOperation("编辑员工信息") 120 | public Result update(@RequestBody EmployeeDTO employeeDTO) { 121 | employeeService.update(employeeDTO); 122 | return Result.success(); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/controller/notify/PayNotifyController.java: -------------------------------------------------------------------------------- 1 | package com.sky.controller.notify; 2 | 3 | import com.alibaba.druid.support.json.JSONUtils; 4 | import com.alibaba.fastjson.JSON; 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.sky.properties.WeChatProperties; 7 | import com.sky.service.OrderService; 8 | import com.wechat.pay.contrib.apache.httpclient.util.AesUtil; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.apache.http.entity.ContentType; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | import java.io.BufferedReader; 17 | import java.nio.charset.StandardCharsets; 18 | import java.util.HashMap; 19 | 20 | /** 21 | * 支付回调相关接口 22 | */ 23 | @RestController 24 | @RequestMapping("/notify") 25 | @Slf4j 26 | public class PayNotifyController { 27 | @Autowired 28 | private OrderService orderService; 29 | @Autowired 30 | private WeChatProperties weChatProperties; 31 | 32 | /** 33 | * 支付成功回调 34 | * 35 | * @param request 36 | */ 37 | @RequestMapping("/paySuccess") 38 | public void paySuccessNotify(HttpServletRequest request, HttpServletResponse response) throws Exception { 39 | //读取数据 40 | String body = readData(request); 41 | log.info("支付成功回调:{}", body); 42 | 43 | //数据解密 44 | String plainText = decryptData(body); 45 | log.info("解密后的文本:{}", plainText); 46 | 47 | JSONObject jsonObject = JSON.parseObject(plainText); 48 | String outTradeNo = jsonObject.getString("out_trade_no");//商户平台订单号 49 | String transactionId = jsonObject.getString("transaction_id");//微信支付交易号 50 | 51 | log.info("商户平台订单号:{}", outTradeNo); 52 | log.info("微信支付交易号:{}", transactionId); 53 | 54 | //业务处理,修改订单状态、来单提醒 55 | orderService.paySuccess(outTradeNo); 56 | 57 | //给微信响应 58 | responseToWeixin(response); 59 | } 60 | 61 | /** 62 | * 读取数据 63 | * 64 | * @param request 65 | * @return 66 | * @throws Exception 67 | */ 68 | private String readData(HttpServletRequest request) throws Exception { 69 | BufferedReader reader = request.getReader(); 70 | StringBuilder result = new StringBuilder(); 71 | String line = null; 72 | while ((line = reader.readLine()) != null) { 73 | if (result.length() > 0) { 74 | result.append("\n"); 75 | } 76 | result.append(line); 77 | } 78 | return result.toString(); 79 | } 80 | 81 | /** 82 | * 数据解密 83 | * 84 | * @param body 85 | * @return 86 | * @throws Exception 87 | */ 88 | private String decryptData(String body) throws Exception { 89 | JSONObject resultObject = JSON.parseObject(body); 90 | JSONObject resource = resultObject.getJSONObject("resource"); 91 | String ciphertext = resource.getString("ciphertext"); 92 | String nonce = resource.getString("nonce"); 93 | String associatedData = resource.getString("associated_data"); 94 | 95 | AesUtil aesUtil = new AesUtil(weChatProperties.getApiV3Key().getBytes(StandardCharsets.UTF_8)); 96 | //密文解密 97 | String plainText = aesUtil.decryptToString(associatedData.getBytes(StandardCharsets.UTF_8), 98 | nonce.getBytes(StandardCharsets.UTF_8), 99 | ciphertext); 100 | 101 | return plainText; 102 | } 103 | 104 | /** 105 | * 给微信响应 106 | * @param response 107 | */ 108 | private void responseToWeixin(HttpServletResponse response) throws Exception{ 109 | response.setStatus(200); 110 | HashMap map = new HashMap<>(); 111 | map.put("code", "SUCCESS"); 112 | map.put("message", "SUCCESS"); 113 | response.setHeader("Content-type", ContentType.APPLICATION_JSON.toString()); 114 | response.getOutputStream().write(JSONUtils.toJSONString(map).getBytes(StandardCharsets.UTF_8)); 115 | response.flushBuffer(); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/impl/ShoppingCartServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.sky.service.impl; 2 | 3 | import com.sky.context.BaseContext; 4 | import com.sky.dto.ShoppingCartDTO; 5 | import com.sky.entity.Dish; 6 | import com.sky.entity.Setmeal; 7 | import com.sky.entity.ShoppingCart; 8 | import com.sky.mapper.DishMapper; 9 | import com.sky.mapper.SetmealMapper; 10 | import com.sky.mapper.ShoppingCartMapper; 11 | import com.sky.service.ShoppingCartService; 12 | import java.time.LocalDateTime; 13 | import java.util.List; 14 | import org.springframework.beans.BeanUtils; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.stereotype.Service; 17 | 18 | /** 19 | * 功能简述 20 | * 21 | * @author hssy 22 | * @version 1.0 23 | */ 24 | @Service 25 | public class ShoppingCartServiceImpl implements ShoppingCartService { 26 | 27 | @Autowired 28 | private ShoppingCartMapper shoppingCartMapper; 29 | 30 | @Autowired 31 | private DishMapper dishMapper; 32 | 33 | @Autowired 34 | private SetmealMapper setmealMapper; 35 | 36 | 37 | @Override 38 | public void add(ShoppingCartDTO shoppingCartDTO) { 39 | ShoppingCart shoppingCart = new ShoppingCart(); 40 | BeanUtils.copyProperties(shoppingCartDTO, shoppingCart); 41 | Long currentId = BaseContext.getCurrentId(); 42 | shoppingCart.setUserId(currentId); 43 | //先查询购物车中是否存在 44 | List list = shoppingCartMapper.list(shoppingCart); 45 | //存在则更新数据的数量 46 | if (list != null && list.size() > 0) { 47 | ShoppingCart cart = list.get(0); 48 | cart.setNumber(cart.getNumber() + 1); 49 | shoppingCartMapper.updateNumberById(cart); 50 | } 51 | //不存在则添加数据 52 | else { 53 | Long dishId = shoppingCart.getDishId(); 54 | Long setmealId = shoppingCart.getSetmealId(); 55 | if (dishId != null) { 56 | Dish dish = dishMapper.getById(dishId); 57 | shoppingCart.setName(dish.getName()); 58 | shoppingCart.setAmount(dish.getPrice()); 59 | shoppingCart.setImage(dish.getImage()); 60 | } else if (setmealId != null) { 61 | Setmeal setmeal = setmealMapper.getById(setmealId); 62 | shoppingCart.setImage(setmeal.getImage()); 63 | shoppingCart.setAmount(setmeal.getPrice()); 64 | shoppingCart.setName(setmeal.getName()); 65 | } 66 | shoppingCart.setNumber(1); 67 | shoppingCart.setCreateTime(LocalDateTime.now()); 68 | shoppingCartMapper.insert(shoppingCart); 69 | } 70 | } 71 | 72 | @Override 73 | public List list() { 74 | Long currentId = BaseContext.getCurrentId(); 75 | ShoppingCart shoppingCart = ShoppingCart 76 | .builder() 77 | .userId(currentId) 78 | .build(); 79 | return shoppingCartMapper.list(shoppingCart); 80 | } 81 | 82 | @Override 83 | public void clean() { 84 | Long currentId = BaseContext.getCurrentId(); 85 | shoppingCartMapper.deleteByUserId(currentId); 86 | } 87 | 88 | 89 | /** 90 | * 删除购物车中一个商品 91 | * 92 | * @param shoppingCartDTO 93 | */ 94 | @Override 95 | public void subShoppingCart(ShoppingCartDTO shoppingCartDTO) { 96 | ShoppingCart shoppingCart = new ShoppingCart(); 97 | BeanUtils.copyProperties(shoppingCartDTO, shoppingCart); 98 | //设置查询条件,查询当前登录用户的购物车数据 99 | shoppingCart.setUserId(BaseContext.getCurrentId()); 100 | 101 | List list = shoppingCartMapper.list(shoppingCart); 102 | 103 | if (list != null && list.size() > 0) { 104 | shoppingCart = list.get(0); 105 | 106 | Integer number = shoppingCart.getNumber(); 107 | if (number == 1) { 108 | //当前商品在购物车中的份数为1,直接删除当前记录 109 | shoppingCartMapper.deleteById(shoppingCart.getId()); 110 | } else { 111 | //当前商品在购物车中的份数不为1,修改份数即可 112 | shoppingCart.setNumber(shoppingCart.getNumber() - 1); 113 | shoppingCartMapper.updateNumberById(shoppingCart); 114 | } 115 | } 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/impl/CategoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.sky.service.impl; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.github.pagehelper.PageHelper; 5 | import com.sky.constant.MessageConstant; 6 | import com.sky.constant.StatusConstant; 7 | import com.sky.context.BaseContext; 8 | import com.sky.dto.CategoryDTO; 9 | import com.sky.dto.CategoryPageQueryDTO; 10 | import com.sky.entity.Category; 11 | import com.sky.exception.DeletionNotAllowedException; 12 | import com.sky.mapper.CategoryMapper; 13 | import com.sky.mapper.DishMapper; 14 | import com.sky.mapper.SetmealMapper; 15 | import com.sky.result.PageResult; 16 | import com.sky.service.CategoryService; 17 | import lombok.extern.slf4j.Slf4j; 18 | import org.springframework.beans.BeanUtils; 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.stereotype.Service; 21 | import java.time.LocalDateTime; 22 | import java.util.List; 23 | 24 | /** 25 | * 分类业务层 26 | */ 27 | @Service 28 | @Slf4j 29 | public class CategoryServiceImpl implements CategoryService { 30 | 31 | @Autowired 32 | private CategoryMapper categoryMapper; 33 | @Autowired 34 | private DishMapper dishMapper; 35 | @Autowired 36 | private SetmealMapper setmealMapper; 37 | 38 | /** 39 | * 新增分类 40 | * @param categoryDTO 41 | */ 42 | public void save(CategoryDTO categoryDTO) { 43 | Category category = new Category(); 44 | //属性拷贝 45 | BeanUtils.copyProperties(categoryDTO, category); 46 | 47 | //分类状态默认为禁用状态0 48 | category.setStatus(StatusConstant.DISABLE); 49 | 50 | //设置创建时间、修改时间、创建人、修改人 51 | // category.setCreateTime(LocalDateTime.now()); 52 | // category.setUpdateTime(LocalDateTime.now()); 53 | // category.setCreateUser(BaseContext.getCurrentId()); 54 | // category.setUpdateUser(BaseContext.getCurrentId()); 55 | 56 | categoryMapper.insert(category); 57 | } 58 | 59 | /** 60 | * 分页查询 61 | * @param categoryPageQueryDTO 62 | * @return 63 | */ 64 | public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) { 65 | PageHelper.startPage(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize()); 66 | //下一条sql进行分页,自动加入limit关键字分页 67 | Page page = categoryMapper.pageQuery(categoryPageQueryDTO); 68 | return new PageResult(page.getTotal(), page.getResult()); 69 | } 70 | 71 | /** 72 | * 根据id删除分类 73 | * @param id 74 | */ 75 | public void deleteById(Long id) { 76 | //查询当前分类是否关联了菜品,如果关联了就抛出业务异常 77 | Integer count = dishMapper.countByCategoryId(id); 78 | if(count > 0){ 79 | //当前分类下有菜品,不能删除 80 | throw new DeletionNotAllowedException(MessageConstant.CATEGORY_BE_RELATED_BY_DISH); 81 | } 82 | 83 | //查询当前分类是否关联了套餐,如果关联了就抛出业务异常 84 | count = setmealMapper.countByCategoryId(id); 85 | if(count > 0){ 86 | //当前分类下有菜品,不能删除 87 | throw new DeletionNotAllowedException(MessageConstant.CATEGORY_BE_RELATED_BY_SETMEAL); 88 | } 89 | 90 | //删除分类数据 91 | categoryMapper.deleteById(id); 92 | } 93 | 94 | /** 95 | * 修改分类 96 | * @param categoryDTO 97 | */ 98 | public void update(CategoryDTO categoryDTO) { 99 | Category category = new Category(); 100 | BeanUtils.copyProperties(categoryDTO,category); 101 | 102 | //设置修改时间、修改人 103 | // category.setUpdateTime(LocalDateTime.now()); 104 | // category.setUpdateUser(BaseContext.getCurrentId()); 105 | 106 | categoryMapper.update(category); 107 | } 108 | 109 | /** 110 | * 启用、禁用分类 111 | * @param status 112 | * @param id 113 | */ 114 | public void startOrStop(Integer status, Long id) { 115 | Category category = Category.builder() 116 | .id(id) 117 | .status(status) 118 | // .updateTime(LocalDateTime.now()) 119 | // .updateUser(BaseContext.getCurrentId()) 120 | .build(); 121 | categoryMapper.update(category); 122 | } 123 | 124 | /** 125 | * 根据类型查询分类 126 | * @param type 127 | * @return 128 | */ 129 | public List list(Integer type) { 130 | return categoryMapper.list(type); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/config/WebMvcConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.sky.config; 2 | 3 | import com.sky.interceptor.JwtTokenAdminInterceptor; 4 | import com.sky.interceptor.JwtTokenUserInterceptor; 5 | import com.sky.json.JacksonObjectMapper; 6 | import java.util.List; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.http.converter.HttpMessageConverter; 12 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; 13 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 14 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 15 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 16 | import springfox.documentation.builders.ApiInfoBuilder; 17 | import springfox.documentation.builders.PathSelectors; 18 | import springfox.documentation.builders.RequestHandlerSelectors; 19 | import springfox.documentation.service.ApiInfo; 20 | import springfox.documentation.spi.DocumentationType; 21 | import springfox.documentation.spring.web.plugins.Docket; 22 | 23 | /** 24 | * 配置类,注册web层相关组件 25 | */ 26 | @Configuration 27 | @Slf4j 28 | public class WebMvcConfiguration extends WebMvcConfigurationSupport { 29 | 30 | @Autowired 31 | private JwtTokenAdminInterceptor jwtTokenAdminInterceptor; 32 | 33 | @Autowired 34 | private JwtTokenUserInterceptor jwtTokenUserInterceptor; 35 | 36 | /** 37 | * 注册自定义拦截器 38 | * 39 | * @param registry 40 | */ 41 | protected void addInterceptors(InterceptorRegistry registry) { 42 | log.info("开始注册自定义拦截器..."); 43 | registry.addInterceptor(jwtTokenAdminInterceptor) 44 | .addPathPatterns("/admin/**") 45 | .excludePathPatterns("/admin/employee/login"); 46 | 47 | registry.addInterceptor(jwtTokenUserInterceptor) 48 | .addPathPatterns("/user/**") 49 | .excludePathPatterns("/user/user/login") 50 | .excludePathPatterns("/user/shop/status"); 51 | } 52 | 53 | /** 54 | * 通过knife4j生成接口文档 55 | * 56 | * @return 57 | */ 58 | @Bean 59 | public Docket docketOne() { 60 | ApiInfo apiInfo = new ApiInfoBuilder() 61 | .title("苍穹外卖项目接口文档") 62 | .version("2.0") 63 | .description("苍穹外卖项目接口文档") 64 | .build(); 65 | Docket docket = new Docket(DocumentationType.SWAGGER_2) 66 | .groupName("管理端接口") 67 | .apiInfo(apiInfo) 68 | .select() 69 | .apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin")) 70 | .paths(PathSelectors.any()) 71 | .build(); 72 | return docket; 73 | } 74 | 75 | @Bean 76 | public Docket docketTwo() { 77 | ApiInfo apiInfo = new ApiInfoBuilder() 78 | .title("苍穹外卖项目接口文档") 79 | .version("2.0") 80 | .description("苍穹外卖项目接口文档") 81 | .build(); 82 | Docket docket = new Docket(DocumentationType.SWAGGER_2) 83 | .groupName("用户端接口") 84 | .apiInfo(apiInfo) 85 | .select() 86 | .apis(RequestHandlerSelectors.basePackage("com.sky.controller.user")) 87 | .paths(PathSelectors.any()) 88 | .build(); 89 | return docket; 90 | } 91 | 92 | /** 93 | * 设置静态资源映射 94 | * 95 | * @param registry 96 | */ 97 | protected void addResourceHandlers(ResourceHandlerRegistry registry) { 98 | registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/"); 99 | registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); 100 | } 101 | 102 | /** 103 | * 扩展springMVc的消息转换器 104 | */ 105 | @Override 106 | protected void extendMessageConverters(List> converters) { 107 | //创建一个消息转换器 108 | MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); 109 | //需要为消息转换器设置一个对象转换器,对象转换器可以将Java对象序列化为json数据 110 | converter.setObjectMapper(new JacksonObjectMapper()); 111 | //将自己的消息转化器加入容器中 112 | converters.add(0, converter); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /sky-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | sky-take-out 7 | com.sky 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | sky-server 12 | 13 | 14 | 15 | com.sky 16 | sky-common 17 | 1.0-SNAPSHOT 18 | 19 | 20 | 21 | com.sky 22 | sky-pojo 23 | 1.0-SNAPSHOT 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-web 40 | compile 41 | 42 | 43 | 44 | mysql 45 | mysql-connector-java 46 | runtime 47 | 48 | 49 | 50 | org.mybatis.spring.boot 51 | mybatis-spring-boot-starter 52 | 53 | 54 | 55 | org.projectlombok 56 | lombok 57 | 58 | 59 | 60 | com.alibaba 61 | fastjson 62 | 63 | 64 | 65 | com.alibaba 66 | druid-spring-boot-starter 67 | 68 | 69 | 70 | com.github.pagehelper 71 | pagehelper-spring-boot-starter 72 | 73 | 74 | 75 | org.aspectj 76 | aspectjrt 77 | 78 | 79 | 80 | org.aspectj 81 | aspectjweaver 82 | 83 | 84 | 85 | com.github.xiaoymin 86 | knife4j-spring-boot-starter 87 | 88 | 89 | 90 | org.springframework.boot 91 | spring-boot-starter-data-redis 92 | 93 | 94 | 95 | org.springframework.boot 96 | spring-boot-starter-cache 97 | 98 | 99 | 100 | org.springframework.boot 101 | spring-boot-starter-websocket 102 | 103 | 104 | 105 | javax.xml.bind 106 | jaxb-api 107 | 108 | 109 | 110 | 111 | org.apache.poi 112 | poi 113 | 114 | 115 | org.apache.poi 116 | poi-ooxml 117 | 118 | 119 | 120 | 121 | 122 | 123 | org.springframework.boot 124 | spring-boot-maven-plugin 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/impl/EmployeeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.sky.service.impl; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.github.pagehelper.PageHelper; 5 | import com.sky.constant.MessageConstant; 6 | import com.sky.constant.PasswordConstant; 7 | import com.sky.constant.StatusConstant; 8 | import com.sky.context.BaseContext; 9 | import com.sky.dto.EmployeeDTO; 10 | import com.sky.dto.EmployeeLoginDTO; 11 | import com.sky.dto.EmployeePageQueryDTO; 12 | import com.sky.entity.Employee; 13 | import com.sky.exception.AccountLockedException; 14 | import com.sky.exception.AccountNotFoundException; 15 | import com.sky.exception.PasswordErrorException; 16 | import com.sky.mapper.EmployeeMapper; 17 | import com.sky.result.PageResult; 18 | import com.sky.service.EmployeeService; 19 | import java.time.LocalDateTime; 20 | import java.util.List; 21 | import org.springframework.beans.BeanUtils; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.stereotype.Service; 24 | import org.springframework.util.DigestUtils; 25 | 26 | @Service 27 | public class EmployeeServiceImpl implements EmployeeService { 28 | 29 | @Autowired 30 | private EmployeeMapper employeeMapper; 31 | 32 | /** 33 | * 员工登录 34 | * 35 | * @param employeeLoginDTO 36 | * @return 37 | */ 38 | public Employee login(EmployeeLoginDTO employeeLoginDTO) { 39 | String username = employeeLoginDTO.getUsername(); 40 | String password = employeeLoginDTO.getPassword(); 41 | 42 | //1、根据用户名查询数据库中的数据 43 | Employee employee = employeeMapper.getByUsername(username); 44 | 45 | //2、处理各种异常情况(用户名不存在、密码不对、账号被锁定) 46 | if (employee == null) { 47 | //账号不存在 48 | throw new AccountNotFoundException(MessageConstant.ACCOUNT_NOT_FOUND); 49 | } 50 | 51 | //密码比对 52 | //md5加密后 53 | password = DigestUtils.md5DigestAsHex(password.getBytes()); 54 | 55 | if (!password.equals(employee.getPassword())) { 56 | //密码错误 57 | throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR); 58 | } 59 | 60 | if (employee.getStatus() == StatusConstant.DISABLE) { 61 | //账号被锁定 62 | throw new AccountLockedException(MessageConstant.ACCOUNT_LOCKED); 63 | } 64 | 65 | //3、返回实体对象 66 | return employee; 67 | } 68 | 69 | @Override 70 | public void save(EmployeeDTO employeeDTO) { 71 | Employee employee = new Employee(); 72 | //提交给数据库的最好是entity 73 | BeanUtils.copyProperties(employeeDTO, employee); 74 | 75 | //填充字段 76 | employee.setStatus(StatusConstant.ENABLE); 77 | employee.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes())); 78 | // employee.setCreateTime(LocalDateTime.now()); 79 | // employee.setUpdateTime(LocalDateTime.now()); 80 | 81 | //通过ThreadLocal获得当前用户的id 82 | // employee.setCreateUser(BaseContext.getCurrentId()); 83 | // employee.setUpdateUser(BaseContext.getCurrentId()); 84 | 85 | employeeMapper.insert(employee); 86 | } 87 | 88 | @Override 89 | public PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO) { 90 | PageHelper.startPage(employeePageQueryDTO.getPage(), employeePageQueryDTO.getPageSize()); 91 | Page page = employeeMapper.selectByPage(employeePageQueryDTO); 92 | long total = page.getTotal(); 93 | List result = page.getResult(); 94 | return new PageResult(total, result); 95 | } 96 | 97 | @Override 98 | public void startOrStop(Integer status, Long id) { 99 | Employee employee = 100 | Employee.builder() 101 | .id(id) 102 | .status(status) 103 | .build(); 104 | employeeMapper.update(employee); 105 | } 106 | 107 | @Override 108 | public Employee getById(Long id) { 109 | Employee employee = employeeMapper.getById(id); 110 | employee.setPassword("****"); 111 | return employee; 112 | } 113 | 114 | @Override 115 | public void update(EmployeeDTO employeeDTO) { 116 | Employee employee = new Employee(); 117 | BeanUtils.copyProperties(employeeDTO,employee); 118 | 119 | // employee.setUpdateTime(LocalDateTime.now()); 120 | // employee.setUpdateUser(BaseContext.getCurrentId()); 121 | 122 | employeeMapper.update(employee); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring-boot-starter-parent 8 | org.springframework.boot 9 | 2.7.3 10 | 11 | com.sky 12 | sky-take-out 13 | pom 14 | 1.0-SNAPSHOT 15 | 16 | sky-common 17 | sky-pojo 18 | sky-server 19 | 20 | 21 | 2.2.0 22 | 1.18.20 23 | 1.2.76 24 | 2.6 25 | 1.2.1 26 | 1.3.0 27 | 3.10.2 28 | 3.0.2 29 | 1.9.4 30 | 0.9.1 31 | 2.3.1 32 | 3.16 33 | 34 | 35 | 36 | 37 | org.mybatis.spring.boot 38 | mybatis-spring-boot-starter 39 | ${mybatis.spring} 40 | 41 | 42 | 43 | org.projectlombok 44 | lombok 45 | ${lombok} 46 | 47 | 48 | 49 | com.alibaba 50 | fastjson 51 | ${fastjson} 52 | 53 | 54 | 55 | commons-lang 56 | commons-lang 57 | ${commons.lang} 58 | 59 | 60 | 61 | com.alibaba 62 | druid-spring-boot-starter 63 | ${druid} 64 | 65 | 66 | 67 | com.github.pagehelper 68 | pagehelper-spring-boot-starter 69 | ${pagehelper} 70 | 71 | 72 | 73 | com.github.xiaoymin 74 | knife4j-spring-boot-starter 75 | ${knife4j} 76 | 77 | 78 | 79 | org.aspectj 80 | aspectjrt 81 | ${aspectj} 82 | 83 | 84 | 85 | org.aspectj 86 | aspectjweaver 87 | ${aspectj} 88 | 89 | 90 | 91 | io.jsonwebtoken 92 | jjwt 93 | ${jjwt} 94 | 95 | 96 | 97 | com.aliyun.oss 98 | aliyun-sdk-oss 99 | ${aliyun.sdk.oss} 100 | 101 | 102 | 103 | javax.xml.bind 104 | jaxb-api 105 | ${jaxb-api} 106 | 107 | 108 | 109 | 110 | org.apache.poi 111 | poi 112 | ${poi} 113 | 114 | 115 | org.apache.poi 116 | poi-ooxml 117 | ${poi} 118 | 119 | 120 | 121 | com.github.wechatpay-apiv3 122 | wechatpay-apache-httpclient 123 | 0.4.8 124 | 125 | 126 | 127 | commons-collections 128 | commons-collections 129 | 3.2.1 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /sky-server/src/main/java/com/sky/service/impl/WorkspaceServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.sky.service.impl; 2 | 3 | import com.sky.constant.StatusConstant; 4 | import com.sky.entity.Orders; 5 | import com.sky.mapper.DishMapper; 6 | import com.sky.mapper.OrderMapper; 7 | import com.sky.mapper.SetmealMapper; 8 | import com.sky.mapper.UserMapper; 9 | import com.sky.service.WorkspaceService; 10 | import com.sky.vo.BusinessDataVO; 11 | import com.sky.vo.DishOverViewVO; 12 | import com.sky.vo.OrderOverViewVO; 13 | import com.sky.vo.SetmealOverViewVO; 14 | import lombok.extern.slf4j.Slf4j; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.stereotype.Service; 17 | import java.time.LocalDateTime; 18 | import java.time.LocalTime; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | @Service 23 | @Slf4j 24 | public class WorkspaceServiceImpl implements WorkspaceService { 25 | 26 | @Autowired 27 | private OrderMapper orderMapper; 28 | @Autowired 29 | private UserMapper userMapper; 30 | @Autowired 31 | private DishMapper dishMapper; 32 | @Autowired 33 | private SetmealMapper setmealMapper; 34 | 35 | /** 36 | * 根据时间段统计营业数据 37 | * @param begin 38 | * @param end 39 | * @return 40 | */ 41 | public BusinessDataVO getBusinessData(LocalDateTime begin, LocalDateTime end) { 42 | /** 43 | * 营业额:当日已完成订单的总金额 44 | * 有效订单:当日已完成订单的数量 45 | * 订单完成率:有效订单数 / 总订单数 46 | * 平均客单价:营业额 / 有效订单数 47 | * 新增用户:当日新增用户的数量 48 | */ 49 | 50 | Map map = new HashMap(); 51 | map.put("begin",begin); 52 | map.put("end",end); 53 | 54 | //查询总订单数 55 | Integer totalOrderCount = orderMapper.countOrderNumByMap(map); 56 | 57 | map.put("status", Orders.COMPLETED); 58 | //营业额 59 | Double turnover = orderMapper.sumByMap((HashMap) map); 60 | turnover = turnover == null? 0.0 : turnover; 61 | 62 | //有效订单数 63 | Integer validOrderCount = orderMapper.countOrderNumByMap(map); 64 | 65 | Double unitPrice = 0.0; 66 | 67 | Double orderCompletionRate = 0.0; 68 | if(totalOrderCount != 0 && validOrderCount != 0){ 69 | //订单完成率 70 | orderCompletionRate = validOrderCount.doubleValue() / totalOrderCount; 71 | //平均客单价 72 | unitPrice = turnover / validOrderCount; 73 | } 74 | 75 | //新增用户数 76 | Integer newUsers = userMapper.countByMap((HashMap) map); 77 | 78 | return BusinessDataVO.builder() 79 | .turnover(turnover) 80 | .validOrderCount(validOrderCount) 81 | .orderCompletionRate(orderCompletionRate) 82 | .unitPrice(unitPrice) 83 | .newUsers(newUsers) 84 | .build(); 85 | } 86 | 87 | 88 | /** 89 | * 查询订单管理数据 90 | * 91 | * @return 92 | */ 93 | public OrderOverViewVO getOrderOverView() { 94 | Map map = new HashMap(); 95 | map.put("begin", LocalDateTime.now().with(LocalTime.MIN)); 96 | map.put("status", Orders.TO_BE_CONFIRMED); 97 | 98 | //待接单 99 | Integer waitingOrders = orderMapper.countOrderNumByMap(map); 100 | 101 | //待派送 102 | map.put("status", Orders.CONFIRMED); 103 | Integer deliveredOrders = orderMapper.countOrderNumByMap(map); 104 | 105 | //已完成 106 | map.put("status", Orders.COMPLETED); 107 | Integer completedOrders = orderMapper.countOrderNumByMap(map); 108 | 109 | //已取消 110 | map.put("status", Orders.CANCELLED); 111 | Integer cancelledOrders = orderMapper.countOrderNumByMap(map); 112 | 113 | //全部订单 114 | map.put("status", null); 115 | Integer allOrders = orderMapper.countOrderNumByMap(map); 116 | 117 | return OrderOverViewVO.builder() 118 | .waitingOrders(waitingOrders) 119 | .deliveredOrders(deliveredOrders) 120 | .completedOrders(completedOrders) 121 | .cancelledOrders(cancelledOrders) 122 | .allOrders(allOrders) 123 | .build(); 124 | } 125 | 126 | /** 127 | * 查询菜品总览 128 | * 129 | * @return 130 | */ 131 | public DishOverViewVO getDishOverView() { 132 | Map map = new HashMap(); 133 | map.put("status", StatusConstant.ENABLE); 134 | Integer sold = dishMapper.countByMap(map); 135 | 136 | map.put("status", StatusConstant.DISABLE); 137 | Integer discontinued = dishMapper.countByMap(map); 138 | 139 | return DishOverViewVO.builder() 140 | .sold(sold) 141 | .discontinued(discontinued) 142 | .build(); 143 | } 144 | 145 | /** 146 | * 查询套餐总览 147 | * 148 | * @return 149 | */ 150 | public SetmealOverViewVO getSetmealOverView() { 151 | Map map = new HashMap(); 152 | map.put("status", StatusConstant.ENABLE); 153 | Integer sold = setmealMapper.countByMap(map); 154 | 155 | map.put("status", StatusConstant.DISABLE); 156 | Integer discontinued = setmealMapper.countByMap(map); 157 | 158 | return SetmealOverViewVO.builder() 159 | .sold(sold) 160 | .discontinued(discontinued) 161 | .build(); 162 | } 163 | } 164 | --------------------------------------------------------------------------------