初始模板

This commit is contained in:
tsukiyalo 2024-10-18 15:31:50 +08:00
commit c761a84991
180 changed files with 10440 additions and 0 deletions

33
school_lend_back_end/.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

View File

@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.bsz</groupId>
<artifactId>school_send_back_end</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>school_send_back_end</name>
<description>school_send_back_end</description>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.38.0.ALL</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 阿里云oss依赖 -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.15.1</version>
</dependency>
<!--日期工具栏依赖-->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.1</version>
</dependency>
<!-- https://doc.xiaominfo.com/knife4j/documentation/get_start.html-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.9.21</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.6.4</version>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,237 @@
create database school_send;
use school_send;
create table user
(
username varchar(256) null comment '用户昵称',
id bigint auto_increment comment 'id'
primary key,
unionId varchar(256) null comment '支付宝开放平台id',
openId varchar(256) null comment 'openId',
userAccount varchar(256) null comment '账号',
avatarUrl varchar(256) null comment '用户头像',
gender tinyint null comment '性别',
userPassword varchar(512) not null comment '密码',
phone varchar(128) null comment '电话',
email varchar(512) null comment '邮箱',
userStatus int default 0 not null comment '状态 0 -正常',
createTime datetime default CURRENT_TIMESTAMP null comment '创建时间',
updateTime datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
isDelete tinyint default 0 not null comment '是否删除',
userRole varchar(256) default 'user' not null comment 'user-普通用户business-商家admin-管理员',
index idx_openId (openId)
) comment '用户' collate = utf8mb4_unicode_ci;
-- 商家表
create table if not exists business
(
id bigint auto_increment comment 'id' primary key,
userId bigint not null comment '用户id',
businessName varchar(512) not null comment '门店名称',
businessAvatar varchar(1024) not null comment '门店头像',
businessPhone varchar(64) not null comment '门店手机号',
address varchar(512) not null comment '店铺详细地址',
businessProfile varchar(512) null comment '门店简介',
businessImages varchar(1024) null comment '商家相册',
categoryId bigint null comment '分类id',
startBusiness varchar(64) not null comment '开始营业时间',
endBusiness varchar(64) not null comment '结束营业时间',
state tinyint default 0 not null comment '状态:0审核中,1启用,2禁用',
storeStatus tinyint default 0 not null comment '店铺状态:0休业,1营业',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
isDelete tinyint default 0 not null comment '是否删除',
index idx_businessId (id),
index idx_userId (userId)
) comment '商家' collate = utf8mb4_unicode_ci;
-- 商家认证表
create table if not exists business_auth
(
id bigint auto_increment comment 'id' primary key,
businessId bigint not null comment '店铺id',
shopkeeper varchar(64) not null comment '店主名',
license varchar(1024) not null comment '营业执照',
frontIdCard varchar(1024) not null comment '身份证正面',
backIdCard varchar(1024) not null comment '身份证反面',
bankCard varchar(64) not null comment '银行卡号',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
isDelete tinyint default 0 not null comment '是否删除',
index idx_businessId (businessId)
) comment '商家认证' collate = utf8mb4_unicode_ci;
-- 系统
-- 分类表
create table if not exists category
(
id bigint auto_increment comment 'id' primary key,
name varchar(256) not null comment '分类名',
image varchar(512) not null comment '分类图片',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
index idx_categoryId (id)
) comment '分类表' collate = utf8mb4_unicode_ci;
-- 系统信息表
create table if not exists systemInfo
(
id bigint auto_increment comment 'id' primary key,
type tinyint not null comment '类型:0公告,1轮播图',
content varchar(256) not null comment '功能内容',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间'
) comment '系统信息' collate = utf8mb4_unicode_ci;
-- 操作日志表
create table if not exists systemLog
(
id bigint auto_increment comment 'id' primary key,
userId bigint not null comment '用户id',
content varchar(256) not null comment '操作内容',
ip varchar(64) not null comment 'ip地址',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
index idx_businessId (userId)
) comment '系统信息' collate = utf8mb4_unicode_ci;
-- 菜品
-- 菜品分组表
create table if not exists dishes_group
(
id bigint auto_increment comment 'id' primary key,
businessId bigint not null comment '商家id',
groupName varchar(128) not null comment '菜品分组名称',
isTopping tinyint default 0 not null comment '是否置顶:0不置顶,1置顶',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
isDelete tinyint default 0 not null comment '是否删除',
index idx_businessId (businessId)
) comment '菜品分组表' collate = utf8mb4_unicode_ci;
-- 菜品表
create table if not exists dishes
(
id bigint auto_increment comment 'id' primary key,
businessId bigint not null comment '商家id',
dishesGroupId bigint not null comment '菜品分组id',
dishesName varchar(128) not null comment '菜品名称',
dishesImage varchar(1024) null comment '菜品图片',
dishesPrice double not null comment '菜品价格',
packPrice double not null comment '打包费',
inventoryStatus int not null comment '库存数量',
status varchar(20) default '上架' not null comment '菜品状态:上架,下架',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
isDelete tinyint default 0 not null comment '是否删除',
index idx_businessId (businessId)
) comment '菜品表' collate = utf8mb4_unicode_ci;
-- 菜品和规格的中间表
create table if not exists specifications_dishes
(
id bigint auto_increment comment 'id' primary key,
dishesId bigint not null comment '菜品id',
specificationsId bigint not null comment '规格id',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
isDelete tinyint default 0 not null comment '是否删除',
index idx_dishesId (dishesId),
index idx_specificationsId (specificationsId)
) comment '菜品和规格的中间表' collate = utf8mb4_unicode_ci;
-- 规格表
create table if not exists specifications
(
id bigint auto_increment comment 'id' primary key,
businessId bigint not null comment '商家id',
specificationsName varchar(128) not null comment '规格名称',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
isDelete tinyint default 0 not null comment '是否删除',
index idx_businessId (businessId)
) comment '规格表' collate = utf8mb4_unicode_ci;
-- 属性表
create table if not exists attribute
(
id bigint auto_increment comment 'id' primary key,
businessId bigint not null comment '商家id',
specificationsId bigint not null comment '规格id',
attributeName varchar(128) not null comment '属性名称',
attributeStatus tinyint default 0 not null comment '属性状态:0在售,1停售',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
index idx_businessId (businessId)
) comment '属性表' collate = utf8mb4_unicode_ci;
-- 订单
-- 订单表
create table if not exists orders
(
id bigint auto_increment comment 'id' primary key,
pickupCode varchar(64) null comment '取餐码',
userName varchar(256) not null comment '姓名',
phone varchar(64) not null comment '手机号',
userId bigint not null comment '下单用户id',
businessId bigint not null comment '商家id',
totalPrice decimal(10, 2) not null comment '订单实际总价',
pickupMethod tinyint not null comment '取餐方式(0堂食 1自提)',
payMethod tinyint not null comment '支付方式0微信支付',
pickupTime datetime null comment '取餐时间',
notes varchar(128) null comment '备注',
state tinyint default 0 not null comment '订单状态:0未支付 1已完成 2已退款 3已取消',
createTime datetime default CURRENT_TIMESTAMP not null comment '下单时间',
updateTime datetime default CURRENT_TIMESTAMP not null comment '支付时间',
isDelete tinyint default 0 not null comment '是否删除',
index idx_businessId (businessId),
index idx_stateId (state)
) comment '订单表' collate = utf8mb4_unicode_ci;
-- 订单详情表
create table if not exists order_details
(
id bigint auto_increment comment 'id' primary key,
orderId bigint not null comment '关联的订单id',
dishesId bigint not null comment '关联的菜品id',
quantity int not null comment '购买数量',
price decimal(10, 2) not null comment '单价',
subtotal decimal(10, 2) not null comment '小计(单价 * 数量)',
attributeNames varchar(512) null comment '规格属性列表',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
isDelete tinyint default 0 not null comment '是否删除',
index idx_orderId (orderId)
) comment '订单详情表' collate = utf8mb4_unicode_ci;
-- 购物车表
create table if not exists cart
(
id bigint auto_increment comment 'id' primary key,
userId bigint not null comment '用户id',
businessId bigint not null comment '商家id',
createTime datetime default CURRENT_TIMESTAMP not null comment '加入购物车时间',
updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
dishesId bigint null comment '菜品id',
quantity int default 1 not null comment '商品数量',
price decimal(10, 2) not null comment '当前选择规格的价格',
subtotal decimal(10, 2) as ((`price` * `quantity`)) stored comment '小计(单价 * 数量)',
selectedOptions varchar(512) default '' not null comment '已选规格属性列表',
isDelete tinyint default 0 not null comment '是否删除',
index idx_userId (userId),
index idx_businessId (businessId)
) comment '购物车表' collate = utf8mb4_unicode_ci;
create table demo(
id int auto_increment primary key ,
name varchar(30) comment '姓名',
detail varchar(256) comment '详情'
);
-- 系统信息表
create table if not exists systemInfo
(
id bigint auto_increment comment 'id' primary key,
type tinyint not null comment '类型:0公告,1轮播图',
content varchar(256) not null comment '功能内容',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间'
) comment '系统信息' collate = utf8mb4_unicode_ci;

View File

@ -0,0 +1,15 @@
package com.bsz.school_send_back_end;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@MapperScan("com.bsz.school_send_back_end.mapper")
@SpringBootApplication
public class UserCenterApplication {
public static void main(String[] args) {
SpringApplication.run(UserCenterApplication.class, args);
}
}

View File

@ -0,0 +1,21 @@
package com.bsz.school_send_back_end.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 权限校验
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AuthCheck {
/**
* 必须有某个角色
* @return
*/
String mustRole() default "";
}

View File

@ -0,0 +1,19 @@
package com.bsz.school_send_back_end.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 系统日志
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface SystemLog {
/**
* 操作步骤
*/
String executeStep() default "";
}

View File

@ -0,0 +1,75 @@
package com.bsz.school_send_back_end.aop;
import com.bsz.school_send_back_end.annotation.AuthCheck;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.contant.UserConstant;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.model.domain.User;
import com.bsz.school_send_back_end.model.enums.UserRoleEnum;
import com.bsz.school_send_back_end.service.UserService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* 权限校验 AOP
*/
@Aspect
@Component
public class AuthInterceptor {
@Resource
private UserService userService;
/**
* 执行拦截
*/
@Around("@annotation(authCheck)")
public Object doInterceptor(ProceedingJoinPoint joinPoint, AuthCheck authCheck) throws Throwable {
String mustRole = authCheck.mustRole();
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
// 当前登录用户
User loginUser = userService.getLoginUser(request);
// 必须有该权限才通过
UserRoleEnum mustUserRoleEnum = UserRoleEnum.getEnumByValue(mustRole);
String userRole = loginUser.getUserRole();
// 如果被封号直接拒绝
if (UserRoleEnum.BAN.equals(UserRoleEnum.getEnumByValue(userRole))) {
throw new BusinessException(ErrorCode.NO_AUTH);
}
// 必须有Boss权限
if (UserRoleEnum.BOSS.equals(mustUserRoleEnum)) {
if (!mustRole.equals(userRole)) {
throw new BusinessException(ErrorCode.NO_AUTH);
}
}
// 必须有管理员权限
if (UserRoleEnum.ADMIN.equals(mustUserRoleEnum)) {
if (!mustRole.equals(userRole) && !UserConstant.BOSS_ROLE.equals(userRole)) {
throw new BusinessException(ErrorCode.NO_AUTH);
}
}
// 必须有商家或管理员权限
if (UserRoleEnum.BUSINESS.equals(mustUserRoleEnum)) {
if (!mustRole.equals(userRole)
&& !UserConstant.ADMIN_ROLE.equals(userRole)
&&!UserConstant.BOSS_ROLE.equals(userRole)) {
throw new BusinessException(ErrorCode.NO_AUTH);
}
}
// 通过权限校验放行
return joinPoint.proceed();
}
}

View File

@ -0,0 +1,67 @@
package com.bsz.school_send_back_end.aop;
import com.bsz.school_send_back_end.annotation.SystemLog;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.domain.Systemlog;
import com.bsz.school_send_back_end.model.domain.User;
import com.bsz.school_send_back_end.service.SystemlogService;
import com.bsz.school_send_back_end.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* 日志AOP
*/
@Slf4j
@Aspect
@Component
public class SystemLogInterceptor {
@Resource
private UserService userService;
@Resource
private SystemlogService systemlogService;
/**
* 执行拦截
*/
@Around("@annotation(systemLog)")
public Object doInterceptor(ProceedingJoinPoint joinPoint, SystemLog systemLog) throws Throwable {
// 获取执行操作
String executeStep = systemLog.executeStep();
ThrowUtils.throwIf(StringUtils.isEmpty(executeStep), ErrorCode.PARAMS_ERROR);
//获取请求
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
//获取登录用户
User loginUser = userService.getLoginUser(httpServletRequest);
//写入系统日志
Systemlog systemlog = new Systemlog();
systemlog.setUserId(loginUser.getId());
systemlog.setContent(executeStep);
systemlog.setIp(httpServletRequest.getRemoteHost());
boolean save = systemlogService.save(systemlog);
if (!save) {
log.error("操作日志写入失败,执行操作:" + executeStep);
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "操作日志写入失败");
}
// 放行
return joinPoint.proceed();
}
}

View File

@ -0,0 +1,49 @@
package com.bsz.school_send_back_end.common;
import lombok.Data;
import java.io.Serializable;
/**
*通用返回类
*
* @author bsz
*/
@Data
public class BaseResponse<T> implements Serializable {
/**
* 状态码
*/
private int code;
/**
* 数据
*/
private T data;
/**
* 消息
*/
private String message;
/**
* 描述
*/
private String description;
public BaseResponse(int code, T data, String message, String description) {
this.code = code;
this.data = data;
this.message = message;
this.description = description;
}
public BaseResponse(int code, T data, String message) {
this(code, data, message, "");
}
public BaseResponse(int code, T data) {
this(code, data, "", "");
}
public BaseResponse(ErrorCode errorCode) {
this(errorCode.getCode(), null , errorCode.getMessage(), errorCode.getDescription());
}
}

View File

