From 1843e5276ef53f400f5c4834c46b6eb35c138a7e Mon Sep 17 00:00:00 2001 From: super <2903208875@qq.com> Date: Fri, 10 Apr 2026 19:33:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=9B=9E=E6=94=B6=EF=BC=8Cbu?= =?UTF-8?q?g=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/.env | 4 +- app/__pycache__/main.cpython-312.pyc | Bin 18363 -> 22621 bytes app/amazon/__pycache__/main.cpython-312.pyc | Bin 27901 -> 27901 bytes .../__pycache__/main.cpython-312.pyc | Bin 8716 -> 8716 bytes app/main.py | 24 +- backend-java/brand_chunk_load_test.py | 56 - .../config/DeleteBrandProgressProperties.java | 1 + .../aiimage/config/InstanceMetadata.java | 37 + .../aiimage/config/RequestTraceFilter.java | 81 + .../DebugRequestInfoController.java | 53 + .../service/DeleteBrandStaleTaskService.java | 21 +- .../dto/ProductRiskCreateTaskRequest.java | 5 + .../model/vo/ProductRiskResultItemVo.java | 4 + .../model/vo/ProductRiskTaskItemVo.java | 4 + .../service/ProductRiskTaskCacheService.java | 8 + .../controller/ShopMatchController.java | 150 ++ .../mapper/ShopMatchCountryPrefMapper.java | 9 + .../mapper/ShopMatchShopCandidateMapper.java | 9 + .../shopmatch/model/dto/ShopMatchRowDto.java | 20 + .../model/dto/ShopMatchShopPayloadDto.java | 25 + .../dto/ShopMatchSubmitResultRequest.java | 18 + .../entity/ShopMatchCountryPrefEntity.java | 18 + .../entity/ShopMatchShopCandidateEntity.java | 19 + .../ShopMatchExcelAssemblyService.java | 79 + .../service/ShopMatchResolveService.java | 274 +++ .../service/ShopMatchTaskCacheService.java | 87 + .../service/ShopMatchTaskService.java | 718 ++++++++ .../task/model/entity/FileTaskEntity.java | 1 + .../service/ZiniaoShopIndexService.java | 21 +- .../src/main/resources/application.yml | 6 +- .../db/V17__shop_match_shop_candidate.sql | 8 + .../db/V18__shop_match_country_pref.sql | 5 + .../db/V19__file_task_scheduled_at.sql | 2 + frontend-vue/shop-match.html | 12 + .../brand/components/BrandShopMatchTab.vue | 1582 +++++++++++++++++ .../pages/brand/components/BrandTopBar.vue | 3 +- frontend-vue/src/shared/api/java-modules.ts | 154 ++ frontend-vue/src/shop-match-main.ts | 7 + frontend-vue/vite.config.ts | 1 + 39 files changed, 3454 insertions(+), 72 deletions(-) delete mode 100644 backend-java/brand_chunk_load_test.py create mode 100644 backend-java/src/main/java/com/nanri/aiimage/config/InstanceMetadata.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/config/RequestTraceFilter.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/debug/controller/DebugRequestInfoController.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/controller/ShopMatchController.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/mapper/ShopMatchCountryPrefMapper.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/mapper/ShopMatchShopCandidateMapper.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchRowDto.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchShopPayloadDto.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchSubmitResultRequest.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/entity/ShopMatchCountryPrefEntity.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/entity/ShopMatchShopCandidateEntity.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchExcelAssemblyService.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchResolveService.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskCacheService.java create mode 100644 backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskService.java create mode 100644 backend-java/src/main/resources/db/V17__shop_match_shop_candidate.sql create mode 100644 backend-java/src/main/resources/db/V18__shop_match_country_pref.sql create mode 100644 backend-java/src/main/resources/db/V19__file_task_scheduled_at.sql create mode 100644 frontend-vue/shop-match.html create mode 100644 frontend-vue/src/pages/brand/components/BrandShopMatchTab.vue create mode 100644 frontend-vue/src/shop-match-main.ts diff --git a/app/.env b/app/.env index c9e68e145..123ec5197 100644 --- a/app/.env +++ b/app/.env @@ -12,8 +12,8 @@ zn_username=%E8%87%AA%E5%8A%A8%E5%8C%96_Robot client_name=ShuFuAI -# java_api_base=http://127.0.0.1:18080 +java_api_base=http://127.0.0.1:18080 # java_api_base=http://8.136.19.173:18081 -java_api_base=http://8.136.19.173:18080 +# java_api_base=http://8.136.19.173:18080 diff --git a/app/__pycache__/main.cpython-312.pyc b/app/__pycache__/main.cpython-312.pyc index 38a623b779fb65bddf00551abd8ec16a81433775..2e240fb213a6cc978127d55c6b4d23e790635fe6 100644 GIT binary patch literal 22621 zcmd6P3v?96nQr$?_q-p{jD+4WLJ}|ngn1ZYf-yo5-WUwFW5wRdpdQ2sNh9}+5NJn4 zBsfS0TVibo5o05-$yx;2kd4>D20vnOuFu)M_s&>DG_;j-eUCK~oO90&24|h)ocs9y z>eomN!cKf2CHSkls=B(Sy6XSG|F6ILU#(UX1z}yyu-{ZeQJ>?59Q0D+mP<=f$0&}f zr8t_?G}29)T1}I-R@=nXGEHnP+oY@2HR)^hO@>+njdiq*##$qZO|>Qxn`_M^w$xfk zY^}9I%rx4X?6r29(ojBYgG+v}8v8UHJE%LO5p!tDrw#7%859yzr+B+jkPC2?MD9*Og7^GRG#TR`IJwbLQCHqK~r)w;;IWpFmm z4o^=z18)h#y;N`#Uo6ie zn%bw`r!AruQbD>+LsO4YH2fVoyjS}e)keErt(DLZQ{v=1qwhTHYT4K3+p)**YjY*u zczOKUbK^fhciMM~9=sD+lc--vgEDm)ci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%23HR&Pum*>-J$;&@>SDMH z@-1FgHMI&}&F&GHko%Yd;|FH!!3mm1mbOM7fMwyF3 z_8)}8KiV8eDkmzRs2Z(J2-3lwkL?_5#zFIA%};Ino^V09?XMQh@T2-&F*n#P*vI9_z5F5(V5=S+;(0dv^AP?_T@)tFv#9L8$`A<=Gz{ zy?W{gm(Tw6+Dj*{zWm1Qk>{?Q8HbAHPosagkS>g}$EbO(96fXSt>3LiJlmOR} zRA?M7`v~Z|(9*oCja-AF3cTstPMZpMZ%}PS!M4c10evU^abtF#4@Ningc}Hkigb>? zn_ozuwE5t+XiP5^@ZyPQz{f~_nn&Y-pHp{n37B##gHX7W$;Ga+6uNJaZX5peF zRh$j88eXaz4LloH25p!dVre+b&vV@YJOMyonCh3O`eM4q<#m)K`Jry-x>uy$l&1Rf zRKGgaS76U_^r04%yDmjtpX#geoM1~8YAmB=(fhx$lpeV!;KXAE7Brx!y^2QPxM!o8 zB!EU9qyKe}x;_7f)1nD(m{m-&)s-pJp;(0u627FaMNh z#W;Ieu%QDdoSsYmf`os`U(JGOGAtF!!Vpdp3I$8ZN!opH!3f-qLg|BhCoke|@Mlb_ z(NG%S8|&94sC~MU>d|6ycp!QBZa~hxxD~i`l4E_E(JO=`FO&WgUqkRu-KrkNN4%od zMY*phuEM>4g!G0-VBT*d6;_7nAQU1`ASaI>VjW@peIjO!v}yU18CG8TIMz83yM zMl)?}&*eTb(OCN`Zq7>IZV%o+Z{pd!&+PR)TlEQpINxGg!FuK&W&Nysezl1$nD=mO zaNfFvHO*Bsf_;4Ow|veAg7kR(9M1?#KI^kGrt&GVEExfRS+%@Q2cvc&CAQh00jL`*Ee!ADggjFi3K76 delta 20 acmeBi>2cvc&CAQh00e1#*EVu9DggjDEd;~> diff --git a/app/main.py b/app/main.py index 7a76502ee..90847a605 100644 --- a/app/main.py +++ b/app/main.py @@ -19,6 +19,7 @@ import threading import time import requests import subprocess +import atexit from amazon.del_brand import kill_process @@ -39,6 +40,21 @@ print(f""" BASE_DIR = os.path.dirname(os.path.abspath(__file__)) APP_URL = "http://127.0.0.1:5123" PORT = 5123 +_shutdown_started = False + + +def cleanup_before_exit(): + global _shutdown_started + if _shutdown_started: + return + _shutdown_started = True + try: + kill_process('v6') + except Exception as e: + print(f"【退出前】关闭紫鸟浏览器进程异常: {str(e)}") + + +atexit.register(cleanup_before_exit) def generate_images(params): @@ -57,6 +73,11 @@ class WindowAPI: window.events.restored += lambda _: setattr(self, '_is_maximized', False) def close(self): + try: + self._window.destroy() + except: + pass + return try: kill_process('v6') except Exception as e: @@ -369,6 +390,7 @@ def start_task_monitor(): def on_window_closing(): + return """窗口关闭事件处理器,执行与 close() 方法相同的清理逻辑""" # 先关闭窗口,避免看起来卡着 try: @@ -419,7 +441,7 @@ def main(): window.expose(api.close, api.minimize, api.maximize, api.toggle_maximize, generate_images, api.save_image, api.save_image_to_folder, api.select_folder, api.select_brand_xlsx_files, api.select_brand_folder, api.save_file_from_url, api.save_template_xlsx,api.save_template_zip,api.upload_file_to_java,api.open_external_url,api.enqueue_json,api.get_detail_del,api.save_file_from_url_new) webview.start( - debug=False, + debug=True, storage_path=cache_path, private_mode=False ) diff --git a/backend-java/brand_chunk_load_test.py b/backend-java/brand_chunk_load_test.py deleted file mode 100644 index da8ccd350..000000000 --- a/backend-java/brand_chunk_load_test.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python3 -import json -import sys -import time -from urllib import request, error - - -def build_chunk(file_url: str, chunk_index: int, chunk_total: int, total_lines: int): - return { - "fileUrl": file_url, - "originalFilename": "demo.xlsx", - "relativePath": None, - "mainSheetName": "Sheet1", - "chunkIndex": chunk_index, - "chunkTotal": chunk_total, - "totalLines": total_lines, - "keptRows": [f"brand-{chunk_index}"], - "invalidBrands": [], - "queryFailedBrands": [] - } - - -def post_json(url: str, payload: dict): - data = json.dumps(payload).encode("utf-8") - req = request.Request(url, data=data, headers={"Content-Type": "application/json"}, method="POST") - with request.urlopen(req, timeout=60) as resp: - return resp.status, resp.read().decode("utf-8", errors="ignore") - - -def main(): - if len(sys.argv) < 4: - print("usage: python brand_chunk_load_test.py [file_url]") - sys.exit(1) - base_url = sys.argv[1].rstrip("/") - task_id = int(sys.argv[2]) - chunk_total = int(sys.argv[3]) - file_url = sys.argv[4] if len(sys.argv) > 4 else "https://example.com/demo.xlsx" - - submit_url = f"{base_url}/api/brand/tasks/{task_id}/result" - started = time.time() - for i in range(1, chunk_total + 1): - payload = { - "strategy": "Terms", - "files": [build_chunk(file_url, i, chunk_total, chunk_total)] - } - status, body = post_json(submit_url, payload) - if i == 1 or i == chunk_total or i % 100 == 0: - print(f"chunk {i}/{chunk_total} status={status} elapsed={time.time() - started:.2f}s") - if status < 200 or status >= 300: - print(body) - sys.exit(2) - print(f"done {chunk_total} chunks in {time.time() - started:.2f}s") - - -if __name__ == "__main__": - main() diff --git a/backend-java/src/main/java/com/nanri/aiimage/config/DeleteBrandProgressProperties.java b/backend-java/src/main/java/com/nanri/aiimage/config/DeleteBrandProgressProperties.java index 349374e63..24351495d 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/config/DeleteBrandProgressProperties.java +++ b/backend-java/src/main/java/com/nanri/aiimage/config/DeleteBrandProgressProperties.java @@ -19,4 +19,5 @@ public class DeleteBrandProgressProperties { * 与删除品牌共用同一定时调度。 */ private long productRiskStaleTimeoutMinutes = 10; + private long productRiskInitialTimeoutMinutes = 10; } diff --git a/backend-java/src/main/java/com/nanri/aiimage/config/InstanceMetadata.java b/backend-java/src/main/java/com/nanri/aiimage/config/InstanceMetadata.java new file mode 100644 index 000000000..2ffa0f5eb --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/config/InstanceMetadata.java @@ -0,0 +1,37 @@ +package com.nanri.aiimage.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.net.InetAddress; + +@Component +public class InstanceMetadata { + + private final String instanceId; + private final String hostname; + + public InstanceMetadata(@Value("${aiimage.instance-id:}") String configuredInstanceId) { + this.hostname = resolveHostname(); + this.instanceId = configuredInstanceId == null || configuredInstanceId.isBlank() + ? this.hostname + : configuredInstanceId.trim(); + } + + public String getInstanceId() { + return instanceId; + } + + public String getHostname() { + return hostname; + } + + private static String resolveHostname() { + try { + return InetAddress.getLocalHost().getHostName(); + } catch (Exception ignored) { + String envHostname = System.getenv("HOSTNAME"); + return (envHostname == null || envHostname.isBlank()) ? "unknown-host" : envHostname; + } + } +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/config/RequestTraceFilter.java b/backend-java/src/main/java/com/nanri/aiimage/config/RequestTraceFilter.java new file mode 100644 index 000000000..05bf06098 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/config/RequestTraceFilter.java @@ -0,0 +1,81 @@ +package com.nanri.aiimage.config; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; +import java.util.Optional; + +@Component +public class RequestTraceFilter extends OncePerRequestFilter { + + private static final Logger log = LoggerFactory.getLogger(RequestTraceFilter.class); + + private final InstanceMetadata instanceMetadata; + + public RequestTraceFilter(InstanceMetadata instanceMetadata) { + this.instanceMetadata = instanceMetadata; + } + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) + throws ServletException, IOException { + long start = System.currentTimeMillis(); + String remoteAddr = firstNonBlank( + request.getHeader("X-Forwarded-For"), + request.getHeader("X-Real-IP"), + request.getRemoteAddr() + ); + String forwardedProto = request.getHeader("X-Forwarded-Proto"); + String forwardedHost = firstNonBlank(request.getHeader("X-Forwarded-Host"), request.getHeader("Host")); + String forwardedPort = request.getHeader("X-Forwarded-Port"); + String requestId = firstNonBlank( + request.getHeader("X-Request-Id"), + request.getHeader("X-Amzn-Trace-Id"), + request.getHeader("Traceparent") + ); + + response.setHeader("X-AIIMAGE-Instance", instanceMetadata.getInstanceId()); + response.setHeader("X-AIIMAGE-Host", instanceMetadata.getHostname()); + + try { + filterChain.doFilter(request, response); + } finally { + long costMs = System.currentTimeMillis() - start; + log.info( + "request-trace instance={} host={} method={} uri={} status={} remote={} forwardedHost={} forwardedProto={} forwardedPort={} requestId={} userAgent={} costMs={}", + instanceMetadata.getInstanceId(), + instanceMetadata.getHostname(), + request.getMethod(), + request.getRequestURI(), + response.getStatus(), + remoteAddr, + blankToDash(forwardedHost), + blankToDash(forwardedProto), + blankToDash(forwardedPort), + blankToDash(requestId), + blankToDash(request.getHeader("User-Agent")), + costMs + ); + } + } + + private static String firstNonBlank(String... values) { + for (String value : values) { + if (value != null && !value.isBlank()) { + return value; + } + } + return null; + } + + private static String blankToDash(String value) { + return Optional.ofNullable(value).filter(v -> !v.isBlank()).orElse("-"); + } +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/debug/controller/DebugRequestInfoController.java b/backend-java/src/main/java/com/nanri/aiimage/modules/debug/controller/DebugRequestInfoController.java new file mode 100644 index 000000000..ee4dc72f6 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/debug/controller/DebugRequestInfoController.java @@ -0,0 +1,53 @@ +package com.nanri.aiimage.modules.debug.controller; + +import com.nanri.aiimage.config.InstanceMetadata; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.LinkedHashMap; +import java.util.Map; + +@RestController +@RequestMapping("/debug") +public class DebugRequestInfoController { + + private final InstanceMetadata instanceMetadata; + + public DebugRequestInfoController(InstanceMetadata instanceMetadata) { + this.instanceMetadata = instanceMetadata; + } + + @GetMapping("/request-info") + public Map requestInfo( + HttpServletRequest request, + @RequestHeader(value = "X-Forwarded-For", required = false) String forwardedFor, + @RequestHeader(value = "X-Real-IP", required = false) String realIp, + @RequestHeader(value = "X-Forwarded-Proto", required = false) String forwardedProto, + @RequestHeader(value = "X-Forwarded-Host", required = false) String forwardedHost, + @RequestHeader(value = "X-Forwarded-Port", required = false) String forwardedPort, + @RequestHeader(value = "X-Request-Id", required = false) String requestId, + @RequestHeader(value = "X-Amzn-Trace-Id", required = false) String amazonTraceId, + @RequestHeader(value = "Traceparent", required = false) String traceparent + ) { + Map result = new LinkedHashMap<>(); + result.put("instanceId", instanceMetadata.getInstanceId()); + result.put("hostname", instanceMetadata.getHostname()); + result.put("serverName", request.getServerName()); + result.put("serverPort", request.getServerPort()); + result.put("method", request.getMethod()); + result.put("uri", request.getRequestURI()); + result.put("remoteAddr", request.getRemoteAddr()); + result.put("xForwardedFor", forwardedFor); + result.put("xRealIp", realIp); + result.put("xForwardedProto", forwardedProto); + result.put("xForwardedHost", forwardedHost); + result.put("xForwardedPort", forwardedPort); + result.put("xRequestId", requestId); + result.put("xAmznTraceId", amazonTraceId); + result.put("traceparent", traceparent); + return result; + } +} 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 c9fa8e8c8..4e4ebf016 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 @@ -3,6 +3,7 @@ package com.nanri.aiimage.modules.deletebrand.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; 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.task.mapper.FileTaskMapper; import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity; @@ -31,6 +32,7 @@ public class DeleteBrandStaleTaskService { private final DeleteBrandTaskCacheService deleteBrandTaskCacheService; private final DeleteBrandRunService deleteBrandRunService; private final ProductRiskTaskService productRiskTaskService; + private final ProductRiskTaskCacheService productRiskTaskCacheService; private final DeleteBrandProgressProperties deleteBrandProgressProperties; @Scheduled(cron = "${aiimage.delete-brand-progress.stale-check-cron:0 */2 * * * *}") @@ -115,7 +117,10 @@ public class DeleteBrandStaleTaskService { private ProductRiskStaleCheckStats failStaleProductRiskResolveTasks() { ProductRiskStaleCheckStats stats = new ProductRiskStaleCheckStats(); long minutes = Math.max(1L, deleteBrandProgressProperties.getProductRiskStaleTimeoutMinutes()); - LocalDateTime threshold = LocalDateTime.now().minusMinutes(minutes); + long initialMinutes = Math.max(minutes, deleteBrandProgressProperties.getProductRiskInitialTimeoutMinutes()); + 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_PRODUCT_RISK) .eq(FileTaskEntity::getStatus, "RUNNING") @@ -125,9 +130,19 @@ public class DeleteBrandStaleTaskService { if (runningTasks.isEmpty()) { return stats; } - log.info("[stale-check] product-risk candidates={} threshold={} timeoutMinutes={}", - runningTasks.size(), threshold, minutes); + log.info("[stale-check] product-risk candidates={} threshold={} timeoutMinutes={} initialThreshold={} initialTimeoutMinutes={}", + runningTasks.size(), threshold, minutes, initialThreshold, initialMinutes); for (FileTaskEntity task : runningTasks) { + boolean hasUploadedPayload = productRiskTaskCacheService.hasAnyShopMergedPayload(task.getId()); + boolean hasFinishedRows = (task.getSuccessFileCount() != null && task.getSuccessFileCount() > 0) + || (task.getFailedFileCount() != null && task.getFailedFileCount() > 0); + boolean hasStartedProgress = hasUploadedPayload || hasFinishedRows; + if (!hasStartedProgress && task.getCreatedAt() != null && task.getCreatedAt().isAfter(initialThreshold)) { + stats.skippedTaskCount++; + log.info("[stale-check] product-risk skip initial-grace taskId={} createdAt={} initialThreshold={}", + task.getId(), task.getCreatedAt(), initialThreshold); + continue; + } try { if (productRiskTaskService.tryFinalizeTask(task.getId(), true)) { stats.finalizedTaskCount++; diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/dto/ProductRiskCreateTaskRequest.java b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/dto/ProductRiskCreateTaskRequest.java index e287cc787..587ebe318 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/dto/ProductRiskCreateTaskRequest.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/dto/ProductRiskCreateTaskRequest.java @@ -8,6 +8,7 @@ import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import lombok.Data; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -27,4 +28,8 @@ public class ProductRiskCreateTaskRequest { + "店名会去重;每店生成一条 biz_file_result(含 resultId)。", requiredMode = Schema.RequiredMode.REQUIRED) private List items = new ArrayList<>(); + + @JsonProperty("schedule_time") + @Schema(description = "可选,定时执行时间,必须晚于当前时间", example = "2026-04-09T18:30:00") + private LocalDateTime scheduleTime; } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/vo/ProductRiskResultItemVo.java b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/vo/ProductRiskResultItemVo.java index 01cebecf9..41a60969c 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/vo/ProductRiskResultItemVo.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/vo/ProductRiskResultItemVo.java @@ -57,4 +57,8 @@ public class ProductRiskResultItemVo { @JsonProperty("downloadUrl") @Schema(description = "预签名下载 URL(列表里可能带;直链下载也可用 GET /results/{resultId}/download)") private String downloadUrl; + + @JsonProperty("scheduledAt") + @Schema(description = "定时执行时间,未设置时为空") + private String scheduledAt; } diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/vo/ProductRiskTaskItemVo.java b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/vo/ProductRiskTaskItemVo.java index b313a185e..971ce126b 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/vo/ProductRiskTaskItemVo.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/productrisk/model/vo/ProductRiskTaskItemVo.java @@ -33,4 +33,8 @@ public class ProductRiskTaskItemVo { @JsonProperty("finishedAt") @Schema(description = "结束时间;RUNNING 时通常为空") private String finishedAt; + + @JsonProperty("scheduledAt") + @Schema(description = "定时执行时间,未设置时为空") + private String scheduledAt; } 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 69f25f199..2a48521ed 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 @@ -73,6 +73,14 @@ public class ProductRiskTaskCacheService { } } + 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 void deleteTaskCache(Long taskId) { if (taskId == null || taskId <= 0) { return; 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 new file mode 100644 index 000000000..63952d34c --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/controller/ShopMatchController.java @@ -0,0 +1,150 @@ +package com.nanri.aiimage.modules.shopmatch.controller; + +import com.nanri.aiimage.common.api.ApiResponse; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCandidateAddRequest; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCountryPreferenceSaveRequest; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCreateTaskRequest; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskMatchShopsRequest; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskTaskBatchRequest; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskCandidateVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskCountryPreferenceVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskCreateTaskVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskDashboardVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskHistoryVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskMatchShopsVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskTaskBatchVo; +import com.nanri.aiimage.modules.shopmatch.model.dto.ShopMatchSubmitResultRequest; +import com.nanri.aiimage.modules.shopmatch.service.ShopMatchResolveService; +import com.nanri.aiimage.modules.shopmatch.service.ShopMatchTaskService; +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.PutMapping; +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/shop-match") +public class ShopMatchController { + + private final ShopMatchResolveService shopMatchResolveService; + private final ShopMatchTaskService shopMatchTaskService; + + @GetMapping("/candidates") + public ApiResponse> listCandidates(@RequestParam("user_id") Long userId) { + return ApiResponse.success(shopMatchResolveService.listCandidates(userId)); + } + + @PostMapping("/candidates") + public ApiResponse addCandidate(@Valid @RequestBody ProductRiskCandidateAddRequest request) { + return ApiResponse.success(shopMatchResolveService.addCandidate(request)); + } + + @DeleteMapping("/candidates/{id}") + public ApiResponse deleteCandidate(@PathVariable Long id, @RequestParam("user_id") Long userId) { + shopMatchResolveService.deleteCandidate(userId, id); + return ApiResponse.success(null); + } + + @GetMapping("/country-preference") + public ApiResponse getCountryPreference(@RequestParam("user_id") Long userId) { + return ApiResponse.success(shopMatchResolveService.getCountryPreference(userId)); + } + + @PutMapping("/country-preference") + public ApiResponse saveCountryPreference(@Valid @RequestBody ProductRiskCountryPreferenceSaveRequest request) { + return ApiResponse.success(shopMatchResolveService.saveCountryPreference(request)); + } + + @PostMapping("/match-shops") + public ApiResponse matchShops(@Valid @RequestBody ProductRiskMatchShopsRequest request) { + return ApiResponse.success(shopMatchResolveService.matchShops(request)); + } + + @GetMapping("/dashboard") + public ApiResponse dashboard(@RequestParam("user_id") Long userId) { + return ApiResponse.success(shopMatchTaskService.dashboard(userId)); + } + + @GetMapping("/history") + public ApiResponse history(@RequestParam("user_id") Long userId) { + return ApiResponse.success(shopMatchTaskService.listHistory(userId)); + } + + @DeleteMapping("/history/{resultId}") + public ApiResponse deleteHistory(@PathVariable Long resultId, @RequestParam("user_id") Long userId) { + shopMatchTaskService.deleteHistory(resultId, userId); + return ApiResponse.success(null); + } + + @PostMapping("/tasks") + public ApiResponse createTask(@Valid @RequestBody ProductRiskCreateTaskRequest request) { + return ApiResponse.success(shopMatchTaskService.createTask(request)); + } + + @DeleteMapping("/tasks/{taskId}") + public ApiResponse deleteTask(@PathVariable Long taskId, @RequestParam("user_id") Long userId) { + shopMatchTaskService.deleteTask(taskId, userId); + return ApiResponse.success(null); + } + + @PostMapping("/tasks/{taskId}/activate") + public ApiResponse activateTask(@PathVariable Long taskId, @RequestParam("user_id") Long userId) { + shopMatchTaskService.activateTask(taskId, userId); + return ApiResponse.success(null); + } + + @PostMapping("/tasks/batch") + public ApiResponse tasksBatch(@Valid @RequestBody ProductRiskTaskBatchRequest request) { + return ApiResponse.success(shopMatchTaskService.getTaskDetailsBatch(request.getTaskIds())); + } + + @PostMapping("/tasks/{taskId}/result") + public ApiResponse submitResult(@PathVariable Long taskId, @Valid @RequestBody ShopMatchSubmitResultRequest request) { + shopMatchTaskService.submitResult(taskId, request); + return ApiResponse.success(null); + } + + @GetMapping("/results/{resultId}/download") + public void downloadResult( + @PathVariable Long resultId, + @RequestParam("user_id") Long userId, + jakarta.servlet.http.HttpServletResponse response) { + String url = shopMatchTaskService.resolveResultDownloadUrl(resultId, userId); + String filename = shopMatchTaskService.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, "下载失败"); + } + } +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/mapper/ShopMatchCountryPrefMapper.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/mapper/ShopMatchCountryPrefMapper.java new file mode 100644 index 000000000..c34f32ffa --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/mapper/ShopMatchCountryPrefMapper.java @@ -0,0 +1,9 @@ +package com.nanri.aiimage.modules.shopmatch.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.nanri.aiimage.modules.shopmatch.model.entity.ShopMatchCountryPrefEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ShopMatchCountryPrefMapper extends BaseMapper { +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/mapper/ShopMatchShopCandidateMapper.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/mapper/ShopMatchShopCandidateMapper.java new file mode 100644 index 000000000..c5cdb0e50 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/mapper/ShopMatchShopCandidateMapper.java @@ -0,0 +1,9 @@ +package com.nanri.aiimage.modules.shopmatch.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.nanri.aiimage.modules.shopmatch.model.entity.ShopMatchShopCandidateEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ShopMatchShopCandidateMapper extends BaseMapper { +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchRowDto.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchRowDto.java new file mode 100644 index 000000000..222cc170b --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchRowDto.java @@ -0,0 +1,20 @@ +package com.nanri.aiimage.modules.shopmatch.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "匹配店铺单行结果") +public class ShopMatchRowDto { + + @Schema(description = "ASIN") + private String asin; + + @Schema(description = "状态") + private String status; + + @JsonProperty("done") + @Schema(description = "该店铺是否已完成回传") + private Boolean done; +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchShopPayloadDto.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchShopPayloadDto.java new file mode 100644 index 000000000..9100f22fa --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchShopPayloadDto.java @@ -0,0 +1,25 @@ +package com.nanri.aiimage.modules.shopmatch.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.nanri.aiimage.modules.productrisk.model.enums.ProductRiskCountryCode; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@Data +@Schema(description = "Python 回传的单店铺结果") +public class ShopMatchShopPayloadDto { + + @JsonProperty("shopName") + @Schema(description = "店铺名称") + private String shopName; + + @Schema(description = "失败时的错误信息") + private String error; + + @Schema(description = "按国家分组的 ASIN/状态 列表") + private Map> countries = new LinkedHashMap<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchSubmitResultRequest.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchSubmitResultRequest.java new file mode 100644 index 000000000..d1719ad82 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/dto/ShopMatchSubmitResultRequest.java @@ -0,0 +1,18 @@ +package com.nanri.aiimage.modules.shopmatch.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 ShopMatchSubmitResultRequest { + + @NotEmpty(message = "shops 不能为空") + @Valid + private List shops = new ArrayList<>(); +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/entity/ShopMatchCountryPrefEntity.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/entity/ShopMatchCountryPrefEntity.java new file mode 100644 index 000000000..c7cf6dc9d --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/entity/ShopMatchCountryPrefEntity.java @@ -0,0 +1,18 @@ +package com.nanri.aiimage.modules.shopmatch.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_shop_match_country_pref") +public class ShopMatchCountryPrefEntity { + + @TableId(type = IdType.INPUT) + private Long userId; + private String countryCodesJson; + private LocalDateTime updatedAt; +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/entity/ShopMatchShopCandidateEntity.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/entity/ShopMatchShopCandidateEntity.java new file mode 100644 index 000000000..4eaf49268 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/model/entity/ShopMatchShopCandidateEntity.java @@ -0,0 +1,19 @@ +package com.nanri.aiimage.modules.shopmatch.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_shop_match_shop_candidate") +public class ShopMatchShopCandidateEntity { + + @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/shopmatch/service/ShopMatchExcelAssemblyService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchExcelAssemblyService.java new file mode 100644 index 000000000..e58159eb6 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchExcelAssemblyService.java @@ -0,0 +1,79 @@ +package com.nanri.aiimage.modules.shopmatch.service; + +import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.modules.productrisk.model.enums.ProductRiskCountryCode; +import com.nanri.aiimage.modules.shopmatch.model.dto.ShopMatchRowDto; +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.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class ShopMatchExcelAssemblyService { + + private static final String[] HEADER = {"ASIN", "状态"}; + + public void writeWorkbook(File outputXlsx, Map> countries) { + Map> safe = countries == null ? Map.of() : countries; + try (XSSFWorkbook wb = new XSSFWorkbook(); FileOutputStream fos = new FileOutputStream(outputXlsx)) { + for (ProductRiskCountryCode code : ProductRiskCountryCode.values()) { + String sheetName = code.getSheetName(); + Sheet sheet = wb.createSheet(sheetName); + Row header = sheet.createRow(0); + header.createCell(0).setCellValue(HEADER[0]); + header.createCell(1).setCellValue(HEADER[1]); + List rows = safe.getOrDefault(sheetName, List.of()); + int rowIndex = 1; + for (ShopMatchRowDto item : rows) { + if (item == null) { + continue; + } + Row row = sheet.createRow(rowIndex++); + row.createCell(0).setCellValue(item.getAsin() == null ? "" : item.getAsin()); + row.createCell(1).setCellValue(item.getStatus() == null ? "" : item.getStatus()); + } + sheet.autoSizeColumn(0); + sheet.autoSizeColumn(1); + } + wb.write(fos); + } catch (Exception ex) { + log.warn("[shop-match] write workbook failed: {}", ex.getMessage()); + throw new BusinessException("生成 Excel 失败: " + ex.getMessage()); + } + } + + public int countRows(Map> countries) { + if (countries == null || countries.isEmpty()) { + return 0; + } + int count = 0; + for (List rows : countries.values()) { + if (rows != null) { + count += rows.size(); + } + } + return count; + } + + public Map> normalizeCountriesMap(Map> raw) { + if (raw == null || raw.isEmpty()) { + return new LinkedHashMap<>(); + } + Map> out = new LinkedHashMap<>(); + for (ProductRiskCountryCode code : ProductRiskCountryCode.values()) { + List rows = raw.get(code); + if (rows != null) { + out.put(code.getSheetName(), rows); + } + } + return out; + } +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchResolveService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchResolveService.java new file mode 100644 index 000000000..0cc801483 --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchResolveService.java @@ -0,0 +1,274 @@ +package com.nanri.aiimage.modules.shopmatch.service; + +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.modules.productrisk.model.dto.ProductRiskCandidateAddRequest; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCountryPreferenceSaveRequest; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskMatchShopsRequest; +import com.nanri.aiimage.modules.productrisk.model.enums.ProductRiskCountryCode; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskCandidateVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskCountryPreferenceVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskMatchShopsVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskShopQueueItemVo; +import com.nanri.aiimage.modules.shopmatch.mapper.ShopMatchCountryPrefMapper; +import com.nanri.aiimage.modules.shopmatch.mapper.ShopMatchShopCandidateMapper; +import com.nanri.aiimage.modules.shopmatch.model.entity.ShopMatchCountryPrefEntity; +import com.nanri.aiimage.modules.shopmatch.model.entity.ShopMatchShopCandidateEntity; +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 ShopMatchResolveService { + + public static final List DEFAULT_COUNTRY_PREFERENCE_ORDER = List.of("DE", "UK", "FR", "IT", "ES"); + + private final ShopMatchShopCandidateMapper candidateMapper; + private final ShopMatchCountryPrefMapper countryPrefMapper; + private final ObjectMapper objectMapper; + private final ZiniaoShopSwitchService ziniaoShopSwitchService; + + public List listCandidates(Long userId) { + if (userId == null || userId <= 0) { + throw new BusinessException("user_id 不合法"); + } + List rows = candidateMapper.selectList( + new LambdaQueryWrapper() + .eq(ShopMatchShopCandidateEntity::getUserId, userId) + .orderByDesc(ShopMatchShopCandidateEntity::getId)); + List list = new ArrayList<>(); + for (ShopMatchShopCandidateEntity 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) { + if (request.getUserId() == null || request.getUserId() <= 0) { + throw new BusinessException("user_id 不合法"); + } + 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() : "存在多个同名店铺,请人工确认"); + } + + ShopMatchShopCandidateEntity existing = candidateMapper.selectOne( + new LambdaQueryWrapper() + .eq(ShopMatchShopCandidateEntity::getUserId, request.getUserId()) + .eq(ShopMatchShopCandidateEntity::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; + } + + ShopMatchShopCandidateEntity entity = new ShopMatchShopCandidateEntity(); + 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) { + if (userId == null || userId <= 0) { + throw new BusinessException("user_id 不合法"); + } + if (id == null || id <= 0) { + throw new BusinessException("id 不合法"); + } + ShopMatchShopCandidateEntity row = candidateMapper.selectById(id); + if (row == null || !userId.equals(row.getUserId())) { + throw new BusinessException("记录不存在"); + } + candidateMapper.deleteById(id); + } + + public ProductRiskMatchShopsVo matchShops(ProductRiskMatchShopsRequest request) { + if (request.getUserId() == null || request.getUserId() <= 0) { + throw new BusinessException("user_id 不合法"); + } + 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 ProductRiskCountryPreferenceVo getCountryPreference(Long userId) { + if (userId == null || userId <= 0) { + throw new BusinessException("user_id 不合法"); + } + ShopMatchCountryPrefEntity row = countryPrefMapper.selectById(userId); + ProductRiskCountryPreferenceVo vo = new ProductRiskCountryPreferenceVo(); + if (row == null || row.getCountryCodesJson() == null || row.getCountryCodesJson().isBlank()) { + vo.getCountryCodes().addAll(DEFAULT_COUNTRY_PREFERENCE_ORDER); + return vo; + } + try { + List parsed = objectMapper.readValue(row.getCountryCodesJson(), new TypeReference>() {}); + vo.getCountryCodes().addAll(sanitizeStoredCodes(parsed)); + } catch (Exception ex) { + vo.getCountryCodes().addAll(DEFAULT_COUNTRY_PREFERENCE_ORDER); + } + return vo; + } + + @Transactional + public ProductRiskCountryPreferenceVo saveCountryPreference(ProductRiskCountryPreferenceSaveRequest request) { + if (request.getUserId() == null || request.getUserId() <= 0) { + throw new BusinessException("user_id 不合法"); + } + List normalized = validateCountryCodesForSave(request.getCountryCodes()); + String json; + try { + json = objectMapper.writeValueAsString(normalized); + } catch (Exception ex) { + throw new BusinessException("保存偏好失败"); + } + + ShopMatchCountryPrefEntity row = countryPrefMapper.selectById(request.getUserId()); + if (row == null) { + row = new ShopMatchCountryPrefEntity(); + row.setUserId(request.getUserId()); + row.setCountryCodesJson(json); + countryPrefMapper.insert(row); + } else { + row.setCountryCodesJson(json); + countryPrefMapper.updateById(row); + } + + ProductRiskCountryPreferenceVo vo = new ProductRiskCountryPreferenceVo(); + vo.getCountryCodes().addAll(normalized); + return vo; + } + + 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 static List sanitizeStoredCodes(List raw) { + List parsed = parseValidCountryCodes(raw); + return parsed.isEmpty() ? new ArrayList<>(DEFAULT_COUNTRY_PREFERENCE_ORDER) : parsed; + } + + private static List validateCountryCodesForSave(List raw) { + if (raw == null || raw.isEmpty()) { + throw new BusinessException("country_codes 至少选择 1 个国家"); + } + LinkedHashSet seen = new LinkedHashSet<>(); + List out = new ArrayList<>(); + for (String item : raw) { + if (item == null || item.isBlank()) { + throw new BusinessException("country_codes 含空值"); + } + String upper = item.trim().toUpperCase(); + try { + ProductRiskCountryCode.valueOf(upper); + } catch (IllegalArgumentException ex) { + throw new BusinessException("非法国家代码: " + item); + } + if (!seen.add(upper)) { + throw new BusinessException("country_codes 存在重复: " + upper); + } + out.add(upper); + } + return out; + } + + private static List parseValidCountryCodes(List raw) { + if (raw == null || raw.isEmpty()) { + return new ArrayList<>(); + } + LinkedHashSet seen = new LinkedHashSet<>(); + List out = new ArrayList<>(); + for (String item : raw) { + if (item == null || item.isBlank()) { + continue; + } + String upper = item.trim().toUpperCase(); + try { + ProductRiskCountryCode.valueOf(upper); + } catch (IllegalArgumentException ex) { + continue; + } + if (seen.add(upper)) { + out.add(upper); + } + } + return out; + } +} 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 new file mode 100644 index 000000000..79335479c --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskCacheService.java @@ -0,0 +1,87 @@ +package com.nanri.aiimage.modules.shopmatch.service; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.modules.shopmatch.model.dto.ShopMatchShopPayloadDto; +import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; + +import java.time.Duration; +import java.util.LinkedHashMap; +import java.util.Map; + +@Service +@RequiredArgsConstructor +public class ShopMatchTaskCacheService { + + private static final long PAYLOAD_TTL_HOURS = 24; + + private final StringRedisTemplate stringRedisTemplate; + private final ObjectMapper objectMapper; + + public ShopMatchShopPayloadDto 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, ShopMatchShopPayloadDto.class); + } catch (Exception ex) { + throw new BusinessException("读取匹配店铺缓存失败"); + } + } + + public void saveShopMergedPayload(Long taskId, String shopKey, ShopMatchShopPayloadDto payload) { + if (taskId == null || taskId <= 0 || shopKey == null || shopKey.isBlank() || payload == null) { + return; + } + try { + String key = buildShopPayloadKey(taskId); + stringRedisTemplate.opsForHash().put(key, shopKey, objectMapper.writeValueAsString(payload)); + stringRedisTemplate.expire(key, Duration.ofHours(PAYLOAD_TTL_HOURS)); + } 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(); + } + LinkedHashMap 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, ShopMatchShopPayloadDto.class)); + } + return out; + } catch (Exception ex) { + throw new BusinessException("读取匹配店铺缓存失败"); + } + } + + public void deleteTaskCache(Long taskId) { + if (taskId == null || taskId <= 0) { + return; + } + stringRedisTemplate.delete(buildShopPayloadKey(taskId)); + } + + private String buildShopPayloadKey(Long taskId) { + return "shop-match:task:shop-payload:" + taskId; + } +} 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 new file mode 100644 index 000000000..3c0c0675e --- /dev/null +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/shopmatch/service/ShopMatchTaskService.java @@ -0,0 +1,718 @@ +package com.nanri.aiimage.modules.shopmatch.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.databind.ObjectMapper; +import com.nanri.aiimage.common.exception.BusinessException; +import com.nanri.aiimage.modules.file.service.oss.OssStorageService; +import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskCreateTaskRequest; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskCreateTaskVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskDashboardVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskHistoryVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskResultItemVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskShopQueueItemVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskTaskBatchVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskTaskDetailVo; +import com.nanri.aiimage.modules.productrisk.model.vo.ProductRiskTaskItemVo; +import com.nanri.aiimage.modules.shopmatch.mapper.ShopMatchShopCandidateMapper; +import com.nanri.aiimage.modules.shopmatch.model.dto.ShopMatchRowDto; +import com.nanri.aiimage.modules.shopmatch.model.dto.ShopMatchShopPayloadDto; +import com.nanri.aiimage.modules.shopmatch.model.dto.ShopMatchSubmitResultRequest; +import com.nanri.aiimage.modules.shopmatch.model.entity.ShopMatchShopCandidateEntity; +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.Locale; +import java.util.Map; + +@Service +@RequiredArgsConstructor +@Slf4j +public class ShopMatchTaskService { + + private static final String MODULE_TYPE = "SHOP_MATCH"; + private static final String CONTENT_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + + private final FileTaskMapper fileTaskMapper; + private final FileResultMapper fileResultMapper; + private final ShopMatchShopCandidateMapper candidateMapper; + private final ZiniaoShopSwitchService ziniaoShopSwitchService; + private final ShopMatchExcelAssemblyService excelAssemblyService; + private final OssStorageService ossStorageService; + private final ObjectMapper objectMapper; + private final ShopMatchTaskCacheService shopMatchTaskCacheService; + + public ProductRiskDashboardVo dashboard(Long userId) { + if (userId == null || userId <= 0) { + throw new BusinessException("user_id 不合法"); + } + ProductRiskDashboardVo vo = new ProductRiskDashboardVo(); + vo.setCandidateCount(candidateMapper.selectCount(new LambdaQueryWrapper() + .eq(ShopMatchShopCandidateEntity::getUserId, userId))); + Long processed = fileTaskMapper.selectCount(new LambdaQueryWrapper() + .eq(FileTaskEntity::getModuleType, MODULE_TYPE) + .eq(FileTaskEntity::getUserId, userId) + .in(FileTaskEntity::getStatus, List.of("SUCCESS", "FAILED"))); + Long success = fileTaskMapper.selectCount(new LambdaQueryWrapper() + .eq(FileTaskEntity::getModuleType, MODULE_TYPE) + .eq(FileTaskEntity::getUserId, userId) + .eq(FileTaskEntity::getStatus, "SUCCESS")); + Long failed = fileTaskMapper.selectCount(new LambdaQueryWrapper() + .eq(FileTaskEntity::getModuleType, MODULE_TYPE) + .eq(FileTaskEntity::getUserId, userId) + .eq(FileTaskEntity::getStatus, "FAILED")); + vo.setProcessedTaskCount(processed == null ? 0L : processed); + vo.setSuccessTaskCount(success == null ? 0L : success); + vo.setFailedTaskCount(failed == null ? 0L : failed); + return vo; + } + + public ProductRiskHistoryVo listHistory(Long userId) { + if (userId == null || userId <= 0) { + throw new BusinessException("user_id 不合法"); + } + ProductRiskHistoryVo vo = new ProductRiskHistoryVo(); + List entities = fileResultMapper.selectList(new LambdaQueryWrapper() + .eq(FileResultEntity::getModuleType, MODULE_TYPE) + .eq(FileResultEntity::getUserId, userId) + .orderByDesc(FileResultEntity::getCreatedAt) + .last("limit 100")); + Map statusByTaskId = new LinkedHashMap<>(); + List taskIds = entities.stream() + .map(FileResultEntity::getTaskId) + .filter(id -> id != null && id > 0) + .distinct() + .toList(); + if (!taskIds.isEmpty()) { + for (FileTaskEntity task : fileTaskMapper.selectBatchIds(taskIds)) { + if (task != null) { + statusByTaskId.put(task.getId(), task.getStatus()); + } + } + } + List items = new ArrayList<>(); + for (FileResultEntity entity : entities) { + items.add(toHistoryItemVo(entity, statusByTaskId.get(entity.getTaskId()))); + } + vo.setItems(items); + return vo; + } + + @Transactional + public void deleteHistory(Long resultId, Long userId) { + if (userId == null || userId <= 0) { + throw new BusinessException("user_id 不合法"); + } + 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); + if (taskId != null && taskId > 0) { + reconcileTaskAfterResultRemoval(taskId); + } + } + + @Transactional + public void deleteTask(Long taskId, Long userId) { + if (userId == null || userId <= 0) { + throw new BusinessException("user_id 不合法"); + } + FileTaskEntity task = fileTaskMapper.selectById(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); + shopMatchTaskCacheService.deleteTaskCache(taskId); + } + + private void reconcileTaskAfterResultRemoval(Long taskId) { + FileTaskEntity task = fileTaskMapper.selectById(taskId); + if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + return; + } + List latest = fileResultMapper.selectList(new LambdaQueryWrapper() + .eq(FileResultEntity::getTaskId, taskId) + .eq(FileResultEntity::getModuleType, MODULE_TYPE) + .orderByAsc(FileResultEntity::getId)); + if (latest.isEmpty()) { + fileTaskMapper.deleteById(taskId); + shopMatchTaskCacheService.deleteTaskCache(taskId); + return; + } + updateTaskStatusFromLatestRows(task, latest); + } + + public ProductRiskTaskBatchVo getTaskDetailsBatch(List taskIds) { + ProductRiskTaskBatchVo batch = new ProductRiskTaskBatchVo(); + if (taskIds == null || taskIds.isEmpty()) { + return batch; + } + for (Long taskId : taskIds) { + if (taskId == null || taskId <= 0) { + continue; + } + FileTaskEntity task = fileTaskMapper.selectById(taskId); + if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + batch.getMissingTaskIds().add(taskId); + continue; + } + batch.getItems().add(buildTaskDetail(task)); + } + 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 (entity.getResultFileUrl() == null || entity.getResultFileUrl().isBlank()) { + 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 entity.getResultFilename() != null && !entity.getResultFilename().isBlank() + ? entity.getResultFilename() + : safeFileStem(entity.getSourceFilename()) + ".xlsx"; + } + + @Transactional + public ProductRiskCreateTaskVo createTask(ProductRiskCreateTaskRequest request) { + if (request.getUserId() == null || request.getUserId() <= 0) { + throw new BusinessException("user_id 不合法"); + } + if (request.getItems() == null || request.getItems().isEmpty()) { + throw new BusinessException("items 不能为空"); + } + List uniqueItems = dedupeQueueItems(request.getItems()); + if (uniqueItems.isEmpty()) { + throw new BusinessException("items 不能为空"); + } + for (ProductRiskShopQueueItemVo item : uniqueItems) { + if (item == null || !item.isMatched()) { + throw new BusinessException("存在未匹配店铺,无法创建任务"); + } + } + + LocalDateTime now = LocalDateTime.now(); + LocalDateTime scheduledAt = request.getScheduleTime(); + if (scheduledAt != null && !scheduledAt.isAfter(now)) { + throw new BusinessException("schedule_time 必须晚于当前时间"); + } + + FileTaskEntity task = new FileTaskEntity(); + task.setTaskNo(MODULE_TYPE + "-" + IdUtil.getSnowflakeNextIdStr()); + task.setModuleType(MODULE_TYPE); + task.setTaskMode("PYTHON_QUEUE"); + task.setStatus(scheduledAt != null ? "SCHEDULED" : "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); + task.setScheduledAt(scheduledAt); + fileTaskMapper.insert(task); + + List snapshot = new ArrayList<>(); + for (ProductRiskShopQueueItemVo item : uniqueItems) { + String normalized = ziniaoShopSwitchService.normalizeShopName(item.getShopName()); + if (normalized.isBlank()) { + throw new BusinessException("店铺名无效"); + } + FileResultEntity result = new FileResultEntity(); + result.setTaskId(task.getId()); + result.setModuleType(MODULE_TYPE); + result.setSourceFilename(normalized); + result.setSourceFileUrl(item.getShopId()); + result.setUserId(request.getUserId()); + result.setSuccess(0); + result.setCreatedAt(LocalDateTime.now()); + fileResultMapper.insert(result); + snapshot.add(toSnapshotVo(result, item, task.getStatus())); + } + try { + task.setRequestJson(objectMapper.writeValueAsString(request)); + task.setResultJson(objectMapper.writeValueAsString(snapshot)); + } catch (Exception ex) { + throw new BusinessException("序列化任务数据失败"); + } + fileTaskMapper.updateById(task); + + ProductRiskCreateTaskVo vo = new ProductRiskCreateTaskVo(); + vo.setTaskId(task.getId()); + vo.setItems(snapshot); + return vo; + } + + @Transactional + public void activateTask(Long taskId, Long userId) { + if (taskId == null || taskId <= 0) { + throw new BusinessException("taskId 不合法"); + } + if (userId == null || userId <= 0) { + throw new BusinessException("user_id 不合法"); + } + FileTaskEntity task = fileTaskMapper.selectById(taskId); + if (task == null || !MODULE_TYPE.equals(task.getModuleType()) || !userId.equals(task.getUserId())) { + throw new BusinessException("任务不存在"); + } + if ("SUCCESS".equals(task.getStatus()) || "FAILED".equals(task.getStatus())) { + throw new BusinessException("任务已结束"); + } + if ("RUNNING".equals(task.getStatus())) { + return; + } + if (!"SCHEDULED".equals(task.getStatus())) { + throw new BusinessException("当前任务状态不允许激活"); + } + if (task.getScheduledAt() != null && LocalDateTime.now().isBefore(task.getScheduledAt())) { + throw new BusinessException("未到定时执行时间"); + } + task.setStatus("RUNNING"); + task.setUpdatedAt(LocalDateTime.now()); + fileTaskMapper.updateById(task); + } + + @Transactional + public void submitResult(Long taskId, ShopMatchSubmitResultRequest 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 = fileTaskMapper.selectById(taskId); + if (task == null || !MODULE_TYPE.equals(task.getModuleType())) { + throw new BusinessException("任务不存在"); + } + if ("SUCCESS".equals(task.getStatus()) || "FAILED".equals(task.getStatus())) { + throw new BusinessException("任务已结束,拒绝重复提交"); + } + + List resultRows = fileResultMapper.selectList(new LambdaQueryWrapper() + .eq(FileResultEntity::getTaskId, taskId) + .eq(FileResultEntity::getModuleType, MODULE_TYPE) + .orderByAsc(FileResultEntity::getId)); + Map payloadByShop = new LinkedHashMap<>(); + for (ShopMatchShopPayloadDto item : request.getShops()) { + if (item == null) { + continue; + } + String key = ziniaoShopSwitchService.normalizeShopName(item.getShopName()); + if (!key.isBlank()) { + payloadByShop.put(key, item); + } + } + File workRoot = FileUtil.mkdir(FileUtil.file(System.getProperty("java.io.tmpdir"), "shop-match-result", String.valueOf(taskId))); + + boolean changed = false; + for (FileResultEntity result : resultRows) { + String shopKey = result.getSourceFilename(); + ShopMatchShopPayloadDto incoming = payloadByShop.get(shopKey); + if (incoming == null) { + continue; + } + changed = true; + ShopMatchShopPayloadDto merged = mergeShopPayload(taskId, shopKey, incoming); + if (incoming.getError() != null && !incoming.getError().isBlank()) { + markResultFailed(result, incoming.getError().trim()); + shopMatchTaskCacheService.removeShopMergedPayload(taskId, shopKey); + continue; + } + if (!isShopPayloadCompleted(merged)) { + continue; + } + if (countPayloadRows(merged) <= 0) { + markResultFailed(result, "未收到可组装的结果数据"); + shopMatchTaskCacheService.removeShopMergedPayload(taskId, shopKey); + continue; + } + try { + assembleShopResult(result, shopKey, merged, workRoot); + shopMatchTaskCacheService.removeShopMergedPayload(taskId, shopKey); + } catch (Exception ex) { + markResultFailed(result, ex.getMessage() == null ? "assemble failed" : ex.getMessage()); + shopMatchTaskCacheService.removeShopMergedPayload(taskId, shopKey); + } + } + + if (!changed) { + return; + } + List latest = fileResultMapper.selectList(new LambdaQueryWrapper() + .eq(FileResultEntity::getTaskId, taskId) + .eq(FileResultEntity::getModuleType, MODULE_TYPE) + .orderByAsc(FileResultEntity::getId)); + updateTaskStatusFromLatestRows(task, latest); + } + + private void assembleShopResult(FileResultEntity result, String shopKey, ShopMatchShopPayloadDto payload, File workRoot) { + Map> countries = excelAssemblyService.normalizeCountriesMap(payload.getCountries()); + String displayName = payload.getShopName() != null && !payload.getShopName().isBlank() ? payload.getShopName().trim() : shopKey; + String stem = safeFileStem(displayName); + File xlsx = FileUtil.file(workRoot, stem + ".xlsx"); + try { + excelAssemblyService.writeWorkbook(xlsx, countries); + String objectKey = ossStorageService.uploadResultFile(xlsx, MODULE_TYPE); + result.setResultFilename(stem + ".xlsx"); + result.setResultFileUrl(objectKey); + result.setResultFileSize(xlsx.length()); + result.setResultContentType(CONTENT_TYPE_XLSX); + result.setRowCount(excelAssemblyService.countRows(countries)); + result.setSuccess(1); + result.setErrorMessage(null); + fileResultMapper.updateById(result); + } finally { + FileUtil.del(xlsx); + } + } + + private void markResultFailed(FileResultEntity result, String message) { + result.setSuccess(0); + result.setErrorMessage(message); + result.setResultFilename(null); + result.setResultFileUrl(null); + result.setResultFileSize(0L); + result.setRowCount(0); + result.setResultContentType(null); + fileResultMapper.updateById(result); + } + + private void updateTaskStatusFromLatestRows(FileTaskEntity task, List latest) { + int ok = 0; + int fail = 0; + List errors = new ArrayList<>(); + boolean allDone = true; + for (FileResultEntity row : latest) { + boolean success = row.getSuccess() != null && row.getSuccess() == 1; + boolean failed = row.getErrorMessage() != null && !row.getErrorMessage().isBlank(); + if (success) { + ok++; + } else if (failed) { + fail++; + errors.add(row.getSourceFilename() + ": " + row.getErrorMessage()); + } else { + allDone = false; + } + } + task.setSuccessFileCount(ok); + task.setFailedFileCount(fail); + task.setUpdatedAt(LocalDateTime.now()); + if (!allDone) { + task.setStatus("RUNNING"); + task.setErrorMessage(null); + task.setFinishedAt(null); + } else if (ok > 0 && fail == 0) { + task.setStatus("SUCCESS"); + task.setErrorMessage(null); + task.setFinishedAt(LocalDateTime.now()); + } else if (ok > 0) { + task.setStatus("SUCCESS"); + task.setErrorMessage(String.join("; ", errors)); + task.setFinishedAt(LocalDateTime.now()); + } else { + task.setStatus("FAILED"); + task.setErrorMessage(errors.isEmpty() ? "all shops failed" : String.join("; ", errors)); + task.setFinishedAt(LocalDateTime.now()); + } + try { + task.setResultJson(objectMapper.writeValueAsString(buildSnapshotFromDb(task.getId(), task.getStatus()))); + } catch (Exception ex) { + log.warn("[shop-match] compact result json failed: {}", ex.getMessage()); + } + fileTaskMapper.updateById(task); + if ("SUCCESS".equals(task.getStatus()) || "FAILED".equals(task.getStatus())) { + shopMatchTaskCacheService.deleteTaskCache(task.getId()); + } + } + + private ProductRiskTaskDetailVo buildTaskDetail(FileTaskEntity task) { + ProductRiskTaskDetailVo detail = new ProductRiskTaskDetailVo(); + detail.setTask(toTaskItemVo(task)); + List rows = fileResultMapper.selectList(new LambdaQueryWrapper() + .eq(FileResultEntity::getTaskId, task.getId()) + .eq(FileResultEntity::getModuleType, MODULE_TYPE) + .orderByAsc(FileResultEntity::getId)); + for (FileResultEntity row : rows) { + detail.getItems().add(toHistoryItemVo(row, task.getStatus())); + } + return detail; + } + + private List buildSnapshotFromDb(Long taskId, String taskStatus) { + List rows = fileResultMapper.selectList(new LambdaQueryWrapper() + .eq(FileResultEntity::getTaskId, taskId) + .eq(FileResultEntity::getModuleType, MODULE_TYPE) + .orderByAsc(FileResultEntity::getId)); + List items = new ArrayList<>(); + for (FileResultEntity row : rows) { + items.add(toHistoryItemVo(row, taskStatus)); + } + return items; + } + + private ProductRiskTaskItemVo toTaskItemVo(FileTaskEntity task) { + ProductRiskTaskItemVo vo = new ProductRiskTaskItemVo(); + vo.setId(task.getId()); + vo.setTaskNo(task.getTaskNo()); + vo.setStatus(task.getStatus()); + vo.setErrorMessage(task.getErrorMessage()); + vo.setCreatedAt(fmt(task.getCreatedAt())); + vo.setUpdatedAt(fmt(task.getUpdatedAt())); + vo.setFinishedAt(fmt(task.getFinishedAt())); + vo.setScheduledAt(fmt(task.getScheduledAt())); + return vo; + } + + private ProductRiskResultItemVo toSnapshotVo(FileResultEntity result, ProductRiskShopQueueItemVo item, String taskStatus) { + ProductRiskResultItemVo vo = new ProductRiskResultItemVo(); + 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.setScheduledAt(fmt(result.getTaskId() == null ? null : loadScheduledAt(result.getTaskId()))); + vo.setSuccess(false); + return vo; + } + + private ProductRiskResultItemVo toHistoryItemVo(FileResultEntity entity, String taskStatus) { + ProductRiskResultItemVo vo = new ProductRiskResultItemVo(); + vo.setResultId(entity.getId()); + vo.setTaskId(entity.getTaskId()); + vo.setShopName(entity.getSourceFilename()); + vo.setShopId(entity.getSourceFileUrl()); + vo.setTaskStatus(taskStatus); + vo.setSuccess(entity.getSuccess() != null && entity.getSuccess() == 1); + vo.setError(entity.getErrorMessage()); + vo.setOutputFilename(entity.getResultFilename()); + vo.setDownloadUrl(entity.getResultFileUrl() == null || entity.getResultFileUrl().isBlank() + ? null + : ossStorageService.generateFreshDownloadUrl(entity.getResultFileUrl())); + vo.setMatched(true); + if (entity.getTaskId() != null) { + vo.setScheduledAt(fmt(loadScheduledAt(entity.getTaskId()))); + } + if (entity.getTaskId() != null) { + mergeQueueFieldsFromRequest(vo, entity.getTaskId()); + } + return vo; + } + + private LocalDateTime loadScheduledAt(Long taskId) { + FileTaskEntity task = fileTaskMapper.selectById(taskId); + return task == null ? null : task.getScheduledAt(); + } + + private void mergeQueueFieldsFromRequest(ProductRiskResultItemVo vo, Long taskId) { + FileTaskEntity task = fileTaskMapper.selectById(taskId); + if (task == null || task.getRequestJson() == null || task.getRequestJson().isBlank()) { + return; + } + try { + ProductRiskCreateTaskRequest request = objectMapper.readValue(task.getRequestJson(), ProductRiskCreateTaskRequest.class); + String key = ziniaoShopSwitchService.normalizeShopName(vo.getShopName()); + for (ProductRiskShopQueueItemVo item : request.getItems()) { + if (item == null) { + continue; + } + if (key.equals(ziniaoShopSwitchService.normalizeShopName(item.getShopName()))) { + vo.setShopName(item.getShopName()); + vo.setShopId(item.getShopId()); + vo.setPlatform(item.getPlatform()); + vo.setCompanyName(item.getCompanyName()); + vo.setMatchStatus(item.getMatchStatus()); + vo.setMatchMessage(item.getMatchMessage()); + break; + } + } + } catch (Exception ignored) { + } + } + + private static String fmt(LocalDateTime time) { + return time == null ? null : time.toString(); + } + + private List dedupeQueueItems(List raw) { + Map byNorm = new LinkedHashMap<>(); + for (ProductRiskShopQueueItemVo item : raw) { + if (item == null) { + continue; + } + String key = ziniaoShopSwitchService.normalizeShopName(item.getShopName()); + if (!key.isBlank()) { + byNorm.putIfAbsent(key, item); + } + } + return new ArrayList<>(byNorm.values()); + } + + private static String safeFileStem(String shopName) { + String value = shopName == null ? "shop" : shopName.trim(); + if (value.isBlank()) { + value = "shop"; + } + return value.replaceAll("[\\\\/:*?\"<>|]", "_"); + } + + private ShopMatchShopPayloadDto mergeShopPayload(Long taskId, String shopKey, ShopMatchShopPayloadDto incoming) { + ShopMatchShopPayloadDto merged = shopMatchTaskCacheService.getShopMergedPayload(taskId, shopKey); + if (merged == null) { + merged = new ShopMatchShopPayloadDto(); + } + if (incoming.getShopName() != null && !incoming.getShopName().isBlank()) { + merged.setShopName(incoming.getShopName().trim()); + } else if (merged.getShopName() == null || merged.getShopName().isBlank()) { + merged.setShopName(shopKey); + } + if (incoming.getError() != null && !incoming.getError().isBlank()) { + merged.setError(incoming.getError().trim()); + } + Map> nextCountries = + merged.getCountries() == null ? new LinkedHashMap<>() : new LinkedHashMap<>(merged.getCountries()); + if (incoming.getCountries() != null && !incoming.getCountries().isEmpty()) { + for (Map.Entry> entry : incoming.getCountries().entrySet()) { + if (entry.getKey() == null || entry.getValue() == null || entry.getValue().isEmpty()) { + continue; + } + nextCountries.put(entry.getKey(), mergeCountryRows(nextCountries.get(entry.getKey()), entry.getValue())); + } + } + merged.setCountries(nextCountries); + shopMatchTaskCacheService.saveShopMergedPayload(taskId, shopKey, merged); + return merged; + } + + private List mergeCountryRows(List existingRows, List incomingRows) { + LinkedHashMap byKey = new LinkedHashMap<>(); + if (existingRows != null) { + for (ShopMatchRowDto row : existingRows) { + if (row != null) { + byKey.put(buildRowKey(row), cloneRow(row)); + } + } + } + for (ShopMatchRowDto row : incomingRows) { + if (row == null) { + continue; + } + if (Boolean.TRUE.equals(row.getDone()) && isEmptyBusinessRow(row) && !byKey.isEmpty()) { + for (Map.Entry entry : byKey.entrySet()) { + ShopMatchRowDto merged = mergeRow(entry.getValue(), row); + merged.setDone(Boolean.TRUE); + entry.setValue(merged); + } + continue; + } + String key = buildRowKey(row); + byKey.put(key, mergeRow(byKey.get(key), row)); + } + return new ArrayList<>(byKey.values()); + } + + private String buildRowKey(ShopMatchRowDto row) { + String asin = row == null || row.getAsin() == null ? "" : row.getAsin().trim().toUpperCase(Locale.ROOT); + return asin.isBlank() ? "row:" + java.util.UUID.randomUUID() : "asin:" + asin; + } + + private ShopMatchRowDto mergeRow(ShopMatchRowDto previous, ShopMatchRowDto incoming) { + if (previous == null) { + return cloneRow(incoming); + } + ShopMatchRowDto merged = cloneRow(previous); + if (incoming.getAsin() != null && !incoming.getAsin().isBlank()) { + merged.setAsin(incoming.getAsin()); + } + if (incoming.getStatus() != null && !incoming.getStatus().isBlank()) { + merged.setStatus(incoming.getStatus()); + } + merged.setDone(incoming.getDone() != null ? incoming.getDone() : merged.getDone()); + return merged; + } + + private ShopMatchRowDto cloneRow(ShopMatchRowDto row) { + ShopMatchRowDto out = new ShopMatchRowDto(); + if (row != null) { + out.setAsin(row.getAsin()); + out.setStatus(row.getStatus()); + out.setDone(row.getDone()); + } + return out; + } + + private boolean isShopPayloadCompleted(ShopMatchShopPayloadDto payload) { + return countPayloadRows(payload) > 0 && payloadHasAnyDoneTrue(payload); + } + + private int countPayloadRows(ShopMatchShopPayloadDto payload) { + if (payload == null || payload.getCountries() == null || payload.getCountries().isEmpty()) { + return 0; + } + int count = 0; + for (List rows : payload.getCountries().values()) { + if (rows == null) { + continue; + } + for (ShopMatchRowDto row : rows) { + if (row != null && !isEmptyBusinessRow(row)) { + count++; + } + } + } + return count; + } + + private boolean payloadHasAnyDoneTrue(ShopMatchShopPayloadDto payload) { + if (payload == null || payload.getCountries() == null) { + return false; + } + for (List rows : payload.getCountries().values()) { + if (rows == null) { + continue; + } + for (ShopMatchRowDto row : rows) { + if (row != null && Boolean.TRUE.equals(row.getDone())) { + return true; + } + } + } + return false; + } + + private boolean isEmptyBusinessRow(ShopMatchRowDto row) { + return row == null || row.getAsin() == null || row.getAsin().trim().isEmpty(); + } +} diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/task/model/entity/FileTaskEntity.java b/backend-java/src/main/java/com/nanri/aiimage/modules/task/model/entity/FileTaskEntity.java index 15f574d60..f83cad32c 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/task/model/entity/FileTaskEntity.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/task/model/entity/FileTaskEntity.java @@ -28,4 +28,5 @@ public class FileTaskEntity { private LocalDateTime createdAt; private LocalDateTime updatedAt; private LocalDateTime finishedAt; + private LocalDateTime scheduledAt; } 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 60df370af..dad61373a 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 @@ -280,13 +280,14 @@ public class ZiniaoShopIndexService { roundEntries.add(entryToStore); } Map byShopId = new LinkedHashMap<>(); - Map byNameOnly = new LinkedHashMap<>(); + Map byNameAlias = new LinkedHashMap<>(); for (ZiniaoShopIndexEntryDto e : roundEntries) { String sid = e.getShopId(); if (sid != null && !sid.isBlank()) { byShopId.merge(sid, e, this::mergeDuplicateShopIndexEntries); - } else if (e.getNormalizedShopName() != null && !e.getNormalizedShopName().isBlank()) { - byNameOnly.merge(e.getNormalizedShopName(), e, this::mergeDuplicateShopIndexEntries); + } + if (e.getNormalizedShopName() != null && !e.getNormalizedShopName().isBlank()) { + byNameAlias.merge(e.getNormalizedShopName(), e, this::mergeDuplicateShopIndexEntries); } } Set activeCacheKeys = new HashSet<>(); @@ -295,14 +296,20 @@ public class ZiniaoShopIndexService { activeCacheKeys.add(key); ziniaoMemoryStoreService.put(ZiniaoMemoryStoreService.CACHE_TYPE_SHOP_INDEX_ENTRY, key, e, resolveEntryTtl()); } - for (ZiniaoShopIndexEntryDto e : byNameOnly.values()) { + for (ZiniaoShopIndexEntryDto e : byNameAlias.values()) { String key = SHOP_ENTRY_KEY_NAME_PREFIX + e.getNormalizedShopName(); activeCacheKeys.add(key); ziniaoMemoryStoreService.put(ZiniaoMemoryStoreService.CACHE_TYPE_SHOP_INDEX_ENTRY, key, e, resolveEntryTtl()); } - log.info("[ziniao-index] refresh persist shopIndex uniqueShopId={} nameOnly={} groupedNames={} activeRows={}", - byShopId.size(), byNameOnly.size(), grouped.size(), activeCacheKeys.size()); - markMissingEntriesAsStale(activeCacheKeys, now); + log.info("[ziniao-index] refresh persist shopIndex uniqueShopId={} nameAlias={} groupedNames={} activeRows={}", + byShopId.size(), byNameAlias.size(), grouped.size(), activeCacheKeys.size()); + boolean fullRefresh = apiKeyAccounts.size() >= allApiKeyAccounts.size(); + if (fullRefresh) { + markMissingEntriesAsStale(activeCacheKeys, now); + } else { + log.info("[ziniao-index] skip stale marking for partial refresh processedApiKeys={}/{} nextOffset={}", + apiKeyAccounts.size(), allApiKeyAccounts.size(), nextOffset); + } cursor.setStatus("SUCCESS"); cursor.setMessage(allInvalidUserIds.isEmpty() diff --git a/backend-java/src/main/resources/application.yml b/backend-java/src/main/resources/application.yml index ebccbeceb..4113b6dd8 100644 --- a/backend-java/src/main/resources/application.yml +++ b/backend-java/src/main/resources/application.yml @@ -12,7 +12,7 @@ spring: max-request-size: 500MB datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: ${AIIMAGE_DB_URL:jdbc:mysql://127.0.0.1:3306/aiimage?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false} + url: ${AIIMAGE_DB_URL:jdbc:mysql://127.0.0.1:3306/aiimage?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true} username: ${AIIMAGE_DB_USERNAME:root} password: ${AIIMAGE_DB_PASSWORD:change-me} hikari: @@ -60,6 +60,7 @@ knife4j: language: zh_cn aiimage: + instance-id: ${AIIMAGE_INSTANCE_ID:} oss: region: ${AIIMAGE_OSS_REGION:cn-hangzhou} endpoint: ${AIIMAGE_OSS_ENDPOINT:oss-cn-hangzhou.aliyuncs.com} @@ -82,10 +83,11 @@ aiimage: stale-check-cron: ${AIIMAGE_DELETE_BRAND_STALE_CHECK_CRON:*/30 * * * * *} finalize-check-cron: ${AIIMAGE_DELETE_BRAND_FINALIZE_CHECK_CRON:30 */2 * * * *} product-risk-stale-timeout-minutes: ${AIIMAGE_PRODUCT_RISK_STALE_TIMEOUT_MINUTES:10} + product-risk-initial-timeout-minutes: ${AIIMAGE_PRODUCT_RISK_INITIAL_TIMEOUT_MINUTES:10} 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} + module-types: ${AIIMAGE_MODULE_CLEANUP_MODULE_TYPES:DEDUPE,SPLIT,CONVERT,DELETE_BRAND,PRODUCT_RISK_RESOLVE,SHOP_MATCH} 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/V17__shop_match_shop_candidate.sql b/backend-java/src/main/resources/db/V17__shop_match_shop_candidate.sql new file mode 100644 index 000000000..a1d494a4e --- /dev/null +++ b/backend-java/src/main/resources/db/V17__shop_match_shop_candidate.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS biz_shop_match_shop_candidate ( + id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键', + user_id BIGINT NOT NULL COMMENT '用户 ID', + shop_name VARCHAR(255) NOT NULL COMMENT '店铺名称(已规范化)', + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + UNIQUE KEY uk_user_shop (user_id, shop_name), + KEY idx_user_id (user_id) +) COMMENT='匹配店铺-用户备选店铺'; diff --git a/backend-java/src/main/resources/db/V18__shop_match_country_pref.sql b/backend-java/src/main/resources/db/V18__shop_match_country_pref.sql new file mode 100644 index 000000000..f965868aa --- /dev/null +++ b/backend-java/src/main/resources/db/V18__shop_match_country_pref.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS biz_shop_match_country_pref ( + user_id BIGINT NOT NULL PRIMARY KEY COMMENT '用户 ID', + country_codes_json VARCHAR(256) NOT NULL COMMENT 'JSON 数组,按处理顺序保存国家代码', + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' +) COMMENT='匹配店铺-用户国家偏好'; diff --git a/backend-java/src/main/resources/db/V19__file_task_scheduled_at.sql b/backend-java/src/main/resources/db/V19__file_task_scheduled_at.sql new file mode 100644 index 000000000..be6be9253 --- /dev/null +++ b/backend-java/src/main/resources/db/V19__file_task_scheduled_at.sql @@ -0,0 +1,2 @@ +ALTER TABLE biz_file_task + ADD COLUMN scheduled_at DATETIME NULL COMMENT '定时执行时间' AFTER finished_at; diff --git a/frontend-vue/shop-match.html b/frontend-vue/shop-match.html new file mode 100644 index 000000000..6a118f507 --- /dev/null +++ b/frontend-vue/shop-match.html @@ -0,0 +1,12 @@ + + + + + + 匹配店铺 - 数富AI + + +
+ + + diff --git a/frontend-vue/src/pages/brand/components/BrandShopMatchTab.vue b/frontend-vue/src/pages/brand/components/BrandShopMatchTab.vue new file mode 100644 index 000000000..23ee18384 --- /dev/null +++ b/frontend-vue/src/pages/brand/components/BrandShopMatchTab.vue @@ -0,0 +1,1582 @@ + + + + + diff --git a/frontend-vue/src/pages/brand/components/BrandTopBar.vue b/frontend-vue/src/pages/brand/components/BrandTopBar.vue index 77b0e9682..04ffa36cb 100644 --- a/frontend-vue/src/pages/brand/components/BrandTopBar.vue +++ b/frontend-vue/src/pages/brand/components/BrandTopBar.vue @@ -38,7 +38,7 @@