company_type.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/xuri/excelize/v2"
  5. "log"
  6. "regexp"
  7. "strings"
  8. )
  9. // 循环外:私营企业code集合
  10. var privateCodes = map[string]bool{
  11. "1130": true, "1151": true, "1152": true, "1212": true, "1222": true,
  12. "2130": true, "2151": true, "2152": true, "2212": true, "2222": true,
  13. "4531": true, "4532": true, "4533": true, "4540": true, "4551": true,
  14. "4552": true, "4553": true, "4560": true,
  15. }
  16. // dealZhuTi 处理经营主体
  17. func dealZhuTi() {
  18. // 打开 Excel
  19. filePath := "经营主体类型.xlsx" // TODO: 改成真实的 xlsx 文件路径
  20. f, err := excelize.OpenFile(filePath)
  21. if err != nil {
  22. log.Fatalf("打开文件失败: %v", err)
  23. }
  24. // 假设只有一个 sheet
  25. sheetName := f.GetSheetName(0)
  26. // 先构造代码 -> 名称 map
  27. codeNameMap := make(map[string]string)
  28. rows, err := f.GetRows(sheetName)
  29. if err != nil {
  30. log.Fatalf("读取行失败: %v", err)
  31. }
  32. for idx, row := range rows {
  33. // 跳过表头
  34. if idx == 0 {
  35. continue
  36. }
  37. if len(row) < 2 {
  38. continue
  39. }
  40. code := strings.TrimSpace(row[0])
  41. name := strings.TrimSpace(row[1])
  42. // 替换中文括号为英文括号
  43. name = strings.ReplaceAll(name, "(", "(")
  44. name = strings.ReplaceAll(name, ")", ")")
  45. codeNameMap[code] = name
  46. }
  47. // 遍历数据行,新增四列
  48. for idx, row := range rows {
  49. if idx == 0 {
  50. // 表头
  51. _ = f.SetCellValue(sheetName, fmt.Sprintf("D%d", idx+1), "第一位名称")
  52. _ = f.SetCellValue(sheetName, fmt.Sprintf("E%d", idx+1), "第二位名称")
  53. _ = f.SetCellValue(sheetName, fmt.Sprintf("F%d", idx+1), "第三位名称")
  54. _ = f.SetCellValue(sheetName, fmt.Sprintf("G%d", idx+1), "第四位名称")
  55. _ = f.SetCellValue(sheetName, fmt.Sprintf("H%d", idx+1), "层级")
  56. _ = f.SetCellValue(sheetName, fmt.Sprintf("I%d", idx+1), "标签1")
  57. continue
  58. }
  59. if len(row) < 2 {
  60. continue
  61. }
  62. code := strings.TrimSpace(row[0])
  63. name := strings.TrimSpace(row[1])
  64. name = strings.ReplaceAll(name, "(", "(")
  65. name = strings.ReplaceAll(name, ")", ")")
  66. // 判断标签
  67. tag := "内资企业"
  68. if strings.HasPrefix(code, "5") || strings.HasPrefix(code, "7") || code == "8500" {
  69. tag = "外企"
  70. } else if strings.HasPrefix(code, "6") {
  71. tag = "外企-港澳台"
  72. } else if strings.HasPrefix(code, "91") || strings.HasPrefix(code, "92") {
  73. tag = "农合"
  74. } else if strings.HasPrefix(code, "95") {
  75. tag = "个体工商户"
  76. } else if privateCodes[code] {
  77. tag = "私营企业"
  78. }
  79. if len(code) != 4 {
  80. continue
  81. }
  82. // 层级判断
  83. level := 4
  84. if strings.HasSuffix(code, "000") {
  85. level = 1
  86. } else if strings.HasSuffix(code, "00") {
  87. level = 2
  88. } else if strings.HasSuffix(code, "0") {
  89. level = 3
  90. }
  91. // 各层级代码
  92. firstCode := code[:1] + "000"
  93. secondCode := code[:2] + "00"
  94. thirdCode := code[:3] + "0"
  95. fourthCode := code
  96. firstName := ""
  97. secondName := ""
  98. thirdName := ""
  99. fourthName := ""
  100. // 根据层级决定填哪些
  101. if level >= 1 {
  102. firstName = codeNameMap[firstCode]
  103. }
  104. if level >= 2 {
  105. secondName = codeNameMap[secondCode]
  106. }
  107. if level >= 3 {
  108. thirdName = codeNameMap[thirdCode]
  109. }
  110. if level == 4 {
  111. fourthName = codeNameMap[fourthCode]
  112. }
  113. // B列加缩进
  114. indent := strings.Repeat(" ", level-1) // 每层两个空格
  115. newName := indent + name
  116. rowNum := idx + 1
  117. // 写回新的名称到 B 列
  118. _ = f.SetCellValue(sheetName, fmt.Sprintf("B%d", rowNum), newName)
  119. // 写层级名称列
  120. _ = f.SetCellValue(sheetName, fmt.Sprintf("D%d", rowNum), firstName)
  121. _ = f.SetCellValue(sheetName, fmt.Sprintf("E%d", rowNum), secondName)
  122. _ = f.SetCellValue(sheetName, fmt.Sprintf("F%d", rowNum), thirdName)
  123. _ = f.SetCellValue(sheetName, fmt.Sprintf("G%d", rowNum), fourthName)
  124. _ = f.SetCellValue(sheetName, fmt.Sprintf("H%d", rowNum), level)
  125. _ = f.SetCellValue(sheetName, fmt.Sprintf("I%d", rowNum), tag)
  126. }
  127. // 保存新文件
  128. err = f.SaveAs("经营主体类型-result3.xlsx")
  129. if err != nil {
  130. log.Fatalf("保存文件失败: %v", err)
  131. }
  132. fmt.Println("处理完成,结果保存在 经营主体类型-result3.xlsx")
  133. }
  134. // matchCompanyType 根据企业类型,返回标准经营主体代码
  135. func matchCompanyType() {
  136. // ⚙️ Excel 文件名
  137. inputFile := "company_types.xlsx"
  138. outputFile := "company_types_out.xlsx"
  139. // 📂 打开 Excel 文件
  140. f, err := excelize.OpenFile(inputFile)
  141. if err != nil {
  142. log.Fatalf("无法打开文件: %v", err)
  143. }
  144. defer f.Close()
  145. // ✅ 加载经营主体类型 Sheet
  146. codeMap, err := loadCodeMap(f, "经营主体类型")
  147. nameMap, err := loadNameMap(f, "经营主体类型")
  148. if err != nil {
  149. log.Fatalf("加载经营主体类型失败: %v", err)
  150. }
  151. // 🔍 正则,用于提取4位数字
  152. re4 := regexp.MustCompile(`\d{4}`)
  153. // 📄 遍历 Sheet2
  154. sheetName := "Sheet2"
  155. rows, err := f.GetRows(sheetName)
  156. if err != nil {
  157. log.Fatalf("读取 Sheet2 失败: %v", err)
  158. }
  159. for idx, row := range rows {
  160. if len(row) == 0 {
  161. continue
  162. }
  163. originText := strings.TrimSpace(row[0])
  164. if originText == "" {
  165. continue
  166. }
  167. var code string
  168. // 去除引号
  169. cleanText := strings.ReplaceAll(originText, `"`, "")
  170. cleanText = strings.TrimSpace(cleanText)
  171. // 替换中文括号为英文括号
  172. cleanText = strings.ReplaceAll(cleanText, "(", "(")
  173. cleanText = strings.ReplaceAll(cleanText, ")", ")")
  174. cleanText = strings.ReplaceAll(cleanText, "外资比例低于25%", "")
  175. // 判断是不是日期(如 2008/10/31)
  176. if matched, _ := regexp.MatchString(`^\d{4}/\d{1,2}/\d{1,2}$`, cleanText); matched {
  177. log.Printf("跳过日期行: %s", cleanText)
  178. continue
  179. }
  180. // 如果包含“年”/“月”/“日”等,也跳过(不提取数字)
  181. if strings.Contains(cleanText, "年") || strings.Contains(cleanText, "月") || strings.Contains(cleanText, "日") {
  182. log.Printf("跳过含日期描述的行: %s", cleanText)
  183. continue
  184. }
  185. // 优先提取4位数字
  186. if m := re4.FindString(cleanText); m != "" {
  187. code = m
  188. } else {
  189. // 去除引号后完全匹配
  190. if c, ok := codeMap[cleanText]; ok {
  191. code = c
  192. }
  193. }
  194. //匹配不到时,需要 提取信息;然后重新匹配
  195. code = getCodeByCompanyType(cleanText, codeMap)
  196. // ✏️ 如果匹配到,就写到 B 列
  197. if code != "" {
  198. cell, _ := excelize.CoordinatesToCellName(2, idx+1) // B列
  199. cell2, _ := excelize.CoordinatesToCellName(3, idx+1) // B列
  200. if err := f.SetCellValue(sheetName, cell, code); err != nil {
  201. log.Printf("写入单元格失败 %s: %v", cell, err)
  202. }
  203. if err = f.SetCellValue(sheetName, cell2, nameMap[code]); err != nil {
  204. log.Printf("写入单元格失败 %s: %v", cell2, err)
  205. }
  206. } else {
  207. log.Printf("未匹配: %s", originText)
  208. }
  209. }
  210. // 💾 保存结果
  211. if err := f.SaveAs(outputFile); err != nil {
  212. log.Fatalf("保存文件失败: %v", err)
  213. }
  214. fmt.Printf("✅ 处理完成!输出文件:%s\n", outputFile)
  215. }
  216. // getCodeByCompanyType 根据企业类型,返回经营主体代码
  217. func getCodeByCompanyType(cleanText string, codeMap map[string]string) (code string) {
  218. if code == "" {
  219. //一人有限责任公司
  220. if strings.Contains(cleanText, "一人有限责任公司分公司") {
  221. cleanText = "一人有限责任公司分公司"
  222. } else if strings.Contains(cleanText, "一人有限责任公司") {
  223. cleanText = "一人有限责任公司"
  224. } else if cleanText == "有限责任(公司)" {
  225. cleanText = "有限责任公司"
  226. } else if cleanText == "上市股份有限公司分公司" {
  227. cleanText = "股份有限公司分公司(上市)"
  228. } else if cleanText == "上市股份有限公司分公司(非上市)" {
  229. cleanText = "股份有限公司分公司(非上市)"
  230. } else if !strings.Contains(cleanText, "非个人") && !strings.Contains(cleanText, "非个体") {
  231. if strings.Contains(cleanText, "个人") || strings.Contains(cleanText, "个体") || strings.Contains(cleanText, "户体商工个") {
  232. cleanText = "个体工商户"
  233. }
  234. } else if strings.Contains(cleanText, "中外合作") { // 中外合作企业 - 有限责任公司(中外合作)
  235. if strings.Contains(cleanText, "非公司外商投资企业(中外合作)") {
  236. cleanText = "非公司外商投资企业(中外合作)"
  237. } else {
  238. cleanText = "有限责任公司(中外合作)"
  239. }
  240. } else if strings.Contains(cleanText, "有限责任公司(中外合资)") { //有限责任公司(中外合资)
  241. cleanText = "有限责任公司(中外合资)"
  242. } else if strings.Contains(cleanText, "外商投资企业分支机构") { //非公司外商投资企业分支机构;外商投资企业分支机构
  243. if strings.Contains(cleanText, "非公司") {
  244. cleanText = "非公司外商投资企业分支机构"
  245. } else {
  246. cleanText = "外商投资企业分支机构"
  247. }
  248. } else if strings.Contains(cleanText, "其他") {
  249. //有限责任公司(港、澳、台)
  250. if strings.Contains(cleanText, "港、澳、台") {
  251. if strings.Contains(cleanText, "有限责任公司") {
  252. cleanText = "有限责任公司(港、澳、台)"
  253. } else if strings.Contains(cleanText, "非公司") {
  254. code = "6300"
  255. cleanText = "非公司"
  256. }
  257. }
  258. } else if strings.Contains(cleanText, "有限责任公司(台港澳与境内合作)") {
  259. cleanText = "有限责任公司(台港澳与境内合作)"
  260. } else if strings.Contains(cleanText, "有限责任公司(台港澳与境内合资)") {
  261. cleanText = "有限责任公司(台港澳与境内合资)"
  262. } else if strings.Contains(cleanText, "有限责任公司(台港澳与外国投资者合资)") {
  263. cleanText = "有限责任公司(台港澳与外国投资者合资)"
  264. } else if strings.Contains(cleanText, "有限责任公司(台港澳合资)") || (strings.Contains(cleanText, "台、港、澳资") && strings.Contains(cleanText, "有限责任公司")) {
  265. cleanText = "有限责任公司(台港澳合资)"
  266. } else if strings.Contains(cleanText, "有限责任公司(台港澳法人独资)") {
  267. cleanText = "有限责任公司(港澳台法人独资)"
  268. } else if strings.Contains(cleanText, "有限责任公司(台港澳自然人独资)") {
  269. cleanText = "有限责任公司(港澳台自然人独资)"
  270. } else if strings.Contains(cleanText, "有限责任公司(外商合资)") {
  271. cleanText = "有限责任公司(外商合资)"
  272. } else if strings.Contains(cleanText, "有限责任公司(外商投资") {
  273. cleanText = "有限责任公司(外商投资、非独资)"
  274. } else if strings.Contains(cleanText, "有限责任公司(外国法人独资)") {
  275. cleanText = "有限责任公司(外国法人独资)"
  276. } else if strings.Contains(cleanText, "外国非法人经济组织独资") {
  277. cleanText = "外国非法人经济组织独资"
  278. } else if strings.Contains(cleanText, "有限责任公司(外国自然人独资)") || strings.Contains(cleanText, "有限责任公司(外自然人独资)") {
  279. cleanText = "有限责任公司(外国自然人独资)"
  280. } else if strings.Contains(cleanText, "有限责任公司(法人独资)(外商投资企业投资)") {
  281. cleanText = "有限责任公司分公司(外商投资企业法人独资)"
  282. } else if strings.Contains(cleanText, "有限责任公司(港、澳、台)") || strings.Contains(cleanText, "有限责任公司(港澳台合资)") {
  283. cleanText = "有限责任公司(台港澳合资)"
  284. } else if strings.Contains(cleanText, "有限责任公司") || strings.Contains(cleanText, "港澳台与境内合作") {
  285. cleanText = "有限责任公司(台港澳与境内合作)"
  286. } else if strings.Contains(cleanText, "港澳台与境内合资") && strings.Contains(cleanText, "有限责任公司") {
  287. cleanText = "有限责任公司(台港澳与境内合资)"
  288. } else
  289. // 这个需要和贾老师确认
  290. if strings.Contains(cleanText, "有限责任公司(法人独资") && strings.Contains(cleanText, "私营") {
  291. cleanText = "有限责任公司(非自然人投资或控股的法人独资)"
  292. } else if strings.Contains(cleanText, "港澳台与外国投资者合资") && strings.Contains(cleanText, "有限责任公司") {
  293. cleanText = "有限责任公司(台港澳与外国投资者合资)"
  294. } else if strings.Contains(cleanText, "港澳台法人独资") && strings.Contains(cleanText, "有限责任公司") {
  295. cleanText = "有限责任公司(港澳台法人独资)"
  296. } else if strings.Contains(cleanText, "港澳台自然人独资") && strings.Contains(cleanText, "有限责任公司") {
  297. cleanText = "有限责任公司(港澳台自然人独资)"
  298. } else if strings.Contains(cleanText, "有限责任公司(港澳台非法人经济组织独资)") {
  299. cleanText = "有限责任公司(台港澳非法人经济组织独资)"
  300. } else if strings.Contains(cleanText, "港澳台投资、非独资") && strings.Contains(cleanText, "有限责任公司") {
  301. cleanText = "有限责任公司(港澳台投资、非独资)"
  302. } else if strings.Contains(cleanText, "港澳台合资") && strings.Contains(cleanText, "未上市") {
  303. if strings.Contains(cleanText, "股份有限公司") {
  304. code = "6230"
  305. }
  306. } else if strings.Contains(cleanText, "集体所有制") {
  307. cleanText = "集体所有制"
  308. } else if strings.Contains(cleanText, "国有独资") {
  309. if strings.Contains(cleanText, "有限责公司分公司") {
  310. cleanText = "有限责任公司分公司(国有独资)"
  311. } else if strings.Contains(cleanText, "有限责公司") {
  312. cleanText = "有限责任公司(国有独资)"
  313. }
  314. } else
  315. //台、港、澳
  316. if strings.Contains(cleanText, "台、港、澳") {
  317. if strings.Contains(cleanText, "台、港、澳分公司") || strings.Contains(cleanText, "台、港、澳投资企业分公司") || strings.Contains(cleanText, "台、港、澳投资公司分公司") {
  318. code = "6810"
  319. }
  320. if strings.Contains(cleanText, "台、港、澳办事处") {
  321. code = "6830"
  322. }
  323. if strings.Contains(cleanText, "台、港、澳投资企业") {
  324. code = "6000"
  325. }
  326. if strings.Contains(cleanText, "台、港、澳投资企业其他") {
  327. code = "6190"
  328. }
  329. } else if cleanText == "股份有限公司分支机构(台港澳与境内合资)" {
  330. code = "6220"
  331. } else if strings.Contains(cleanText, "台港澳投资企业办事处") {
  332. code = "6830"
  333. } else if strings.Contains(cleanText, "台港澳投资有限合伙企业") {
  334. code = "6400"
  335. } else if strings.Contains(cleanText, "台港澳投资普通合伙企业分支机构") {
  336. code = "6840"
  337. } else if strings.Contains(cleanText, "台港澳投资特殊普通合伙企业分支机构") {
  338. code = "6420"
  339. } else if strings.Contains(cleanText, "台港澳股份有限公司") {
  340. code = "6200"
  341. } else if strings.Contains(cleanText, "台港澳非公司") {
  342. code = "6300"
  343. } else if cleanText == "国外投资" {
  344. code = "5000"
  345. } else if strings.Contains(cleanText, "国有事业单位营业") {
  346. cleanText = "国有事业单位营业"
  347. } else if strings.Contains(cleanText, "国有控股") {
  348. if strings.Contains(cleanText, "非上市") {
  349. if strings.Contains(cleanText, "股份有限公司分公司") {
  350. code = "1223"
  351. }
  352. } else if strings.Contains(cleanText, "上市") {
  353. if strings.Contains(cleanText, "股份有限公司分公司") {
  354. code = "2213"
  355. cleanText = "股份有限公司分公司(上市、国有控股)"
  356. }
  357. } else if strings.Contains(cleanText, "股份有限公司分公司") {
  358. code = "2223"
  359. } else if strings.Contains(cleanText, "有限责任公司分公司") {
  360. code = "2140"
  361. } else if strings.Contains(cleanText, "有限责任公司") {
  362. code = "1140"
  363. }
  364. } else if strings.Contains(cleanText, "国有") {
  365. if strings.Contains(cleanText, "经营单位") && strings.Contains(cleanText, "非法人") {
  366. code = "4410"
  367. cleanText = "国有经营单位(非法人)"
  368. } else if strings.Contains(cleanText, "国有联营") {
  369. code = "4600"
  370. }
  371. } else
  372. //合伙企业
  373. if strings.Contains(cleanText, "合伙企业") {
  374. if strings.Contains(cleanText, "特殊普通合伙") {
  375. code = "4532"
  376. } else if strings.Contains(cleanText, "普通合伙") {
  377. code = "4530"
  378. } else if strings.Contains(cleanText, "有限合伙") {
  379. code = "4533"
  380. } else if strings.Contains(cleanText, "合伙企业分支机构") {
  381. code = "4550"
  382. }
  383. } else if strings.Contains(cleanText, "合伙私营企业") {
  384. code = "4530"
  385. } else if cleanText == "内资企业法人联营" {
  386. cleanText = "联营"
  387. } else
  388. //农民专业合作社分支机构
  389. if strings.Contains(cleanText, "合作社") {
  390. if strings.Contains(cleanText, "农民专业合作社分支机构") {
  391. cleanText = "农民专业合作社分支机构"
  392. } else if strings.Contains(cleanText, "农民专业合作社") {
  393. cleanText = "农民专业合作社"
  394. } else if strings.Contains(cleanText, "合作社分支机构") {
  395. cleanText = "农民专业合作社分支机构"
  396. } else {
  397. cleanText = "农民专业合作社"
  398. }
  399. } else if strings.Contains(cleanText, "非公司") {
  400. if strings.Contains(cleanText, "港、澳、台投资企业分支机构") {
  401. cleanText = "非公司台、港、澳投资企业分支机构"
  402. code = "6820"
  403. } else if strings.Contains(cleanText, "港、澳、台企业(港澳台合资)") {
  404. cleanText = "非公司台、港、澳企业(台港澳与境内合作)"
  405. code = "6310"
  406. } else if strings.Contains(cleanText, "非公司外商投资企业") && strings.Contains(cleanText, "其他") {
  407. code = "5390"
  408. }
  409. } else if strings.Contains(cleanText, "股份有限公司(上市公司)") {
  410. cleanText = "股份有限公司(上市)"
  411. code = "1210"
  412. } else if strings.Contains(cleanText, "股份有限公司(中外合资、上市)") {
  413. cleanText = "股份有限公司(中外合资、上市)"
  414. code = "5220"
  415. } else if strings.Contains(cleanText, "股份有限公司(中外合资、未上市)") || strings.Contains(cleanText, "股份有限公司(中外合资,未上市)") {
  416. cleanText = "股份有限公司(中外合资、未上市)"
  417. code = "5210"
  418. } else if cleanText == "股份有限公司(其他)" {
  419. code = "5290"
  420. } else if strings.Contains(cleanText, "股份有限公司(其他台港澳股份有限公司)") {
  421. code = "6290"
  422. } else if cleanText == "股份有限公司(台、港、澳资)" {
  423. code = "6270"
  424. } else if strings.Contains(cleanText, "股份有限公司(台港澳与境内合资、上市)") || strings.Contains(cleanText, "股份有限公司(台港澳与境内合资,上市)") {
  425. cleanText = "股份有限公司(台港澳与境内合资、上市)"
  426. code = "6220"
  427. } else if strings.Contains(cleanText, "股份有限公司(台港澳与境内合资、未上市)") {
  428. cleanText = "股份有限公司(台港澳与境内合资、未上市)"
  429. code = "6210"
  430. } else if strings.Contains(cleanText, "股份有限公司(台港澳与外国投资者合资、未上市)") {
  431. cleanText = "股份有限公司(台港澳与外国投资者合资、未上市)"
  432. code = "6250"
  433. } else if strings.Contains(cleanText, "股份有限公司(台港澳合资、上市)") {
  434. cleanText = "股份有限公司(台港澳合资、上市)"
  435. code = "6240"
  436. } else if strings.Contains(cleanText, "股份有限公司(台港澳合资、未上市)") {
  437. cleanText = "股份有限公司(台港澳合资、未上市)"
  438. code = "6230"
  439. } else if cleanText == "股份有限公司(港、澳、台)" {
  440. code = "6200"
  441. } else {
  442. }
  443. // 判断是不是日期(如 2008/10/31)
  444. if matched, _ := regexp.MatchString(`^\d{4}/\d{1,2}/\d{1,2}$`, cleanText); matched {
  445. log.Printf("跳过日期行: %s", cleanText)
  446. return
  447. }
  448. // 如果包含“年”/“月”/“日”等,也跳过(不提取数字)
  449. if strings.Contains(cleanText, "年") || strings.Contains(cleanText, "月") || strings.Contains(cleanText, "日") {
  450. log.Printf("跳过含日期描述的行: %s", cleanText)
  451. return
  452. }
  453. cleanText = strings.TrimSpace(cleanText)
  454. cleanText = strings.ReplaceAll(cleanText, "(", "(")
  455. cleanText = strings.ReplaceAll(cleanText, ")", ")")
  456. if code == "" {
  457. if c, ok := codeMap[cleanText]; ok {
  458. code = c
  459. }
  460. }
  461. }
  462. return code
  463. }
  464. // 📦 加载经营主体类型 Sheet,返回 名称=>代码 的映射
  465. func loadCodeMap(f *excelize.File, sheetName string) (map[string]string, error) {
  466. codeMap := make(map[string]string)
  467. rows, err := f.GetRows(sheetName)
  468. if err != nil {
  469. return nil, err
  470. }
  471. for idx, row := range rows {
  472. if idx == 0 {
  473. continue // 跳过表头
  474. }
  475. if len(row) >= 2 {
  476. name := strings.TrimSpace(row[1])
  477. code := strings.TrimSpace(row[0])
  478. // 替换中文括号为英文括号
  479. name = strings.ReplaceAll(name, "(", "(")
  480. name = strings.ReplaceAll(name, ")", ")")
  481. codeMap[name] = code
  482. }
  483. }
  484. return codeMap, nil
  485. }
  486. func loadNameMap(f *excelize.File, sheetName string) (map[string]string, error) {
  487. codeMap := make(map[string]string)
  488. rows, err := f.GetRows(sheetName)
  489. if err != nil {
  490. return nil, err
  491. }
  492. for idx, row := range rows {
  493. if idx == 0 {
  494. continue // 跳过表头
  495. }
  496. if len(row) >= 2 {
  497. name := strings.TrimSpace(row[1])
  498. code := strings.TrimSpace(row[0])
  499. // 替换中文括号为英文括号
  500. name = strings.ReplaceAll(name, "(", "(")
  501. name = strings.ReplaceAll(name, ")", ")")
  502. codeMap[code] = name
  503. }
  504. }
  505. return codeMap, nil
  506. }