Commit 92664fd0c2b63c88cf872b0217892ff9df49c7f2
1 parent
24dbfaa6
2022年9月30日14:19:51 防止同名主题封面文件被误删除
Showing
7 changed files
with
31 additions
and
24 deletions
fw-dalaran-server/src/main/java/cn/fw/dalaran/server/controller/app/OtherController.java
... | ... | @@ -97,7 +97,7 @@ public class OtherController { |
97 | 97 | handleType = "删除"; |
98 | 98 | if (file.isDirectory()) |
99 | 99 | result = common.deleteAllFile(dir, file); |
100 | - else if(file.isFile()) | |
100 | + else if (file.isFile()) | |
101 | 101 | result = file.delete(); |
102 | 102 | } |
103 | 103 | log.info(String.format("%s文件或文件夹, 路径为: %s, 结果为: %s", handleType, dir, Objects.isNull(result) ? "未执行" : (result ? "成功" : "失败"))); | ... | ... |
fw-dalaran-server/src/main/java/cn/fw/dalaran/server/controller/common/DataExchangeController.java
... | ... | @@ -117,6 +117,7 @@ public class DataExchangeController { |
117 | 117 | * 计算图片相似度 |
118 | 118 | * |
119 | 119 | * @param theme 主题名 |
120 | + * @param themeId 主题id | |
120 | 121 | * @param fid 服务器图片id |
121 | 122 | * @param coverUrl 作品封面图地址 |
122 | 123 | * @param itemId 作品id |
... | ... | @@ -125,8 +126,8 @@ public class DataExchangeController { |
125 | 126 | * @throws Exception |
126 | 127 | */ |
127 | 128 | @GetMapping("/calcSimilarity") |
128 | - public Message<BigDecimal> calcSimilarity(String theme, String fid, String coverUrl, String account, String itemId, Integer type) throws Exception { | |
129 | - return success(commonBizService.validCover(theme, 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)); | |
130 | 131 | } |
131 | 132 | |
132 | 133 | /** | ... | ... |
fw-dalaran-server/src/main/java/cn/fw/dalaran/server/task/OtherTask.java
... | ... | @@ -32,7 +32,7 @@ public class OtherTask { |
32 | 32 | /** |
33 | 33 | * 每天都找已经停止抓数据7天及其更久的主题, 删除缓存封面图 |
34 | 34 | */ |
35 | - @Scheduled(fixedRate = 15 * 60 * 1000, initialDelay = 5 * 1000) | |
35 | + @Scheduled(fixedRate = 60 * 60 * 1000, initialDelay = 5 * 1000) | |
36 | 36 | public void deleteCoverFiles() { |
37 | 37 | final List<ActivityTheme> themeList = activityThemeService.lambdaQuery() |
38 | 38 | .list() |
... | ... | @@ -47,7 +47,10 @@ public class OtherTask { |
47 | 47 | sb.append(tempDir); |
48 | 48 | sb.append("activityTheme"); |
49 | 49 | sb.append(File.separator); |
50 | + sb.append(item.getId()); | |
51 | + sb.append("「"); | |
50 | 52 | sb.append(item.getTheme()); |
53 | + sb.append("」"); | |
51 | 54 | String dirPath = sb.toString(); |
52 | 55 | File file = new File(dirPath); |
53 | 56 | if (file.isDirectory()) | ... | ... |
fw-dalaran-server/src/main/resources/application-local.yml
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/biz/CommonBizService.java
... | ... | @@ -214,7 +214,7 @@ public class CommonBizService { |
214 | 214 | .list(); |
215 | 215 | for (ThemeFile themeFile : list) { |
216 | 216 | try { |
217 | - final BigDecimal coverSimilarity = this.validCover(activityTheme.getTheme(), themeFile.getFileId(), videoCover, accountNo, videoId, 1); | |
217 | + final BigDecimal coverSimilarity = this.validCover(activityTheme.getTheme(), themeFile.getThemeId(), themeFile.getFileId(), videoCover, accountNo, videoId, 1); | |
218 | 218 | if (validCover = coverSimilarity.compareTo(rate) >= 0) |
219 | 219 | break; |
220 | 220 | } catch (Exception e) { |
... | ... | @@ -491,7 +491,7 @@ public class CommonBizService { |
491 | 491 | .list(); |
492 | 492 | for (ThemeFile themeFile : list) { |
493 | 493 | try { |
494 | - final BigDecimal coverSimilarity = this.validCover(activityTheme.getTheme(), themeFile.getFileId(), liveCover, accountNo, roomNo, 2); | |
494 | + final BigDecimal coverSimilarity = this.validCover(activityTheme.getTheme(), activityTheme.getId(), themeFile.getFileId(), liveCover, accountNo, roomNo, 2); | |
495 | 495 | if (validCover = coverSimilarity.compareTo(rate) >= 0) |
496 | 496 | break; |
497 | 497 | } catch (Exception e) { |
... | ... | @@ -959,6 +959,7 @@ public class CommonBizService { |
959 | 959 | * 验证封面匹配度 |
960 | 960 | * |
961 | 961 | * @param theme 主题名 |
962 | + * @param themeId 主题id | |
962 | 963 | * @param fileId 文件id(主题配置指定封面图文件) |
963 | 964 | * @param coverUrl 用户作品封面图地址 |
964 | 965 | * @param account 账户号 |
... | ... | @@ -967,20 +968,20 @@ public class CommonBizService { |
967 | 968 | * @return 封面图匹配度 |
968 | 969 | * @throws Exception |
969 | 970 | */ |
970 | - public BigDecimal validCover(String theme, 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 { | |
971 | 972 | int[][] imagePixArr1;// 图片1的像素数组 |
972 | 973 | int[][] imagePixArr2;// 图片2的像素数组 |
973 | - File imageFile1 = this.findLocalCacheImageTheme(theme, fileId); | |
974 | + File imageFile1 = this.findLocalCacheImageTheme(theme, themeId, fileId); | |
974 | 975 | imagePixArr1 = ImageUtils.readImagePixel(imageFile1); |
975 | 976 | File imageFile2; |
976 | - File localCacheImage = this.findLocalCacheImageUser(theme, account, itemId, type); | |
977 | + File localCacheImage = this.findLocalCacheImageUser(theme, themeId, account, itemId, type); | |
977 | 978 | if (Objects.nonNull(localCacheImage)) { |
978 | 979 | imageFile2 = localCacheImage; |
979 | 980 | } else { |
980 | 981 | imageFile2 = ImageUtils.convertFileByUrl(coverUrl, itemId); |
981 | 982 | String tempDir = common.getActivityThemeCoverDir(); |
982 | 983 | File file = new File(ImageUtils.modifyResolution1(imageFile2.getPath(), |
983 | - tempDir + "activityTheme" + File.separator + theme + File.separator + account + File.separator + (Objects.equals(type, 1) ? "video" : "live"), | |
984 | + tempDir + "activityTheme" + File.separator + themeId + "「" + theme + "」" + File.separator + account + File.separator + (Objects.equals(type, 1) ? "video" : "live"), | |
984 | 985 | "fw_theme_cover_" + itemId, |
985 | 986 | 512, 512)); |
986 | 987 | if (imageFile2.delete()) { |
... | ... | @@ -996,13 +997,14 @@ public class CommonBizService { |
996 | 997 | * 获取本地已下载的封面图(用户作品封面图) |
997 | 998 | * |
998 | 999 | * @param theme 主题名 |
1000 | + * @param themeId 主题id | |
999 | 1001 | * @param account 账号 |
1000 | 1002 | * @param itemId 视频id/直播间id |
1001 | 1003 | * @param type 1:视频, 2:直播 |
1002 | 1004 | */ |
1003 | - private File findLocalCacheImageUser(String theme, String account, String itemId, Integer type) { | |
1005 | + private File findLocalCacheImageUser(String theme, Long themeId, String account, String itemId, Integer type) { | |
1004 | 1006 | String tempDir = common.getActivityThemeCoverDir(); |
1005 | - File file = new File(tempDir + File.separator + "activityTheme" + File.separator + 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")); | |
1006 | 1008 | if (!file.exists()) { |
1007 | 1009 | boolean mkdirs = file.mkdirs(); |
1008 | 1010 | if (mkdirs) |
... | ... | @@ -1021,12 +1023,13 @@ public class CommonBizService { |
1021 | 1023 | /** |
1022 | 1024 | * 获取本地已下载的主题背景图 |
1023 | 1025 | * |
1024 | - * @param theme 主题名 | |
1025 | - * @param fileId 文件id(主题配置指定封面图文件) | |
1026 | + * @param theme 主题名 | |
1027 | + * @param themeId 主题id | |
1028 | + * @param fileId 文件id(主题配置指定封面图文件) | |
1026 | 1029 | */ |
1027 | - private File findLocalCacheImageTheme(String theme, String fileId) { | |
1030 | + private File findLocalCacheImageTheme(String theme, Long themeId, String fileId) { | |
1028 | 1031 | String tempDir = common.getActivityThemeCoverDir(); |
1029 | - File file = new File(tempDir + "activityTheme" + File.separator + theme + File.separator + "settingCover"); | |
1032 | + File file = new File(tempDir + "activityTheme" + File.separator + themeId + "「" + theme + "」" + File.separator + "settingCover"); | |
1030 | 1033 | if (!file.exists()) { |
1031 | 1034 | boolean mkdirs = file.mkdirs(); |
1032 | 1035 | if (mkdirs) | ... | ... |
fw-dalaran-service/src/main/java/cn/fw/dalaran/service/data/impl/ActivityThemeServiceImpl.java
... | ... | @@ -99,7 +99,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
99 | 99 | return true; |
100 | 100 | } else { |
101 | 101 | shopIds1.retainAll(shopIds2); |
102 | - return shopIds1.size() > 0; | |
102 | + return !shopIds1.isEmpty(); | |
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
... | ... | @@ -346,7 +346,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
346 | 346 | .type(item.getType()) |
347 | 347 | .build()) |
348 | 348 | .collect(Collectors.toList()); |
349 | - if (fileList.size() > 0) | |
349 | + if (!fileList.isEmpty()) | |
350 | 350 | return themeFileService.saveBatch(fileList); |
351 | 351 | return true; |
352 | 352 | } |
... | ... | @@ -365,7 +365,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti |
365 | 365 | String fileId = item.getFid(); |
366 | 366 | File downloadFile = ImageUtils.convertFileByUrl(serverAddr + fileId, fileId); |
367 | 367 | ImageUtils.modifyResolution1(downloadFile.getPath(), |
368 | - tempDir + "activityTheme" + File.separator + activityTheme.getTheme() + File.separator + "settingCover", | |
368 | + tempDir + "activityTheme" + File.separator + activityTheme.getId() + "「" + activityTheme.getTheme() + "」" + File.separator + "settingCover", | |
369 | 369 | "fw_theme_cover_" + fileId, |
370 | 370 | 512, 512); |
371 | 371 | boolean result = downloadFile.delete(); | ... | ... |
fw-dalaran-service/src/main/test/example/ImageListener.java
... | ... | @@ -19,13 +19,13 @@ public class ImageListener implements ActionListener { |
19 | 19 | } |
20 | 20 | |
21 | 21 | public ImageListener() throws Exception { |
22 | - File imageFile1 = ImageUtils.convertFileByUrl("https://p2.a.yximgs.com/upic/2022/07/02/18/BMjAyMjA3MDIxODQyNDVfMTA2MjU5OTU5MV83ODE2MDkwNTkzMF8yXzM=_B50b9301c2d61ea0faf60a882a60cd336.jpg?tag=1-1656909189-nil-0-b9qwvimwnk-c1383d641aa55e8e&clientCacheKey=3x62tedv27b8a39.jpg&di=6f711692&bp=10000"); | |
23 | - File imageFile2 = ImageUtils.convertFileByUrl("http://gate.feewee.cn/file/show?fid=f19fd7afd5504b0f919b1f806bbe0a2a"); | |
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"); | |
24 | 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 | 25 | /*File imageFile1 = new File("C:\\Users\\wmy3969\\Desktop\\2.png"); |
26 | 26 | File imageFile2 = new File("C:\\Users\\wmy3969\\Desktop\\2022.4.23-4.30短视频背景封面jpg\\春风十里焕新鲸喜\\1.png");*/ |
27 | - imagePixArr1 = ImageUtils.readImagePixel(new File(ImageUtils.modifyResolution(imageFile1.getPath(), "C:\\Users\\wmy3969\\Desktop", 256, 512))); | |
28 | - imagePixArr2 = ImageUtils.readImagePixel(new File(ImageUtils.modifyResolution(imageFile2.getPath(), "C:\\Users\\wmy3969\\Desktop", 256, 512))); | |
27 | + imagePixArr1 = ImageUtils.readImagePixel(new File(ImageUtils.modifyResolution(imageFile1.getPath(), "C:\\Users\\wmy3969\\Desktop", 512, 512))); | |
28 | + imagePixArr2 = ImageUtils.readImagePixel(new File(ImageUtils.modifyResolution(imageFile2.getPath(), "C:\\Users\\wmy3969\\Desktop", 512, 512))); | |
29 | 29 | /*imagePixArr1 = ImageUtils.readImagePixel(imageFile1); |
30 | 30 | imagePixArr2 = ImageUtils.readImagePixel(imageFile2);*/ |
31 | 31 | } | ... | ... |