点歌相关接口

This commit is contained in:
张松 2025-03-01 11:21:23 +08:00
parent 076c215278
commit 7a15a48e04
10 changed files with 476 additions and 0 deletions

View File

@ -0,0 +1,94 @@
package com.czg.controller.admin;
import com.czg.account.dto.song.BaseShopSongDTO;
import com.czg.account.dto.song.ShopSongAddDTO;
import com.czg.account.dto.song.ShopSongEditDTO;
import com.czg.account.entity.ShopSong;
import com.czg.account.service.ShopSongService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 点歌相关接口
* @author Administrator
*/
@RestController
@RequestMapping("/admin/shopSong")
public class ShopSongController {
@Resource
private ShopSongService shopSongService;
/**
* 点歌页面地址
* @return url
*/
@SaAdminCheckPermission(value = "shopSong:url", name = "点歌页面地址")
@GetMapping("/url")
public CzgResult<String> getSongUrl(){
return CzgResult.success(shopSongService.getSongUrl(StpKit.USER.getShopId()));
}
/**
* 歌曲列表
* @return 分页数据
*/
@SaAdminCheckPermission(value = "shopSong:list", name = "店铺歌曲查询")
@GetMapping
public CzgResult<Page<ShopSong>> list(){
return CzgResult.success(shopSongService.page(PageUtil.buildPage(), new QueryWrapper().eq(ShopSong::getShopId, StpKit.USER.getShopId()).orderBy(ShopSong::getCreateTime, false)));
}
/**
* 歌曲详情
* @return 分页数据
*/
@SaAdminCheckPermission(value = "shopSong:detail", name = "店铺歌曲详情")
@GetMapping("/detail")
public CzgResult<ShopSong> detail(@RequestParam Integer id){
return CzgResult.success(shopSongService.getOne(new QueryWrapper().eq(ShopSong::getShopId, StpKit.USER.getShopId()).eq(ShopSong::getId, id)));
}
/**
* 店铺歌曲新增
* @param shopSongAddDTO 歌曲数据
* @return 是否成功
*/
@SaAdminCheckPermission(value = "shopSong:add", name = "店铺歌曲新增")
@PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated ShopSongAddDTO shopSongAddDTO){
return CzgResult.success(shopSongService.add(StpKit.USER.getShopId(), shopSongAddDTO));
}
/**
* 歌曲修改
* @param shopSongEditDTO 修改信息
* @return 是否成功
*/
@SaAdminCheckPermission(value = "shopSong:edit", name = "店铺歌曲修改")
@PutMapping
public CzgResult<Boolean> edit(@RequestBody @Validated ShopSongEditDTO shopSongEditDTO){
return CzgResult.success(shopSongService.edit(StpKit.USER.getShopId(), shopSongEditDTO));
}
/**
* 歌曲删除
* @param shopSongEditDTO 删除信息
* @return 是否成功
*/
@SaAdminCheckPermission(value = "shopSong:del", name = "店铺歌曲删除")
@DeleteMapping
public CzgResult<Boolean> delete(@RequestBody @Validated BaseShopSongDTO shopSongEditDTO){
return CzgResult.success(shopSongService.remove(new QueryWrapper().eq(ShopSong::getShopId, StpKit.USER.getShopId()).eq(ShopSong::getId, shopSongEditDTO.getId())));
}
}

View File

