| | |
| | | @Transactional |
| | | public Map<String, Object> createProduct(ProductCreateRequest request) { |
| | | ensureMerchantExists(request.merchantId()); |
| | | validateProductConfiguration(request.merchantId(), request.salePrice(), request.productImages()); |
| | | validateProductRights(request.merchantId(), request.rightsConfig()); |
| | | String productNo = BusinessIdGenerator.next("P"); |
| | | BigDecimal subsidyAmount = valueOrZero(request.subsidyAmount()); |
| | |
| | | @Transactional |
| | | public Map<String, Object> updateProduct(Long id, ProductUpdateRequest request) { |
| | | ensureMerchantExists(request.merchantId()); |
| | | validateProductConfiguration(request.merchantId(), request.salePrice(), request.productImages()); |
| | | validateProductRights(request.merchantId(), request.rightsConfig()); |
| | | BigDecimal subsidyAmount = valueOrZero(request.subsidyAmount()); |
| | | int updated = jdbcTemplate.update(""" |
| | |
| | | if (rightsConfig == null) { |
| | | return; |
| | | } |
| | | if (isHotelMerchant(merchantId)) { |
| | | if (isHotelMerchant(merchantId) || isHealthCheckMerchant(merchantId)) { |
| | | return; |
| | | } |
| | | for (Map<String, Object> right : rightsConfig) { |
| | |
| | | } |
| | | } |
| | | |
| | | private void validateProductConfiguration(Long merchantId, BigDecimal salePrice, List<String> productImages) { |
| | | if (isHealthCheckMerchant(merchantId)) { |
| | | return; |
| | | } |
| | | if (salePrice == null) { |
| | | throw new BusinessException(ErrorCode.BAD_REQUEST, "商品金额不能为空"); |
| | | } |
| | | if (productImages == null || productImages.isEmpty()) { |
| | | throw new BusinessException(ErrorCode.BAD_REQUEST, "请至少添加一张商品图片"); |
| | | } |
| | | } |
| | | |
| | | private boolean isHotelMerchant(Long merchantId) { |
| | | String type = merchantType(merchantId); |
| | | return "hotel".equalsIgnoreCase(type) || "酒店服务".equals(type); |
| | | } |
| | | |
| | | private boolean isHealthCheckMerchant(Long merchantId) { |
| | | String type = merchantType(merchantId); |
| | | return "healthCheck".equalsIgnoreCase(type) || "免费体检".equals(type); |
| | | } |
| | | |
| | | private String merchantType(Long merchantId) { |
| | | List<String> types = jdbcTemplate.queryForList( |
| | | "select merchant_type from merchant where deleted = 0 and id = ? limit 1", |
| | | String.class, |
| | | merchantId); |
| | | if (types.isEmpty()) { |
| | | return false; |
| | | return ""; |
| | | } |
| | | String type = types.get(0) == null ? "" : types.get(0).trim(); |
| | | return "hotel".equalsIgnoreCase(type) || "酒店服务".equals(type); |
| | | return types.get(0) == null ? "" : types.get(0).trim(); |
| | | } |
| | | |
| | | private void validateCouponConfiguration(String validStart, String validEnd, String productScope, List<Long> productIds) { |