longzhong.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package data_source
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/models/data_manage"
  5. "time"
  6. )
  7. type Longzhonginfo struct {
  8. LongzhonginfoId int
  9. TradeCode string
  10. SecName string
  11. Unit string
  12. Frequency string
  13. LastModifyDate string
  14. }
  15. func GetLongzhonginfoByClassifyId(classifyId int) (items []*Longzhonginfo, err error) {
  16. sql := `SELECT * FROM longzhonginfo WHERE classify_id=? ORDER BY longzhonginfo_id ASC `
  17. o := orm.NewOrmUsingDB("edb")
  18. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  19. return
  20. }
  21. func GetLongzhongDataMaxCount(classifyId int) (count int, err error) {
  22. o := orm.NewOrmUsingDB("edb")
  23. sql := `SELECT MAX(t.num) AS count FROM (
  24. SELECT COUNT(1) AS num FROM longzhonginfo AS a
  25. INNER JOIN longzhongdata AS b ON a.longzhonginfo_id=b.longzhonginfo_id
  26. WHERE a.classify_id=?
  27. GROUP BY a.longzhonginfo_id
  28. )AS t `
  29. err = o.Raw(sql, classifyId).QueryRow(&count)
  30. return
  31. }
  32. type Longzhongdata struct {
  33. LongzhongdataId int `orm:"column(longzhongdata_id);pk"`
  34. LongzhonginfoId int
  35. TradeCode string
  36. Dt string
  37. Close float64
  38. CreateTime time.Time
  39. ModifyTime time.Time
  40. UnitDesc string
  41. UpdTime string
  42. DisplayTime string
  43. }
  44. func GetLongzhongDataById(lzInfoId int) (items []*Longzhongdata, err error) {
  45. o := orm.NewOrmUsingDB("edb")
  46. sql := `SELECT * FROM longzhongdata WHERE longzhonginfo_id=? ORDER BY dt DESC `
  47. _, err = o.Raw(sql, lzInfoId).QueryRows(&items)
  48. return
  49. }
  50. func GetLongzhongSurveyDataMaxCount(classifyName string) (count int, err error) {
  51. o := orm.NewOrmUsingDB("edb")
  52. sql := `SELECT MAX(t.num) AS count FROM (
  53. SELECT COUNT(1) AS num FROM longzhong_survey_product AS a
  54. INNER JOIN longzhong_survey_data AS b ON a.survey_product_id=b.survey_product_id
  55. WHERE a.breed_name=?
  56. GROUP BY a.survey_product_id
  57. )AS t `
  58. err = o.Raw(sql, classifyName).QueryRow(&count)
  59. return
  60. }
  61. func GetLongzhongSurveyDataMaxCountByFrequency(classifyName string, frequency int) (count int, err error) {
  62. o := orm.NewOrmUsingDB("edb")
  63. sql := `SELECT MAX(t.num) AS count FROM (
  64. SELECT COUNT(1) AS num FROM longzhong_survey_product AS a
  65. INNER JOIN longzhong_survey_data AS b ON a.survey_product_id=b.survey_product_id
  66. WHERE a.breed_name=? AND a.frequency=?
  67. GROUP BY a.survey_product_id
  68. )AS t `
  69. err = o.Raw(sql, classifyName, frequency).QueryRow(&count)
  70. return
  71. }
  72. type ExportLzSurveyDataMaxCount struct {
  73. Count int `description:"最大数据量"`
  74. BreedId int `description:"品种ID"`
  75. }
  76. func GetExportLzSurveyDataMaxCount(breedIds string) (items []ExportLzSurveyDataMaxCount, err error) {
  77. o := orm.NewOrmUsingDB("edb")
  78. sql := ` SELECT
  79. MAX(t.num) AS count,
  80. t.breed_id
  81. FROM
  82. (
  83. SELECT
  84. COUNT(1) AS num,
  85. a.breed_id AS breed_id
  86. FROM
  87. longzhong_survey_product AS a
  88. INNER JOIN longzhong_survey_data AS b ON a.survey_product_id = b.survey_product_id
  89. WHERE
  90. a.breed_id IN (` + breedIds + `)
  91. GROUP BY
  92. a.survey_product_id
  93. ) AS t
  94. GROUP BY
  95. t.breed_id `
  96. _, err = o.Raw(sql).QueryRows(&items)
  97. return
  98. }
  99. func GetExportLzSurveyDataByBreedIds(breedIds string) (items []*LongzhongSurveyData, err error) {
  100. o := orm.NewOrmUsingDB("edb")
  101. fields := ` survey_product_id, breed_id, input_value, data_time `
  102. sql := `SELECT ` + fields + ` FROM longzhong_survey_data WHERE breed_id IN (` + breedIds + `) ORDER BY breed_id ASC, survey_product_id ASC, data_time DESC `
  103. _, err = o.Raw(sql).QueryRows(&items)
  104. return
  105. }
  106. type LongzhongSurveyData struct {
  107. SurveyDataId int `orm:"column(survey_data_id);pk"`
  108. SurveyProductId int
  109. ProjectQuotaId int64
  110. BreedId string
  111. BreedName string
  112. QuotaId string
  113. QuotaName string
  114. UnitId string
  115. UnitName string
  116. SampleType int64
  117. SampleId string
  118. SampleName string
  119. DeviceId string
  120. Device string
  121. ProductCraftId string
  122. ProductCraft string
  123. ProductLine string
  124. InputMode int64
  125. Frequency int64
  126. InputValue float64
  127. TaskShouldFinishTime int64
  128. CustomId string
  129. CustomType int64
  130. Custom string
  131. QuotaSampleId int64
  132. TaskActualFinishTime int64
  133. AreaName string
  134. ProvinceName string
  135. ResearchStartData int64
  136. ResearchStopData int64
  137. DataTime string
  138. }
  139. func GetLongzhongSurveyDataById(lzInfoId int) (items []*LongzhongSurveyData, err error) {
  140. o := orm.NewOrmUsingDB("edb")
  141. sql := `SELECT * FROM longzhong_survey_data WHERE survey_product_id=? ORDER BY data_time DESC `
  142. _, err = o.Raw(sql, lzInfoId).QueryRows(&items)
  143. return
  144. }
  145. // GetLzItemList 模糊查询隆众数据库指标列表
  146. func GetLzItemList(keyword string) (items []*data_manage.LongzhongSurveyProduct, err error) {
  147. o := orm.NewOrmUsingDB("edb")
  148. sql := "SELECT * FROM longzhong_survey_product WHERE CONCAT(sample_name,breed_name,custom,quota_name,lz_code) LIKE '%" + keyword + "%'"
  149. _, err = o.Raw(sql).QueryRows(&items)
  150. return
  151. }
  152. type lzSurveyData struct {
  153. DataTime string `orm:"column(data_time)" description:"日期"`
  154. InputValue string `orm:"column(input_value)" description:"值"`
  155. }
  156. // GetLzItemListByCode 根据code查询隆众数据列表
  157. func GetLzItemListByCode(lzCode string) (items []*lzSurveyData, err error) {
  158. o := orm.NewOrmUsingDB("edb")
  159. sql := "SELECT * FROM longzhong_survey_data WHERE survey_product_id=? GROUP BY data_time DESC"
  160. _, err = o.Raw(sql, lzCode).QueryRows(&items)
  161. return
  162. }
  163. // GetLzProductIdByCode 根据code查询隆众数据列表
  164. func GetLzProductIdByCode(lzCode string) (productId int, err error) {
  165. o := orm.NewOrmUsingDB("edb")
  166. sql := "SELECT survey_product_id FROM longzhong_survey_product WHERE lz_code=?"
  167. err = o.Raw(sql, lzCode).QueryRow(&productId)
  168. return
  169. }
  170. // GetLzProductIdByCode 根据code查询隆众数据列表
  171. func GetLzSurveyDataMaxCountByProductId(surveyProductId int) (productId int, err error) {
  172. o := orm.NewOrmUsingDB("edb")
  173. sql := "SELECT COUNT(1) FROM longzhong_survey_data WHERE survey_product_id=?"
  174. err = o.Raw(sql, surveyProductId).QueryRow(&productId)
  175. return
  176. }