Browse Source

Merge branch 'dev-ent_v1.0' of ssh://192.168.3.207:10022/qmx/datatag into dev-ent_v1.0

# Conflicts:
#	src/service/customer_service.go
zouyuxuan 5 years ago
parent
commit
33fba70821

+ 36 - 4
src/history/historytask.go

@@ -12,10 +12,12 @@ import (
 type HistoryData struct {
 	*xweb.Action
 	historyTask xweb.Mapper `xweb:"/service/history/(.*)"`
+	historyList xweb.Mapper `xweb:"/service/historylog/list"`
 }
 
 func (this *HistoryData) HistoryTask(history_id string) {
 	log.Println("开始历史任务...")
+	go UpdateHistoryState(1, history_id, 0)
 	//加载一个客户
 	log.Println("history_id", history_id)
 	customer, _ := Mgo.Find("historylog", map[string]interface{}{"_id": qu.StringTOBsonId(history_id)}, nil, nil, false, -1, -1)
@@ -52,17 +54,47 @@ func (this *HistoryData) HistoryTask(history_id string) {
 		}
 		tag_rules := qu.ObjArrToMapArr(tag_rule)
 		dep_rules := qu.ObjArrToMapArr(dep_rule)
-		log.Println(tag_rules)
-		log.Println(dep_rules)
 		cus.GetTagRules(tag_rules)               //获取客户打标签规则
 		cus.GetDepartments("history", dep_rules) //获取客户信息
 		//PrintLog(cus)        //打印查看初始化的信息
 		qu.Debug("customer:", cus.ID, cus.Name, cus.PushModel, cus.AppId, cus.IsTagRule, cus.IsSearchHosp, cus.IsSearchEnps, len(cus.TagRules), len(cus.Departments))
 		cus.GetData("history") //获取数据
+		// log.Println("c.SaveDataMap111", cus.SaveDataMap)
 		cus.RemoveRepeatData() //数据去重
-
-		cus.AssembelAndSaveData() //组装、保存数据
+		// log.Println("c.SaveDataMap222", cus.SaveDataMap)
+		resultcount := cus.AssembelAndSaveData(history_id) //组装、保存数据
+		go UpdateHistoryState(2, history_id, resultcount)
 	} else {
 		log.Println("初始化客户信息失败")
 	}
 }
+
+func (this *HistoryData) HistoryList() {
+	id := this.GetString("id")
+	if this.Method() == "POST" {
+		data, _ := Mgo.Find("historylog", `{"user_id":"`+id+`"}`, `{updatetime: desc}`, nil, false, -1, -1)
+		this.ServeJson(map[string]interface{}{
+			"data": data,
+		})
+	} else {
+		this.T["id"] = id
+		this.Render("private/historylog_list.html", &this.T)
+	}
+}
+
+func UpdateHistoryState(state int, history_id string, count int) {
+	if state == 2 {
+		Mgo.Update("historylog", map[string]interface{}{"_id": qu.StringTOBsonId(history_id)}, map[string]interface{}{
+			"$set": map[string]interface{}{
+				"state":        state,
+				"result_count": count,
+			},
+		}, false, false)
+		return
+	}
+	Mgo.Update("historylog", map[string]interface{}{"_id": qu.StringTOBsonId(history_id)}, map[string]interface{}{
+		"$set": map[string]interface{}{
+			"state": state,
+		},
+	}, false, false)
+}

+ 35 - 19
src/history/task.go

@@ -38,9 +38,15 @@ func (c *Customer) GetTagRules(tagRules []map[string]interface{}) {
 					TR.DepartRuleIds[drid] = true
 				}
 			}
+
+			o_list, ok := tr["o_list"].([]interface{})
+			if !ok {
+				o_list = []interface{}{}
+			}
+			o_lists := qu.ObjArrToMapArr(o_list)
 			//规则
-			if o_list, ok := tr["o_list"].(primitive.A); ok && len(o_list) > 0 {
-				TR.GetKeyAddNotKeyWord(o_list)
+			if len(o_list) > 0 {
+				TR.GetKeyAddNotKeyWord(o_lists)
 			}
 			c.TagRules = append(c.TagRules, TR)
 		}
