task.go 29 KB

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