完善c端接口
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
package com.ruoyi.web.controller.back;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.MusicInfo;
|
||||
import com.ruoyi.common.core.domain.entity.ShopUser;
|
||||
import com.ruoyi.common.utils.MusicUtil;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.system.config.AliConfig;
|
||||
import com.ruoyi.system.mapper.MusicInfoMapper;
|
||||
import com.ruoyi.system.mapper.ShopUserMapper;
|
||||
import com.ruoyi.system.service.ShopUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -12,20 +20,33 @@ import javax.servlet.http.HttpServletResponse;
|
||||
@RestController
|
||||
public class FileController {
|
||||
|
||||
@Autowired
|
||||
private ShopUserMapper shopUserMapper;
|
||||
@Autowired
|
||||
private MusicInfoMapper musicInfoMapper;
|
||||
|
||||
/**
|
||||
* 下载OSS文件
|
||||
*/
|
||||
@GetMapping("/download/{objectName}/{fileName}")
|
||||
public void downloadOssFile(@PathVariable String objectName,@PathVariable String fileName, HttpServletResponse response) {
|
||||
@GetMapping("/download/{objectName}")
|
||||
public void downloadOssFile(@PathVariable String objectName, HttpServletResponse response) {
|
||||
try {
|
||||
String[] file = objectName.split("file/download");
|
||||
String ossPath = objectName.split("file/download")[1];
|
||||
// 获取文件字节
|
||||
if (objectName.equals("musicFile")){
|
||||
if (objectName.equals("musicFile")) {
|
||||
//TODO:// 获取是否是vip 音乐,检查用户登录状态
|
||||
|
||||
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
ShopUser shopUser = shopUserMapper.selectShopUserByUserId(userId);
|
||||
MusicInfo musicInfo = musicInfoMapper.selectByPath(objectName);
|
||||
if (musicInfo.getVip() != null && musicInfo.getVip() == 1) {
|
||||
// 判断用户vip
|
||||
if (!MusicUtil.getShopIsVip(shopUser)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
byte[] data = AliConfig.ossDown(objectName+"/"+fileName);
|
||||
String fileName = ossPath.substring(objectName.lastIndexOf("/") + 1);
|
||||
byte[] data = AliConfig.ossDown(ossPath);
|
||||
// 设置响应头,支持中文文件名
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
|
||||
@@ -36,7 +57,8 @@ public class FileController {
|
||||
try {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"msg\":\"下载失败: " + e.getMessage() + "\"}");
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,14 +66,14 @@ public class MusicSceneController extends BaseController
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:scene:add')")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody MusicScene musicScene)
|
||||
{
|
||||
return toAjax(musicSceneService.insertMusicScene(musicScene));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.ruoyi.web.controller.back;
|
||||
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.MusicInfo;
|
||||
import com.ruoyi.system.config.AliConfig;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/back/upload")
|
||||
public class UploadOSSController extends BaseController {
|
||||
|
||||
|
||||
@PostMapping("/music/file")
|
||||
public AjaxResult addFile(
|
||||
@RequestParam("file") MultipartFile file
|
||||
) throws IOException {
|
||||
// 1. 处理文件上传
|
||||
if (file != null && !file.isEmpty()) {
|
||||
// 保存文件逻辑
|
||||
return AjaxResult.error("文件不能为空");
|
||||
}
|
||||
|
||||
return AjaxResult.success(AliConfig.ossUp("musicFile/" , file.getOriginalFilename(), file.getInputStream()));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/musicImg/file")
|
||||
public AjaxResult addMusicImgFile(
|
||||
@RequestParam("file") MultipartFile file
|
||||
) throws IOException {
|
||||
// 1. 处理文件上传
|
||||
if (file != null && !file.isEmpty()) {
|
||||
// 保存文件逻辑
|
||||
return AjaxResult.error("文件不能为空");
|
||||
}
|
||||
return AjaxResult.success(AliConfig.ossUp("musicImg/" , file.getOriginalFilename(), file.getInputStream()));
|
||||
}
|
||||
|
||||
@PostMapping("/config/file")
|
||||
public AjaxResult addConfigFile(
|
||||
@RequestParam("file") MultipartFile file
|
||||
) throws IOException {
|
||||
// 1. 处理文件上传
|
||||
if (file != null && !file.isEmpty()) {
|
||||
// 保存文件逻辑
|
||||
return AjaxResult.error("文件不能为空");
|
||||
}
|
||||
return AjaxResult.success(AliConfig.ossUp("config/" , file.getOriginalFilename(), file.getInputStream()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,5 +67,13 @@ public class IndexController extends BaseController {
|
||||
return AjaxResult.success(recommendInfoService.findRecommendBindMusic());
|
||||
}
|
||||
|
||||
@GetMapping("/re/music/{reId}")
|
||||
// 获取推荐音乐
|
||||
public TableDataInfo getRecommendMusicByReId(@PathVariable String reId){
|
||||
startPage();
|
||||
List<MusicInfo> list = recommendInfoService.findRecommendMusicByReId(reId);
|
||||
return getDataTableData(list);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
package com.ruoyi.web.controller.client;
|
||||
|
||||
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.CategoryInfo;
|
||||
import com.ruoyi.common.core.domain.entity.MusicInfo;
|
||||
import com.ruoyi.common.core.domain.entity.MusicScene;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.system.service.IMusicInfoService;
|
||||
import com.ruoyi.system.service.IMusicSceneService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RequestMapping("/client/music")
|
||||
@RestController
|
||||
@@ -22,6 +23,8 @@ public class MusicController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IMusicInfoService musicService;
|
||||
@Autowired
|
||||
private IMusicSceneService musicSceneService;
|
||||
|
||||
// 根据分类获取音乐
|
||||
@RequestMapping("/cate/music")
|
||||
@@ -84,7 +87,31 @@ public class MusicController extends BaseController {
|
||||
@RequestMapping("/getMusicInfo/{musicId}")
|
||||
public AjaxResult getMusicInfo(@PathVariable String musicId){
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
return AjaxResult.success(musicService.getMusicInfo(userId,musicId));
|
||||
MusicInfo musicInfo = musicService.getMusicInfo(userId, musicId);
|
||||
if (musicInfo != null){
|
||||
return AjaxResult.success(musicInfo);
|
||||
}else {
|
||||
return new AjaxResult(HttpStatus.USER_VIP_EXPIRE, "请开通会员");
|
||||
}
|
||||
}
|
||||
|
||||
// 新增用户混音
|
||||
@RequestMapping("/add/mixMusic")
|
||||
public AjaxResult addMixMusicInfo(@RequestBody Map<String,String> param){
|
||||
MusicInfo newMusic = musicService.addMixMusicInfo(param);
|
||||
if (newMusic != null){
|
||||
return AjaxResult.success(newMusic);
|
||||
}
|
||||
return AjaxResult.error("混音错误");
|
||||
}
|
||||
|
||||
// 获取场景音乐
|
||||
@GetMapping("/scene/list")
|
||||
public TableDataInfo list(MusicScene musicScene)
|
||||
{
|
||||
startPage();
|
||||
List<MusicScene> list = musicSceneService.selectMusicSceneList(musicScene);
|
||||
return getDataTableData(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user