refactor(auth):重构认证服务并移除冗余代码

- 移除了 AuthServiceImpl 中的登录、注册、token 验证等方法,仅保留错误上报和客户端信息功能
- 删除了设备注册和离线通知相关逻辑
- 移除了 IAuthService 接口中的登录、注册、验证 token 等方法定义
- 清理了 AccountManager.vue 中的无关注释文字-优化了阿里巴巴1688 服务中的图片上传处理逻辑- 移除了 AmazonScrapingServiceImpl 中未使用的日志导入和空行
- 统一了 Vue 组件中的同步导入方式,替换异步组件定义
- 更新了应用配置文件中的服务器地址和懒加载设置
- 新增缓存管理服务用于统一清理各类缓存数据
- 优化了设备 IP 地址获取逻辑并在注册时传递给后端- 调整了构建配置以减小安装包体积并支持多语言
- 修改了主进程窗口加载逻辑以适配开发与生产环境- 添加了全局样式限制图片预览器尺寸
- 移除了设备 ID 测试类和部分无用的正则表达式导入
This commit is contained in:
2025-10-20 18:01:40 +08:00
parent 0c85aa5677
commit 17f03c3ade
27 changed files with 517 additions and 535 deletions

View File

@@ -7,7 +7,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
@Slf4j
@SpringBootApplication
@SpringBootApplication(
exclude = {
org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration.class,
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration.class
}
)
public class ErpClientSbApplication {
public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = SpringApplication.run(ErpClientSbApplication.class, args);
@@ -16,10 +21,8 @@ public class ErpClientSbApplication {
log.error("捕获到未处理异常: " + ex.getMessage(), ex);
errorReporter.reportSystemError("未捕获异常: " + thread.getName(), (Exception) ex);
});
log.info("Started Success");
ResourcePreloader.init();
ResourcePreloader.preloadErpDashboard();
ResourcePreloader.executePreloading();
}
}

View File

