增加了评分接口(测试版)
This commit is contained in:
parent
a5d69bdf75
commit
7e0de7039e
|
@ -0,0 +1,24 @@
|
|||
package com.cj.jiaqingjiayi.contant;
|
||||
|
||||
/**
|
||||
* 文件常量
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public interface FileConstant {
|
||||
|
||||
/**
|
||||
* COS 访问地址
|
||||
*/
|
||||
String COS_HOST = "xxxxxxxxxxxxxxxxxxxx";
|
||||
|
||||
/**
|
||||
* 服务器访问地址
|
||||
*/
|
||||
String SERVER_HOST = "154.8.193.216:9494";
|
||||
|
||||
/**
|
||||
* 服务器上传路径
|
||||
*/
|
||||
String SERVER_UPLOAD_DIR = "/www/wwwroot/images";
|
||||
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package com.cj.jiaqingjiayi.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
||||
import com.cj.jiaqingjiayi.common.BaseResponse;
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.common.ResultUtils;
|
||||
import com.cj.jiaqingjiayi.exception.BusinessException;
|
||||
import com.cj.jiaqingjiayi.exception.ThrowUtils;
|
||||
import com.cj.jiaqingjiayi.model.CommonRequest;
|
||||
import com.cj.jiaqingjiayi.model.domain.Collect;
|
||||
import com.cj.jiaqingjiayi.model.domain.User;
|
||||
import com.cj.jiaqingjiayi.model.request.collect.CollectAddRequest;
|
||||
import com.cj.jiaqingjiayi.service.CollectService;
|
||||
import com.cj.jiaqingjiayi.service.UserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
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 javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/collect")
|
||||
@Api(tags = "收藏接口")
|
||||
public class CollectController {
|
||||
|
||||
@Resource
|
||||
private CollectService collectService;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 添加收藏
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@ApiOperation(value = "添加收藏")
|
||||
public BaseResponse<Boolean> addCollect(@RequestBody CollectAddRequest collectAddRequest, HttpServletRequest request) {
|
||||
if (collectAddRequest == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
collectService.validCollect(collectAddRequest);
|
||||
Collect collect = new Collect();
|
||||
BeanUtils.copyProperties(collectAddRequest, collect);
|
||||
Boolean result = collectService.addCollect(collect, request);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.SYSTEM_ERROR);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一条收藏
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation(value = "删除一条收藏")
|
||||
public BaseResponse<Boolean> deleteCollect(@RequestBody CommonRequest commonRequest) {
|
||||
if (commonRequest == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
Long id = commonRequest.getId();
|
||||
LambdaQueryWrapper<Collect> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Collect::getId, id);
|
||||
boolean remove = collectService.remove(wrapper);
|
||||
ThrowUtils.throwIf(!remove, ErrorCode.SYSTEM_ERROR);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除所有收藏
|
||||
*/
|
||||
@PostMapping("/delete/all")
|
||||
@ApiOperation(value = "删除所有收藏")
|
||||
public BaseResponse<Boolean> deleteCollectAll(HttpServletRequest request) {
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
Long loginUserId = loginUser.getId();
|
||||
LambdaQueryWrapper<Collect> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Collect::getUserId, loginUserId);
|
||||
boolean remove = collectService.remove(wrapper);
|
||||
ThrowUtils.throwIf(!remove, ErrorCode.SYSTEM_ERROR);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有收藏
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@ApiOperation(value = "查询所有收藏")
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
package com.cj.jiaqingjiayi.controller;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
|
||||
import com.cj.jiaqingjiayi.common.BaseResponse;
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.common.ResultUtils;
|
||||
import com.cj.jiaqingjiayi.contant.FileConstant;
|
||||
import com.cj.jiaqingjiayi.exception.BusinessException;
|
||||
import com.cj.jiaqingjiayi.model.domain.User;
|
||||
import com.cj.jiaqingjiayi.model.request.UploadFileRequest;
|
||||
import com.cj.jiaqingjiayi.service.UserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.cj.jiaqingjiayi.model.enums.FileUploadBizEnum;
|
||||
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);
|
||||
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, "文件类型错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.cj.jiaqingjiayi.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
|
||||
import com.cj.jiaqingjiayi.common.BaseResponse;
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.common.ResultUtils;
|
||||
import com.cj.jiaqingjiayi.exception.BusinessException;
|
||||
import com.cj.jiaqingjiayi.exception.ThrowUtils;
|
||||
import com.cj.jiaqingjiayi.model.CommonRequest;
|
||||
import com.cj.jiaqingjiayi.model.domain.User;
|
||||
import com.cj.jiaqingjiayi.model.domain.UserRating;
|
||||
import com.cj.jiaqingjiayi.model.request.userRating.UserRatingAddRequest;
|
||||
import com.cj.jiaqingjiayi.service.UserRatingService;
|
||||
import com.cj.jiaqingjiayi.service.UserService;
|
||||
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 javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/level")
|
||||
public class UserRatingController {
|
||||
|
||||
@Resource
|
||||
private UserRatingService userRatingService;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 添加用户评分
|
||||
* @param userRatingAddRequest 用户评分请求
|
||||
* @param request 当期那登录用户
|
||||
* @return 是否添加成功
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public BaseResponse<Boolean> addRating (@RequestBody UserRatingAddRequest userRatingAddRequest, HttpServletRequest request) {
|
||||
if (userRatingAddRequest == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
|
||||
UserRating userRating = new UserRating();
|
||||
BeanUtils.copyProperties(userRatingAddRequest, userRating);
|
||||
userRatingService.validUserRating(userRating, request);
|
||||
boolean save = userRatingService.save(userRating);
|
||||
ThrowUtils.throwIf(!save, ErrorCode.SYSTEM_ERROR, "添加失败");
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户评分
|
||||
* @param commonRequest 用户评分id
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public BaseResponse<Boolean> deleteUserRating (@RequestBody CommonRequest commonRequest) {
|
||||
if (commonRequest == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
boolean remove = userRatingService.removeById(commonRequest.getId());
|
||||
ThrowUtils.throwIf(!remove, ErrorCode.SYSTEM_ERROR, "删除失败");
|
||||
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示当前用户评分
|
||||
* @param request 当前用户
|
||||
* @return 评分列表
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public BaseResponse<List<UserRating>> listUserRating (HttpServletRequest request) {
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
Long userId = loginUser.getId();
|
||||
List<UserRating> list = userRatingService.list(Wrappers.<UserRating>lambdaQuery().eq(UserRating::getUserId, userId));
|
||||
return ResultUtils.success(list);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.cj.jiaqingjiayi.mapper;
|
||||
|
||||
import com.cj.jiaqingjiayi.model.domain.BusinessLevel;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【business_level】的数据库操作Mapper
|
||||
* @createDate 2024-12-02 14:13:25
|
||||
* @Entity com.cj.jiaqingjiayi.model.domain.BusinessLevel
|
||||
*/
|
||||
public interface BusinessLevelMapper extends BaseMapper<BusinessLevel> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.cj.jiaqingjiayi.mapper;
|
||||
|
||||
import com.cj.jiaqingjiayi.model.domain.Collect;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【collect(收藏)】的数据库操作Mapper
|
||||
* @createDate 2024-12-02 14:11:46
|
||||
* @Entity com.cj.jiaqingjiayi.model.domain.Collect
|
||||
*/
|
||||
public interface CollectMapper extends BaseMapper<Collect> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.cj.jiaqingjiayi.mapper;
|
||||
|
||||
import com.cj.jiaqingjiayi.model.domain.UserRating;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【user_rating(用户评分)】的数据库操作Mapper
|
||||
* @createDate 2024-12-02 14:14:23
|
||||
* @Entity com.cj.jiaqingjiayi.model.domain.UserRating
|
||||
*/
|
||||
public interface UserRatingMapper extends BaseMapper<UserRating> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.cj.jiaqingjiayi.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 business_level
|
||||
*/
|
||||
@TableName(value ="business_level")
|
||||
@Data
|
||||
public class BusinessLevel implements Serializable {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
*/
|
||||
private Long businessId;
|
||||
|
||||
/**
|
||||
* 综合评分
|
||||
*/
|
||||
private BigDecimal averageScore;
|
||||
|
||||
/**
|
||||
* 等级
|
||||
*/
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.cj.jiaqingjiayi.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 lombok.Data;
|
||||
|
||||
/**
|
||||
* 收藏
|
||||
* @TableName collect
|
||||
*/
|
||||
@TableName(value ="collect")
|
||||
@Data
|
||||
public class Collect implements Serializable {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
*/
|
||||
private Long businessId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.cj.jiaqingjiayi.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 user_rating
|
||||
*/
|
||||
@TableName(value ="user_rating")
|
||||
@Data
|
||||
public class UserRating implements Serializable {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
*/
|
||||
private Long businessId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 评分
|
||||
*/
|
||||
private Integer rating;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.cj.jiaqingjiayi.model.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public enum FileUploadBizEnum {
|
||||
USER_AVATAR("头像", "user_avatar"),
|
||||
|
||||
DISHES_IMAGE("商品", "commodities"),
|
||||
|
||||
CARD_IMAGE("证件", "card"),
|
||||
|
||||
SYSTEM_IMAGE("系统", "system");
|
||||
|
||||
|
||||
private final String text;
|
||||
|
||||
private final String value;
|
||||
|
||||
FileUploadBizEnum(String text, String value) {
|
||||
this.text = text;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值列表
|
||||
*/
|
||||
public static List<String> getValues() {
|
||||
return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 value获取枚举
|
||||
*/
|
||||
public static FileUploadBizEnum getEnumByValue(String value) {
|
||||
if (ObjectUtils.isEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (FileUploadBizEnum fileEnum : FileUploadBizEnum.values()) {
|
||||
if (fileEnum.value.equals(value)) {
|
||||
return fileEnum;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.cj.jiaqingjiayi.model.request;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class UploadFileRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* 业务
|
||||
*/
|
||||
@Schema(description = "业务标识,例如:user_avatar,commodities,card,system")
|
||||
private String biz;
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 5633491538829896175L;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.cj.jiaqingjiayi.model.request.collect;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CollectAddRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
*/
|
||||
private Long businessId;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.cj.jiaqingjiayi.model.request.order;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderCountRequest {
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
*/
|
||||
private Long businessId;
|
||||
|
||||
/**
|
||||
* 商家名称
|
||||
*/
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 商家状态
|
||||
*/
|
||||
private Long businessState;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
*/
|
||||
private Integer paymentStatus;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private String startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private String endTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.cj.jiaqingjiayi.model.request.userRating;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class UserRatingAddRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
*/
|
||||
private Long businessId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 评分
|
||||
*/
|
||||
private Integer rating;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.cj.jiaqingjiayi.service;
|
||||
|
||||
import com.cj.jiaqingjiayi.model.domain.BusinessLevel;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【business_level】的数据库操作Service
|
||||
* @createDate 2024-12-02 14:13:25
|
||||
*/
|
||||
public interface BusinessLevelService extends IService<BusinessLevel> {
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.cj.jiaqingjiayi.service;
|
||||
|
||||
import com.cj.jiaqingjiayi.model.domain.Collect;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.cj.jiaqingjiayi.model.request.collect.CollectAddRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【collect(收藏)】的数据库操作Service
|
||||
* @createDate 2024-12-02 14:11:46
|
||||
*/
|
||||
public interface CollectService extends IService<Collect> {
|
||||
|
||||
/**
|
||||
* 校验
|
||||
*/
|
||||
void validCollect(CollectAddRequest collectAddRequest);
|
||||
|
||||
/**
|
||||
* 添加收藏
|
||||
*/
|
||||
Boolean addCollect(Collect collect, HttpServletRequest request);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.cj.jiaqingjiayi.service;
|
||||
|
||||
import com.cj.jiaqingjiayi.model.domain.UserRating;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【user_rating(用户评分)】的数据库操作Service
|
||||
* @createDate 2024-12-02 14:14:23
|
||||
*/
|
||||
public interface UserRatingService extends IService<UserRating> {
|
||||
|
||||
/**
|
||||
* 校验
|
||||
*/
|
||||
void validUserRating(UserRating userRating, HttpServletRequest request);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.cj.jiaqingjiayi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cj.jiaqingjiayi.model.domain.BusinessLevel;
|
||||
import com.cj.jiaqingjiayi.service.BusinessLevelService;
|
||||
import com.cj.jiaqingjiayi.mapper.BusinessLevelMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【business_level】的数据库操作Service实现
|
||||
* @createDate 2024-12-02 14:13:25
|
||||
*/
|
||||
@Service
|
||||
public class BusinessLevelServiceImpl extends ServiceImpl<BusinessLevelMapper, BusinessLevel>
|
||||
implements BusinessLevelService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.cj.jiaqingjiayi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.exception.ThrowUtils;
|
||||
import com.cj.jiaqingjiayi.model.domain.Business;
|
||||
import com.cj.jiaqingjiayi.model.domain.Collect;
|
||||
import com.cj.jiaqingjiayi.model.domain.User;
|
||||
import com.cj.jiaqingjiayi.model.request.collect.CollectAddRequest;
|
||||
import com.cj.jiaqingjiayi.service.BusinessService;
|
||||
import com.cj.jiaqingjiayi.service.CollectService;
|
||||
import com.cj.jiaqingjiayi.mapper.CollectMapper;
|
||||
import com.cj.jiaqingjiayi.service.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【collect(收藏)】的数据库操作Service实现
|
||||
* @createDate 2024-12-02 14:11:46
|
||||
*/
|
||||
@Service
|
||||
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect>
|
||||
implements CollectService{
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private BusinessService businessService;
|
||||
|
||||
@Override
|
||||
public void validCollect(CollectAddRequest collectAddRequest) {
|
||||
Long businessId = collectAddRequest.getBusinessId();
|
||||
ThrowUtils.throwIf(businessId == null, ErrorCode.PARAMS_ERROR, "参数不全");
|
||||
LambdaQueryWrapper<Business> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Business::getId, businessId);
|
||||
long count = businessService.count(wrapper);
|
||||
ThrowUtils.throwIf(count != 1, ErrorCode.PARAMS_ERROR, "填写的商家id不存在");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean addCollect(Collect collect, HttpServletRequest request) {
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
Long loginUserId = loginUser.getId();
|
||||
Long businessId = collect.getBusinessId();
|
||||
LambdaQueryWrapper<Collect> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Collect::getBusinessId, businessId);
|
||||
wrapper.eq(Collect::getUserId, loginUserId);
|
||||
long count = this.count(wrapper);
|
||||
ThrowUtils.throwIf(count > 0, ErrorCode.OPERATION_ERROR, "该商家已收藏");
|
||||
collect.setUserId(loginUserId);
|
||||
return this.save(collect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package com.cj.jiaqingjiayi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.exception.BusinessException;
|
||||
import com.cj.jiaqingjiayi.exception.ThrowUtils;
|
||||
import com.cj.jiaqingjiayi.model.domain.Orders;
|
||||
import com.cj.jiaqingjiayi.model.domain.User;
|
||||
import com.cj.jiaqingjiayi.model.domain.UserRating;
|
||||
import com.cj.jiaqingjiayi.service.OrdersService;
|
||||
import com.cj.jiaqingjiayi.service.UserRatingService;
|
||||
import com.cj.jiaqingjiayi.mapper.UserRatingMapper;
|
||||
import com.cj.jiaqingjiayi.service.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【user_rating(用户评分)】的数据库操作Service实现
|
||||
* @createDate 2024-12-02 14:14:23
|
||||
*/
|
||||
@Service
|
||||
public class UserRatingServiceImpl extends ServiceImpl<UserRatingMapper, UserRating>
|
||||
implements UserRatingService{
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private OrdersService ordersService;
|
||||
|
||||
@Override
|
||||
public void validUserRating(UserRating userRating, HttpServletRequest request) {
|
||||
|
||||
if (userRating.getRating() < 1 || userRating.getRating() > 5) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "分数不在可选范围内");
|
||||
}
|
||||
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
if (!loginUser.getId().equals(userRating.getUserId())) {
|
||||
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "当前登录用户与评分中的用户不匹配");
|
||||
}
|
||||
Orders orders = ordersService.getOne(Wrappers.<Orders>lambdaQuery().eq(Orders::getId, userRating.getOrderId()));
|
||||
ThrowUtils.throwIf(orders == null, ErrorCode.NOT_FOUND_ERROR, "订单不存在");
|
||||
ThrowUtils.throwIf(!orders.getBusinessId().equals(userRating.getBusinessId()) ,ErrorCode.NOT_FOUND_ERROR, "该商家与订单商家不一致");
|
||||
|
||||
long count = this.count(Wrappers.<UserRating>lambdaQuery().eq(UserRating::getOrderId, userRating.getOrderId()));
|
||||
ThrowUtils.throwIf(count > 0, ErrorCode.SYSTEM_ERROR, "该订单已评分");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cj.jiaqingjiayi.mapper.BusinessLevelMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.cj.jiaqingjiayi.model.domain.BusinessLevel">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="businessId" column="businessId" jdbcType="BIGINT"/>
|
||||
<result property="averageScore" column="averageScore" jdbcType="DECIMAL"/>
|
||||
<result property="level" column="level" jdbcType="TINYINT"/>
|
||||
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="updateTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,businessId,averageScore,
|
||||
level,createTime,updateTime
|
||||
</sql>
|
||||
</mapper>
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cj.jiaqingjiayi.mapper.CollectMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.cj.jiaqingjiayi.model.domain.Collect">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="userId" column="userId" jdbcType="BIGINT"/>
|
||||
<result property="businessId" column="businessId" jdbcType="BIGINT"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,userId,businessId
|
||||
</sql>
|
||||
</mapper>
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cj.jiaqingjiayi.mapper.UserRatingMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.cj.jiaqingjiayi.model.domain.UserRating">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="businessId" column="businessId" jdbcType="BIGINT"/>
|
||||
<result property="userId" column="userId" jdbcType="BIGINT"/>
|
||||
<result property="orderId" column="orderId" jdbcType="BIGINT"/>
|
||||
<result property="rating" column="rating" jdbcType="TINYINT"/>
|
||||
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,businessId,userId,
|
||||
orderId,rating,createTime
|
||||
</sql>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user