data_source_longzhong.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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 *Longzhonginfo, 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 `
  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. }
  375. type SurveyProduct struct {
  376. Message string `json:"message"`
  377. Response struct {
  378. List []struct {
  379. AreaName interface{} `json:"areaName"`
  380. BreedID string `json:"breedId"`
  381. BreedName string `json:"breedName"`
  382. Custom string `json:"custom"`
  383. CustomID string `json:"customId"`
  384. CustomType int64 `json:"customType"`
  385. Device string `json:"device"`
  386. DeviceID string `json:"deviceId"`
  387. Frequency int64 `json:"frequency"`
  388. InputMode int64 `json:"inputMode"`
  389. InputValue interface{} `json:"inputValue"`
  390. Labels interface{} `json:"labels"`
  391. ProductCraft string `json:"productCraft"`
  392. ProductCraftID string `json:"productCraftId"`
  393. ProductLine string `json:"productLine"`
  394. ProjectQuotaID int64 `json:"projectQuotaId"`
  395. ProvinceName interface{} `json:"provinceName"`
  396. QuotaID string `json:"quotaId"`
  397. QuotaName string `json:"quotaName"`
  398. QuotaSampleID int64 `json:"quotaSampleId"`
  399. ResearchStartDate interface{} `json:"researchStartDate"`
  400. ResearchStopDate interface{} `json:"researchStopDate"`
  401. SampleID string `json:"sampleId"`
  402. SampleName string `json:"sampleName"`
  403. SampleType int64 `json:"sampleType"`
  404. TaskActualFinishTime interface{} `json:"taskActualFinishTime"`
  405. TaskShouldFinishTime interface{} `json:"taskShouldFinishTime"`
  406. UnitID string `json:"unitId"`
  407. UnitName string `json:"unitName"`
  408. } `json:"list"`
  409. PageNum int64 `json:"pageNum"`
  410. PageSize int64 `json:"pageSize"`
  411. Pages int64 `json:"pages"`
  412. Total int64 `json:"total"`
  413. } `json:"response"`
  414. Status string `json:"status"`
  415. }
  416. type LongzhongSurveyProduct struct {
  417. SurveyProductId int `orm:"column(survey_product_id);pk"`
  418. ProjectQuotaId int64
  419. BreedId string
  420. BreedName string
  421. QuotaId string
  422. QuotaName string
  423. UnitId string
  424. UnitName string
  425. SampleType int64
  426. SampleId string
  427. SampleName string
  428. DeviceId string
  429. Device string
  430. ProductCraftId string
  431. ProductCraft string
  432. ProductLine string
  433. InputMode int64
  434. Frequency int64
  435. InputValue string
  436. TaskShouldFinishTime int
  437. CustomId string
  438. CustomType int64
  439. Custom string
  440. QuotaSampleId int64
  441. StartDate string
  442. EndDate string
  443. ModifyTime time.Time
  444. LzCode string
  445. }
  446. //判断指标数据是否已经录入
  447. func GetLongzhongSurveyProductCount(quotaSampleId int64) (count int, err error) {
  448. o := orm.NewOrm()
  449. o.Using("edb")
  450. sql := `SELECT COUNT(1) AS count FROM longzhong_survey_product WHERE quota_sample_id=? `
  451. err = o.Raw(sql, quotaSampleId).QueryRow(&count)
  452. return
  453. }
  454. func AddLongzhongSurveyProduct(item *LongzhongSurveyProduct) (lastId int64, err error) {
  455. o := orm.NewOrm()
  456. o.Using("edb")
  457. lastId, err = o.Insert(item)
  458. return
  459. }
  460. func ModifLongzhongSurveyProduct(item *LongzhongSurveyProduct) (err error) {
  461. o := orm.NewOrm()
  462. o.Using("edb")
  463. sql := `UPDATE longzhong_survey_product
  464. SET
  465. breed_id = ?,
  466. breed_name = ?,
  467. quota_id= ?,
  468. quota_name=?,
  469. unit_id = ?,
  470. unit_name = ?,
  471. project_quota_id = ?
  472. WHERE quota_sample_id = ? `
  473. _, err = o.Raw(sql, item.BreedId, item.BreedName, item.QuotaId, item.QuotaName, item.UnitId, item.UnitName, item.ProjectQuotaId, item.QuotaSampleId).Exec()
  474. return
  475. }
  476. //判断指标数据是否已经录入
  477. func GetLongzhongSurveyList() (items []*LongzhongSurveyProduct, err error) {
  478. o := orm.NewOrm()
  479. o.Using("edb")
  480. sql := `SELECT * FROM longzhong_survey_product ORDER BY survey_product_id ASC`
  481. _, err = o.Raw(sql).QueryRows(&items)
  482. return
  483. }
  484. type LongzhongSurveyData struct {
  485. SurveyDataId int `orm:"column(survey_data_id);pk"`
  486. SurveyProductId int
  487. ProjectQuotaId int64
  488. BreedId string
  489. BreedName string
  490. QuotaId string
  491. QuotaName string
  492. UnitId string
  493. UnitName string
  494. SampleType int64
  495. SampleId string
  496. SampleName string
  497. DeviceId string
  498. Device string
  499. ProductCraftId string
  500. ProductCraft string
  501. ProductLine string
  502. InputMode int64
  503. Frequency int64
  504. InputValue string
  505. TaskShouldFinishTime int64
  506. CustomId string
  507. CustomType int64
  508. Custom string
  509. QuotaSampleId int64
  510. TaskActualFinishTime int64
  511. AreaName string
  512. ProvinceName string
  513. ResearchStartData int64
  514. ResearchStopData int64
  515. DataTime string
  516. }
  517. func AddLongzhongSurveyData(item *LongzhongSurveyData) (err error) {
  518. o := orm.NewOrm()
  519. o.Using("edb")
  520. _, err = o.Insert(item)
  521. return
  522. }
  523. type LzSurveyData struct {
  524. Message string `json:"message"`
  525. Response struct {
  526. List []struct {
  527. AreaName interface{} `json:"areaName"`
  528. BreedID string `json:"breedId"`
  529. BreedName string `json:"breedName"`
  530. Custom string `json:"custom"`
  531. CustomID string `json:"customId"`
  532. CustomType int64 `json:"customType"`
  533. Device string `json:"device"`
  534. DeviceID string `json:"deviceId"`
  535. Frequency int64 `json:"frequency"`
  536. InputMode int64 `json:"inputMode"`
  537. InputValue string `json:"inputValue"`
  538. Labels interface{} `json:"labels"`
  539. ProductCraft string `json:"productCraft"`
  540. ProductCraftID string `json:"productCraftId"`
  541. ProductLine string `json:"productLine"`
  542. ProjectQuotaID int64 `json:"projectQuotaId"`
  543. ProvinceName interface{} `json:"provinceName"`
  544. QuotaID string `json:"quotaId"`
  545. QuotaName string `json:"quotaName"`
  546. QuotaSampleID int64 `json:"quotaSampleId"`
  547. ResearchStartDate int64 `json:"researchStartDate"`
  548. ResearchStopDate int64 `json:"researchStopDate"`
  549. SampleID string `json:"sampleId"`
  550. SampleName string `json:"sampleName"`
  551. SampleType int64 `json:"sampleType"`
  552. TaskActualFinishTime int64 `json:"taskActualFinishTime"`
  553. TaskShouldFinishTime int64 `json:"taskShouldFinishTime"`
  554. UnitID string `json:"unitId"`
  555. UnitName string `json:"unitName"`
  556. } `json:"list"`
  557. PageNum int64 `json:"pageNum"`
  558. PageSize int64 `json:"pageSize"`
  559. Pages int64 `json:"pages"`
  560. Total int64 `json:"total"`
  561. } `json:"response"`
  562. Status string `json:"status"`
  563. }
  564. //判断指标数据是否已经录入
  565. func GetLzSurveyDataCount(surveyProductId, quotaSampleId int, dataTime string) (count int, err error) {
  566. o := orm.NewOrm()
  567. o.Using("edb")
  568. sql := `SELECT COUNT(1) AS count FROM longzhong_survey_data WHERE survey_product_id=? AND quota_sample_id=? AND data_time=? `
  569. err = o.Raw(sql, surveyProductId, quotaSampleId, dataTime).QueryRow(&count)
  570. return
  571. }
  572. type LzSurveyMaxAndMinInfo struct {
  573. MinDate string `description:"最小日期"`
  574. MaxDate string `description:"最大日期"`
  575. MinValue float64 `description:"最小值"`
  576. MaxValue float64 `description:"最大值"`
  577. }
  578. func GetLzSurveyMaxAndMinInfo(surveyProductId, quotaSampleId int) (item *LzSurveyMaxAndMinInfo, err error) {
  579. o := orm.NewOrm()
  580. o.Using("edb")
  581. sql := ``
  582. sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(input_value) AS min_value,MAX(input_value) AS max_value
  583. FROM longzhong_survey_data WHERE survey_product_id=? AND quota_sample_id=? `
  584. err = o.Raw(sql, surveyProductId, quotaSampleId).QueryRow(&item)
  585. return
  586. }
  587. func ModifyLzSurveyMaxAndMinInfo(item *LzSurveyMaxAndMinInfo, surveyProductId int) (err error) {
  588. o := orm.NewOrm()
  589. o.Using("edb")
  590. sql := ` UPDATE longzhong_survey_product SET start_date=?,end_date=?,min_value=?,max_value=? WHERE survey_product_id=? `
  591. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, surveyProductId).Exec()
  592. return
  593. }
  594. func ModifLongzhongSurveyProductCode(lzCode string, surveyProductId int) (err error) {
  595. o := orm.NewOrm()
  596. o.Using("edb")
  597. sql := `UPDATE longzhong_survey_product
  598. SET lz_code= ?
  599. WHERE survey_product_id = ? `
  600. _, err = o.Raw(sql, lzCode, surveyProductId).Exec()
  601. return
  602. }
  603. //判断指标数据是否已经录入
  604. func GetLongzhongSurveyProductItem(quotaSampleId int64) (item *LongzhongSurveyProduct, err error) {
  605. o := orm.NewOrm()
  606. o.Using("edb")
  607. sql := `SELECT * FROM longzhong_survey_product WHERE quota_sample_id=? `
  608. err = o.Raw(sql, quotaSampleId).QueryRow(&item)
  609. return
  610. }