task.go 6.1 KB

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