Răsfoiți Sursa

二次推送增加是否匹配项目id选项

fuwencai 4 ani în urmă
părinte
comite
590c37e977

+ 85 - 3
src/service/second_push.go

@@ -229,6 +229,8 @@ func (s *SecondPush) SecondPushTask() {
 			email := qu.ObjToString(c["sendMail"])
 			starttime := qu.Int64All(c["starttime"])
 			endtime := qu.Int64All(c["endtime"])
+			projectIdSearch := qu.ObjToString(c["projectIdSearch"]) // 是否匹配项目id  "0"-否 "1"-是
+			updateMap := [][]map[string]interface{}{}
 			if len(c) != 0 && c != nil {
 				if c["dep_rules"] != nil && len(c["dep_rules"].([]interface{})) != 0 {
 					idMap := map[bson.ObjectId]bool{}
@@ -245,11 +247,44 @@ func (s *SecondPush) SecondPushTask() {
 						d, _ := MgoCus.Find("usermail", q, nil, nil, false, 0, 0)
 						if len(*d) > 0 && d != nil {
 							for _, l := range *d {
+								// 根据id进行去重
 								if _, ok := idMap[l["_id"].(bson.ObjectId)]; !ok {
 									idMap[l["_id"].(bson.ObjectId)] = true
+									// 项目匹配为"1" 以及项目id为空时进行项目id匹配   同时更新数据库项目id
+									if projectIdSearch == "1" && (l["projectId"] == "" || l["projectId"] == nil) {
+										_projectid := ""
+										projectId := GetProjectId(qu.ObjToString(l["id"]))
+										if projectId != "" {
+											l["projectId"] = SE.EncodeString(projectId)
+											_projectid = SE.EncodeString(projectId)
+										} else {
+											l["projectId"] = ""
+											_projectid = ""
+										}
+										updateMap = append(updateMap, []map[string]interface{}{
+											map[string]interface{}{
+												"_id": l["_id"],
+											},
+											map[string]interface{}{
+												"$set": map[string]interface{}{
+													"projectId": _projectid,
+												},
+											},
+										})
+										if len(updateMap) > 500 {
+											b := MgoCus.UpdateBulk("usermail", updateMap...)
+											log.Println("更新是否成功", b)
+											updateMap = [][]map[string]interface{}{}
+										}
+
+									}
 									xlsxArr = append(xlsxArr, l)
 								}
 							}
+							if len(updateMap) > 0 {
+								b := MgoCus.UpdateBulk("usermail", updateMap...)
+								log.Println("更新是否成功", b)
+							}
 						}
 					}
 				} else {
@@ -261,11 +296,41 @@ func (s *SecondPush) SecondPushTask() {
 							"$lte": endtime,
 						},
 					}
-
 					d, _ := MgoCus.Find("usermail", q, nil, nil, false, 0, 0)
 					for _, l := range *d {
+						// 项目匹配为"1" 以及项目id为空时进行项目id匹配   同时更新数据库
+						if projectIdSearch == "1" && (l["projectId"] == "" || l["projectId"] == nil) {
+							_projectid := ""
+							projectId := GetProjectId(qu.ObjToString(l["id"]))
+							if projectId != "" {
+								l["projectId"] = SE.EncodeString(projectId)
+								_projectid = SE.EncodeString(projectId)
+							} else {
+								l["projectId"] = ""
+								_projectid = ""
+							}
+							updateMap = append(updateMap, []map[string]interface{}{
+								map[string]interface{}{
+									"_id": l["_id"],
+								},
+								map[string]interface{}{
+									"$set": map[string]interface{}{
+										"projectId": _projectid,
+									},
+								},
+							})
+							if len(updateMap) > 500 {
+								b := MgoCus.UpdateBulk("usermail", updateMap...)
+								log.Println("更新是否成功", b)
+								updateMap = [][]map[string]interface{}{}
+							}
+						}
 						xlsxArr = append(xlsxArr, l)
 					}
+					if len(updateMap) > 0 {
+						b := MgoCus.UpdateBulk("usermail", updateMap...)
+						log.Println("更新是否成功", b)
+					}
 				}
 				if len(xlsxArr) == 0 {
 					log.Println("查询数据为空")
@@ -286,6 +351,22 @@ func (s *SecondPush) SecondPushTask() {
 	}
 
 }
+func GetProjectId(id string) string {
+	query := `{"query": {"bool": {"must": [{"term": {"projectset.ids": "%s"}}],"must_not": [],"should": []}}}`
+	querys := fmt.Sprintf(query, id)
+	projectId := ""
+	projectIdArr := []string{}
+	data := Es.Get("projectset", "projectset", querys)
+	if data != nil && *data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			projectIdArr = append(projectIdArr, qu.ObjToString(v["_id"]))
+
+		}
+		projectId = strings.Join(projectIdArr, ",")
+		log.Println("projectId", projectId)
+	}
+	return projectId
+}
 
 //func (s *SecondPush) HistoryList() {
 //	id := s.GetString("id")
@@ -671,7 +752,7 @@ func GetXlsxs(mMap []map[string]interface{}, fn, email, id string) {
 						row.AddCell().SetValue(v["projectname"]) //项目名称
 						row.AddCell().SetValue(v["buyer"])       //采购单位
 						row.AddCell().SetValue(v["buyer_type"])  //采购单位类别---私有标签tagname
-						if v["bidamount"] != nil { //中标金额
+						if v["bidamount"] != nil {               //中标金额
 							row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
 						} else {
 							row.AddCell()
@@ -732,7 +813,7 @@ func GetXlsxs(mMap []map[string]interface{}, fn, email, id string) {
 			log.Println("fname", fname)
 			err = newFile.Save(dir + fname)
 			if err != nil {
-				log.Println("xls error", fname)
+				log.Println("xls error", err, fname)
 			} else {
 				for i := 0; i < len(history.Gmails); i++ {
 					gmail := history.Gmails[i]
@@ -761,6 +842,7 @@ func (s *SecondPush) AddSecondPushRule() {
 					"i_extfieldstype": i_extfieldstype,
 					"starttime":       s.GetString("starttime"),
 					"endtime":         s.GetString("endtime"),
+					"projectIdSearch": s.GetString("projectIdSearch"),
 				},
 			}
 			isupdata := Mgo.UpdateById("second_push", mongoutil.StringTOBsonId(his_id), set)

+ 13 - 0
src/web/templates/private/second_push_create.html

@@ -77,6 +77,13 @@
                                                         <option value="5">河南移动字段包</option>
                                                     </select>
                                                 </div>
+                                                <label class="col-sm-2 control-label ">项目id匹配</label>
+                                                <div class="col-sm-2">
+                                                    <select class="form-control selectpicker" id="projectIdSearch">
+                                                        <option value="1">是</option>
+                                                        <option value="0" selected>否</option>
+                                                    </select>
+                                                </div>
                                             </div>
                                             <div class="form-group">
                                                 <label class="col-sm-2 control-label ">开始时间</label>
@@ -253,6 +260,11 @@
             $(".delete-button").hide();
             $(".select-button").hide();
 
+        }
+        if(dataMap.projectIdSearch!=undefined){
+            $("#projectIdSearch").val(dataMap.projectIdSearch)
+            $("#projectIdSearch").selectpicker("refresh")
+
         }
         if (dataMap.i_state == 0) {
             $('.tab_2').hide()
@@ -408,6 +420,7 @@
         dataMap.sendMail = $("#sendMail").val();
         dataMap.s_pushid = s_pushid;
         dataMap.c_id = c_id;
+        dataMap.projectIdSearch = $("#projectIdSearch option:selected").val();
         if ($('#starttime').find("input").val() != "") {
             var start = $('#starttime').find("input").val();
             start = new Date(start).getTime() / 1000;