支持分享音乐文件夹

新增在获取音乐数据时,隐藏实际文件路径的功能
调整原播放音乐提供路径改为提供音乐MD5
This commit is contained in:
Yutousama 2022-01-06 02:59:08 +08:00
parent 006fb8c836
commit 11534b04f7
7 changed files with 644 additions and 579 deletions

View File

@ -2,9 +2,12 @@ package com.yutou.nas.Controllers;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yutou.nas.mybatis.model.MusicData;
import com.yutou.nas.utils.*;
import com.yutou.nas.Services.impl.MusicToolsServiceImpl; import com.yutou.nas.Services.impl.MusicToolsServiceImpl;
import com.yutou.nas.mybatis.model.MusicData;
import com.yutou.nas.utils.ConfigTools;
import com.yutou.nas.utils.RedisTools;
import com.yutou.nas.utils.StringUtils;
import com.yutou.nas.utils.Tools;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -15,10 +18,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import static com.yutou.nas.Datas.AppData.defaultMusicPath; import static com.yutou.nas.Datas.AppData.defaultMusicPath;
@ -36,7 +37,7 @@ public class MusicController {
json.put("code", 0); json.put("code", 0);
json.put("scan", musicTools.isScan()); json.put("scan", musicTools.isScan());
json.put("size", musicTools.getLength()); json.put("size", musicTools.getLength());
json.put("data", JSONArray.toJSON(musicTools.getMusicList())); json.put("data", JSONArray.toJSON(musicTools.getMusicList(true)));
return json.toJSONString(); return json.toJSONString();
} }
@ -58,7 +59,7 @@ public class MusicController {
json.put("code", 0); json.put("code", 0);
json.put("scan", musicTools.isScan()); json.put("scan", musicTools.isScan());
json.put("size", musicTools.getLength()); json.put("size", musicTools.getLength());
json.put("data", JSONArray.toJSON(musicTools.getPath(path, type))); json.put("data", JSONArray.toJSON(musicTools.getPath(path, type, true)));
return json.toJSONString(); return json.toJSONString();
} }
@ -71,7 +72,7 @@ public class MusicController {
if (StringUtils.isEmpty(album)) { if (StringUtils.isEmpty(album)) {
json.put("data", JSONArray.toJSON(musicTools.getAllAlbum())); json.put("data", JSONArray.toJSON(musicTools.getAllAlbum()));
} else { } else {
json.put("data", JSONArray.toJSON(musicTools.selectAlbum(album))); json.put("data", JSONArray.toJSON(musicTools.selectAlbum(album, true)));
} }
return json.toJSONString(); return json.toJSONString();
} }
@ -85,7 +86,7 @@ public class MusicController {
if (StringUtils.isEmpty(artist)) { if (StringUtils.isEmpty(artist)) {
json.put("data", JSONArray.toJSON(musicTools.getAllArtist())); json.put("data", JSONArray.toJSON(musicTools.getAllArtist()));
} else { } else {
json.put("data", JSONArray.toJSON(musicTools.selectArtist(artist))); json.put("data", JSONArray.toJSON(musicTools.selectArtist(artist, true)));
} }
return json.toJSONString(); return json.toJSONString();
} }
@ -104,9 +105,7 @@ public class MusicController {
@ResponseBody @ResponseBody
public String findFile(@RequestBody JSONObject body) { public String findFile(@RequestBody JSONObject body) {
String path = body.getString("path"); String path = body.getString("path");
if (!path.startsWith(defaultMusicPath)) {
path = Tools.base64ToString(path);
}
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
if (StringUtils.isEmpty(path)) { if (StringUtils.isEmpty(path)) {
json.put("code", -1); json.put("code", -1);
@ -114,7 +113,7 @@ public class MusicController {
return json.toJSONString(); return json.toJSONString();
} }
json.put("code", 0); json.put("code", 0);
json.put("data", musicTools.getMusicData(path)); json.put("data", musicTools.getMusicDataOfMd5(path, true));
return json.toJSONString(); return json.toJSONString();
} }
@ -147,24 +146,9 @@ public class MusicController {
@RequestMapping(value = "/nas/music/image.do", produces = MediaType.IMAGE_JPEG_VALUE) @RequestMapping(value = "/nas/music/image.do", produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody @ResponseBody
public byte[] getImage(@RequestBody JSONObject body) { public byte[] getImage(@RequestBody JSONObject body) {
String fileName = body.getString("fileName"); String md5 = body.getString("fileName");
if (!fileName.startsWith(defaultMusicPath)) {
fileName = Tools.base64ToString(fileName); File file = musicTools.getMusicOfMd5(md5, false);
}
List<MusicData> list = null;
if ("album".equals(body.getString("type"))) {
list = musicTools.selectAlbum(fileName);
}
File file;
if (list != null && !list.isEmpty()) {
fileName = list.get(0).getFile();
}
if(!fileName.startsWith("/media/yutou/disk_lvm/public/音乐/")
||fileName.endsWith("..")
||fileName.endsWith("../")){
return null;
}
file = new File(fileName);
if (file.exists()) { if (file.exists()) {
try { try {
return musicTools.readImage(file.getAbsolutePath()); return musicTools.readImage(file.getAbsolutePath());
@ -178,83 +162,87 @@ public class MusicController {
@RequestMapping("/nas/music/random.do") @RequestMapping("/nas/music/random.do")
@ResponseBody @ResponseBody
public String random() { public String random() {
List<MusicData> list = musicTools.getMusicList(); List<MusicData> list = musicTools.getMusicList(true);
MusicData data = list.get(Tools.randomCommon(0, list.size() - 1, 1)[0]); MusicData data = list.get(Tools.randomCommon(0, list.size() - 1, 1)[0]);
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("code", 0); json.put("code", 0);
try { json.put("data", data.getMd5());
json.put("data", URLEncoder.encode(getBase64(data.getFile()), "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return json.toJSONString(); return json.toJSONString();
} }
private String getBase64(String str) {
return new String(Base64.getEncoder().encode(str.getBytes()));
}
@RequestMapping("/nas/music/play.do") @RequestMapping("/nas/music/play.do")
public ResponseEntity<FileSystemResource> play(String filePath, String random) { public ResponseEntity<FileSystemResource> play(String filePath, String random) {
String _filePath;
boolean _random; boolean _random;
_random = !StringUtils.isEmpty(random) && "true".equals(random); _random = !StringUtils.isEmpty(random) && "true".equals(random);
_filePath = Tools.base64ToString(filePath);
if (_random) { if (_random) {
List<MusicData> list = musicTools.getMusicList(); List<MusicData> list = musicTools.getMusicList(true);
MusicData data = list.get(Tools.randomCommon(0, list.size() - 1, 1)[0]); MusicData data = list.get(Tools.randomCommon(0, list.size() - 1, 1)[0]);
_filePath = data.getFile(); filePath = data.getMd5();
} }
if(!_filePath.startsWith("/media/yutou/disk_lvm/public/音乐/")
||_filePath.endsWith("..") File file = musicTools.getMusicOfMd5(filePath, false);
||_filePath.endsWith("../")){
return null;
}
File file = new File(_filePath);
if (file.exists()) { if (file.exists()) {
return Tools.getFile(file); return Tools.getFile(file);
} else { } else {
return null; return null;
} }
} }
@RequestMapping("/nas/music/share.do") @RequestMapping("/nas/music/share.do")
@ResponseBody @ResponseBody
public JSONObject share(@RequestBody JSONObject data){ public JSONObject share(@RequestBody JSONObject data) {
System.out.println(data); System.out.println(data);
String file=data.getString("file"); String md5 = data.getString("file");
String token=data.getString("token"); boolean isDir = data.getBoolean("isDir");
JSONObject json=new JSONObject(); JSONObject json = new JSONObject();
File music=new File(file); File music;
if(music.exists()){ if (isDir) {
String key=Tools.getMD5(UUID.randomUUID().toString()+music.getAbsolutePath()); music = new File(md5);
RedisTools.set(key,file,3600); } else {
JSONObject item=new JSONObject(); music = musicTools.getMusicOfMd5(md5, false);
item.put("share",key); }
json.put("code",1); if (music.exists()) {
json.put("msg","ok"); String key = Tools.getMD5(UUID.randomUUID() + music.getAbsolutePath());
json.put("data",item); RedisTools.set(key, music.getAbsolutePath(), 3600);
}else{ JSONObject item = new JSONObject();
json.put("code",-1); item.put("share", key);
json.put("msg","文件不存在"); json.put("code", 1);
json.put("data","{}"); json.put("msg", "ok");
json.put("data", item);
} else {
json.put("code", -1);
json.put("msg", "文件不存在");
json.put("data", "{}");
} }
return json; return json;
} }
@RequestMapping("/nas/music/playShare.do") @RequestMapping("/nas/music/playShare.do")
@ResponseBody @ResponseBody
public JSONObject playShare(String token) throws UnsupportedEncodingException { public JSONObject playShare(String token) {
JSONObject json=new JSONObject(); JSONObject json = new JSONObject();
String redis=RedisTools.get(token); String redis = RedisTools.get(token);
if(redis!=null&&!"-999".equals(token)){ if (redis != null && !"-999".equals(token)) {
String file=redis; File file = new File(redis);
JSONObject item=new JSONObject(); JSONArray array = new JSONArray();
item.put("file",file); if (file.isFile()) {
json.put("code",0); array.add(musicTools.getMusicData(file.getAbsolutePath(), true));
json.put("data",item); } else {
}else{ for (File listFile : Objects.requireNonNull(file.listFiles())) {
json.put("code",-1); MusicData data=musicTools.getMusicData(listFile.getAbsolutePath(), true);
json.put("msg","分享已过期"); if(data!=null) {
array.add(data);
}
}
}
JSONObject item = new JSONObject();
item.put("file", array);
json.put("code", 0);
json.put("data", item);
} else {
json.put("code", -1);
json.put("msg", "分享已过期");
} }
return json; return json;
} }

View File

@ -146,7 +146,7 @@ public class MusicFavoritesController {
MusicDataExample dataExample = new MusicDataExample(); MusicDataExample dataExample = new MusicDataExample();
dataExample.createCriteria().andMd5EqualTo(favorites.getMusisMd5()); dataExample.createCriteria().andMd5EqualTo(favorites.getMusisMd5());
try { try {
dataList.add(musicDataDao.selectByExample(dataExample).get(0)); dataList.add(musicDataDao.selectByExample(dataExample,true).get(0));
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }

View File

@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import;
@Import(BTDownloadManager.class) @Import(BTDownloadManager.class)
@SpringBootApplication @SpringBootApplication
public class NasApplication { public class NasApplication {
public static final String version="1.2.4"; public static final String version="1.2.5";
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(NasApplication.class, args); SpringApplication.run(NasApplication.class, args);
AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir"); AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");

View File

@ -3,6 +3,7 @@ package com.yutou.nas.Services;
import com.yutou.nas.mybatis.model.MusicData; import com.yutou.nas.mybatis.model.MusicData;
import java.io.File;
import java.util.List; import java.util.List;
public interface IMusicToolsService { public interface IMusicToolsService {
@ -10,15 +11,16 @@ public interface IMusicToolsService {
void scanMusic(); void scanMusic();
List<MusicData> getPath(String path, boolean isDir); List<MusicData> getPath(String path, boolean isDir,boolean delPath);
MusicData getMusicData(String md5); MusicData getMusicDataOfMd5(String md5,boolean isDelFile);
MusicData getMusicData(String path,boolean isDelFile);
List<MusicData> findOfTitle(String title); List<MusicData> findOfTitle(String title,boolean isDelFile);
List<MusicData> findOfArtist(String by); List<MusicData> findOfArtist(String by,boolean isDelFile);
List<MusicData> getMusicList(); List<MusicData> getMusicList(boolean isDelFile);
int getLength(); int getLength();
@ -27,4 +29,6 @@ public interface IMusicToolsService {
String getMusicPath(); String getMusicPath();
byte[] readImage(String path) throws Exception; byte[] readImage(String path) throws Exception;
File getMusicOfMd5(String md5,boolean isDelFile);
} }

View File

@ -1,5 +1,6 @@
package com.yutou.nas.Services.impl; package com.yutou.nas.Services.impl;
import com.alibaba.fastjson.JSONObject;
import com.yutou.nas.Datas.AppData; import com.yutou.nas.Datas.AppData;
import com.yutou.nas.mybatis.dao.MusicDataDao; import com.yutou.nas.mybatis.dao.MusicDataDao;
import com.yutou.nas.mybatis.model.MusicData; import com.yutou.nas.mybatis.model.MusicData;
@ -108,7 +109,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
* @return 音乐列表 * @return 音乐列表
*/ */
@Override @Override
public List<MusicData> getPath(String path, boolean isDir) { public List<MusicData> getPath(String path, boolean isDir,boolean delPath) {
List<MusicData> list = new ArrayList<>(); List<MusicData> list = new ArrayList<>();
List<MusicData> main = new ArrayList<>(); List<MusicData> main = new ArrayList<>();
MusicDataExample example = new MusicDataExample(); MusicDataExample example = new MusicDataExample();
@ -119,7 +120,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
} }
if (isDir) { if (isDir) {
example.createCriteria().andFileLike(tmpPath.replace(File.separator, replacement) + "%"); example.createCriteria().andFileLike(tmpPath.replace(File.separator, replacement) + "%");
main = musicDataDao.selectByExample(example); main = musicDataDao.selectByExample(example,delPath);
} }
tmpPath = tmpPath.replace(File.separator, replacement) tmpPath = tmpPath.replace(File.separator, replacement)
.replace("+", "\\+") .replace("+", "\\+")
@ -127,7 +128,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
.replace("(", "\\(") .replace("(", "\\(")
.replace(")", "\\)") .replace(")", "\\)")
.replace("]", "\\]"); .replace("]", "\\]");
main.addAll(musicDataDao.selectByRegexp(tmpPath + replacement + "([^" + replacement + "]+)$")); main.addAll(musicDataDao.selectByRegexp(tmpPath + replacement + "([^" + replacement + "]+)$",delPath));
if (!path.equals(AppData.defaultMusicPath) && !"root".equals(path)) { if (!path.equals(AppData.defaultMusicPath) && !"root".equals(path)) {
MusicData t2 = new MusicData(); MusicData t2 = new MusicData();
@ -147,6 +148,8 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
return list; return list;
} }
public List<String> getAllAlbum() { public List<String> getAllAlbum() {
return musicDataDao.selectAllAlbum(); return musicDataDao.selectAllAlbum();
} }
@ -155,12 +158,12 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
return musicDataDao.selectAllArtist(); return musicDataDao.selectAllArtist();
} }
public List<MusicData> selectAlbum(String album) { public List<MusicData> selectAlbum(String album,boolean isDelFile) {
return musicDataDao.selectAlbum(album); return musicDataDao.selectAlbum(album,isDelFile);
} }
public List<MusicData> selectArtist(String artist) { public List<MusicData> selectArtist(String artist,boolean isDelFile) {
return musicDataDao.selectArtist(artist); return musicDataDao.selectArtist(artist,isDelFile);
} }
private void getDirList(String path, List<MusicData> list) { private void getDirList(String path, List<MusicData> list) {
@ -189,7 +192,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
MusicData data = getMetadata(file); MusicData data = getMetadata(file);
if (data != null) { if (data != null) {
try { try {
if (getMusicData(file.getAbsolutePath()) == null) { if (getMusicData(file.getAbsolutePath(),false) == null) {
// System.out.println(data); // System.out.println(data);
musicDataDao.insert(data); musicDataDao.insert(data);
} }
@ -202,10 +205,20 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
} }
@Override @Override
public MusicData getMusicData(String path) { public MusicData getMusicData(String path,boolean delFile) {
MusicDataExample example = new MusicDataExample(); MusicDataExample example = new MusicDataExample();
example.createCriteria().andFileEqualTo(path); example.createCriteria().andFileEqualTo(path);
List<MusicData> list = musicDataDao.selectByExample(example); List<MusicData> list = musicDataDao.selectByExample(example,delFile);
if (list != null && list.size() > 0) {
return list.get(0);
}
return null;
}
@Override
public MusicData getMusicDataOfMd5(String md5, boolean isDelFile) {
MusicDataExample example = new MusicDataExample();
example.createCriteria().andMd5EqualTo(md5);
List<MusicData> list = musicDataDao.selectByExample(example,isDelFile);
if (list != null && list.size() > 0) { if (list != null && list.size() > 0) {
return list.get(0); return list.get(0);
} }
@ -471,23 +484,23 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
} }
@Override @Override
public List<MusicData> findOfTitle(String title) { public List<MusicData> findOfTitle(String title,boolean delFile) {
return find(title, FIND_TITLE); return find(title, FIND_TITLE,delFile);
} }
@Override @Override
public List<MusicData> findOfArtist(String by) { public List<MusicData> findOfArtist(String by,boolean delFile) {
return find(by, FIND_ARTIST); return find(by, FIND_ARTIST,delFile);
} }
@Override @Override
public List<MusicData> getMusicList() { public List<MusicData> getMusicList(boolean delFile) {
return musicDataDao.selectByExample(new MusicDataExample()); return musicDataDao.selectByExample(new MusicDataExample(),delFile);
} }
@Override @Override
public int getLength() { public int getLength() {
return musicDataDao.selectByExample(new MusicDataExample()).size(); return musicDataDao.selectByExample(new MusicDataExample(),true).size();
} }
@Override @Override
@ -495,7 +508,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
return isScan; return isScan;
} }
private List<MusicData> find(String title, int type) { private List<MusicData> find(String title, int type,boolean delFile) {
List<MusicData> list; List<MusicData> list;
MusicDataExample example = new MusicDataExample(); MusicDataExample example = new MusicDataExample();
if (type == FIND_TITLE) { if (type == FIND_TITLE) {
@ -503,7 +516,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
} else if (type == FIND_ARTIST) { } else if (type == FIND_ARTIST) {
example.createCriteria().andArtistEqualTo(title); example.createCriteria().andArtistEqualTo(title);
} }
list = musicDataDao.selectByExample(example); list = musicDataDao.selectByExample(example,delFile);
return list; return list;
} }
@ -530,6 +543,19 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
return bytes; return bytes;
} }
@Override
public File getMusicOfMd5(String md5,boolean delFile) {
MusicDataExample example=new MusicDataExample();
example.createCriteria().andMd5EqualTo(md5);
List<MusicData> list=musicDataDao.selectByExample(example,delFile);
Log.i("Music Size",list.size());
if(list!=null&&!list.isEmpty()){
Log.i("Music File", list.get(0).toString());
return new File(list.get(0).getFile());
}
return null;
}
private byte[] readImageFile(File file) throws Exception { private byte[] readImageFile(File file) throws Exception {
String path = file.getAbsolutePath().replace(file.getName(), ""); String path = file.getAbsolutePath().replace(file.getName(), "");
File img = new File(path, "cover.jpg"); File img = new File(path, "cover.jpg");

View File

@ -19,9 +19,9 @@ public interface MusicDataDao {
int insertSelective(MusicData record); int insertSelective(MusicData record);
List<MusicData> selectByExample(MusicDataExample example); List<MusicData> selectByExample(@Param("example") MusicDataExample example,@Param("isDelFile") boolean isDelFile);
MusicData selectByPrimaryKey(Integer id); MusicData selectByPrimaryKey(@Param("id")Integer id,@Param("isDelFile")boolean isDelFile);
int updateByExampleSelective(@Param("record") MusicData record, @Param("example") MusicDataExample example); int updateByExampleSelective(@Param("record") MusicData record, @Param("example") MusicDataExample example);
@ -32,10 +32,11 @@ public interface MusicDataDao {
int updateByPrimaryKey(MusicData record); int updateByPrimaryKey(MusicData record);
void truncate(); void truncate();
List<MusicData> selectByRegexp(String regexp); List<MusicData> selectByRegexp(@Param("regexp")String regexp,@Param("isDelFile")boolean isDelFile);
List<String> selectAllAlbum(); List<String> selectAllAlbum();
List<String> selectAllArtist(); List<String> selectAllArtist();
List<MusicData> selectAlbum(String album); List<MusicData> selectAlbum(@Param("album")String album,@Param("isDelFile")boolean isDelFile);
List<MusicData> selectArtist(String artist); List<MusicData> selectArtist(@Param("artist")String artist,@Param("isDelFile")boolean isDelFile);
} }

View File

@ -2,32 +2,32 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yutou.nas.mybatis.dao.MusicDataDao"> <mapper namespace="com.yutou.nas.mybatis.dao.MusicDataDao">
<resultMap id="BaseResultMap" type="com.yutou.nas.mybatis.model.MusicData"> <resultMap id="BaseResultMap" type="com.yutou.nas.mybatis.model.MusicData">
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id"/>
<result column="artist" jdbcType="VARCHAR" property="artist" /> <result column="artist" jdbcType="VARCHAR" property="artist"/>
<result column="album" jdbcType="VARCHAR" property="album" /> <result column="album" jdbcType="VARCHAR" property="album"/>
<result column="title" jdbcType="VARCHAR" property="title" /> <result column="title" jdbcType="VARCHAR" property="title"/>
<result column="comment" jdbcType="VARCHAR" property="comment" /> <result column="comment" jdbcType="VARCHAR" property="comment"/>
<result column="year" jdbcType="VARCHAR" property="year" /> <result column="year" jdbcType="VARCHAR" property="year"/>
<result column="track" jdbcType="VARCHAR" property="track" /> <result column="track" jdbcType="VARCHAR" property="track"/>
<result column="disc_no" jdbcType="VARCHAR" property="discNo" /> <result column="disc_no" jdbcType="VARCHAR" property="discNo"/>
<result column="composer" jdbcType="VARCHAR" property="composer" /> <result column="composer" jdbcType="VARCHAR" property="composer"/>
<result column="artist_sort" jdbcType="VARCHAR" property="artistSort" /> <result column="artist_sort" jdbcType="VARCHAR" property="artistSort"/>
<result column="file" jdbcType="VARCHAR" property="file" /> <result column="file" jdbcType="VARCHAR" property="file"/>
<result column="lastDir" jdbcType="VARCHAR" property="lastdir" /> <result column="lastDir" jdbcType="VARCHAR" property="lastdir"/>
<result column="isDir" jdbcType="INTEGER" property="isdir" /> <result column="isDir" jdbcType="INTEGER" property="isdir"/>
<result column="bitRate" jdbcType="INTEGER" property="bitrate" /> <result column="bitRate" jdbcType="INTEGER" property="bitrate"/>
<result column="sampleRate" jdbcType="INTEGER" property="samplerate" /> <result column="sampleRate" jdbcType="INTEGER" property="samplerate"/>
<result column="noOfSamples" jdbcType="BIGINT" property="noofsamples" /> <result column="noOfSamples" jdbcType="BIGINT" property="noofsamples"/>
<result column="channelCount" jdbcType="INTEGER" property="channelcount" /> <result column="channelCount" jdbcType="INTEGER" property="channelcount"/>
<result column="encodingType" jdbcType="VARCHAR" property="encodingtype" /> <result column="encodingType" jdbcType="VARCHAR" property="encodingtype"/>
<result column="durationAsDouble" jdbcType="DOUBLE" property="durationasdouble" /> <result column="durationAsDouble" jdbcType="DOUBLE" property="durationasdouble"/>
<result column="lossless" jdbcType="INTEGER" property="lossless" /> <result column="lossless" jdbcType="INTEGER" property="lossless"/>
<result column="variableBitRate" jdbcType="INTEGER" property="variablebitrate" /> <result column="variableBitRate" jdbcType="INTEGER" property="variablebitrate"/>
<result column="md5" jdbcType="VARCHAR" property="md5" /> <result column="md5" jdbcType="VARCHAR" property="md5"/>
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
<foreach collection="oredCriteria" item="criteria" separator="or"> <foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid"> <if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")"> <trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion"> <foreach collection="criteria.criteria" item="criterion">
@ -43,7 +43,8 @@
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
@ -72,7 +73,8 @@
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
@ -84,59 +86,77 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, artist, album, title, `comment`, `year`, track, disc_no, composer, artist_sort, id
, artist, album, title, `comment`, `year`, track, disc_no, composer, artist_sort,
`file`, lastDir, isDir, bitRate, sampleRate, noOfSamples, channelCount, encodingType, `file`, lastDir, isDir, bitRate, sampleRate, noOfSamples, channelCount, encodingType,
durationAsDouble, lossless, variableBitRate, md5 durationAsDouble, lossless, variableBitRate, md5
</sql> </sql>
<sql id="Base_Column_ListNotFile">
id
, artist, album, title, `comment`, `year`, track, disc_no, composer, artist_sort,
isDir, bitRate, sampleRate, noOfSamples, channelCount, encodingType,
durationAsDouble, lossless, variableBitRate, md5
</sql>
<select id="selectByExample" parameterType="com.yutou.nas.mybatis.model.MusicDataExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.yutou.nas.mybatis.model.MusicDataExample" resultMap="BaseResultMap">
select select
<if test="distinct">
distinct <if test="isDelFile ==true">
<include refid="Base_Column_ListNotFile"/>
</if>
<if test="isDelFile != true">
<include refid="Base_Column_List"/>
</if> </if>
<include refid="Base_Column_List" />
from music_data from music_data
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
<if test="orderByClause != null"> <if test="example.orderByClause != null">
order by ${orderByClause} order by ${example.orderByClause}
</if> </if>
</select> </select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" />
<if test="isDelFile ==true">
<include refid="Base_Column_ListNotFile"/>
</if>
<if test="isDelFile != true">
<include refid="Base_Column_List"/>
</if>
from music_data from music_data
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from music_data delete
from music_data
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</delete> </delete>
<delete id="deleteByExample" parameterType="com.yutou.nas.mybatis.model.MusicDataExample"> <delete id="deleteByExample" parameterType="com.yutou.nas.mybatis.model.MusicDataExample">
delete from music_data delete from music_data
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
</delete> </delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.nas.mybatis.model.MusicData" useGeneratedKeys="true"> <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.nas.mybatis.model.MusicData"
useGeneratedKeys="true">
insert into music_data (artist, album, title, insert into music_data (artist, album, title,
`comment`, `year`, track, `comment`, `year`, track,
disc_no, composer, artist_sort, disc_no, composer, artist_sort,
`file`, lastDir, isDir, `file`, lastDir, isDir,
bitRate, sampleRate, noOfSamples, bitRate, sampleRate, noOfSamples,
channelCount, encodingType, durationAsDouble, channelCount, encodingType, durationAsDouble,
lossless, variableBitRate, md5 lossless, variableBitRate, md5)
)
values (#{artist,jdbcType=VARCHAR}, #{album,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, values (#{artist,jdbcType=VARCHAR}, #{album,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR},
#{comment,jdbcType=VARCHAR}, #{year,jdbcType=VARCHAR}, #{track,jdbcType=VARCHAR}, #{comment,jdbcType=VARCHAR}, #{year,jdbcType=VARCHAR}, #{track,jdbcType=VARCHAR},
#{discNo,jdbcType=VARCHAR}, #{composer,jdbcType=VARCHAR}, #{artistSort,jdbcType=VARCHAR}, #{discNo,jdbcType=VARCHAR}, #{composer,jdbcType=VARCHAR}, #{artistSort,jdbcType=VARCHAR},
#{file,jdbcType=VARCHAR}, #{lastdir,jdbcType=VARCHAR}, #{isdir,jdbcType=INTEGER}, #{file,jdbcType=VARCHAR}, #{lastdir,jdbcType=VARCHAR}, #{isdir,jdbcType=INTEGER},
#{bitrate,jdbcType=INTEGER}, #{samplerate,jdbcType=INTEGER}, #{noofsamples,jdbcType=BIGINT}, #{bitrate,jdbcType=INTEGER}, #{samplerate,jdbcType=INTEGER}, #{noofsamples,jdbcType=BIGINT},
#{channelcount,jdbcType=INTEGER}, #{encodingtype,jdbcType=VARCHAR}, #{durationasdouble,jdbcType=DOUBLE}, #{channelcount,jdbcType=INTEGER}, #{encodingtype,jdbcType=VARCHAR}, #{durationasdouble,jdbcType=DOUBLE},
#{lossless,jdbcType=INTEGER}, #{variablebitrate,jdbcType=INTEGER}, #{md5,jdbcType=VARCHAR} #{lossless,jdbcType=INTEGER}, #{variablebitrate,jdbcType=INTEGER}, #{md5,jdbcType=VARCHAR})
)
</insert> </insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.nas.mybatis.model.MusicData" useGeneratedKeys="true"> <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.nas.mybatis.model.MusicData"
useGeneratedKeys="true">
insert into music_data insert into music_data
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="artist != null"> <if test="artist != null">
@ -269,29 +289,55 @@
</if> </if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.yutou.nas.mybatis.model.MusicDataExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="com.yutou.nas.mybatis.model.MusicDataExample"
resultType="java.lang.Long">
select count(*) from music_data select count(*) from music_data
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause"/>
</if> </if>
</select> </select>
<select id="selectByRegexp" resultType="com.yutou.nas.mybatis.model.MusicData"> <select id="selectByRegexp" resultType="com.yutou.nas.mybatis.model.MusicData">
select * from music_data where `file` REGEXP #{regexp,jdbcType=VARCHAR} select
<if test="isDelFile ==true">
<include refid="Base_Column_ListNotFile"/>
</if>
<if test="isDelFile != true">
<include refid="Base_Column_List"/>
</if>
from music_data
where `file` REGEXP #{regexp,jdbcType=VARCHAR}
</select> </select>
<select id="selectAllAlbum" resultType="java.lang.String"> <select id="selectAllAlbum" resultType="java.lang.String">
SELECT album FROM music_data group by `album`; SELECT album
FROM music_data
group by `album`;
</select> </select>
<select id="selectAllArtist" resultType="java.lang.String"> <select id="selectAllArtist" resultType="java.lang.String">
SELECT artist FROM music_data group by `artist`; SELECT artist
FROM music_data
group by `artist`;
</select> </select>
<select id="selectAlbum" resultType="com.yutou.nas.mybatis.model.MusicData"> <select id="selectAlbum" resultType="com.yutou.nas.mybatis.model.MusicData">
select select
<include refid="Base_Column_List" />
<if test="isDelFile ==true">
<include refid="Base_Column_ListNotFile"/>
</if>
<if test="isDelFile != true">
<include refid="Base_Column_List"/>
</if>
from music_data where `album`= #{album,jdbcType=VARCHAR} from music_data where `album`= #{album,jdbcType=VARCHAR}
</select> </select>
<select id="selectArtist" resultType="com.yutou.nas.mybatis.model.MusicData"> <select id="selectArtist" resultType="com.yutou.nas.mybatis.model.MusicData">
select select
<include refid="Base_Column_List" />
<if test="isDelFile ==true">
<include refid="Base_Column_ListNotFile"/>
</if>
<if test="isDelFile != true">
<include refid="Base_Column_List"/>
</if>
from music_data where `artist`= #{artist,jdbcType=VARCHAR} from music_data where `artist`= #{artist,jdbcType=VARCHAR}
</select> </select>
<update id="updateByExampleSelective" parameterType="map"> <update id="updateByExampleSelective" parameterType="map">
@ -365,7 +411,7 @@
</if> </if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause"/>
</if> </if>
</update> </update>
<update id="updateByExample" parameterType="map"> <update id="updateByExample" parameterType="map">
@ -393,7 +439,7 @@
variableBitRate = #{record.variablebitrate,jdbcType=INTEGER}, variableBitRate = #{record.variablebitrate,jdbcType=INTEGER},
md5 = #{record.md5,jdbcType=VARCHAR} md5 = #{record.md5,jdbcType=VARCHAR}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause"/>
</if> </if>
</update> </update>
<update id="updateByPrimaryKeySelective" parameterType="com.yutou.nas.mybatis.model.MusicData"> <update id="updateByPrimaryKeySelective" parameterType="com.yutou.nas.mybatis.model.MusicData">