bidding.go 11 KB

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