bidding.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. package main
  2. import (
  3. "data_tidb/config"
  4. "fmt"
  5. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  6. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  7. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  8. "reflect"
  9. "regexp"
  10. "sort"
  11. "strings"
  12. "sync"
  13. "time"
  14. )
  15. var (
  16. regLetter = regexp.MustCompile("[a-z]*")
  17. )
  18. func TaskBidding() {
  19. sess := MongoB.GetMgoConn()
  20. defer MongoB.DestoryMongoConn(sess)
  21. ch := make(chan bool, 10)
  22. wg := &sync.WaitGroup{}
  23. q := map[string]interface{}{
  24. "_id": map[string]interface{}{
  25. "$gt": mongodb.StringTOBsonId("6558df800000000000000000"),
  26. "$lte": mongodb.StringTOBsonId("655a31000000000000000000"),
  27. },
  28. }
  29. query := sess.DB(config.Conf.DB.MongoB.Dbname).C("bidding").Find(q).Sort("_id").Iter()
  30. count := 0
  31. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  32. if count%10000 == 0 {
  33. log.Info(fmt.Sprintf("current --- %d", count))
  34. }
  35. ch <- true
  36. wg.Add(1)
  37. go func(tmp map[string]interface{}) {
  38. defer func() {
  39. <-ch
  40. wg.Done()
  41. }()
  42. if util.IntAll(tmp["extracttype"]) != -1 {
  43. taskBase(tmp) //基础标讯数据
  44. taskExpand(tmp) //扩展数据
  45. //taskDetail(tmp) //正文信息
  46. //taskAtts(tmp) //附件信息
  47. //taskIntent(tmp) //采购意向
  48. //taskPackage(tmp) //分包
  49. }
  50. }(tmp)
  51. tmp = make(map[string]interface{})
  52. }
  53. wg.Wait()
  54. log.Info(fmt.Sprintf("is over --- %d", count))
  55. }
  56. func taskBase(tmp map[string]interface{}) {
  57. tmpid := mongodb.BsonIdToSId(tmp["_id"])
  58. info := map[string]interface{}{}
  59. info["s_info_id"] = tmpid
  60. area, city, district := util.ObjToString(tmp["area"]), util.ObjToString(tmp["city"]), util.ObjToString(tmp["district"])
  61. if area != "" {
  62. info["area_code"] = AreaCode[area]
  63. if city != "" {
  64. info["city_code"] = AreaCode[area+","+city]
  65. if district != "" {
  66. info["district_code"] = AreaCode[area+","+city+","+district]
  67. }
  68. }
  69. }
  70. if toptype := util.ObjToString(tmp["toptype"]); toptype != "" {
  71. info["s_toptype_code"] = TopTypeCode["toptype"]
  72. }
  73. if subtype := util.ObjToString(tmp["subtype"]); subtype != "" {
  74. info["s_subtype_code"] = SubTypeCode[subtype]
  75. }
  76. if buyerclass := util.ObjToString(tmp["buyerclass"]); buyerclass != "" {
  77. info["s_buyerclass_code"] = BuyerCode[buyerclass]
  78. }
  79. //特别结构
  80. info["i_isValidFile"] = util.IntAll(tmp["isValidFile"])
  81. info["i_multipackage"] = util.IntAll(tmp["multipackage"])
  82. //文本相关
  83. transferTextInfo(tmp, &info, []string{"title", "projectname", "projectcode", "purchasing", "site", "href"}, []int{})
  84. //金额相关
  85. transferMoneyRateInfo(tmp, &info, []string{"budget", "bidamount", "biddiscount"}, []float64{1000000000.0, 1000000000.0, 100.0})
  86. //时间相关
  87. transferDateTimeInfo(tmp, &info, []string{"comeintime", "publishtime", "bidopentime", "bidendtime"})
  88. //主体相关
  89. if code := getNameId(util.ObjToString(tmp["buyer"])); code != "" {
  90. info["s_buyer_id"] = code
  91. }
  92. if code := getNameId(util.ObjToString(tmp["agency"])); code != "" {
  93. info["s_agency_id"] = code
  94. }
  95. info["d_updatetime"] = time.Now().Format(util.Date_Full_Layout)
  96. info["d_createtime"] = time.Now().Format(util.Date_Full_Layout)
  97. InsertGlobalMysqlData("dwd_f_bid_baseinfo", info, mongodb.BsonIdToSId(tmp["_id"]))
  98. }
  99. func getNameId(name string) string {
  100. if name == "" {
  101. return ""
  102. }
  103. info := MysqlTool.FindOne("dws_f_ent_baseinfo", map[string]interface{}{"name": name}, "name_id", "")
  104. if info != nil && (*info)["name_id"] != nil {
  105. return util.ObjToString((*info)["name_id"])
  106. } else {
  107. return ""
  108. }
  109. }
  110. func taskExpand(tmp map[string]interface{}) {
  111. tmpid := mongodb.BsonIdToSId(tmp["_id"])
  112. info := map[string]interface{}{}
  113. info["s_info_id"] = tmpid
  114. //文本相关
  115. transferTextInfo(tmp, &info, []string{"projectperiod", "project_scale", "project_timeunit", "bidmethod", "getdocmethod", "currency", "funds", "payway", "bid_bond", "contract_bond", "contractcode", "buyerzipcode", "bidopenaddress", "buyeraddr", "agencyaddr", "projectaddr", "enterprise_qualification", "personnel_qualification", "performance_qualification", "enterprise_credit"}, []int{1000, 5000, 50, 255, 500, 20, 5000, 500, 1000, 500, 100, 100, 1000, 1000, 1000, 1000, 20000, 20000, 20000, 20000})
  116. //时间相关
  117. transferDateTimeInfo(tmp, &info, []string{"project_startdate", "project_completedate", "signstarttime", "bidendtime", "bidstarttime", "docstarttime", "docendtime", "signaturedate", "signendtime"})
  118. //布尔相关
  119. transferBoolInfo(tmp, &info, []string{"bid_guarantee", "contract_guarantee"})
  120. //金额相关
  121. transferMoneyRateInfo(tmp, &info, []string{"docamount", "agencyfee", "agencyrate"}, []float64{10000000.0, 10000000.0, 10000000.0})
  122. //投标方式
  123. bidway := util.ObjToString(tmp["bidway"])
  124. if bidway == "电子投标" {
  125. info["i_bidway"] = 1
  126. } else if bidway == "纸质投标" {
  127. info["i_bidway"] = 0
  128. } else {
  129. }
  130. //评审专家
  131. if tmp["review_experts"] != nil {
  132. if reflect.TypeOf(tmp["review_experts"]).String() == "string" {
  133. info["s_review_experts"] = tmp["review_experts"]
  134. } else if reflect.TypeOf(tmp["review_experts"]).String() == "[]interface {}" {
  135. if arr, ok := tmp["review_experts"].([]interface{}); ok {
  136. info["s_review_experts"] = strings.Join(util.ObjArrToStringArr(arr), ",")
  137. }
  138. }
  139. }
  140. //工期时长
  141. if tmp["project_duration"] != nil {
  142. info["i_project_duration"] = util.IntAll(tmp["project_duration"])
  143. }
  144. info["d_updatetime"] = time.Now().Format(util.Date_Full_Layout)
  145. info["d_createtime"] = time.Now().Format(util.Date_Full_Layout)
  146. InsertGlobalMysqlData("dwd_f_bid_expand_baseinfo", info, tmpid)
  147. }
  148. func taskDetail(tmp map[string]interface{}) {
  149. tmpid := mongodb.BsonIdToSId(tmp["_id"])
  150. s_detail := util.ObjToString(tmp["detail"])
  151. s_contenthtml := util.ObjToString(tmp["contenthtml"])
  152. info := map[string]interface{}{
  153. "s_info_id": tmpid,
  154. "s_detail": s_detail,
  155. "s_contenthtml": s_contenthtml,
  156. "d_createtime": time.Now().Format(util.Date_Full_Layout),
  157. "d_updatetime": time.Now().Format(util.Date_Full_Layout),
  158. }
  159. InsertGlobalMysqlData("dwd_f_bid_detail", info, tmpid)
  160. }
  161. func taskAtts(tmp map[string]interface{}) {
  162. tmpid := mongodb.BsonIdToSId(tmp["_id"])
  163. f_baseInfo := map[string]interface{}{}
  164. attach_text := util.ObjToMap(tmp["attach_text"])
  165. if projectinfo := util.ObjToMap(tmp["projectinfo"]); projectinfo != nil {
  166. attachments := util.ObjToMap((*projectinfo)["attachments"])
  167. for index, attr := range *attachments {
  168. if at, ok := attr.(map[string]interface{}); ok {
  169. if util.ObjToString(at["fid"]) != "" {
  170. //ftype := ""
  171. //for _, s := range FileTypeArr {
  172. // ft := strings.ToLower(util.ObjToString(tmp["ftype"]))
  173. // if strings.Contains(ft, s) {
  174. // ftype = s
  175. // break
  176. // }
  177. //}
  178. f_baseInfo["s_info_id"] = tmpid
  179. f_baseInfo["s_file_name"] = util.ObjToString(at["filename"])
  180. f_baseInfo["s_file_url"] = util.ObjToString(at["org_url"])
  181. f_baseInfo["s_file_size"] = util.ObjToString(at["size"])
  182. f_baseInfo["s_file_suffix"] = util.ObjToString(at["ftype"])
  183. f_baseInfo["s_file_oss_url"] = util.ObjToString(at["fid"])
  184. f_baseInfo["d_createtime"] = time.Now().Format(util.Date_Full_Layout)
  185. f_id := InsertGlobalMysqlData("dwd_f_bid_file_baseinfo", f_baseInfo, tmpid)
  186. if f_id > 0 && util.IntAll(index) > 0 && attach_text != nil {
  187. att_key := fmt.Sprintf("%d", util.IntAll(index)-1)
  188. if att_info := util.ObjToMap((*attach_text)[att_key]); att_info != nil {
  189. taskAttsAttach(*att_info, tmpid, f_id)
  190. }
  191. }
  192. }
  193. }
  194. }
  195. }
  196. }
  197. func taskAttsAttach(att_info map[string]interface{}, tmpid string, f_id int64) {
  198. for _, v := range att_info {
  199. if att, b := v.(map[string]interface{}); b {
  200. info := map[string]interface{}{}
  201. info["s_info_id"] = tmpid
  202. info["s_file_id"] = f_id
  203. info["d_createtime"] = time.Now().Format(util.Date_Full_Layout)
  204. attach_url := util.ObjToString(att["attach_url"])
  205. if attach_url != "" {
  206. //bs := OssGetObject(attach_url)
  207. //if utf8.RuneCountInString(bs) > 100000 {
  208. // bs = string(([]rune(bs))[:100000])
  209. //}
  210. //info["s_file_text"] = bs
  211. }
  212. InsertGlobalMysqlData("dwd_f_bid_file_text", info, tmpid)
  213. }
  214. }
  215. }
  216. func taskIntent(tmp map[string]interface{}) {
  217. procurementlist := IsMarkInterfaceMap(tmp["procurementlist"])
  218. tmpid := mongodb.BsonIdToSId(tmp["_id"])
  219. for _, p1 := range procurementlist {
  220. info := map[string]interface{}{}
  221. info["s_info_id"] = tmpid
  222. if p1["itemname"] != nil {
  223. info["s_intention_name"] = p1["itemname"]
  224. }
  225. if p1["projectscope"] != nil {
  226. info["s_intention_demand"] = p1["projectscope"]
  227. }
  228. if p1["item"] != nil {
  229. info["s_item"] = p1["item"]
  230. }
  231. if p1["totalprice"] != nil {
  232. info["f_totalprice"] = p1["totalprice"]
  233. }
  234. if p1["expurasingtime"] != nil {
  235. info["s_expurasingtime"] = p1["expurasingtime"]
  236. }
  237. if p1["reserved_amount"] != nil {
  238. info["s_reserved_amount"] = p1["reserved_amount"]
  239. }
  240. if b := util.ObjToString(tmp["buyer"]); b != "" {
  241. if code := getNameId(b); code != "" {
  242. info["s_buyer_id"] = code
  243. }
  244. }
  245. info["d_createtime"] = time.Now().Format(util.Date_Full_Layout)
  246. InsertGlobalMysqlData("dwd_f_bid_intention_baseinfo", info, tmpid)
  247. }
  248. }
  249. func taskPackage(tmp map[string]interface{}) {
  250. tmpid := mongodb.BsonIdToSId(tmp["_id"])
  251. //筛选分包
  252. packages := filterPackageInfos(tmp)
  253. if len(packages) <= 1 { //单包···标讯本身
  254. baseInfo := CPBaseInfoFromBidding(tmp, tmpid)
  255. pid := InsertGlobalMysqlData("dwd_f_bid_package_baseinfo", baseInfo, tmpid)
  256. if pid > 0 {
  257. //投标人信息
  258. CPBidderBiddingBaseInfo(tmp, tmpid, pid)
  259. //标的物信息
  260. new_purlist := CPBiddingPackageGoodsBaseInfo(tmp, tmpid, pid)
  261. for _, v := range new_purlist {
  262. InsertGlobalMysqlData("dwd_f_bid_package_goods_baseinfo", v, tmpid)
  263. }
  264. }
  265. } else { //多包...具体源信息
  266. for k, v := range packages {
  267. baseInfo := CPBaseInfoFromPackage(v, tmpid)
  268. pid := InsertGlobalMysqlData("dwd_f_bid_package_baseinfo", baseInfo, tmpid)
  269. if pid > 0 { //投标人信息
  270. if k == 0 { //标的物信息
  271. CPBidderPackageBaseInfo(v, tmp, tmpid, pid, true)
  272. new_purlist := CPBiddingPackageGoodsBaseInfo(tmp, tmpid, pid)
  273. for _, v1 := range new_purlist {
  274. InsertGlobalMysqlData("dwd_f_bid_package_goods_baseinfo", v1, tmpid)
  275. }
  276. } else {
  277. CPBidderPackageBaseInfo(v, tmp, tmpid, pid, false)
  278. }
  279. }
  280. }
  281. }
  282. }
  283. func BinarySearch(s []string, k string) int {
  284. sort.Strings(s)
  285. lo, hi := 0, len(s)-1
  286. for lo <= hi {
  287. m := (lo + hi) >> 1
  288. if s[m] < k {
  289. lo = m + 1
  290. } else if s[m] > k {
  291. hi = m - 1
  292. } else {
  293. return m
  294. }
  295. }
  296. return -1
  297. }