data_source_longzhong.go 12 KB

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