Skip to content

Commit

Permalink
Update qiusheng-core 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KADGang committed Jun 8, 2022
1 parent 947eb7a commit 7377f14
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 39 deletions.
2 changes: 1 addition & 1 deletion api-entity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>QiuSheng-Dubbo</artifactId>
<artifactId>QiuSheng</artifactId>
<groupId>org.pockettech.qiusheng</groupId>
<version>1.0.0</version>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.pockettech.qiusheng.entity.data.Chart;
import org.pockettech.qiusheng.entity.data.Song;
import org.pockettech.qiusheng.entity.data.User;
import org.springframework.util.ResourceUtils;

import java.io.*;
import java.math.BigInteger;
Expand All @@ -24,6 +25,7 @@
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

//该类为谱面文件处理的工具类,包含一系列对谱面文件处理的方法
@NoArgsConstructor
public class ChartFileHandler {

Expand All @@ -42,6 +44,31 @@ public ChartFileHandler(String rootResourcePath) {
this.rootResourcePath = rootResourcePath;
}

public static String getLocalFilePath() throws FileNotFoundException {
String os = System.getProperty("os.name");
String filePath = "";

if (os.toLowerCase().startsWith("win")) {
File path = new File(ResourceUtils.getURL("classpath:").getPath());
filePath = path.getParentFile().getParentFile().getParent() + File.separator + "MalodyV" + File.separator;
// 项目作为jar包运行时路径会带上“file:\\”,在此找到并删除
int sub = filePath.indexOf("file:" + File.separator);
if (sub != -1){
filePath = filePath.substring(sub + ("file:" + File.separator).length());
}
} else {
filePath = "MalodyV" + File.separator;
}
return filePath;
}

public static boolean deleteFileFromChart(Chart chart) throws FileNotFoundException {
String filePath = getLocalFilePath() + "_song_" + chart.getSid() + File.separator + chart.getC_file_path().substring(chart.getC_file_path().lastIndexOf("/") + 1);
File file = new File(filePath);

return file.delete();
}

//获取文件后缀
public static String getFileExtension(String filePath) {
String extension = "";
Expand Down
2 changes: 1 addition & 1 deletion api-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>QiuSheng-Dubbo</artifactId>
<artifactId>QiuSheng</artifactId>
<groupId>org.pockettech.qiusheng</groupId>
<version>1.0.0</version>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>org.pockettech.qiusheng</groupId>
<artifactId>QiuSheng-Dubbo</artifactId>
<artifactId>QiuSheng</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<modules>
Expand Down
3 changes: 2 additions & 1 deletion qiusheng-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>QiuSheng-Dubbo</artifactId>
<artifactId>QiuSheng</artifactId>
<groupId>org.pockettech.qiusheng</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>qiusheng-core</artifactId>
<version>1.1.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.pockettech.qiusheng.config;

import org.pockettech.qiusheng.entity.tools.ChartFileHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.io.File;
import java.io.IOException;

@Configuration
Expand All @@ -15,19 +14,9 @@ public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String file_path = null;
String os = System.getProperty("os.name");

try {
if (os.toLowerCase().startsWith("win")) {
File path = new File(ResourceUtils.getURL("classpath:").getPath());
file_path = path.getParentFile().getParentFile().getParent() + File.separator + "MalodyV" + File.separator;
int sub = file_path.indexOf("file:" + File.separator);
if (sub != -1){
file_path = file_path.substring(sub + ("file:" + File.separator).length());
}
} else {
file_path = "MalodyV" + File.separator;
}
file_path = ChartFileHandler.getLocalFilePath();
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.pockettech.qiusheng.dao;

import org.apache.ibatis.annotations.Param;
import org.pockettech.qiusheng.entity.data.Chart;
import org.pockettech.qiusheng.entity.data.Song;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.pockettech.qiusheng.entity.tools.ChartFileHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.DigestUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

Expand Down Expand Up @@ -156,20 +155,7 @@ public void uploading(@RequestParam(required = false) MultipartFile file,
log.info("已收到" + name);

try {
String os = System.getProperty("os.name");
String filePath = "";

if (os.toLowerCase().startsWith("win")) {
File path = new File(ResourceUtils.getURL("classpath:").getPath());
filePath = path.getParentFile().getParentFile().getParent() + File.separator + "MalodyV" + File.separator;
// 项目作为jar包运行时路径会带上“file:\\”,在此找到并删除
int sub = filePath.indexOf("file:" + File.separator);
if (sub != -1){
filePath = filePath.substring(sub + ("file:" + File.separator).length());
}
} else {
filePath = "MalodyV" + File.separator;
}
String filePath = ChartFileHandler.getLocalFilePath();

filePath = filePath + "_song_" + sid + File.separator;
log.info("----------上传路径为" + filePath + "----------");
Expand All @@ -196,7 +182,7 @@ public void uploading(@RequestParam(required = false) MultipartFile file,

log.info("文件" + name + "存入成功");

//TODO:此处存在可能的隐患:通常情况下客户端会优先传输铺面文件进行谱面信息在数据库登记,
//TIP:此处存在可能的隐患:通常情况下客户端会优先传输铺面文件进行谱面信息在数据库登记,
// 此后对音频文件进行分析即可更新数据库中的信息,不知道会不会存在不寻常的情况如谱面文件上传失败。
if (ChartFileHandler.getFileExtension(name).equals(".mc")) {
ChartFileHandler chartFileHandler = new ChartFileHandler("http://" + localhost + ":" + port + "/resource");
Expand Down Expand Up @@ -337,9 +323,13 @@ public DownloadResult chartDownload(@RequestParam(required = false) int cid) {

@PostMapping("/admin/store/deleteChart")
@ResponseBody
public int deleteChart(@RequestParam int cid) {
public int deleteChart(@RequestParam int cid) throws FileNotFoundException {
//TODO:考虑添加删除铺面文件的选项
Chart chart = chartDao.findChartByCid(cid);
if (!ChartFileHandler.deleteFileFromChart(chart))
return 1;

int deleteCode = chartDao.deleteChart(cid);
//TODO:添加删除铺面文件的选项与逻辑

if (deleteCode == 0) {
log.info("删除谱面(cid: " + cid + ")时出错,可能原因为数据库中并未存在该谱面");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
package org.pockettech.qiusheng.impl;

import lombok.extern.slf4j.Slf4j;
import org.pockettech.qiusheng.dao.ChartDao;
import org.pockettech.qiusheng.entity.data.Chart;
import org.pockettech.qiusheng.entity.data.Song;
import org.pockettech.qiusheng.api.StoreListService;
import org.pockettech.qiusheng.dao.SongDao;
import org.pockettech.qiusheng.entity.result.ListResult;
import org.pockettech.qiusheng.entity.result.SongResult;
import org.pockettech.qiusheng.entity.builder.StoreConditionalFilterBuilder;
import org.pockettech.qiusheng.entity.filter.StoreConditionalFilter;
import org.pockettech.qiusheng.entity.tools.ChartFileHandler;
import org.pockettech.qiusheng.entity.tools.SongFilterHandle;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

//这里是返回歌曲列表的服务,以及推荐列表的服务
@RestController
@Slf4j
public class StoreListServiceImpl implements StoreListService {
@Resource
SongDao songDao;
@Resource
ChartDao chartDao;

StoreConditionalFilterBuilder builder = new StoreConditionalFilterBuilder();
// 歌曲列表
Expand Down Expand Up @@ -89,17 +97,33 @@ public ListResult<SongResult> storePromote(@RequestParam(required = false) Integ

@PostMapping("/admin/store/deleteSong")
@ResponseBody
public int deleteSong(@RequestParam int sid) {
//TODO:添加删除歌曲以下所有铺面文件的选项与逻辑
public int deleteSong(@RequestParam int sid) throws FileNotFoundException {
File songFolder = new File(ChartFileHandler.getLocalFilePath() + "_song_" + String.valueOf(sid));

for (File f : Objects.requireNonNull(songFolder.listFiles()))
if (!f.delete())
return 1;

if (!songFolder.delete())
return 1;

//TODO:添加删除歌曲以下所有铺面文件的选项与逻辑
List<Chart> charts =chartDao.findSomeChartBySid(sid, 0, 50);
for (Chart chart: charts) {
if (chartDao.deleteChart(chart.getCid()) == 0) {
log.info("删除谱面(cid: " + chart.getCid() + ")时出错,可能原因为数据库中并未存在该谱面");
return 1;
} else
log.info("成功删除谱面(cid: " + chart.getCid() + ")");
}

int deleteCode = songDao.deleteSong(sid);

if (deleteCode == 0) {
log.info("删除谱面(cid: " + sid + ")时出错,可能原因为数据库中并未存在该谱面");
log.info("删除歌曲(sid: " + sid + ")时出错,可能原因为数据库中并未存在该歌曲");
return 1;
} else
log.info("成功删除谱面(cid: " + sid + ")");
log.info("成功删除歌曲(sid: " + sid + ")以及其下所有谱面文件和信息");

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions qiusheng-core/src/main/resources/mapping/ChartMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@

<resultMap id="findChartsBySidMap" type="org.pockettech.qiusheng.entity.data.Chart">
<id column="cid" property="cid" jdbcType="INTEGER"/>
<result column="sid" property="sid" jdbcType="INTEGER"/>
<result column="uid" property="uid" jdbcType="INTEGER"/>
<result column="version" property="version" jdbcType="VARCHAR"/>
<result column="level" property="level" jdbcType="INTEGER"/>
<result column="type" property="type" jdbcType="INTEGER"/>
<result column="size" property="size" jdbcType="INTEGER"/>
<result column="c_mode" property="c_mode" jdbcType="INTEGER"/>
<result column="c_file_path" property="c_file_path" jdbcType="VARCHAR"/>
<collection property="user" ofType="org.pockettech.qiusheng.entity.data.User">
<id column="uid" property="uid" jdbcType="INTEGER"/>
<result column="user_name" property="user_name" jdbcType="VARCHAR"/>
Expand Down

0 comments on commit 7377f14

Please sign in to comment.