c_deepseek.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. package clean
  2. import (
  3. "data_ai/ul"
  4. "github.com/google/uuid"
  5. "github.com/shopspring/decimal"
  6. qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  7. "strings"
  8. )
  9. var DSToptype = map[string]map[string]string{
  10. "招标公告": { //招标
  11. "单一来源公告": "单一",
  12. "询价公告": "询价",
  13. "竞价公告": "竞价",
  14. "邀标公告": "邀标",
  15. "竞争谈判公告": "竞谈",
  16. "变更公告": "变更",
  17. "招标公告": "招标",
  18. },
  19. "结果公告": { //其它
  20. "中标公告": "中标",
  21. "候选公告": "中标",
  22. "成交公告": "成交",
  23. "变更公告": "结果变更",
  24. "结果其它公告": "其它",
  25. "废标公告": "废标",
  26. "流标公告": "流标",
  27. },
  28. "预告公告": { //预告
  29. "预告公告": "预告",
  30. "预审公告": "预审",
  31. "预审结果公告": "预审结果",
  32. "论证意见公告": "论证意见",
  33. "需求公示公告": "需求公示",
  34. },
  35. }
  36. // 清洗新模型····
  37. func CleanDeepSeekInfo(ai_info map[string]interface{}, tmp map[string]interface{}) map[string]interface{} {
  38. fns := getfnsinfo(tmp)
  39. zhipu := *qu.ObjToMap(ai_info["任务1"])
  40. data := map[string]interface{}{}
  41. //重点字段
  42. if s_area, s_city := CleanRegion(qu.ObjToString(zhipu["省份"]), qu.ObjToString(zhipu["城市"])); s_area != "" || s_city != "" {
  43. data["s_area"] = s_area
  44. data["s_city"] = s_city
  45. }
  46. if s_buyer := CleanBuyer(qu.ObjToString(zhipu["采购单位"])); s_buyer != "" {
  47. data["s_buyer"] = s_buyer
  48. }
  49. if s_pname := CleanPname(qu.ObjToString(zhipu["项目名称"])); s_pname != "" {
  50. data["s_projectname"] = s_pname
  51. }
  52. if s_pcode := CleanPcode(qu.ObjToString(zhipu["项目编号"]), fns); s_pcode != "" {
  53. data["s_projectcode"] = s_pcode
  54. }
  55. if s_biddingcode := CleanOtherCode(qu.ObjToString(zhipu["招标编号"])); s_biddingcode != "" {
  56. data["s_biddingcode"] = s_biddingcode
  57. }
  58. if s_packagecode := CleanOtherCode(qu.ObjToString(zhipu["标段编号"])); s_packagecode != "" {
  59. data["s_packagecode"] = s_packagecode
  60. }
  61. if s_contractcode := CleanOtherCode(qu.ObjToString(zhipu["合同编号"])); s_contractcode != "" {
  62. data["s_contractcode"] = s_contractcode
  63. }
  64. if s_budget, s_budget_unit := CleanMoney([]interface{}{zhipu["预算金额"], ""}); s_budget > 0.0 && s_budget < 1000000000.0 {
  65. if !s_budget_unit {
  66. if n_s_budget := ConvertMoney(s_budget, qu.ObjToString(zhipu["预算金额单位"])); n_s_budget > 0.0 && n_s_budget < 1000000000.0 {
  67. data["s_budget"] = n_s_budget
  68. } else {
  69. data["s_budget"] = s_budget
  70. }
  71. } else {
  72. data["s_budget"] = s_budget
  73. }
  74. }
  75. if s_bidamount, s_bidamount_unit := CleanMoney([]interface{}{zhipu["中标金额"], ""}); s_bidamount > 0.0 && s_bidamount < 1000000000.0 {
  76. if !s_bidamount_unit {
  77. if n_s_bidamount := ConvertMoney(s_bidamount, qu.ObjToString(zhipu["中标金额单位"])); n_s_bidamount > 0.0 && n_s_bidamount < 1000000000.0 {
  78. data["s_bidamount"] = n_s_bidamount
  79. } else {
  80. data["s_bidamount"] = s_bidamount
  81. }
  82. } else {
  83. data["s_bidamount"] = s_bidamount
  84. }
  85. }
  86. if s_agency := CleanAgency(qu.ObjToString(zhipu["代理机构"])); s_agency != "" {
  87. data["s_agency"] = s_agency
  88. }
  89. if s_winner := CleanWinner(qu.ObjToString(zhipu["中标单位"])); s_winner != "" {
  90. data["s_winner"] = s_winner
  91. }
  92. //其他字段
  93. if s_bidopenaddress := CleanOtherName(qu.ObjToString(zhipu["开标地点"])); s_bidopenaddress != "" {
  94. data["s_bidopenaddress"] = s_bidopenaddress
  95. }
  96. if s_biddiscount := CleanDiscount(qu.ObjToString(zhipu["中标金额折扣率"])); s_biddiscount > 0.0 {
  97. data["s_biddiscount"] = s_biddiscount
  98. }
  99. //时间相关
  100. if s_bidopentime := CleanTime(qu.ObjToString(zhipu["开标日期"])); s_bidopentime > 0 {
  101. data["s_bidopentime"] = s_bidopentime
  102. }
  103. if s_bidendtime := CleanTime(qu.ObjToString(zhipu["投标截止时间"])); s_bidendtime > 0 {
  104. data["s_bidendtime"] = s_bidendtime
  105. }
  106. if s_docstarttime := CleanTime(qu.ObjToString(zhipu["招标文件获取开始时间"])); s_docstarttime > 0 {
  107. data["s_docstarttime"] = s_docstarttime
  108. }
  109. if s_docendtime := CleanTime(qu.ObjToString(zhipu["招标文件获取结束时间"])); s_docendtime > 0 {
  110. data["s_docendtime"] = s_docendtime
  111. }
  112. //联系方式方式
  113. if s_buyerperson := CleanContactPerson(qu.ObjToString(zhipu["采购单位联系人"])); s_buyerperson != "" {
  114. data["s_buyerperson"] = s_buyerperson
  115. }
  116. if s_buyertel := CleanContactTel(qu.ObjToString(zhipu["采购单位联系方式"])); s_buyertel != "" {
  117. data["s_buyertel"] = s_buyertel
  118. }
  119. if s_agencyperson := CleanContactPerson(qu.ObjToString(zhipu["代理机构联系人"])); s_agencyperson != "" {
  120. data["s_agencyperson"] = s_agencyperson
  121. }
  122. if s_agencytel := CleanContactTel(qu.ObjToString(zhipu["代理机构联系方式"])); s_agencytel != "" {
  123. data["s_agencytel"] = s_agencytel
  124. }
  125. if s_winnerperson := CleanContactPerson(qu.ObjToString(zhipu["中标单位联系人"])); s_winnerperson != "" {
  126. data["s_winnerperson"] = s_winnerperson
  127. }
  128. if s_winnertel := CleanContactTel(qu.ObjToString(zhipu["中标单位联系方式"])); s_winnertel != "" {
  129. data["s_winnertel"] = s_winnertel
  130. }
  131. //标的物字段
  132. if zhipu["s_purchasinglist"] != nil {
  133. data["s_purchasinglist"] = zhipu["s_purchasinglist"]
  134. }
  135. //分类字段
  136. //o_toptype, _ := qu.ObjToString(tmp["toptype"]), qu.ObjToString(tmp["subtype"])
  137. //ts_type := *qu.ObjToMap(ai_info["任务2"])
  138. //toptype_ai, subtype_ai := qu.ObjToString(ts_type["一级分类"]), qu.ObjToString(ts_type["二级分类"])
  139. //new_toptype, new_subtype := TopSubConvert(o_toptype, toptype_ai, subtype_ai)
  140. //if new_toptype != "" && new_subtype != "" {
  141. // data["s_toptype"] = new_toptype
  142. // data["s_subtype"] = new_subtype
  143. //}
  144. //解析分包···
  145. p_info := *qu.ObjToMap(ai_info["任务2"])
  146. if pkg := PackageConvert(p_info); len(pkg) > 0 {
  147. data["s_pkg"] = pkg
  148. }
  149. //最终根据分类-删除
  150. return data
  151. }
  152. // 转换分包
  153. func PackageConvert(res map[string]interface{}) map[string]interface{} {
  154. //转格式...
  155. if res == nil {
  156. return map[string]interface{}{}
  157. }
  158. ai_pkg := map[string]interface{}{}
  159. s_winner, s_bidamount, s_budget, com_package := "", 0.0, 0.0, []map[string]interface{}{}
  160. win_arr, win_temp := []string{}, map[string]string{}
  161. pkginfo := ul.IsMarkInterfaceMap(res["分包信息"])
  162. for _, v := range pkginfo {
  163. name := qu.ObjToString(v["标段名称"])
  164. code := qu.ObjToString(v["标段/包号"])
  165. winner := CleanWinner(qu.ObjToString(v["中标单位"]))
  166. bidamount, bidamount_unit := CleanMoney([]interface{}{v["中标金额"], ""})
  167. budget, budget_unit := CleanMoney([]interface{}{v["预算金额"], ""})
  168. if !bidamount_unit {
  169. bidamount = ConvertMoney(bidamount, qu.ObjToString(v["中标金额单位"]))
  170. }
  171. if !budget_unit {
  172. budget = ConvertMoney(budget, qu.ObjToString(v["预算金额单位"]))
  173. }
  174. if bidamount > 1000000000.0 {
  175. bidamount = 0.0
  176. }
  177. if budget > 1000000000.0 {
  178. budget = 0.0
  179. }
  180. //各种编号编号
  181. projectcode := CleanPcode(qu.ObjToString(v["项目编号"]), []string{})
  182. packagecode := CleanOtherCode(qu.ObjToString(v["标段编号"]))
  183. contractcode := CleanOtherCode(qu.ObjToString(v["合同编号"]))
  184. //分包信息结构
  185. package_id := uuid.New().String()
  186. package_id = strings.ReplaceAll(package_id, "-", "")
  187. p := map[string]interface{}{
  188. "package_id": package_id,
  189. "name": name,
  190. "code": code,
  191. "budget": budget,
  192. "winner": winner,
  193. "bidamount": bidamount,
  194. "projectcode": projectcode,
  195. "packagecode": packagecode,
  196. "contractcode": contractcode,
  197. }
  198. com_package = append(com_package, p)
  199. //去重计算单位与总金额-精度丢失···
  200. s_bid1 := decimal.NewFromFloat(s_bidamount)
  201. s_bid2 := decimal.NewFromFloat(bidamount)
  202. s_bid_add := s_bid1.Add(s_bid2)
  203. s_bidamount, _ = s_bid_add.Float64()
  204. s_bud1 := decimal.NewFromFloat(s_budget)
  205. s_bud2 := decimal.NewFromFloat(budget)
  206. s_bud_add := s_bud1.Add(s_bud2)
  207. s_budget, _ = s_bud_add.Float64()
  208. if win_temp[winner] == "" && winner != "" {
  209. win_arr = append(win_arr, winner)
  210. win_temp[winner] = winner
  211. }
  212. }
  213. s_winner = strings.Join(win_arr, ",")
  214. ai_pkg["s_winner"] = s_winner
  215. ai_pkg["s_bidamount"] = s_bidamount
  216. ai_pkg["s_budget"] = s_budget
  217. ai_pkg["com_package"] = com_package
  218. return ai_pkg
  219. }
  220. // 分类校验···
  221. func TopSubConvert(old_toptype string, toptype_ai string, subtype_ai string) (string, string) {
  222. if old_toptype == "拟建" {
  223. return "拟建", "拟建"
  224. } else if old_toptype == "产权" {
  225. return "产权", "产权"
  226. } else if old_toptype == "采购意向" {
  227. return "采购意向", "采购意向"
  228. } else {
  229. }
  230. if toptype_ai == "采购意向公告" {
  231. return "采购意向", "采购意向"
  232. } else if toptype_ai == "合同公告" {
  233. return "其它", "合同"
  234. } else if toptype_ai == "验收公告" {
  235. return "其它", "验收"
  236. } else if toptype_ai == "违规公告" {
  237. return "其它", "违规"
  238. } else {
  239. }
  240. //映射大模型识别的分类
  241. new_toptype, new_subtype := "", ""
  242. Sub := DSToptype[toptype_ai]
  243. if Sub != nil {
  244. if toptype_ai == "招标公告" {
  245. new_toptype = "招标"
  246. if Sub[subtype_ai] != "" {
  247. new_subtype = Sub[subtype_ai]
  248. } else {
  249. new_subtype = "招标"
  250. }
  251. } else if toptype_ai == "结果公告" {
  252. new_toptype = "结果"
  253. if Sub[subtype_ai] != "" {
  254. new_subtype = Sub[subtype_ai]
  255. } else {
  256. new_subtype = "其它"
  257. }
  258. } else if toptype_ai == "预告公告" {
  259. new_toptype = "预告"
  260. if Sub[subtype_ai] != "" {
  261. new_subtype = Sub[subtype_ai]
  262. } else {
  263. new_subtype = "预告"
  264. }
  265. } else {
  266. }
  267. }
  268. return new_toptype, new_subtype
  269. }
  270. // 获取附件名字信息
  271. func getfnsinfo(tmp map[string]interface{}) []string {
  272. arr := []string{}
  273. if projectinfo := qu.ObjToMap(tmp["projectinfo"]); projectinfo != nil {
  274. if attachments := qu.ObjToMap((*projectinfo)["attachments"]); attachments != nil {
  275. for _, v := range *attachments {
  276. if info := qu.ObjToMap(v); info != nil {
  277. if filename := qu.ObjToString((*info)["filename"]); filename != "" {
  278. arr = append(arr, filename)
  279. }
  280. }
  281. }
  282. }
  283. }
  284. return arr
  285. }