main.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/xuri/excelize/v2"
  5. "go.mongodb.org/mongo-driver/bson"
  6. utils "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  7. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  8. "log"
  9. "strings"
  10. "time"
  11. )
  12. func main() {
  13. //getWinnerArea()
  14. //winnerCity()
  15. //test1()
  16. //statisticWinner()
  17. getBidding()
  18. log.Println("处理结束")
  19. }
  20. // getWinnerArea 获取中标单位所在区域
  21. func getWinnerArea() {
  22. /**
  23. 本次只获取 北京、天津、河北三个地区
  24. */
  25. MgoP := &mongodb.MongodbSim{
  26. //MongodbAddr: "127.0.0.1:27080",
  27. MongodbAddr: "172.17.4.85:27080",
  28. DbName: "qfw",
  29. Size: 10,
  30. //Direct: true,
  31. }
  32. MgoP.InitPool()
  33. // 定义年份的时间范围
  34. year := 2023
  35. now := time.Now()
  36. startTime := time.Date(year, 1, 1, 0, 0, 0, 0, now.Location())
  37. endTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, now.Location())
  38. where := map[string]interface{}{
  39. "firsttime": bson.M{
  40. "$gte": startTime.Unix(),
  41. "$lt": endTime.Unix(),
  42. },
  43. }
  44. type WinnerArea struct {
  45. Winner string `json:"winner"`
  46. Area string `json:"area"`
  47. City string `json:"city"`
  48. District string `json:"district"`
  49. UniqueKey string `json:"unique_key"`
  50. WinnerProvince string `json:"winner_province"`
  51. WinnerCity string `json:"winner_city"`
  52. WinnerDistrict string `json:"winner_district"`
  53. Count int `json:"count"`
  54. }
  55. sess := MgoP.GetMgoConn()
  56. defer MgoP.DestoryMongoConn(sess)
  57. query := sess.DB("qfw").C("projectset_20230904").Find(where).Select(map[string]interface{}{"list": 0}).Iter()
  58. count := 0
  59. areas := []string{"北京", "北京市", "天津", "天津市", "河北", "河北省"}
  60. listMap := make(map[string]WinnerArea)
  61. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  62. if count%10000 == 0 {
  63. log.Println("current ---", count, tmp["projectname"])
  64. }
  65. // 有中标单位
  66. if _, ok := tmp["s_winner"]; ok {
  67. if IsInStringArray(utils.ObjToString(tmp["area"]), areas) {
  68. key := utils.ObjToString(tmp["city"]) + "-" + utils.ObjToString(tmp["district"]) + "_" + utils.ObjToString(tmp["s_winner"])
  69. // 获取当前值
  70. windata, found := listMap[key]
  71. if !found {
  72. windata = WinnerArea{
  73. Winner: utils.ObjToString(tmp["s_winner"]),
  74. Area: utils.ObjToString(tmp["area"]),
  75. City: utils.ObjToString(tmp["city"]),
  76. District: utils.ObjToString(tmp["district"]),
  77. UniqueKey: key,
  78. Count: 1, // 初始化计数
  79. }
  80. listMap[key] = windata
  81. } else {
  82. windata.Count++
  83. listMap[key] = windata
  84. }
  85. }
  86. }
  87. }
  88. log.Println("2023年 总数是:", len(listMap))
  89. for k, _ := range listMap {
  90. data := structToMap(listMap[k])
  91. //log.Println(data)
  92. MgoP.Save("wcc_2023_winner_area_0608", data)
  93. }
  94. }
  95. // winnerCity 更新中标单位省市区
  96. func winnerCity() {
  97. // 本地
  98. //Mgo := &mongodb.MongodbSim{
  99. // MongodbAddr: "127.0.0.1:27017",
  100. // Size: 10,
  101. // DbName: "wcc",
  102. //}
  103. //Mgo.InitPool()
  104. // 线上163
  105. Mgo := &mongodb.MongodbSim{
  106. MongodbAddr: "172.17.189.140:27080",
  107. //MongodbAddr: "127.0.0.1:27083",
  108. Size: 10,
  109. DbName: "qfw",
  110. UserName: "SJZY_RWbid_ES",
  111. Password: "SJZY@B4i4D5e6S",
  112. //Direct: true,
  113. }
  114. Mgo.InitPool()
  115. sess := Mgo.GetMgoConn()
  116. defer Mgo.DestoryMongoConn(sess)
  117. coll := "wcc_2023_winner_area_0608"
  118. query := sess.DB("qfw").C(coll).Find(nil).Select(nil).Iter()
  119. count := 0
  120. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  121. if count%10000 == 0 {
  122. log.Println("current ---", count, tmp["winner"])
  123. }
  124. data := map[string]interface{}{
  125. "buyer": tmp["winner"],
  126. }
  127. res := GetAreaInfo(data)
  128. if res != nil {
  129. update := map[string]interface{}{
  130. "winner_province": res["area"],
  131. "winner_city": res["city"],
  132. "winner_district": res["district"],
  133. }
  134. Mgo.UpdateById(coll, tmp["_id"], map[string]interface{}{"$set": update})
  135. }
  136. }
  137. }
  138. // statisticWinner 统计中标单位区域分布
  139. func statisticWinner() {
  140. //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"}
  141. f, err := excelize.OpenFile("./中标项目区域分布.xlsx")
  142. if err != nil {
  143. fmt.Println(err)
  144. return
  145. }
  146. defer func() {
  147. if err := f.Close(); err != nil {
  148. fmt.Println(err)
  149. }
  150. }()
  151. rows, err := f.GetRows("2019")
  152. if err != nil {
  153. fmt.Println(err)
  154. return
  155. }
  156. cells, _ := f.GetCols("2019")
  157. //log.Println(rows, cells)
  158. // 线上163
  159. Mgo := &mongodb.MongodbSim{
  160. //MongodbAddr: "172.17.189.140:27080",
  161. MongodbAddr: "127.0.0.1:27083",
  162. Size: 10,
  163. DbName: "qfw",
  164. UserName: "SJZY_RWbid_ES",
  165. Password: "SJZY@B4i4D5e6S",
  166. Direct: true,
  167. }
  168. Mgo.InitPool()
  169. coll := "wcc_2019_winner_area_0608"
  170. for i := 1; i < len(rows); i++ {
  171. rowData := make([]interface{}, 0)
  172. area1 := strings.Replace(rows[i][0], " ", "", -1)
  173. for j := 1; j < len(cells); j++ {
  174. area2 := strings.Replace(cells[j][0], " ", "", -1)
  175. where := make(map[string]interface{})
  176. if i < 18 {
  177. if area1 == "北京市" {
  178. where["city"] = "北京市"
  179. } else {
  180. where["city"] = "北京市"
  181. where["district"] = area1
  182. }
  183. } else if i < 35 {
  184. if area1 == "天津市" {
  185. where["city"] = "天津市"
  186. } else {
  187. where["city"] = "天津市"
  188. where["district"] = area1
  189. }
  190. } else {
  191. if area1 == "河北省" {
  192. where["area"] = "河北"
  193. } else {
  194. where["area"] = "河北"
  195. where["city"] = area1
  196. }
  197. }
  198. if j < 18 {
  199. if area2 == "北京市" {
  200. where["winner_city"] = "北京市"
  201. } else {
  202. where["winner_city"] = "北京市"
  203. where["winner_district"] = area2
  204. }
  205. } else if j < 35 {
  206. if area2 == "天津市" {
  207. where["winner_city"] = "天津市"
  208. } else {
  209. where["winner_city"] = "天津市"
  210. where["winner_district"] = area2
  211. }
  212. } else {
  213. if area2 == "河北省" {
  214. where["winner_province"] = "河北"
  215. } else {
  216. where["winner_province"] = "河北"
  217. where["winner_city"] = area2
  218. }
  219. }
  220. num := Mgo.Count(coll, where)
  221. log.Println("iiiiiii", i, area1, ",jjjjjjjj", j, area2, num)
  222. rowData = append(rowData, num)
  223. }
  224. //_ = xlsx.SetSheetRow(sheet, fmt.Sprintf("%s%d", "C", line), &subtitles)
  225. f.SetSheetRow("2019", fmt.Sprintf("%s%d", "B", i+1), &rowData)
  226. }
  227. f.Save()
  228. }