fix: 档口入库码匹配自动恢复顺运宝会话 (#236)
This commit is contained in:
@@ -146,11 +146,11 @@ func (h *Handler) InnerCodeMatch(c *gin.Context) {
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, "顺运宝地址配置有误,没有执行匹配。")
|
||||
return
|
||||
}
|
||||
if err := service.EnsureSybSession(h.db, client, cfg.Syb.Username, time.Now()); err != nil {
|
||||
message := "校验顺运宝会话失败,没有执行匹配。"
|
||||
if errors.Is(err, service.ErrSybLoginRequired) {
|
||||
message = "顺运宝会话已过期,请先到“顺运宝数据”页面登录后再匹配。"
|
||||
}
|
||||
autoLoggedIn, message := ensureInnerCodeMatchSession(
|
||||
func() error { return service.EnsureSybSession(h.db, client, cfg.Syb.Username, time.Now()) },
|
||||
func() (string, bool) { return h.attemptSybAutoLogin(c, client, *cfg) },
|
||||
)
|
||||
if message != "" {
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, message)
|
||||
return
|
||||
}
|
||||
@@ -159,11 +159,35 @@ func (h *Handler) InnerCodeMatch(c *gin.Context) {
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, "匹配失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
message := fmt.Sprintf("匹配完成:处理 %d 条,可回写 %d 条,已存在 %d 条,跳过 %d 条,失败 %d 条。",
|
||||
message = fmt.Sprintf("匹配完成:处理 %d 条,可回写 %d 条,已存在 %d 条,跳过 %d 条,失败 %d 条。",
|
||||
result.Total, result.Ready, result.AlreadyFilled, result.Skipped, result.Failed)
|
||||
if autoLoggedIn {
|
||||
message = "顺运宝自动登录成功;" + message
|
||||
}
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, message)
|
||||
}
|
||||
|
||||
// ensureInnerCodeMatchSession 只负责“检查缓存 → 必要时自动登录”的编排。
|
||||
// 自动登录成功后调用方继续使用同一个 client;这里绝不启动顺运宝同步。
|
||||
func ensureInnerCodeMatchSession(checkSession func() error, autoLogin func() (string, bool)) (bool, string) {
|
||||
err := checkSession()
|
||||
if err == nil {
|
||||
return false, ""
|
||||
}
|
||||
if !errors.Is(err, service.ErrSybLoginRequired) {
|
||||
return false, "校验顺运宝会话失败,没有执行匹配。"
|
||||
}
|
||||
reason, ok := autoLogin()
|
||||
if ok {
|
||||
return true, ""
|
||||
}
|
||||
reason = strings.TrimSpace(reason)
|
||||
if reason == "" {
|
||||
reason = "未配置验证码识别服务,无法自动登录"
|
||||
}
|
||||
return false, "顺运宝自动登录未完成:" + reason + ";没有执行匹配,请到“顺运宝数据”页面完成登录。"
|
||||
}
|
||||
|
||||
// InnerCodeApply 在操作员确认后逐条执行安全回写。
|
||||
func (h *Handler) InnerCodeApply(c *gin.Context) {
|
||||
businessDate, status, keyword := c.PostForm("date"), c.PostForm("status"), c.PostForm("q")
|
||||
|
||||
Reference in New Issue
Block a user