123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- package main
- import (
- "fmt"
- "github.com/xuri/excelize/v2"
- "go.mongodb.org/mongo-driver/bson"
- utils "jygit.jydev.jianyu360.cn/data_processing/common_utils"
- "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
- "log"
- "strings"
- "time"
- )
- func main() {
- //getWinnerArea()
- //winnerCity()
- //test1()
- //statisticWinner()
- getBidding()
- log.Println("处理结束")
- }
- // getWinnerArea 获取中标单位所在区域
- func getWinnerArea() {
- /**
- 本次只获取 北京、天津、河北三个地区
- */
- MgoP := &mongodb.MongodbSim{
- //MongodbAddr: "127.0.0.1:27080",
- MongodbAddr: "172.17.4.85:27080",
- DbName: "qfw",
- Size: 10,
- //Direct: true,
- }
- MgoP.InitPool()
- // 定义年份的时间范围
- year := 2023
- now := time.Now()
- startTime := time.Date(year, 1, 1, 0, 0, 0, 0, now.Location())
- endTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, now.Location())
- where := map[string]interface{}{
- "firsttime": bson.M{
- "$gte": startTime.Unix(),
- "$lt": endTime.Unix(),
- },
- }
- type WinnerArea struct {
- Winner string `json:"winner"`
- Area string `json:"area"`
- City string `json:"city"`
- District string `json:"district"`
- UniqueKey string `json:"unique_key"`
- WinnerProvince string `json:"winner_province"`
- WinnerCity string `json:"winner_city"`
- WinnerDistrict string `json:"winner_district"`
- Count int `json:"count"`
- }
- sess := MgoP.GetMgoConn()
- defer MgoP.DestoryMongoConn(sess)
- query := sess.DB("qfw").C("projectset_20230904").Find(where).Select(map[string]interface{}{"list": 0}).Iter()
- count := 0
- areas := []string{"北京", "北京市", "天津", "天津市", "河北", "河北省"}
- listMap := make(map[string]WinnerArea)
- for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
- if count%10000 == 0 {
- log.Println("current ---", count, tmp["projectname"])
- }
- // 有中标单位
- if _, ok := tmp["s_winner"]; ok {
- if IsInStringArray(utils.ObjToString(tmp["area"]), areas) {
- key := utils.ObjToString(tmp["city"]) + "-" + utils.ObjToString(tmp["district"]) + "_" + utils.ObjToString(tmp["s_winner"])
- // 获取当前值
- windata, found := listMap[key]
- if !found {
- windata = WinnerArea{
- Winner: utils.ObjToString(tmp["s_winner"]),
- Area: utils.ObjToString(tmp["area"]),
- City: utils.ObjToString(tmp["city"]),
- District: utils.ObjToString(tmp["district"]),
- UniqueKey: key,
- Count: 1, // 初始化计数
- }
- listMap[key] = windata
- } else {
- windata.Count++
- listMap[key] = windata
- }
- }
- }
- }
- log.Println("2023年 总数是:", len(listMap))
- for k, _ := range listMap {
- data := structToMap(listMap[k])
- //log.Println(data)
- MgoP.Save("wcc_2023_winner_area_0608", data)
- }
- }
- // winnerCity 更新中标单位省市区
- func winnerCity() {
- // 本地
- //Mgo := &mongodb.MongodbSim{
- // MongodbAddr: "127.0.0.1:27017",
- // Size: 10,
- // DbName: "wcc",
- //}
- //Mgo.InitPool()
- // 线上163
- Mgo := &mongodb.MongodbSim{
- MongodbAddr: "172.17.189.140:27080",
- //MongodbAddr: "127.0.0.1:27083",
- Size: 10,
- DbName: "qfw",
- UserName: "SJZY_RWbid_ES",
- Password: "SJZY@B4i4D5e6S",
- //Direct: true,
- }
- Mgo.InitPool()
- sess := Mgo.GetMgoConn()
- defer Mgo.DestoryMongoConn(sess)
- coll := "wcc_2023_winner_area_0608"
- query := sess.DB("qfw").C(coll).Find(nil).Select(nil).Iter()
- count := 0
- for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
- if count%10000 == 0 {
- log.Println("current ---", count, tmp["winner"])
- }
- data := map[string]interface{}{
- "buyer": tmp["winner"],
- }
- res := GetAreaInfo(data)
- if res != nil {
- update := map[string]interface{}{
- "winner_province": res["area"],
- "winner_city": res["city"],
- "winner_district": res["district"],
- }
- Mgo.UpdateById(coll, tmp["_id"], map[string]interface{}{"$set": update})
- }
- }
- }
- // statisticWinner 统计中标单位区域分布
- func statisticWinner() {
- //cellsLine := []string{"B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "P", "Q", "R", "S", "T"}
- f, err := excelize.OpenFile("./中标项目区域分布.xlsx")
- if err != nil {
- fmt.Println(err)
- return
- }
- defer func() {
- if err := f.Close(); err != nil {
- fmt.Println(err)
- }
- }()
- rows, err := f.GetRows("2019")
- if err != nil {
- fmt.Println(err)
- return
- }
- cells, _ := f.GetCols("2019")
- //log.Println(rows, cells)
- // 线上163
- Mgo := &mongodb.MongodbSim{
- //MongodbAddr: "172.17.189.140:27080",
- MongodbAddr: "127.0.0.1:27083",
- Size: 10,
- DbName: "qfw",
- UserName: "SJZY_RWbid_ES",
- Password: "SJZY@B4i4D5e6S",
- Direct: true,
- }
- Mgo.InitPool()
- coll := "wcc_2019_winner_area_0608"
- for i := 1; i < len(rows); i++ {
- rowData := make([]interface{}, 0)
- area1 := strings.Replace(rows[i][0], " ", "", -1)
- for j := 1; j < len(cells); j++ {
- area2 := strings.Replace(cells[j][0], " ", "", -1)
- where := make(map[string]interface{})
- if i < 18 {
- if area1 == "北京市" {
- where["city"] = "北京市"
- } else {
- where["city"] = "北京市"
- where["district"] = area1
- }
- } else if i < 35 {
- if area1 == "天津市" {
- where["city"] = "天津市"
- } else {
- where["city"] = "天津市"
- where["district"] = area1
- }
- } else {
- if area1 == "河北省" {
- where["area"] = "河北"
- } else {
- where["area"] = "河北"
- where["city"] = area1
- }
- }
- if j < 18 {
- if area2 == "北京市" {
- where["winner_city"] = "北京市"
- } else {
- where["winner_city"] = "北京市"
- where["winner_district"] = area2
- }
- } else if j < 35 {
- if area2 == "天津市" {
- where["winner_city"] = "天津市"
- } else {
- where["winner_city"] = "天津市"
- where["winner_district"] = area2
- }
- } else {
- if area2 == "河北省" {
- where["winner_province"] = "河北"
- } else {
- where["winner_province"] = "河北"
- where["winner_city"] = area2
- }
- }
- num := Mgo.Count(coll, where)
- log.Println("iiiiiii", i, area1, ",jjjjjjjj", j, area2, num)
- rowData = append(rowData, num)
- }
- //_ = xlsx.SetSheetRow(sheet, fmt.Sprintf("%s%d", "C", line), &subtitles)
- f.SetSheetRow("2019", fmt.Sprintf("%s%d", "B", i+1), &rowData)
- }
- f.Save()
- }
|