edb_data_base.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package data_manage
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_task/utils"
  6. "rdluck_tools/orm"
  7. "strconv"
  8. "time"
  9. )
  10. func GetEdbDataTableName(source int) (tableName string) {
  11. switch source {
  12. case utils.DATA_SOURCE_THS:
  13. tableName = "edb_data_ths"
  14. case utils.DATA_SOURCE_WIND:
  15. tableName = "edb_data_wind"
  16. case utils.DATA_SOURCE_PB:
  17. tableName = "edb_data_pb"
  18. case utils.DATA_SOURCE_CALCULATE:
  19. tableName = "edb_data_calculate"
  20. case utils.DATA_SOURCE_CALCULATE_LJZZY:
  21. tableName = "edb_data_calculate_ljzzy"
  22. case utils.DATA_SOURCE_CALCULATE_TBZ:
  23. tableName = "edb_data_calculate_tbz"
  24. case utils.DATA_SOURCE_CALCULATE_TCZ:
  25. tableName = "edb_data_calculate_tcz"
  26. case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  27. tableName = "edb_data_calculate_nszydpjjs"
  28. case utils.DATA_SOURCE_MANUAL:
  29. tableName = "edb_data_manual"
  30. case utils.DATA_SOURCE_LZ:
  31. tableName = "edb_data_lz"
  32. case utils.DATA_SOURCE_YS:
  33. tableName = "edb_data_ys"
  34. case utils.DATA_SOURCE_CALCULATE_HBZ:
  35. tableName = "edb_data_calculate_hbz"
  36. case utils.DATA_SOURCE_CALCULATE_HCZ:
  37. tableName = "edb_data_calculate_hcz"
  38. case utils.DATA_SOURCE_CALCULATE_BP:
  39. tableName = "edb_data_calculate_bp"
  40. case utils.DATA_SOURCE_GL:
  41. tableName = "edb_data_gl"
  42. default:
  43. tableName = ""
  44. errors.New("无效的渠道:" + strconv.Itoa(source))
  45. return
  46. }
  47. return
  48. }
  49. func GetEdbInfoCalculateTableName(source int) (tableName string) {
  50. switch source {
  51. case utils.DATA_SOURCE_CALCULATE:
  52. tableName = "edb_info_calculate"
  53. case utils.DATA_SOURCE_CALCULATE_LJZZY:
  54. tableName = "edb_info_calculate_ljzzy"
  55. case utils.DATA_SOURCE_CALCULATE_TBZ:
  56. tableName = "edb_info_calculate_tbz"
  57. case utils.DATA_SOURCE_CALCULATE_TCZ:
  58. tableName = "edb_info_calculate_tcz"
  59. case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  60. tableName = "edb_info_calculate_nszydpjjs"
  61. case utils.DATA_SOURCE_CALCULATE_HBZ:
  62. tableName = "edb_info_calculate_hbz"
  63. case utils.DATA_SOURCE_CALCULATE_HCZ:
  64. tableName = "edb_info_calculate_hcz"
  65. case utils.DATA_SOURCE_CALCULATE_BP:
  66. tableName = "edb_info_calculate_bp"
  67. default:
  68. tableName = ""
  69. errors.New("无效的渠道:" + strconv.Itoa(source))
  70. return
  71. }
  72. return
  73. }
  74. func GetAddSql(edbInfoId, edbCode, dataTime, timestampStr,value string) (addSql string) {
  75. nowStr := time.Now().Format(utils.FormatDateTime)
  76. addSql += "("
  77. addSql += edbInfoId + "," + "'" + edbCode + "'" + "," + "'" + dataTime + "'" + "," + value + "," + "'" + nowStr + "'" +
  78. "," + "'" + nowStr + "'" + "," + "1"
  79. addSql += "," + "'" + timestampStr + "'"
  80. addSql += "),"
  81. return
  82. }
  83. func GetEdbDataBaseByCodeAndDate(source int, edbCode string, startDate string) (count int, err error) {
  84. o := orm.NewOrm()
  85. o.Using("data")
  86. tableName := GetEdbDataTableName(source)
  87. sql := ` SELECT COUNT(1) AS count FROM %s WHERE edb_code=? AND data_time=? `
  88. sql = fmt.Sprintf(sql, tableName)
  89. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  90. return
  91. }
  92. type EdbDataBase struct {
  93. EdbDataId int `orm:"column(edb_data_id);pk"`
  94. EdbInfoId int
  95. EdbCode string
  96. DataTime string
  97. Value string
  98. Status int
  99. CreateTime time.Time
  100. ModifyTime time.Time
  101. DataTimestamp int64
  102. }