release- 上架与mall联动

release-2024-08-08
pikaqiudeshujia 7 months ago
parent 0f0c16f07f
commit c882c8207b

@ -38,8 +38,6 @@ public class Constants {
public static final String RABBIT_MESSAGE_CLEAN_JOURANL_QUERY_PAGE = "clean_journal_query_page"; public static final String RABBIT_MESSAGE_CLEAN_JOURANL_QUERY_PAGE = "clean_journal_query_page";
public static final String RABBIT_MESSAGE_USER_COLLECT_JOURNAL = "user_collect_journal"; public static final String RABBIT_MESSAGE_USER_COLLECT_JOURNAL = "user_collect_journal";
public static final String RABBIT_MALL_PRODUCT_ADD = "luoo_mall_product_add";
public static final String TOKEN_PREFIX = "Bearer "; public static final String TOKEN_PREFIX = "Bearer ";
public static final int TOKEN_PREFIX_LENGTH = TOKEN_PREFIX.length(); public static final int TOKEN_PREFIX_LENGTH = TOKEN_PREFIX.length();

@ -26,9 +26,17 @@ public class MallProduct implements Serializable {
// 品牌,固定雀乐 // 品牌,固定雀乐
private Long brandId; private Long brandId;
// 品牌名称,固定雀乐
private String brandName;
// 分类,固定歌曲 // 分类,固定歌曲
private Long productCategoryId; private Long productCategoryId;
/**
*
*/
private String productCategoryName;
// 产品属性分类表,固定歌曲 // 产品属性分类表,固定歌曲
private Long productAttributeCategoryId; private Long productAttributeCategoryId;
@ -38,10 +46,6 @@ public class MallProduct implements Serializable {
// 商品图片取歌曲图片image // 商品图片取歌曲图片image
private String pic; private String pic;
// 排序,取歌曲排序
@ApiModelProperty(value = "排序")
private Integer sort;
// 价格 // 价格
private BigDecimal price; private BigDecimal price;

@ -22,6 +22,9 @@ import java.io.Serializable;
@NoArgsConstructor @NoArgsConstructor
public class MallProductAttributeValue implements Serializable { public class MallProductAttributeValue implements Serializable {
private Long id;
private Long productId;
// 商品属性id // 商品属性id
private Long productAttributeId; private Long productAttributeId;

@ -0,0 +1,67 @@
package com.luoo.music.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @Author: yawei.huang
* @Package: com.luoo.music.config
* @Project: luoo_parent
* @Date: 2024/5/8 9:23
* @Filename: MallConfig
* @Describe:
*/
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "mall")
public class MallConfig {
// 表pms_product属性
/**
* id
*/
private Long brandId;
/**
*
*/
private String brandName;
/**
* id
*/
private Long productCategoryId;
/**
*
*/
private String productCategoryName;
/**
* id
*/
private Long productAttributeCategoryId;
// 表pms_product_attribute_value属性
/**
* id
*/
private Long artistId;
/**
*
*/
private Long artistName;
/**
* id
*/
private Long albumId;
/**
*
*/
private Long albumName;
/**
* id
*/
private Long songId;
}

@ -0,0 +1,35 @@
package com.luoo.music.config;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
/**
* @Author: yawei.huang
* @Package: com.macro.mall.config
* @Project: macrozhengmall
* @Date: 2024/5/8 14:13
* @Filename: RabbitMQConfig
* @Describe:
*/
@Configuration
public class RabbitMQConfig implements InitializingBean {
/**
* RabbitTemplate
*/
@Resource
private RabbitTemplate rabbitTemplate;
/**
* JSON
*/
@Override
public void afterPropertiesSet() {
//使用JSON序列化
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
}
}

@ -6,6 +6,7 @@ import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@ -32,7 +33,7 @@ public class AlbumSongAddDTO implements Serializable {
private Integer charge; private Integer charge;
@ApiModelProperty("歌曲定价") @ApiModelProperty("歌曲定价")
private Float price; private BigDecimal price;
@ApiModelProperty("歌手") @ApiModelProperty("歌手")
@NotBlank(message = "歌手不能为空") @NotBlank(message = "歌手不能为空")

@ -6,6 +6,7 @@ import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@ -32,7 +33,7 @@ public class AlbumSongRequireDTO implements Serializable {
private Integer charge; private Integer charge;
@ApiModelProperty("歌曲定价") @ApiModelProperty("歌曲定价")
private Float price; private BigDecimal price;
@ApiModelProperty("歌手") @ApiModelProperty("歌手")
@NotBlank(message = "歌手不能为空") @NotBlank(message = "歌手不能为空")

@ -11,6 +11,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -134,7 +135,7 @@ public class ArtistAlbum implements Serializable {
@Transient @Transient
@ApiModelProperty("价格") @ApiModelProperty("价格")
private Float price; private BigDecimal price;
@Transient @Transient
@ApiModelProperty("风格列表") @ApiModelProperty("风格列表")

@ -13,6 +13,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -108,7 +109,7 @@ public class SongInfo implements Serializable {
private Integer charge; private Integer charge;
@ApiModelProperty("歌曲定价") @ApiModelProperty("歌曲定价")
private Float price; private BigDecimal price;
// @ApiModelProperty("编曲") // @ApiModelProperty("编曲")

@ -2,11 +2,14 @@ package com.luoo.music.service;
import api.PageResult; import api.PageResult;
import com.luoo.music.client.UserClient; import com.luoo.music.client.UserClient;
import com.luoo.music.config.MallConfig;
import com.luoo.music.dao.*; import com.luoo.music.dao.*;
import com.luoo.music.dto.response.*; import com.luoo.music.dto.response.*;
import com.luoo.music.pojo.*; import com.luoo.music.pojo.*;
import com.luoo.music.util.Constants; import com.luoo.music.util.Constants;
import constants.ErrorConstants; import constants.ErrorConstants;
import dto.MallProduct;
import dto.MallProductAttributeValue;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.AlbumStateEnum; import enums.AlbumStateEnum;
import enums.SongInfoChargeEnum; import enums.SongInfoChargeEnum;
@ -16,6 +19,7 @@ import exception.BizException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -32,6 +36,7 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -74,6 +79,12 @@ public class AlbumService {
@Autowired @Autowired
private UserClient userClient; private UserClient userClient;
@Autowired
private MallConfig mallConfig;
@Autowired
private RabbitTemplate rabbitTemplate;
public PageResult<ArtistAlbum> getList(AlbumSearchDTO albumSearchDTO, Integer page, Integer size) { public PageResult<ArtistAlbum> getList(AlbumSearchDTO albumSearchDTO, Integer page, Integer size) {
List<ArtistAlbum> result = new ArrayList<>(); List<ArtistAlbum> result = new ArrayList<>();
Sort sort = new Sort(Sort.Direction.DESC, "createTime"); Sort sort = new Sort(Sort.Direction.DESC, "createTime");
@ -299,7 +310,7 @@ public class AlbumService {
ArtistAlbum artistAlbum = new ArtistAlbum(); ArtistAlbum artistAlbum = new ArtistAlbum();
BeanUtils.copyProperties(albumUpdateDTO, artistAlbum); BeanUtils.copyProperties(albumUpdateDTO, artistAlbum);
ArtistAlbum old = checkAlbum(token, artistAlbum.getId()); ArtistAlbum old = checkAlbumIsSelf(token, artistAlbum.getId());
artistAlbum.setArtistId(old.getArtistId()); artistAlbum.setArtistId(old.getArtistId());
artistAlbum.setArtistName(old.getArtistName()); artistAlbum.setArtistName(old.getArtistName());
@ -309,15 +320,20 @@ public class AlbumService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void changeAlbumState(String token, String id, Integer state) { public void changeAlbumState(String token, String id, Integer state) {
ArtistAlbum artistAlbum = checkAlbum(token, id); ArtistAlbum artistAlbum = checkAlbumIsSelf(token, id);
switch (state) { switch (state) {
case -1: case -1:
// 不可抗力强制下架
break; break;
case 1: case 1:
// 申请审核操作 // 申请审核操作
checkForApply(id, artistAlbum); checkForApply(id, artistAlbum);
break; break;
case 2:
case 3:
checkAlbum(artistAlbum);
break;
case 4: case 4:
// 上架操作 // 上架操作
shelving(artistAlbum); shelving(artistAlbum);
@ -383,6 +399,16 @@ public class AlbumService {
} }
} }
/**
*
*/
private void checkAlbum(ArtistAlbum artistAlbum) {
if (ObjectUtils.notEqual(AlbumStateEnum.IN_APPROVE.getCode(), artistAlbum.getState())) {
// 必须在待审核状态下申请审核
throw new BizException(ErrorConstants.STATE_ERROR);
}
}
/** /**
* *
* *
@ -393,6 +419,37 @@ public class AlbumService {
if (ObjectUtils.notEqual(AlbumStateEnum.WAIT_ARRIVE.getCode(), artistAlbum.getState())) { if (ObjectUtils.notEqual(AlbumStateEnum.WAIT_ARRIVE.getCode(), artistAlbum.getState())) {
throw new BizException(ErrorConstants.STATE_ERROR); throw new BizException(ErrorConstants.STATE_ERROR);
} }
// 拼接MALL模块需要的商品对象和参数对象
List<SongInfo> songInfoList = songInfoDao.findByAlbumId(artistAlbum.getId());
for (SongInfo songInfo : songInfoList) {
MallProduct mallProduct = MallProduct.builder()
.brandId(mallConfig.getBrandId())
.brandName(mallConfig.getBrandName())
.productCategoryName(mallConfig.getProductCategoryName())
.productCategoryId(mallConfig.getProductCategoryId())
.productAttributeCategoryId(mallConfig.getProductAttributeCategoryId())
.name(songInfo.getName())
.pic(songInfo.getImage())
.subTitle(songInfo.getName())
.price(songInfo.getPrice())
.build();
List<MallProductAttributeValue> attributeValueList = new ArrayList<>();
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getAlbumId()).value(artistAlbum.getId()).build());
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getAlbumName()).value(artistAlbum.getName()).build());
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getSongId()).value(songInfo.getId()).build());
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getArtistId()).value(artistAlbum.getArtistId()).build());
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getArtistName()).value(artistAlbum.getArtistName()).build());
Map<String, Object> mallMqMap = new HashMap<>();
mallMqMap.put("songId", songInfo.getId());
mallMqMap.put("mallProduct", mallProduct);
mallMqMap.put("attributeValueList", attributeValueList);
rabbitTemplate.convertAndSend("luoo_mall_product_add", mallMqMap);
}
// 上架的同时发起MQMALL接收到后会调用商品新增的接口
} }
/** /**
@ -428,7 +485,7 @@ public class AlbumService {
throw new BizException(ErrorConstants.THE_SONG_DOES_NOT_EXIST); throw new BizException(ErrorConstants.THE_SONG_DOES_NOT_EXIST);
} }
checkAlbum(token, artistAlbumSong.getAlbumId()); checkAlbumIsSelf(token, artistAlbumSong.getAlbumId());
artistAlbumSongDao.delete(artistAlbumSong); artistAlbumSongDao.delete(artistAlbumSong);
} }
@ -440,7 +497,7 @@ public class AlbumService {
* @param id id * @param id id
* @return * @return
*/ */
private ArtistAlbum checkAlbum(String token, String id) { private ArtistAlbum checkAlbumIsSelf(String token, String id) {
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get(); ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get();
UserLoginDto user = jwtUtil.getUserLoginDto(token); UserLoginDto user = jwtUtil.getUserLoginDto(token);
@ -466,7 +523,7 @@ public class AlbumService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void addNewSong(String token, String id, AlbumSongAddDTO albumSongAddDTO) { public void addNewSong(String token, String id, AlbumSongAddDTO albumSongAddDTO) {
UserLoginDto user = jwtUtil.getUserLoginDto(token); UserLoginDto user = jwtUtil.getUserLoginDto(token);
ArtistAlbum artistAlbum = checkAlbum(token, id); ArtistAlbum artistAlbum = checkAlbumIsSelf(token, id);
addSongForAlbum(albumSongAddDTO, user, artistAlbum); addSongForAlbum(albumSongAddDTO, user, artistAlbum);
} }
@ -481,7 +538,7 @@ public class AlbumService {
// 定价不能为空 // 定价不能为空
throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY); throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
} }
if (albumSongRequireDTO.getPrice() <= 0) { if (albumSongRequireDTO.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
// 定价必须大于0 // 定价必须大于0
throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0); throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
} }
@ -502,7 +559,7 @@ public class AlbumService {
// 定价不能为空 // 定价不能为空
throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY); throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY);
} }
if (albumSongAddDTO.getPrice() <= 0) { if (albumSongAddDTO.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
// 定价必须大于0 // 定价必须大于0
throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0); throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0);
} }

@ -58,11 +58,11 @@ spring:
type: caffeine type: caffeine
mall: mall:
product:
brandId: 60 brandId: 60
brandName: 雀乐
productCategoryId: 57 productCategoryId: 57
productCategoryName: 歌曲
productAttributeCategoryId: 16 productAttributeCategoryId: 16
attribute:
artistId: 74 artistId: 74
artistName: 75 artistName: 75
albumId: 76 albumId: 76

@ -41,7 +41,7 @@ alter table tb_song_info
add mv_url varchar(50) null comment 'mv'; add mv_url varchar(50) null comment 'mv';
alter table tb_song_info alter table tb_song_info
add price float null comment '价格'; add price decimal null comment '价格';
alter table tb_song_info alter table tb_song_info
add version int null comment '歌曲版本'; add version int null comment '歌曲版本';

Loading…
Cancel
Save