task.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  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_winner", companyName); err == nil && b {
  395. maps := make(map[string]interface{})
  396. text := redis.GetStr("qyxy_winner", 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. save["bid_unittype"] = []string{"厂商"}
  425. }
  426. // search_type
  427. if t := util.ObjToString(save["company_type"]); t != "" {
  428. if t != "个体工商户" && t != "其他" {
  429. t1 := util.ObjToString(save["company_type_old"])
  430. name := util.ObjToString(save["company_name"])
  431. if strings.Contains(t1, "有限合伙") {
  432. save["search_type"] = "有限合伙"
  433. } else if strings.Contains(t1, "合伙") {
  434. save["search_type"] = "普通合伙"
  435. } else if strings.Contains(name, "股份") ||
  436. (strings.Contains(t1, "上市") && !strings.Contains(t1, "非上市")) {
  437. save["search_type"] = "股份有限公司"
  438. } else {
  439. save["search_type"] = "有限责任公司"
  440. }
  441. }
  442. }
  443. // company_shortname
  444. if m := getStName(util.ObjToString(save["company_name"])); m != "" {
  445. save["company_shortname"] = m
  446. }
  447. }
  448. update["$set"] = save
  449. if len(push) > 0 {
  450. update["$push"] = push
  451. }
  452. updataInfo := []map[string]interface{}{
  453. {"_id": save["_id"]},
  454. update,
  455. }
  456. updatePool <- updataInfo
  457. }
  458. // InfoStd 存量全量数据
  459. func InfoStd(tmp map[string]interface{}) {
  460. save := make(map[string]interface{})
  461. for _, v := range company_base {
  462. if tmp[v] == nil {
  463. continue
  464. }
  465. // company_type
  466. if v == "company_type" {
  467. save["company_type_old"] = tmp[v]
  468. if text := util.ObjToString(tmp["company_type"]); text != "" {
  469. if strings.Contains(text, "个体") || strings.Contains(text, "非公司") {
  470. save["company_type"] = "个体工商户"
  471. } else {
  472. text = strings.ReplaceAll(text, "(", "(")
  473. text = strings.ReplaceAll(text, ")", ")")
  474. if stype := QyStypeMap[text]; stype != "" {
  475. save["company_type"] = stype
  476. } else {
  477. save["company_type"] = "其他"
  478. }
  479. }
  480. }
  481. // company_status
  482. } else if v == "company_status" {
  483. save["company_status_old"] = tmp[v]
  484. if text := util.ObjToString(tmp["company_status"]); text != "" {
  485. text = strings.ReplaceAll(text, "(", "(")
  486. text = strings.ReplaceAll(text, ")", ")")
  487. if status := CompanyStatusMap[text]; status != "" {
  488. save["company_status"] = status
  489. } else {
  490. save["company_status"] = "其他"
  491. }
  492. }
  493. } else if v == "capital" {
  494. // capital/currency
  495. text := util.ObjToString(tmp[v])
  496. if currency := GetCurrency(text); currency != "" {
  497. save["currency"] = currency //币种
  498. }
  499. capital := ObjToMoney(text)
  500. capital = capital / 10000
  501. if capital != 0 {
  502. save[v] = capital
  503. }
  504. } else if v == "use_flag" {
  505. save[v] = util.IntAll(tmp[v])
  506. } else {
  507. save[v] = tmp[v]
  508. }
  509. }
  510. save["_id"] = tmp["company_id"]
  511. // mysql create_time/update_time
  512. save["create_time_msql"] = tmp["create_time"]
  513. save["update_time_msql"] = tmp["update_time"]
  514. save["createtime"] = time.Now().Unix()
  515. save["updatetime"] = time.Now().Unix()
  516. // company_area/company_city/company_district
  517. pshort := util.ObjToString(tmp["province_short"])
  518. save["company_area"] = province_map[pshort]
  519. for i, field := range AreaFiled {
  520. if tmp[field] == nil {
  521. continue
  522. }
  523. if code := fmt.Sprint(tmp[field]); code != "" {
  524. if i == 0 && len(code) >= 8 { //credit_no企业信用代码
  525. code = code[2:8]
  526. } else if i == 1 && len(code) >= 6 { //company_code注册号
  527. code = code[:6]
  528. }
  529. if city := AddressMap[code]; city != nil { //未作废中取
  530. if city.Province != "" && strings.Contains(city.Province, util.ObjToString(save["company_area"])) {
  531. if city.City != "" {
  532. save["company_city"] = city.City //市
  533. }
  534. if city.District != "" {
  535. save["company_district"] = city.District //县
  536. }
  537. break
  538. }
  539. } else { //作废中取
  540. if city := AddressOldMap[code]; city != nil {
  541. if city.Province != "" && city.Province == save["company_area"] {
  542. if city.City != "" {
  543. save["company_city"] = city.City //市
  544. }
  545. if city.District != "" {
  546. save["company_district"] = city.District //县
  547. }
  548. }
  549. break
  550. }
  551. }
  552. }
  553. }
  554. if tmp["company_type"] != "个体工商户" {
  555. // history_name
  556. historyNameFun(save)
  557. // company_employee
  558. employeeFun(save)
  559. // company_partner
  560. partnerFun(save)
  561. // annual_report_base
  562. reportFun(save)
  563. // website_url
  564. websiteFun(save)
  565. // bid_contracttype
  566. var types []string
  567. if phone := util.ObjToString(save["company_phone"]); phone != "" {
  568. if len(phone) == 11 {
  569. types = append(types, "手机号")
  570. } else {
  571. types = append(types, "固定电话")
  572. }
  573. }
  574. if util.ObjToString(save["company_email"]) != "" {
  575. types = append(types, "邮箱")
  576. }
  577. companyName := util.ObjToString(tmp["company_name"])
  578. // redis bid_unittype、bid_purchasing、bid_projectname
  579. if b, err := redis.Exists("qyxy_winner", companyName); err == nil && b {
  580. maps := make(map[string]interface{})
  581. text := redis.GetStr("qyxy_winner", companyName)
  582. err1 := json.Unmarshal([]byte(text), &maps)
  583. if err1 != nil {
  584. util.Debug(companyName, "winner-----map解析异常")
  585. } else {
  586. for k := range maps {
  587. if k == "bid_contracttype" {
  588. t1 := util.ObjArrToStringArr(maps[k].([]interface{}))
  589. types = append(types, t1...)
  590. } else {
  591. save[k] = maps[k]
  592. }
  593. }
  594. }
  595. }
  596. if len(types) == 0 {
  597. types = append(types, "不存在")
  598. }
  599. save["bid_contracttype"] = types
  600. // bid_unittype
  601. flag := false
  602. for _, v := range WordsArr {
  603. if strings.Contains(util.ObjToString(tmp["business_scope"]), v) {
  604. flag = true
  605. break
  606. }
  607. }
  608. if flag {
  609. save["bid_unittype"] = []string{"厂商"}
  610. }
  611. // search_type
  612. if t := util.ObjToString(save["company_type"]); t != "" {
  613. if t != "个体工商户" && t != "其他" {
  614. t1 := util.ObjToString(save["company_type_old"])
  615. name := util.ObjToString(save["company_name"])
  616. if strings.Contains(t1, "有限合伙") {
  617. save["search_type"] = "有限合伙"
  618. } else if strings.Contains(t1, "合伙") {
  619. save["search_type"] = "普通合伙"
  620. } else if strings.Contains(name, "股份") ||
  621. (strings.Contains(t1, "上市") && !strings.Contains(t1, "非上市")) {
  622. save["search_type"] = "股份有限公司"
  623. } else {
  624. save["search_type"] = "有限责任公司"
  625. }
  626. }
  627. }
  628. // company_shortname
  629. if m := getStName(util.ObjToString(tmp["company_name"])); m != "" {
  630. save["company_shortname"] = m
  631. }
  632. }
  633. saveInfo := []map[string]interface{}{
  634. {"_id": tmp["company_id"]},
  635. {"$set": save},
  636. }
  637. //savePool <- save
  638. updatePool <- saveInfo
  639. }
  640. // 曾用名
  641. func historynamefunMysql(tmp map[string]interface{}) {
  642. query := "SELECT history_name FROM company_history_name WHERE company_id=?"
  643. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  644. if len(*info) > 0 {
  645. var names []string
  646. for _, v := range *info {
  647. names = append(names, util.ObjToString(v["history_name"]))
  648. }
  649. tmp["history_name"] = strings.Join(names, ",")
  650. }
  651. }
  652. func historyNameFun(tmp map[string]interface{}) {
  653. field := bson.M{"history_name": 1}
  654. info, b := MongoTool1.Find("company_history_name", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  655. if b && len(*info) > 0 {
  656. var names []string
  657. for _, v := range *info {
  658. names = append(names, util.ObjToString(v["history_name"]))
  659. }
  660. tmp["history_name"] = strings.Join(names, ",")
  661. }
  662. }
  663. // company_employee 高管
  664. func employeeFunMySql(tmp map[string]interface{}) {
  665. query := "SELECT employee_name, position, is_history FROM company_employee WHERE company_id=?"
  666. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  667. if len(*info) > 0 {
  668. var names []string
  669. tmp["employees"] = *info
  670. for _, v := range *info {
  671. names = append(names, util.ObjToString(v["employee_name"]))
  672. }
  673. tmp["employee_name"] = strings.Join(names, ",")
  674. }
  675. }
  676. func employeeFun(tmp map[string]interface{}) {
  677. field := bson.M{"employee_name": 1, "position": 1, "is_history": 1}
  678. info, b := MongoTool1.Find("company_employee", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  679. if b && len(*info) > 0 {
  680. var names []string
  681. tmp["employees"] = *info
  682. for _, v := range *info {
  683. names = append(names, util.ObjToString(v["employee_name"]))
  684. }
  685. tmp["employee_name"] = strings.Join(names, ",")
  686. }
  687. }
  688. // company_partner 合伙人
  689. func partnerFunMySql(tmp map[string]interface{}) {
  690. query := "SELECT stock_name, stock_type, is_personal, identify_type, identify_no, stock_capital, stock_realcapital, is_history FROM company_partner WHERE company_id=?"
  691. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  692. if len(*info) > 0 {
  693. var names []string
  694. tmp["partners"] = *info
  695. for _, v := range *info {
  696. if util.IntAll(tmp["is_history"]) == 0 {
  697. names = append(names, util.ObjToString(v["stock_name"]))
  698. }
  699. }
  700. tmp["stock_name"] = strings.Join(names, ",")
  701. }
  702. }
  703. func partnerFun(tmp map[string]interface{}) {
  704. 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}
  705. info, b := MongoTool1.Find("company_partner", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  706. if b && len(*info) > 0 {
  707. var names []string
  708. tmp["partners"] = *info
  709. for _, v := range *info {
  710. if util.IntAll(tmp["is_history"]) == 0 {
  711. names = append(names, util.ObjToString(v["stock_name"]))
  712. }
  713. }
  714. tmp["stock_name"] = strings.Join(names, ",")
  715. }
  716. }
  717. // annual_report_base 年报信息
  718. func reportFunMysql(tmp map[string]interface{}) {
  719. query := "SELECT report_year, company_phone, company_email, zip_code, employee_no, operator_name FROM annual_report_base WHERE company_id=?"
  720. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  721. if len(*info) > 0 {
  722. tmp["annual_reports"] = *info
  723. year := 0
  724. phone, email := "", ""
  725. for _, v := range *info {
  726. if year < util.IntAll(v["report_year"]) {
  727. year = util.IntAll(v["report_year"])
  728. phone = util.ObjToString(v["company_phone"])
  729. email = util.ObjToString(v["company_email"])
  730. }
  731. }
  732. if year != 0 {
  733. tmp["company_phone"] = phone
  734. tmp["company_email"] = email
  735. }
  736. }
  737. }
  738. func reportFun(tmp map[string]interface{}) {
  739. field := bson.M{"report_year": 1, "company_phone": 1, "company_email": 1, "zip_code": 1, "employee_no": 1, "operator_name": 1}
  740. info, b := MongoTool1.Find("annual_report_base", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  741. if b && len(*info) > 0 {
  742. tmp["annual_reports"] = *info
  743. year := 0
  744. phone, email := "", ""
  745. for _, v := range *info {
  746. if year < util.IntAll(v["report_year"]) {
  747. year = util.IntAll(v["report_year"])
  748. phone = util.ObjToString(v["company_phone"])
  749. email = util.ObjToString(v["company_email"])
  750. }
  751. }
  752. if year != 0 {
  753. tmp["company_phone"] = phone
  754. tmp["company_email"] = email
  755. }
  756. }
  757. }
  758. // website_url
  759. func websiteFunMySql(tmp map[string]interface{}) {
  760. query := "SELECT website_url, website_name, website_type, report_year, is_history FROM annual_report_website WHERE company_id=?"
  761. info := MysqlTool.SelectBySql(query, util.ObjToString(tmp["_id"]))
  762. if len(*info) > 0 {
  763. year := 0
  764. web := ""
  765. for _, v := range *info {
  766. if year < util.IntAll(v["report_year"]) && util.IntAll(tmp["is_history"]) == 0 {
  767. year = util.IntAll(v["report_year"])
  768. web = util.ObjToString(v["website_url"])
  769. }
  770. }
  771. if year != 0 {
  772. tmp["website_url"] = web
  773. }
  774. }
  775. }
  776. func websiteFun(tmp map[string]interface{}) {
  777. field := bson.M{"website_url": 1, "website_name": 1, "website_type": 1, "report_year": 1, "is_history": 1}
  778. info, b := MongoTool1.Find("annual_report_website", bson.M{"company_id": tmp["_id"]}, nil, field, false, -1, -1)
  779. if b && len(*info) > 0 {
  780. year := 0
  781. web := ""
  782. for _, v := range *info {
  783. if year < util.IntAll(v["report_year"]) && util.IntAll(tmp["is_history"]) == 0 {
  784. year = util.IntAll(v["report_year"])
  785. web = util.ObjToString(v["website_url"])
  786. }
  787. }
  788. if year != 0 {
  789. tmp["website_url"] = web
  790. }
  791. }
  792. }
  793. // company_shortname 企业简称
  794. func getStName(name string) string {
  795. regnames := regPre.FindStringSubmatch(name)
  796. lenth := len(regnames)
  797. if lenth < 1 {
  798. return ""
  799. }
  800. newstr := regnames[lenth-1]
  801. ch := seg.Cut(newstr, false)
  802. val := []string{}
  803. for word := range ch {
  804. val = append(val, word)
  805. }
  806. name2 := ""
  807. for _, v := range val {
  808. name2 = name2 + v
  809. if len([]rune(name2)) >= 4 {
  810. break
  811. }
  812. }
  813. return name2
  814. }
  815. func taskinfo(tmp map[string]interface{}) {
  816. q := map[string]interface{}{"company_id": tmp["_id"]}
  817. info, _ := MongoTool1.FindOne("company_base", q)
  818. if len(*info) > 0 {
  819. InfoStd(*info)
  820. }
  821. }
  822. func taskinfo1() {
  823. //updataMap := make(map[string]interface{})
  824. //updataMap["company_area"] = "内蒙古"
  825. //for i, field := range AreaFiled {
  826. // if tmp[field] == nil {
  827. // continue
  828. // }
  829. // if code := fmt.Sprint(tmp[field]); code != "" {
  830. // if i == 0 && len(code) >= 8 { //credit_no企业信用代码
  831. // code = code[2:8]
  832. // } else if i == 1 && len(code) >= 6 { //company_code注册号
  833. // code = code[:6]
  834. // }
  835. // if city := AddressMap[code]; city != nil {
  836. // if city.Province != "" && city.Province == util.ObjToString(updataMap["company_area"]) {
  837. // if city.City != "" {
  838. // updataMap["company_city"] = city.City //市
  839. // }
  840. // if city.District != "" {
  841. // updataMap["company_district"] = city.District //县
  842. // }
  843. // break
  844. // }
  845. // } else { //作废中取
  846. // if city := AddressOldMap[code]; city != nil {
  847. // if city.Province != "" && city.Province == util.ObjToString(updataMap["company_area"]) {
  848. // if city.City != "" {
  849. // updataMap["company_city"] = city.City //市
  850. // }
  851. // if city.District != "" {
  852. // updataMap["company_district"] = city.District //县
  853. // }
  854. // }
  855. // break
  856. // }
  857. // }
  858. // }
  859. //}
  860. //
  861. //_, _ = client.Update().Index("qyxy_v2").Type("qyxy").Id(util.ObjToString(tmp["_id"])).
  862. // Doc(updataMap).Refresh(true).Do()
  863. //updataInfo := []map[string]interface{}{
  864. // {"_id": tmp["_id"]},
  865. // {"$set": updataMap},
  866. //}
  867. //updatePool <- updataInfo
  868. }