完善了订单信息

This commit is contained in:
chen-xin-zhi 2024-11-13 20:21:36 +08:00
parent b4f263830f
commit 938d2472da
35 changed files with 442 additions and 171 deletions

View File

@ -0,0 +1,32 @@
package com.cultural.heritage.constant;
/**
* 正则表达式
*/
public interface RegexConstant {
/**
* 手机号正则
*/
String PHONE_REGEX = "^1[3-9]\\d{9}$";
/**
* 邮箱正则
*/
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

@ -9,10 +9,13 @@ import com.cultural.heritage.model.dto.CommonRequest;
import com.cultural.heritage.model.dto.address.AddressAddRequest;
import com.cultural.heritage.model.dto.address.AddressUpdateRequest;
import com.cultural.heritage.model.entity.Address;
import com.cultural.heritage.model.entity.User;
import com.cultural.heritage.service.address.AddressService;
import com.cultural.heritage.service.user.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
@ -33,6 +36,11 @@ public class AddressController {
private AddressService addressService;
@Resource
private UserService userService;
/**
* 添加地址信息
* @param addressAddRequest 地址添加请求体
@ -40,12 +48,16 @@ public class AddressController {
*/
@PostMapping("/add")
@Operation(summary = "小程序端用户添加地址信息", description = "参数地址添加请求体权限所有人方法名addAddress")
public BaseResponse<Boolean> addAddress(@RequestBody AddressAddRequest addressAddRequest) {
public BaseResponse<Boolean> addAddress(@RequestBody AddressAddRequest addressAddRequest, HttpServletRequest request) {
if (addressAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
Address address = new Address();
BeanUtils.copyProperties(addressAddRequest, address);
address.setUserId(userId);
addressService.validAddress(address, false);
addressService.verifyIsDefault(address);
boolean result = addressService.save(address);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
@ -61,10 +73,11 @@ public class AddressController {
*/
@PostMapping("/delete")
@Operation(summary = "小程序端用户删除地址信息", description = "参数地址删除请求体权限所有人方法名delAddress")
public BaseResponse<Boolean> delAddress(@RequestBody CommonRequest deleteRequest) {
public BaseResponse<Boolean> delAddress(@RequestBody CommonRequest deleteRequest, HttpServletRequest request) {
if (deleteRequest == null || deleteRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
userService.getLoginUser(request);
Long id = deleteRequest.getId();
boolean result = addressService.removeById(id);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
@ -81,12 +94,16 @@ public class AddressController {
*/
@PostMapping("/update")
@Operation(summary = "小程序端用户更新地址信息", description = "参数地址更新请求体权限所有人方法名updateAddress")
public BaseResponse<Boolean> updateAddress(@RequestBody AddressUpdateRequest addressUpdateRequest) {
public BaseResponse<Boolean> updateAddress(@RequestBody AddressUpdateRequest addressUpdateRequest, HttpServletRequest request) {
if (addressUpdateRequest == null || addressUpdateRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
Address address = new Address();
BeanUtils.copyProperties(addressUpdateRequest, address);
address.setUserId(userId);
addressService.validAddress(address, true);
addressService.verifyIsDefault(address);
boolean result = addressService.updateById(address);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
@ -98,17 +115,14 @@ public class AddressController {
/**
* 查询用户地址信息
* @param addressQueryRequest 地址查询请求体
* @return 用户地址列表
*/
@PostMapping("/list")
@Operation(summary = "小程序端查询用户地址信息", description = "参数:地址查询请求体,权限:所有人,方法名:listAddress")
public BaseResponse<List<Address>> listAddress(@RequestBody CommonRequest addressQueryRequest) {
if (addressQueryRequest == null || addressQueryRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = addressQueryRequest.getId();
List<Address> list = addressService.getUserAddressById(id);
@Operation(summary = "小程序端查询用户地址信息", description = "参数:无,权限:所有人,方法名:listAddress")
public BaseResponse<List<Address>> listAddress(HttpServletRequest request) {
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
List<Address> list = addressService.getUserAddressById(userId);
return ResultUtils.success(list);
}

View File

@ -9,10 +9,13 @@ import com.cultural.heritage.model.dto.CommonRequest;
import com.cultural.heritage.model.dto.contacts.ContactsAddRequest;
import com.cultural.heritage.model.dto.contacts.ContactsUpdateRequest;
import com.cultural.heritage.model.entity.Contacts;
import com.cultural.heritage.model.entity.User;
import com.cultural.heritage.service.address.ContactsService;
import com.cultural.heritage.service.user.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
@ -33,6 +36,10 @@ public class ContactsController {
private ContactsService contactsService;
@Resource
private UserService userService;
/**
* 添加联系人
* @param contactsAddRequest 联系人添加请求体
@ -40,12 +47,16 @@ public class ContactsController {
*/
@PostMapping("/add")
@Operation(summary = "小程序端用户添加联系人信息", description = "参数联系人添加请求体权限所有人方法名addContacts")
public BaseResponse<Boolean> addContacts(@RequestBody ContactsAddRequest contactsAddRequest) {
public BaseResponse<Boolean> addContacts(@RequestBody ContactsAddRequest contactsAddRequest, HttpServletRequest request) {
if (contactsAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
Contacts contacts = new Contacts();
BeanUtils.copyProperties(contactsAddRequest, contacts);
contacts.setUserId(userId);
contactsService.validContacts(contacts, false);
contactsService.verifyIsDefault(contacts);
boolean result = contactsService.save(contacts);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
@ -61,12 +72,16 @@ public class ContactsController {
*/
@PostMapping("/update")
@Operation(summary = "小程序端用户更新联系人信息", description = "参数:联系人更新请求体权限所有人方法名updateContacts")
public BaseResponse<Boolean> updateContacts(@RequestBody ContactsUpdateRequest contactsUpdateRequest) {
public BaseResponse<Boolean> updateContacts(@RequestBody ContactsUpdateRequest contactsUpdateRequest, HttpServletRequest request) {
if (contactsUpdateRequest == null || contactsUpdateRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
Contacts contacts = new Contacts();
BeanUtils.copyProperties(contactsUpdateRequest, contacts);
contacts.setUserId(userId);
contactsService.validContacts(contacts, true);
contactsService.verifyIsDefault(contacts);
boolean result = contactsService.updateById(contacts);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
@ -83,10 +98,11 @@ public class ContactsController {
*/
@PostMapping("/delete")
@Operation(summary = "小程序端用户删除联系人信息", description = "参数联系人删除请求体权限所有人方法名deleteContacts")
public BaseResponse<Boolean> deleteContacts(@RequestBody CommonRequest contactsDeleteRequest) {
public BaseResponse<Boolean> deleteContacts(@RequestBody CommonRequest contactsDeleteRequest, HttpServletRequest request) {
if (contactsDeleteRequest == null || contactsDeleteRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
userService.getLoginUser(request);
Long id = contactsDeleteRequest.getId();
boolean result = contactsService.removeById(id);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
@ -97,17 +113,14 @@ public class ContactsController {
/**
* 查询用户联系人信息
* @param contactsQueryRequest 联系人查询请求体
* @return 用户联系人列表
*/
@PostMapping("/list")
@Operation(summary = "小程序端用户查询联系人信息", description = "参数联系人查询请求体权限所有人方法名listUserContacts")
public BaseResponse<List<Contacts>> listUserContacts(@RequestBody CommonRequest contactsQueryRequest) {
if (contactsQueryRequest == null || contactsQueryRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = contactsQueryRequest.getId();
List<Contacts> list = contactsService.getUserAddressById(id);
@Operation(summary = "小程序端用户查询联系人信息", description = "参数权限所有人方法名listUserContacts")
public BaseResponse<List<Contacts>> listUserContacts(HttpServletRequest request) {
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
List<Contacts> list = contactsService.getUserContactsById(userId);
return ResultUtils.success(list);
}

View File

@ -48,7 +48,7 @@ public class FileController {
* @return 图片可访问地址
*/
@PostMapping("/upload/server/not_login")
@Operation(summary = "未登录情况下的文件上传", description = "参数:(文档上是false但biz是必传的)文件对象multipartFile), 业务类型(biz)权限所有人方法名uploadServerFileNotLogin")
@Operation(summary = "(未使用)未登录情况下的文件上传", description = "参数:(文档上是false但biz是必传的)文件对象multipartFile), 业务类型(biz)权限所有人方法名uploadServerFileNotLogin")
private BaseResponse<String> uploadServerFileNotLogin(@RequestPart("file")MultipartFile multipartFile, UploadFileRequest uploadFileRequest) {
//获取业务名称
String biz = uploadFileRequest.getBiz();

View File

@ -6,20 +6,22 @@ import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.common.ResultUtils;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.CommonRequest;
import com.cultural.heritage.model.dto.cart.CartRecordAddRequest;
import com.cultural.heritage.model.dto.cart.CartRecordUpdateRequest;
import com.cultural.heritage.model.entity.CartRecord;
import com.cultural.heritage.model.entity.Good;
import com.cultural.heritage.model.entity.User;
import com.cultural.heritage.model.vo.cart.CartOrderVO;
import com.cultural.heritage.model.vo.cart.CartRecordQueryVO;
import com.cultural.heritage.model.vo.cart.CartRecordVO;
import com.cultural.heritage.model.vo.good.GoodVO;
import com.cultural.heritage.service.good.CartRecordService;
import com.cultural.heritage.service.good.GoodService;
import com.cultural.heritage.service.user.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
@ -44,6 +46,10 @@ public class CartRecordController {
@Resource
private GoodService goodService;
@Resource
private UserService userService;
/**
* 用户添加商品至购物车
* @param cartRecordAddRequest 购物车记录添加请求体
@ -51,11 +57,11 @@ public class CartRecordController {
*/
@PostMapping("/add")
@Operation(summary = "小程序端用户添加商品至购物车", description = "参数购物车记录添加请求体权限所有人方法名addCartRecord")
public BaseResponse<Boolean> addCartRecord(@RequestBody CartRecordAddRequest cartRecordAddRequest) {
public BaseResponse<Boolean> addCartRecord(@RequestBody CartRecordAddRequest cartRecordAddRequest, HttpServletRequest request) {
if (cartRecordAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
boolean result = cartRecordService.dealAlreadyExistGood(cartRecordAddRequest);
boolean result = cartRecordService.dealAlreadyExistGood(cartRecordAddRequest, request);
return ResultUtils.success(result);
}
@ -67,13 +73,16 @@ public class CartRecordController {
*/
@PostMapping("/update")
@Operation(summary = "小程序端用户更新商品至购物车", description = "参数购物车记录更新请求体权限所有人方法名updateCartRecord")
public BaseResponse<Boolean> updateCartRecord(@RequestBody List<CartRecordUpdateRequest> cartRecordUpdateRequestList) {
public BaseResponse<Boolean> updateCartRecord(@RequestBody List<CartRecordUpdateRequest> cartRecordUpdateRequestList, HttpServletRequest request) {
if (CollectionUtils.isEmpty(cartRecordUpdateRequestList)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
List<CartRecord> cartRecordList = cartRecordUpdateRequestList.stream().map(cartRecordUpdateRequest -> {
CartRecord cartRecord = new CartRecord();
BeanUtils.copyProperties(cartRecordUpdateRequest, cartRecord);
cartRecord.setUserId(userId);
return cartRecord;
}).toList();
boolean result = cartRecordService.updateBatchById(cartRecordList);
@ -89,10 +98,11 @@ public class CartRecordController {
*/
@PostMapping("/delete")
@Operation(summary = "小程序端用户删除购物车的物品", description = "参数:购物车记录删除请求体(商品id列表如[2,3,4])权限所有人方法名deleteCart")
public BaseResponse<Boolean> deleteCart(@RequestBody List<Integer> idList) {
public BaseResponse<Boolean> deleteCart(@RequestBody List<Integer> idList, HttpServletRequest request) {
if (CollectionUtils.isEmpty(idList)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
userService.getLoginUser(request);
boolean result = cartRecordService.removeBatchByIds(idList);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
@ -101,17 +111,14 @@ public class CartRecordController {
/**
* 展示用户购物车中的商品
* @param userIdRequest 用户id请求体
* @return
*/
@PostMapping("/list")
@Operation(summary = "小程序端用户查询购物车中的商品", description = "参数购物车记录查询请求体权限所有人方法名listUserCartRecord")
public BaseResponse<List<CartRecordVO>> listUserCartRecord(@RequestBody CommonRequest userIdRequest) {
if (userIdRequest == null || userIdRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
@Operation(summary = "小程序端用户查询购物车中的商品", description = "参数权限所有人方法名listUserCartRecord")
public BaseResponse<List<CartRecordVO>> listUserCartRecord(HttpServletRequest request) {
// 根据用户id查询购物车记录
Long userId = userIdRequest.getId();
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
QueryWrapper<CartRecord> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userId", userId);
List<CartRecord> list = cartRecordService.list(queryWrapper);
@ -126,10 +133,11 @@ public class CartRecordController {
* @return 订单商品信息列表
*/
@PostMapping("/cart/list")
public BaseResponse<List<CartOrderVO>> listCartRecord(@RequestBody List<CartRecordQueryVO> cartRecordQueryVOList) {
public BaseResponse<List<CartOrderVO>> listCartRecord(@RequestBody List<CartRecordQueryVO> cartRecordQueryVOList, HttpServletRequest request) {
if (cartRecordQueryVOList == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
userService.getLoginUser(request);
List<CartOrderVO> cartOrderVOList = cartRecordQueryVOList.stream().map(cartRecordQueryVO -> {
Long goodId = cartRecordQueryVO.getGoodId();
Integer quantity = cartRecordQueryVO.getQuantity();

View File

@ -1,6 +1,7 @@
package com.cultural.heritage.controller.good;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cultural.heritage.annotation.AuthCheck;
import com.cultural.heritage.common.BaseResponse;
import com.cultural.heritage.common.ErrorCode;
@ -8,6 +9,7 @@ import com.cultural.heritage.common.ResultUtils;
import com.cultural.heritage.constant.UserConstant;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.CommonDelBatchRequest;
import com.cultural.heritage.model.dto.CommonRequest;
import com.cultural.heritage.model.dto.category.CategoryAddRequest;
import com.cultural.heritage.model.dto.category.CategoryUpdateRequest;
@ -15,12 +17,15 @@ import com.cultural.heritage.model.entity.Category;
import com.cultural.heritage.model.entity.Good;
import com.cultural.heritage.service.good.CategoryService;
import com.cultural.heritage.service.good.GoodService;
import com.cultural.heritage.service.user.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -41,11 +46,13 @@ public class CategoryController {
private CategoryService categoryService;
@Resource
private GoodService goodService;
@Resource
private UserService userService;
/**
* 添加商品类别
@ -80,13 +87,49 @@ public class CategoryController {
if (deleteCategoryRequest == null || deleteCategoryRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 删除当前类别下的所有商品
Long id = deleteCategoryRequest.getId();
// 根据类别id获取商品删除的条件
QueryWrapper<Good> queryWrapper = categoryService.getDeleteQueryWrapper(id);
List<Good> goodList = goodService.list(queryWrapper);
boolean isSuccess = goodService.removeBatchByIds(goodList);
ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR);
// 删除当前类别
boolean result = categoryService.removeById(id);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true, "类别删除成功");
}
/**
* 批量删除商品类别
* @param commonDelBatchRequest 类别删除请求体
* @return 是否删除成功
*/
@PostMapping("/delBath")
@Operation(summary = "Web端管理员批量删除商品类别", description = "参数:类别删除请求体,权限:管理员(admin, boss)方法名deleteCategory")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> delBatchCategory(@RequestBody CommonDelBatchRequest commonDelBatchRequest) {
if (commonDelBatchRequest == null || CollectionUtils.isEmpty(commonDelBatchRequest.getIdList())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
List<Long> idList = commonDelBatchRequest.getIdList();
// 删除当前类别下的所有商品
idList.forEach(id -> {
// 根据类别id获取商品删除的条件
QueryWrapper<Good> queryWrapper = categoryService.getDeleteQueryWrapper(id);
List<Good> goodList = goodService.list(queryWrapper);
boolean isSuccess = goodService.removeBatchByIds(goodList);
ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR);
// 删除当前类别
boolean result = categoryService.removeById(id);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
});
return ResultUtils.success(true, "批量删除类别成功");
}
/**
* 更新商品类别
@ -115,7 +158,8 @@ public class CategoryController {
*/
@PostMapping("/list")
@Operation(summary = "(小程序端和Web端)用户查询商品类别", description = "参数权限所有人方法名listCategory")
public BaseResponse<List<Category>> listCategory() {
public BaseResponse<List<Category>> listCategory(HttpServletRequest request) {
userService.getLoginUser(request);
List<Category> list = categoryService.list();
return ResultUtils.success(list);
}
@ -129,10 +173,11 @@ public class CategoryController {
*/
@PostMapping("/list/type")
@Operation(summary = "小程序端用户根据类别id查询该类的所有商品", description = "参数类别id方法名listGoodByCategory")
public BaseResponse<Map<Long, List<Good>>> listGoodByCategory(@RequestBody CommonRequest categoryQueryRequest) {
public BaseResponse<Map<Long, List<Good>>> listGoodByCategory(@RequestBody CommonRequest categoryQueryRequest, HttpServletRequest request) {
if (categoryQueryRequest == null || categoryQueryRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
userService.getLoginUser(request);
Long id = categoryQueryRequest.getId();
Category category = categoryService.getCategoryById(id);
String typeName = category.getTypeName();
@ -149,4 +194,7 @@ public class CategoryController {
}

View File

@ -25,6 +25,7 @@ import com.cultural.heritage.service.user.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
@ -145,12 +146,13 @@ public class CouponController {
@PostMapping("/exchange")
@Transactional(rollbackFor = Exception.class)
@Operation(summary = "小程序端用户积分兑换优惠券", description = "参数:兑换记录添加请求体,权限:管理员(admin, boss)方法名pointsExchangeCoupon")
public BaseResponse<Boolean> pointsExchangeCoupon(@RequestBody ExchangeAddRequest exchangeAddRequest) {
public BaseResponse<Boolean> pointsExchangeCoupon(@RequestBody ExchangeAddRequest exchangeAddRequest, HttpServletRequest request) {
if (exchangeAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 更新用户积分
Long userId = exchangeAddRequest.getUserId();
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
Integer requirePoints = exchangeAddRequest.getRequirePoints();
Integer quantity = exchangeAddRequest.getQuantity();
if (userId <= 0) {
@ -210,10 +212,11 @@ public class CouponController {
*/
@PostMapping("/delRecord")
@Operation(summary = "小程序端用户删除兑换记录", description = "参数:兑换记录删除请求体,权限:管理员(admin, boss)方法名deleteExchangeRecord")
public BaseResponse<Boolean> deleteExchangeRecord(@RequestBody CommonRequest commonRequest) {
public BaseResponse<Boolean> deleteExchangeRecord(@RequestBody CommonRequest commonRequest, HttpServletRequest request) {
if (commonRequest == null || commonRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
userService.getLoginUser(request);
Long id = commonRequest.getId();
boolean result = exchangeService.removeById(id);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);

View File

@ -25,9 +25,11 @@ import com.cultural.heritage.model.vo.good.ServiceGoodCardVO;
import com.cultural.heritage.model.vo.good.ServiceGoodVO;
import com.cultural.heritage.service.good.AppointmentDateService;
import com.cultural.heritage.service.good.GoodService;
import com.cultural.heritage.service.user.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
@ -51,6 +53,9 @@ public class GoodController {
private GoodService goodService;
@Resource
private UserService userService;
@Resource
private AppointmentDateService appointmentDateService;
@ -140,6 +145,7 @@ public class GoodController {
*/
@PostMapping("/delete/service")
@Operation(summary = "Web端管理员删除服务类商品", description = "参数: 商品删除请求体,权限:管理员(admin, boss)方法名deleteServiceGood")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> deleteServiceGood(@RequestBody CommonRequest deleteRequest) {
if (deleteRequest == null || deleteRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -210,7 +216,7 @@ public class GoodController {
@Operation(summary = "Web端管理员批量删除商品", description = "参数:商品批量删除请求体,权限:管理员(admin, boss)方法名delBatchGoods")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> delBatchGoods(@RequestBody CommonDelBatchRequest commonDelBatchRequest) {
List<Integer> idList = commonDelBatchRequest.getIdList();
List<Long> idList = commonDelBatchRequest.getIdList();
boolean result = goodService.removeBatchByIds(idList);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
@ -226,11 +232,12 @@ public class GoodController {
* @return 商品信息
*/
@PostMapping("/getById")
@Operation(summary = "根据id查询商品", description = "参数商品根据id查询请求体权限管理员(admin, boss), 方法名:getGoodById")
public BaseResponse<Good> getGoodById(@RequestBody CommonRequest getByIdRequest) {
@Operation(summary = "根据id查询商品", description = "参数商品根据id查询请求体权限所有人, 方法名:getGoodById")
public BaseResponse<Good> getGoodById(@RequestBody CommonRequest getByIdRequest, HttpServletRequest request) {
if (getByIdRequest == null || getByIdRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
userService.getLoginUser(request);
Long id = getByIdRequest.getId();
Good good = goodService.getById(id);
ThrowUtils.throwIf(good == null, ErrorCode.NOT_FOUND_ERROR);
@ -245,7 +252,7 @@ public class GoodController {
* @return 服务类商品列表
*/
@PostMapping("/service/list/page")
@Operation(summary = "Web端管理员分页查询服务类商品")
@Operation(summary = "Web端管理员分页查询服务类商品", description = "参数:商品查询请求体,权限:管理员(admin, boss)方法名listServiceGoodVOByPage")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Page<ServiceGoodVO>> listServiceGoodVOByPage(@RequestBody GoodQueryRequest goodQueryRequest) {
if (goodQueryRequest == null) {
@ -283,12 +290,12 @@ public class GoodController {
* @return 服务类商品信息
*/
@PostMapping("/service/list/id")
@Operation(summary = "小程序端用户根据id查询服务类商品")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<ServiceGoodVO> listServiceGoodVO(@RequestBody CommonRequest commonRequest) {
@Operation(summary = "小程序端用户根据id查询服务类商品", description = "参数根据id查询请求体权限所有人方法名listServiceGoodVO")
public BaseResponse<ServiceGoodVO> listServiceGoodVO(@RequestBody CommonRequest commonRequest, HttpServletRequest request) {
if (commonRequest == null || commonRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
userService.getLoginUser(request);
Long id = commonRequest.getId();
Good good = goodService.getById(id);
ThrowUtils.throwIf(good == null, ErrorCode.NOT_FOUND_ERROR, "商品不存在");
@ -312,9 +319,9 @@ public class GoodController {
* @return 服务类商品卡片列表
*/
@GetMapping("/service/list/card")
@Operation(summary = "小程序端展示服务类商品卡片")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<List<ServiceGoodCardVO>> listServiceGoodCardVO() {
@Operation(summary = "小程序端展示服务类商品卡片", description = "参数权限所有人方法名listServiceGoodCardVO")
public BaseResponse<List<ServiceGoodCardVO>> listServiceGoodCardVO(HttpServletRequest request) {
userService.getLoginUser(request);
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("isGoodType", 0);
List<Good> goodList = goodService.list(queryWrapper);
@ -333,7 +340,7 @@ public class GoodController {
* @return 是否更新成功
*/
@PostMapping("/service/update")
@Operation(summary = "Web端管理员更新服务类商品")
@Operation(summary = "Web端管理员更新服务类商品", description = "参数:服务类商品更新请求体,权限:管理员(admin, boss)方法名updateServiceGoodById")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> updateServiceGoodById(@RequestBody ServiceGoodUpdateRequest serviceGoodUpdateRequest) {
if (serviceGoodUpdateRequest == null || serviceGoodUpdateRequest.getId() <= 0) {

View File

@ -10,7 +10,6 @@ import com.cultural.heritage.common.ResultUtils;
import com.cultural.heritage.constant.UserConstant;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.CommonRequest;
import com.cultural.heritage.model.dto.order.OrderAddRequest;
import com.cultural.heritage.model.dto.order.OrderItemAddRequest;
import com.cultural.heritage.model.dto.order.OrderQueryRequest;
@ -18,12 +17,15 @@ import com.cultural.heritage.model.dto.order.OrderUpdateRequest;
import com.cultural.heritage.model.dto.order.capital.OrderMainInfoAddRequest;
import com.cultural.heritage.model.entity.Order;
import com.cultural.heritage.model.entity.OrderItems;
import com.cultural.heritage.model.entity.User;
import com.cultural.heritage.model.vo.order.OrderVO;
import com.cultural.heritage.service.order.OrderItemService;
import com.cultural.heritage.service.order.OrderService;
import com.cultural.heritage.service.user.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
@ -50,6 +52,11 @@ public class OrderController {
private OrderItemService orderItemService;
@Resource
private UserService userService;
/**
* 用户创建订单
* @param orderMainInfoAddRequest 订单创建请求体
@ -57,11 +64,13 @@ public class OrderController {
*/
@PostMapping("/add")
@Transactional(rollbackFor = Exception.class)
@Operation(summary = "小程序端创建用户订单", description = "参数:订单创建请求体,排序字段 sortField: totalAmount权限所有人方法名addOrder")
public BaseResponse<Long> addOrder(@RequestBody OrderMainInfoAddRequest orderMainInfoAddRequest) {
@Operation(summary = "小程序端创建用户订单", description = "参数:订单创建请求体,排序字段 sortField: totalAmount id createTime权限所有人方法名addOrder")
public BaseResponse<Long> addOrder(@RequestBody OrderMainInfoAddRequest orderMainInfoAddRequest, HttpServletRequest request) {
if (orderMainInfoAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 校验用户当前是否处于登录态
User loginUser = userService.getLoginUser(request);
// 封装订单详细信息请求体
OrderAddRequest orderAddRequest = orderService.initOrderMainInfo(orderMainInfoAddRequest);
if (orderAddRequest == null) {
@ -70,6 +79,9 @@ public class OrderController {
// 创建一个总订单
Order order = new Order();
BeanUtils.copyProperties(orderAddRequest, order);
order.setUserId(loginUser.getId());
// 校验订单
orderService.validOrder(order);
boolean result = orderService.save(order);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
// 创建订单明细
@ -130,16 +142,13 @@ public class OrderController {
/**
* 小程序端用户查询订单
* @param commonRequest 用户id请求体
* @return 用户订单列表
*/
@PostMapping("/list")
@Operation(summary = "小程序端用户查询订单", description = "参数用户id请求体权限所有人方法名listUserOrder")
public BaseResponse<List<OrderVO>> listUserOrder(@RequestBody CommonRequest commonRequest) {
if (commonRequest == null || commonRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = commonRequest.getId();
public BaseResponse<List<OrderVO>> listUserOrder(HttpServletRequest request) {
User loginUser = userService.getLoginUser(request);
Long id = loginUser.getId();
QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userId", id);
List<Order> orders = orderService.list(queryWrapper);

View File

@ -18,6 +18,7 @@ import com.cultural.heritage.model.dto.user.*;
import com.cultural.heritage.model.entity.User;
import com.cultural.heritage.model.vo.user.UserVO;
import com.cultural.heritage.service.user.UserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
@ -59,6 +60,7 @@ public class UserController {
* @return 登录用户信息
*/
@PostMapping("/login")
@ApiOperationSupport(order = 1)
@Operation(summary = "Web端用户登录", description = "参数:{账号,密码}, 权限:所有人), 方法名userLogin")
public BaseResponse<UserVO> userLogin(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request){
if(userLoginRequest == null) {
@ -83,6 +85,7 @@ public class UserController {
* @return 用户登录信息
*/
@GetMapping("/login/wx_open")
@ApiOperationSupport(order = 2)
@Operation(summary = "(无法测)微信小程序用户登录", description = "参数code(用户登录凭证), 权限:所有人, 方法名userLoginByWxOpen")
public BaseResponse<UserVO> userLoginByWxOpen(@RequestParam("code") String code, HttpServletRequest request) {
WxMaJscode2SessionResult sessionInfo;

View File

@ -69,39 +69,6 @@ public class WeChatController {
return sb.toString();
}
// l2Xqw8jS3iBL3__mZ33T8TFMj_w2tnERt6rLLUAfwRP5OWzAj5BzJyhsmuMzo3GJ
// private String getOneContent(String token) throws IOException {
// String path = " https://api.weixin.qq.com/cgi-bin/freepublish/getarticle?access_token=" + token;
// URL url = new URL(path);
// HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// connection.setRequestMethod("POST");
// connection.setDoOutput(true);
// connection.setRequestProperty("content-type", "application/json;charset=utf-8");
// connection.connect();
// // post发送的参数
// Map<String, Object> map = new HashMap<>();
// map.put("article_id", "l2Xqw8jS3iBL3__mZ33T8TFMj_w2tnERt6rLLUAfwRP5OWzAj5BzJyhsmuMzo3GJ"); // news表示图文类型的素材具体看API文档
// // 将map转换成json字符串
// String paramBody = JSON.toJSONString(map); // 这里用了Alibaba的fastjson
//
// OutputStream out = connection.getOutputStream();
// BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
// bw.write(paramBody); // 向流中写入参数字符串
// bw.flush();
//
// InputStream in = connection.getInputStream();
// byte[] b = new byte[100];
// int len = -1;
// StringBuffer sb = new StringBuffer();
// while((len = in.read(b)) != -1) {
// sb.append(new String(b,0,len));
// }
//
// in.close();
// return sb.toString();
// }
private String getContentList(String token) throws IOException {
@ -138,14 +105,6 @@ public class WeChatController {
}
// @Test
// public void test() throws IOException {
// String result1 = getToken();
// Map<String,Object> token = (Map<String, Object>) JSON.parseObject(result1);
// String result2 = getContentList(token.get("access_token").toString());
// System.out.println(result2);
// }
}

View File

@ -13,7 +13,7 @@ public class CommonDelBatchRequest implements Serializable {
@Schema(description = "批量删除的商品id列表(id > 0)", example = "[8, 9, 17]")
private List<Integer> idList;
private List<Long> idList;
@Serial

View File

@ -39,12 +39,6 @@ public class AddressAddRequest implements Serializable {
private String detailAddress;
/**
* 用户id
*/
@Schema(description = "用户id(id > 0)", example = "2")
private Long userId;
/**
* 是否为默认地址
*/

View File

@ -44,12 +44,6 @@ public class AddressUpdateRequest implements Serializable {
private String detailAddress;
/**
* 用户id
*/
@Schema(description = "用户id(id > 0)", example = "2")
private Long userId;
/**
* 是否为默认地址
*/

View File

@ -10,12 +10,6 @@ import java.io.Serializable;
@Schema(description = "购物车记录添加请求体", requiredProperties = {"userId", "goodId", "quantity", "subtotal", "isGoodType"})
public class CartRecordAddRequest implements Serializable {
/**
* 用户id
*/
@Schema(description = "用户Id(id > 0)", example = "2")
private Long userId;
/**
* 商品id
*/

View File

@ -16,11 +16,6 @@ public class CartRecordUpdateRequest implements Serializable {
@Schema(description = "购物车记录Id(id > 0)", example = "5")
private Long id;
/**
* 用户id
*/
@Schema(description = "用户Id(id > 0)", example = "2")
private Long userId;
/**
* 商品id

View File

@ -28,12 +28,6 @@ public class ContactsAddRequest implements Serializable {
private String phone;
/**
* 用户id
*/
@Schema(description = "用户id(id > 0)", example = "2")
private Long userId;
/**
* 是否默认
*/

View File

@ -34,12 +34,6 @@ public class ContactsUpdateRequest implements Serializable {
private String phone;
/**
* 用户id
*/
@Schema(description = "用户id(id > 0)", example = "2")
private Long userId;
/**
* 是否默认
*/

View File

@ -15,12 +15,6 @@ import java.io.Serializable;
public class ExchangeAddRequest implements Serializable {
/**
* 用户id
*/
@Schema(description = "用户id(id > 0)", example = "2")
private Long userId;
/**
* 优惠券id
*/

View File

@ -22,12 +22,12 @@ public class OrderAddRequest implements Serializable {
@Schema(description = "订单类别", example = "product")
private String orderType;
/**
* 用户id
*/
@Schema(description = "用户id(id > 0)", example = "2")
private Long userId;
//
// /**
// * 用户id
// */
// @Schema(description = "用户id(id > 0)", example = "2")
// private Long userId;
/**

View File

@ -13,11 +13,11 @@ import java.util.List;
public class OrderMainInfoAddRequest implements Serializable {
/**
* 用户id
*/
@Schema(description = "用户id(id > 0)", example = "2")
private Long userId;
// /**
// * 用户id
// */
// @Schema(description = "用户id(id > 0)", example = "2")
// private Long userId;
/**

View File

@ -40,7 +40,7 @@ public class Order implements Serializable {
/**
* 订单编号
*/
private String OrderNumber;
private String orderNumber;
/**

View File

@ -18,4 +18,8 @@ public interface AddressService extends IService<Address> {
List<Address> getUserAddressById(Long id);
/**
* 校验用户提交的地址信息
*/
void validAddress(Address address, boolean update);
}

View File

@ -1,9 +1,7 @@
package com.cultural.heritage.service.address;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cultural.heritage.model.entity.Address;
import com.cultural.heritage.model.entity.Contacts;
import io.swagger.v3.oas.models.info.Contact;
import java.util.List;
@ -17,5 +15,11 @@ public interface ContactsService extends IService<Contacts> {
/**
* 根据userId获取用户联系人
*/
List<Contacts> getUserAddressById(Long id);
List<Contacts> getUserContactsById(Long id);
/**
* 校验用户提交的地址信息
*/
void validContacts(Contacts contacts, boolean update);
}

View File

@ -3,10 +3,14 @@ package com.cultural.heritage.service.address.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.mapper.AddressMapper;
import com.cultural.heritage.model.entity.Address;
import com.cultural.heritage.service.address.AddressService;
import com.cultural.heritage.utils.RegexUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
@ -37,4 +41,33 @@ public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> impl
return list;
}
/**
* 校验用户提交的地址信息
*/
@Override
public void validAddress(Address address, boolean update) {
Long userId = address.getUserId();
String name = address.getName();
String phone = address.getPhone();
String region = address.getRegion();
String detailAddress = address.getDetailAddress();
Integer isDefault = address.getIsDefault();
if (update) {
if (userId == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数id错误");
}
}
if (ObjectUtils.isEmpty(isDefault)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isAnyBlank(name, region, detailAddress, phone)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数不全");
}
if (StringUtils.isNotBlank(phone) && RegexUtils.isPhoneInvalid(phone)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "手机号格式无效");
}
}
}

View File

@ -3,10 +3,14 @@ package com.cultural.heritage.service.address.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.mapper.ContactsMapper;
import com.cultural.heritage.model.entity.Contacts;
import com.cultural.heritage.service.address.ContactsService;
import com.cultural.heritage.utils.RegexUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
@ -19,7 +23,7 @@ public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> i
public void verifyIsDefault(Contacts contacts) {
Integer isDefault = contacts.getIsDefault();
Long userId = contacts.getUserId();
List<Contacts> list = this.getUserAddressById(userId);
List<Contacts> list = this.getUserContactsById(userId);
if (isDefault == 1) {
list.forEach(item -> item.setIsDefault(0));
}
@ -28,10 +32,37 @@ public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> i
}
@Override
public List<Contacts> getUserAddressById(Long userId) {
public List<Contacts> getUserContactsById(Long userId) {
QueryWrapper<Contacts> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userId", userId);
List<Contacts> list = this.list(queryWrapper);
return list;
}
/**
* 校验用户提交的地址信息
*/
@Override
public void validContacts(Contacts contacts, boolean update) {
String name = contacts.getName();
String phone = contacts.getPhone();
Long userId = contacts.getUserId();
Integer isDefault = contacts.getIsDefault();
if (update) {
if (userId == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数id错误");
}
}
if (ObjectUtils.isEmpty(isDefault)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isAnyBlank(name, phone)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isNotBlank(phone) && RegexUtils.isPhoneInvalid(phone)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "手机号格式错误");
}
}
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.cultural.heritage.model.dto.cart.CartRecordAddRequest;
import com.cultural.heritage.model.entity.CartRecord;
import com.cultural.heritage.model.vo.cart.CartRecordVO;
import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
@ -12,11 +13,17 @@ public interface CartRecordService extends IService<CartRecord> {
/**
* 处理用户购物车已存在该商品
*/
boolean dealAlreadyExistGood(CartRecordAddRequest cartRecordAddRequest);
boolean dealAlreadyExistGood(CartRecordAddRequest cartRecordAddRequest, HttpServletRequest request);
/**
* 封装用户购物车中的商品信息
*/
List<CartRecordVO> transformToCartRecordVOList(List<CartRecord> list);
/**
* 校验购物车中的商品信息
*/
void validCart(CartRecord cartRecord, boolean update);
}

View File

@ -1,7 +1,9 @@
package com.cultural.heritage.service.good;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cultural.heritage.model.entity.Category;
import com.cultural.heritage.model.entity.Good;
import java.util.List;
@ -24,4 +26,10 @@ public interface CategoryService extends IService<Category> {
*/
void validCategory(Category category, boolean add);
/**
* 根据类别id获取商品删除的条件
*/
QueryWrapper<Good> getDeleteQueryWrapper(Long id);
}

View File

@ -9,10 +9,13 @@ import com.cultural.heritage.mapper.GoodMapper;
import com.cultural.heritage.model.dto.cart.CartRecordAddRequest;
import com.cultural.heritage.model.entity.CartRecord;
import com.cultural.heritage.model.entity.Good;
import com.cultural.heritage.model.entity.User;
import com.cultural.heritage.model.vo.cart.CartRecordVO;
import com.cultural.heritage.model.vo.good.GoodVO;
import com.cultural.heritage.service.good.CartRecordService;
import com.cultural.heritage.service.user.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
@ -26,12 +29,16 @@ public class CartRecordServiceImpl extends ServiceImpl<CartRecordMapper, CartRec
private GoodMapper goodMapper;
@Resource
private UserService userService;
/**
* 处理用户购物车已存在该商品
*/
@Override
public boolean dealAlreadyExistGood(CartRecordAddRequest cartRecordAddRequest) {
Long userId = cartRecordAddRequest.getUserId();
public boolean dealAlreadyExistGood(CartRecordAddRequest cartRecordAddRequest, HttpServletRequest request) {
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
Long goodId = cartRecordAddRequest.getGoodId();
QueryWrapper<CartRecord> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userId", userId);
@ -45,6 +52,8 @@ public class CartRecordServiceImpl extends ServiceImpl<CartRecordMapper, CartRec
} else {
CartRecord cartGood = new CartRecord();
BeanUtils.copyProperties(cartRecordAddRequest, cartGood);
cartGood.setUserId(userId);
this.validCart(cartGood, false);
boolean result = this.save(cartGood);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
}
@ -53,6 +62,8 @@ public class CartRecordServiceImpl extends ServiceImpl<CartRecordMapper, CartRec
/**
* 封装用户购物车中的商品信息
*/
@ -70,9 +81,18 @@ public class CartRecordServiceImpl extends ServiceImpl<CartRecordMapper, CartRec
Good good = goodMapper.selectOne(queryWrapper);
GoodVO goodVO = new GoodVO();
BeanUtils.copyProperties(good, goodVO);
cartRecordVO.setGoodVO(goodVO);
return cartRecordVO;
}).toList();
}
/**
* 校验购物车中的商品信息
*/
@Override
public void validCart(CartRecord cartRecord, boolean update) {
}
}

View File

@ -7,6 +7,7 @@ import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.mapper.CategoryMapper;
import com.cultural.heritage.model.entity.Category;
import com.cultural.heritage.model.entity.Good;
import com.cultural.heritage.service.good.CategoryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@ -67,4 +68,17 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
}
}
/**
* 根据类别id获取商品删除的条件
*/
@Override
public QueryWrapper<Good> getDeleteQueryWrapper(Long id) {
Category category = this.getById(id);
String typeName = category.getTypeName();
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", typeName);
return queryWrapper;
}
}

View File

@ -20,4 +20,10 @@ public interface OrderService extends IService<Order> {
* 封装订单详细信息请求体
*/
OrderAddRequest initOrderMainInfo(OrderMainInfoAddRequest orderMainInfoAddRequest);
/**
* 校验订单
*/
void validOrder(Order order);
}

View File

@ -91,7 +91,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
*/
@Override
public OrderAddRequest initOrderMainInfo(OrderMainInfoAddRequest orderMainInfoAddRequest) {
Long userId = orderMainInfoAddRequest.getUserId();
String userName = orderMainInfoAddRequest.getUserName();
Long addressId = orderMainInfoAddRequest.getAddressId();
Long contactsId = orderMainInfoAddRequest.getContactsId();
@ -143,7 +142,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
// 创建订单详细信息请求体
OrderAddRequest orderAddRequest = new OrderAddRequest();
orderAddRequest.setUserId(userId);
orderAddRequest.setUserName(userName);
orderAddRequest.setOrderNumber(orderNumber);
orderAddRequest.setOrderStatus(orderStatus);
@ -158,6 +156,31 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
}
/**
* 校验订单
*/
@Override
public void validOrder(Order order) {
String orderType = order.getOrderType();
String orderNumber = order.getOrderNumber();
Long userId = order.getUserId();
String userName = order.getUserName();
Double totalAmount = order.getTotalAmount();
String orderStatus = order.getOrderStatus();
if (ObjectUtils.isEmpty(totalAmount) || totalAmount.floatValue() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "价格错误");
}
if (ObjectUtils.isEmpty(userId)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
if (StringUtils.isAnyBlank(orderType, orderNumber, userName, orderStatus)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数不全");
}
}
/**
* 根据id获取订单(地址联系人优惠券商品)信息
*/

View File

@ -0,0 +1,57 @@
package com.cultural.heritage.utils;
import org.apache.commons.lang3.StringUtils;
import static com.cultural.heritage.constant.RegexConstant.*;
public class RegexUtils {
/**
* 是否是无效手机格式
*
* @param phone 要校验的手机号
* @return true:符合false不符合
*/
public static boolean isPhoneInvalid(String phone) {
return mismatch(phone, PHONE_REGEX);
}
/**
* 是否是无效邮箱格式
*
* @param email 要校验的邮箱
* @return true:符合false不符合
*/
public static boolean isEmailInvalid(String email) {
return mismatch(email, EMAIL_REGEX);
}
/**
* 是否是无效18位身份证格式
*
* @param idCard 要校验的身份证号码
* @return true:符合false不符合
*/
public static boolean isIdCardInvalid(String idCard) {
return mismatch(idCard, ID_CARD_REGEX);
}
/**
* 是否是无效验证码格式
*
* @param code 要校验的验证码
* @return true:符合false不符合
*/
public static boolean isCodeInvalid(String code) {
return mismatch(code, VERIFY_CODE_REGEX);
}
// 校验是否不符合正则格式
private static boolean mismatch(String str, String regex) {
if (StringUtils.isBlank(str)) {
return true;
}
return !str.matches(regex);
}
}

View File

@ -56,4 +56,8 @@ wx:
appSecret: 847bdda7c2b01e88d59948b9ba50ef8d
official:
appId: wx5d04ca2de0e628a8
appSecret: 495af5bc4df1b86ffcfc21bb12daea76
appSecret: 495af5bc4df1b86ffcfc21bb12daea76
knife4j:
enable: true

View File

@ -1,5 +1,7 @@
package com.cultural.heritage.test;
import org.apache.commons.lang3.ObjectUtils;
public class Test {
public static void main(String[] args) {
// Date date = new Date();
@ -15,8 +17,11 @@ public class Test {
// System.out.println(format);
// System.out.println(StringUtils.isBlank(null));
//
// double num = 3.1415926;
// System.out.printf("%.2f", num); // 输出3.14
double num = 3.1415926;
System.out.printf("%.2f", num); // 输出3.14
// System.out.println(StringUtils.isAnyBlank("333", "333", null, "dfs"));
System.out.println(ObjectUtils.anyNull(null));
}
}