diff --git a/src/main/java/com/cultural/heritage/controller/book/BookingDateController.java b/src/main/java/com/cultural/heritage/controller/book/BookingDateController.java index 0c2f08a..73114d4 100644 --- a/src/main/java/com/cultural/heritage/controller/book/BookingDateController.java +++ b/src/main/java/com/cultural/heritage/controller/book/BookingDateController.java @@ -22,6 +22,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; @@ -142,7 +143,7 @@ public class BookingDateController { @Transactional(rollbackFor = Exception.class) @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse addTimePeriod(@RequestBody BookingTimeSingleAddRequest bookingTimeSingleAddRequest) { - if (bookingTimeSingleAddRequest == null) { + if (bookingTimeSingleAddRequest == null || StringUtils.isBlank(bookingTimeSingleAddRequest.getTimePoint())) { throw new BusinessException(ErrorCode.PARAMS_ERROR); } BookingTime bookingTime = new BookingTime(); diff --git a/src/main/java/com/cultural/heritage/controller/order/OrderController.java b/src/main/java/com/cultural/heritage/controller/order/OrderController.java index d1fc7f6..3bdd7de 100644 --- a/src/main/java/com/cultural/heritage/controller/order/OrderController.java +++ b/src/main/java/com/cultural/heritage/controller/order/OrderController.java @@ -367,7 +367,7 @@ public class OrderController { * @return 是否取消成功 */ @PostMapping ("/cancel/id") - @Operation(summary = "小程序端用户取消常规类商品订单", description = "参数:订单id,权限:所有人,方法名:cancelOrderById") + @Operation(summary = "小程序端用户取消服务类商品订单", description = "参数:订单id,权限:所有人,方法名:cancelOrderById") public BaseResponse cancelOrderById(@RequestBody CommonRequest commonRequest, HttpServletRequest request) { if (commonRequest == null || commonRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -429,6 +429,31 @@ public class OrderController { + /** + * 小程序端用户删除商品订单 + * @param commonRequest 订单id + * @return 是否取消成功 + */ + @PostMapping ("/delete/id") + @Operation(summary = "小程序端用户删除商品订单", description = "参数:订单id,权限:所有人,方法名:deleteOrderById") + public BaseResponse deleteOrderById(@RequestBody CommonRequest commonRequest, HttpServletRequest request) { + if (commonRequest == null || commonRequest.getId() <= 0) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Long id = commonRequest.getId(); + userService.getLoginUser(request); + Order order = orderService.getById(id); + ThrowUtils.throwIf(order == null, ErrorCode.OPERATION_ERROR, "订单不存在"); + ThrowUtils.throwIf(!order.getOrderStatus().equals(OrderStatusConstant.TRANSACTION_CLOSED), ErrorCode.SYSTEM_ERROR, "订单状态错误"); + + boolean remove = orderService.removeById(id); + ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "订单删除失败"); + return ResultUtils.success(true); + } + + + + /** * 小程序端用户取消服务类商品订单 diff --git a/src/main/java/com/cultural/heritage/controller/user/UserController.java b/src/main/java/com/cultural/heritage/controller/user/UserController.java index 7248c36..4e72f07 100644 --- a/src/main/java/com/cultural/heritage/controller/user/UserController.java +++ b/src/main/java/com/cultural/heritage/controller/user/UserController.java @@ -185,6 +185,7 @@ public class UserController { BeanUtils.copyProperties(userAddRequest, user); String encryptPassword = DigestUtils.md5DigestAsHex((SALT + user.getUserPassword()).getBytes()); user.setUserPassword(encryptPassword); + userService.validUser(user, false); boolean save = userService.save(user); if (!save) { throw new BusinessException(ErrorCode.SYSTEM_ERROR); @@ -225,6 +226,9 @@ public class UserController { } User user = new User(); BeanUtils.copyProperties(userUpdateRequest, user); + String encryptPassword = DigestUtils.md5DigestAsHex((SALT + user.getUserPassword()).getBytes()); + user.setUserPassword(encryptPassword); + userService.validUser(user, true); boolean result = userService.updateById(user); ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR); return ResultUtils.success(true); diff --git a/src/main/java/com/cultural/heritage/service/user/UserService.java b/src/main/java/com/cultural/heritage/service/user/UserService.java index ce826a3..6fbcd0e 100644 --- a/src/main/java/com/cultural/heritage/service/user/UserService.java +++ b/src/main/java/com/cultural/heritage/service/user/UserService.java @@ -25,6 +25,13 @@ public interface UserService extends IService { */ UserVO getUserVO(User user); + + /** + * 校验用户信息 + */ + void validUser(User user, boolean update); + + /** * 用户退出 * @return 是否退出成功 diff --git a/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java b/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java index a69627f..a2b4b13 100644 --- a/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java @@ -15,6 +15,7 @@ import com.cultural.heritage.model.entity.User; import com.cultural.heritage.model.enums.UserRoleEnum; import com.cultural.heritage.model.vo.user.UserVO; import com.cultural.heritage.service.user.UserService; +import com.cultural.heritage.utils.RegexUtils; import com.cultural.heritage.utils.SqlUtils; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; @@ -80,6 +81,23 @@ public class UserServiceImpl extends ServiceImpl implements Us } + @Override + public void validUser(User user, boolean update) { + String userAccount = user.getUserAccount(); + String userPassword = user.getUserPassword(); + String userName = user.getUserName(); + String userAvatar = user.getUserAvatar(); + String phone = user.getPhone(); + String userRole = user.getUserRole(); + Long id = user.getId(); + ThrowUtils.throwIf(update && id == null, ErrorCode.OPERATION_ERROR, "id字段为null"); + if (StringUtils.isAnyBlank(userAccount, userPassword, userName, userAvatar, phone, userRole)) { + throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在参数为空"); + } + ThrowUtils.throwIf(!RegexUtils.isPhoneInvalid(phone), ErrorCode.OPERATION_ERROR, "手机号格式错误"); + } + + @Override public boolean userLogout(HttpServletRequest request) { HttpSession session = request.getSession();