@@ -59,8 +59,6 @@ public class RakutenController {
}
List<RakutenProduct> allProducts = new ArrayList<>();
List<String> skippedShops = new ArrayList<>();
// 2. 遍历店铺,优先缓存,缺失则爬取
for (String currentShopName : shopNames) {
if (rakutenCacheService.hasRecentData(currentShopName)) {
// 从缓存获取
@@ -87,7 +85,6 @@ public class RakutenController {
if (cachedCount > 0) {
dataReportUtil.reportDataCollection("RAKUTEN_CACHE", cachedCount, "0");
}
return JsonData.buildSuccess(Map.of("products", allProducts, "total", allProducts.size(), "sessionId", batchId, "skippedShops", skippedShops, "newProductsCount", newProducts.size()));
} catch (Exception e) {
log.error("获取乐天商品失败", e);
@@ -127,24 +124,6 @@ public class RakutenController {
}
// 解析 skuPriceJson 或 skuPrice 字段中的价格键,返回从小到大排序的价格列表
private static List<Double> parseSkuPriceList(Object skuPriceJson, Object skuPrice) {
String src = skuPriceJson != null ? String.valueOf(skuPriceJson) : (skuPrice != null ? String.valueOf(skuPrice) : null);
if (src == null || src.isEmpty()) return Collections.emptyList();
try {
Pattern pattern = Pattern.compile("(\\d+(?:\\.\\d+)?)\\s*:");
Matcher m = pattern.matcher(src);
List<Double> prices = new ArrayList<>();
while (m.find()) {
String num = m.group(1);
try { prices.add(Double.parseDouble(num)); } catch (NumberFormatException ignored) {}
}
Collections.sort(prices);
return prices;
} catch (Exception ignored) {
return Collections.emptyList();
}
}
}

View File

@@ -2,7 +2,8 @@ package com.tashow.erp.controller;
import com.tashow.erp.entity.AuthTokenEntity;
import com.tashow.erp.repository.AuthTokenRepository;
import com.tashow.erp.service.IGenmaiService;
import com.tashow.erp.service.impl.CacheManagementServiceImpl;
import com.tashow.erp.service.impl.GenmaiServiceImpl;
import com.tashow.erp.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -25,7 +26,10 @@ public class SystemController {
private AuthTokenRepository authTokenRepository;
@Autowired
private IGenmaiService genmaiService;
private GenmaiServiceImpl genmaiService;
@Autowired
private CacheManagementServiceImpl cacheManagementService;
@Autowired
private RestTemplate restTemplate;
@@ -87,6 +91,19 @@ public class SystemController {
return JsonData.buildSuccess(deviceId);
}
/**
* 获取本机内网IP地址
*/
@GetMapping("/local-ip")
public JsonData getLocalIp() {
try {
java.net.InetAddress localHost = java.net.InetAddress.getLocalHost();
return JsonData.buildSuccess(localHost.getHostAddress());
} catch (Exception e) {
return JsonData.buildSuccess("127.0.0.1");
}
}
// ==================== 版本信息 ====================
/**
@@ -165,5 +182,20 @@ public class SystemController {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
// ==================== 缓存管理 ====================
/**
* 清理缓存
*/
@PostMapping("/cache/clear")
public JsonData clearCache() {
try {
cacheManagementService.clearCache();
return JsonData.buildSuccess("缓存清理成功");
} catch (Exception e) {
return JsonData.buildError("清理缓存失败: " + e.getMessage());
}
}
}

View File

@@ -9,7 +9,6 @@ import com.tashow.erp.service.Alibaba1688Service;
import com.tashow.erp.utils.Alibaba1688CookieUtil;
import com.tashow.erp.utils.ErrorReporter;
import com.tashow.erp.utils.QiniuUtil;
import org.openqa.selenium.chrome.ChromeDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,8 +26,6 @@ import java.io.IOException;
import java.net.HttpURLConnection;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 1688识图搜索服务
@@ -42,7 +39,6 @@ public class Alibaba1688ServiceImpl implements Alibaba1688Service {
private final RestTemplate noSslRestTemplate = createNoSslRestTemplate();
@Autowired
private ErrorReporter errorReporter;
private RestTemplate createNoSslRestTemplate() {
try {
TrustManager[] trustManagers = new TrustManager[] {
@@ -56,7 +52,6 @@ public class Alibaba1688ServiceImpl implements Alibaba1688Service {
sslContext.init(null, trustManagers, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory() {
@Override
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
@@ -73,15 +68,12 @@ public class Alibaba1688ServiceImpl implements Alibaba1688Service {
return new RestTemplate();
}
}
/**
* 通过1688 API获取商品详情链接价格
* @return
*/
@Override
public SearchResult get1688Detail(String uploadedUrl) {
uploadedUrl = uploadedUrl.split("\\?")[0];
String fileName = "temp_" + System.currentTimeMillis() + ".png";
List<String> detailUrls = new ArrayList<>();
SearchResult result = new SearchResult();
@@ -119,14 +111,12 @@ public class Alibaba1688ServiceImpl implements Alibaba1688Service {
.filter(fee -> fee > 0)
.ifPresent(freight::add);
}
offerIterator = null;
for (int retry = 0; retry < 3 && (offerIterator == null || !offerIterator.hasNext()); retry++) {
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
JsonNode root = objectMapper.readTree(response.getBody());
offerIterator = root.path("data").path("offerList").path("offers").elements();
}
for (int i = 0; i < 10 && offerIterator.hasNext(); i++) {
JsonNode offer = offerIterator.next();
String offerId = offer.path("id").asText();
@@ -160,7 +150,7 @@ public class Alibaba1688ServiceImpl implements Alibaba1688Service {
result.setSkuPrice(skuPrices);
result.setMedian( median);
result.setMapRecognitionLink( uploadImageBase64(imageUrl));
result.setMapRecognitionLink( uploadImageBase64(uploadedUrl));
result.setFreight(freightFee.isEmpty() ? 0.0 : freightFee.get(Math.max(0, freightFee.size()/2-1)));
// String weight = getWeight(detailUrls);
// result.setWeight(weight);
@@ -238,7 +228,6 @@ public class Alibaba1688ServiceImpl implements Alibaba1688Service {
if (priceNode.isNumber() && priceNode.asDouble() > 0) {
return priceNode.asDouble();
}
// 如果price是数组且有元素检查第一个元素
if (priceNode.isArray() && priceNode.size() > 0) {
JsonNode firstPrice = priceNode.get(0);
@@ -284,6 +273,4 @@ public class Alibaba1688ServiceImpl implements Alibaba1688Service {
JSONObject json = JSON.parseObject(response.getBody());
return "https://s.1688.com/youyuan/index.htm?tab=imageSearch&imageId=" + json.getJSONObject("data").getString("imageId");
}
}

View File

@@ -1,13 +1,9 @@
package com.tashow.erp.service.impl;
import com.tashow.erp.entity.AmazonProductEntity;
import com.tashow.erp.repository.AmazonProductRepository;
import com.tashow.erp.service.IAmazonScrapingService;
import com.tashow.erp.utils.DataReportUtil;
import com.tashow.erp.utils.ErrorReporter;
import com.tashow.erp.utils.RakutenProxyUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import us.codecraft.webmagic.Page;
@@ -15,11 +11,9 @@ import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.selector.Html;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* 亚马逊数据采集服务实现类
*
@@ -38,7 +32,6 @@ public class AmazonScrapingServiceImpl implements IAmazonScrapingService, PagePr
private static final Object spiderLock = new Object();
private final Map<String, AmazonProductEntity> resultCache = new ConcurrentHashMap<>();
private Site site;
/**
* 处理亚马逊页面数据提取
*/
@@ -46,15 +39,12 @@ public class AmazonScrapingServiceImpl implements IAmazonScrapingService, PagePr
public void process(Page page) {
Html html = page.getHtml();
String url = page.getUrl().toString();
// 提取ASIN
String asin = html.xpath("//input[@id='ASIN']/@value").toString();
if (isEmpty(asin)) {
String[] parts = url.split("/dp/");
if (parts.length > 1) asin = parts[1].split("/")[0].split("\\?")[0];
}
// 提取价格
String priceSymbol = html.xpath("//span[@class='a-price-symbol']/text()").toString();
String priceWhole = html.xpath("//span[@class='a-price-whole']/text()").toString();
@@ -82,7 +72,6 @@ public class AmazonScrapingServiceImpl implements IAmazonScrapingService, PagePr
entity.setAsin(asin != null ? asin : "");
entity.setPrice(price);
entity.setSeller(seller);
resultCache.put(asin, entity);
page.putField("entity", entity);
}
@@ -138,7 +127,6 @@ public class AmazonScrapingServiceImpl implements IAmazonScrapingService, PagePr
allProducts.put(cleanAsin, entity);
}
}
return new ArrayList<>(allProducts.values());
}
@@ -155,7 +143,6 @@ public class AmazonScrapingServiceImpl implements IAmazonScrapingService, PagePr
}
return "https://www.amazon.co.jp/dp/" + asin;
}
/**
* 根据地区配置Site
*/

View File

@@ -1,4 +1,5 @@
package com.tashow.erp.service.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tashow.erp.service.IAuthService;
@@ -8,13 +9,13 @@ import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
import jakarta.annotation.PostConstruct;
/**
* 认证服务实现类 - 简化版
* 提供基础的登录、注册、token验证功能
* 提供错误上报和客户端信息获取功能
*/
@Service
public class AuthServiceImpl implements IAuthService {
@@ -25,72 +26,8 @@ public class AuthServiceImpl implements IAuthService {
@Autowired
private ApiForwarder apiForwarder;
@Autowired
private com.tashow.erp.repository.CacheDataRepository cacheDataRepository;
@Getter
private String clientId = DeviceUtils.generateDeviceId();
private String accessToken;
private String refreshToken;
/**
* 应用启动时从SQLite恢复token
*/
@PostConstruct
private void initTokenFromCache() {
try {
cacheDataRepository.findByCacheKey("token").ifPresent(entity ->
accessToken = entity.getCacheValue()
);
} catch (Exception ignored) {}
}
/**
* 保存token到SQLite
*/
private void saveTokenToCache(String token) {
try {
com.tashow.erp.entity.CacheDataEntity entity = cacheDataRepository.findByCacheKey("token")
.orElse(new com.tashow.erp.entity.CacheDataEntity());
entity.setCacheKey("token");
entity.setCacheValue(token);
cacheDataRepository.save(entity);
} catch (Exception ignored) {}
}
/**
* 客户端登录认证
*/
@Override
public Map<String, Object> login(String username, String password) {
Map<String, Object> result = new HashMap<>();
Map<String, Object> loginData = new HashMap<>();
loginData.put("username", username);
loginData.put("password", password);
loginData.putAll(getClientInfo());
JsonNode response = sendPostRequest("/monitor/account/login", loginData);
if (response.has("code") && response.get("code").asInt() == 200) {
JsonNode data = response.has("data") ? response.get("data") : response;
accessToken = data.has("accessToken") ? data.get("accessToken").asText() :
data.has("token") ? data.get("token").asText() : null;
refreshToken = data.has("refreshToken") ? data.get("refreshToken").asText() : null;
if (accessToken != null) {
saveTokenToCache(accessToken);
registerDeviceOnLogin(username);
}
result.put("success", true);
result.put("message", "登录成功");
result.put("token", accessToken);
result.put("permissions", data.has("permissions") ? data.get("permissions").asText() : null);
} else {
result.put("success", false);
result.put("message", response.has("msg") ? response.get("msg").asText() : "登录失败");
}
return result;
}
/**
* 获取客户端基本信息
@@ -114,161 +51,10 @@ public class AuthServiceImpl implements IAuthService {
errorData.put("clientId", clientId);
errorData.put("errorType", errorType);
errorData.put("errorMessage", errorMessage);
sendPostRequest("/monitor/error", errorData);
} catch (Exception ignored) {}
}
/**
* 检查版本更新
*/
@Override
public String checkVersion(String currentVersion) {
JsonNode response = sendGetRequest("/monitor/version?currentVersion=" + currentVersion);
return response.toString();
}
/**
* 发送POST请求
*/
private JsonNode sendPostRequest(String path, Map<String, Object> data){
if (data != null) {
data.putIfAbsent("_clientUser", System.getProperty("user.name"));
data.putIfAbsent("_clientOs", System.getProperty("os.name"));
errorData.putIfAbsent("_clientUser", System.getProperty("user.name"));
errorData.putIfAbsent("_clientOs", System.getProperty("os.name"));
apiForwarder.post("/monitor/error", errorData, null);
} catch (Exception ignored) {
}
org.springframework.http.ResponseEntity<?> resp = apiForwarder.post(path, data, buildAuthHeader());
return objectMapper.valueToTree(resp.getBody());
}
/**
* 发送GET请求
*/
private JsonNode sendGetRequest(String path){
org.springframework.http.ResponseEntity<?> resp = apiForwarder.get(path, buildAuthHeader());
return objectMapper.valueToTree(resp.getBody());
}
/**
* 构建认证头
*/
private String buildAuthHeader(){
return (accessToken == null || accessToken.isEmpty()) ? null : ("Bearer " + accessToken.trim());
}
/**
* 验证token
*/
@Override
public Map<String, Object> verifyToken(String token) {
Map<String, Object> result = new HashMap<>();
Map<String, Object> verifyData = new HashMap<>();
verifyData.put("token", token);
JsonNode response = sendPostRequest("/monitor/account/verify", verifyData);
if (response.has("code") && response.get("code").asInt() == 200) {
JsonNode dataNode = response.has("data") ? response.get("data") : response;
result.put("success", true);
result.put("username", dataNode.get("username").asText());
result.put("permissions", dataNode.get("permissions").asText());
} else {
result.put("success", false);
result.put("message", "token验证失败");
}
return result;
}
/**
* 注册新账号
*/
@Override
public Map<String, Object> register(String username, String password) {
Map<String, Object> result = new HashMap<>();
try {
Map<String, Object> registerData = new HashMap<>();
registerData.put("accountName", username);
registerData.put("username", username);
registerData.put("password", password);
registerData.putAll(getClientInfo());
JsonNode response = sendPostRequest("/monitor/account/register", registerData);
if (response.has("code") && response.get("code").asInt() == 200) {
JsonNode data = response.has("data") ? response.get("data") : response;
String newAccessToken = data.has("accessToken") ? data.get("accessToken").asText() : null;
String newRefreshToken = data.has("refreshToken") ? data.get("refreshToken").asText() : null;
if (newAccessToken != null) {
accessToken = newAccessToken;
refreshToken = newRefreshToken;
saveTokenToCache(newAccessToken);
registerDeviceOnLogin(username);
}
result.put("success", true);
result.put("message", "注册成功");
} else {
String errorMessage = response.has("msg") ? response.get("msg").asText() :
(response.has("message") ? response.get("message").asText() : "注册失败");
result.put("success", false);
result.put("message", errorMessage);
}
} catch (Exception e) {
result.put("success", false);
result.put("message", "注册失败:" + e.getMessage());
}
return result;
}
/**
* 检查用户名是否可用
*/
@Override
public boolean checkUsername(String username) {
try {
JsonNode response = sendGetRequest("/monitor/account/check-username?username=" + username);
if (response.has("code") && response.get("code").asInt() == 200) {
JsonNode dataNode = response.has("data") ? response.get("data") : response;
return dataNode.asBoolean();
}
} catch (Exception ignored) {}
return false;
}
/**
* 退出登录清除本地token
*/
public void logout() {
try {
// 通知服务器设备离线
setDeviceOffline();
// 清除内存中的token
accessToken = null;
refreshToken = null;
// 删除SQLite中的token缓存
cacheDataRepository.deleteByCacheKey("token");
} catch (Exception ignored) {}
}
/**
* 登录时注册设备
*/
private void registerDeviceOnLogin(String username) {
try {
Map<String, Object> deviceData = new HashMap<>();
deviceData.put("username", username);
deviceData.put("deviceId", clientId);
deviceData.put("os", System.getProperty("os.name"));
apiForwarder.post("/monitor/device/register", deviceData, buildAuthHeader());
} catch (Exception ignored) {}
}
/**
* 设备离线
*/
private void setDeviceOffline() {
try {
Map<String, Object> offlineData = new HashMap<>();
offlineData.put("deviceId", clientId);
apiForwarder.post("/monitor/device/offline", offlineData, buildAuthHeader());
} catch (Exception ignored) {}
}
}

View File

@@ -2,14 +2,13 @@ package com.tashow.erp.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tashow.erp.entity.BanmaOrderEntity;
import com.tashow.erp.repository.BanmaOrderRepository;
import com.tashow.erp.service.ICacheService;
import com.tashow.erp.service.IBanmaOrderService;
import com.tashow.erp.utils.DataReportUtil;
import com.tashow.erp.utils.ErrorReporter;
import com.tashow.erp.utils.LoggerUtil;
import com.tashow.erp.utils.SagawaExpressSdk;
import com.tashow.erp.utils.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
@@ -25,16 +24,17 @@ import java.util.stream.Collectors;
* @author ruoyi
*/
@Service
public class BanmaOrderServiceImpl implements IBanmaOrderService {
public class BanmaOrderServiceImpl {
private static final Logger logger = LoggerUtil.getLogger(BanmaOrderServiceImpl.class);
private static final String SERVICE_NAME = "banma";
private static final String RUOYI_ADMIN_BASE = "http://192.168.1.89:8085";
private static final String API_URL = "https://banma365.cn/api/order/list?%srecipientName=&page=%d&size=%d&markFlag=0&state=4&_t=%d";
private static final String API_URL_WITH_TIME = "https://banma365.cn/api/order/list?%srecipientName=&page=%d&size=%d&markFlag=0&state=4&orderedAtStart=%s&orderedAtEnd=%s&_t=%d";
private static final String TRACKING_URL = "https://banma365.cn/zebraExpressHub/web/tracking/getByExpressNumber/%s";
@Value("${api.server.base-url}")
private String ruoyiAdminBase;
private RestTemplate restTemplate;
private final ObjectMapper objectMapper = new ObjectMapper();
private final ICacheService cacheService;
private final CacheServiceImpl cacheService;
private final BanmaOrderRepository banmaOrderRepository;
private final DataReportUtil dataReportUtil;
private final ErrorReporter errorReporter;
@@ -44,7 +44,7 @@ public class BanmaOrderServiceImpl implements IBanmaOrderService {
private String currentBatchSessionId = null;
// 物流信息缓存,避免重复查询
private final Map<String, String> trackingInfoCache = new ConcurrentHashMap<>();
public BanmaOrderServiceImpl(BanmaOrderRepository banmaOrderRepository, ICacheService cacheService, DataReportUtil dataReportUtil, ErrorReporter errorReporter) {
public BanmaOrderServiceImpl(BanmaOrderRepository banmaOrderRepository, CacheServiceImpl cacheService, DataReportUtil dataReportUtil, ErrorReporter errorReporter) {
this.banmaOrderRepository = banmaOrderRepository;
this.cacheService = cacheService;
this.dataReportUtil = dataReportUtil;
@@ -56,7 +56,7 @@ public class BanmaOrderServiceImpl implements IBanmaOrderService {
}
@SuppressWarnings("unchecked")
private void fetchTokenFromServer(Long accountId) {
Map<String, Object> resp = restTemplate.getForObject(RUOYI_ADMIN_BASE + "/tool/banma/accounts", Map.class);
Map<String, Object> resp = restTemplate.getForObject(ruoyiAdminBase + "/tool/banma/accounts", Map.class);
List<Map<String, Object>> list = (List<Map<String, Object>>) resp.get("data");
if (list == null || list.isEmpty()) return;
Map<String, Object> account = accountId != null

View File

@@ -0,0 +1,48 @@
package com.tashow.erp.service.impl;
import com.tashow.erp.repository.*;
import com.tashow.erp.service.ICacheManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* 缓存管理服务实现
*/
@Service
public class CacheManagementServiceImpl implements ICacheManagementService {
@Autowired
private RakutenProductRepository rakutenProductRepository;
@Autowired
private AmazonProductRepository amazonProductRepository;
@Autowired
private Alibaba1688ProductRepository alibaba1688ProductRepository;
@Autowired
private ZebraOrderRepository zebraOrderRepository;
@Autowired
private BanmaOrderRepository banmaOrderRepository;
@Autowired
private CacheDataRepository cacheDataRepository;
@Autowired
private UpdateStatusRepository updateStatusRepository;
@Override
@Transactional
public void clearCache() {
rakutenProductRepository.deleteAll();
amazonProductRepository.deleteAll();
alibaba1688ProductRepository.deleteAll();
zebraOrderRepository.deleteAll();
banmaOrderRepository.deleteAll();
cacheDataRepository.deleteAll();
updateStatusRepository.deleteAll();
}
}

View File

@@ -46,10 +46,8 @@ public class RakutenScrapingServiceImpl implements RakutenScrapingService {
public List<RakutenProduct> scrapeProductsWithSearch(String shopName) {
String url = "https://ranking.rakuten.co.jp/search?stx=" + URLEncoder.encode(shopName, StandardCharsets.UTF_8);
List<RakutenProduct> products = new ArrayList<>();
Spider spider = Spider.create(new RakutenPageProcessor(products, errorReporter)).addUrl(url).setDownloader(new RakutenProxyUtil().createProxyDownloader(new RakutenProxyUtil().detectSystemProxy(url))).thread(1);
spider.run();
log.info("采集完成,店铺: {},数量: {}", shopName, products.size());
return products;
}
@@ -57,7 +55,6 @@ public class RakutenScrapingServiceImpl implements RakutenScrapingService {
private class RakutenPageProcessor implements PageProcessor {
private final List<RakutenProduct> products;
private final ErrorReporter errorReporter;
RakutenPageProcessor(List<RakutenProduct> products, ErrorReporter errorReporter) {
this.products = products;
this.errorReporter = errorReporter;
@@ -129,8 +126,6 @@ public class RakutenScrapingServiceImpl implements RakutenScrapingService {
product.setMedian(searchResult.getMedian());
product.setWeight(searchResult.getWeight());
product.setSkuPriceJson(JSON.toJSONString(searchResult.getSkuPrice()));
}).collect(Collectors.toList());
if (!matchingProducts.isEmpty()) {
rakutenProductRepository.saveAll(matchingProducts);

View File

@@ -8,6 +8,8 @@ javafx:
# resizable: false
spring:
main:
lazy-initialization: false
datasource:
url: jdbc:sqlite:./data/erp-cache.db?journal_mode=WAL&synchronous=NORMAL&cache_size=10000&temp_store=memory&busy_timeout=30000
driver-class-name: org.sqlite.JDBC
@@ -42,8 +44,8 @@ server:
api:
server:
# 主服务器API配置
# base-url: "http://8.138.23.49:8080"
base-url: "http://192.168.1.89:8085"
base-url: "http://8.138.23.49:8085"
#base-url: "http://192.168.1.89:8085"
paths:
monitor: "/monitor/client/api"
login: "/monitor/account/login"