global.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. (*update_info)["ext_ai_record"] = ext_ai_record
  25. //跨分类是否删除结果类字段
  26. if s_subtype == "单一" || s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" {
  27. } else {
  28. for k, _ := range Unset_Check {
  29. if tmp[k] != nil {
  30. return true
  31. }
  32. }
  33. }
  34. return false
  35. }
  36. // 选取分类
  37. func ChooseTheBestClassField(ai_zhipu map[string]interface{}, tmp map[string]interface{}, update_info *map[string]interface{}, ext_ai_record *map[string]interface{}) (string, string) {
  38. //分类字段···
  39. s_toptype, s_subtype := qu.ObjToString(ai_zhipu["s_toptype"]), qu.ObjToString(ai_zhipu["s_subtype"])
  40. ns_toptype, ns_subtype := CheckClassByOtherFileds(s_toptype, s_subtype, tmp)
  41. if ns_toptype != s_toptype || ns_subtype != s_subtype {
  42. (*ext_ai_record)["s_toptype"] = ns_toptype
  43. (*ext_ai_record)["s_subtype"] = ns_subtype
  44. }
  45. //赋值···
  46. s_toptype, s_subtype = ns_toptype, ns_subtype
  47. if qu.ObjToString(tmp["toptype"]) == "拟建" || qu.ObjToString(tmp["toptype"]) == "产权" {
  48. s_toptype = qu.ObjToString(tmp["toptype"])
  49. s_subtype = qu.ObjToString(tmp["subtype"])
  50. } else {
  51. if s_toptype != "" && s_subtype != "" {
  52. (*update_info)["toptype"] = s_toptype
  53. (*update_info)["subtype"] = s_subtype
  54. (*ext_ai_record)["toptype"] = tmp["toptype"]
  55. (*ext_ai_record)["subtype"] = tmp["subtype"]
  56. } else {
  57. s_toptype = qu.ObjToString(tmp["toptype"])
  58. s_subtype = qu.ObjToString(tmp["subtype"])
  59. }
  60. }
  61. return s_toptype, s_subtype
  62. }
  63. // 选取字段
  64. 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{}) {
  65. //基础字段···
  66. if s_buyer := qu.ObjToString(ai_zhipu["s_buyer"]); s_buyer != "" {
  67. (*update_info)["buyer"] = s_buyer
  68. (*ext_ai_record)["buyer"] = tmp["buyer"]
  69. if agency := qu.ObjToString(tmp["agency"]); agency != "" && agency == s_buyer {
  70. delete((*update_info), "buyer")
  71. delete((*ext_ai_record), "buyer")
  72. }
  73. }
  74. if s_projectname := qu.ObjToString(ai_zhipu["s_projectname"]); s_projectname != "" {
  75. (*update_info)["projectname"] = s_projectname
  76. (*ext_ai_record)["projectname"] = tmp["projectname"]
  77. }
  78. if s_projectcode := qu.ObjToString(ai_zhipu["s_projectcode"]); s_projectcode != "" {
  79. (*update_info)["projectcode"] = s_projectcode
  80. (*ext_ai_record)["projectcode"] = tmp["projectcode"]
  81. }
  82. if s_budget := qu.Float64All(ai_zhipu["s_budget"]); s_budget > 0.0 && s_budget < 1000000000.0 {
  83. (*update_info)["budget"] = s_budget
  84. (*ext_ai_record)["budget"] = tmp["budget"]
  85. }
  86. //地域字段···
  87. o_area, o_district := qu.ObjToString(tmp["area"]), qu.ObjToString(tmp["district"])
  88. s_area, s_city := qu.ObjToString(ai_zhipu["s_area"]), qu.ObjToString(ai_zhipu["s_city"])
  89. if s_area != "" && s_area != "全国" {
  90. (*update_info)["area"] = s_area
  91. if s_city != "" {
  92. (*update_info)["city"] = s_city
  93. if o_district != "" {
  94. //判断抽取的区县是否合理···
  95. isT := false
  96. if ds := S_DistrictDict[o_district]; ds != nil {
  97. for _, v := range ds {
  98. if v.C_Name == s_city && v.P_Name == s_area {
  99. isT = true
  100. break
  101. }
  102. }
  103. }
  104. if !isT {
  105. (*update_info)["district"] = ""
  106. }
  107. }
  108. } else {
  109. if o_area != s_area {
  110. (*update_info)["city"] = ""
  111. (*update_info)["district"] = ""
  112. }
  113. }
  114. (*ext_ai_record)["area"] = tmp["area"]
  115. (*ext_ai_record)["city"] = tmp["city"]
  116. (*ext_ai_record)["district"] = tmp["district"]
  117. }
  118. //先用外围字段替换
  119. if s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" || s_subtype == "单一" {
  120. if s_bidamount := qu.Float64All(ai_zhipu["s_bidamount"]); s_bidamount > 0.0 && s_bidamount < 1000000000.0 {
  121. (*update_info)["bidamount"] = s_bidamount
  122. (*ext_ai_record)["bidamount"] = tmp["bidamount"]
  123. }
  124. if s_winner := qu.ObjToString(ai_zhipu["s_winner"]); s_winner != "" {
  125. (*update_info)["s_winner"] = s_winner
  126. (*ext_ai_record)["s_winner"] = tmp["s_winner"]
  127. (*update_info)["winner"] = s_winner
  128. (*ext_ai_record)["winner"] = tmp["winner"]
  129. //对于winner来说...规则值有包含关系,采用规则值
  130. if winner := qu.ObjToString(tmp["winner"]); winner != "" {
  131. if strings.Contains(s_winner, winner) {
  132. delete((*update_info), "winner")
  133. delete((*ext_ai_record), "winner")
  134. }
  135. }
  136. }
  137. //旧版弃用
  138. //isRulePkg := false
  139. //if pkg := *qu.ObjToMap(tmp["package"]); len(pkg) > 1 && (s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同") {
  140. // if !staffInfo(pkg) {
  141. // isRulePkg = true
  142. // }
  143. //}
  144. //if isRulePkg { //优先采用大模型分包-值替换
  145. // if ispkg, ok := ai_zhipu["ispkg"].(bool); ispkg && ok {
  146. // if s_pkg := qu.ObjToMap(ai_zhipu["s_pkg"]); s_pkg != nil {
  147. // if p_winner := qu.ObjToString((*s_pkg)["s_winner"]); p_winner != "" {
  148. // (*update_check)["s_winner"] = p_winner
  149. // (*update_check)["winner"] = p_winner
  150. // ext_ai_record["s_winner"] = tmp["s_winner"]
  151. // ext_ai_record["winner"] = tmp["winner"]
  152. // }
  153. // if p_bidamount := qu.Float64All((*s_pkg)["s_bidamount"]); p_bidamount > 0.0 {
  154. // (*update_check)["bidamount"] = p_bidamount
  155. // ext_ai_record["bidamount"] = tmp["bidamount"]
  156. // }
  157. // if s_package := qu.ObjToMap((*s_pkg)["s_pkg"]); s_package != nil {
  158. // (*update_check)["package"] = s_package
  159. // ext_ai_record["package"] = tmp["package"]
  160. // }
  161. // }
  162. // }
  163. //}
  164. } else {
  165. }
  166. }
  167. // 选取分包
  168. 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{}) {
  169. //新分包判定···com_package - 默认大模型分包可信
  170. if s_pkg := qu.ObjToMap(ai_zhipu["s_pkg"]); s_pkg != nil {
  171. com_package := IsMarkInterfaceMap((*s_pkg)["com_package"])
  172. //是否替换外围字段···质谱外围是否已提取
  173. if len(com_package) > 1 { //多包字段覆盖
  174. //校验核对分包结构
  175. new_com_package := staffAiPackageInfo(com_package, s_toptype, s_subtype)
  176. (*update_info)["com_package"] = new_com_package
  177. if p_budget := qu.Float64All((*s_pkg)["s_budget"]); p_budget > 0.0 {
  178. (*update_info)["budget"] = p_budget
  179. (*ext_ai_record)["budget"] = tmp["budget"]
  180. }
  181. if s_subtype == "单一" || s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" {
  182. if p_winner := qu.ObjToString((*s_pkg)["s_winner"]); p_winner != "" {
  183. (*update_info)["s_winner"] = p_winner
  184. (*update_info)["winner"] = p_winner
  185. (*ext_ai_record)["s_winner"] = tmp["s_winner"]
  186. (*ext_ai_record)["winner"] = tmp["winner"]
  187. //对于winner来说...规则值有包含关系,采用规则值应用判重
  188. if winner := qu.ObjToString(tmp["winner"]); winner != "" {
  189. if strings.Contains(p_winner, winner) {
  190. delete((*update_info), "winner")
  191. delete((*ext_ai_record), "winner")
  192. }
  193. }
  194. }
  195. if p_bidamount := qu.Float64All((*s_pkg)["s_bidamount"]); p_bidamount > 0.0 {
  196. (*update_info)["bidamount"] = p_bidamount
  197. (*ext_ai_record)["bidamount"] = tmp["bidamount"]
  198. }
  199. }
  200. } else if len(com_package) == 1 { //单包字段覆盖
  201. if p_budget := qu.Float64All((*s_pkg)["s_budget"]); p_budget > 0.0 && (*update_info)["budget"] == nil {
  202. (*update_info)["budget"] = p_budget
  203. (*ext_ai_record)["budget"] = tmp["budget"]
  204. }
  205. if s_subtype == "单一" || s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" {
  206. if p_winner := qu.ObjToString((*s_pkg)["s_winner"]); p_winner != "" && (*update_info)["s_winner"] == nil {
  207. (*update_info)["s_winner"] = p_winner
  208. (*update_info)["winner"] = p_winner
  209. (*ext_ai_record)["s_winner"] = tmp["s_winner"]
  210. (*ext_ai_record)["winner"] = tmp["winner"]
  211. //对于winner来说...规则值有包含关系,采用规则值应用判重
  212. if winner := qu.ObjToString(tmp["winner"]); winner != "" {
  213. if strings.Contains(p_winner, winner) {
  214. delete((*update_info), "winner")
  215. delete((*ext_ai_record), "winner")
  216. }
  217. }
  218. }
  219. if p_bidamount := qu.Float64All((*s_pkg)["s_bidamount"]); p_bidamount > 0.0 && (*update_info)["bidamount"] == nil {
  220. (*update_info)["bidamount"] = p_bidamount
  221. (*ext_ai_record)["bidamount"] = tmp["bidamount"]
  222. }
  223. }
  224. } else {
  225. }
  226. }
  227. }
  228. // 选取金额
  229. func ChooseTheBestAmountField(tmp map[string]interface{}, update_info *map[string]interface{}) {
  230. if r_budget := qu.Float64All((*update_info)["budget"]); r_budget > 0.0 && r_budget < 1000000000.0 {
  231. if o_budget := qu.Float64All(tmp["budget"]); o_budget > 0.0 {
  232. if r_budget/o_budget == 10000.0 || o_budget/r_budget == 10000.0 {
  233. (*update_info)["budget"] = filterAmount(r_budget, o_budget)
  234. }
  235. }
  236. }
  237. if r_bidamount := qu.Float64All((*update_info)["bidamount"]); r_bidamount > 0.0 && r_bidamount < 1000000000.0 {
  238. if o_bidamount := qu.Float64All(tmp["bidamount"]); o_bidamount > 0.0 {
  239. if r_bidamount/o_bidamount == 10000.0 || o_bidamount/r_bidamount == 10000.0 {
  240. (*update_info)["bidamount"] = filterAmount(r_bidamount, o_bidamount)
  241. }
  242. }
  243. }
  244. }
  245. // 筛选金额
  246. func filterAmount(f1 float64, f2 float64) float64 {
  247. //选取一个合适的金额 ...
  248. if f1 > f2 {
  249. if f1 > 100000000.0 {
  250. return f2
  251. } else {
  252. return f1
  253. }
  254. } else if f1 < f2 {
  255. if f2 > 100000000.0 {
  256. return f1
  257. } else {
  258. return f2
  259. }
  260. } else {
  261. return f1
  262. }
  263. }
  264. // 核算分包信息
  265. func staffInfo(pkg map[string]interface{}) bool {
  266. //鉴定中标单位
  267. is_w := 0
  268. for _, v := range pkg {
  269. info := *qu.ObjToMap(v)
  270. if winner := qu.ObjToString(info["winner"]); winner != "" {
  271. is_w++
  272. }
  273. }
  274. //鉴定中标金额
  275. is_b := 0
  276. for _, v := range pkg {
  277. info := *qu.ObjToMap(v)
  278. if bidamount := qu.Float64All(info["bidamount"]); bidamount > 0.0 {
  279. is_b++
  280. }
  281. }
  282. if is_w != len(pkg) && is_w > 0 {
  283. return false
  284. }
  285. if is_b != len(pkg) && is_b > 0 {
  286. return false
  287. }
  288. if is_w == 0 || is_b == 0 {
  289. return false
  290. }
  291. return true
  292. }
  293. // 核对ai分包
  294. func staffAiPackageInfo(com_package []map[string]interface{}, s_toptype string, s_subtype string) []map[string]interface{} {
  295. if s_subtype == "单一" || s_subtype == "中标" || s_subtype == "成交" || s_subtype == "合同" {
  296. return com_package
  297. }
  298. new_com_package := []map[string]interface{}{}
  299. for _, v := range com_package {
  300. delete(v, "winner")
  301. delete(v, "bidamount")
  302. new_com_package = append(new_com_package, v)
  303. }
  304. return new_com_package
  305. }
  306. // 核对分类
  307. func CheckClassByOtherFileds(toptype_ai, subtype_ai string, data map[string]interface{}) (string, string) {
  308. toptype_rule := qu.ObjToString(data["toptype"])
  309. subtype_rule := qu.ObjToString(data["subtype"])
  310. //1、结果类 中标和成交错误校正
  311. s_winner := qu.ObjToString(data["s_winner"])
  312. winnerorder := IsMarkInterfaceMap(data["winnerorder"])
  313. if toptype_ai == "结果" && toptype_rule == "结果" {
  314. if subtype_ai == "成交" && subtype_rule == "成交" && len(winnerorder) > 0 { //规则、大模型都错
  315. return "结果", "中标"
  316. }
  317. if ((subtype_ai == "中标" || subtype_ai == "其它") && subtype_rule == "成交") || ((subtype_ai == "成交" || subtype_ai == "其它") && subtype_rule == "中标") {
  318. if len(winnerorder) > 0 { //有中标候选人->中标
  319. return toptype_ai, "中标"
  320. }
  321. if s_winner != "" || data["bidamount"] != nil {
  322. return toptype_ai, "成交"
  323. }
  324. }
  325. }
  326. //2、招标、结果错误校正
  327. if toptype_ai != "结果" && toptype_rule == "结果" {
  328. //return toptype_rule,subtype_rule//默认规则为准
  329. if len(winnerorder) > 0 || s_winner != "" || data["bidamount"] != nil {
  330. return toptype_rule, subtype_rule
  331. } else {
  332. return toptype_ai, subtype_ai
  333. }
  334. } else if toptype_ai == "结果" && toptype_rule != "结果" && (subtype_ai == "中标" || subtype_ai == "成交") { //结果-变更
  335. //return toptype_rule,subtype_rule//默认规则为准
  336. if len(winnerorder) > 0 { //有中标候选人->中标
  337. return toptype_ai, "中标" //这里subtype返回"中标",避免ai识别错误
  338. } else if s_winner != "" || data["bidamount"] != nil {
  339. return toptype_ai, "成交" //这里subtype返回"成交",避免ai识别错误
  340. } else {
  341. return toptype_ai, subtype_ai
  342. }
  343. }
  344. return toptype_ai, subtype_ai
  345. }