|
@@ -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,
|
|
|
})
|