global.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. package ul
  2. import (
  3. qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  4. "strings"
  5. )
  6. var Unset_Check = map[string]interface{}{"winner": 1, "s_winner": 1, "bidamount": 1, "winnerorder": 1}
  7. // 大模型与抽取数据合并计算
  8. func ChooseCheckDataAI(tmp map[string]interface{}, update_info *map[string]interface{}) bool {
  9. if tmp["ai_zhipu"] == nil {
  10. return false
  11. }
  12. //记录抽取原值
  13. ext_ai_record := map[string]interface{}{}
  14. ai_zhipu := *qu.ObjToMap(tmp["ai_zhipu"])
  15. //选取分类
  16. s_toptype, s_subtype := ChooseTheBestClassField(ai_zhipu, tmp, update_info, &ext_ai_record)
  17. //选取字段
  18. ChooseTheBestCoreField(ai_zhipu, s_toptype, s_subtype, tmp, update_info, &ext_ai_record)
  19. //选取分包
  20. ChooseTheBestPackageField(ai_zhipu, s_toptype, s_subtype, tmp, update_info, &ext_ai_record)
  21. //最终金额修正与选取
  22. ChooseTheBestAmountField(tmp, update_info)
  23. //最终单位修正与选取
  24. ChooseTheBestUnitField(ai_zhipu, s_toptype, s_subtype, tmp, update_info, &ext_ai_record)
  25. //其他字段选取
  26. ChooseTheBestOtherField(ai_zhipu, tmp, update_info, &ext_ai_record)
  27. //字段记录
  28. (*update_info)["ext_ai_record"] = ext_ai_record
  29. //跨分类是否删除结果类字段
  30. if s_subtype == "单一" || s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" {
  31. } else {
  32. for k, _ := range Unset_Check {
  33. if tmp[k] != nil {
  34. return true
  35. }
  36. }
  37. }
  38. return false
  39. }
  40. // 选取分类
  41. func ChooseTheBestClassField(ai_zhipu map[string]interface{}, tmp map[string]interface{}, update_info *map[string]interface{}, ext_ai_record *map[string]interface{}) (string, string) {
  42. //分类字段···
  43. s_toptype, s_subtype := qu.ObjToString(ai_zhipu["s_toptype"]), qu.ObjToString(ai_zhipu["s_subtype"])
  44. ns_toptype, ns_subtype := CheckClassByOtherFileds(s_toptype, s_subtype, tmp)
  45. if ns_toptype != s_toptype || ns_subtype != s_subtype {
  46. (*ext_ai_record)["s_toptype"] = ns_toptype
  47. (*ext_ai_record)["s_subtype"] = ns_subtype
  48. }
  49. //赋值···
  50. s_toptype, s_subtype = ns_toptype, ns_subtype
  51. if qu.ObjToString(tmp["toptype"]) == "拟建" || qu.ObjToString(tmp["toptype"]) == "产权" {
  52. s_toptype = qu.ObjToString(tmp["toptype"])
  53. s_subtype = qu.ObjToString(tmp["subtype"])
  54. } else {
  55. if s_toptype != "" && s_subtype != "" {
  56. (*update_info)["toptype"] = s_toptype
  57. (*update_info)["subtype"] = s_subtype
  58. (*ext_ai_record)["toptype"] = tmp["toptype"]
  59. (*ext_ai_record)["subtype"] = tmp["subtype"]
  60. } else {
  61. s_toptype = qu.ObjToString(tmp["toptype"])
  62. s_subtype = qu.ObjToString(tmp["subtype"])
  63. }
  64. }
  65. return s_toptype, s_subtype
  66. }
  67. // 选取字段
  68. func ChooseTheBestCoreField(ai_zhipu map[string]interface{}, s_toptype string, s_subtype string, tmp map[string]interface{}, update_info *map[string]interface{}, ext_ai_record *map[string]interface{}) {
  69. if s_buyer := qu.ObjToString(ai_zhipu["s_buyer"]); s_buyer != "" {
  70. (*update_info)["buyer"] = s_buyer
  71. (*ext_ai_record)["buyer"] = tmp["buyer"]
  72. }
  73. //基础字段···
  74. if s_agency := qu.ObjToString(ai_zhipu["s_agency"]); s_agency != "" {
  75. (*update_info)["agency"] = s_agency
  76. (*ext_ai_record)["agency"] = tmp["agency"]
  77. }
  78. if s_projectname := qu.ObjToString(ai_zhipu["s_projectname"]); s_projectname != "" {
  79. (*update_info)["projectname"] = s_projectname
  80. (*ext_ai_record)["projectname"] = tmp["projectname"]
  81. }
  82. if s_projectcode := qu.ObjToString(ai_zhipu["s_projectcode"]); s_projectcode != "" {
  83. (*update_info)["projectcode"] = s_projectcode
  84. (*ext_ai_record)["projectcode"] = tmp["projectcode"]
  85. }
  86. if s_budget := qu.Float64All(ai_zhipu["s_budget"]); s_budget > 0.0 && s_budget < 1000000000.0 {
  87. (*update_info)["budget"] = s_budget
  88. (*ext_ai_record)["budget"] = tmp["budget"]
  89. }
  90. //规则地域字段···
  91. o_area, o_city, o_district := qu.ObjToString(tmp["area"]), qu.ObjToString(tmp["city"]), qu.ObjToString(tmp["district"])
  92. s_area, s_city := qu.ObjToString(ai_zhipu["s_area"]), qu.ObjToString(ai_zhipu["s_city"])
  93. if s_area != "" && s_area != "全国" {
  94. (*update_info)["area"] = s_area
  95. if s_city != "" {
  96. (*update_info)["city"] = s_city
  97. if o_district != "" {
  98. if s_city != o_city || s_area != o_area {
  99. (*update_info)["district"] = ""
  100. }
  101. }
  102. } else {
  103. if o_area != s_area {
  104. (*update_info)["city"] = ""
  105. (*update_info)["district"] = ""
  106. }
  107. }
  108. (*ext_ai_record)["area"] = tmp["area"]
  109. (*ext_ai_record)["city"] = tmp["city"]
  110. (*ext_ai_record)["district"] = tmp["district"]
  111. }
  112. //先用外围字段替换
  113. if s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" || s_subtype == "单一" {
  114. if s_bidamount := qu.Float64All(ai_zhipu["s_bidamount"]); s_bidamount > 0.0 && s_bidamount < 1000000000.0 {
  115. (*update_info)["bidamount"] = s_bidamount
  116. (*ext_ai_record)["bidamount"] = tmp["bidamount"]
  117. }
  118. if s_winner := qu.ObjToString(ai_zhipu["s_winner"]); s_winner != "" {
  119. (*update_info)["s_winner"] = s_winner
  120. (*ext_ai_record)["s_winner"] = tmp["s_winner"]
  121. (*update_info)["winner"] = s_winner
  122. (*ext_ai_record)["winner"] = tmp["winner"]
  123. //对于winner来说...规则值有包含关系,采用规则值
  124. if winner := qu.ObjToString(tmp["winner"]); winner != "" {
  125. if strings.Contains(s_winner, winner) {
  126. delete((*update_info), "winner")
  127. delete((*ext_ai_record), "winner")
  128. }
  129. }
  130. }
  131. //旧版弃用
  132. //isRulePkg := false
  133. //if pkg := *qu.ObjToMap(tmp["package"]); len(pkg) > 1 && (s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同") {
  134. // if !staffInfo(pkg) {
  135. // isRulePkg = true
  136. // }
  137. //}
  138. //if isRulePkg { //优先采用大模型分包-值替换
  139. // if ispkg, ok := ai_zhipu["ispkg"].(bool); ispkg && ok {
  140. // if s_pkg := qu.ObjToMap(ai_zhipu["s_pkg"]); s_pkg != nil {
  141. // if p_winner := qu.ObjToString((*s_pkg)["s_winner"]); p_winner != "" {
  142. // (*update_check)["s_winner"] = p_winner
  143. // (*update_check)["winner"] = p_winner
  144. // ext_ai_record["s_winner"] = tmp["s_winner"]
  145. // ext_ai_record["winner"] = tmp["winner"]
  146. // }
  147. // if p_bidamount := qu.Float64All((*s_pkg)["s_bidamount"]); p_bidamount > 0.0 {
  148. // (*update_check)["bidamount"] = p_bidamount
  149. // ext_ai_record["bidamount"] = tmp["bidamount"]
  150. // }
  151. // if s_package := qu.ObjToMap((*s_pkg)["s_pkg"]); s_package != nil {
  152. // (*update_check)["package"] = s_package
  153. // ext_ai_record["package"] = tmp["package"]
  154. // }
  155. // }
  156. // }
  157. //}
  158. } else {
  159. }
  160. }
  161. // 选取分包
  162. func ChooseTheBestPackageField(ai_zhipu map[string]interface{}, s_toptype string, s_subtype string, tmp map[string]interface{}, update_info *map[string]interface{}, ext_ai_record *map[string]interface{}) {
  163. //新分包判定···com_package - 默认大模型分包可信
  164. if s_pkg := qu.ObjToMap(ai_zhipu["s_pkg"]); s_pkg != nil {
  165. com_package := IsMarkInterfaceMap((*s_pkg)["com_package"])
  166. //是否替换外围字段···质谱外围是否已提取
  167. if len(com_package) > 1 { //多包字段覆盖
  168. //校验核对分包结构
  169. new_com_package := staffAiPackageInfo(com_package, s_toptype, s_subtype)
  170. (*update_info)["com_package"] = new_com_package
  171. if p_budget := qu.Float64All((*s_pkg)["s_budget"]); p_budget > 0.0 {
  172. (*update_info)["budget"] = p_budget
  173. (*ext_ai_record)["budget"] = tmp["budget"]
  174. }
  175. if s_subtype == "单一" || s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" {
  176. if p_winner := qu.ObjToString((*s_pkg)["s_winner"]); p_winner != "" {
  177. (*update_info)["s_winner"] = p_winner
  178. (*update_info)["winner"] = p_winner
  179. (*ext_ai_record)["s_winner"] = tmp["s_winner"]
  180. (*ext_ai_record)["winner"] = tmp["winner"]
  181. //对于winner来说...规则值有包含关系,采用规则值应用判重
  182. if winner := qu.ObjToString(tmp["winner"]); winner != "" {
  183. if strings.Contains(p_winner, winner) {
  184. delete((*update_info), "winner")
  185. delete((*ext_ai_record), "winner")
  186. }
  187. }
  188. }
  189. if p_bidamount := qu.Float64All((*s_pkg)["s_bidamount"]); p_bidamount > 0.0 {
  190. (*update_info)["bidamount"] = p_bidamount
  191. (*ext_ai_record)["bidamount"] = tmp["bidamount"]
  192. }
  193. }
  194. } else if len(com_package) == 1 { //单包字段覆盖
  195. if p_budget := qu.Float64All((*s_pkg)["s_budget"]); p_budget > 0.0 && (*update_info)["budget"] == nil {
  196. (*update_info)["budget"] = p_budget
  197. (*ext_ai_record)["budget"] = tmp["budget"]
  198. }
  199. if s_subtype == "单一" || s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" {
  200. if p_winner := qu.ObjToString((*s_pkg)["s_winner"]); p_winner != "" && (*update_info)["s_winner"] == nil {
  201. (*update_info)["s_winner"] = p_winner
  202. (*update_info)["winner"] = p_winner
  203. (*ext_ai_record)["s_winner"] = tmp["s_winner"]
  204. (*ext_ai_record)["winner"] = tmp["winner"]
  205. //对于winner来说...规则值有包含关系,采用规则值应用判重
  206. if winner := qu.ObjToString(tmp["winner"]); winner != "" {
  207. if strings.Contains(p_winner, winner) {
  208. delete((*update_info), "winner")
  209. delete((*ext_ai_record), "winner")
  210. }
  211. }
  212. }
  213. if p_bidamount := qu.Float64All((*s_pkg)["s_bidamount"]); p_bidamount > 0.0 && (*update_info)["bidamount"] == nil {
  214. (*update_info)["bidamount"] = p_bidamount
  215. (*ext_ai_record)["bidamount"] = tmp["bidamount"]
  216. }
  217. }
  218. } else {
  219. }
  220. }
  221. }
  222. // 选取金额
  223. func ChooseTheBestAmountField(tmp map[string]interface{}, update_info *map[string]interface{}) {
  224. if r_budget := qu.Float64All((*update_info)["budget"]); r_budget > 0.0 && r_budget < 1000000000.0 {
  225. if o_budget := qu.Float64All(tmp["budget"]); o_budget > 0.0 {
  226. if r_budget/o_budget == 10000.0 || o_budget/r_budget == 10000.0 {
  227. (*update_info)["budget"] = filterAmount(r_budget, o_budget)
  228. }
  229. }
  230. }
  231. if r_bidamount := qu.Float64All((*update_info)["bidamount"]); r_bidamount > 0.0 && r_bidamount < 1000000000.0 {
  232. if o_bidamount := qu.Float64All(tmp["bidamount"]); o_bidamount > 0.0 {
  233. if r_bidamount/o_bidamount == 10000.0 || o_bidamount/r_bidamount == 10000.0 {
  234. (*update_info)["bidamount"] = filterAmount(r_bidamount, o_bidamount)
  235. }
  236. }
  237. }
  238. }
  239. // 选择核对单位值
  240. func ChooseTheBestUnitField(ai_zhipu map[string]interface{}, s_toptype string, s_subtype string, tmp map[string]interface{}, update_info *map[string]interface{}, ext_ai_record *map[string]interface{}) {
  241. buyer := qu.ObjToString((*update_info)["buyer"])
  242. s_winner := qu.ObjToString((*update_info)["s_winner"])
  243. agency := qu.ObjToString((*update_info)["agency"])
  244. if buyer == "" {
  245. buyer = qu.ObjToString(tmp["buyer"])
  246. }
  247. if s_winner == "" {
  248. s_winner = qu.ObjToString(tmp["s_winner"])
  249. }
  250. if agency == "" {
  251. agency = qu.ObjToString(tmp["agency"])
  252. }
  253. if buyer == s_winner && buyer != "" {
  254. if strings.Contains(buyer, "公司") {
  255. (*update_info)["buyer"] = ""
  256. (*ext_ai_record)["buyer"] = tmp["buyer"]
  257. } else {
  258. if s_subtype == "单一" || s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" {
  259. (*update_info)["s_winner"] = ""
  260. (*update_info)["winner"] = ""
  261. (*ext_ai_record)["s_winner"] = tmp["s_winner"]
  262. (*ext_ai_record)["winner"] = tmp["winner"]
  263. }
  264. }
  265. }
  266. if agency != "" {
  267. if agency == buyer || agency == s_winner {
  268. (*update_info)["agency"] = ""
  269. (*ext_ai_record)["agency"] = tmp["buyer"]
  270. }
  271. }
  272. }
  273. // 选择其它字段
  274. func ChooseTheBestOtherField(ai_zhipu map[string]interface{}, tmp map[string]interface{}, update_info *map[string]interface{}, ext_ai_record *map[string]interface{}) {
  275. if purchasinglist := ai_zhipu["purchasinglist"]; purchasinglist != nil {
  276. (*update_info)["purchasinglist"] = purchasinglist
  277. (*ext_ai_record)["purchasinglist"] = tmp["purchasinglist"]
  278. }
  279. //新增字段
  280. if biddingcode := ai_zhipu["s_biddingcode"]; biddingcode != nil {
  281. (*update_info)["biddingcode"] = biddingcode
  282. }
  283. if packagecode := ai_zhipu["s_packagecode"]; packagecode != nil {
  284. (*update_info)["packagecode"] = packagecode
  285. }
  286. //替换字段
  287. if contractcode := ai_zhipu["s_contractcode"]; contractcode != nil {
  288. (*update_info)["contractcode"] = contractcode
  289. (*ext_ai_record)["contractcode"] = tmp["contractcode"]
  290. }
  291. if bidopenaddress := ai_zhipu["s_bidopenaddress"]; bidopenaddress != nil {
  292. (*update_info)["bidopenaddress"] = bidopenaddress
  293. (*ext_ai_record)["bidopenaddress"] = tmp["bidopenaddress"]
  294. }
  295. if biddiscount := ai_zhipu["s_biddiscount"]; biddiscount != nil {
  296. (*update_info)["biddiscount"] = biddiscount
  297. (*ext_ai_record)["biddiscount"] = tmp["biddiscount"]
  298. }
  299. if bidopentime := ai_zhipu["s_bidopentime"]; bidopentime != nil {
  300. (*update_info)["bidopentime"] = bidopentime
  301. (*ext_ai_record)["bidopentime"] = tmp["bidopentime"]
  302. }
  303. if bidendtime := ai_zhipu["s_bidendtime"]; bidendtime != nil {
  304. (*update_info)["bidendtime"] = bidendtime
  305. (*ext_ai_record)["bidendtime"] = tmp["bidendtime"]
  306. }
  307. if docstarttime := ai_zhipu["s_docstarttime"]; docstarttime != nil {
  308. (*update_info)["docstarttime"] = docstarttime
  309. (*ext_ai_record)["docstarttime"] = tmp["docstarttime"]
  310. }
  311. if docendtime := ai_zhipu["s_docendtime"]; docendtime != nil {
  312. (*update_info)["docendtime"] = docendtime
  313. (*ext_ai_record)["docendtime"] = tmp["docendtime"]
  314. }
  315. //联系方式
  316. if buyerperson := ai_zhipu["s_buyerperson"]; buyerperson != nil {
  317. (*update_info)["buyerperson"] = buyerperson
  318. (*ext_ai_record)["buyerperson"] = tmp["buyerperson"]
  319. }
  320. if buyertel := ai_zhipu["s_buyertel"]; buyertel != nil {
  321. (*update_info)["buyertel"] = buyertel
  322. (*ext_ai_record)["buyertel"] = tmp["buyertel"]
  323. }
  324. if agencyperson := ai_zhipu["s_agencyperson"]; agencyperson != nil {
  325. (*update_info)["agencyperson"] = agencyperson
  326. (*ext_ai_record)["agencyperson"] = tmp["agencyperson"]
  327. }
  328. if agencytel := ai_zhipu["s_agencytel"]; agencytel != nil {
  329. (*update_info)["agencytel"] = agencytel
  330. (*ext_ai_record)["agencytel"] = tmp["agencytel"]
  331. }
  332. if winnerperson := ai_zhipu["s_winnerperson"]; winnerperson != nil {
  333. (*update_info)["winnerperson"] = winnerperson
  334. (*ext_ai_record)["winnerperson"] = tmp["winnerperson"]
  335. }
  336. if winnertel := ai_zhipu["s_winnertel"]; winnertel != nil {
  337. (*update_info)["winnertel"] = winnertel
  338. (*ext_ai_record)["winnertel"] = tmp["winnertel"]
  339. }
  340. }
  341. // 筛选金额
  342. func filterAmount(f1 float64, f2 float64) float64 {
  343. //选取一个合适的金额 ...
  344. if f1 > f2 {
  345. if f1 > 100000000.0 {
  346. return f2
  347. } else {
  348. return f1
  349. }
  350. } else if f1 < f2 {
  351. if f2 > 100000000.0 {
  352. return f1
  353. } else {
  354. return f2
  355. }
  356. } else {
  357. return f1
  358. }
  359. }
  360. // 核算分包信息
  361. func staffInfo(pkg map[string]interface{}) bool {
  362. //鉴定中标单位
  363. is_w := 0
  364. for _, v := range pkg {
  365. info := *qu.ObjToMap(v)
  366. if winner := qu.ObjToString(info["winner"]); winner != "" {
  367. is_w++
  368. }
  369. }
  370. //鉴定中标金额
  371. is_b := 0
  372. for _, v := range pkg {
  373. info := *qu.ObjToMap(v)
  374. if bidamount := qu.Float64All(info["bidamount"]); bidamount > 0.0 {
  375. is_b++
  376. }
  377. }
  378. if is_w != len(pkg) && is_w > 0 {
  379. return false
  380. }
  381. if is_b != len(pkg) && is_b > 0 {
  382. return false
  383. }
  384. if is_w == 0 || is_b == 0 {
  385. return false
  386. }
  387. return true
  388. }
  389. // 核对ai分包
  390. func staffAiPackageInfo(com_package []map[string]interface{}, s_toptype string, s_subtype string) []map[string]interface{} {
  391. if s_subtype == "单一" || s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" {
  392. return com_package
  393. }
  394. new_com_package := []map[string]interface{}{}
  395. for _, v := range com_package {
  396. delete(v, "winner")
  397. delete(v, "bidamount")
  398. new_com_package = append(new_com_package, v)
  399. }
  400. return new_com_package
  401. }
  402. // 核对分类
  403. func CheckClassByOtherFileds(toptype_ai, subtype_ai string, data map[string]interface{}) (string, string) {
  404. toptype_rule := qu.ObjToString(data["toptype"])
  405. subtype_rule := qu.ObjToString(data["subtype"])
  406. //1、结果类 中标和成交错误校正
  407. s_winner := qu.ObjToString(data["s_winner"])
  408. winnerorder := IsMarkInterfaceMap(data["winnerorder"])
  409. if toptype_ai == "结果" && toptype_rule == "结果" {
  410. if subtype_ai == "成交" && subtype_rule == "成交" && len(winnerorder) > 0 { //规则、大模型都错
  411. return "结果", "中标"
  412. }
  413. if ((subtype_ai == "中标" || subtype_ai == "其它") && subtype_rule == "成交") || ((subtype_ai == "成交" || subtype_ai == "其它") && subtype_rule == "中标") {
  414. if len(winnerorder) > 0 { //有中标候选人->中标
  415. return toptype_ai, "中标"
  416. }
  417. if s_winner != "" || data["bidamount"] != nil {
  418. return toptype_ai, "成交"
  419. }
  420. }
  421. }
  422. //2、招标、结果错误校正
  423. if toptype_ai != "结果" && toptype_rule == "结果" {
  424. //return toptype_rule,subtype_rule//默认规则为准
  425. if len(winnerorder) > 0 || s_winner != "" || data["bidamount"] != nil {
  426. return toptype_rule, subtype_rule
  427. } else {
  428. return toptype_ai, subtype_ai
  429. }
  430. } else if toptype_ai == "结果" && toptype_rule != "结果" && (subtype_ai == "中标" || subtype_ai == "成交") { //结果-变更
  431. //return toptype_rule,subtype_rule//默认规则为准
  432. if len(winnerorder) > 0 { //有中标候选人->中标
  433. return toptype_ai, "中标" //这里subtype返回"中标",避免ai识别错误
  434. } else if s_winner != "" || data["bidamount"] != nil {
  435. return toptype_ai, "成交" //这里subtype返回"成交",避免ai识别错误
  436. } else {
  437. return toptype_ai, subtype_ai
  438. }
  439. }
  440. return toptype_ai, subtype_ai
  441. }