sun-pc 9 сар өмнө
parent
commit
326fe1493a

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 13 - 0
boxcost/api/aa.json


+ 41 - 10
boxcost/api/aadiffupdatetest.go

@@ -66,16 +66,47 @@ func DiffUpdatePlanTest(c *gin.Context, apictx *ApiSession) (interface{}, error)
 	return result, err1
 }
 
-func PrintDiff(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	id := c.Query("id")
-	changeLogs := model.Logs{}
-	_, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: repo.CollectionLogs,
-		Query:       repo.Map{"_id": id},
-	}, &changeLogs)
+// 更新生产计划
+func DiffUpdateProduceTest(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var produce model.ProduceBill
+	err := c.ShouldBindJSON(&produce)
 	if err != nil {
-		return nil, err
+		fmt.Println(err)
+		log.Error(err)
+		return nil, errors.New("参数错误")
 	}
-	fmt.Println(changeLogs.Diff)
-	return changeLogs, nil
+	if produce.Id.Hex() == "" {
+		return nil, errors.New("id的为空")
+	}
+	produce.UpdateTime = time.Now()
+
+	result, err1 := repo.RepoUpdateSetDoc1(apictx.CreateRepoCtx(), "bill-produce_copy1", produce.Id.Hex(), &produce, &repo.RecordLogReq{
+		Path:     c.Request.URL.Path,
+		UserId:   apictx.User.ID,
+		TargetId: produce.Id.Hex(),
+	})
+
+	// ========================记录更新日志 查询更新后数据============================
+	// planModel2 := &model.ProductPlan{}
+	// newPlan := getDataById(apictx, plan.Id.Hex(), planModel2, "product-plan_copy1")
+	// // ============================================================================
+
+	// // ============================记录更新前后差异================================
+	// diffStr, err := diffUpdateData(oldPlan, newPlan)
+	// if err != nil {
+	// 	fmt.Println(err)
+	// }
+
+	// // 记录到数据库中
+	// changeLogs := &model.Logs{
+	// 	Path:       c.Request.URL.Path,
+	// 	UserId:     apictx.User.ID,
+	// 	TargetId:   plan.Id.Hex(),
+	// 	Diff:       diffStr,
+	// 	CreateTime: time.Now(),
+	// 	UpdateTime: time.Now(),
+	// }
+	// repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionLogs, changeLogs)
+	// ==========================================================================
+	return result, err1
 }

+ 98 - 11
boxcost/api/aadiffupdatetest.http

@@ -1,4 +1,4 @@
-@host = 127.0.0.1:8888
+@host = 192.168.110.131:8888
 
 
 ###
@@ -6,14 +6,14 @@
 # 不存在时则创建
 POST http://{{host}}/boxcost/diffUpdatePlanTest HTTP/1.1
 Content-Type: application/json
-Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjE4NzE1MDgsImlkIjoiNjQyYTUyNGY1ZjUwYmM5MDNmOTg2Mzk0Iiwia2V5IjoiYm94Y29zdCIsIm5hbWUiOiLlrZnog5wiLCJvcmlnX2lhdCI6MTcyMTI2NjcwOCwicGFyZW50IjoiNjQyYTUyNGY1ZjUwYmM5MDNmOTg2Mzk0IiwicGhvbmUiOiIxMzQwODU0NzgyMyIsInJvbGUiOiIiLCJzdGF0ZSI6MSwidXNlclR5cGUiOjJ9.oBKvW_adQUfzc5yuH_0dfHdsU559SmtfEq9UWQGJkfQ
+Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjI4MjU4OTIsImlkIjoiNjQyYTUyNGY1ZjUwYmM5MDNmOTg2Mzk0Iiwia2V5IjoiYm94Y29zdCIsIm5hbWUiOiLlrZnog5wiLCJvcmlnX2lhdCI6MTcyMjIyMTA5MiwicGFyZW50IjoiNjQyYTUyNGY1ZjUwYmM5MDNmOTg2Mzk0IiwicGhvbmUiOiIxMzQwODU0NzgyMyIsInJvbGUiOiIiLCJzdGF0ZSI6MSwidXNlclR5cGUiOjJ9.Cz7qI3-Vah0io5ZLIFDyVOf8qsqdmbT8WHdprrjbdXw
 
 {
     "_id": "64aa52935cca777202101884",
-    "name": "2023年-稻香锦绣内贴纸fdsds更换zzzz",
+    "name": "2023年-稻香锦绣内贴纸fdsds换xxx",
     "pack": {
       "_id": "646c37becfd68ee5e94335ef",
-      "name": "2023年-稻香rrrr锦绣",
+      "name": "2023年-稻香rrrererer锦绣",
       "thumbnail": "",
       "compCounts": 6,
       "designer": "1",
@@ -36,8 +36,8 @@ Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjE4NzE1M
               "deliveryTime": "2023-07-11T06:23:49.091Z",
               "supplierInfo": {
                 "_id": "635f4afa769300c4a84bfd1b",
-                "name": "016-成都凯纸业",
-                "address": "崇州经开区霞光路51号",
+                "name": "016-成都凯纸业sxferexfdfd",
+                "address": "崇州经开区霞光路fdfer51号",
                 "phone": "15982811956",
                 "categorys": [
                   "纸张erererr",
@@ -65,7 +65,7 @@ Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjE4NzE1M
               "billType": 1
             },
             {
-              "id": "1685594164090642bd76a26be7db05898efab",
+              "id": "1685594164090642bd76a26be7fdfb05898efab",
               "typeId": "642bd76a26be7db05898efab",
               "orderPrice": 0.12,
               "orderCount": 4600,
@@ -75,7 +75,7 @@ Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjE4NzE1M
               "supplierInfo": {
                 "_id": "63846b744d585ba68be6cba1",
                 "name": "008-成都宏川印务",
-                "address": "成都崇州经济开发区泗维路333号",
+                "address": "成都崇州经济开发区泗维路dhfjkdhf号",
                 "phone": "13689052627",
                 "categorys": [
                   "外协加工"
@@ -112,7 +112,7 @@ Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjE4NzE1M
               "supplierInfo": {
                 "_id": "6388441551ba5b3307f8ab61",
                 "name": "018-覆膜 熊明军",
-                "address": "金鸡路556号 覆膜 熊明军",
+                "address": "金鸡路556号 覆膜熊明军",
                 "phone": "13980871668",
                 "categorys": [
                   "外协加工"
@@ -186,7 +186,7 @@ Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjE4NzE1M
               "supplierInfo": {
                 "_id": "638eecd4f9039e0980fe5650",
                 "name": "020-烫金 温学刚",
-                "address": "崇州金鸡路556号 烫金 温学刚",
+                "address": "崇州金鸡路556号 罗哦哦哦烫金 温学刚",
                 "phone": "13028138020",
                 "categorys": [
                   "外协加工"
@@ -230,12 +230,99 @@ Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjE4NzE1M
   }
 
 
+
+###
+# 工艺单日志记录测试
+# 测试数据表(collection): bill-produce_copy1
+POST http://{{host}}/boxcost/diffUpdateProduceTest HTTP/1.1
+Content-Type: application/json
+Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjI4MjU4OTIsImlkIjoiNjQyYTUyNGY1ZjUwYmM5MDNmOTg2Mzk0Iiwia2V5IjoiYm94Y29zdCIsIm5hbWUiOiLlrZnog5wiLCJvcmlnX2lhdCI6MTcyMjIyMTA5MiwicGFyZW50IjoiNjQyYTUyNGY1ZjUwYmM5MDNmOTg2Mzk0IiwicGhvbmUiOiIxMzQwODU0NzgyMyIsInJvbGUiOiIiLCJzdGF0ZSI6MSwidXNlclR5cGUiOjJ9.Cz7qI3-Vah0io5ZLIFDyVOf8qsqdmbT8WHdprrjbdXw
+
+{
+    "_id": "66a74ff9e6e5177313cc4de9",
+    "packId": "647ae9ba097738f60ad6d794",
+    "planId": "6679876623830800fd77569c",
+    "supplierId": "63e9b2cb201413726b012296",
+    "userId": "63e208dc7452ab74932b9e37",
+    "userName": "郑茜",
+    "type": "外协加工",
+    "status": "created",
+    "reviewed": -1,
+    "signUsers": null,
+    "createTime": "2024-07-29T08:16:57.116Z",
+    "updateTime": "2024-07-29T08:16:57.116Z",
+    "completeTime": "0001-01-01T00:00:00Z",
+    "supplier": "014-成都佳顺印务",
+    "sendTo": "双流区彭镇罗汉路185号瑞达天盛,杨开英,电话:13890030861",
+    "productName": "2024年月饼手工盒-福运礼(10000套)--面纸补数11",
+    "produces": [
+        {
+            "id": "648040f27306b5a7cef71ccdUIgirTRS43gZu_0Nz7WLM",
+            "name": "冷烫(普通)",
+            "norm": "照样",
+            "price": 0,
+            "price2": 6,
+            "orderCount": 2000,
+            "orderPrice": 2.125,
+            "confirmCount": 0,
+            "isFix": false,
+            "paperCount": 2000,
+            "remark": "",
+            "paper": "红色触感豹150g",
+            "paperSize": "787*920",
+            "printSize": "787*450",
+            "deliveryTime": "2024-07-30T08:15:40.08Z",
+            "unit": "元/张",
+            "unit2": "元/平方米"
+        }
+    ],
+    "serialNumber": "WXJG-004034",
+    "remark": "",
+    "isPrint": false,
+    "isLam": false,
+    "isPaper": false,
+    "billType": "",
+    "isSend": false,
+    "sendTime": "0001-01-01T00:00:00Z",
+    "isAck": false,
+    "ackTime": "0001-01-01T00:00:00Z",
+    "compProduceName": "冷烫(普通)",
+    "supplierRemark": "",
+    "isRecord": null
+}
+
+
+
+
+// CollectionMaterial      = "material"
+	// CollectionCraft         = "craft"
+	// CollectionProduct       = "product"
+	// CollectionSupplier      = "supplier"
+	// CollectionSupplierPrice = "supplier-price"
+	// CollectionPack          = "pack"
+	// CollectionProductPlan   = "product-plan" // 计划
+	// CollectionBillPurchase  = "bill-purchase" // 材料采购单
+	// CollectionBillProduce   = "bill-produce"  // 工艺采购单
+	// CollectionBillProduct   = "bill-product" // 成品采购单
+
+	// CollectionSupplierMatprice     = "supplier-mats"
+	// CollectionSupplierCraftprice   = "supplier-crafts"
+	// CollectionSupplierProductprice = "supplier-product" // 成品采购
+	// CollectionIncrement            = "increment"
+	// CollectionSignature            = "signature"
+	// CollectionUsers                = "users"
+	// // 更改日志记录
+	// CollectionLogs        = "logs"
+	// CollectionRequestLogs = "request-logs"
+	// CollectionPlanTrack   = "plan-track"
 ###
 # 打印更改差异
-GET http://{{host}}/boxcost/printDiff?id=669e2e5a224892c0ab3a5048 HTTP/1.1
+GET http://{{host}}/boxcost/printDiff?query={"targetId":"64aa52935cca777202101884","collection":"product-plan_copy1"} HTTP/1.1
 Content-Type: application/json
 
 
+
+
 ###
 # 打印更改差异
 # POST  http://{{host}}/boxcost/units/update HTTP/1.1

+ 50 - 0
boxcost/api/diff-logs.go

@@ -0,0 +1,50 @@
+package api
+
+import (
+	"box-cost/db/repo"
+	"errors"
+
+	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson"
+)
+
+func PrintDiff(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	// id := c.Query("id")
+	// CollectionMaterial      = "material"
+	// CollectionCraft         = "craft"
+	// CollectionProduct       = "product"
+	// CollectionSupplier      = "supplier"
+	// CollectionSupplierPrice = "supplier-price"
+	// CollectionPack          = "pack"
+	// CollectionProductPlan   = "product-plan" // 计划
+	// CollectionBillPurchase  = "bill-purchase" // 材料采购单
+	// CollectionBillProduce   = "bill-produce"  // 工艺采购单
+	// CollectionBillProduct   = "bill-product" // 成品采购单
+
+	// CollectionSupplierMatprice     = "supplier-mats"
+	// CollectionSupplierCraftprice   = "supplier-crafts"
+	// CollectionSupplierProductprice = "supplier-product" // 成品采购
+	// CollectionIncrement            = "increment"
+	// CollectionSignature            = "signature"
+	// CollectionUsers                = "users"
+	// // 更改日志记录
+	// CollectionLogs        = "logs"
+	// CollectionRequestLogs = "request-logs"
+	// CollectionPlanTrack   = "plan-track"
+
+	// ?query={"targetId":"","collection":""}
+	page, size, query := UtilQueryPageSize(c)
+	if _, ok := query["targetId"]; !ok {
+		return errors.New("目标id不能为空"), nil
+	}
+	if _, ok := query["collection"]; !ok {
+		return errors.New("目标类型不能为空"), nil
+	}
+	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+		CollectName: repo.CollectionLogs,
+		Query:       query,
+		Page:        page,
+		Size:        size,
+		Sort:        bson.M{"createTime": -1},
+	})
+}

+ 2 - 0
boxcost/api/router.go

@@ -19,7 +19,9 @@ func RegRouters(svc *Service) {
 	boxcost.GET("/removeSyncBill", RemovePlanSyncBill)
 	boxcost.GET("/callback", callback)
 	boxcost.POSTJWT("/diffUpdatePlanTest", DiffUpdatePlanTest)
+	boxcost.POSTJWT("/diffUpdateProduceTest", DiffUpdateProduceTest)
 	boxcost.GET("/printDiff", PrintDiff)
+	boxcost.GETJWT("/logs/list", PrintDiff)
 	boxcost.POSTJWT("/download/plan/track", DownloadPlanTrack)
 
 	PlanTrack(boxcost)

+ 0 - 11
boxcost/boxcost.log

@@ -1,11 +0,0 @@
-{"level":"info","timestamp":"2023-06-14 12:50:44","message":"[error decoding key pack.components.1.stages.1.deliveryTime: parsing time \"2023-06-07 05:26:29.341\" as \"2006-01-02T15:04:05.999Z07:00\": cannot parse \" 05:26:29.341\" as \"T\"]","service_name":"boxcost"}
-{"level":"info","timestamp":"2023-06-14 12:53:15","message":"[error decoding key pack.components.1.stages.1.deliveryTime: parsing time \"2023-06-07 05:26:29.341\" as \"2006-01-02T15:04:05.999Z07:00\": cannot parse \" 05:26:29.341\" as \"T\"]","service_name":"boxcost"}
-{"level":"info","timestamp":"2023-06-14 12:53:59","message":"[error decoding key pack.components.1.stages.1.deliveryTime: parsing time \"2023-06-07 05:26:29.341\" as \"2006-01-02T15:04:05.999Z07:00\": cannot parse \" 05:26:29.341\" as \"T\"]","service_name":"boxcost"}
-{"level":"error","timestamp":"2023-10-27 15:27:12","message":"[Post \"http://localhost:3001/convert/office\": dial tcp 127.0.0.1:3001: connect: connection refused]","service_name":"boxcost"}
-{"level":"error","timestamp":"2023-10-27 15:27:12","message":"[Post \"http://localhost:3001/convert/office\": dial tcp 127.0.0.1:3001: connect: connection refused]","service_name":"boxcost"}
-{"level":"error","timestamp":"2023-10-27 15:27:12","message":"[Post \"http://localhost:3001/convert/office\": dial tcp 127.0.0.1:3001: connect: connection refused]","service_name":"boxcost"}
-{"level":"error","timestamp":"2023-10-27 15:27:13","message":"[Post \"http://localhost:3001/convert/office\": dial tcp 127.0.0.1:3001: connect: connection refused]","service_name":"boxcost"}
-{"level":"error","timestamp":"2023-10-27 15:27:24","message":"[Post \"http://localhost:3001/convert/office\": dial tcp 127.0.0.1:3001: connect: connection refused]","service_name":"boxcost"}
-{"level":"error","timestamp":"2023-10-27 15:27:24","message":"[Post \"http://localhost:3001/convert/office\": dial tcp 127.0.0.1:3001: connect: connection refused]","service_name":"boxcost"}
-{"level":"error","timestamp":"2023-10-27 15:27:24","message":"[Post \"http://localhost:3001/convert/office\": dial tcp 127.0.0.1:3001: connect: connection refused]","service_name":"boxcost"}
-{"level":"error","timestamp":"2023-10-27 15:27:24","message":"[Post \"http://localhost:3001/convert/office\": dial tcp 127.0.0.1:3001: connect: connection refused]","service_name":"boxcost"}

+ 11 - 7
boxcost/db/model/logs.go

@@ -7,11 +7,15 @@ import (
 )
 
 type Logs struct {
-	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	Path       string             `bson:"path,omitempty" json:"path"`
-	UserId     string             `bson:"userId,omitempty" json:"userId"`
-	TargetId   string             `bson:"targetId,omitempty" json:"targetId"`
-	Diff       string             `bson:"diff,omitempty" json:"diff"`
-	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
-	UpdateTime time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
+	Id       primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	Path     string             `bson:"path,omitempty" json:"path"`
+	UserId   string             `bson:"userId,omitempty" json:"userId"`
+	TargetId string             `bson:"targetId,omitempty" json:"targetId"`
+	// 哪个数据表
+	Collection string      `bson:"collection,omitempty" json:"collection"`
+	Diff       string      `bson:"diff,omitempty" json:"diff"`
+	Changes    []string    `bson:"changes,omitempty" json:"changes"`
+	UserInfo   *UserSmaple `bson:"userInfo,omitempty" json:"userInfo"`
+	CreateTime time.Time   `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime time.Time   `bson:"updateTime,omitempty" json:"updateTime"`
 }

+ 120 - 8
boxcost/db/repo/repo.go

@@ -2,11 +2,14 @@ package repo
 
 import (
 	"box-cost/db"
+	"box-cost/db/model"
 	dm "box-cost/db/model"
 	"box-cost/log"
 	"context"
 	"encoding/json"
 	"fmt"
+	"html"
+	"regexp"
 	"time"
 
 	"github.com/sergi/go-diff/diffmatchpatch"
@@ -147,6 +150,9 @@ func RepoUpdateSetDoc1(ctx *RepoSession, collectName string, idstr string, model
 	colls := ctx.Client.GetCollection(collectName)
 	update := bson.M{"$set": model}
 
+	// 获取模型对应的数据表
+	collection := getModel2Collection(model)
+
 	uid, _ := primitive.ObjectIDFromHex(idstr)
 
 	// ========================记录更新日志 查询更新前数据============================
@@ -164,18 +170,25 @@ func RepoUpdateSetDoc1(ctx *RepoSession, collectName string, idstr string, model
 	// ============================================================================
 
 	// ============================记录更新前后差异================================
-	diffStr, err := diffUpdateData(oldData, newData)
+	diff, err := diffUpdateData(oldData, newData)
+	if err != nil {
+		fmt.Println(err)
+	}
+	fmt.Println(diff.Diff)
+	userInfo, err := getUserById(ctx, recordLogReq.UserId)
 	if err != nil {
 		fmt.Println(err)
 	}
-	fmt.Println(diffStr)
 
 	// 记录到数据库中
 	changeLogs := &dm.Logs{
 		Path:       recordLogReq.Path,
 		UserId:     recordLogReq.UserId,
 		TargetId:   recordLogReq.TargetId,
-		Diff:       diffStr,
+		Collection: collection,
+		UserInfo:   userInfo,
+		Diff:       diff.Diff,
+		Changes:    diff.Changes,
 		CreateTime: time.Now(),
 		UpdateTime: time.Now(),
 	}
@@ -185,25 +198,124 @@ func RepoUpdateSetDoc1(ctx *RepoSession, collectName string, idstr string, model
 
 }
 
+func getUserById(ctx *RepoSession, id string) (*model.UserSmaple, error) {
+	user := &model.UserSmaple{}
+	_, err := RepoSeachDoc(ctx, &DocSearchOptions{
+		Db:          "box-user",
+		CollectName: CollectionUsers,
+		Query:       Map{"_id": id},
+		Project:     []string{"name", "avatar", "city", "loginName", "roles", "phone"},
+	}, user)
+	return user, err
+}
+
+func getModel2Collection(omodel interface{}) string {
+	// 订单
+	if _, ok := omodel.(*dm.PurchaseBill); ok {
+		return CollectionBillPurchase
+	}
+	// if _, ok := omodel.(*dm.ProduceBill); ok {
+	// 	return CollectionBillProduce
+	// }
+
+	// test
+	if _, ok := omodel.(*dm.ProduceBill); ok {
+		return "bill-produce_copy1"
+	}
+
+	if _, ok := omodel.(*dm.ProductBill); ok {
+		return CollectionBillProduct
+	}
+
+	// 计划
+	// if _, ok := omodel.(*dm.ProductPlan); ok {
+	// 	return CollectionProductPlan
+	// }
+
+	// test
+	if _, ok := omodel.(*dm.ProductPlan); ok {
+		return "product-plan_copy1"
+	}
+
+	if _, ok := omodel.(*dm.Product); ok {
+		return CollectionProduct
+	}
+
+	// craft
+	if _, ok := omodel.(*dm.Craft); ok {
+		return CollectionCraft
+	}
+
+	// material
+	if _, ok := omodel.(*dm.Material); ok {
+		return CollectionMaterial
+	}
+
+	// pack
+	if _, ok := omodel.(*dm.Pack); ok {
+		return CollectionPack
+	}
+
+	if _, ok := omodel.(*dm.PlanTrack); ok {
+		return CollectionPlanTrack
+	}
+
+	if _, ok := omodel.(*dm.Signature); ok {
+		return CollectionSignature
+	}
+
+	if _, ok := omodel.(*dm.Supplier); ok {
+		return CollectionSupplier
+	}
+
+	if _, ok := omodel.(*dm.Setting); ok {
+		return "infos"
+	}
+
+	if _, ok := omodel.(*dm.Unit); ok {
+		return "units"
+	}
+
+	if _, ok := omodel.(*dm.Category); ok {
+		return "cates"
+	}
+
+	return ""
+}
+
+type DiffUpdateData struct {
+	Diff    string
+	Changes []string
+}
+
 // 比较差异字符
-func diffUpdateData(oldObj any, newObj any) (diffStr string, err error) {
+func diffUpdateData(oldObj any, newObj any) (*DiffUpdateData, error) {
 	oldObjByte, err := json.Marshal(oldObj)
 	if err != nil {
-		return "", err
+		return &DiffUpdateData{}, err
 	}
 	newObjByte, err := json.Marshal(newObj)
 	if err != nil {
-		return "", err
+		return &DiffUpdateData{}, err
 	}
 
 	dmp := diffmatchpatch.New()
 	diffs := dmp.DiffMain(string(oldObjByte), string(newObjByte), false)
+
 	// 返回差异数据用于日志记录
+	diff := &DiffUpdateData{}
 	if len(diffs) > 0 {
-		return dmp.DiffPrettyText(diffs), nil
+		// return dmp.DiffPrettyText(diffs), nil
+		htmlString := html.UnescapeString(dmp.DiffPrettyHtml(diffs))
+		delInsRegex := regexp.MustCompile(`"([^"]+)":\s*"([^"]*(<del[^>]*>.*?</del>|<ins[^>]*>.*?</ins>)+[^"]*)",`)
+		delInsMatches := delInsRegex.FindAllString(htmlString, -1)
+		diff.Diff = htmlString
+		diff.Changes = delInsMatches
+		return diff, nil
+
 	}
 
-	return "", err
+	return &DiffUpdateData{}, err
 }
 
 func RepoUpdateSeDbDoc(ctx *RepoSession, db string, collectName string, idstr string, model interface{}) (*mongo.UpdateResult, error) {

+ 8 - 2
boxcost/middleware/logger.go

@@ -66,9 +66,15 @@ func CreateLog(start time.Time, reqb string, resb string, session *repo.RepoSess
 	ip := c.ClientIP()
 	code := c.Writer.Status()
 	query := c.Request.URL.RawQuery
-	id, _ := c.Get("userId")
+	_id, _ := c.Get("userId")
+	id := ""
+	if _id == nil {
+		id = ""
+	} else {
+		id = _id.(string)
+	}
 	requesLogs := &model.RequestLogs{
-		UserId:     id.(string),
+		UserId:     id,
 		Path:       path,
 		Method:     method,
 		Ip:         ip,

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно