feat: 支持勾选部分档口入库码匹配 (#235)
This commit is contained in:
@@ -127,6 +127,15 @@ func (h *Handler) InnerCodeMatch(c *gin.Context) {
|
||||
h.innerCodeRedirect(c, time.Now().In(innerCodeLocation).Format("2006-01-02"), status, keyword, 1, "业务日期无效,没有执行匹配。")
|
||||
return
|
||||
}
|
||||
ids := parseInnerCodeIDs(c.PostFormArray("ids"))
|
||||
if len(ids) == 0 {
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, "请先勾选要匹配的记录。")
|
||||
return
|
||||
}
|
||||
if len(ids) > service.PageSize {
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, "一次最多匹配当前页 20 条记录,请刷新后重新勾选。")
|
||||
return
|
||||
}
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, "顺运宝配置不可用,没有执行匹配。")
|
||||
@@ -145,7 +154,7 @@ func (h *Handler) InnerCodeMatch(c *gin.Context) {
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, message)
|
||||
return
|
||||
}
|
||||
result, err := service.PlanInnerCodeRecords(c.Request.Context(), h.db, client, businessDate)
|
||||
result, err := service.PlanInnerCodeRecords(c.Request.Context(), h.db, client, businessDate, ids)
|
||||
if err != nil {
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, "匹配失败:"+err.Error())
|
||||
return
|
||||
@@ -159,12 +168,7 @@ func (h *Handler) InnerCodeMatch(c *gin.Context) {
|
||||
func (h *Handler) InnerCodeApply(c *gin.Context) {
|
||||
businessDate, status, keyword := c.PostForm("date"), c.PostForm("status"), c.PostForm("q")
|
||||
pageNumber := service.ParsePage(c.PostForm("page"))
|
||||
ids := make([]int64, 0)
|
||||
for _, raw := range c.PostFormArray("ids") {
|
||||
if id, err := strconv.ParseInt(strings.TrimSpace(raw), 10, 64); err == nil && id > 0 {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
ids := parseInnerCodeIDs(c.PostFormArray("ids"))
|
||||
client, message := h.innerCodeSybClient()
|
||||
if message != "" {
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, message)
|
||||
@@ -180,6 +184,20 @@ func (h *Handler) InnerCodeApply(c *gin.Context) {
|
||||
h.innerCodeRedirect(c, businessDate, status, keyword, pageNumber, message)
|
||||
}
|
||||
|
||||
func parseInnerCodeIDs(rawIDs []string) []int64 {
|
||||
ids := make([]int64, 0, len(rawIDs))
|
||||
seen := make(map[int64]bool, len(rawIDs))
|
||||
for _, raw := range rawIDs {
|
||||
id, err := strconv.ParseInt(strings.TrimSpace(raw), 10, 64)
|
||||
if err != nil || id <= 0 || seen[id] {
|
||||
continue
|
||||
}
|
||||
seen[id] = true
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// InnerCodeRecheck 只重新读取未知结果,绝不再次发送删除或写入。
|
||||
func (h *Handler) InnerCodeRecheck(c *gin.Context) {
|
||||
businessDate, status, keyword := c.PostForm("date"), c.PostForm("status"), c.PostForm("q")
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package web
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseInnerCodeIDs_过滤无效并保持首次选择顺序(t *testing.T) {
|
||||
got := parseInnerCodeIDs([]string{" 8 ", "bad", "0", "8", "3"})
|
||||
if len(got) != 2 || got[0] != 8 || got[1] != 3 {
|
||||
t.Fatalf("解析结果不正确: %v", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user