data_source_longzhong.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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 classify_id IN(55,56) `
  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. }
  199. type LzPriceInfo struct {
  200. Standard string `json:"standard"`
  201. ModelName string `json:"modelName"`
  202. Unit string `json:"unit"`
  203. AreaName string `json:"areaName"`
  204. PriceType string `json:"priceType"`
  205. Memo string `json:"memo"`
  206. Id string `json:"id"`
  207. ProductName string `json:"productName"`
  208. MarketName string `json:"marketName"`
  209. ManufactureName string `json:"manufactureName"`
  210. }
  211. type LzPriceInfoResp struct {
  212. Msg string `json:"msg"`
  213. Code int `json:"code"`
  214. Data []*LzPriceInfo `json:"data"`
  215. }
  216. type Longzhongpriceinfo struct {
  217. LongzhongpriceinfoId int `orm:"column(longzhongpriceinfo_id);pk"`
  218. Standard string
  219. ModelName string
  220. Unit string
  221. AreaName string
  222. PriceType string
  223. Memo string
  224. PriceId string
  225. ProductName string
  226. InfoType string
  227. InfoTypeRemark string
  228. MarketName string
  229. ManufactureName string
  230. }
  231. func AddLongzhongpriceinfo(item *Longzhongpriceinfo) (newId int64, err error) {
  232. o := orm.NewOrm()
  233. o.Using("edb")
  234. newId, err = o.Insert(item)
  235. return
  236. }
  237. //判断指标数据是否已经录入
  238. func GetLongzhongpriceinfoCount(unitid string) (count int, err error) {
  239. o := orm.NewOrm()
  240. o.Using("edb")
  241. sql := `SELECT COUNT(1) AS count FROM longzhongpriceinfo WHERE price_id=? `
  242. err = o.Raw(sql, unitid).QueryRow(&count)
  243. return
  244. }
  245. //判断指标数据是否已经录入
  246. func GetLongzhongpriceinfo() (items []*Longzhongpriceinfo, err error) {
  247. o := orm.NewOrm()
  248. o.Using("edb")
  249. sql := `SELECT * FROM longzhongpriceinfo `
  250. _, err = o.Raw(sql).QueryRows(&items)
  251. return
  252. }
  253. type Longzhongpricedata struct {
  254. LongzhongpricedataId int `orm:"column(longzhongpricedata_id);pk"`
  255. LongzhongpriceinfoId int
  256. PriceDate string
  257. Memo string
  258. Price string
  259. CnyPrice string
  260. ZsyPrice string
  261. ZshPrice string
  262. LowPrice string
  263. HighPrice string
  264. RisePrice string
  265. TonPrice string
  266. PriceType string
  267. UpdateDate string
  268. }
  269. func AddLongzhongpricedata(item *Longzhongpricedata) (newId int64, err error) {
  270. o := orm.NewOrm()
  271. o.Using("edb")
  272. newId, err = o.Insert(item)
  273. return
  274. }
  275. //判断指标数据是否已经录入
  276. func GetLongzhongpricedataCount(unitid, priceDate string) (count int, err error) {
  277. o := orm.NewOrm()
  278. o.Using("edb")
  279. sql := `SELECT COUNT(1) AS count FROM longzhongpricedata WHERE longzhongpriceinfo_id=? AND price_date=? `
  280. err = o.Raw(sql, unitid, priceDate).QueryRow(&count)
  281. return
  282. }
  283. type LzPriceData struct {
  284. Id string `json:"id"`
  285. PriceDate string `json:"priceDate"`
  286. Memo string `json:"memo"`
  287. Price string `json:"price"`
  288. CnyPrice string `json:"cnyPrice"`
  289. ZsyPrice string `json:"zsyPrice"`
  290. ZshPrice string `json:"zshPrice"`
  291. LowPrice string `json:"lowPrice"`
  292. HighPrice string `json:"highPrice"`
  293. RisePrice string `json:"risePrice"`
  294. TonPrice string `json:"tonPrice"`
  295. PriceType string `json:"priceType"`
  296. UpdateDate string `json:"updateDate"`
  297. }
  298. type LzPriceDataResp struct {
  299. Msg string `json:"msg"`
  300. Code int `json:"code"`
  301. Data []*LzPriceData `json:"data"`
  302. }
  303. func GetLongzhongPriceDataMaxCount(productName string) (count int, err error) {
  304. o := orm.NewOrm()
  305. o.Using("edb")
  306. sql := `SELECT MAX(t.num) AS count FROM (
  307. SELECT COUNT(1) AS num FROM longzhongpriceinfo AS a
  308. INNER JOIN longzhongpricedata AS b ON a.longzhongpriceinfo_id=b.longzhongpriceinfo_id
  309. WHERE a.product_name=?
  310. GROUP BY a.product_name
  311. )AS t `
  312. err = o.Raw(sql, productName).QueryRow(&count)
  313. return
  314. }
  315. type LongzhongpricedataItems struct {
  316. LongzhongpricedataId int `orm:"column(longzhongpricedata_id);pk"`
  317. LongzhongpriceinfoId int
  318. PriceDate string
  319. Memo string
  320. Price float64
  321. CnyPrice float64
  322. ZsyPrice float64
  323. ZshPrice float64
  324. LowPrice float64
  325. HighPrice float64
  326. RisePrice float64
  327. TonPrice float64
  328. PriceType string
  329. UpdateDate string
  330. }
  331. func GetLongzhongPriceDataById(lzPriceInfoId int) (items []*LongzhongpricedataItems, err error) {
  332. o := orm.NewOrm()
  333. o.Using("edb")
  334. sql := `SELECT * FROM longzhongpricedata WHERE longzhongpriceinfo_id=? ORDER BY price_date DESC `
  335. _, err = o.Raw(sql, lzPriceInfoId).QueryRows(&items)
  336. return
  337. }
  338. func ModifyLongzhongpriceinfo(item *Longzhongpriceinfo) (err error) {
  339. o := orm.NewOrm()
  340. o.Using("edb")
  341. sql := `UPDATE longzhongpriceinfo
  342. SET
  343. standard = ?,
  344. model_name = ?,
  345. unit= ?,
  346. area_name=?,
  347. price_type = ?,
  348. memo = ?,
  349. market_name = ?,
  350. manufacture_name = ?
  351. WHERE price_id = ? `
  352. _, err = o.Raw(sql, item.Standard, item.ModelName, item.Unit, item.AreaName, item.PriceType, item.Memo, item.MarketName, item.ManufactureName, item.PriceId).Exec()
  353. return
  354. }