package api import ( "assetcenter/db/repo" "fmt" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson/primitive" ) func Move(r *GinRouter) { // 同步色卡名和序列 r.GET("/move/mat/cardInfo", MoveCardInfo) } func MoveCardInfo(c *gin.Context, apictx *ApiSession) (interface{}, error) { collections := []string{ "personal_mat_user", "platform_mat_company", "company_mats_user", "platform_mat2d_user", "platform_mat_team", "company_mats_company", "company_mat2d_user", "platform_mat2d_company", "personal_mat_user", } for _, collect := range collections { fmt.Println("-----------------同步开始------------------------") fmt.Println("-----------------" + collect + "------------------------") ok, mats := repo.RepoSeachDocsMap(apictx.CreateRepoCtx(), &repo.DocsSearchOptions{ Db: "sku3d-tree", CollectName: collect, Project: []string{"name", "cusNum", "source"}, }) // fmt.Println(ok) if !ok { continue } isUpdate := false if len(mats) > 0 { for _, mat := range mats { if mat["name"] == nil { mat["name"] = "默认" } if mat["cusNum"] == nil { mat["cusNum"] = "mr-001" } if source, ok := mat["source"]; ok { if sv, ok := source.(map[string]interface{}); ok { if slistv, ok := sv["colorCards"]; ok { if slist, ok := slistv.(primitive.A); ok { if len(slist) > 0 { for i, list := range slist { _name := list.(map[string]interface{})["name"] _cusNum := list.(map[string]interface{})["cusNum"] if _name == nil { slist[i].(map[string]interface{})["name"] = mat["name"] isUpdate = true } if _cusNum == nil { slist[i].(map[string]interface{})["cusNum"] = mat["cusNum"] isUpdate = true } } } } } } fmt.Println(isUpdate) fmt.Println(mat["name"]) fmt.Println(mat["_id"].(primitive.ObjectID).Hex()) // return mat["source"], nil if isUpdate { repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), "sku3d-tree", collect, mat["_id"].(primitive.ObjectID).Hex(), &mat) } } } } } fmt.Println("-----------------同步结束------------------------") return 1, nil }