style: 统一日志格式, 移除[]括号和-分隔符, key=value规范化
This commit is contained in:
parent
de576330bb
commit
a72f5d884f
@ -17,6 +17,7 @@ import (
|
||||
func main() {
|
||||
// 日志同时输出到GUI窗口和本地文件
|
||||
log.SetOutput(io.MultiWriter(&guiLogWriter{}, initFileLog()))
|
||||
log.SetFlags(log.Ltime)
|
||||
|
||||
log.Printf("孔网商品定价 %s 启动中...", version)
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ func InitDB(dbPath string) error {
|
||||
// 确保数据库目录存在
|
||||
dir := "./data"
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
log.Printf("[DB] 数据库目录不存在, 创建: %s", dir)
|
||||
log.Printf("[DB] 数据库目录不存在, 创建: dir=%s", dir)
|
||||
os.MkdirAll(dir, 0755)
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ func (h *ConfigHandler) GetConfigPrice(w http.ResponseWriter, r *http.Request) {
|
||||
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
||||
clientIP = forwarded
|
||||
}
|
||||
log.Printf("[GetConfigPrice] 收到请求, 来源IP: %s", clientIP)
|
||||
log.Printf("[GetConfigPrice] 收到请求: clientIP=%s", clientIP)
|
||||
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
@ -40,7 +40,7 @@ func (h *ConfigHandler) GetConfigPrice(w http.ResponseWriter, r *http.Request) {
|
||||
// 1. 加载yaml配置
|
||||
cfg, err := config.Load(h.configPath)
|
||||
if err != nil {
|
||||
log.Printf("[GetConfigPrice] 读取配置失败: %s, 来源IP: %s", err.Error(), clientIP)
|
||||
log.Printf("[GetConfigPrice] 读取配置失败: err=%s, clientIP=%s", err.Error(), clientIP)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(fmt.Sprintf(`{"code":500,"message":"读取配置失败: %s"}`, err.Error())))
|
||||
return
|
||||
@ -49,7 +49,7 @@ func (h *ConfigHandler) GetConfigPrice(w http.ResponseWriter, r *http.Request) {
|
||||
// 2. 查询 kfz_config 数据库,有数据则覆盖对应字段
|
||||
dbCfg, err := repository.GetKfzConfig()
|
||||
if err != nil {
|
||||
log.Printf("[GetConfigPrice] 查询kfz_config失败: %s", err.Error())
|
||||
log.Printf("[GetConfigPrice] 查询kfz_config失败: err=%s", err.Error())
|
||||
// 查询出错不影响返回yaml配置,继续执行
|
||||
} else if dbCfg != nil {
|
||||
cfg.NewPrice = dbCfg.NewPrice
|
||||
@ -83,7 +83,7 @@ func (h *ConfigHandler) SetConfigPrice(w http.ResponseWriter, r *http.Request) {
|
||||
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
||||
clientIP = forwarded
|
||||
}
|
||||
log.Printf("[SetConfigPrice] 收到请求, 来源IP: %s", clientIP)
|
||||
log.Printf("[SetConfigPrice] 收到请求: clientIP=%s", clientIP)
|
||||
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
@ -91,7 +91,7 @@ func (h *ConfigHandler) SetConfigPrice(w http.ResponseWriter, r *http.Request) {
|
||||
// 1. 获取现有配置(无数据则为空结构体)
|
||||
dbCfg, err := repository.GetKfzConfig()
|
||||
if err != nil {
|
||||
log.Printf("[SetConfigPrice] 查询kfz_config失败: %s", err.Error())
|
||||
log.Printf("[SetConfigPrice] 查询kfz_config失败: err=%s", err.Error())
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(fmt.Sprintf(`{"code":500,"message":"查询配置失败: %s"}`, err.Error())))
|
||||
return
|
||||
@ -119,7 +119,7 @@ func (h *ConfigHandler) SetConfigPrice(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// 3. 保存
|
||||
if err := repository.SaveKfzConfig(dbCfg); err != nil {
|
||||
log.Printf("[SetConfigPrice] 保存kfz_config失败: %s", err.Error())
|
||||
log.Printf("[SetConfigPrice] 保存kfz_config失败: err=%s", err.Error())
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(fmt.Sprintf(`{"code":500,"message":"保存配置失败: %s"}`, err.Error())))
|
||||
return
|
||||
|
||||
@ -34,12 +34,12 @@ func (h *GoodsHandler) QueryGoods(w http.ResponseWriter, r *http.Request) {
|
||||
clientIP = forwarded
|
||||
}
|
||||
if count%20 == 1 {
|
||||
log.Printf("[QueryGoods] 收到请求, 来源IP: %s, Method: %s", clientIP, r.Method)
|
||||
log.Printf("[QueryGoods] 收到请求: clientIP=%s, method=%s", clientIP, r.Method)
|
||||
}
|
||||
|
||||
// 只支持POST请求
|
||||
if r.Method != http.MethodPost {
|
||||
log.Printf("[QueryGoods] 方法不允许: %s, 来源IP: %s", r.Method, clientIP)
|
||||
log.Printf("[QueryGoods] 方法不允许: method=%s, clientIP=%s", r.Method, clientIP)
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
@ -54,7 +54,7 @@ func (h *GoodsHandler) QueryGoods(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
||||
// 尝试纯表单解析
|
||||
if err := r.ParseForm(); err != nil {
|
||||
log.Printf("[QueryGoods] 参数解析失败: %v, 来源IP: %s", err, clientIP)
|
||||
log.Printf("[QueryGoods] 参数解析失败: err=%v, clientIP=%s", err, clientIP)
|
||||
http.Error(w, "Invalid request form", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -85,7 +85,7 @@ func (h *GoodsHandler) QueryGoods(w http.ResponseWriter, r *http.Request) {
|
||||
minShippingFee := r.FormValue("min_shipping_fee")
|
||||
minPrice := r.FormValue("min_price")
|
||||
|
||||
log.Printf("[QueryGoods] 解析参数完成 - isbn=[%s], book_name=[%s], author=[%s], publishing=[%s], out_id=[%s], quality=[%s], query_index=[%s], user_id=[%s], placeholder_down_price=[%s], min_shipping_fee=[%s], min_price=[%s]",
|
||||
log.Printf("[QueryGoods] 解析参数完成: isbn=%s, book_name=%s, author=%s, publishing=%s, out_id=%s, quality=%s, query_index=%s, user_id=%s, placeholder_down_price=%s, min_shipping_fee=%s, min_price=%s",
|
||||
isbn, bookName, author, publishing, outID, quality, queryIndex, userID, placeholderDownPrice, minShippingFee, minPrice)
|
||||
|
||||
var req service.QueryRequest
|
||||
@ -103,7 +103,7 @@ func (h *GoodsHandler) QueryGoods(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// 调用服务层
|
||||
resp := h.goodsService.QueryGoods(&req)
|
||||
log.Printf("[QueryGoods] 处理完成, ID=%d, Code=%d, Message=%s", resp.ID, resp.Code, resp.Message)
|
||||
log.Printf("[QueryGoods] 处理完成: id=%d, code=%d, message=%s", resp.ID, resp.Code, resp.Message)
|
||||
|
||||
// 返回响应
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
@ -27,20 +27,20 @@ func (h *KfzHandler) KfzLogin(w http.ResponseWriter, r *http.Request) {
|
||||
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
||||
clientIP = forwarded
|
||||
}
|
||||
log.Printf("[KfzLogin] 收到登录请求, 来源IP: %s", clientIP)
|
||||
log.Printf("[KfzLogin] 收到登录请求: clientIP=%s", clientIP)
|
||||
|
||||
r.ParseMultipartForm(32 << 20)
|
||||
username := r.PostForm.Get("username")
|
||||
password := r.PostForm.Get("password")
|
||||
|
||||
if username == "" || password == "" {
|
||||
log.Printf("[KfzLogin] username或password为空, 来源IP: %s", clientIP)
|
||||
log.Printf("[KfzLogin] username或password为空: clientIP=%s", clientIP)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(`{"code":500,"message":"username和password不能为空"}`))
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("[KfzLogin] 开始登录孔网, username=%s, 来源IP: %s", username, clientIP)
|
||||
log.Printf("[KfzLogin] 开始登录孔网: username=%s, clientIP=%s", username, clientIP)
|
||||
token, err := service.OutKfzLogin(username, password)
|
||||
if err != nil {
|
||||
log.Printf("[KfzLogin] 孔网登录失败: username=%s, 错误=%v, 来源IP: %s", username, err, clientIP)
|
||||
@ -62,7 +62,7 @@ func (h *KfzHandler) KfzLogin(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// 保存账号密码和token到数据库
|
||||
if err := h.tokenRepo.UpsertByUsername(username, password, token); err != nil {
|
||||
log.Printf("[KfzLogin] 保存Token记录失败: %v, 来源IP: %s", err, clientIP)
|
||||
log.Printf("[KfzLogin] 保存Token记录失败: err=%v, clientIP=%s", err, clientIP)
|
||||
} else {
|
||||
log.Printf("[KfzLogin] 账号密码已保存到数据库: username=%s", username)
|
||||
}
|
||||
|
||||
@ -47,16 +47,16 @@ func (h *TokenHandler) BatchAddTokens(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var inputs []TokenInput
|
||||
if err := json.NewDecoder(r.Body).Decode(&inputs); err != nil {
|
||||
log.Printf("[Token/BatchAdd] 请求体解析失败: %v, 来源IP: %s", err, clientIP)
|
||||
log.Printf("[Token/BatchAdd] 请求体解析失败: err=%v, clientIP=%s", err, clientIP)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(TokenResponse{Code: 400, Message: "invalid request body"})
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("[Token/BatchAdd] 收到请求, 来源IP: %s, token数量: %d", clientIP, len(inputs))
|
||||
log.Printf("[Token/BatchAdd] 收到请求: clientIP=%s, tokenCount=%d", clientIP, len(inputs))
|
||||
|
||||
if len(inputs) == 0 {
|
||||
log.Printf("[Token/BatchAdd] 空数组, 来源IP: %s", clientIP)
|
||||
log.Printf("[Token/BatchAdd] 空数组: clientIP=%s", clientIP)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(TokenResponse{Code: 400, Message: "empty array"})
|
||||
return
|
||||
@ -82,7 +82,7 @@ func (h *TokenHandler) BatchAddTokens(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if len(failed) > 0 {
|
||||
log.Printf("[Token/BatchAdd] 部分成功: 成功%d条, 失败%d条, 来源IP: %s", len(inputs)-len(failed), len(failed), clientIP)
|
||||
log.Printf("[Token/BatchAdd] 部分成功: successCount=%d, failCount=%d, clientIP=%s", len(inputs)-len(failed), len(failed), clientIP)
|
||||
json.NewEncoder(w).Encode(TokenResponse{
|
||||
Code: 207,
|
||||
Message: "partial success",
|
||||
@ -91,7 +91,7 @@ func (h *TokenHandler) BatchAddTokens(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("[Token/BatchAdd] 全部成功: %d条, 来源IP: %s", len(inputs), clientIP)
|
||||
log.Printf("[Token/BatchAdd] 全部成功: count=%d, clientIP=%s", len(inputs), clientIP)
|
||||
json.NewEncoder(w).Encode(TokenResponse{Code: 200, Message: "success"})
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ func (h *TokenHandler) GetAllTokens(w http.ResponseWriter, r *http.Request) {
|
||||
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
||||
clientIP = forwarded
|
||||
}
|
||||
log.Printf("[Token/GetAll] 收到请求, 来源IP: %s", clientIP)
|
||||
log.Printf("[Token/GetAll] 收到请求: clientIP=%s", clientIP)
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
return
|
||||
@ -109,13 +109,13 @@ func (h *TokenHandler) GetAllTokens(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
records, err := h.tokenRepo.GetAll()
|
||||
if err != nil {
|
||||
log.Printf("[Token/GetAll] 查询失败: %v, 来源IP: %s", err, clientIP)
|
||||
log.Printf("[Token/GetAll] 查询失败: err=%v, clientIP=%s", err, clientIP)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(TokenResponse{Code: 500, Message: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("[Token/GetAll] 查询成功: 共%d条记录, 来源IP: %s", len(records), clientIP)
|
||||
log.Printf("[Token/GetAll] 查询成功: count=%d, clientIP=%s", len(records), clientIP)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(TokenResponse{Code: 200, Message: "success", Data: records})
|
||||
}
|
||||
@ -126,7 +126,7 @@ func (h *TokenHandler) DeleteToken(w http.ResponseWriter, r *http.Request) {
|
||||
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
||||
clientIP = forwarded
|
||||
}
|
||||
log.Printf("[Token/Delete] 收到请求, 来源IP: %s", clientIP)
|
||||
log.Printf("[Token/Delete] 收到请求: clientIP=%s", clientIP)
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
return
|
||||
@ -144,7 +144,7 @@ func (h *TokenHandler) DeleteToken(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
log.Printf("[Token/Delete] 参数id无效: %s, 来源IP: %s", idStr, clientIP)
|
||||
log.Printf("[Token/Delete] 参数id无效: id=%s, clientIP=%s", idStr, clientIP)
|
||||
http.Error(w, "invalid id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -168,7 +168,7 @@ func (h *TokenHandler) UpdateToken(w http.ResponseWriter, r *http.Request) {
|
||||
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
||||
clientIP = forwarded
|
||||
}
|
||||
log.Printf("[Token/Update] 收到请求, 来源IP: %s", clientIP)
|
||||
log.Printf("[Token/Update] 收到请求: clientIP=%s", clientIP)
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
return
|
||||
@ -185,7 +185,7 @@ func (h *TokenHandler) UpdateToken(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
log.Printf("[Token/Update] 参数id无效: %s, 来源IP: %s", idStr, clientIP)
|
||||
log.Printf("[Token/Update] 参数id无效: id=%s, clientIP=%s", idStr, clientIP)
|
||||
http.Error(w, "invalid id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -215,7 +215,7 @@ func (h *TokenHandler) GetEnabledTokens(w http.ResponseWriter, r *http.Request)
|
||||
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
||||
clientIP = forwarded
|
||||
}
|
||||
log.Printf("[Token/GetEnabled] 收到请求, 来源IP: %s", clientIP)
|
||||
log.Printf("[Token/GetEnabled] 收到请求: clientIP=%s", clientIP)
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
return
|
||||
@ -223,13 +223,13 @@ func (h *TokenHandler) GetEnabledTokens(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
records, err := h.tokenRepo.GetEnabledTokens()
|
||||
if err != nil {
|
||||
log.Printf("[Token/GetEnabled] 查询失败: %v, 来源IP: %s", err, clientIP)
|
||||
log.Printf("[Token/GetEnabled] 查询失败: err=%v, clientIP=%s", err, clientIP)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(TokenResponse{Code: 500, Message: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("[Token/GetEnabled] 查询成功: 共%d条启用token, 来源IP: %s", len(records), clientIP)
|
||||
log.Printf("[Token/GetEnabled] 查询成功: count=%d, clientIP=%s", len(records), clientIP)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(TokenResponse{Code: 200, Message: "success", Data: records})
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ func GetKfzConfig() (*KfzConfig, error) {
|
||||
return nil, nil // 无数据
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("[Repo/Config] 查询kfz_config失败: %v", err)
|
||||
log.Printf("[Repo/Config] 查询kfz_config失败: err=%v", err)
|
||||
return nil, fmt.Errorf("查询kfz_config失败: %w", err)
|
||||
}
|
||||
log.Printf("[Repo/Config] 查询成功: new_price=%.2f, placeholder_down_price=%.2f, min_shipping_fee=%.2f, min_price=%.2f, query_index=%d",
|
||||
@ -45,7 +45,7 @@ func SaveKfzConfig(cfg *KfzConfig) error {
|
||||
var count int
|
||||
err := database.DB.QueryRow("SELECT COUNT(*) FROM kfz_config").Scan(&count)
|
||||
if err != nil {
|
||||
log.Printf("[Repo/Config] 查询kfz_config数量失败: %v", err)
|
||||
log.Printf("[Repo/Config] 查询kfz_config数量失败: err=%v", err)
|
||||
return fmt.Errorf("查询kfz_config失败: %w", err)
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ func SaveKfzConfig(cfg *KfzConfig) error {
|
||||
cfg.NewPrice, cfg.PlaceholderDownPrice, cfg.MinShippingFee, cfg.MinPrice, cfg.QueryIndex,
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("[Repo/Config] 插入配置失败: %v", err)
|
||||
log.Printf("[Repo/Config] 插入配置失败: err=%v", err)
|
||||
return fmt.Errorf("插入kfz_config失败: %w", err)
|
||||
}
|
||||
log.Printf("[Repo/Config] 插入配置成功: new_price=%.2f, placeholder_down_price=%.2f, min_shipping_fee=%.2f, min_price=%.2f, query_index=%d",
|
||||
@ -66,7 +66,7 @@ func SaveKfzConfig(cfg *KfzConfig) error {
|
||||
cfg.NewPrice, cfg.PlaceholderDownPrice, cfg.MinShippingFee, cfg.MinPrice, cfg.QueryIndex,
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("[Repo/Config] 更新配置失败: %v", err)
|
||||
log.Printf("[Repo/Config] 更新配置失败: err=%v", err)
|
||||
return fmt.Errorf("更新kfz_config失败: %w", err)
|
||||
}
|
||||
log.Printf("[Repo/Config] 更新配置成功: new_price=%.2f, placeholder_down_price=%.2f, min_shipping_fee=%.2f, min_price=%.2f, query_index=%d",
|
||||
|
||||
@ -47,7 +47,7 @@ func (r *GoodsRepository) Insert(isbn, bookName, author, publishing, outID, qual
|
||||
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
log.Printf("[Repo/Goods] 获取自增ID失败: %v", err)
|
||||
log.Printf("[Repo/Goods] 获取自增ID失败: err=%v", err)
|
||||
return 0, fmt.Errorf("获取自增ID失败: %w", err)
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ func (r *GoodsRepository) GetAllOrderByUpdatedAt() (*GoodsPricing, error) {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
log.Printf("[Repo/Goods] 查询待处理记录失败: %v", err)
|
||||
log.Printf("[Repo/Goods] 查询待处理记录失败: err=%v", err)
|
||||
return nil, fmt.Errorf("查询记录失败: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@ -136,9 +136,9 @@ func (s *GoodsService) sendCallback(outID, userID string, price, shippingFee flo
|
||||
End()
|
||||
|
||||
if len(errs) > 0 {
|
||||
log.Printf("回调失败: %v", errs)
|
||||
log.Printf("回调失败: errs=%v", errs)
|
||||
} else {
|
||||
log.Printf("最低书价:%v", minPrice)
|
||||
log.Printf("最低书价: min_price=%v", minPrice)
|
||||
log.Printf("回调成功: product_id=%s, user_id=%s, sale_price=%d, cost=%d", outID, userID, salePrice, cost)
|
||||
}
|
||||
}
|
||||
@ -205,7 +205,7 @@ func (s *GoodsService) syncGoodsPricing() {
|
||||
// 查询数据库数据
|
||||
kfzConfig, err := repository.GetKfzConfig()
|
||||
if err != nil {
|
||||
log.Printf("[syncGoodsPricing] 获取config数据库数据失败: %v", err)
|
||||
log.Printf("[syncGoodsPricing] 获取config数据库数据失败: err=%v", err)
|
||||
return
|
||||
}
|
||||
if kfzConfig == nil {
|
||||
@ -216,7 +216,7 @@ func (s *GoodsService) syncGoodsPricing() {
|
||||
// 查询一条记录,按fail_count升序、updated_at倒序
|
||||
record, err := s.goodsRepository.GetAllOrderByUpdatedAt()
|
||||
if err != nil {
|
||||
log.Printf("[syncGoodsPricing] 查询待处理记录失败: %v", err)
|
||||
log.Printf("[syncGoodsPricing] 查询待处理记录失败: err=%v", err)
|
||||
return
|
||||
}
|
||||
if record == nil {
|
||||
@ -279,7 +279,7 @@ func (s *GoodsService) outGetAllGoods(isbn string, bookName string, author strin
|
||||
log.Printf("[outGetAllGoods] 没有可用的token, 查询终止")
|
||||
return nil, fmt.Errorf("没有可用的token")
|
||||
}
|
||||
log.Printf("[outGetAllGoods] 可用token数量: %d", len(tokens))
|
||||
log.Printf("[outGetAllGoods] 可用token数量: count=%d", len(tokens))
|
||||
|
||||
// 轮询选择token
|
||||
s.tokenMu.Lock()
|
||||
@ -289,7 +289,7 @@ func (s *GoodsService) outGetAllGoods(isbn string, bookName string, author strin
|
||||
s.tokenMu.Unlock()
|
||||
|
||||
token := tokens[currentIdx].Token
|
||||
log.Printf("[outGetAllGoods] 使用token索引: %d/%d, username=%s", currentIdx, len(tokens), tokens[currentIdx].Username)
|
||||
log.Printf("[outGetAllGoods] 使用token索引: index=%d, total=%d, username=%s", currentIdx, len(tokens), tokens[currentIdx].Username)
|
||||
|
||||
kfzUrl := "https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/list?dataType=0&page=1&sortType=7&userArea=13003000000&quaSelect=2"
|
||||
|
||||
@ -327,7 +327,7 @@ func (s *GoodsService) outGetAllGoods(isbn string, bookName string, author strin
|
||||
// 加入查询参数
|
||||
kfzUrl = kfzUrl + "&actionPath=" + actionPath
|
||||
|
||||
log.Printf("[outGetAllGoods] 请求孔网URL: %s", kfzUrl)
|
||||
log.Printf("[outGetAllGoods] 请求孔网URL: url=%s", kfzUrl)
|
||||
|
||||
// 执行搜索请求,最多重试2次(首次失败+自动刷新token后重试1次)
|
||||
bookInfo, err := s.doKfzSearch(kfzUrl, token, tokens[currentIdx], queryIndex)
|
||||
@ -354,7 +354,7 @@ func (s *GoodsService) doKfzSearch(kfzUrl, token string, tokenRecord *repository
|
||||
s.reportBadPassword(tokenRecord.Username)
|
||||
return nil, refreshErr
|
||||
}
|
||||
log.Printf("[outGetAllGoods] 自动重新登录失败: %v", refreshErr)
|
||||
log.Printf("[outGetAllGoods] 自动重新登录失败: err=%v", refreshErr)
|
||||
return nil, err
|
||||
}
|
||||
token = newToken
|
||||
@ -389,17 +389,17 @@ func (s *GoodsService) doKfzSearchOnce(kfzUrl, token string, queryIndex int) (*m
|
||||
|
||||
// 错误处理
|
||||
if len(errsSpt) > 0 {
|
||||
log.Printf("[outGetAllGoods] 孔网请求失败: %v", errsSpt)
|
||||
log.Printf("[outGetAllGoods] 孔网请求失败: errs=%v", errsSpt)
|
||||
return nil, fmt.Errorf("请求失败: %v", errsSpt)
|
||||
}
|
||||
|
||||
// 检查HTTP状态码
|
||||
if respSpt.StatusCode != http.StatusOK {
|
||||
log.Printf("[outGetAllGoods] 孔网HTTP错误: %s", respSpt.Status)
|
||||
log.Printf("[outGetAllGoods] 孔网HTTP错误: status=%s", respSpt.Status)
|
||||
return nil, fmt.Errorf("HTTP错误: %s", respSpt.Status)
|
||||
}
|
||||
|
||||
log.Printf("[outGetAllGoods] 孔网响应数据: %s", bodySpt)
|
||||
log.Printf("[outGetAllGoods] 孔网响应数据: body=%s", bodySpt)
|
||||
|
||||
// 解析响应
|
||||
var apiSptResp struct {
|
||||
@ -429,7 +429,7 @@ func (s *GoodsService) doKfzSearchOnce(kfzUrl, token string, queryIndex int) (*m
|
||||
|
||||
// 解析JSON
|
||||
if err := json.Unmarshal([]byte(bodySpt), &apiSptResp); err != nil {
|
||||
log.Printf("[outGetAllGoods] 解析孔网响应JSON失败: %v", err)
|
||||
log.Printf("[outGetAllGoods] 解析孔网响应JSON失败: err=%v", err)
|
||||
return nil, fmt.Errorf("解析JSON失败: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@ -915,3 +915,21 @@
|
||||
2026/06/30 11:20:10 [Repo/Config] 查询成功: new_price=9999.00, placeholder_down_price=0.01, min_shipping_fee=3.00, min_price=1.00, query_index=3
|
||||
2026/06/30 11:20:15 [Repo/Config] 查询成功: new_price=9999.00, placeholder_down_price=0.01, min_shipping_fee=3.00, min_price=1.00, query_index=3
|
||||
2026/06/30 11:20:20 [Repo/Config] 查询成功: new_price=9999.00, placeholder_down_price=0.01, min_shipping_fee=3.00, min_price=1.00, query_index=3
|
||||
====== 2026-06-30 11:47:21 日志文件初始化完成 ======
|
||||
2026/06/30 11:47:21 孔网商品定价 v1.0.3 启动中...
|
||||
2026/06/30 11:47:21 配置加载成功: port=8080, timer=5s, rate_limit=2s
|
||||
2026/06/30 11:47:21 config: {"Port":"8080","TimerInterval":5,"APIRateLimit":2,"CallbackURL":"http://192.168.101.213:9090/api/product/updatePrice","NewPrice":0,"PlaceholderDownPrice":0,"MinShippingFee":0,"MinPrice":0,"QueryIndex":0}
|
||||
2026/06/30 11:47:21 [DB] 初始化数据库: path=./data/goods_pricing.db
|
||||
2026/06/30 11:47:21 [DB] 数据库初始化完成
|
||||
2026/06/30 11:47:21 数据库初始化成功
|
||||
2026/06/30 11:47:21 [TimerScheduler] 定时器启动, 间隔=5秒
|
||||
2026/06/30 11:47:21 定时器已启动,5秒后开始首次同步
|
||||
2026/06/30 11:47:21 服务器正在启动 8080
|
||||
2026/06/30 11:47:26 [Repo/Config] kfz_config表无数据
|
||||
2026/06/30 11:47:26 [syncGoodsPricing] kfz_config表中无配置数据, 跳过本次同步。请到进销存系统中设置核价器配置
|
||||
2026/06/30 11:47:31 [Repo/Config] kfz_config表无数据
|
||||
2026/06/30 11:47:32 [syncGoodsPricing] kfz_config表中无配置数据, 跳过本次同步。请到进销存系统中设置核价器配置
|
||||
2026/06/30 11:47:36 [Repo/Config] kfz_config表无数据
|
||||
2026/06/30 11:47:37 [syncGoodsPricing] kfz_config表中无配置数据, 跳过本次同步。请到进销存系统中设置核价器配置
|
||||
2026/06/30 11:47:41 [Repo/Config] kfz_config表无数据
|
||||
2026/06/30 11:47:42 [syncGoodsPricing] kfz_config表中无配置数据, 跳过本次同步。请到进销存系统中设置核价器配置
|
||||
|
||||
Loading…
Reference in New Issue
Block a user