task.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package main
  2. import (
  3. "go.mongodb.org/mongo-driver/bson"
  4. "mongodb"
  5. "qfw/util"
  6. "regexp"
  7. "sort"
  8. "strings"
  9. "time"
  10. )
  11. var numReg = regexp.MustCompile("[0-9]+")
  12. func taskinfo1(tmp map[string]interface{}) {
  13. info := tmp["v_baseinfo"].(map[string]interface{})
  14. delete(info, "field_source")
  15. delete(info, "v_fieldscore")
  16. id := util.ObjToString(tmp["id"])
  17. info["_id"] = mongodb.StringTOBsonId(id)
  18. Mgo.SaveByOriID(collSave, info)
  19. }
  20. func taskinfo(info map[string]interface{}) {
  21. id := mongodb.BsonIdToSId(info["_id"])
  22. //info, ok := tmp["v_baseinfo"].(map[string]interface{})
  23. //if !ok {
  24. // util.Debug("data err ---", id)
  25. // return
  26. //}
  27. // 数据标签
  28. //var mtkey []string
  29. var tag []string
  30. for key, v := range TagMatchRule {
  31. M:
  32. for _, matching := range v {
  33. if matching.excludeKey != "" {
  34. // 匹配排除词
  35. for _, way := range matching.excludeKeyWay {
  36. field := MatchWayMap[way]
  37. if val := util.ObjToString(info[field]); val != "" {
  38. for _, e1 := range matching.excludeKeyReg {
  39. if e1.regs.MatchString(val) {
  40. continue
  41. }
  42. }
  43. }
  44. }
  45. }
  46. if matching.matchKey != "" {
  47. // 匹配关键词
  48. for _, way := range matching.matchKeyWay {
  49. field := MatchWayMap[way]
  50. if val := util.ObjToString(info[field]); val != "" {
  51. for _, r1 := range matching.matchKeyReg {
  52. if r1.regs.MatchString(val) {
  53. if matching.addKey != "" {
  54. // 匹配附加词
  55. for _, w1 := range matching.addKeyWay {
  56. field = MatchWayMap[w1]
  57. if v1 := util.ObjToString(info[field]); v1 != "" {
  58. for _, r2 := range matching.addKeyReg {
  59. if r2.regs != nil && r2.regs.MatchString(v1) {
  60. //mtkey = append(mtkey, matching.matchKey)
  61. tag = append(tag, key) // 标签
  62. break M
  63. } else {
  64. // && 特殊处理
  65. if strings.Contains(r2.keyStr, "&&") {
  66. flag := true
  67. for _, s := range strings.Split(r2.keyStr, "&&") {
  68. if !strings.Contains(v1, s) {
  69. flag = false
  70. break
  71. }
  72. }
  73. if flag {
  74. //mtkey = append(mtkey, matching.matchKey)
  75. tag = append(tag, key) // 标签
  76. break M
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. } else {
  84. //mtkey = append(mtkey, matching.matchKey)
  85. tag = append(tag, key) // 标签
  86. break M
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. //info["mtkey"] = strings.Join(mtkey, "-")
  96. if len(tag) > 0 {
  97. info["tag_rule"] = strings.Join(tag, ",")
  98. } else {
  99. info["tag_rule"] = "IT"
  100. }
  101. /**
  102. 项目结束日期 project_completedate(中标、成交、合同)
  103. 1、优先采用project_completedate
  104. 2、通过项目周期(projectperiod)、工期时长(project_duration)、工期单位(project_timeunit)、项目开始时间(project_startdate/signaturedate)(发布时间/合同签订时间)
  105. */
  106. completeData := util.Int64All(info["project_completedate"])
  107. subtype := util.ObjToString(info["subtype"])
  108. if completeData == 0 {
  109. if subtype == "中标" || subtype == "成交" || subtype == "合同" {
  110. var dur int
  111. if util.IntAll(info["project_duration"]) != 0 {
  112. dur = util.IntAll(info["project_duration"])
  113. } else {
  114. period := periodMethod(info["projectperiod"])
  115. if period > 0 {
  116. dur = period
  117. }
  118. }
  119. if dur > 0 {
  120. timeunit := util.ObjToString(info["project_timeunit"])
  121. startdate := util.Int64All(info["project_startdate"])
  122. if startdate > 0 {
  123. completeData = YcEndTime(startdate, dur, timeunit)
  124. } else if startdate = util.Int64All(info["signaturedate"]); startdate > 0 {
  125. completeData = YcEndTime(startdate, dur, timeunit)
  126. } else {
  127. startdate = util.Int64All(info["publishtime"])
  128. completeData = YcEndTime(startdate, dur, timeunit)
  129. }
  130. }
  131. if completeData != 0 {
  132. info["project_completedate"] = completeData
  133. }
  134. }
  135. }
  136. // 企业标签(采购单位 1 /中标单位 2 )
  137. if info["buyer"] != nil {
  138. qyxy, _ := Mgo.FindOne(qyxyColl, map[string]interface{}{"company_name": util.ObjToString(info["buyer"])})
  139. if len(*qyxy) > 0 {
  140. if (*qyxy)["bid_type"] == nil {
  141. Mgo.UpdateById(qyxyColl, (*qyxy)["_id"], bson.M{"$set": bson.M{"bid_type": "1"}})
  142. } else {
  143. stype := strings.Split(util.ObjToString((*qyxy)["bid_type"]), ",")
  144. if !strings.Contains(util.ObjToString((*qyxy)["bid_type"]), "1") {
  145. stype = append(stype, "1")
  146. sort.Strings(stype)
  147. Mgo.UpdateById(qyxyColl, (*qyxy)["_id"], bson.M{"$set": bson.M{"bid_type": strings.Join(stype, ",")}})
  148. }
  149. }
  150. }
  151. }
  152. if info["s_winner"] != nil {
  153. winner := util.ObjToString(info["s_winner"])
  154. for _, s := range strings.Split(winner, ",") {
  155. qyxy, _ := Mgo.FindOne(qyxyColl, map[string]interface{}{"company_name": s})
  156. if len(*qyxy) > 0 {
  157. if (*qyxy)["bid_type"] == nil {
  158. Mgo.UpdateById(qyxyColl, (*qyxy)["_id"], bson.M{"$set": bson.M{"bid_type": "2"}})
  159. } else {
  160. stype := strings.Split(util.ObjToString((*qyxy)["bid_type"]), ",")
  161. if !strings.Contains(util.ObjToString((*qyxy)["bid_type"]), "2") {
  162. stype = append(stype, "2")
  163. Mgo.UpdateById(qyxyColl, (*qyxy)["_id"], bson.M{"$set": bson.M{"bid_type": strings.Join(stype, ",")}})
  164. }
  165. }
  166. }
  167. }
  168. //for _, op := range operators {
  169. // if strings.Contains(winner, op) {
  170. // info["isOperators"] = true
  171. // break
  172. // }
  173. //}
  174. }
  175. //info["_id"] = mongodb.StringTOBsonId(id)
  176. delete(info, "_id")
  177. info["updatetime"] = time.Now().Unix()
  178. //savePool <- info
  179. update := []map[string]interface{}{{
  180. "_id": mongodb.StringTOBsonId(id),
  181. },
  182. {"$set": info},
  183. }
  184. updatePool <- update
  185. }
  186. func periodMethod(str interface{}) int {
  187. if util.ObjToString(str) != "" {
  188. arr := numReg.FindStringSubmatch(util.ObjToString(str))
  189. if len(arr) > 0 {
  190. return util.IntAll(arr[0])
  191. }
  192. }
  193. return 0
  194. }
  195. func YcEndTime(starttime int64, num int, unit string) int64 {
  196. yuceendtime := int64(0)
  197. if unit == "日历天" || unit == "天" || unit == "日" {
  198. yuceendtime = starttime + int64(num*86400)
  199. } else if unit == "周" {
  200. yuceendtime = time.Unix(starttime, 0).AddDate(0, 0, num*7).Unix()
  201. } else if unit == "月" {
  202. yuceendtime = time.Unix(starttime, 0).AddDate(0, num, 0).Unix()
  203. } else if unit == "年" {
  204. yuceendtime = time.Unix(starttime, 0).AddDate(num, 0, 0).Unix()
  205. } else if unit == "工作日" {
  206. n := num / 7 * 2
  207. yuceendtime = time.Unix(starttime, 0).AddDate(0, 0, num+n).Unix()
  208. }
  209. return yuceendtime
  210. }