Răsfoiți Sursa

创建信息-日志记录

apple 5 ani în urmă
părinte
comite
7639ff72c3

+ 2 - 3
src/config.json

@@ -5,9 +5,8 @@
   "dbsize": 5,
   "dbname": "datatag",
   "jydbname": "extract_kf",
-  "jycollname1": "zk_xiufu_test01",
-  "jycollname2": "zk_xiufu_test",
-  "jyrecord": "zk_record",
+  "jycollname1": "zk_xiufu_test",
+  "jycollname2": "zk_xiufu_test01",
   "mgodben": "192.168.3.207:27092",
   "dbnameen": "enterprise",
   "mongoenc": "winner_enterprise",

+ 96 - 35
src/service/repair_rule.go

@@ -4,8 +4,10 @@ import (
 	"github.com/go-xweb/xweb"
 	"gopkg.in/mgo.v2/bson"
 	"log"
+	"qfw/common/src/qfw/util"
 	qu "qfw/util"
 	"qfw/util/elastic"
+	"time"
 	. "util"
 )
 
@@ -17,6 +19,9 @@ type RepairRule struct {
 	repairEdit     xweb.Mapper `xweb:"/service/jianyu/edit"`
 	repairDelete   xweb.Mapper `xweb:"/service/jianyu/delete"`
 	repairSave     xweb.Mapper `xweb:"/service/jianyu/save"`
+	repairCreate   xweb.Mapper `xweb:"/service/jianyu/create"`
+	repairNewSave   xweb.Mapper `xweb:"/service/jianyu/newSave"`
+
 
 }
 
@@ -28,6 +33,64 @@ func (jy *RepairRule) RepairList() {
 
 }
 