@ -11,6 +11,8 @@ public interface RedisCst {
String LOGIN_CODE = "login:code:";
String SYS_LOG_KEY = "sys:log:";
/**
* key过期监听
*/
@ -33,6 +35,10 @@ public interface RedisCst {
String PRINT_ORDER_DETAIL = "print:order:detail:";
// 点歌地址url
String SONG_URL = "song:";
static String getLockKey(String sign, Object... args) {
StringBuilder key = new StringBuilder(LOCK_KEY + ":" + sign + ":");
for (Object arg : args) {
@ -51,4 +57,8 @@ public interface RedisCst {
static String getPrintOrderDetailKey(Long orderId, Long detailId) {
return PRINT_ORDER_DETAIL + orderId + ":" + detailId;
}
static String getSongUrlKey(Long shopId) {
return SONG_URL + shopId;
}
}

View File

@ -0,0 +1,25 @@
package com.czg.account.dto.song;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
/**
* 点歌-歌曲表 实体类
*
* @author zs
* @since 2025-03-01
*/
@Data
public class BaseShopSongDTO {
@NotNull
private Long id;
}

View File

@ -0,0 +1,77 @@
package com.czg.account.dto.song;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* 点歌-歌曲表 实体类
*
* @author zs
* @since 2025-03-01
*/
@Data
@Builder
@Accessors(chain = true)
public class ShopSongAddDTO{
/**
* 歌曲图片
*/
@NotBlank(message = "歌曲图片不为空")
private String img;
/**
* 歌曲名称
*/
@NotBlank(message = "歌曲名称不为空")
private String name;
/**
* 原唱歌手
*/
private String originSinger;
/**
* 演出歌手id
*/
private Integer singerId;
/**
* 演出歌手名称
*/
@NotEmpty(message = "演出歌手名称不为空")
private String singer;
/**
* 单价
*/
@NotNull(message = "单价不为空")
@DecimalMin("0.01")
private BigDecimal price;
/**
* 点播次数
*/
private Integer salesNumber;
/**
* 歌曲状态1-开启0-关闭
*/
private Integer status;
private Integer sort;
}

View File

@ -0,0 +1,68 @@
package com.czg.account.dto.song;
import jakarta.validation.constraints.*;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
/**
* 点歌-歌曲表 实体类
*
* @author zs
* @since 2025-03-01
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@Accessors(chain = true)
public class ShopSongEditDTO extends BaseShopSongDTO {
/**
* 歌曲图片
*/
@Size(min = 1, message = "歌曲图片不为空")
private String img;
/**
* 歌曲名称
*/
@Size(min = 1, message = "歌曲名称不为空")
private String name;
/**
* 原唱歌手
*/
private String originSinger;
/**
* 演出歌手id
*/
private Integer singerId;
/**
* 演出歌手名称
*/
@NotEmpty(message = "演出歌手名称不为空")
private String singer;
/**
* 单价
*/
@DecimalMin("0.01")
private BigDecimal price;
/**
* 点播次数
*/
private Integer salesNumber;
/**
* 歌曲状态1-开启0-关闭
*/
private Integer status;
private Integer sort;
}

View File

@ -0,0 +1,96 @@
package com.czg.account.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 点歌-歌曲表 实体类
*
* @author zs
* @since 2025-03-01
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_song")
public class ShopSong implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 店铺id
*/
private Long shopId;
/**
* 歌曲图片
*/
private String img;
/**
* 歌曲名称
*/
private String name;
/**
* 原唱歌手
*/
private String originSinger;
/**
* 演出歌手id
*/
private Integer singerId;
/**
* 演出歌手名称
*/
private String singer;
/**
* 单价
*/
private BigDecimal price;
/**
* 点播次数
*/
private Integer salesNumber;
/**
* 歌曲状态1-开启0-关闭
*/
private Integer status;
private Integer sort;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* 更新时间
*/
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,22 @@
package com.czg.account.service;
import com.czg.account.dto.song.ShopSongAddDTO;
import com.czg.account.dto.song.ShopSongEditDTO;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopSong;
/**
* 点歌-歌曲表 服务层
*
* @author zs
* @since 2025-03-01
*/
public interface ShopSongService extends IService<ShopSong> {
Boolean add(Long shopId, ShopSongAddDTO shopSongAddDTO);
Boolean edit(Long shopId, ShopSongEditDTO shopSongEditDTO);
String getSongUrl(Long shopId);
}

View File

@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopSong;
/**
* 点歌-歌曲表 映射层
*
* @author zs
* @since 2025-03-01
*/
public interface ShopSongMapper extends BaseMapper<ShopSong> {
}

View File

@ -0,0 +1,63 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.czg.account.dto.song.ShopSongAddDTO;
import com.czg.account.dto.song.ShopSongEditDTO;
import com.czg.config.RedisCst;
import com.czg.exception.ApiNotPrintException;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopSong;
import com.czg.account.service.ShopSongService;
import com.czg.service.account.mapper.ShopSongMapper;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 点歌-歌曲表 服务层实现
*
* @author zs
* @since 2025-03-01
*/
@Service
public class ShopSongServiceImpl extends ServiceImpl<ShopSongMapper, ShopSong> implements ShopSongService{
@Resource
private RedisService redisService;
@Override
public Boolean add(Long shopId, ShopSongAddDTO shopSongAddDTO) {
ShopSong shopSong = BeanUtil.copyProperties(shopSongAddDTO, ShopSong.class);
shopSong.setShopId(shopId);
return save(shopSong);
}
@Override
public Boolean edit(Long shopId, ShopSongEditDTO shopSongEditDTO) {
ShopSong shopSong = getOne(new QueryWrapper().eq(ShopSong::getShopId, StpKit.USER.getShopId()).eq(ShopSong::getId, shopSongEditDTO.getId()));
if (shopSong == null) {
throw new ApiNotPrintException("歌曲列表不存在");
}
BeanUtil.copyProperties(shopSongEditDTO, shopSong);
return updateById(shopSong);
}
@Override
public String getSongUrl(Long shopId) {
String code;
String key = RedisCst.getSongUrlKey(shopId);
if(redisService.hasKey(key)){
code = (String) redisService.get(key);
}else {
code = RandomStringUtils.randomAlphanumeric(12);
redisService.set(key, code);
redisService.set(key, shopId);
}
return code;
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.ShopSongMapper">
</mapper>