@@ -23,109 +23,113 @@ type ENSMap struct {
2323}
2424
2525// ENSMapLN 最终统一导出格式
26- var ENSMapLN = map [string ]* ENSMap {
26+ var ENSMapLN = map [string ]* EnsGo {
2727 "enterprise_info" : {
2828 Name : "企业信息" ,
29- JField : []string {"name" , "legal_person" , "status" , "phone" , "email" , "registered_capital" , "incorporation_date" , "address" , "scope" , "reg_code" , "pid" },
29+ Field : []string {"name" , "legal_person" , "status" , "phone" , "email" , "registered_capital" , "incorporation_date" , "address" , "scope" , "reg_code" , "pid" },
3030 KeyWord : []string {"企业名称" , "法人代表" , "经营状态" , "电话" , "邮箱" , "注册资本" , "成立日期" , "注册地址" , "经营范围" , "统一社会信用代码" , "PID" },
3131 },
3232 "icp" : {
3333 Name : "ICP备案" ,
34- Only : "domain" ,
35- JField : []string {"website_name" , "website" , "domain" , "icp" , "company_name" },
34+ Field : []string {"website_name" , "website" , "domain" , "icp" , "company_name" },
3635 KeyWord : []string {"网站名称" , "网址" , "域名" , "网站备案/许可证号" , "公司名称" },
3736 },
3837 "wx_app" : {
3938 Name : "微信小程序" ,
40- JField : []string {"name" , "category" , "logo" , "qrcode" , "read_num" },
39+ Field : []string {"name" , "category" , "logo" , "qrcode" , "read_num" },
4140 KeyWord : []string {"名称" , "分类" , "头像" , "二维码" , "阅读量" },
4241 },
4342 "wechat" : {
4443 Name : "微信公众号" ,
45- JField : []string {"name" , "wechat_id" , "description" , "qrcode" , "avatar" },
44+ Field : []string {"name" , "wechat_id" , "description" , "qrcode" , "avatar" },
4645 KeyWord : []string {"名称" , "ID" , "简介" , "二维码" , "头像" },
4746 },
4847 "weibo" : {
4948 Name : "微博" ,
50- JField : []string {"name" , "profile_url" , "description" , "avatar" },
49+ Field : []string {"name" , "profile_url" , "description" , "avatar" },
5150 KeyWord : []string {"微博昵称" , "链接" , "简介" , "头像" },
5251 },
5352 "supplier" : {
5453 Name : "供应商" ,
55- JField : []string {"name" , "scale" , "amount" , "report_time" , "data_source" , "relation" , "pid" },
54+ Field : []string {"name" , "scale" , "amount" , "report_time" , "data_source" , "relation" , "pid" },
5655 KeyWord : []string {"名称" , "金额占比" , "金额" , "报告期/公开时间" , "数据来源" , "关联关系" , "PID" },
5756 },
5857 "job" : {
5958 Name : "招聘" ,
60- JField : []string {"name" , "education" , "location" , "publish_time" , "salary" },
59+ Field : []string {"name" , "education" , "location" , "publish_time" , "salary" },
6160 KeyWord : []string {"招聘职位" , "学历" , "办公地点" , "发布日期" , "薪资" },
6261 },
6362 "invest" : {
6463 Name : "投资" ,
65- JField : []string {"name" , "legal_person" , "status" , "scale" , "pid" },
64+ Field : []string {"name" , "legal_person" , "status" , "scale" , "pid" },
6665 KeyWord : []string {"企业名称" , "法人" , "状态" , "投资比例" , "PID" },
6766 },
6867 "branch" : {
6968 Name : "分支机构" ,
70- JField : []string {"name" , "legal_person" , "status" , "pid" },
69+ Field : []string {"name" , "legal_person" , "status" , "pid" },
7170 KeyWord : []string {"企业名称" , "法人" , "状态" , "PID" },
7271 },
7372 "holds" : {
7473 Name : "控股企业" ,
75- JField : []string {"name" , "legal_person" , "status" , "scale" , "level" , "pid" },
74+ Field : []string {"name" , "legal_person" , "status" , "scale" , "level" , "pid" },
7675 KeyWord : []string {"企业名称" , "法人" , "状态" , "投资比例" , "持股层级" , "PID" },
7776 },
7877 "app" : {
7978 Name : "APP" ,
80- JField : []string {"name" , "category" , "version" , "update_at" , "description" , "logo" , "bundle_id" , "link" , "market" },
79+ Field : []string {"name" , "category" , "version" , "update_at" , "description" , "logo" , "bundle_id" , "link" , "market" },
8180 KeyWord : []string {"名称" , "分类" , "当前版本" , "更新时间" , "简介" , "logo" , "Bundle ID" , "链接" , "market" },
8281 },
8382 "copyright" : {
8483 Name : "软件著作权" ,
85- JField : []string {"name" , "short_name" , "category" , "reg_num" , "pub_type" },
84+ Field : []string {"name" , "short_name" , "category" , "reg_num" , "pub_type" },
8685 KeyWord : []string {"软件全称" , "软件简称" , "分类" , "登记号" , "权利取得方式" },
8786 },
8887 "partner" : {
8988 Name : "股东信息" ,
90- JField : []string {"name" , "scale" , "reg_cap" , "pid" },
89+ Field : []string {"name" , "scale" , "reg_cap" , "pid" },
9190 KeyWord : []string {"股东名称" , "持股比例" , "认缴出资金额" , "PID" },
9291 },
9392}
9493
94+ func DataToMap (info []gjson.Result , en * EnsGo , em * EnsGo , ext string ) (res []map [string ]string ) {
95+ for _ , v := range info {
96+ strData := make (map [string ]string , len (em .Field )+ 1 )
97+ // 获取字段值并转换为字符串
98+ for i , field := range em .Field {
99+ // 判断是否最后一位字符,如果是那就是要加入from字段的
100+ if i == len (em .Field )- 1 && i >= len (en .Field ) {
101+ strData ["ref" ] = v .Get (field ).String ()
102+ } else {
103+ strData [en.Field [i ]] = v .Get (field ).String ()
104+ }
105+ }
106+ // 添加额外信息,用于后期展示
107+ strData ["extra" ] = ext
108+ res = append (res , strData )
109+ }
110+ return res
111+ }
112+
95113// InfoToMap 将输出的json转为统一map格式
96114func InfoToMap (infos map [string ][]gjson.Result , enMap map [string ]* EnsGo , extraInfo string ) (res map [string ][]map [string ]string ) {
97115 res = make (map [string ][]map [string ]string )
98116 for k , info := range infos {
99- en := ENSMapLN [k ].JField
100- // 分类信息
101- var data []map [string ]string
102- for _ , v := range info {
103- strData := make (map [string ]string , len (enMap [k ].Field )+ 1 )
104- // 获取字段值并转换为字符串
105- for i , field := range enMap [k ].Field {
106- if i == len (enMap [k ].Field )- 1 && i >= len (en ) {
107- strData ["from" ] = v .Get (field ).String ()
108- } else {
109- strData [en [i ]] = v .Get (field ).String ()
110- }
111- }
112- // 添加额外信息,用于后期展示
113- strData ["extra" ] = extraInfo
114- data = append (data , strData )
117+ // 判断是否有这个类型,有时候数据可能会比较混杂
118+ if _ , ok := enMap [k ]; ! ok {
119+ continue
115120 }
116- // 信息全部存入
117- res [k ] = data
121+ res [k ] = DataToMap (info , ENSMapLN [k ], enMap [k ], extraInfo )
118122 }
119123 return res
120124}
121125
122126func OutStrByEnInfo (data map [string ][]map [string ]string , types string ) (str string ) {
123127 var builder strings.Builder
124128 s := data [types ]
125- em := ENSMapLN [types ].JField
129+ em := ENSMapLN [types ].Field
126130 for _ , m := range s {
127131 first := true
128- for _ , key := range append (em , "from " , "extra" ) {
132+ for _ , key := range append (em , "ref " , "extra" ) {
129133 if ! first { // 如果不是第一个元素,则先写入逗号
130134 builder .WriteString ("," )
131135 }
@@ -139,6 +143,23 @@ func OutStrByEnInfo(data map[string][]map[string]string, types string) (str stri
139143 return str
140144}
141145
146+ func OriginalToMapList (infos []gjson.Result , em * EnsGo ) (res []map [string ]string ) {
147+ for _ , info := range infos {
148+ res = append (res , OriginalToMap (info , em ))
149+ }
150+ return res
151+ }
152+
153+ func OriginalToMap (info gjson.Result , em * EnsGo ) (res map [string ]string ) {
154+ // 获取字段值并转换为字符串
155+ res = make (map [string ]string )
156+ for _ , field := range em .Field {
157+ // 判断是否最后一位字符,如果是那就是要加入from字段的
158+ res [field ] = info .Get (field ).String ()
159+ }
160+ return res
161+ }
162+
142163func OutFileByEnInfo (data map [string ][]map [string ]string , name string , types string , dir string ) (err error ) {
143164 if dir == "!" {
144165 gologger .Debug ().Str ("设定DIR" , dir ).Msgf ("不导出文件" )
@@ -182,7 +203,7 @@ func OutFileByEnInfo(data map[string][]map[string]string, name string, types str
182203 for i , m := range v {
183204 if len (m ) > 0 {
184205 // 把信息全部提取出来,转为interface
185- for _ , p := range append (em .JField , "from " , "extra" ) {
206+ for _ , p := range append (em .Field , "ref " , "extra" ) {
186207 exData [i ] = append (exData [i ], m [p ])
187208 }
188209 }
0 commit comments