From 236b73755cd84c24753899fcb70ceeb6d1e81634 Mon Sep 17 00:00:00 2001 From: super <2903208875@qq.com> Date: Wed, 22 Apr 2026 01:09:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=90=8E=E5=8F=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=B3=BB=E7=BB=9F=E3=80=81=E4=BF=AE=E5=A4=8DBUG?= =?UTF-8?q?=E3=80=81=E5=A4=84=E7=90=86=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 + app/__pycache__/ali_oss.cpython-312.pyc | Bin 3937 -> 3864 bytes app/__pycache__/app.cpython-312.pyc | Bin 2765 -> 2765 bytes app/__pycache__/main.cpython-312.pyc | Bin 22621 -> 23695 bytes .../approve - 副本.cpython-312.pyc | Bin 0 -> 45174 bytes .../__pycache__/backend_api.cpython-312.pyc | Bin 0 -> 122 bytes .../__pycache__/price_match.cpython-312.pyc | Bin 0 -> 13517 bytes app/app.py | 2 - .../__pycache__/brand_备份.cpython-312.pyc | Bin 0 -> 35533 bytes app/main.py | 3 - backend-java/docs/patrol-delete-python-api.md | 126 ++ .../config/DeleteBrandProgressProperties.java | 6 + .../config/ModuleCleanupProperties.java | 2 +- .../aiimage/config/PropertiesConfig.java | 2 +- .../aiimage/config/StorageProperties.java | 4 +- .../config/TaskPressureProperties.java | 11 + .../controller/DeleteBrandRunController.java | 2 + .../service/DeleteBrandRunService.java | 65 +- .../service/DeleteBrandStaleTaskService.java | 81 +- .../service/DeleteBrandTaskCacheService.java | 127 +- .../controller/PatrolDeleteController.java | 371 ++++++ .../PatrolDeleteShopCandidateMapper.java | 9 + .../model/dto/PatrolDeleteCartRatioDto.java | 15 + .../dto/PatrolDeleteCountryMetricRowDto.java | 24 + .../dto/PatrolDeleteCountrySectionDto.java | 18 + .../dto/PatrolDeleteCreateTaskRequest.java | 26 + .../model/dto/PatrolDeleteShopPayloadDto.java | 44 + .../dto/PatrolDeleteSubmitResultRequest.java | 19 + .../dto/PatrolDeleteTaskBatchRequest.java | 14 + .../model/dto/PatrolDeleteTaskItemDto.java | 50 + .../PatrolDeleteShopCandidateEntity.java | 19 + .../model/vo/PatrolDeleteCreateTaskVo.java | 13 + .../model/vo/PatrolDeleteHistoryVo.java | 12 + .../model/vo/PatrolDeleteResultItemVo.java | 52 + .../model/vo/PatrolDeleteTaskBatchVo.java | 14 + .../PatrolDeleteExcelAssemblyService.java | 144 +++ .../service/PatrolDeleteResolveService.java | 166 +++ .../service/PatrolDeleteTaskCacheService.java | 211 ++++ .../service/PatrolDeleteTaskService.java | 883 +++++++++++++ .../controller/PriceTrackController.java | 5 +- .../model/vo/PriceTrackCreateTaskVo.java | 3 + .../model/vo/PriceTrackMatchShopsVo.java | 3 + .../pricetrack/service/PriceTrackService.java | 1 + .../service/PriceTrackTaskCacheService.java | 82 +- .../service/PriceTrackTaskService.java | 122 +- .../ProductRiskResolveController.java | 5 +- .../service/ProductRiskTaskCacheService.java | 83 +- .../service/ProductRiskTaskService.java | 82 +- .../mapper/ShopManageGroupMemberMapper.java | 9 + .../dto/ShopManageGroupCreateRequest.java | 7 +- .../dto/ShopManageGroupUpdateRequest.java | 8 +- .../entity/ShopManageGroupMemberEntity.java | 26 + .../model/vo/ShopManageGroupItemVo.java | 6 + .../service/ShopManageGroupService.java | 290 +++-- .../controller/ShopMatchController.java | 5 +- .../service/ShopMatchTaskCacheService.java | 83 +- .../service/ShopMatchTaskService.java | 111 +- .../ziniao/service/ZiniaoAuthService.java | 20 + .../service/ZiniaoShopIndexService.java | 16 +- .../src/main/resources/application.yml | 13 +- .../db/V27__patrol_delete_shop_candidate.sql | 8 + .../db/V28__shop_manage_group_member.sql | 17 + .../src/main/resources/logback-spring.xml | 41 + .../__pycache__/admin_api.cpython-312.pyc | Bin 84968 -> 86277 bytes backend/blueprints/admin_api.py | 24 +- backend/web_source/admin.html | 304 ++--- frontend-vue/patrol-delete.html | 12 + .../brand/components/BrandDeleteBrandTab.vue | 12 +- .../brand/components/BrandPatrolDeleteTab.vue | 1099 +++++++++++++++++ .../brand/components/BrandPriceTrackTab.vue | 133 +- .../brand/components/BrandProductRiskTab.vue | 111 +- .../brand/components/BrandShopMatchTab.vue | 60 +- .../pages/brand/components/BrandTopBar.vue | 3 +- frontend-vue/src/patrol-delete-main.ts | 12 + frontend-vue/src/shared/api/java-modules.ts | 305 ++++- .../src/shared/task-progress-config.ts | 18 + frontend-vue/vite.config.ts | 1 + 77 files changed, 5157 insertions(+), 522 deletions(-) create mode 100644 app/amazon/__pycache__/approve - 副本.cpython-312.pyc create mode 100644 app/amazon/__pycache__/backend_api.cpython-312.pyc create mode 100644 app/amazon/__pycache__/price_match.cpython-312.pyc create mode 100644 app/blueprints/__pycache__/brand_备份.cpython-312.pyc create mode 100644 backend-java/docs/patrol-delete-python-api.md create mode 100644 backend-java/src/main/java/com/nanri/aiimage/config/TaskPressureProperties.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/controller/PatrolDeleteController.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/mapper/PatrolDeleteShopCandidateMapper.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCartRatioDto.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCountryMetricRowDto.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCountrySectionDto.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCreateTaskRequest.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteShopPayloadDto.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteSubmitResultRequest.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteTaskBatchRequest.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteTaskItemDto.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/entity/PatrolDeleteShopCandidateEntity.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteCreateTaskVo.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteHistoryVo.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteResultItemVo.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteTaskBatchVo.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteExcelAssemblyService.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteResolveService.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteTaskCacheService.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteTaskService.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/mapper/ShopManageGroupMemberMapper.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/entity/ShopManageGroupMemberEntity.java create mode 100644 backend-java/src/main/resources/db/V27__patrol_delete_shop_candidate.sql create mode 100644 backend-java/src/main/resources/db/V28__shop_manage_group_member.sql create mode 100644 backend-java/src/main/resources/logback-spring.xml create mode 100644 frontend-vue/patrol-delete.html create mode 100644 frontend-vue/src/pages/brand/components/BrandPatrolDeleteTab.vue create mode 100644 frontend-vue/src/patrol-delete-main.ts create mode 100644 frontend-vue/src/shared/task-progress-config.ts diff --git a/.gitignore b/.gitignore index b7c8c7e..55e3fff 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ backend-java/target/ backend-java/data/ backend-java/*.log backend-java/logs/ +logs/ +aiimage-backend.log* +backend/tmp/ # backend-java local config backend-java/src/main/resources/application-local.yml @@ -39,3 +42,4 @@ backend/__pycache__ app/assets/ app/new_web_source app/user_data/ +OPS_REDIS_MYSQL_OPTIMIZATION_NOTES.md diff --git a/app/__pycache__/ali_oss.cpython-312.pyc b/app/__pycache__/ali_oss.cpython-312.pyc index 553a2107b3fe8336732035a910201ae0f2ced9b0..eba58bb52565164f8f39c42028e9ede1ea3c6024 100644 GIT binary patch delta 574 zcmZ9Izi-n}5XaxM9qJ~w(>A5#hZ7Z&rno6B1n3k3Lj@BZiiE^KBSRvH6qNMr46V|x z?NSMG6$t|y15#M3`~!?gtW4gJ_yY)REO6(D0Zw|K``-DU@2mGUH^`ZvO*1Me-W-2x z-a0e;Qok#O=nG$9JYwS~d8+sl$0U!HxJ=+c$?nYag@40e_*?g6PkfL=by5%MXB-C+ zKRHoC^yEIt2f|Ud92Fv@VVV$VPulf8$Hb(%i*MD6oW(#bNDEV%9Zk_djE;ARx3xQ? zBh64{9#5y9Uf?f|4jD>dGqQ{lT6!VFD}#8q(`vi*THW>CS{GVyle#&)ufLP&(GUHl zQeEaT?YZxFV38zTWL#q88B2^J<1!(THE<|9b8wA&W&9XhO|P&lF|IJy80(Cyc+PNE zLX%P0;0~J%G&17B4VJPwF(2N(j*pD29r~X6&$kDgG`^0nj9)U1C+0)@9@S1V&|P@e zalva$HilNp_}fgy3>ttcBaV5iuux&iUcxsBv{uveVG|!)h4X3dhI{qOi*~)+YE)qx ZUt6WbjLZ!h-vy=j`JbG|Mf_r&`~kPDcs&3B delta 636 zcmYL_&ui2`6vs13mWJI;YZ7pY){< z@~$#E@BW|iIK#__9S=o#Q?ixoKd}w=tuC)0NkP?S22(=6BH0D-dJGWR~#IS)liC99MLM+4QoIO7@nPulO zgCU_g42eH7KfHYg#`85&h7QR;h_0+8KUBss?_{SsRWT)?^j4!!Oe= h_Chxaye3rdRCP8G%qg~0}w2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V{jwFF{MPhJF(V92>Z+OQc1NN zMeL{Bt4Im^+>t|ktnA9{MvM)Arrd%sCc2VYL!j%jYF+BP)@dd^q4BX~*$*89YQV3RuRvV)pMHl^IYr&jJlwiw5yv`8!+4VYXwZ z-dnxUq)i9>R@4ohV!_b8DDQ$BqNb?eIMWf}L!Kk_?BG(+F(=SA$_6QAxXlY$y9~{ zxEKEP=h?fvDw3&JKS;7LB&Hk;qCha{Z=z?|v%4D-JngZk(O)9WA8Tf+5>cjN(Pdm= z3i8lniz~#4smi2v700`Zb%?{wPmPTkcmq`7x?<(`e~|q-!T`e40Hy;v?L;VHn4Z~% zR4p7Fph{G=ir^uX#0!gQSH~i8-D=QIxY+YfdK@{h9X#rSLF?!hVaxQdI1kg6*Ow_% zZ4U$;OyMEm?FHKak1qXi1rE_&^er5nMc|EvHxIcb5>v;*+FF_eBJfYpZ)ADb+~;^( zaK9(`*;Cg{b)NPXoD?!=95UHV&gBZkbHH&hijJMW3V@5@{nJ!GD;* zYbNRviGLs_+VEjX5)wAY{4(_pa|ax2><+e?zY-R=A@ DF=%1b diff --git a/app/amazon/__pycache__/approve - 副本.cpython-312.pyc b/app/amazon/__pycache__/approve - 副本.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..51270b4a835038ed5539382bc3b003ab9926d7d9 GIT binary patch literal 45174 zcmdVD3tSu5wJ$u9&6oBvu8inUi-2Bd#yG9tkuR+a8yhOY}(f->d$z?AIi|h^&?V>Iz`bG zE$OCqbH9?^5^^uyErnlcx2z{-cZ>v|$-3n|irtDH=UX?AO*)LM#GJVwzX#sYJa#8ob#&~Z5{hE}fsUg! zw3d!PBio%wC+tq5b-R#h2(Qtp}fY)#_d*qsV7D#g#Z zYiqI)!vHaAZjSL%CE38jM4 z&Of@=&JUp|zN8ZBK1|=V$8`LA-0xutpN~2H8os#2ED6S~Imq<&*ql8(E&I&UU>xJ@ zwe=q8a9Hezgd6+8zW(!)po+FQtPWd`72`GcSb7HgdRJTQ)}ZE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{_0%cD7VMOUThsD3b;3arkg{Njb;l#wv5(K{^GYZm!Lmk7& zVR(9o>8DiIAE`RP6(q@@ z#3bENJtUX3Nk%r_pvc9)uF@PMv;3WB-uUd%fvI@&(X|0>vR_-| z)fTxAPiZURc}%Q7CdC_*;)_WOWaP0iX&-BoMykKFYgjTTm8)|DDVe9*Pqwp_t4G?W zQq~N&eXL0YFZA)LpT$$ExZ%3LduU|aqmO*7(z5X-K9xCO%<~%;dyR`fGA=o`X}D#i z2;z^ljuwojvN_dbC@Uv5e5h%}ZyVJ93E#^3P-OzVN|iQOO2uS+J~xy_sggmemm~+` zlOA1*luQ0{?i<-e0GFzBF}>X5>i|bPvEkSTzXlXiv;7(qm?Psjs?Pnwj?MJ4yB jU*sjVs6et-w#a24#7OY0lD90Af1u54St9>n310sXDIL^< literal 0 HcmV?d00001 diff --git a/app/amazon/__pycache__/backend_api.cpython-312.pyc b/app/amazon/__pycache__/backend_api.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f6066b83cded0a6e57463b67fcf353cbe5c172e6 GIT binary patch literal 122 zcmX@j%ge<81ZjNNGC}lX5P=Rpvj9b=GgLBYGWxA#C}INgK7-W!l1wZph)K*%tjf=e vNlHx4PR&b+Pb|pPE2zB1VUwGmQks)$SHucb$q2;7AjU^#Mn=XWW*`dykMJ2? literal 0 HcmV?d00001 diff --git a/app/amazon/__pycache__/price_match.cpython-312.pyc b/app/amazon/__pycache__/price_match.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..56c0306d6667564b558e46f6d864e9a06c99fbac GIT binary patch literal 13517 zcmc&*d3X~?mTz5lOKRKlE#I<@!NSPK95I+9nA7Gk36P0nFdCt5Kt_ktk^p<>sUIS&I(4L%y+O`>!}5^X+`eAG@!*)vcCB z43qt5+o-y_>eZ`P*Q?)qRs1O}O@qM`eqze@%mWzq7xW=KDbdK?ei?=hVI)S%>{vVh zmbJ^cZ+W{M-g3Lbp=ejgP@clBbg0@@j+FKk?ptY3b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%n)qb9|IBs88+GfMhq(=A*z=BC~r=&w@j6ARrr_fd?^bl8-V6QwnYkeXr@zd6&BFOTXl2|O(%c3QKF(}-b$3xtLR%g6KxsKrzDzv=})Hn zjFSf*8d%zy9-tox(uSK7JzY+JDWxPv1PjJx`1@A6i8hT-60(#HJ~p@=vn;tg%Tk)l zGj11>+xuts=VS8Ho3c_YUQS8M#z}O%8NLG moduleTypes = new ArrayList<>(List.of("DEDUPE", "SPLIT", "CONVERT", "DELETE_BRAND", "PRODUCT_RISK_RESOLVE", "PRICE_TRACK")); + private List moduleTypes = new ArrayList<>(List.of("DEDUPE", "SPLIT", "CONVERT", "DELETE_BRAND", "PRODUCT_RISK_RESOLVE", "PRICE_TRACK", "SHOP_MATCH", "PATROL_DELETE")); } diff --git a/backend-java/src/main/java/com/nanri/aiimage/config/PropertiesConfig.java b/backend-java/src/main/java/com/nanri/aiimage/config/PropertiesConfig.java index 24b5973..6a48a49 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/config/PropertiesConfig.java +++ b/backend-java/src/main/java/com/nanri/aiimage/config/PropertiesConfig.java @@ -4,6 +4,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Configuration; @Configuration -@EnableConfigurationProperties({OssProperties.class, StorageProperties.class, BrandProgressProperties.class, DeleteBrandProgressProperties.class, ZiniaoProperties.class, ModuleCleanupProperties.class}) +@EnableConfigurationProperties({OssProperties.class, StorageProperties.class, BrandProgressProperties.class, DeleteBrandProgressProperties.class, ZiniaoProperties.class, ModuleCleanupProperties.class, TaskPressureProperties.class}) public class PropertiesConfig { } diff --git a/backend-java/src/main/java/com/nanri/aiimage/config/StorageProperties.java b/backend-java/src/main/java/com/nanri/aiimage/config/StorageProperties.java index 7eb4830..2fa7509 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/config/StorageProperties.java +++ b/backend-java/src/main/java/com/nanri/aiimage/config/StorageProperties.java @@ -8,7 +8,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; public class StorageProperties { private String localTempDir; private boolean cleanupEnabled = true; - private String cleanupCron = "0 0 */6 * * *"; - private long sourceRetentionHours = 48; + private String cleanupCron = "0 0 * * * *"; + private long sourceRetentionHours = 24; private long resultRetentionHours = 24; } diff --git a/backend-java/src/main/java/com/nanri/aiimage/config/TaskPressureProperties.java b/backend-java/src/main/java/com/nanri/aiimage/config/TaskPressureProperties.java new file mode 100644 index 0000000..5c7fdf8 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/config/TaskPressureProperties.java @@ -0,0 +1,11 @@ +package com.nanri.aiimage.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@Data +@ConfigurationProperties(prefix = "aiimage.task-pressure") +public class TaskPressureProperties { + private long localTaskEntityCacheMillis = 3000; + private int dbSelectBatchSize = 200; +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/controller/DeleteBrandRunController.java b/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/controller/DeleteBrandRunController.java index 45b895c..94a7ade 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/controller/DeleteBrandRunController.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/controller/DeleteBrandRunController.java @@ -106,6 +106,8 @@ public class DeleteBrandRunController { @PathVariable Long taskId, @Valid @RequestBody DeleteBrandSubmitResultRequest request, jakarta.servlet.http.HttpServletResponse response) { + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); + response.setContentType("application/json;charset=UTF-8"); try { deleteBrandRunService.submitResult(taskId, request); return ApiResponse.success(null); diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandRunService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandRunService.java index 1e357ae..4a0805c 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandRunService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandRunService.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.nanri.aiimage.common.exception.BusinessException; import com.nanri.aiimage.config.DeleteBrandProgressProperties; +import com.nanri.aiimage.config.TaskPressureProperties; import com.nanri.aiimage.modules.deletebrand.model.cache.DeleteBrandParsedFileCacheDto; import com.nanri.aiimage.modules.deletebrand.model.dto.DeleteBrandCountryResultItemDto; import com.nanri.aiimage.modules.deletebrand.model.dto.DeleteBrandProcessedCountryDto; @@ -77,6 +78,7 @@ public class DeleteBrandRunService { private final OssStorageService ossStorageService; private final ObjectMapper objectMapper; private final DeleteBrandProgressProperties deleteBrandProgressProperties; + private final TaskPressureProperties taskPressureProperties; public DeleteBrandRunVo run(DeleteBrandRunRequest request) { if (request.getUserId() == null || request.getUserId() <= 0) { @@ -248,7 +250,7 @@ public class DeleteBrandRunService { .distinct() .toList(); if (!taskIds.isEmpty()) { - List tasks = fileTaskMapper.selectBatchIds(taskIds); + List tasks = selectTasksByIdsInBatches(taskIds); for (FileTaskEntity task : tasks) { try { statusByTaskId.put(task.getId(), task.getStatus()); @@ -320,7 +322,7 @@ public class DeleteBrandRunService { } public DeleteBrandTaskDeletionStatusVo getTaskDeletionStatus(Long taskId, Long userId) { - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType()) || !userId.equals(task.getUserId())) { throw new BusinessException("任务不存在"); } @@ -487,7 +489,7 @@ public class DeleteBrandRunService { } public DeleteBrandTaskDetailVo getTaskDetail(Long taskId) { - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { throw new BusinessException("任务不存在"); } @@ -519,7 +521,7 @@ public class DeleteBrandRunService { java.util.Map taskById = new java.util.LinkedHashMap<>(cachedTasks); if (!missingTaskIds.isEmpty()) { - java.util.List dbTasks = fileTaskMapper.selectBatchIds(missingTaskIds).stream() + java.util.List dbTasks = selectTasksByIdsInBatches(missingTaskIds).stream() .filter(task -> task != null && MODULE_TYPE.equals(task.getModuleType())) .toList(); for (FileTaskEntity dbTask : dbTasks) { @@ -569,7 +571,7 @@ public class DeleteBrandRunService { java.util.Map taskById = new java.util.LinkedHashMap<>(cachedTasks); if (!missingTaskIds.isEmpty()) { - java.util.List dbTasks = fileTaskMapper.selectBatchIds(missingTaskIds).stream() + java.util.List dbTasks = selectTasksByIdsInBatches(missingTaskIds).stream() .filter(task -> task != null && MODULE_TYPE.equals(task.getModuleType())) .toList(); for (FileTaskEntity dbTask : dbTasks) { @@ -949,6 +951,32 @@ public class DeleteBrandRunService { } } + private FileTaskEntity loadTaskForExecution(Long taskId) { + Map cachedTasks = deleteBrandTaskCacheService.getTaskCacheBatch(List.of(taskId)); + FileTaskEntity cached = cachedTasks.get(taskId); + if (cached != null) { + return cached; + } + FileTaskEntity dbTask = fileTaskMapper.selectById(taskId); + if (dbTask != null && MODULE_TYPE.equals(dbTask.getModuleType())) { + deleteBrandTaskCacheService.saveTaskCache(dbTask); + } + return dbTask; + } + + private List selectTasksByIdsInBatches(List taskIds) { + List tasks = new ArrayList<>(); + if (taskIds == null || taskIds.isEmpty()) { + return tasks; + } + int batchSize = Math.max(1, taskPressureProperties.getDbSelectBatchSize()); + for (int start = 0; start < taskIds.size(); start += batchSize) { + int end = Math.min(start + batchSize, taskIds.size()); + tasks.addAll(fileTaskMapper.selectBatchIds(taskIds.subList(start, end))); + } + return tasks; + } + @Transactional public void submitResult(Long taskId, DeleteBrandSubmitResultRequest request) { log.info("[DeleteBrand] Received submitResult for taskId: {}, files count: {}", taskId, request == null || request.getFiles() == null ? 0 : request.getFiles().size()); @@ -960,7 +988,7 @@ public class DeleteBrandRunService { throw new BusinessException("files 不能为空"); } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { throw new BusinessException("任务不存在"); } @@ -981,8 +1009,10 @@ public class DeleteBrandRunService { task.setUpdatedAt(LocalDateTime.now()); task.setFinishedAt(null); fileTaskMapper.updateById(task); + deleteBrandTaskCacheService.saveTaskCache(task); } + boolean shouldTryFinalize = false; for (DeleteBrandResultFileDto fileDto : request.getFiles()) { log.info("[DeleteBrand] submitResult processing chunk -> taskId: {}, file: {}, chunkIndex: {}/{}, processedRows: {}/{}", @@ -1000,15 +1030,11 @@ public class DeleteBrandRunService { } // 更早的 duplicate fast-path:尽量在较重的校验/进度写入之前直接短路 - if (deleteBrandTaskCacheService.hasSameResultChunk(taskId, fileIdentity, fileDto.getChunkIndex(), fileDto)) { - log.info("[DeleteBrand] Duplicate chunk ignored for taskId: {}, file: {}, chunkIndex: {}", taskId, fileIdentity, fileDto.getChunkIndex()); - continue; - } - validateChunk(fileDto, parsedFile); validateResultFileAgainstParsed(fileDto, parsedFile); - boolean stored = deleteBrandTaskCacheService.mergeResultChunk(taskId, fileIdentity, fileDto.getChunkIndex(), fileDto); + boolean stored = deleteBrandTaskCacheService.storeResultChunkIfChanged(taskId, fileIdentity, fileDto.getChunkIndex(), fileDto); if (!stored) { + log.info("[DeleteBrand] Duplicate chunk ignored for taskId: {}, file: {}, chunkIndex: {}", taskId, fileIdentity, fileDto.getChunkIndex()); continue; } @@ -1023,20 +1049,21 @@ public class DeleteBrandRunService { progress.put("current_asin", blankToEmpty(fileDto.getCurrentAsin())); progress.put("updated_at", String.valueOf(System.currentTimeMillis())); progress.put("last_heartbeat_at", String.valueOf(System.currentTimeMillis())); - deleteBrandTaskCacheService.saveProgress(taskId, progress); + deleteBrandTaskCacheService.saveProgress(taskId, progress, true); // 如果该文件已完成,立即更新成品计数的 Redis 缓存「提示」,让后续 tryFinalizeTask 能更精确 if (isFileCompleted(fileDto)) { log.info("[DeleteBrand] File chunk transmission fully reached via chunkTotal for taskId: {}, file: {}", taskId, fileDto.getSourceFilename()); - java.util.Map currentProgress = deleteBrandTaskCacheService.getProgress(taskId); - int finishedCount = parseInt(currentProgress.get("finished_files")) == null ? 0 : parseInt(currentProgress.get("finished_files")); + shouldTryFinalize = true; // 这里我们暂不直接 increment,而是标记需要重算或在 tryFinalizeTask 中重新计算 // 为了保险,我们直接在 tryFinalizeTask 里重新遍历分片状态 } } - tryFinalizeTask(taskId, false); + if (shouldTryFinalize) { + tryFinalizeTask(taskId, false); + } } public void tryFinalizeTask(Long taskId, boolean fromCompensation) { @@ -1044,7 +1071,7 @@ public class DeleteBrandRunService { return; } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { return; } @@ -1082,6 +1109,7 @@ public class DeleteBrandRunService { task.setUpdatedAt(LocalDateTime.now()); } fileTaskMapper.updateById(task); + deleteBrandTaskCacheService.saveTaskCache(task); log.info("[DeleteBrand] tryFinalizeTask skipping -> finishedFiles ({}) < expectedFiles ({})", finishedFiles, expectedFiles); return; @@ -1093,11 +1121,12 @@ public class DeleteBrandRunService { if (fromCompensation) { progress.put("last_heartbeat_at", String.valueOf(System.currentTimeMillis())); } - deleteBrandTaskCacheService.saveProgress(taskId, progress); + deleteBrandTaskCacheService.saveProgress(taskId, progress, true); task.setSuccessFileCount(finishedFiles); task.setUpdatedAt(LocalDateTime.now()); fileTaskMapper.updateById(task); + deleteBrandTaskCacheService.saveTaskCache(task); log.info("[DeleteBrand] tryFinalizeTask calling finalizeTask -> finishedFiles: {}, expectedFiles: {}", finishedFiles, expectedFiles); diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandStaleTaskService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandStaleTaskService.java index 5b45afd..e80de33 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandStaleTaskService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandStaleTaskService.java @@ -6,6 +6,8 @@ import com.nanri.aiimage.common.service.DistributedJobLockService; import com.nanri.aiimage.config.DeleteBrandProgressProperties; import com.nanri.aiimage.modules.productrisk.service.ProductRiskTaskCacheService; import com.nanri.aiimage.modules.productrisk.service.ProductRiskTaskService; +import com.nanri.aiimage.modules.patroldelete.service.PatrolDeleteTaskCacheService; +import com.nanri.aiimage.modules.patroldelete.service.PatrolDeleteTaskService; import com.nanri.aiimage.modules.pricetrack.service.PriceTrackTaskCacheService; import com.nanri.aiimage.modules.pricetrack.service.PriceTrackTaskService; import com.nanri.aiimage.modules.shopmatch.service.ShopMatchTaskCacheService; @@ -14,6 +16,7 @@ import com.nanri.aiimage.modules.task.mapper.FileTaskMapper; import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -37,10 +40,10 @@ public class DeleteBrandStaleTaskService { private static final String MODULE_TYPE_PRODUCT_RISK = "PRODUCT_RISK_RESOLVE"; private static final String MODULE_TYPE_PRICE_TRACK = "PRICE_TRACK"; private static final String MODULE_TYPE_SHOP_MATCH = "SHOP_MATCH"; + private static final String MODULE_TYPE_PATROL_DELETE = "PATROL_DELETE"; private static final Duration STALE_CHECK_LOCK_TTL = Duration.ofMinutes(10); private static final Duration FINALIZE_CHECK_LOCK_TTL = Duration.ofMinutes(10); private static final Duration TEMP_DIR_CLEANUP_LOCK_TTL = Duration.ofMinutes(10); - private static final Duration TEMP_DIR_RETENTION = Duration.ofHours(48); private final FileTaskMapper fileTaskMapper; private final DeleteBrandTaskCacheService deleteBrandTaskCacheService; @@ -51,9 +54,14 @@ public class DeleteBrandStaleTaskService { private final PriceTrackTaskCacheService priceTrackTaskCacheService; private final ShopMatchTaskService shopMatchTaskService; private final ShopMatchTaskCacheService shopMatchTaskCacheService; + private final PatrolDeleteTaskService patrolDeleteTaskService; + private final PatrolDeleteTaskCacheService patrolDeleteTaskCacheService; private final DeleteBrandProgressProperties deleteBrandProgressProperties; private final DistributedJobLockService distributedJobLockService; + @Value("${aiimage.temp-dir.retention-hours:24}") + private long tempDirRetentionHours; + @Scheduled(cron = "${aiimage.delete-brand-progress.stale-check-cron:0 */2 * * * *}") public void failStaleRunningTasks() { DistributedJobLockService.LockHandle lockHandle = @@ -69,6 +77,7 @@ public class DeleteBrandStaleTaskService { ProductRiskStaleCheckStats stats = failStaleProductRiskResolveTasks(); PriceTrackStaleCheckStats priceTrackStats = failStalePriceTrackTasks(); ShopMatchStaleCheckStats shopMatchStats = failStaleShopMatchTasks(); + ShopMatchStaleCheckStats patrolDeleteStats = failStalePatrolDeleteTasks(); log.info("[stale-check] product-risk summary scanned={} finalized={} failed={} skipped={} elapsedMs={} thread={}", stats.scannedTaskCount, stats.finalizedTaskCount, @@ -90,6 +99,13 @@ public class DeleteBrandStaleTaskService { shopMatchStats.skippedTaskCount, System.currentTimeMillis() - startedAt, Thread.currentThread().getName()); + log.info("[stale-check] patrol-delete summary scanned={} finalized={} failed={} skipped={} elapsedMs={} thread={}", + patrolDeleteStats.scannedTaskCount, + patrolDeleteStats.finalizedTaskCount, + patrolDeleteStats.failedTaskCount, + patrolDeleteStats.skippedTaskCount, + System.currentTimeMillis() - startedAt, + Thread.currentThread().getName()); } } @@ -335,6 +351,65 @@ public class DeleteBrandStaleTaskService { return stats; } + private ShopMatchStaleCheckStats failStalePatrolDeleteTasks() { + ShopMatchStaleCheckStats stats = new ShopMatchStaleCheckStats(); + long minutes = Math.max(1L, deleteBrandProgressProperties.getPatrolDeleteStaleTimeoutMinutes()); + long initialMinutes = Math.max(minutes, deleteBrandProgressProperties.getPatrolDeleteInitialTimeoutMinutes()); + long staleTimeoutMillis = Duration.ofMinutes(minutes).toMillis(); + long nowMillis = System.currentTimeMillis(); + LocalDateTime now = LocalDateTime.now(); + LocalDateTime threshold = now.minusMinutes(minutes); + LocalDateTime initialThreshold = now.minusMinutes(initialMinutes); + java.util.List runningTasks = fileTaskMapper.selectList(new LambdaQueryWrapper() + .eq(FileTaskEntity::getModuleType, MODULE_TYPE_PATROL_DELETE) + .eq(FileTaskEntity::getStatus, "RUNNING") + .lt(FileTaskEntity::getUpdatedAt, threshold) + .last("limit 200")); + stats.scannedTaskCount = runningTasks.size(); + if (runningTasks.isEmpty()) { + return stats; + } + for (FileTaskEntity task : runningTasks) { + long lastHeartbeatMillis = patrolDeleteTaskCacheService.getTaskHeartbeatMillis(task.getId()); + boolean hasUploadedPayload = patrolDeleteTaskCacheService.hasAnyShopMergedPayload(task.getId()); + boolean hasFinishedRows = (task.getSuccessFileCount() != null && task.getSuccessFileCount() > 0) + || (task.getFailedFileCount() != null && task.getFailedFileCount() > 0); + boolean hasStartedProgress = lastHeartbeatMillis > 0L || hasUploadedPayload || hasFinishedRows; + if (lastHeartbeatMillis > 0L && nowMillis - lastHeartbeatMillis < staleTimeoutMillis) { + stats.skippedTaskCount++; + continue; + } + if (!hasStartedProgress && task.getCreatedAt() != null && task.getCreatedAt().isAfter(initialThreshold)) { + stats.skippedTaskCount++; + continue; + } + try { + if (patrolDeleteTaskService.tryFinalizeTask(task.getId(), true)) { + stats.finalizedTaskCount++; + log.info("[stale-check] patrol-delete finalized taskId={}", task.getId()); + continue; + } + } catch (Exception ex) { + log.warn("[stale-check] patrol-delete finalize threw taskId={} msg={}", task.getId(), ex.getMessage()); + } + int updated = fileTaskMapper.update(null, new LambdaUpdateWrapper() + .eq(FileTaskEntity::getId, task.getId()) + .eq(FileTaskEntity::getModuleType, MODULE_TYPE_PATROL_DELETE) + .eq(FileTaskEntity::getStatus, "RUNNING") + .set(FileTaskEntity::getStatus, "FAILED") + .set(FileTaskEntity::getErrorMessage, "长时间未收到 Python 结果回传,任务已自动失败") + .set(FileTaskEntity::getUpdatedAt, LocalDateTime.now()) + .set(FileTaskEntity::getFinishedAt, LocalDateTime.now())); + if (updated > 0) { + stats.failedTaskCount++; + patrolDeleteTaskCacheService.deleteTaskCache(task.getId()); + } else { + stats.skippedTaskCount++; + } + } + return stats; + } + @Scheduled(cron = "${aiimage.delete-brand-progress.finalize-check-cron:30 */2 * * * *}") public void finalizeCompletedRunningTasks() { DistributedJobLockService.LockHandle lockHandle = @@ -369,12 +444,14 @@ public class DeleteBrandStaleTaskService { return; } try (lockHandle) { - Instant cutoff = Instant.now().minus(TEMP_DIR_RETENTION); + Instant cutoff = Instant.now().minus(Duration.ofHours(Math.max(1L, tempDirRetentionHours))); List dirNames = List.of( "shop-match-cache", + "patrol-delete-cache", "brand-task-cache", "delete-brand-task-cache", "shop-match-result", + "patrol-delete-result", "delete-brand-result", "product-risk-result", "price-track-result" diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandTaskCacheService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandTaskCacheService.java index 75e38ae..e13a50d 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandTaskCacheService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/deletebrand/service/DeleteBrandTaskCacheService.java @@ -3,6 +3,7 @@ package com.nanri.aiimage.modules.deletebrand.service; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.config.TaskPressureProperties; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; @@ -24,10 +25,16 @@ public class DeleteBrandTaskCacheService { private static final long PAYLOAD_TTL_HOURS = 24; private static final long LOCAL_PARSED_PAYLOAD_CACHE_MILLIS = 3000; + private static final long LOCAL_PROGRESS_CACHE_MILLIS = 1500; + private static final long MIN_PROGRESS_REDIS_FLUSH_MILLIS = 1200; private final StringRedisTemplate stringRedisTemplate; private final ObjectMapper objectMapper; + private final TaskPressureProperties taskPressureProperties; private final ConcurrentHashMap parsedPayloadLocalCache = new ConcurrentHashMap<>(); + private final ConcurrentHashMap progressLocalCache = new ConcurrentHashMap<>(); + private final ConcurrentHashMap progressRedisFlushAt = new ConcurrentHashMap<>(); + private final ConcurrentHashMap taskEntityLocalCache = new ConcurrentHashMap<>(); public void saveParsedPayload(Long taskId, Object payload) { try { @@ -75,13 +82,44 @@ public class DeleteBrandTaskCacheService { } public void saveProgress(Long taskId, java.util.Map values) { + saveProgress(taskId, values, false); + } + + public void saveProgress(Long taskId, java.util.Map values, boolean forceWrite) { + if (taskId == null || taskId <= 0 || values == null || values.isEmpty()) { + return; + } + long now = System.currentTimeMillis(); + java.util.Map merged = new java.util.LinkedHashMap<>(); + LocalProgressCacheEntry cached = progressLocalCache.get(taskId); + if (cached != null && cached.isFresh(now)) { + merged.putAll(cached.values()); + } + merged.putAll(values); + progressLocalCache.put(taskId, new LocalProgressCacheEntry(now, merged)); + + Long lastFlushAt = progressRedisFlushAt.get(taskId); + if (!forceWrite && lastFlushAt != null && now - lastFlushAt < MIN_PROGRESS_REDIS_FLUSH_MILLIS) { + return; + } + String key = buildProgressKey(taskId); - stringRedisTemplate.opsForHash().putAll(key, values); + stringRedisTemplate.opsForHash().putAll(key, merged); stringRedisTemplate.expire(key, Duration.ofHours(PAYLOAD_TTL_HOURS)); + progressRedisFlushAt.put(taskId, now); } public java.util.Map getProgress(Long taskId) { - return stringRedisTemplate.opsForHash().entries(buildProgressKey(taskId)); + long now = System.currentTimeMillis(); + LocalProgressCacheEntry cached = progressLocalCache.get(taskId); + if (cached != null && cached.isFresh(now)) { + return new java.util.LinkedHashMap<>(cached.values()); + } + java.util.Map values = stringRedisTemplate.opsForHash().entries(buildProgressKey(taskId)); + if (!values.isEmpty()) { + progressLocalCache.put(taskId, new LocalProgressCacheEntry(now, toStringMap(values))); + } + return values; } public java.util.Map> getProgressBatch(java.util.List taskIds) { @@ -98,16 +136,30 @@ public class DeleteBrandTaskCacheService { return result; } + long now = System.currentTimeMillis(); + java.util.List missingTaskIds = new java.util.ArrayList<>(); + for (Long taskId : normalizedTaskIds) { + LocalProgressCacheEntry cached = progressLocalCache.get(taskId); + if (cached != null && cached.isFresh(now)) { + result.put(taskId, new java.util.LinkedHashMap<>(cached.values())); + } else { + missingTaskIds.add(taskId); + } + } + if (missingTaskIds.isEmpty()) { + return result; + } + java.util.List pipelineResults = stringRedisTemplate.executePipelined((org.springframework.data.redis.core.RedisCallback) connection -> { org.springframework.data.redis.serializer.RedisSerializer serializer = stringRedisTemplate.getStringSerializer(); - for (Long taskId : normalizedTaskIds) { + for (Long taskId : missingTaskIds) { connection.hGetAll(serializer.serialize(buildProgressKey(taskId))); } return null; }); - for (int i = 0; i < normalizedTaskIds.size(); i++) { - Long taskId = normalizedTaskIds.get(i); + for (int i = 0; i < missingTaskIds.size(); i++) { + Long taskId = missingTaskIds.get(i); Object raw = pipelineResults != null && i < pipelineResults.size() ? pipelineResults.get(i) : null; if (raw instanceof java.util.Map rawMap) { java.util.Map converted = new java.util.LinkedHashMap<>(); @@ -115,6 +167,7 @@ public class DeleteBrandTaskCacheService { converted.put(entry.getKey(), entry.getValue()); } result.put(taskId, converted); + progressLocalCache.put(taskId, new LocalProgressCacheEntry(now, toStringMap(converted))); } else { result.put(taskId, java.util.Collections.emptyMap()); } @@ -169,6 +222,10 @@ public class DeleteBrandTaskCacheService { return true; } + public boolean storeResultChunkIfChanged(Long taskId, String fileIdentity, Integer chunkIndex, Object chunk) { + return mergeResultChunk(taskId, fileIdentity, chunkIndex, chunk); + } + public java.util.Map> groupResultChunkJsonByFile(Long taskId) { java.util.Map stored = stringRedisTemplate.opsForHash().entries(buildResultChunksKey(taskId)); java.util.Map> grouped = new java.util.LinkedHashMap<>(); @@ -188,6 +245,9 @@ public class DeleteBrandTaskCacheService { public void delete(Long taskId) { parsedPayloadLocalCache.remove(taskId); + progressLocalCache.remove(taskId); + progressRedisFlushAt.remove(taskId); + taskEntityLocalCache.remove(taskId); stringRedisTemplate.delete(buildProgressKey(taskId)); stringRedisTemplate.delete(buildResultChunksKey(taskId)); stringRedisTemplate.delete(buildTaskEntityKey(taskId)); @@ -198,6 +258,11 @@ public class DeleteBrandTaskCacheService { if (task == null || task.getId() == null) { return; } + long now = System.currentTimeMillis(); + taskEntityLocalCache.put(task.getId(), new LocalTaskEntityCacheEntry( + now, + objectMapper.convertValue(task, com.nanri.aiimage.modules.task.model.entity.FileTaskEntity.class) + )); try { stringRedisTemplate.opsForValue().set(buildTaskEntityKey(task.getId()), objectMapper.writeValueAsString(task), Duration.ofHours(PAYLOAD_TTL_HOURS)); } catch (Exception ignored) { @@ -215,15 +280,32 @@ public class DeleteBrandTaskCacheService { return result; } - java.util.List keys = normalized.stream().map(this::buildTaskEntityKey).toList(); + long now = System.currentTimeMillis(); + java.util.List missingIds = new java.util.ArrayList<>(); + for (Long taskId : normalized) { + LocalTaskEntityCacheEntry cached = taskEntityLocalCache.get(taskId); + if (isLocalTaskEntityCacheFresh(cached, now)) { + result.put(taskId, objectMapper.convertValue(cached.task(), com.nanri.aiimage.modules.task.model.entity.FileTaskEntity.class)); + } else { + missingIds.add(taskId); + } + } + if (missingIds.isEmpty()) { + return result; + } + + java.util.List keys = missingIds.stream().map(this::buildTaskEntityKey).toList(); java.util.List values = stringRedisTemplate.opsForValue().multiGet(keys); - for (int i = 0; i < normalized.size(); i++) { - Long taskId = normalized.get(i); + for (int i = 0; i < missingIds.size(); i++) { + Long taskId = missingIds.get(i); String val = values != null && i < values.size() ? values.get(i) : null; if (val != null && !val.isBlank()) { try { - result.put(taskId, objectMapper.readValue(val, com.nanri.aiimage.modules.task.model.entity.FileTaskEntity.class)); + com.nanri.aiimage.modules.task.model.entity.FileTaskEntity task = + objectMapper.readValue(val, com.nanri.aiimage.modules.task.model.entity.FileTaskEntity.class); + result.put(taskId, task); + taskEntityLocalCache.put(taskId, new LocalTaskEntityCacheEntry(now, task)); } catch (Exception ignored) { } } @@ -265,6 +347,33 @@ public class DeleteBrandTaskCacheService { } } + private record LocalProgressCacheEntry(long cachedAtMillis, java.util.Map values) { + private boolean isFresh(long now) { + return now - cachedAtMillis <= LOCAL_PROGRESS_CACHE_MILLIS; + } + } + + private record LocalTaskEntityCacheEntry( + long cachedAtMillis, + com.nanri.aiimage.modules.task.model.entity.FileTaskEntity task + ) {} + + private boolean isLocalTaskEntityCacheFresh(LocalTaskEntityCacheEntry cached, long now) { + return cached != null + && now - cached.cachedAtMillis() <= Math.max(0L, taskPressureProperties.getLocalTaskEntityCacheMillis()); + } + + private java.util.Map toStringMap(java.util.Map values) { + java.util.Map converted = new java.util.LinkedHashMap<>(); + for (java.util.Map.Entry entry : values.entrySet()) { + if (entry.getKey() == null || entry.getValue() == null) { + continue; + } + converted.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); + } + return converted; + } + private String buildProgressKey(Long taskId) { return "delete-brand:task:progress:" + taskId; } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/controller/PatrolDeleteController.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/controller/PatrolDeleteController.java new file mode 100644 index 0000000..13365e8 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/controller/PatrolDeleteController.java @@ -0,0 +1,371 @@ +package com.nanri.aiimage.modules.patroldelete.controller; + +import com.nanri.aiimage.common.api.ApiResponse; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteCreateTaskRequest; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteSubmitResultRequest; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteTaskBatchRequest; +import com.nanri.aiimage.modules.patroldelete.model.vo.PatrolDeleteCreateTaskVo; +import com.nanri.aiimage.modules.patroldelete.model.vo.PatrolDeleteHistoryVo; +import com.nanri.aiimage.modules.patroldelete.model.vo.PatrolDeleteTaskBatchVo; +import com.nanri.aiimage.modules.patroldelete.service.PatrolDeleteResolveService; +import com.nanri.aiimage.modules.patroldelete.service.PatrolDeleteTaskService; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCandidateAddRequest; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskMatchShopsRequest; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskCandidateVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskDashboardVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskMatchShopsVo; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ResponseStatusException; + +import java.io.InputStream; +import java.net.URI; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.List; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/patrol-delete") +@Tag( + name = "巡店删除", + description = "巡店删除模块:管理备选店铺、批量匹配紫鸟店铺、创建任务、接收 Python 分片结果、自动收尾生成 Excel 并提供下载。涉及查询和删除的接口需要携带 user_id。") +public class PatrolDeleteController { + + private final PatrolDeleteResolveService patrolDeleteResolveService; + private final PatrolDeleteTaskService patrolDeleteTaskService; + + @GetMapping("/candidates") + @Operation(summary = "查询备选店铺列表", description = "返回当前用户在巡店删除模块中已保存的备选店铺。") + public ApiResponse> listCandidates( + @Parameter(name = "user_id", description = "当前用户 ID", required = true, in = ParameterIn.QUERY, example = "1") + @RequestParam("user_id") Long userId) { + return ApiResponse.success(patrolDeleteResolveService.listCandidates(userId)); + } + + @PostMapping("/candidates") + @Operation(summary = "新增备选店铺", description = "向巡店删除备选区新增一条店铺记录,供后续匹配和创建任务使用。") + public ApiResponse addCandidate( + @io.swagger.v3.oas.annotations.parameters.RequestBody( + description = "新增备选店铺请求,需传入用户 ID 和店铺名。", + required = true, + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ProductRiskCandidateAddRequest.class), + examples = @ExampleObject( + name = "新增店铺示例", + value = """ + { + "user_id": 1, + "shop_name": "郭亚芳" + } + """))) + @Valid @RequestBody ProductRiskCandidateAddRequest request) { + return ApiResponse.success(patrolDeleteResolveService.addCandidate(request)); + } + + @DeleteMapping("/candidates/{id}") + @Operation(summary = "删除备选店铺", description = "删除当前用户名下的一条备选店铺记录。") + public ApiResponse deleteCandidate( + @Parameter(description = "备选店铺记录主键", example = "10") + @PathVariable Long id, + @Parameter(name = "user_id", description = "当前用户 ID", required = true, in = ParameterIn.QUERY, example = "1") + @RequestParam("user_id") Long userId) { + patrolDeleteResolveService.deleteCandidate(userId, id); + return ApiResponse.success(null); + } + + @PostMapping("/match-shops") + @Operation(summary = "批量匹配店铺", description = "根据店铺名批量匹配紫鸟店铺索引,返回是否命中、店铺 ID、平台、公司和匹配状态。") + public ApiResponse matchShops( + @io.swagger.v3.oas.annotations.parameters.RequestBody( + description = "批量匹配请求,传入 user_id 和待匹配的店铺名称列表。", + required = true, + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ProductRiskMatchShopsRequest.class), + examples = @ExampleObject( + name = "匹配店铺示例", + value = """ + { + "user_id": 1, + "shop_names": [ + "郭亚芳", + "示例店铺A" + ] + } + """))) + @Valid @RequestBody ProductRiskMatchShopsRequest request) { + return ApiResponse.success(patrolDeleteResolveService.matchShops(request)); + } + + @GetMapping("/dashboard") + @Operation(summary = "查询统计看板", description = "返回备选店铺数、已处理任务数、成功任务数和失败任务数。") + public ApiResponse dashboard( + @Parameter(name = "user_id", description = "当前用户 ID", required = true, in = ParameterIn.QUERY, example = "1") + @RequestParam("user_id") Long userId) { + return ApiResponse.success(patrolDeleteTaskService.dashboard(userId)); + } + + @GetMapping("/history") + @Operation(summary = "查询任务记录", description = "返回当前用户在巡店删除模块中的当前任务和历史任务记录。") + public ApiResponse history( + @Parameter(name = "user_id", description = "当前用户 ID", required = true, in = ParameterIn.QUERY, example = "1") + @RequestParam("user_id") Long userId) { + return ApiResponse.success(patrolDeleteTaskService.listHistory(userId)); + } + + @PostMapping("/tasks/progress/batch") + @Operation(summary = "批量查询巡店删除任务进度", description = "仅返回任务状态和店铺结果摘要,用于前端轮询降载。") + public ApiResponse taskProgressBatch(@Valid @RequestBody PatrolDeleteTaskBatchRequest request) { + return ApiResponse.success(patrolDeleteTaskService.getTaskProgressBatch(request.getTaskIds())); + } + + @PostMapping("/tasks") + @Operation(summary = "创建巡店删除任务", description = "根据已匹配的店铺创建任务和占位结果记录,后续由 Python 端处理并回传结果。") + public ApiResponse createTask( + @io.swagger.v3.oas.annotations.parameters.RequestBody( + description = "创建任务请求。items 中每一项代表一个待处理店铺,需携带默认模板结构。", + required = true, + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = PatrolDeleteCreateTaskRequest.class), + examples = @ExampleObject( + name = "创建任务示例", + value = """ + { + "user_id": 1, + "items": [ + { + "shopName": "郭亚芳", + "matched": true, + "shopId": "27730548558377", + "platform": "亚马逊", + "companyName": "示例公司", + "matchStatus": "MATCHED", + "matchMessage": "索引已命中", + "countrySections": [ + { + "country": "德国", + "rows": [ + { + "status": "全部", + "quantity": "", + "deleteQuantity": "", + "processStatus": "" + } + ] + } + ], + "cartRatios": [ + { + "country": "德国", + "ratio": "" + } + ] + } + ] + } + """))) + @Valid @RequestBody PatrolDeleteCreateTaskRequest request) { + return ApiResponse.success(patrolDeleteTaskService.createTask(request)); + } + + @PostMapping("/tasks/{taskId}/result") + @Operation( + summary = "提交巡店删除结果", + description = "供 Python 端回传处理结果。支持按店铺分片多次提交,服务端会合并分片、按店铺完成状态自动收尾,并在任务结束后生成 Excel。") + public ApiResponse submitResult( + @Parameter(description = "任务主键,必须是运行中的任务", example = "3089") + @PathVariable Long taskId, + @io.swagger.v3.oas.annotations.parameters.RequestBody( + description = "巡店删除结果回传请求。shops 表示本次提交的店铺结果分片列表。shopDone=true 表示该店铺已全部提交完成。", + required = true, + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = PatrolDeleteSubmitResultRequest.class), + examples = { + @ExampleObject( + name = "成功分片示例", + summary = "一个店铺分片回传,包含状态数据和购物车比例数据", + value = """ + { + "shops": [ + { + "shopName": "郭亚芳", + "submissionId": "patrol-delete:3089:郭亚芳:1711111111111", + "chunkIndex": 1, + "chunkTotal": 2, + "shopDone": false, + "countrySections": [ + { + "country": "德国", + "rows": [ + { + "status": "正常", + "quantity": "12", + "deleteQuantity": "3", + "processStatus": "处理中" + }, + { + "status": "下架", + "quantity": "2", + "deleteQuantity": "2", + "processStatus": "已完成" + } + ] + }, + { + "country": "英国", + "rows": [ + { + "status": "正常", + "quantity": "5", + "deleteQuantity": "1", + "processStatus": "处理中" + } + ] + } + ], + "cartRatios": [ + { + "country": "德国", + "ratio": "25%" + }, + { + "country": "英国", + "ratio": "18%" + } + ] + } + ] + } + """), + @ExampleObject( + name = "店铺完成示例", + summary = "最后一片提交完成后,将 shopDone 置为 true", + value = """ + { + "shops": [ + { + "shopName": "郭亚芳", + "submissionId": "patrol-delete:3089:郭亚芳:1711111111111", + "chunkIndex": 2, + "chunkTotal": 2, + "shopDone": true, + "countrySections": [ + { + "country": "法国", + "rows": [ + { + "status": "正常", + "quantity": "4", + "deleteQuantity": "0", + "processStatus": "已完成" + } + ] + } + ], + "cartRatios": [ + { + "country": "法国", + "ratio": "12%" + } + ] + } + ] + } + """), + @ExampleObject( + name = "失败示例", + summary = "店铺处理失败时直接回传错误信息", + value = """ + { + "shops": [ + { + "shopName": "郭亚芳", + "shopDone": true, + "error": "紫鸟页面加载超时,未能完成删除数据采集" + } + ] + } + """) + })) + @Valid @RequestBody PatrolDeleteSubmitResultRequest request, + jakarta.servlet.http.HttpServletResponse response) { + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); + response.setContentType("application/json;charset=UTF-8"); + patrolDeleteTaskService.submitResult(taskId, request); + return ApiResponse.success(null); + } + + @GetMapping("/results/{resultId}/download") + @Operation(summary = "下载结果文件", description = "按结果记录下载服务端已生成并上传到 OSS 的巡店删除 Excel 文件。") + public void downloadResult( + @Parameter(description = "结果记录主键", example = "4599") + @PathVariable Long resultId, + @Parameter(name = "user_id", description = "当前用户 ID", required = true, in = ParameterIn.QUERY, example = "1") + @RequestParam("user_id") Long userId, + jakarta.servlet.http.HttpServletResponse response) { + String url = patrolDeleteTaskService.resolveResultDownloadUrl(resultId, userId); + String filename = patrolDeleteTaskService.resolveResultDownloadFilename(resultId, userId); + if (url == null || url.isBlank()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "暂无可下载结果"); + } + try { + String encodedFilename = URLEncoder.encode(filename, StandardCharsets.UTF_8).replace("+", "%20"); + response.setContentType("application/octet-stream"); + response.setHeader(HttpHeaders.CONTENT_DISPOSITION, + "attachment; filename=\"" + filename + "\"; filename*=UTF-8''" + encodedFilename); + try (InputStream in = URI.create(url).toURL().openStream()) { + byte[] buffer = new byte[65536]; + int read; + while ((read = in.read(buffer)) != -1) { + response.getOutputStream().write(buffer, 0, read); + } + response.getOutputStream().flush(); + } + } catch (Exception ex) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "下载失败"); + } + } + + @DeleteMapping("/tasks/{taskId}") + @Operation(summary = "删除任务", description = "删除整条巡店删除任务以及该任务下关联的所有结果记录。") + public ApiResponse deleteTask( + @Parameter(description = "任务主键", example = "3089") + @PathVariable Long taskId, + @Parameter(name = "user_id", description = "当前用户 ID", required = true, in = ParameterIn.QUERY, example = "1") + @RequestParam("user_id") Long userId) { + patrolDeleteTaskService.deleteTask(taskId, userId); + return ApiResponse.success(null); + } + + @DeleteMapping("/history/{resultId}") + @Operation(summary = "删除单条历史记录", description = "删除一条巡店删除结果记录,并同步重算其所属任务状态。") + public ApiResponse deleteHistory( + @Parameter(description = "结果记录主键", example = "4599") + @PathVariable Long resultId, + @Parameter(name = "user_id", description = "当前用户 ID", required = true, in = ParameterIn.QUERY, example = "1") + @RequestParam("user_id") Long userId) { + patrolDeleteTaskService.deleteHistory(resultId, userId); + return ApiResponse.success(null); + } +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/mapper/PatrolDeleteShopCandidateMapper.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/mapper/PatrolDeleteShopCandidateMapper.java new file mode 100644 index 0000000..e919a0c --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/mapper/PatrolDeleteShopCandidateMapper.java @@ -0,0 +1,9 @@ +package com.nanri.aiimage.modules.patroldelete.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.nanri.aiimage.modules.patroldelete.model.entity.PatrolDeleteShopCandidateEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface PatrolDeleteShopCandidateMapper extends BaseMapper { +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCartRatioDto.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCartRatioDto.java new file mode 100644 index 0000000..fdc6ab9 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCartRatioDto.java @@ -0,0 +1,15 @@ +package com.nanri.aiimage.modules.patroldelete.model.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "购物车比例数据") +public class PatrolDeleteCartRatioDto { + + @Schema(description = "国家名称", example = "德国") + private String country; + + @Schema(description = "购物车比例", example = "25%") + private String ratio; +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCountryMetricRowDto.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCountryMetricRowDto.java new file mode 100644 index 0000000..07a65d9 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCountryMetricRowDto.java @@ -0,0 +1,24 @@ +package com.nanri.aiimage.modules.patroldelete.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "国家状态数据中的单行记录") +public class PatrolDeleteCountryMetricRowDto { + + @Schema(description = "商品状态", example = "正常") + private String status; + + @Schema(description = "该状态下的商品数量", example = "12") + private String quantity; + + @JsonProperty("deleteQuantity") + @Schema(description = "已删除数量", example = "3") + private String deleteQuantity; + + @JsonProperty("processStatus") + @Schema(description = "处理结果或处理状态", example = "处理中") + private String processStatus; +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCountrySectionDto.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCountrySectionDto.java new file mode 100644 index 0000000..c9ccc16 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCountrySectionDto.java @@ -0,0 +1,18 @@ +package com.nanri.aiimage.modules.patroldelete.model.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +@Schema(description = "单个国家的状态数据分组") +public class PatrolDeleteCountrySectionDto { + + @Schema(description = "国家名称", example = "德国") + private String country; + + @Schema(description = "该国家下的多行状态数据") + private List rows = new ArrayList<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCreateTaskRequest.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCreateTaskRequest.java new file mode 100644 index 0000000..94a67dd --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteCreateTaskRequest.java @@ -0,0 +1,26 @@ +package com.nanri.aiimage.modules.patroldelete.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +@Schema(description = "创建巡店删除任务请求") +public class PatrolDeleteCreateTaskRequest { + + @NotNull + @JsonProperty("user_id") + @Schema(description = "当前用户 ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED) + private Long userId; + + @Valid + @NotEmpty + @Schema(description = "待创建的店铺任务列表,通常由已匹配成功的店铺组成", requiredMode = Schema.RequiredMode.REQUIRED) + private List items = new ArrayList<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteShopPayloadDto.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteShopPayloadDto.java new file mode 100644 index 0000000..da55853 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteShopPayloadDto.java @@ -0,0 +1,44 @@ +package com.nanri.aiimage.modules.patroldelete.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +@Schema(description = "单个店铺的巡店删除结果分片") +public class PatrolDeleteShopPayloadDto { + + @JsonProperty("shopName") + @Schema(description = "店铺名称,服务端按店铺名称聚合分片", example = "郭亚芳") + private String shopName; + + @Schema(description = "店铺处理失败时的错误信息;有值时该店铺会直接标记失败", example = "紫鸟页面加载超时,未能完成删除数据采集") + private String error; + + @JsonProperty("countrySections") + @Schema(description = "各国家的状态数据列表。同一国家可分多片提交,服务端会按顺序合并") + private List countrySections = new ArrayList<>(); + + @JsonProperty("cartRatios") + @Schema(description = "购物车比例数据列表,通常只在店铺首行展示") + private List cartRatios = new ArrayList<>(); + + @JsonProperty("shopDone") + @Schema(description = "该店铺是否已全部提交完成。最后一片应传 true", example = "true") + private Boolean shopDone; + + @JsonProperty("submissionId") + @Schema(description = "本次店铺提交批次标识,便于问题排查与日志跟踪", example = "patrol-delete:3089:郭亚芳:1711111111111") + private String submissionId; + + @JsonProperty("chunkIndex") + @Schema(description = "当前分片序号,建议从 1 开始", example = "1") + private Integer chunkIndex; + + @JsonProperty("chunkTotal") + @Schema(description = "当前店铺总分片数", example = "2") + private Integer chunkTotal; +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteSubmitResultRequest.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteSubmitResultRequest.java new file mode 100644 index 0000000..06d184e --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteSubmitResultRequest.java @@ -0,0 +1,19 @@ +package com.nanri.aiimage.modules.patroldelete.model.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotEmpty; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +@Schema(description = "巡店删除结果回传请求") +public class PatrolDeleteSubmitResultRequest { + + @Valid + @NotEmpty + @Schema(description = "本次提交的店铺结果分片列表,支持一次提交多个店铺", requiredMode = Schema.RequiredMode.REQUIRED) + private List shops = new ArrayList<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteTaskBatchRequest.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteTaskBatchRequest.java new file mode 100644 index 0000000..dd775b8 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteTaskBatchRequest.java @@ -0,0 +1,14 @@ +package com.nanri.aiimage.modules.patroldelete.model.dto; + +import jakarta.validation.constraints.NotEmpty; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class PatrolDeleteTaskBatchRequest { + + @NotEmpty(message = "taskIds 不能为空") + private List taskIds = new ArrayList<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteTaskItemDto.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteTaskItemDto.java new file mode 100644 index 0000000..01c3606 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/dto/PatrolDeleteTaskItemDto.java @@ -0,0 +1,50 @@ +package com.nanri.aiimage.modules.patroldelete.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +@Schema(description = "巡店删除任务中的单个店铺项") +public class PatrolDeleteTaskItemDto { + + @JsonProperty("shopName") + @Schema(description = "店铺名称", example = "郭亚芳") + private String shopName; + + @Schema(description = "该店铺是否已完成紫鸟匹配,创建任务时必须为 true", example = "true") + private boolean matched; + + @JsonProperty("shopId") + @Schema(description = "匹配到的紫鸟店铺 ID", example = "27730548558377") + private String shopId; + + @Schema(description = "店铺所属平台", example = "亚马逊") + private String platform; + + @JsonProperty("companyName") + @Schema(description = "店铺所属公司名称", example = "示例公司") + private String companyName; + + @JsonProperty("matchStatus") + @Schema(description = "匹配状态,如 MATCHED、PENDING、CONFLICT、INDEX_STALE", example = "MATCHED") + private String matchStatus; + + @JsonProperty("matchMessage") + @Schema(description = "匹配状态说明", example = "索引已命中") + private String matchMessage; + + @Valid + @JsonProperty("countrySections") + @Schema(description = "默认模板中的国家状态数据结构") + private List countrySections = new ArrayList<>(); + + @Valid + @JsonProperty("cartRatios") + @Schema(description = "默认模板中的购物车比例结构") + private List cartRatios = new ArrayList<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/entity/PatrolDeleteShopCandidateEntity.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/entity/PatrolDeleteShopCandidateEntity.java new file mode 100644 index 0000000..e4595f1 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/entity/PatrolDeleteShopCandidateEntity.java @@ -0,0 +1,19 @@ +package com.nanri.aiimage.modules.patroldelete.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@TableName("biz_patrol_delete_shop_candidate") +public class PatrolDeleteShopCandidateEntity { + + @TableId(type = IdType.AUTO) + private Long id; + private Long userId; + private String shopName; + private LocalDateTime createdAt; +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteCreateTaskVo.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteCreateTaskVo.java new file mode 100644 index 0000000..957dff9 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteCreateTaskVo.java @@ -0,0 +1,13 @@ +package com.nanri.aiimage.modules.patroldelete.model.vo; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class PatrolDeleteCreateTaskVo { + + private Long taskId; + private List items = new ArrayList<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteHistoryVo.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteHistoryVo.java new file mode 100644 index 0000000..3c7b6d6 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteHistoryVo.java @@ -0,0 +1,12 @@ +package com.nanri.aiimage.modules.patroldelete.model.vo; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class PatrolDeleteHistoryVo { + + private List items = new ArrayList<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteResultItemVo.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteResultItemVo.java new file mode 100644 index 0000000..9b827e2 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteResultItemVo.java @@ -0,0 +1,52 @@ +package com.nanri.aiimage.modules.patroldelete.model.vo; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteCartRatioDto; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteCountrySectionDto; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Data +public class PatrolDeleteResultItemVo { + + private Long resultId; + private Long taskId; + + @JsonProperty("shopName") + private String shopName; + + @JsonProperty("shopId") + private String shopId; + + private String platform; + + @JsonProperty("companyName") + private String companyName; + + private boolean matched; + + @JsonProperty("matchStatus") + private String matchStatus; + + @JsonProperty("matchMessage") + private String matchMessage; + + @JsonProperty("taskStatus") + private String taskStatus; + + private Boolean success; + private String error; + private LocalDateTime createdAt; + private LocalDateTime finishedAt; + private String outputFilename; + private String downloadUrl; + + @JsonProperty("countrySections") + private List countrySections = new ArrayList<>(); + + @JsonProperty("cartRatios") + private List cartRatios = new ArrayList<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteTaskBatchVo.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteTaskBatchVo.java new file mode 100644 index 0000000..6fd1802 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/model/vo/PatrolDeleteTaskBatchVo.java @@ -0,0 +1,14 @@ +package com.nanri.aiimage.modules.patroldelete.model.vo; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class PatrolDeleteTaskBatchVo { + + private List items = new ArrayList<>(); + + private List missingTaskIds = new ArrayList<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteExcelAssemblyService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteExcelAssemblyService.java new file mode 100644 index 0000000..90313e6 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteExcelAssemblyService.java @@ -0,0 +1,144 @@ +package com.nanri.aiimage.modules.patroldelete.service; + +import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteCartRatioDto; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteCountryMetricRowDto; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteCountrySectionDto; +import com.nanri.aiimage.modules.patroldelete.model.vo.PatrolDeleteResultItemVo; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.FileOutputStream; +import java.util.List; + +@Service +@Slf4j +public class PatrolDeleteExcelAssemblyService { + + private static final String COUNTRY_DE = "德国"; + private static final String COUNTRY_UK = "英国"; + private static final String COUNTRY_FR = "法国"; + private static final String COUNTRY_IT = "意大利"; + private static final String COUNTRY_ES = "西班牙"; + + private static final String[] HEADER = { + "店铺名", + COUNTRY_DE, "数量", "删除数量", "删除结果", + COUNTRY_UK, "数量", "删除数量", "删除结果", + COUNTRY_FR, "数量", "删除数量", "删除结果", + COUNTRY_IT, "数量", "删除数量", "删除结果", + COUNTRY_ES, "数量", "删除数量", "删除结果", + "国家", "购物车比例", + "国家", "购物车比例", + "国家", "购物车比例", + "国家", "购物车比例", + "国家", "购物车比例" + }; + + public void writeWorkbook(File outputXlsx, List items) { + try (XSSFWorkbook workbook = new XSSFWorkbook(); + FileOutputStream outputStream = new FileOutputStream(outputXlsx)) { + Sheet sheet = workbook.createSheet("巡店删除结果"); + Row headerRow = sheet.createRow(0); + for (int columnIndex = 0; columnIndex < HEADER.length; columnIndex++) { + headerRow.createCell(columnIndex).setCellValue(HEADER[columnIndex]); + } + + int rowIndex = 1; + for (PatrolDeleteResultItemVo item : items) { + if (item == null || Boolean.FALSE.equals(item.getSuccess())) { + continue; + } + int shopRowCount = maxCountryRowCount(item.getCountrySections()); + for (int shopRowIndex = 0; shopRowIndex < shopRowCount; shopRowIndex++) { + Row row = sheet.createRow(rowIndex++); + row.createCell(0).setCellValue(shopRowIndex == 0 ? safe(item.getShopName()) : ""); + writeCountryColumns(row, 1, findSection(item.getCountrySections(), COUNTRY_DE), shopRowIndex); + writeCountryColumns(row, 5, findSection(item.getCountrySections(), COUNTRY_UK), shopRowIndex); + writeCountryColumns(row, 9, findSection(item.getCountrySections(), COUNTRY_FR), shopRowIndex); + writeCountryColumns(row, 13, findSection(item.getCountrySections(), COUNTRY_IT), shopRowIndex); + writeCountryColumns(row, 17, findSection(item.getCountrySections(), COUNTRY_ES), shopRowIndex); + if (shopRowIndex == 0) { + writeCartRatioColumns(row, 21, item.getCartRatios(), 0); + writeCartRatioColumns(row, 23, item.getCartRatios(), 1); + writeCartRatioColumns(row, 25, item.getCartRatios(), 2); + writeCartRatioColumns(row, 27, item.getCartRatios(), 3); + writeCartRatioColumns(row, 29, item.getCartRatios(), 4); + } + } + rowIndex++; + } + + for (int columnIndex = 0; columnIndex < HEADER.length; columnIndex++) { + sheet.autoSizeColumn(columnIndex); + } + workbook.write(outputStream); + } catch (Exception ex) { + log.warn("[patrol-delete] write workbook failed: {}", ex.getMessage()); + throw new BusinessException("生成巡店删除结果 Excel 失败: " + ex.getMessage()); + } + } + + public int countRows(List items) { + int count = 0; + if (items == null) { + return 0; + } + for (PatrolDeleteResultItemVo item : items) { + if (item != null && !Boolean.FALSE.equals(item.getSuccess())) { + count += maxCountryRowCount(item.getCountrySections()); + } + } + return count; + } + + private int maxCountryRowCount(List sections) { + int max = 1; + if (sections == null) { + return max; + } + for (PatrolDeleteCountrySectionDto section : sections) { + if (section != null && section.getRows() != null && section.getRows().size() > max) { + max = section.getRows().size(); + } + } + return max; + } + + private PatrolDeleteCountrySectionDto findSection(List sections, String country) { + if (sections == null) { + return null; + } + for (PatrolDeleteCountrySectionDto section : sections) { + if (section != null && country.equals(section.getCountry())) { + return section; + } + } + return null; + } + + private void writeCountryColumns(Row row, int startColumn, PatrolDeleteCountrySectionDto section, int rowIndex) { + PatrolDeleteCountryMetricRowDto metric = null; + if (section != null && section.getRows() != null && rowIndex < section.getRows().size()) { + metric = section.getRows().get(rowIndex); + } + row.createCell(startColumn).setCellValue(metric == null ? "" : safe(metric.getStatus())); + row.createCell(startColumn + 1).setCellValue(metric == null ? "" : safe(metric.getQuantity())); + row.createCell(startColumn + 2).setCellValue(metric == null ? "" : safe(metric.getDeleteQuantity())); + row.createCell(startColumn + 3).setCellValue(metric == null ? "" : safe(metric.getProcessStatus())); + } + + private void writeCartRatioColumns(Row row, int startColumn, List ratios, int ratioIndex) { + PatrolDeleteCartRatioDto ratio = ratios != null && ratioIndex < ratios.size() ? ratios.get(ratioIndex) : null; + row.createCell(startColumn).setCellValue(ratio == null ? "" : safe(ratio.getCountry())); + row.createCell(startColumn + 1).setCellValue(ratio == null ? "" : safe(ratio.getRatio())); + } + + private String safe(String value) { + return value == null ? "" : value; + } +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteResolveService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteResolveService.java new file mode 100644 index 0000000..4a2138f --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteResolveService.java @@ -0,0 +1,166 @@ +package com.nanri.aiimage.modules.patroldelete.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.modules.patroldelete.mapper.PatrolDeleteShopCandidateMapper; +import com.nanri.aiimage.modules.patroldelete.model.entity.PatrolDeleteShopCandidateEntity; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCandidateAddRequest; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskMatchShopsRequest; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskCandidateVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskMatchShopsVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskShopQueueItemVo; +import com.nanri.aiimage.modules.ziniao.model.vo.ZiniaoShopMatchResultVo; +import com.nanri.aiimage.modules.ziniao.service.ZiniaoShopIndexService; +import com.nanri.aiimage.modules.ziniao.service.ZiniaoShopSwitchService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; + +@Service +@RequiredArgsConstructor +public class PatrolDeleteResolveService { + + private final PatrolDeleteShopCandidateMapper candidateMapper; + private final ZiniaoShopSwitchService ziniaoShopSwitchService; + + public List listCandidates(Long userId) { + validateUserId(userId); + List rows = candidateMapper.selectList( + new LambdaQueryWrapper() + .eq(PatrolDeleteShopCandidateEntity::getUserId, userId) + .orderByDesc(PatrolDeleteShopCandidateEntity::getId)); + List list = new ArrayList<>(); + for (PatrolDeleteShopCandidateEntity row : rows) { + ProductRiskCandidateVo vo = new ProductRiskCandidateVo(); + vo.setId(row.getId()); + vo.setShopName(row.getShopName()); + vo.setCreatedAt(row.getCreatedAt()); + list.add(vo); + } + return list; + } + + @Transactional + public ProductRiskCandidateVo addCandidate(ProductRiskCandidateAddRequest request) { + validateUserId(request.getUserId()); + String normalized = ziniaoShopSwitchService.normalizeShopName(request.getShopName()); + if (normalized.isBlank()) { + throw new BusinessException("店铺名不能为空"); + } + ZiniaoShopMatchResultVo indexHit = ziniaoShopSwitchService.findIndexedStoreByName(normalized, false); + if (indexHit == null || !indexHit.isMatched()) { + String hint = indexHit != null && indexHit.getMatchMessage() != null && !indexHit.getMatchMessage().isBlank() + ? indexHit.getMatchMessage() + : "店铺索引未命中,无法加入备选"; + throw new BusinessException(hint); + } + if (ZiniaoShopIndexService.MATCH_STATUS_CONFLICT.equals(indexHit.getMatchStatus())) { + throw new BusinessException(indexHit.getMatchMessage() != null ? indexHit.getMatchMessage() : "存在多个同名店铺,请人工确认"); + } + PatrolDeleteShopCandidateEntity existing = candidateMapper.selectOne( + new LambdaQueryWrapper() + .eq(PatrolDeleteShopCandidateEntity::getUserId, request.getUserId()) + .eq(PatrolDeleteShopCandidateEntity::getShopName, normalized) + .last("limit 1")); + if (existing != null) { + ProductRiskCandidateVo vo = new ProductRiskCandidateVo(); + vo.setId(existing.getId()); + vo.setShopName(existing.getShopName()); + vo.setCreatedAt(existing.getCreatedAt()); + return vo; + } + PatrolDeleteShopCandidateEntity entity = new PatrolDeleteShopCandidateEntity(); + entity.setUserId(request.getUserId()); + entity.setShopName(normalized); + entity.setCreatedAt(LocalDateTime.now()); + candidateMapper.insert(entity); + + ProductRiskCandidateVo vo = new ProductRiskCandidateVo(); + vo.setId(entity.getId()); + vo.setShopName(entity.getShopName()); + vo.setCreatedAt(entity.getCreatedAt()); + return vo; + } + + @Transactional + public void deleteCandidate(Long userId, Long id) { + validateUserId(userId); + if (id == null || id <= 0) { + throw new BusinessException("id 不合法"); + } + PatrolDeleteShopCandidateEntity row = candidateMapper.selectById(id); + if (row == null || !userId.equals(row.getUserId())) { + throw new BusinessException("记录不存在"); + } + candidateMapper.deleteById(id); + } + + public ProductRiskMatchShopsVo matchShops(ProductRiskMatchShopsRequest request) { + validateUserId(request.getUserId()); + LinkedHashSet ordered = new LinkedHashSet<>(); + for (String raw : request.getShopNames()) { + String normalized = ziniaoShopSwitchService.normalizeShopName(raw); + if (!normalized.isBlank()) { + ordered.add(normalized); + } + } + if (ordered.isEmpty()) { + throw new BusinessException("shop_names 无有效店铺名"); + } + ProductRiskMatchShopsVo vo = new ProductRiskMatchShopsVo(); + for (String shopName : ordered) { + vo.getItems().add(matchOneShop(shopName)); + } + return vo; + } + + public long countCandidates(Long userId) { + validateUserId(userId); + Long count = candidateMapper.selectCount(new LambdaQueryWrapper() + .eq(PatrolDeleteShopCandidateEntity::getUserId, userId)); + return count == null ? 0L : count; + } + + private ProductRiskShopQueueItemVo matchOneShop(String shopName) { + ProductRiskShopQueueItemVo item = new ProductRiskShopQueueItemVo(); + item.setShopName(shopName); + try { + ZiniaoShopMatchResultVo matched = ziniaoShopSwitchService.findIndexedStoreByName(shopName, false); + if (matched == null) { + item.setMatched(false); + item.setMatchStatus("PENDING"); + item.setMatchMessage("匹配结果为空"); + return item; + } + item.setMatched(matched.isMatched()); + item.setShopId(matched.getShopId()); + item.setPlatform(matched.getPlatform()); + item.setCompanyName(matched.getCompanyName()); + item.setMatchedUserId(matched.getMatchedUserId()); + item.setMatchStatus(matched.getMatchStatus()); + item.setMatchMessage(matched.getMatchMessage()); + item.setOpenStoreUrl(matched.getOpenStoreUrl()); + } catch (BusinessException ex) { + item.setMatched(false); + item.setMatchStatus("PENDING"); + item.setMatchMessage(ex.getMessage()); + } catch (Exception ex) { + item.setMatched(false); + item.setMatchStatus("PENDING"); + item.setMatchMessage(Objects.toString(ex.getMessage(), "匹配异常")); + } + return item; + } + + private void validateUserId(Long userId) { + if (userId == null || userId <= 0) { + throw new BusinessException("user_id 不合法"); + } + } +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteTaskCacheService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteTaskCacheService.java new file mode 100644 index 0000000..c48d0ee --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteTaskCacheService.java @@ -0,0 +1,211 @@ +package com.nanri.aiimage.modules.patroldelete.service; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.config.TaskPressureProperties; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteShopPayloadDto; +import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity; +import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; + +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Service +@RequiredArgsConstructor +public class PatrolDeleteTaskCacheService { + + private static final long PAYLOAD_TTL_HOURS = 24; + private final StringRedisTemplate stringRedisTemplate; + private final ObjectMapper objectMapper; + private final TaskPressureProperties taskPressureProperties; + private final ConcurrentHashMap taskEntityLocalCache = new ConcurrentHashMap<>(); + + public PatrolDeleteShopPayloadDto getShopMergedPayload(Long taskId, String shopKey) { + if (taskId == null || taskId <= 0 || shopKey == null || shopKey.isBlank()) { + return null; + } + Object raw = stringRedisTemplate.opsForHash().get(buildShopPayloadKey(taskId), shopKey); + if (!(raw instanceof String json) || json.isBlank()) { + return null; + } + try { + return objectMapper.readValue(json, PatrolDeleteShopPayloadDto.class); + } catch (Exception ex) { + throw new BusinessException("读取巡店删除店铺缓存失败"); + } + } + + public void saveShopMergedPayload(Long taskId, String shopKey, PatrolDeleteShopPayloadDto payload) { + if (taskId == null || taskId <= 0 || shopKey == null || shopKey.isBlank() || payload == null) { + return; + } + try { + stringRedisTemplate.opsForHash().put(buildShopPayloadKey(taskId), shopKey, objectMapper.writeValueAsString(payload)); + stringRedisTemplate.expire(buildShopPayloadKey(taskId), Duration.ofHours(PAYLOAD_TTL_HOURS)); + touchTaskHeartbeat(taskId); + } catch (Exception ex) { + throw new BusinessException("暂存巡店删除店铺缓存失败"); + } + } + + public void removeShopMergedPayload(Long taskId, String shopKey) { + if (taskId == null || taskId <= 0 || shopKey == null || shopKey.isBlank()) { + return; + } + stringRedisTemplate.opsForHash().delete(buildShopPayloadKey(taskId), shopKey); + } + + public Map getAllShopMergedPayload(Long taskId) { + try { + Map raw = stringRedisTemplate.opsForHash().entries(buildShopPayloadKey(taskId)); + if (raw == null || raw.isEmpty()) { + return Map.of(); + } + Map out = new LinkedHashMap<>(); + for (Map.Entry entry : raw.entrySet()) { + if (!(entry.getKey() instanceof String key) || !(entry.getValue() instanceof String val) || val.isBlank()) { + continue; + } + out.put(key, objectMapper.readValue(val, PatrolDeleteShopPayloadDto.class)); + } + return out; + } catch (Exception ex) { + throw new BusinessException("读取巡店删除缓存失败"); + } + } + + public boolean hasAnyShopMergedPayload(Long taskId) { + if (taskId == null || taskId <= 0) { + return false; + } + Long size = stringRedisTemplate.opsForHash().size(buildShopPayloadKey(taskId)); + return size != null && size > 0; + } + + public long countShopMergedPayload(Long taskId) { + if (taskId == null || taskId <= 0) { + return 0L; + } + Long size = stringRedisTemplate.opsForHash().size(buildShopPayloadKey(taskId)); + return size == null ? 0L : size; + } + + public long getTaskHeartbeatMillis(Long taskId) { + if (taskId == null || taskId <= 0) { + return 0L; + } + String raw = stringRedisTemplate.opsForValue().get(buildTaskHeartbeatKey(taskId)); + if (raw == null || raw.isBlank()) { + return 0L; + } + try { + return Long.parseLong(raw); + } catch (NumberFormatException ignored) { + return 0L; + } + } + + public void touchTaskHeartbeat(Long taskId) { + stringRedisTemplate.opsForValue().set( + buildTaskHeartbeatKey(taskId), + String.valueOf(Instant.now().toEpochMilli()), + Duration.ofHours(PAYLOAD_TTL_HOURS)); + } + + public void deleteTaskCache(Long taskId) { + if (taskId == null || taskId <= 0) { + return; + } + taskEntityLocalCache.remove(taskId); + stringRedisTemplate.delete(buildShopPayloadKey(taskId)); + stringRedisTemplate.delete(buildTaskHeartbeatKey(taskId)); + stringRedisTemplate.delete(buildTaskEntityKey(taskId)); + } + + public void saveTaskCache(FileTaskEntity task) { + if (task == null || task.getId() == null) { + return; + } + long now = System.currentTimeMillis(); + taskEntityLocalCache.put(task.getId(), new LocalTaskEntityCacheEntry( + now, + objectMapper.convertValue(task, FileTaskEntity.class) + )); + try { + stringRedisTemplate.opsForValue().set( + buildTaskEntityKey(task.getId()), + objectMapper.writeValueAsString(task), + Duration.ofHours(PAYLOAD_TTL_HOURS) + ); + } catch (Exception ignored) { + } + } + + public Map getTaskCacheBatch(java.util.List taskIds) { + Map result = new LinkedHashMap<>(); + if (taskIds == null || taskIds.isEmpty()) { + return result; + } + java.util.List normalized = taskIds.stream() + .filter(id -> id != null && id > 0) + .distinct() + .toList(); + if (normalized.isEmpty()) { + return result; + } + long now = System.currentTimeMillis(); + java.util.List missingIds = new ArrayList<>(); + for (Long taskId : normalized) { + LocalTaskEntityCacheEntry cached = taskEntityLocalCache.get(taskId); + if (isLocalCacheFresh(cached, now)) { + result.put(taskId, objectMapper.convertValue(cached.task(), FileTaskEntity.class)); + } else { + missingIds.add(taskId); + } + } + if (missingIds.isEmpty()) { + return result; + } + java.util.List keys = missingIds.stream().map(this::buildTaskEntityKey).toList(); + java.util.List values = stringRedisTemplate.opsForValue().multiGet(keys); + for (int i = 0; i < missingIds.size(); i++) { + Long taskId = missingIds.get(i); + String val = values != null && i < values.size() ? values.get(i) : null; + if (val == null || val.isBlank()) { + continue; + } + try { + FileTaskEntity task = objectMapper.readValue(val, FileTaskEntity.class); + result.put(taskId, task); + taskEntityLocalCache.put(taskId, new LocalTaskEntityCacheEntry(now, task)); + } catch (Exception ignored) { + } + } + return result; + } + + private String buildShopPayloadKey(Long taskId) { + return "patrol-delete:task:shop-payload:" + taskId; + } + + private String buildTaskHeartbeatKey(Long taskId) { + return "patrol-delete:task:heartbeat:" + taskId; + } + + private String buildTaskEntityKey(Long taskId) { + return "patrol-delete:task:entity:" + taskId; + } + + private boolean isLocalCacheFresh(LocalTaskEntityCacheEntry cached, long now) { + return cached != null + && now - cached.cachedAtMillis() <= Math.max(0L, taskPressureProperties.getLocalTaskEntityCacheMillis()); + } + + private record LocalTaskEntityCacheEntry(long cachedAtMillis, FileTaskEntity task) {} +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteTaskService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteTaskService.java new file mode 100644 index 0000000..ffd31a8 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/patroldelete/service/PatrolDeleteTaskService.java @@ -0,0 +1,883 @@ +package com.nanri.aiimage.modules.patroldelete.service; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.IdUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.config.TaskPressureProperties; +import com.nanri.aiimage.modules.file.service.oss.OssStorageService; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteCartRatioDto; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteCountryMetricRowDto; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteCountrySectionDto; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteCreateTaskRequest; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteShopPayloadDto; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteSubmitResultRequest; +import com.nanri.aiimage.modules.patroldelete.model.dto.PatrolDeleteTaskItemDto; +import com.nanri.aiimage.modules.patroldelete.model.vo.PatrolDeleteTaskBatchVo; +import com.nanri.aiimage.modules.patroldelete.model.vo.PatrolDeleteCreateTaskVo; +import com.nanri.aiimage.modules.patroldelete.model.vo.PatrolDeleteHistoryVo; +import com.nanri.aiimage.modules.patroldelete.model.vo.PatrolDeleteResultItemVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskDashboardVo; +import com.nanri.aiimage.modules.task.mapper.FileResultMapper; +import com.nanri.aiimage.modules.task.mapper.FileTaskMapper; +import com.nanri.aiimage.modules.task.model.entity.FileResultEntity; +import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity; +import com.nanri.aiimage.modules.ziniao.service.ZiniaoShopSwitchService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.File; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@Service +@RequiredArgsConstructor +@Slf4j +public class PatrolDeleteTaskService { + + private static final String MODULE_TYPE = "PATROL_DELETE"; + private static final String CONTENT_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + private static final String INTERRUPTED_MESSAGE = "Python 在该店铺结果提交完成前中断"; + + private final FileTaskMapper fileTaskMapper; + private final FileResultMapper fileResultMapper; + private final PatrolDeleteResolveService patrolDeleteResolveService; + private final PatrolDeleteExcelAssemblyService excelAssemblyService; + private final PatrolDeleteTaskCacheService taskCacheService; + private final OssStorageService ossStorageService; + private final ZiniaoShopSwitchService ziniaoShopSwitchService; + private final ObjectMapper objectMapper; + private final TaskPressureProperties taskPressureProperties; + + private FileTaskEntity loadTaskForExecution(Long taskId) { + Map cachedTasks = taskCacheService.getTaskCacheBatch(List.of(taskId)); + FileTaskEntity cached = cachedTasks.get(taskId); + if (cached != null) { + return cached; + } + FileTaskEntity dbTask = fileTaskMapper.selectById(taskId); + if (dbTask != null && MODULE_TYPE.equals(dbTask.getModuleType())) { + taskCacheService.saveTaskCache(dbTask); + } + return dbTask; + } + + private Map loadTaskMapByIds(List taskIds) { + Map result = new LinkedHashMap<>(); + if (taskIds == null || taskIds.isEmpty()) { + return result; + } + List normalizedTaskIds = taskIds.stream() + .filter(taskId -> taskId != null && taskId > 0) + .distinct() + .toList(); + if (normalizedTaskIds.isEmpty()) { + return result; + } + Map cachedTasks = taskCacheService.getTaskCacheBatch(normalizedTaskIds); + result.putAll(cachedTasks); + List missingTaskIds = normalizedTaskIds.stream() + .filter(taskId -> !cachedTasks.containsKey(taskId)) + .toList(); + if (!missingTaskIds.isEmpty()) { + for (FileTaskEntity dbTask : selectTasksByIdsInBatches(missingTaskIds)) { + if (dbTask == null || !MODULE_TYPE.equals(dbTask.getModuleType())) { + continue; + } + result.put(dbTask.getId(), dbTask); + if ("RUNNING".equals(dbTask.getStatus())) { + taskCacheService.saveTaskCache(dbTask); + } + } + } + return result; + } + + private List selectTasksByIdsInBatches(List taskIds) { + List tasks = new ArrayList<>(); + if (taskIds == null || taskIds.isEmpty()) { + return tasks; + } + int batchSize = Math.max(1, taskPressureProperties.getDbSelectBatchSize()); + for (int start = 0; start < taskIds.size(); start += batchSize) { + int end = Math.min(start + batchSize, taskIds.size()); + tasks.addAll(fileTaskMapper.selectBatchIds(taskIds.subList(start, end))); + } + return tasks; + } + + public ProductRiskDashboardVo dashboard(Long userId) { + validateUserId(userId); + ProductRiskDashboardVo vo = new ProductRiskDashboardVo(); + vo.setCandidateCount(patrolDeleteResolveService.countCandidates(userId)); + vo.setProcessedTaskCount(countTasks(userId, List.of("SUCCESS", "FAILED"))); + vo.setSuccessTaskCount(countTasks(userId, List.of("SUCCESS"))); + vo.setFailedTaskCount(countTasks(userId, List.of("FAILED"))); + return vo; + } + + public PatrolDeleteHistoryVo listHistory(Long userId) { + validateUserId(userId); + PatrolDeleteHistoryVo vo = new PatrolDeleteHistoryVo(); + List entities = fileResultMapper.selectList(new LambdaQueryWrapper() + .eq(FileResultEntity::getModuleType, MODULE_TYPE) + .eq(FileResultEntity::getUserId, userId) + .orderByDesc(FileResultEntity::getCreatedAt) + .last("limit 100")); + if (entities.isEmpty()) { + vo.setItems(List.of()); + return vo; + } + + Map taskMap = loadTaskMap(entities); + Map> snapshotMap = buildSnapshotMap(taskMap); + List items = new ArrayList<>(); + for (FileResultEntity entity : entities) { + FileTaskEntity task = taskMap.get(entity.getTaskId()); + PatrolDeleteResultItemVo snapshot = snapshotMap.getOrDefault(entity.getTaskId(), Map.of()).get(entity.getId()); + items.add(toHistoryItem(entity, task, snapshot)); + } + vo.setItems(items); + return vo; + } + + public PatrolDeleteTaskBatchVo getTaskProgressBatch(List taskIds) { + PatrolDeleteTaskBatchVo batch = new PatrolDeleteTaskBatchVo(); + if (taskIds == null || taskIds.isEmpty()) { + return batch; + } + + List normalizedTaskIds = taskIds.stream() + .filter(taskId -> taskId != null && taskId > 0) + .distinct() + .limit(50) + .toList(); + if (normalizedTaskIds.isEmpty()) { + return batch; + } + + Map taskMap = loadTaskMapByIds(normalizedTaskIds); + List rows = fileResultMapper.selectList(new LambdaQueryWrapper() + .eq(FileResultEntity::getModuleType, MODULE_TYPE) + .in(FileResultEntity::getTaskId, normalizedTaskIds) + .orderByAsc(FileResultEntity::getId)); + Map> rowsByTaskId = new LinkedHashMap<>(); + for (FileResultEntity row : rows) { + rowsByTaskId.computeIfAbsent(row.getTaskId(), ignored -> new ArrayList<>()).add(row); + } + + for (Long taskId : normalizedTaskIds) { + FileTaskEntity task = taskMap.get(taskId); + if (task == null) { + batch.getMissingTaskIds().add(taskId); + continue; + } + List taskRows = rowsByTaskId.get(taskId); + if (taskRows == null || taskRows.isEmpty()) { + batch.getMissingTaskIds().add(taskId); + continue; + } + List snapshots = buildSnapshotFromDb(task, taskRows); + batch.getItems().addAll(snapshots); + } + return batch; + } + + public String resolveResultDownloadUrl(Long resultId, Long userId) { + FileResultEntity entity = fileResultMapper.selectById(resultId); + if (entity == null || !MODULE_TYPE.equals(entity.getModuleType()) || !userId.equals(entity.getUserId())) { + throw new BusinessException("记录不存在"); + } + if (blank(entity.getResultFileUrl())) { + throw new BusinessException("暂无可下载文件"); + } + return ossStorageService.generateFreshDownloadUrl(entity.getResultFileUrl()); + } + + public String resolveResultDownloadFilename(Long resultId, Long userId) { + FileResultEntity entity = fileResultMapper.selectById(resultId); + if (entity == null || !MODULE_TYPE.equals(entity.getModuleType()) || !userId.equals(entity.getUserId())) { + throw new BusinessException("记录不存在"); + } + return !blank(entity.getResultFilename()) + ? entity.getResultFilename() + : safeFileStem(entity.getSourceFilename()) + ".xlsx"; + } + + @Transactional + public PatrolDeleteCreateTaskVo createTask(PatrolDeleteCreateTaskRequest request) { + validateUserId(request.getUserId()); + if (request.getItems() == null || request.getItems().isEmpty()) { + throw new BusinessException("items 不能为空"); + } + + List uniqueItems = dedupeItems(request.getItems()); + if (uniqueItems.isEmpty()) { + throw new BusinessException("items 不能为空"); + } + for (PatrolDeleteTaskItemDto item : uniqueItems) { + if (item == null || !item.isMatched()) { + throw new BusinessException("存在未匹配店铺,无法创建任务"); + } + } + + LocalDateTime now = LocalDateTime.now(); + FileTaskEntity task = new FileTaskEntity(); + task.setTaskNo(MODULE_TYPE + "-" + IdUtil.getSnowflakeNextIdStr()); + task.setModuleType(MODULE_TYPE); + task.setTaskMode("PYTHON_QUEUE"); + task.setStatus("RUNNING"); + task.setSourceFileCount(uniqueItems.size()); + task.setSuccessFileCount(0); + task.setFailedFileCount(0); + task.setCreatedBy("user:" + request.getUserId()); + task.setUserId(request.getUserId()); + task.setCreatedAt(now); + task.setUpdatedAt(now); + fileTaskMapper.insert(task); + taskCacheService.saveTaskCache(task); + taskCacheService.touchTaskHeartbeat(task.getId()); + + List snapshots = new ArrayList<>(); + for (PatrolDeleteTaskItemDto item : uniqueItems) { + String normalizedShopName = ziniaoShopSwitchService.normalizeShopName(item.getShopName()); + if (blank(normalizedShopName)) { + throw new BusinessException("任务数据已失效,请刷新后重试"); + } + FileResultEntity result = new FileResultEntity(); + result.setTaskId(task.getId()); + result.setModuleType(MODULE_TYPE); + result.setSourceFilename(normalizedShopName); + result.setSourceFileUrl(item.getShopId()); + result.setUserId(request.getUserId()); + result.setSuccess(null); + result.setCreatedAt(now); + fileResultMapper.insert(result); + snapshots.add(toSnapshotVo(result, item, task.getStatus(), null)); + } + persistTaskJson(task, uniqueItems, snapshots); + + PatrolDeleteCreateTaskVo vo = new PatrolDeleteCreateTaskVo(); + vo.setTaskId(task.getId()); + vo.setItems(snapshots); + return vo; + } + + @Transactional + public void submitResult(Long taskId, PatrolDeleteSubmitResultRequest request) { + if (taskId == null || taskId <= 0) { + throw new BusinessException("taskId 不合法"); + } + if (request == null || request.getShops() == null || request.getShops().isEmpty()) { + throw new BusinessException("shops 不能为空"); + } + + FileTaskEntity task = loadTaskForExecution(taskId); + if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + throw new BusinessException("任务不存在"); + } + if ("SUCCESS".equals(task.getStatus()) || "FAILED".equals(task.getStatus())) { + throw new BusinessException("任务已结束,拒绝重复提交"); + } + + taskCacheService.touchTaskHeartbeat(taskId); + List resultRows = listTaskRows(taskId); + List snapshots = buildSnapshotFromDb(task, resultRows); + Map snapshotByResultId = indexSnapshotByResultId(snapshots); + Map payloadByShop = normalizePayloadByShop(request.getShops()); + + for (FileResultEntity row : resultRows) { + String shopKey = row.getSourceFilename(); + PatrolDeleteShopPayloadDto incoming = payloadByShop.get(shopKey); + if (incoming == null) { + continue; + } + PatrolDeleteShopPayloadDto mergedPayload = mergeShopPayload(taskId, shopKey, incoming); + PatrolDeleteResultItemVo snapshot = snapshotByResultId.get(row.getId()); + mergePayloadIntoSnapshot(snapshot, mergedPayload); + + if (!blank(mergedPayload.getError())) { + markResultFailed(row, mergedPayload.getError()); + applyFailureToSnapshot(snapshot, mergedPayload.getError()); + taskCacheService.removeShopMergedPayload(taskId, shopKey); + continue; + } + + if (Boolean.TRUE.equals(mergedPayload.getShopDone())) { + markResultSuccess(row); + applySuccessToSnapshot(snapshot); + taskCacheService.removeShopMergedPayload(taskId, shopKey); + } + } + + persistSnapshotJson(task, snapshots); + fileTaskMapper.updateById(task); + tryFinalizeTask(taskId, false); + } + + @Transactional + public boolean tryFinalizeTask(Long taskId, boolean fromCompensation) { + if (taskId == null || taskId <= 0) { + return false; + } + FileTaskEntity task = loadTaskForExecution(taskId); + if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + return false; + } + if ("SUCCESS".equals(task.getStatus()) || "FAILED".equals(task.getStatus())) { + return true; + } + + List rows = listTaskRows(taskId); + if (rows.isEmpty()) { + return false; + } + + Map cachedPayloads = taskCacheService.getAllShopMergedPayload(taskId); + List snapshots = buildSnapshotFromDb(task, rows); + Map snapshotByResultId = indexSnapshotByResultId(snapshots); + boolean changed = false; + + for (FileResultEntity row : rows) { + if (isResultFinished(row)) { + continue; + } + PatrolDeleteResultItemVo snapshot = snapshotByResultId.get(row.getId()); + PatrolDeleteShopPayloadDto cached = cachedPayloads.get(row.getSourceFilename()); + if (cached == null) { + if (fromCompensation) { + markResultFailed(row, INTERRUPTED_MESSAGE); + applyFailureToSnapshot(snapshot, INTERRUPTED_MESSAGE); + changed = true; + } + continue; + } + + mergePayloadIntoSnapshot(snapshot, cached); + + if (!blank(cached.getError())) { + markResultFailed(row, cached.getError()); + applyFailureToSnapshot(snapshot, cached.getError()); + taskCacheService.removeShopMergedPayload(taskId, row.getSourceFilename()); + changed = true; + continue; + } + + if (Boolean.TRUE.equals(cached.getShopDone()) || (fromCompensation && hasAnyPayloadData(cached))) { + markResultSuccess(row); + applySuccessToSnapshot(snapshot); + taskCacheService.removeShopMergedPayload(taskId, row.getSourceFilename()); + changed = true; + continue; + } + + if (fromCompensation) { + markResultFailed(row, INTERRUPTED_MESSAGE); + applyFailureToSnapshot(snapshot, INTERRUPTED_MESSAGE); + taskCacheService.removeShopMergedPayload(taskId, row.getSourceFilename()); + changed = true; + } + } + + List latestRows = listTaskRows(taskId); + updateTaskStatusFromRows(task, latestRows); + if (latestRows.stream().allMatch(this::isResultFinished)) { + finalizeTaskWorkbook(task, latestRows, snapshots); + return true; + } + + persistSnapshotJson(task, snapshots); + fileTaskMapper.updateById(task); + return changed; + } + + @Transactional + public void deleteTask(Long taskId, Long userId) { + validateUserId(userId); + FileTaskEntity task = loadTaskForExecution(taskId); + if (task == null || !MODULE_TYPE.equals(task.getModuleType()) || !userId.equals(task.getUserId())) { + throw new BusinessException("任务不存在"); + } + fileResultMapper.delete(new LambdaQueryWrapper() + .eq(FileResultEntity::getTaskId, taskId) + .eq(FileResultEntity::getModuleType, MODULE_TYPE)); + fileTaskMapper.deleteById(taskId); + taskCacheService.deleteTaskCache(taskId); + } + + @Transactional + public void deleteHistory(Long resultId, Long userId) { + validateUserId(userId); + FileResultEntity entity = fileResultMapper.selectById(resultId); + if (entity == null || !MODULE_TYPE.equals(entity.getModuleType()) || !userId.equals(entity.getUserId())) { + throw new BusinessException("记录不存在"); + } + Long taskId = entity.getTaskId(); + fileResultMapper.deleteById(resultId); + reconcileTaskAfterResultRemoval(taskId); + } + + private void reconcileTaskAfterResultRemoval(Long taskId) { + if (taskId == null || taskId <= 0) { + return; + } + FileTaskEntity task = loadTaskForExecution(taskId); + if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + return; + } + List rows = listTaskRows(taskId); + if (rows.isEmpty()) { + fileTaskMapper.deleteById(taskId); + taskCacheService.deleteTaskCache(taskId); + return; + } + updateTaskStatusFromRows(task, rows); + persistSnapshotJson(task, buildSnapshotFromDb(task, rows)); + fileTaskMapper.updateById(task); + } + + private long countTasks(Long userId, List statuses) { + Long count = fileTaskMapper.selectCount(new LambdaQueryWrapper() + .eq(FileTaskEntity::getModuleType, MODULE_TYPE) + .eq(FileTaskEntity::getUserId, userId) + .in(FileTaskEntity::getStatus, statuses)); + return count == null ? 0L : count; + } + + private List listTaskRows(Long taskId) { + return fileResultMapper.selectList(new LambdaQueryWrapper() + .eq(FileResultEntity::getTaskId, taskId) + .eq(FileResultEntity::getModuleType, MODULE_TYPE) + .orderByAsc(FileResultEntity::getId)); + } + + private Map normalizePayloadByShop(List shops) { + Map payloadByShop = new LinkedHashMap<>(); + for (PatrolDeleteShopPayloadDto item : shops) { + if (item == null) { + continue; + } + String shopKey = ziniaoShopSwitchService.normalizeShopName(item.getShopName()); + if (blank(shopKey)) { + continue; + } + item.setShopName(shopKey); + payloadByShop.put(shopKey, item); + } + return payloadByShop; + } + + private Map loadTaskMap(List entities) { + List taskIds = entities.stream() + .map(FileResultEntity::getTaskId) + .filter(id -> id != null && id > 0) + .distinct() + .toList(); + Map taskMap = new LinkedHashMap<>(); + if (taskIds.isEmpty()) { + return taskMap; + } + for (FileTaskEntity task : selectTasksByIdsInBatches(taskIds)) { + if (task != null && MODULE_TYPE.equals(task.getModuleType())) { + taskMap.put(task.getId(), task); + } + } + return taskMap; + } + + private Map> buildSnapshotMap(Map taskMap) { + Map> out = new LinkedHashMap<>(); + for (Map.Entry entry : taskMap.entrySet()) { + out.put(entry.getKey(), indexSnapshotByResultId(parseTaskSnapshots(entry.getValue().getResultJson()))); + } + return out; + } + + private PatrolDeleteResultItemVo toHistoryItem(FileResultEntity entity, FileTaskEntity task, PatrolDeleteResultItemVo snapshot) { + PatrolDeleteResultItemVo item = snapshot != null ? snapshot : new PatrolDeleteResultItemVo(); + item.setResultId(entity.getId()); + item.setTaskId(entity.getTaskId()); + item.setShopName(firstNonBlank(item.getShopName(), entity.getSourceFilename())); + item.setShopId(firstNonBlank(item.getShopId(), entity.getSourceFileUrl())); + item.setTaskStatus(task != null ? task.getStatus() : item.getTaskStatus()); + item.setSuccess(entity.getSuccess() == null ? item.getSuccess() : entity.getSuccess() == 1); + item.setError(!blank(entity.getErrorMessage()) ? entity.getErrorMessage() : item.getError()); + item.setCreatedAt(entity.getCreatedAt()); + item.setFinishedAt(task != null ? task.getFinishedAt() : item.getFinishedAt()); + item.setOutputFilename(firstNonBlank(item.getOutputFilename(), entity.getResultFilename())); + item.setDownloadUrl(blank(entity.getResultFileUrl()) + ? item.getDownloadUrl() + : ossStorageService.generateFreshDownloadUrl(entity.getResultFileUrl())); + if (item.getCountrySections() == null) { + item.setCountrySections(new ArrayList<>()); + } + if (item.getCartRatios() == null) { + item.setCartRatios(new ArrayList<>()); + } + return item; + } + + private List dedupeItems(List items) { + LinkedHashMap map = new LinkedHashMap<>(); + for (PatrolDeleteTaskItemDto item : items) { + if (item == null) { + continue; + } + String normalizedShopName = ziniaoShopSwitchService.normalizeShopName(item.getShopName()); + if (blank(normalizedShopName)) { + continue; + } + item.setShopName(normalizedShopName); + String key = normalizedShopName + "::" + Objects.toString(item.getShopId(), ""); + map.put(key, item); + } + return new ArrayList<>(map.values()); + } + + private PatrolDeleteResultItemVo toSnapshotVo(FileResultEntity result, PatrolDeleteTaskItemDto item, String taskStatus, LocalDateTime finishedAt) { + PatrolDeleteResultItemVo vo = new PatrolDeleteResultItemVo(); + vo.setResultId(result.getId()); + vo.setTaskId(result.getTaskId()); + vo.setShopName(item.getShopName()); + vo.setShopId(item.getShopId()); + vo.setPlatform(item.getPlatform()); + vo.setCompanyName(item.getCompanyName()); + vo.setMatched(item.isMatched()); + vo.setMatchStatus(item.getMatchStatus()); + vo.setMatchMessage(item.getMatchMessage()); + vo.setTaskStatus(taskStatus); + vo.setSuccess(result.getSuccess() == null ? null : result.getSuccess() == 1); + vo.setError(result.getErrorMessage()); + vo.setCreatedAt(result.getCreatedAt()); + vo.setFinishedAt(finishedAt); + vo.setCountrySections(copyCountrySections(item.getCountrySections())); + vo.setCartRatios(copyCartRatios(item.getCartRatios())); + vo.setOutputFilename(result.getResultFilename()); + vo.setDownloadUrl(null); + return vo; + } + + private void persistTaskJson(FileTaskEntity task, List requestItems, List snapshots) { + try { + task.setRequestJson(objectMapper.writeValueAsString(requestItems)); + task.setResultJson(objectMapper.writeValueAsString(snapshots)); + fileTaskMapper.updateById(task); + } catch (Exception ex) { + throw new BusinessException("巡店删除任务快照保存失败"); + } + } + + private List buildSnapshotFromDb(FileTaskEntity task, List rows) { + List existing = parseTaskSnapshots(task.getResultJson()); + Map snapshotByResultId = indexSnapshotByResultId(existing); + List list = new ArrayList<>(); + for (FileResultEntity row : rows) { + list.add(toHistoryItem(row, task, snapshotByResultId.get(row.getId()))); + } + return list; + } + + private Map indexSnapshotByResultId(List snapshots) { + Map map = new LinkedHashMap<>(); + if (snapshots == null) { + return map; + } + for (PatrolDeleteResultItemVo snapshot : snapshots) { + if (snapshot != null && snapshot.getResultId() != null) { + map.put(snapshot.getResultId(), snapshot); + } + } + return map; + } + + private void updateTaskStatusFromRows(FileTaskEntity task, List rows) { + long successCount = rows.stream().filter(row -> Integer.valueOf(1).equals(row.getSuccess())).count(); + long failedCount = rows.stream().filter(row -> Integer.valueOf(0).equals(row.getSuccess())).count(); + long pendingCount = rows.stream().filter(row -> !isResultFinished(row)).count(); + task.setSuccessFileCount((int) successCount); + task.setFailedFileCount((int) failedCount); + task.setUpdatedAt(LocalDateTime.now()); + if (pendingCount > 0) { + task.setStatus("RUNNING"); + task.setFinishedAt(null); + task.setErrorMessage(null); + return; + } + task.setStatus(failedCount > 0 ? "FAILED" : "SUCCESS"); + task.setFinishedAt(LocalDateTime.now()); + if (failedCount > 0) { + List errors = new ArrayList<>(); + for (FileResultEntity row : rows) { + if (!blank(row.getErrorMessage())) { + errors.add(row.getSourceFilename() + ": " + row.getErrorMessage()); + } + } + task.setErrorMessage(String.join("; ", errors)); + } else { + task.setErrorMessage(null); + } + } + + private PatrolDeleteShopPayloadDto mergeShopPayload(Long taskId, String shopKey, PatrolDeleteShopPayloadDto incoming) { + PatrolDeleteShopPayloadDto merged = taskCacheService.getShopMergedPayload(taskId, shopKey); + if (merged == null) { + merged = new PatrolDeleteShopPayloadDto(); + merged.setShopName(shopKey); + merged.setCountrySections(new ArrayList<>()); + merged.setCartRatios(new ArrayList<>()); + } + + merged.setShopName(firstNonBlank(incoming.getShopName(), merged.getShopName())); + merged.setSubmissionId(firstNonBlank(incoming.getSubmissionId(), merged.getSubmissionId())); + merged.setChunkIndex(incoming.getChunkIndex()); + merged.setChunkTotal(incoming.getChunkTotal()); + + if (!blank(incoming.getError())) { + merged.setError(incoming.getError().trim()); + merged.setShopDone(Boolean.TRUE); + taskCacheService.saveShopMergedPayload(taskId, shopKey, merged); + return merged; + } + + merged.setCountrySections(mergeCountrySections(merged.getCountrySections(), incoming.getCountrySections())); + merged.setCartRatios(mergeCartRatios(merged.getCartRatios(), incoming.getCartRatios())); + if (Boolean.TRUE.equals(incoming.getShopDone())) { + merged.setShopDone(Boolean.TRUE); + } + taskCacheService.saveShopMergedPayload(taskId, shopKey, merged); + return merged; + } + + private void mergePayloadIntoSnapshot(PatrolDeleteResultItemVo snapshot, PatrolDeleteShopPayloadDto payload) { + if (snapshot == null || payload == null) { + return; + } + snapshot.setShopName(firstNonBlank(payload.getShopName(), snapshot.getShopName())); + snapshot.setCountrySections(copyCountrySections(payload.getCountrySections())); + snapshot.setCartRatios(copyCartRatios(payload.getCartRatios())); + if (!blank(payload.getError())) { + snapshot.setError(payload.getError().trim()); + } + } + + private void applySuccessToSnapshot(PatrolDeleteResultItemVo snapshot) { + if (snapshot == null) { + return; + } + snapshot.setSuccess(Boolean.TRUE); + snapshot.setError(null); + } + + private void applyFailureToSnapshot(PatrolDeleteResultItemVo snapshot, String error) { + if (snapshot == null) { + return; + } + snapshot.setSuccess(Boolean.FALSE); + snapshot.setError(blankToNull(error)); + } + + private List mergeCountrySections(List base, List incoming) { + Map map = new LinkedHashMap<>(); + for (PatrolDeleteCountrySectionDto section : copyCountrySections(base)) { + map.put(section.getCountry(), section); + } + for (PatrolDeleteCountrySectionDto section : copyCountrySections(incoming)) { + PatrolDeleteCountrySectionDto existing = map.get(section.getCountry()); + if (existing == null) { + map.put(section.getCountry(), section); + continue; + } + List mergedRows = existing.getRows() == null + ? new ArrayList<>() + : new ArrayList<>(existing.getRows()); + if (section.getRows() != null) { + mergedRows.addAll(section.getRows()); + } + existing.setRows(mergedRows); + } + return new ArrayList<>(map.values()); + } + + private List mergeCartRatios(List base, List incoming) { + Map map = new LinkedHashMap<>(); + for (PatrolDeleteCartRatioDto ratio : copyCartRatios(base)) { + map.put(ratio.getCountry(), ratio); + } + for (PatrolDeleteCartRatioDto ratio : copyCartRatios(incoming)) { + if (!blank(ratio.getCountry())) { + map.put(ratio.getCountry(), ratio); + } + } + return new ArrayList<>(map.values()); + } + + private boolean hasAnyPayloadData(PatrolDeleteShopPayloadDto payload) { + if (payload == null) { + return false; + } + if (payload.getCountrySections() != null) { + for (PatrolDeleteCountrySectionDto section : payload.getCountrySections()) { + if (section == null || section.getRows() == null) { + continue; + } + for (PatrolDeleteCountryMetricRowDto row : section.getRows()) { + if (row != null && (!blank(row.getStatus()) + || !blank(row.getQuantity()) + || !blank(row.getDeleteQuantity()) + || !blank(row.getProcessStatus()))) { + return true; + } + } + } + } + if (payload.getCartRatios() != null) { + for (PatrolDeleteCartRatioDto ratio : payload.getCartRatios()) { + if (ratio != null && (!blank(ratio.getCountry()) || !blank(ratio.getRatio()))) { + return true; + } + } + } + return false; + } + + private void finalizeTaskWorkbook(FileTaskEntity task, List rows, List snapshots) { + List successItems = snapshots.stream() + .filter(item -> Boolean.TRUE.equals(item.getSuccess())) + .toList(); + if (!successItems.isEmpty()) { + File workRoot = FileUtil.mkdir(FileUtil.file(System.getProperty("java.io.tmpdir"), "patrol-delete-result", String.valueOf(task.getId()))); + String filename = safeFileStem("巡店删除-" + task.getId()) + ".xlsx"; + File xlsx = FileUtil.file(workRoot, filename); + try { + excelAssemblyService.writeWorkbook(xlsx, successItems); + String objectKey = ossStorageService.uploadResultFile(xlsx, MODULE_TYPE); + long fileSize = xlsx.length(); + int rowCount = excelAssemblyService.countRows(successItems); + for (FileResultEntity row : rows) { + if (Integer.valueOf(1).equals(row.getSuccess())) { + row.setResultFilename(filename); + row.setResultFileUrl(objectKey); + row.setResultFileSize(fileSize); + row.setResultContentType(CONTENT_TYPE_XLSX); + row.setRowCount(rowCount); + fileResultMapper.updateById(row); + } + } + snapshots = buildSnapshotFromDb(task, rows); + } finally { + FileUtil.del(xlsx); + } + } + + persistSnapshotJson(task, snapshots); + fileTaskMapper.updateById(task); + taskCacheService.deleteTaskCache(task.getId()); + } + + private void markResultSuccess(FileResultEntity row) { + row.setSuccess(1); + row.setErrorMessage(null); + fileResultMapper.updateById(row); + } + + private void markResultFailed(FileResultEntity row, String message) { + row.setSuccess(0); + row.setErrorMessage(blankToNull(message)); + row.setResultFilename(null); + row.setResultFileUrl(null); + row.setResultFileSize(0L); + row.setResultContentType(null); + row.setRowCount(0); + fileResultMapper.updateById(row); + } + + private boolean isResultFinished(FileResultEntity row) { + return Integer.valueOf(1).equals(row.getSuccess()) || Integer.valueOf(0).equals(row.getSuccess()); + } + + private List parseTaskSnapshots(String json) { + if (blank(json)) { + return new ArrayList<>(); + } + try { + return objectMapper.readValue(json, new TypeReference>() {}); + } catch (Exception ex) { + log.warn("[patrol-delete] parse task snapshot failed: {}", ex.getMessage()); + return new ArrayList<>(); + } + } + + private void persistSnapshotJson(FileTaskEntity task, List snapshots) { + try { + task.setResultJson(objectMapper.writeValueAsString(snapshots == null ? List.of() : snapshots)); + } catch (Exception ex) { + throw new BusinessException("巡店删除任务快照保存失败"); + } + } + + private List copyCountrySections(List sections) { + List copy = new ArrayList<>(); + if (sections == null) { + return copy; + } + for (PatrolDeleteCountrySectionDto section : sections) { + if (section == null) { + continue; + } + PatrolDeleteCountrySectionDto item = new PatrolDeleteCountrySectionDto(); + item.setCountry(section.getCountry()); + item.setRows(section.getRows() == null ? new ArrayList<>() : new ArrayList<>(section.getRows())); + copy.add(item); + } + return copy; + } + + private List copyCartRatios(List ratios) { + List copy = new ArrayList<>(); + if (ratios == null) { + return copy; + } + for (PatrolDeleteCartRatioDto ratio : ratios) { + if (ratio == null) { + continue; + } + PatrolDeleteCartRatioDto item = new PatrolDeleteCartRatioDto(); + item.setCountry(ratio.getCountry()); + item.setRatio(ratio.getRatio()); + copy.add(item); + } + return copy; + } + + private String firstNonBlank(String first, String second) { + return !blank(first) ? first : second; + } + + private String safeFileStem(String value) { + String raw = value == null ? "result" : value.trim(); + String safe = raw.replaceAll("[\\\\/:*?\"<>|]+", "_"); + return safe.isBlank() ? "result" : safe; + } + + private boolean blank(String value) { + return value == null || value.isBlank(); + } + + private String blankToNull(String value) { + return blank(value) ? null : value.trim(); + } + + private void validateUserId(Long userId) { + if (userId == null || userId <= 0) { + throw new BusinessException("user_id 不合法"); + } + } +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/controller/PriceTrackController.java b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/controller/PriceTrackController.java index 5482cd0..8a8a811 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/controller/PriceTrackController.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/controller/PriceTrackController.java @@ -223,7 +223,10 @@ public class PriceTrackController { example = "200" ) @PathVariable Long taskId, - @Valid @RequestBody PriceTrackSubmitResultRequest request) { + @Valid @RequestBody PriceTrackSubmitResultRequest request, + jakarta.servlet.http.HttpServletResponse response) { + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); + response.setContentType("application/json;charset=UTF-8"); priceTrackTaskService.submitResult(taskId, request); return ApiResponse.success(null); } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/model/vo/PriceTrackCreateTaskVo.java b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/model/vo/PriceTrackCreateTaskVo.java index 1e6b686..d9887ae 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/model/vo/PriceTrackCreateTaskVo.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/model/vo/PriceTrackCreateTaskVo.java @@ -20,4 +20,7 @@ public class PriceTrackCreateTaskVo { @Schema(description = "parsed asin rows by country") private Map>> asinRowsByCountry; + + @Schema(description = "minimum price grouped by country code and asin") + private Map> minimumPriceByCountryAndAsin; } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/model/vo/PriceTrackMatchShopsVo.java b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/model/vo/PriceTrackMatchShopsVo.java index 6d220f0..426e06d 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/model/vo/PriceTrackMatchShopsVo.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/model/vo/PriceTrackMatchShopsVo.java @@ -20,6 +20,9 @@ public class PriceTrackMatchShopsVo { @Schema(description = "Parsed asin rows grouped by country code") private Map>> asinRowsByCountry; + @Schema(description = "Minimum price grouped by country code and asin") + private Map> minimumPriceByCountryAndAsin; + @Data @Schema(description = "Single matched shop item") public static class PriceTrackShopQueueItem { diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackService.java index 3792c0a..7caade6 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackService.java @@ -158,6 +158,7 @@ public class PriceTrackService { PriceTrackMatchShopsVo vo = new PriceTrackMatchShopsVo(); vo.setSkipAsinsByCountry(skipAsinsByCountry); vo.setAsinRowsByCountry(asinRowsByCountry); + vo.setMinimumPriceByCountryAndAsin(priceTrackTaskService.buildMinimumPriceLookupForMatch(asinRowsByCountry)); for (String shopName : ordered) { vo.getItems().add(matchOneShop(shopName, skipAsinsByCountry)); } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackTaskCacheService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackTaskCacheService.java index 20a0ce9..432c18e 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackTaskCacheService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackTaskCacheService.java @@ -2,24 +2,29 @@ package com.nanri.aiimage.modules.pricetrack.service; import com.fasterxml.jackson.databind.ObjectMapper; import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.config.TaskPressureProperties; import com.nanri.aiimage.modules.pricetrack.model.dto.PriceTrackSubmitResultRequest; +import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import java.time.Duration; import java.time.Instant; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; @Service @RequiredArgsConstructor public class PriceTrackTaskCacheService { private static final long HEARTBEAT_TTL_HOURS = 24; - private final StringRedisTemplate stringRedisTemplate; private final ObjectMapper objectMapper; + private final TaskPressureProperties taskPressureProperties; + private final ConcurrentHashMap taskEntityLocalCache = new ConcurrentHashMap<>(); public void touchTaskHeartbeat(Long taskId) { if (taskId == null || taskId <= 0) { @@ -112,8 +117,72 @@ public class PriceTrackTaskCacheService { if (taskId == null || taskId <= 0) { return; } + taskEntityLocalCache.remove(taskId); stringRedisTemplate.delete(buildShopPayloadKey(taskId)); stringRedisTemplate.delete(buildTaskHeartbeatKey(taskId)); + stringRedisTemplate.delete(buildTaskEntityKey(taskId)); + } + + public void saveTaskCache(FileTaskEntity task) { + if (task == null || task.getId() == null) { + return; + } + long now = System.currentTimeMillis(); + taskEntityLocalCache.put(task.getId(), new LocalTaskEntityCacheEntry( + now, + objectMapper.convertValue(task, FileTaskEntity.class) + )); + try { + stringRedisTemplate.opsForValue().set( + buildTaskEntityKey(task.getId()), + objectMapper.writeValueAsString(task), + Duration.ofHours(HEARTBEAT_TTL_HOURS) + ); + } catch (Exception ignored) { + } + } + + public Map getTaskCacheBatch(java.util.List taskIds) { + Map result = new LinkedHashMap<>(); + if (taskIds == null || taskIds.isEmpty()) { + return result; + } + java.util.List normalized = taskIds.stream() + .filter(id -> id != null && id > 0) + .distinct() + .toList(); + if (normalized.isEmpty()) { + return result; + } + long now = System.currentTimeMillis(); + java.util.List missingIds = new ArrayList<>(); + for (Long taskId : normalized) { + LocalTaskEntityCacheEntry cached = taskEntityLocalCache.get(taskId); + if (isLocalCacheFresh(cached, now)) { + result.put(taskId, objectMapper.convertValue(cached.task(), FileTaskEntity.class)); + } else { + missingIds.add(taskId); + } + } + if (missingIds.isEmpty()) { + return result; + } + java.util.List keys = missingIds.stream().map(this::buildTaskEntityKey).toList(); + java.util.List values = stringRedisTemplate.opsForValue().multiGet(keys); + for (int i = 0; i < missingIds.size(); i++) { + Long taskId = missingIds.get(i); + String val = values != null && i < values.size() ? values.get(i) : null; + if (val == null || val.isBlank()) { + continue; + } + try { + FileTaskEntity task = objectMapper.readValue(val, FileTaskEntity.class); + result.put(taskId, task); + taskEntityLocalCache.put(taskId, new LocalTaskEntityCacheEntry(now, task)); + } catch (Exception ignored) { + } + } + return result; } private String buildShopPayloadKey(Long taskId) { @@ -123,4 +192,15 @@ public class PriceTrackTaskCacheService { private String buildTaskHeartbeatKey(Long taskId) { return "price-track:task:heartbeat:" + taskId; } + + private String buildTaskEntityKey(Long taskId) { + return "price-track:task:entity:" + taskId; + } + + private boolean isLocalCacheFresh(LocalTaskEntityCacheEntry cached, long now) { + return cached != null + && now - cached.cachedAtMillis() <= Math.max(0L, taskPressureProperties.getLocalTaskEntityCacheMillis()); + } + + private record LocalTaskEntityCacheEntry(long cachedAtMillis, FileTaskEntity task) {} } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackTaskService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackTaskService.java index b66815a..75c07d0 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackTaskService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/pricetrack/service/PriceTrackTaskService.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.nanri.aiimage.common.exception.BusinessException; import com.nanri.aiimage.common.util.ExcelStreamReader; +import com.nanri.aiimage.config.TaskPressureProperties; import com.nanri.aiimage.modules.file.service.oss.OssStorageService; import com.nanri.aiimage.modules.productrisk.model.enums.ProductRiskCountryCode; import com.nanri.aiimage.modules.pricetrack.mapper.PriceTrackShopCandidateMapper; @@ -64,6 +65,62 @@ public class PriceTrackTaskService { private final PriceTrackExcelAssemblyService excelAssemblyService; private final PriceTrackTaskCacheService priceTrackTaskCacheService; private final PriceTrackLoopRunService priceTrackLoopRunService; + private final TaskPressureProperties taskPressureProperties; + + private FileTaskEntity loadTaskForExecution(Long taskId) { + Map cachedTasks = priceTrackTaskCacheService.getTaskCacheBatch(List.of(taskId)); + FileTaskEntity cached = cachedTasks.get(taskId); + if (cached != null) { + return cached; + } + FileTaskEntity dbTask = fileTaskMapper.selectById(taskId); + if (dbTask != null && MODULE_TYPE.equals(dbTask.getModuleType())) { + priceTrackTaskCacheService.saveTaskCache(dbTask); + } + return dbTask; + } + + private Map loadTaskMapByIds(List taskIds) { + Map result = new LinkedHashMap<>(); + if (taskIds == null || taskIds.isEmpty()) { + return result; + } + List normalizedTaskIds = taskIds.stream() + .filter(taskId -> taskId != null && taskId > 0) + .distinct() + .toList(); + if (normalizedTaskIds.isEmpty()) { + return result; + } + Map cachedTasks = priceTrackTaskCacheService.getTaskCacheBatch(normalizedTaskIds); + result.putAll(cachedTasks); + List missingTaskIds = normalizedTaskIds.stream() + .filter(taskId -> !cachedTasks.containsKey(taskId)) + .toList(); + for (FileTaskEntity dbTask : selectTasksByIdsInBatches(missingTaskIds)) { + if (dbTask == null || !MODULE_TYPE.equals(dbTask.getModuleType())) { + continue; + } + result.put(dbTask.getId(), dbTask); + if ("RUNNING".equals(dbTask.getStatus())) { + priceTrackTaskCacheService.saveTaskCache(dbTask); + } + } + return result; + } + + private List selectTasksByIdsInBatches(List taskIds) { + List tasks = new ArrayList<>(); + if (taskIds == null || taskIds.isEmpty()) { + return tasks; + } + int batchSize = Math.max(1, taskPressureProperties.getDbSelectBatchSize()); + for (int start = 0; start < taskIds.size(); start += batchSize) { + int end = Math.min(start + batchSize, taskIds.size()); + tasks.addAll(fileTaskMapper.selectBatchIds(taskIds.subList(start, end))); + } + return tasks; + } public PriceTrackDashboardVo dashboard(Long userId) { if (userId == null || userId <= 0) throw new BusinessException("user_id 不合法"); @@ -104,7 +161,7 @@ public class PriceTrackTaskService { .distinct() .toList(); if (!taskIds.isEmpty()) { - List tasks = fileTaskMapper.selectBatchIds(taskIds); + List tasks = selectTasksByIdsInBatches(taskIds); for (FileTaskEntity t : tasks) { if (t != null) statusByTaskId.put(t.getId(), t.getStatus()); } @@ -134,7 +191,7 @@ public class PriceTrackTaskService { @Transactional public void deleteTask(Long taskId, Long userId) { if (userId == null || userId <= 0) throw new BusinessException("user_id 不合法"); - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType()) || !userId.equals(task.getUserId())) { throw new BusinessException("任务不存在"); } @@ -164,7 +221,7 @@ public class PriceTrackTaskService { vo.setRemoved(false); for (FileResultEntity fr : candidates) { if (fr.getTaskId() == null) continue; - FileTaskEntity task = fileTaskMapper.selectById(fr.getTaskId()); + FileTaskEntity task = loadTaskForExecution(fr.getTaskId()); if (task == null || !MODULE_TYPE.equals(task.getModuleType()) || !userId.equals(task.getUserId())) continue; if (!"RUNNING".equals(task.getStatus())) continue; fileResultMapper.deleteById(fr.getId()); @@ -178,10 +235,11 @@ public class PriceTrackTaskService { public PriceTrackTaskBatchVo getTaskDetailsBatch(List taskIds) { PriceTrackTaskBatchVo batch = new PriceTrackTaskBatchVo(); if (taskIds == null || taskIds.isEmpty()) return batch; + Map taskMap = loadTaskMapByIds(taskIds); for (Long taskId : taskIds) { if (taskId == null || taskId <= 0) continue; - FileTaskEntity task = fileTaskMapper.selectById(taskId); - if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + FileTaskEntity task = taskMap.get(taskId); + if (task == null) { batch.getMissingTaskIds().add(taskId); continue; } @@ -195,12 +253,13 @@ public class PriceTrackTaskService { if (taskIds == null || taskIds.isEmpty()) { return batch; } + Map taskMap = loadTaskMapByIds(taskIds); for (Long taskId : taskIds) { if (taskId == null || taskId <= 0) { continue; } - FileTaskEntity task = fileTaskMapper.selectById(taskId); - if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + FileTaskEntity task = taskMap.get(taskId); + if (task == null) { batch.getMissingTaskIds().add(taskId); continue; } @@ -237,6 +296,8 @@ public class PriceTrackTaskService { Map>> asinRowsByCountry = request.isAsinMode() ? parseAsinRowsByCountry(request.getAsinFiles(), request.getCountryCodes()) : new LinkedHashMap<>(); + Map> minimumPriceByCountryAndAsin = + buildMinimumPriceByCountryAndAsin(asinRowsByCountry); log.info("[price-track] createTask skipAsins countries={} asinMode={}", skipAsinsByCountry.keySet(), request.isAsinMode()); @@ -254,6 +315,7 @@ public class PriceTrackTaskService { task.setCreatedAt(LocalDateTime.now()); task.setUpdatedAt(LocalDateTime.now()); fileTaskMapper.insert(task); + priceTrackTaskCacheService.saveTaskCache(task); priceTrackTaskCacheService.touchTaskHeartbeat(task.getId()); if (request.getLoopRunId() != null) { priceTrackLoopRunService.bindChildTask(request.getLoopRunId(), task.getId(), request.getRoundIndex(), request.getShopIndex()); @@ -287,6 +349,7 @@ public class PriceTrackTaskService { ctx.put("countryCodes", request.getCountryCodes()); ctx.put("skipAsinsByCountry", skipAsinsByCountry); ctx.put("asinRowsByCountry", asinRowsByCountry); + ctx.put("minimumPriceByCountryAndAsin", minimumPriceByCountryAndAsin); ctx.put("items", uniqueItems); ctx.put("loopRunId", request.getLoopRunId()); ctx.put("roundIndex", request.getRoundIndex()); @@ -306,6 +369,7 @@ public class PriceTrackTaskService { vo.setItems(snapshot); vo.setSkipAsinsByCountry(skipAsinsByCountry); vo.setAsinRowsByCountry(asinRowsByCountry); + vo.setMinimumPriceByCountryAndAsin(minimumPriceByCountryAndAsin); return vo; } @@ -315,7 +379,7 @@ public class PriceTrackTaskService { if (request == null || request.getShops() == null || request.getShops().isEmpty()) { throw new BusinessException("shops 不能为空"); } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { throw new BusinessException("任务不存在"); } @@ -386,7 +450,7 @@ public class PriceTrackTaskService { @Transactional public boolean tryFinalizeTask(Long taskId, boolean fromCompensation) { if (taskId == null || taskId <= 0) return false; - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) return false; if (!"RUNNING".equals(task.getStatus())) { log.warn("[price-track] stale finalize skipped taskId={} status={} fromCompensation={}", @@ -490,7 +554,7 @@ public class PriceTrackTaskService { // ---- private helpers ---- private void reconcileTaskAfterResultRemoval(Long taskId) { - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) return; List latest = fileResultMapper.selectList( new LambdaQueryWrapper() @@ -552,6 +616,11 @@ public class PriceTrackTaskService { return parseAsinRowsByCountry(asinFiles, countryCodes); } + public Map> buildMinimumPriceLookupForMatch( + Map>> asinRowsByCountry) { + return buildMinimumPriceByCountryAndAsin(asinRowsByCountry); + } + private Map>> parseAsinRowsByCountry(List asinFiles, List countryCodes) { Map>> merged = new LinkedHashMap<>(); if (asinFiles == null || asinFiles.isEmpty()) { @@ -654,6 +723,37 @@ public class PriceTrackTaskService { } } + private Map> buildMinimumPriceByCountryAndAsin( + Map>> asinRowsByCountry) { + Map> out = new LinkedHashMap<>(); + if (asinRowsByCountry == null || asinRowsByCountry.isEmpty()) { + return out; + } + for (Map.Entry>> entry : asinRowsByCountry.entrySet()) { + String countryCode = entry.getKey(); + if (countryCode == null || countryCode.isBlank()) { + continue; + } + Map minimumPriceByAsin = new LinkedHashMap<>(); + List> rows = entry.getValue(); + if (rows != null) { + for (Map row : rows) { + if (row == null || row.isEmpty()) { + continue; + } + String asin = normalizeCellText(row.get("asin")).toUpperCase(Locale.ROOT); + if (asin.isBlank()) { + continue; + } + String minimumPrice = normalizeCellText(row.get("minimumPrice")); + minimumPriceByAsin.put(asin, minimumPrice); + } + } + out.put(countryCode, minimumPriceByAsin); + } + return out; + } + private String resolveCountryCode(String sheetName, List countryCodes, boolean singleSheetFallback) { String normalized = normalizeHeaderText(sheetName).toUpperCase(Locale.ROOT); for (ProductRiskCountryCode code : ProductRiskCountryCode.values()) { @@ -832,7 +932,7 @@ public class PriceTrackTaskService { } private void mergeQueueFieldsFromRequest(PriceTrackResultItemVo vo, Long taskId) { - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || task.getRequestJson() == null || task.getRequestJson().isBlank()) return; try { Map payload = objectMapper.readValue(task.getRequestJson(), new TypeReference>() {}); diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/controller/ProductRiskResolveController.java b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/controller/ProductRiskResolveController.java index dad10af..3a9151d 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/controller/ProductRiskResolveController.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/controller/ProductRiskResolveController.java @@ -229,7 +229,10 @@ public class ProductRiskResolveController { } """) })) - @Valid @RequestBody ProductRiskSubmitResultRequest request) { + @Valid @RequestBody ProductRiskSubmitResultRequest request, + jakarta.servlet.http.HttpServletResponse response) { + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); + response.setContentType("application/json;charset=UTF-8"); productRiskTaskService.submitResult(taskId, request); return ApiResponse.success(null); } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/service/ProductRiskTaskCacheService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/service/ProductRiskTaskCacheService.java index c509033..aac342b 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/service/ProductRiskTaskCacheService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/service/ProductRiskTaskCacheService.java @@ -2,23 +2,29 @@ package com.nanri.aiimage.modules.productrisk.service; import com.fasterxml.jackson.databind.ObjectMapper; import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.config.TaskPressureProperties; import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskShopPayloadDto; +import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import java.time.Duration; import java.time.Instant; +import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; @Service @RequiredArgsConstructor public class ProductRiskTaskCacheService { private static final long PAYLOAD_TTL_HOURS = 24; - private final StringRedisTemplate stringRedisTemplate; private final ObjectMapper objectMapper; + private final TaskPressureProperties taskPressureProperties; + private final ConcurrentHashMap taskEntityLocalCache = new ConcurrentHashMap<>(); public ProductRiskShopPayloadDto getShopMergedPayload(Long taskId, String shopKey) { if (taskId == null || taskId <= 0 || shopKey == null || shopKey.isBlank()) { @@ -109,8 +115,72 @@ public class ProductRiskTaskCacheService { if (taskId == null || taskId <= 0) { return; } + taskEntityLocalCache.remove(taskId); stringRedisTemplate.delete(buildShopPayloadKey(taskId)); stringRedisTemplate.delete(buildTaskHeartbeatKey(taskId)); + stringRedisTemplate.delete(buildTaskEntityKey(taskId)); + } + + public void saveTaskCache(FileTaskEntity task) { + if (task == null || task.getId() == null) { + return; + } + long now = System.currentTimeMillis(); + taskEntityLocalCache.put(task.getId(), new LocalTaskEntityCacheEntry( + now, + objectMapper.convertValue(task, FileTaskEntity.class) + )); + try { + stringRedisTemplate.opsForValue().set( + buildTaskEntityKey(task.getId()), + objectMapper.writeValueAsString(task), + Duration.ofHours(PAYLOAD_TTL_HOURS) + ); + } catch (Exception ignored) { + } + } + + public Map getTaskCacheBatch(java.util.List taskIds) { + Map result = new LinkedHashMap<>(); + if (taskIds == null || taskIds.isEmpty()) { + return result; + } + java.util.List normalized = taskIds.stream() + .filter(id -> id != null && id > 0) + .distinct() + .toList(); + if (normalized.isEmpty()) { + return result; + } + long now = System.currentTimeMillis(); + java.util.List missingIds = new ArrayList<>(); + for (Long taskId : normalized) { + LocalTaskEntityCacheEntry cached = taskEntityLocalCache.get(taskId); + if (isLocalCacheFresh(cached, now)) { + result.put(taskId, objectMapper.convertValue(cached.task(), FileTaskEntity.class)); + } else { + missingIds.add(taskId); + } + } + if (missingIds.isEmpty()) { + return result; + } + java.util.List keys = missingIds.stream().map(this::buildTaskEntityKey).toList(); + java.util.List values = stringRedisTemplate.opsForValue().multiGet(keys); + for (int i = 0; i < missingIds.size(); i++) { + Long taskId = missingIds.get(i); + String val = values != null && i < values.size() ? values.get(i) : null; + if (val == null || val.isBlank()) { + continue; + } + try { + FileTaskEntity task = objectMapper.readValue(val, FileTaskEntity.class); + result.put(taskId, task); + taskEntityLocalCache.put(taskId, new LocalTaskEntityCacheEntry(now, task)); + } catch (Exception ignored) { + } + } + return result; } private String buildShopPayloadKey(Long taskId) { @@ -127,4 +197,15 @@ public class ProductRiskTaskCacheService { private String buildTaskHeartbeatKey(Long taskId) { return "product-risk:task:heartbeat:" + taskId; } + + private String buildTaskEntityKey(Long taskId) { + return "product-risk:task:entity:" + taskId; + } + + private boolean isLocalCacheFresh(LocalTaskEntityCacheEntry cached, long now) { + return cached != null + && now - cached.cachedAtMillis() <= Math.max(0L, taskPressureProperties.getLocalTaskEntityCacheMillis()); + } + + private record LocalTaskEntityCacheEntry(long cachedAtMillis, FileTaskEntity task) {} } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/service/ProductRiskTaskService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/service/ProductRiskTaskService.java index 837fd9f..a7cf6d5 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/service/ProductRiskTaskService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/service/ProductRiskTaskService.java @@ -3,6 +3,7 @@ package com.nanri.aiimage.modules.productrisk.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.fasterxml.jackson.databind.ObjectMapper; import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.config.TaskPressureProperties; import com.nanri.aiimage.modules.file.service.oss.OssStorageService; import com.nanri.aiimage.modules.productrisk.mapper.ProductRiskShopCandidateMapper; import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCreateTaskRequest; @@ -57,6 +58,62 @@ public class ProductRiskTaskService { private final OssStorageService ossStorageService; private final ObjectMapper objectMapper; private final ProductRiskTaskCacheService productRiskTaskCacheService; + private final TaskPressureProperties taskPressureProperties; + + private FileTaskEntity loadTaskForExecution(Long taskId) { + Map cachedTasks = productRiskTaskCacheService.getTaskCacheBatch(List.of(taskId)); + FileTaskEntity cached = cachedTasks.get(taskId); + if (cached != null) { + return cached; + } + FileTaskEntity dbTask = fileTaskMapper.selectById(taskId); + if (dbTask != null && MODULE_TYPE.equals(dbTask.getModuleType())) { + productRiskTaskCacheService.saveTaskCache(dbTask); + } + return dbTask; + } + + private Map loadTaskMapByIds(List taskIds) { + Map result = new LinkedHashMap<>(); + if (taskIds == null || taskIds.isEmpty()) { + return result; + } + List normalizedTaskIds = taskIds.stream() + .filter(taskId -> taskId != null && taskId > 0) + .distinct() + .toList(); + if (normalizedTaskIds.isEmpty()) { + return result; + } + Map cachedTasks = productRiskTaskCacheService.getTaskCacheBatch(normalizedTaskIds); + result.putAll(cachedTasks); + List missingTaskIds = normalizedTaskIds.stream() + .filter(taskId -> !cachedTasks.containsKey(taskId)) + .toList(); + for (FileTaskEntity dbTask : selectTasksByIdsInBatches(missingTaskIds)) { + if (dbTask == null || !MODULE_TYPE.equals(dbTask.getModuleType())) { + continue; + } + result.put(dbTask.getId(), dbTask); + if ("RUNNING".equals(dbTask.getStatus())) { + productRiskTaskCacheService.saveTaskCache(dbTask); + } + } + return result; + } + + private List selectTasksByIdsInBatches(List taskIds) { + List tasks = new ArrayList<>(); + if (taskIds == null || taskIds.isEmpty()) { + return tasks; + } + int batchSize = Math.max(1, taskPressureProperties.getDbSelectBatchSize()); + for (int start = 0; start < taskIds.size(); start += batchSize) { + int end = Math.min(start + batchSize, taskIds.size()); + tasks.addAll(fileTaskMapper.selectBatchIds(taskIds.subList(start, end))); + } + return tasks; + } public ProductRiskDashboardVo dashboard(Long userId) { if (userId == null || userId <= 0) { @@ -100,7 +157,7 @@ public class ProductRiskTaskService { .distinct() .toList(); if (!taskIds.isEmpty()) { - List tasks = fileTaskMapper.selectBatchIds(taskIds); + List tasks = selectTasksByIdsInBatches(taskIds); for (FileTaskEntity t : tasks) { if (t != null) { statusByTaskId.put(t.getId(), t.getStatus()); @@ -139,7 +196,7 @@ public class ProductRiskTaskService { if (userId == null || userId <= 0) { throw new BusinessException("user_id 不合法"); } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType()) || !userId.equals(task.getUserId())) { throw new BusinessException("任务不存在"); } @@ -178,7 +235,7 @@ public class ProductRiskTaskService { if (fr.getTaskId() == null) { continue; } - FileTaskEntity t = fileTaskMapper.selectById(fr.getTaskId()); + FileTaskEntity t = loadTaskForExecution(fr.getTaskId()); if (t == null || !MODULE_TYPE.equals(t.getModuleType()) || !userId.equals(t.getUserId())) { continue; } @@ -198,7 +255,7 @@ public class ProductRiskTaskService { * 删除一条 file_result 后重算父任务状态;若无剩余结果则删除任务。 */ private void reconcileTaskAfterResultRemoval(Long taskId) { - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { return; } @@ -270,12 +327,13 @@ public class ProductRiskTaskService { if (taskIds == null || taskIds.isEmpty()) { return batch; } + Map taskMap = loadTaskMapByIds(taskIds); for (Long taskId : taskIds) { if (taskId == null || taskId <= 0) { continue; } - FileTaskEntity task = fileTaskMapper.selectById(taskId); - if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + FileTaskEntity task = taskMap.get(taskId); + if (task == null) { batch.getMissingTaskIds().add(taskId); continue; } @@ -289,12 +347,13 @@ public class ProductRiskTaskService { if (taskIds == null || taskIds.isEmpty()) { return batch; } + Map taskMap = loadTaskMapByIds(taskIds); for (Long taskId : taskIds) { if (taskId == null || taskId <= 0) { continue; } - FileTaskEntity task = fileTaskMapper.selectById(taskId); - if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + FileTaskEntity task = taskMap.get(taskId); + if (task == null) { batch.getMissingTaskIds().add(taskId); continue; } @@ -359,6 +418,7 @@ public class ProductRiskTaskService { task.setCreatedAt(LocalDateTime.now()); task.setUpdatedAt(LocalDateTime.now()); fileTaskMapper.insert(task); + productRiskTaskCacheService.saveTaskCache(task); productRiskTaskCacheService.touchTaskHeartbeat(task.getId()); List snapshot = new ArrayList<>(); @@ -405,7 +465,7 @@ public class ProductRiskTaskService { throw new BusinessException("shops 不能为空"); } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { throw new BusinessException("任务不存在"); } @@ -566,7 +626,7 @@ public class ProductRiskTaskService { if (taskId == null || taskId <= 0) { return false; } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { return false; } @@ -861,7 +921,7 @@ public class ProductRiskTaskService { } private void mergeQueueFieldsFromRequest(ProductRiskResultItemVo vo, Long taskId) { - FileTaskEntity t = fileTaskMapper.selectById(taskId); + FileTaskEntity t = loadTaskForExecution(taskId); if (t == null || t.getRequestJson() == null || t.getRequestJson().isBlank()) { return; } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/mapper/ShopManageGroupMemberMapper.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/mapper/ShopManageGroupMemberMapper.java new file mode 100644 index 0000000..5802616 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/mapper/ShopManageGroupMemberMapper.java @@ -0,0 +1,9 @@ +package com.nanri.aiimage.modules.shopkey.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.nanri.aiimage.modules.shopkey.model.entity.ShopManageGroupMemberEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ShopManageGroupMemberMapper extends BaseMapper { +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/dto/ShopManageGroupCreateRequest.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/dto/ShopManageGroupCreateRequest.java index 236cba7..3db5c4d 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/dto/ShopManageGroupCreateRequest.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/dto/ShopManageGroupCreateRequest.java @@ -5,6 +5,8 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.Data; +import java.util.List; + @Data public class ShopManageGroupCreateRequest { @@ -12,9 +14,8 @@ public class ShopManageGroupCreateRequest { @NotBlank(message = "分组名称不能为空") private String groupName; - @Schema(description = "关联用户ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "关联用户不能为空") - private Long userId; + @Schema(description = "组员用户ID列表") + private List memberUserIds; @Schema(description = "创建人用户ID,由后台代理透传", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "创建人不能为空") diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/dto/ShopManageGroupUpdateRequest.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/dto/ShopManageGroupUpdateRequest.java index cfa0f92..4dcf6c9 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/dto/ShopManageGroupUpdateRequest.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/dto/ShopManageGroupUpdateRequest.java @@ -2,9 +2,10 @@ package com.nanri.aiimage.modules.shopkey.model.dto; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; import lombok.Data; +import java.util.List; + @Data public class ShopManageGroupUpdateRequest { @@ -12,7 +13,6 @@ public class ShopManageGroupUpdateRequest { @NotBlank(message = "分组名称不能为空") private String groupName; - @Schema(description = "关联用户ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "关联用户不能为空") - private Long userId; + @Schema(description = "组员用户ID列表") + private List memberUserIds; } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/entity/ShopManageGroupMemberEntity.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/entity/ShopManageGroupMemberEntity.java new file mode 100644 index 0000000..c22fccb --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/entity/ShopManageGroupMemberEntity.java @@ -0,0 +1,26 @@ +package com.nanri.aiimage.modules.shopkey.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@TableName("biz_shop_manage_group_member") +public class ShopManageGroupMemberEntity { + + @TableId(type = IdType.AUTO) + private Long id; + + @TableField("group_id") + private Long groupId; + + @TableField("user_id") + private Long userId; + + private LocalDateTime createdAt; + private LocalDateTime updatedAt; +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/vo/ShopManageGroupItemVo.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/vo/ShopManageGroupItemVo.java index 3f6de7f..0d2aa0e 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/vo/ShopManageGroupItemVo.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/model/vo/ShopManageGroupItemVo.java @@ -3,11 +3,17 @@ package com.nanri.aiimage.modules.shopkey.model.vo; import lombok.Data; import java.time.LocalDateTime; +import java.util.List; @Data public class ShopManageGroupItemVo { private Long id; private String groupName; + private Long leaderUserId; + private String leaderUsername; + private List memberUserIds; + private List memberUsernames; + private Integer memberCount; private Long userId; private String username; private LocalDateTime createdAt; diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/service/ShopManageGroupService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/service/ShopManageGroupService.java index b18f70d..7aae45f 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/service/ShopManageGroupService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopkey/service/ShopManageGroupService.java @@ -5,26 +5,37 @@ import com.nanri.aiimage.common.exception.BusinessException; import com.nanri.aiimage.modules.permission.mapper.AdminUserMapper; import com.nanri.aiimage.modules.permission.model.entity.AdminUserEntity; import com.nanri.aiimage.modules.shopkey.mapper.ShopManageGroupMapper; +import com.nanri.aiimage.modules.shopkey.mapper.ShopManageGroupMemberMapper; import com.nanri.aiimage.modules.shopkey.mapper.ShopManageMapper; +import com.nanri.aiimage.modules.shopkey.mapper.SkipPriceAsinMapper; import com.nanri.aiimage.modules.shopkey.model.dto.ShopManageGroupCreateRequest; import com.nanri.aiimage.modules.shopkey.model.dto.ShopManageGroupUpdateRequest; import com.nanri.aiimage.modules.shopkey.model.entity.ShopManageEntity; import com.nanri.aiimage.modules.shopkey.model.entity.ShopManageGroupEntity; +import com.nanri.aiimage.modules.shopkey.model.entity.ShopManageGroupMemberEntity; +import com.nanri.aiimage.modules.shopkey.model.entity.SkipPriceAsinEntity; import com.nanri.aiimage.modules.shopkey.model.vo.ShopManageGroupItemVo; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class ShopManageGroupService { private final ShopManageGroupMapper groupMapper; + private final ShopManageGroupMemberMapper groupMemberMapper; private final ShopManageMapper shopManageMapper; + private final SkipPriceAsinMapper skipPriceAsinMapper; private final AdminUserMapper adminUserMapper; public List list() { @@ -32,28 +43,22 @@ public class ShopManageGroupService { } public List list(Long createdById) { - return groupMapper.selectList(new LambdaQueryWrapper() - .eq(createdById != null && createdById > 0, ShopManageGroupEntity::getCreatedById, createdById) - .orderByAsc(ShopManageGroupEntity::getId)) - .stream() - .map(this::toVo) - .toList(); + return toVoList(groupMapper.selectList(new LambdaQueryWrapper() + .eq(createdById != null && createdById > 0, ShopManageGroupEntity::getCreatedById, createdById) + .orderByAsc(ShopManageGroupEntity::getId))); } public List listAccessible(Long operatorId, boolean superAdmin) { if (superAdmin) { return list(); } - Long normalizedOperatorId = normalizePositiveId(operatorId, "操作人不能为空"); - return groupMapper.selectList(new LambdaQueryWrapper() - .and(wrapper -> wrapper - .eq(ShopManageGroupEntity::getCreatedById, normalizedOperatorId) - .or() - .eq(ShopManageGroupEntity::getUserId, normalizedOperatorId)) - .orderByAsc(ShopManageGroupEntity::getId)) - .stream() - .map(this::toVo) - .toList(); + Set groupIds = listAccessibleGroupIds(operatorId, false); + if (groupIds.isEmpty()) { + return List.of(); + } + return toVoList(groupMapper.selectList(new LambdaQueryWrapper() + .in(ShopManageGroupEntity::getId, groupIds) + .orderByAsc(ShopManageGroupEntity::getId))); } public Set listAccessibleGroupIds(Long operatorId, boolean superAdmin) { @@ -63,69 +68,80 @@ public class ShopManageGroupService { .stream() .map(ShopManageGroupEntity::getId) .filter(id -> id != null && id > 0) - .collect(java.util.stream.Collectors.toCollection(LinkedHashSet::new)); + .collect(Collectors.toCollection(LinkedHashSet::new)); } Long normalizedOperatorId = normalizePositiveId(operatorId, "操作人不能为空"); - return groupMapper.selectList(new LambdaQueryWrapper() + LinkedHashSet groupIds = groupMapper.selectList(new LambdaQueryWrapper() .select(ShopManageGroupEntity::getId) - .and(wrapper -> wrapper - .eq(ShopManageGroupEntity::getCreatedById, normalizedOperatorId) - .or() - .eq(ShopManageGroupEntity::getUserId, normalizedOperatorId))) + .eq(ShopManageGroupEntity::getCreatedById, normalizedOperatorId)) .stream() .map(ShopManageGroupEntity::getId) .filter(id -> id != null && id > 0) - .collect(java.util.stream.Collectors.toCollection(LinkedHashSet::new)); + .collect(Collectors.toCollection(LinkedHashSet::new)); + groupIds.addAll(groupMemberMapper.selectList(new LambdaQueryWrapper() + .select(ShopManageGroupMemberEntity::getGroupId) + .eq(ShopManageGroupMemberEntity::getUserId, normalizedOperatorId)) + .stream() + .map(ShopManageGroupMemberEntity::getGroupId) + .filter(id -> id != null && id > 0) + .collect(Collectors.toCollection(LinkedHashSet::new))); + return groupIds; } @Transactional public ShopManageGroupItemVo create(ShopManageGroupCreateRequest request, Long operatorId, boolean superAdmin) { Long createdById = normalizePositiveId(request.getCreatedById(), "创建人不能为空"); - AdminUserEntity bindUser = getBindableUser(request.getUserId(), operatorId, superAdmin); + validateLeaderOperator(createdById, operatorId, superAdmin); String groupName = normalizeRequired(request.getGroupName(), "分组名称不能为空"); - ensureGroupNameMatchesUser(groupName, bindUser); ensureGroupNameUnique(groupName, null); - ensureUserUnique(request.getUserId(), null); ShopManageGroupEntity entity = new ShopManageGroupEntity(); entity.setGroupName(groupName); - entity.setUserId(bindUser.getId()); entity.setCreatedById(createdById); groupMapper.insert(entity); + replaceMembers(entity.getId(), request.getMemberUserIds(), createdById, operatorId, superAdmin); return toVo(getById(entity.getId())); } @Transactional public ShopManageGroupItemVo update(Long id, Long operatorId, boolean superAdmin, ShopManageGroupUpdateRequest request) { - ShopManageGroupEntity entity = getById(id); - validateOwnership(entity, operatorId, superAdmin); - AdminUserEntity bindUser = getBindableUser(request.getUserId(), operatorId, superAdmin); + ShopManageGroupEntity entity = getManageableById(id, operatorId, superAdmin); String groupName = normalizeRequired(request.getGroupName(), "分组名称不能为空"); - ensureGroupNameMatchesUser(groupName, bindUser); ensureGroupNameUnique(groupName, id); - ensureUserUnique(bindUser.getId(), id); entity.setGroupName(groupName); - entity.setUserId(bindUser.getId()); groupMapper.updateById(entity); + replaceMembers(entity.getId(), request.getMemberUserIds(), entity.getCreatedById(), operatorId, superAdmin); return toVo(getById(id)); } @Transactional public void delete(Long id, Long operatorId, boolean superAdmin) { - ShopManageGroupEntity entity = getById(id); - validateOwnership(entity, operatorId, superAdmin); + ShopManageGroupEntity entity = getManageableById(id, operatorId, superAdmin); Long useCount = shopManageMapper.selectCount(new LambdaQueryWrapper() .eq(ShopManageEntity::getGroupId, entity.getId())); if (useCount != null && useCount > 0) { throw new BusinessException("该分组下存在店铺,无法删除"); } + Long skipPriceAsinCount = skipPriceAsinMapper.selectCount(new LambdaQueryWrapper() + .eq(SkipPriceAsinEntity::getGroupId, entity.getId())); + if (skipPriceAsinCount != null && skipPriceAsinCount > 0) { + throw new BusinessException("该分组下存在跳过跟价 ASIN,无法删除"); + } + groupMemberMapper.delete(new LambdaQueryWrapper() + .eq(ShopManageGroupMemberEntity::getGroupId, entity.getId())); groupMapper.deleteById(entity.getId()); } public ShopManageGroupEntity getAccessibleById(Long id, Long operatorId, boolean superAdmin) { ShopManageGroupEntity entity = getById(id); - validateOwnership(entity, operatorId, superAdmin); + validateAccess(entity, operatorId, superAdmin); + return entity; + } + + public ShopManageGroupEntity getManageableById(Long id, Long operatorId, boolean superAdmin) { + ShopManageGroupEntity entity = getById(id); + validateManageAccess(entity, operatorId, superAdmin); return entity; } @@ -149,56 +165,105 @@ public class ShopManageGroupService { } } - private void ensureUserUnique(Long userId, Long excludeId) { - LambdaQueryWrapper query = new LambdaQueryWrapper() - .eq(ShopManageGroupEntity::getUserId, userId); - if (excludeId != null) { - query.ne(ShopManageGroupEntity::getId, excludeId); - } - Long count = groupMapper.selectCount(query); - if (count != null && count > 0) { - throw new BusinessException("该用户已绑定分组"); - } - } - - private void ensureGroupNameMatchesUser(String groupName, AdminUserEntity bindUser) { - if (bindUser == null || bindUser.getUsername() == null || !groupName.equals(bindUser.getUsername().trim())) { - throw new BusinessException("分组名称必须与关联用户名一致"); - } - } - - private void validateOwnership(ShopManageGroupEntity entity, Long operatorId, boolean superAdmin) { + private void validateAccess(ShopManageGroupEntity entity, Long operatorId, boolean superAdmin) { if (superAdmin) { return; } Long normalizedOperatorId = normalizePositiveId(operatorId, "操作人不能为空"); boolean createdBySelf = entity.getCreatedById() != null && entity.getCreatedById().equals(normalizedOperatorId); - boolean boundToSelf = entity.getUserId() != null && entity.getUserId().equals(normalizedOperatorId); - if (!createdBySelf && !boundToSelf) { + boolean memberOfGroup = isGroupMember(entity.getId(), normalizedOperatorId); + if (!createdBySelf && !memberOfGroup) { throw new BusinessException("只能操作自己有权限的分组数据"); } } - private AdminUserEntity getBindableUser(Long userId, Long operatorId, boolean superAdmin) { - Long normalizedUserId = normalizePositiveId(userId, "关联用户不能为空"); - AdminUserEntity user = adminUserMapper.selectById(normalizedUserId); - if (user == null) { - throw new BusinessException("关联用户不存在"); - } + private void validateManageAccess(ShopManageGroupEntity entity, Long operatorId, boolean superAdmin) { if (superAdmin) { - return user; + return; } Long normalizedOperatorId = normalizePositiveId(operatorId, "操作人不能为空"); - boolean self = user.getId() != null && user.getId().equals(normalizedOperatorId); - boolean createdBySelf = user.getCreatedById() != null && user.getCreatedById().equals(normalizedOperatorId); - if (!self && !createdBySelf) { - throw new BusinessException("只能关联自己可见的用户"); + boolean createdBySelf = entity.getCreatedById() != null && entity.getCreatedById().equals(normalizedOperatorId); + if (!createdBySelf) { + throw new BusinessException("只有组长才能维护分组"); } - return user; + } + + private void validateLeaderOperator(Long leaderId, Long operatorId, boolean superAdmin) { + if (superAdmin) { + return; + } + Long normalizedOperatorId = normalizePositiveId(operatorId, "操作人不能为空"); + if (!normalizedOperatorId.equals(leaderId)) { + throw new BusinessException("普通管理员只能创建自己作为组长的分组"); + } + } + + private boolean isGroupMember(Long groupId, Long userId) { + if (groupId == null || userId == null || groupId <= 0 || userId <= 0) { + return false; + } + Long count = groupMemberMapper.selectCount(new LambdaQueryWrapper() + .eq(ShopManageGroupMemberEntity::getGroupId, groupId) + .eq(ShopManageGroupMemberEntity::getUserId, userId)); + return count != null && count > 0; + } + + private void replaceMembers(Long groupId, List memberUserIds, Long leaderId, Long operatorId, boolean superAdmin) { + List members = resolveMembers(memberUserIds, leaderId, operatorId, superAdmin, groupId); + groupMemberMapper.delete(new LambdaQueryWrapper() + .eq(ShopManageGroupMemberEntity::getGroupId, groupId)); + for (AdminUserEntity member : members) { + ShopManageGroupMemberEntity entity = new ShopManageGroupMemberEntity(); + entity.setGroupId(groupId); + entity.setUserId(member.getId()); + groupMemberMapper.insert(entity); + } + } + + private List resolveMembers(List memberUserIds, Long leaderId, Long operatorId, + boolean superAdmin, Long currentGroupId) { + validateLeaderOperator(leaderId, operatorId, superAdmin); + if (memberUserIds == null || memberUserIds.isEmpty()) { + return List.of(); + } + AdminUserEntity operatorUser = operatorId == null ? null : adminUserMapper.selectById(operatorId); + boolean operatorCanBindAllNormals = superAdmin + || (operatorUser != null && "admin".equalsIgnoreCase(normalizeBlank(operatorUser.getUsername()))); + LinkedHashSet uniqueIds = new LinkedHashSet<>(); + for (Long memberUserId : memberUserIds) { + uniqueIds.add(normalizePositiveId(memberUserId, "组员用户不能为空")); + } + List members = new ArrayList<>(); + for (Long memberUserId : uniqueIds) { + AdminUserEntity user = adminUserMapper.selectById(memberUserId); + if (user == null) { + throw new BusinessException("组员用户不存在"); + } + if (leaderId != null && leaderId.equals(user.getId())) { + throw new BusinessException("组长不能作为组员重复加入分组"); + } + if (!superAdmin && !"normal".equals(normalizeBlank(user.getRole()))) { + throw new BusinessException("只能绑定普通员工账号"); + } + if (!operatorCanBindAllNormals && (user.getCreatedById() == null || !user.getCreatedById().equals(leaderId))) { + throw new BusinessException("只能添加组长自己创建的普通员工账号"); + } + LambdaQueryWrapper query = new LambdaQueryWrapper() + .eq(ShopManageGroupMemberEntity::getUserId, user.getId()); + if (currentGroupId != null) { + query.ne(ShopManageGroupMemberEntity::getGroupId, currentGroupId); + } + Long count = groupMemberMapper.selectCount(query); + if (count != null && count > 0) { + throw new BusinessException("该普通员工账号已加入其他分组"); + } + members.add(user); + } + return members; } private String normalizeRequired(String value, String message) { - String normalized = value == null ? "" : value.trim(); + String normalized = normalizeBlank(value); if (normalized.isEmpty()) { throw new BusinessException(message); } @@ -212,15 +277,82 @@ public class ShopManageGroupService { return value; } + private String normalizeBlank(String value) { + return value == null ? "" : value.trim(); + } + private ShopManageGroupItemVo toVo(ShopManageGroupEntity entity) { - ShopManageGroupItemVo vo = new ShopManageGroupItemVo(); - vo.setId(entity.getId()); - vo.setGroupName(entity.getGroupName()); - vo.setUserId(entity.getUserId()); - AdminUserEntity bindUser = entity.getUserId() == null ? null : adminUserMapper.selectById(entity.getUserId()); - vo.setUsername(bindUser == null ? "" : (bindUser.getUsername() == null ? "" : bindUser.getUsername())); - vo.setCreatedAt(entity.getCreatedAt()); - vo.setUpdatedAt(entity.getUpdatedAt()); - return vo; + return toVoList(List.of(entity)).stream().findFirst().orElseThrow(); + } + + private List toVoList(List groups) { + if (groups == null || groups.isEmpty()) { + return List.of(); + } + + List groupIds = groups.stream() + .map(ShopManageGroupEntity::getId) + .filter(id -> id != null && id > 0) + .toList(); + Map> membersByGroupId = groupIds.isEmpty() + ? Map.of() + : groupMemberMapper.selectList(new LambdaQueryWrapper() + .in(ShopManageGroupMemberEntity::getGroupId, groupIds) + .orderByAsc(ShopManageGroupMemberEntity::getId)) + .stream() + .collect(Collectors.groupingBy( + ShopManageGroupMemberEntity::getGroupId, + LinkedHashMap::new, + Collectors.toList())); + + LinkedHashSet userIds = new LinkedHashSet<>(); + for (ShopManageGroupEntity group : groups) { + if (group.getCreatedById() != null && group.getCreatedById() > 0) { + userIds.add(group.getCreatedById()); + } + } + for (List members : membersByGroupId.values()) { + for (ShopManageGroupMemberEntity member : members) { + if (member.getUserId() != null && member.getUserId() > 0) { + userIds.add(member.getUserId()); + } + } + } + + Map userById = userIds.isEmpty() + ? Map.of() + : adminUserMapper.selectBatchIds(userIds).stream() + .filter(user -> user.getId() != null) + .collect(Collectors.toMap(AdminUserEntity::getId, user -> user, (left, right) -> left, LinkedHashMap::new)); + + List result = new ArrayList<>(); + for (ShopManageGroupEntity entity : groups) { + ShopManageGroupItemVo vo = new ShopManageGroupItemVo(); + vo.setId(entity.getId()); + vo.setGroupName(entity.getGroupName()); + vo.setLeaderUserId(entity.getCreatedById()); + AdminUserEntity leaderUser = entity.getCreatedById() == null ? null : userById.get(entity.getCreatedById()); + vo.setLeaderUsername(leaderUser == null ? "" : normalizeBlank(leaderUser.getUsername())); + + List memberEntities = membersByGroupId.getOrDefault(entity.getId(), Collections.emptyList()); + List memberUserIds = memberEntities.stream() + .map(ShopManageGroupMemberEntity::getUserId) + .filter(id -> id != null && id > 0) + .toList(); + List memberUsernames = memberUserIds.stream() + .map(userById::get) + .map(user -> user == null ? "" : normalizeBlank(user.getUsername())) + .toList(); + + vo.setMemberUserIds(memberUserIds); + vo.setMemberUsernames(memberUsernames); + vo.setMemberCount(memberUserIds.size()); + vo.setUserId(memberUserIds.isEmpty() ? null : memberUserIds.get(0)); + vo.setUsername(memberUsernames.isEmpty() ? "" : memberUsernames.get(0)); + vo.setCreatedAt(entity.getCreatedAt()); + vo.setUpdatedAt(entity.getUpdatedAt()); + result.add(vo); + } + return result; } } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/controller/ShopMatchController.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/controller/ShopMatchController.java index afd9300..3d43e77 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/controller/ShopMatchController.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/controller/ShopMatchController.java @@ -173,7 +173,10 @@ public class ShopMatchController { @Operation(summary = "提交匹配结果", description = "Python 可多次分批回传结果;后端会组装文件并在超时场景自动补偿收尾。") public ApiResponse submitResult( @Parameter(description = "任务主键", example = "200") @PathVariable Long taskId, - @Valid @RequestBody ShopMatchSubmitResultRequest request) { + @Valid @RequestBody ShopMatchSubmitResultRequest request, + jakarta.servlet.http.HttpServletResponse response) { + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); + response.setContentType("application/json;charset=UTF-8"); shopMatchTaskService.submitResult(taskId, request); return ApiResponse.success(null); } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskCacheService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskCacheService.java index 1f98db7..9925eae 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskCacheService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskCacheService.java @@ -2,7 +2,9 @@ package com.nanri.aiimage.modules.shopmatch.service; import com.fasterxml.jackson.databind.ObjectMapper; import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.config.TaskPressureProperties; import com.nanri.aiimage.modules.shopmatch.model.dto.ShopMatchShopPayloadDto; +import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -14,10 +16,12 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.security.MessageDigest; import java.time.Duration; +import java.util.ArrayList; import java.util.Comparator; import java.util.HexFormat; import java.util.LinkedHashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; @Service @RequiredArgsConstructor @@ -25,8 +29,9 @@ import java.util.Map; public class ShopMatchTaskCacheService { private static final long PAYLOAD_TTL_HOURS = 24; - private final ObjectMapper objectMapper; + private final TaskPressureProperties taskPressureProperties; + private final ConcurrentHashMap taskEntityLocalCache = new ConcurrentHashMap<>(); public ShopMatchShopPayloadDto getShopMergedPayload(Long taskId, String shopKey) { if (taskId == null || taskId <= 0 || shopKey == null || shopKey.isBlank()) { @@ -127,9 +132,11 @@ public class ShopMatchTaskCacheService { if (taskId == null || taskId <= 0) { return; } + taskEntityLocalCache.remove(taskId); try { Path taskDir = buildTaskDir(taskId); if (!Files.exists(taskDir)) { + Files.deleteIfExists(buildTaskEntityFile(taskId)); return; } try (var walk = Files.walk(taskDir)) { @@ -145,6 +152,69 @@ public class ShopMatchTaskCacheService { } catch (Exception ex) { log.warn("[shop-match] delete task cache failed taskId={} msg={}", taskId, ex.getMessage()); } + try { + Files.deleteIfExists(buildTaskEntityFile(taskId)); + } catch (IOException ignored) { + } + } + + public void saveTaskCache(FileTaskEntity task) { + if (task == null || task.getId() == null) { + return; + } + long now = System.currentTimeMillis(); + taskEntityLocalCache.put(task.getId(), new LocalTaskEntityCacheEntry( + now, + objectMapper.convertValue(task, FileTaskEntity.class) + )); + try { + Files.createDirectories(buildTaskDir(task.getId())); + Files.writeString( + buildTaskEntityFile(task.getId()), + objectMapper.writeValueAsString(task), + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING, + StandardOpenOption.WRITE + ); + } catch (Exception ignored) { + } + } + + public Map getTaskCacheBatch(java.util.List taskIds) { + Map result = new LinkedHashMap<>(); + if (taskIds == null || taskIds.isEmpty()) { + return result; + } + java.util.List normalized = taskIds.stream() + .filter(id -> id != null && id > 0) + .distinct() + .toList(); + if (normalized.isEmpty()) { + return result; + } + long now = System.currentTimeMillis(); + java.util.List missingIds = new ArrayList<>(); + for (Long taskId : normalized) { + LocalTaskEntityCacheEntry cached = taskEntityLocalCache.get(taskId); + if (isLocalCacheFresh(cached, now)) { + result.put(taskId, objectMapper.convertValue(cached.task(), FileTaskEntity.class)); + } else { + missingIds.add(taskId); + } + } + for (Long taskId : missingIds) { + Path file = buildTaskEntityFile(taskId); + if (!Files.isRegularFile(file)) { + continue; + } + try { + FileTaskEntity task = objectMapper.readValue(Files.readString(file), FileTaskEntity.class); + result.put(taskId, task); + taskEntityLocalCache.put(taskId, new LocalTaskEntityCacheEntry(now, task)); + } catch (Exception ignored) { + } + } + return result; } public Duration getPayloadTtl() { @@ -159,6 +229,10 @@ public class ShopMatchTaskCacheService { return buildTaskDir(taskId).resolve(hashShopKey(shopKey) + ".json"); } + private Path buildTaskEntityFile(Long taskId) { + return buildTaskDir(taskId).resolve("_task-entity.json"); + } + private String hashShopKey(String shopKey) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); @@ -181,4 +255,11 @@ public class ShopMatchTaskCacheService { this.payload = payload; } } + + private boolean isLocalCacheFresh(LocalTaskEntityCacheEntry cached, long now) { + return cached != null + && now - cached.cachedAtMillis() <= Math.max(0L, taskPressureProperties.getLocalTaskEntityCacheMillis()); + } + + private record LocalTaskEntityCacheEntry(long cachedAtMillis, FileTaskEntity task) {} } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskService.java index c308662..1b213c9 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskService.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.IdUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.fasterxml.jackson.databind.ObjectMapper; import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.config.TaskPressureProperties; import com.nanri.aiimage.modules.file.service.oss.OssStorageService; import com.nanri.aiimage.modules.productrisk.model.enums.ProductRiskCountryCode; import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskCreateTaskVo; @@ -60,6 +61,71 @@ public class ShopMatchTaskService { private final OssStorageService ossStorageService; private final ObjectMapper objectMapper; private final ShopMatchTaskCacheService shopMatchTaskCacheService; + private final TaskPressureProperties taskPressureProperties; + + private FileTaskEntity loadTaskForExecution(Long taskId) { + Map cachedTasks = shopMatchTaskCacheService.getTaskCacheBatch(List.of(taskId)); + FileTaskEntity cached = cachedTasks.get(taskId); + if (cached != null) { + if (!MODULE_TYPE.equals(cached.getModuleType()) + || (cached.getRequestJson() != null && !cached.getRequestJson().isBlank())) { + return cached; + } + FileTaskEntity dbTask = fileTaskMapper.selectById(taskId); + if (dbTask != null && MODULE_TYPE.equals(dbTask.getModuleType())) { + shopMatchTaskCacheService.saveTaskCache(dbTask); + return dbTask; + } + return cached; + } + FileTaskEntity dbTask = fileTaskMapper.selectById(taskId); + if (dbTask != null && MODULE_TYPE.equals(dbTask.getModuleType())) { + shopMatchTaskCacheService.saveTaskCache(dbTask); + } + return dbTask; + } + + private Map loadTaskMapByIds(List taskIds) { + Map result = new LinkedHashMap<>(); + if (taskIds == null || taskIds.isEmpty()) { + return result; + } + List normalizedTaskIds = taskIds.stream() + .filter(taskId -> taskId != null && taskId > 0) + .distinct() + .toList(); + if (normalizedTaskIds.isEmpty()) { + return result; + } + Map cachedTasks = shopMatchTaskCacheService.getTaskCacheBatch(normalizedTaskIds); + result.putAll(cachedTasks); + List missingTaskIds = normalizedTaskIds.stream() + .filter(taskId -> !cachedTasks.containsKey(taskId)) + .toList(); + for (FileTaskEntity dbTask : selectTasksByIdsInBatches(missingTaskIds)) { + if (dbTask == null || !MODULE_TYPE.equals(dbTask.getModuleType())) { + continue; + } + result.put(dbTask.getId(), dbTask); + if ("RUNNING".equals(dbTask.getStatus()) || "SCHEDULED".equals(dbTask.getStatus())) { + shopMatchTaskCacheService.saveTaskCache(dbTask); + } + } + return result; + } + + private List selectTasksByIdsInBatches(List taskIds) { + List tasks = new ArrayList<>(); + if (taskIds == null || taskIds.isEmpty()) { + return tasks; + } + int batchSize = Math.max(1, taskPressureProperties.getDbSelectBatchSize()); + for (int start = 0; start < taskIds.size(); start += batchSize) { + int end = Math.min(start + batchSize, taskIds.size()); + tasks.addAll(fileTaskMapper.selectBatchIds(taskIds.subList(start, end))); + } + return tasks; + } public ProductRiskDashboardVo dashboard(Long userId) { if (userId == null || userId <= 0) { @@ -103,7 +169,7 @@ public class ShopMatchTaskService { .distinct() .toList(); if (!taskIds.isEmpty()) { - for (FileTaskEntity task : fileTaskMapper.selectBatchIds(taskIds)) { + for (FileTaskEntity task : selectTasksByIdsInBatches(taskIds)) { if (task != null) { statusByTaskId.put(task.getId(), task.getStatus()); } @@ -138,7 +204,7 @@ public class ShopMatchTaskService { if (userId == null || userId <= 0) { throw new BusinessException("user_id 不合法"); } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType()) || !userId.equals(task.getUserId())) { throw new BusinessException("任务不存在"); } @@ -150,7 +216,7 @@ public class ShopMatchTaskService { } private void reconcileTaskAfterResultRemoval(Long taskId) { - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { return; } @@ -171,12 +237,13 @@ public class ShopMatchTaskService { if (taskIds == null || taskIds.isEmpty()) { return batch; } + Map taskMap = loadTaskMapByIds(taskIds); for (Long taskId : taskIds) { if (taskId == null || taskId <= 0) { continue; } - FileTaskEntity task = fileTaskMapper.selectById(taskId); - if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + FileTaskEntity task = taskMap.get(taskId); + if (task == null) { batch.getMissingTaskIds().add(taskId); continue; } @@ -190,12 +257,13 @@ public class ShopMatchTaskService { if (taskIds == null || taskIds.isEmpty()) { return batch; } + Map taskMap = loadTaskMapByIds(taskIds); for (Long taskId : taskIds) { if (taskId == null || taskId <= 0) { continue; } - FileTaskEntity task = fileTaskMapper.selectById(taskId); - if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + FileTaskEntity task = taskMap.get(taskId); + if (task == null) { batch.getMissingTaskIds().add(taskId); continue; } @@ -270,6 +338,7 @@ public class ShopMatchTaskService { task.setUpdatedAt(now); task.setScheduledAt(scheduleTimes.isEmpty() ? null : scheduleTimes.get(0)); fileTaskMapper.insert(task); + shopMatchTaskCacheService.saveTaskCache(task); List snapshot = new ArrayList<>(); for (ProductRiskShopQueueItemVo item : uniqueItems) { @@ -294,7 +363,7 @@ public class ShopMatchTaskService { } catch (Exception ex) { throw new BusinessException("task 不存在"); } - fileTaskMapper.updateById(task); + updateTaskAndRefreshCache(task); ProductRiskCreateTaskVo vo = new ProductRiskCreateTaskVo(); vo.setTaskId(task.getId()); @@ -313,7 +382,7 @@ public class ShopMatchTaskService { if (stageIndex == null || stageIndex < 0) { throw new BusinessException("stage_index 不合法"); } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType()) || !userId.equals(task.getUserId())) { throw new BusinessException("任务不存在"); } @@ -341,7 +410,7 @@ public class ShopMatchTaskService { task.setStatus("RUNNING"); task.setUpdatedAt(now); persistTaskRequest(task, state); - fileTaskMapper.updateById(task); + updateTaskAndRefreshCache(task); } @Transactional @@ -355,7 +424,7 @@ public class ShopMatchTaskService { if (request == null || request.getStageIndex() == null || request.getStageIndex() < 0) { throw new BusinessException("stage_index 不合法"); } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType()) || !userId.equals(task.getUserId())) { throw new BusinessException("任务不存在"); } @@ -377,7 +446,7 @@ public class ShopMatchTaskService { task.setUpdatedAt(now()); task.setFinishedAt(null); persistTaskRequest(task, state); - fileTaskMapper.updateById(task); + updateTaskAndRefreshCache(task); } @@ -390,7 +459,7 @@ public class ShopMatchTaskService { throw new BusinessException("shops 不能为空"); } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { throw new BusinessException("任务不存在"); } @@ -460,7 +529,7 @@ public class ShopMatchTaskService { if (taskId == null || taskId <= 0) { return false; } - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { return false; } @@ -640,7 +709,7 @@ public class ShopMatchTaskService { } catch (Exception ex) { log.warn("[shop-match] compact result json failed: {}", ex.getMessage()); } - fileTaskMapper.updateById(task); + updateTaskAndRefreshCache(task); if ("SUCCESS".equals(task.getStatus()) || "FAILED".equals(task.getStatus())) { shopMatchTaskCacheService.deleteTaskCache(task.getId()); } @@ -799,12 +868,12 @@ public class ShopMatchTaskService { } private LocalDateTime loadScheduledAt(Long taskId) { - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); return task == null ? null : task.getScheduledAt(); } private void mergeQueueFieldsFromRequest(ProductRiskResultItemVo vo, Long taskId) { - FileTaskEntity task = fileTaskMapper.selectById(taskId); + FileTaskEntity task = loadTaskForExecution(taskId); ShopMatchCreateTaskRequest request = parseTaskRequestSilently(task); if (request == null) { return; @@ -849,7 +918,8 @@ public class ShopMatchTaskService { } try { return objectMapper.readValue(task.getRequestJson(), ShopMatchCreateTaskRequest.class); - } catch (Exception ignored) { + } catch (Exception ex) { + log.warn("[shop-match] parse task request failed taskId={} msg={}", task.getId(), ex.getMessage()); return null; } } @@ -862,6 +932,11 @@ public class ShopMatchTaskService { } } + private void updateTaskAndRefreshCache(FileTaskEntity task) { + fileTaskMapper.updateById(task); + shopMatchTaskCacheService.saveTaskCache(task); + } + private static String fmt(LocalDateTime time) { return time == null ? null : time.toString(); } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/ziniao/service/ZiniaoAuthService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/ziniao/service/ZiniaoAuthService.java index 6b137e3..bc206da 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/ziniao/service/ZiniaoAuthService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/ziniao/service/ZiniaoAuthService.java @@ -142,6 +142,26 @@ public class ZiniaoAuthService { return getOrLoadUserStores(apiKey, companyId, userId); } +public boolean isIpWhitelistError(BusinessException ex) { + String message = ex == null ? null : ex.getMessage(); + if (message == null || message.isBlank()) { + return false; + } + String lowerMessage = message.toLowerCase(); + return message.contains("白名单") + || message.contains("IP白名单") + || message.contains("ip白名单") + || message.contains("当前ip") + || message.contains("当前IP") + || message.contains("禁止当前ip") + || message.contains("禁止当前IP") + || message.contains("禁止访问") + || lowerMessage.contains("whitelist") + || lowerMessage.contains("current ip") + || lowerMessage.contains("forbid") + || lowerMessage.contains("forbidden"); + } + public boolean isInvalidUserStoresError(BusinessException ex) { String message = ex == null ? null : ex.getMessage(); if (message == null || message.isBlank()) { diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/ziniao/service/ZiniaoShopIndexService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/ziniao/service/ZiniaoShopIndexService.java index dad6137..40339bb 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/ziniao/service/ZiniaoShopIndexService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/ziniao/service/ZiniaoShopIndexService.java @@ -190,12 +190,19 @@ public class ZiniaoShopIndexService { try { companyId = ziniaoAuthService.resolveCompanyIdForIndex(apiKey); } catch (BusinessException ex) { + rethrowIfIpWhitelistError(ex); log.warn("[ziniao-index] skip apiKey while resolving companyId, msg={}", ex.getMessage()); continue; } Set invalidUserIds = new LinkedHashSet<>(); - List staff = ziniaoAuthService.getOrLoadStaffForIndex(apiKey, companyId); + List staff; + try { + staff = ziniaoAuthService.getOrLoadStaffForIndex(apiKey, companyId); + } catch (BusinessException ex) { + rethrowIfIpWhitelistError(ex); + throw ex; + } for (Long userId : buildUserIds(staff)) { if (invalidUserIds.contains(userId)) { continue; @@ -204,6 +211,7 @@ public class ZiniaoShopIndexService { try { stores = ziniaoAuthService.getOrLoadUserStoresForIndex(apiKey, companyId, userId); } catch (BusinessException ex) { + rethrowIfIpWhitelistError(ex); if (ziniaoAuthService.isInvalidUserStoresError(ex)) { invalidUserIds.add(userId); allInvalidUserIds.add(userId); @@ -662,4 +670,10 @@ public class ZiniaoShopIndexService { throw new BusinessException("生成紫鸟 apiKey 缓存键失败"); } } + + private void rethrowIfIpWhitelistError(BusinessException ex) { + if (ziniaoAuthService.isIpWhitelistError(ex)) { + throw new BusinessException("紫鸟刷新店铺索引失败:当前服务器 IP 未加入紫鸟白名单,已停止本轮刷新且不会更新索引数据"); + } + } } diff --git a/backend-java/src/main/resources/application.yml b/backend-java/src/main/resources/application.yml index 26247eb..faf0ee3 100644 --- a/backend-java/src/main/resources/application.yml +++ b/backend-java/src/main/resources/application.yml @@ -70,9 +70,11 @@ aiimage: storage: local-temp-dir: ${AIIMAGE_STORAGE_LOCAL_TEMP_DIR:./data/tmp} cleanup-enabled: ${AIIMAGE_STORAGE_CLEANUP_ENABLED:true} - cleanup-cron: ${AIIMAGE_STORAGE_CLEANUP_CRON:0 0 */6 * * *} - source-retention-hours: ${AIIMAGE_STORAGE_SOURCE_RETENTION_HOURS:48} + cleanup-cron: ${AIIMAGE_STORAGE_CLEANUP_CRON:0 0 * * * *} + source-retention-hours: ${AIIMAGE_STORAGE_SOURCE_RETENTION_HOURS:24} result-retention-hours: ${AIIMAGE_STORAGE_RESULT_RETENTION_HOURS:24} + temp-dir: + retention-hours: ${AIIMAGE_TEMP_DIR_RETENTION_HOURS:24} brand-progress: ttl-hours: ${AIIMAGE_BRAND_PROGRESS_TTL_HOURS:24} failed-ttl-hours: ${AIIMAGE_BRAND_PROGRESS_FAILED_TTL_HOURS:2} @@ -88,10 +90,15 @@ aiimage: price-track-initial-timeout-minutes: ${AIIMAGE_PRICE_TRACK_INITIAL_TIMEOUT_MINUTES:20} shop-match-stale-timeout-minutes: ${AIIMAGE_SHOP_MATCH_STALE_TIMEOUT_MINUTES:20} shop-match-initial-timeout-minutes: ${AIIMAGE_SHOP_MATCH_INITIAL_TIMEOUT_MINUTES:20} + patrol-delete-stale-timeout-minutes: ${AIIMAGE_PATROL_DELETE_STALE_TIMEOUT_MINUTES:20} + patrol-delete-initial-timeout-minutes: ${AIIMAGE_PATROL_DELETE_INITIAL_TIMEOUT_MINUTES:20} module-cleanup: enabled: ${AIIMAGE_MODULE_CLEANUP_ENABLED:true} cron: ${AIIMAGE_MODULE_CLEANUP_CRON:0 0 0 * * *} - module-types: ${AIIMAGE_MODULE_CLEANUP_MODULE_TYPES:DEDUPE,SPLIT,CONVERT,DELETE_BRAND,PRODUCT_RISK_RESOLVE,PRICE_TRACK,SHOP_MATCH} + module-types: ${AIIMAGE_MODULE_CLEANUP_MODULE_TYPES:DEDUPE,SPLIT,CONVERT,DELETE_BRAND,PRODUCT_RISK_RESOLVE,PRICE_TRACK,SHOP_MATCH,PATROL_DELETE} + task-pressure: + local-task-entity-cache-millis: ${AIIMAGE_TASK_LOCAL_ENTITY_CACHE_MILLIS:3000} + db-select-batch-size: ${AIIMAGE_TASK_DB_SELECT_BATCH_SIZE:200} security: shop-credential-key: ${AIIMAGE_SHOP_CREDENTIAL_KEY:change-me-shop-credential-key} internal-token: ${AIIMAGE_INTERNAL_TOKEN:} diff --git a/backend-java/src/main/resources/db/V27__patrol_delete_shop_candidate.sql b/backend-java/src/main/resources/db/V27__patrol_delete_shop_candidate.sql new file mode 100644 index 0000000..460cc0c --- /dev/null +++ b/backend-java/src/main/resources/db/V27__patrol_delete_shop_candidate.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS biz_patrol_delete_shop_candidate ( + id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT 'primary key', + user_id BIGINT NOT NULL COMMENT 'user id', + shop_name VARCHAR(255) NOT NULL COMMENT 'normalized shop name', + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'created time', + UNIQUE KEY uk_user_shop (user_id, shop_name), + KEY idx_user_id (user_id) +) COMMENT='patrol delete candidate shops'; diff --git a/backend-java/src/main/resources/db/V28__shop_manage_group_member.sql b/backend-java/src/main/resources/db/V28__shop_manage_group_member.sql new file mode 100644 index 0000000..f10b817 --- /dev/null +++ b/backend-java/src/main/resources/db/V28__shop_manage_group_member.sql @@ -0,0 +1,17 @@ +CREATE TABLE IF NOT EXISTS biz_shop_manage_group_member ( + id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键', + group_id BIGINT NOT NULL COMMENT '分组ID', + user_id BIGINT NOT NULL COMMENT '组员用户ID', + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + UNIQUE KEY uk_user_id (user_id), + KEY idx_group_id (group_id) +) COMMENT='店铺管理分组成员表'; + +INSERT INTO biz_shop_manage_group_member (group_id, user_id) +SELECT g.id, g.user_id +FROM biz_shop_manage_group g +LEFT JOIN biz_shop_manage_group_member m ON m.user_id = g.user_id +WHERE g.user_id IS NOT NULL + AND g.user_id > 0 + AND m.id IS NULL; diff --git a/backend-java/src/main/resources/logback-spring.xml b/backend-java/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..a36eabb --- /dev/null +++ b/backend-java/src/main/resources/logback-spring.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + ${CONSOLE_PATTERN} + UTF-8 + + + + + ${APP_LOG_FILE} + + ${FILE_PATTERN} + UTF-8 + + + ${APP_LOG_ARCHIVE} + 50MB + 1 + 500MB + true + + + + + + + + + + diff --git a/backend/blueprints/__pycache__/admin_api.cpython-312.pyc b/backend/blueprints/__pycache__/admin_api.cpython-312.pyc index 4b38d6bfa5382dc85954c23c0ea5130358131aae..da6ab9a05a9b06640fefe941e206493ee2a00348 100644 GIT binary patch delta 6359 zcmcgw3wV^((f($4zuoL5+07=q$%bq;2}ZIIk^l*J2}uCC{1kGb6bT6-yM$Z_;oF5^ z-54y^I~RMbpI8(TD)0bGT{Yk@0{Ub6sMK8SFKlhCVoRYFRxWBO)XtnQn?Q>Em*;82 z!~4ydGiS~@Gjrz5*+0qRkDnJ~-iwYl2>4g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fcN0fP&8l*vLA2o!UiWe!w3hk(b!lO(U_b3{mRt0`3@JWE|^!QFm9(2h+P|BS|YP3aO8O1Zx}U%z;jsWwJKW_HH}<(FwRg`f~;-uY_jI>kXW zMSql*I(iVP>5{w9)RCx8>oD^(c5w5d`5;CXv%m^|@ih#xzUf6PT+j_ri>!&Fs-SstI=c*+tCnq3ZgkI zpx-%<5bb=t=DG4_=YYeO+=GVP@6UQsUv0z@cc%_d8R_PO7bIyL?Jerx zvC-sL@BoZuvrZeizB@R~d(f(vknqJsc!|Z~;pr>WA0K$wk;?14!&ahrT8z~gV?JZF zxTH405^W3%7Je}quDwj&A(gyqd1Dj|=37$W<|cy=mTAPdTvOCjaQ+kX-98h z(zs%x{zFRQK?3y<({hf67DHL}^eTBA`TY8JQtx@~Fy>EYLM}YZKgxt*UUg4dw9aa5 z?WE!vS#YiAmo5-_Gq1~nWdBPvrh59nN0RzEpa$rAi|}1pFx2ufI*lO`Bt74f4?UXj z9yw>sQTwXPQTtN77L)eIm|k9e#i9Hu4f7r^$pdflK9a9`@F{#r9;Ec@a&f#*eLf)A zPjG ztUkBD06x|Vk!L+mybjNVV;H@aXxIxx!+@rh*THH42k%=1gW)?qy$B}34gB3Acy%Ft z*UOg(M4FR@U;s5!Ny;MVPe5O2GJR~x^hqVt*ONSippak;0e#2FWd!8}_Y%6(_`AfTH_rqfZTGeD+2AX9?sgAR%m^c6eA*`Dh3mT#0aPhb=v9z-D*|w~v8X pw-1aRmVseBK#k#1zzfKf(#ceWQLr5@;(NxzQQdvH{Mlld{9nNsB47Xj diff --git a/backend/blueprints/admin_api.py b/backend/blueprints/admin_api.py index c5a0e46..66b6633 100644 --- a/backend/blueprints/admin_api.py +++ b/backend/blueprints/admin_api.py @@ -406,12 +406,13 @@ def list_users(): search_username = (request.args.get('username') or request.args.get('search') or '').strip() created_by_id_arg = request.args.get('created_by_id') or request.args.get('admin_id') created_by_id = int(created_by_id_arg) if created_by_id_arg and str(created_by_id_arg).isdigit() else None - if role != 'super_admin': + can_view_all_users = role == 'super_admin' or (current_row and (current_row.get('username') or '').strip().lower() == 'admin') + if not can_view_all_users: created_by_id = None try: conn = get_db() with conn.cursor() as cur: - if role == 'super_admin': + if can_view_all_users: where_parts = ["1=1"] params = [] if search_username: @@ -1526,6 +1527,11 @@ def list_shop_manage_groups(): { 'id': item.get('id'), 'group_name': item.get('groupName') or '', + 'leader_user_id': item.get('leaderUserId'), + 'leader_username': item.get('leaderUsername') or '', + 'member_user_ids': item.get('memberUserIds') or [], + 'member_usernames': item.get('memberUsernames') or [], + 'member_count': item.get('memberCount') or 0, 'user_id': item.get('userId'), 'username': item.get('username') or '', 'created_at': (item.get('createdAt') or '').replace('T', ' ')[:16], @@ -1545,7 +1551,7 @@ def create_shop_manage_group(): data = request.get_json() or {} payload = { 'groupName': (data.get('group_name') or '').strip(), - 'userId': data.get('user_id'), + 'memberUserIds': data.get('member_user_ids') or [], 'createdById': current_row.get('id') if current_row else None, } result, error_response, status = _proxy_backend_java( @@ -1566,6 +1572,11 @@ def create_shop_manage_group(): 'item': { 'id': item.get('id'), 'group_name': item.get('groupName') or '', + 'leader_user_id': item.get('leaderUserId'), + 'leader_username': item.get('leaderUsername') or '', + 'member_user_ids': item.get('memberUserIds') or [], + 'member_usernames': item.get('memberUsernames') or [], + 'member_count': item.get('memberCount') or 0, 'user_id': item.get('userId'), 'username': item.get('username') or '', 'created_at': (item.get('createdAt') or '').replace('T', ' ')[:16], @@ -1583,7 +1594,7 @@ def update_shop_manage_group(item_id): data = request.get_json() or {} payload = { 'groupName': (data.get('group_name') or '').strip(), - 'userId': data.get('user_id'), + 'memberUserIds': data.get('member_user_ids') or [], } result, error_response, status = _proxy_backend_java( 'PUT', @@ -1603,6 +1614,11 @@ def update_shop_manage_group(item_id): 'item': { 'id': item.get('id'), 'group_name': item.get('groupName') or '', + 'leader_user_id': item.get('leaderUserId'), + 'leader_username': item.get('leaderUsername') or '', + 'member_user_ids': item.get('memberUserIds') or [], + 'member_usernames': item.get('memberUsernames') or [], + 'member_count': item.get('memberCount') or 0, 'user_id': item.get('userId'), 'username': item.get('username') or '', 'created_at': (item.get('createdAt') or '').replace('T', ' ')[:16], diff --git a/backend/web_source/admin.html b/backend/web_source/admin.html index 82837a5..2aa0b12 100644 --- a/backend/web_source/admin.html +++ b/backend/web_source/admin.html @@ -314,6 +314,10 @@ display: flex; } + #shopManageGroupModal { + z-index: 1010; + } + .modal { background: #fff; border-radius: 8px; @@ -948,17 +952,24 @@

分组管理

+
- - + +
- +
+
+ + +
可添加当前组长创建的普通员工账号,按住 Ctrl 或 Command 可多选。
+
+
+
@@ -968,7 +979,9 @@ 序号 分组名称 - 关联用户 + 组长 + 组员数量 + 组员 创建时间 修改时间 操作 @@ -1658,43 +1671,61 @@ sel.value = cur || ''; }); } - var shopManageGroupUsers = []; - function refreshShopManageGroupUserSelect(selectedUserId) { - var sel = document.getElementById('shopManageGroupUserSelect'); - if (!sel) return; - var opts = ['']; - shopManageGroupUsers.forEach(function (u) { - opts.push(''); + var shopManageAllUsers = []; + function getEligibleShopManageGroupUsers(leaderUserId) { + var canViewAllMembers = currentUserRole === 'super_admin'; + return shopManageAllUsers.filter(function (u) { + if (String(u.id || '') === String(leaderUserId || '')) return false; + if (canViewAllMembers) return true; + return String(u.role || '') === 'normal' && + String(u.created_by_id || '') === String(leaderUserId || ''); }); - sel.innerHTML = opts.join(''); - if (selectedUserId != null && selectedUserId !== '') { - sel.value = String(selectedUserId); - } - syncShopManageGroupNameWithUser(); } - function syncShopManageGroupNameWithUser() { - var sel = document.getElementById('shopManageGroupUserSelect'); - var input = document.getElementById('shopManageGroupInput'); - if (!sel || !input) return; - var selectedUser = null; - shopManageGroupUsers.some(function (u) { - if (String(u.id) === String(sel.value || '')) { - selectedUser = u; - return true; - } - return false; + function refreshShopManageGroupMemberSelect(leaderUserId, selectedUserIds) { + var sel = document.getElementById('shopManageGroupMemberSelect'); + if (!sel) return; + var selectedMap = {}; + (selectedUserIds || []).forEach(function (id) { + selectedMap[String(id)] = true; }); - input.value = selectedUser ? (selectedUser.username || '') : ''; + var options = getEligibleShopManageGroupUsers(leaderUserId).map(function (u) { + return ''; + }); + sel.innerHTML = options.join(''); + } + function setShopManageGroupLeader(leaderUserId, leaderUsername, selectedUserIds) { + var leaderIdEl = document.getElementById('shopManageGroupLeaderUserId'); + var leaderNameEl = document.getElementById('shopManageGroupLeaderName'); + if (leaderIdEl) leaderIdEl.value = leaderUserId ? String(leaderUserId) : ''; + if (leaderNameEl) leaderNameEl.value = leaderUsername || ''; + refreshShopManageGroupMemberSelect(leaderUserId, selectedUserIds || []); + } + function getSelectedShopManageGroupMemberIds() { + var sel = document.getElementById('shopManageGroupMemberSelect'); + if (!sel) return []; + return Array.prototype.slice.call(sel.options || []) + .filter(function (opt) { return !!opt.selected; }) + .map(function (opt) { return Number(opt.value); }) + .filter(function (id) { return !!id; }); } function loadUserOptions() { return fetch('/api/admin/users?page=1&page_size=999') .then(function (r) { return r.json(); }) .then(function (res) { var items = res.items || []; - shopManageGroupUsers = items.map(function (u) { - return { id: u.id, username: u.username || '', role: u.role || 'normal' }; + shopManageAllUsers = items.map(function (u) { + return { + id: u.id, + username: u.username || '', + role: u.role || 'normal', + created_by_id: u.created_by_id || null + }; }); - refreshShopManageGroupUserSelect(document.getElementById('shopManageGroupUserSelect') ? document.getElementById('shopManageGroupUserSelect').value : ''); + setShopManageGroupLeader( + document.getElementById('shopManageGroupLeaderUserId') ? document.getElementById('shopManageGroupLeaderUserId').value : '', + document.getElementById('shopManageGroupLeaderName') ? document.getElementById('shopManageGroupLeaderName').value : '', + getSelectedShopManageGroupMemberIds() + ); var sel = document.getElementById('filterUser'); var cur = sel.value; sel.innerHTML = ''; @@ -2163,107 +2194,6 @@ return query; } - function refreshShopGroupSelects(selectedCreateId, selectedEditId) { - var createSel = document.getElementById('shopManageGroupSelect'); - var editSel = document.getElementById('editShopManageGroupSelect'); - var filterSel = document.getElementById('shopManageFilterGroupId'); - var skipCreateSel = document.getElementById('skipPriceAsinGroupSelect'); - var skipFilterSel = document.getElementById('skipPriceAsinFilterGroupId'); - var chooseSkipShopSel = document.getElementById('chooseSkipPriceAsinShopGroupId'); - var selectedFilterId = filterSel ? filterSel.value : ''; - var selectedSkipCreateId = skipCreateSel ? skipCreateSel.value : ''; - var selectedSkipFilterId = skipFilterSel ? skipFilterSel.value : ''; - var selectedChooseSkipShopId = chooseSkipShopSel ? chooseSkipShopSel.value : ''; - var createOpts = ['']; - var filterOpts = ['']; - shopManageGroups.forEach(function (g) { - var option = ''; - createOpts.push(option); - filterOpts.push(option); - }); - createSel.innerHTML = createOpts.join(''); - editSel.innerHTML = createOpts.join(''); - if (skipCreateSel) skipCreateSel.innerHTML = createOpts.join(''); - if (filterSel) filterSel.innerHTML = filterOpts.join(''); - if (skipFilterSel) skipFilterSel.innerHTML = filterOpts.join(''); - if (chooseSkipShopSel) chooseSkipShopSel.innerHTML = filterOpts.join(''); - if (selectedCreateId != null) createSel.value = String(selectedCreateId); - if (selectedEditId != null) editSel.value = String(selectedEditId); - if (filterSel && selectedFilterId) filterSel.value = selectedFilterId; - if (skipCreateSel && selectedSkipCreateId) skipCreateSel.value = selectedSkipCreateId; - if (skipFilterSel && selectedSkipFilterId) skipFilterSel.value = selectedSkipFilterId; - if (chooseSkipShopSel && selectedChooseSkipShopId) chooseSkipShopSel.value = selectedChooseSkipShopId; - } - - function loadShopManageGroups(selectedCreateId, selectedEditId) { - return fetch('/api/admin/shop-manage-groups') - .then(function (r) { return r.json(); }) - .then(function (res) { - if (!res.success) throw new Error(res.error || '加载分组失败'); - shopManageGroups = res.items || []; - refreshShopGroupSelects(selectedCreateId, selectedEditId); - return shopManageGroups; - }) - .catch(function () { - shopManageGroups = []; - refreshShopGroupSelects(); - return []; - }); - } - - function openShopManageGroupModal() { - document.getElementById('shopManageGroupEditId').value = ''; - document.getElementById('shopManageGroupInput').value = ''; - document.getElementById('msgShopManageGroup').textContent = ''; - document.getElementById('msgShopManageGroup').className = 'msg'; - loadShopManageGroups().then(function () { - renderShopManageGroupRows(); - document.getElementById('shopManageGroupModal').classList.add('show'); - }); - } - - function renderShopManageGroupRows() { - var tbody = document.getElementById('shopManageGroupListBody'); - if (!shopManageGroups.length) { - tbody.innerHTML = '暂无分组'; - return; - } - tbody.innerHTML = shopManageGroups.map(function (item, index) { - return '' + (index + 1) + '' + (item.group_name || '') + '' + (item.created_at || '') + '' + (item.updated_at || '') + '' + - ' ' + - '' + - ''; - }).join(''); - - document.querySelectorAll('[data-shop-group-edit]').forEach(function (btn) { - btn.onclick = function () { - document.getElementById('shopManageGroupEditId').value = btn.dataset.shopGroupEdit; - document.getElementById('shopManageGroupInput').value = (btn.dataset.shopGroupName || '').replace(/"/g, '"'); - }; - }); - - document.querySelectorAll('[data-shop-group-delete]').forEach(function (btn) { - btn.onclick = function () { - var gid = btn.dataset.shopGroupDelete; - var gname = (btn.dataset.shopGroupName || '').replace(/"/g, '"'); - if (!confirm('确定删除分组“' + gname + '”吗?')) return; - fetch('/api/admin/shop-manage-group/' + gid, { method: 'DELETE' }) - .then(function (r) { return r.json(); }) - .then(function (res) { - if (!res.success) { - alert(res.error || '删除失败'); - return; - } - loadShopManageGroups().then(function () { - renderShopManageGroupRows(); - loadShopManage(shopManagePage); - loadSkipPriceAsin(skipPriceAsinPage); - }); - }); - }; - }); - } - function loadShopManage(page) { shopManagePage = page || 1; fetch('/api/admin/shop-manages?' + buildShopManageQuery(shopManagePage)) @@ -2325,65 +2255,6 @@ }); } - document.getElementById('btnManageShopGroups').onclick = openShopManageGroupModal; - document.getElementById('btnManageShopGroupsFromEdit').onclick = openShopManageGroupModal; - document.getElementById('btnSearchShopManage').onclick = function () { - loadShopManage(1); - }; - document.getElementById('shopManageFilterShopName').addEventListener('keydown', function (e) { - if (e.key === 'Enter') { - e.preventDefault(); - loadShopManage(1); - } - }); - document.getElementById('btnCloseShopManageGroupModal').onclick = function () { - document.getElementById('shopManageGroupModal').classList.remove('show'); - }; - document.getElementById('btnCancelShopManageGroupEdit').onclick = function () { - document.getElementById('shopManageGroupEditId').value = ''; - document.getElementById('shopManageGroupInput').value = ''; - }; - document.getElementById('btnSaveShopManageGroup').onclick = function () { - var editId = (document.getElementById('shopManageGroupEditId').value || '').trim(); - var groupName = (document.getElementById('shopManageGroupInput').value || '').trim(); - var msgEl = document.getElementById('msgShopManageGroup'); - msgEl.textContent = ''; - msgEl.className = 'msg'; - if (!groupName) { - msgEl.textContent = '请输入分组名称'; - msgEl.className = 'msg err'; - return; - } - var method = editId ? 'PUT' : 'POST'; - var url = editId ? ('/api/admin/shop-manage-group/' + editId) : '/api/admin/shop-manage-group'; - fetch(url, { - method: method, - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ group_name: groupName }) - }) - .then(function (r) { return r.json(); }) - .then(function (res) { - if (!res.success) { - msgEl.textContent = res.error || '保存失败'; - msgEl.className = 'msg err'; - return; - } - document.getElementById('shopManageGroupEditId').value = ''; - document.getElementById('shopManageGroupInput').value = ''; - msgEl.textContent = res.msg || '保存成功'; - msgEl.className = 'msg ok'; - loadShopManageGroups().then(function () { - renderShopManageGroupRows(); - loadShopManage(shopManagePage); - loadSkipPriceAsin(skipPriceAsinPage); - }); - }) - .catch(function () { - msgEl.textContent = '请求失败'; - msgEl.className = 'msg err'; - }); - }; - function refreshShopGroupSelects(selectedCreateId, selectedEditId) { var createSel = document.getElementById('shopManageGroupSelect'); var editSel = document.getElementById('editShopManageGroupSelect'); @@ -2434,10 +2305,12 @@ function resetShopManageGroupForm() { document.getElementById('shopManageGroupEditId').value = ''; + document.getElementById('shopManageGroupLeaderUserId').value = currentUserId || ''; + document.getElementById('shopManageGroupLeaderName').value = currentUserUsername || ''; document.getElementById('shopManageGroupInput').value = ''; document.getElementById('msgShopManageGroup').textContent = ''; document.getElementById('msgShopManageGroup').className = 'msg'; - refreshShopManageGroupUserSelect(''); + refreshShopManageGroupMemberSelect(currentUserId, []); } function openShopManageGroupModal() { @@ -2453,20 +2326,33 @@ function renderShopManageGroupRows() { var tbody = document.getElementById('shopManageGroupListBody'); if (!shopManageGroups.length) { - tbody.innerHTML = '暂无分组'; + tbody.innerHTML = '暂无分组'; return; } tbody.innerHTML = shopManageGroups.map(function (item, index) { - return '' + (index + 1) + '' + (item.group_name || '') + '' + (item.username || '') + '' + (item.created_at || '') + '' + (item.updated_at || '') + '' + - ' ' + + var memberNames = Array.isArray(item.member_usernames) ? item.member_usernames.join('、') : ''; + return '' + (index + 1) + '' + (item.group_name || '') + '' + (item.leader_username || '') + '' + (item.member_count || 0) + '' + (memberNames || '-') + '' + (item.created_at || '') + '' + (item.updated_at || '') + '' + + ' ' + '' + ''; }).join(''); document.querySelectorAll('[data-shop-group-edit]').forEach(function (btn) { btn.onclick = function () { - document.getElementById('shopManageGroupEditId').value = btn.dataset.shopGroupEdit; - refreshShopManageGroupUserSelect(btn.dataset.shopGroupUserId || ''); + var item = null; + shopManageGroups.some(function (group) { + if (String(group.id || '') === String(btn.dataset.shopGroupEdit || '')) { + item = group; + return true; + } + return false; + }); + if (!item) return; + document.getElementById('shopManageGroupEditId').value = item.id || ''; + document.getElementById('shopManageGroupInput').value = item.group_name || ''; + setShopManageGroupLeader(item.leader_user_id || '', item.leader_username || '', item.member_user_ids || []); + document.getElementById('msgShopManageGroup').textContent = ''; + document.getElementById('msgShopManageGroup').className = 'msg'; }; }); @@ -2492,10 +2378,18 @@ }); } - document.getElementById('shopManageGroupUserSelect').onchange = syncShopManageGroupNameWithUser; document.getElementById('btnManageShopGroups').onclick = openShopManageGroupModal; document.getElementById('btnManageShopGroupsFromEdit').onclick = openShopManageGroupModal; document.getElementById('btnManageSkipPriceAsinGroups').onclick = openShopManageGroupModal; + document.getElementById('btnSearchShopManage').onclick = function () { + loadShopManage(1); + }; + document.getElementById('shopManageFilterShopName').addEventListener('keydown', function (e) { + if (e.key === 'Enter') { + e.preventDefault(); + loadShopManage(1); + } + }); document.getElementById('btnCloseShopManageGroupModal').onclick = function () { document.getElementById('shopManageGroupModal').classList.remove('show'); }; @@ -2503,12 +2397,12 @@ document.getElementById('btnSaveShopManageGroup').onclick = function () { var editId = (document.getElementById('shopManageGroupEditId').value || '').trim(); var groupName = (document.getElementById('shopManageGroupInput').value || '').trim(); - var userId = (document.getElementById('shopManageGroupUserSelect').value || '').trim(); + var memberUserIds = getSelectedShopManageGroupMemberIds(); var msgEl = document.getElementById('msgShopManageGroup'); msgEl.textContent = ''; msgEl.className = 'msg'; - if (!userId || !groupName) { - msgEl.textContent = '请选择关联用户'; + if (!groupName) { + msgEl.textContent = '请输入分组名称'; msgEl.className = 'msg err'; return; } @@ -2517,7 +2411,7 @@ fetch(url, { method: method, headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ group_name: groupName, user_id: Number(userId) }) + body: JSON.stringify({ group_name: groupName, member_user_ids: memberUserIds }) }) .then(function (r) { return r.json(); }) .then(function (res) { diff --git a/frontend-vue/patrol-delete.html b/frontend-vue/patrol-delete.html new file mode 100644 index 0000000..6cee3bf --- /dev/null +++ b/frontend-vue/patrol-delete.html @@ -0,0 +1,12 @@ + + + + + + 巡店删除 - 数富AI + + +
+ + + diff --git a/frontend-vue/src/pages/brand/components/BrandDeleteBrandTab.vue b/frontend-vue/src/pages/brand/components/BrandDeleteBrandTab.vue index 0817eee..ac2ba96 100644 --- a/frontend-vue/src/pages/brand/components/BrandDeleteBrandTab.vue +++ b/frontend-vue/src/pages/brand/components/BrandDeleteBrandTab.vue @@ -1,4 +1,4 @@ -