data_source_longzhong.go 11 KB

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