+func (jy *RepairRule) RepairNewSave() {
+	defer qu.Catch()
+	log.Println("新增数据")
+	//mongo新增
+	request_data := GetPostForm(jy.Request)
+	updata:=qu.ObjToMap(request_data["data"])
+	reasons := qu.ObjToString(request_data["reasons"])
+	new_data:=*updata
+	delete(*updata,"_id")
+	cur_id:=JYMgo.Save(JyCollNameTwo,*updata)
+	if cur_id!="" {
+		log.Println("当前新增id:",cur_id)
+		//新增es
+		client := elastic.GetEsConn()
+		defer elastic.DestoryEsConn(client)
+		_, err := client.Index().Index(EsIndex).Type(EsType).Id(cur_id).BodyJson(util.ObjToMap(*updata)).Do()
+		if err != nil {
+			log.Println("保存到ES出错", err)
+		}
+
+		//日志记录
+		user := jy.GetSession("user").(map[string]interface{})
+		log_data :=map[string]interface{}{
+			"s_modifyuser":user["name"],
+			"s_type":1,
+			"i_modifytime":time.Now().Unix(),
+			"s_modifyreason":reasons,
+			"o_oldinfo":map[string]interface{}{},
+			"o_newinfo":new_data,
+		}
+		Mgo.Save(JyRecord,log_data)
+
+
+		jy.ServeJson(map[string]interface{}{
+			"rep": true,
+		})
+
+
+	}else {
+		jy.ServeJson(map[string]interface{}{
+			"rep": false,
+		})
+	}
+
+
+
+}
+
+
+//新增数据
+func (jy *RepairRule) RepairCreate() {
+	defer qu.Catch()
+	jy.T["detail"] = map[string]string{"detail":""}
+	jy.T["contenthtml"] = map[string]string{"contenthtml":""}
+	jy.T["data"] = map[string]string{"title":"新增信息等等"}
+	jy.Render("repair/jianyu_create.html", &jy.T)
+}
+
 //编辑
 func (jy *RepairRule) RepairEdit() {
 	defer qu.Catch()
@@ -54,8 +117,7 @@ func (jy *RepairRule) RepairDelete() {
 	defer qu.Catch()
 	id := jy.GetString("_id")
 	coll := jy.GetString("coll")
-	souredata, _ := JYMgo.FindById(coll,id,"")//记录当前表的源数据
-
+	old_data, _ := JYMgo.FindById(coll,id,"")//记录当前表的源数据
 	log.Println(id,coll)
 	set := bson.M{"_id":qu.StringTOBsonId(id)}
 	b :=JYMgo.Del(coll,set)
@@ -73,22 +135,20 @@ func (jy *RepairRule) RepairDelete() {
 			log.Println("delete es err:", err)
 		}
 
-		//新增mongo记录
-		count := JYMgo.Count(JyRecord,bson.M{"_id": qu.StringTOBsonId(id)})
-		if count<=0 {
-			log.Println("删除-无记录-新增源数据:",id)
-			(*souredata)["is_exist_type"] = "0"
-			(*souredata)["is_exist_coll"] = coll
-			JYMgo.SaveByOriID(JyRecord,souredata)
-		}else {
-			log.Println("删除-有记录-更新数据:",id)
-			set := bson.M{
-				"$set": bson.M{
-					"is_exist_type": "0",
-				},
-			}
-			JYMgo.UpdateById(JyRecord, id, set)
+		//日志记录
+		user := jy.GetSession("user").(map[string]interface{})
+		log_data :=map[string]interface{}{
+			"s_modifyuser":user["name"],
+			"s_type":3,
+			"i_modifytime":time.Now().Unix(),
+			"s_modifyreason":"",
+			"o_oldinfo":old_data,
+			"o_newinfo":map[string]interface{}{},
 		}
+		Mgo.Save(JyRecord,log_data)
+
+
+
 
 		jy.ServeJson(map[string]interface{}{
 			"rep": b,
@@ -100,13 +160,13 @@ func (jy *RepairRule) RepairDelete() {
 //修改-mongo -es
 func (jy *RepairRule) RepairSave() {
 	if jy.Method() == "POST" {
-		data := GetPostForm(jy.Request)
-		updata:=qu.ObjToMap(data["data"])
-		coll:=qu.ObjToString(data["coll"])
+		request_data := GetPostForm(jy.Request)
+		updata:=qu.ObjToMap(request_data["data"])
+		coll:=qu.ObjToString(request_data["coll"])
+		reasons := qu.ObjToString(request_data["reasons"])
 		id := qu.ObjToString((*updata)["_id"])
-		souredata, _ := JYMgo.FindById(coll,id,"")//记录当前表的源数据
-
-
+		old_data, _ := JYMgo.FindById(coll,id,"")//记录当前表的源数据
+		new_data:=*updata
 		query := bson.M{
 			"_id": qu.StringTOBsonId(id),
 		}
@@ -127,19 +187,20 @@ func (jy *RepairRule) RepairSave() {
 				log.Println("update es err:", err)
 			}
 
-			//_, err := client.Index().Index(EsIndex).Type(EsType).Id(id).BodyJson(util.ObjToMap(*updata)).Do()
-			//if err != nil {
-			//	log.Println("保存到ES出错", err)
-			//}
-			count := JYMgo.Count(JyRecord,bson.M{"_id": qu.StringTOBsonId(id)})
-			if count<=0 {
-				(*souredata)["is_exist_type"] = "1"
-				(*souredata)["is_exist_coll"] = coll
-				log.Println("更新,无数据,记录源数据:",id)
-				JYMgo.SaveByOriID(JyRecord,souredata)
-			}else {
-				log.Println("更新,有数据,已记录:",id)
+			//日志记录
+			user := jy.GetSession("user").(map[string]interface{})
+			log_data :=map[string]interface{}{
+				"s_modifyuser":user["name"],
+				"s_type":2,
+				"i_modifytime":time.Now().Unix(),
+				"s_modifyreason":reasons,
+				"o_oldinfo":old_data,
+				"o_newinfo":new_data,
 			}
+			Mgo.Save(JyRecord,log_data)
+
+
+
 			jy.ServeJson(map[string]interface{}{
 				"rep": rep,
 			})

+ 1 - 1
src/util/config.go

@@ -64,7 +64,7 @@ func initJYMgo()  {
 	}
 	JyCollNameOne = qu.ObjToString(Sysconfig["jycollname1"])
 	JyCollNameTwo = qu.ObjToString(Sysconfig["jycollname2"])
-	JyRecord = qu.ObjToString(Sysconfig["jyrecord"])
+	JyRecord = "jymodifylog"
 	JYMgo.InitPool()
 
 }

+ 127 - 0
src/web/templates/repair/jianyu_create.html

@@ -0,0 +1,127 @@
+{{include "com/inc.html"}}
+<!-- Main Header -->
+{{include "com/header.html"}}
+<!-- Left side column. 权限菜单 -->
+{{include "com/menu.html"}}
+{{include "com/modal.html"}}
+
+<style>
+    /* 方法1:设置textarea合适的宽高 */
+    #jsonTextarea {
+        float: left;
+        margin-right: 20px;
+        width: 40%;
+        height: 70vh;
+        outline: none;
+        padding: 5px;
+    }
+
+    /* 方法2:自定义高亮样式 */
+    #jsonPre {
+        float: left;
+        width: 40%;
+        height: 70vh;
+        outline: 1px solid #ccc;
+        padding: 5px;
+        overflow: scroll;
+    }
+</style>
+
+<div class="content-wrapper">
+    <section class="content-header">
+        <h1>新增数据</h1>
+        <ol class="breadcrumb">
+            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
+            <li><a href="/service/jianyu/repair">数据中心</a></li>
+            <li><a href="#">添加数据</a></li>
+        </ol>
+    </section>
+    <!-- Main content -->
+    <section class="content">
+        <div class="nav-tabs-custom">
+            <ul class="nav nav-tabs edit-step">
+                </br>
+                <button class="btn btn-primary btn-sm" style="float: right;margin-top: 7px;margin-right: 10px" onclick="saveRepair()"><i class="fa fa-fw fa-file-text fa-lg"></i>保存数据</button>
+                </br></br></br>
+            </ul>
+
+
+            <div class="box-body">
+                <div class="form-group">
+                    <div class="col-sm-3">
+                        <input type="text" class="form-control" id="reasons" placeholder="请输入新增原因" required>
+                    </div>
+                </div>
+            </div>
+
+
+
+            <form class="form-horizontal">
+                <div class="box-body">
+                    <textarea id="jsonTextarea" style="width: 100%;height: 300px"></textarea>
+                </div>
+                <div class="box-body">
+                    <textarea id="jsonDetail" style="width: 100%;height: 300px"></textarea>
+                    <textarea id="jsonContentHtml" style="width: 100%;height: 300px"></textarea>
+
+                </div>
+            </form>
+        </div>
+    </section>
+</div>
+
+{{include "com/dialog.html"}}
+{{include "com/footer.html"}}
+<script>
+    menuActive("/service/jianyu/repair");
+    var new_data = {{.T.data}};
+    var new_detail = {{.T.detail}};
+    var new_contentHtml = {{.T.contenthtml}};
+
+    function parse(str) {
+        return JSON.stringify(str, null, "\t")
+    }
+
+    $('#jsonTextarea').val(parse(new_data));
+    $('#jsonDetail').val(parse(new_detail));
+    $('#jsonContentHtml').val(parse(new_contentHtml));
+
+    //添加更新
+    function saveRepair() {
+        showConfirm("确定添加新信息?", function() {
+            var curData = document.getElementById('jsonTextarea').value;
+            var data = JSON.parse(curData)
+            var updata = {}
+            for (var k in data) {
+                updata[k] = data[k]
+            }
+            alert(JSON.stringify(updata))
+            var content = document.getElementById('jsonContentHtml').value;
+            var conData = JSON.parse(content)
+            updata["contenthtml"] = conData["contenthtml"]
+
+            var detail = document.getElementById('jsonDetail').value;
+            var detData = JSON.parse(detail)
+            updata["detail"] = detData["detail"]
+
+            alert(JSON.stringify(updata))
+            $.ajax({
+                url: "/service/jianyu/newSave",
+                type: 'POST',
+                data: {"data":JSON.stringify(updata),"reasons":$("#reasons").val()},
+                success: function (task) {
+                    if (task.rep) {
+                        window.location.href="/service/jianyu/repair"
+                    } else {
+                        showTip("添加失败,请检查数据后在试");
+                    }
+                }
+            })
+        });
+
+
+    }
+
+
+
+</script>

+ 40 - 29
src/web/templates/repair/jianyu_edit.html

@@ -27,8 +27,7 @@
     }
 </style>
 
-{{/*<script src="/time/js/angular.min.js"></script>*/}}
-{{/*<script src="/time/js/wui-date.js"></script>*/}}
+
 <div class="content-wrapper">
     <section class="content-header">
         <h1>维护数据</h1>
@@ -46,6 +45,13 @@
                 <button class="btn btn-primary btn-sm" style="float: right;margin-top: 7px;margin-right: 10px" onclick="saveRepair()"><i class="fa fa-fw fa-file-text fa-lg"></i>更新数据</button>
                 </br></br></br>
             </ul>
+            <div class="box-body">
+                <div class="form-group">
+                    <div class="col-sm-3">
+                        <input type="text" class="form-control" id="reasons" placeholder="请输入更新原因" required>
+                    </div>
+                </div>
+            </div>
             <form class="form-horizontal">
                 <div class="box-body">
                     <textarea id="jsonTextarea" style="width: 100%;height: 300px"></textarea>
@@ -80,34 +86,39 @@
 
     //更新
     function saveRepair() {
-        var curData = document.getElementById('jsonTextarea').value;
-        var data = JSON.parse(curData)
-        var updata = {}
-        for (var k in data) {
-            updata[k] = data[k]
-        }
-        var content = document.getElementById('jsonContentHtml').value;
-        var conData = JSON.parse(content)
-        updata["contenthtml"] = conData["contenthtml"]
-
-        var detail = document.getElementById('jsonDetail').value;
-        var detData = JSON.parse(detail)
-        updata["detail"] = detData["detail"]
-
-        // alert(JSON.stringify(updata))
-
-        $.ajax({
-            url: "/service/jianyu/save",
-            type: 'POST',
-            data: {"data":JSON.stringify(updata),"coll":edit_coll},
-            success: function (task) {
-                if (task.rep) {
-                    window.location.href="/service/jianyu/repair"
-                } else {
-                    showTip("更新失败,请稍后在试");
-                }
+
+        showConfirm("确定更新信息?", function() {
+
+            var curData = document.getElementById('jsonTextarea').value;
+            var data = JSON.parse(curData)
+            var updata = {}
+            for (var k in data) {
+                updata[k] = data[k]
             }
-        })
+            var content = document.getElementById('jsonContentHtml').value;
+            var conData = JSON.parse(content)
+            updata["contenthtml"] = conData["contenthtml"]
+
+            var detail = document.getElementById('jsonDetail').value;
+            var detData = JSON.parse(detail)
+            updata["detail"] = detData["detail"]
+
+            // alert(JSON.stringify(updata))
+
+            $.ajax({
+                url: "/service/jianyu/save",
+                type: 'POST',
+                data: {"data":JSON.stringify(updata),"coll":edit_coll,"reasons":$("#reasons").val()},
+                success: function (task) {
+                    if (task.rep) {
+                        window.location.href="/service/jianyu/repair"
+                    } else {
+                        showTip("更新失败,请稍后在试");
+                    }
+                }
+            })
+        });
+
     }
 
 

+ 7 - 4
src/web/templates/repair/jianyu_repair.html

@@ -41,6 +41,10 @@
 
 <div class="content-wrapper" id="showbtn">
     <section class="content-header">
+
+        <h1>
+            <small><a href="/service/jianyu/create" class="btn btn-primary opr">新增信息</a></small>
+        </h1>
         <ol class="breadcrumb">
             <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
             <li><a href="/service/jianyu/repair"> 维护中心</a></li>
@@ -116,12 +120,12 @@
             },
             "columns": [
                 {"data": null,width:"8%"},
-                {"data": "title"},
-                {"data": "href",width:"20%"},
+                {"data": "title",width:"25%"},
+                {"data": "href",width:"15%"},
                 {"data": null,width:"10%", render: function (val){
                         return curColl
                     }},
-                {"data": "publishtime",width:"18%", render: function (val) {
+                {"data": "publishtime",width:"15%", render: function (val) {
                         var dt = new Date()
                         dt.setTime(parseInt(val) * 1000);
                         return dt.format("yyyy-MM-dd hh-mm-ss")
@@ -138,7 +142,6 @@
         });
     });
 
-
     function idSearch() {
         var search_name = $('#idSea').val()
         $.ajax({