bidding.go 11 KB

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