Commit c42bc764691326b01606ab66b6bd5f47fde0f7da

Authored by 王明元
1 parent a04b7462

2022年10月2日22:39:29 避开中文文件夹名称, 修改打印日志, 增加手动处理设置封面图程序

fw-dalaran-server/src/main/java/cn/fw/dalaran/server/controller/common/DataExchangeController.java
@@ -126,8 +126,8 @@ public class DataExchangeController { @@ -126,8 +126,8 @@ public class DataExchangeController {
126 * @throws Exception 126 * @throws Exception
127 */ 127 */
128 @GetMapping("/calcSimilarity") 128 @GetMapping("/calcSimilarity")
129 - public Message<BigDecimal> calcSimilarity(/*String theme,*/ Long themeId, String fid, String coverUrl, String account, String itemId, Integer type) throws Exception {  
130 - return success(commonBizService.validCover(/*theme,*/ themeId, fid, coverUrl, account, itemId, type)); 129 + public Message<BigDecimal> calcSimilarity(String theme, Long themeId, String fid, String coverUrl, String account, String itemId, Integer type) throws Exception {
  130 + return success(commonBizService.validCover(theme, themeId, fid, coverUrl, account, itemId, type));
131 } 131 }
132 132
133 /** 133 /**
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/biz/CommonBizService.java
@@ -214,7 +214,7 @@ public class CommonBizService { @@ -214,7 +214,7 @@ public class CommonBizService {
214 .list(); 214 .list();
215 for (ThemeFile themeFile : list) { 215 for (ThemeFile themeFile : list) {
216 try { 216 try {
217 - final BigDecimal coverSimilarity = this.validCover(/*activityTheme.getTheme(),*/ themeFile.getThemeId(), themeFile.getFileId(), videoCover, accountNo, videoId, 1); 217 + final BigDecimal coverSimilarity = this.validCover(activityTheme.getTheme(), themeFile.getThemeId(), themeFile.getFileId(), videoCover, accountNo, videoId, 1);
218 if (validCover = coverSimilarity.compareTo(rate) >= 0) 218 if (validCover = coverSimilarity.compareTo(rate) >= 0)
219 break; 219 break;
220 } catch (Exception e) { 220 } catch (Exception e) {
@@ -491,7 +491,7 @@ public class CommonBizService { @@ -491,7 +491,7 @@ public class CommonBizService {
491 .list(); 491 .list();
492 for (ThemeFile themeFile : list) { 492 for (ThemeFile themeFile : list) {
493 try { 493 try {
494 - final BigDecimal coverSimilarity = this.validCover(/*activityTheme.getTheme(),*/ activityTheme.getId(), themeFile.getFileId(), liveCover, accountNo, roomNo, 2); 494 + final BigDecimal coverSimilarity = this.validCover(activityTheme.getTheme(), activityTheme.getId(), themeFile.getFileId(), liveCover, accountNo, roomNo, 2);
495 if (validCover = coverSimilarity.compareTo(rate) >= 0) 495 if (validCover = coverSimilarity.compareTo(rate) >= 0)
496 break; 496 break;
497 } catch (Exception e) { 497 } catch (Exception e) {
@@ -968,7 +968,7 @@ public class CommonBizService { @@ -968,7 +968,7 @@ public class CommonBizService {
968 * @return 封面图匹配度 968 * @return 封面图匹配度
969 * @throws Exception 969 * @throws Exception
970 */ 970 */
971 - public BigDecimal validCover(/*String theme,*/ Long themeId, String fileId, String coverUrl, String account, String itemId, Integer type) throws Exception { 971 + public BigDecimal validCover(String theme, Long themeId, String fileId, String coverUrl, String account, String itemId, Integer type) throws Exception {
972 int[][] imagePixArr1;// 图片1的像素数组 972 int[][] imagePixArr1;// 图片1的像素数组
973 int[][] imagePixArr2;// 图片2的像素数组 973 int[][] imagePixArr2;// 图片2的像素数组
974 File imageFile1 = this.findLocalCacheImageTheme(/*theme,*/ themeId, fileId); 974 File imageFile1 = this.findLocalCacheImageTheme(/*theme,*/ themeId, fileId);
@@ -989,7 +989,7 @@ public class CommonBizService { @@ -989,7 +989,7 @@ public class CommonBizService {
989 } 989 }
990 } 990 }
991 imagePixArr2 = ImageUtils.readImagePixel(imageFile2); 991 imagePixArr2 = ImageUtils.readImagePixel(imageFile2);
992 - String msg = String.format("\n 主题: %s\n 设置封面文件id: %s\n 账户号: %s\n %s%s\n", /*theme,*/ fileId, account, Objects.equals(type, 1) ? "短视频id: " : "直播间号: ", itemId); 992 + String msg = String.format("\n 主题id: %s \n 主题名: %s\n 设置封面文件id: %s\n 账户号: %s\n %s%s\n", themeId, theme, fileId, account, Objects.equals(type, 1) ? "短视频id: " : "直播间号: ", itemId);
993 return BigDecimal.valueOf(ImageUtils.calcSimilarity(ImageUtils.getFingerprint(imagePixArr1), ImageUtils.getFingerprint(imagePixArr2), msg)); 993 return BigDecimal.valueOf(ImageUtils.calcSimilarity(ImageUtils.getFingerprint(imagePixArr1), ImageUtils.getFingerprint(imagePixArr2), msg));
994 } 994 }
995 995
@@ -1004,7 +1004,7 @@ public class CommonBizService { @@ -1004,7 +1004,7 @@ public class CommonBizService {
1004 */ 1004 */
1005 private File findLocalCacheImageUser(/*String theme,*/ Long themeId, String account, String itemId, Integer type) { 1005 private File findLocalCacheImageUser(/*String theme,*/ Long themeId, String account, String itemId, Integer type) {
1006 String tempDir = common.getActivityThemeCoverDir(); 1006 String tempDir = common.getActivityThemeCoverDir();
1007 - File file = new File(tempDir + File.separator + "activityTheme" + File.separator + themeId /*+ "#" + theme*/ + File.separator + account + File.separator + (Objects.equals(type, 1) ? "video" : "live")); 1007 + File file = new File(tempDir + File.separator + "activityTheme" + File.separator + themeId /*+ "#" + theme*/ + File.separator + account + File.separator + (Objects.equals(type, 1) ? "video" : "live"));
1008 if (!file.exists()) { 1008 if (!file.exists()) {
1009 boolean mkdirs = file.mkdirs(); 1009 boolean mkdirs = file.mkdirs();
1010 if (mkdirs) 1010 if (mkdirs)
@@ -1021,7 +1021,7 @@ public class CommonBizService { @@ -1021,7 +1021,7 @@ public class CommonBizService {
1021 } 1021 }
1022 1022
1023 /** 1023 /**
1024 - * 获取本地已下载的主题背景图 1024 + * 获取本地已下载的主题背景图(主题预设封面图)
1025 * 1025 *
1026 * @param theme 主题名 1026 * @param theme 主题名
1027 * @param themeId 主题id 1027 * @param themeId 主题id
@@ -1029,7 +1029,7 @@ public class CommonBizService { @@ -1029,7 +1029,7 @@ public class CommonBizService {
1029 */ 1029 */
1030 private File findLocalCacheImageTheme(/*String theme,*/ Long themeId, String fileId) { 1030 private File findLocalCacheImageTheme(/*String theme,*/ Long themeId, String fileId) {
1031 String tempDir = common.getActivityThemeCoverDir(); 1031 String tempDir = common.getActivityThemeCoverDir();
1032 - File file = new File(tempDir + "activityTheme" + File.separator + themeId /*+ "#" + theme*/ + File.separator + "settingCover"); 1032 + File file = new File(tempDir + "activityTheme" + File.separator + themeId /*+ "#" + theme*/ + File.separator + "settingCover");
1033 if (!file.exists()) { 1033 if (!file.exists()) {
1034 boolean mkdirs = file.mkdirs(); 1034 boolean mkdirs = file.mkdirs();
1035 if (mkdirs) 1035 if (mkdirs)
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/data/impl/ActivityThemeServiceImpl.java
@@ -376,6 +376,38 @@ public class ActivityThemeServiceImpl extends ServiceImpl&lt;ActivityThemeDao, Acti @@ -376,6 +376,38 @@ public class ActivityThemeServiceImpl extends ServiceImpl&lt;ActivityThemeDao, Acti
376 } 376 }
377 377
378 /** 378 /**
  379 + * 活动主题数据封面图处理
  380 + */
  381 + public static void main(String[] args) {
  382 + int themeId = 76;
  383 + String tempDir = System.getProperty("java.io.tmpdir");// 获取当前环境临时文件夹路径
  384 + Arrays.asList("1076f977869a4874bbe046627e24653a",
  385 + "409e23a6e5b04fe8999b3fd5e4897b59",
  386 + "4346c78272a5430494b034279ac51777",
  387 + "4e515025cea04d518f3c97707ae53d15",
  388 + "54081e10b2ad4323970f0ecce4874781",
  389 + "564efb8b46c641628035d6b77d85e40a",
  390 + "6ed3e5f2cb2246148f4231ea12a84c0b",
  391 + "79be977223f345f3b98523b84852ff3f",
  392 + "821294cc1fd8468aaf3b9f3dd7e00775",
  393 + "82b8f8f1ba6e45f0aaac47e69131e950",
  394 + "a948a03cc2c4431ea9ac4c60fd39c6be",
  395 + "e10bf422633c47c4a4061eaa0afe3ff2")
  396 + .forEach(item -> {
  397 + try {
  398 + File downloadFile = ImageUtils.convertFileByUrl("https://gate.feewee.cn/file/show?fid=" + item, item);
  399 + ImageUtils.modifyResolution(downloadFile.getPath(),
  400 + tempDir + "activityTheme" + File.separator + themeId /*+ "#" + activityTheme.getTheme()*/ + File.separator + "settingCover",
  401 + "fw_theme_cover_" + item,
  402 + 512, 512);
  403 + boolean result = downloadFile.delete();
  404 + } catch (Exception e) {
  405 + log.error("下载转换封面图失败", e);
  406 + }
  407 + });
  408 + }
  409 +
  410 + /**
379 * 监听器, 收到消息后执行更新主题信息 411 * 监听器, 收到消息后执行更新主题信息
380 * 412 *
381 * @param msg 消息 413 * @param msg 消息
fw-dalaran-service/src/main/test/example/ImageListener.java
@@ -19,8 +19,8 @@ public class ImageListener implements ActionListener { @@ -19,8 +19,8 @@ public class ImageListener implements ActionListener {
19 } 19 }
20 20
21 public ImageListener() throws Exception { 21 public ImageListener() throws Exception {
22 - File imageFile1 = ImageUtils.convertFileByUrl("https://gate.feewee.cn/file/show?fid=e1d71b45dd0e4d73bde25afc3e260de5");  
23 - File imageFile2 = ImageUtils.convertFileByUrl("https://gate.feewee.cn/file/show?fid=7dfedbed8996443584b6b2221b79235e"); 22 + File imageFile1 = ImageUtils.convertFileByUrl("https://gate.feewee.cn/file/show?fid=0684ce9b0d384ff1a1070c61b7ed376c");
  23 + File imageFile2 = ImageUtils.convertFileByUrl("https://gate.feewee.cn/file/show?fid=0aff5b6acf6040459b6d5e69f1290c3b");
24 //File imageFile2 = ImageUtils.convertFileByUrl("https://p2.a.yximgs.com/upic/2022/01/20/20/BMjAyMjAxMjAyMDEyMTZfNDcwOTM0NDgyXzY1MzMwMDA5Mjk0XzJfMw==_B0296c8ed5afa94b9b7a06dd1612c3ecb.jpg?tag=1-1642748356-nil-0-ndrgo4aid6-21e0d82706b2e935&clientCacheKey=3x4xb3uvxtpibvc.jpg&di=abd4f314&bp=10000"); 24 //File imageFile2 = ImageUtils.convertFileByUrl("https://p2.a.yximgs.com/upic/2022/01/20/20/BMjAyMjAxMjAyMDEyMTZfNDcwOTM0NDgyXzY1MzMwMDA5Mjk0XzJfMw==_B0296c8ed5afa94b9b7a06dd1612c3ecb.jpg?tag=1-1642748356-nil-0-ndrgo4aid6-21e0d82706b2e935&clientCacheKey=3x4xb3uvxtpibvc.jpg&di=abd4f314&bp=10000");
25 /*File imageFile1 = new File("C:\\Users\\wmy3969\\Desktop\\2.png"); 25 /*File imageFile1 = new File("C:\\Users\\wmy3969\\Desktop\\2.png");
26 File imageFile2 = new File("C:\\Users\\wmy3969\\Desktop\\2022.4.23-4.30短视频背景封面jpg\\春风十里焕新鲸喜\\1.png");*/ 26 File imageFile2 = new File("C:\\Users\\wmy3969\\Desktop\\2022.4.23-4.30短视频背景封面jpg\\春风十里焕新鲸喜\\1.png");*/