lz_data.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type LzClassify struct {
  8. BreedId int `description:"分类id"`
  9. BreedName string `description:"分类名称"`
  10. }
  11. func GetLzSurveyClassify() (items []*LzClassify, err error) {
  12. sql := ` SELECT breed_id,breed_name FROM longzhong_survey_product GROUP BY breed_name ORDER BY breed_name DESC `
  13. o := orm.NewOrmUsingDB("edb")
  14. o.Raw(sql).QueryRows(&items)
  15. return
  16. }
  17. type LzFrequency struct {
  18. Frequency int `description:"频度:1-日度 2-周度 3-月度 4-季度 5-年度 99-无固定频率"`
  19. }
  20. func GetLzFrequencyByClassifyId(breedId int) (items []*LzFrequency, err error) {
  21. sql := ` SELECT frequency FROM longzhong_survey_product WHERE breed_id=? GROUP BY frequency ORDER BY frequency ASC `
  22. o := orm.NewOrmUsingDB("edb")
  23. _, err = o.Raw(sql, breedId).QueryRows(&items)
  24. return
  25. }
  26. // [2025-zsh-时间类型修复-chenhan]
  27. type LongzhongSurveyProduct struct {
  28. SurveyProductId int `orm:"column(survey_product_id);pk"`
  29. ProjectQuotaId int64
  30. BreedId string
  31. BreedName string
  32. QuotaId string
  33. QuotaName string
  34. UnitId string
  35. UnitName string
  36. SampleType int64
  37. SampleId string
  38. SampleName string
  39. DeviceId string
  40. Device string
  41. ProductCraftId string
  42. ProductCraft string
  43. ProductLine string
  44. InputMode int64
  45. Frequency int64
  46. InputValue string
  47. TaskShouldFinishTime int
  48. CustomId string
  49. CustomType int64
  50. Custom string
  51. QuotaSampleId int64
  52. StartDate string
  53. EndDate string
  54. ModifyTime time.Time
  55. LzCode string
  56. }
  57. type LongzhongSurveyProductOrm struct {
  58. SurveyProductId int `orm:"column(survey_product_id);pk"`
  59. ProjectQuotaId int64
  60. BreedId string
  61. BreedName string
  62. QuotaId string
  63. QuotaName string
  64. UnitId string
  65. UnitName string
  66. SampleType int64
  67. SampleId string
  68. SampleName string
  69. DeviceId string
  70. Device string
  71. ProductCraftId string
  72. ProductCraft string
  73. ProductLine string
  74. InputMode int64
  75. Frequency int64
  76. InputValue string
  77. TaskShouldFinishTime int
  78. CustomId string
  79. CustomType int64
  80. Custom string
  81. QuotaSampleId int64
  82. StartDate time.Time
  83. EndDate time.Time
  84. ModifyTime time.Time
  85. LzCode string
  86. }
  87. func (obj *LongzhongSurveyProductOrm) toView() *LongzhongSurveyProduct {
  88. return &LongzhongSurveyProduct{
  89. SurveyProductId: obj.SurveyProductId,
  90. ProjectQuotaId: obj.ProjectQuotaId,
  91. BreedId: obj.BreedId,
  92. BreedName: obj.BreedName,
  93. QuotaId: obj.QuotaId,
  94. QuotaName: obj.QuotaName,
  95. UnitId: obj.UnitId,
  96. UnitName: obj.UnitName,
  97. SampleType: obj.SampleType,
  98. SampleId: obj.SampleId,
  99. SampleName: obj.SampleName,
  100. DeviceId: obj.DeviceId,
  101. Device: obj.Device,
  102. ProductCraftId: obj.ProductCraftId,
  103. ProductCraft: obj.ProductCraft,
  104. ProductLine: obj.ProductLine,
  105. InputMode: obj.InputMode,
  106. Frequency: obj.Frequency,
  107. InputValue: obj.InputValue,
  108. TaskShouldFinishTime: obj.TaskShouldFinishTime,
  109. CustomId: obj.CustomId,
  110. CustomType: obj.CustomType,
  111. Custom: obj.Custom,
  112. QuotaSampleId: obj.QuotaSampleId,
  113. StartDate: obj.StartDate.Format(utils.FormatDate),
  114. EndDate: obj.EndDate.Format(utils.FormatDate),
  115. ModifyTime: obj.ModifyTime,
  116. LzCode: obj.LzCode,
  117. }
  118. }
  119. func ToLongzhongSurveyProductList(items []*LongzhongSurveyProductOrm) (itemsOrm []*LongzhongSurveyProduct) {
  120. for _, item := range items {
  121. itemsOrm = append(itemsOrm, item.toView())
  122. }
  123. return
  124. }
  125. func GetLongzhongSurveyProduct(breedId, frequency int) (items []*LongzhongSurveyProduct, err error) {
  126. sql := ` SELECT * FROM longzhong_survey_product WHERE breed_id=? AND frequency=? ORDER BY survey_product_id ASC `
  127. o := orm.NewOrmUsingDB("edb")
  128. _, err = o.Raw(sql, breedId, frequency).QueryRows(&items)
  129. return
  130. }
  131. type LzProductList struct {
  132. SurveyProductId int `orm:"column(survey_product_id);pk"`
  133. BreedName string `description:"品种名称"`
  134. QuotaName string `description:"指标名称"`
  135. UnitName string `description:"单位"`
  136. SampleType int64 `description:"样本类型 0-空 1-企业 2-港口 3-运距 4-区域/国家 99-不确定"`
  137. SampleName string `description:"样本名称"`
  138. Device string `description:"设备"`
  139. Frequency int64 `description:"频度"`
  140. Custom string `description:"扩展字段"`
  141. StartDate string `description:"开始日期"`
  142. EndDate string `description:"结束日期"`
  143. ModifyTime string `description:"修改时间"`
  144. LzCode string `description:"指标编码"`
  145. DataList []*LzProductData
  146. }
  147. type LzProductData struct {
  148. InputValue string `description:"日期"`
  149. DataTime string `description:"值"`
  150. }
  151. func GetLongzhongSurveyProductData(surveyProductId int) (items []*LzProductData, err error) {
  152. sql := ` SELECT * FROM longzhong_survey_data WHERE survey_product_id=? ORDER BY data_time DESC `
  153. o := orm.NewOrmUsingDB("edb")
  154. _, err = o.Raw(sql, surveyProductId).QueryRows(&items)
  155. return
  156. }
  157. func GetLongzhongSurveyProductByCode(lzCode string) (items *LongzhongSurveyProduct, err error) {
  158. sql := ` SELECT * FROM longzhong_survey_product WHERE lz_code=? `
  159. o := orm.NewOrmUsingDB("edb")
  160. err = o.Raw(sql, lzCode).QueryRow(&items)
  161. return
  162. }