From c882c8207b09d6f1f8a679dabb806b71678f109e Mon Sep 17 00:00:00 2001 From: pikaqiudeshujia Date: Wed, 8 May 2024 16:26:27 +0800 Subject: [PATCH] =?UTF-8?q?release-=20=E4=B8=8A=E6=9E=B6=E4=B8=8Emall?= =?UTF-8?q?=E8=81=94=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/constants/Constants.java | 2 - .../src/main/java/dto/MallProduct.java | 12 ++- .../java/dto/MallProductAttributeValue.java | 3 + .../com/luoo/music/config/MallConfig.java | 67 ++++++++++++++++ .../com/luoo/music/config/RabbitMQConfig.java | 35 +++++++++ .../music/dto/response/AlbumSongAddDTO.java | 3 +- .../dto/response/AlbumSongRequireDTO.java | 3 +- .../java/com/luoo/music/pojo/ArtistAlbum.java | 3 +- .../java/com/luoo/music/pojo/SongInfo.java | 3 +- .../com/luoo/music/service/AlbumService.java | 77 ++++++++++++++++--- luoo_music/src/main/resources/bootstrap.yml | 20 ++--- .../src/main/resources/sql/20240428.sql | 2 +- 12 files changed, 199 insertions(+), 31 deletions(-) create mode 100644 luoo_music/src/main/java/com/luoo/music/config/MallConfig.java create mode 100644 luoo_music/src/main/java/com/luoo/music/config/RabbitMQConfig.java diff --git a/luoo_common/src/main/java/constants/Constants.java b/luoo_common/src/main/java/constants/Constants.java index b5a400d..e6da96c 100644 --- a/luoo_common/src/main/java/constants/Constants.java +++ b/luoo_common/src/main/java/constants/Constants.java @@ -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_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 int TOKEN_PREFIX_LENGTH = TOKEN_PREFIX.length(); diff --git a/luoo_common/src/main/java/dto/MallProduct.java b/luoo_common/src/main/java/dto/MallProduct.java index bf9464f..188c901 100644 --- a/luoo_common/src/main/java/dto/MallProduct.java +++ b/luoo_common/src/main/java/dto/MallProduct.java @@ -26,9 +26,17 @@ public class MallProduct implements Serializable { // 品牌,固定雀乐 private Long brandId; + // 品牌名称,固定雀乐 + private String brandName; + // 分类,固定歌曲 private Long productCategoryId; + /** + * 分类名称,固定歌曲 + */ + private String productCategoryName; + // 产品属性分类表,固定歌曲 private Long productAttributeCategoryId; @@ -38,10 +46,6 @@ public class MallProduct implements Serializable { // 商品图片,取歌曲图片image private String pic; - // 排序,取歌曲排序 - @ApiModelProperty(value = "排序") - private Integer sort; - // 价格 private BigDecimal price; diff --git a/luoo_common/src/main/java/dto/MallProductAttributeValue.java b/luoo_common/src/main/java/dto/MallProductAttributeValue.java index a51f9e7..a9e1370 100644 --- a/luoo_common/src/main/java/dto/MallProductAttributeValue.java +++ b/luoo_common/src/main/java/dto/MallProductAttributeValue.java @@ -22,6 +22,9 @@ import java.io.Serializable; @NoArgsConstructor public class MallProductAttributeValue implements Serializable { + private Long id; + + private Long productId; // 商品属性id private Long productAttributeId; diff --git a/luoo_music/src/main/java/com/luoo/music/config/MallConfig.java b/luoo_music/src/main/java/com/luoo/music/config/MallConfig.java new file mode 100644 index 0000000..84666bc --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/config/MallConfig.java @@ -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; +} diff --git a/luoo_music/src/main/java/com/luoo/music/config/RabbitMQConfig.java b/luoo_music/src/main/java/com/luoo/music/config/RabbitMQConfig.java new file mode 100644 index 0000000..ff5751a --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/config/RabbitMQConfig.java @@ -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()); + } +} diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongAddDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongAddDTO.java index c70b840..f732b81 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongAddDTO.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongAddDTO.java @@ -6,6 +6,7 @@ import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; +import java.math.BigDecimal; import java.util.List; /** @@ -32,7 +33,7 @@ public class AlbumSongAddDTO implements Serializable { private Integer charge; @ApiModelProperty("歌曲定价") - private Float price; + private BigDecimal price; @ApiModelProperty("歌手") @NotBlank(message = "歌手不能为空") diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongRequireDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongRequireDTO.java index 943bab3..d2cdd35 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongRequireDTO.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/response/AlbumSongRequireDTO.java @@ -6,6 +6,7 @@ import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; +import java.math.BigDecimal; import java.util.List; /** @@ -32,7 +33,7 @@ public class AlbumSongRequireDTO implements Serializable { private Integer charge; @ApiModelProperty("歌曲定价") - private Float price; + private BigDecimal price; @ApiModelProperty("歌手") @NotBlank(message = "歌手不能为空") diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java b/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java index 7800171..66820f7 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java @@ -11,6 +11,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; import java.io.Serializable; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.Date; import java.util.List; @@ -134,7 +135,7 @@ public class ArtistAlbum implements Serializable { @Transient @ApiModelProperty("价格") - private Float price; + private BigDecimal price; @Transient @ApiModelProperty("风格列表") diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java b/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java index e56f094..2ccce54 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java @@ -13,6 +13,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; @@ -108,7 +109,7 @@ public class SongInfo implements Serializable { private Integer charge; @ApiModelProperty("歌曲定价") - private Float price; + private BigDecimal price; // @ApiModelProperty("编曲") diff --git a/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java b/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java index b3421e9..1d32119 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java @@ -2,11 +2,14 @@ package com.luoo.music.service; import api.PageResult; import com.luoo.music.client.UserClient; +import com.luoo.music.config.MallConfig; import com.luoo.music.dao.*; import com.luoo.music.dto.response.*; import com.luoo.music.pojo.*; import com.luoo.music.util.Constants; import constants.ErrorConstants; +import dto.MallProduct; +import dto.MallProductAttributeValue; import dto.UserLoginDto; import enums.AlbumStateEnum; import enums.SongInfoChargeEnum; @@ -16,6 +19,7 @@ import exception.BizException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.ObjectUtils; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -32,6 +36,7 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import java.math.BigDecimal; import java.time.LocalDate; import java.util.*; import java.util.stream.Collectors; @@ -74,6 +79,12 @@ public class AlbumService { @Autowired private UserClient userClient; + @Autowired + private MallConfig mallConfig; + + @Autowired + private RabbitTemplate rabbitTemplate; + public PageResult getList(AlbumSearchDTO albumSearchDTO, Integer page, Integer size) { List result = new ArrayList<>(); Sort sort = new Sort(Sort.Direction.DESC, "createTime"); @@ -254,7 +265,7 @@ public class AlbumService { UserLoginDto user = jwtUtil.getUserLoginDto(token); if (user != null) { Integer type = artistAlbum.getType(); - if(ObjectUtils.notEqual(UserTypeEnum.ARTIST_PERSON.getCode(), type) && + if (ObjectUtils.notEqual(UserTypeEnum.ARTIST_PERSON.getCode(), type) && ObjectUtils.notEqual(UserTypeEnum.ARTIST_BAND.getCode(), type) ) { throw new BizException(ErrorConstants.USER_IS_NOT_ARTIST); @@ -262,7 +273,7 @@ public class AlbumService { // 校验是否通过实名认证 Boolean realNameInfo = userClient.getRealNameInfo(user.getUserId()); - if(!realNameInfo) { + if (!realNameInfo) { // 未通过实名认证 throw new BizException(ErrorConstants.THE_REAL_NAME_AUTHENTICATION_IS_NOT_PASSED); } @@ -299,7 +310,7 @@ public class AlbumService { ArtistAlbum artistAlbum = new ArtistAlbum(); BeanUtils.copyProperties(albumUpdateDTO, artistAlbum); - ArtistAlbum old = checkAlbum(token, artistAlbum.getId()); + ArtistAlbum old = checkAlbumIsSelf(token, artistAlbum.getId()); artistAlbum.setArtistId(old.getArtistId()); artistAlbum.setArtistName(old.getArtistName()); @@ -309,15 +320,20 @@ public class AlbumService { @Transactional(rollbackFor = Exception.class) public void changeAlbumState(String token, String id, Integer state) { - ArtistAlbum artistAlbum = checkAlbum(token, id); + ArtistAlbum artistAlbum = checkAlbumIsSelf(token, id); switch (state) { case -1: + // 不可抗力强制下架 break; case 1: // 申请审核操作 checkForApply(id, artistAlbum); break; + case 2: + case 3: + checkAlbum(artistAlbum); + break; case 4: // 上架操作 shelving(artistAlbum); @@ -332,7 +348,7 @@ public class AlbumService { } artistAlbum.setState(state); - if(ObjectUtils.notEqual(state, AlbumStateEnum.FORCE.getCode())) { + if (ObjectUtils.notEqual(state, AlbumStateEnum.FORCE.getCode())) { // 强制下架不校验是否本人操作 checkUserIsSelf(token, 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())) { throw new BizException(ErrorConstants.STATE_ERROR); } + + // 拼接MALL模块需要的商品对象和参数对象 + List 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 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 mallMqMap = new HashMap<>(); + mallMqMap.put("songId", songInfo.getId()); + mallMqMap.put("mallProduct", mallProduct); + mallMqMap.put("attributeValueList", attributeValueList); + + rabbitTemplate.convertAndSend("luoo_mall_product_add", mallMqMap); + } + + + // 上架的同时,发起MQ,MALL接收到后会调用商品新增的接口 } /** @@ -428,7 +485,7 @@ public class AlbumService { throw new BizException(ErrorConstants.THE_SONG_DOES_NOT_EXIST); } - checkAlbum(token, artistAlbumSong.getAlbumId()); + checkAlbumIsSelf(token, artistAlbumSong.getAlbumId()); artistAlbumSongDao.delete(artistAlbumSong); } @@ -440,7 +497,7 @@ public class AlbumService { * @param id 专辑id * @return 如果是本人操作,返回该专辑对象 */ - private ArtistAlbum checkAlbum(String token, String id) { + private ArtistAlbum checkAlbumIsSelf(String token, String id) { ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get(); UserLoginDto user = jwtUtil.getUserLoginDto(token); @@ -466,7 +523,7 @@ public class AlbumService { @Transactional(rollbackFor = Exception.class) public void addNewSong(String token, String id, AlbumSongAddDTO albumSongAddDTO) { UserLoginDto user = jwtUtil.getUserLoginDto(token); - ArtistAlbum artistAlbum = checkAlbum(token, id); + ArtistAlbum artistAlbum = checkAlbumIsSelf(token, id); addSongForAlbum(albumSongAddDTO, user, artistAlbum); } @@ -481,7 +538,7 @@ public class AlbumService { // 定价不能为空 throw new BizException(ErrorConstants.PRICE_CAN_NOT_BE_EMPTY); } - if (albumSongRequireDTO.getPrice() <= 0) { + if (albumSongRequireDTO.getPrice().compareTo(BigDecimal.ZERO) <= 0) { // 定价必须大于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); } - if (albumSongAddDTO.getPrice() <= 0) { + if (albumSongAddDTO.getPrice().compareTo(BigDecimal.ZERO) <= 0) { // 定价必须大于0 throw new BizException(ErrorConstants.PRICING_MUST_BE_GREATER_THAN_0); } diff --git a/luoo_music/src/main/resources/bootstrap.yml b/luoo_music/src/main/resources/bootstrap.yml index d58b2de..4c90f91 100644 --- a/luoo_music/src/main/resources/bootstrap.yml +++ b/luoo_music/src/main/resources/bootstrap.yml @@ -58,13 +58,13 @@ spring: type: caffeine mall: - product: - brandId: 60 - productCategoryId: 57 - productAttributeCategoryId: 16 - attribute: - artistId: 74 - artistName: 75 - albumId: 76 - albumName: 77 - songId: 78 + brandId: 60 + brandName: 雀乐 + productCategoryId: 57 + productCategoryName: 歌曲 + productAttributeCategoryId: 16 + artistId: 74 + artistName: 75 + albumId: 76 + albumName: 77 + songId: 78 diff --git a/luoo_music/src/main/resources/sql/20240428.sql b/luoo_music/src/main/resources/sql/20240428.sql index fecc1d8..ec777e9 100644 --- a/luoo_music/src/main/resources/sql/20240428.sql +++ b/luoo_music/src/main/resources/sql/20240428.sql @@ -41,7 +41,7 @@ alter table tb_song_info add mv_url varchar(50) null comment 'mv'; alter table tb_song_info - add price float null comment '价格'; + add price decimal null comment '价格'; alter table tb_song_info add version int null comment '歌曲版本';