@@ -54,9 +60,9 @@ func (c *Customer) GetDepartments(stype string, departments []map[string]interfa
 	if len(departments) > 0 {
 		departMap := map[string]interface{}{}
 		for _, ds := range departments {
-			s_id := qu.BsonIdToSId(ds["s_departid"])
+			s_id := qu.ObjToString(ds["s_departid"])
 			if departMap[s_id] == nil {
-				departMap[s_id] = ds["s_departid_name"]
+				departMap[s_id] = ds["s_depart_name"]
 			}
 		}
 		for k, v := range departMap {
@@ -71,14 +77,15 @@ func (c *Customer) GetDepartments(stype string, departments []map[string]interfa
 			DM.CustomerID = c.ID
 			dsArr := []map[string]interface{}{}
 			for _, ds := range departments {
-				s_id := qu.BsonIdToSId(ds["s_departid"])
+				s_id := qu.ObjToString(ds["s_departid"])
 				if s_id == k {
 					dsArr = append(dsArr, ds)
 				}
 			}
 			DM.GetSearchRules(c.ID, stype, c.IdRange, dsArr) //获取某个部门的所有规则
 			c.Departments = append(c.Departments, DM)
-			//qu.Debug("Departments---", DM.ID, DM.Name, DM.CustomerID, len(DM.Rules))
+			qu.Debug("Departments---", DM.ID, DM.Name, DM.CustomerID, len(DM.Rules))
+			log.Println(DM.Rules)
 		}
 	}
 }
@@ -195,18 +202,18 @@ func (c *Customer) GetData(stype string) {
 								*/
 								//1.附加词匹配
 								IsMatch := false
-								//qu.Debug("sr.AW---", len(sr.AW))
+								qu.Debug("sr.AW---", len(sr.AW))
 								for i, aw := range sr.AW {
-									//qu.Debug("-------------------------开始附加词匹配--------------------------")
+									qu.Debug("-------------------------开始附加词匹配--------------------------")
 									IsMatchAddKey := RegMatch(fieldText, aw.MatchType, aw.KeyReg, nil, nil, false, true)
-									//qu.Debug(IsMatchAddKey, "------------------------------------------------------------")
+									qu.Debug(IsMatchAddKey, "------------------------------------------------------------")
 
 									//2.关键词匹配
 									if IsMatchAddKey {
 										kw := sr.KW[i]
-										//qu.Debug("-------------------------开始关键词匹配--------------------------")
+										qu.Debug("-------------------------开始关键词匹配--------------------------")
 										IsMatchKey := RegMatch(fieldText, kw.MatchType, kw.KeyReg, matchKey, matchKeyType, true, false)
-										//qu.Debug(IsMatchKey, "------------------------------------------------------------")
+										qu.Debug(IsMatchKey, "------------------------------------------------------------")
 										if IsMatchKey {
 											IsMatch = true
 										}
@@ -215,7 +222,7 @@ func (c *Customer) GetData(stype string) {
 								/*
 									到此已经匹配完数据
 								*/
-								//qu.Debug("---------------------", id, IsMatch, matchKey)
+								qu.Debug("---------------------", id, IsMatch, matchKey)
 								if IsMatch { //匹配成功,数据上新增规则id,matchKey,item并临时保存数据
 									tmpMatchKey := MapDataToArr(matchKey)
 									tmpMatchKeyType := MapDataToArr(matchKeyType)
@@ -350,7 +357,7 @@ func (c *Customer) RemoveRepeatData() {
 }
 
 //组装保存数据
-func (c *Customer) AssembelAndSaveData() {
+func (c *Customer) AssembelAndSaveData(historyId string) int {
 	log.Println("开始组装保存数据...")
 	defer qu.Catch()
 	ch := make(chan bool, 10)
@@ -365,7 +372,7 @@ func (c *Customer) AssembelAndSaveData() {
 					<-ch
 					wg.Done()
 				}()
-				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps)
+				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId)
 			}(tmp)
 			n++
 			if n%500 == 0 {
@@ -384,7 +391,7 @@ func (c *Customer) AssembelAndSaveData() {
 							<-ch
 							wg.Done()
 						}()
-						AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps)
+						AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId)
 					}(tmp)
 					n++
 					if n%500 == 0 {
@@ -403,7 +410,7 @@ func (c *Customer) AssembelAndSaveData() {
 					<-ch
 					wg.Done()
 				}()
-				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps)
+				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId)
 			}(tmp)
 			n++
 			if n%500 == 0 {
@@ -413,6 +420,7 @@ func (c *Customer) AssembelAndSaveData() {
 		wg.Wait()
 	}
 	log.Println("数据保存完毕...		Save Number:", n)
+	return n
 }
 
 //获取用户所有规则
@@ -442,11 +450,19 @@ func (d *Department) GetSearchRules(cid, stype string, idRange bson.M, searchRul
 				SR.GetEs(d.Name, esquery, idRange)
 			}
 			//获取关键词和附加词
-			if o_rules, ok := sr["o_rules"].(primitive.A); ok && len(o_rules) > 0 {
+			o_rule, ok := sr["o_rules"].([]interface{})
+			if !ok {
+				o_rule = []interface{}{}
+				log.Println("777")
+			}
+			o_rules := qu.ObjArrToMapArr(o_rule)
+			if len(o_rules) > 0 {
+				log.Println("666")
 				SR.GetKeyAddWord(o_rules)
 			}
 			//获取全局清理词
 			SR.GetClearWord(clearKey, clearKeyMatch)
+			log.Println("srsr", SR)
 			d.Rules = append(d.Rules, SR)
 		}
 	}
@@ -522,7 +538,7 @@ func (sr *SearchRule) GetClearWord(key, match string) {
 }
 
 //关键词、附加词处理