@ -0,0 +1,48 @@
package com.bsz.school_send_back_end.common;
/**
* 错误码
*/
public enum ErrorCode {
SUCCESS(0, "ok", ""),
PARAMS_ERROR(40000, "请求参数错误", ""),
NULL_ERROR(40001, "请求数据为空", ""),
NOT_LOGIN(40100, "未登录", ""),
NO_AUTH(40101, "无权限", ""),
NOT_FOUND_ERROR(40400,"请求数据不存在",""),
SYSTEM_ERROR(50000, "系统内部异常", ""),
OPERATION_ERROR(50001, "操作失败", "");
/**
* 状态码
*/
private final int code;
/**
* 状态码信息
*/
private final String message;
/**
* 状态码的详细描述
*/
private final String description;
ErrorCode(int code, String message, String description) {
this.code = code;
this.message = message;
this.description = description;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
public String getDescription() {
return description;
}
}

View File

@ -0,0 +1,68 @@
package com.bsz.school_send_back_end.common;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
/**
* 返回工具类
*/
public class ResultUtils {
/**
* 成功
*
* @param data
* @param <T>
* @return
*/
public static <T> BaseResponse<T> success(T data) {
return new BaseResponse<>(0, data, "ok");
}
public static <T> BaseResponse<T> success(T data, String message) {
return new BaseResponse<>(0, data, message);
}
/**
* 失败
*
* @param errorCode
* @return
*/
public static BaseResponse error(ErrorCode errorCode) {
return new BaseResponse<>(errorCode);
}
/**
* 失败
*
* @param code
* @param message
* @param description
* @return
*/
public static BaseResponse error(int code, String message, String description) {
return new BaseResponse(code, null, message, description);
}
/**
* 失败
*
* @param errorCode
* @return
*/
public static BaseResponse error(ErrorCode errorCode, String message, String description) {
return new BaseResponse(errorCode.getCode(), null, message, description);
}
/**
* 失败
*
* @param errorCode
* @return
*/
public static BaseResponse error(ErrorCode errorCode, String description) {
return new BaseResponse(errorCode.getCode(), errorCode.getMessage(), description);
}
}

View File

@ -0,0 +1,42 @@
package com.bsz.school_send_back_end.config;
import com.alipay.api.internal.util.AlipaySignature;
import org.springframework.context.annotation.Configuration;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class AliPayNotifyHandler {
public void aliPayNotifyUrl(HttpServletRequest request) {
// HttpServletRequest 的参数转换为 Map<String, String>
Map<String, String> params = new HashMap<>();
Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String paramName = parameterNames.nextElement();
params.put(paramName, request.getParameter(paramName));
}
// 之后可以使用 params 进行业务处理
// 例如
String alipayrsaPublicKey = "MIIBIjANBgKGhKiG9WOBAOEFAAOCAQ8AMIIBCgKCAOEAUQWP3y7DHD0Z+/K+TcGlki0/acP8";
try {
// 验证签名
boolean flag = AlipaySignature.rsaCheckV1(params, alipayrsaPublicKey, "UTF-8", "RSA2");
if (flag && "TRADE_SUCCESS".equals(params.get("trade_status"))) {
// 业务处理
System.out.println("success");
} else {
System.out.println("fail");
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("fail");
}
}
}

View File

@ -0,0 +1,39 @@
package com.bsz.school_send_back_end.config;
import com.alipay.api.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
public class AlipayClients {
//appid
public String appId = "2021004151684053";
//私钥
//沙箱公钥 支付宝公钥
public String PublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3JKMG3clg/1MqewlIK/koEhiQiSLagckb/2/Dyvg+rJ2snGiAgzNvhvvc1GdVC+Xnn/P+U+2tAytyuvbOuhmGgNZjeObczJXpo/0D6LBdYDrg4PVMDxpStCxLUpaShHbc/l/IquaorBwd94UJxIPAbUQkUBCbo94mGbhDX+yU4FQ6k1yeUtn03jvZ3AY0BEHpenCxWKgr5S/CUAYEitMbi/r7extBy6f4FCR120NM7VaNEK1xpHbGHo6rDpyiAOR1lWFuiqOJ1hv14UL/SfOLlzvUZiiPysIxdNjycZyiyRvFRHP3n8GBAaJDm9vVHwDfgQ5s3Ig2ggBeYXkFHZqWwIDAQAB";
// public String PublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjqGlEXMznr4XlQ3hvbZnQmfj0iJ2MAmPmpNyXMuQhuMK2xx8t9HozL+YzZ8l/4ksgtzGCHx0NiObsYe6Tt0EogfBqXjPTst21AjrT1TPKOxSfv6WuqNLNuY5o/i8ev0OLAGg8YUD2PL1GXSIrUMqjUuCFYQ7iFgEtcN54GVh4XG7Qj6wpN8CCTwmG4R4vHk4Al0ydE2yf0Efj49EgIi+Oq8EkXPSgdWpcS+UaEyuFVr3R5am36MHp+rXkOm6NluVJFBD/JHsOjB/Wt0EGd2HSyhR7n0hjFpNfVodughLL53/zG+nZ7+mM25s2S7Qh4iirxTedeqXlvBMXffxLSQrtQIDAQAB";
//公钥appPrivateKey
//沙箱私钥 支付宝私钥
public String appPrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCc1rWOaCHl7KnDDMctWIgFJqerq9ZU8QsxSA+wQC4nrTfoQVSVZn8fDNosilCHda7yv910A9aJYqZKx0+NOXY9YvMbKYifWtO8TtzAQ9Q0EQXce85gnVQ3yn9evE1MVwfmMIiXJ2jx/dmGrxuADrLcsNB/U4xsusKcNQaA76vALtAYTnKwOODaDt5Qd2OC25PRcGtKupKIbir/f62tNquBkCX+Z5URBpy0rZY2hCu30v3uPv8I3OlpxegFwNDHpKMIY3+wjQtqsogQTn20E5wzeV3VNabNxbORq6B6nh8mvxlo9q14XvmMJDPUoWiJgyUUpaAPZFWSpRCrLvWQY/klAgMBAAECggEAZJ/Ahig7L2gClriZBXfadOuTAapS7dZkpu6j2iGjOyOATgu0N9I11vcI9zCab/5KC0abzzYzK5vWMv3jBSmLueDFNnUUSaEdXaB/Mv+RowIU75ujEgt+n/jUdTR8p3DjCYWz7L6FL1T9fdLU4vkLOlpauoYg/xVnjI7cqFacq8SWr3jiGj/I31O18y02/eDiyAb5RMlSlNGnzvDuRwJ3h2Sn1u7znbMCi6CydG3hx+I0GE2iJqVPymc1f0T0vm7Jy3l/zL84oNKLTgPCqG9k+eriC7RaMkbvPQFjWCDCuWxgYM2pi1L9ZDG+FkReTFsZw6r/TWc4sl2xtj3GDSrHYQKBgQD1NwFBMQwsUQ/aJP63R0gILWSFR0+yQ314vfRRVKoZTujbQr7RBAzgQff97DirINIxXCBeV0zifpc2IaAPaY29YjDnQU+xGqIO91EWPjMkQ6XUvGGesKnKDYkA5yBMyD3/BH8BwJruidW2DwtC2rGTW1hatkXNtYccEI79/00UOQKBgQCjvKIySZdRolOYUfSPHHipOygWClFy1DlI54XDnj0gRBoOrFkeqrXr+G8dYeXP6UnMqLWX8V3RuEJB8klwKGLkMtUWdqMQUFM5yvjuX2d1Y9R2ESw0ch70B/6aItMVv6aN4GjGwCJWD1XD54IpWxtAKJsUxbDiN+343cVqSQQETQKBgQDq9JBcMa3TTLyerbHuVPt88lmNpr2DNk2kAoZ142S0qTpO1M5XIcVgn3UKNWw69FDSgM529rkxkFA8ys0910q7erkW7Cp6rOU459onMOP5zGO5yeLTlbyqYHu0hMEbMQbOMjWrrSwGgcVnE1Ub8sYRRoYLLPkHWPcjee45C4WEaQKBgHkUUeDb+JD+d9DIsg9uH3ANdcwunyJJ+36E7q7EgjEtCxPUsSZzWIoBsbFJppbDzbYRABA3BYjDOAPqNhJBWzeiu16cJmM28wRmqwQi+q+dPgx9EHJL/cW5b7XtkKihi3mY/AIVLI71UhfHR8JrQ9CC9oM62V2/vDNvU8AP9G91AoGANdvRubukeWgvWryBTaPuUTpjkP1mOuJuHiHEW5/XePsURwS6gGP/qJ9bSbhYhQ6iDaMOQ8vahfYM3Q4jvDxgcKS/N1fxFTohcN4bVdvekq62YdTNqcGhNzaxMNboFZYt2dPeDm8PRRMP+abddrS2NqgVSOC3Ru5Kh9iRIs2LOgE=";
// public String appPrivateKey ="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCOoaURczOevheVDeG9tmdCZ+PSInYwCY+ak3Jcy5CG4wrbHHy30ejMv5jNnyX/iSyC3MYIfHQ2I5uxh7pO3QSiB8GpeM9Oy3bUCOtPVM8o7FJ+/pa6o0s25jmj+Lx6/Q4sAaDxhQPY8vUZdIitQyqNS4IVhDuIWAS1w3ngZWHhcbtCPrCk3wIJPCYbhHi8eTgCXTJ0TbJ/QR+Pj0SAiL46rwSRc9KB1alxL5RoTK4VWvdHlqbfowen6teQ6bo2W5UkUEP8kew6MH9a3QQZ3YdLKFHufSGMWk19Wh26CEsvnf/Mb6dnv6YzbmzZLtCHiKKvFN516peW8Exd9/EtJCu1AgMBAAECggEAPghReVhoL/cu3HXQIylsmXYDoIW6b0QJP8o25+Lk9bVTKF6oY24Y2MvPkkZQSWYIhNWuD0zJYi50bW7BecEoXawP7zwKtZNKGAfVB4i0HHFDo9XoCj4w3SyeDxGEL91VR5Bhxgj61mU8chi7xNc8b31SkzcSiUb2rXLZ091kB58/xtzQk2nZAhKhwms7gbX7qxm8+TWLRK9g4vWmsGVqbgFNj/sutqBURSeU/pHmW9PMqgcWvx6AwWWi+VgBUSoIgMnX7r7s6ZlgeDIgioii3JdCcr1nq39sVYPwFpwIe7a1DOCB58B+v2un1XoThC7ZNEcbwP5oYpUdFhSoxClrNQKBgQDJc/A1nz2yYiLUHUMJn2DhyTrOnCSclmowuzJVkyuo5gQPfZ3dTmjdPkM/fg09J3+zi3UCSwZd6dGMzJVHWooMniSiomZ/rY+o9SVTAJOjxt29N8jFN92b3fB43hbAWyBOuy4NMZMcr+4cADuqRHz2pKAeaALiZdpTbrTCzVXtqwKBgQC1QGS0sv8VU9fyBCyrYU4kQh8Fcvz0g6ObgUnHZi6UIL+Cy0/3JIGeIyvB/n47RF1wLUz4wykwW70e1qlMz7w21HM+DB8fVuzbO7SmQI3gDo024kQkWWGUhe3/w9ztzLF9ezleSN6wnrPeDbeMV+pURbsxIXA9xg7DYpZZ76ksHwKBgHQnF/oi7bTbpo88q/lxXq/wkaqtFuL+Sw378UKsD4Fb1j2ERTBj1Ey0aJvENyfqjVPddcKztWESvtL65pt0laI+0IrBLm4xiWJ2rmWUMIw+zn0aG/Wyh2Emb0+RZfbU0+TxQdUzn0nsGlMkw0IiKRcgxn2hpQAaj+6JJ0omkIPvAoGAZ2eGTKT17Cf6QgNprJiF6R+j7QruD11uoJABFHZSSoXoXGk7hMbZ/+sW0sUrJQrat93QVPeabxFXctmKmtzFBw7rdFGcC9gepvCIHnUju9jxbYdm0sn/ZqmF323RhAVMmUcMsqKmEWNpQFzZA4NAl7V0lxH5o/RzhbqgBk05WYcCgYEAny/umQs7+NYgwL/FztMJVljfQsGY81mhgrQyPhmg/7NiWmLodJtwQgSj3UitDVtUGhZRnuidO8P1XW0sUyDwc8xMLb+0qVxX4gMpM4J1B0UaIp+oPg7hCXeFGxkWQl8bPY0RFa3GOfT2/D63NpXqYw8Fe1lZWoIMz+PBdx0YN90=";
//应用证书
private String appCertPath;
//支付宝证书
private String alipayCertPath;
//支付宝根证书
private String alipayRootCertPath;
//回调地址
private String notify;
//字符集 签名
private String gateway = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
// 公私钥模式
@Bean
public AlipayClient alipayClient() throws AlipayApiException {
AlipayClient client = new DefaultAlipayClient(this.gateway, this.appId, this.appPrivateKey, AlipayConstants.FORMAT_JSON, AlipayConstants.CHARSET_UTF8, PublicKey, AlipayConstants.SIGN_TYPE_RSA2);
return client;
}
}

View File

@ -0,0 +1,28 @@
package com.bsz.school_send_back_end.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 全局跨域配置
*
*
* @author bsz
*/
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 覆盖所有请求
registry.addMapping("/**")
// 允许发送 Cookie
.allowCredentials(true)
// 放行哪些域名必须用 patterns否则 * 会和 allowCredentials 冲突
.allowedOriginPatterns("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.exposedHeaders("*");
}
}

View File

@ -0,0 +1,28 @@
package com.bsz.school_send_back_end.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
/**
* Spring MVC Json 配置
*/
@JsonComponent
public class JsonConfig {
/**
* 添加 Long json 精度丢失的配置
*/
@Bean
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
SimpleModule module = new SimpleModule();
module.addSerializer(Long.class, ToStringSerializer.instance);
module.addSerializer(Long.TYPE, ToStringSerializer.instance);
objectMapper.registerModule(module);
return objectMapper;
}
}

View File

