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,7 +97,7 @@ public class OtherController { | ||
97 | handleType = "删除"; | 97 | handleType = "删除"; |
98 | if (file.isDirectory()) | 98 | if (file.isDirectory()) |
99 | result = common.deleteAllFile(dir, file); | 99 | result = common.deleteAllFile(dir, file); |
100 | - else if(file.isFile()) | 100 | + else if (file.isFile()) |
101 | result = file.delete(); | 101 | result = file.delete(); |
102 | } | 102 | } |
103 | log.info(String.format("%s文件或文件夹, 路径为: %s, 结果为: %s", handleType, dir, Objects.isNull(result) ? "未执行" : (result ? "成功" : "失败"))); | 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,6 +117,7 @@ public class DataExchangeController { | ||
117 | * 计算图片相似度 | 117 | * 计算图片相似度 |
118 | * | 118 | * |
119 | * @param theme 主题名 | 119 | * @param theme 主题名 |
120 | + * @param themeId 主题id | ||
120 | * @param fid 服务器图片id | 121 | * @param fid 服务器图片id |
121 | * @param coverUrl 作品封面图地址 | 122 | * @param coverUrl 作品封面图地址 |
122 | * @param itemId 作品id | 123 | * @param itemId 作品id |
@@ -125,8 +126,8 @@ public class DataExchangeController { | @@ -125,8 +126,8 @@ public class DataExchangeController { | ||
125 | * @throws Exception | 126 | * @throws Exception |
126 | */ | 127 | */ |
127 | @GetMapping("/calcSimilarity") | 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,7 +32,7 @@ public class OtherTask { | ||
32 | /** | 32 | /** |
33 | * 每天都找已经停止抓数据7天及其更久的主题, 删除缓存封面图 | 33 | * 每天都找已经停止抓数据7天及其更久的主题, 删除缓存封面图 |
34 | */ | 34 | */ |
35 | - @Scheduled(fixedRate = 15 * 60 * 1000, initialDelay = 5 * 1000) | 35 | + @Scheduled(fixedRate = 60 * 60 * 1000, initialDelay = 5 * 1000) |
36 | public void deleteCoverFiles() { | 36 | public void deleteCoverFiles() { |
37 | final List<ActivityTheme> themeList = activityThemeService.lambdaQuery() | 37 | final List<ActivityTheme> themeList = activityThemeService.lambdaQuery() |
38 | .list() | 38 | .list() |
@@ -47,7 +47,10 @@ public class OtherTask { | @@ -47,7 +47,10 @@ public class OtherTask { | ||
47 | sb.append(tempDir); | 47 | sb.append(tempDir); |
48 | sb.append("activityTheme"); | 48 | sb.append("activityTheme"); |
49 | sb.append(File.separator); | 49 | sb.append(File.separator); |
50 | + sb.append(item.getId()); | ||
51 | + sb.append("「"); | ||
50 | sb.append(item.getTheme()); | 52 | sb.append(item.getTheme()); |
53 | + sb.append("」"); | ||
51 | String dirPath = sb.toString(); | 54 | String dirPath = sb.toString(); |
52 | File file = new File(dirPath); | 55 | File file = new File(dirPath); |
53 | if (file.isDirectory()) | 56 | if (file.isDirectory()) |
fw-dalaran-server/src/main/resources/application-local.yml
@@ -20,6 +20,6 @@ rocketmq: | @@ -20,6 +20,6 @@ rocketmq: | ||
20 | name-srv-addr: 172.26.154.169:9876 | 20 | name-srv-addr: 172.26.154.169:9876 |
21 | producer-group: ${spring.application.name} | 21 | producer-group: ${spring.application.name} |
22 | task: | 22 | task: |
23 | - switch: 'on' | 23 | + switch: 'off' |
24 | 24 | ||
25 | file-server-addr: 'http://testgate.feewee.cn/file/show?fid=' | 25 | file-server-addr: 'http://testgate.feewee.cn/file/show?fid=' |
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.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(), 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) { |
@@ -959,6 +959,7 @@ public class CommonBizService { | @@ -959,6 +959,7 @@ public class CommonBizService { | ||
959 | * 验证封面匹配度 | 959 | * 验证封面匹配度 |
960 | * | 960 | * |
961 | * @param theme 主题名 | 961 | * @param theme 主题名 |
962 | + * @param themeId 主题id | ||
962 | * @param fileId 文件id(主题配置指定封面图文件) | 963 | * @param fileId 文件id(主题配置指定封面图文件) |
963 | * @param coverUrl 用户作品封面图地址 | 964 | * @param coverUrl 用户作品封面图地址 |
964 | * @param account 账户号 | 965 | * @param account 账户号 |
@@ -967,20 +968,20 @@ public class CommonBizService { | @@ -967,20 +968,20 @@ public class CommonBizService { | ||
967 | * @return 封面图匹配度 | 968 | * @return 封面图匹配度 |
968 | * @throws Exception | 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 | int[][] imagePixArr1;// 图片1的像素数组 | 972 | int[][] imagePixArr1;// 图片1的像素数组 |
972 | int[][] imagePixArr2;// 图片2的像素数组 | 973 | int[][] imagePixArr2;// 图片2的像素数组 |
973 | - File imageFile1 = this.findLocalCacheImageTheme(theme, fileId); | 974 | + File imageFile1 = this.findLocalCacheImageTheme(theme, themeId, fileId); |
974 | imagePixArr1 = ImageUtils.readImagePixel(imageFile1); | 975 | imagePixArr1 = ImageUtils.readImagePixel(imageFile1); |
975 | File imageFile2; | 976 | File imageFile2; |
976 | - File localCacheImage = this.findLocalCacheImageUser(theme, account, itemId, type); | 977 | + File localCacheImage = this.findLocalCacheImageUser(theme, themeId, account, itemId, type); |
977 | if (Objects.nonNull(localCacheImage)) { | 978 | if (Objects.nonNull(localCacheImage)) { |
978 | imageFile2 = localCacheImage; | 979 | imageFile2 = localCacheImage; |
979 | } else { | 980 | } else { |
980 | imageFile2 = ImageUtils.convertFileByUrl(coverUrl, itemId); | 981 | imageFile2 = ImageUtils.convertFileByUrl(coverUrl, itemId); |
981 | String tempDir = common.getActivityThemeCoverDir(); | 982 | String tempDir = common.getActivityThemeCoverDir(); |
982 | File file = new File(ImageUtils.modifyResolution1(imageFile2.getPath(), | 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 | "fw_theme_cover_" + itemId, | 985 | "fw_theme_cover_" + itemId, |
985 | 512, 512)); | 986 | 512, 512)); |
986 | if (imageFile2.delete()) { | 987 | if (imageFile2.delete()) { |
@@ -996,13 +997,14 @@ public class CommonBizService { | @@ -996,13 +997,14 @@ public class CommonBizService { | ||
996 | * 获取本地已下载的封面图(用户作品封面图) | 997 | * 获取本地已下载的封面图(用户作品封面图) |
997 | * | 998 | * |
998 | * @param theme 主题名 | 999 | * @param theme 主题名 |
1000 | + * @param themeId 主题id | ||
999 | * @param account 账号 | 1001 | * @param account 账号 |
1000 | * @param itemId 视频id/直播间id | 1002 | * @param itemId 视频id/直播间id |
1001 | * @param type 1:视频, 2:直播 | 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 | String tempDir = common.getActivityThemeCoverDir(); | 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 | if (!file.exists()) { | 1008 | if (!file.exists()) { |
1007 | boolean mkdirs = file.mkdirs(); | 1009 | boolean mkdirs = file.mkdirs(); |
1008 | if (mkdirs) | 1010 | if (mkdirs) |
@@ -1021,12 +1023,13 @@ public class CommonBizService { | @@ -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 | String tempDir = common.getActivityThemeCoverDir(); | 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 | if (!file.exists()) { | 1033 | if (!file.exists()) { |
1031 | boolean mkdirs = file.mkdirs(); | 1034 | boolean mkdirs = file.mkdirs(); |
1032 | if (mkdirs) | 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,7 +99,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti | ||
99 | return true; | 99 | return true; |
100 | } else { | 100 | } else { |
101 | shopIds1.retainAll(shopIds2); | 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,7 +346,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti | ||
346 | .type(item.getType()) | 346 | .type(item.getType()) |
347 | .build()) | 347 | .build()) |
348 | .collect(Collectors.toList()); | 348 | .collect(Collectors.toList()); |
349 | - if (fileList.size() > 0) | 349 | + if (!fileList.isEmpty()) |
350 | return themeFileService.saveBatch(fileList); | 350 | return themeFileService.saveBatch(fileList); |
351 | return true; | 351 | return true; |
352 | } | 352 | } |
@@ -365,7 +365,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti | @@ -365,7 +365,7 @@ public class ActivityThemeServiceImpl extends ServiceImpl<ActivityThemeDao, Acti | ||
365 | String fileId = item.getFid(); | 365 | String fileId = item.getFid(); |
366 | File downloadFile = ImageUtils.convertFileByUrl(serverAddr + fileId, fileId); | 366 | File downloadFile = ImageUtils.convertFileByUrl(serverAddr + fileId, fileId); |
367 | ImageUtils.modifyResolution1(downloadFile.getPath(), | 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 | "fw_theme_cover_" + fileId, | 369 | "fw_theme_cover_" + fileId, |
370 | 512, 512); | 370 | 512, 512); |
371 | boolean result = downloadFile.delete(); | 371 | boolean result = downloadFile.delete(); |
fw-dalaran-service/src/main/test/example/ImageListener.java
@@ -19,13 +19,13 @@ public class ImageListener implements ActionListener { | @@ -19,13 +19,13 @@ 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://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 | //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");*/ |
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 | /*imagePixArr1 = ImageUtils.readImagePixel(imageFile1); | 29 | /*imagePixArr1 = ImageUtils.readImagePixel(imageFile1); |
30 | imagePixArr2 = ImageUtils.readImagePixel(imageFile2);*/ | 30 | imagePixArr2 = ImageUtils.readImagePixel(imageFile2);*/ |
31 | } | 31 | } |