data_source_longzhong.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. AddTime string
  17. DisplayTime string
  18. }
  19. type Longzhonginfo struct {
  20. LongzhonginfoId int `orm:"column(longzhonginfo_id);pk"`
  21. TradeCode string
  22. SecName string
  23. Frequency string
  24. ClassifyId int
  25. ClassifyName string
  26. Unit string
  27. CreateTime time.Time
  28. Remark string
  29. IsNormal string
  30. LastModifyDate string
  31. Unitid int64
  32. TempId int64
  33. TempName string
  34. ModifyTime time.Time
  35. }
  36. func GetLongzhonginfoBySecName(secName string) (item *Longzhongdata, err error) {
  37. o := orm.NewOrm()
  38. o.Using("edb")
  39. sql := `SELECT * FROM longzhonginfo WHERE sec_name=? `
  40. err = o.Raw(sql, secName).QueryRow(&item)
  41. return
  42. }
  43. //判断指标数据是否已经录入
  44. func GetLongzhongdataCount(longzhonginfoId int, dt string) (count int, err error) {
  45. o := orm.NewOrm()
  46. o.Using("edb")
  47. sql := `SELECT COUNT(1) AS count FROM longzhongdata WHERE longzhonginfo_id=? AND dt=? `
  48. err = o.Raw(sql, longzhonginfoId, dt).QueryRow(&count)
  49. return
  50. }
  51. func AddLongzhongdata(item *Longzhongdata) (err error) {
  52. o := orm.NewOrm()
  53. o.Using("edb")
  54. _, err = o.Insert(item)
  55. return
  56. }
  57. func ModifyLongzhongdata(item *Longzhongdata) (err error) {
  58. o := orm.NewOrm()
  59. o.Using("edb")
  60. sql := ` UPDATE longzhongdata
  61. SET
  62. close = ?,
  63. modify_time= NOW(),
  64. unit_desc= ?,
  65. upd_time = ?,
  66. add_time=?,
  67. display_time=?
  68. WHERE longzhonginfo_id = ? AND dt=?
  69. `
  70. _, err = o.Raw(sql, item.Close, item.UnitDesc, item.UpdTime, item.AddTime, item.DisplayTime, item.LongzhonginfoId, item.Dt).Exec()
  71. return
  72. }
  73. func AddLongzhonginfo(item *Longzhonginfo) (newId int64, err error) {
  74. o := orm.NewOrm()
  75. o.Using("edb")
  76. newId, err = o.Insert(item)
  77. return
  78. }
  79. func ModifyLongzhonginfo(item *Longzhonginfo) (err error) {
  80. o := orm.NewOrm()
  81. o.Using("edb")
  82. sql := `UPDATE longzhonginfo
  83. SET
  84. sec_name = ?,
  85. unit = ?,
  86. frequency = ?,
  87. classify_id = ?,
  88. classify_name = ?,
  89. remark = ?,
  90. last_modify_date = ?,
  91. temp_name = ?,
  92. is_normal = ?,
  93. modify_time=NOW()
  94. WHERE unitid = ? AND temp_id = ? `
  95. _, err = o.Raw(sql, item.SecName, item.Unit, item.Frequency, item.ClassifyId, item.ClassifyName, item.Remark, item.LastModifyDate, item.TempName, item.IsNormal, item.Unitid, item.TempId).Exec()
  96. return
  97. }
  98. //判断指标数据是否已经录入
  99. func GetLongzhonginfoCount(classifyId int, unitid int64) (count int, err error) {
  100. o := orm.NewOrm()
  101. o.Using("edb")
  102. sql := `SELECT COUNT(1) AS count FROM longzhonginfo WHERE classify_id=? AND unitid=? `
  103. err = o.Raw(sql, classifyId, unitid).QueryRow(&count)
  104. return
  105. }
  106. type LzProductInfoResp struct {
  107. Msg string `json:"msg"`
  108. Code string `json:"code"`
  109. Data []*LzProductInfo `json:"data"`
  110. }
  111. type LzProductInfo struct {
  112. Unitid int64 `json:"unitid"`
  113. ProUnitName string `json:"proUnitName"`
  114. Tempid int64 `json:"tempid"`
  115. TempName string `json:"tempName"`
  116. Proid int `json:"proid"`
  117. ProName string `json:"proName"`
  118. Unit string `json:"unit"`
  119. LzType string `json:"type"`
  120. Maxdate string `json:"maxdate"`
  121. IsNormal string `json:"isNormal"`
  122. }
  123. func GetLongzhonginfoMaxId() (count int, err error) {
  124. o := orm.NewOrm()
  125. o.Using("edb")
  126. sql := `SELECT MAX(longzhonginfo_id) AS count FROM longzhonginfo`
  127. err = o.Raw(sql).QueryRow(&count)
  128. return
  129. }
  130. type LzProductInfoDetail struct {
  131. UnitId int64 `json:"unit_id"`
  132. UnitName string `json:"unit_name"`
  133. TempId int `json:"temp_id"`
  134. TempName string `json:"temp_name"`
  135. TempUnit string `json:"temp_unit"`
  136. ProId int `json:"pro_id"`
  137. ProCnName string `json:"pro_cn_name"`
  138. UnitValue float64 `json:"unit_value"`
  139. UnitDesc string `json:"unit_desc"`
  140. DataTime string `json:"data_time"`
  141. UpdTime string `json:"upd_time"`
  142. AddTime string `json:"add_time"`
  143. DisplayTime string `json:"display_time"`
  144. }
  145. type LzProductInfoDetailResp struct {
  146. Msg string `json:"msg"`
  147. Code string `json:"code"`
  148. Data []*LzProductInfoDetail `json:"data"`
  149. Pagesize int `json:"pagesize"`
  150. Page int `json:"page"`
  151. }
  152. func GetLongzhonginfoByUnitId(classifyName string, unitId int64) (item *Longzhongdata, err error) {
  153. o := orm.NewOrm()
  154. o.Using("edb")
  155. sql := `SELECT * FROM longzhonginfo WHERE unitid=? AND classify_name=?`
  156. err = o.Raw(sql, unitId, classifyName).QueryRow(&item)
  157. return
  158. }
  159. func GetLongzhongDataById(lzInfoId int) (items []*Longzhongdata, err error) {
  160. o := orm.NewOrm()
  161. o.Using("edb")
  162. sql := `SELECT * FROM longzhongdata WHERE longzhonginfo_id=? ORDER BY dt DESC `
  163. _, err = o.Raw(sql, lzInfoId).QueryRows(&items)
  164. return
  165. }
  166. func GetLongzhongDataMaxCount(classifyId int) (count int, err error) {
  167. o := orm.NewOrm()
  168. o.Using("edb")
  169. sql := `SELECT MAX(t.num) AS count FROM (
  170. SELECT COUNT(1) AS num FROM longzhonginfo AS a
  171. INNER JOIN longzhongdata AS b ON a.longzhonginfo_id=b.longzhonginfo_id
  172. WHERE a.classify_id=?
  173. GROUP BY a.longzhonginfo_id
  174. )AS t `
  175. err = o.Raw(sql, classifyId).QueryRow(&count)
  176. return
  177. }
  178. type LongzhonginfoList struct {
  179. LongzhonginfoId int `orm:"column(longzhonginfo_id);pk"`
  180. TradeCode string
  181. SecName string
  182. Frequency string
  183. ClassifyId int
  184. ClassifyName string
  185. Unit string
  186. IsNormal string
  187. LastModifyDate string
  188. Unitid int
  189. }
  190. func GetLongzhonginfoList() (items []*LongzhonginfoList, err error) {
  191. o := orm.NewOrm()
  192. o.Using("edb")
  193. sql := ` SELECT * FROM longzhonginfo `
  194. _, err = o.Raw(sql).QueryRows(&items)
  195. return
  196. }
  197. func ModifyLongzhonginfoIsNormal(longzhonginfoId int) (err error) {
  198. o := orm.NewOrm()
  199. o.Using("edb")
  200. sql := ` UPDATE longzhonginfo SET is_normal=0 WHERE longzhonginfo_id=? `
  201. _, err = o.Raw(sql, longzhonginfoId).Exec()
  202. return
  203. }
  204. type LzPriceInfo struct {
  205. Standard string `json:"standard"`
  206. ModelName string `json:"modelName"`
  207. Unit string `json:"unit"`
  208. AreaName string `json:"areaName"`
  209. PriceType string `json:"priceType"`
  210. Memo string `json:"memo"`
  211. Id string `json:"id"`
  212. ProductName string `json:"productName"`
  213. MarketName string `json:"marketName"`
  214. ManufactureName string `json:"manufactureName"`
  215. }
  216. type LzPriceInfoResp struct {
  217. Msg string `json:"msg"`
  218. Code int `json:"code"`
  219. Data []*LzPriceInfo `json:"data"`
  220. }
  221. type Longzhongpriceinfo struct {
  222. LongzhongpriceinfoId int `orm:"column(longzhongpriceinfo_id);pk"`
  223. Standard string
  224. ModelName string
  225. Unit string
  226. AreaName string
  227. PriceType string
  228. Memo string
  229. PriceId string
  230. ProductName string
  231. InfoType string
  232. InfoTypeRemark string
  233. MarketName string
  234. ManufactureName string
  235. }
  236. func AddLongzhongpriceinfo(item *Longzhongpriceinfo) (newId int64, err error) {
  237. o := orm.NewOrm()
  238. o.Using("edb")
  239. newId, err = o.Insert(item)
  240. return
  241. }
  242. //判断指标数据是否已经录入
  243. func GetLongzhongpriceinfoCount(unitid string) (count int, err error) {
  244. o := orm.NewOrm()
  245. o.Using("edb")
  246. sql := `SELECT COUNT(1) AS count FROM longzhongpriceinfo WHERE price_id=? `
  247. err = o.Raw(sql, unitid).QueryRow(&count)
  248. return
  249. }
  250. //判断指标数据是否已经录入
  251. func GetLongzhongpriceinfo() (items []*Longzhongpriceinfo, err error) {
  252. o := orm.NewOrm()
  253. o.Using("edb")
  254. sql := `SELECT * FROM longzhongpriceinfo `
  255. _, err = o.Raw(sql).QueryRows(&items)
  256. return
  257. }
  258. type Longzhongpricedata struct {
  259. LongzhongpricedataId int `orm:"column(longzhongpricedata_id);pk"`
  260. LongzhongpriceinfoId int
  261. PriceDate string
  262. Memo string
  263. Price string
  264. CnyPrice string
  265. ZsyPrice string
  266. ZshPrice string
  267. LowPrice string
  268. HighPrice string
  269. RisePrice string
  270. TonPrice string
  271. PriceType string
  272. UpdateDate string
  273. }
  274. func AddLongzhongpricedata(item *Longzhongpricedata) (newId int64, err error) {
  275. o := orm.NewOrm()
  276. o.Using("edb")
  277. newId, err = o.Insert(item)
  278. return
  279. }
  280. //判断指标数据是否已经录入
  281. func GetLongzhongpricedataCount(longzhongpriceinfoId int, priceDate string) (count int, err error) {
  282. o := orm.NewOrm()
  283. o.Using("edb")
  284. sql := `SELECT COUNT(1) AS count FROM longzhongpricedata WHERE longzhongpriceinfo_id=? AND price_date=? `
  285. err = o.Raw(sql, longzhongpriceinfoId, priceDate).QueryRow(&count)
  286. return
  287. }
  288. type LzPriceData struct {
  289. Id string `json:"id"`
  290. PriceDate string `json:"priceDate"`
  291. Memo string `json:"memo"`
  292. Price string `json:"price"`
  293. CnyPrice string `json:"cnyPrice"`
  294. ZsyPrice string `json:"zsyPrice"`
  295. ZshPrice string `json:"zshPrice"`
  296. LowPrice string `json:"lowPrice"`
  297. HighPrice string `json:"highPrice"`
  298. RisePrice string `json:"risePrice"`
  299. TonPrice string `json:"tonPrice"`
  300. PriceType string `json:"priceType"`
  301. UpdateDate string `json:"updateDate"`
  302. }
  303. type LzPriceDataResp struct {
  304. Msg string `json:"msg"`
  305. Code int `json:"code"`
  306. Data []*LzPriceData `json:"data"`
  307. }
  308. func GetLongzhongPriceDataMaxCount(productName string) (count int, err error) {
  309. o := orm.NewOrm()
  310. o.Using("edb")
  311. sql := `SELECT MAX(t.num) AS count FROM (
  312. SELECT COUNT(1) AS num FROM longzhongpriceinfo AS a
  313. INNER JOIN longzhongpricedata AS b ON a.longzhongpriceinfo_id=b.longzhongpriceinfo_id
  314. WHERE a.product_name=?
  315. GROUP BY a.product_name
  316. )AS t `
  317. err = o.Raw(sql, productName).QueryRow(&count)
  318. return
  319. }
  320. type LongzhongpricedataItems struct {
  321. LongzhongpricedataId int `orm:"column(longzhongpricedata_id);pk"`
  322. LongzhongpriceinfoId int
  323. PriceDate string
  324. Memo string
  325. Price float64
  326. CnyPrice float64
  327. ZsyPrice float64
  328. ZshPrice float64
  329. LowPrice float64
  330. HighPrice float64
  331. RisePrice float64
  332. TonPrice float64
  333. PriceType string
  334. UpdateDate string
  335. }
  336. func GetLongzhongPriceDataById(lzPriceInfoId int) (items []*LongzhongpricedataItems, err error) {
  337. o := orm.NewOrm()
  338. o.Using("edb")
  339. sql := `SELECT * FROM longzhongpricedata WHERE longzhongpriceinfo_id=? ORDER BY price_date DESC `
  340. _, err = o.Raw(sql, lzPriceInfoId).QueryRows(&items)
  341. return
  342. }
  343. func ModifyLongzhongpriceinfo(item *Longzhongpriceinfo) (err error) {
  344. o := orm.NewOrm()
  345. o.Using("edb")
  346. sql := `UPDATE longzhongpriceinfo
  347. SET
  348. standard = ?,
  349. model_name = ?,
  350. unit= ?,
  351. area_name=?,
  352. price_type = ?,
  353. memo = ?,
  354. market_name = ?,
  355. manufacture_name = ?
  356. WHERE price_id = ? `
  357. _, err = o.Raw(sql, item.Standard, item.ModelName, item.Unit, item.AreaName, item.PriceType, item.Memo, item.MarketName, item.ManufactureName, item.PriceId).Exec()
  358. return
  359. }