repo.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. package repo
  2. import (
  3. "box-cost/db"
  4. dm "box-cost/db/model"
  5. "box-cost/log"
  6. "context"
  7. "encoding/json"
  8. "fmt"
  9. "time"
  10. "github.com/sergi/go-diff/diffmatchpatch"
  11. "go.mongodb.org/mongo-driver/bson"
  12. "go.mongodb.org/mongo-driver/bson/primitive"
  13. "go.mongodb.org/mongo-driver/mongo"
  14. "go.mongodb.org/mongo-driver/mongo/options"
  15. )
  16. type RepoSession struct {
  17. Ctx context.Context
  18. Client *db.MongoDB
  19. }
  20. const (
  21. CollectionMaterial = "material"
  22. CollectionCraft = "craft"
  23. CollectionProduct = "product"
  24. CollectionSupplier = "supplier"
  25. CollectionSupplierPrice = "supplier-price"
  26. CollectionPack = "pack"
  27. CollectionProductPlan = "product-plan"
  28. CollectionBillPurchase = "bill-purchase"
  29. CollectionBillProduce = "bill-produce"
  30. CollectionBillProduct = "bill-product" // 成品采购
  31. CollectionSupplierMatprice = "supplier-mats"
  32. CollectionSupplierCraftprice = "supplier-crafts"
  33. CollectionSupplierProductprice = "supplier-product" // 成品采购
  34. CollectionIncrement = "increment"
  35. CollectionSignature = "signature"
  36. CollectionUsers = "users"
  37. // 更改日志记录
  38. CollectionLogs = "logs"
  39. CollectionRequestLogs = "request-logs"
  40. )
  41. type Map map[string]interface{}
  42. type PageResult struct {
  43. List []map[string]interface{} `json:"list"`
  44. Total int64 `json:"total"`
  45. Page int64 `json:"page"`
  46. Size int64 `json:"size"`
  47. }
  48. type PageSearchOptions struct {
  49. Db string
  50. CollectName string
  51. Page int64
  52. Size int64
  53. Query map[string]interface{}
  54. Project []string
  55. Sort interface{}
  56. }
  57. type DocSearchOptions struct {
  58. Db string
  59. CollectName string
  60. Query Map
  61. Project []string
  62. Sort bson.M
  63. }
  64. type DocFilterOptions struct {
  65. Db string
  66. CollectName string
  67. Query Map
  68. }
  69. func NewDocSearchOptions(filter Map, project []string) *DocSearchOptions {
  70. return &DocSearchOptions{
  71. Query: filter,
  72. Project: project,
  73. }
  74. }
  75. func RepoAddDoc(ctx *RepoSession, collectName string, doc interface{}) (string, error) {
  76. users := ctx.Client.GetCollection(collectName)
  77. result, err := users.InsertOne(ctx.Ctx, doc)
  78. if err != nil {
  79. return "", err
  80. }
  81. return result.InsertedID.(primitive.ObjectID).Hex(), nil
  82. }
  83. func RepoDbAddDoc(ctx *RepoSession, dbName string, collectName string, doc interface{}) (string, error) {
  84. users := ctx.Client.GetDbCollection(dbName, collectName)
  85. result, err := users.InsertOne(ctx.Ctx, doc)
  86. if err != nil {
  87. return "", err
  88. }
  89. return result.InsertedID.(primitive.ObjectID).Hex(), nil
  90. }
  91. func RepoDeleteDoc(ctx *RepoSession, collectName string, id string) (interface{}, error) {
  92. uid, _ := primitive.ObjectIDFromHex(id)
  93. colls := ctx.Client.GetCollection(collectName)
  94. return colls.DeleteOne(ctx.Ctx, &bson.M{"_id": uid})
  95. }
  96. func RepoDeleteDbDoc(ctx *RepoSession, dbName string, collectName string, id string) (interface{}, error) {
  97. uid, _ := primitive.ObjectIDFromHex(id)
  98. colls := ctx.Client.GetDbCollection(dbName, collectName)
  99. return colls.DeleteOne(ctx.Ctx, &bson.M{"_id": uid})
  100. }
  101. func RepoDeleteDocs(ctx *RepoSession, collectName string, query interface{}) (interface{}, error) {
  102. colls := ctx.Client.GetCollection(collectName)
  103. return colls.DeleteMany(ctx.Ctx, query)
  104. }
  105. func RepoUpdateSetDoc(ctx *RepoSession, collectName string, idstr string, model interface{}) (*mongo.UpdateResult, error) {
  106. colls := ctx.Client.GetCollection(collectName)
  107. update := bson.M{"$set": model}
  108. uid, _ := primitive.ObjectIDFromHex(idstr)
  109. return colls.UpdateByID(ctx.Ctx, uid, update)
  110. }
  111. type RecordLogReq struct {
  112. Path string
  113. UserId string
  114. TargetId string
  115. }
  116. func RepoUpdateSetDoc1(ctx *RepoSession, collectName string, idstr string, model interface{}, recordLogReq *RecordLogReq) (*mongo.UpdateResult, error) {
  117. colls := ctx.Client.GetCollection(collectName)
  118. update := bson.M{"$set": model}
  119. uid, _ := primitive.ObjectIDFromHex(idstr)
  120. // ========================记录更新日志 查询更新前数据============================
  121. var oldData Map
  122. err := colls.FindOne(ctx.Ctx, bson.M{"_id": uid}).Decode(&oldData)
  123. fmt.Println(err)
  124. // ============================================================================
  125. result, err1 := colls.UpdateByID(ctx.Ctx, uid, update)
  126. // ========================记录更新日志 查询更新后数据============================
  127. var newData Map
  128. colls.FindOne(ctx.Ctx, bson.M{"_id": uid}).Decode(&newData)
  129. // ============================================================================
  130. // ============================记录更新前后差异================================
  131. diffStr, err := diffUpdateData(oldData, newData)
  132. if err != nil {
  133. fmt.Println(err)
  134. }
  135. fmt.Println(diffStr)
  136. // 记录到数据库中
  137. changeLogs := &dm.Logs{
  138. Path: recordLogReq.Path,
  139. UserId: recordLogReq.UserId,
  140. TargetId: recordLogReq.TargetId,
  141. Diff: diffStr,
  142. CreateTime: time.Now(),
  143. UpdateTime: time.Now(),
  144. }
  145. RepoAddDoc(ctx, CollectionLogs, changeLogs)
  146. // ==========================================================================
  147. return result, err1
  148. }
  149. // 比较差异字符
  150. func diffUpdateData(oldObj any, newObj any) (diffStr string, err error) {
  151. oldObjByte, err := json.Marshal(oldObj)
  152. if err != nil {
  153. return "", err
  154. }
  155. newObjByte, err := json.Marshal(newObj)
  156. if err != nil {
  157. return "", err
  158. }
  159. dmp := diffmatchpatch.New()
  160. diffs := dmp.DiffMain(string(oldObjByte), string(newObjByte), false)
  161. // 返回差异数据用于日志记录
  162. if len(diffs) > 0 {
  163. return dmp.DiffPrettyText(diffs), nil
  164. }
  165. return "", err
  166. }
  167. func RepoUpdateSeDbDoc(ctx *RepoSession, db string, collectName string, idstr string, model interface{}) (*mongo.UpdateResult, error) {
  168. colls := ctx.Client.GetDbCollection(db, collectName)
  169. update := bson.M{"$set": model}
  170. uid, _ := primitive.ObjectIDFromHex(idstr)
  171. return colls.UpdateByID(ctx.Ctx, uid, update)
  172. }
  173. func RepoUpdateSetDocProps(ctx *RepoSession, collectName string, idstr string, update interface{}) (*mongo.UpdateResult, error) {
  174. colls := ctx.Client.GetCollection(collectName)
  175. // update := bson.M{"$set": model}
  176. uid, _ := primitive.ObjectIDFromHex(idstr)
  177. return colls.UpdateByID(ctx.Ctx, uid, update)
  178. }
  179. func RepoUpdateSetDocsProps(ctx *RepoSession, filter *DocFilterOptions, model interface{}) (*mongo.UpdateResult, error) {
  180. colls := ctx.Client.GetCollection(filter.CollectName)
  181. if len(filter.Db) > 0 {
  182. colls = ctx.Client.GetDbCollection(filter.Db, filter.CollectName)
  183. }
  184. update := bson.M{"$set": model}
  185. filterParams := bson.M{}
  186. if len(filter.Query) > 0 {
  187. for k, v := range filter.Query {
  188. if k == "_id" {
  189. if uid, ok := v.(string); ok {
  190. docId, _ := primitive.ObjectIDFromHex(uid)
  191. filterParams["_id"] = docId
  192. continue
  193. }
  194. }
  195. filterParams[k] = v
  196. }
  197. }
  198. return colls.UpdateMany(ctx.Ctx, filterParams, update)
  199. }
  200. func RepoUpdateSetDbDocProps(ctx *RepoSession, db string, collectName string, idstr string, update interface{}) (*mongo.UpdateResult, error) {
  201. colls := ctx.Client.GetDbCollection(db, collectName)
  202. // update := bson.M{"$set": model}
  203. uid, _ := primitive.ObjectIDFromHex(idstr)
  204. return colls.UpdateByID(ctx.Ctx, uid, update)
  205. }
  206. func RepoSeachDoc(ctx *RepoSession, param *DocSearchOptions, v interface{}) (bool, error) {
  207. colls := ctx.Client.GetDbCollection(param.Db, param.CollectName)
  208. opt := &options.FindOneOptions{}
  209. if len(param.Project) > 0 {
  210. prj := bson.M{}
  211. for _, v := range param.Project {
  212. prj[v] = 1
  213. }
  214. opt.SetProjection(prj)
  215. }
  216. if len(param.Sort) > 0 {
  217. opt.Sort = param.Sort
  218. }
  219. filter := bson.M{}
  220. if len(param.Query) > 0 {
  221. for k, v := range param.Query {
  222. if k == "_id" {
  223. if uid, ok := v.(string); ok {
  224. docId, _ := primitive.ObjectIDFromHex(uid)
  225. filter["_id"] = docId
  226. continue
  227. }
  228. }
  229. filter[k] = v
  230. }
  231. }
  232. err := colls.FindOne(ctx.Ctx, filter, opt).Decode(v)
  233. if err == mongo.ErrNoDocuments {
  234. return false, nil
  235. }
  236. if err != nil {
  237. return false, err
  238. }
  239. return true, nil
  240. }
  241. func RepoSeachDocMap(ctx *RepoSession, param *DocSearchOptions) (bool, map[string]interface{}) {
  242. ret := map[string]interface{}{}
  243. ok := true
  244. colls := ctx.Client.GetDbCollection(param.Db, param.CollectName)
  245. opt := &options.FindOneOptions{}
  246. if len(param.Project) > 0 {
  247. prj := bson.M{}
  248. for _, v := range param.Project {
  249. prj[v] = 1
  250. }
  251. opt.SetProjection(prj)
  252. }
  253. if len(param.Sort) > 0 {
  254. opt.Sort = param.Sort
  255. }
  256. filter := bson.M{}
  257. if len(param.Query) > 0 {
  258. for k, v := range param.Query {
  259. if k == "_id" {
  260. if uid, ok := v.(string); ok {
  261. docId, _ := primitive.ObjectIDFromHex(uid)
  262. filter["_id"] = docId
  263. continue
  264. }
  265. }
  266. filter[k] = v
  267. }
  268. }
  269. ok = true
  270. err := colls.FindOne(ctx.Ctx, filter, opt).Decode(ret)
  271. if err == mongo.ErrNoDocuments {
  272. ok = false
  273. }
  274. if err != nil {
  275. ok = false
  276. }
  277. return ok, ret
  278. }
  279. // PageSearch 单表分页查询
  280. func RepoPageSearch(ctx *RepoSession, para *PageSearchOptions) (out *PageResult, err error) {
  281. var colls *mongo.Collection
  282. if len(para.Db) > 0 {
  283. colls = ctx.Client.GetDbCollection(para.Db, para.CollectName)
  284. } else {
  285. colls = ctx.Client.GetCollection(para.CollectName)
  286. }
  287. findoptions := &options.FindOptions{}
  288. if para.Size > 0 {
  289. findoptions.SetLimit(para.Size)
  290. findoptions.SetSkip(para.Size * (para.Page - 1))
  291. }
  292. if para.Sort != nil {
  293. findoptions.SetSort(para.Sort)
  294. }
  295. if len(para.Project) > 0 {
  296. prj := bson.M{}
  297. for _, v := range para.Project {
  298. prj[v] = 1
  299. }
  300. findoptions.SetProjection(prj)
  301. }
  302. filter := bson.M{}
  303. if len(para.Query) > 0 {
  304. for k, v := range para.Query {
  305. if value, ok := v.(string); ok {
  306. if len(value) > 0 {
  307. filter[k] = v
  308. continue
  309. }
  310. } else if v != nil {
  311. filter[k] = v
  312. }
  313. }
  314. }
  315. cur, err := colls.Find(ctx.Ctx, filter, findoptions)
  316. out = &PageResult{
  317. List: []map[string]interface{}{},
  318. Total: 0,
  319. Page: para.Page,
  320. Size: para.Size,
  321. }
  322. if err != nil {
  323. return out, err
  324. }
  325. defer cur.Close(ctx.Ctx)
  326. err = cur.All(ctx.Ctx, &out.List)
  327. out.Total, _ = colls.CountDocuments(ctx.Ctx, filter)
  328. return
  329. }
  330. func RepoDbCountDoc(ctx *RepoSession, db string, collectionName string, Query Map) (int64, error) {
  331. colls := ctx.Client.GetDbCollection(db, collectionName)
  332. filter := bson.M{}
  333. if len(Query) > 0 {
  334. for k, v := range Query {
  335. if value, ok := v.(string); ok {
  336. if len(value) > 0 {
  337. filter[k] = v
  338. continue
  339. }
  340. } else {
  341. filter[k] = v
  342. }
  343. }
  344. }
  345. return colls.CountDocuments(ctx.Ctx, filter)
  346. }
  347. func RepoCountDoc(ctx *RepoSession, collectionName string, Query Map) (int64, error) {
  348. colls := ctx.Client.GetCollection(collectionName)
  349. filter := bson.M{}
  350. if len(Query) > 0 {
  351. for k, v := range Query {
  352. if value, ok := v.(string); ok {
  353. if len(value) > 0 {
  354. filter[k] = v
  355. continue
  356. }
  357. } else {
  358. filter[k] = v
  359. }
  360. }
  361. }
  362. return colls.CountDocuments(ctx.Ctx, filter)
  363. }
  364. // PageSearch 单表分页查询
  365. func RepoDocsSearch(ctx *RepoSession, para *PageSearchOptions, out interface{}) (err error) {
  366. colls := ctx.Client.GetCollection(para.CollectName)
  367. if len(para.Db) > 0 {
  368. colls = ctx.Client.GetDbCollection(para.Db, para.CollectName)
  369. }
  370. findoptions := &options.FindOptions{}
  371. if para.Size > 0 {
  372. findoptions.SetLimit(para.Size)
  373. findoptions.SetSkip(para.Size * (para.Page - 1))
  374. }
  375. if para.Sort != nil {
  376. findoptions.SetSort(para.Sort)
  377. }
  378. if len(para.Project) > 0 {
  379. prj := bson.M{}
  380. for _, v := range para.Project {
  381. prj[v] = 1
  382. }
  383. findoptions.SetProjection(prj)
  384. }
  385. filter := bson.M{}
  386. if len(para.Query) > 0 {
  387. for k, v := range para.Query {
  388. if value, ok := v.(string); ok {
  389. if len(value) > 0 {
  390. filter[k] = v
  391. continue
  392. }
  393. } else {
  394. filter[k] = v
  395. }
  396. }
  397. }
  398. cur, err := colls.Find(ctx.Ctx, filter, findoptions)
  399. if err != nil {
  400. return err
  401. }
  402. defer cur.Close(ctx.Ctx)
  403. err = cur.All(ctx.Ctx, out)
  404. return
  405. }
  406. func RepoDocArrayAppend(ctx *RepoSession, collectName string, idstr string, fieldpath string, arrayItem interface{}) (*mongo.UpdateResult, error) {
  407. colls := ctx.Client.GetCollection(collectName)
  408. arrayOp := bson.M{}
  409. arrayOp[fieldpath] = arrayItem
  410. update := bson.M{"$push": arrayOp}
  411. uid, _ := primitive.ObjectIDFromHex(idstr)
  412. return colls.UpdateByID(ctx.Ctx, uid, update)
  413. }
  414. // { _id: 4, "grades.grade": 85 },
  415. // { $set: { "grades.$.std" : 6 } }
  416. type ArrayOneUpdateOption struct {
  417. Query Map
  418. Set Map
  419. CollectName string
  420. Id string
  421. }
  422. // if len(scene.Stickers) > 0 {
  423. // optSet["scenes.$.stickers"] = scene.Stickers
  424. // }
  425. // option := &repo.ArrayOneUpdateOption{
  426. // CollectName: repo.CollectionDesigns,
  427. // Id: id,
  428. // Query: repo.Map{"scenes.id": scene.Id},
  429. // Set: optSet,
  430. // }
  431. func RepoDocArrayOneUpdate(ctx *RepoSession, options *ArrayOneUpdateOption) (*mongo.UpdateResult, error) {
  432. colls := ctx.Client.GetCollection(options.CollectName)
  433. docId, _ := primitive.ObjectIDFromHex(options.Id)
  434. query := bson.M{"_id": docId}
  435. if len(options.Query) > 0 {
  436. for k, v := range options.Query {
  437. query[k] = v
  438. }
  439. }
  440. setOp := bson.M{}
  441. for k, v := range options.Set {
  442. setOp[k] = v
  443. }
  444. update := bson.M{"$set": setOp}
  445. return colls.UpdateOne(ctx.Ctx, query, update)
  446. }
  447. type ArrayOneRemoveOption struct {
  448. ArrayQuery Map
  449. CollectName string
  450. Id string
  451. }
  452. // { $pull: { "items" : { id: 23 } } }
  453. func RepoDocArrayOneRemove(ctx *RepoSession, options *ArrayOneRemoveOption) (*mongo.UpdateResult, error) {
  454. colls := ctx.Client.GetCollection(options.CollectName)
  455. docId, _ := primitive.ObjectIDFromHex(options.Id)
  456. query := bson.M{"_id": docId}
  457. arrayQuery := bson.M{}
  458. if len(options.ArrayQuery) > 0 {
  459. for k, v := range options.ArrayQuery {
  460. arrayQuery[k] = v
  461. }
  462. }
  463. update := bson.M{"$pull": arrayQuery}
  464. return colls.UpdateOne(ctx.Ctx, query, update)
  465. }
  466. type ArrayOneSearchOption struct {
  467. ArrayQuery Map
  468. CollectName string
  469. Id string
  470. Field string
  471. }
  472. func RepoDocArraySearch(ctx *RepoSession, options *ArrayOneSearchOption, entity interface{}) error {
  473. colls := ctx.Client.GetCollection(options.CollectName)
  474. docId, _ := primitive.ObjectIDFromHex(options.Id)
  475. match := []bson.E{}
  476. match = append(match, bson.E{"_id", docId})
  477. matchStage := bson.D{
  478. {"$match", match},
  479. }
  480. unwindStage := bson.D{
  481. {"$unwind", fmt.Sprintf("%s%s", "$", options.Field)},
  482. }
  483. pipe := mongo.Pipeline{matchStage, unwindStage}
  484. if len(options.ArrayQuery) > 0 {
  485. match2 := []bson.E{}
  486. for k, v := range options.ArrayQuery {
  487. match2 = append(match2, bson.E{k, v})
  488. }
  489. match2Stage := bson.D{
  490. {"$match", match2},
  491. }
  492. pipe = append(pipe, match2Stage)
  493. }
  494. curr, err := colls.Aggregate(ctx.Ctx, pipe)
  495. if err != nil {
  496. return err
  497. }
  498. defer curr.Close(ctx.Ctx)
  499. if curr.Next(ctx.Ctx) {
  500. err = curr.Decode(entity)
  501. if err != nil {
  502. return err
  503. }
  504. return nil
  505. }
  506. return nil
  507. }
  508. type DocsSearchOptions struct {
  509. CollectName string
  510. Query map[string]interface{}
  511. Project []string
  512. Sort interface{} //bson.D{ bson.E{"update_time", -1}, bson.E{"goods_id", -1},}
  513. }
  514. func RepoSeachDocsMap(ctx *RepoSession, param *DocsSearchOptions) (ok bool, list []map[string]interface{}) {
  515. colls := ctx.Client.GetCollection(param.CollectName)
  516. findoptions := &options.FindOptions{}
  517. if len(param.Project) > 0 {
  518. prj := bson.M{}
  519. for _, v := range param.Project {
  520. prj[v] = 1
  521. }
  522. findoptions.SetProjection(prj)
  523. }
  524. if param.Sort != nil {
  525. findoptions.SetSort(param.Sort)
  526. }
  527. filter := bson.M{}
  528. if len(param.Query) > 0 {
  529. for k, v := range param.Query {
  530. if value, ok := v.(string); ok {
  531. if len(value) > 0 {
  532. filter[k] = v
  533. continue
  534. }
  535. } else {
  536. filter[k] = v
  537. }
  538. }
  539. }
  540. cur, err := colls.Find(ctx.Ctx, filter, findoptions)
  541. if err != nil {
  542. ok = false
  543. return
  544. }
  545. defer cur.Close(ctx.Ctx)
  546. listRes := []map[string]interface{}{}
  547. err = cur.All(ctx.Ctx, &listRes)
  548. if err != nil {
  549. log.Error(err)
  550. ok = false
  551. return
  552. }
  553. list = listRes
  554. ok = true
  555. return
  556. }
  557. type DbDocsSearchOptions struct {
  558. Db string
  559. CollectName string
  560. Query map[string]interface{}
  561. Project []string
  562. Sort interface{} //bson.D{ bson.E{"update_time", -1}, bson.E{"goods_id", -1},}
  563. }
  564. func DbRepoSeachDocsMap(ctx *RepoSession, param *DbDocsSearchOptions) (ok bool, list []map[string]interface{}) {
  565. colls := ctx.Client.GetDbCollection(param.Db, param.CollectName)
  566. findoptions := &options.FindOptions{}
  567. if len(param.Project) > 0 {
  568. prj := bson.M{}
  569. for _, v := range param.Project {
  570. prj[v] = 1
  571. }
  572. findoptions.SetProjection(prj)
  573. }
  574. if param.Sort != nil {
  575. findoptions.SetSort(param.Sort)
  576. }
  577. filter := bson.M{}
  578. if len(param.Query) > 0 {
  579. for k, v := range param.Query {
  580. if value, ok := v.(string); ok {
  581. if len(value) > 0 {
  582. filter[k] = v
  583. continue
  584. }
  585. } else {
  586. filter[k] = v
  587. }
  588. }
  589. }
  590. cur, err := colls.Find(ctx.Ctx, filter, findoptions)
  591. if err != nil {
  592. ok = false
  593. return
  594. }
  595. defer cur.Close(ctx.Ctx)
  596. listRes := []map[string]interface{}{}
  597. err = cur.All(ctx.Ctx, &listRes)
  598. if err != nil {
  599. log.Error(err)
  600. ok = false
  601. return
  602. }
  603. list = listRes
  604. ok = true
  605. return
  606. }