task.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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. //client := Es.GetEsConn()
  47. //defer Es.DestoryEsConn(client)
  48. pool := make(chan bool, 10)
  49. wg := &sync.WaitGroup{}
  50. //q := bson.M{"_id": bson.M{"$gt": lastId}}
  51. //q := bson.M{"_id": 262454280}
  52. //q := map[string]interface{}{"_id": "3fd1352a95f552bda9bac1248eb24f03"}
  53. //q := map[string]interface{}{"company_name": nil}
  54. it := sess.DB("mixdata").C("qyxy_tmp").Find(nil).Select(nil).Iter()
  55. count := 0
  56. for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
  57. if count%2000 == 0 {
  58. util.Debug("current:", count)
  59. }
  60. pool <- true
  61. wg.Add(1)
  62. go func(tmp map[string]interface{}) {
  63. defer func() {
  64. <-pool
  65. wg.Done()
  66. }()
  67. IncStd(tmp)
  68. //taskinfo(tmp)
  69. }(tmp)
  70. }
  71. util.Debug("over ---", count)
  72. }
  73. // IncStd 增量数据 临时表qyxy_tmp
  74. func IncStd(tmp map[string]interface{}) {
  75. update := make(map[string]interface{})
  76. save := make(map[string]interface{})
  77. push := make(map[string]interface{})
  78. // company_base
  79. if tmp["company_base"] != nil {
  80. companyArr := util.ObjArrToMapArr(tmp["company_base"].([]interface{}))
  81. company := companyArr[len(companyArr)-1]
  82. for _, v := range company_base {
  83. if company[v] == nil {
  84. continue
  85. }
  86. // company_type
  87. if v == "company_type" {
  88. save["company_type_old"] = company[v]
  89. if text := util.ObjToString(company["company_type"]); text != "" {
  90. if strings.Contains(text, "个体") || strings.Contains(text, "非公司") {
  91. save["company_type"] = "个体工商户"
  92. } else {
  93. text = strings.ReplaceAll(text, "(", "(")
  94. text = strings.ReplaceAll(text, ")", ")")
  95. if stype := QyStypeMap[text]; stype != "" {
  96. save["company_type"] = stype
  97. } else {
  98. save["company_type"] = "其他"
  99. }
  100. }
  101. }
  102. // company_status
  103. } else if v == "company_status" {
  104. save["company_status_old"] = company[v]
  105. if text := util.ObjToString(company["company_status"]); text != "" {
  106. text = strings.ReplaceAll(text, "(", "(")
  107. text = strings.ReplaceAll(text, ")", ")")
  108. if status := CompanyStatusMap[text]; status != "" {
  109. save["company_status"] = status
  110. } else {
  111. save["company_status"] = "其他"
  112. }
  113. }
  114. } else if v == "capital" {
  115. // capital/currency
  116. text := util.ObjToString(company[v])
  117. if currency := GetCurrency(text); currency != "" {
  118. save["currency"] = currency //币种
  119. }
  120. capital := ObjToMoney(text)
  121. capital = capital / 10000
  122. if capital != 0 {
  123. save[v] = capital
  124. }
  125. } else if v == "use_flag" {
  126. save[v] = util.IntAll(company[v])
  127. } else {
  128. save[v] = company[v]
  129. }
  130. }
  131. // mysql create_time/update_time
  132. save["create_time_msql"] = company["create_time"]
  133. save["update_time_msql"] = company["update_time"]
  134. // company_area/company_city/company_district
  135. pshort := util.ObjToString(company["province_short"])
  136. save["company_area"] = province_map[pshort]
  137. for i, field := range AreaFiled {
  138. if company[field] == nil {
  139. continue
  140. }
  141. if code := fmt.Sprint(company[field]); code != "" {
  142. if i == 0 && len(code) >= 8 { //credit_no企业信用代码
  143. code = code[2:8]
  144. } else if i == 1 && len(code) >= 6 { //company_code注册号
  145. code = code[:6]
  146. }
  147. if city := AddressMap[code]; city != nil { //未作废中取
  148. if city.Province != "" && city.Province == util.ObjToString(save["company_area"]) {
  149. if city.City != "" {
  150. save["company_city"] = city.City //市
  151. }
  152. if city.District != "" {
  153. save["company_district"] = city.District //县
  154. }
  155. break
  156. }
  157. } else { //作废中取
  158. if city := AddressOldMap[code]; city != nil {
  159. if city.Province != "" && city.Province == util.ObjToString(save["company_area"]) {
  160. if city.City != "" {
  161. save["company_city"] = city.City //市
  162. }
  163. if city.District != "" {
  164. save["company_district"] = city.District //县
  165. }
  166. }
  167. break
  168. }
  169. }
  170. }
  171. }
  172. }
  173. save["_id"] = tmp["_id"]
  174. save["updatetime"] = time.Now().Unix()
  175. if save["company_type"] != "个体工商户" {
  176. // history_name
  177. if tmp["company_history_name"] != nil {
  178. history_name := util.ObjArrToMapArr(tmp["company_history_name"].([]interface{}))
  179. var names []string
  180. for _, h := range history_name {
  181. names = append(names, util.ObjToString(h["history_name"]))
  182. }
  183. save["history_name"] = strings.Join(names, ",")
  184. }
  185. // company_employee、company_partner、annual_report_base涉及存量更新动作
  186. oldTmp := &map[string]interface{}{}
  187. if tmp["company_employee"] != nil || tmp["company_partner"] != nil || tmp["annual_report_base"] != nil {
  188. fields := map[string]interface{}{"employees": 1, "partners": 1, "annual_reports": 1}
  189. oldTmp, _ = MongoTool.FindOneByField("qyxy_std", map[string]interface{}{"_id": tmp["_id"]}, fields)
  190. }
  191. // company_employee
  192. if tmp["company_employee"] != nil {
  193. employees := util.ObjArrToMapArr(tmp["company_employee"].([]interface{}))
  194. var names []string
  195. var arr []map[string]interface{}
  196. if (*oldTmp)["employees"] != nil {
  197. arr = util.ObjArrToMapArr((*oldTmp)["employees"].([]interface{}))
  198. } else {
  199. arr = make([]map[string]interface{}, 0)
  200. }
  201. //arr := (*oldTmp)["employees"].([]map[string]interface{})
  202. for _, v := range employees {
  203. ep := make(map[string]interface{})
  204. if util.ObjToString(v["_operation_type"]) == "insert" {
  205. ep["employee_name"] = v["employee_name"]
  206. ep["position"] = v["position"]
  207. ep["is_history"] = v["is_history"]
  208. ep["_id"] = util.IntAll(v["id"])
  209. arr = append(arr, ep)
  210. names = append(names, util.ObjToString(v["employee_name"]))
  211. } else {
  212. eq_flag := true
  213. for _, m := range arr {
  214. if util.IntAll(v["id"]) == util.IntAll(m["_id"]) {
  215. eq_flag = false
  216. m["employee_name"] = v["employee_name"]
  217. m["position"] = v["position"]
  218. m["is_history"] = v["is_history"]
  219. break
  220. }
  221. }
  222. if eq_flag {
  223. ep := make(map[string]interface{})
  224. ep["employee_name"] = v["employee_name"]
  225. ep["position"] = v["position"]
  226. ep["is_history"] = v["is_history"]
  227. ep["_id"] = util.IntAll(v["id"])
  228. arr = append(arr, ep)
  229. names = append(names, util.ObjToString(v["employee_name"]))
  230. }
  231. }
  232. }
  233. save["employees"] = arr
  234. //push["employees"] = bson.M{"$each": arr}
  235. save["employee_name"] = strings.Join(names, ",")
  236. }
  237. // company_partner
  238. if tmp["company_partner"] != nil {
  239. partners := util.ObjArrToMapArr(tmp["company_partner"].([]interface{}))
  240. var names []string
  241. var arr []map[string]interface{}
  242. if (*oldTmp)["partners"] != nil {
  243. arr = util.ObjArrToMapArr((*oldTmp)["partners"].([]interface{}))
  244. } else {
  245. arr = make([]map[string]interface{}, 0)
  246. }
  247. for _, v := range partners {
  248. if util.ObjToString(v["_operation_type"]) == "insert" {
  249. exp := make(map[string]interface{})
  250. exp["stock_capital"] = v["stock_capital"]
  251. exp["stock_name"] = v["stock_name"]
  252. exp["identify_no"] = v["identify_no"]
  253. exp["stock_realcapital"] = v["stock_realcapital"]
  254. exp["is_history"] = v["is_history"]
  255. exp["is_personal"] = v["is_personal"]
  256. exp["stock_type"] = v["stock_type"]
  257. exp["identify_type"] = v["identify_type"]
  258. exp["_id"] = util.IntAll(v["id"])
  259. arr = append(arr, exp)
  260. names = append(names, util.ObjToString(v["stock_name"]))
  261. } else {
  262. eqFlag := true
  263. for _, m := range arr {
  264. if util.IntAll(v["id"]) == util.IntAll(m["_id"]) {
  265. eqFlag = false
  266. m["stock_capital"] = v["stock_capital"]
  267. m["stock_name"] = v["stock_name"]
  268. m["identify_no"] = v["identify_no"]
  269. m["stock_realcapital"] = v["stock_realcapital"]
  270. m["is_history"] = v["is_history"]
  271. m["is_personal"] = v["is_personal"]
  272. m["stock_type"] = v["stock_type"]
  273. m["identify_type"] = v["identify_type"]
  274. break
  275. }
  276. }
  277. if eqFlag {
  278. exp := make(map[string]interface{})
  279. exp["stock_capital"] = v["stock_capital"]
  280. exp["stock_name"] = v["stock_name"]
  281. exp["identify_no"] = v["identify_no"]
  282. exp["stock_realcapital"] = v["stock_realcapital"]
  283. exp["is_history"] = v["is_history"]
  284. exp["is_personal"] = v["is_personal"]
  285. exp["stock_type"] = v["stock_type"]
  286. exp["identify_type"] = v["identify_type"]
  287. exp["_id"] = util.IntAll(v["id"])
  288. arr = append(arr, exp)
  289. names = append(names, util.ObjToString(v["stock_name"]))
  290. }
  291. }
  292. }
  293. save["partners"] = arr
  294. //push["partners"] = bson.M{"$each": arr}
  295. save["stock_name"] = strings.Join(names, ",")
  296. }
  297. // annual_report_base
  298. if tmp["annual_report_base"] != nil {
  299. reports := util.ObjArrToMapArr(tmp["annual_report_base"].([]interface{}))
  300. var arr []map[string]interface{}
  301. if (*oldTmp)["annual_reports"] != nil {
  302. arr = util.ObjArrToMapArr((*oldTmp)["annual_reports"].([]interface{}))
  303. } else {
  304. arr = make([]map[string]interface{}, 0)
  305. }
  306. year := 0
  307. phone, email := "", ""
  308. for _, v := range reports {
  309. if util.ObjToString(v["_operation_type"]) == "insert" {
  310. exp := make(map[string]interface{})
  311. exp["operator_name"] = v["operator_name"]
  312. exp["report_year"] = v["report_year"]
  313. exp["zip_code"] = v["zip_code"]
  314. exp["employee_no"] = v["employee_no"]
  315. exp["company_phone"] = v["company_phone"]
  316. exp["company_email"] = v["company_email"]
  317. exp["_id"] = util.IntAll(v["id"])
  318. arr = append(arr, exp)
  319. if year < util.IntAll(v["report_year"]) {
  320. year = util.IntAll(v["report_year"])
  321. phone = util.ObjToString(v["company_phone"])
  322. email = util.ObjToString(v["company_email"])
  323. }
  324. } else {
  325. eqFlag := true
  326. for _, m := range arr {
  327. if util.IntAll(v["id"]) == util.IntAll(m["_id"]) {
  328. eqFlag = false
  329. m["operator_name"] = v["operator_name"]
  330. m["report_year"] = v["report_year"]
  331. m["zip_code"] = v["zip_code"]
  332. m["employee_no"] = v["employee_no"]
  333. m["company_phone"] = v["company_phone"]
  334. m["company_email"] = v["company_email"]
  335. break
  336. }
  337. }
  338. if eqFlag {
  339. exp := make(map[string]interface{})
  340. exp["stock_capital"] = v["stock_capital"]
  341. exp["stock_name"] = v["stock_name"]
  342. exp["identify_no"] = v["identify_no"]
  343. exp["stock_realcapital"] = v["stock_realcapital"]
  344. exp["is_history"] = v["is_history"]
  345. exp["is_personal"] = v["is_personal"]
  346. exp["stock_type"] = v["stock_type"]
  347. exp["identify_type"] = v["identify_type"]
  348. exp["_id"] = util.IntAll(v["id"])
  349. arr = append(arr, exp)
  350. if year < util.IntAll(v["report_year"]) {
  351. year = util.IntAll(v["report_year"])
  352. phone = util.ObjToString(v["company_phone"])
  353. email = util.ObjToString(v["company_email"])
  354. }
  355. }
  356. }
  357. }
  358. save["annual_reports"] = arr
  359. //push["annual_reports"] = bson.M{"$each": arr}
  360. if year != 0 {
  361. save["company_phone"] = phone
  362. save["company_email"] = email
  363. }
  364. }
  365. // website_url
  366. if tmp["annual_report_website"] != nil {
  367. webs := util.ObjArrToMapArr(tmp["annual_report_website"].([]interface{}))
  368. year := 0
  369. web := ""
  370. for _, v := range webs {
  371. if year < util.IntAll(v["report_year"]) && util.IntAll(v["is_history"]) == 0 {
  372. year = util.IntAll(v["report_year"])
  373. web = util.ObjToString(v["website_url"])
  374. }
  375. }
  376. if year != 0 {
  377. save["website_url"] = web
  378. }
  379. }
  380. // bid_contracttype
  381. var types []string
  382. if phone := util.ObjToString(save["company_phone"]); phone != "" {
  383. if len(phone) == 11 {
  384. types = append(types, "手机号")
  385. } else {
  386. types = append(types, "固定电话")
  387. }
  388. }
  389. if util.ObjToString(save["company_email"]) != "" {
  390. types = append(types, "邮箱")
  391. }
  392. //companyName := util.ObjToString(save["company_name"])
  393. // redis bid_unittype、bid_purchasing、bid_projectname
  394. //if b, err := redis.Exists("qyxy", companyName); err == nil && b {
  395. // maps := make(map[string]interface{})
  396. // text := redis.GetStr("qyxy", companyName)
  397. // err1 := json.Unmarshal([]byte(text), &maps)
  398. // if err1 != nil {
  399. // util.Debug(companyName, "winner-----map解析异常")
  400. // } else {
  401. // for k := range maps {
  402. // if k == "bid_contracttype" {
  403. // t1 := util.ObjArrToStringArr(maps[k].([]interface{}))
  404. // types = append(types, t1...)
  405. // } else {
  406. // save[k] = maps[k]
  407. // }
  408. // }
  409. // }
  410. //}
  411. if len(types) == 0 {
  412. types = append(types, "不存在")
  413. }
  414. save["bid_contracttype"] = types
  415. // bid_unittype
  416. flag := false
  417. for _, v := range WordsArr {
  418. if strings.Contains(util.ObjToString(save["business_scope"]), v) {
  419. flag = true
  420. break
  421. }
  422. }
  423. if flag {
  424. if save["bid_unittype"] != nil {
  425. save["bid_unittype"] = append(util.ObjArrToStringArr(save["bid_unittype"].([]interface{})), "厂商")
  426. } else {
  427. save["bid_unittype"] = []string{"厂商"}
  428. }
  429. }
  430. // search_type
  431. if t := util.ObjToString(save["company_type"]); t != "" {
  432. if t != "个体工商户" && t != "其他" {
  433. t1 := util.ObjToString(save["company_type_old"])
  434. name := util.ObjToString(save["company_name"])
  435. if strings.Contains(t1, "有限合伙") {
  436. save["search_type"] = "有限合伙"
  437. } else if strings.Contains(t1, "合伙") {
  438. save["search_type"] = "普通合伙"
  439. } else if strings.Contains(name, "股份") ||
  440. (strings.Contains(t1, "上市") && !strings.Contains(t1, "非上市")) {
  441. save["search_type"] = "股份有限公司"
  442. } else {
  443. save["search_type"] = "有限责任公司"
  444. }
  445. }
  446. }
  447. // company_shortname
  448. if m := getStName(util.ObjToString(save["company_name"])); m != "" {
  449. save["company_shortname"] = m
  450. }
  451. }
  452. update["$set"] = save
  453. if len(push) > 0 {
  454. update["$push"] = push
  455. }
  456. updataInfo := []map[string]interface{}{
  457. {"_id": save["_id"]},
  458. update,
  459. }
  460. updatePool <- updataInfo
  461. }
  462. // InfoStd 存量全量数据
  463. func InfoStd(tmp map[string]interface{}) {
  464. save := make(map[string]interface{})
  465. for _, v := range company_base {
  466. if tmp[v] == nil {
  467. continue
  468. }
  469. // company_type
  470. if v == "company_type" {
  471. save["company_type_old"] = tmp[v]
  472. if text := util.ObjToString(tmp["company_type"]); text != "" {
  473. if strings.Contains(text, "个体") || strings.Contains(text, "非公司") {
  474. save["company_type"] = "个体工商户"
  475. } else {
  476. text = strings.ReplaceAll(text, "(", "(")
  477. text = strings.ReplaceAll(text, ")", ")")
  478. if stype := QyStypeMap[text]; stype != "" {
  479. save["company_type"] = stype
  480. } else {
  481. save["company_type"] = "其他"
  482. }
  483. }
  484. }
  485. // company_status
  486. } else if v == "company_status" {
  487. save["company_status_old"] = tmp[v]
  488. if text := util.ObjToString(tmp["company_status"]); text != "" {
  489. text = strings.ReplaceAll(text, "(", "(")
  490. text = strings.ReplaceAll(text, ")", ")")
  491. if status := CompanyStatusMap[text]; status != "" {
  492. save["company_status"] = status
  493. } else {
  494. save["company_status"] = "其他"
  495. }
  496. }
  497. } else if v == "capital" {
  498. // capital/currency
  499. text := util.ObjToString(tmp[v])
  500. if currency := GetCurrency(text); currency != "" {
  501. save["currency"] = currency //币种
  502. }
  503. capital := ObjToMoney(text)
  504. capital = capital / 10000
  505. if capital != 0 {
  506. save[v] = capital
  507. }
  508. } else if v == "use_flag" {
  509. save[v] = util.IntAll(tmp[v])
  510. } else {
  511. save[v] = tmp[v]
  512. }
  513. }
  514. save["_id"] = tmp["company_id"]
  515. // mysql create_time/update_time
  516. save["create_time_msql"] = tmp["create_time"]
  517. save["update_time_msql"] = tmp["update_time"]
  518. save["createtime"] = time.Now().Unix()
  519. save["updatetime"] = time.Now().Unix()
  520. // company_area/company_city/company_district
  521. pshort := util.ObjToString(tmp["province_short"])
  522. save["company_area"] = province_map[pshort]
  523. for i, field := range AreaFiled {
  524. if tmp[field] == nil {
  525. continue
  526. }
  527. if code := fmt.Sprint(tmp[field]); code != "" {
  528. if i == 0 && len(code) >= 8 { //credit_no企业信用代码
  529. code = code[2:8]
  530. } else if i == 1 && len(code) >= 6 { //company_code注册号
  531. code = code[:6]
  532. }
  533. if city := AddressMap[code]; city != nil { //未作废中取
  534. if city.Province != "" && strings.Contains(city.Province, util.ObjToString(save["company_area"])) {
  535. if city.City != "" {
  536. save["company_city"] = city.City //市
  537. }
  538. if city.District != "" {
  539. save["company_district"] = city.District //县
  540. }
  541. break
  542. }
  543. } else { //作废中取
  544. if city := AddressOldMap[code]; city != nil {
  545. if city.Province != "" && city.Province == save["company_area"] {
  546. if city.City != "" {
  547. save["company_city"] = city.City //市
  548. }
  549. if city.District != "" {
  550. save["company_district"] = city.District //县
  551. }
  552. }
  553. break
  554. }
  555. }
  556. }
  557. }
  558. if tmp["company_type"] != "个体工商户" {
  559. // history_name
  560. historyNameFun(save)
  561. // company_employee
  562. employeeFun(save)
  563. // company_partner
  564. partnerFun(save)
  565. // annual_report_base
  566. reportFun(save)
  567. // website_url
  568. websiteFun(save)
  569. // bid_contracttype
  570. var types []string
  571. if phone := util.ObjToString(save["company_phone"]); phone != "" {
  572. if len(phone) == 11 {
  573. types = append(types, "手机号")
  574. } else {
  575. types = append(types, "固定电话")
  576. }
  577. }
  578. if util.ObjToString(save["company_email"]) != "" {
  579. types = append(types, "邮箱")
  580. }
  581. companyName := util.ObjToString(tmp["company_name"])
  582. // redis bid_unittype、bid_purchasing、bid_projectname
  583. if b, err := redis.Exists("qyxy", companyName); err == nil && b {
  584. maps := make(map[string]interface{})
  585. text := redis.GetStr("qyxy", companyName)
  586. err1 := json.Unmarshal([]byte(text), &maps)
  587. if err1 != nil {
  588. util.Debug(companyName, "winner-----map解析异常")
  589. } else {
  590. for k := range maps {
  591. if k == "bid_contracttype" {
  592. t1 := util.ObjArrToStringArr(maps[k].([]interface{}))
  593. types = append(types, t1...)
  594. } else {
  595. save[k] = maps[k]
  596. }
  597. }
  598. }
  599. }
  600. if len(types) == 0 {
  601. types = append(types, "不存在")
  602. }
  603. save["bid_contracttype"] = types
  604. // bid_unittype
  605. flag := false
  606. for _, v := range WordsArr {
  607. if strings.Contains(util.ObjToString(tmp["business_scope"]), v) {
  608. flag = true
  609. break
  610. }
  611. }
  612. if flag {
  613. save["bid_unittype"] = []string{"厂商"}
  614. }
  615. // search_type
  616. if t := util.ObjToString(save["company_type"]); t != "" {
  617. if t != "个体工商户" && t != "其他" {
  618. t1 := util.ObjToString(save["company_type_old"])
  619. name := util.ObjToString(save["company_name"])
  620. if strings.Contains(t1, "有限合伙") {
  621. save["search_type"] = "有限合伙"
  622. } else if strings.Contains(t1, "合伙") {
  623. save["search_type"] = "普通合伙"
  624. } else if strings.Contains(name, "股份") ||
  625. (strings.Contains(t1, "上市") && !strings.Contains(t1, "非上市")) {
  626. save["search_type"] = "股份有限公司"
  627. } else {
  628. save["search_type"] = "有限责任公司"
  629. }
  630. }
  631. }
  632. // company_shortname
  633. if m := getStName(util.ObjToString(tmp["company_name"])); m != "" {
  634. save["company_shortname"] = m
  635. }
  636. }
  637. saveInfo := []map[string]interface{}{
  638. {"_id": tmp["company_id"]},
  639. {"$set": save},
  640. }
  641. //savePool <- save
  642. updatePool <- saveInfo
  643. }
  644. // 曾用名
  645. func historynamefunMysql(tmp map[string]interface{}) {
  646. query := "SELECT history_name FROM company_history_name WHERE company_id=?"
  647. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  648. if len(*info) > 0 {
  649. var names []string
  650. for _, v := range *info {
  651. names = append(names, util.ObjToString(v["history_name"]))
  652. }
  653. tmp["history_name"] = strings.Join(names, ",")
  654. }
  655. }
  656. func historyNameFun(tmp map[string]interface{}) {
  657. field := bson.M{"history_name": 1}
  658. info, b := MongoTool1.Find("company_history_name", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  659. if b && len(*info) > 0 {
  660. var names []string
  661. for _, v := range *info {
  662. names = append(names, util.ObjToString(v["history_name"]))
  663. }
  664. tmp["history_name"] = strings.Join(names, ",")
  665. }
  666. }
  667. // company_employee 高管
  668. func employeeFunMySql(tmp map[string]interface{}) {
  669. query := "SELECT employee_name, position, is_history FROM company_employee WHERE company_id=?"
  670. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  671. if len(*info) > 0 {
  672. var names []string
  673. tmp["employees"] = *info
  674. for _, v := range *info {
  675. names = append(names, util.ObjToString(v["employee_name"]))
  676. }
  677. tmp["employee_name"] = strings.Join(names, ",")
  678. }
  679. }
  680. func employeeFun(tmp map[string]interface{}) {
  681. field := bson.M{"employee_name": 1, "position": 1, "is_history": 1}
  682. info, b := MongoTool1.Find("company_employee", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  683. if b && len(*info) > 0 {
  684. var names []string
  685. tmp["employees"] = *info
  686. for _, v := range *info {
  687. names = append(names, util.ObjToString(v["employee_name"]))
  688. }
  689. tmp["employee_name"] = strings.Join(names, ",")
  690. }
  691. }
  692. // company_partner 合伙人
  693. func partnerFunMySql(tmp map[string]interface{}) {
  694. query := "SELECT stock_name, stock_type, is_personal, identify_type, identify_no, stock_capital, stock_realcapital, is_history FROM company_partner WHERE company_id=?"
  695. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  696. if len(*info) > 0 {
  697. var names []string
  698. tmp["partners"] = *info
  699. for _, v := range *info {
  700. if util.IntAll(tmp["is_history"]) == 0 {
  701. names = append(names, util.ObjToString(v["stock_name"]))
  702. }
  703. }
  704. tmp["stock_name"] = strings.Join(names, ",")
  705. }
  706. }
  707. func partnerFun(tmp map[string]interface{}) {
  708. 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}
  709. info, b := MongoTool1.Find("company_partner", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  710. if b && len(*info) > 0 {
  711. var names []string
  712. tmp["partners"] = *info
  713. for _, v := range *info {
  714. if util.IntAll(tmp["is_history"]) == 0 {
  715. names = append(names, util.ObjToString(v["stock_name"]))
  716. }
  717. }
  718. tmp["stock_name"] = strings.Join(names, ",")
  719. }
  720. }
  721. // annual_report_base 年报信息
  722. func reportFunMysql(tmp map[string]interface{}) {
  723. query := "SELECT report_year, company_phone, company_email, zip_code, employee_no, operator_name FROM annual_report_base WHERE company_id=?"
  724. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  725. if len(*info) > 0 {
  726. tmp["annual_reports"] = *info
  727. year := 0
  728. phone, email := "", ""
  729. for _, v := range *info {
  730. if year < util.IntAll(v["report_year"]) {
  731. year = util.IntAll(v["report_year"])
  732. phone = util.ObjToString(v["company_phone"])
  733. email = util.ObjToString(v["company_email"])
  734. }
  735. }
  736. if year != 0 {
  737. tmp["company_phone"] = phone
  738. tmp["company_email"] = email
  739. }
  740. }
  741. }
  742. func reportFun(tmp map[string]interface{}) {
  743. field := bson.M{"report_year": 1, "company_phone": 1, "company_email": 1, "zip_code": 1, "employee_no": 1, "operator_name": 1}
  744. info, b := MongoTool1.Find("annual_report_base", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  745. if b && len(*info) > 0 {
  746. tmp["annual_reports"] = *info
  747. year := 0
  748. phone, email := "", ""
  749. for _, v := range *info {
  750. if year < util.IntAll(v["report_year"]) {
  751. year = util.IntAll(v["report_year"])
  752. phone = util.ObjToString(v["company_phone"])
  753. email = util.ObjToString(v["company_email"])
  754. }
  755. }
  756. if year != 0 {
  757. tmp["company_phone"] = phone
  758. tmp["company_email"] = email
  759. }
  760. }
  761. }
  762. // website_url
  763. func websiteFunMySql(tmp map[string]interface{}) {
  764. query := "SELECT website_url, website_name, website_type, report_year, is_history FROM annual_report_website WHERE company_id=?"
  765. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  766. if len(*info) > 0 {
  767. year := 0
  768. web := ""
  769. for _, v := range *info {
  770. if year < util.IntAll(v["report_year"]) && util.IntAll(tmp["is_history"]) == 0 {
  771. year = util.IntAll(v["report_year"])
  772. web = util.ObjToString(v["website_url"])
  773. }
  774. }
  775. if year != 0 {
  776. tmp["website_url"] = web
  777. }
  778. }
  779. }
  780. func websiteFun(tmp map[string]interface{}) {
  781. field := bson.M{"website_url": 1, "website_name": 1, "website_type": 1, "report_year": 1, "is_history": 1}
  782. info, b := MongoTool1.Find("annual_report_website", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  783. if b && len(*info) > 0 {
  784. year := 0
  785. web := ""
  786. for _, v := range *info {
  787. if year < util.IntAll(v["report_year"]) && util.IntAll(tmp["is_history"]) == 0 {
  788. year = util.IntAll(v["report_year"])
  789. web = util.ObjToString(v["website_url"])
  790. }
  791. }
  792. if year != 0 {
  793. tmp["website_url"] = web
  794. }
  795. }
  796. }
  797. // company_shortname 企业简称
  798. func getStName(name string) string {
  799. regnames := regPre.FindStringSubmatch(name)
  800. lenth := len(regnames)
  801. if lenth < 1 {
  802. return ""
  803. }
  804. newstr := regnames[lenth-1]
  805. ch := seg.Cut(newstr, false)
  806. val := []string{}
  807. for word := range ch {
  808. val = append(val, word)
  809. }
  810. name2 := ""
  811. for _, v := range val {
  812. name2 = name2 + v
  813. if len([]rune(name2)) >= 4 {
  814. break
  815. }
  816. }
  817. return name2
  818. }
  819. func taskinfo(tmp map[string]interface{}) {
  820. q := map[string]interface{}{"company_id": tmp["_id"]}
  821. info, _ := MongoTool1.FindOne("company_base", q)
  822. if len(*info) > 0 {
  823. InfoStd(*info)
  824. }
  825. }
  826. func taskinfo1() {
  827. //updataMap := make(map[string]interface{})
  828. //updataMap["company_area"] = "内蒙古"
  829. //for i, field := range AreaFiled {
  830. // if tmp[field] == nil {
  831. // continue
  832. // }
  833. // if code := fmt.Sprint(tmp[field]); code != "" {
  834. // if i == 0 && len(code) >= 8 { //credit_no企业信用代码
  835. // code = code[2:8]
  836. // } else if i == 1 && len(code) >= 6 { //company_code注册号
  837. // code = code[:6]
  838. // }
  839. // if city := AddressMap[code]; city != nil {
  840. // if city.Province != "" && city.Province == util.ObjToString(updataMap["company_area"]) {
  841. // if city.City != "" {
  842. // updataMap["company_city"] = city.City //市
  843. // }
  844. // if city.District != "" {
  845. // updataMap["company_district"] = city.District //县
  846. // }
  847. // break
  848. // }
  849. // } else { //作废中取
  850. // if city := AddressOldMap[code]; city != nil {
  851. // if city.Province != "" && city.Province == util.ObjToString(updataMap["company_area"]) {
  852. // if city.City != "" {
  853. // updataMap["company_city"] = city.City //市
  854. // }
  855. // if city.District != "" {
  856. // updataMap["company_district"] = city.District //县
  857. // }
  858. // }
  859. // break
  860. // }
  861. // }
  862. // }
  863. //}
  864. //
  865. //_, _ = client.Update().Index("qyxy_v2").Type("qyxy").Id(util.ObjToString(tmp["_id"])).
  866. // Doc(updataMap).Refresh(true).Do()
  867. //updataInfo := []map[string]interface{}{
  868. // {"_id": tmp["_id"]},
  869. // {"$set": updataMap},
  870. //}
  871. //updatePool <- updataInfo
  872. }