common.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package task
  4. import (
  5. "adm-dws/apis"
  6. "adm-dws/common.in/clinit"
  7. "time"
  8. )
  9. func NewDwsMessage(dwsMessage *apis.DwsMessage,outputSourceCode string) *apis.DwsMessage{
  10. msg := &apis.DwsMessage{}
  11. msg.OdsMsgType =dwsMessage.OdsMsgType
  12. if dwsMessage.Timestamp != 0 {
  13. msg.Timestamp = dwsMessage.Timestamp
  14. }else{
  15. msg.Timestamp = time.Now().Unix()
  16. }
  17. msg.SourceCode = outputSourceCode
  18. msg.OfflineTaskId = dwsMessage.OfflineTaskId
  19. return msg
  20. }
  21. func NewAdsMessage(dwsMessage *apis.DwsMessage,outputSourceCode,action string) *apis.AdsMessage {
  22. msg := &apis.AdsMessage{}
  23. msg.OdsMsgType =dwsMessage.OdsMsgType
  24. msg.Timestamp = time.Now().Unix()
  25. msg.SourceCode = outputSourceCode
  26. msg.Action = action
  27. msg.OfflineTaskId = dwsMessage.OfflineTaskId
  28. return msg
  29. }
  30. var ProvinceMap map[string]string
  31. var AreaMap map[string]string
  32. var SurnameMap map[string]string
  33. var CompoundSurnameMap map[string]string
  34. var LastNameMap map[string]string
  35. func Load(){
  36. ProvinceMap = make(map[string]string)
  37. AreaMap = make(map[string]string)
  38. SurnameMap = make(map[string]string)
  39. CompoundSurnameMap = make(map[string]string)
  40. LastNameMap = make(map[string]string)
  41. var codeList []string
  42. err := clinit.DB().Raw("select plate_code from t_adm_province").Find(&codeList).Error
  43. if err == nil {
  44. for _,v := range codeList{
  45. ProvinceMap[v] = ""
  46. }
  47. }
  48. err = clinit.DB().Raw("select area_code from t_adm_area").Find(&codeList).Error
  49. if err == nil {
  50. for _,v := range codeList{
  51. AreaMap[v] = ""
  52. }
  53. }
  54. err = clinit.DB().Raw("select surname from t_adm_surname").Find(&codeList).Error
  55. if err == nil {
  56. for _,v := range codeList{
  57. if len(v) > 3{
  58. CompoundSurnameMap[v] = ""
  59. }else{
  60. SurnameMap[v] = ""
  61. }
  62. }
  63. }
  64. err = clinit.DB().Raw("select last_name from t_adm_lastname").Find(&codeList).Error
  65. if err == nil {
  66. for _,v := range codeList{
  67. for _,v1 := range v{
  68. LastNameMap[string(v1)] = ""
  69. }
  70. //LastNameMap[v] = ""
  71. }
  72. }
  73. }