bidding.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. package main
  2. import (
  3. "data_tidb/config"
  4. "fmt"
  5. "github.com/shopspring/decimal"
  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. "regexp"
  11. "sort"
  12. "strconv"
  13. "strings"
  14. "sync"
  15. "time"
  16. )
  17. var (
  18. regLetter = regexp.MustCompile("[a-z]*")
  19. )
  20. func TaskBidding() {
  21. sess := MongoB.GetMgoConn()
  22. defer MongoB.DestoryMongoConn(sess)
  23. ch := make(chan bool, 10)
  24. wg := &sync.WaitGroup{}
  25. q := map[string]interface{}{
  26. "_id": map[string]interface{}{
  27. "$gt": mongodb.StringTOBsonId("100000000000000000000000"),
  28. "$lte": mongodb.StringTOBsonId("900000000000000000000000"),
  29. },
  30. }
  31. query := sess.DB(config.Conf.DB.MongoB.Dbname).C("bidding").Find(q).Sort("_id").Iter()
  32. count := 0
  33. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  34. if count%10000 == 0 {
  35. log.Info(fmt.Sprintf("current --- %d", count))
  36. }
  37. ch <- true
  38. wg.Add(1)
  39. go func(tmp map[string]interface{}) {
  40. defer func() {
  41. <-ch
  42. wg.Done()
  43. }()
  44. if util.IntAll(tmp["extracttype"]) != -1 {
  45. //taskBase(tmp) //基础标讯数据
  46. //taskExpand(tmp) //扩展数据
  47. //taskDetail(tmp) //正文信息
  48. //taskAtts(tmp) //附件信息
  49. //taskIntent(tmp) //采购意向
  50. //taskPackage(tmp) //分包
  51. }
  52. }(tmp)
  53. tmp = make(map[string]interface{})
  54. }
  55. wg.Wait()
  56. log.Info(fmt.Sprintf("is over --- %d", count))
  57. }
  58. // @Description 基本信息
  59. func taskBase(tmp map[string]interface{}) {
  60. saveM := make(map[string]interface{})
  61. var errf []string // 异常字段
  62. for _, nf := range BaseField {
  63. f := nf[2:]
  64. if f == "info_id" {
  65. saveM[nf] = mongodb.BsonIdToSId(tmp["_id"])
  66. } else if f == "area_code" {
  67. if tmp["area"] != nil {
  68. saveM[nf] = AreaCode[util.ObjToString(tmp["area"])]
  69. }
  70. } else if f == "city_code" {
  71. if tmp["area"] != nil && tmp["city"] != nil {
  72. c := util.ObjToString(tmp["area"]) + "," + util.ObjToString(tmp["city"])
  73. saveM[nf] = AreaCode[c]
  74. }
  75. } else if f == "district_code" {
  76. if tmp["area"] != nil && tmp["city"] != nil && tmp["district"] != nil {
  77. c := util.ObjToString(tmp["area"]) + "," + util.ObjToString(tmp["city"]) + "," + util.ObjToString(tmp["district"])
  78. saveM[nf] = AreaCode[c]
  79. }
  80. } else if f == "toptype_code" {
  81. if obj := util.ObjToString(tmp["toptype"]); obj != "" {
  82. saveM[nf] = TopTypeCode[obj]
  83. }
  84. } else if f == "subtype_code" {
  85. if obj := util.ObjToString(tmp["subtype"]); obj != "" {
  86. saveM[nf] = SubTypeCode[obj]
  87. }
  88. } else if f == "buyerclass_code" {
  89. if obj := util.ObjToString(tmp["buyerclass"]); obj != "" {
  90. saveM[nf] = BuyerCode[obj]
  91. }
  92. } else if f == "createtime" || f == "updatetime" {
  93. saveM[nf] = time.Now().Format(util.Date_Full_Layout)
  94. } else if f == "comeintime" || f == "publishtime" || f == "bidopentime" || f == "bidendtime" {
  95. if tmp[f] != nil && util.IntAll(tmp[f]) > 0 {
  96. t := util.Int64All(tmp[f])
  97. saveM[nf] = util.FormatDateByInt64(&t, util.Date_Full_Layout)
  98. }
  99. } else if f == "multipackage" || f == "isValidFile" {
  100. if tmp[f] == nil {
  101. saveM[nf] = 0
  102. } else {
  103. saveM[nf] = tmp[f]
  104. }
  105. } else if f == "buyer_id" {
  106. if b := util.ObjToString(tmp["buyer"]); b != "" {
  107. if code := getNameId(b); code != "" {
  108. saveM[nf] = code
  109. }
  110. }
  111. } else if f == "agency_id" {
  112. if b := util.ObjToString(tmp["agency"]); b != "" {
  113. if code := getNameId(b); code != "" {
  114. saveM[nf] = code
  115. }
  116. }
  117. } else {
  118. if tmp[f] != nil {
  119. if BaseVMap[f] != nil {
  120. var b bool
  121. saveM[nf], b = verifyF(f, tmp[f], BaseVMap[f])
  122. if b { // 保存异常字段数据
  123. errf = append(errf, f)
  124. }
  125. } else {
  126. saveM[nf] = tmp[f]
  127. }
  128. }
  129. }
  130. }
  131. saveBasePool <- saveM
  132. if len(errf) > 0 {
  133. saveErrPool <- map[string]interface{}{"infoid": mongodb.BsonIdToSId(tmp["_id"]), "f": strings.Join(errf, ",")}
  134. }
  135. }
  136. func getNameId(name string) string {
  137. info := MysqlTool.FindOne("dws_f_ent_baseinfo", map[string]interface{}{"name": name}, "name_id", "")
  138. if info != nil && (*info)["name_id"] != nil {
  139. return util.ObjToString((*info)["name_id"])
  140. } else {
  141. return ""
  142. }
  143. }
  144. // @Description 扩展信息
  145. func taskExpand(tmp map[string]interface{}) {
  146. saveM := make(map[string]interface{})
  147. var errf []string // 异常字段
  148. for _, nf := range ExpandField {
  149. f := nf[2:]
  150. if f == "info_id" {
  151. saveM[nf] = mongodb.BsonIdToSId(tmp["_id"])
  152. } else if f == "project_startdate" || f == "project_completedate" || f == "signstarttime" || f == "bidendtime" || f == "bidstarttime" || f == "docstarttime" ||
  153. f == "docendtime" || f == "signaturedate" || f == "signendtime" {
  154. if tmp[f] != nil && util.IntAll(tmp[f]) > 0 {
  155. t := util.Int64All(tmp[f])
  156. saveM[nf] = util.FormatDateByInt64(&t, util.Date_Full_Layout)
  157. }
  158. } else if f == "createtime" || f == "updatetime" {
  159. saveM[nf] = time.Now().Format(util.Date_Full_Layout)
  160. } else if f == "bidway" {
  161. if util.ObjToString(tmp[f]) == "电子投标" {
  162. saveM[nf] = 1
  163. } else if util.ObjToString(tmp[f]) == "纸质投标" {
  164. saveM[nf] = 0
  165. }
  166. } else if f == "review_experts" { //评标专家
  167. if tmp[f] != nil {
  168. if reflect.TypeOf(tmp[f]).String() == "string" {
  169. saveM[nf] = tmp[f]
  170. } else if reflect.TypeOf(tmp[f]).String() == "[]interface {}" {
  171. if arr, ok := tmp[f].([]interface{}); ok {
  172. saveM[nf] = strings.Join(util.ObjArrToStringArr(arr), ",")
  173. }
  174. }
  175. }
  176. } else if f == "bid_guarantee" || f == "contract_guarantee" {
  177. if tmp[f] != nil {
  178. if tmp[f].(bool) {
  179. saveM[nf] = 1
  180. } else {
  181. saveM[nf] = 0
  182. }
  183. }
  184. } else if f == "agencyfee" {
  185. if tmp[f] != nil {
  186. if reflect.TypeOf(tmp[f]).String() == "string" {
  187. v2, err := strconv.ParseFloat(strings.ReplaceAll(util.ObjToString(tmp[f]), "%", ""), 64)
  188. if err != nil {
  189. v, _ := decimal.NewFromFloat(v2).Div(decimal.NewFromFloat(float64(100))).Float64()
  190. saveM[nf] = v
  191. }
  192. } else {
  193. saveM[nf], _ = util.FormatFloat(util.Float64All(tmp[f]), 4)
  194. }
  195. }
  196. } else if f == "project_duration" {
  197. if tmp[f] != nil {
  198. saveM[nf] = util.IntAll(tmp[f])
  199. }
  200. } else {
  201. if tmp[f] != nil {
  202. if ExpandVMap[f] != nil {
  203. var b bool
  204. saveM[nf], b = verifyF(f, tmp[f], ExpandVMap[f])
  205. if b { // 保存异常字段数据
  206. errf = append(errf, f)
  207. }
  208. } else {
  209. saveM[nf] = tmp[f]
  210. }
  211. }
  212. }
  213. }
  214. saveExpandPool <- saveM
  215. if len(errf) > 0 {
  216. saveErrPool <- map[string]interface{}{"infoid": mongodb.BsonIdToSId(tmp["_id"]), "f": strings.Join(errf, ",")}
  217. }
  218. }
  219. // @Description 正文信息
  220. func taskDetail(tmp map[string]interface{}) {
  221. id := mongodb.BsonIdToSId(tmp["_id"])
  222. s_detail := util.ObjToString(tmp["detail"])
  223. s_contenthtml := util.ObjToString(tmp["contenthtml"])
  224. saveDetailPool <- map[string]interface{}{
  225. "s_info_id": id,
  226. "s_detail": s_detail,
  227. "s_contenthtml": s_contenthtml,
  228. "d_createtime": time.Now().Format(util.Date_Full_Layout),
  229. "d_updatetime": time.Now().Format(util.Date_Full_Layout),
  230. }
  231. }
  232. // @Description 附件
  233. func taskAtts(tmp map[string]interface{}) {
  234. tmpid := mongodb.BsonIdToSId(tmp["_id"])
  235. f_baseInfo := map[string]interface{}{}
  236. attach_text := util.ObjToMap(tmp["attach_text"])
  237. if projectinfo := util.ObjToMap(tmp["projectinfo"]); projectinfo != nil {
  238. attachments := util.ObjToMap((*projectinfo)["attachments"])
  239. for index, attr := range *attachments {
  240. if at, ok := attr.(map[string]interface{}); ok {
  241. if util.ObjToString(at["fid"]) != "" {
  242. //ftype := ""
  243. //for _, s := range FileTypeArr {
  244. // ft := strings.ToLower(util.ObjToString(tmp["ftype"]))
  245. // if strings.Contains(ft, s) {
  246. // ftype = s
  247. // break
  248. // }
  249. //}
  250. f_baseInfo["s_info_id"] = tmpid
  251. f_baseInfo["s_file_name"] = util.ObjToString(at["filename"])
  252. f_baseInfo["s_file_url"] = util.ObjToString(at["org_url"])
  253. f_baseInfo["s_file_size"] = util.ObjToString(at["size"])
  254. f_baseInfo["s_file_suffix"] = util.ObjToString(at["ftype"])
  255. f_baseInfo["s_file_oss_url"] = util.ObjToString(at["fid"])
  256. f_baseInfo["d_createtime"] = time.Now().Format(util.Date_Full_Layout)
  257. f_id := InsertGlobalMysqlData("dwd_f_bid_file_baseinfo", f_baseInfo, tmpid)
  258. if f_id > 0 && util.IntAll(index) > 0 && attach_text != nil {
  259. att_key := fmt.Sprintf("%d", util.IntAll(index)-1)
  260. if att_info := util.ObjToMap((*attach_text)[att_key]); att_info != nil {
  261. taskAttsAttach(*att_info, tmpid, f_id)
  262. }
  263. }
  264. }
  265. }
  266. }
  267. }
  268. }
  269. func taskAttsAttach(att_info map[string]interface{}, tmpid string, f_id int64) {
  270. for _, v := range att_info {
  271. if att, b := v.(map[string]interface{}); b {
  272. info := map[string]interface{}{}
  273. info["s_info_id"] = tmpid
  274. info["s_file_id"] = f_id
  275. info["d_createtime"] = time.Now().Format(util.Date_Full_Layout)
  276. attach_url := util.ObjToString(att["attach_url"])
  277. if attach_url != "" {
  278. //bs := OssGetObject(attach_url)
  279. //if utf8.RuneCountInString(bs) > 100000 {
  280. // bs = string(([]rune(bs))[:100000])
  281. //}
  282. //info["s_file_text"] = bs
  283. }
  284. saveAttrPool <- info
  285. }
  286. }
  287. }
  288. // @Description 采购意向
  289. func taskIntent(tmp map[string]interface{}) {
  290. procurementlist := IsMarkInterfaceMap(tmp["procurementlist"])
  291. tmpid := mongodb.BsonIdToSId(tmp["_id"])
  292. for _, p1 := range procurementlist {
  293. info := map[string]interface{}{}
  294. info["s_info_id"] = tmpid
  295. if p1["itemname"] != nil {
  296. info["s_intention_name"] = p1["itemname"]
  297. }
  298. if p1["projectscope"] != nil {
  299. info["s_intention_demand"] = p1["projectscope"]
  300. }
  301. if p1["item"] != nil {
  302. info["s_item"] = p1["item"]
  303. }
  304. if p1["totalprice"] != nil {
  305. info["f_totalprice"] = p1["totalprice"]
  306. }
  307. if p1["expurasingtime"] != nil {
  308. info["s_expurasingtime"] = p1["expurasingtime"]
  309. }
  310. if p1["reserved_amount"] != nil {
  311. info["s_reserved_amount"] = p1["reserved_amount"]
  312. }
  313. if b := util.ObjToString(tmp["buyer"]); b != "" {
  314. if code := getNameId(b); code != "" {
  315. info["s_buyer_id"] = code
  316. }
  317. }
  318. info["d_createtime"] = time.Now().Format(util.Date_Full_Layout)
  319. //InsertGlobalMysqlData("dwd_f_bid_intention_baseinfo", info, tmpid)
  320. saveIntentPool <- info
  321. }
  322. }
  323. // @Description 分包基本信息
  324. func taskPackage(tmp map[string]interface{}) {
  325. tmpid := mongodb.BsonIdToSId(tmp["_id"])
  326. //筛选分包
  327. packages := filterPackageInfos(tmp)
  328. if len(packages) <= 1 { //单包···标讯本身
  329. baseInfo := CPBaseInfoFromBidding(tmp, tmpid)
  330. pid := InsertGlobalMysqlData("dwd_f_bid_package_baseinfo", baseInfo, tmpid)
  331. if pid > 0 {
  332. //投标人信息
  333. CPBidderBiddingBaseInfo(tmp, tmpid, pid)
  334. //标的物信息
  335. new_purlist := CPBiddingPackageGoodsBaseInfo(tmp, tmpid, pid)
  336. for _, v := range new_purlist {
  337. saveGoodsPool <- v
  338. }
  339. }
  340. } else { //多包...具体源信息
  341. for k, v := range packages {
  342. baseInfo := CPBaseInfoFromPackage(v, tmpid)
  343. pid := InsertGlobalMysqlData("dwd_f_bid_package_baseinfo", baseInfo, tmpid)
  344. if pid > 0 { //投标人信息
  345. if k == 0 { //标的物信息
  346. CPBidderPackageBaseInfo(v, tmp, tmpid, pid, true)
  347. new_purlist := CPBiddingPackageGoodsBaseInfo(tmp, tmpid, pid)
  348. for _, v1 := range new_purlist {
  349. saveGoodsPool <- v1
  350. }
  351. } else {
  352. CPBidderPackageBaseInfo(v, tmp, tmpid, pid, false)
  353. }
  354. }
  355. }
  356. }
  357. }
  358. func BinarySearch(s []string, k string) int {
  359. sort.Strings(s)
  360. lo, hi := 0, len(s)-1
  361. for lo <= hi {
  362. m := (lo + hi) >> 1
  363. if s[m] < k {
  364. lo = m + 1
  365. } else if s[m] > k {
  366. hi = m - 1
  367. } else {
  368. return m
  369. }
  370. }
  371. return -1
  372. }