aadiffupdatetest.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package api
  2. import (
  3. "box-cost/db/model"
  4. "box-cost/db/repo"
  5. "box-cost/log"
  6. "errors"
  7. "fmt"
  8. "time"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // 更新生产计划
  12. func DiffUpdatePlanTest(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  13. var plan model.ProductPlan
  14. err := c.ShouldBindJSON(&plan)
  15. if err != nil {
  16. fmt.Println(err)
  17. log.Error(err)
  18. return nil, errors.New("参数错误")
  19. }
  20. if plan.Id.Hex() == "" {
  21. return nil, errors.New("id的为空")
  22. }
  23. plan.UpdateTime = time.Now()
  24. // repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
  25. // CollectName: "product-plan_copy1",
  26. // Query: repo.Map{"_id": plan.Id.Hex()},
  27. // }, &plan)
  28. // return plan, nil
  29. // ========================记录更新日志 查询更新前数据============================
  30. // planModel1 := &model.ProductPlan{}
  31. // oldPlan := getDataById(apictx, plan.Id.Hex(), planModel1, "product-plan_copy1")
  32. // // ============================================================================
  33. result, err1 := repo.RepoUpdateSetDoc1(apictx.CreateRepoCtx(), "product-plan_copy1", plan.Id.Hex(), &plan, &repo.RecordLogReq{
  34. Path: c.Request.URL.Path,
  35. UserId: apictx.User.ID,
  36. TargetId: plan.Id.Hex(),
  37. })
  38. // ========================记录更新日志 查询更新后数据============================
  39. // planModel2 := &model.ProductPlan{}
  40. // newPlan := getDataById(apictx, plan.Id.Hex(), planModel2, "product-plan_copy1")
  41. // // ============================================================================
  42. // // ============================记录更新前后差异================================
  43. // diffStr, err := diffUpdateData(oldPlan, newPlan)
  44. // if err != nil {
  45. // fmt.Println(err)
  46. // }
  47. // // 记录到数据库中
  48. // changeLogs := &model.Logs{
  49. // Path: c.Request.URL.Path,
  50. // UserId: apictx.User.ID,
  51. // TargetId: plan.Id.Hex(),
  52. // Diff: diffStr,
  53. // CreateTime: time.Now(),
  54. // UpdateTime: time.Now(),
  55. // }
  56. // repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionLogs, changeLogs)
  57. // ==========================================================================
  58. return result, err1
  59. }
  60. func PrintDiff(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  61. id := c.Query("id")
  62. changeLogs := model.Logs{}
  63. _, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
  64. CollectName: repo.CollectionLogs,
  65. Query: repo.Map{"_id": id},
  66. }, &changeLogs)
  67. if err != nil {
  68. return nil, err
  69. }
  70. fmt.Println(changeLogs.Diff)
  71. return changeLogs, nil
  72. }