data_source_longzhong.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "time"
  5. )
  6. type Longzhongdata struct {
  7. LongzhongdataId int `orm:"column(longzhongdata_id);pk"`
  8. LongzhonginfoId int
  9. TradeCode string
  10. Dt string
  11. Close float64
  12. CreateTime time.Time
  13. ModifyTime time.Time
  14. UnitDesc string
  15. UpdTime string
  16. }
  17. type Longzhonginfo struct {
  18. LongzhonginfoId int `orm:"column(longzhonginfo_id);pk"`
  19. TradeCode string
  20. SecName string
  21. Frequency string
  22. ClassifyId int
  23. ClassifyName string
  24. Unit string
  25. CreateTime time.Time
  26. Remark string
  27. IsNormal string
  28. LastModifyDate string
  29. Unitid int64
  30. TempId int64
  31. TempName string
  32. ModifyTime time.Time
  33. }
  34. func GetLongzhonginfoBySecName(secName string) (item *Longzhongdata, err error) {
  35. o := orm.NewOrm()
  36. o.Using("edb")
  37. sql := `SELECT * FROM longzhonginfo WHERE sec_name=? `
  38. err = o.Raw(sql, secName).QueryRow(&item)
  39. return
  40. }
  41. //判断指标数据是否已经录入
  42. func GetLongzhongdataCount(longzhonginfoId int, dt string) (count int, err error) {
  43. o := orm.NewOrm()
  44. o.Using("edb")
  45. sql := `SELECT COUNT(1) AS count FROM longzhongdata WHERE longzhonginfo_id=? AND dt=? `
  46. err = o.Raw(sql, longzhonginfoId, dt).QueryRow(&count)
  47. return
  48. }
  49. func AddLongzhongdata(item *Longzhongdata) (err error) {
  50. o := orm.NewOrm()
  51. o.Using("edb")
  52. _, err = o.Insert(item)
  53. return
  54. }
  55. func ModifyLongzhongdata(item *Longzhongdata) (err error) {
  56. o := orm.NewOrm()
  57. o.Using("edb")
  58. sql := ` UPDATE longzhongdata
  59. SET
  60. close = ?,
  61. modify_time= NOW(),
  62. unit_desc= ?,
  63. upd_time = ?
  64. WHERE longzhonginfo_id = ? AND dt=?
  65. `
  66. _, err = o.Raw(sql, item.Close, item.UnitDesc, item.UpdTime, item.LongzhonginfoId, item.Dt).Exec()
  67. return
  68. }
  69. func AddLongzhonginfo(item *Longzhonginfo) (newId int64, err error) {
  70. o := orm.NewOrm()
  71. o.Using("edb")
  72. newId, err = o.Insert(item)
  73. return
  74. }
  75. func ModifyLongzhonginfo(item *Longzhonginfo) (err error) {
  76. o := orm.NewOrm()
  77. o.Using("edb")
  78. sql := `UPDATE longzhonginfo
  79. SET
  80. sec_name = ?,
  81. unit = ?,
  82. frequency = ?,
  83. classify_id = ?,
  84. classify_name = ?,
  85. remark = ?,
  86. last_modify_date = ?,
  87. temp_id = ?,
  88. temp_name = ?,
  89. is_normal = ?,
  90. modify_time=NOW()
  91. WHERE unitid = ? `
  92. _, err = o.Raw(sql, item.SecName, item.Unit, item.Frequency, item.ClassifyId, item.ClassifyName, item.Remark, item.LastModifyDate, item.TempId, item.TempName, item.IsNormal, item.Unitid).Exec()
  93. return
  94. }
  95. //判断指标数据是否已经录入
  96. func GetLongzhonginfoCount(classifyId int, unitid int64) (count int, err error) {
  97. o := orm.NewOrm()
  98. o.Using("edb")
  99. sql := `SELECT COUNT(1) AS count FROM longzhonginfo WHERE classify_id=? AND unitid=? `
  100. err = o.Raw(sql, classifyId, unitid).QueryRow(&count)
  101. return
  102. }
  103. type LzProductInfoResp struct {
  104. Msg string `json:"msg"`
  105. Code string `json:"code"`
  106. Data []*LzProductInfo `json:"data"`
  107. }
  108. type LzProductInfo struct {
  109. Unitid int64 `json:"unitid"`
  110. ProUnitName string `json:"proUnitName"`
  111. Tempid int64 `json:"tempid"`
  112. TempName string `json:"tempName"`
  113. Proid int `json:"proid"`
  114. ProName string `json:"proName"`
  115. Unit string `json:"unit"`
  116. LzType string `json:"type"`
  117. Maxdate string `json:"maxdate"`
  118. IsNormal string `json:"isNormal"`
  119. }
  120. func GetLongzhonginfoMaxId() (count int, err error) {
  121. o := orm.NewOrm()
  122. o.Using("edb")
  123. sql := `SELECT MAX(longzhonginfo_id) AS count FROM longzhonginfo`
  124. err = o.Raw(sql).QueryRow(&count)
  125. return
  126. }
  127. type LzProductInfoDetail struct {
  128. UnitId int64 `json:"unit_id"`
  129. UnitName string `json:"unit_name"`
  130. TempId int `json:"temp_id"`
  131. TempName string `json:"temp_name"`
  132. TempUnit string `json:"temp_unit"`
  133. ProId int `json:"pro_id"`
  134. ProCnName string `json:"pro_cn_name"`
  135. UnitValue float64 `json:"unit_value"`
  136. UnitDesc string `json:"unit_desc"`
  137. DataTime string `json:"data_time"`
  138. UpdTime string `json:"upd_time"`
  139. }
  140. type LzProductInfoDetailResp struct {
  141. Msg string `json:"msg"`
  142. Code string `json:"code"`
  143. Data []*LzProductInfoDetail `json:"data"`
  144. Pagesize int `json:"pagesize"`
  145. Page int `json:"page"`
  146. }
  147. func GetLongzhonginfoByUnitId(classifyName string, unitId int64) (item *Longzhongdata, err error) {
  148. o := orm.NewOrm()
  149. o.Using("edb")
  150. sql := `SELECT * FROM longzhonginfo WHERE unitid=? AND classify_name=?`
  151. err = o.Raw(sql, unitId, classifyName).QueryRow(&item)
  152. return
  153. }
  154. func GetLongzhongDataById(lzInfoId int) (items []*Longzhongdata, err error) {
  155. o := orm.NewOrm()
  156. o.Using("edb")
  157. sql := `SELECT * FROM longzhongdata WHERE longzhonginfo_id=? ORDER BY dt DESC `
  158. _, err = o.Raw(sql, lzInfoId).QueryRows(&items)
  159. return
  160. }
  161. func GetLongzhongDataMaxCount(classifyId int) (count int, err error) {
  162. o := orm.NewOrm()
  163. o.Using("edb")
  164. sql := `SELECT MAX(t.num) AS count FROM (
  165. SELECT COUNT(1) AS num FROM longzhonginfo AS a
  166. INNER JOIN longzhongdata AS b ON a.longzhonginfo_id=b.longzhonginfo_id
  167. WHERE a.classify_id=?
  168. GROUP BY a.longzhonginfo_id
  169. )AS t `
  170. err = o.Raw(sql, classifyId).QueryRow(&count)
  171. return
  172. }
  173. type LongzhonginfoList struct {
  174. LongzhonginfoId int `orm:"column(longzhonginfo_id);pk"`
  175. TradeCode string
  176. SecName string
  177. Frequency string
  178. ClassifyId int
  179. ClassifyName string
  180. Unit string
  181. IsNormal string
  182. LastModifyDate string
  183. Unitid int
  184. }
  185. func GetLongzhonginfoList() (items []*LongzhonginfoList, err error) {
  186. o := orm.NewOrm()
  187. o.Using("edb")
  188. sql := ` SELECT * FROM longzhonginfo WHERE is_normal=1 `
  189. _, err = o.Raw(sql).QueryRows(&items)
  190. return
  191. }
  192. func ModifyLongzhonginfoIsNormal(longzhonginfoId int) (err error) {
  193. o := orm.NewOrm()
  194. o.Using("edb")
  195. sql := ` UPDATE longzhonginfo SET is_normal=0 WHERE longzhonginfo_id=? `
  196. _, err = o.Raw(sql,longzhonginfoId).Exec()
  197. return
  198. }