校快送 2024.12.10 v0.0.6

This commit is contained in:
tsukiyalo 2024-12-11 14:00:20 +08:00
parent f0debc7d38
commit 947b94418b
18 changed files with 240 additions and 115 deletions

View File

@ -4,22 +4,22 @@ use school_send;
create table user
(
username varchar(256) null comment '用户昵称',
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-管理员',
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;
@ -179,7 +179,7 @@ create table if not exists orders
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已取消',
state tinyint default 0 not null comment '订单状态:0未支付 1已完成 2已退款 3已取消 4已出餐 5已完成',
createTime datetime default CURRENT_TIMESTAMP not null comment '下单时间',
updateTime datetime default CURRENT_TIMESTAMP not null comment '支付时间',
isDelete tinyint default 0 not null comment '是否删除',
@ -221,9 +221,10 @@ create table if not exists cart
) comment '购物车表' collate = utf8mb4_unicode_ci;
create table demo(
id int auto_increment primary key ,
name varchar(30) comment '姓名',
create table demo
(
id int auto_increment primary key,
name varchar(30) comment '姓名',
detail varchar(256) comment '详情'
);
@ -252,23 +253,25 @@ create table private_message
# 收藏表
create table collect
(
id bigint auto_increment comment 'id' primary key ,
userId bigint not null comment '用户id',
id bigint auto_increment comment 'id' primary key,
userId bigint not null comment '用户id',
businessId bigint not null comment '商家id'
) comment '收藏';
# 用户评分表
-- 用户评分表
create table user_rating
(
id bigint auto_increment primary key comment 'id',
businessId bigint not null comment '商家id',
userId bigint not null comment '用户id',
orderId bigint not null comment '订单id',
rating tinyint not null comment '评分',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间'
id bigint auto_increment primary key comment 'id',
businessId bigint not null comment '商家id',
userId bigint not null comment '用户id',
orderId bigint not null comment '订单id',
rating tinyint not null comment '评分',
review varchar(512) null comment '评论',
businessReview varchar(512) null comment '商家回复',
createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间'
) comment '用户评分' collate = utf8mb4_unicode_ci;
# 商家等级表
-- 商家等级表
create table business_level
(
id bigint auto_increment primary key comment 'id',

View File

@ -12,7 +12,6 @@ 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.BusinessLevel;
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;
@ -21,7 +20,6 @@ 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.BusinessLevelService;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.UserService;
import lombok.extern.slf4j.Slf4j;
@ -33,7 +31,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import static com.bsz.school_send_back_end.contant.UserConstant.USER_SALT;
@ -55,9 +52,6 @@ public class BusinessController {
@Resource
private UserService userService;
@Resource
private BusinessLevelService businessLevelService;
@PostMapping("/add")
public BaseResponse<Long> addBusiness(@RequestBody BusinessAddRequest businessAddRequest) {
@ -213,8 +207,6 @@ public class BusinessController {
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());

View File

@ -10,6 +10,7 @@ import com.bsz.school_send_back_end.model.domain.Collect;
import com.bsz.school_send_back_end.model.domain.User;
import com.bsz.school_send_back_end.model.dto.CommonRequest;
import com.bsz.school_send_back_end.model.dto.collect.CollectAddRequest;
import com.bsz.school_send_back_end.model.vo.CollectVO;
import com.bsz.school_send_back_end.service.CollectService;
import com.bsz.school_send_back_end.service.UserService;
import lombok.extern.slf4j.Slf4j;
@ -84,12 +85,8 @@ public class CollectController {
* 查询所有收藏
*/
@PostMapping("/list")
public BaseResponse<List<Collect>> listCollect(HttpServletRequest request) {
User loginUser = userService.getLoginUser(request);
Long loginUserId = loginUser.getId();
LambdaQueryWrapper<Collect> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Collect::getUserId, loginUserId);
List<Collect> list = collectService.list(wrapper);
return ResultUtils.success(list);
public BaseResponse<List<CollectVO>> listCollect(HttpServletRequest request) {
List<CollectVO> collectList = collectService.getCollectList(request);
return ResultUtils.success(collectList);
}
}

View File

@ -2,7 +2,9 @@ package com.bsz.school_send_back_end.controller;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsz.school_send_back_end.annotation.AuthCheck;
@ -40,6 +42,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 订单相关接口
**/
@ -140,7 +143,7 @@ public class OrdersController {
}
/**
* 根据 id 获取订单信息仅管理员
* 根据 id 获取订单信息
*/
@GetMapping("/get/my")
public BaseResponse<OrdersVO> getOrderVOByMyId(@RequestParam Long id, HttpServletRequest request) {
@ -359,6 +362,53 @@ public class OrdersController {
.doWrite(ordersExcelVOList); // 导出的数据集合
}
@PostMapping("/delete")
@AuthCheck(mustRole = UserConstant.DEFAULT_ROLE)
public BaseResponse<Boolean> deleteOrder (@RequestBody CommonRequest commonRequest, HttpServletRequest request) {
if (commonRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long orderId = commonRequest.getId();
LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Orders::getId, orderId);
Orders orders = ordersService.getOne(wrapper);
User loginUser = userService.getLoginUser(request);
Long loginUserId = loginUser.getId();
ThrowUtils.throwIf(!orders.getUserId().equals(loginUserId), ErrorCode.OPERATION_ERROR,
"当前用户不是该订单所有者");
log.info("oldOrders:" + orders);
LambdaUpdateWrapper<Orders> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(Orders::getIsDelete,1);
updateWrapper.eq(Orders::getId, orderId);
boolean update = ordersService.update(updateWrapper);
log.info("orders:" + orders);
ThrowUtils.throwIf(!update, ErrorCode.SYSTEM_ERROR);
return ResultUtils.success(true);
}
@PostMapping("/update")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
public BaseResponse<Boolean> updateOrderState(@RequestBody CommonRequest commonRequest,HttpServletRequest request) {
if (commonRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = commonRequest.getId();
LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Orders::getId, id);
Orders orders = ordersService.getOne(queryWrapper);
Business loginBusiness = businessService.getLoginBusiness(request);
Long businessId = loginBusiness.getId();
ThrowUtils.throwIf(!businessId.equals(orders.getBusinessId()), ErrorCode.FORBIDDEN_ERROR, "当前订单不属于当前登录用户");
LambdaUpdateWrapper<Orders> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(Orders::getState,4);
updateWrapper.eq(Orders::getId, id);
boolean update = ordersService.update(updateWrapper);
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR,"修改订单状态失败");
return ResultUtils.success(true);
}
private BaseResponse<String> getStringBaseResponse(String type, String startTime, String endTime, QueryWrapper<Orders> queryWrapper) {
queryWrapper.ge(StringUtils.isNotBlank(startTime), "createTime", startTime);

View File

@ -4,9 +4,7 @@ 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.AlipayTradeQueryModel;
import com.alipay.api.domain.AlipayTradeRefundModel;
import com.alipay.api.domain.*;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
@ -28,6 +26,7 @@ import com.bsz.school_send_back_end.service.OrdersService;
import com.bsz.school_send_back_end.service.UserService;
import com.bsz.school_send_back_end.service.WebsocketService;
import com.bsz.school_send_back_end.utils.RandomNumberGenerator;
import com.bsz.school_send_back_end.utils.UniqueNumberGenerator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
@ -109,7 +108,7 @@ public class TestAlipayController {
user.setOpenId(response.getOpenId());
user.setUsername(StringUtils.isAnyBlank(response1.getNickName()) ? "随机名字" + randomNumberGenerator.generateRandomNumber() : response1.getNickName());
user.setUserPassword("123456");
user.setUserAccount("用户" + randomNumberGenerator.generateRandomNumber());
user.setUserAccount("yonghu" + randomNumberGenerator.generateRandomNumber());
user.setAvatarUrl(StringUtils.isAnyBlank(response1.getAvatar()) ? "https://tfs.alipayobjects.com/images/partner/ATuihpR50zu7UAAAAAAAAAAAAADtl2AA" : response1.getAvatar());
userMapper.insert(user);
req.getSession().setAttribute(RedisKeyConstant.USER_LOGIN_STATE,user);
@ -149,22 +148,31 @@ public class TestAlipayController {
}
@GetMapping("/test/close")
public String closeOrder(String orderNo) throws AlipayApiException {
public String closeOrder(String out_trade_no, Long orderId) throws AlipayApiException {
log.info("out_trade_no:" + out_trade_no);
AlipayClients clients = new AlipayClients();
AlipayTradeCloseRequest request = new AlipayTradeCloseRequest();
AlipayTradeCloseModel model = new AlipayTradeCloseModel();
//model.setTradeNo(); 这是订单项
//订单项可能会有多个支付单
model.setTradeNo(orderNo);
model.setTradeNo(out_trade_no);
request.setBizModel(model);
request.setNotifyUrl(NOURL);
// request.setNotifyUrl(NOURL + "/close");
LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Orders::getId, orderId);
Orders orders = ordersService.getOne(queryWrapper);
log.info("orders:" + orders);
ThrowUtils.throwIf(!orders.getState().equals(0),ErrorCode.SYSTEM_ERROR,"当前订单已支付或已退款");
orders.setState(3);
boolean update = ordersService.updateById(orders);
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "修改订单状态失败");
AlipayTradeCloseResponse response = clients.alipayClient().execute(request);
//这里应该写进日志
log.info("订单已取消");
return response.getBody();
}
@ -182,20 +190,18 @@ public class TestAlipayController {
model.setOutTradeNo(orderNo);
model.setRefundAmount(String.valueOf(orders.getTotalPrice()));
//退款请求单号 要求唯一 需改
//model.setOutRequestNo("123");
String number = UniqueNumberGenerator.generateNumber();
model.setOutRequestNo(number);
log.info("outRequestNo:" + number);
request.setBizModel(model);
request.setNotifyUrl(NOURL);
AlipayTradeRefundResponse response = clients.alipayClient().execute(request);
String body = response.getBody();
ThrowUtils.throwIf(!orders.getState().equals(1),ErrorCode.SYSTEM_ERROR,"当前订单未支付");
orders.setState(2);
Date date = new Date();
orders.setUpdateTime(date);
boolean update = ordersService.updateById(orders);
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "修改订单状态失败");
log.info("orderState:" + orders.getState());
AlipayTradeRefundResponse response = clients.alipayClient().execute(request);
log.info("退款成功");
String body = response.getBody();
return body;
}

View File

@ -1,16 +1,22 @@
package com.bsz.school_send_back_end.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.User;
import com.bsz.school_send_back_end.model.domain.UserRating;
import com.bsz.school_send_back_end.model.dto.CommonRequest;
import com.bsz.school_send_back_end.model.dto.userRating.UserRatingAddRequest;
import com.bsz.school_send_back_end.model.dto.userRating.UserRatingReviewRequest;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.UserRatingService;
import com.bsz.school_send_back_end.service.UserService;
import lombok.extern.slf4j.Slf4j;
@ -35,6 +41,9 @@ public class UserRatingController {
@Resource
private UserService userService;
@Resource
private BusinessService businessService;
/**
* 添加用户评分
* @param userRatingAddRequest 用户评分请求
@ -83,4 +92,36 @@ public class UserRatingController {
List<UserRating> list = userRatingService.list(Wrappers.<UserRating>lambdaQuery().eq(UserRating::getUserId, userId));
return ResultUtils.success(list);
}
/**
* 展示当前用户评分
* @param request 当前用户
* @return 评分列表
*/
@PostMapping("/list/business")
public BaseResponse<List<UserRating>> listUserRatingByBusiness (HttpServletRequest request) {
Business loginBusiness = businessService.getLoginBusiness(request);
Long businessId = loginBusiness.getId();
List<UserRating> list = userRatingService.list(Wrappers.<UserRating>lambdaQuery()
.eq(UserRating::getBusinessId, businessId));
return ResultUtils.success(list);
}
@PostMapping("/business/reply")
@AuthCheck(mustRole = UserConstant.BUSINESS_ROLE)
public BaseResponse<Boolean> businessReply (@RequestBody UserRatingReviewRequest userRatingReviewRequest, HttpServletRequest request) {
if (userRatingReviewRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = userRatingReviewRequest.getId();
String businessReview = userRatingReviewRequest.getBusinessReview();
userRatingService.validUserRatingByBusiness(id, request);
LambdaQueryWrapper<UserRating> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserRating::getId, id);
UserRating userRating = userRatingService.getOne(wrapper);
userRating.setBusinessReview(businessReview);
boolean update = userRatingService.updateById(userRating);
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
}

View File

@ -8,7 +8,7 @@ import org.apache.ibatis.annotations.Select;
/**
* @author pc
* @description 针对表user_rating(用户评分)的数据库操作Mapper
* @createDate 2024-11-29 22:23:08
* @createDate 2024-12-09 16:06:45
* @Entity com.bsz.school_send_back_end.model.domain.UserRating
*/
public interface UserRatingMapper extends BaseMapper<UserRating> {

View File

@ -41,6 +41,16 @@ public class UserRating implements Serializable {
*/
private Integer rating;
/**
* 评论
*/
private String review;
/**
* 商家回复
*/
private String businessReview;
/**
* 创建时间
*/

View File

@ -86,6 +86,11 @@ public class BusinessVO implements Serializable {
*/
private Date createTime;
/**
* 状态:0禁用,1启用
*/
private Integer state;
/**
* 等级
*/

View File

@ -4,9 +4,12 @@ import com.bsz.school_send_back_end.model.domain.Collect;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsz.school_send_back_end.model.dto.cart.CartAddRequest;
import com.bsz.school_send_back_end.model.dto.collect.CollectAddRequest;
import com.bsz.school_send_back_end.model.vo.BusinessVO;
import com.bsz.school_send_back_end.model.vo.CollectVO;
import javax.servlet.http.HttpServletRequest;
import java.net.http.HttpClient;
import java.util.List;
/**
* @author pc
@ -25,4 +28,9 @@ public interface CollectService extends IService<Collect> {
*/
Boolean addCollect(Collect collect, HttpServletRequest request);
/**
* 根据收藏获取商家信息列表
*/
List<CollectVO> getCollectList(HttpServletRequest request);
}

View File

@ -8,7 +8,7 @@ import javax.servlet.http.HttpServletRequest;
/**
* @author pc
* @description 针对表user_rating(用户评分)的数据库操作Service
* @createDate 2024-11-29 22:23:08
* @createDate 2024-12-09 16:06:45
*/
public interface UserRatingService extends IService<UserRating> {
@ -16,4 +16,9 @@ public interface UserRatingService extends IService<UserRating> {
* 校验
*/
void validUserRating(UserRating userRating, HttpServletRequest request);
/**
* 校验商家是否能够回复用户评分
*/
void validUserRatingByBusiness(Long userRatingId, HttpServletRequest request);
}

View File

@ -13,10 +13,8 @@ import com.bsz.school_send_back_end.exception.ThrowUtils;
import com.bsz.school_send_back_end.model.domain.OrderDetails;
import com.bsz.school_send_back_end.model.domain.Orders;
import com.bsz.school_send_back_end.service.AliPayService;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.OrderDetailsService;
import com.bsz.school_send_back_end.service.OrdersService;
import com.bsz.school_send_back_end.utils.RandomNumberGenerator;
import com.bsz.school_send_back_end.utils.UniqueNumberGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -24,9 +22,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -38,9 +35,6 @@ public class AlipayServiceImpl implements AliPayService {
@Resource
private OrderDetailsService orderDetailsService;
@Resource
private BusinessService businessService;
@Override
@Transactional(rollbackFor = Exception.class)
public synchronized String createPayment(String orderId, String miniOpenId, BigDecimal amount) {
@ -64,7 +58,10 @@ public class AlipayServiceImpl implements AliPayService {
LambdaQueryWrapper<OrderDetails> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderDetails::getOrderId, orderId);
OrderDetails orderDetails = orderDetailsService.getOne(wrapper);
List<OrderDetails> orderDetailsList = orderDetailsService.list(wrapper);
String subject = orderDetailsList.stream()
.map(OrderDetails::getAttributeNames)
.collect(Collectors.joining(", "));
//给支付宝的订单号设置成取餐码
order.setPickupCode(outTradeNo);
boolean update = ordersService.updateById(order);
@ -72,7 +69,7 @@ public class AlipayServiceImpl implements AliPayService {
model.setOutTradeNo(outTradeNo);
model.setTotalAmount(String.valueOf(amount));
model.setSubject(orderDetails.getAttributeNames());
model.setSubject(subject);
model.setProductCode("JSAPI_PAY");
model.setSellerId("2088721037756350");
model.setBuyerId("2088722037756360");
@ -85,7 +82,6 @@ public class AlipayServiceImpl implements AliPayService {
try {
AlipayTradeCreateResponse response = clients.alipayClient().execute(aliRequest);
trade_no = response.getTradeNo();
if (trade_no == null) {
throw new BusinessException(ErrorCode.NULL_ERROR, "未获取到trade_no");
}

View File

@ -2,8 +2,6 @@ package com.bsz.school_send_back_end.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.mapper.UserRatingMapper;
import com.bsz.school_send_back_end.model.domain.BusinessLevel;
import com.bsz.school_send_back_end.service.BusinessLevelService;
@ -13,7 +11,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**

View File

@ -1,6 +1,7 @@
package com.bsz.school_send_back_end.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsz.school_send_back_end.common.ErrorCode;
import com.bsz.school_send_back_end.exception.ThrowUtils;
@ -8,14 +9,18 @@ import com.bsz.school_send_back_end.model.domain.Business;
import com.bsz.school_send_back_end.model.domain.Collect;
import com.bsz.school_send_back_end.model.domain.User;
import com.bsz.school_send_back_end.model.dto.collect.CollectAddRequest;
import com.bsz.school_send_back_end.model.vo.CollectVO;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.CollectService;
import com.bsz.school_send_back_end.mapper.CollectMapper;
import com.bsz.school_send_back_end.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author xy
@ -52,6 +57,24 @@ public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect>
collect.setUserId(loginUserId);
return this.save(collect);
}
@Override
public List<CollectVO> getCollectList(HttpServletRequest request) {
User loginUser = userService.getLoginUser(request);
Long loginUserId = loginUser.getId();
LambdaQueryWrapper<Collect> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Collect::getUserId, loginUserId);
List<Collect> collectList = this.list(wrapper);
return collectList.stream().map(item -> {
CollectVO collectVO = new CollectVO();
BeanUtils.copyProperties(item, collectVO);
Business business = businessService.getOne(Wrappers.<Business>lambdaQuery()
.eq(Business::getId, item.getBusinessId()));
collectVO.setBusiness(business);
return collectVO;
}).collect(Collectors.toList());
}
}

View File

@ -152,7 +152,7 @@ public class DishesServiceImpl extends ServiceImpl<DishesMapper, Dishes>
ThrowUtils.throwIf(count > 0,ErrorCode.PARAMS_ERROR,"已存在该菜品");
}
else {
ThrowUtils.throwIf(count > 0,ErrorCode.PARAMS_ERROR,"已存在该菜品");
ThrowUtils.throwIf(count > 1,ErrorCode.PARAMS_ERROR,"已存在该菜品");
}
}

View File

@ -1,13 +1,17 @@
package com.bsz.school_send_back_end.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.Business;
import com.bsz.school_send_back_end.model.domain.Orders;
import com.bsz.school_send_back_end.model.domain.User;
import com.bsz.school_send_back_end.model.domain.UserRating;
import com.bsz.school_send_back_end.service.BusinessService;
import com.bsz.school_send_back_end.service.OrdersService;
import com.bsz.school_send_back_end.service.UserRatingService;
import com.bsz.school_send_back_end.mapper.UserRatingMapper;
@ -20,7 +24,7 @@ import javax.servlet.http.HttpServletRequest;
/**
* @author pc
* @description 针对表user_rating(用户评分)的数据库操作Service实现
* @createDate 2024-11-29 22:23:08
* @createDate 2024-12-09 16:06:45
*/
@Service
public class UserRatingServiceImpl extends ServiceImpl<UserRatingMapper, UserRating>
@ -32,6 +36,9 @@ public class UserRatingServiceImpl extends ServiceImpl<UserRatingMapper, UserRat
@Resource
private OrdersService ordersService;
@Resource
private BusinessService businessService;
@Override
public void validUserRating(UserRating userRating, HttpServletRequest request) {
@ -51,6 +58,24 @@ public class UserRatingServiceImpl extends ServiceImpl<UserRatingMapper, UserRat
ThrowUtils.throwIf(count > 0, ErrorCode.SYSTEM_ERROR, "该订单已评分");
}
@Override
public void validUserRatingByBusiness(Long userRatingId, HttpServletRequest request) {
LambdaQueryWrapper<UserRating> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(UserRating::getId, userRatingId);
UserRating userRating = this.getOne(queryWrapper);
Business loginBusiness = businessService.getLoginBusiness(request);
Long businessId = loginBusiness.getId();
if (businessId.equals(userRating.getBusinessId())) {
throw new BusinessException(ErrorCode.OPERATION_ERROR,"该用户评分不属于当前商家");
}
if (StringUtils.isBlank(userRating.getReview())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "当前用户没有评论");
}
if (StringUtils.isNotBlank(userRating.getBusinessReview())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR,"当前用户评分已回复");
}
}
}

View File

@ -1,36 +0,0 @@
//package com.bsz.school_send_back_end.utils;
//
//import cn.hutool.json.JSONObject;
//import com.alipay.easysdk.factory.Factory;
//import com.alipay.easysdk.util.generic.models.AlipayOpenApiGenericResponse;
//import com.bsz.school_send_back_end.common.ErrorCode;
//import com.bsz.school_send_back_end.exception.BusinessException;
//
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 支付宝工具类
// *
// * @author 玄德
// */
//public class AlipayUtils {
//
// /**
// * 获取用户信息
// */
// public static JSONObject getUserInfo(String accessToken) throws Exception {
// Map<String, String> bizParams = new HashMap<>();
// bizParams.put("auth_token", accessToken);
// AlipayOpenApiGenericResponse userInfoResponse =
// Factory.Util.Generic().execute("alipay.user.info.share", bizParams, null);
// String httpBody = userInfoResponse.getHttpBody();
// if(httpBody == null)
// {
// throw new BusinessException(ErrorCode.SYSTEM_ERROR);
// }
// return new JSONObject(httpBody).getJSONObject("alipay_user_info_share_response");
// }
//
//}

View File

@ -10,11 +10,14 @@
<result property="userId" column="userId" jdbcType="BIGINT"/>
<result property="orderId" column="orderId" jdbcType="BIGINT"/>
<result property="rating" column="rating" jdbcType="TINYINT"/>
<result property="review" column="review" jdbcType="VARCHAR"/>
<result property="businessReview" column="businessReview" jdbcType="VARCHAR"/>
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,businessId,userId,
orderId,rating,createTime
orderId,rating,review,
businessReview,createTime
</sql>
</mapper>