package service import ( "encoding/json" "fmt" "history" "log" "os" mongoutil "qfw/mongodb" qu "qfw/util" "qfw/util/mail" "strconv" "strings" "time" . "util" "github.com/tealeg/xlsx" "github.com/go-xweb/xweb" "gopkg.in/mgo.v2/bson" ) var ( xlsxArr []map[string]interface{} SE = qu.SimpleEncrypt{Key: "topJYBX2019"} ) type SecondPush struct { *xweb.Action secondPush xweb.Mapper `xweb:"/service/secondpush/create"` getUserRule xweb.Mapper `xweb:"/service/secondpush/getrules"` saveSpushRule xweb.Mapper `xweb:"/service/secondpush/saverule"` secondPushTask xweb.Mapper `xweb:"/service/secondpush/dotask"` addSecondPushRule xweb.Mapper `xweb:"/service/secondpush/add"` //保存二次推送规则 secondPushList xweb.Mapper `xweb:"/service/secondpush/list"` secondPushClone xweb.Mapper `xweb:"/service/secondPushClone/(.*)"` delSecondPushRule xweb.Mapper `xweb:"/service/customer/secondpush/delrule"` //删除历史任务规则 } func (s *SecondPush) SecondPush() { defer qu.Catch() id := s.GetString("id") user := s.GetSession("user").(map[string]interface{}) query := bson.M{} query["_id"] = mongoutil.StringTOBsonId(id) s_pushid := s.GetString("s_pushid") secondpush_id := "" if s_pushid != "" { secondpush_id = s_pushid hData, ok := Mgo.FindOne("second_push", bson.M{"_id": mongoutil.StringTOBsonId(secondpush_id)}) if ok && hData != nil && len(*hData) > 0 { s.T["spush_rule"] = (*hData)["dep_rules"] (*hData)["_id"] = id s.T["data"] = *hData } } else { var user_name, user_customername, appid = "", "", "" userInfo, ok := Mgo.FindOne("euser", query) if ok && userInfo != nil && *userInfo != nil { user_name = qu.ObjToString((*userInfo)["s_name"]) user_customername = qu.ObjToString((*userInfo)["s_customername"]) appid = qu.ObjToString((*userInfo)["s_appid"]) } secondpush_id = Mgo.Save("second_push", 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_appid": appid, }) s.Redirect("/service/secondpush/create?id=" + id + "&s_pushid=" + secondpush_id) return } s.T["spush_id"] = secondpush_id s.Render("private/second_push_create.html", &s.T) } func (s *SecondPush) GetUserRule() { customerId := s.GetString("c_id") query := bson.M{ "s_userid": customerId, "b_delete": false, } data, _ := 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": mongoutil.BsonIdToSId(m["_id"]), "b_delete": false, } history_rule_data["department_isuse"] = m["i_isuse"] history_rule_data["depart_name"] = m["s_name"] depart_rule_data, _ := 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"] = mongoutil.BsonIdToSId(j["_id"]) } history_rule_data["department_rule"] = depart_rule_data history_rule_data["is_slected"] = true } res = append(res, history_rule_data) } s.ServeJson(map[string]interface{}{ "status": "success", "data": res, }) } else { s.ServeJson(map[string]interface{}{ "status": "fail", "data": "", }) } } //保存二次推送规则 func (s *SecondPush) SaveSpushRule() { rules_id := s.GetString("rulesid") s_pushid := s.GetString("s_pushid") // userid := s.GetString("userid") if s_pushid != "" { user_history, _ := Mgo.FindOne("second_push", map[string]interface{}{ "_id": mongoutil.StringTOBsonId(s_pushid), }) if *user_history != nil && user_history != nil { if (*user_history)["dep_rules"] != nil { dep_rules := qu.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[mongoutil.BsonIdToSId(r["_id"])] = true } } rules_id_list := strings.Split(rules_id, ",") for _, rule := range rules_id_list { if !ruleMap[rule] { query := bson.M{ "_id": mongoutil.StringTOBsonId(rule), "b_delete": false, } res, _ := Mgo.FindOne("euserdepartrule", query) if res != nil && len(*res) != 0 { //获取规则所属部门信息 department_info, _ := Mgo.FindOne("euserdepart", map[string]interface{}{ "_id": mongoutil.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 := Mgo.Update("second_push", map[string]interface{}{ "_id": mongoutil.StringTOBsonId(s_pushid), }, set, false, false) s.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": mongoutil.StringTOBsonId(rule), "b_delete": false, } res, _ := Mgo.FindOne("euserdepartrule", query) if res != nil && *res != nil { //获取规则所属部门信息 department_info, _ := Mgo.FindOne("euserdepart", map[string]interface{}{ "_id": mongoutil.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 := Mgo.Update("second_push", map[string]interface{}{ "_id": mongoutil.StringTOBsonId(s_pushid), }, set, false, false) s.ServeJson(map[string]interface{}{ "status": isupdata, }) return } } s.ServeJson(map[string]interface{}{ "status": "fail", }) } } func (s *SecondPush) SecondPushTask() { log.Println("开始二次推送任务...") s_pushid := s.GetString("s_pushid") if s_pushid != "" { customer, _ := Mgo.Find("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(s_pushid)}, nil, nil, false, -1, -1) if len(*customer) == 1 { c := (*customer)[0] customer_name := qu.ObjToString(c["s_name"]) //客户名称 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{} for _, m := range c["dep_rules"].([]interface{}) { log.Println("ruleid", mongoutil.BsonIdToSId(m.(map[string]interface{})["_id"])) q := bson.M{ "ruleid": bson.M{"$regex": mongoutil.BsonIdToSId(m.(map[string]interface{})["_id"])}, "bget": 1, "createtime": bson.M{ "$gte": starttime, "$lte": endtime, }, } 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匹配 同时更新数据库 if projectIdSearch == "1" && (l["projectId"] == "" || l["projectId"] == nil) { updateMap = searchProjectId(l, updateMap) } xlsxArr = append(xlsxArr, l) } } if len(updateMap) > 0 { MgoCus.UpdateBulk("usermail", updateMap...) } } } } else { q := bson.M{ "appid": c["s_appid"], "bget": 1, "createtime": bson.M{ "$gte": starttime, "$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) { updateMap = searchProjectId(l, updateMap) } xlsxArr = append(xlsxArr, l) } if len(updateMap) > 0 { MgoCus.UpdateBulk("usermail", updateMap...) } } if len(xlsxArr) == 0 { log.Println("查询数据为空") } else { log.Println(len(xlsxArr)) GetXlsxs(xlsxArr, customer_name, email, s_pushid, qu.ObjToString(c["s_appid"])) go UpdateHistoryState(2, s_pushid, len(xlsxArr)) s.ServeJson(map[string]interface{}{ "status": true, }) xlsxArr = []map[string]interface{}{} } } } else { log.Println("初始化客户信息失败") } } } func searchProjectId(l map[string]interface{}, updateMap [][]map[string]interface{}) [][]map[string]interface{} { _projectid := "" projectId := getProjectId(qu.ObjToString(l["id"])) if projectId != "" { l["projectId"] = projectId _projectid = 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 { MgoCus.UpdateBulk("usermail", updateMap...) updateMap = [][]map[string]interface{}{} } return updateMap } 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("id", id, "projectId", projectId) } return projectId } //func (s *SecondPush) HistoryList() { // id := s.GetString("id") // if s.Method() == "POST" { // data, _ := Mgo.Find("second_push", map[string]interface{}{"user_id": id}, `{"updatetime":-1}`, nil, false, -1, -1) // s.ServeJson(map[string]interface{}{ // "data": data, // }) // } else { // s.T["id"] = id // s.Render("private/historylog_list.html", &s.T) // } //} func UpdateHistoryState(state int, s_pushid string, count int) { if state == 2 { Mgo.Update("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(s_pushid)}, map[string]interface{}{ "$set": map[string]interface{}{ "state": state, "result_count": count, "finishtime": time.Now().Unix(), }, }, false, false) return } Mgo.Update("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(s_pushid)}, map[string]interface{}{ "$set": map[string]interface{}{ "state": state, }, }, false, false) } func (s *SecondPush) HistoryClone(hid string) { data, ok := Mgo.FindOne("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)}) if ok && data != nil && *data != nil { (*data)["state"] = 0 (*data)["result_count"] = nil (*data)["createtime"] = time.Now().Unix() (*data)["updatetime"] = time.Now().Unix() Mgo.Save("second_push", *data) } } func (s *SecondPush) HistoryRuleEdit() { hid := s.GetString("hid") rid := s.GetString("rid") if s.Method() == "POST" { data := GetPostForm(s.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"] = mongoutil.StringTOBsonId(rid) if qu.IntAll(data["i_esquerytype"]) == 1 { //自动生成es data["s_esquery"] = Utiltags(data) } datas, ok := Mgo.FindOne("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)}) if ok && datas != nil && *datas != nil { dep_rules := qu.ObjArrToMapArr((*datas)["dep_rules"].([]interface{})) for k, v := range dep_rules { if rid == mongoutil.BsonIdToSId(v["_id"]) { dep_rules[k] = data } } rep := Mgo.Update("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)}, map[string]interface{}{"$set": map[string]interface{}{"dep_rules": dep_rules}}, false, false) s.ServeJson(map[string]interface{}{ "rep": rep, "s_esquery": data["s_esquery"], }) } } else { id := s.GetString("id") data, ok := Mgo.FindOne("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)}) if ok && data != nil && *data != nil { dep_rules := qu.ObjArrToMapArr((*data)["dep_rules"].([]interface{})) for _, v := range dep_rules { if rid == mongoutil.BsonIdToSId(v["_id"]) { s.T["data"] = v } } } s.T["did"] = id //部门id s.T["cid"] = id //客户id s.T["ids"] = id s.T["history_id"] = hid s.T["rid"] = rid s.T["province"] = Province s.T["city"] = ProvinceCitys s.T["district"] = CityDistricts s.T["topTypeArr"] = TopTypeArr s.T["subTypeArr"] = SubTypeArr s.T["matchTypeMap"] = MatchTypeMap s.T["matchTypeMap2"] = MatchTypeMap2 s.T["existField"] = ExistFiled s.T["buyerClass"] = BuyerClass s.T["scopeClass"] = ScopeClassMap s.Render("private/history_rule_edit.html", &s.T) } } func GetXlsxs(mMap []map[string]interface{}, fn, email, id, appid string) { if id != "" { isfile := false isfilehref := false if history.FileTextAppidMap[appid] { isfile = true } if history.NeedFilehrefAppidMap[appid] { isfilehref = true } query := bson.M{ "_id": bson.ObjectIdHex(id), } data, ok := Mgo.FindOne("second_push", query) if ok && (*data) != nil && len(*data) > 0 { dataType := qu.IntAll((*data)["i_extfieldstype"]) xf, err := xlsx.OpenFile("web/res/fields.xlsx") if err != nil { log.Println("fields file not foud", err.Error()) } newFile := xlsx.NewFile() style := xlsx.NewStyle() style.Font.Size = 12 style.Font.Bold = true style.Alignment.Vertical = "center" style.Alignment.Horizontal = "center" if dataType == 1 { sh := xf.Sheets[0] sheetIndex := map[string]int{} for _, v := range mMap { // 拿到所选字段包的sheet页 如果item存在则追加 不存在则创建新sheet页 var sheet *xlsx.Sheet if v["item"].(string) == "" { v["item"] = "其他方式" } items := strings.Split(v["item"].(string), ",") for _, i := range items { if len(items) > 1 && v["itemdist"] != nil { v["matchkey"] = v["itemdist"].(map[string]interface{})[i] v["item"] = i } if _, ok := newFile.Sheet[v["item"].(string)]; ok { sheet = newFile.Sheet[v["item"].(string)] sheetIndex[v["item"].(string)] += 1 } else { sheet, err = newFile.AppendSheet(*sh, v["item"].(string)) sheetIndex[v["item"].(string)] = 1 } row := sheet.AddRow() row.AddCell().SetInt(sheetIndex[v["item"].(string)]) row.AddCell().SetValue(v["matchkey"]) row.AddCell().SetValue(v["area"]) row.AddCell().SetValue(v["city"]) row.AddCell().SetValue(v["title"]) row.AddCell().SetValue(v["subtype"]) if v["publishtime"] != nil { row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02")) } else { row.AddCell() } row.AddCell().SetValue(v["buyer"]) row.AddCell().SetValue(v["s_winner"]) if v["bidamount"] != nil { row.AddCell().SetFloat(qu.Float64All(v["bidamount"])) } else { row.AddCell() } row.AddCell().SetValue(v["projectname"]) row.AddCell().SetValue(v["detail"]) row.AddCell().SetValue(v["jybxhref"]) ids := SE.EncodeString(qu.ObjToString(v["id"])) row.AddCell().SetValue(ids) } } //xf.Sheets = xf.Sheets[0:1] } else if dataType == 2 { sh := xf.Sheets[1] if isfile { cell := sh.Rows[0].AddCell() cell.SetValue("附件") cell.SetStyle(style) } if isfilehref { cell := sh.Rows[0].AddCell() cell.SetValue("附件链接") cell.SetStyle(style) } for _, v := range mMap { if v["item"].(string) == "" { v["item"] = "其他方式" } items := strings.Split(v["item"].(string), ",") for _, i := range items { if len(items) > 1 && v["itemdist"] != nil { v["matchkey"] = v["itemdist"].(map[string]interface{})[i] v["item"] = i } var sheet *xlsx.Sheet if _, ok := newFile.Sheet[v["item"].(string)]; ok { sheet = newFile.Sheet[v["item"].(string)] } else { sheet, err = newFile.AppendSheet(*sh, v["item"].(string)) } row := sheet.AddRow() // row.AddCell().SetInt(i + 1) row.AddCell().SetValue(v["matchkey"]) row.AddCell().SetValue(v["area"]) row.AddCell().SetValue(v["city"]) row.AddCell().SetValue(v["title"]) row.AddCell().SetValue(v["subtype"]) row.AddCell().SetValue(v["detail"]) if v["publishtime"] != nil { row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02")) } else { row.AddCell() } row.AddCell().SetValue(v["href"]) row.AddCell().SetValue(v["jybxhref"]) row.AddCell().SetValue(v["projectname"]) row.AddCell().SetValue(v["projectcode"]) row.AddCell().SetValue(v["projectscope"]) if v["budget"] != nil { row.AddCell().SetFloat(qu.Float64All(v["budget"])) } else { row.AddCell() } if v["bidamount"] != nil { row.AddCell().SetFloat(qu.Float64All(v["bidamount"])) } else { row.AddCell() } if v["bidopentime"] != nil { row.AddCell().SetValue(time.Unix(qu.Int64All(v["bidopentime"]), 0).Format("2006-01-02")) } else { row.AddCell() } row.AddCell().SetValue(v["buyer"]) row.AddCell().SetValue(v["buyerperson"]) row.AddCell().SetValue(v["buyertel"]) row.AddCell().SetValue(v["agency"]) row.AddCell().SetValue(v["s_winner"]) row.AddCell().SetValue(v["winnerperson"]) row.AddCell().SetValue(v["winnertel"]) row.AddCell().SetValue(v["legal_person"]) row.AddCell().SetValue(v["company_phone"]) row.AddCell().SetValue(v["company_email"]) ids := SE.EncodeString(qu.ObjToString(v["id"])) row.AddCell().SetValue(ids) if isfile { row.AddCell().SetValue(v["filetext"]) } if isfilehref { if v["filehref"] != nil { if filelist, ok := v["filehref"].([]interface{}); ok { index := 0 for _, url := range filelist { if urlMap, ok := url.(map[string]interface{}); ok { if urlMap["url"] != nil { style1 := xlsx.NewStyle() style1.Font.Name = "宋体" style1.Font.Size = 12 style1.Font.Bold = false if history.FilterFilehrefAppidMap[appid] { if strings.Contains(urlMap["url"].(string), "jy-datafile.oss-cn-beijing.aliyuncs.com") { cell := row.AddCell() cell.SetStyle(style1) cell.SetValue(urlMap["url"]) index++ } } else { cell := row.AddCell() cell.SetStyle(style1) cell.SetValue(urlMap["url"]) index++ } } } } } } } } } //xf.Sheets = xf.Sheets[1:2] } else if dataType == 3 { sh := xf.Sheets[2] for _, v := range mMap { if v["item"].(string) == "" { v["item"] = "其他方式" } items := strings.Split(v["item"].(string), ",") for _, i := range items { if len(items) > 1 && v["itemdist"] != nil { v["matchkey"] = v["itemdist"].(map[string]interface{})[i] v["item"] = i } var sheet *xlsx.Sheet if _, ok := newFile.Sheet[v["item"].(string)]; ok { sheet = newFile.Sheet[v["item"].(string)] } else { sheet, err = newFile.AppendSheet(*sh, v["item"].(string)) } row := sheet.AddRow() // row.AddCell().SetInt(i + 1) row.AddCell().SetValue(v["departname"]) row.AddCell().SetValue(v["rulename"]) row.AddCell().SetValue(v["matchkey"]) row.AddCell().SetValue(v["toptype"]) row.AddCell().SetValue(v["area"]) row.AddCell().SetValue(v["city"]) row.AddCell().SetValue(v["district"]) row.AddCell().SetValue(v["title"]) row.AddCell().SetValue(v["detail"]) if v["publishtime"] != nil { row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02")) } else { row.AddCell() } row.AddCell().SetValue(v["href"]) if v["bidamount"] != nil { row.AddCell().SetFloat(qu.Float64All(v["bidamount"])) } else { row.AddCell() } row.AddCell().SetValue(v["buyer"]) row.AddCell().SetValue(v["buyerclass"]) row.AddCell().SetValue(v["buyerperson"]) row.AddCell().SetValue(v["buyertel"]) row.AddCell().SetValue(v["s_winner"]) row.AddCell().SetValue(v["legal_person"]) row.AddCell().SetValue(v["company_phone"]) row.AddCell().SetValue(v["company_address"]) row.AddCell().SetValue(v["rank"]) row.AddCell().SetValue(v["purchasing"]) row.AddCell().SetValue(v["capital"]) row.AddCell().SetValue(v["establish_date"]) row.AddCell().SetValue(v["business_scope"]) row.AddCell().SetValue(v["stock_name"]) row.AddCell().SetValue(v["buyer_credit_no"]) row.AddCell().SetValue(v["winner_credit_no"]) ids := SE.EncodeString(qu.ObjToString(v["id"])) row.AddCell().SetValue(ids) } } //xf.Sheets = xf.Sheets[2:3] } else if dataType == 4 { sh := xf.Sheets[3] for _, v := range mMap { if v["item"].(string) == "" { v["item"] = "其他方式" } items := strings.Split(v["item"].(string), ",") for _, i := range items { if len(items) > 1 && v["itemdist"] != nil { v["matchkey"] = v["itemdist"].(map[string]interface{})[i] v["item"] = i } var sheet *xlsx.Sheet if _, ok := newFile.Sheet[v["item"].(string)]; ok { sheet = newFile.Sheet[v["item"].(string)] } else { sheet, err = newFile.AppendSheet(*sh, v["item"].(string)) } row := sheet.AddRow() // row.AddCell().SetInt(i + 1) row.AddCell().SetValue(v["departname"]) row.AddCell().SetValue(v["rulename"]) row.AddCell().SetValue(v["matchkey"]) row.AddCell().SetValue(v["area"]) row.AddCell().SetValue(v["city"]) row.AddCell().SetValue(v["title"]) row.AddCell().SetValue(v["subtype"]) row.AddCell().SetValue(v["detail"]) if v["publishtime"] != nil { row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02")) } else { row.AddCell() } row.AddCell().SetValue(v["href"]) row.AddCell().SetValue(v["jybxhref"]) row.AddCell().SetValue(v["projectname"]) row.AddCell().SetValue(v["projectcode"]) row.AddCell().SetValue(v["projectscope"]) if v["budget"] != nil { row.AddCell().SetFloat(qu.Float64All(v["budget"])) } else { row.AddCell() } if v["bidamount"] != nil { row.AddCell().SetFloat(qu.Float64All(v["bidamount"])) } else { row.AddCell() } if v["bidopentime"] != nil { row.AddCell().SetValue(time.Unix(qu.Int64All(v["bidopentime"]), 0).Format("2006-01-02")) } else { row.AddCell() } row.AddCell().SetValue(v["buyer"]) row.AddCell().SetValue(v["buyerperson"]) row.AddCell().SetValue(v["buyertel"]) row.AddCell().SetValue(v["agency"]) row.AddCell().SetValue(v["s_winner"]) row.AddCell().SetValue(v["winnerperson"]) row.AddCell().SetValue(v["winnertel"]) row.AddCell().SetValue(v["legal_person"]) row.AddCell().SetValue(v["company_phone"]) row.AddCell().SetValue(v["company_email"]) ids := SE.EncodeString(qu.ObjToString(v["id"])) row.AddCell().SetValue(ids) } } //xf.Sheets = xf.Sheets[3:4] } else if dataType == 5 { sh := xf.Sheets[4] for _, v := range mMap { if v["item"].(string) == "" { v["item"] = "其他方式" } items := strings.Split(v["item"].(string), ",") for _, i := range items { if len(items) > 1 && v["itemdist"] != nil { v["matchkey"] = v["itemdist"].(map[string]interface{})[i] v["item"] = i } var sheet *xlsx.Sheet if _, ok := newFile.Sheet[v["item"].(string)]; ok { sheet = newFile.Sheet[v["item"].(string)] } else { sheet, err = newFile.AppendSheet(*sh, v["item"].(string)) } row := sheet.AddRow() // row.AddCell().SetInt(i + 1) row.AddCell().SetValue(v["matchkey"]) //信息匹配词 row.AddCell().SetValue(v["city"]) //城市 row.AddCell().SetValue(v["district"]) //县区 row.AddCell().SetValue(v["projectname"]) //项目名称 row.AddCell().SetValue(v["buyer"]) //采购单位 row.AddCell().SetValue(v["buyer_type"]) //采购单位类别---私有标签tagname if v["bidamount"] != nil { //中标金额 row.AddCell().SetFloat(qu.Float64All(v["bidamount"])) } else { row.AddCell() } if v["budget"] != nil { //预算 row.AddCell().SetFloat(qu.Float64All(v["budget"])) } else { row.AddCell() } if v["publishtime"] != nil { //公告发布时间 row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02")) } else { row.AddCell() } if v["bidopentime"] != nil { //开标日期 row.AddCell().SetValue(time.Unix(qu.Int64All(v["bidopentime"]), 0).Format("2006-01-02")) } else { row.AddCell() } row.AddCell().SetValue(v["s_winner"]) //中标单位 row.AddCell().SetValue(v["winner_type"]) //中标模式--移动、电信、联通 row.AddCell().SetValue(v["title"]) //公告标题 row.AddCell().SetValue(v["subtype"]) //公告类别 row.AddCell().SetValue(v["area"]) //省份 row.AddCell().SetValue(v["projectcode"]) //项目编号 row.AddCell().SetValue(v["projectscope"]) //项目范围 row.AddCell().SetValue(v["agency"]) //招标代理机构 row.AddCell().SetValue(v["detail"]) //公告内容 row.AddCell().SetValue(v["href"]) //公告地址 row.AddCell().SetValue(v["buyerperson"]) //采购单位联系人 row.AddCell().SetValue(v["buyertel"]) //采购单位联系电话 row.AddCell().SetValue(v["winnerperson"]) //中标单位联系人 row.AddCell().SetValue(v["winnertel"]) //中标单位联系电话 row.AddCell().SetValue(v["legal_person"]) //中标企业联系人 row.AddCell().SetValue(v["company_phone"]) //中标企业联系电话 row.AddCell().SetValue(v["company_email"]) //中标企业邮箱 ids := SE.EncodeString(qu.ObjToString(v["id"])) //唯一标识 row.AddCell().SetValue(ids) row.AddCell().SetValue(SE.EncodeString(qu.ObjToString(v["projectId"]))) //项目标识 row.AddCell().SetValue(v["jybxhref"]) //row.AddCell().SetValue(v["projectcode"]) } } //xf.Sheets = xf.Sheets[4:5] } //xf.Sheets[0].Name = "详细数据" //生文件 //t := strconv.FormatInt(time.Now().Unix(), 10) t := time.Now().Format("20060102") dir := "./web/res/xlsx/" + t + "/" if b, _ := history.PathExists(dir); !b { err1 := os.MkdirAll(dir, os.ModePerm) if err1 != nil { log.Println("mkdir err", dir) } } fname := fmt.Sprintf("%s_%s_%s.xlsx", fn, t, qu.GetRandom(4)) log.Println("fname", fname) err = newFile.Save(dir + fname) if err != nil { log.Println("xls error", err, fname) } else { for i := 0; i < len(history.Gmails); i++ { gmail := history.Gmails[i] status := mail.GSendMail_q("剑鱼标讯", email, "", "", fn, "", dir+fname, fname, gmail) if status { log.Println("send mail success", fname, email) break } } } } } } func (s *SecondPush) AddSecondPushRule() { defer qu.Catch() if s.Method() == "POST" { his_id := s.GetString("s_pushid") if his_id != "" { i_updatetime, _ := strconv.ParseInt(s.GetString("i_updatetime"), 10, 64) i_extfieldstype, _ := strconv.Atoi(s.GetString("i_extfieldstype")) set := bson.M{ "$set": bson.M{ "i_updatetime": i_updatetime, "sendMail": s.GetString("sendMail"), "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) if isupdata { s.ServeJson(map[string]interface{}{ "history_id": his_id, "rep": true, }) } else { s.ServeJson(map[string]interface{}{ "history_id": "", "rep": false, }) } } } } func (s *SecondPush) SecondPushList() { id := s.GetString("id") if s.Method() == "POST" { data, _ := Mgo.Find("second_push", map[string]interface{}{"user_id": id}, `{"updatetime":-1}`, nil, false, -1, -1) s.ServeJson(map[string]interface{}{ "data": data, }) } } func (s *SecondPush) SecondPushClone(hid string) { data, ok := Mgo.FindOne("second_push", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)}) user := s.GetSession("user").(map[string]interface{}) if ok && data != nil && *data != nil { (*data)["state"] = 0 (*data)["result_count"] = nil (*data)["createtime"] = time.Now().Unix() (*data)["updatetime"] = time.Now().Unix() (*data)["create_user"] = user["name"] delete((*data), "finishtime") Mgo.Save("second_push", *data) } } func (s *SecondPush) DelSecondPushRule() { id := s.GetString("id") hid := s.GetString("s_pushid") if hid != "" { data, ok := Mgo.FindOne("second_push", bson.M{"_id": mongoutil.StringTOBsonId(hid)}) if ok && data != nil && *data != nil { if (*data)["dep_rules"] != nil { dep_rules := qu.ObjArrToMapArr((*data)["dep_rules"].([]interface{})) ruleMap := map[string]bool{id: true} ruleArr := []map[string]interface{}{} for _, m := range dep_rules { if !ruleMap[mongoutil.BsonIdToSId(m["_id"])] { ruleArr = append(ruleArr, m) } } ok := Mgo.Update("second_push", bson.M{"_id": mongoutil.StringTOBsonId(hid)}, bson.M{"$set": bson.M{"dep_rules": ruleArr}}, false, false) s.ServeJson(map[string]interface{}{ "success": ok, }) } } } }