@ -0,0 +1,53 @@
package com.bsz.school_send_back_end.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @author bsz
* Knife4j 接口文档配置
*
* http://localhost:8080/api/doc.html#/home 接口文档地址
*/
@Configuration
@EnableSwagger2
@Profile({"dev", "test"}) //版本控制访问
public class Knife4jConfig {
@Bean
public Docket defaultApi2() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
// 指定 Controller 扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.bsz.school_send_back_end.controller"))
.paths(PathSelectors.any())
.build();
}
/**
* 自定义接口文档信息
* @return 接口文档
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
// 接口文档的标题
.title("校快送接口平台管理")
// 接口文档的描述信息
.description("校快送的接口文档,进行测试")
// 提供服务的是谁可以填写你自己的地址因为是你自己提供的服务
.termsOfServiceUrl("https://gitee.com/shir23zxc/school_lend_back-end")
.contact(new Contact("bsz", "https://account.bilibili.com/account/face/upload?spm_id_from=333.999.0.0", "1113832400@qq.com"))
// 版本
.version("1.0")
// 构建
.build();
}
}

View File

@ -0,0 +1,27 @@
package com.bsz.school_send_back_end.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* MyBatis Plus 配置
*/
@Configuration
@MapperScan("com.bsz.school_send_back_end.mapper")
public class MyBatisPlusConfig {
/**
* 拦截器配置
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 分页插件
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.contant;
/**
* 通用常量
*/
public interface CommonConstant {
/**
* 升序
*/
String SORT_ORDER_ASC = "ascend";
/**
* 降序
*/
String SORT_ORDER_DESC = " descend";
}

View File

@ -0,0 +1,24 @@
package com.bsz.school_send_back_end.contant;
/**
* 文件常量
*/
@SuppressWarnings("all")
public interface FileConstant {
/**
* COS 访问地址
*/
String COS_HOST = "xxxxxxxxxxxxxxxxxxxx";
/**
* 服务器访问地址
*/
String SERVER_HOST = "http://39.101.78.35/images";
/**
* 服务器上传路径
*/
String SERVER_UPLOAD_DIR = "/www/wwwroot/images";
}

View File

@ -0,0 +1,32 @@
package com.bsz.school_send_back_end.contant;
/**
* 正则表达式常量
*/
@SuppressWarnings("all")
public interface RegexConstant {
/**
* 手机号正则
*/
String PHONE_REGEX = "^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$";
/**
* 邮箱正则
*/
String EMAIL_REGEX = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
/**
* 18位身份证号正则
*/
String ID_CARD_REGEX = "^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9xX]$";
/**
* 验证码正则, 6位数字或字母
*/
String VERIFY_CODE_REGEX = "^[a-zA-Z\\d]{6}$";
/**
* 密码正则4~32位的字母数字下划线
*/
String PASSWORD_REGEX = "^\\w{4,32}$";
}

View File

@ -0,0 +1,37 @@
package com.bsz.school_send_back_end.contant;
/**
* 系统日志通用常量
*/
public interface SystemLogConstant {
/**
* 添加菜品
*/
String ADD_DISHES = "添加菜品";
/**
* 删除菜品
*/
String DELETE_DISHES = "删除菜品";
/**
* 修改菜品
*/
String UPDATE_DISHES = "修改菜品";
/**
* 删除菜品分组
*/
String ADD_DISHES_GROUP = "添加菜品分组";
/**
* 删除菜品分组
*/
String DELETE_DISHES_GROUP = "删除菜品分组";
/**
* 修改菜品分组
*/
String UPDATE_DISHES_GROUP = "修改菜品分组";
}

View File

@ -0,0 +1,44 @@
package com.bsz.school_send_back_end.contant;
/**
* 用户常量
*/
public interface UserConstant {
/**
* 用户登录态键
*/
String USER_LOGIN_STATE = "userLoginState";
/**
* 盐值
*/
String USER_SALT = "bsz";
// ------- 权限 --------
/**
* 默认角色
*/
String DEFAULT_ROLE = "user";
/**
* 商家角色
*/
String BUSINESS_ROLE = "business";
/**
* 管理员角色
*/
String ADMIN_ROLE = "admin";
/**
* Boss
*/
String BOSS_ROLE = "boss";
/**
* 被封号
*/
String BAN_ROLE = "ban";
}

View File

@ -0,0 +1,338 @@
package com.bsz.school_send_back_end.controller;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeCloseModel;
import com.alipay.api.domain.AlipayTradeCreateModel;
import com.alipay.api.domain.AlipayTradeQueryModel;
import com.alipay.api.domain.AlipayTradeRefundModel;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.config.AlipayClients;
import com.bsz.school_send_back_end.contant.UserConstant;
import com.bsz.school_send_back_end.mapper.UserMapper;
import com.bsz.school_send_back_end.model.domain.User;
import com.bsz.school_send_back_end.utils.RandomNumberGenerator;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.*;
@RestController
@RequestMapping("/Alipay")
public class AlipayController {
@Value("${alipay.appId}")
public String appId;
@Value("${alipay.appPrivateKey}")
public String appPrivateKey;
@Value("${alipay.alipayPublicKey}")
public String PublicKey;
@Resource
private UserMapper userMapper;
@Resource
private RandomNumberGenerator randomNumberGenerator;
private static String authToken;
public static final String NOURL = "http://39.101.78.35:6271/Alipay/notifyUrl";
/**
* 解析code获取open_id和token
* @return aaa
* @throws AlipayApiException 支付宝api异常
*/
@GetMapping("/parseCode")
public BaseResponse<User> login(String authcode, HttpServletRequest req) throws AlipayApiException {
String privateKey = appPrivateKey;
String alipayPublicKey = PublicKey;
AlipayConfig alipayConfig = new AlipayConfig();
//沙箱网关
alipayConfig.setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do");
//支付宝网关
alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
alipayConfig.setAppId(appId);
alipayConfig.setPrivateKey(privateKey);
alipayConfig.setFormat("json");
alipayConfig.setAlipayPublicKey(alipayPublicKey);
alipayConfig.setCharset("UTF-8");
alipayConfig.setSignType("RSA2");
AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
request.setCode(authcode);
request.setGrantType("authorization_code");
AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
// System.out.println(response.getBody());打印所有响应
authToken = response.getAccessToken();
if (!response.isSuccess()) {
return ResultUtils.error(ErrorCode.PARAMS_ERROR);
}
AlipayUserInfoShareRequest request1 = new AlipayUserInfoShareRequest();
AlipayUserInfoShareResponse response1 = alipayClient.execute(request1, authToken);
User oid = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, response.getOpenId()));
if (response1.isSuccess()) {
if (oid == null) {
User user = new User();
user.setOpenId(response.getOpenId());
user.setUsername(StringUtils.isAnyBlank(response1.getNickName()) ? "随机名字" + randomNumberGenerator.generateRandomNumber() : response1.getNickName());
user.setUserPassword("123456");
user.setAvatarUrl(StringUtils.isAnyBlank(response1.getAvatar()) ? "https://tfs.alipayobjects.com/images/partner/ATuihpR50zu7UAAAAAAAAAAAAADtl2AA" : response1.getAvatar());
userMapper.insert(user);
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE,user);
return ResultUtils.success(user,"注册成功");
}
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE,oid);
return ResultUtils.success(oid,"登录成功");
}
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE,oid);
return ResultUtils.success(oid,"登录成功");
}
// @GetMapping("/login")
// public BaseResponse<User> getMessage() throws AlipayApiException {
// AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", appId, appPrivateKey, "json", "GBK", PublicKey, "RSA2");
// AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest();
// AlipayUserInfoShareResponse response = alipayClient.execute(request, authToken);
// User oid = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, response.getOpenId()));
// if (response.isSuccess()) {
// if (oid == null) {
// User user = new User();
// user.setOpenId(response.getOpenId());
// user.setUsername(StringUtils.isAnyBlank(response.getNickName()) ? "随机名字" + randomNumberGenerator.generateRandomNumber() : response.getNickName());
// user.setUserPassword("123456");
// user.setAvatarUrl(StringUtils.isAnyBlank(response.getAvatar()) ? "https://tfs.alipayobjects.com/images/partner/ATuihpR50zu7UAAAAAAAAAAAAADtl2AA" : response.getAvatar());
// userMapper.insert(user);
// return ResultUtils.success(user,"注册成功");
// }
// return ResultUtils.success(oid,"登录成功");
// }
// return ResultUtils.error(ErrorCode.PARAMS_ERROR);
//
// }
@GetMapping("/test/parseCode")
public BaseResponse<User> test_login(String authcode, HttpServletRequest req) throws AlipayApiException {
AlipayClients clients = new AlipayClients();
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
request.setCode(authcode);
request.setGrantType("authorization_code");
AlipaySystemOauthTokenResponse response = clients.alipayClient().execute(request);
// System.out.println(response.getBody());打印所有响应
authToken = response.getAccessToken();
if (!response.isSuccess()) {
return ResultUtils.error(ErrorCode.PARAMS_ERROR);
}
AlipayUserInfoShareRequest request1 = new AlipayUserInfoShareRequest();
AlipayUserInfoShareResponse response1 = clients.alipayClient().execute(request1, authToken);
User oid = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, response.getOpenId()));
if (response.isSuccess()) {
if (oid == null) {
User user = new User();
user.setOpenId(response.getOpenId());
user.setUsername(StringUtils.isAnyBlank(response1.getNickName()) ? "随机名字" + randomNumberGenerator.generateRandomNumber() : response1.getNickName());
user.setUserPassword("123456");
user.setAvatarUrl(StringUtils.isAnyBlank(response1.getAvatar()) ? "https://tfs.alipayobjects.com/images/partner/ATuihpR50zu7UAAAAAAAAAAAAADtl2AA" : response1.getAvatar());
userMapper.insert(user);
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE,oid);
return ResultUtils.success(user,"注册成功");
}
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE,oid);
return ResultUtils.success(oid,"登录成功");
}
return ResultUtils.error(ErrorCode.PARAMS_ERROR);
}
/* @GetMapping("/test/login")
public BaseResponse<User> test_getMessage() throws AlipayApiException {
AlipayClients clients = new AlipayClients();
AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest();
AlipayUserInfoShareResponse response = clients.alipayClient().execute(request, authToken);
User oid = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, response.getOpenId()));
if (response.isSuccess()) {
if (oid == null) {
User user = new User();
user.setOpenId(response.getOpenId());
user.setUsername(StringUtils.isAnyBlank(response.getNickName()) ? "随机名字" + randomNumberGenerator.generateRandomNumber() : response.getNickName());
user.setUserPassword("123456");
user.setAvatarUrl(StringUtils.isAnyBlank(response.getAvatar()) ? "https://tfs.alipayobjects.com/images/partner/ATuihpR50zu7UAAAAAAAAAAAAADtl2AA" : response.getAvatar());
userMapper.insert(user);
return ResultUtils.success(user,"注册成功");
}
return ResultUtils.success(oid,"登录成功");
}
return ResultUtils.error(ErrorCode.PARAMS_ERROR);
}*/
@GetMapping("/trade")
public BaseResponse<String> AlipayTradeCreate() throws AlipayApiException {
//创建客户端
AlipayClients clients = new AlipayClients();
//AlipayClient client = clients.alipayClient();
//创建交易请求
AlipayTradeCreateRequest request = new AlipayTradeCreateRequest();
//创建实体类
AlipayTradeCreateModel model = new AlipayTradeCreateModel();
//请求参数 沙箱内部参数
//TODO 后续传入 数据库中菜品
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String datePart = dateFormat.format(new Date());
// 生成随机部分确保其长度为9位
Random random = new Random();
String randomPart = String.format("%09d", random.nextInt(1000000000)); // 生成一个0到8位的随机数补足到9位
// 拼接日期和随机部分并赋值给String a
String a = datePart + randomPart;
System.out.println(a);
model.setOutTradeNo(a);
model.setTotalAmount("88.88");
model.setSubject("Iphone6 16G");
model.setProductCode("JSAPI_PAY");
model.setSellerId("2088721035350152");
model.setBuyerId("2088722035366541");
model.setOpAppId("2021004151684053");
///回调地址
request.setNotifyUrl("http://39.101.78.35:6271/Alipay/notifyUrl");
request.setBizModel(model);
String tradeNo = "";
try {
AlipayTradeCreateResponse response = clients.alipayClient().execute(request);
String trade_no = response.getTradeNo();
tradeNo = trade_no;
} catch (AlipayApiException e) {
e.printStackTrace();
}
return ResultUtils.success(tradeNo);
}
@GetMapping("/test/close")
public String closeOrder(String orderNo) throws AlipayApiException {
AlipayClients clients = new AlipayClients();
AlipayTradeCloseRequest request = new AlipayTradeCloseRequest();
AlipayTradeCloseModel model = new AlipayTradeCloseModel();
//model.setTradeNo(); 这是订单项
//订单项可能会有多个支付单
model.setOutTradeNo(orderNo);
request.setBizModel(model);
request.setNotifyUrl(NOURL);
AlipayTradeCloseResponse response = clients.alipayClient().execute(request);
//这里应该写进日志
return "";
}
@GetMapping("/test/refund")
public String test_refund(String orderNo) throws AlipayApiException {
AlipayClients clients = new AlipayClients();
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
AlipayTradeRefundModel model = new AlipayTradeRefundModel();
model.setOutTradeNo(orderNo);
model.setRefundAmount("1");
//退款请求单号 要求唯一 需改
model.setOutRequestNo("123");
request.setBizModel(model);
request.setNotifyUrl(NOURL);
AlipayTradeRefundResponse response = clients.alipayClient().execute(request);
return "";
}
@GetMapping("/test/query")
public String test_query (String orderNo) throws AlipayApiException {
AlipayClients clients = new AlipayClients();
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
AlipayTradeQueryModel model = new AlipayTradeQueryModel();
model.setOutTradeNo(orderNo);
request.setBizModel(model);
request.setNotifyUrl(NOURL);
AlipayTradeQueryResponse response = clients.alipayClient().execute(request);
String body = response.getBody();
return body;
}
@PostMapping("/notifyUrl")
public void aliPayNotifyUrl(HttpServletRequest request, HttpServletResponse response) {
// HttpServletRequest 的参数转换为 Map<String, String>
Map<String,String> params = new HashMap<>();Map<String, String[]> requestParams = request.getParameterMap();
for(String name : requestParams.keySet()) {
params.put(name, request.getParameter(name));
}
String resultInfo = "buyer_id=208****42&total_amount=0.01&body=***试&trade_no=20190329**941025940236&notify_time=2019-03-29 19:42:04&subject=**电脑网站支付&sign_type=RSA2&charset=UTF-8&auth_app_id=201****222&notify_type=trade_status_sync&invoice_amount=0.01&out_trade_no=20190329ygyg45484544100003&trade_status=TRADE_SUCCESS&gmt_payment=2019-03-29 19:42:03&version=1.0&point_amount=0.00&sign=LDDUIGQmc+1qNtk3oyoAKVeMUKTngdX3ZjVeZOK0EjiPDJ/+Nk+0WSqcE6J7/5xb96Z/vP0yY3pVhZUiFVJ1G45/ys/HAleHh+EERZ1lkCkule1sSyaGFTKQGKx4uHpTyqIgRB1bouf19RPbSx1EkA0VkCarSy9G/OEG5Qmg8UdL2dRulMhlbOHS7tdMJJycDA8vOspOUMeQmk/H6IK9R2Kou5hN2T3KR1GWLYFK+z1jeZhQB3q52lZynO0OFjSzU4aQUBMW5QskQppBYd/ghtY/2YP+2H6YVGNgVmaheZMQ3PVTBALEV+8rZa91salH9DkKN2UCYGvNSNDT1VGCTQ==&gmt_create=2019-03-29 19:42:00&buyer_pay_amount=0.01&receipt_amount=0.01&fund_bill_list=[{\"amount\":\"0.01\",\"fundChannel\":\"PCREDIT\"}]&seller_id=208****5&app_id=2014100***22&notify_id=20190329002221942040**8";
//编码格式
String charset="utf-8";
//支付宝公钥
String alipaypublicKey="";
//签名方式
String sign_type="RSA2";
//对待签名字符串数据通过&进行拆分
String [] temp = resultInfo.split("&");
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
//把拆分数据放在map集合内
for (int i = 0; i < temp.length; i++) {
String[] arr = temp[i].split("=", 2); //通过"="号分割成2个数据
String[] tempAagin = new String[arr.length]; //再开辟一个数组用来接收分割后的数据
for (int j = 0; j < arr.length; j++) {
tempAagin[j] = arr[j];
}
map.put(tempAagin[0], tempAagin[1]);
}
System.out.println(map);
String alipayrsaPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3JKMG3clg/1MqewlIK/koEhiQiSLagckb/2/Dyvg+rJ2snGiAgzNvhvvc1GdVC+Xnn/P+U+2tAytyuvbOuhmGgNZjeObczJXpo/0D6LBdYDrg4PVMDxpStCxLUpaShHbc/l/IquaorBwd94UJxIPAbUQkUBCbo94mGbhDX+yU4FQ6k1yeUtn03jvZ3AY0BEHpenCxWKgr5S/CUAYEitMbi/r7extBy6f4FCR120NM7VaNEK1xpHbGHo6rDpyiAOR1lWFuiqOJ1hv14UL/SfOLlzvUZiiPysIxdNjycZyiyRvFRHP3n8GBAaJDm9vVHwDfgQ5s3Ig2ggBeYXkFHZqWwIDAQAB";
try {
//验签方法
boolean signVerified = AlipaySignature.rsaCheckV1(params,PublicKey,charset,sign_type);
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
if (signVerified && "TRADE_SUCCESS".equals(params.get("trade_status"))) {
// 业务处理
writer.println("success");
} else {
writer.println("fail");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,221 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsz.school_send_back_end.annotation.AuthCheck;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.contant.UserConstant;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.domain.Business;
import com.bsz.school_send_back_end.model.domain.BusinessAuth;
import com.bsz.school_send_back_end.model.domain.User;
import com.bsz.school_send_back_end.model.dto.business.BusinessAddRequest;
import com.bsz.school_send_back_end.model.dto.business.BusinessQueryRequest;
import com.bsz.school_send_back_end.model.dto.business.BusinessUpdateMyRequest;
import com.bsz.school_send_back_end.model.dto.business.BusinessUpdateRequest;
import com.bsz.school_send_back_end.model.vo.BusinessAdminVO;
import com.bsz.school_send_back_end.model.vo.BusinessVO;
import com.bsz.school_send_back_end.service.BusinessAuthService;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import static com.bsz.school_send_back_end.contant.UserConstant.USER_SALT;
/**
* 商家接口
*/
@Slf4j
@RestController
@RequestMapping("/business")
public class BusinessController {
@Resource
private BusinessService businessService;
@Resource
private BusinessAuthService businessAuthService;
@Resource
private UserService userService;
@PostMapping("/add")
public BaseResponse<Long> addBusiness(@RequestBody BusinessAddRequest businessAddRequest) {
ThrowUtils.throwIf(businessAddRequest == null,ErrorCode.PARAMS_ERROR);
User user = new User();
BeanUtils.copyProperties(businessAddRequest, user);
Business business = new Business();
BeanUtils.copyProperties(businessAddRequest, business);
BusinessAuth businessAuth = new BusinessAuth();
BeanUtils.copyProperties(businessAddRequest, businessAuth);
//对每个应该校验的业务进行校验
businessService.validUser(user, true);
businessService.validBusiness(business, true);
businessService.validBusinessAuth(businessAuth, true);
//加密
String encryptPassword = DigestUtils.md5DigestAsHex((USER_SALT + user.getUserPassword()).getBytes());
user.setUserPassword(encryptPassword);
//更改用户权限为商家
user.setUserRole("business");
//往user表中补充商家信息
user.setUsername(business.getBusinessName());
user.setAvatarUrl(business.getBusinessAvatar());
user.setPhone(business.getBusinessPhone());
//插入到表中
businessService.addBusiness(user, business, businessAuth);
return ResultUtils.success(business.getId(),"添加商家成功");
}
/**
* 管理员更新商家
*/
@PostMapping("/update")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> updateBusiness (@RequestBody BusinessUpdateRequest businessUpdateRequest) {
if (businessUpdateRequest == null || businessUpdateRequest.getId() == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "传入参数为空");
}
Business business = new Business();
BeanUtils.copyProperties(businessUpdateRequest, business);
//更新不添加 只需要判断修改符不符合逻辑
businessService.validBusiness(business, false);
boolean updateById = businessService.updateById(business);
ThrowUtils.throwIf(!updateById, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**
* 商家更新个人信息
*/
@PostMapping("/update/my")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
public BaseResponse<Boolean> updateMyBusiness (@RequestBody BusinessUpdateMyRequest businessUpdateMyRequest, HttpServletRequest request) {
if (businessUpdateMyRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 获取当前登录商家信息
Business loginBusiness = businessService.getLoginBusiness(request);
ThrowUtils.throwIf(loginBusiness == null, ErrorCode.NOT_FOUND_ERROR);
Business business = new Business();
business.setId(loginBusiness.getId());
business.setUserId(loginBusiness.getUserId());
BeanUtils.copyProperties(businessUpdateMyRequest, business);
// 校验
businessService.validBusiness(business, false);
// 修改商家信息
boolean updateBusiness = businessService.updateById(business);
ThrowUtils.throwIf(!updateBusiness, ErrorCode.OPERATION_ERROR, "修改商家信息失败");
// 修改用户信息
User loginUser = userService.getById(loginBusiness.getUserId());
if (StringUtils.isNotBlank(business.getBusinessName())) {
loginUser.setUsername(business.getBusinessName());
}
if (StringUtils.isNotBlank(business.getBusinessPhone())) {
loginUser.setPhone(business.getBusinessPhone());
}
boolean updateUser = userService.updateById(loginUser);
ThrowUtils.throwIf(!updateUser, ErrorCode.OPERATION_ERROR, "修改用户信息失败");
return ResultUtils.success(true);
}
/**
* 根据id查询
*/
@GetMapping("/getById")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<BusinessAdminVO> getBusinessById(long id) {
if (id <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Business business = businessService.getById(id);
ThrowUtils.throwIf(business == null , ErrorCode.NULL_ERROR);
BusinessAdminVO businessAdminVO = businessAuthService.getBusinessAdminVO(business);
return ResultUtils.success(businessAdminVO);
}
/**
* 根据当前登录用户获取商家信息
*/
@PostMapping("/get/current")
public BaseResponse<BusinessVO> getByBusiness (HttpServletRequest request) {
Business loginBusiness = businessService.getLoginBusiness(request);
BusinessVO businessVO = businessService.getBusinessVO(loginBusiness);
return ResultUtils.success(businessVO);
}
/**
* 查询所有商家
*/
@PostMapping("/list")
public BaseResponse<List<Business>> listBusinessAll(){
List<Business> businessList = businessService.list();
return new BaseResponse<>(0,businessList,"查询成功");
}
/**
* 分页查询
*/
@PostMapping("/list/page")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Page<Business>> listBusinessByPage (@RequestBody BusinessQueryRequest businessQueryRequest) {
Page<Business> businessPage = businessService.page(new Page<>(businessQueryRequest.getCurrent(), businessQueryRequest.getPageSize()),
businessService.getQueryWrapper(businessQueryRequest));
return ResultUtils.success(businessPage);
}
/**
* 分页获取商家列表用户视图
*/
@PostMapping("/list/page/vo")
public BaseResponse<Page<BusinessVO>> listBusinessVOByPage(@RequestBody BusinessQueryRequest businessQueryRequest) {
long current = businessQueryRequest.getCurrent();
long size = businessQueryRequest.getPageSize();
ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
QueryWrapper<Business> queryWrapper = businessService.getQueryWrapper(businessQueryRequest);
// 只显示正常营业商家
queryWrapper.eq("state", 1);
Page<Business> businessPage = businessService.page(new Page<>(current, size), queryWrapper);
Page<BusinessVO> businessVOPage = new Page<>(current, size, businessPage.getTotal());
List<BusinessVO> businessVOList = businessService.getBusinessVO(businessPage.getRecords());
businessVOPage.setRecords(businessVOList);
return ResultUtils.success(businessVOPage);
}
}

View File

@ -0,0 +1,196 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.domain.Cart;
import com.bsz.school_send_back_end.model.domain.User;
import com.bsz.school_send_back_end.model.dto.cart.CartAddRequest;
import com.bsz.school_send_back_end.model.dto.cart.CartDeleteRequest;
import com.bsz.school_send_back_end.model.dto.cart.CartQueryRequest;
import com.bsz.school_send_back_end.model.dto.cart.CartUpdateRequest;
import com.bsz.school_send_back_end.model.vo.CartVO;
import com.bsz.school_send_back_end.service.CartService;
import com.bsz.school_send_back_end.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@Slf4j
@RequestMapping("/cart")
public class CartController {
@Resource
private CartService cartService;
@Resource
private UserService userService;
/**
* 添加剂购物车
* @param cartAddRequest 添加请求
* @param request 网络请求
* @return 购物车id
*/
@PostMapping("/add")
@Transactional(rollbackFor = Exception.class)
public BaseResponse<Long> addCart (@RequestBody CartAddRequest cartAddRequest, HttpServletRequest request) {
if (cartAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
//校验
cartService.validCart(cartAddRequest);
//添加菜品到购物车
Long cart = cartService.addCart(cartAddRequest, request);
return ResultUtils.success(cart);
}
/**
* 更新购物车
* @param cartUpdateRequest 更新请求
* @param request 网络请求
* @return 是否成功
*/
@PostMapping("/update")
@Transactional(rollbackFor = Exception.class)
public BaseResponse<Boolean> updateCart (@RequestBody CartUpdateRequest cartUpdateRequest, HttpServletRequest request){
if (cartUpdateRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
//校验
CartAddRequest cartAddRequest = new CartAddRequest();
BeanUtils.copyProperties(cartUpdateRequest,cartAddRequest);
cartService.validCart(cartAddRequest);
Boolean cart = cartService.updateCart(cartUpdateRequest, request);
return ResultUtils.success(cart);
}
/**
* 删除购物车
* @param cartDeleteRequest 删除请求
* @param request 网络请求
* @return 是否成功
*/
@PostMapping("/delete")
@Transactional(rollbackFor = Exception.class)
public BaseResponse<Boolean> deleteCart (@RequestBody CartDeleteRequest cartDeleteRequest, HttpServletRequest request) {
if (cartDeleteRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = cartDeleteRequest.getId();
Boolean cart = cartService.deleteCart(id, request);
ThrowUtils.throwIf(!cart, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**
* 根据商户id获取购物车脱敏列表
* @param cartQueryRequest 商户id
* @param request 网络请求
* @return 脱敏列表
*/
@PostMapping("/selectByBusinessId")
public BaseResponse<List<CartVO>> selectByBusinessId (@RequestBody CartQueryRequest cartQueryRequest, HttpServletRequest request) {
if (cartQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long businessId = cartQueryRequest.getId();
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Cart::getBusinessId, businessId);
queryWrapper.eq(Cart::getUserId, userId);
List<Cart> cartList = cartService.list(queryWrapper);
List<CartVO> cartVOList = this.getCartVOList(cartList);
return ResultUtils.success(cartVOList);
}
/**
* 根据用户查找购物车列表
* @param request 网络请求
* @return 脱敏列表
*/
@PostMapping("/selectByUserId")
public BaseResponse<List<CartVO>> selectByUserId (HttpServletRequest request) {
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
LambdaQueryWrapper<Cart> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Cart::getUserId, userId);
List<Cart> cartList = cartService.list(wrapper);
List<CartVO> cartVOList = this.getCartVOList(cartList);
return ResultUtils.success(cartVOList);
}
/**
* 清空商家内的购物车
* @param cartQueryRequest 商家id
* @param request 网络请求
* @return 是否成功
*/
@PostMapping("/empty/business")
public BaseResponse<Boolean> emptyBusinessCart(@RequestBody CartQueryRequest cartQueryRequest, HttpServletRequest request) {
if (cartQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long businessId = cartQueryRequest.getId();
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Cart::getBusinessId, businessId);
queryWrapper.eq(Cart::getUserId, userId);
boolean remove = cartService.remove(queryWrapper);
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**
* 清空用户购物车
* @param request 网络请求
* @return 是否成功
*/
@PostMapping("/empty/user")
public BaseResponse<Boolean> emptyUserCart(HttpServletRequest request) {
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Cart::getUserId, userId);
boolean remove = cartService.remove(queryWrapper);
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
private List<CartVO> getCartVOList(List<Cart> cartList) {
if (CollectionUtils.isEmpty(cartList)) {
return new ArrayList<>();
}
return cartList.stream().map(item ->{
CartVO cartVO = new CartVO();
BeanUtils.copyProperties(item, cartVO);
return cartVO;
}).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,118 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bsz.school_send_back_end.annotation.AuthCheck;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.contant.UserConstant;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.domain.Business;
import com.bsz.school_send_back_end.model.domain.Category;
import com.bsz.school_send_back_end.model.dto.category.CategoryAddRequest;
import com.bsz.school_send_back_end.model.dto.category.CategoryDeleteRequest;
import com.bsz.school_send_back_end.model.dto.category.CategoryUpdateRequest;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {
@Resource
private CategoryService categoryService;
@Resource
private BusinessService businessService;
/**
* 添加类别
* @param categoryAddRequest 添加请求体
* @return 是否成功
*/
@PostMapping("/add")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Long> addCategory (@RequestBody CategoryAddRequest categoryAddRequest) {
if (categoryAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Category category = new Category();
BeanUtils.copyProperties(categoryAddRequest, category);
categoryService.validCategory(category, true);
boolean save = categoryService.save(category);
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR);
Long id = category.getId();
return ResultUtils.success(id,"添加成功");
}
/**
* 修改类别
* @param categoryUpdateRequest 修改请求体
* @return 返回修改后类别
*/
@PostMapping("/update")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Category> updateCategory (@RequestBody CategoryUpdateRequest categoryUpdateRequest) {
if (categoryUpdateRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Category category = new Category();
BeanUtils.copyProperties(categoryUpdateRequest, category);
categoryService.validCategory(category, false);
boolean update = categoryService.updateById(category);
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "操作失败");
return new BaseResponse<>(0,category,"修改成功");
}
/**
* 根据id删除
* @param categoryDeleteRequest 删除请求体
* @return 是否成功
*/
@PostMapping("/delete")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> deleteCategory (@RequestBody CategoryDeleteRequest categoryDeleteRequest) {
if (categoryDeleteRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
LambdaQueryWrapper<Business> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Business::getCategoryId, categoryDeleteRequest.getId());
long count = businessService.count(wrapper);
ThrowUtils.throwIf(count > 0, ErrorCode.OPERATION_ERROR, "该分类下拥有商家");
boolean remove = categoryService.removeById(categoryDeleteRequest.getId());
return ResultUtils.success(remove);
}
/**
* 根据id查询分类
*/
@GetMapping("/getById")
public BaseResponse<Category> getCategoryById (long id) {
if (id <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Category category = categoryService.getById(id);
ThrowUtils.throwIf(category == null, ErrorCode.NOT_FOUND_ERROR);
return ResultUtils.success(category);
}
/**
* 查询类别
*/
@GetMapping("/list")
public BaseResponse<List<Category>> listCategoryAll() {
List<Category> categoryList = categoryService.list();
return ResultUtils.success(categoryList);
}
}

View File

@ -0,0 +1,207 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsz.school_send_back_end.annotation.AuthCheck;
import com.bsz.school_send_back_end.annotation.SystemLog;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.contant.SystemLogConstant;
import com.bsz.school_send_back_end.contant.UserConstant;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.domain.Business;
import com.bsz.school_send_back_end.model.domain.Dishes;
import com.bsz.school_send_back_end.model.dto.Dishes.DishesAddRequest;
import com.bsz.school_send_back_end.model.dto.Dishes.DishesDeleteRequest;
import com.bsz.school_send_back_end.model.dto.Dishes.DishesQueryRequest;
import com.bsz.school_send_back_end.model.dto.Dishes.DishesUpdateRequest;
import com.bsz.school_send_back_end.model.vo.DishesVO;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.DishesService;
import com.bsz.school_send_back_end.service.SpecificationsDishesService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/dishes")
public class DishesController {
@Resource
private DishesService dishesService;
@Resource
private BusinessService businessService;
@Resource
private SpecificationsDishesService specificationsDishesService;
/**
*添加菜品
* @param dishesAddRequest 添加菜品请求体
* @return 是否成功
*/
@PostMapping("/add")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
@Transactional(rollbackFor = Exception.class)
@SystemLog(executeStep = SystemLogConstant.ADD_DISHES)
public BaseResponse<Boolean> addDishes (@RequestBody DishesAddRequest dishesAddRequest, HttpServletRequest request) {
if (dishesAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Dishes dishes = new Dishes();
BeanUtils.copyProperties(dishesAddRequest,dishes);
//校验
dishesService.validDishes(dishes,false);
//添加商家id
Business loginBusiness = businessService.getLoginBusiness(request);
Long businessId = loginBusiness.getId();
dishes.setBusinessId(businessId);
//保存菜品信息
Long dishesId = dishesService.addDishes(dishes);
//中间表中添加数据
List<Long> specificationsIds = dishesAddRequest.getSpecificationsIds();
specificationsDishesService.add(dishesId,specificationsIds);
return ResultUtils.success(true);
}
/**
* 删除菜品
* @param dishesDeleteRequest 删除请求
* @param request 网络请求
* @return 是否成功
*/
@PostMapping("/delete")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
@Transactional(rollbackFor = Exception.class)
@SystemLog(executeStep = SystemLogConstant.DELETE_DISHES)
public BaseResponse<Boolean> deleteDishes(@RequestBody DishesDeleteRequest dishesDeleteRequest,HttpServletRequest request) {
if (dishesDeleteRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long dishesId = dishesDeleteRequest.getId();
//获取商家id
Business business = businessService.getLoginBusiness(request);
Long businessId = business.getId();
//校验菜品是不是当前登录商家的
LambdaQueryWrapper<Dishes> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Dishes::getId, dishesId);
wrapper.eq(Dishes::getBusinessId, businessId);
Dishes dishes = dishesService.getOne(wrapper);
ThrowUtils.throwIf(dishes == null, ErrorCode.OPERATION_ERROR, "当前商家无权限删除该菜品");
//删除菜品
boolean dishesRemove = dishesService.removeById(dishesId);
ThrowUtils.throwIf(!dishesRemove, ErrorCode.OPERATION_ERROR);
//删除中间表信息
specificationsDishesService.deleteByDishesId(dishesId);
return ResultUtils.success(true);
}
/**
* 更新菜品
* @param dishesUpdateRequest 更新请求
* @param request 网络请求
* @return 是否成功
*/
@PostMapping("/update")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
@Transactional(rollbackFor = Exception.class)
@SystemLog(executeStep = SystemLogConstant.UPDATE_DISHES)
public BaseResponse<Boolean> updateDishes (@RequestBody DishesUpdateRequest dishesUpdateRequest, HttpServletRequest request) {
if (dishesUpdateRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Dishes dishes = new Dishes();
BeanUtils.copyProperties(dishesUpdateRequest, dishes);
//校验
dishesService.validDishes(dishes, true);
//添加商家id
Business loginBusiness = businessService.getLoginBusiness(request);
Long businessId = loginBusiness.getId();
dishes.setBusinessId(businessId);
//更新菜品
Boolean updateDishes = dishesService.updateDishes(dishes);
ThrowUtils.throwIf(!updateDishes, ErrorCode.OPERATION_ERROR);
//更新中间表的信息
Long dishesId = dishes.getId();
List<Long> specificationsIds = dishesUpdateRequest.getSpecificationsIds();
return ResultUtils.success(specificationsDishesService.updateByDishesId(dishesId, specificationsIds));
}
/**
* 更新菜品状态
* @param dishesUpdateRequest 菜品请求体
* @param request 前端请求
* @return 是否成功
*/
@PostMapping("/update/status")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
@SystemLog(executeStep = SystemLogConstant.UPDATE_DISHES)
public BaseResponse<Boolean> updateDishesStatus (@RequestBody DishesUpdateRequest dishesUpdateRequest, HttpServletRequest request) {
Long id = dishesUpdateRequest.getId();
String status = dishesUpdateRequest.getStatus();
if (id == null || StringUtils.isBlank(status)) {
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "请补全参数");
}
//获取商家id
Business loginBusiness = businessService.getLoginBusiness(request);
Long businessId = loginBusiness.getId();
//更新状态
LambdaUpdateWrapper<Dishes> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(Dishes::getId, id);
wrapper.eq(Dishes::getBusinessId, businessId);
wrapper.set(Dishes::getStatus, status);
return ResultUtils.success(dishesService.update(wrapper));
}
/**
*获取菜品脱敏列表
* @param dishesQueryRequest 查询请求体
* @return 脱敏列表
*/
@PostMapping("/list/dishes")
public BaseResponse<List<Dishes>> dishesList(@RequestBody DishesQueryRequest dishesQueryRequest) {
Long businessId = dishesQueryRequest.getBusinessId();
if (businessId == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
//获取查询条件
QueryWrapper<Dishes> wrapper = dishesService.getWrapper(dishesQueryRequest);
//根据查询条件该商家的所有菜品
List<Dishes> list = dishesService.list(wrapper);
//获取菜品脱敏列表
return ResultUtils.success(list);
}
/**
*获取菜品脱敏列表
* @param dishesQueryRequest 查询请求体
* @return 分页列表
*/
@PostMapping("/list/page/dishesVO")
public BaseResponse<Page<DishesVO>> dishesVOPage(@RequestBody DishesQueryRequest dishesQueryRequest) {
long current = dishesQueryRequest.getCurrent();
long pageSize = dishesQueryRequest.getPageSize();
//获取查询条件
QueryWrapper<Dishes> wrapper = dishesService.getWrapper(dishesQueryRequest);
//获取商家多有菜品
Page<Dishes> dishesPage = dishesService.page(new Page<>(current, pageSize), wrapper);
//获取脱敏信息列表
List<Dishes> dishesList = dishesPage.getRecords();
long total = dishesPage.getTotal();
List<DishesVO> dishesVOList = dishesService.getDishesVOList(dishesList);
Page<DishesVO> dishesVOPage = new Page<>(current, pageSize, total);
dishesVOPage.setRecords(dishesVOList);
return ResultUtils.success(dishesVOPage);
}
}

View File

@ -0,0 +1,156 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bsz.school_send_back_end.annotation.AuthCheck;
import com.bsz.school_send_back_end.annotation.SystemLog;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.contant.SystemLogConstant;
import com.bsz.school_send_back_end.contant.UserConstant;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.domain.Business;
import com.bsz.school_send_back_end.model.domain.Dishes;
import com.bsz.school_send_back_end.model.domain.DishesGroup;
import com.bsz.school_send_back_end.model.dto.DishesGroup.DishesGroupAddRequest;
import com.bsz.school_send_back_end.model.dto.DishesGroup.DishesGroupDeleteRequest;
import com.bsz.school_send_back_end.model.dto.DishesGroup.DishesGroupQueryRequest;
import com.bsz.school_send_back_end.model.dto.DishesGroup.DishesGroupUpdateRequest;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.DishesGroupService;
import com.bsz.school_send_back_end.service.DishesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/dishesGroup")
public class DishesGroupController {
@Resource
private BusinessService businessService;
@Resource
private DishesGroupService dishesGroupService;
@Resource
private DishesService dishesService;
/**
* 添加菜品分组
* @param dishesGroupAddRequest 添加请求
* @param request 网络请求
* @return 是否成功
*/
@PostMapping("/add")
@Transactional(rollbackFor = Exception.class)
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
@SystemLog(executeStep = SystemLogConstant.ADD_DISHES_GROUP)
public BaseResponse<Boolean> addDishesGroup(@RequestBody DishesGroupAddRequest dishesGroupAddRequest, HttpServletRequest request) {
if (dishesGroupAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
}
DishesGroup dishesGroup = new DishesGroup();
BeanUtils.copyProperties(dishesGroupAddRequest,dishesGroup);
//校验请求体
dishesGroupService.validDishesGroup(dishesGroup,false);
//添加分组
Boolean result = dishesGroupService.addDishesGroup(dishesGroup, request);
ThrowUtils.throwIf(!result,ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**
* 删除菜品分组
* @param dishesGroupDeleteRequest 删除请求
* @param request 网络请求
* @return 是否成功
*/
@PostMapping("/delete")
@Transactional(rollbackFor = Exception.class)
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
@SystemLog(executeStep = SystemLogConstant.DELETE_DISHES_GROUP)
public BaseResponse<Boolean> deleteDishesGroup (@RequestBody DishesGroupDeleteRequest dishesGroupDeleteRequest, HttpServletRequest request) {
if (dishesGroupDeleteRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = dishesGroupDeleteRequest.getId();
//获取商家id
Business loginBusiness = businessService.getLoginBusiness(request);
Long businessId = loginBusiness.getId();
// 校验分组是否为当前商家的分组
QueryWrapper<DishesGroup> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id",id);
queryWrapper.eq("businessId",businessId);
DishesGroup dishesGroup = dishesGroupService.getOne(queryWrapper);
ThrowUtils.throwIf(dishesGroup == null,ErrorCode.OPERATION_ERROR,"当前商家无权删除该分组");
//删除分组
boolean byId = dishesGroupService.removeById(id);
ThrowUtils.throwIf(!byId,ErrorCode.OPERATION_ERROR);
//检查分组下是否有菜品
LambdaQueryWrapper<Dishes> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Dishes::getDishesGroupId, id);
long count = dishesService.count(wrapper);
ThrowUtils.throwIf(count > 0, ErrorCode.OPERATION_ERROR, "该分组下还有菜品");
//删除该分组的菜品以及中检表
dishesService.removeByDishesGroupId(id);
return ResultUtils.success(true);
}
/**
* 更行菜品分组
* @param dishesGroupUpdateRequest 更新请求
* @param request 网轮廓请求
* @return 是否成功
*/
@PostMapping("/update")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
@SystemLog(executeStep = SystemLogConstant.UPDATE_DISHES_GROUP)
public BaseResponse<Boolean> updateDishesGroup (@RequestBody DishesGroupUpdateRequest dishesGroupUpdateRequest,HttpServletRequest request){
if (dishesGroupUpdateRequest == null) {
throw new BusinessException(ErrorCode.OPERATION_ERROR);
}
DishesGroup dishesGroup = new DishesGroup();
BeanUtils.copyProperties(dishesGroupUpdateRequest,dishesGroup);
//校验
dishesGroupService.validDishesGroup(dishesGroup,true);
//更新菜品分组信息
Boolean result = dishesGroupService.updateDishesGroupById(dishesGroup, request);
ThrowUtils.throwIf(!result,ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**
* 查询菜品分组脱敏列表
* @param dishesGroupQueryRequest 菜品分组请求体
* @return 脱敏列表
*/
@PostMapping("/list/dishesGroup")
public BaseResponse<List<DishesGroup>> dishesGroupList (@RequestBody DishesGroupQueryRequest dishesGroupQueryRequest){
//获取商家id
Long businessId = dishesGroupQueryRequest.getBusinessId();
Business business = businessService.getById(businessId);
if (business == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR,"该商家不存在");
}
//查询商家菜品分组信息
QueryWrapper<DishesGroup> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("businessId",businessId);
List<DishesGroup> list = dishesGroupService.list(queryWrapper);
// 获取菜品分组脱敏列表
return ResultUtils.success(list);
}
}

View File

@ -0,0 +1,147 @@
package com.bsz.school_send_back_end.controller;
import cn.hutool.core.io.FileUtil;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.contant.FileConstant;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.model.domain.User;
import com.bsz.school_send_back_end.model.dto.file.UploadFileRequest;
import com.bsz.school_send_back_end.model.enums.FileUploadBizEnum;
import com.bsz.school_send_back_end.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
/**
* 文件上传
*/
@Slf4j
@RestController
@RequestMapping("/file")
public class FileController {
@Resource
private UserService userService;
@PostMapping("/upload/server/not_login")
public BaseResponse<String> uploadServerNotLogin (@RequestPart("file")MultipartFile multipartFile, UploadFileRequest uploadFileRequest) {
//获取业务名称
String biz = uploadFileRequest.getBiz();
FileUploadBizEnum fileUploadBizEnum = FileUploadBizEnum.getEnumByValue(biz);
if (fileUploadBizEnum == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
//校验文件
validfile(multipartFile, fileUploadBizEnum);
//文件目录根据业务用户来划分
String uuid = RandomStringUtils.randomAlphabetic(8);
String fileName = uuid + "-" + multipartFile.getOriginalFilename();
String filePath = String.format("/%s/%s/%s", fileUploadBizEnum.getValue(), 0, fileName);
try {
//判断目录是否存在
File file = new File(FileConstant.SERVER_UPLOAD_DIR, filePath);
log.info("filepath:{}",file);
if (!file.exists()) {
boolean mkdirs = file.mkdirs();
if (!mkdirs) {
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"创建目录失败");
}
}
multipartFile.transferTo(new File(FileConstant.SERVER_UPLOAD_DIR, filePath));
// 返回可访问地址
return ResultUtils.success(FileConstant.SERVER_HOST + filePath);
}
catch (IOException e) {
log.error("file upload error, filePath = " + filePath, e);http://39.101.78.35/images
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"上传失败");
}
}
@PostMapping("/upload/server")
public BaseResponse<String> uploadServerFile(@RequestPart("file") MultipartFile multipartFile, UploadFileRequest uploadFileRequest, HttpServletRequest request) {
// 获取业务名称
String biz = uploadFileRequest.getBiz();
FileUploadBizEnum fileUploadBizEnum = FileUploadBizEnum.getEnumByValue(biz);
if (fileUploadBizEnum == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "业务名称错误");
}
//校验文件
validfile(multipartFile,fileUploadBizEnum);
//校验用户是否登录
User loginUser = userService.getLoginUser(request);
if (loginUser == null) {
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "未登录");
}
// 文件目录根据业务用户来划分
String uuid = RandomStringUtils.randomAlphabetic(8);
String fileName = uuid + "-" + multipartFile.getOriginalFilename();
String filePath = String.format("/%s/%s/%s", fileUploadBizEnum.getValue(), loginUser.getId(), fileName);
try {
File file = new File(FileConstant.SERVER_UPLOAD_DIR, filePath);
if (!file.exists()) {
//创建目录
boolean mkdirs = file.mkdirs();
if (!mkdirs) {
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "创建目录失败");
}
}
multipartFile.transferTo(new File(FileConstant.SERVER_UPLOAD_DIR,filePath));
//返回可访问的地址
return ResultUtils.success(FileConstant.SERVER_HOST + filePath);
}
catch (IOException e) {
log.error("file upload error, filepath = " + filePath, e);
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "上传失败");
}
}
/**
* 校验文件
*/
private void validfile(MultipartFile multipartFile, FileUploadBizEnum fileUploadBizEnum) {
//文件大小
long fileSize = multipartFile.getSize();
//文件后缀
String fileSuffix = FileUtil.getSuffix(multipartFile.getOriginalFilename());
final long TWO_M = 2*1024*1024L;
if (FileUploadBizEnum.USER_AVATAR.equals(fileUploadBizEnum)) {
if (fileSize > TWO_M) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "文件大小不能超过 2M");
}
if (!Arrays.asList("jpeg", "jpg", "svg", "png", "webp").contains(fileSuffix)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "文件类型错误");
}
}
}
}

View File

@ -0,0 +1,327 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsz.school_send_back_end.annotation.AuthCheck;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.contant.CommonConstant;
import com.bsz.school_send_back_end.contant.UserConstant;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.domain.*;
import com.bsz.school_send_back_end.model.dto.CommonRequest;
import com.bsz.school_send_back_end.model.dto.order.*;
import com.bsz.school_send_back_end.model.vo.OrdersVO;
import com.bsz.school_send_back_end.service.*;
import com.bsz.school_send_back_end.utils.SqlUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 订单相关接口
**/
@Slf4j
@RestController
@Tag(name = "订单接口")
@RequestMapping("/orders")
public class OrdersController {
@Resource
private UserService userService;
@Resource
private DishesService dishesService;
@Resource
private OrdersService ordersService;
@Resource
private BusinessService businessService;
@Resource
private OrderDetailsService orderDetailsService;
/**
* 创建订单
*
* @return 订单id
*/
@PostMapping("/add")
public BaseResponse<Long> addOrders(@RequestBody OrderAddRequest orderAddRequest, HttpServletRequest request) {
if (orderAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 提取订单
Orders orders = new Orders();
User loginUser = userService.getLoginUser(request);
BeanUtils.copyProperties(orderAddRequest, orders);
orders.setUserId(loginUser.getId());
ordersService.validOrder(orders);
// 提取订单详情
List<OrderDetailAddRequest> detailAddRequest = orderAddRequest.getOrderDetailAddRequest();
List<OrderDetails> orderDetailsList = detailAddRequest.stream().map(item -> {
OrderDetails orderDetails = new OrderDetails();
BeanUtils.copyProperties(item, orderDetails);
orderDetailsService.validOrderDetail(orderDetails);
Long dishesId = orderDetails.getDishesId();
// 根据菜品设置价格
Dishes dishes = dishesService.getById(dishesId);
BigDecimal dishesPrice = BigDecimal.valueOf(dishes.getDishesPrice());
orderDetails.setPrice(dishesPrice);
double subtotal = dishes.getDishesPrice() * orderDetails.getQuantity();
orderDetails.setSubtotal(BigDecimal.valueOf(subtotal));
return orderDetails;
}).toList();
// 创建订单
long orderId = ordersService.addOrder(orders, orderDetailsList);
return ResultUtils.success(orderId, "订单创建成功");
}
/**
* 取消订单
*/
@PostMapping("/cancel")
public BaseResponse<Boolean> cancelOrder(@RequestBody CommonRequest commonRequest, HttpServletRequest request) {
Long orderId = commonRequest.getId();
if (orderId == null || orderId <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 校验订单
Orders orders = ordersService.getById(orderId);
ThrowUtils.throwIf(orders == null, ErrorCode.NOT_FOUND_ERROR);
ThrowUtils.throwIf(orders.getState() != 0, ErrorCode.OPERATION_ERROR, "订单状态错误");
// 判断是否为自己的订单
User loginUser = userService.getLoginUser(request);
if (!orders.getUserId().equals(loginUser.getId())) {
throw new BusinessException(ErrorCode.NO_AUTH);
}
// 修改订单状态
orders.setState(3);
boolean update = ordersService.updateById(orders);
ThrowUtils.throwIf(!update, ErrorCode.SYSTEM_ERROR);
return ResultUtils.success(true);
}
/**
* 根据 id 获取订单信息仅管理员
*/
@GetMapping("/get")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<OrdersVO> getOrderVOById(long id) {
if (id <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Orders orders = ordersService.getById(id);
ThrowUtils.throwIf(orders == null, ErrorCode.NOT_FOUND_ERROR);
return ResultUtils.success(ordersService.getOrdersVO(orders));
}
/**
* 分页获取订单列表管理员
*/
@PostMapping("/list/page")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Page<Orders>> listOrdersByPage(@RequestBody OrderQueryRequest orderQueryRequest) {
long current = orderQueryRequest.getCurrent();
long size = orderQueryRequest.getPageSize();
Page<Orders> ordersPage = ordersService.page(new Page<>(current, size),
ordersService.getQueryWrapper(orderQueryRequest));
return ResultUtils.success(ordersPage);
}
/**
* 获取我的订单
*/
@PostMapping("/my/page")
public BaseResponse<Page<OrdersVO>> getMyOrders(@RequestBody MyOrderQueryRequest myOrderQueryRequest, HttpServletRequest request) {
if (myOrderQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
long current = myOrderQueryRequest.getCurrent();
long size = myOrderQueryRequest.getPageSize();
User loginUser = userService.getLoginUser(request);
OrderQueryRequest orderQueryRequest = new OrderQueryRequest();
BeanUtils.copyProperties(myOrderQueryRequest, orderQueryRequest);
QueryWrapper<Orders> queryWrapper = ordersService.getQueryWrapper(orderQueryRequest);
if (loginUser.getUserRole().equals(UserConstant.BUSINESS_ROLE)) {
// 商家获取订单
Business loginBusiness = businessService.getLoginBusiness(request);
queryWrapper.eq("businessId", loginBusiness.getId());
} else {
// 用户获取订单
queryWrapper.eq("userId", loginUser.getId());
}
Page<Orders> ordersPage = ordersService.page(new Page<>(current, size),
queryWrapper);
Page<OrdersVO> ordersVOPage = new Page<>(current, size, ordersPage.getTotal());
List<OrdersVO> ordersVOList = ordersService.getOrdersVO(ordersPage.getRecords());
ordersVOPage.setRecords(ordersVOList);
return ResultUtils.success(ordersVOPage);
}
/**
* 订单统计
*/
@PostMapping("/count")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
public BaseResponse<String> ordersCount(@RequestBody OrderCountRequest orderCountRequest) {
String type = orderCountRequest.getType();
Integer state = orderCountRequest.getState();
Long businessId = orderCountRequest.getBusinessId();
String startTime = orderCountRequest.getStartTime();
String endTime = orderCountRequest.getEndTime();
ThrowUtils.throwIf(StringUtils.isBlank(type), ErrorCode.PARAMS_ERROR);
QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(state != null, "state", state);
queryWrapper.eq(businessId != null, "businessId", businessId);
return getStringBaseResponse(type, startTime, endTime, queryWrapper);
}
/**
* 订单金额统计
*/
@PostMapping("/count/money")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
public BaseResponse<List<BigDecimal>> ordersCountMoney(@RequestBody OrderCountRequest orderCountRequest) {
// 获取查询类型
String type = orderCountRequest.getType();
ThrowUtils.throwIf(StringUtils.isBlank(type), ErrorCode.PARAMS_ERROR);
OrderQueryRequest orderQueryRequest = new OrderQueryRequest();
BeanUtils.copyProperties(orderCountRequest, orderQueryRequest);
List<BigDecimal> moneyCountList = new ArrayList<>();
if (type.equals("week")) {
LocalDate today = LocalDate.now();
DateTimeFormatter startFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00");
DateTimeFormatter endFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59");
// 遍历查询7天数据放入数组
for (int i = 0; i <= 6; i++) {
LocalDate date = today.minusDays(i);
orderQueryRequest.setStartTime(date.format(startFormatter));
orderQueryRequest.setEndTime(date.format(endFormatter));
QueryWrapper<Orders> queryWrapper = ordersService.getQueryWrapper(orderQueryRequest);
List<Orders> ordertList = ordersService.list(queryWrapper);
BigDecimal money = new BigDecimal("0");
for (Orders order : ordertList) {
money = money.add(order.getTotalPrice());
}
moneyCountList.add(money);
}
} else {
QueryWrapper<Orders> queryWrapper = ordersService.getQueryWrapper(orderQueryRequest);
List<Orders> ordertList = ordersService.list(queryWrapper);
BigDecimal money = new BigDecimal("0");
for (Orders order : ordertList) {
money = money.add(order.getTotalPrice());
}
moneyCountList.add(money);
}
return ResultUtils.success(moneyCountList);
}
/**
* 订单数量统计
*/
@PostMapping("/count/number")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
public BaseResponse<List<Long>> ordersCountNumber(@RequestBody OrderCountRequest orderCountRequest) {
// 获取查询类型
String type = orderCountRequest.getType();
ThrowUtils.throwIf(StringUtils.isBlank(type), ErrorCode.PARAMS_ERROR);
OrderQueryRequest orderQueryRequest = new OrderQueryRequest();
BeanUtils.copyProperties(orderCountRequest, orderQueryRequest);
List<Long> numberCountList = new ArrayList<>();
if (type.equals("week")) {
LocalDate today = LocalDate.now();
DateTimeFormatter startFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00");
DateTimeFormatter endFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59");
// 遍历查询7天数据放入数组
for (int i = 0; i <= 6; i++) {
LocalDate date = today.minusDays(i);
orderQueryRequest.setStartTime(date.format(startFormatter));
orderQueryRequest.setEndTime(date.format(endFormatter));
QueryWrapper<Orders> queryWrapper = ordersService.getQueryWrapper(orderQueryRequest);
long count = ordersService.count(queryWrapper );
numberCountList.add(count);
}
} else {
QueryWrapper<Orders> queryWrapper = ordersService.getQueryWrapper(orderQueryRequest);
long count = ordersService.count(queryWrapper);
numberCountList.add(count);
}
return ResultUtils.success(numberCountList);
}
/**
* 订单统计(web端)
*/
@PostMapping("/count/web")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
public BaseResponse<String> ordersCountByWeb(@RequestBody OrderCountRequest orderCountRequest) {
String type = orderCountRequest.getType();
Integer state = orderCountRequest.getState();
String businessName = orderCountRequest.getBusinessName();
Long businessState = orderCountRequest.getBusinessState();
String startTime = orderCountRequest.getStartTime();
String endTime = orderCountRequest.getEndTime();
Long categoryId = orderCountRequest.getCategoryId();
List<Long> businessIdList = new ArrayList<>();
ThrowUtils.throwIf(StringUtils.isBlank(type), ErrorCode.PARAMS_ERROR);
if (categoryId != null || businessName != null || businessState != null) {
QueryWrapper<Business> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(businessName), "businessName", businessName);
wrapper.eq(businessState != null, "state", businessState);
wrapper.eq(categoryId != null, "categoryId", categoryId);
List<Business> businessList = businessService.list(wrapper);
if (CollectionUtils.isEmpty(businessList)) {
return ResultUtils.success("0");
}
businessIdList = businessList.stream().map(Business::getId).collect(Collectors.toList());
}
QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(state != null, "state", state);
queryWrapper.in(!CollectionUtils.isEmpty(businessIdList), "businessId", businessIdList);
return getStringBaseResponse(type, startTime, endTime, queryWrapper);
}
private BaseResponse<String> getStringBaseResponse(String type, String startTime, String endTime, QueryWrapper<Orders> queryWrapper) {
queryWrapper.ge(StringUtils.isNotBlank(startTime), "createTime", startTime);
queryWrapper.le(StringUtils.isNotBlank(endTime), "createTime", endTime);
if (type.equals("money")) {
List<Orders> ordertList = ordersService.list(queryWrapper);
BigDecimal money = new BigDecimal("0");
for (Orders order : ordertList) {
money = money.add(order.getTotalPrice());
}
String strMoney = String.valueOf(money);
return ResultUtils.success(strMoney);
} else if (type.equals("number")) {
long count = ordersService.count(queryWrapper);
String strNumber = String.valueOf(count);
return ResultUtils.success(strNumber);
} else {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "type不正确");
}
}
}

View File

@ -0,0 +1,41 @@
package com.bsz.school_send_back_end.controller;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.service.OssService;
import com.bsz.school_send_back_end.common.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@Api(tags = "阿里云文件管理")
@RestController
@RequestMapping("/fileOss")
public class OssController {
@Resource
private OssService ossService;
/**
* 上传头像
*
* @param file
* @return
*/
@ApiOperation(value = "文件上传")
@PostMapping("/upload")
public BaseResponse<String> uploadOssFile(@RequestParam(required = false) MultipartFile file) {
//获取上传的文件
if (file.isEmpty()) {
return null;
}
//返回上传到oss的路径
String url = ossService.uploadFileAvatar(file);
//返回r对象
return ResultUtils.success(url);
}
}

View File

@ -0,0 +1,149 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bsz.school_send_back_end.annotation.AuthCheck;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.contant.UserConstant;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.domain.Business;
import com.bsz.school_send_back_end.model.domain.Specifications;
import com.bsz.school_send_back_end.model.domain.SpecificationsDishes;
import com.bsz.school_send_back_end.model.dto.attribute.AttributeAddRequest;
import com.bsz.school_send_back_end.model.dto.attribute.AttributeUpdateRequest;
import com.bsz.school_send_back_end.model.dto.specifications.SpecificationsAddRequest;
import com.bsz.school_send_back_end.model.dto.specifications.SpecificationsMyQueryRequest;
import com.bsz.school_send_back_end.model.dto.specifications.SpecificationsQueryRequest;
import com.bsz.school_send_back_end.model.dto.specifications.SpecificationsUpdateRequest;
import com.bsz.school_send_back_end.model.vo.SpecificationsVO;
import com.bsz.school_send_back_end.service.AttributeService;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.SpecificationsDishesService;
import com.bsz.school_send_back_end.service.SpecificationsService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Slf4j
@RestController
@Tag(name = "规格接口")
@RequestMapping("/specifications")
public class SpecificationsController {
@Resource
private SpecificationsService specificationsService;
@Resource
private SpecificationsDishesService specificationsDishesService;
@Resource
private BusinessService businessService;
@Resource
private AttributeService attributeService;
/**
* 添加规格
* @param specificationsAddRequest 添加请求体
* @param request 网络请求
* @return 是否成功
*/
@PostMapping("/add")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
@Transactional(rollbackFor = Exception.class)
public BaseResponse<Boolean> addSpecifications(@RequestBody SpecificationsAddRequest specificationsAddRequest, HttpServletRequest request){
if (specificationsAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Specifications specifications = new Specifications();
BeanUtils.copyProperties(specificationsAddRequest,specifications);
//校验请求体
specificationsService.validSpecifications(specifications, false);
//添加规格和属性
List<AttributeAddRequest> attributeAddRequests = specificationsAddRequest.getAttributeAddRequests();
Boolean aBoolean = specificationsService.addSpecifications(specifications, attributeAddRequests, request);
ThrowUtils.throwIf(!aBoolean, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**·
* 更新规格
* @param specificationsUpdateRequest 更新请求体
* @param request 网络请求
* @return 是否成功
*/
@PostMapping("/update")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
@Transactional(rollbackFor = Exception.class)
public BaseResponse<Boolean> updateSpecifications(@RequestBody SpecificationsUpdateRequest specificationsUpdateRequest, HttpServletRequest request) {
if (specificationsUpdateRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Specifications specifications = new Specifications();
BeanUtils.copyProperties(specificationsUpdateRequest,specifications);
//校验
specificationsService.validSpecifications(specifications,true);
//更新规格和属性
List<AttributeUpdateRequest> attributeUpdateRequests = specificationsUpdateRequest.getAttributeUpdateRequests();
Boolean aBoolean = specificationsService.updateSpecifications(specifications, attributeUpdateRequests, request);
ThrowUtils.throwIf(!aBoolean, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**
* 根据菜品id获取规格脱敏信息
* @param specificationsMyQueryRequest 请求体
* @return 脱敏列表
*/
@PostMapping("/list/specificationsVOByDishesId")
public BaseResponse<List<SpecificationsVO>> specificationsVOByDishesId(@RequestBody SpecificationsMyQueryRequest specificationsMyQueryRequest) {
if (specificationsMyQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long dishesId = specificationsMyQueryRequest.getId();
//根据id获取中间表数据
QueryWrapper<SpecificationsDishes> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("dishesId",dishesId);
List<SpecificationsDishes> list = specificationsDishesService.list(queryWrapper);
//根据中间表数据中的规格获取规格信息和属性
return ResultUtils.success(specificationsDishesService.getSpecificationsAddAttribute(list));
}
/**
* 获取脱敏列表
* @param specificationsQueryRequest 前端请求
* @param request 网络请求
* @return 脱敏列表
*/
@PostMapping("/list/specificationsVO")
public BaseResponse<List<SpecificationsVO>> specificationsVOList(@RequestBody SpecificationsQueryRequest specificationsQueryRequest, HttpServletRequest request) {
//获取商家id
Business loginBusiness = businessService.getLoginBusiness(request);
Long businessId = loginBusiness.getId();
//获取商家的规格表
String specificationsName = specificationsQueryRequest.getSpecificationsName();
QueryWrapper<Specifications> queryWrapper = new QueryWrapper<>();
queryWrapper.like(StringUtils.isNotBlank(specificationsName), "specificationsName", specificationsName);
queryWrapper.eq("businessId",businessId);
List<Specifications> list = specificationsService.list(queryWrapper);
//对规格信息脱敏
List<SpecificationsVO> specificationsVO = specificationsService.getSpecificationsVO(list);
//获取各规格的属性脱敏信息
return ResultUtils.success(attributeService.getBySpecificationsVoId(specificationsVO));
}
}

View File

@ -0,0 +1,77 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.domain.Systeminfo;
import com.bsz.school_send_back_end.model.dto.system.SystemAddRequest;
import com.bsz.school_send_back_end.model.dto.system.SystemDeleteRequest;
import com.bsz.school_send_back_end.model.dto.system.SystemQueryRequest;
import com.bsz.school_send_back_end.service.SysteminfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
@Slf4j
@RequestMapping("/system")
public class SystemInfoController {
@Resource
private SysteminfoService systeminfoService;
/**
* 添加功能
*/
@PostMapping("/add")
public BaseResponse<Boolean> addInfo (@RequestBody SystemAddRequest systemAddRequest) {
if (systemAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Systeminfo systeminfo = new Systeminfo();
BeanUtils.copyProperties(systemAddRequest, systeminfo);
ThrowUtils.throwIf(systeminfo.getContent() == null, ErrorCode.PARAMS_ERROR, "内容为空");
boolean save = systeminfoService.save(systeminfo);
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true, "添加成功");
}
/**
* 删除功能
*/
@PostMapping("/delete")
public BaseResponse<Boolean> deleteInfo (@RequestBody SystemDeleteRequest deleteRequest) {
if (deleteRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
boolean remove = systeminfoService.removeById(deleteRequest.getId());
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "添加失败");
return ResultUtils.success(true,"删除成功");
}
/**
*查询列表
*/
@PostMapping("/list")
public BaseResponse<List<Systeminfo>> selectInfo (@RequestBody SystemQueryRequest common) {
if (common == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
LambdaQueryWrapper<Systeminfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Systeminfo::getType, common.getType());
List<Systeminfo> list = systeminfoService.list(queryWrapper);
return ResultUtils.success(list,"查询成功");
}
}

View File

@ -0,0 +1,86 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsz.school_send_back_end.annotation.AuthCheck;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.contant.UserConstant;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.model.domain.Business;
import com.bsz.school_send_back_end.model.domain.Systemlog;
import com.bsz.school_send_back_end.model.dto.log.LogQueryRequest;
import com.bsz.school_send_back_end.model.vo.BusinessLogVO;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.SystemlogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/log")
@Slf4j
public class SystemLogController {
@Resource
private BusinessService businessService;
@Resource
private SystemlogService systemlogService;
/**
* 分页获取商家系统日志列表
*/
@PostMapping("/business/logs")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Page<BusinessLogVO>> getLogByPage(@RequestBody LogQueryRequest logQueryRequest) {
if (logQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
long current = logQueryRequest.getCurrent();
long pageSize = logQueryRequest.getPageSize();
//根据手机号获取用户id
String businessPhone = logQueryRequest.getBusinessPhone();
if (StringUtils.isNotBlank(businessPhone)) {
LambdaQueryWrapper<Business> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Business::getBusinessPhone, businessPhone);
Business business = businessService.getOne(wrapper);
if (business == null) {
logQueryRequest.setUserId((long) -1);
}
else {
logQueryRequest.setUserId(business.getUserId());
}
}
Page<Systemlog> systemlogPage = systemlogService.page(new Page<>(current, pageSize),
systemlogService.getQueryWrapper(logQueryRequest));
List<Systemlog> systemlogList = systemlogPage.getRecords();
List<BusinessLogVO> businessLogVOList = systemlogList.stream().map(item -> {
BusinessLogVO businessLogVO = new BusinessLogVO();
BeanUtils.copyProperties(item, businessLogVO);
//查询商家信息
Long userId = item.getUserId();
Business business = null;
if (userId != null && userId > -1) {
QueryWrapper<Business> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userId", userId);
business = businessService.getOne(queryWrapper);
}
businessLogVO.setBusiness(business);
return businessLogVO;
}).collect(Collectors.toList());
Page<BusinessLogVO> businessLogVOPage = new Page<>(current, pageSize, systemlogPage.getTotal());
businessLogVOPage.setRecords(businessLogVOList);
return ResultUtils.success(businessLogVOPage);
}
}

View File

@ -0,0 +1,381 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsz.school_send_back_end.annotation.AuthCheck;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.contant.UserConstant;
import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.vo.LoginUserVO;
import com.bsz.school_send_back_end.model.dto.user.*;
import com.bsz.school_send_back_end.common.ResultUtils;
import com.bsz.school_send_back_end.exception.BusinessException;
import com.bsz.school_send_back_end.mapper.UserMapper;
import com.bsz.school_send_back_end.model.domain.User;
import com.bsz.school_send_back_end.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import static com.bsz.school_send_back_end.contant.UserConstant.*;
/**
* 用户接口
*/
@RestController
@RequestMapping("/user")
public class UserController {
@Resource
private UserService userService;
@Resource
private UserMapper userMapper;
/**
* 用户注册请求接口
*
* @param userRegisterRequest
* @return
*/
@PostMapping("/register")
public BaseResponse<Long> userRegister(@RequestBody UserRegisterRequest userRegisterRequest) {
if (userRegisterRequest == null){
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
}
String userAccount = userRegisterRequest.getUserAccount();
String userPassword = userRegisterRequest.getUserPassword();
String checkPassword = userRegisterRequest.getCheckPassword();
if (StringUtils.isAllBlank(userAccount, userPassword, checkPassword)) {
return ResultUtils.error(ErrorCode.PARAMS_ERROR);
}
long result = userService.userRegister(userAccount, userPassword, checkPassword);
return ResultUtils.success(result);
}
/**
* 用户登录请求接口
*
* @param userLoginRequest
* @param request 前端请求对象
* @return
*/
@PostMapping("/login")
public BaseResponse<LoginUserVO> userLogin(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request) {
if (userLoginRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
}
String userAccount = userLoginRequest.getUserAccount();
String userPassword = userLoginRequest.getUserPassword();
if (StringUtils.isAllBlank(userAccount, userPassword)){
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
}
LoginUserVO loginUserVO = userService.userLogin(userAccount, userPassword, request);
return ResultUtils.success(loginUserVO);
}
/*
@GetMapping("/search")
public BaseResponse<List<User>> searchUsers( String username, HttpServletRequest request) {
if (!isAdmin(request)){
throw new BusinessException(ErrorCode.NO_AUTH, "缺少管理员权限");
}
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
if (StringUtils.isNotBlank(username)) {
queryWrapper.like("userAccount", username);
}
List<User> userList = userService.list(queryWrapper);
List<User> list = userList.stream().map(user -> userService.getSafetyUser(user)).collect(Collectors.toList());
return ResultUtils.success(list);
}*/
/**
* 查询用户
*
* @param searchRequest
* @param request
* @return
*/
@GetMapping("/search")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<List<User>> searchUsers(UserSearchRequest searchRequest, HttpServletRequest request) {
String username = searchRequest.getUsername();
String userAccount = searchRequest.getUserAccount();
Integer gender = searchRequest.getGender();
String phone = searchRequest.getPhone();
String email = searchRequest.getEmail();
Integer userStatus = searchRequest.getUserStatus();
String userRole = searchRequest.getUserRole();
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
Date updateTime = searchRequest.getUpdateTime();
Date createTime = searchRequest.getCreateTime();
//校验
// username
if (StringUtils.isNotBlank(username)) {
queryWrapper.like("username", username);
}
// userAccount
if (StringUtils.isNotBlank(userAccount)) {
queryWrapper.like("userAccount", userAccount);
}
// gender
if (gender != null) {
queryWrapper.eq("gender", gender);
}
// phone
if (StringUtils.isNotBlank(phone)) {
queryWrapper.like("phone", phone);
}
// email
if (StringUtils.isNotBlank(email)) {
queryWrapper.like("email", email);
}
// userStatus
if (userStatus != null) {
queryWrapper.eq("userStatus", userStatus);
}
//userRole
if (userRole != null) {
queryWrapper.eq("userRole", userRole);
}
if (updateTime != null) {
queryWrapper.like("updateTime", updateTime);
}
if (createTime != null) {
queryWrapper.like("createTime", createTime);
}
List<User> userList = userService.list(queryWrapper);
List<User> users = userList.stream().map(userService::getSafetyUser).collect(Collectors.toList());
return ResultUtils.success(users);
}
/**
* 用户注销的接口
*
* @param request
* @return
*/
@PostMapping("/logout")
public BaseResponse<Integer> userLogout(HttpServletRequest request) {
if (request == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
}
int logoutResult = userService.userLogout(request);
return ResultUtils.success(logoutResult);
}
/**
* 获取当前的用户
* @param request
* @return
*/
@GetMapping("/current")
public BaseResponse<LoginUserVO> getCurrenUser(HttpServletRequest request) {
//获取登录态
User user = userService.getLoginUser(request);
return ResultUtils.success(userService.getLoginUserVO(user));
}
/**
* 新增用户
*
* @param userAddRequest
* @param request
* @return
*/
@PostMapping("/add")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Long> addUser(@RequestBody UserAddRequest userAddRequest, HttpServletRequest request) {
if (userAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
}
User user = new User();
String userAccount = userAddRequest.getUserAccount();
String userPassword = userAddRequest.getUserPassword();
if (StringUtils.isAllEmpty(userAccount,userPassword)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR,"未输入账号和密码");
}
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userAccount", userAccount);
Long count = userMapper.selectCount(queryWrapper);
if (count > 0){
throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在相同用户");
}
BeanUtils.copyProperties(userAddRequest, user);
String encryptPassword = DigestUtils.md5DigestAsHex((USER_SALT + userPassword).getBytes());
user.setUserPassword(encryptPassword);
boolean result = userService.save(user);
if (!result) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "操作失败");
}
return ResultUtils.success(user.getId());
}
/**
* 删除用户
*
* @param deleteRequest
* @param request
* @return
*/
@PostMapping("delete")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> deleteUser(@RequestBody UserDeleteRequest deleteRequest, HttpServletRequest request) {
if (deleteRequest == null || deleteRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
boolean removeUser = userService.removeById(deleteRequest.getId());
return ResultUtils.success(removeUser);
}
/**
* 更新用户
*
* @param userUpdateRequest
* @param request
* @return
*/
@PostMapping("/update")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> updateUser(@RequestBody UserUpdateRequest userUpdateRequest , HttpServletRequest request) {
if (userUpdateRequest == null || userUpdateRequest.getId() == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数错误");
}
User user = new User();
BeanUtils.copyProperties(userUpdateRequest, user);
boolean result = userService.updateById(user);
if (!result) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "未找到该用户");
}
return ResultUtils.success(true);
}
/**
* 根据 id 获取用户仅管理员
*
* @param id id
* @return 用户信息
*/
@GetMapping("/getById")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<User> getUserById(long id, HttpServletRequest request) {
if (id <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
User user = userService.getById(id);
ThrowUtils.throwIf(user == null, ErrorCode.PARAMS_ERROR);
return ResultUtils.success(user);
}
/**
* 分页获取用户列表仅管理员
*
* @return 用户列表
*/
@PostMapping("/list/page")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Page<User>> listUserByPage(@RequestBody UserSearchRequest userSearchRequest, HttpServletRequest request) {
long current = userSearchRequest.getCurrent();
long size = userSearchRequest.getPageSize();
Page<User> userPage = userService.page(new Page<>(current, size),
userService.getQueryWrapper(userSearchRequest));
return ResultUtils.success(userPage);
}
/**
* 用户自己更新个人信息
*
* @param userUpdateMyRequest
* @param request
* @return
*/
@PostMapping("/update/my")
@ApiOperation(value = "用户更新信息")
public BaseResponse<Boolean> updateMyUser(@RequestBody UserUpdateMyRequest userUpdateMyRequest,
HttpServletRequest request) {
if (userUpdateMyRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
User loginUser = userService.getLoginUser(request);
User user = new User();
BeanUtils.copyProperties(userUpdateMyRequest, user);
user.setId(loginUser.getId());
boolean result = userService.updateById(user);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**
* 修改密码
*
* @param updatePasswordRequest
* @param request
* @return
*/
@PostMapping("/update/password")
@ApiOperation(value = "用户密码更改")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> updateUserPassword(@RequestBody UserUpdatePasswordRequest updatePasswordRequest,
HttpServletRequest request) {
boolean updateUserPassword = userService.updateUserPassword(updatePasswordRequest, request);
if (updateUserPassword) {
return ResultUtils.success(true);
} else {
return ResultUtils.error(ErrorCode.OPERATION_ERROR);
}
}
// /**
// * 用户登录(支付宝)
// */
// /**
// * 用户登录支付宝
// */
// @GetMapping("/login/alipay")
// public BaseResponse<LoginUserVO> userLoginByAlipay(HttpServletRequest request, @RequestParam("authCode") String authCode) {
// AlipaySystemOauthTokenResponse oauthTokenResponse;
// try {
// // 获取access_token openId
// oauthTokenResponse = Factory.Base.OAuth().getToken(authCode);
// String accessToken = oauthTokenResponse.getAccessToken();
// // 获取用户信息
// JSONObject userInfo = AlipayUtils.getUserInfo(accessToken);
// String openId = userInfo.getStr("open_id");
// return ResultUtils.success(userService.userLoginByAlipay(openId, userInfo, request));
// } catch (Exception e) {
// throw new BusinessException(ErrorCode.SYSTEM_ERROR, "登录失败,系统错误");
// }
// }
}

View File

@ -0,0 +1,49 @@
package com.bsz.school_send_back_end.exception;
import com.bsz.school_send_back_end.common.ErrorCode;
/**
* 自定义异常类
*
*/
public class BusinessException extends RuntimeException {
/**
* 异常码
*/
private final int code;
/**
* 描述
*/
private final String description;
public BusinessException(String message, int code, String description) {
super(message);
this.code = code;
this.description = description;
}
public BusinessException(ErrorCode errorCode) {
super(errorCode.getMessage());
this.code = errorCode.getCode();
this.description = errorCode.getDescription();
}
public BusinessException(ErrorCode errorCode, String description) {
super(errorCode.getMessage());
this.code = errorCode.getCode();
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
}

View File

@ -0,0 +1,30 @@
package com.bsz.school_send_back_end.exception;
import com.bsz.school_send_back_end.common.BaseResponse;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* 全局异常处理器
*
*/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
@ExceptionHandler(BusinessException.class)
public BaseResponse<?> businessExceptionHandler(BusinessException e) {
log.error("businessException: " + e.getMessage(), e);
return ResultUtils.error(e.getCode(), e.getMessage(), e.getDescription());
}
@ExceptionHandler(RuntimeException.class)
public BaseResponse<?> runtimeExceptionHandler(RuntimeException e) {
log.error("runtimeException", e);
return ResultUtils.error(ErrorCode.SYSTEM_ERROR, e.getMessage(), "");
}
}

View File

@ -0,0 +1,44 @@
package com.bsz.school_send_back_end.exception;
import com.bsz.school_send_back_end.common.ErrorCode;
/**
* 抛异常工具类
*/
@SuppressWarnings("all")
public class ThrowUtils {
/**
* 条件成立则抛异常
*
* @param condition 条件
* @param runtimeException 运行时异常
*/
public static void throwIf(boolean condition, RuntimeException runtimeException) {
if (condition) {
throw runtimeException;
}
}
/**
* 条件成立则抛异常
*
* @param condition 条件
* @param errorCode 自定义异常
*/
public static void throwIf(boolean condition, ErrorCode errorCode) {
throwIf(condition, new BusinessException(errorCode));
}
/**
* 条件成立则抛异常
*
* @param condition 条件
* @param errorCode 自定义异常
* @param message 报错信息
*/
public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
throwIf(condition, new BusinessException(errorCode, message));
}
}

View File

@ -0,0 +1,15 @@
package com.bsz.school_send_back_end.mapper;
import com.bsz.school_send_back_end.model.domain.Attribute;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author xy
*/
public interface AttributeMapper extends BaseMapper<Attribute> {
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.mapper;
import com.bsz.school_send_back_end.model.domain.BusinessAuth;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author Lenovo
* @description 针对表business_auth(商家认证)的数据库操作Mapper
* @createDate 2024-06-24 21:01:17
* @Entity com.bsz.school_send_back_end.model.domain.BusinessAuth
*/
public interface BusinessAuthMapper extends BaseMapper<BusinessAuth> {
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.mapper;
import com.bsz.school_send_back_end.model.domain.Business;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author Lenovo
* @description 针对表business(商家)的数据库操作Mapper
* @createDate 2024-06-24 21:01:17
* @Entity com.bsz.school_send_back_end.model.domain.Business
*/
public interface BusinessMapper extends BaseMapper<Business> {
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.mapper;
import com.bsz.school_send_back_end.model.domain.Cart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author pc
* @description 针对表cart(购物车表)的数据库操作Mapper
* @createDate 2024-08-13 13:59:13
* @Entity com.bsz.school_send_back_end.model.domain.Cart
*/
public interface CartMapper extends BaseMapper<Cart> {
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.mapper;
import com.bsz.school_send_back_end.model.domain.Category;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author pc
* @description 针对表category(分类表)的数据库操作Mapper
* @createDate 2024-09-01 18:09:04
* @Entity com.bsz.school_send_back_end.model.domain.Category
*/
public interface CategoryMapper extends BaseMapper<Category> {
}

View File

@ -0,0 +1,15 @@
package com.bsz.school_send_back_end.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bsz.school_send_back_end.model.domain.DishesGroup;
/**
* @author bsz
*/
public interface DishesGroupMapper extends BaseMapper<DishesGroup> {
}

View File

@ -0,0 +1,19 @@
package com.bsz.school_send_back_end.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bsz.school_send_back_end.model.domain.Dishes;
/**
* @author pc
* @description 针对表dishes(菜品表)的数据库操作Mapper
* @createDate 2024-06-29 17:23:31
* @Entity com.bsz.school_send_back_end.model.domain.Dishes
*/
public interface DishesMapper extends BaseMapper<Dishes> {
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.mapper;
import com.bsz.school_send_back_end.model.domain.OrderDetails;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author Lenovo
* @description 针对表order_details(订单详情表)的数据库操作Mapper
* @createDate 2024-09-12 12:31:48
* @Entity com.bsz.school_send_back_end.model.domain.OrderDetails
*/
public interface OrderDetailsMapper extends BaseMapper<OrderDetails> {
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.mapper;
import com.bsz.school_send_back_end.model.domain.Orders;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author Lenovo
* @description 针对表orders(订单表)的数据库操作Mapper
* @createDate 2024-09-12 12:31:49
* @Entity com.bsz.school_send_back_end.model.domain.Orders
*/
public interface OrdersMapper extends BaseMapper<Orders> {
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.mapper;
import com.bsz.school_send_back_end.model.domain.SpecificationsDishes;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author pc
* @description 针对表specifications_dishes(菜品和规格的中间表)的数据库操作Mapper
* @createDate 2024-06-29 21:18:25
* @Entity generator.domain.SpecificationsDishes
*/
public interface SpecificationsDishesMapper extends BaseMapper<SpecificationsDishes> {
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bsz.school_send_back_end.model.domain.Specifications;
/**
* @author pc
* @description 针对表specifications(规格表)的数据库操作Mapper
* @createDate 2024-06-29 21:10:34
* @Entity com.bsz.school_send_back_end.model.domain.Specifications
*/
public interface SpecificationsMapper extends BaseMapper<Specifications> {
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.mapper;
import com.bsz.school_send_back_end.model.domain.Systeminfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author pc
* @description 针对表systeminfo(系统信息)的数据库操作Mapper
* @createDate 2024-09-23 19:16:42
* @Entity com.bsz.school_send_back_end.model.domain.Systeminfo
*/
public interface SysteminfoMapper extends BaseMapper<Systeminfo> {
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.mapper;
import com.bsz.school_send_back_end.model.domain.Systemlog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author pc
* @description 针对表systemlog(系统信息)的数据库操作Mapper
* @createDate 2024-09-25 15:40:09
* @Entity com.bsz.school_send_back_end.model.domain.Systemlog
*/
public interface SystemlogMapper extends BaseMapper<Systemlog> {
}

View File

@ -0,0 +1,21 @@
package com.bsz.school_send_back_end.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bsz.school_send_back_end.model.domain.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
/**
* @author bsz
* @description 针对表user(用户)的数据库操作Mapper
* @createDate 2024-05-09 20:59:59
*
*/
@Mapper
public interface UserMapper extends BaseMapper<User> {
}

View File

@ -0,0 +1,59 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 属性表
* @TableName attribute
*/
@TableName(value ="attribute")
@Data
public class Attribute implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 商家id
*/
private Long businessId;
/**
* 规格id
*/
private Long specificationsId;
/**
* 属性名称
*/
private String attributeName;
/**
* 属性状态:0在售,1停售
*/
private Integer attributeStatus;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
@Serial
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,106 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 商家
*
* @TableName business
*/
@TableName(value = "business")
@Data
public class Business implements Serializable {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 用户id
*/
private Long userId;
/**
* 门店名称
*/
private String businessName;
/**
* 门店头像
*/
private String businessAvatar;
/**
* 门店手机号
*/
private String businessPhone;
/**
* 店铺详细地址
*/
private String address;
/**
* 门店简介
*/
private String businessProfile;
/**
* 商家相册
*/
private String businessImages;
/**
* 分类id
*/
private Long categoryId;
/**
* 开始营业时间
*/
private String startBusiness;
/**
* 结束营业时间
*/
private String endBusiness;
/**
* 状态:0禁用,1启用
*/
private Integer state;
/**
* 店铺状态:0休业,1营业
*/
private Integer storeStatus;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 是否删除
*/
@TableLogic
private Integer isDelete;
@Serial
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,72 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 商家
* @TableName business_auth
*/
@TableName(value ="business_auth")
@Data
public class BusinessAuth implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 店铺id
*/
private Long businessId;
/**
* 店主名
*/
private String shopkeeper;
/**
* 营业执照
*/
private String license;
/**
* 身份证正面
*/
private String frontIdCard;
/**
* 身份证反面
*/
private String backIdCard;
/**
* 银行卡号
*/
private String bankCard;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 是否删除
*/
@TableLogic
private Integer isDelete;
@Serial
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,80 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;
/**
* 购物车表
* @TableName cart
*/
@TableName(value ="cart")
@Data
public class Cart implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 用户id
*/
private Long userId;
/**
* 商家id
*/
private Long businessId;
/**
* 加入购物车时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 菜品id
*/
private Long dishesId;
/**
* 商品数量
*/
private Integer quantity;
/**
* 当前选择规格的价格
*/
private BigDecimal price;
/**
* 小计单价 * 数量
*/
private BigDecimal subtotal;
/**
* 已选规格属性列表
*/
private String selectedOptions;
/**
* 是否删除
*/
private Integer isDelete;
@Serial
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,46 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 分类表
* @TableName category
*/
@TableName(value ="category")
@Data
public class Category implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 分类名
*/
private String name;
/**
* 分类图片
*/
private String image;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,83 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 菜品表
* @TableName dishes
*/
@TableName(value ="dishes")
@Data
public class Dishes implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 商家id
*/
private Long businessId;
/**
* 菜品分组id
*/
private Long dishesGroupId;
/**
* 菜品名称
*/
private String dishesName;
/**
* 菜品图片
*/
private String dishesImage;
/**
* 菜品价格
*/
private Double dishesPrice;
/**
* 打包费
*/
private Double packPrice;
/**
* 库存数量
*/
private Integer inventoryStatus;
/**
* 菜品状态上架下架
*/
private String status;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 是否删除
*/
@TableLogic
private Integer isDelete;
@Serial
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,57 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 菜品分组表
* @TableName dishes_group
*/
@TableName(value ="dishes_group")
@Data
public class DishesGroup implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 商家id
*/
private Long businessId;
/**
* 菜品分组名称
*/
private String groupName;
/**
* 是否置顶:0不置顶,1置顶
*/
private Integer isTopping;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 是否删除
*/
@TableLogic
private Integer isDelete;
@Serial
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,73 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;
/**
* 订单详情表
* @TableName order_details
*/
@TableName(value ="order_details")
@Data
public class OrderDetails implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 关联的订单id
*/
private Long orderId;
/**
* 关联的菜品id
*/
private Long dishesId;
/**
* 购买数量
*/
private Integer quantity;
/**
* 单价
*/
private BigDecimal price;
/**
* 小计单价 * 数量
*/
private BigDecimal subtotal;
/**
* 规格属性列表
*/
private String attributeNames;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间OrderDetailsServiceImpl
* OrdersServiceImpl
*/
private Date updateTime;
/**
* 是否删除
*/
private Integer isDelete;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,97 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;
/**
* 订单表
* @TableName orders
*/
@TableName(value ="orders")
@Data
public class Orders implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 取餐码
*/
private String pickupCode;
/**
* 姓名
*/
private String userName;
/**
* 手机号
*/
private String phone;
/**
* 下单用户id
*/
private Long userId;
/**
* 商家id
*/
private Long businessId;
/**
* 订单实际总价
*/
private BigDecimal totalPrice;
/**
* 取餐方式(0堂食 1自提)
*/
private Integer pickupMethod;
/**
* 支付方式0微信支付
*/
private Integer payMethod;
/**
* 取餐时间
*/
private Date pickupTime;
/**
* 备注
*/
private String notes;
/**
* 订单状态:0未支付 1已完成 2已退款 3已取消
*/
private Integer state;
/**
* 下单时间
*/
private Date createTime;
/**
* 支付时间
*/
private Date updateTime;
/**
* 是否删除
*/
private Integer isDelete;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,52 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 规格表
* @TableName specifications
*/
@Data
@TableName(value ="specifications")
public class Specifications implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 商家id
*/
private Long businessId;
/**
* 规格名称
*/
private String specificationsName;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 是否删除
*/
@TableLogic
private Integer isDelete;
@Serial
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,53 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 菜品和规格的中间表
* @TableName specifications_dishes
*/
@TableName(value ="specifications_dishes")
@Data
public class SpecificationsDishes implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 菜品id
*/
private Long dishesId;
/**
* 规格id
*/
private Long specificationsId;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 是否删除
*/
@TableLogic
private Integer isDelete;
@Serial
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,41 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 系统信息
* @TableName systeminfo
*/
@TableName(value ="systeminfo")
@Data
public class Systeminfo implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 类型:0公告,1轮播图
*/
private Integer type;
/**
* 功能内容
*/
private String content;
/**
* 创建时间
*/
private Date createTime;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,46 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 系统信息
* @TableName systemlog
*/
@TableName(value ="systemlog")
@Data
public class Systemlog implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 用户id
*/
private Long userId;
/**
* 操作内容
*/
private String content;
/**
* ip地址
*/
private String ip;
/**
* 创建时间
*/
private Date createTime;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,96 @@
package com.bsz.school_send_back_end.model.domain;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 用户
* @TableName user
*/
@TableName(value ="user")
@Data
public class User implements Serializable {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 支付宝开放平台id
*/
private String unionId;
/**
* openId
*/
private String openId;
/**
* 用户昵称
*/
private String username;
/**
* 账号
*/
private String userAccount;
/**
* 用户头像
*/
private String avatarUrl;
/**
* 性别
*/
private Integer gender;
/**
* 密码
*/
private String userPassword;
/**
* 电话
*/
private String phone;
/**
* 邮箱
*/
private String email;
/**
* 状态 0 -正常
*/
private Integer userStatus;
/**
* 创建时间
*/
private Date createTime;
/**
*
*/
private Date updateTime;
/**
* 是否删除
*/
@TableLogic
private Integer isDelete;
/**
* 用户角色 0 - 普通用户 1 - 管理员 2 - 商家
*/
private String userRole;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,20 @@
package com.bsz.school_send_back_end.model.dto;
import lombok.Data;
import java.io.Serializable;
/**
* 通用请求
*/
@Data
@SuppressWarnings("all")
public class CommonRequest implements Serializable {
/**
* id
*/
private Long id;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,61 @@
package com.bsz.school_send_back_end.model.dto.Dishes;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
public class DishesAddRequest implements Serializable {
/**
* 该菜品的规格id列表
*/
private List<Long> specificationsIds;
/**
* 商家id
*/
private Long businessId;
/**
* 菜品分组id
*/
private Long dishesGroupId;
/**
* 菜品名称
*/
private String dishesName;
/**
* 菜品图片
*/
private String dishesImage;
/**
* 菜品价格
*/
private Double dishesPrice;
/**
* 打包费
*/
private Double packPrice;
/**
* 库存数量
*/
private Integer inventoryStatus;
/**
* 菜品状态上架下架
*/
private String status;
@Serial
private static final long serialVersionUID = 4275284130550579408L;
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.model.dto.Dishes;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class DishesDeleteRequest implements Serializable {
/**
* id
*/
private Long id;
@Serial
private static final long serialVersionUID = 3490090832442230078L;
}

View File

@ -0,0 +1,33 @@
package com.bsz.school_send_back_end.model.dto.Dishes;
import com.bsz.school_send_back_end.model.dto.PageRequest;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class DishesQueryRequest extends PageRequest implements Serializable {
/**
* 商家id
*/
private Long businessId;
/**
* 菜品分组id
*/
private Long dishesGroupId;
/**
* 菜品名称
*/
private String dishesName;
/**
* 菜品状态上架下架
*/
private String status;
@Serial
private static final long serialVersionUID = 7657901721509360225L;
}

View File

@ -0,0 +1,64 @@
package com.bsz.school_send_back_end.model.dto.Dishes;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
public class DishesUpdateRequest implements Serializable {
/**
* id
*/
private Long id;
/**
* 该菜品的规格id列表
*/
private List<Long> specificationsIds;
/**
* 商家id
*/
private Long businessId;
/**
* 菜品分组id
*/
private Long dishesGroupId;
/**
* 菜品名称
*/
private String dishesName;
/**
* 菜品图片
*/
private String dishesImage;
/**
* 菜品价格
*/
private Double dishesPrice;
/**
* 打包费
*/
private Double packPrice;
/**
* 库存数量
*/
private Integer inventoryStatus;
/**
* 菜品状态上架下架
*/
private String status;
@Serial
private static final long serialVersionUID = 692981642677866302L;
}

View File

@ -0,0 +1,23 @@
package com.bsz.school_send_back_end.model.dto.DishesGroup;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class DishesGroupAddRequest implements Serializable {
/**
* 菜品分组名称
*/
private String groupName;
/**
* 是否置顶:0不置顶,1置顶
*/
private Integer isTopping;
@Serial
private static final long serialVersionUID = -3305541981600216983L;
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.model.dto.DishesGroup;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class DishesGroupDeleteRequest implements Serializable {
/**
* id
*/
private Long id;
@Serial
private static final long serialVersionUID = 1451141219473984015L;
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.model.dto.DishesGroup;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class DishesGroupQueryRequest implements Serializable {
/**
* 商家id
*/
private Long businessId;
@Serial
private static final long serialVersionUID = -5330731551871723003L;
}

View File

@ -0,0 +1,28 @@
package com.bsz.school_send_back_end.model.dto.DishesGroup;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class DishesGroupUpdateRequest implements Serializable {
/**
* id
*/
private Long id;
/**
* 菜品分组名称
*/
private String groupName;
/**
* 是否置顶:0不置顶,1置顶
*/
private Integer isTopping;
@Serial
private static final long serialVersionUID = 96052001253631145L;
}

View File

@ -0,0 +1,33 @@
package com.bsz.school_send_back_end.model.dto;
import com.bsz.school_send_back_end.contant.CommonConstant;
import lombok.Data;
/**
* 分页请求
*
* @author bsz
*/
@Data
public class PageRequest {
/**
* 当前页号
*/
private long current = 1;
/**
* 页面大小
*/
private long pageSize = 10;
/**
* 排序字段
*/
private String sortField;
/**
* 排序顺序默认升序
*/
private String sortOrder = CommonConstant.SORT_ORDER_ASC;
}

View File

@ -0,0 +1,29 @@
package com.bsz.school_send_back_end.model.dto.attribute;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 属性添加请求体
*
* @author xy
*/
@Data
public class AttributeAddRequest implements Serializable {
/**
* 属性名称
*/
private String attributeName;
/**
* 属性状态:0在售,1停售
*/
private Integer attributeStatus;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,31 @@
package com.bsz.school_send_back_end.model.dto.attribute;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* @author xy
*/
@Data
public class AttributeUpdateRequest implements Serializable {
/**
* 属性id
*/
private Long id;
/**
* 属性名称
*/
private String attributeName;
/**
* 属性状态:0在售,1停售
*/
private Integer attributeStatus;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,98 @@
package com.bsz.school_send_back_end.model.dto.business;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 商家添加请求
*
* @TableName business
*/
@Data
public class BusinessAddRequest implements Serializable {
@Serial
private static final long serialVersionUID = -923925091426442746L;
/**
* 账号
*/
private String userAccount;
/**
* 密码
*/
private String userPassword;
/**
* 门店名
*/
private String businessName;
/**
* 门店头像
*/
private String businessAvatar;
/**
* 门店手机号
*/
private String businessPhone;
/**
* 店铺详细地址
*/
private String address;
/**
* 门店简介
*/
private String businessProfile;
/**
* 商家相册
*/
private String businessImages;
/**
* 分类id
*/
private Long categoryId;
/**
* 店主名
*/
private String shopkeeper;
/**
* 营业执照
*/
private String license;
/**
* 身份证正面
*/
private String frontIdCard;
/**
* 身份证反面
*/
private String backIdCard;
/**
* 银行卡号
*/
private String bankCard;
/**
* 开始营业时间
*/
private String startBusiness;
/**
* 结束营业时间
*/
private String endBusiness;
}

View File

@ -0,0 +1,61 @@
package com.bsz.school_send_back_end.model.dto.business;
import com.bsz.school_send_back_end.model.dto.PageRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* 商家查询请求体
*
* @TableName business
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class BusinessQueryRequest extends PageRequest implements Serializable {
/**
* id
*/
private Long id;
/**
* 用户id
*/
private Long userId;
/**
* 门店名称
*/
private String businessName;
/**
* 门店地址
*/
private String address;
/**
* 门店简介
*/
private String businessProfile;
/**
* 分类id
*/
private Long categoryId;
/**
* 状态:0禁用,1启用
*/
private Integer state;
/**
* 店铺状态:0休业,1营业
*/
private Integer storeStatus;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,66 @@
package com.bsz.school_send_back_end.model.dto.business;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 商家添加请求
*/
@Data
public class BusinessUpdateMyRequest implements Serializable {
/**
* 门店昵称
*/
private String businessName;
/**
* 门店头像
*/
private String businessAvatar;
/**
* 手机号
*/
private String businessPhone;
/**
* 店铺详细地址
*/
private String address;
/**
* 门店简介
*/
private String businessProfile;
/**
* 商家相册
*/
private String businessImages;
/**
* 分类id
*/
private Long categoryId;
/**
* 开始营业时间
*/
private String startBusiness;
/**
* 结束营业时间
*/
private String endBusiness;
/**
* 店铺状态:0休业,1营业
*/
private Integer storeStatus;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,83 @@
package com.bsz.school_send_back_end.model.dto.business;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 商家更新请求
*
*/
@Data
public class BusinessUpdateRequest implements Serializable {
@Serial
private static final long serialVersionUID = -3591512809067116995L;
/**
* id
*/
private Long id;
/**
* 用户id
*/
private Long userId;
/**
* 门店昵称
*/
private String businessName;
/**
* 门店头像
*/
private String businessAvatar;
/**
* 门店手机号
*/
private String businessPhone;
/**
* 店铺详细地址
*/
private String address;
/**
* 门店简介
*/
private String businessProfile;
/**
* 商家相册
*/
private String businessImages;
/**
* 分类id
*/
private Long categoryId;
/**
* 开始营业时间
*/
private String startBusiness;
/**
* 结束营业时间
*/
private String endBusiness;
/**
* 状态:0禁用,1启用
*/
private Integer state;
/**
* 店铺状态:0休业,1营业
*/
private Integer storeStatus;
}

View File

@ -0,0 +1,36 @@
package com.bsz.school_send_back_end.model.dto.cart;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* @author xy
*/
@Data
public class CartAddRequest implements Serializable {
/**
* 商家id
*/
private Long businessId;
/**
* 关联的菜品id
*/
private Long dishesId;
/**
* 菜品数量
*/
private Integer quantity;
/**
* 已选规格属性列表
*/
private String selectedOptions = "";
@Serial
private static final long serialVersionUID = 4086381861303093101L;
}

View File

@ -0,0 +1,21 @@
package com.bsz.school_send_back_end.model.dto.cart;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* @author xy
*/
@Data
public class CartDeleteRequest implements Serializable {
/**
* id
*/
private Long id;
@Serial
private static final long serialVersionUID = 4086381861303093101L;
}

View File

@ -0,0 +1,21 @@
package com.bsz.school_send_back_end.model.dto.cart;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* @author xy
*/
@Data
public class CartQueryRequest implements Serializable {
/**
* id
*/
private Long id;
@Serial
private static final long serialVersionUID = 4086381861303093101L;
}

View File

@ -0,0 +1,42 @@
package com.bsz.school_send_back_end.model.dto.cart;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* @author xy
*/
@Data
public class CartUpdateRequest implements Serializable {
/**
* id
*/
private Long id;
/**
* 关联的菜品id
*/
private Long dishesId;
/**
* 菜品数量
*/
private Integer quantity;
/**
* 是否加入有规格的菜品
*/
private Boolean isSelectedOptions = false;
/**
* 已选规格属性列表
*/
private String selectedOptions = "";
@Serial
private static final long serialVersionUID = 4086381861303093101L;
}

View File

@ -0,0 +1,23 @@
package com.bsz.school_send_back_end.model.dto.category;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class CategoryAddRequest implements Serializable {
/**
* 分类名
*/
private String name;
/**
* 分类图片
*/
private String image;
@Serial
private static final long serialVersionUID = -8266948446201272634L;
}

View File

@ -0,0 +1,18 @@
package com.bsz.school_send_back_end.model.dto.category;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class CategoryDeleteRequest implements Serializable {
/**
* id
*/
private Long id;
@Serial
private static final long serialVersionUID = -8266948446201272634L;
}

View File

@ -0,0 +1,30 @@
package com.bsz.school_send_back_end.model.dto.category;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class CategoryUpdateRequest implements Serializable {
/**
* id
*/
private Long id;
/**
* 分类名
*/
private String name;
/**
* 分类图片
*/
private String image;
@Serial
private static final long serialVersionUID = -8266948446201272634L;
}

View File

@ -0,0 +1,19 @@
package com.bsz.school_send_back_end.model.dto.file;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class UploadFileRequest implements Serializable {
/**
* 业务
*/
private String biz;
@Serial
private static final long serialVersionUID = 5633491538829896175L;
}

View File

@ -0,0 +1,47 @@
package com.bsz.school_send_back_end.model.dto.log;
import com.bsz.school_send_back_end.model.dto.PageRequest;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
*系统信息查询请求
*/
@Data
public class LogQueryRequest extends PageRequest implements Serializable{
/**
* 用户id
*/
private Long userId;
/**
* 手机号
*/
private String businessPhone;
/**
* 操作内容
*/
private String content;
/**
* ip
*/
private String ip;
/**
* 开始时间
*/
private String startTime;
/**
* 结束时间
*/
private String endTime;
@Serial
private static final long serialVersionUID = 2952253938605974287L;
}

View File

@ -0,0 +1,44 @@
package com.bsz.school_send_back_end.model.dto.order;
import com.bsz.school_send_back_end.model.dto.PageRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* 我的订单查询请求
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class MyOrderQueryRequest extends PageRequest implements Serializable {
/**
* id
*/
private Long id;
/**
* 取餐方式(0堂食 1自提)
*/
private Integer pickupMethod;
/**
* 订单状态:0未支付 1已完成 2已取消
*/
private Integer state;
/**
* 开始时间
*/
private String startTime;
/**
* 结束时间
*/
private String endTime;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,63 @@
package com.bsz.school_send_back_end.model.dto.order;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
/**
* 订单创建请求
*/
@Data
public class OrderAddRequest implements Serializable {
/**
* 姓名
*/
private String userName;
/**
* 手机号
*/
private String phone;
/**
* 商家id
*/
private Long businessId;
/**
* 订单实际总价
*/
private BigDecimal totalPrice;
/**
* 取餐方式(0堂食 1自提)
*/
private Integer pickupMethod;
/**
* 支付方式
*/
private Integer payMethod;
/**
* 取餐时间
*/
private String pickupTime;
/**
* 备注
*/
private String notes;
/**
* 订单详情
*/
private List<OrderDetailAddRequest> orderDetailAddRequest;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,48 @@
package com.bsz.school_send_back_end.model.dto.order;
import lombok.Data;
@Data
public class OrderCountRequest {
/**
* 商家id
*/
private Long businessId;
/**
* 商家名称
*/
private String businessName;
/**
* 商家状态
*/
private Long businessState;
/**
* 餐厅分类
*/
private Long categoryId;
/**
* 类型
*/
private String type;
/**
* 支付状态
*/
private Integer state;
/**
* 开始时间
*/
private String startTime;
/**
* 结束时间
*/
private String endTime;
}

View File

@ -0,0 +1,33 @@
package com.bsz.school_send_back_end.model.dto.order;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 订单详情创建请求
*/
@Data
public class OrderDetailAddRequest implements Serializable {
/**
* 关联的菜品id
*/
private Long dishesId;
/**
* 购买数量
*/
private Integer quantity;
/**
* 规格属性列表
*/
private String attributeNames;
@Serial
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,58 @@
package com.bsz.school_send_back_end.model.dto.order;
import com.bsz.school_send_back_end.model.dto.PageRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* 订单查询请求
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class OrderQueryRequest extends PageRequest implements Serializable {
/**
* id
*/
private Long id;
/**
* 下单用户id
*/
private Long userId;
/**
* 商家id
*/
private Long businessId;
/**
* 取餐码
*/
private String pickupCode;
/**
* 取餐方式(0堂食 1自提)
*/
private Integer pickupMethod;
/**
* 订单状态:0未支付 1已完成 2已取消
*/
private Integer state;
/**
* 开始时间
*/
private String startTime;
/**
* 结束时间
*/
private String endTime;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,25 @@
package com.bsz.school_send_back_end.model.dto.specifications;
import com.bsz.school_send_back_end.model.dto.attribute.AttributeAddRequest;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
public class SpecificationsAddRequest implements Serializable {
/**
* 规格名称
*/
private String specificationsName;
/**
* 属性请求体列表
*/
private List<AttributeAddRequest> attributeAddRequests;
@Serial
private static final long serialVersionUID = -2573217224030065261L;
}

View File

@ -0,0 +1,21 @@
package com.bsz.school_send_back_end.model.dto.specifications;
import lombok.Data;
import java.io.Serializable;
/**
* 用户删除请求
*
* @author bsz
*/
@Data
public class SpecificationsMyQueryRequest implements Serializable {
/**
* id
*/
private Long id;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,21 @@
package com.bsz.school_send_back_end.model.dto.specifications;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* @author ASUS
*/
@Data
public class SpecificationsQueryRequest implements Serializable {
/**
* 规格名称
*/
private String specificationsName;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,30 @@
package com.bsz.school_send_back_end.model.dto.specifications;
import com.bsz.school_send_back_end.model.dto.attribute.AttributeUpdateRequest;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
public class SpecificationsUpdateRequest implements Serializable {
/**
* 规格id
*/
private Long id;
/**
* 规格名称
*/
private String specificationsName;
/**
* 属性请求体列表
*/
private List<AttributeUpdateRequest> attributeUpdateRequests;
@Serial
private static final long serialVersionUID = -2573217224030065261L;
}

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