yusuan.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. package main
  2. import (
  3. "log"
  4. "math"
  5. "reflect"
  6. "regexp"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. var regString = `(\d+[.,]{0,}\d+)`
  12. var reg, _ = regexp.Compile(regString)
  13. // 从解析文档中提取全部项目信息
  14. func getProjectItemFromFilejx() {
  15. //list, _ := db.Find(cf.YusuanInfo, `{"handle":{"$exists":1}}`, nil, nil, false, -1, -1)
  16. list, _ := db.Find(cf.YusuanInfo, `{ "file_path" : "2024年/北京/北京市/政府/2024_北京市经济和信息化局_1.xlsx" }`, nil, nil, false, -1, -1)
  17. pronum := 0
  18. for k, data := range *list {
  19. tmp, _ := data["performance_result"].([]interface{})
  20. if len(tmp) > 0 {
  21. for _, v := range tmp {
  22. t, _ := v.(map[string]interface{})
  23. tmp3, _ := t["sheetdata"].([]interface{})
  24. for _, v := range tmp3 {
  25. item, _ := v.(map[string]interface{})
  26. budget, ok := item["budget"]
  27. if ok {
  28. ty := reflect.TypeOf(budget).Kind()
  29. switch ty {
  30. case reflect.Int:
  31. item["budget_f"] = float64(budget.(int))
  32. case reflect.Int32:
  33. item["budget_f"] = float64(budget.(int32))
  34. case reflect.String:
  35. budget_f := budget.(string)
  36. if strings.Contains(budget_f, ",") {
  37. budget_f = strings.ReplaceAll(budget_f, ",", "")
  38. }
  39. rs, _ := strconv.ParseFloat(budget_f, 64)
  40. item["budget_f"] = rs
  41. default:
  42. item["budget_f"] = budget
  43. }
  44. unit, _ := item["unit"].(string)
  45. if strings.Contains(unit, "万") {
  46. item["budget_f"] = math.Round(item["budget_f"].(float64) * 10000)
  47. }
  48. } else {
  49. total_amount, ok := item["total_amount"]
  50. if ok {
  51. ty := reflect.TypeOf(total_amount).Kind()
  52. switch ty {
  53. case reflect.Int:
  54. item["budget_f"] = float64(total_amount.(int))
  55. case reflect.Int32:
  56. item["budget_f"] = float64(total_amount.(int32))
  57. case reflect.String:
  58. budget_f := total_amount.(string)
  59. if strings.Contains(budget_f, ",") {
  60. budget_f = strings.ReplaceAll(budget_f, ",", "")
  61. }
  62. rs, _ := strconv.ParseFloat(budget_f, 64)
  63. item["budget_f"] = rs
  64. default:
  65. item["budget_f"] = total_amount
  66. }
  67. unit, _ := item["unit"].(string)
  68. if strings.Contains(unit, "万") {
  69. item["budget_f"] = math.Round(item["budget_f"].(float64) * 10000)
  70. }
  71. }
  72. }
  73. for _, f := range cf.Projectitem_field {
  74. item[f] = data[f]
  75. }
  76. pronum++
  77. db.Save(cf.ProjectItem, item)
  78. }
  79. }
  80. }
  81. if k%1000 == 0 {
  82. log.Printf("加载数据量为:%d,生成项目数据量为:%d", k, pronum)
  83. }
  84. }
  85. }
  86. // 匹配客户项目信息
  87. type Data struct {
  88. ismatch bool
  89. isnotmatch bool
  90. matchkey map[string]bool
  91. matchkey_field map[string]bool
  92. matchkey_add map[string]bool
  93. matchkey_add_field map[string]bool
  94. notmatchkey map[string]bool
  95. notmatchkey_field map[string]bool
  96. rule_index string
  97. }
  98. func getCustomerMatchProject() {
  99. list, _ := db.Find(cf.ProjectItem, nil, nil, nil, false, -1, -1)
  100. pipienum := 0
  101. for k, tmp := range *list {
  102. d := &Data{
  103. matchkey: map[string]bool{},
  104. matchkey_field: map[string]bool{},
  105. matchkey_add: map[string]bool{},
  106. matchkey_add_field: map[string]bool{},
  107. notmatchkey: map[string]bool{},
  108. notmatchkey_field: map[string]bool{},
  109. }
  110. for _, rule := range ucf.Rules {
  111. //关键词
  112. mkey := strings.Split(rule.Match, ",")
  113. for _, field := range rule.MatchField.Field {
  114. content, _ := tmp[field].(string)
  115. //关键词匹配
  116. for _, key := range mkey {
  117. keys := strings.Split(key, "&&")
  118. ismatch := true
  119. for _, v := range keys {
  120. if !strings.Contains(content, v) {
  121. ismatch = false
  122. break
  123. }
  124. }
  125. if ismatch {
  126. d.ismatch = true
  127. d.matchkey[key] = true
  128. d.matchkey_field[field] = true
  129. }
  130. }
  131. }
  132. //处理附件词、排除词
  133. if d.ismatch {
  134. d.rule_index = rule.Index
  135. //附加词
  136. addkey := strings.Split(rule.MatchAdd, ",")
  137. if len(addkey) > 0 {
  138. //附加词匹配
  139. for _, key := range addkey {
  140. for _, field := range rule.MatchAddField.Field {
  141. content, _ := tmp[field].(string)
  142. if strings.Contains(content, key) {
  143. d.matchkey_add[key] = true
  144. d.matchkey_add_field[field] = true
  145. }
  146. }
  147. }
  148. }
  149. //排除词
  150. notkey := strings.Split(rule.NotMatch, ",")
  151. if len(notkey) > 0 {
  152. //附加词匹配
  153. for _, key := range notkey {
  154. for _, field := range rule.NotMatchField.Field {
  155. content, _ := tmp[field].(string)
  156. if strings.Contains(content, key) {
  157. d.notmatchkey[key] = true
  158. d.notmatchkey_field[field] = true
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. if d.ismatch {
  166. //提取
  167. pipienum++
  168. tmp["matchkey"] = getKeyMap(d.matchkey)
  169. tmp["matchkey_filed"] = getKeyMap(d.matchkey_field)
  170. tmp["matchkey_add"] = getKeyMap(d.matchkey_add)
  171. tmp["matchkey_add_filed"] = getKeyMap(d.matchkey_add_field)
  172. tmp["matchkey_not"] = getKeyMap(d.notmatchkey)
  173. tmp["matchkey_not_filed"] = getKeyMap(d.notmatchkey_field)
  174. tmp["rule_index"] = d.rule_index
  175. tmp["comeintime"] = time.Now().Unix()
  176. db.Save(ucf.Totbale, tmp)
  177. } else {
  178. //不提取
  179. }
  180. if k%1000 == 0 {
  181. log.Printf("加载数量为:%d,匹配数据量为:%d", k, pipienum)
  182. }
  183. }
  184. log.Println(ucf.User, pipienum, "匹配项目已处理完成")
  185. }
  186. func getKeyMap(m map[string]bool) string {
  187. ll := []string{}
  188. for k, _ := range m {
  189. ll = append(ll, k)
  190. }
  191. return strings.Join(ll, ",")
  192. }
  193. // 修复预算
  194. func xiuyusuan() {
  195. list, _ := db.Find("project_hp", nil, nil, nil, false, -1, -1)
  196. for _, tmp := range *list {
  197. total_budget, ok := tmp["total_budget"].(string)
  198. if ok {
  199. if strings.Contains(total_budget, ",") {
  200. log.Println(total_budget)
  201. total_budget = strings.ReplaceAll(total_budget, ",", "")
  202. }
  203. budget, _ := strconv.ParseFloat(total_budget, 64)
  204. log.Println(total_budget, budget)
  205. unit, _ := tmp["unit"].(string)
  206. if strings.Contains(unit, "万") {
  207. budget = budget * 10000
  208. }
  209. //log.Println(total_budget, budget, tmp["_id"])
  210. db.Update(
  211. "project_hp",
  212. map[string]interface{}{"_id": tmp["_id"]},
  213. map[string]interface{}{"$set": map[string]interface{}{"total_budget_f": budget}},
  214. true,
  215. false,
  216. )
  217. }
  218. }
  219. }