task.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. package main
  2. import (
  3. "data_credible/config"
  4. "fmt"
  5. "go.mongodb.org/mongo-driver/bson"
  6. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  7. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  8. "strings"
  9. )
  10. func task1(tmp map[string]interface{}) {
  11. id := util.ObjToString(tmp["id"])
  12. save := make(map[string]interface{})
  13. if id == "" {
  14. id = mongodb.BsonIdToSId(tmp["_id"])
  15. }
  16. save["infoid"] = id
  17. save["data_tag"] = 2
  18. site := util.ObjToString(tmp["site"])
  19. save["site"] = site
  20. if SiteMap[site] != nil {
  21. s1 := strings.Split(util.ObjToString(SiteMap[site]), "-")
  22. if s1[0] != "" {
  23. save["site_toptype"] = s1[0]
  24. }
  25. if s1[1] != "" {
  26. save["site_subtype"] = s1[1]
  27. }
  28. } else {
  29. //log.Error("siteMap not find", zap.String("site", site))
  30. }
  31. if CodeMap[util.ObjToString(tmp["spidercode"])] != nil {
  32. save["collection_platform"] = CodeMap[util.ObjToString(tmp["spidercode"])]
  33. } else {
  34. //log.Error("codeMap not find", zap.String("spidercode", util.ObjToString(tmp["spidercode"])))
  35. }
  36. save["href"] = tmp["href"]
  37. if tmp["jybxhref"] != nil {
  38. save["jyhref"] = tmp["jybxhref"]
  39. } else {
  40. save["jyhref"] = fmt.Sprintf(config.Conf.Serve.JyHref, util.CommonEncodeArticle("content", id))
  41. }
  42. for _, s := range []string{"spidercode", "buyerclass", "toptype", "subtype", "s_topscopeclass", "s_subscopeclass", "area", "city", "multipackage"} {
  43. if tmp[s] != nil {
  44. save[s] = tmp[s]
  45. }
  46. }
  47. p := util.Int64All(tmp["publishtime"])
  48. save["publishtime"] = p
  49. save["s_publishtime"] = util.FormatDateByInt64(&p, util.Date_Short_Layout)
  50. if tmp["updatetime"] != nil {
  51. u := util.Int64All(tmp["updatetime"])
  52. save["updatetime"] = u
  53. save["s_updatetime"] = util.FormatDateByInt64(&u, util.Date_Short_Layout)
  54. } else {
  55. u := util.Int64All(tmp["createtime"])
  56. save["updatetime"] = u
  57. save["s_updatetime"] = util.FormatDateByInt64(&u, util.Date_Short_Layout)
  58. }
  59. if util.ObjToString(tmp["purchasing"]) != "" {
  60. save["is_purchasing"] = 1
  61. } else {
  62. save["is_purchasing"] = 0
  63. }
  64. tagM := make(map[string]interface{}) // 标注字段
  65. check := make(map[string]interface{})
  66. tag := 0 // 标注字段
  67. tagC := 0
  68. tlog, _ := MongoE.FindById(config.Conf.DB.MongoE.Coll, id, bson.M{"field_source": 0, "kvtext": 0})
  69. blog, _ := Mongo.FindById("bidding", id, bson.M{"purchasinglist": 1, "procurementlist": 1})
  70. for _, f := range config.Conf.Serve.Fields {
  71. if tmp[fmt.Sprintf("ck_%s", f)] != nil {
  72. tag++
  73. tagM[f] = util.IntAll(tmp[fmt.Sprintf("ck_%s", f)])
  74. }
  75. if tmp[f] == nil {
  76. continue
  77. }
  78. m := make(map[string]interface{})
  79. if f == "package" {
  80. if tagM[f] != nil {
  81. tagC++
  82. m["clean_flag"] = 1
  83. m["is_mark"] = 2
  84. execObj(f, save, tmp, *tlog)
  85. } else {
  86. execObj1(f, save, tmp, *tlog)
  87. m["clean_flag"] = 0
  88. }
  89. } else if f == "purchasinglist" || f == "procurementlist" {
  90. if tagM[f] != nil {
  91. tagC++
  92. m["clean_flag"] = 1
  93. m["is_mark"] = 2
  94. execObj(f, save, tmp, *blog)
  95. } else {
  96. execObj1(f, save, tmp, *blog)
  97. m["clean_flag"] = 0
  98. }
  99. } else {
  100. if tagM[f] != nil {
  101. m["clean_flag"] = 1
  102. t := util.IntAll(tagM[f])
  103. if t == 1 {
  104. m["is_mark"] = t
  105. } else {
  106. m["is_mark"] = 2
  107. }
  108. if t != 1 {
  109. tagC++
  110. if (*tlog)[f] != nil {
  111. m["pre_value"] = (*tlog)[f]
  112. }
  113. m["aft_value"] = tmp[f]
  114. } else {
  115. m["pre_value"] = tmp[f]
  116. }
  117. } else {
  118. m["pre_value"] = tmp[f]
  119. m["clean_flag"] = 0
  120. }
  121. }
  122. check[f] = m
  123. }
  124. save["need_field_num"] = tag
  125. save["v_fieldcheck"] = check
  126. save["clean_field_num"] = tagC
  127. if len(save) > 0 {
  128. savePool <- save
  129. }
  130. }
  131. func taskInfo(tmp map[string]interface{}) {
  132. if info, ok := tmp["v_baseinfo"].(map[string]interface{}); ok {
  133. id := util.ObjToString(info["id"])
  134. if id == "" {
  135. id = util.ObjToString(tmp["id"])
  136. }
  137. save := make(map[string]interface{})
  138. save["infoid"] = id
  139. save["data_tag"] = 1
  140. site := util.ObjToString(info["site"])
  141. save["site"] = site
  142. if SiteMap[site] != nil {
  143. s1 := strings.Split(util.ObjToString(SiteMap[site]), "-")
  144. if s1[0] != "" {
  145. save["site_toptype"] = s1[0]
  146. }
  147. if s1[1] != "" {
  148. save["site_subtype"] = s1[1]
  149. }
  150. } else {
  151. //log.Error("siteMap not find", zap.String("site", site))
  152. }
  153. if CodeMap[util.ObjToString(info["spidercode"])] != nil {
  154. save["collection_platform"] = CodeMap[util.ObjToString(info["spidercode"])]
  155. } else {
  156. //log.Error("codeMap not find", zap.String("spidercode", util.ObjToString(info["spidercode"])))
  157. }
  158. save["href"] = info["href"]
  159. if tmp["jybxhref"] != nil {
  160. save["jyhref"] = tmp["jybxhref"]
  161. } else {
  162. save["jyhref"] = fmt.Sprintf(config.Conf.Serve.JyHref, util.CommonEncodeArticle("content", id))
  163. }
  164. for _, s := range []string{"spidercode", "buyerclass", "toptype", "subtype", "s_topscopeclass", "s_subscopeclass", "area", "city", "multipackage"} {
  165. if info[s] != nil {
  166. save[s] = info[s]
  167. }
  168. }
  169. p := util.Int64All(info["publishtime"])
  170. save["publishtime"] = p
  171. save["s_publishtime"] = util.FormatDateByInt64(&p, util.Date_Short_Layout)
  172. if tmp["i_updatetime"] != nil {
  173. u := util.Int64All(tmp["i_updatetime"])
  174. save["updatetime"] = u
  175. save["s_updatetime"] = util.FormatDateByInt64(&u, util.Date_Short_Layout)
  176. } else {
  177. u := util.Int64All(tmp["i_createtime"])
  178. save["updatetime"] = u
  179. save["s_updatetime"] = util.FormatDateByInt64(&u, util.Date_Short_Layout)
  180. }
  181. if util.ObjToString(info["purchasing"]) != "" {
  182. save["is_purchasing"] = 1
  183. } else {
  184. save["is_purchasing"] = 0
  185. }
  186. tag := tmp["v_taginfo"].(map[string]interface{})
  187. save["need_field_num"] = len(tag)
  188. check := make(map[string]interface{})
  189. tagC := 0
  190. tlog, _ := MongoE.FindById(config.Conf.DB.MongoE.Coll, id, bson.M{"field_source": 0, "kvtext": 0})
  191. blog, _ := Mongo.FindById("bidding", id, bson.M{"purchasinglist": 1, "procurementlist": 1, "toptype": 1, "subtype": 1})
  192. save["toptype"] = (*blog)["toptype"]
  193. save["subtype"] = (*blog)["subtype"]
  194. for _, f := range config.Conf.Serve.Fields {
  195. if info[f] == nil {
  196. continue
  197. }
  198. m := make(map[string]interface{})
  199. if f == "package" {
  200. if tag[f] != nil {
  201. tagC++
  202. m["clean_flag"] = 1
  203. m["is_mark"] = 2
  204. execObj(f, save, info, *tlog)
  205. } else {
  206. execObj1(f, save, info, *tlog)
  207. m["clean_flag"] = 0
  208. }
  209. } else if f == "purchasinglist" || f == "procurementlist" {
  210. if tag[f] != nil {
  211. tagC++
  212. m["clean_flag"] = 1
  213. m["is_mark"] = 2
  214. execObj(f, save, info, *blog)
  215. } else {
  216. execObj1(f, save, tmp, *blog)
  217. m["clean_flag"] = 0
  218. }
  219. } else {
  220. if tag[f] != nil {
  221. m["clean_flag"] = 1
  222. t := util.IntAll(tag[f])
  223. m["is_mark"] = t
  224. if t != 1 {
  225. tagC++
  226. if (*tlog)[f] != nil {
  227. m["pre_value"] = (*tlog)[f]
  228. }
  229. m["aft_value"] = info[f]
  230. } else {
  231. m["pre_value"] = info[f]
  232. }
  233. } else {
  234. m["pre_value"] = info[f]
  235. m["clean_flag"] = 0
  236. }
  237. }
  238. check[f] = m
  239. }
  240. save["v_fieldcheck"] = check
  241. save["clean_field_num"] = tagC
  242. if len(save) > 0 {
  243. savePool <- save
  244. }
  245. }
  246. }
  247. func execObj(f string, save, info, tinfo map[string]interface{}) {
  248. if info[f] == nil {
  249. return
  250. }
  251. m := make(map[string]interface{})
  252. if f == "package" {
  253. obj := info[f].(map[string]interface{})
  254. m["aft_num"] = len(obj)
  255. m["modify_num"] = len(obj)
  256. m["aft_value"] = obj
  257. if preObj, ok := tinfo[f].(map[string]interface{}); ok {
  258. m["pre_num"] = len(preObj)
  259. m["pre_value"] = preObj
  260. } else {
  261. m["pre_num"] = 0
  262. }
  263. if save["multipackage"] == nil {
  264. if package1 := m["pre_value"]; package1 != nil {
  265. packageM, _ := package1.(map[string]interface{})
  266. for _, p := range packageM {
  267. pm, _ := p.(map[string]interface{})
  268. if util.ObjToString(pm["winner"]) != "" || util.Float64All(pm["budget"]) > 0 ||
  269. util.Float64All(pm["bidamount"]) > 0 {
  270. save["multipackage"] = 1
  271. break
  272. }
  273. }
  274. } else {
  275. save["multipackage"] = 0
  276. }
  277. }
  278. } else {
  279. obj := info[f].([]interface{})
  280. m["aft_num"] = len(obj)
  281. m["modify_num"] = len(obj)
  282. m["aft_value"] = obj
  283. if preObj, ok := tinfo[f].([]interface{}); ok {
  284. m["pre_num"] = len(preObj)
  285. m["pre_value"] = preObj
  286. } else {
  287. m["pre_num"] = 0
  288. }
  289. }
  290. save[f] = m
  291. }
  292. func execObj1(f string, save, info, tinfo map[string]interface{}) {
  293. if info[f] == nil {
  294. return
  295. }
  296. m := make(map[string]interface{})
  297. if f == "package" {
  298. if preObj, ok := tinfo[f].(map[string]interface{}); ok {
  299. m["pre_num"] = len(preObj)
  300. m["pre_value"] = preObj
  301. } else {
  302. m["pre_num"] = 0
  303. }
  304. } else {
  305. if preObj, ok := tinfo[f].([]interface{}); ok {
  306. m["pre_num"] = len(preObj)
  307. m["pre_value"] = preObj
  308. } else {
  309. m["pre_num"] = 0
  310. }
  311. }
  312. save[f] = m
  313. }