task.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/cron"
  6. "github.com/wangbin/jiebago"
  7. "go.mongodb.org/mongo-driver/bson"
  8. "qfw/util"
  9. "qfw/util/redis"
  10. "regexp"
  11. "strings"
  12. "sync"
  13. "time"
  14. )
  15. var (
  16. AreaFiled = []string{"credit_no", "company_code"}
  17. WordsArr = []string{"研发", "研制", "开发", "生产", "制造", "制作", "加工", "种植"}
  18. seg jiebago.Segmenter
  19. regPre, _ = regexp.Compile(`^(.+[省|市|区|县|州])?(.+)`)
  20. )
  21. // 企业基本信息
  22. var company_base = []string{"company_name", "company_code", "credit_no", "org_code", "legal_person", "company_status",
  23. "authority", "establish_date", "issue_date", "operation_startdate", "operation_enddate", "capital", "company_type",
  24. "company_status", "company_address", "business_scope", "cancel_date", "cancel_reason", "revoke_date", "revoke_reason",
  25. "legal_person_type", "real_capital", "en_name", "list_code", "tax_code", "use_flag",
  26. }
  27. var province_map = map[string]string{
  28. "BJ": "北京", "TJ": "天津", "SH": "上海", "CQ": "重庆", "HB": "河北", "SX": "山西", "NMG": "内蒙", "LN": "辽宁", "JL": "吉林",
  29. "HLJ": "黑龙江", "JS": "江苏", "ZJ": "浙江", "AH": "安徽", "FJ": "福建", "JX": "江西", "SD": "山东", "HEN": "河南", "HUB": "湖北",
  30. "HUN": "湖南", "GD": "广东", "GX": "广西", "HAIN": "海南", "SC": "四川", "GZ": "贵州", "YN": "云南", "XZ": "西藏", "SAX": "陕西",
  31. "GS": "甘肃", "QH": "青海", "NX": "宁夏", "XJ": "新疆",
  32. }
  33. func TimeTask() {
  34. c := cron.New()
  35. //cronstr := "0 0 " + fmt.Sprint(TaskTime) + " * * ?" //每天TaskTime跑一次
  36. cronstrPa := "0 0 15 ? * WED" //凭安增量数据每周二跑一次
  37. _ = c.AddFunc(cronstrPa, func() {
  38. TaskFun()
  39. })
  40. c.Start()
  41. }
  42. func TaskFun() {
  43. defer util.Catch()
  44. sess := MongoTool1.GetMgoConn()
  45. defer MongoTool1.DestoryMongoConn(sess)
  46. pool := make(chan bool, 10)
  47. wg := &sync.WaitGroup{}
  48. //q := bson.M{"_id": bson.M{"$gt": lastId}}
  49. //q := bson.M{"_id": 262454280}
  50. it := sess.DB("mixdata").C("qyxy_tmp").Find(nil).Select(nil).Iter()
  51. count := 0
  52. for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
  53. lastId = util.Int64All(tmp["_id"])
  54. if count%20000 == 0 {
  55. util.Debug("current:", count)
  56. }
  57. pool <- true
  58. wg.Add(1)
  59. go func(tmp map[string]interface{}) {
  60. defer func() {
  61. <-pool
  62. wg.Done()
  63. }()
  64. IncStd(tmp)
  65. }(tmp)
  66. }
  67. util.Debug("over ---", count)
  68. }
  69. // IncStd 增量数据 临时表qyxy_tmp
  70. func IncStd(tmp map[string]interface{}) {
  71. update := make(map[string]interface{})
  72. save := make(map[string]interface{})
  73. push := make(map[string]interface{})
  74. // company_base
  75. if tmp["company_base"] != nil {
  76. companyArr := util.ObjArrToMapArr(tmp["company_base"].([]interface{}))
  77. company := companyArr[len(companyArr)-1]
  78. for _, v := range company_base{
  79. if company[v] == nil {
  80. continue
  81. }
  82. // company_type
  83. if v == "company_type" {
  84. save["company_type_old"] = company[v]
  85. if text := util.ObjToString(company["company_type"]); text != "" {
  86. if strings.Contains(text, "个体") || strings.Contains(text, "非公司") {
  87. save["company_type"] = "个体工商户"
  88. } else {
  89. text = strings.ReplaceAll(text, "(", "(")
  90. text = strings.ReplaceAll(text, ")", ")")
  91. if stype := QyStypeMap[text]; stype != "" {
  92. save["company_type"] = stype
  93. } else {
  94. save["company_type"] = "其他"
  95. }
  96. }
  97. }
  98. // company_status
  99. }else if v == "company_status" {
  100. save["company_status_old"] = company[v]
  101. if text := util.ObjToString(company["company_status"]); text != "" {
  102. text = strings.ReplaceAll(text, "(", "(")
  103. text = strings.ReplaceAll(text, ")", ")")
  104. if status := CompanyStatusMap[text]; status != "" {
  105. save["company_status"] = status
  106. } else {
  107. save["company_status"] = "其他"
  108. }
  109. }
  110. }else if v == "capital" {
  111. // capital/currency
  112. text := util.ObjToString(company[v])
  113. if currency := GetCurrency(text); currency != "" {
  114. save["currency"] = currency //币种
  115. }
  116. capital := ObjToMoney(text)
  117. capital = capital / 10000
  118. if capital != 0 {
  119. save[v] = capital
  120. }
  121. }else if v == "use_flag" {
  122. save[v] = util.IntAll(company[v])
  123. }else {
  124. save[v] = company[v]
  125. }
  126. }
  127. // mysql create_time/update_time
  128. save["create_time_msql"] = company["create_time"]
  129. save["update_time_msql"] = company["update_time"]
  130. // company_area/company_city/company_district
  131. pshort := util.ObjToString(company["province_short"])
  132. save["company_area"] = province_map[pshort]
  133. for i, field := range AreaFiled {
  134. if company[field] == nil {
  135. continue
  136. }
  137. if code := fmt.Sprint(company[field]); code != "" {
  138. if i == 0 && len(code) >= 8 { //credit_no企业信用代码
  139. code = code[2:8]
  140. } else if i == 1 && len(code) >= 6 { //company_code注册号
  141. code = code[:6]
  142. }
  143. if city := AddressMap[code]; city != nil { //未作废中取
  144. if city.Province != "" && city.Province == save["company_area"] {
  145. if city.City != "" {
  146. save["company_city"] = city.City //市
  147. }
  148. if city.District != "" {
  149. save["company_district"] = city.District //县
  150. }
  151. break
  152. }
  153. } else { //作废中取
  154. if city := AddressOldMap[code]; city != nil {
  155. if city.Province != "" && city.Province == save["company_area"] {
  156. if city.City != "" {
  157. save["company_city"] = city.City //市
  158. }
  159. if city.District != "" {
  160. save["company_district"] = city.District //县
  161. }
  162. }
  163. break
  164. }
  165. }
  166. }
  167. }
  168. }
  169. save["_id"] = tmp["_id"]
  170. save["updatetime"] = time.Now().Unix()
  171. if save["company_type"] != "个体工商户" {
  172. // history_name
  173. if tmp["company_history_name"] != nil {
  174. history_name := util.ObjArrToMapArr(tmp["company_history_name"].([]interface{}))
  175. var names []string
  176. for _, h := range history_name{
  177. names = append(names, util.ObjToString(h["history_name"]))
  178. }
  179. save["history_name"] = strings.Join(names, ",")
  180. }
  181. // company_employee
  182. if tmp["company_employee"] != nil {
  183. employees := util.ObjArrToMapArr(tmp["company_employee"].([]interface{}))
  184. var names []string
  185. var arr []map[string]interface{}
  186. for _, v := range employees{
  187. tmp := make(map[string]interface{})
  188. tmp["employee_name"] = v["employee_name"]
  189. tmp["position"] = v["position"]
  190. tmp["is_history"] = v["is_history"]
  191. arr = append(arr, tmp)
  192. names = append(names, util.ObjToString(v["employee_name"]))
  193. }
  194. //save["employees"] = arr
  195. push["employees"] = bson.M{"$each": arr}
  196. save["employee_name"] = strings.Join(names, ",")
  197. }
  198. // company_partner
  199. if tmp["company_partner"] != nil {
  200. partners := util.ObjArrToMapArr(tmp["company_partner"].([]interface{}))
  201. var names []string
  202. var arr []map[string]interface{}
  203. tmp["partners"] = partners
  204. for _, v := range partners{
  205. if util.IntAll(tmp["is_history"]) == 0 {
  206. tmp := make(map[string]interface{})
  207. tmp["stock_capital"] = v["stock_capital"]
  208. tmp["stock_name"] = v["stock_name"]
  209. tmp["identify_no"] = v["identify_no"]
  210. tmp["stock_realcapital"] = v["stock_realcapital"]
  211. tmp["is_history"] = v["is_history"]
  212. tmp["is_personal"] = v["is_personal"]
  213. tmp["stock_type"] = v["stock_type"]
  214. tmp["identify_type"] = v["identify_type"]
  215. arr = append(arr, tmp)
  216. names = append(names, util.ObjToString(v["stock_name"]))
  217. }
  218. }
  219. //save["partners"] = arr
  220. push["partners"] = bson.M{"$each": arr}
  221. save["stock_name"] = strings.Join(names, ",")
  222. }
  223. // annual_report_base
  224. if tmp["annual_report_base"] != nil {
  225. reports := util.ObjArrToMapArr(tmp["annual_report_base"].([]interface{}))
  226. var arr []map[string]interface{}
  227. year := 0
  228. phone, email := "", ""
  229. for _, v := range reports{
  230. tmp := make(map[string]interface{})
  231. tmp["operator_name"] = v["operator_name"]
  232. tmp["report_year"] = v["report_year"]
  233. tmp["zip_code"] = v["zip_code"]
  234. tmp["employee_no"] = v["employee_no"]
  235. tmp["company_phone"] = v["company_phone"]
  236. tmp["company_email"] = v["company_email"]
  237. arr = append(arr, tmp)
  238. if year < util.IntAll(v["report_year"]) {
  239. year = util.IntAll(v["report_year"])
  240. phone = util.ObjToString(v["company_phone"])
  241. email = util.ObjToString(v["company_email"])
  242. }
  243. }
  244. //save["annual_reports"] = arr
  245. push["annual_reports"] = bson.M{"$each": arr}
  246. if year != 0 {
  247. save["company_phone"] = phone
  248. save["company_email"] = email
  249. }
  250. }
  251. // website_url
  252. if tmp["annual_report_website"] != nil {
  253. webs := util.ObjArrToMapArr(tmp["annual_report_website"].([]interface{}))
  254. year := 0
  255. web := ""
  256. for _, v := range webs{
  257. if year < util.IntAll(v["report_year"]) && util.IntAll(v["is_history"]) == 0 {
  258. year = util.IntAll(v["report_year"])
  259. web = util.ObjToString(v["website_url"])
  260. }
  261. }
  262. if year != 0 {
  263. save["website_url"] = web
  264. }
  265. }
  266. // bid_contracttype
  267. var types []string
  268. if phone := util.ObjToString(save["company_phone"]); phone != "" {
  269. if len(phone) == 11 {
  270. types = append(types, "手机号")
  271. }else {
  272. types = append(types, "固定电话")
  273. }
  274. }
  275. if util.ObjToString(save["company_email"]) != "" {
  276. types = append(types, "邮箱")
  277. }
  278. companyName := util.ObjToString(save["company_name"])
  279. // redis bid_unittype、bid_purchasing、bid_projectname
  280. if b, err := redis.Exists("qyxy_winner", companyName); err == nil && b {
  281. maps := make(map[string]interface{})
  282. text := redis.GetStr("qyxy_winner", companyName)
  283. err1 := json.Unmarshal([]byte(text), &maps)
  284. if err1 != nil {
  285. util.Debug(companyName, "winner-----map解析异常")
  286. }else {
  287. for k := range maps{
  288. if k == "bid_contracttype" {
  289. t1 := util.ObjArrToStringArr(maps[k].([]interface{}))
  290. types = append(types, t1...)
  291. }else {
  292. save[k] = maps[k]
  293. }
  294. }
  295. }
  296. }
  297. if len(types) == 0 {
  298. types = append(types, "不存在")
  299. }
  300. save["bid_contracttype"] = types
  301. // bid_unittype
  302. flag := false
  303. for _, v := range WordsArr{
  304. if strings.Contains(util.ObjToString(save["business_scope"]), v) {
  305. flag = true
  306. break
  307. }
  308. }
  309. if flag {
  310. save["bid_unittype"] = []string{"厂商"}
  311. }
  312. // search_type
  313. if t := util.ObjToString(save["company_type"]); t != "" {
  314. if t != "个体工商户" && t != "其他" {
  315. t1 := util.ObjToString(save["company_type_old"])
  316. name := util.ObjToString(save["company_name"])
  317. if strings.Contains(t1, "有限合伙") {
  318. save["search_type"] = "有限合伙"
  319. }else if strings.Contains(t1, "合伙") {
  320. save["search_type"] = "普通合伙"
  321. }else if strings.Contains(name, "股份") ||
  322. (strings.Contains(t1, "上市") && !strings.Contains(t1, "非上市")) {
  323. save["search_type"] = "股份有限公司"
  324. }else {
  325. save["search_type"] = "有限责任公司"
  326. }
  327. }
  328. }
  329. // company_shortname
  330. if m := getStName(util.ObjToString(save["company_name"])); m != "" {
  331. save["company_shortname"] = m
  332. }
  333. }
  334. update["$set"] = save
  335. if len(push) > 0 {
  336. update["$push"] = push
  337. }
  338. updataInfo := []map[string]interface{}{
  339. {"_id": save["_id"]},
  340. update,
  341. }
  342. updatePool <- updataInfo
  343. }
  344. // InfoStd 存量全量数据
  345. func InfoStd(tmp map[string]interface{}) {
  346. save := make(map[string]interface{})
  347. for _, v := range company_base{
  348. if tmp[v] == nil {
  349. continue
  350. }
  351. // company_type
  352. if v == "company_type" {
  353. save["company_type_old"] = tmp[v]
  354. if text := util.ObjToString(tmp["company_type"]); text != "" {
  355. if strings.Contains(text, "个体") || strings.Contains(text, "非公司") {
  356. save["company_type"] = "个体工商户"
  357. } else {
  358. text = strings.ReplaceAll(text, "(", "(")
  359. text = strings.ReplaceAll(text, ")", ")")
  360. if stype := QyStypeMap[text]; stype != "" {
  361. save["company_type"] = stype
  362. } else {
  363. save["company_type"] = "其他"
  364. }
  365. }
  366. }
  367. // company_status
  368. }else if v == "company_status" {
  369. save["company_status_old"] = tmp[v]
  370. if text := util.ObjToString(tmp["company_status"]); text != "" {
  371. text = strings.ReplaceAll(text, "(", "(")
  372. text = strings.ReplaceAll(text, ")", ")")
  373. if status := CompanyStatusMap[text]; status != "" {
  374. save["company_status"] = status
  375. } else {
  376. save["company_status"] = "其他"
  377. }
  378. }
  379. }else if v == "capital" {
  380. // capital/currency
  381. text := util.ObjToString(tmp[v])
  382. if currency := GetCurrency(text); currency != "" {
  383. save["currency"] = currency //币种
  384. }
  385. capital := ObjToMoney(text)
  386. capital = capital / 10000
  387. if capital != 0 {
  388. save[v] = capital
  389. }
  390. }else if v == "use_flag" {
  391. save[v] = util.IntAll(tmp[v])
  392. }else {
  393. save[v] = tmp[v]
  394. }
  395. }
  396. save["_id"] = tmp["company_id"]
  397. // mysql create_time/update_time
  398. save["create_time_msql"] = tmp["create_time"]
  399. save["update_time_msql"] = tmp["update_time"]
  400. save["createtime"] = time.Now().Unix()
  401. save["updatetime"] = time.Now().Unix()
  402. // company_area/company_city/company_district
  403. pshort := util.ObjToString(tmp["province_short"])
  404. save["company_area"] = province_map[pshort]
  405. for i, field := range AreaFiled {
  406. if tmp[field] == nil {
  407. continue
  408. }
  409. if code := fmt.Sprint(tmp[field]); code != "" {
  410. if i == 0 && len(code) >= 8 { //credit_no企业信用代码
  411. code = code[2:8]
  412. } else if i == 1 && len(code) >= 6 { //company_code注册号
  413. code = code[:6]
  414. }
  415. if city := AddressMap[code]; city != nil { //未作废中取
  416. if city.Province != "" && city.Province == save["company_area"] {
  417. if city.City != "" {
  418. save["company_city"] = city.City //市
  419. }
  420. if city.District != "" {
  421. save["company_district"] = city.District //县
  422. }
  423. break
  424. }
  425. } else { //作废中取
  426. if city := AddressOldMap[code]; city != nil {
  427. if city.Province != "" && city.Province == save["company_area"] {
  428. if city.City != "" {
  429. save["company_city"] = city.City //市
  430. }
  431. if city.District != "" {
  432. save["company_district"] = city.District //县
  433. }
  434. }
  435. break
  436. }
  437. }
  438. }
  439. }
  440. if tmp["company_type"] != "个体工商户" {
  441. // history_name
  442. historyNameFun(save)
  443. // company_employee
  444. employeeFun(save)
  445. // company_partner
  446. partnerFun(save)
  447. // annual_report_base
  448. reportFun(save)
  449. // website_url
  450. websiteFun(save)
  451. // bid_contracttype
  452. var types []string
  453. if phone := util.ObjToString(save["company_phone"]); phone != "" {
  454. if len(phone) == 11 {
  455. types = append(types, "手机号")
  456. }else {
  457. types = append(types, "固定电话")
  458. }
  459. }
  460. if util.ObjToString(save["company_email"]) != "" {
  461. types = append(types, "邮箱")
  462. }
  463. companyName := util.ObjToString(tmp["company_name"])
  464. // redis bid_unittype、bid_purchasing、bid_projectname
  465. if b, err := redis.Exists("qyxy_winner", companyName); err == nil && b {
  466. maps := make(map[string]interface{})
  467. text := redis.GetStr("qyxy_winner", companyName)
  468. err1 := json.Unmarshal([]byte(text), &maps)
  469. if err1 != nil {
  470. util.Debug(companyName, "winner-----map解析异常")
  471. }else {
  472. for k := range maps{
  473. if k == "bid_contracttype" {
  474. t1 := util.ObjArrToStringArr(maps[k].([]interface{}))
  475. types = append(types, t1...)
  476. }else {
  477. save[k] = maps[k]
  478. }
  479. }
  480. }
  481. }
  482. if len(types) == 0 {
  483. types = append(types, "不存在")
  484. }
  485. save["bid_contracttype"] = types
  486. // bid_unittype
  487. flag := false
  488. for _, v := range WordsArr{
  489. if strings.Contains(util.ObjToString(tmp["business_scope"]), v) {
  490. flag = true
  491. break
  492. }
  493. }
  494. if flag {
  495. save["bid_unittype"] = []string{"厂商"}
  496. }
  497. // search_type
  498. if t := util.ObjToString(save["company_type"]); t != "" {
  499. if t != "个体工商户" && t != "其他" {
  500. t1 := util.ObjToString(save["company_type_old"])
  501. name := util.ObjToString(save["company_name"])
  502. if strings.Contains(t1, "有限合伙") {
  503. save["search_type"] = "有限合伙"
  504. }else if strings.Contains(t1, "合伙") {
  505. save["search_type"] = "普通合伙"
  506. }else if strings.Contains(name, "股份") ||
  507. (strings.Contains(t1, "上市") && !strings.Contains(t1, "非上市")) {
  508. save["search_type"] = "股份有限公司"
  509. }else {
  510. save["search_type"] = "有限责任公司"
  511. }
  512. }
  513. }
  514. // company_shortname
  515. if m := getStName(util.ObjToString(tmp["company_name"])); m != "" {
  516. save["company_shortname"] = m
  517. }
  518. }
  519. saveInfo := []map[string]interface{}{
  520. {"_id": tmp["company_id"]},
  521. {"$set": save},
  522. }
  523. //savePool <- save
  524. updatePool <- saveInfo
  525. }
  526. // 曾用名
  527. func historynamefunMysql(tmp map[string]interface{}) {
  528. query := "SELECT history_name FROM company_history_name WHERE company_id=?"
  529. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  530. if len(*info) > 0 {
  531. var names []string
  532. for _, v := range *info{
  533. names = append(names, util.ObjToString(v["history_name"]))
  534. }
  535. tmp["history_name"] = strings.Join(names, ",")
  536. }
  537. }
  538. func historyNameFun(tmp map[string]interface{}) {
  539. field := bson.M{"history_name": 1}
  540. info, b := MongoTool1.Find("company_history_name", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  541. if b && len(*info) > 0 {
  542. var names []string
  543. for _, v := range *info{
  544. names = append(names, util.ObjToString(v["history_name"]))
  545. }
  546. tmp["history_name"] = strings.Join(names, ",")
  547. }
  548. }
  549. // company_employee 高管
  550. func employeeFunMySql(tmp map[string]interface{}) {
  551. query := "SELECT employee_name, position, is_history FROM company_employee WHERE company_id=?"
  552. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  553. if len(*info) > 0 {
  554. var names []string
  555. tmp["employees"] = *info
  556. for _, v := range *info{
  557. names = append(names, util.ObjToString(v["employee_name"]))
  558. }
  559. tmp["employee_name"] = strings.Join(names, ",")
  560. }
  561. }
  562. func employeeFun(tmp map[string]interface{}) {
  563. field := bson.M{"employee_name": 1, "position": 1, "is_history": 1}
  564. info, b := MongoTool1.Find("company_employee", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  565. if b && len(*info) > 0 {
  566. var names []string
  567. tmp["employees"] = *info
  568. for _, v := range *info{
  569. names = append(names, util.ObjToString(v["employee_name"]))
  570. }
  571. tmp["employee_name"] = strings.Join(names, ",")
  572. }
  573. }
  574. // company_partner 合伙人
  575. func partnerFunMySql(tmp map[string]interface{}) {
  576. query := "SELECT stock_name, stock_type, is_personal, identify_type, identify_no, stock_capital, stock_realcapital, is_history FROM company_partner WHERE company_id=?"
  577. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  578. if len(*info) > 0 {
  579. var names []string
  580. tmp["partners"] = *info
  581. for _, v := range *info{
  582. if util.IntAll(tmp["is_history"]) == 0 {
  583. names = append(names, util.ObjToString(v["stock_name"]))
  584. }
  585. }
  586. tmp["stock_name"] = strings.Join(names, ",")
  587. }
  588. }
  589. func partnerFun(tmp map[string]interface{}) {
  590. field := bson.M{"stock_name": 1, "stock_type": 1, "is_personal": 1, "identify_type": 1, "identify_no": 1, "stock_capital": 1, "stock_realcapital": 1, "is_history": 1}
  591. info, b := MongoTool1.Find("company_partner", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  592. if b && len(*info) > 0 {
  593. var names []string
  594. tmp["partners"] = *info
  595. for _, v := range *info{
  596. if util.IntAll(tmp["is_history"]) == 0 {
  597. names = append(names, util.ObjToString(v["stock_name"]))
  598. }
  599. }
  600. tmp["stock_name"] = strings.Join(names, ",")
  601. }
  602. }
  603. // annual_report_base 年报信息
  604. func reportFunMysql(tmp map[string]interface{}) {
  605. query := "SELECT report_year, company_phone, company_email, zip_code, employee_no, operator_name FROM annual_report_base WHERE company_id=?"
  606. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  607. if len(*info) > 0 {
  608. tmp["annual_reports"] = *info
  609. year := 0
  610. phone, email := "", ""
  611. for _, v := range *info{
  612. if year < util.IntAll(v["report_year"]) {
  613. year = util.IntAll(v["report_year"])
  614. phone = util.ObjToString(v["company_phone"])
  615. email = util.ObjToString(v["company_email"])
  616. }
  617. }
  618. if year != 0 {
  619. tmp["company_phone"] = phone
  620. tmp["company_email"] = email
  621. }
  622. }
  623. }
  624. func reportFun(tmp map[string]interface{}) {
  625. field := bson.M{"report_year": 1, "company_phone": 1, "company_email": 1, "zip_code": 1, "employee_no": 1, "operator_name": 1}
  626. info, b := MongoTool1.Find("annual_report_base", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  627. if b && len(*info) > 0 {
  628. tmp["annual_reports"] = *info
  629. year := 0
  630. phone, email := "", ""
  631. for _, v := range *info{
  632. if year < util.IntAll(v["report_year"]) {
  633. year = util.IntAll(v["report_year"])
  634. phone = util.ObjToString(v["company_phone"])
  635. email = util.ObjToString(v["company_email"])
  636. }
  637. }
  638. if year != 0 {
  639. tmp["company_phone"] = phone
  640. tmp["company_email"] = email
  641. }
  642. }
  643. }
  644. // website_url
  645. func websiteFunMySql(tmp map[string]interface{}) {
  646. query := "SELECT website_url, website_name, website_type, report_year, is_history FROM annual_report_website WHERE company_id=?"
  647. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  648. if len(*info) > 0 {
  649. year := 0
  650. web := ""
  651. for _, v := range *info{
  652. if year < util.IntAll(v["report_year"]) && util.IntAll(tmp["is_history"]) == 0 {
  653. year = util.IntAll(v["report_year"])
  654. web = util.ObjToString(v["website_url"])
  655. }
  656. }
  657. if year != 0 {
  658. tmp["website_url"] = web
  659. }
  660. }
  661. }
  662. func websiteFun(tmp map[string]interface{}) {
  663. field := bson.M{"website_url": 1, "website_name": 1, "website_type": 1, "report_year": 1, "is_history": 1}
  664. info, b := MongoTool1.Find("annual_report_website", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  665. if b && len(*info) > 0 {
  666. year := 0
  667. web := ""
  668. for _, v := range *info{
  669. if year < util.IntAll(v["report_year"]) && util.IntAll(tmp["is_history"]) == 0 {
  670. year = util.IntAll(v["report_year"])
  671. web = util.ObjToString(v["website_url"])
  672. }
  673. }
  674. if year != 0 {
  675. tmp["website_url"] = web
  676. }
  677. }
  678. }
  679. // company_shortname 企业简称
  680. func getStName(name string) string {
  681. regnames := regPre.FindStringSubmatch(name)
  682. lenth := len(regnames)
  683. if lenth < 1 {
  684. return ""
  685. }
  686. newstr := regnames[lenth-1]
  687. ch := seg.Cut(newstr, false)
  688. val := []string{}
  689. for word := range ch {
  690. val = append(val, word)
  691. }
  692. name2 := ""
  693. for _, v := range val {
  694. name2 = name2 + v
  695. if len([]rune(name2)) >= 4 {
  696. break
  697. }
  698. }
  699. return name2
  700. }