target.go 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/models/data_manage"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. "gorm.io/gorm"
  8. "sort"
  9. "strconv"
  10. "strings"
  11. "time"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. )
  14. type DataList struct {
  15. TradeCode string `gorm:"column:TRADE_CODE;type:varchar(255);not null" description:"指标编码"`
  16. SecName string `gorm:"column:SEC_NAME;type:varchar(255);not null" description:"指标名称"`
  17. Unit string `gorm:"column:UNIT;type:varchar(255);not null" description:"单位"`
  18. Remark string `gorm:"column:REMARK;type:varchar(255);not null" description:"备注"`
  19. Frequency string `gorm:"type:varchar(255);not null" description:"频度"`
  20. ClassifyId int `gorm:"type:int;not null" description:"分类id"`
  21. ClassifyName string `gorm:"type:varchar(255);not null" description:"分类名称"`
  22. Dt string `gorm:"column:DT;type:varchar(255);not null" description:"录入日期"`
  23. Close float64 `gorm:"column:CLOSE;type:float;not null" description:"录入值"`
  24. ModifyTime string `gorm:"type:varchar(255);not null" description:"修改时间"`
  25. }
  26. type DataListResp struct {
  27. List []*DataList
  28. Paging *paging.PagingItem `description:"分页数据"`
  29. }
  30. func GetDataList(condition string, pars []interface{}, startSize, pageSize int) (items []*DataList, err error) {
  31. sql := `select a.TRADE_CODE,a.SEC_NAME,a.UNIT,a.frequency,a.classify_id,b.classify_name,c.DT,c.CLOSE,c.modify_time FROM edbdata AS c
  32. inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  33. left join edbdata_classify AS b ON a.classify_id=b.classify_id
  34. where a.classify_id>0`
  35. if condition != "" {
  36. sql += condition
  37. }
  38. sql += ` order by c.DT desc limit ?,? `
  39. //o := orm.NewOrmUsingDB("edb")
  40. //_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  41. err = global.DmSQL["edb"].Raw(sql, pars, startSize, pageSize).Find(&items).Error
  42. return
  43. }
  44. func GetDataListCount(condition string, pars []interface{}) (count int, err error) {
  45. sql := ` select count(1) as count FROM edbdata AS c
  46. inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  47. left join edbdata_classify AS b ON a.classify_id=b.classify_id
  48. where a.classify_id>0 `
  49. if condition != "" {
  50. sql += condition
  51. }
  52. //o := orm.NewOrmUsingDB("edb")
  53. //err = o.Raw(sql, pars).QueryRow(&count)
  54. err = global.DmSQL["edb"].Raw(sql, pars).Scan(&count).Error
  55. return
  56. }
  57. type DataAddReq struct {
  58. TradeCode string `description:"指标唯一编码"`
  59. CreateDate string `description:"创建日期"`
  60. Close string `description:"录入值"`
  61. }
  62. type Edbdata struct {
  63. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;type:varchar(255)" orm:"column(TRADE_CODE);pk" description:"指标编码"`
  64. Dt string `gorm:"column:DT;type:varchar(255)" orm:"column(DT)" description:"日期"`
  65. Close string `gorm:"column:CLOSE;type:varchar(255)" orm:"column(CLOSE)" description:"值"`
  66. ModifyTime time.Time `gorm:"column:modify_time;type:timestamp" orm:"column(modify_time)" description:"修改时间"`
  67. }
  68. func GetDataInfo(tradeCode, creteDate string) (item *Edbdata, err error) {
  69. sql := " SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? "
  70. //o := orm.NewOrmUsingDB("edb")
  71. //err = o.Raw(sql, tradeCode, creteDate).QueryRow(&item)
  72. err = global.DmSQL["edb"].Raw(sql, tradeCode, creteDate).First(&item).Error
  73. return
  74. }
  75. func AddEdbdata(item *Edbdata) (lastId int64, err error) {
  76. //o := orm.NewOrmUsingDB("edb")
  77. //lastId, err = o.Insert(item)
  78. err = global.DmSQL["edb"].Create(item).Error
  79. if err != nil {
  80. return
  81. }
  82. return
  83. }
  84. type DataEditReq struct {
  85. TradeCode string `description:"指标唯一编码"`
  86. CreateDate string `description:"创建日期"`
  87. Close interface{} `description:"录入值"`
  88. OldCreateDate string `description:"旧的录入日期"`
  89. }
  90. // BatchDataEditReq 批量修改指标
  91. type BatchDataEditReq struct {
  92. OldCreateDate string `description:"旧的录入日期"`
  93. CreateDate string `description:"新的录入日期"`
  94. List []DataEditReq `description:"需要修改的数据"`
  95. }
  96. // 编辑数据
  97. func EditEdbdata(item *Edbdata) (err error) {
  98. //o := orm.NewOrmUsingDB("edb")
  99. sql := ` UPDATE edbdata SET CLOSE = ?,modify_time=NOW() WHERE TRADE_CODE = ? AND DT = ? `
  100. //_, err = o.Raw(sql, item.Close, item.TradeCode, item.Dt).Exec()
  101. err = global.DmSQL["edb"].Exec(sql, item.Close, item.TradeCode, item.Dt).Error
  102. return
  103. }
  104. type EdbdataDeleteRecord struct {
  105. Id int `orm:"column(id);pk"`
  106. TradeCode string `orm:"column(TRADE_CODE)" description:"指标编码"`
  107. Dt string `orm:"column(DT)" description:"日期"`
  108. Close string `orm:"column(CLOSE)" description:"值"`
  109. ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
  110. CreateTime time.Time
  111. SysUserId int
  112. }
  113. func AddEdbdataDeleteRecord(item *EdbdataDeleteRecord) (lastId int64, err error) {
  114. //o := orm.NewOrmUsingDB("edb")
  115. //lastId, err = o.Insert(item)
  116. err = global.DmSQL["edb"].Create(item).Error
  117. lastId = int64(item.Id)
  118. return
  119. }
  120. // DeleteEdbData 根据指标code和日期删除数据
  121. func DeleteEdbData(tradeCode, dt string) (err error) {
  122. //o := orm.NewOrmUsingDB("edb")
  123. sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
  124. //_, err = o.Raw(sql, tradeCode, dt).Exec()
  125. err = global.DmSQL["edb"].Exec(sql, tradeCode, dt).Error
  126. return
  127. }
  128. // DeleteAllEdbData 根据指标code删除数据
  129. func DeleteAllEdbData(tradeCode string) (err error) {
  130. //o := orm.NewOrmUsingDB("edb")
  131. sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? `
  132. //_, err = o.Raw(sql, tradeCode).Exec()
  133. err = global.DmSQL["edb"].Exec(sql, tradeCode).Error
  134. return
  135. }
  136. type Edbinfo struct {
  137. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;type:varchar(255)" orm:"column(TRADE_CODE);pk" description:"指标code"`
  138. SecName string `gorm:"column:SEC_NAME;type:varchar(255)" orm:"column(SEC_NAME);" description:"指标名称"`
  139. Unit string `gorm:"column:UNIT;type:varchar(255)" orm:"column(UNIT);" description:"单位"`
  140. Remark string `gorm:"column:REMARK;type:varchar(255)" orm:"column(REMARK);" description:"备注"`
  141. Frequency string `gorm:"column:FREQUENCY;type:varchar(255)" orm:"column(frequency)" description:"频度"`
  142. ClassifyId int `gorm:"column:CLASSIFY_ID;type:int" orm:"column(classify_id)" description:"分类id"`
  143. ClassifyName string `gorm:"-" orm:"-" description:"分类名称"`
  144. CreateDate string `gorm:"column:CREATE_DATE;type:varchar(255)" orm:"column(create_date)" description:"创建时间"`
  145. UserId int `gorm:"column:USER_ID;type:int" orm:"column(user_id)" description:"录入用户id"`
  146. UserName string `gorm:"column:USER_NAME;type:varchar(255)" orm:"column(user_name)" description:"录入用户名称"`
  147. NoticeTime string `gorm:"column:NOTICE_TIME;type:varchar(255)" orm:"column(notice_time)" description:"通知时间"`
  148. Mobile string `gorm:"column:MOBILE;type:varchar(255)" orm:"column(mobile)" description:"录入者手机号"`
  149. Sort int `gorm:"column:SORT;type:int" orm:"column(sort)" description:"排序"`
  150. ModifyTime string `gorm:"column:MODIFY_TIME;type:varchar(255)" description:"最近一次更新时间"`
  151. IsJoinEdb int8 `gorm:"column:IS_JOIN_EDB;type:tinyint" description:"指标库是否已添加:0-否;1-是"`
  152. StartDate string `gorm:"column:START_DATE;type:varchar(255)" description:"数据开始日期"`
  153. EndDate string `gorm:"column:END_DATE;type:varchar(255)" description:"数据结束日期"`
  154. LatestValue float64 `gorm:"column:LATEST_VALUE;type:decimal(10,2)" description:"指标最新值"`
  155. }
  156. func DeleteEdbinfoByTraceCodeList(tradeCodeList []string) (err error) {
  157. if len(tradeCodeList) == 0 {
  158. return
  159. }
  160. //o := orm.NewOrmUsingDB("edb")
  161. o := global.DmSQL["edb"]
  162. //err = o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
  163. // var holder []string
  164. // for range tradeCodeList {
  165. // holder = append(holder, "?")
  166. // }
  167. // sql := ` DELETE FROM edbdata WHERE TRADE_CODE in (` + strings.Join(holder, ",") + `) `
  168. // _, err := txOrm.Raw(sql, tradeCodeList).Exec()
  169. // if err != nil {
  170. // return err
  171. // }
  172. // sql = ` DELETE FROM edbinfo WHERE TRADE_CODE in (` + strings.Join(holder, ",") + `)`
  173. // _, err = txOrm.Raw(sql, tradeCodeList).Exec()
  174. // if err != nil {
  175. // return err
  176. // }
  177. // return nil
  178. //})
  179. err = o.Transaction(func(tx *gorm.DB) error {
  180. var holder []string
  181. for range tradeCodeList {
  182. holder = append(holder, "?")
  183. }
  184. sql := ` DELETE FROM edbdata WHERE TRADE_CODE in (` + strings.Join(holder, ",") + `) `
  185. txErr := tx.Exec(sql, tradeCodeList).Error
  186. if txErr != nil {
  187. return txErr
  188. }
  189. sql = ` DELETE FROM edbinfo WHERE TRADE_CODE in (` + strings.Join(holder, ",") + `)`
  190. txErr = tx.Exec(sql, tradeCodeList).Error
  191. if txErr != nil {
  192. return txErr
  193. }
  194. return nil
  195. })
  196. return
  197. }
  198. func GetEdbinfoListCount(condition string, pars []interface{}, mobile string, roleType int) (count int, err error) {
  199. //o := orm.NewOrmUsingDB("edb")
  200. sql := ``
  201. if mobile != "" && roleType == 1 {
  202. sql = `SELECT COUNT(1) AS count FROM edbinfo AS a
  203. INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
  204. WHERE a.classify_id>0`
  205. if condition != "" {
  206. sql += condition
  207. }
  208. //err = o.Raw(sql, mobile, pars).QueryRow(&count)
  209. err = global.DmSQL["edb"].Raw(sql, mobile, pars).Scan(&count).Error
  210. } else {
  211. sql = `SELECT COUNT(1) AS count FROM edbinfo AS a WHERE a.classify_id>0`
  212. if condition != "" {
  213. sql += condition
  214. }
  215. //err = o.Raw(sql, pars).QueryRow(&count)
  216. err = global.DmSQL["edb"].Raw(sql, pars).Scan(&count).Error
  217. }
  218. return
  219. }
  220. type EdbinfoItem struct {
  221. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;type:varchar(255)"` //`orm:"column(TRADE_CODE);pk" description:"指标code"`
  222. SecName string `gorm:"column:SEC_NAME;type:varchar(255)"` //`orm:"column(SEC_NAME);" description:"指标名称"`
  223. Unit string `gorm:"column:UNIT;type:varchar(255)"` //`orm:"column(UNIT);" description:"单位"`
  224. Remark string `gorm:"column:REMARK;type:varchar(255)"` //`orm:"column(REMARK);" description:"备注"`
  225. Frequency string `gorm:"column:frequency;"` //`description:"频度"`
  226. ClassifyId int `gorm:"column:classify_id;type:int"` //`description:"分类id"`
  227. ClassifyName string `gorm:"-"` // `description:"分类名称"`
  228. CreateDate string `gorm:"column:create_date;"` // `description:"创建时间"`
  229. UserId int `gorm:"column:user_id;"` // `description:"录入用户id"`
  230. UserName string `gorm:"column:user_name;"` // `description:"录入用户名称"`
  231. NoticeTime string `gorm:"column:notice_time;"` //`description:"通知时间"`
  232. Mobile string `gorm:"column:mobile"` // `description:"录入者手机号"`
  233. ModifyTime string `gorm:"column:modify_time;"` //`// `description:"最近一次更新时间"`
  234. StartDate string `gorm:"column:start_date;"` // `description:"数据开始日期"`
  235. EndDate string `gorm:"column:end_date;"` // `description:"数据结束日期"`
  236. LatestValue float64 `gorm:"column:latest_value;"` // `description:"指标最新值"`
  237. }
  238. func GetEdbinfoItemList(condition string, pars []interface{}, startSize, pageSize int, mobile string, roleType int) (items []*EdbinfoItem, err error) {
  239. //o := orm.NewOrmUsingDB("edb")
  240. sql := ``
  241. if mobile != "" && roleType == 1 {
  242. sql = ` SELECT DISTINCT a.*,b.classify_name FROM edbinfo AS a
  243. LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  244. INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
  245. WHERE a.classify_id>0`
  246. if condition != "" {
  247. sql += condition
  248. }
  249. sql += ` ORDER BY a.create_date DESC LIMIT ?,? `
  250. //_, err = o.Raw(sql, mobile, pars, startSize, pageSize).QueryRows(&items)
  251. err = global.DmSQL["edb"].Raw(sql, mobile, pars, startSize, pageSize).Find(&items).Error
  252. } else {
  253. sql = `SELECT DISTINCT a.*,b.classify_name FROM edbinfo AS a
  254. LEFT JOIN edbdata_classify AS b on a.classify_id=b.classify_id
  255. WHERE a.classify_id>0`
  256. if condition != "" {
  257. sql += condition
  258. }
  259. sql += ` ORDER BY a.create_date DESC LIMIT ?,? `
  260. //_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  261. err = global.DmSQL["edb"].Raw(sql, pars, startSize, pageSize).Find(&items).Error
  262. }
  263. return
  264. }
  265. // EdbParamsInfo 指标数据结构体
  266. type EdbParamsInfo struct {
  267. Unit string `gorm:"column:UNIT;"` //`orm:"column(UNIT);" description:"单位"`
  268. Frequency string `gorm:"column:frequency;"` //`orm:"column(frequency);" description:"单位"`
  269. }
  270. // GetEdbUnitList 获取指标单位
  271. func GetEdbUnitList() (items []*EdbParamsInfo, err error) {
  272. //o := orm.NewOrmUsingDB("edb")
  273. sql := `SELECT UNIT from edbinfo group by UNIT`
  274. //_, err = o.Raw(sql).QueryRows(&items)
  275. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  276. return
  277. }
  278. // GetEdbFrequencyList 获取指标频度
  279. func GetEdbFrequencyList(classifyId, userId int) (items []*EdbParamsInfo, err error) {
  280. //o := orm.NewOrmUsingDB("edb")
  281. sql := `SELECT frequency from edbinfo a
  282. join edbdata b on a.TRADE_CODE=b.TRADE_CODE
  283. where classify_id = ? `
  284. if userId > 0 {
  285. sql += ` and a.user_id = ` + fmt.Sprint(userId) + ` `
  286. }
  287. sql += ` group by a.frequency`
  288. //_, err = o.Raw(sql, classifyId).QueryRows(&items)
  289. err = global.DmSQL["edb"].Raw(sql, classifyId).Find(&items).Error
  290. return
  291. }
  292. type TargetListResp struct {
  293. List []*EdbinfoItem
  294. Paging *paging.PagingItem `description:"分页数据"`
  295. }
  296. type EdbinfoAddReq struct {
  297. SecName string `description:"指标名称"`
  298. Unit string `description:"单位"`
  299. Frequency string `description:"频度"`
  300. ClassifyId int `description:"分类id"`
  301. NoticeTime string `description:"通知时间"`
  302. }
  303. // GetMaxTradeCode 获取指标最大trade_code
  304. func GetMaxTradeCode() (max_trade_code string, err error) {
  305. sql := " SELECT MAX(TRADE_CODE) AS max_trade_code FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' "
  306. //o := orm.NewOrmUsingDB("edb")
  307. //err = o.Raw(sql).QueryRow(&max_trade_code)
  308. err = global.DmSQL["edb"].Raw(sql).Scan(&max_trade_code).Error
  309. if (err != nil && utils.IsErrNoRow(err)) || max_trade_code == `` {
  310. max_trade_code = "W00"
  311. }
  312. return
  313. }
  314. func GetEdbinfoBySecName(secName string) (item *Edbinfo, err error) {
  315. sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? `
  316. //o := orm.NewOrmUsingDB("edb")
  317. //err = o.Raw(sql, secName).QueryRow(&item)
  318. err = global.DmSQL["edb"].Raw(sql, secName).First(&item).Error
  319. return
  320. }
  321. func GetEdbinfoByTradeCode(tradeCode string) (item *Edbinfo, err error) {
  322. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE=? `
  323. //o := orm.NewOrmUsingDB("edb")
  324. //err = o.Raw(sql, tradeCode).QueryRow(&item)
  325. err = global.DmSQL["edb"].Raw(sql, tradeCode).First(&item).Error
  326. return
  327. }
  328. func AddEdbinfo(tradeCode, secName, unit, remark, frequency, noticeTime string, classifyId int, userId int, userName string) (err error) {
  329. //o := orm.NewOrmUsingDB("edb")
  330. currTime := time.Now().Format(utils.FormatDateTime)
  331. edbInfo := &Edbinfo{
  332. TradeCode: tradeCode,
  333. SecName: secName,
  334. Unit: unit,
  335. Remark: remark,
  336. Frequency: frequency,
  337. ClassifyId: classifyId,
  338. CreateDate: currTime,
  339. UserId: userId,
  340. UserName: userName,
  341. NoticeTime: noticeTime,
  342. Mobile: "",
  343. ModifyTime: currTime,
  344. IsJoinEdb: 0,
  345. }
  346. //_, err = o.Insert(edbInfo)
  347. err = global.DmSQL["edb"].Create(edbInfo).Error
  348. return
  349. }
  350. func AddEdbinfoUser(tradeCode, mobile string) (err error) {
  351. //o := orm.NewOrmUsingDB("edb")
  352. sql := `INSERT INTO edbinfo_user(TRADE_CODE, mobile) VALUES (?,?)`
  353. //_, err = o.Raw(sql, tradeCode, mobile).Exec()
  354. err = global.DmSQL["edb"].Exec(sql, tradeCode, mobile).Error
  355. return
  356. }
  357. type EdbinfoEditReq struct {
  358. TradeCode string `description:"指标code"`
  359. SecName string `description:"指标名称"`
  360. Unit string `description:"单位"`
  361. Frequency string `description:"频度"`
  362. ClassifyId int `description:"分类id"`
  363. NoticeTime string `description:"通知时间"`
  364. }
  365. func EditEdbinfo(tradeCode, secName, unit, frequency, noticeTime string, classifyId int) (err error) {
  366. sql := `UPDATE edbinfo SET SEC_NAME= ?, UNIT = ?,classify_id=?,frequency=?,notice_time=?,create_date=NOW() WHERE TRADE_CODE=? `
  367. //o := orm.NewOrmUsingDB("edb")
  368. //_, err = o.Raw(sql, secName, unit, classifyId, frequency, noticeTime, tradeCode).Exec()
  369. err = global.DmSQL["edb"].Exec(sql, secName, unit, classifyId, frequency, noticeTime, tradeCode).Error
  370. return
  371. }
  372. func SearchTargetEntry(classifyId int, keyWord string) (items []*Edbinfo, err error) {
  373. where := ""
  374. pars := make([]interface{}, 0)
  375. sql := `SELECT * FROM edbinfo WHERE classify_id>0 AND classify_id=? `
  376. pars = append(pars, classifyId)
  377. if keyWord != "" {
  378. sql += `AND SEC_NAME LIKE ? `
  379. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  380. }
  381. sql += where
  382. //o := orm.NewOrmUsingDB("edb")
  383. //_, err = o.Raw(sql, pars...).QueryRows(&items)
  384. err = global.DmSQL["edb"].Raw(sql, pars).Find(&items).Error
  385. return
  386. }
  387. type SearchTargetListResp struct {
  388. List []*Edbinfo
  389. }
  390. type EdbdataClassify struct {
  391. ClassifyId int `gorm:"column:classify_id;type:int" xorm:"int 'classify_id'"`
  392. ClassifyName string `gorm:"column:classify_name;type:varchar(255)" xorm:"varchar(255) 'classify_name'"`
  393. ParentId int `gorm:"column:parent_id;type:int" xorm:"int 'parent_id'"`
  394. EdbInfoTotal int `gorm:"column:edb_info_total;type:int" xorm:"int 'edb_info_total'"`
  395. TradeCode string `gorm:"column:trade_code;type:varchar(255)" xorm:"varchar(255) 'trade_code'"`
  396. UniqueCode string `gorm:"column:unique_code;type:varchar(255)" xorm:"varchar(255) 'unique_code'"`
  397. }
  398. func GetEdbdataClassifyByClassifyName(classifyName string) (item *EdbdataClassify, err error) {
  399. sql := `SELECT * FROM edbdata_classify WHERE classify_name=? `
  400. //o := orm.NewOrmUsingDB("edb")
  401. //err = o.Raw(sql, classifyName).QueryRow(&item)
  402. err = global.DmSQL["edb"].Raw(sql, classifyName).First(&item).Error
  403. return
  404. }
  405. type EdbdataClassifyList struct {
  406. ClassifyId int
  407. ClassifyName string
  408. ParentId int
  409. Child []*EdbdataClassify
  410. TradeCode string
  411. UniqueCode string
  412. }
  413. func GetEdbdataClassify(userId int64) (items []*EdbdataClassifyList, err error) {
  414. var newItems []*EdbdataClassifyList
  415. //o := orm.NewOrmUsingDB("edb")
  416. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=0 `
  417. //_, err = o.Raw(sql).QueryRows(&newItems)
  418. err = global.DmSQL["edb"].Raw(sql).Find(&newItems).Error
  419. if err != nil {
  420. return
  421. }
  422. classifyLen := len(newItems)
  423. for i := 0; i < classifyLen; i++ {
  424. var childItems []*EdbdataClassify
  425. parentId := newItems[i].ClassifyId
  426. childSql := ``
  427. if userId > 0 {
  428. userClassifyList, _ := GetManualUserClassify(int(userId))
  429. var userIdArr []string
  430. for _, v := range userClassifyList {
  431. userIdArr = append(userIdArr, strconv.Itoa(v.ClassifyId))
  432. }
  433. userIdStr := strings.Join(userIdArr, ",")
  434. if userIdStr != "" {
  435. childSql = "SELECT a.classify_id,a.classify_name,a.parent_id FROM edbdata_classify AS a WHERE a.is_show=1 and a.classify_id IN(" + userIdStr + ") AND parent_id=? ORDER BY a.create_time ASC "
  436. // _, err = o.Raw(childSql, parentId).QueryRows(&childItems)
  437. err = global.DmSQL["edb"].Raw(childSql, parentId).Find(&childItems).Error
  438. }
  439. } else {
  440. childSql = "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE is_show=1 and parent_id=? ORDER BY create_time ASC "
  441. //_, err = o.Raw(childSql, parentId).QueryRows(&childItems)
  442. err = global.DmSQL["edb"].Raw(childSql, parentId).Find(&childItems).Error
  443. }
  444. if err != nil {
  445. return
  446. }
  447. newItems[i].Child = childItems
  448. }
  449. for _, v := range newItems {
  450. childLen := len(v.Child)
  451. if childLen > 0 {
  452. items = append(items, v)
  453. }
  454. }
  455. return
  456. }
  457. type ManualUserClassify struct {
  458. ManualUserClassifyId int `gorm:"column:manual_user_classify_id"` //`orm:"column(manual_user_classify_id);pk"`
  459. AdminId int `gorm:"column:admin_id"`
  460. ClassifyId int `gorm:"column:classify_id"`
  461. CreateTime time.Time `gorm:"column:create_time"`
  462. }
  463. func GetManualUserClassify(sysUserId int) (list []*ManualUserClassify, err error) {
  464. //o := orm.NewOrmUsingDB("data")
  465. sql := `SELECT * FROM manual_user_classify WHERE admin_id=? `
  466. //_, err = o.Raw(sql, sysUserId).QueryRows(&list)
  467. err = global.DmSQL["data"].Raw(sql, sysUserId).Find(&list).Error
  468. return
  469. }
  470. type EdbdataClassifyResp struct {
  471. List []*EdbdataClassifyList
  472. }
  473. func GetTargetBySecName(secName string) (item *Edbinfo, err error) {
  474. sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? `
  475. //o := orm.NewOrmUsingDB("edb")
  476. //err = o.Raw(sql, secName).QueryRow(&item)
  477. err = global.DmSQL["edb"].Raw(sql, secName).First(&item).Error
  478. return
  479. }
  480. // 更新指标数据信息
  481. func (edbinfo *Edbinfo) Update(cols []string) (err error) {
  482. //o := orm.NewOrmUsingDB("edb")
  483. //_, err = o.Update(edbinfo, cols...)
  484. err = global.DmSQL["edb"].Select(cols).Updates(edbinfo).Error
  485. return
  486. }
  487. func ModifyTargetClassifyId(tradeCode string, classifyId int) (err error) {
  488. sql := `UPDATE edbinfo SET classify_id=? WHERE TRADE_CODE=? `
  489. //o := orm.NewOrmUsingDB("edb")
  490. //_, err = o.Raw(sql, classifyId, tradeCode).Exec()
  491. err = global.DmSQL["edb"].Exec(sql, classifyId, tradeCode).Error
  492. return
  493. }
  494. func GetTargetsDataCount(tradeCode, dt string) (count int, err error) {
  495. sql := `SELECT COUNT(1) AS count FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  496. //o := orm.NewOrmUsingDB("edb")
  497. //err = o.Raw(sql, tradeCode, dt).QueryRow(&count)
  498. err = global.DmSQL["edb"].Raw(sql, tradeCode, dt).Scan(&count).Error
  499. return
  500. }
  501. // GetTargetsDataList 根据code获取指标数据列表
  502. func GetTargetsDataList(tradeCode string) (items []*Edbdata, err error) {
  503. //o := orm.NewOrmUsingDB("edb")
  504. sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? ORDER BY DT ASC `
  505. //_, err = o.Raw(sql, tradeCode).QueryRows(&items)
  506. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&items).Error
  507. return
  508. }
  509. func GetTargetsData(tradeCode, dt string) (item *Edbdata, err error) {
  510. sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  511. //o := orm.NewOrmUsingDB("edb")
  512. //err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
  513. err = global.DmSQL["edb"].Raw(sql, tradeCode, dt).First(&item).Error
  514. return
  515. }
  516. func ModifyTargetsDataByImport(tradeCode, dt, close string) (err error) {
  517. sql := `UPDATE edbdata SET CLOSE=?,modify_time=NOW() WHERE TRADE_CODE=? AND DT=? `
  518. //o := orm.NewOrmUsingDB("edb")
  519. //_, err = o.Raw(sql, close, tradeCode, dt).Exec()
  520. err = global.DmSQL["edb"].Exec(sql, close, tradeCode, dt).Error
  521. return
  522. }
  523. func AddTargetsDataByImport(tradeCode, dt, close string) (err error) {
  524. sql := `INSERT INTO edbdata(TRADE_CODE, DT,CLOSE, modify_time)VALUES(?,?,?,NOW()) `
  525. //o := orm.NewOrmUsingDB("edb")
  526. //_, err = o.Raw(sql, tradeCode, dt, close).Exec()
  527. err = global.DmSQL["edb"].Exec(sql, tradeCode, dt, close).Error
  528. return
  529. }
  530. type EdbdataImportResp struct {
  531. Status int
  532. Msg string
  533. SuccessCount int
  534. FailCount int
  535. }
  536. func GetFailList(sysUserId int) (items []*EdbdataImportFail, err error) {
  537. //o := orm.NewOrmUsingDB("edb")
  538. sql := ` SELECT * FROM edbdata_import_fail WHERE sys_user_id=? `
  539. //_, err = o.Raw(sql, sysUserId).QueryRows(&items)
  540. err = global.DmSQL["edb"].Raw(sql, sysUserId).Find(&items).Error
  541. return
  542. }
  543. type DataListForExport struct {
  544. TradeCode string `gorm:"column:TRADE_CODE"` //`orm:"column(TRADE_CODE)" description:"指标code"`
  545. SecName string `gorm:"column:SEC_NAME"` //`orm:"column(SEC_NAME)" description:"指标名称"`
  546. Unit string `gorm:"column:UNIT"` //`orm:"column(UNIT)" description:"单位"`
  547. Frequency string `gorm:"column:frequency"` //`description:"频度"`
  548. ClassifyId int `gorm:"column:classify_id"` //`description:"分类id"`
  549. NoticeTime string `gorm:"column:notice_time"` //`description:"通知时间"`
  550. ClassifyName string `gorm:"column:classify_name"`
  551. Dt string `gorm:"column:DT"` //`orm:"column(DT)" description:"日期"`
  552. Close float64 `gorm:"column:CLOSE"` //`orm:"column(CLOSE)" description:"值"`
  553. }
  554. func GetDataListForExport(startDate, endDate, frequency, keyWord string, classifyId int) (items []*DataListForExport, err error) {
  555. where := ``
  556. var pars []interface{}
  557. if keyWord != "" {
  558. where = ` AND SEC_NAME LIKE ? `
  559. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  560. }
  561. if startDate != "" {
  562. where += ` AND create_date>=? `
  563. pars = append(pars, startDate)
  564. }
  565. if endDate != "" {
  566. where += ` AND create_date<=? `
  567. pars = append(pars, endDate)
  568. }
  569. if frequency != "" {
  570. where += ` AND frequency=? `
  571. pars = append(pars, frequency)
  572. }
  573. if classifyId > 0 {
  574. where += ` AND classify_id=? `
  575. pars = append(pars, classifyId)
  576. }
  577. sql := ` SELECT a.TRADE_CODE,a.SEC_NAME,a.UNIT,a.frequency,a.classify_id,b.classify_name,c.DT,c.CLOSE FROM edbdata AS c
  578. INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  579. LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  580. WHERE a.classify_id>0 `
  581. if where != "" {
  582. sql += where
  583. }
  584. sql = sql + " ORDER BY c.DT DESC "
  585. //o := orm.NewOrmUsingDB("edb")
  586. //_, err = o.Raw(sql, pars).QueryRows(&items)
  587. err = global.DmSQL["edb"].Raw(sql, pars).Find(&items).Error
  588. return
  589. }
  590. type DataDeleteReq struct {
  591. TradeCode string `description:"指标唯一编码"`
  592. CreateDate string `description:"数据录入日期"`
  593. }
  594. func DataDelete(tradeCode, createDate, close string, modifyTime time.Time, sysUserId int) (err error) {
  595. //o := orm.NewOrmUsingDB("edb")
  596. //to, err := o.Begin()
  597. to := global.DmSQL["edb"].Begin()
  598. if err != nil {
  599. return
  600. }
  601. defer func() {
  602. if err != nil {
  603. _ = to.Rollback()
  604. } else {
  605. _ = to.Commit()
  606. }
  607. }()
  608. recordSql := ` INSERT INTO edbdata_delete_record(TRADE_CODE,DT,CLOSE,modify_time,create_time,sys_user_id)
  609. VALUES(?,?,?,?,?,?)`
  610. //_, err = to.Raw(recordSql, tradeCode, createDate, close, modifyTime, time.Now(), sysUserId).Exec()
  611. err = to.Exec(recordSql, tradeCode, createDate, close, modifyTime, time.Now(), sysUserId).Error
  612. sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
  613. //_, err = to.Raw(sql, tradeCode, createDate).Exec()
  614. err = to.Exec(sql, tradeCode, createDate).Error
  615. return
  616. }
  617. func GetTargetInfoCount(tradeCode string) (count int, err error) {
  618. sql := ` SELECT COUNT(1) AS count FROM edbdata AS c
  619. INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  620. WHERE a.TRADE_CODE=? `
  621. //o := orm.NewOrmUsingDB("edb")
  622. //err = o.Raw(sql, tradeCode).QueryRow(&count)
  623. err = global.DmSQL["edb"].Raw(sql, tradeCode).Scan(&count).Error
  624. return
  625. }
  626. type TargetDeleteReq struct {
  627. TradeCode string `description:"指标唯一编码"`
  628. }
  629. func TargetDelete(tradeCode string) (err error) {
  630. //o := orm.NewOrmUsingDB("edb")
  631. //to, err := o.Begin()
  632. to := global.DmSQL["edb"].Begin()
  633. if err != nil {
  634. return
  635. }
  636. defer func() {
  637. if err != nil {
  638. _ = to.Rollback()
  639. } else {
  640. _ = to.Commit()
  641. }
  642. }()
  643. sql := " DELETE FROM edbinfo WHERE TRADE_CODE = ? "
  644. //_, err = to.Raw(sql, tradeCode).Exec()
  645. err = to.Exec(sql, tradeCode).Error
  646. sql = " DELETE FROM edbdata WHERE TRADE_CODE = ? "
  647. //_, err = to.Raw(sql, tradeCode).Exec()
  648. err = to.Exec(sql, tradeCode).Error
  649. return
  650. }
  651. type Researcher struct {
  652. AdminId int `gorm:"column:admin_id"` //`description:"系统用户id"`
  653. AdminName string `gorm:"column:admin_name"` //`description:"系统用户名称"`
  654. RealName string `gorm:"column:real_name"` //`description:"系统用户姓名"`
  655. Role string `gorm:"column:role"` //`description:"系统用户角色"`
  656. Mobile string `gorm:"column:mobile"` //`description:"手机号"`
  657. TargetCount int `gorm:"column:target_count"` //`description:"指标数量"`
  658. }
  659. type ResearcherListResp struct {
  660. List []*Researcher
  661. }
  662. func GetResearcherEntry() (items []*Researcher, err error) {
  663. sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role_type=1 `
  664. //o := orm.NewOrm()
  665. //_, err = o.Raw(sql).QueryRows(&items)
  666. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  667. researchLen := len(items)
  668. //edbO := orm.NewOrmUsingDB("edb")
  669. for i := 0; i < researchLen; i++ {
  670. var count int
  671. mobile := items[i].Mobile
  672. sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM edbinfo_user AS a
  673. INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
  674. WHERE a.mobile=? AND b.classify_id>0 `
  675. //err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
  676. err = global.DmSQL["edb"].Raw(sqlCount, mobile).Scan(&count).Error
  677. items[i].TargetCount = count
  678. }
  679. return
  680. }
  681. func GetResearcherEntryByMobile(mobile string) (items []*Researcher, err error) {
  682. sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role_type=1 `
  683. if mobile != "" {
  684. sql += ` AND mobile IN(` + mobile + `)`
  685. }
  686. //o := orm.NewOrm()
  687. //_, err = o.Raw(sql).QueryRows(&items)
  688. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  689. researchLen := len(items)
  690. //edbO := orm.NewOrmUsingDB("edb")
  691. for i := 0; i < researchLen; i++ {
  692. var count int
  693. mobile := items[i].Mobile
  694. sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM edbinfo_user AS a
  695. INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
  696. WHERE a.mobile=? AND b.classify_id>0 `
  697. //err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
  698. err = global.DmSQL["edb"].Raw(sqlCount, mobile).Scan(&count).Error
  699. items[i].TargetCount = count
  700. }
  701. return
  702. }
  703. type EdbinfoItems struct {
  704. TradeCode string `gorm:"column:TRADE_CODE"` //`orm:"column(TRADE_CODE);pk" description:"指标code"`
  705. SecName string `gorm:"column:SEC_NAME"` //`orm:"column(SEC_NAME);" description:"指标名称"`
  706. Unit string `gorm:"column:UNIT"` //`orm:"column(UNIT);" description:"单位"`
  707. Remark string `gorm:"column:REMARK"` //`orm:"column(REMARK);" description:"备注"`
  708. Frequency string `gorm:"column:frequency"` //`description:"频度"`
  709. ClassifyId int `gorm:"column:classify_id"` //`description:"分类id"`
  710. ClassifyName string `gorm:"column:classify_name"` //`description:"分类名称"`
  711. CreateDate string `gorm:"column:create_date"` //`description:"创建时间"`
  712. UserId int `gorm:"column:user_id"` //`description:"录入用户id"`
  713. NoticeTime string `gorm:"column:notice_time"` //`description:"通知时间"`
  714. Mobile string `gorm:"column:mobile"` //`description:"录入者手机号"`
  715. ModifyDate string `gorm:"column:modify_date"` //`description:"待更新日期"`
  716. Status string `gorm:"column:status"` // `description:"状态:未完成/完成"`
  717. }
  718. type TargetItemsResp struct {
  719. List SortEdbInfo
  720. }
  721. type SortEdbInfo []EdbinfoItems
  722. func GetTargetItems(mobile string, classifyId int) (lastItems SortEdbInfo, err error) {
  723. var items []*EdbinfoItems
  724. //o := orm.NewOrmUsingDB("edb")
  725. //sql := ` SELECT *,'' modify_date,'' status FROM edbinfo AS a WHERE a.classify_id>0 `
  726. sql := ` SELECT *,'' modify_date,'' STATUS FROM edbinfo AS a
  727. WHERE a.classify_id>0
  728. `
  729. if classifyId > 0 {
  730. sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ``
  731. }
  732. sql += ` GROUP BY a.TRADE_CODE `
  733. //if classifyId > 0 {
  734. // sql = ` SELECT *,'' modify_date,'' status FROM edbinfo AS a
  735. // WHERE a.classify_id=` + strconv.Itoa(classifyId) + ` AND a.classify_id>0
  736. // GROUP BY a.TRADE_CODE `
  737. //}
  738. sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk ) COLLATE gbk_chinese_ci ASC `
  739. //_, err = o.Raw(sql).QueryRows(&items)
  740. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  741. if err != nil {
  742. return
  743. }
  744. itemsLen := len(items)
  745. nowWeek := time.Now().Weekday().String()
  746. fmt.Println(nowWeek)
  747. finishEdbInfo := SortEdbInfo{}
  748. unFinishEdbInfo := SortEdbInfo{}
  749. for i := 0; i < itemsLen; i++ {
  750. noticeTime := items[i].NoticeTime
  751. frequency := items[i].Frequency
  752. tradeCode := items[i].TradeCode
  753. if noticeTime != "" {
  754. if frequency == "周度" {
  755. noticeArr := strings.Split(noticeTime, " ")
  756. noticeWeek := noticeArr[0]
  757. fmt.Println(noticeWeek)
  758. addDay := 0
  759. if nowWeek == "Sunday" {
  760. if noticeWeek == "周日" {
  761. addDay = 0
  762. } else if noticeWeek == "周一" {
  763. addDay = 1
  764. } else if noticeWeek == "周二" {
  765. addDay = 2
  766. } else if noticeWeek == "周三" {
  767. addDay = 3
  768. } else if noticeWeek == "周四" {
  769. addDay = 4
  770. } else if noticeWeek == "周五" {
  771. addDay = 5
  772. } else if noticeWeek == "周六" {
  773. addDay = 6
  774. } else {
  775. addDay = 0
  776. }
  777. } else if nowWeek == "Monday" {
  778. if noticeWeek == "周日" {
  779. addDay = 6
  780. } else if noticeWeek == "周一" {
  781. addDay = 0
  782. } else if noticeWeek == "周二" {
  783. addDay = 1
  784. } else if noticeWeek == "周三" {
  785. addDay = 2
  786. } else if noticeWeek == "周四" {
  787. addDay = 3
  788. } else if noticeWeek == "周五" {
  789. addDay = 4
  790. } else if noticeWeek == "周六" {
  791. addDay = 5
  792. } else {
  793. addDay = 0
  794. }
  795. } else if nowWeek == "Tuesday" {
  796. if noticeWeek == "周日" {
  797. addDay = 5
  798. } else if noticeWeek == "周一" {
  799. addDay = 6
  800. } else if noticeWeek == "周二" {
  801. addDay = 0
  802. } else if noticeWeek == "周三" {
  803. addDay = 1
  804. } else if noticeWeek == "周四" {
  805. addDay = 2
  806. } else if noticeWeek == "周五" {
  807. addDay = 3
  808. } else if noticeWeek == "周六" {
  809. addDay = 4
  810. } else {
  811. addDay = 0
  812. }
  813. } else if nowWeek == "Wednesday" {
  814. if noticeWeek == "周日" {
  815. addDay = 4
  816. } else if noticeWeek == "周一" {
  817. addDay = 5
  818. } else if noticeWeek == "周二" {
  819. addDay = 6
  820. } else if noticeWeek == "周三" {
  821. addDay = 0
  822. } else if noticeWeek == "周四" {
  823. addDay = 1
  824. } else if noticeWeek == "周五" {
  825. addDay = 2
  826. } else if noticeWeek == "周六" {
  827. addDay = 3
  828. } else {
  829. addDay = 0
  830. }
  831. } else if nowWeek == "Thursday" {
  832. if noticeWeek == "周日" {
  833. addDay = 3
  834. } else if noticeWeek == "周一" {
  835. addDay = 4
  836. } else if noticeWeek == "周二" {
  837. addDay = 5
  838. } else if noticeWeek == "周三" {
  839. addDay = 6
  840. } else if noticeWeek == "周四" {
  841. addDay = 0
  842. } else if noticeWeek == "周五" {
  843. addDay = 1
  844. } else if noticeWeek == "周六" {
  845. addDay = 2
  846. } else {
  847. addDay = 0
  848. }
  849. } else if nowWeek == "Friday" {
  850. if noticeWeek == "周日" {
  851. addDay = 2
  852. } else if noticeWeek == "周一" {
  853. addDay = 3
  854. } else if noticeWeek == "周二" {
  855. addDay = 4
  856. } else if noticeWeek == "周三" {
  857. addDay = 5
  858. } else if noticeWeek == "周四" {
  859. addDay = 6
  860. } else if noticeWeek == "周五" {
  861. addDay = 0
  862. } else if noticeWeek == "周六" {
  863. addDay = 1
  864. } else {
  865. addDay = 0
  866. }
  867. } else if nowWeek == "Saturday" {
  868. if noticeWeek == "周日" {
  869. addDay = 1
  870. } else if noticeWeek == "周一" {
  871. addDay = 2
  872. } else if noticeWeek == "周二" {
  873. addDay = 3
  874. } else if noticeWeek == "周三" {
  875. addDay = 4
  876. } else if noticeWeek == "周四" {
  877. addDay = 5
  878. } else if noticeWeek == "周五" {
  879. addDay = 6
  880. } else if noticeWeek == "周六" {
  881. addDay = 0
  882. } else {
  883. addDay = 0
  884. }
  885. }
  886. modifyDate := time.Now().AddDate(0, 0, addDay)
  887. modifyDateStr := modifyDate.Format(utils.FormatDate)
  888. items[i].ModifyDate = modifyDateStr
  889. modifyDateEndStr := modifyDate.AddDate(0, 0, -7).Format(utils.FormatDate)
  890. fmt.Println("addDay:", addDay)
  891. fmt.Println("modifyDateEndStr:", modifyDateEndStr)
  892. count := 0
  893. sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
  894. //err = o.Raw(sqlCount, tradeCode, modifyDateEndStr, modifyDateStr).QueryRow(&count)
  895. err = global.DmSQL["edb"].Raw(sqlCount, tradeCode, modifyDateEndStr, modifyDateStr).Scan(&count).Error
  896. if err != nil {
  897. return nil, err
  898. }
  899. if count > 0 {
  900. items[i].Status = "完成"
  901. finishEdbInfo = append(finishEdbInfo, *items[i])
  902. } else {
  903. items[i].Status = "未完成"
  904. unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
  905. }
  906. } else if frequency == "日度" {
  907. items[i].Status = "完成"
  908. finishEdbInfo = append(finishEdbInfo, *items[i])
  909. } else if frequency == "月度" {
  910. myYear := time.Now().Year()
  911. myMonth := time.Now().Format("01")
  912. startDate, endDate := utils.GetMonthStartAndEnd(strconv.Itoa(myYear), myMonth)
  913. count := 0
  914. sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
  915. //err = o.Raw(sqlCount, tradeCode, startDate, endDate).QueryRow(&count)
  916. err = global.DmSQL["edb"].Raw(sqlCount, tradeCode, startDate, endDate).Scan(&count).Error
  917. if err != nil {
  918. return nil, err
  919. }
  920. if noticeTime != "" {
  921. var modifyDateStr string
  922. strArr := strings.Split(noticeTime, "日")
  923. myYear := time.Now().Year()
  924. myMonth := time.Now().Format("01")
  925. modifyDateStr = strconv.Itoa(myYear) + "-" + myMonth + "-" + strArr[0]
  926. items[i].ModifyDate = modifyDateStr
  927. }
  928. if count > 0 {
  929. items[i].Status = "完成"
  930. finishEdbInfo = append(finishEdbInfo, *items[i])
  931. } else {
  932. items[i].Status = "未完成"
  933. unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
  934. }
  935. } else {
  936. items[i].Status = "完成"
  937. finishEdbInfo = append(finishEdbInfo, *items[i])
  938. }
  939. } else {
  940. if frequency == "月度" {
  941. myYear := time.Now().Year()
  942. myMonth := time.Now().Format("01")
  943. startDate, endDate := utils.GetMonthStartAndEnd(strconv.Itoa(myYear), myMonth)
  944. count := 0
  945. sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
  946. //err = o.Raw(sqlCount, tradeCode, startDate, endDate).QueryRow(&count)
  947. err = global.DmSQL["edb"].Raw(sqlCount, tradeCode, startDate, endDate).Scan(&count).Error
  948. if err != nil {
  949. return nil, err
  950. }
  951. if count > 0 {
  952. items[i].Status = "完成"
  953. finishEdbInfo = append(finishEdbInfo, *items[i])
  954. } else {
  955. items[i].Status = "未完成"
  956. unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
  957. }
  958. } else {
  959. items[i].Status = "完成"
  960. finishEdbInfo = append(finishEdbInfo, *items[i])
  961. }
  962. }
  963. }
  964. sort.Sort(SortByModifyDate{finishEdbInfo})
  965. sort.Sort(SortByModifyDate{unFinishEdbInfo})
  966. lastItems = append(lastItems, unFinishEdbInfo...)
  967. lastItems = append(lastItems, finishEdbInfo...)
  968. return
  969. }
  970. // 获取此 slice 的长度
  971. func (p SortEdbInfo) Len() int { return len(p) }
  972. // 根据元素的状态降序排序
  973. func (p SortEdbInfo) Less(i, j int) bool {
  974. return p[i].Status > p[j].Status
  975. }
  976. // 交换数据
  977. func (p SortEdbInfo) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
  978. // 嵌套结构体 将继承 SortEdbInfo 的所有属性和方法
  979. // 所以相当于SortByName 也实现了 Len() 和 Swap() 方法
  980. type SortByStatus struct{ SortEdbInfo }
  981. // 根据元素的姓名长度降序排序 (此处按照自己的业务逻辑写)
  982. func (p SortByStatus) Less(i, j int) bool {
  983. return len(p.SortEdbInfo[i].Status) > len(p.SortEdbInfo[j].Status)
  984. }
  985. type SortByModifyDate struct{ SortEdbInfo }
  986. // 根据元素的年龄降序排序 (此处按照自己的业务逻辑写)
  987. func (p SortByModifyDate) Less(i, j int) bool {
  988. return p.SortEdbInfo[i].ModifyDate > p.SortEdbInfo[j].ModifyDate
  989. }
  990. type DataCheckResp struct {
  991. Status int `description:"状态:1:该日期已存在数据,是否确认修改?,0:数据不存在"`
  992. Close string `description:"值"`
  993. }
  994. type TargetCheckResp struct {
  995. Status int `description:"状态:1:该指标有关联数据,请先删除数据,0:指标不存在关联数据,可直接删除"`
  996. }
  997. type EdbdataExportList struct {
  998. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;not null" description:"指标code"`
  999. SecName string `gorm:"column:SEC_NAME" description:"指标名称"`
  1000. Unit string `gorm:"column:UNIT" description:"单位"`
  1001. Remark string `gorm:"column:REMARK" description:"备注"`
  1002. Frequency string `gorm:"column:frequency" description:"频度"` //`description:"频度"`
  1003. ClassifyId int `gorm:"column:classify_id" description:"分类id"` //`description:"分类id"`
  1004. ClassifyName string `gorm:"column:classify_name" description:"分类名称"` //`description:"分类名称"`
  1005. CreateDate string `gorm:"column:create_date" description:"创建时间"` //`description:"创建时间"`
  1006. Dt string `gorm:"column:DT" description:"最新一次录入时间"`
  1007. }
  1008. func GetEdbdataSecName(condition string, pars []interface{}) (items []*EdbdataExportList, err error) {
  1009. //sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt
  1010. // FROM edbdata AS c
  1011. // INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  1012. // INNER JOIN edbinfo_user AS d ON a.TRADE_CODE=d.TRADE_CODE
  1013. // LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  1014. // WHERE a.classify_id>0`
  1015. sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt,b.classify_name
  1016. FROM edbdata AS c
  1017. INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  1018. LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  1019. WHERE a.classify_id>0`
  1020. if condition != "" {
  1021. sql += condition
  1022. }
  1023. sql += " GROUP BY a.TRADE_CODE ORDER BY a.TRADE_CODE ASC "
  1024. //o := orm.NewOrmUsingDB("edb")
  1025. //_, err = o.Raw(sql, pars).QueryRows(&items)
  1026. err = global.DmSQL["edb"].Raw(sql, pars).Find(&items).Error
  1027. return
  1028. }
  1029. func GetEdbDataFrequency(classifyId int) (items []*string, err error) {
  1030. sql := `SELECT DISTINCT frequency FROM edbinfo where classify_id=? AND frequency IS NOT NULL ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
  1031. //o := orm.NewOrmUsingDB("edb")
  1032. //_, err = o.Raw(sql, classifyId).QueryRows(&items)
  1033. err = global.DmSQL["edb"].Raw(sql, classifyId).Find(&items).Error
  1034. return
  1035. }
  1036. // GetEdbDataFrequencyByClassifyIdList
  1037. // @Description: 根据分类列表获取所有的频度
  1038. // @author: Roc
  1039. // @datetime 2024-08-15 17:51:13
  1040. // @param classifyIdList []int
  1041. // @return items []*string
  1042. // @return err error
  1043. func GetEdbDataFrequencyByClassifyIdList(classifyIdList []int) (items []string, err error) {
  1044. num := len(classifyIdList)
  1045. if num <= 0 {
  1046. return
  1047. }
  1048. sql := `SELECT DISTINCT frequency FROM edbinfo where classify_id in (` + utils.GetOrmInReplace(num) + `) AND frequency IS NOT NULL ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
  1049. //o := orm.NewOrmUsingDB("edb")
  1050. //_, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  1051. err = global.DmSQL["edb"].Raw(sql, classifyIdList).Find(&items).Error
  1052. return
  1053. }
  1054. func GetEdbDataFrequencyByKeyord(keyword string) (items []string, err error) {
  1055. sql := `SELECT DISTINCT frequency FROM edbinfo where SEC_NAME=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
  1056. //o := orm.NewOrmUsingDB("edb")
  1057. //_, err = o.Raw(sql, keyword).QueryRows(&items)
  1058. err = global.DmSQL["edb"].Raw(sql, keyword).Find(&items).Error
  1059. return
  1060. }
  1061. type EdbdataList struct {
  1062. Dt string `gorm:"column:DT" description:"录入时间"` //`orm:"column(DT);" description:"录入时间"`
  1063. }
  1064. func GetEdbdataList(tradeCode string) (items []*EdbdataList, err error) {
  1065. sql := ` SELECT DT FROM edbdata WHERE TRADE_CODE IN(` + tradeCode + `) GROUP BY DT ORDER BY DT DESC `
  1066. //o := orm.NewOrmUsingDB("edb")
  1067. //_, err = o.Raw(sql).QueryRows(&items)
  1068. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1069. return
  1070. }
  1071. type EdbdataItem struct {
  1072. TradeCode string `gorm:"column:TRADE_CODE" description:"指标code"` //`orm:"column(TRADE_CODE);" description:"指标code"`
  1073. Dt string `gorm:"column:DT" description:"最新一次录入时间"` // `orm:"column(DT);" description:"最新一次录入时间"`
  1074. Close float64 `gorm:"column:CLOSE" description:"值"` //`orm:"column(CLOSE);" description:"值"`
  1075. }
  1076. func GetEdbdataValueByTradeCode(tradeCode, dt string) (item *EdbdataItem, err error) {
  1077. sql := ` SELECT TRADE_CODE,DT,CLOSE FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  1078. //o := orm.NewOrmUsingDB("edb")
  1079. //err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
  1080. err = global.DmSQL["edb"].Raw(sql, tradeCode, dt).First(&item).Error
  1081. return
  1082. }
  1083. func GetEdbdataAllByTradeCode(tradeCode string) (items []*EdbdataItem, err error) {
  1084. sql := ` SELECT * FROM edbdata WHERE TRADE_CODE=? `
  1085. //o := orm.NewOrmUsingDB("edb")
  1086. //_, err = o.Raw(sql, tradeCode).QueryRows(&items)
  1087. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&items).Error
  1088. return
  1089. }
  1090. func GetEdbdataClassifyByParentId(parentId int) (items []*EdbdataClassify, err error) {
  1091. sql := ` SELECT * FROM edbdata_classify WHERE parent_id=? `
  1092. //o := orm.NewOrmUsingDB("edb")
  1093. //_, err = o.Raw(sql, parentId).QueryRows(&items)
  1094. err = global.DmSQL["edb"].Raw(sql, parentId).Find(&items).Error
  1095. return
  1096. }
  1097. type LzPriceClassify struct {
  1098. ProductName string `gorm:"column:product_name" description:"产品名称"`
  1099. }
  1100. func GetLzPriceClassify() (items []*LzPriceClassify, err error) {
  1101. sql := ` SELECT product_name FROM longzhongpriceinfo GROUP BY product_name ORDER BY product_name DESC `
  1102. //o := orm.NewOrmUsingDB("edb")
  1103. //_, err = o.Raw(sql).QueryRows(&items)
  1104. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1105. return
  1106. }
  1107. type Longzhongpriceinfo struct {
  1108. LongzhongpriceinfoId int `gorm:"column:longzhongpriceinfo_id"` //`orm:"column(longzhongpriceinfo_id);pk"`
  1109. Standard string `gorm:"column:standard"`
  1110. ModelName string `gorm:"column:model_name"`
  1111. Unit string `gorm:"column:unit"`
  1112. AreaName string `gorm:"column:area_name"`
  1113. PriceType string `gorm:"column:price_type"`
  1114. Memo string `gorm:"column:memo"`
  1115. PriceId string `gorm:"column:price_id"`
  1116. ProductName string `gorm:"column:product_name"`
  1117. InfoType string `gorm:"column:info_type"`
  1118. InfoTypeRemark string `gorm:"column:info_type_remark"`
  1119. MarketName string `gorm:"column:market_name"`
  1120. ManufactureName string `gorm:"column:manufacture_name"`
  1121. }
  1122. func GetLongzhongpriceinfoByClassifyName(productName string) (items []*Longzhongpriceinfo, err error) {
  1123. sql := `SELECT * FROM longzhongpriceinfo WHERE product_name=? ORDER BY longzhongpriceinfo_id ASC `
  1124. //o := orm.NewOrmUsingDB("edb")
  1125. //_, err = o.Raw(sql, productName).QueryRows(&items)
  1126. err = global.DmSQL["edb"].Raw(sql, productName).Find(&items).Error
  1127. return
  1128. }
  1129. func GetLongzhongPriceDataMaxCount(productName string) (count int, err error) {
  1130. //o := orm.NewOrmUsingDB("edb")
  1131. sql := `SELECT MAX(t.num) AS count FROM (
  1132. SELECT COUNT(1) AS num FROM longzhongpriceinfo AS a
  1133. INNER JOIN longzhongpricedata AS b ON a.longzhongpriceinfo_id=b.longzhongpriceinfo_id
  1134. WHERE a.product_name=?
  1135. GROUP BY a.product_name
  1136. )AS t `
  1137. //err = o.Raw(sql, productName).QueryRow(&count)
  1138. err = global.DmSQL["edb"].Raw(sql, productName).Scan(&count).Error
  1139. return
  1140. }
  1141. type LongzhongpricedataItems struct {
  1142. LongzhongpricedataId int `gorm:"column:longzhongpricedata_id"` //`orm:"column(longzhongpricedata_id);pk"`
  1143. LongzhongpriceinfoId int `gorm:"column:longzhongpriceinfo_id"`
  1144. PriceDate string `gorm:"column:price_date"`
  1145. Memo string `gorm:"column:memo"`
  1146. Price float64 `gorm:"column:price"`
  1147. CnyPrice float64 `gorm:"column:cny_price"`
  1148. ZsyPrice float64 `gorm:"column:zsy_price"`
  1149. ZshPrice float64 `gorm:"column:zsh_price"`
  1150. LowPrice float64 `gorm:"column:low_price"`
  1151. HighPrice float64 `gorm:"column:high_price"`
  1152. RisePrice float64 `gorm:"column:rise_price"`
  1153. TonPrice float64 `gorm:"column:ton_price"`
  1154. PriceType string `gorm:"column:price_type"`
  1155. UpdateDate string `gorm:"column:update_date"`
  1156. }
  1157. func GetLongzhongPriceDataById(lzPriceInfoId int) (items []*LongzhongpricedataItems, err error) {
  1158. //o := orm.NewOrmUsingDB("edb")
  1159. sql := ` SELECT DISTINCT a.longzhongpriceinfo_id,a.price_date,a.memo,a.price,a.cny_price,a.zsy_price,a.zsh_price,a.low_price,a.high_price,a.rise_price,a.ton_price,a.price_type,a.update_date
  1160. FROM longzhongpricedata AS a
  1161. WHERE longzhongpriceinfo_id=? ORDER BY price_date DESC `
  1162. //_, err = o.Raw(sql, lzPriceInfoId).QueryRows(&items)
  1163. err = global.DmSQL["edb"].Raw(sql, lzPriceInfoId).Find(&items).Error
  1164. return
  1165. }
  1166. func GetLzSurveyClassify() (items []*LzPriceClassify, err error) {
  1167. sql := ` SELECT breed_name AS product_name FROM longzhong_survey_product GROUP BY breed_name ORDER BY breed_name DESC `
  1168. //o := orm.NewOrmUsingDB("edb")
  1169. //_, err = o.Raw(sql).QueryRows(&items)
  1170. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1171. return
  1172. }
  1173. // LongzhongSurveyProduct 结构体
  1174. type LongzhongSurveyProduct struct {
  1175. SurveyProductId int `gorm:"column:survey_product_id;primaryKey;autoIncrement:false;not null" description:"调查产品ID"`
  1176. ProjectQuotaId int64 `gorm:"column:project_quota_id" description:"项目配额ID"`
  1177. BreedId string `gorm:"column:breed_id" description:"品种ID"`
  1178. BreedName string `gorm:"column:breed_name" description:"品种名称"`
  1179. QuotaId string `gorm:"column:quota_id" description:"配额ID"`
  1180. QuotaName string `gorm:"column:quota_name" description:"配额名称"`
  1181. UnitId string `gorm:"column:unit_id" description:"单位ID"`
  1182. UnitName string `gorm:"column:unit_name" description:"单位名称"`
  1183. SampleType int64 `gorm:"column:sample_type" description:"样本类型"`
  1184. SampleId string `gorm:"column:sample_id" description:"样本ID"`
  1185. SampleName string `gorm:"column:sample_name" description:"样本名称"`
  1186. DeviceId string `gorm:"column:device_id" description:"设备ID"`
  1187. Device string `gorm:"column:device" description:"设备名称"`
  1188. ProductCraftId string `gorm:"column:product_craft_id" description:"工艺ID"`
  1189. ProductCraft string `gorm:"column:product_craft" description:"工艺名称"`
  1190. ProductLine string `gorm:"column:product_line" description:"生产线"`
  1191. InputMode int64 `gorm:"column:input_mode" description:"输入模式"`
  1192. Frequency int64 `gorm:"column:frequency" description:"频率"`
  1193. InputValue string `gorm:"column:input_value" description:"输入值"`
  1194. TaskShouldFinishTime int `gorm:"column:task_should_finish_time" description:"任务应完成时间"`
  1195. CustomId string `gorm:"column:custom_id" description:"自定义ID"`
  1196. CustomType int64 `gorm:"column:custom_type" description:"自定义类型"`
  1197. Custom string `gorm:"column:custom" description:"自定义名称"`
  1198. QuotaSampleId int64 `gorm:"column:quota_sample_id" description:"配额样本ID"`
  1199. StartDate string `gorm:"column:start_date" description:"开始日期"`
  1200. EndDate string `gorm:"column:end_date" description:"结束日期"`
  1201. LzCode string `gorm:"column:lz_code" description:"龙种代码"`
  1202. }
  1203. func GetLongzhongSurveyProductByClassifyName(productName string) (items []*LongzhongSurveyProduct, err error) {
  1204. sql := `SELECT * FROM longzhong_survey_product WHERE breed_name=? ORDER BY survey_product_id ASC `
  1205. //o := orm.NewOrmUsingDB("edb")
  1206. //_, err = o.Raw(sql, productName).QueryRows(&items)
  1207. err = global.DmSQL["edb"].Raw(sql, productName).Find(&items).Error
  1208. return
  1209. }
  1210. func GetLzSurveyProductByNameAndFrequency(productName string, frequency int) (items []*LongzhongSurveyProduct, err error) {
  1211. sql := `SELECT * FROM longzhong_survey_product WHERE breed_name=? AND frequency=? ORDER BY survey_product_id ASC `
  1212. //o := orm.NewOrmUsingDB("edb")
  1213. //_, err = o.Raw(sql, productName, frequency).QueryRows(&items)
  1214. err = global.DmSQL["edb"].Raw(sql, productName, frequency).Find(&items).Error
  1215. return
  1216. }
  1217. func GetExportLzSurveyProductByBreedIds(breedIds []string) (items []*LongzhongSurveyProduct, err error) {
  1218. if len(breedIds) == 0 {
  1219. return
  1220. }
  1221. field := ` survey_product_id, breed_id, breed_name, sample_name, custom, quota_name, lz_code, frequency, unit_name, end_date, input_value `
  1222. sql := `SELECT ` + field + ` FROM longzhong_survey_product WHERE breed_id IN (` + utils.GetOrmInReplace(len(breedIds)) + `) ORDER BY breed_id ASC, frequency ASC, survey_product_id ASC `
  1223. //o := orm.NewOrmUsingDB("edb")
  1224. //_, err = o.Raw(sql, breedIds).QueryRows(&items)
  1225. err = global.DmSQL["edb"].Raw(sql, breedIds).Find(&items).Error
  1226. return
  1227. }
  1228. func GetLzFrequency(productName string) (items []*int, err error) {
  1229. sql := `SELECT DISTINCT frequency FROM longzhong_survey_product WHERE breed_name=? ORDER BY frequency`
  1230. //o := orm.NewOrmUsingDB("edb")
  1231. //_, err = o.Raw(sql, productName).QueryRows(&items)
  1232. err = global.DmSQL["edb"].Raw(sql, productName).Find(&items).Error
  1233. return
  1234. }
  1235. // EdbInfoItem
  1236. type EdbInfoItem struct {
  1237. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;type:varchar(255)" orm:"column(TRADE_CODE);pk" description:"指标code"`
  1238. SecName string `gorm:"column:SEC_NAME;type:varchar(255)" orm:"column(SEC_NAME);" description:"指标名称"`
  1239. Unit string `gorm:"column:UNIT;type:varchar(255)" orm:"column(UNIT);" description:"单位"`
  1240. Remark string `gorm:"column:REMARK;type:varchar(255)" orm:"column(REMARK);" description:"备注"`
  1241. Frequency string `gorm:"column:FREQUENCY;type:varchar(255)" description:"频度"`
  1242. ClassifyId int `gorm:"column:CLASSIFY_ID;type:int" description:"分类id"`
  1243. ClassifyName string `gorm:"column:CLASSIFY_NAME;type:varchar(255)" description:"分类名称"`
  1244. CreateDate string `gorm:"column:CREATE_DATE;type:varchar(255)" description:"创建时间"`
  1245. UserId int `gorm:"column:USER_ID;type:int" description:"录入用户id"`
  1246. UserName string `gorm:"column:USER_NAME;type:varchar(255)" description:"录入用户名称"`
  1247. NoticeTime string `gorm:"column:NOTICE_TIME;type:varchar(255)" description:"通知时间"`
  1248. Mobile string `gorm:"column:MOBILE;type:varchar(255)" description:"录入者手机号"`
  1249. ModifyDate string `gorm:"column:MODIFY_DATE;type:varchar(255)" description:"待更新日期"`
  1250. ModifyTime string `gorm:"column:MODIFY_TIME;type:varchar(255)" description:"最近一次更新时间"`
  1251. Status string `gorm:"column:STATUS;type:varchar(255)" description:"状态:未完成/完成"`
  1252. IsJoinEdb int8 `gorm:"column:IS_JOIN_EDB;type:tinyint" description:"指标库是否已添加:0-否;1-是"`
  1253. StartDate string `gorm:"column:START_DATE;type:varchar(255)" description:"数据开始日期"`
  1254. EndDate string `gorm:"column:END_DATE;type:varchar(255)" description:"数据结束日期"`
  1255. LatestValue float64 `gorm:"column:LATEST_VALUE;type:decimal(10,2)" description:"指标最新值"`
  1256. DataList []*Edbdata `gorm:"-" description:"指标数据列表"`
  1257. }
  1258. // GetTargetItemList 获取指标列表数据
  1259. func GetTargetItemList(classifyId, edbShowType int, frequency, keyword, tradeCode string, classifyIdStrList []string) (items []*EdbInfoItem, err error) {
  1260. //o := orm.NewOrmUsingDB("edb")
  1261. pars := make([]interface{}, 0)
  1262. sql := ` SELECT a.*,'' modify_date,'' STATUS FROM edbinfo AS a `
  1263. if edbShowType != 0 {
  1264. sql = ` SELECT a.*,b.DT,'' modify_date,'' STATUS FROM edbinfo AS a
  1265. left join edbdata b on a.TRADE_CODE=b.TRADE_CODE `
  1266. }
  1267. sql += ` WHERE a.classify_id>0 `
  1268. //如果没有分类id集合列表,那么就没有数据了,不用往下执行了,直接返回好了
  1269. if len(classifyIdStrList) <= 0 {
  1270. return
  1271. }
  1272. if len(classifyIdStrList) > 0 {
  1273. sql += ` AND a.classify_id in (` + strings.Join(classifyIdStrList, ",") + `) `
  1274. }
  1275. if classifyId > 0 {
  1276. sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ` `
  1277. }
  1278. //频度
  1279. if frequency != "" {
  1280. sql += ` AND a.frequency="` + frequency + `" `
  1281. }
  1282. //关键字
  1283. if keyword != "" {
  1284. sql += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  1285. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  1286. }
  1287. //指定指标
  1288. if tradeCode != "" {
  1289. sql += ` AND a.TRADE_CODE = "` + tradeCode + `" `
  1290. }
  1291. //指标里面是否有数据
  1292. switch edbShowType {
  1293. case 1:
  1294. sql += ` AND b.CLOSE is not null `
  1295. case 2:
  1296. sql += ` AND b.CLOSE is null `
  1297. }
  1298. sql += ` GROUP BY a.TRADE_CODE `
  1299. sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk ) COLLATE gbk_chinese_ci ASC `
  1300. //_, err = o.Raw(sql, pars).QueryRows(&items)
  1301. err = global.DmSQL["edb"].Raw(sql, pars).Find(&items).Error
  1302. return
  1303. }
  1304. // GetLzItemList 模糊查询隆众数据库指标列表
  1305. func GetLzItemList(keyword string) (items []*data_manage.LongzhongSurveyProduct, err error) {
  1306. //o := orm.NewOrmUsingDB("edb")
  1307. sql := "SELECT * FROM longzhong_survey_product WHERE CONCAT(sample_name,breed_name,custom,quota_name,lz_code) LIKE ?"
  1308. //_, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
  1309. err = global.DmSQL["edb"].Raw(sql, utils.GetLikeKeyword(keyword)).Find(&items).Error
  1310. return
  1311. }
  1312. type lzSurveyData struct {
  1313. DataTime string `gorm:"column:data_time"` //`orm:"column(data_time)" description:"日期"`
  1314. InputValue string `gorm:"column:input_value"` //`orm:"column(input_value)" description:"值"`
  1315. }
  1316. // GetLzItemListByCode 根据code查询隆众数据列表
  1317. func GetLzItemListByCode(lzCode string) (items []*lzSurveyData, err error) {
  1318. //o := orm.NewOrmUsingDB("edb")
  1319. sql := "SELECT * FROM longzhong_survey_data WHERE survey_product_id=? GROUP BY data_time DESC"
  1320. //_, err = o.Raw(sql, lzCode).QueryRows(&items)
  1321. err = global.DmSQL["edb"].Raw(sql, lzCode).Find(&items).Error
  1322. return
  1323. }
  1324. // GetEdbDataListByCodes 通过指标ID获取所有数据
  1325. func GetEdbDataListByCodes(tradeCode string) (items []*Edbdata, err error) {
  1326. sql := ` SELECT TRADE_CODE,DT,round(CLOSE,4) CLOSE,modify_time FROM edbdata WHERE TRADE_CODE IN(` + tradeCode + `) GROUP BY TRADE_CODE,DT ORDER BY DT DESC `
  1327. //o := orm.NewOrmUsingDB("edb")
  1328. //_, err = o.Raw(sql).QueryRows(&items)
  1329. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1330. return
  1331. }
  1332. // TargetItemListResp 指标数据结构体
  1333. type TargetItemListResp struct {
  1334. List []*EdbInfoItem
  1335. FrequencyList []string
  1336. }
  1337. // BatchDataDeleteReq 批量删除某日的指标数据请求结构体
  1338. type BatchDataDeleteReq struct {
  1339. CreateDate string `description:"创建日期"`
  1340. TradeCodeList []string `description:"指标唯一编码列表"`
  1341. }
  1342. // BatchDeleteEdbDataByDate 批量删除某日的指标数据
  1343. func BatchDeleteEdbDataByDate(tradeCodes, dt string, opUserId int) (err error) {
  1344. //o := orm.NewOrmUsingDB("edb")
  1345. var list []*Edbdata
  1346. sql := ` select * FROM edbdata WHERE TRADE_CODE in (` + tradeCodes + `) AND DT = ? `
  1347. //_, err = o.Raw(sql, dt).QueryRows(&list)
  1348. err = global.DmSQL["edb"].Raw(sql, dt).Find(&list).Error
  1349. if err != nil {
  1350. return
  1351. }
  1352. deleteRecordList := make([]*EdbdataDeleteRecord, 0)
  1353. for _, edbDataInfo := range list {
  1354. deleteRecord := &EdbdataDeleteRecord{
  1355. TradeCode: edbDataInfo.TradeCode,
  1356. Dt: edbDataInfo.Dt,
  1357. Close: edbDataInfo.Close,
  1358. ModifyTime: time.Now(),
  1359. CreateTime: time.Now(),
  1360. SysUserId: opUserId,
  1361. }
  1362. deleteRecordList = append(deleteRecordList, deleteRecord)
  1363. }
  1364. if len(deleteRecordList) > 0 {
  1365. //_, tmpErr := o.InsertMulti(len(deleteRecordList), deleteRecordList)
  1366. tmpErr := global.DmSQL["edb"].CreateInBatches(deleteRecordList, utils.MultiAddNum).Error
  1367. if tmpErr != nil {
  1368. err = tmpErr
  1369. return
  1370. }
  1371. }
  1372. sql = ` DELETE FROM edbdata WHERE TRADE_CODE in (` + tradeCodes + `) AND DT = ? `
  1373. //_, err = o.Raw(sql, dt).Exec()
  1374. err = global.DmSQL["edb"].Exec(sql, dt).Error
  1375. return
  1376. }
  1377. // BatchDeleteEdbData 批量删除指标数据
  1378. func BatchDeleteEdbData(tradeCode string, opUserId int) (err error) {
  1379. //o := orm.NewOrmUsingDB("edb")
  1380. var list []*Edbdata
  1381. sql := ` select * FROM edbdata WHERE TRADE_CODE = ? `
  1382. //_, err = o.Raw(sql, tradeCode).QueryRows(&list)
  1383. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&list).Error
  1384. if err != nil {
  1385. return
  1386. }
  1387. deleteRecordList := make([]*EdbdataDeleteRecord, 0)
  1388. for _, edbDataInfo := range list {
  1389. deleteRecord := &EdbdataDeleteRecord{
  1390. TradeCode: edbDataInfo.TradeCode,
  1391. Dt: edbDataInfo.Dt,
  1392. Close: edbDataInfo.Close,
  1393. ModifyTime: time.Now(),
  1394. CreateTime: time.Now(),
  1395. SysUserId: opUserId,
  1396. }
  1397. deleteRecordList = append(deleteRecordList, deleteRecord)
  1398. }
  1399. //_, err = o.InsertMulti(len(deleteRecordList), deleteRecordList)
  1400. err = global.DmSQL["edb"].CreateInBatches(deleteRecordList, utils.MultiAddNum).Error
  1401. if err != nil {
  1402. return
  1403. }
  1404. sql = ` DELETE FROM edbdata WHERE TRADE_CODE = ? `
  1405. //_, err = o.Raw(sql, tradeCode).Exec()
  1406. err = global.DmSQL["edb"].Exec(sql, tradeCode).Error
  1407. return
  1408. }
  1409. // GetEdbInfoCountByClassifyId 根据指标分类id获取当前分类下的指标数量
  1410. func GetEdbInfoCountByClassifyId(classifyId int) (count int, err error) {
  1411. //o := orm.NewOrmUsingDB("edb")
  1412. sql := `SELECT COUNT(1) AS count FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a
  1413. INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
  1414. WHERE a.classify_id=? group by a.TRADE_CODE) d `
  1415. //err = o.Raw(sql, classifyId).QueryRow(&count)
  1416. err = global.DmSQL["edb"].Raw(sql, classifyId).Scan(&count).Error
  1417. return
  1418. }
  1419. // EdbInfoGroupCount 指标分类id获取当前分类下的指标数量
  1420. type EdbInfoGroupCount struct {
  1421. Count int `gorm:"column:count"`
  1422. ClassifyId int `gorm:"column:classify_id"`
  1423. }
  1424. // GetEdbInfoGroupCountByClassifyIds 根据指标分类id获取当前分类下的指标数量
  1425. func GetEdbInfoGroupCountByClassifyIds(classifyIds string) (list []*EdbInfoGroupCount, err error) {
  1426. //o := orm.NewOrmUsingDB("edb")
  1427. sql := `SELECT COUNT(1) AS count,classify_id FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a
  1428. INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
  1429. WHERE a.classify_id in (` + classifyIds + `) group by a.TRADE_CODE) d
  1430. GROUP BY classify_id `
  1431. //_, err = o.Raw(sql).QueryRows(&list)
  1432. err = global.DmSQL["edb"].Raw(sql).Find(&list).Error
  1433. return
  1434. }
  1435. // GetExcelData 获取excel样式数据
  1436. func GetExcelData() (list []*data_manage.ExcelStyle, err error) {
  1437. //o := orm.NewOrmUsingDB("edb")
  1438. sql := `SELECT * FROM excel_style `
  1439. //_, err = o.Raw(sql).QueryRows(&list)
  1440. err = global.DmSQL["edb"].Raw(sql).Find(&list).Error
  1441. return
  1442. }
  1443. // AddExcelData 添加excel样式数据
  1444. func AddExcelData(item *data_manage.ExcelStyle) (id int64, err error) {
  1445. //o := orm.NewOrmUsingDB("edb")
  1446. //id, err = o.Insert(item)
  1447. err = global.DmSQL["edb"].Create(item).Error
  1448. return
  1449. }
  1450. type EdbdataFloat struct {
  1451. TradeCode string `gorm:"column:TRADE_CODE"` //`orm:"column(TRADE_CODE);pk" description:"指标编码"`
  1452. Dt string `gorm:"column:DT"` //`orm:"column(DT)" description:"日期"`
  1453. Close float64 `gorm:"column:CLOSE"` //`orm:"column(CLOSE)" description:"值"`
  1454. ModifyTime time.Time `gorm:"column:modify_time"` //`orm:"column(modify_time)" description:"修改时间"`
  1455. }
  1456. func GetTargetsDataFloat(tradeCode, dt string) (item *EdbdataFloat, err error) {
  1457. sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  1458. //o := orm.NewOrmUsingDB("edb")
  1459. //err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
  1460. err = global.DmSQL["edb"].Raw(sql, tradeCode, dt).First(&item).Error
  1461. return
  1462. }
  1463. func ModifyEdbinfo(tradeCode, unit, frequency string, classifyId int) (err error) {
  1464. sql := `UPDATE edbinfo SET UNIT = ?,frequency=?, classify_id=?, create_date=NOW() WHERE TRADE_CODE=? `
  1465. //o := orm.NewOrmUsingDB("edb")
  1466. //_, err = o.Raw(sql, unit, frequency, classifyId, tradeCode).Exec()
  1467. err = global.DmSQL["edb"].Exec(sql, unit, frequency, classifyId, tradeCode).Error
  1468. return
  1469. }
  1470. func DeleteTargetsDataByImport(tradeCode, dt string) (err error) {
  1471. sql := `DELETE FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  1472. //o := orm.NewOrmUsingDB("edb")
  1473. //_, err = o.Raw(sql, tradeCode, dt).Exec()
  1474. err = global.DmSQL["edb"].Exec(sql, tradeCode, dt).Error
  1475. return
  1476. }
  1477. // GetEdbinfoListByCodeListGroupByUserId 根据指标code列表、用户分组获取指标信息
  1478. func GetEdbinfoListByCodeListGroupByUserId(edbCodeList []string) (items []*Edbinfo, err error) {
  1479. num := len(edbCodeList)
  1480. if num <= 0 {
  1481. return
  1482. }
  1483. //o := orm.NewOrmUsingDB("edb")
  1484. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) GROUP BY user_id `
  1485. //_, err = o.Raw(sql, edbCodeList).QueryRows(&items)
  1486. err = global.DmSQL["edb"].Raw(sql, edbCodeList).Find(&items).Error
  1487. return
  1488. }
  1489. // GetEdbinfoListByCodeListByCodeIdList
  1490. // @Description: 根据指标code列表获取列表信息
  1491. // @param edbCodeList
  1492. // @return items
  1493. // @return err
  1494. func GetEdbinfoListByCodeListByCodeIdList(edbCodeList []string) (items []*Edbinfo, err error) {
  1495. num := len(edbCodeList)
  1496. if num <= 0 {
  1497. return
  1498. }
  1499. //o := orm.NewOrmUsingDB("edb")
  1500. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  1501. //_, err = o.Raw(sql, edbCodeList).QueryRows(&items)
  1502. err = global.DmSQL["edb"].Raw(sql, edbCodeList).Find(&items).Error
  1503. return
  1504. }
  1505. // GetEdbinfoListByCodeListByUserId
  1506. // @Description: 根据用户id列表获取指标列表信息
  1507. // @param userIdList
  1508. // @return items
  1509. // @return err
  1510. func GetEdbinfoListByCodeListByUserId(userIdList []int) (items []*Edbinfo, err error) {
  1511. num := len(userIdList)
  1512. if num <= 0 {
  1513. return
  1514. }
  1515. //o := orm.NewOrmUsingDB("edb")
  1516. sql := `SELECT * FROM edbinfo WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
  1517. //_, err = o.Raw(sql, userIdList).QueryRows(&items)
  1518. err = global.DmSQL["edb"].Raw(sql, userIdList).Find(&items).Error
  1519. return
  1520. }
  1521. // ModifyEdbinfoUserIdByCodeList 根据指标code列表修改创建人
  1522. func ModifyEdbinfoUserIdByCodeList(edbCodeList []string, userId int, userName string) (err error) {
  1523. num := len(edbCodeList)
  1524. if num <= 0 {
  1525. return
  1526. }
  1527. //o := orm.NewOrmUsingDB("edb")
  1528. sql := `UPDATE edbinfo SET user_id = ?,user_name = ? WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  1529. //_, err = o.Raw(sql, userId, userName, edbCodeList).Exec()
  1530. err = global.DmSQL["edb"].Exec(sql, userId, userName, edbCodeList).Error
  1531. return
  1532. }
  1533. // ModifyEdbinfoUserIdByOldUserId
  1534. // @Description: 根据旧用户id修改新用户id
  1535. // @author: Roc
  1536. // @datetime 2024-03-25 17:59:32
  1537. // @param oldUserId int
  1538. // @param userId int
  1539. // @return err error
  1540. func ModifyEdbinfoUserIdByOldUserId(oldUserIdList []int, userId int) (err error) {
  1541. num := len(oldUserIdList)
  1542. if num <= 0 {
  1543. return
  1544. }
  1545. //o := orm.NewOrmUsingDB("edb")
  1546. sql := `UPDATE edbinfo SET user_id=? WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
  1547. //_, err = o.Raw(sql, userId, oldUserIdList).Exec()
  1548. err = global.DmSQL["edb"].Exec(sql, userId, oldUserIdList).Error
  1549. return
  1550. }
  1551. func GetEdbInfoAdminList() (list []int, err error) {
  1552. sql := `SELECT user_id FROM edbinfo GROUP BY user_id `
  1553. //o := orm.NewOrmUsingDB("edb")
  1554. //_, err = o.Raw(sql).QueryRows(&list)
  1555. err = global.DmSQL["edb"].Raw(sql).Find(&list).Error
  1556. return
  1557. }
  1558. // GetAllChildManualEdbClassify
  1559. // @Description: 获取手工数据中所有的子分类
  1560. // @author: Roc
  1561. // @datetime 2024-07-16 13:27:28
  1562. // @return items []*EdbdataClassify
  1563. // @return err error
  1564. func GetAllChildManualEdbClassify() (items []*EdbdataClassify, err error) {
  1565. //o := orm.NewOrmUsingDB("edb")
  1566. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id > 0 `
  1567. //_, err = o.Raw(sql).QueryRows(&items)
  1568. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1569. return
  1570. }
  1571. // GetChildManualEdbClassifyByIdList
  1572. // @Description: 获取手工数据中所有的子分类
  1573. // @author: Roc
  1574. // @datetime 2024-07-16 13:33:57
  1575. // @param idList []int
  1576. // @return items []*EdbdataClassify
  1577. // @return err error
  1578. func GetChildManualEdbClassifyByIdList(idList []int) (items []*EdbdataClassify, err error) {
  1579. num := len(idList)
  1580. if num <= 0 {
  1581. return
  1582. }
  1583. //o := orm.NewOrmUsingDB("edb")
  1584. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id in (` + utils.GetOrmInReplace(num) + `) `
  1585. //_, err = o.Raw(sql, idList).QueryRows(&items)
  1586. err = global.DmSQL["edb"].Raw(sql, idList).Find(&items).Error
  1587. return
  1588. }
  1589. // EdbinfoMaxMinDate
  1590. // @Description: 手工指标的最小最大日期
  1591. type EdbinfoMaxMinDate struct {
  1592. MinDate string `gorm:"column:min_date"`
  1593. MaxDate string `gorm:"column:max_date"`
  1594. }
  1595. // GetEdbdataMaxMinDate
  1596. // @Description: 获取手工指标的最小最大日期
  1597. // @author: Roc
  1598. // @datetime 2024-08-01 14:27:20
  1599. // @param tradeCode string
  1600. // @return item EdbinfoMaxMinDate
  1601. // @return err error
  1602. func GetEdbdataMaxMinDate(tradeCode string) (item EdbinfoMaxMinDate, err error) {
  1603. //o := orm.NewOrmUsingDB("edb")
  1604. sql := ` SELECT MIN(DT) min_date,MAX(DT) max_date FROM edbdata WHERE TRADE_CODE = ? `
  1605. //err = o.Raw(sql, tradeCode).QueryRow(&item)
  1606. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&item).Error
  1607. return
  1608. }
  1609. // GetEdbdataLatestValue
  1610. // @Description: 获取手工数据的最新值
  1611. // @author: Roc
  1612. // @datetime 2024-08-02 10:33:22
  1613. // @param tradeCode string
  1614. // @return latestValue float64
  1615. // @return err error
  1616. func GetEdbdataLatestValue(tradeCode string) (latestValue float64, err error) {
  1617. //o := orm.NewOrmUsingDB("edb")
  1618. sql := ` SELECT CLOSE FROM edbdata WHERE TRADE_CODE = ? ORDER BY DT DESC LIMIT 1`
  1619. //err = o.Raw(sql, tradeCode).QueryRow(&latestValue)
  1620. err = global.DmSQL["edb"].Raw(sql, tradeCode).Scan(&latestValue).Error
  1621. return
  1622. }
  1623. // ModifyEdbinfoMaxMinDate
  1624. // @Description: 修改手工指标的最小最大日期
  1625. // @author: Roc
  1626. // @datetime 2024-08-01 15:33:45
  1627. // @param startDate string
  1628. // @param endDate string
  1629. // @param tradeCode string
  1630. // @return err error
  1631. func ModifyEdbinfoMaxMinDate(tradeCode, startDate, endDate string, latestValue float64) (err error) {
  1632. //o := orm.NewOrmUsingDB("edb")
  1633. sql := ` UPDATE edbinfo SET start_date = ?, end_date = ?, latest_value = ? , modify_time = now() WHERE TRADE_CODE = ? `
  1634. //_, err = o.Raw(sql, startDate, endDate, latestValue, tradeCode).Exec()
  1635. err = global.DmSQL["edb"].Exec(sql, startDate, endDate, latestValue, tradeCode).Error
  1636. return
  1637. }