File was renamed from service-daylucky/src/test/java/com/ks/VisualUserTest.java |
| | |
| | | package com.ks; |
| | | package com.ks.daylucky; |
| | | |
| | | import com.ks.daylucky.exception.UserInfoException; |
| | | import com.ks.daylucky.pojo.DO.UserInfo; |
| | | import com.ks.daylucky.service.UserInfoService; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | |
| | | import org.junit.Test; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.yeshi.utils.HtmlToolUtil; |
| | | import org.yeshi.utils.HttpUtil; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.tencentcloud.COSManager; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | @SpringBootTest |
| | | public class VisualUserTest { |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | Logger logger = LoggerFactory.getLogger(VisualUserTest.class); |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void downloadPortrait () { |
| | | try { |
| | | File file = new File("D://portrait"); |
| | | File[] fs = file.listFiles(); |
| | | for (File f : fs) { |
| | | if (!f.getName().contains("3")) { |
| | | continue; |
| | | } |
| | | @Test |
| | | public void downloadPortrait() { |
| | | try { |
| | | File file = new File("D://portrait"); |
| | | File[] fs = file.listFiles(); |
| | | for (File f : fs) { |
| | | if (!f.getName().contains("3")) { |
| | | continue; |
| | | } |
| | | |
| | | if (!f.getName().contains("download")) { |
| | | String downloadDir = file.getAbsolutePath() + "/download/" + f.getName(); |
| | | if (!new File(downloadDir).exists()) { |
| | | new File(downloadDir).mkdirs(); |
| | | } |
| | | File[] cfs = f.listFiles(); |
| | | for (File cf : cfs) { |
| | | List<String> list = IOUtils.readLines(new FileInputStream(cf)); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | String fileName = cf.getName().replace(".txt", "_") + i + ".jpg"; |
| | | if (!new File(downloadDir, fileName).exists()) { |
| | | try { |
| | | IOUtils.write(IOUtils.toByteArray(HttpUtil.getAsInputStream(list.get(i))), new FileOutputStream(new File(downloadDir, fileName))); |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (!f.getName().contains("download")) { |
| | | String downloadDir = file.getAbsolutePath() + "/download/" + f.getName(); |
| | | if (!new File(downloadDir).exists()) { |
| | | new File(downloadDir).mkdirs(); |
| | | } |
| | | File[] cfs = f.listFiles(); |
| | | for (File cf : cfs) { |
| | | List<String> list = IOUtils.readLines(new FileInputStream(cf)); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | String fileName = cf.getName().replace(".txt", "_") + i + ".jpg"; |
| | | if (!new File(downloadDir, fileName).exists()) { |
| | | try { |
| | | IOUtils.write(IOUtils.toByteArray(HttpUtil.getAsInputStream(list.get(i))), new FileOutputStream(new File(downloadDir, fileName))); |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | @org.junit.jupiter.api.Test |
| | | public void addDemoUser() { |
| | | |
| | | List<String> nickNameList = new ArrayList<>(); |
| | | List<String[]> list = HtmlToolUtil.parseSQLYogExportHtmData("C:\\Users\\Administrator\\Desktop\\草稿\\昵称.htm", 1); |
| | | for (String[] sts : list) { |
| | | if (!StringUtil.isNullOrEmpty(sts[0])) { |
| | | nickNameList.add(sts[0].trim()); |
| | | } |
| | | } |
| | | System.out.println(nickNameList.size()); |
| | | |
| | | int p = 0; |
| | | int count = 0; |
| | | File dir = new File("D:\\portrait\\download_ys"); |
| | | for (File f : dir.listFiles()) { |
| | | File[] fs = f.listFiles(); |
| | | for (File ff : fs) { |
| | | if (ff.length() == 0) { |
| | | count++; |
| | | } else { |
| | | // COSManager.getInstance().uploadFile(ff,"/portrait/"+ff.getName()); |
| | | //添加昵称 |
| | | String portrait = "http://img.j.banliapp.com/portrait/" + ff.getName(); |
| | | String nickName = nickNameList.get(p); |
| | | UserInfo userInfo = new UserInfo(); |
| | | userInfo.setNickName(nickName); |
| | | userInfo.setPortrait(portrait); |
| | | userInfo.setIdentifyCode(UUID.randomUUID().toString()); |
| | | userInfo.setAlipayUid(userInfo.getIdentifyCode()); |
| | | userInfo.setAppId(5L); |
| | | userInfo.setType(UserInfo.TYPE_VIRTUAL); |
| | | userInfo.setState(UserInfo.STATE_LOGINED); |
| | | try { |
| | | userInfoService.addUserInfo(userInfo); |
| | | } catch (UserInfoException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | p++; |
| | | } |
| | | } |
| | | } |
| | | |
| | | System.out.println(count); |
| | | |
| | | |
| | | } |
| | | |
| | | } |