-func (sr *SearchRule) GetKeyAddWord(o_rules primitive.A) {
+func (sr *SearchRule) GetKeyAddWord(o_rules []map[string]interface{}) {
 	defer qu.Catch()
 	kw, aw, _, _ := GetNotkeyAndKeyAddWord(o_rules, sr.Fields, false)
 	sr.KW = kw
@@ -531,7 +547,7 @@ func (sr *SearchRule) GetKeyAddWord(o_rules primitive.A) {
 }
 
 //排除词、关键词、附加词处理
-func (tr *TagRule) GetKeyAddNotKeyWord(o_list primitive.A) {
+func (tr *TagRule) GetKeyAddNotKeyWord(o_list []map[string]interface{}) {
 	defer qu.Catch()
 	kw, aw, nkw, tagnames := GetNotkeyAndKeyAddWord(o_list, tr.Fields, true)
 	tr.NW = nkw

+ 4 - 3
src/history/util_history.go

@@ -29,10 +29,10 @@ var MatchType = map[string]interface{}{
 }
 
 //加载排除词、附加词、关键词
-func GetNotkeyAndKeyAddWord(list primitive.A, fieldMap map[string]interface{}, hasNotKey bool) (kws []*KeyWord, aws []*AddWord, nkws []*NotKeyWord, tagnames []string) {
+func GetNotkeyAndKeyAddWord(list []map[string]interface{}, fieldMap map[string]interface{}, hasNotKey bool) (kws []*KeyWord, aws []*AddWord, nkws []*NotKeyWord, tagnames []string) {
 	defer qu.Catch()
 	for _, rules := range list {
-		ruleMap := rules.(map[string]interface{})
+		ruleMap := rules
 		if hasNotKey { //是否处理排除词
 			//排除词匹配方式
 			nkm := qu.ObjToString(ruleMap["s_notkeymatch"])
@@ -440,7 +440,7 @@ func MergeField(str1, str2 string) string {
 }
 
 //补充信息并保存
-func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool) {
+func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool, historyId string) {
 	if IsSearchHosp { //医院信息
 		SearchHospInfo(tmp)
 	}
@@ -448,6 +448,7 @@ func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool) {
 		SearchEnterpriseInfo(tmp)
 	}
 	tmp["createtime"] = time.Now().Unix()
+	tmp["historyId"] = historyId
 	id := qu.ObjToString(tmp["id"])
 	tmp["jybxhref"] = `https://www.jianyu360.com/article/content/` + qu.CommonEncodeArticle("content", id) + `.html`
 	if publishtime, ok := tmp["publishtime"].(float64); ok && publishtime > 0 {

+ 233 - 120
src/service/customer_service.go

@@ -58,6 +58,9 @@ type Customer struct {
 	saveHistoryRule      xweb.Mapper `xweb:"/service/customer/history/saverule"`   //保存历史规则
 	historyRuleCreate    xweb.Mapper `xweb:"/service/cuser/rule/history/edit"`
 	historyCuserRuleList xweb.Mapper `xweb:"/service/tag/history/ruleList"` //私有标签关联历史规则
+	historyTagDel 		 xweb.Mapper `xweb:"/service/tag/history/del"` //历史任务删除私有标签
+	historyTagEdit 		 xweb.Mapper `xweb:"/service/tag/history/del"` //历史任务修改私有标签
+
 }
 
 func (c *Customer) CustomerList() {
@@ -872,26 +875,28 @@ func (c *Customer) CustomerHistory() {
 //选择历史规则
 func (c *Customer) CustomerAllRule() {
 	customerId := c.GetString("c_id")
+	log.Println("cid",customerId)
 	query := bson.M{
 		"s_userid": customerId,
 		"b_delete": false,
 	}
 	inc_query := bson.M{
-		"s_appid": customerId,
+		"user_id": customerId,
 	}
 	//获取新增历史规则
 	inc_rules := []map[string]interface{}{}
 	inc_rule := make(map[string]interface{})
 	inc_data, _ := Mgo.FindOne("historylog", inc_query)
 	if inc_data != nil && (len(*inc_data) != 0) {
-		for _, t := range (*inc_data)["dep_rule"].([]interface{}) {
-			if t.(map[string]interface{})["is_new"].(bool) {
-				inc_rule["id"] = t.(map[string]interface{})["id"] //规则id
+		for _, t := range (*inc_data)["dep_rules"].([]interface{}) {
+			if !t.(map[string]interface{})["is_new"].(bool) {
+				inc_rule["id"] = t.(map[string]interface{})["_id"].(bson.ObjectId).Hex() //规则id
 				inc_rule["s_depart_name"] = t.(map[string]interface{})["s_depart_name"]
-				inc_rule["s_name"] = t.(map[string]interface{})["s_name"]
+				inc_rule["s_name"] = t.(map[string]interface{})["s_tagname"]
 				inc_rule["s_depart_status"] = t.(map[string]interface{})["s_depart_status"]
 				inc_rule["s_rule_status"] = t.(map[string]interface{})["s_rule_status"]
-				inc_rule["rule_updatetime"] = t.(map[string]interface{})["rule_updatetime"]
+				inc_rule["rule_updatetime"] = t.(map[string]interface{})["i_updatetime"]
+				inc_rule["isinc"] = true
 				inc_rules = append(inc_rules, inc_rule)
 			}
 		}
@@ -933,66 +938,58 @@ func (c *Customer) CustomerAllRule() {
 //保存历史规则
 func (c *Customer) SaveHistoryRule() {
 	rules_id := c.GetString("rulesid")
+	//rules_id := c.GetSlice("rulesid")
 	userid := c.GetString("userid")
-	log.Println("userid",userid)
-	user_rules := make(map[string]interface{})
-	user_history, _ := Mgo.FindOne("historylog", map[string]interface{}{
-		"user_id":userid,
-	})
-	if *user_history != nil&&len(*user_history)!=0 {
-		dep_rules := (*user_history)["dep_rules"].([]interface{})
-		for _, m := range dep_rules {
-			if strings.Contains(rules_id,m.(map[string]interface{})["_id"].(bson.ObjectId).Hex()) {
-				continue
-			}
-			rules_id_list := strings.Split(rules_id, ",")
-			for _, rule := range rules_id_list {
-				//dep_rule := make(map[string]interface{})
-				query := bson.M{
-					"_id":      bson.ObjectIdHex(rule),
-					"b_delete": false,
+	if userid != "" {
+		user_rules := make(map[string]interface{})
+		user_history, _ := Mgo.FindOne("historylog", map[string]interface{}{
+			"user_id": userid,
+		})
+		if *user_history != nil && len(*user_history) != 0 {
+			dep_rules := (*user_history)["dep_rules"].([]interface{})
+			for _, m := range dep_rules {
+				if strings.Contains(rules_id, m.(map[string]interface{})["_id"].(bson.ObjectId).Hex()) {
+					continue
 				}
-				res, _ := Mgo.FindOne("euserdepartrule", query)
-				if res != nil && len(*res) != 0 {
-					//获取规则所属部门信息
-					department_info, _ := Mgo.FindOne("euserdepart", map[string]interface{}{
-						"_id":      bson.ObjectIdHex((*res)["s_departid"].(string)),
+				rules_id_list := strings.Split(rules_id, ",")
+				for _, rule := range rules_id_list {
+					//dep_rule := make(map[string]interface{})
+					query := bson.M{
+						"_id":      bson.ObjectIdHex(rule),
 						"b_delete": false,
+					}
+					res, _ := Mgo.FindOne("euserdepartrule", query)
+					if res != nil && len(*res) != 0 {
+						//获取规则所属部门信息
+						department_info, _ := Mgo.FindOne("euserdepart", map[string]interface{}{
+							"_id":      bson.ObjectIdHex((*res)["s_departid"].(string)),
+							"b_delete": false,
+						})
+						(*res)["is_new"] = false
+						(*res)["s_depart_name"] = (*department_info)["s_name"]
+						dep_rules = append(dep_rules, *res)
+					}
+				}
+				set := bson.M{
+					"$set": bson.M{
+						"dep_rules":  dep_rules,
+						"updatetime": time.Now().Unix(),
+					},
+				}
+				isupdata := Mgo.Update("historylog", map[string]interface{}{
+					"user_id": userid,
+				}, set, false, false)
+				if isupdata {
+					c.ServeJson(map[string]interface{}{
+						"status": "success",
+					})
+				} else {
+					c.ServeJson(map[string]interface{}{
+						"status": "fail",
 					})
-					//dep_rule["_id"] = (*res)["_id"]
-					//dep_rule["is_new"] = false
-					//dep_rule["s_departid"] = (*res)["s_departid"]
-					//dep_rule["s_name"] = (*res)["s_tagname"]
-					//dep_rule["o_rules"] = *res
-					//dep_rule["rule_updatetime"] = (*department_info)["i_updatetime"]
-					//dep_rule["s_depart_name"] =
-					//dep_rule["s_depart_status"] = (*department_info)["i_isuse"]
-					(*res)["is_new"] = false
-					(*res)["s_depart_name"] = (*department_info)["s_name"]
-					dep_rules = append(dep_rules, *res)
 				}
 			}
-			set := bson.M{
-				"$set": bson.M{
-					"dep_rules": dep_rules,
-					"createtime": time.Now().Unix(),
-				},
-			}
-			isupdata:=Mgo.Update("historylog", map[string]interface{}{
-				"user_id": userid,
-			}, set,false,false)
-			if isupdata {
-				c.ServeJson(map[string]interface{}{
-					"status": "success",
-				})
-			} else {
-				c.ServeJson(map[string]interface{}{
-					"status": "fail",
-				})
-			}
-		}
-	} else {
-		if userid != "" {
+		} else {
 			//获取私有标签
 			usertags := getTserTag(userid)
 			user_rules["tag_rules"] = usertags
@@ -1003,54 +1000,83 @@ func (c *Customer) SaveHistoryRule() {
 				user_rules["s_name"] = (*userinfo)["s_customername"]
 				user_rules["s_appid"] = (*userinfo)["s_appid"]
 			}
-		}
-		//获取用户规则
-		if rules_id != "" {
-			dep_rules := []interface{}{}
-			rules_id_list := strings.Split(rules_id, ",")
-			for _, rule := range rules_id_list {
-				//dep_rule := make(map[string]interface{})
-				query := bson.M{
-					"_id":      bson.ObjectIdHex(rule),
-					"b_delete": false,
+			//获取用户规则
+			if rules_id != "" {
+				dep_rules := []interface{}{}
+				rules_id_list := strings.Split(rules_id, ",")
+				for _, rule := range rules_id_list {
+					//dep_rule := make(map[string]interface{})
+					query := bson.M{
+						"_id":      bson.ObjectIdHex(rule),
+						"b_delete": false,
+					}
+					res, _ := Mgo.FindOne("cuserdepartrule", query)
+					if res != nil && len(*res) != 0 {
+						//获取规则所属部门信息
+						department_info, _ := Mgo.FindOne("cuserdepart", map[string]interface{}{
+							"_id":      bson.ObjectIdHex((*res)["s_departid"].(string)),
+							"b_delete": false,
+						})
+						(*res)["is_new"] = false
+						(*res)["s_depart_name"] = (*department_info)["s_name"]
+						dep_rules = append(dep_rules, *res)
+					}
+				}
+				user_rules["dep_rules"] = dep_rules
+				user_rules["user_id"] = userid
+				user_rules["createtime"] = time.Now().Unix()
+				user_rules["state"] = 0
+
+				userinfo, _ := Mgo.FindOne("euer", map[string]interface{}{
+					"s_userid": userid,
+				})
+				if userinfo != nil && len(*userinfo) != 0 {
+					log.Println("s_name", user_rules["s_name"])
+					user_rules["s_name"] = (*userinfo)["s_customername"]
+					user_rules["s_appid"] = (*userinfo)["s_appid"]
 				}
-				res, _ := Mgo.FindOne("cuserdepartrule", query)
-				if res != nil && len(*res) != 0 {
-					//获取规则所属部门信息
-					department_info, _ := Mgo.FindOne("cuserdepart", map[string]interface{}{
-						"_id":      bson.ObjectIdHex((*res)["s_departid"].(string)),
+			}
+			//获取用户规则
+			if rules_id != "" {
+				dep_rules := []interface{}{}
+				for _, rule := range strings.Split(rules_id, ",") {
+					//dep_rule := make(map[string]interface{})
+					query := bson.M{
+						"_id":      bson.ObjectIdHex(rule),
 						"b_delete": false,
-					})
-					//dep_rule["id"] = (*res)["_id"].(bson.ObjectId).Hex()
-					//dep_rule["is_new"] = false
-					//dep_rule["s_departid"] = (*res)["s_departid"]
-					//dep_rule["s_name"] = (*res)["s_tagname"]
-					//dep_rule["o_rules"] = *res
-					//dep_rule["rule_updatetime"] = (*department_info)["i_updatetime"]
-					//dep_rule["s_depart_name"] = (*department_info)["s_name"]
-					//dep_rule["s_depart_status"] = (*department_info)["i_isuse"]
-					(*res)["is_new"] = false
-					(*res)["s_depart_name"] = (*department_info)["s_name"]
-					dep_rules = append(dep_rules, *res)
+					}
+					res, _ := Mgo.FindOne("cuserdepartrule", query)
+					if res != nil && len(*res) != 0 {
+						//获取规则所属部门信息
+						department_info, _ := Mgo.FindOne("cuserdepart", map[string]interface{}{
+							"_id":      bson.ObjectIdHex((*res)["s_departid"].(string)),
+							"b_delete": false,
+						})
+						(*res)["is_new"] = false
+						(*res)["s_depart_name"] = (*department_info)["s_name"]
+						dep_rules = append(dep_rules, *res)
+					}
 				}
+				//获取私有标签
+				usertags := getTserTag(userid)
+				user_rules["dep_rules"] = dep_rules
+				user_rules["tag_rules"] = usertags
+				user_rules["createtime"] = time.Now().Unix()
+			}
+			issave := Mgo.Save("historylog", user_rules)
+			if issave != "" {
+				c.ServeJson(map[string]interface{}{
+					"status": "success",
+				})
+			} else {
+				c.ServeJson(map[string]interface{}{
+					"status": "fail",
+				})
 			}
-			user_rules["dep_rules"] = dep_rules
-			user_rules["user_id"] = userid
-			user_rules["createtime"] = time.Now().Unix()
-			user_rules["state"] = 0
 
 		}
-		issave := Mgo.Save("historylog", user_rules)
-		if issave != "" {
-			c.ServeJson(map[string]interface{}{
-				"status": "success",
-			})
-		} else {
-			c.ServeJson(map[string]interface{}{
-				"status": "fail",
-			})
-		}
 	}
+
 }
 
 func (c *Customer) HistoryRuleCreate() {
@@ -1099,9 +1125,9 @@ func (c *Customer) HistoryRuleCreate() {
 			data["b_delete"] = false
 			data["s_dataid"] = qu.SE.EncodeString(fmt.Sprintf("%v", i_createtime) + s_tagnamekey + s_id)
 			data["i_type"] = "historyData"
-			id = Mgo.Save("cuserdepartrule", data)
+			id = Mgo.Save("euserdepartrule", data)
 			if id != "" {
-				rep = true
+				rep = AddHistoryLog(data, false, id)
 			} else {
 				rep = false
 			}
@@ -1109,7 +1135,10 @@ func (c *Customer) HistoryRuleCreate() {
 			query := bson.M{
 				"_id": qu.StringTOBsonId(id),
 			}
-			rep = Mgo.Update("cuserdepartrule", query, bson.M{"$set": data}, false, false)
+			reps := Mgo.Update("euserdepartrule", query, bson.M{"$set": data}, false, false)
+			if reps {
+				rep = AddHistoryLog(data, true, id)
+			}
 		}
 
 		c.ServeJson(map[string]interface{}{
@@ -1123,6 +1152,7 @@ func (c *Customer) HistoryRuleCreate() {
 		c.T["did"] = id //部门id
 		c.T["cid"] = id //客户id
 		c.T["ids"] = id
+		c.T["history_id"] = c.GetString("hid")
 		c.T["province"] = Province
 		c.T["city"] = ProvinceCitys
 		c.T["district"] = CityDistricts
@@ -1142,20 +1172,20 @@ func (c *Customer) HistoryTagAssociated() {
 	defer qu.Catch()
 	userid := c.GetString("userid")
 	rule_id := c.GetString("_id")
-	tags :=c.GetString("ids")
-	tags_id := strings.Split(tags,",")
+	tags := c.GetString("ids")
+	tags_id := strings.Split(tags, ",")
 
-	if userid!=""{
-		user_info,_ :=Mgo.FindOne("historylog",map[string]interface{}{
-			"user_id":userid,
+	if userid != "" {
+		user_info, _ := Mgo.FindOne("historylog", map[string]interface{}{
+			"user_id": userid,
 		})
-		log.Println("tag_id",tags_id)
-		if user_info!=nil{
+		log.Println("tag_id", tags_id)
+		if user_info != nil {
 			tagrules := (*user_info)["tag_rules"]
-			for _,m := range tagrules.([]interface{}){
-					if m.(map[string]interface{})["_id"].(bson.ObjectId).Hex() == rule_id{
-						log.Println("&&")
-						m.(map[string]interface{})["o_departruleids"] = tags
+			for _, m := range tagrules.([]interface{}) {
+				if m.(map[string]interface{})["_id"].(bson.ObjectId).Hex() == rule_id {
+					log.Println("&&")
+					m.(map[string]interface{})["o_departruleids"] = tags
 				}
 			}
 			set := bson.M{
@@ -1163,11 +1193,11 @@ func (c *Customer) HistoryTagAssociated() {
 					"tag_rules": tagrules,
 				},
 			}
-			log.Println("set",set)
-			is_updata:=Mgo.Update("historylog",map[string]interface{}{
-				"user_id":userid,
-			},set,false,false)
-			if is_updata{
+			log.Println("set", set)
+			is_updata := Mgo.Update("historylog", map[string]interface{}{
+				"user_id": userid,
+			}, set, false, false)
+			if is_updata {
 				c.ServeJson(map[string]interface{}{
 					"rep": is_updata,
 				})
@@ -1180,3 +1210,86 @@ func getTserTag(userid string) *[]map[string]interface{} {
 	usertags, _ := Mgo.Find("eusertagrule", map[string]interface{}{"s_userid": userid, "b_delete": false}, `{"i_createtime":-1}`, nil, false, 0, 0)
 	return usertags
 }
+
+func AddHistoryLog(ruleData map[string]interface{}, isUpdate bool, id string) bool {
+	history_id := qu.StringTOBsonId(ruleData["history_id"].(string))
+	hData, ok := Mgo.FindOne("historylog", bson.M{"_id": history_id})
+	if ok && hData != nil && *hData != nil {
+		dep_rules := qu.ObjArrToMapArr((*hData)["dep_rules"].([]interface{}))
+		ruleData["is_new"] = true
+		if isUpdate {
+			for _, v := range dep_rules {
+				if qu.BsonIdToSId(v["_id"]) == id {
+					v = ruleData
+				}
+			}
+		} else {
+			dep_rules = append(dep_rules, ruleData)
+		}
+		return Mgo.Update("historylog", bson.M{"_id": history_id}, bson.M{"$set": bson.M{"dep_rules": dep_rules}}, false, false)
+	} else {
+		return false
+	}
+
+}
+
+
+//历史任务删除私有标签
+func (c *Customer)HistoryTagDel(){
+	defer qu.Catch()
+	userid := c.GetString("userid")
+	tagid := c.GetString("tagid")
+	if userid!=""&&tagid!=""{
+		user_info,_:=Mgo.FindOne("historylog",map[string]interface{}{"user_id":userid})
+		if user_info!=nil&&len(*user_info)!=0{
+			user_tag_rules := (*user_info)["tag_rules"].([]interface{})
+			for _,m:=range user_tag_rules{
+				if m.(map[string]interface{})["_id"].(bson.ObjectId).Hex() == tagid{
+					m.(map[string]interface{})["b_delete"] = true
+				}
+			}
+
+			is_updata :=Mgo.Update("historylog",bson.M{"user_id": userid}, bson.M{"$set": bson.M{"tag_rules": user_tag_rules}},false,false)
+			if is_updata{
+				c.ServeJson(map[string]interface{}{
+					"rep":true,
+				})
+			}
+			return
+		}
+	}
+	c.ServeJson(map[string]interface{}{
+		"rep":false,
+	})
+}
+
+
+func (c *Customer)HistoryTagEdit(){
+	defer qu.Catch()
+	_id := c.GetString("_id")
+	userid := c.GetString("userid")
+	data := GetPostForm(c.Request)
+	cid := qu.ObjToString(data["s_userid"])
+	createTime := time.Now().Unix()
+	o_rules := []map[string]interface{}{}
+	o_rulesStr := data["o_list"].(string)
+	json.Unmarshal([]byte(o_rulesStr), &o_rules)
+	data["o_list"] = o_rules
+	var rep = true
+	if _id == "" {
+		data["i_createtime"] = createTime
+		data["i_updatetime"] = createTime
+		data["b_delete"] = false
+		_id = Mgo.Save("eusertagrule", data)
+	} else {
+		query := bson.M{
+			"user_id": userid,
+		}
+		rep = Mgo.Update("historylog", query, bson.M{"$set": data}, false, false)
+	}
+
+	c.ServeJson(map[string]interface{}{
+		"id":  cid,
+		"rep": rep,
+	})
+}

+ 2 - 2
src/web/templates/private/cuser_rule_history_edit.html

@@ -22,13 +22,13 @@
                 <button class="btn btn-danger btn-sm" onclick="archive()"><i class="fa fa-fw fa-save fa-lg"></i>存档</button>
             </small>
         </h1>
-        <ol class="breadcrumb">
+        <!-- <ol class="breadcrumb">
             <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
             <li><a href="/service/customer/list"> 客户列表</a></li>
             <li><a href="/service/customer/edit?id={{.T.cid}}"> 编辑客户</a></li>
             <li><a href="/service/cuser/rule/list?ids={{.T.ids}}"> 客户规则</a></li>
             <li><a href="#"> 新增客户规则</a></li>
-        </ol>
+        </ol> -->
     </section>
     <!-- Main content -->
     <section class="content">

+ 31 - 215
src/web/templates/private/customer_history.html

@@ -153,89 +153,6 @@
     </section>
 </div>
 
-<!-- 新增部门 -->
-<div class="modal fade" id="modal-add-depart" tabindex="-1" role="dialog" aria-hidden="true">
-    <div class="modal-dialog" style="width: 50%">
-        <div class="modal-content">
-            <div class="modal-header">
-                <div class="modal-header">
-                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
-                    <div class="edit-form">
-                        <div class="edit-info">
-                            <span class="glyphicon glyphicon-ok-sign" aria-hidden="true"></span>
-                            <span>新增部门</span>
-                        </div>
-                        <form class="form-horizontal">
-                            <div class="form-group">
-                                <label class="col-sm-3 control-label"><span style="color:red;">* </span>部门名称</label>
-                                <div class="col-sm-6">
-                                    <input class="form-control" placeholder="销售部、销售部-xx子部门" id="depart_name"/></div>
-                            </div>
-                            <div class="form-group">
-                                <label class="col-sm-3 control-label">联系人</label>
-                                <div class="col-sm-6">
-                                    <input class="form-control" placeholder="输入联系人名称" id="depart_contract"/></div>
-                            </div>
-                            <div class="form-group">
-                                <label class="col-sm-3 control-label">是否启用</label>
-                                <div class="col-sm-6">
-                                    <select class="form-control selectpicker" id="isuseSelect">
-                                        <option value=1 selected>是</option>
-                                        <option value=0>否</option>
-                                    </select>
-                                </div>
-                            </div>
-                        </form>
-                    </div>
-                </div>
-                <div class="modal-footer">
-                    <input type="button" onclick="saveDepart()" class="btn btn-primary saveBtn" value="保存">
-                    <input type="button" onclick="cancelModel()" class="btn btn-default" style="margin-left: 24px"
-                           value="取消">
-                </div>
-            </div>
-        </div>
-    </div><!-- /.modal -->
-</div>
-<!-- 关联客户规则 -->
-<div class="modal fade" id="modal-associated" tabindex="-1" role="dialog" aria-hidden="true">
-    <div class="modal-dialog" style="width: 60%">
-        <div class="modal-content">
-            <div class="modal-header">
-                <div class="modal-header">
-                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
-                    <div class="edit-form">
-                        <div class="edit-info">
-                            <span class="glyphicon glyphicon-ok-sign" aria-hidden="true"></span>
-                            <span>关联客户规则</span>
-                        </div>
-                        <div class="content">
-                            <table id="cuserRule" class="table table-bordered">
-                                <thead>
-                                <tr>
-                                    <th>编号</th>
-                                    <th><input type="checkbox" id="selrow" onclick="allSelect(this)"/></th>
-                                    <th>规则名称</th>
-                                    <th>部门名称</th>
-                                    <th>创建时间</th>
-                                </tr>
-                                </thead>
-                                <tbody class="historyCuserRule">
-
-                                </tbody>
-                            </table>
-                        </div>
-                    </div>
-                </div>
-                <div class="modal-footer">
-                    <input type="button" onclick="saveTagrule()" class="btn btn-primary saveBtn" value="保存">
-                    <input type="button" onclick="cancelModel()" class="btn btn-default" style="margin-left: 24px"
-                           value="取消">
-                </div>
-            </div>
-        </div>
-    </div><!-- /.modal -->
-</div>
 
 <!--历史规则-->
 <div class="modal fade" id="modal-history" tabindex="-1" role="dialog" aria-hidden="true">
@@ -373,19 +290,19 @@
     //表格全选
     function allSelect(obj) {
         if ($(obj).is(':checked')) {
-            keyTableChecked = true;
-            keyTableAllChecked = true;
-            $('input[name="ckb-rule"]').each(function () {
-                this.checked = true;
-                selectIndex.push($(this).parents("tr").index());
+            console.log("全选")
+            $(".history_rules tr").each(function () {
+                $(".history_rules tr").find('td').eq(0).find('input').addClass("");
+                var tag_ruleid = $(this).find('td').eq(7).text();
+                console.log("tag_ruleid",tag_ruleid)
             })
+
         } else {
-            selectIndex.length = 0;
-            keyTableChecked = false;
-            keyTableAllChecked = false;
-            $('input[name="ckb-keyid"]').each(function () {
-                this.checked = false;
+            console.log("反选")
+            $(".history_rules tr").each(function () {
+                $(".history_rules tr").find('td').eq(0).find('input').removeClass("checked");
             })
+
         }
     }
     function singleSelect(obj) {
@@ -428,16 +345,6 @@
     }
 
     function saveCuser() {
-        var name = $('#customername').val();
-        var contract = $('#contract').val();
-        var saleperson = $('#seller').val();
-        if (name == "" || saleperson == "") {
-            showTip("请填写必填字段!", 1000)
-            return
-        }
-        dataMap.s_name = name
-        dataMap.s_customername = contract
-        dataMap.s_salesperson = saleperson
         if (dataMap.i_state == 1) {
             dataMap.i_pushmodel = $('#pushModelSelect option:selected').val()
             dataMap.i_pushtype = $('#pushTypeSelect option:selected').val()
@@ -457,116 +364,9 @@
         })
     }
 
-    var depart_flag = -1;      // 0:新增,1:修改
     function showDepart() {
         window.location.href="/service/cuser/rule/history/edit?id="+c_id
     }
-    //修改部门
-    function modify_Depart() {
-        depart_flag = 1
-        var index = selectIndex[0] - 1;
-        $('#modal-add-depart').modal("show");
-    }
-    function del_Depart() {
-        if (keyTableChecked && selectIndex.length > 0) {
-            showConfirm("确定删除?", function() {
-                var tmp = []
-                for (var i in selectIndex) {
-                    var j = selectIndex[i] - 1;
-                    tmp.push(j)
-                }
-                var did = departArr[tmp[0]]._id
-                var bol = false
-                $.ajax({
-                    url: "/service/depart/del",
-                    type: "post",
-                    data: {"id": did},
-                    success: function (r) {
-                        bol = r.rep
-                        if(r.rep){
-                            // showTip("删除成功", 1000)
-                            window.location.reload()
-                        }else{
-                            showTip("删除失败", 1000);
-                        }
-                    }
-                })
-                if (!bol) {
-                    return
-                }
-            })
-        }else {
-            showTip("请选中需要删除的关键词", 1000)
-        }
-    }
-    function saveDepart() {
-        var name = $('#depart_name').val();
-        if (name != "") {
-            if (depart_flag == 1) {
-                var index = selectIndex[0] - 1;
-                var depart = departArr[index]
-                depart["id"] = depart["_id"]
-            }else {
-                var depart = {}
-                depart["s_userid"] = dataMap._id
-            }
-            depart["s_name"] = name;
-            depart["s_contract"] = $('#depart_contract').val();
-            depart["s_subname"] = $('#s_depart_name').val()
-            depart["i_isuse"] =  $('#isuseSelect').val()
-            if (depart_flag == 1) {
-                var index = selectIndex[0] - 1;
-                departArr.splice(index, 1, depart)
-            }else {
-                departArr.push(depart)
-            }
-            $('#departTable').dataTable().fnClearTable();
-            $('#departTable').dataTable().fnAddData(departArr);
-            $('#modal-add-depart').modal('hide');
-
-            $.ajax({
-                url: "/service/depart/edit",
-                type: "post",
-                data: depart,
-                success: function (r) {
-                    if(r.rep){
-                        // showTip("保存成功", 1000)
-                        window.location.reload()
-                    }else{
-                        showTip("保存失败", 1000);
-                    }
-                }
-            })
-        }else {
-            showTip("部门名称不能为空", 500)
-        }
-    }
-    function setup(val, bol) {
-        var msg = ""
-        var i_isuse = 0
-        if (bol) {
-            msg = "确定启用?"
-            i_isuse = 1
-        }else {
-            msg = "确定停用?"
-            i_isuse = 0
-        }
-        showConfirm(msg, function() {
-            $.ajax({
-                url:"/service/customer/setup",
-                type:"post",
-                data:{"_id": val, "i_isuse": i_isuse},
-                success:function(r){
-                    if(r.rep){
-                        // showTip("设置成功", 1000);
-                        window.location.reload()
-                    }else{
-                        showTip("设置失败", 1000);
-                    }
-                }
-            })
-        });
-    }
     function setupTag(val, bol) {
         var msg = ""
         var i_isuse = 0
@@ -596,9 +396,9 @@
     function delTag(val) {
         showConfirm("确定删除?", function () {
             $.ajax({
-                url: "/service/euser/tag/del",
+                url: "/service/tag/history/del",
                 type: "post",
-                data: {"_id": val},
+                data: {"tagid": val,"userid":c_id},
                 success: function (r) {
                     if (r.rep) {
                         window.location.reload()
@@ -693,7 +493,7 @@
                             }else{
                                 html += "</td><td>"+"未启用"+"</td>"
                             }
-                            html += "<td hidden>"+r.inc_rules[i].id+"</td><td hidden class='is_inc'>true</td>"
+                            html += "<td hidden>"+r.inc_rules[t].id+"</td><td hidden class='is_inc'>true</td>"
                             number++
                         }
                     }
@@ -766,8 +566,8 @@
         if (selected_rules.length>0){
             for (var i=0;i<selected_rules.length;i++){
                 html += '<tr><td>'+num+'</td><td>'+selected_rules[i].department_name+'</td><td>'+selected_rules[i].rule_name+'</td><td>'+selected_rules[i].update_time+'</td>'+'<td>'+selected_rules[i].department_status+'</td>'+'<td>'+selected_rules[i].rule_status+'</td>';
-                if (selected_rules.isinc == "true"){
-                    html += "<td><span>修改</span><span>删除</span></td>"
+                if (selected_rules[i].isinc == "true"){
+                    html += '<td><span onclick="del_selected_rule(\''+selected_rules[i].rule_id+'\')">删除</span></td>'
                 }else{
                     html += "<td></td>"
                 }
@@ -794,5 +594,21 @@
     function getcheck(e) {
         $(e).toggleClass("checked")
     }
+    $("#pushTypeSelect").on("change",function(){
+            selectid = $("option:selected",this).val();//需求主键
+            if (selectid == 0){
+                $(".sendmail").show()
+            }else{
+                $(".sendmail").hide()
+            }
+
+        });
+
+//删除选中规则
+function del_selected_rule(rule_id) {
+    showConfirm("确定删除?", function () {
+
+    });
+}
 </script>
 /service/cuser/rule/list

+ 1 - 1
src/web/templates/private/customer_list.html

@@ -175,6 +175,6 @@
         })
     }
     function historyData(val) {
-        window.location.href = "/service/customer/history?id=" + val
+        window.location.href = "/service/historylog/list?id=" + val
     }
 </script>

+ 129 - 0
src/web/templates/private/historylog_list.html

@@ -0,0 +1,129 @@
+{{include "com/inc.html"}}
+<!-- Main Header -->
+{{include "com/header.html"}}
+<!-- Left side column. 权限菜单 -->
+{{include "com/menu.html"}}
+
+<div class="content-wrapper" id="showbtn">
+    <section class="content-header">
+        <h1>
+            <small><a id="addWork" 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/historylog/list?id={{.T.id}}"> 记录</a></li>
+        </ol>
+    </section>
+    <!-- Main content -->
+    <section class="content">
+        <div class="row">
+            <div class="col-xs-12">
+                <div class="box">
+                    <div class="box-body">
+                        <table id="dataTable" class="table table-bordered table-hover">
+                            <thead>
+                                <tr>
+                                    <th>序号</th>
+                                    <th>ID</th>
+                                    <th>操作人</th>
+                                    <th>状态</th>
+                                    <th>数据总量</th>
+                                    <th>创建时间</th>
+                                    <th>修改时间</th>
+                                </tr>
+                            </thead>
+                        </table>
+                    </div>
+                    <!-- /.box-body -->
+                </div>
+                <!-- /.box -->
+            </div>
+        </div>
+    </section>
+</div>
+{{include "com/footer.html"}}
+<script>
+    $(function() {
+        ttable = $('#dataTable').DataTable({
+            "paging": true,
+            "lengthChange": false,
+            "searching": false,
+            "ordering": false,
+            "info": true,
+            "autoWidth": false,
+            "ajax": {
+                "url": "/service/historylog/list",
+                "type": "post",
+                "data": {
+                    "id": {{.T.id}}
+                }
+            },
+            "language": {
+                "url": "/dist/js/dataTables.chinese.lang"
+            },
+            "fnDrawCallback": function() {
+                $("ul.pagination").prepend(
+                    "&nbsp;&nbsp;&nbsp;转到第 <input type='text' id='changePage'   style='width:20px;'> 页    <a type='text' href='javascript:void(0);' id='dataTable-btn' style='text-align:center'>GO</a>"
+                );
+                $('#dataTable-btn').click(function(e) {
+                    var redirectpage = 0
+                    if ($("#changePage").val() && $("#changePage").val() > 0) {
+                        var redirectpage = $("#changePage").val() - 1;
+                    }
+                    ttable.page(redirectpage).draw(false);
+                });
+                this.api().column(0).nodes().each(function(cell, i) {
+                    cell.innerHTML = i + 1;
+                });
+            },
+            "columns": [{
+                    "data": null,
+                    width: "5%"
+                },
+                {
+                    "data": "_id"
+                },
+                {
+                    "data": "create_user"
+                },
+                {
+                    "data": "state",
+                    render: function(val) {
+                        var str = "";
+                        if(val === 0){
+                            str = "未执行";
+                        }else if(val === 1){
+                            str = "未完成";
+                        }else if(val === 2){
+                            str = "已完成";
+                        }
+                        return str
+                    }
+                },
+                {
+                    "data": "result_count"
+                },
+                {
+                    "data": "createtime",
+                    render: function(val) {
+                        var dt = new Date()
+                        dt.setTime(parseInt(val) * 1000)
+                        return dt.format("yyyy-MM-dd hh:mm:ss")
+                    }
+                },
+                {
+                    "data": "updatetime",
+                    render: function(val) {
+                        var dt = new Date()
+                        dt.setTime(parseInt(val) * 1000)
+                        return dt.format("yyyy-MM-dd hh:mm:ss")
+                    }
+                }
+            ]
+        });
+        
+        $("#addWork").on("click",function(){
+            window.location.href = "/service/customer/history?id="+ {{.T.id}};
+        })
+    });
+</script>