package zero.file.videoProject.util.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import zero.file.videoProject.bean.Student;
import zero.file.videoProject.bean.util.imageName;
import zero.file.videoProject.bean.video;
import zero.file.videoProject.mappers.untils.tonameMapper;
import java.io.File;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserMapperTest {
@Autowired
public tonameMapper tonamejpg;
@Test
public void testInsert(){
Pattern pattern = Pattern.compile("(.+(?=\\.mp4))+");
Pattern pattern2 = Pattern.compile("^\\d+");
Scanner sc = new Scanner(System.in);
System.out.println("请输入要处理的文件所在的目录:");
String folederPath = sc.nextLine();
File f = new File(folederPath);
// File f = new File("C:\\Users\\17517\\Videos\\bilibili\\Java");
File[] fileArray = f.listFiles();
String name = null;
String name2 = null;
List<Integer> list = new ArrayList<Integer>();
ArrayList<imageName> imageName = new ArrayList<imageName>();
Map<String,Integer> map = new HashMap<>();
video video = new video();
for (int i = 0; i <= fileArray.length - 1; i++) {
Matcher matcher = pattern.matcher(fileArray[i].getName());
while (matcher.find()) {
name = matcher.group();
Matcher matcher2 = pattern2.matcher(name);
while (matcher2.find()) {
name2 = matcher2.group();
int num = Integer.valueOf(name2);
imageName s1 = new imageName(name,num);
imageName.add(s1);
map.put(name,num);
}
}
}
Collections.sort(imageName, new Comparator<imageName>() {
@Override
public int compare(imageName o1, imageName o2) {
int num = o1.getNum() - o2.getNum();
return num;
}
});
for (imageName s : imageName){
System.out.println(s.getName() + "," + s.getNum());
video.setId(s.getName());
video.setCategory(s.getName());
video.setName(s.getName());
video.setLabel(s.getName());
tonamejpg.insert(video);
}
}
}