global.go 13 KB

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