lz_data.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package data_manage
  2. import (
  3. "gorm.io/gorm"
  4. "time"
  5. "eta/eta_api/global"
  6. "eta/eta_api/utils"
  7. )
  8. type LzClassify struct {
  9. BreedId int `gorm:"column:breed_id" description:"分类id"`
  10. BreedName string `gorm:"column:breed_name" description:"分类名称"`
  11. }
  12. func GetLzSurveyClassify() (items []*LzClassify, err error) {
  13. sql := `SELECT breed_id,breed_name FROM longzhong_survey_product GROUP BY breed_name ORDER BY breed_name DESC`
  14. o := global.DbMap[utils.DbNameManualIndex]
  15. err = o.Raw(sql).Find(&items).Error
  16. return
  17. }
  18. type LzFrequency struct {
  19. Frequency int `description:"频度:1-日度 2-周度 3-月度 4-季度 5-年度 99-无固定频率"`
  20. }
  21. func GetLzFrequencyByClassifyId(breedId int) (items []*LzFrequency, err error) {
  22. sql := `SELECT frequency FROM longzhong_survey_product WHERE breed_id=? GROUP BY frequency ORDER BY frequency ASC`
  23. o := global.DbMap[utils.DbNameManualIndex]
  24. err = o.Raw(sql, breedId).Find(&items).Error
  25. return
  26. }
  27. type LongzhongSurveyProduct struct {
  28. SurveyProductId int `gorm:"column:survey_product_id;primaryKey"`
  29. ProjectQuotaId int64 `gorm:"column:project_quota_id"`
  30. BreedId string `gorm:"column:breed_id"`
  31. BreedName string `gorm:"column:breed_name"`
  32. QuotaId string `gorm:"column:quota_id"`
  33. QuotaName string `gorm:"column:quota_name"`
  34. UnitId string `gorm:"column:unit_id"`
  35. UnitName string `gorm:"column:unit_name"`
  36. SampleType int64 `gorm:"column:sample_type"`
  37. SampleId string `gorm:"column:sample_id"`
  38. SampleName string `gorm:"column:sample_name"`
  39. DeviceId string `gorm:"column:device_id"`
  40. Device string `gorm:"column:device"`
  41. ProductCraftId string `gorm:"column:product_craft_id"`
  42. ProductCraft string `gorm:"column:product_craft"`
  43. ProductLine string `gorm:"column:product_line"`
  44. InputMode int64 `gorm:"column:input_mode"`
  45. Frequency int64 `gorm:"column:frequency"`
  46. InputValue string `gorm:"column:input_value"`
  47. TaskShouldFinishTime int `gorm:"column:task_should_finish_time"`
  48. CustomId string `gorm:"column:custom_id"`
  49. CustomType int64 `gorm:"column:custom_type"`
  50. Custom string `gorm:"column:custom"`
  51. QuotaSampleId int64 `gorm:"column:quota_sample_id"`
  52. StartDate string `gorm:"column:start_date"`
  53. EndDate string `gorm:"column:end_date"`
  54. ModifyTime time.Time `gorm:"column:modify_time"`
  55. LzCode string `gorm:"column:lz_code"`
  56. }
  57. func GetLongzhongSurveyProduct(breedId, frequency int) (items []*LongzhongSurveyProduct, err error) {
  58. sql := `SELECT * FROM longzhong_survey_product WHERE breed_id=? AND frequency=? ORDER BY survey_product_id ASC`
  59. o := global.DbMap[utils.DbNameManualIndex]
  60. err = o.Raw(sql, breedId, frequency).Find(&items).Error
  61. return
  62. }
  63. type LzProductList struct {
  64. SurveyProductId int `gorm:"column:survey_product_id;primaryKey"`
  65. BreedName string `gorm:"column:breed_name" description:"品种名称"`
  66. QuotaName string `gorm:"column:quota_name" description:"指标名称"`
  67. UnitName string `gorm:"column:unit_name" description:"单位"`
  68. SampleType int64 `gorm:"column:sample_type" description:"样本类型 0-空 1-企业 2-港口 3-运距 4-区域/国家 99-不确定"`
  69. SampleName string `gorm:"column:sample_name" description:"样本名称"`
  70. Device string `gorm:"column:device" description:"设备"`
  71. Frequency int64 `gorm:"column:frequency" description:"频度"`
  72. Custom string `gorm:"column:custom" description:"扩展字段"`
  73. StartDate string `gorm:"column:start_date" description:"开始日期"`
  74. EndDate string `gorm:"column:end_date" description:"结束日期"`
  75. ModifyTime string `gorm:"column:modify_time" description:"修改时间"`
  76. LzCode string `gorm:"column:lz_code" description:"指标编码"`
  77. DataList []*LzProductData `gorm:"-"`
  78. }
  79. type LzProductData struct {
  80. InputValue string `description:"日期"`
  81. DataTime string `description:"值"`
  82. }
  83. func (m *LzProductData) AfterFind(db *gorm.DB) (err error) {
  84. if utils.NeedDateOrTimeFormat(utils.DbDriverName) {
  85. if m.DataTime != "" {
  86. m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
  87. }
  88. }
  89. return
  90. }
  91. func GetLongzhongSurveyProductData(surveyProductId int) (items []*LzProductData, err error) {
  92. sql := `SELECT * FROM longzhong_survey_data WHERE survey_product_id=? ORDER BY data_time DESC`
  93. o := global.DbMap[utils.DbNameManualIndex]
  94. err = o.Raw(sql, surveyProductId).Find(&items).Error
  95. return
  96. }
  97. func GetLongzhongSurveyProductByCode(lzCode string) (items *LongzhongSurveyProduct, err error) {
  98. sql := `SELECT * FROM longzhong_survey_product WHERE lz_code=?`
  99. o := global.DbMap[utils.DbNameManualIndex]
  100. err = o.Raw(sql, lzCode).First(&items).Error
  101. return
  102. }