bidding.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. package main
  2. import (
  3. util "app.yhyue.com/data_processing/common_utils"
  4. "app.yhyue.com/data_processing/common_utils/log"
  5. "app.yhyue.com/data_processing/common_utils/mongodb"
  6. "app.yhyue.com/data_processing/common_utils/redis"
  7. "data_tidb/config"
  8. "fmt"
  9. "github.com/shopspring/decimal"
  10. "reflect"
  11. "regexp"
  12. "sort"
  13. "strconv"
  14. "strings"
  15. "sync"
  16. "time"
  17. )
  18. var (
  19. regLetter = regexp.MustCompile("[a-z]*")
  20. )
  21. func doBiddingTask(gtid, lteid string, mapInfo map[string]interface{}) {
  22. sess := MongoB.GetMgoConn()
  23. defer MongoB.DestoryMongoConn(sess)
  24. ch := make(chan bool, 10)
  25. wg := &sync.WaitGroup{}
  26. stype := util.ObjToString(mapInfo["stype"])
  27. q := map[string]interface{}{"_id": map[string]interface{}{"$gt": mongodb.StringTOBsonId(gtid),
  28. "$lte": mongodb.StringTOBsonId(lteid)}}
  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%1000 == 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["dataprocess"]) != 8 {
  43. return
  44. }
  45. if stype == "bidding_history" && tmp["history_updatetime"] == nil {
  46. return
  47. }
  48. taskBase(tmp)
  49. taskTags(tmp)
  50. //taskExpand(tmp)
  51. //taskAtts(tmp)
  52. //taskInfoformat(tmp)
  53. //taskIntent(tmp)
  54. //taskWinner(tmp)
  55. //taskPackage(tmp)
  56. //taskPur(tmp)
  57. }(tmp)
  58. tmp = make(map[string]interface{})
  59. }
  60. wg.Wait()
  61. log.Info(fmt.Sprintf("over --- %d", count))
  62. }
  63. func taskB() {
  64. sess := MongoB.GetMgoConn()
  65. defer MongoB.DestoryMongoConn(sess)
  66. ch := make(chan bool, 10)
  67. wg := &sync.WaitGroup{}
  68. q := map[string]interface{}{"_id": mongodb.StringTOBsonId("634eac71911e1eb345b2d861")}
  69. //q := map[string]interface{}{"_id": map[string]interface{}{"$gt": mongodb.StringTOBsonId("6347dc8a911e1eb345aa7fcf"),
  70. // "$lte": mongodb.StringTOBsonId("634e93d6631ff1ac3de1cf18")}}
  71. query := sess.DB(config.Conf.DB.MongoB.Dbname).C("bidding").Find(q).Sort("_id").Iter()
  72. count := 0
  73. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  74. if count%20000 == 0 {
  75. log.Info(fmt.Sprintf("current --- %d", count))
  76. }
  77. ch <- true
  78. wg.Add(1)
  79. go func(tmp map[string]interface{}) {
  80. defer func() {
  81. <-ch
  82. wg.Done()
  83. }()
  84. if util.IntAll(tmp["extracttype"]) != -1 {
  85. taskBase(tmp)
  86. taskTags(tmp)
  87. //taskExpand(tmp)
  88. //taskAtts(tmp)
  89. //taskInfoformat(tmp)
  90. //taskIntent(tmp)
  91. //taskWinner(tmp)
  92. //taskPackage(tmp)
  93. //taskPur(tmp)
  94. }
  95. }(tmp)
  96. tmp = make(map[string]interface{})
  97. }
  98. wg.Wait()
  99. log.Info(fmt.Sprintf("over --- %d", count))
  100. }
  101. // @Description 基本信息
  102. // @Author J 2022/9/22 11:12
  103. func taskBase(tmp map[string]interface{}) {
  104. saveM := make(map[string]interface{})
  105. var errf []string // 异常字段
  106. for _, f := range BaseField {
  107. if f == "infoid" {
  108. saveM[f] = mongodb.BsonIdToSId(tmp["_id"])
  109. } else if f == "area_code" {
  110. if tmp["area"] != nil {
  111. saveM[f] = AreaCode[util.ObjToString(tmp["area"])]
  112. }
  113. } else if f == "city_code" {
  114. if tmp["area"] != nil && tmp["city"] != nil {
  115. c := util.ObjToString(tmp["area"]) + "," + util.ObjToString(tmp["city"])
  116. saveM[f] = AreaCode[c]
  117. }
  118. } else if f == "district_code" {
  119. if tmp["area"] != nil && tmp["city"] != nil && tmp["district"] != nil {
  120. c := util.ObjToString(tmp["area"]) + "," + util.ObjToString(tmp["city"]) + "," + util.ObjToString(tmp["district"])
  121. saveM[f] = AreaCode[c]
  122. }
  123. } else if f == "toptype_code" {
  124. if obj := util.ObjToString(tmp["toptype"]); obj != "" {
  125. saveM[f] = TopTypeCode[obj]
  126. }
  127. } else if f == "subtype_code" {
  128. if obj := util.ObjToString(tmp["subtype"]); obj != "" {
  129. saveM[f] = SubTypeCode[obj]
  130. }
  131. } else if f == "buyerclass_code" {
  132. if obj := util.ObjToString(tmp["buyerclass"]); obj != "" {
  133. saveM[f] = BuyerCode[obj]
  134. }
  135. } else if f == "createtime" || f == "updatetime" {
  136. saveM[f] = time.Now().Format(util.Date_Full_Layout)
  137. } else if f == "comeintime" || f == "publishtime" || f == "bidopentime" {
  138. if tmp[f] != nil && util.IntAll(tmp[f]) > 0 {
  139. t := util.Int64All(tmp[f])
  140. saveM[f] = util.FormatDateByInt64(&t, util.Date_Full_Layout)
  141. }
  142. } else if f == "multipackage" || f == "isValidFile" {
  143. if tmp[f] == nil {
  144. saveM[f] = 0
  145. } else {
  146. saveM[f] = tmp[f]
  147. }
  148. } else if f == "buyer_id" {
  149. if b := util.ObjToString(tmp["buyer"]); b != "" {
  150. util.Debug(b)
  151. saveM["buyer"] = b
  152. //if code := redis.GetStr("qyxy_id", b); code != "" {
  153. if code := getNameId(b); code != "" {
  154. saveM[f] = code
  155. }
  156. }
  157. } else if f == "agency_id" {
  158. if b := util.ObjToString(tmp["agency"]); b != "" {
  159. saveM["agency"] = b
  160. //if code := redis.GetStr("qyxy_id", b); code != "" {
  161. if code := getNameId(b); code != "" {
  162. saveM[f] = code
  163. }
  164. } else {
  165. if tmp[f] != nil {
  166. saveM[f] = tmp[f]
  167. }
  168. }
  169. } else {
  170. if tmp[f] != nil {
  171. if BaseVMap[f] != nil {
  172. var b bool
  173. saveM[f], b = verifyF(f, tmp[f], BaseVMap[f])
  174. // 保存异常字段数据
  175. if b {
  176. errf = append(errf, f)
  177. }
  178. } else {
  179. saveM[f] = tmp[f]
  180. }
  181. }
  182. }
  183. }
  184. util.Debug(saveM)
  185. saveBasePool <- saveM
  186. if len(errf) > 0 {
  187. saveErrPool <- map[string]interface{}{"infoid": mongodb.BsonIdToSId(tmp["_id"]), "f": strings.Join(errf, ",")}
  188. }
  189. }
  190. func getNameId(name string) string {
  191. info := MysqlTool.FindOne("dws_f_ent_baseinfo", map[string]interface{}{"name": name}, "name_id", "")
  192. if info != nil && (*info)["name_Id"] != nil {
  193. return util.ObjToString((*info)["name_Id"])
  194. } else {
  195. return ""
  196. }
  197. }
  198. // @Description 扩展信息
  199. // @Author J 2022/9/22 11:13
  200. func taskExpand(tmp map[string]interface{}) {
  201. saveM := make(map[string]interface{})
  202. var errf []string // 异常字段
  203. for _, f := range ExpandField {
  204. if f == "infoid" {
  205. saveM[f] = mongodb.BsonIdToSId(tmp["_id"])
  206. } else if f == "project_startdate" || f == "project_completedate" || f == "signaturedate" || f == "bidendtime" || f == "bidstarttime" {
  207. if tmp[f] != nil && util.IntAll(tmp[f]) > 0 {
  208. t := util.Int64All(tmp[f])
  209. saveM[f] = util.FormatDateByInt64(&t, util.Date_Full_Layout)
  210. }
  211. } else if f == "createtime" || f == "updatetime" {
  212. saveM[f] = time.Now().Format(util.Date_Full_Layout)
  213. } else if f == "bidway" {
  214. if util.ObjToString(tmp[f]) == "电子投标" {
  215. saveM[f] = 1
  216. } else if util.ObjToString(tmp[f]) == "纸质投标" {
  217. saveM[f] = 0
  218. }
  219. } else if f == "review_experts" {
  220. if tmp[f] != nil {
  221. if reflect.TypeOf(tmp[f]).String() == "string" {
  222. saveM[f] = tmp[f]
  223. } else if reflect.TypeOf(tmp[f]).String() == "[]interface {}" {
  224. if arr, ok := tmp[f].([]interface{}); ok {
  225. saveM[f] = strings.Join(util.ObjArrToStringArr(arr), ",")
  226. }
  227. }
  228. }
  229. } else if f == "bid_guarantee" || f == "contract_guarantee" {
  230. if tmp[f] != nil {
  231. if tmp[f].(bool) {
  232. saveM[f] = 1
  233. } else {
  234. saveM[f] = 0
  235. }
  236. }
  237. } else if f == "supervisorrate" || f == "agencyfee" {
  238. if tmp[f] != nil {
  239. if reflect.TypeOf(tmp[f]).String() == "string" {
  240. v2, err := strconv.ParseFloat(strings.ReplaceAll(util.ObjToString(tmp[f]), "%", ""), 64)
  241. if err != nil {
  242. v, _ := decimal.NewFromFloat(v2).Div(decimal.NewFromFloat(float64(100))).Float64()
  243. saveM[f] = v
  244. }
  245. } else {
  246. saveM[f], _ = util.FormatFloat(util.Float64All(tmp[f]), 4)
  247. }
  248. }
  249. } else if f == "project_duration" {
  250. if tmp[f] != nil {
  251. tmp[f] = util.IntAll(tmp[f])
  252. }
  253. } else {
  254. if tmp[f] != nil {
  255. if ExpandVMap[f] != nil {
  256. var b bool
  257. saveM[f], b = verifyF(f, tmp[f], ExpandVMap[f])
  258. // 保存异常字段数据
  259. if b {
  260. errf = append(errf, f)
  261. }
  262. } else {
  263. saveM[f] = tmp[f]
  264. }
  265. }
  266. }
  267. }
  268. saveExpandPool <- saveM
  269. if len(errf) > 0 {
  270. saveErrPool <- map[string]interface{}{"infoid": mongodb.BsonIdToSId(tmp["_id"]), "f": strings.Join(errf, ",")}
  271. }
  272. }
  273. // @Description 标签记录
  274. // @Author J 2022/9/22 11:13
  275. func taskTags(tmp map[string]interface{}) {
  276. id := mongodb.BsonIdToSId(tmp["_id"])
  277. if topArr, ok := tmp["topscopeclass"].([]interface{}); ok {
  278. for _, i2 := range topArr {
  279. tclass := regLetter.ReplaceAllString(util.ObjToString(i2), "") // 去除字母
  280. code := TopScopeCode[tclass]
  281. saveTagPool <- map[string]interface{}{"infoid": id, "labelcode": "1", "labelvalues": code, "labelweight": 1, "createtime": time.Now().Format(util.Date_Full_Layout)}
  282. //MysqlTool.Insert("bid_tags", map[string]interface{}{"infoid": id, "labelcode": "1", "labelvalues": code, "labelweight": 1, "createtime": time.Now().Format(util.Date_Full_Layout)})
  283. }
  284. }
  285. if subArr, ok := tmp["subscopeclass"].([]interface{}); ok {
  286. for _, i2 := range subArr {
  287. sc := strings.Split(util.ObjToString(i2), "_")
  288. if len(sc) > 1 {
  289. code := SubScopeCode[sc[1]]
  290. saveTagPool <- map[string]interface{}{"infoid": id, "labelcode": "2", "labelvalues": code, "labelweight": 1, "createtime": time.Now().Format(util.Date_Full_Layout)}
  291. }
  292. //MysqlTool.Insert("bid_tags", map[string]interface{}{"infoid": id, "labelcode": "2", "labelvalues": code, "labelweight": 1, "createtime": time.Now().Format(util.Date_Full_Layout)})
  293. }
  294. }
  295. if tArr, ok := tmp["certificate_class"].([]interface{}); ok {
  296. for _, i2 := range tArr {
  297. if util.ObjToString(i2) == "ISO" {
  298. saveTagPool <- map[string]interface{}{"infoid": id, "labelcode": "3", "labelvalues": "01", "labelweight": 1, "createtime": time.Now().Format(util.Date_Full_Layout)}
  299. //MysqlTool.Insert("bid_tags", map[string]interface{}{"infoid": id, "labelcode": "3", "labelvalues": "01", "labelweight": 1, "createtime": time.Now().Format(util.Date_Full_Layout)})
  300. } else if util.ObjToString(i2) == "AAA" {
  301. saveTagPool <- map[string]interface{}{"infoid": id, "labelcode": "3", "labelvalues": "02", "labelweight": 1, "createtime": time.Now().Format(util.Date_Full_Layout)}
  302. //MysqlTool.Insert("bid_tags", map[string]interface{}{"infoid": id, "labelcode": "3", "labelvalues": "02", "labelweight": 1, "createtime": time.Now().Format(util.Date_Full_Layout)})
  303. } else if util.ObjToString(i2) == "ISO,AAA" {
  304. saveTagPool <- map[string]interface{}{"infoid": id, "labelcode": "3", "labelvalues": "03", "labelweight": 1, "createtime": time.Now().Format(util.Date_Full_Layout)}
  305. //MysqlTool.Insert("bid_tags", map[string]interface{}{"infoid": id, "labelcode": "3", "labelvalues": "03", "labelweight": 1, "createtime": time.Now().Format(util.Date_Full_Layout)})
  306. }
  307. }
  308. }
  309. }
  310. // @Description 附件
  311. // @Author J 2022/9/22 11:13
  312. func taskAtts(tmp map[string]interface{}) {
  313. id := mongodb.BsonIdToSId(tmp["_id"])
  314. if tmp["projectinfo"] != nil {
  315. if pinfo, o := tmp["projectinfo"].(map[string]interface{}); o {
  316. if attsMap, ok := pinfo["attachments"].(map[string]interface{}); ok {
  317. for _, attr := range attsMap {
  318. if at, ok := attr.(map[string]interface{}); ok {
  319. if util.ObjToString(at["fid"]) != "" {
  320. ftype := ""
  321. for _, s := range FileTypeArr {
  322. ft := strings.ToLower(util.ObjToString(tmp["ftype"]))
  323. if strings.Contains(ft, s) {
  324. ftype = s
  325. break
  326. }
  327. }
  328. saveAttrPool <- map[string]interface{}{"infoid": id, "org_url": at["org_url"], "size": at["size"], "fid": at["fid"],
  329. "filename": at["filename"], "ftype": ftype, "file_type": 0, "createtime": time.Now().Format(util.Date_Full_Layout)}
  330. }
  331. }
  332. }
  333. }
  334. }
  335. }
  336. if attachTxt, o := tmp["attach_text"].(map[string]interface{}); o {
  337. if len(attachTxt) > 0 {
  338. for _, at := range attachTxt {
  339. at1 := at.(map[string]interface{})
  340. if len(at1) > 0 {
  341. for k, v := range at1 {
  342. if reflect.TypeOf(v).String() == "string" {
  343. if util.ObjToString(at1["attach_url"]) != "" {
  344. saveAttrPool <- map[string]interface{}{"infoid": id, "fid": at1["attach_url"], "filename": at1["file_name"], "file_type": 1, "createtime": time.Now().Format(util.Date_Full_Layout)}
  345. }
  346. break
  347. } else {
  348. if at2, ok := at1[k].(map[string]interface{}); ok {
  349. if util.ObjToString(at2["attach_url"]) != "" {
  350. saveAttrPool <- map[string]interface{}{"infoid": id, "fid": at2["attach_url"], "filename": at2["file_name"], "file_type": 1, "createtime": time.Now().Format(util.Date_Full_Layout)}
  351. }
  352. }
  353. }
  354. }
  355. }
  356. }
  357. }
  358. }
  359. }
  360. // @Description 拟建
  361. // @Author J 2022/9/22 15:56
  362. func taskInfoformat(tmp map[string]interface{}) {
  363. if util.IntAll(tmp["infoformat"]) != 2 && tmp["projectinfo"] != nil {
  364. return
  365. }
  366. if info, ok := tmp["projectinfo"].(map[string]interface{}); ok {
  367. delete(info, "attachments")
  368. if len(info) > 0 {
  369. saveM := make(map[string]interface{})
  370. for _, f := range IfmField {
  371. if f == "infoid" {
  372. saveM[f] = mongodb.BsonIdToSId(tmp["_id"])
  373. } else if f == "createtime" || f == "updatetime" {
  374. saveM[f] = time.Now().Format(util.Date_Full_Layout)
  375. } else if f == "approvetime" {
  376. if info[f] != nil && util.IntAll(tmp[f]) > 0 {
  377. saveM[f] = info[f]
  378. }
  379. } else {
  380. if info[f] != nil {
  381. saveM[f] = info[f]
  382. }
  383. }
  384. }
  385. saveIfmPool <- saveM
  386. }
  387. }
  388. }
  389. // @Description 采购意向
  390. // @Author J 2022/9/22 16:27
  391. func taskIntent(tmp map[string]interface{}) {
  392. if arr, ok := tmp["procurementlist"].([]interface{}); ok {
  393. for _, p := range arr {
  394. p1 := p.(map[string]interface{})
  395. saveM := make(map[string]interface{})
  396. for _, f := range IntentField {
  397. if f == "infoid" {
  398. saveM[f] = mongodb.BsonIdToSId(tmp["_id"])
  399. } else if f == "createtime" || f == "updatetime" {
  400. saveM[f] = time.Now().Format(util.Date_Full_Layout)
  401. } else if f == "buyer_id" {
  402. if b := util.ObjToString(tmp["buyer"]); b != "" {
  403. if code := redis.GetStr("qyxy_id", b); code != "" {
  404. saveM[f] = code
  405. }
  406. }
  407. } else {
  408. if p1[f] != nil {
  409. saveM[f] = p1[f]
  410. }
  411. }
  412. }
  413. saveIntentPool <- saveM
  414. }
  415. }
  416. }
  417. // @Description 中标单位
  418. // @Author J 2022/9/27 10:58
  419. func taskWinner(tmp map[string]interface{}) {
  420. if wod, ok := tmp["winnerorder"].([]interface{}); ok {
  421. for _, w := range wod {
  422. w1 := w.(map[string]interface{})
  423. if w1["sort"] != nil {
  424. saveM := make(map[string]interface{})
  425. for _, f := range WinnerField {
  426. if f == "infoid" {
  427. saveM[f] = mongodb.BsonIdToSId(tmp["_id"])
  428. } else if f == "createtime" || f == "updatetime" {
  429. saveM[f] = time.Now().Format(util.Date_Full_Layout)
  430. } else if f == "winnersort" {
  431. saveM[f] = util.IntAll(w1["sort"])
  432. } else if f == "winner_id" {
  433. if b := util.ObjToString(w1["entname"]); b != "" {
  434. saveM["winner"] = b
  435. if code := redis.GetStr("qyxy_id", b); code != "" {
  436. saveM[f] = code
  437. }
  438. }
  439. } else if f == "package_id" {
  440. }
  441. }
  442. saveWinnerPool <- saveM
  443. }
  444. }
  445. }
  446. warr := strings.Split(util.ObjToString(tmp["s_winner"]), ",")
  447. if BinarySearch(warr, util.ObjToString(tmp["winner"])) == -1 {
  448. warr = append(warr, util.ObjToString(tmp["winner"]))
  449. }
  450. for _, s := range warr {
  451. saveM := make(map[string]interface{})
  452. for _, f := range WinnerField {
  453. if f == "infoid" {
  454. saveM[f] = mongodb.BsonIdToSId(tmp["_id"])
  455. } else if f == "createtime" || f == "updatetime" {
  456. saveM[f] = time.Now().Format(util.Date_Full_Layout)
  457. } else if f == "winnersort" {
  458. saveM[f] = 0
  459. } else if f == "winner_id" {
  460. if s != "" {
  461. saveM["winner"] = s
  462. if code := redis.GetStr("qyxy_id", s); code != "" {
  463. saveM[f] = code
  464. }
  465. }
  466. }
  467. }
  468. saveWinnerPool <- saveM
  469. }
  470. }
  471. func BinarySearch(s []string, k string) int {
  472. sort.Strings(s)
  473. lo, hi := 0, len(s)-1
  474. for lo <= hi {
  475. m := (lo + hi) >> 1
  476. if s[m] < k {
  477. lo = m + 1
  478. } else if s[m] > k {
  479. hi = m - 1
  480. } else {
  481. return m
  482. }
  483. }
  484. return -1
  485. }
  486. func taskPackage(tmp map[string]interface{}) {
  487. }
  488. // @Description 标的物
  489. // @Author J 2022/9/29 16:48
  490. func taskPur(tmp map[string]interface{}) {
  491. if plist, ok := tmp["purchasinglist"].([]interface{}); ok {
  492. for _, p := range plist {
  493. saveM := make(map[string]interface{})
  494. p1 := p.(map[string]interface{})
  495. for _, f := range PurField {
  496. if f == "infoid" {
  497. saveM[f] = mongodb.BsonIdToSId(tmp["_id"])
  498. } else if f == "unitprice" || f == "totalprice" {
  499. if p1[f] != nil {
  500. if reflect.TypeOf(p1[f]).String() == "string" {
  501. } else {
  502. if util.Float64All(p1[f]) <= 10000000000 {
  503. saveM[f], _ = util.FormatFloat(util.Float64All(p1[f]), 4)
  504. }
  505. }
  506. }
  507. } else {
  508. if p1[f] != nil {
  509. if reflect.TypeOf(p1[f]).String() == "string" {
  510. if f == "item" || f == "itemname" || f == "brandname" {
  511. if len(util.ObjToString(p1[f])) <= 500 {
  512. saveM[f] = p1[f]
  513. }
  514. } else {
  515. saveM[f] = p1[f]
  516. }
  517. } else {
  518. saveM[f] = p1[f]
  519. }
  520. }
  521. }
  522. }
  523. savePurPool <- saveM
  524. }
  525. }
  526. }