package client import ( "cmplatform/util" "encoding/json" "fmt" "io" "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/encrypt" "app.yhyue.com/moapp/jybase/go-xweb/xweb" "app.yhyue.com/moapp/jybase/mongodb" "github.com/lauyoume/gopinyin" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "log" "strconv" "strings" "time" ) type OwnTag struct { *xweb.Action customerSave xweb.Mapper `xweb:"/client/customer/save"` //客户信息保存 euserTagEdit xweb.Mapper `xweb:"/client/customer/tag/edit"` //客户信息保存 euserImport xweb.Mapper `xweb:"/client/customer/tag/import"` //私有标签导入关键词 customerHistory xweb.Mapper `xweb:"/client/customer/history"` //私有标签导入关键词 customerEdit xweb.Mapper `xweb:"/client/customer/edit"` //编辑客户信息 tagSetup xweb.Mapper `xweb:"/client/customer/tag/setup"` //标签的启用禁用 tagDel xweb.Mapper `xweb:"/client/customer/tag/del"` //删除标签 cuserRuleList xweb.Mapper `xweb:"/client/tag/ruleList"` //规则列表 客户 tagAssociated xweb.Mapper `xweb:"/client/customer/tag/associated"` //私有标签关联规则 addhistoryrule xweb.Mapper `xweb:"/client/rule/history/add"` //新增历史任务 historyRuleCreate xweb.Mapper `xweb:"/client/customer/rule/history/edit"` //新增历史任务规则 historyTagDel xweb.Mapper `xweb:"/client/tag/history/del"` //历史任务删除私有标签 historyTagAssociated xweb.Mapper `xweb:"/client/customer/historytag/associated"` //私有标签关联历史规则 saveHistoryRule xweb.Mapper `xweb:"/client/customer/history/saverule"` //保存历史规则 delHistoryRule xweb.Mapper `xweb:"/client/customer/history/delrule"` //删除历史任务规则 historyRuleEdit xweb.Mapper `xweb:"/client/historyRule/edit"` //编辑历史规则 customerAllRule xweb.Mapper `xweb:"/client/customer/history/allrule"` //用户历史规则 } // 保存客户信息 func (c *OwnTag) CustomerSave() { defer common.Catch() if c.Method() == "POST" { //data := GetPostForm(c.Request) data := map[string]interface{}{} err := json.Unmarshal(c.Body(), &data) if err != nil { log.Println("err", err) } log.Println("接收数据:", data) id := common.ObjToString(data["id"]) delete(data, "id") i_createtime := time.Now().Unix() data["i_updatetime"] = i_createtime var rep = false if id == "" { departArr := []map[string]interface{}{} departArrStr := data["depart"].(string) json.Unmarshal([]byte(departArrStr), &departArr) delete(data, "depart") data["b_delete"] = false data["i_createtime"] = i_createtime data["i_state"] = 0 id = util.Mgo.Save("cuser", data) if id != "" { for _, v := range departArr { v["s_userid"] = id v["i_createtime"] = time.Now().Unix() v["i_updatetime"] = time.Now().Unix() v["i_isuse"] = common.IntAll(v["i_isuse"]) v["b_delete"] = false } if len(departArr) == 0 { rep = true } else { rep = util.Mgo.SaveBulk("cuserdepart", departArr...) } } else { rep = false } } else { if data["mails"] != nil { mailsMap := map[string]interface{}{} mails := common.ObjArrToStringArr(data["mails"].([]interface{})) for _, val := range mails { mailArr := strings.Split(val, "+") mailsMap[mailArr[0]] = mailArr[1] } log.Println(mailsMap) appid := common.ObjToString(data["s_appid"]) q := bson.M{ "appid": appid, } setMap := map[string]interface{}{ "mails": mailsMap, } rep = util.MgoCus.Update("user", q, bson.M{"$set": setMap}, false, false) c.ServeJson(map[string]interface{}{ "rep": rep, }) return } delete(data, "mails") query := bson.M{ "_id": mongodb.StringTOBsonId(id), } rep = util.Mgo.Update("cuser", query, bson.M{"$set": data}, false, false) } c.ServeJson(map[string]interface{}{ "rep": rep, }) } } // 新建/编辑标签 func (c *OwnTag) EuserTagEdit() { defer common.Catch() if c.Method() == "POST" { _id := c.GetString("_id") data := util.GetPostForm(c.Request) cid := common.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 hid := common.ObjToString(data["hid"]) var rep = true if hid == "" { if _id == "" { data["i_createtime"] = createTime data["i_updatetime"] = createTime data["b_delete"] = false _id = util.Mgo.Save("eusertagrule", data) } else { query := bson.M{ "_id": mongodb.StringTOBsonId(_id), } rep = util.Mgo.Update("eusertagrule", query, bson.M{"$set": data}, false, false) } } else { if _id == "" { data["i_createtime"] = createTime data["i_updatetime"] = createTime data["i_type"] = "historyData" data["b_delete"] = true _id = util.Mgo.Save("eusertagrule", data) rep = AddHistoryLogTag(data, false, _id) } else { query := bson.M{ "_id": mongodb.StringTOBsonId(_id), } reps := util.Mgo.Update("eusertagrule", query, bson.M{"$set": data}, false, false) if reps { rep = AddHistoryLogTag(data, true, _id) } } } c.ServeJson(map[string]interface{}{ "id": cid, "rep": rep, }) } else { if c.GetString("id") != "" { data, _ := util.Mgo.FindById("eusertagrule", c.GetString("id"), nil) c.T["tagrule"] = *data } cid := c.GetString("cid") c.T["cid"] = cid c.T["matchTypeMap"] = util.MatchTypeMap3 c.T["hid"] = c.GetString("hid") c.Render("client/customer_tag_rule.html", &c.T) } } func (c *OwnTag) CustomerHistory() { defer common.Catch() id := c.GetString("id") user := c.GetSession("user").(map[string]interface{}) query := bson.M{} query["_id"] = mongodb.StringTOBsonId(id) hid := c.GetString("hid") history_id := "" if hid != "" { history_id = hid hData, ok := util.Mgo.FindOne("historylog", bson.M{"_id": mongodb.StringTOBsonId(history_id)}) if ok && hData != nil && len(*hData) > 0 { c.T["history_rule"] = (*hData)["dep_rules"] c.T["tagrule"] = (*hData)["tag_rules"] (*hData)["_id"] = id c.T["data"] = *hData } } else { var user_name, user_customername, user_salesperson, appid = "", "", "", "" var push_model, push_type, i_push = 0, 0, 0 userInfo, ok := util.Mgo.FindOne("euser", query) if ok && userInfo != nil && *userInfo != nil { user_name = common.ObjToString((*userInfo)["s_name"]) user_customername = common.ObjToString((*userInfo)["s_customername"]) user_salesperson = common.ObjToString((*userInfo)["s_salesperson"]) push_model = common.IntAll((*userInfo)["i_pushmodel"]) push_type = common.IntAll((*userInfo)["i_pushtype"]) i_push = common.IntAll((*userInfo)["i_push"]) appid = common.ObjToString((*userInfo)["s_appid"]) } history_id = util.Mgo.Save("historylog", map[string]interface{}{ "createtime": time.Now().Unix(), "updatetime": time.Now().Unix(), "user_id": id, "create_user": user["name"], "state": 0, "s_name": user_name, "s_customername": user_customername, "s_salesperson": user_salesperson, "i_pushmodel": push_model, "i_pushtype": push_type, "i_push": i_push, "s_appid": appid, }) c.Redirect("/client/customer/history?id=" + id + "&hid=" + history_id) return } c.T["history_id"] = history_id c.Render("client/customer_history.html", &c.T) } // 导入关键词 func (c *OwnTag) EuserImport() { defer common.Catch() if c.Method() == "POST" { mf, _, err := c.GetFile("xlsx") if err == nil { binary, err := io.ReadAll(mf) if err == nil { rdata, err := util.Parsxlsx1(binary) if err == nil { c.ServeJson(map[string]interface{}{ "rdata": rdata, "rep": true, }) return } } } c.ServeJson(map[string]interface{}{ "rep": false, }) } } // 编辑客户信息 func (c *OwnTag) CustomerEdit() { defer common.Catch() id := c.GetString("id") query := bson.M{} query["_id"] = mongodb.StringTOBsonId(id) data, _ := util.Mgo.FindOneByField("cuser", query, `{}`) depart, _ := util.Mgo.Find("cuserdepart", bson.M{"s_userid": id, "b_delete": false}, nil, nil, false, -1, -1) (*data)["_id"] = mongodb.BsonIdToSId((*data)["_id"]) if (*data)["i_state"] == 1 { tagRule, _ := util.Mgo.Find("eusertagrule", bson.M{"s_userid": id, "b_delete": false}, nil, nil, false, -1, -1) c.T["tagrule"] = *tagRule } c.T["data"] = *data c.T["depart"] = *depart c.Render("client/index.html", &c.T) } // 标签的启用禁用 func (c *OwnTag) TagSetup() { defer common.Catch() if c.Method() == "POST" { _id := c.GetString("_id") i_isuse, _ := c.GetInt("i_isuse") set := bson.M{ "$set": bson.M{ "i_isuse": i_isuse, }, } b := util.Mgo.UpdateById("eusertagrule", _id, set) c.ServeJson(map[string]interface{}{ "rep": b, }) } } // 删除标签 func (c *OwnTag) TagDel() { defer common.Catch() _id := c.GetString("_id") set := bson.M{ "$set": bson.M{ "b_delete": true, }, } b := util.Mgo.UpdateById("eusertagrule", _id, set) c.ServeJson(map[string]interface{}{ "rep": b, }) } // 关联规则列表 func (c *OwnTag) CuserRuleList() { defer common.Catch() if c.Method() == "POST" { eid := c.GetString("eid") start, _ := c.GetInt("start") limit, _ := c.GetInt("length") draw, _ := c.GetInt("draw") searchStr := c.GetString("search[value]") search := strings.TrimSpace(searchStr) query := bson.M{ "s_userid": eid, "i_isuse": 1, "b_delete": false, } if search != "" { query["$or"] = []interface{}{ bson.M{"s_name": bson.M{"$regex": search}}, } } data, _ := util.Mgo.Find("euserdepartrule", query, `{"i_createtime":-1}`, nil, false, int(start), int(limit)) for _, v := range *data { d, _ := util.Mgo.FindById("euserdepart", common.ObjToString(v["s_departid"]), nil) v["s_depart"] = common.ObjToString((*d)["s_name"]) } count := util.Mgo.Count("euserdepartrule", query) c.ServeJson(map[string]interface{}{ "draw": draw, "data": data, "recordsFiltered": count, "recordsTotal": count, }) } } func (c *OwnTag) TagAssociated() { defer common.Catch() _id := c.GetString("_id") ids := c.GetString("ids") set := bson.M{ "$set": bson.M{ "o_departruleids": ids, }, } b := util.Mgo.UpdateById("eusertagrule", _id, set) c.ServeJson(map[string]interface{}{ "rep": b, }) } func (c *OwnTag) Addhistoryrule() { defer common.Catch() if c.Method() == "POST" { his_id := c.GetString("history_id") //log.Println("hisid", his_id) if his_id != "" { //newHistory["tag_rules"] = usertags push_model, _ := strconv.Atoi(c.GetString("send_mode")) push_type, _ := strconv.Atoi(c.GetString("push_type")) isDup, _ := strconv.Atoi(c.GetString("isDup")) i_updatetime, _ := strconv.ParseInt(c.GetString("i_updatetime"), 10, 64) i_extfieldstype, _ := strconv.Atoi(c.GetString("i_extfieldstype")) set := bson.M{ "$set": bson.M{ "i_pushmodel": push_model, "s_customername": c.GetString("s_customername"), "s_salesperson": c.GetString("s_salesperson"), "s_name": c.GetString("s_name"), "i_pushtype": push_type, "s_extends": c.GetString("s_extends"), "i_updatetime": i_updatetime, "sendMail": c.GetString("sendMail"), "isDup": isDup, "i_extfieldstype": i_extfieldstype, }, } isupdata := util.Mgo.UpdateById("historylog", mongodb.StringTOBsonId(his_id), set) if isupdata { c.ServeJson(map[string]interface{}{ "history_id": his_id, "rep": true, }) } else { //log.Println(666) c.ServeJson(map[string]interface{}{ "history_id": "", "rep": false, }) } } } } func (c *OwnTag) HistoryRuleCreate() { defer common.Catch() if c.Method() == "POST" { user := c.GetSession("user").(map[string]interface{}) data := util.GetPostForm(c.Request) o_rules := []map[string]interface{}{} o_rulesStr := data["o_rules"].(string) json.Unmarshal([]byte(o_rulesStr), &o_rules) data["o_rules"] = o_rules id := common.ObjToString(data["id"]) user_id := data["ids"] delete(data, "id") delete(data, "ids") if common.IntAll(data["i_esquerytype"]) == 1 { //自动生成es data["s_esquery"] = util.Utiltags(data, id) } i_createtime := time.Now().Unix() data["i_updatetime"] = i_createtime data["s_updateuser"] = user["name"] data["s_depart_name"] = data["departmentName"] var rep = false s_id := "" if id == "" { //新建 dData, ok := util.Mgo.FindOne("euserdepart", bson.M{"s_userid": user_id, "s_name": data["departmentName"]}) if dData == nil || *dData == nil || !ok { d_data := map[string]interface{}{ "i_isuse": 1, "s_userid": user_id, "s_name": data["s_depart_name"], "i_createtime": time.Now().Unix(), "i_updatetime": time.Now().Unix(), "b_delete": true, "i_type": "historyData", } s_id = util.Mgo.Save("euserdepart", d_data) } else { s_id = mongodb.BsonIdToSId((*dData)["_id"]) } data["s_userid"] = user_id data["s_departid"] = s_id data["i_createtime"] = i_createtime data["s_createuser"] = user["name"] s_namekey := gopinyin.Convert(common.ObjToString(data["s_name"]), false) data["s_namekey"] = s_namekey data["b_delete"] = true data["s_dataid"] = encrypt.SE.EncodeString(fmt.Sprintf("%v", i_createtime) + s_namekey + s_id) data["i_type"] = "historyData" id = util.Mgo.Save("euserdepartrule", data) if id != "" { rep = AddHistoryLogDep(data, false, id) } else { rep = false } } else { query := bson.M{ "_id": mongodb.StringTOBsonId(id), } reps := util.Mgo.Update("euserdepartrule", query, bson.M{"$set": data}, false, false) if reps { rep = AddHistoryLogDep(data, true, id) } } c.ServeJson(map[string]interface{}{ "id": id, "rep": rep, "s_esquery": data["s_esquery"], "s_dataid": data["s_dataid"], }) } else { id := c.GetString("id") c.T["did"] = id //部门id c.T["cid"] = id //客户id c.T["ids"] = id c.T["history_id"] = c.GetString("hid") c.T["province"] = util.Province c.T["city"] = util.ProvinceCitys c.T["district"] = util.CityDistricts c.T["topTypeArr"] = util.TopTypeArr c.T["subTypeArr"] = util.SubTypeArr c.T["matchTypeMap"] = util.MatchTypeMap c.T["matchTypeMap2"] = util.MatchTypeMap2 c.T["existField"] = util.ExistFiled c.T["buyerClass"] = util.BuyerClass c.T["scopeClass"] = util.ScopeClassMap c.Render("client/cuser_rule_history_edit.html", &c.T) } } // 历史任务删除私有标签 func (c *OwnTag) HistoryTagDel() { defer common.Catch() // userid := c.GetString("userid") tagid := c.GetString("tagid") hid := c.GetString("hid") user_info, _ := util.Mgo.FindOne("historylog", bson.M{"_id": mongodb.StringTOBsonId(hid)}) if user_info != nil && *user_info != nil { if (*user_info)["tag_rules"] != nil { user_tag_rules := common.ObjArrToMapArr((*user_info)["tag_rules"].([]interface{})) ruleMap := map[string]bool{tagid: true} ruleArr := []map[string]interface{}{} for _, m := range user_tag_rules { if !ruleMap[mongodb.BsonIdToSId(m["_id"])] { ruleArr = append(ruleArr, m) } } is_updata := util.Mgo.Update("historylog", bson.M{"_id": mongodb.StringTOBsonId(hid)}, bson.M{"$set": bson.M{"tag_rules": ruleArr}}, false, false) c.ServeJson(map[string]interface{}{ "rep": is_updata, }) } return } c.ServeJson(map[string]interface{}{ "rep": false, }) } // 私有标签关联数据 func (c *OwnTag) HistoryTagAssociated() { defer common.Catch() userid := c.GetString("userid") rule_id := c.GetString("_id") tags := c.GetString("ids") hid := c.GetString("hid") if userid != "" { user_info, _ := util.Mgo.FindOne("historylog", map[string]interface{}{ "_id": mongodb.StringTOBsonId(hid), }) if user_info != nil && *user_info != nil { tagrules := (*user_info)["tag_rules"] if tagrules != nil { tagrulesArr := common.ObjArrToMapArr(tagrules.([]interface{})) for _, m := range tagrulesArr { if rule_id == mongodb.BsonIdToSId(m["_id"]) { m["o_departruleids"] = tags } } set := bson.M{ "$set": bson.M{ "tag_rules": tagrulesArr, }, } is_updata := util.Mgo.Update("historylog", map[string]interface{}{ "_id": mongodb.StringTOBsonId(hid), }, set, false, false) c.ServeJson(map[string]interface{}{ "rep": is_updata, }) } } } } // 保存历史规则 func (c *OwnTag) SaveHistoryRule() { rules_id := c.GetString("rulesid") history_id := c.GetString("hid") // userid := c.GetString("userid") if history_id != "" { user_history, _ := util.Mgo.FindOne("historylog", map[string]interface{}{ "_id": mongodb.StringTOBsonId(history_id), }) if *user_history != nil && user_history != nil { //获取私有标签 // usertags := getTserTag(userid) if (*user_history)["dep_rules"] != nil { dep_rules := common.ObjArrToMapArr((*user_history)["dep_rules"].([]interface{})) dep_new_rules := []map[string]interface{}{} ruleMap := map[string]bool{} if len(dep_rules) > 0 { for _, r := range dep_rules { dep_new_rules = append(dep_new_rules, r) ruleMap[mongodb.BsonIdToSId(r["_id"])] = true } } rules_id_list := strings.Split(rules_id, ",") for _, rule := range rules_id_list { if !ruleMap[rule] { query := bson.M{ "_id": mongodb.StringTOBsonId(rule), "b_delete": false, } res, _ := util.Mgo.FindOne("euserdepartrule", query) if res != nil && len(*res) != 0 { //获取规则所属部门信息 department_info, _ := util.Mgo.FindOne("euserdepart", map[string]interface{}{ "_id": mongodb.StringTOBsonId((*res)["s_departid"].(string)), "b_delete": false, }) (*res)["is_new"] = false (*res)["s_depart_name"] = (*department_info)["s_name"] dep_new_rules = append(dep_new_rules, *res) } } } set := bson.M{ "$set": bson.M{ "dep_rules": dep_new_rules, // "tag_rules": usertags, "updatetime": time.Now().Unix(), }, } ok := util.Mgo.Update("historylog", map[string]interface{}{ "_id": mongodb.StringTOBsonId(history_id), }, set, false, false) //log.Println("ok", ok) c.ServeJson(map[string]interface{}{ "status": ok, }) return } else { rules_id_list := strings.Split(rules_id, ",") dep_rules := []map[string]interface{}{} for _, rule := range rules_id_list { query := bson.M{ "_id": mongodb.StringTOBsonId(rule), "b_delete": false, } res, _ := util.Mgo.FindOne("euserdepartrule", query) if res != nil && *res != nil { //获取规则所属部门信息 department_info, _ := util.Mgo.FindOne("euserdepart", map[string]interface{}{ "_id": mongodb.StringTOBsonId((*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, // "tag_rules": usertags, "updatetime": time.Now().Unix(), }, } isupdata := util.Mgo.Update("historylog", map[string]interface{}{ "_id": mongodb.StringTOBsonId(history_id), }, set, false, false) c.ServeJson(map[string]interface{}{ "status": isupdata, }) return } } c.ServeJson(map[string]interface{}{ "status": "fail", }) } } func (c *OwnTag) DelHistoryRule() { id := c.GetString("id") hid := c.GetString("hid") if hid != "" { data, ok := util.Mgo.FindOne("historylog", bson.M{"_id": mongodb.StringTOBsonId(hid)}) if ok && data != nil && *data != nil { if (*data)["dep_rules"] != nil { dep_rules := common.ObjArrToMapArr((*data)["dep_rules"].([]interface{})) ruleMap := map[string]bool{id: true} ruleArr := []map[string]interface{}{} for _, m := range dep_rules { if !ruleMap[mongodb.BsonIdToSId(m["_id"])] { ruleArr = append(ruleArr, m) } } ok := util.Mgo.Update("historylog", bson.M{"_id": mongodb.StringTOBsonId(hid)}, bson.M{"$set": bson.M{"dep_rules": ruleArr}}, false, false) c.ServeJson(map[string]interface{}{ "success": ok, }) } } } } func (c *OwnTag) HistoryRuleEdit() { hid := c.GetString("hid") rid := c.GetString("rid") if c.Method() == "POST" { data := util.GetPostForm(c.Request) o_rules := []map[string]interface{}{} o_rulesStr := data["o_rules"].(string) json.Unmarshal([]byte(o_rulesStr), &o_rules) data["o_rules"] = o_rules data["_id"] = mongodb.StringTOBsonId(rid) if common.IntAll(data["i_esquerytype"]) == 1 { //自动生成es data["s_esquery"] = util.Utiltags(data, rid) } datas, ok := util.Mgo.FindOne("historylog", map[string]interface{}{"_id": mongodb.StringTOBsonId(hid)}) if ok && datas != nil && *datas != nil { dep_rules := common.ObjArrToMapArr((*datas)["dep_rules"].([]interface{})) for k, v := range dep_rules { if rid == mongodb.BsonIdToSId(v["_id"]) { dep_rules[k] = data } } rep := util.Mgo.Update("historylog", map[string]interface{}{"_id": mongodb.StringTOBsonId(hid)}, map[string]interface{}{"$set": map[string]interface{}{"dep_rules": dep_rules}}, false, false) c.ServeJson(map[string]interface{}{ "rep": rep, "s_esquery": data["s_esquery"], }) } } else { id := c.GetString("id") data, ok := util.Mgo.FindOne("historylog", map[string]interface{}{"_id": mongodb.StringTOBsonId(hid)}) if ok && data != nil && *data != nil { dep_rules := common.ObjArrToMapArr((*data)["dep_rules"].([]interface{})) for _, v := range dep_rules { if rid == mongodb.BsonIdToSId(v["_id"]) { c.T["data"] = v } } } c.T["did"] = id //部门id c.T["cid"] = id //客户id c.T["ids"] = id c.T["history_id"] = hid c.T["rid"] = rid c.T["province"] = util.Province c.T["city"] = util.ProvinceCitys c.T["district"] = util.CityDistricts c.T["topTypeArr"] = util.TopTypeArr c.T["subTypeArr"] = util.SubTypeArr c.T["matchTypeMap"] = util.MatchTypeMap c.T["matchTypeMap2"] = util.MatchTypeMap2 c.T["existField"] = util.ExistFiled c.T["buyerClass"] = util.BuyerClass c.T["scopeClass"] = util.ScopeClassMap c.Render("private/history_rule_edit.html", &c.T) } } // 选择历史规则 func (c *OwnTag) CustomerAllRule() { customerId := c.GetString("c_id") history_id := c.GetString("hid") query := bson.M{ "s_userid": customerId, "b_delete": false, } inc_query := bson.M{ "user_id": customerId, "_id": mongodb.StringTOBsonId(history_id), } //获取新增历史规则 inc_rules := []map[string]interface{}{} inc_rule := make(map[string]interface{}) inc_data, _ := util.Mgo.FindOne("historylog", inc_query) if inc_data != nil && *inc_data != nil { for _, t := range (*inc_data)["dep_rules"].([]interface{}) { if !t.(map[string]interface{})["is_new"].(bool) { inc_rule["id"] = t.(map[string]interface{})["_id"].(primitive.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_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{})["i_updatetime"] inc_rule["isinc"] = true inc_rules = append(inc_rules, inc_rule) } } } data, _ := util.Mgo.Find("euserdepart", query, `{"i_createtime":-1}`, nil, false, 0, 0) if data != nil && len(*data) != 0 { res := []map[string]interface{}{} for _, m := range *data { history_rule_data := make(map[string]interface{}) q := bson.M{ "s_departid": m["_id"].(primitive.ObjectID).Hex(), "b_delete": false, } history_rule_data["department_isuse"] = m["i_isuse"] history_rule_data["depart_name"] = m["s_name"] depart_rule_data, _ := util.Mgo.Find("euserdepartrule", q, `{"i_createtime":-1}`, `{"s_name":1,"i_updatetime":1,"i_isuse":1,"_id":1}`, false, 0, 0) if depart_rule_data != nil && len(*depart_rule_data) != 0 { for _, j := range *depart_rule_data { j["_id"] = j["_id"].(primitive.ObjectID).Hex() } history_rule_data["department_rule"] = depart_rule_data history_rule_data["is_slected"] = true } res = append(res, history_rule_data) } c.ServeJson(map[string]interface{}{ "status": "success", "data": res, "inc_rules": inc_rules, }) } else { c.ServeJson(map[string]interface{}{ "status": "fail", "data": "", }) } } func AddHistoryLogTag(ruleData map[string]interface{}, isUpdate bool, id string) bool { history_id := mongodb.StringTOBsonId(common.ObjToString(ruleData["hid"])) hData, ok := util.Mgo.FindOne("historylog", bson.M{"_id": history_id}) if ok && hData != nil && *hData != nil && len(*hData) > 0 { tag_rules := []map[string]interface{}{} if (*hData)["tag_rules"] != nil { tag_rules = common.ObjArrToMapArr((*hData)["tag_rules"].([]interface{})) } ruleData["is_new"] = true if isUpdate { for k, v := range tag_rules { if mongodb.BsonIdToSId(v["_id"]) == id { tag_rules[k] = ruleData } } } else { tag_rules = append(tag_rules, ruleData) } return util.Mgo.Update("historylog", bson.M{"_id": history_id}, bson.M{"$set": bson.M{"tag_rules": tag_rules}}, false, false) } else { return false } } func AddHistoryLogDep(ruleData map[string]interface{}, isUpdate bool, id string) bool { history_id := mongodb.StringTOBsonId(ruleData["history_id"].(string)) hData, ok := util.Mgo.FindOne("historylog", bson.M{"_id": history_id}) if ok && hData != nil && *hData != nil && len(*hData) > 0 { dep_rules := []map[string]interface{}{} if (*hData)["dep_rules"] != nil { dep_rules = common.ObjArrToMapArr((*hData)["dep_rules"].([]interface{})) } ruleData["is_new"] = true if isUpdate { for k, v := range dep_rules { if mongodb.BsonIdToSId(v["_id"]) == id { dep_rules[k] = ruleData } } } else { dep_rules = append(dep_rules, ruleData) } return util.Mgo.Update("historylog", bson.M{"_id": history_id}, bson.M{"$set": bson.M{"dep_rules": dep_rules}}, false, false) } else { return false } }