target.go 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794
  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" gorm:"primaryKey" 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" gorm:"primaryKey" `
  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" gorm:"primaryKey" 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" gorm:"primaryKey" 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" gorm:"primaryKey" `
  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. defer func() {
  599. if err != nil {
  600. _ = to.Rollback()
  601. } else {
  602. _ = to.Commit()
  603. }
  604. }()
  605. recordSql := ` INSERT INTO edbdata_delete_record(TRADE_CODE,DT,CLOSE,modify_time,create_time,sys_user_id)
  606. VALUES(?,?,?,?,?,?)`
  607. //_, err = to.Raw(recordSql, tradeCode, createDate, close, modifyTime, time.Now(), sysUserId).Exec()
  608. err = to.Exec(recordSql, tradeCode, createDate, close, modifyTime, time.Now(), sysUserId).Error
  609. sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
  610. //_, err = to.Raw(sql, tradeCode, createDate).Exec()
  611. err = to.Exec(sql, tradeCode, createDate).Error
  612. return
  613. }
  614. func GetTargetInfoCount(tradeCode string) (count int, err error) {
  615. sql := ` SELECT COUNT(1) AS count FROM edbdata AS c
  616. INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  617. WHERE a.TRADE_CODE=? `
  618. //o := orm.NewOrmUsingDB("edb")
  619. //err = o.Raw(sql, tradeCode).QueryRow(&count)
  620. err = global.DmSQL["edb"].Raw(sql, tradeCode).Scan(&count).Error
  621. return
  622. }
  623. type TargetDeleteReq struct {
  624. TradeCode string `description:"指标唯一编码"`
  625. }
  626. func TargetDelete(tradeCode string) (err error) {
  627. //o := orm.NewOrmUsingDB("edb")
  628. //to, err := o.Begin()
  629. to := global.DmSQL["edb"].Begin()
  630. defer func() {
  631. if err != nil {
  632. _ = to.Rollback()
  633. } else {
  634. _ = to.Commit()
  635. }
  636. }()
  637. sql := " DELETE FROM edbinfo WHERE TRADE_CODE = ? "
  638. //_, err = to.Raw(sql, tradeCode).Exec()
  639. err = to.Exec(sql, tradeCode).Error
  640. sql = " DELETE FROM edbdata WHERE TRADE_CODE = ? "
  641. //_, err = to.Raw(sql, tradeCode).Exec()
  642. err = to.Exec(sql, tradeCode).Error
  643. return
  644. }
  645. type Researcher struct {
  646. AdminId int `gorm:"column:admin_id"` //`description:"系统用户id"`
  647. AdminName string `gorm:"column:admin_name"` //`description:"系统用户名称"`
  648. RealName string `gorm:"column:real_name"` //`description:"系统用户姓名"`
  649. Role string `gorm:"column:role"` //`description:"系统用户角色"`
  650. Mobile string `gorm:"column:mobile"` //`description:"手机号"`
  651. TargetCount int `gorm:"column:target_count"` //`description:"指标数量"`
  652. }
  653. type ResearcherListResp struct {
  654. List []*Researcher
  655. }
  656. func GetResearcherEntry() (items []*Researcher, err error) {
  657. sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role_type=1 `
  658. //o := orm.NewOrm()
  659. //_, err = o.Raw(sql).QueryRows(&items)
  660. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  661. researchLen := len(items)
  662. //edbO := orm.NewOrmUsingDB("edb")
  663. for i := 0; i < researchLen; i++ {
  664. var count int
  665. mobile := items[i].Mobile
  666. sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM edbinfo_user AS a
  667. INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
  668. WHERE a.mobile=? AND b.classify_id>0 `
  669. //err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
  670. err = global.DmSQL["edb"].Raw(sqlCount, mobile).Scan(&count).Error
  671. items[i].TargetCount = count
  672. }
  673. return
  674. }
  675. func GetResearcherEntryByMobile(mobile string) (items []*Researcher, err error) {
  676. sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role_type=1 `
  677. if mobile != "" {
  678. sql += ` AND mobile IN(` + mobile + `)`
  679. }
  680. //o := orm.NewOrm()
  681. //_, err = o.Raw(sql).QueryRows(&items)
  682. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  683. researchLen := len(items)
  684. //edbO := orm.NewOrmUsingDB("edb")
  685. for i := 0; i < researchLen; i++ {
  686. var count int
  687. mobile := items[i].Mobile
  688. sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM edbinfo_user AS a
  689. INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
  690. WHERE a.mobile=? AND b.classify_id>0 `
  691. //err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
  692. err = global.DmSQL["edb"].Raw(sqlCount, mobile).Scan(&count).Error
  693. items[i].TargetCount = count
  694. }
  695. return
  696. }
  697. type EdbinfoItems struct {
  698. TradeCode string `gorm:"column:TRADE_CODE"` //`orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标code"`
  699. SecName string `gorm:"column:SEC_NAME"` //`orm:"column(SEC_NAME);" description:"指标名称"`
  700. Unit string `gorm:"column:UNIT"` //`orm:"column(UNIT);" description:"单位"`
  701. Remark string `gorm:"column:REMARK"` //`orm:"column(REMARK);" description:"备注"`
  702. Frequency string `gorm:"column:frequency"` //`description:"频度"`
  703. ClassifyId int `gorm:"column:classify_id"` //`description:"分类id"`
  704. ClassifyName string `gorm:"column:classify_name"` //`description:"分类名称"`
  705. CreateDate string `gorm:"column:create_date"` //`description:"创建时间"`
  706. UserId int `gorm:"column:user_id"` //`description:"录入用户id"`
  707. NoticeTime string `gorm:"column:notice_time"` //`description:"通知时间"`
  708. Mobile string `gorm:"column:mobile"` //`description:"录入者手机号"`
  709. ModifyDate string `gorm:"column:modify_date"` //`description:"待更新日期"`
  710. Status string `gorm:"column:status"` // `description:"状态:未完成/完成"`
  711. }
  712. type TargetItemsResp struct {
  713. List SortEdbInfo
  714. }
  715. type SortEdbInfo []EdbinfoItems
  716. func GetTargetItems(mobile string, classifyId int) (lastItems SortEdbInfo, err error) {
  717. var items []*EdbinfoItems
  718. //o := orm.NewOrmUsingDB("edb")
  719. //sql := ` SELECT *,'' modify_date,'' status FROM edbinfo AS a WHERE a.classify_id>0 `
  720. sql := ` SELECT *,'' modify_date,'' STATUS FROM edbinfo AS a
  721. WHERE a.classify_id>0
  722. `
  723. if classifyId > 0 {
  724. sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ``
  725. }
  726. sql += ` GROUP BY a.TRADE_CODE `
  727. //if classifyId > 0 {
  728. // sql = ` SELECT *,'' modify_date,'' status FROM edbinfo AS a
  729. // WHERE a.classify_id=` + strconv.Itoa(classifyId) + ` AND a.classify_id>0
  730. // GROUP BY a.TRADE_CODE `
  731. //}
  732. sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk ) COLLATE gbk_chinese_ci ASC `
  733. //_, err = o.Raw(sql).QueryRows(&items)
  734. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  735. if err != nil {
  736. return
  737. }
  738. itemsLen := len(items)
  739. nowWeek := time.Now().Weekday().String()
  740. fmt.Println(nowWeek)
  741. finishEdbInfo := SortEdbInfo{}
  742. unFinishEdbInfo := SortEdbInfo{}
  743. for i := 0; i < itemsLen; i++ {
  744. noticeTime := items[i].NoticeTime
  745. frequency := items[i].Frequency
  746. tradeCode := items[i].TradeCode
  747. if noticeTime != "" {
  748. if frequency == "周度" {
  749. noticeArr := strings.Split(noticeTime, " ")
  750. noticeWeek := noticeArr[0]
  751. fmt.Println(noticeWeek)
  752. addDay := 0
  753. if nowWeek == "Sunday" {
  754. if noticeWeek == "周日" {
  755. addDay = 0
  756. } else if noticeWeek == "周一" {
  757. addDay = 1
  758. } else if noticeWeek == "周二" {
  759. addDay = 2
  760. } else if noticeWeek == "周三" {
  761. addDay = 3
  762. } else if noticeWeek == "周四" {
  763. addDay = 4
  764. } else if noticeWeek == "周五" {
  765. addDay = 5
  766. } else if noticeWeek == "周六" {
  767. addDay = 6
  768. } else {
  769. addDay = 0
  770. }
  771. } else if nowWeek == "Monday" {
  772. if noticeWeek == "周日" {
  773. addDay = 6
  774. } else if noticeWeek == "周一" {
  775. addDay = 0
  776. } else if noticeWeek == "周二" {
  777. addDay = 1
  778. } else if noticeWeek == "周三" {
  779. addDay = 2
  780. } else if noticeWeek == "周四" {
  781. addDay = 3
  782. } else if noticeWeek == "周五" {
  783. addDay = 4
  784. } else if noticeWeek == "周六" {
  785. addDay = 5
  786. } else {
  787. addDay = 0
  788. }
  789. } else if nowWeek == "Tuesday" {
  790. if noticeWeek == "周日" {
  791. addDay = 5
  792. } else if noticeWeek == "周一" {
  793. addDay = 6
  794. } else if noticeWeek == "周二" {
  795. addDay = 0
  796. } else if noticeWeek == "周三" {
  797. addDay = 1
  798. } else if noticeWeek == "周四" {
  799. addDay = 2
  800. } else if noticeWeek == "周五" {
  801. addDay = 3
  802. } else if noticeWeek == "周六" {
  803. addDay = 4
  804. } else {
  805. addDay = 0
  806. }
  807. } else if nowWeek == "Wednesday" {
  808. if noticeWeek == "周日" {
  809. addDay = 4
  810. } else if noticeWeek == "周一" {
  811. addDay = 5
  812. } else if noticeWeek == "周二" {
  813. addDay = 6
  814. } else if noticeWeek == "周三" {
  815. addDay = 0
  816. } else if noticeWeek == "周四" {
  817. addDay = 1
  818. } else if noticeWeek == "周五" {
  819. addDay = 2
  820. } else if noticeWeek == "周六" {
  821. addDay = 3
  822. } else {
  823. addDay = 0
  824. }
  825. } else if nowWeek == "Thursday" {
  826. if noticeWeek == "周日" {
  827. addDay = 3
  828. } else if noticeWeek == "周一" {
  829. addDay = 4
  830. } else if noticeWeek == "周二" {
  831. addDay = 5
  832. } else if noticeWeek == "周三" {
  833. addDay = 6
  834. } else if noticeWeek == "周四" {
  835. addDay = 0
  836. } else if noticeWeek == "周五" {
  837. addDay = 1
  838. } else if noticeWeek == "周六" {
  839. addDay = 2
  840. } else {
  841. addDay = 0
  842. }
  843. } else if nowWeek == "Friday" {
  844. if noticeWeek == "周日" {
  845. addDay = 2
  846. } else if noticeWeek == "周一" {
  847. addDay = 3
  848. } else if noticeWeek == "周二" {
  849. addDay = 4
  850. } else if noticeWeek == "周三" {
  851. addDay = 5
  852. } else if noticeWeek == "周四" {
  853. addDay = 6
  854. } else if noticeWeek == "周五" {
  855. addDay = 0
  856. } else if noticeWeek == "周六" {
  857. addDay = 1
  858. } else {
  859. addDay = 0
  860. }
  861. } else if nowWeek == "Saturday" {
  862. if noticeWeek == "周日" {
  863. addDay = 1
  864. } else if noticeWeek == "周一" {
  865. addDay = 2
  866. } else if noticeWeek == "周二" {
  867. addDay = 3
  868. } else if noticeWeek == "周三" {
  869. addDay = 4
  870. } else if noticeWeek == "周四" {
  871. addDay = 5
  872. } else if noticeWeek == "周五" {
  873. addDay = 6
  874. } else if noticeWeek == "周六" {
  875. addDay = 0
  876. } else {
  877. addDay = 0
  878. }
  879. }
  880. modifyDate := time.Now().AddDate(0, 0, addDay)
  881. modifyDateStr := modifyDate.Format(utils.FormatDate)
  882. items[i].ModifyDate = modifyDateStr
  883. modifyDateEndStr := modifyDate.AddDate(0, 0, -7).Format(utils.FormatDate)
  884. fmt.Println("addDay:", addDay)
  885. fmt.Println("modifyDateEndStr:", modifyDateEndStr)
  886. count := 0
  887. sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
  888. //err = o.Raw(sqlCount, tradeCode, modifyDateEndStr, modifyDateStr).QueryRow(&count)
  889. err = global.DmSQL["edb"].Raw(sqlCount, tradeCode, modifyDateEndStr, modifyDateStr).Scan(&count).Error
  890. if err != nil {
  891. return nil, err
  892. }
  893. if count > 0 {
  894. items[i].Status = "完成"
  895. finishEdbInfo = append(finishEdbInfo, *items[i])
  896. } else {
  897. items[i].Status = "未完成"
  898. unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
  899. }
  900. } else if frequency == "日度" {
  901. items[i].Status = "完成"
  902. finishEdbInfo = append(finishEdbInfo, *items[i])
  903. } else if frequency == "月度" {
  904. myYear := time.Now().Year()
  905. myMonth := time.Now().Format("01")
  906. startDate, endDate := utils.GetMonthStartAndEnd(strconv.Itoa(myYear), myMonth)
  907. count := 0
  908. sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
  909. //err = o.Raw(sqlCount, tradeCode, startDate, endDate).QueryRow(&count)
  910. err = global.DmSQL["edb"].Raw(sqlCount, tradeCode, startDate, endDate).Scan(&count).Error
  911. if err != nil {
  912. return nil, err
  913. }
  914. if noticeTime != "" {
  915. var modifyDateStr string
  916. strArr := strings.Split(noticeTime, "日")
  917. myYear := time.Now().Year()
  918. myMonth := time.Now().Format("01")
  919. modifyDateStr = strconv.Itoa(myYear) + "-" + myMonth + "-" + strArr[0]
  920. items[i].ModifyDate = modifyDateStr
  921. }
  922. if count > 0 {
  923. items[i].Status = "完成"
  924. finishEdbInfo = append(finishEdbInfo, *items[i])
  925. } else {
  926. items[i].Status = "未完成"
  927. unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
  928. }
  929. } else {
  930. items[i].Status = "完成"
  931. finishEdbInfo = append(finishEdbInfo, *items[i])
  932. }
  933. } else {
  934. if frequency == "月度" {
  935. myYear := time.Now().Year()
  936. myMonth := time.Now().Format("01")
  937. startDate, endDate := utils.GetMonthStartAndEnd(strconv.Itoa(myYear), myMonth)
  938. count := 0
  939. sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
  940. //err = o.Raw(sqlCount, tradeCode, startDate, endDate).QueryRow(&count)
  941. err = global.DmSQL["edb"].Raw(sqlCount, tradeCode, startDate, endDate).Scan(&count).Error
  942. if err != nil {
  943. return nil, err
  944. }
  945. if count > 0 {
  946. items[i].Status = "完成"
  947. finishEdbInfo = append(finishEdbInfo, *items[i])
  948. } else {
  949. items[i].Status = "未完成"
  950. unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
  951. }
  952. } else {
  953. items[i].Status = "完成"
  954. finishEdbInfo = append(finishEdbInfo, *items[i])
  955. }
  956. }
  957. }
  958. sort.Sort(SortByModifyDate{finishEdbInfo})
  959. sort.Sort(SortByModifyDate{unFinishEdbInfo})
  960. lastItems = append(lastItems, unFinishEdbInfo...)
  961. lastItems = append(lastItems, finishEdbInfo...)
  962. return
  963. }
  964. // 获取此 slice 的长度
  965. func (p SortEdbInfo) Len() int { return len(p) }
  966. // 根据元素的状态降序排序
  967. func (p SortEdbInfo) Less(i, j int) bool {
  968. return p[i].Status > p[j].Status
  969. }
  970. // 交换数据
  971. func (p SortEdbInfo) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
  972. // 嵌套结构体 将继承 SortEdbInfo 的所有属性和方法
  973. // 所以相当于SortByName 也实现了 Len() 和 Swap() 方法
  974. type SortByStatus struct{ SortEdbInfo }
  975. // 根据元素的姓名长度降序排序 (此处按照自己的业务逻辑写)
  976. func (p SortByStatus) Less(i, j int) bool {
  977. return len(p.SortEdbInfo[i].Status) > len(p.SortEdbInfo[j].Status)
  978. }
  979. type SortByModifyDate struct{ SortEdbInfo }
  980. // 根据元素的年龄降序排序 (此处按照自己的业务逻辑写)
  981. func (p SortByModifyDate) Less(i, j int) bool {
  982. return p.SortEdbInfo[i].ModifyDate > p.SortEdbInfo[j].ModifyDate
  983. }
  984. type DataCheckResp struct {
  985. Status int `description:"状态:1:该日期已存在数据,是否确认修改?,0:数据不存在"`
  986. Close string `description:"值"`
  987. }
  988. type TargetCheckResp struct {
  989. Status int `description:"状态:1:该指标有关联数据,请先删除数据,0:指标不存在关联数据,可直接删除"`
  990. }
  991. type EdbdataExportList struct {
  992. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;not null" description:"指标code"`
  993. SecName string `gorm:"column:SEC_NAME" description:"指标名称"`
  994. Unit string `gorm:"column:UNIT" description:"单位"`
  995. Remark string `gorm:"column:REMARK" description:"备注"`
  996. Frequency string `gorm:"column:frequency" description:"频度"` //`description:"频度"`
  997. ClassifyId int `gorm:"column:classify_id" description:"分类id"` //`description:"分类id"`
  998. ClassifyName string `gorm:"column:classify_name" description:"分类名称"` //`description:"分类名称"`
  999. CreateDate string `gorm:"column:create_date" description:"创建时间"` //`description:"创建时间"`
  1000. Dt string `gorm:"column:DT" description:"最新一次录入时间"`
  1001. }
  1002. func GetEdbdataSecName(condition string, pars []interface{}) (items []*EdbdataExportList, err error) {
  1003. //sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt
  1004. // FROM edbdata AS c
  1005. // INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  1006. // INNER JOIN edbinfo_user AS d ON a.TRADE_CODE=d.TRADE_CODE
  1007. // LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  1008. // WHERE a.classify_id>0`
  1009. sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt,b.classify_name
  1010. FROM edbdata AS c
  1011. INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  1012. LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  1013. WHERE a.classify_id>0`
  1014. if condition != "" {
  1015. sql += condition
  1016. }
  1017. sql += " GROUP BY a.TRADE_CODE ORDER BY a.TRADE_CODE ASC "
  1018. //o := orm.NewOrmUsingDB("edb")
  1019. //_, err = o.Raw(sql, pars).QueryRows(&items)
  1020. err = global.DmSQL["edb"].Raw(sql, pars).Find(&items).Error
  1021. return
  1022. }
  1023. func GetEdbDataFrequency(classifyId int) (items []*string, err error) {
  1024. sql := `SELECT DISTINCT frequency FROM edbinfo where classify_id=? AND frequency IS NOT NULL ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
  1025. //o := orm.NewOrmUsingDB("edb")
  1026. //_, err = o.Raw(sql, classifyId).QueryRows(&items)
  1027. err = global.DmSQL["edb"].Raw(sql, classifyId).Find(&items).Error
  1028. return
  1029. }
  1030. // GetEdbDataFrequencyByClassifyIdList
  1031. // @Description: 根据分类列表获取所有的频度
  1032. // @author: Roc
  1033. // @datetime 2024-08-15 17:51:13
  1034. // @param classifyIdList []int
  1035. // @return items []*string
  1036. // @return err error
  1037. func GetEdbDataFrequencyByClassifyIdList(classifyIdList []int) (items []string, err error) {
  1038. num := len(classifyIdList)
  1039. if num <= 0 {
  1040. return
  1041. }
  1042. sql := `SELECT DISTINCT frequency FROM edbinfo where classify_id in (` + utils.GetOrmInReplace(num) + `) AND frequency IS NOT NULL ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
  1043. //o := orm.NewOrmUsingDB("edb")
  1044. //_, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  1045. err = global.DmSQL["edb"].Raw(sql, classifyIdList).Find(&items).Error
  1046. return
  1047. }
  1048. func GetEdbDataFrequencyByKeyord(keyword string) (items []string, err error) {
  1049. sql := `SELECT DISTINCT frequency FROM edbinfo where SEC_NAME=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
  1050. //o := orm.NewOrmUsingDB("edb")
  1051. //_, err = o.Raw(sql, keyword).QueryRows(&items)
  1052. err = global.DmSQL["edb"].Raw(sql, keyword).Find(&items).Error
  1053. return
  1054. }
  1055. type EdbdataList struct {
  1056. Dt string `gorm:"column:DT" description:"录入时间"` //`orm:"column(DT);" description:"录入时间"`
  1057. }
  1058. func GetEdbdataList(tradeCode string) (items []*EdbdataList, err error) {
  1059. sql := ` SELECT DT FROM edbdata WHERE TRADE_CODE IN(` + tradeCode + `) GROUP BY DT ORDER BY DT DESC `
  1060. //o := orm.NewOrmUsingDB("edb")
  1061. //_, err = o.Raw(sql).QueryRows(&items)
  1062. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1063. return
  1064. }
  1065. type EdbdataItem struct {
  1066. TradeCode string `gorm:"column:TRADE_CODE" description:"指标code"` //`orm:"column(TRADE_CODE);" description:"指标code"`
  1067. Dt string `gorm:"column:DT" description:"最新一次录入时间"` // `orm:"column(DT);" description:"最新一次录入时间"`
  1068. Close float64 `gorm:"column:CLOSE" description:"值"` //`orm:"column(CLOSE);" description:"值"`
  1069. }
  1070. func GetEdbdataValueByTradeCode(tradeCode, dt string) (item *EdbdataItem, err error) {
  1071. sql := ` SELECT TRADE_CODE,DT,CLOSE FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  1072. //o := orm.NewOrmUsingDB("edb")
  1073. //err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
  1074. err = global.DmSQL["edb"].Raw(sql, tradeCode, dt).First(&item).Error
  1075. return
  1076. }
  1077. func GetEdbdataAllByTradeCode(tradeCode string) (items []*EdbdataItem, err error) {
  1078. sql := ` SELECT * FROM edbdata WHERE TRADE_CODE=? `
  1079. //o := orm.NewOrmUsingDB("edb")
  1080. //_, err = o.Raw(sql, tradeCode).QueryRows(&items)
  1081. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&items).Error
  1082. return
  1083. }
  1084. func GetEdbdataClassifyByParentId(parentId int) (items []*EdbdataClassify, err error) {
  1085. sql := ` SELECT * FROM edbdata_classify WHERE parent_id=? `
  1086. //o := orm.NewOrmUsingDB("edb")
  1087. //_, err = o.Raw(sql, parentId).QueryRows(&items)
  1088. err = global.DmSQL["edb"].Raw(sql, parentId).Find(&items).Error
  1089. return
  1090. }
  1091. type LzPriceClassify struct {
  1092. ProductName string `gorm:"column:product_name" description:"产品名称"`
  1093. }
  1094. func GetLzPriceClassify() (items []*LzPriceClassify, err error) {
  1095. sql := ` SELECT product_name FROM longzhongpriceinfo GROUP BY product_name ORDER BY product_name DESC `
  1096. //o := orm.NewOrmUsingDB("edb")
  1097. //_, err = o.Raw(sql).QueryRows(&items)
  1098. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1099. return
  1100. }
  1101. type Longzhongpriceinfo struct {
  1102. LongzhongpriceinfoId int `gorm:"column:longzhongpriceinfo_id"` //`orm:"column(longzhongpriceinfo_id);pk" gorm:"primaryKey" `
  1103. Standard string `gorm:"column:standard"`
  1104. ModelName string `gorm:"column:model_name"`
  1105. Unit string `gorm:"column:unit"`
  1106. AreaName string `gorm:"column:area_name"`
  1107. PriceType string `gorm:"column:price_type"`
  1108. Memo string `gorm:"column:memo"`
  1109. PriceId string `gorm:"column:price_id"`
  1110. ProductName string `gorm:"column:product_name"`
  1111. InfoType string `gorm:"column:info_type"`
  1112. InfoTypeRemark string `gorm:"column:info_type_remark"`
  1113. MarketName string `gorm:"column:market_name"`
  1114. ManufactureName string `gorm:"column:manufacture_name"`
  1115. }
  1116. func GetLongzhongpriceinfoByClassifyName(productName string) (items []*Longzhongpriceinfo, err error) {
  1117. sql := `SELECT * FROM longzhongpriceinfo WHERE product_name=? ORDER BY longzhongpriceinfo_id ASC `
  1118. //o := orm.NewOrmUsingDB("edb")
  1119. //_, err = o.Raw(sql, productName).QueryRows(&items)
  1120. err = global.DmSQL["edb"].Raw(sql, productName).Find(&items).Error
  1121. return
  1122. }
  1123. func GetLongzhongPriceDataMaxCount(productName string) (count int, err error) {
  1124. //o := orm.NewOrmUsingDB("edb")
  1125. sql := `SELECT MAX(t.num) AS count FROM (
  1126. SELECT COUNT(1) AS num FROM longzhongpriceinfo AS a
  1127. INNER JOIN longzhongpricedata AS b ON a.longzhongpriceinfo_id=b.longzhongpriceinfo_id
  1128. WHERE a.product_name=?
  1129. GROUP BY a.product_name
  1130. )AS t `
  1131. //err = o.Raw(sql, productName).QueryRow(&count)
  1132. err = global.DmSQL["edb"].Raw(sql, productName).Scan(&count).Error
  1133. return
  1134. }
  1135. type LongzhongpricedataItems struct {
  1136. LongzhongpricedataId int `gorm:"column:longzhongpricedata_id"` //`orm:"column(longzhongpricedata_id);pk" gorm:"primaryKey" `
  1137. LongzhongpriceinfoId int `gorm:"column:longzhongpriceinfo_id"`
  1138. PriceDate string `gorm:"column:price_date"`
  1139. Memo string `gorm:"column:memo"`
  1140. Price float64 `gorm:"column:price"`
  1141. CnyPrice float64 `gorm:"column:cny_price"`
  1142. ZsyPrice float64 `gorm:"column:zsy_price"`
  1143. ZshPrice float64 `gorm:"column:zsh_price"`
  1144. LowPrice float64 `gorm:"column:low_price"`
  1145. HighPrice float64 `gorm:"column:high_price"`
  1146. RisePrice float64 `gorm:"column:rise_price"`
  1147. TonPrice float64 `gorm:"column:ton_price"`
  1148. PriceType string `gorm:"column:price_type"`
  1149. UpdateDate string `gorm:"column:update_date"`
  1150. }
  1151. func GetLongzhongPriceDataById(lzPriceInfoId int) (items []*LongzhongpricedataItems, err error) {
  1152. //o := orm.NewOrmUsingDB("edb")
  1153. 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
  1154. FROM longzhongpricedata AS a
  1155. WHERE longzhongpriceinfo_id=? ORDER BY price_date DESC `
  1156. //_, err = o.Raw(sql, lzPriceInfoId).QueryRows(&items)
  1157. err = global.DmSQL["edb"].Raw(sql, lzPriceInfoId).Find(&items).Error
  1158. return
  1159. }
  1160. func GetLzSurveyClassify() (items []*LzPriceClassify, err error) {
  1161. sql := ` SELECT breed_name AS product_name FROM longzhong_survey_product GROUP BY breed_name ORDER BY breed_name DESC `
  1162. //o := orm.NewOrmUsingDB("edb")
  1163. //_, err = o.Raw(sql).QueryRows(&items)
  1164. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1165. return
  1166. }
  1167. // LongzhongSurveyProduct 结构体
  1168. type LongzhongSurveyProduct struct {
  1169. SurveyProductId int `gorm:"column:survey_product_id;primaryKey;autoIncrement:false;not null" description:"调查产品ID"`
  1170. ProjectQuotaId int64 `gorm:"column:project_quota_id" description:"项目配额ID"`
  1171. BreedId string `gorm:"column:breed_id" description:"品种ID"`
  1172. BreedName string `gorm:"column:breed_name" description:"品种名称"`
  1173. QuotaId string `gorm:"column:quota_id" description:"配额ID"`
  1174. QuotaName string `gorm:"column:quota_name" description:"配额名称"`
  1175. UnitId string `gorm:"column:unit_id" description:"单位ID"`
  1176. UnitName string `gorm:"column:unit_name" description:"单位名称"`
  1177. SampleType int64 `gorm:"column:sample_type" description:"样本类型"`
  1178. SampleId string `gorm:"column:sample_id" description:"样本ID"`
  1179. SampleName string `gorm:"column:sample_name" description:"样本名称"`
  1180. DeviceId string `gorm:"column:device_id" description:"设备ID"`
  1181. Device string `gorm:"column:device" description:"设备名称"`
  1182. ProductCraftId string `gorm:"column:product_craft_id" description:"工艺ID"`
  1183. ProductCraft string `gorm:"column:product_craft" description:"工艺名称"`
  1184. ProductLine string `gorm:"column:product_line" description:"生产线"`
  1185. InputMode int64 `gorm:"column:input_mode" description:"输入模式"`
  1186. Frequency int64 `gorm:"column:frequency" description:"频率"`
  1187. InputValue string `gorm:"column:input_value" description:"输入值"`
  1188. TaskShouldFinishTime int `gorm:"column:task_should_finish_time" description:"任务应完成时间"`
  1189. CustomId string `gorm:"column:custom_id" description:"自定义ID"`
  1190. CustomType int64 `gorm:"column:custom_type" description:"自定义类型"`
  1191. Custom string `gorm:"column:custom" description:"自定义名称"`
  1192. QuotaSampleId int64 `gorm:"column:quota_sample_id" description:"配额样本ID"`
  1193. StartDate string `gorm:"column:start_date" description:"开始日期"`
  1194. EndDate string `gorm:"column:end_date" description:"结束日期"`
  1195. LzCode string `gorm:"column:lz_code" description:"龙种代码"`
  1196. }
  1197. func GetLongzhongSurveyProductByClassifyName(productName string) (items []*LongzhongSurveyProduct, err error) {
  1198. sql := `SELECT * FROM longzhong_survey_product WHERE breed_name=? ORDER BY survey_product_id ASC `
  1199. //o := orm.NewOrmUsingDB("edb")
  1200. //_, err = o.Raw(sql, productName).QueryRows(&items)
  1201. err = global.DmSQL["edb"].Raw(sql, productName).Find(&items).Error
  1202. return
  1203. }
  1204. func GetLzSurveyProductByNameAndFrequency(productName string, frequency int) (items []*LongzhongSurveyProduct, err error) {
  1205. sql := `SELECT * FROM longzhong_survey_product WHERE breed_name=? AND frequency=? ORDER BY survey_product_id ASC `
  1206. //o := orm.NewOrmUsingDB("edb")
  1207. //_, err = o.Raw(sql, productName, frequency).QueryRows(&items)
  1208. err = global.DmSQL["edb"].Raw(sql, productName, frequency).Find(&items).Error
  1209. return
  1210. }
  1211. func GetExportLzSurveyProductByBreedIds(breedIds []string) (items []*LongzhongSurveyProduct, err error) {
  1212. if len(breedIds) == 0 {
  1213. return
  1214. }
  1215. field := ` survey_product_id, breed_id, breed_name, sample_name, custom, quota_name, lz_code, frequency, unit_name, end_date, input_value `
  1216. 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 `
  1217. //o := orm.NewOrmUsingDB("edb")
  1218. //_, err = o.Raw(sql, breedIds).QueryRows(&items)
  1219. err = global.DmSQL["edb"].Raw(sql, breedIds).Find(&items).Error
  1220. return
  1221. }
  1222. func GetLzFrequency(productName string) (items []*int, err error) {
  1223. sql := `SELECT DISTINCT frequency FROM longzhong_survey_product WHERE breed_name=? ORDER BY frequency`
  1224. //o := orm.NewOrmUsingDB("edb")
  1225. //_, err = o.Raw(sql, productName).QueryRows(&items)
  1226. err = global.DmSQL["edb"].Raw(sql, productName).Find(&items).Error
  1227. return
  1228. }
  1229. // EdbInfoItem
  1230. type EdbInfoItem struct {
  1231. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;type:varchar(255)" orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标code"`
  1232. SecName string `gorm:"column:SEC_NAME;type:varchar(255)" orm:"column(SEC_NAME);" description:"指标名称"`
  1233. Unit string `gorm:"column:UNIT;type:varchar(255)" orm:"column(UNIT);" description:"单位"`
  1234. Remark string `gorm:"column:REMARK;type:varchar(255)" orm:"column(REMARK);" description:"备注"`
  1235. Frequency string `gorm:"column:FREQUENCY;type:varchar(255)" description:"频度"`
  1236. ClassifyId int `gorm:"column:CLASSIFY_ID;type:int" description:"分类id"`
  1237. ClassifyName string `gorm:"column:CLASSIFY_NAME;type:varchar(255)" description:"分类名称"`
  1238. CreateDate string `gorm:"column:CREATE_DATE;type:varchar(255)" description:"创建时间"`
  1239. UserId int `gorm:"column:USER_ID;type:int" description:"录入用户id"`
  1240. UserName string `gorm:"column:USER_NAME;type:varchar(255)" description:"录入用户名称"`
  1241. NoticeTime string `gorm:"column:NOTICE_TIME;type:varchar(255)" description:"通知时间"`
  1242. Mobile string `gorm:"column:MOBILE;type:varchar(255)" description:"录入者手机号"`
  1243. ModifyDate string `gorm:"column:MODIFY_DATE;type:varchar(255)" description:"待更新日期"`
  1244. ModifyTime string `gorm:"column:MODIFY_TIME;type:varchar(255)" description:"最近一次更新时间"`
  1245. Status string `gorm:"column:STATUS;type:varchar(255)" description:"状态:未完成/完成"`
  1246. IsJoinEdb int8 `gorm:"column:IS_JOIN_EDB;type:tinyint" description:"指标库是否已添加:0-否;1-是"`
  1247. StartDate string `gorm:"column:START_DATE;type:varchar(255)" description:"数据开始日期"`
  1248. EndDate string `gorm:"column:END_DATE;type:varchar(255)" description:"数据结束日期"`
  1249. LatestValue float64 `gorm:"column:LATEST_VALUE;type:decimal(10,2)" description:"指标最新值"`
  1250. DataList []*Edbdata `gorm:"-" description:"指标数据列表"`
  1251. }
  1252. // GetTargetItemList 获取指标列表数据
  1253. func GetTargetItemList(classifyId, edbShowType int, frequency, keyword, tradeCode string, classifyIdStrList []string) (items []*EdbInfoItem, err error) {
  1254. //o := orm.NewOrmUsingDB("edb")
  1255. pars := make([]interface{}, 0)
  1256. sql := ` SELECT a.*,'' modify_date,'' STATUS FROM edbinfo AS a `
  1257. if edbShowType != 0 {
  1258. sql = ` SELECT a.*,b.DT,'' modify_date,'' STATUS FROM edbinfo AS a
  1259. left join edbdata b on a.TRADE_CODE=b.TRADE_CODE `
  1260. }
  1261. sql += ` WHERE a.classify_id>0 `
  1262. //如果没有分类id集合列表,那么就没有数据了,不用往下执行了,直接返回好了
  1263. if len(classifyIdStrList) <= 0 {
  1264. return
  1265. }
  1266. if len(classifyIdStrList) > 0 {
  1267. sql += ` AND a.classify_id in (` + strings.Join(classifyIdStrList, ",") + `) `
  1268. }
  1269. if classifyId > 0 {
  1270. sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ` `
  1271. }
  1272. //频度
  1273. if frequency != "" {
  1274. sql += ` AND a.frequency="` + frequency + `" `
  1275. }
  1276. //关键字
  1277. if keyword != "" {
  1278. sql += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  1279. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  1280. }
  1281. //指定指标
  1282. if tradeCode != "" {
  1283. sql += ` AND a.TRADE_CODE = "` + tradeCode + `" `
  1284. }
  1285. //指标里面是否有数据
  1286. switch edbShowType {
  1287. case 1:
  1288. sql += ` AND b.CLOSE is not null `
  1289. case 2:
  1290. sql += ` AND b.CLOSE is null `
  1291. }
  1292. sql += ` GROUP BY a.TRADE_CODE `
  1293. sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk ) COLLATE gbk_chinese_ci ASC `
  1294. //_, err = o.Raw(sql, pars).QueryRows(&items)
  1295. err = global.DmSQL["edb"].Raw(sql, pars).Find(&items).Error
  1296. return
  1297. }
  1298. // GetLzItemList 模糊查询隆众数据库指标列表
  1299. func GetLzItemList(keyword string) (items []*data_manage.LongzhongSurveyProduct, err error) {
  1300. //o := orm.NewOrmUsingDB("edb")
  1301. sql := "SELECT * FROM longzhong_survey_product WHERE CONCAT(sample_name,breed_name,custom,quota_name,lz_code) LIKE ?"
  1302. //_, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
  1303. err = global.DmSQL["edb"].Raw(sql, utils.GetLikeKeyword(keyword)).Find(&items).Error
  1304. return
  1305. }
  1306. type lzSurveyData struct {
  1307. DataTime string `gorm:"column:data_time"` //`orm:"column(data_time)" description:"日期"`
  1308. InputValue string `gorm:"column:input_value"` //`orm:"column(input_value)" description:"值"`
  1309. }
  1310. // GetLzItemListByCode 根据code查询隆众数据列表
  1311. func GetLzItemListByCode(lzCode string) (items []*lzSurveyData, err error) {
  1312. //o := orm.NewOrmUsingDB("edb")
  1313. sql := "SELECT * FROM longzhong_survey_data WHERE survey_product_id=? GROUP BY data_time DESC"
  1314. //_, err = o.Raw(sql, lzCode).QueryRows(&items)
  1315. err = global.DmSQL["edb"].Raw(sql, lzCode).Find(&items).Error
  1316. return
  1317. }
  1318. // GetEdbDataListByCodes 通过指标ID获取所有数据
  1319. func GetEdbDataListByCodes(tradeCode string) (items []*Edbdata, err error) {
  1320. 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 `
  1321. //o := orm.NewOrmUsingDB("edb")
  1322. //_, err = o.Raw(sql).QueryRows(&items)
  1323. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1324. return
  1325. }
  1326. // TargetItemListResp 指标数据结构体
  1327. type TargetItemListResp struct {
  1328. List []*EdbInfoItem
  1329. FrequencyList []string
  1330. }
  1331. // BatchDataDeleteReq 批量删除某日的指标数据请求结构体
  1332. type BatchDataDeleteReq struct {
  1333. CreateDate string `description:"创建日期"`
  1334. TradeCodeList []string `description:"指标唯一编码列表"`
  1335. }
  1336. // BatchDeleteEdbDataByDate 批量删除某日的指标数据
  1337. func BatchDeleteEdbDataByDate(tradeCodes, dt string, opUserId int) (err error) {
  1338. //o := orm.NewOrmUsingDB("edb")
  1339. var list []*Edbdata
  1340. sql := ` select * FROM edbdata WHERE TRADE_CODE in (` + tradeCodes + `) AND DT = ? `
  1341. //_, err = o.Raw(sql, dt).QueryRows(&list)
  1342. err = global.DmSQL["edb"].Raw(sql, dt).Find(&list).Error
  1343. if err != nil {
  1344. return
  1345. }
  1346. deleteRecordList := make([]*EdbdataDeleteRecord, 0)
  1347. for _, edbDataInfo := range list {
  1348. deleteRecord := &EdbdataDeleteRecord{
  1349. TradeCode: edbDataInfo.TradeCode,
  1350. Dt: edbDataInfo.Dt,
  1351. Close: edbDataInfo.Close,
  1352. ModifyTime: time.Now(),
  1353. CreateTime: time.Now(),
  1354. SysUserId: opUserId,
  1355. }
  1356. deleteRecordList = append(deleteRecordList, deleteRecord)
  1357. }
  1358. if len(deleteRecordList) > 0 {
  1359. //_, tmpErr := o.InsertMulti(len(deleteRecordList), deleteRecordList)
  1360. tmpErr := global.DmSQL["edb"].CreateInBatches(deleteRecordList, utils.MultiAddNum).Error
  1361. if tmpErr != nil {
  1362. err = tmpErr
  1363. return
  1364. }
  1365. }
  1366. sql = ` DELETE FROM edbdata WHERE TRADE_CODE in (` + tradeCodes + `) AND DT = ? `
  1367. //_, err = o.Raw(sql, dt).Exec()
  1368. err = global.DmSQL["edb"].Exec(sql, dt).Error
  1369. return
  1370. }
  1371. // BatchDeleteEdbData 批量删除指标数据
  1372. func BatchDeleteEdbData(tradeCode string, opUserId int) (err error) {
  1373. //o := orm.NewOrmUsingDB("edb")
  1374. var list []*Edbdata
  1375. sql := ` select * FROM edbdata WHERE TRADE_CODE = ? `
  1376. //_, err = o.Raw(sql, tradeCode).QueryRows(&list)
  1377. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&list).Error
  1378. if err != nil {
  1379. return
  1380. }
  1381. deleteRecordList := make([]*EdbdataDeleteRecord, 0)
  1382. for _, edbDataInfo := range list {
  1383. deleteRecord := &EdbdataDeleteRecord{
  1384. TradeCode: edbDataInfo.TradeCode,
  1385. Dt: edbDataInfo.Dt,
  1386. Close: edbDataInfo.Close,
  1387. ModifyTime: time.Now(),
  1388. CreateTime: time.Now(),
  1389. SysUserId: opUserId,
  1390. }
  1391. deleteRecordList = append(deleteRecordList, deleteRecord)
  1392. }
  1393. //_, err = o.InsertMulti(len(deleteRecordList), deleteRecordList)
  1394. err = global.DmSQL["edb"].CreateInBatches(deleteRecordList, utils.MultiAddNum).Error
  1395. if err != nil {
  1396. return
  1397. }
  1398. sql = ` DELETE FROM edbdata WHERE TRADE_CODE = ? `
  1399. //_, err = o.Raw(sql, tradeCode).Exec()
  1400. err = global.DmSQL["edb"].Exec(sql, tradeCode).Error
  1401. return
  1402. }
  1403. // GetEdbInfoCountByClassifyId 根据指标分类id获取当前分类下的指标数量
  1404. func GetEdbInfoCountByClassifyId(classifyId int) (count int, err error) {
  1405. //o := orm.NewOrmUsingDB("edb")
  1406. sql := `SELECT COUNT(1) AS count FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a
  1407. INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
  1408. WHERE a.classify_id=? group by a.TRADE_CODE) d `
  1409. //err = o.Raw(sql, classifyId).QueryRow(&count)
  1410. err = global.DmSQL["edb"].Raw(sql, classifyId).Scan(&count).Error
  1411. return
  1412. }
  1413. // EdbInfoGroupCount 指标分类id获取当前分类下的指标数量
  1414. type EdbInfoGroupCount struct {
  1415. Count int `gorm:"column:count"`
  1416. ClassifyId int `gorm:"column:classify_id"`
  1417. }
  1418. // GetEdbInfoGroupCountByClassifyIds 根据指标分类id获取当前分类下的指标数量
  1419. func GetEdbInfoGroupCountByClassifyIds(classifyIds string) (list []*EdbInfoGroupCount, err error) {
  1420. //o := orm.NewOrmUsingDB("edb")
  1421. sql := `SELECT COUNT(1) AS count,classify_id FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a
  1422. INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
  1423. WHERE a.classify_id in (` + classifyIds + `) group by a.TRADE_CODE) d
  1424. GROUP BY classify_id `
  1425. //_, err = o.Raw(sql).QueryRows(&list)
  1426. err = global.DmSQL["edb"].Raw(sql).Find(&list).Error
  1427. return
  1428. }
  1429. // GetExcelData 获取excel样式数据
  1430. func GetExcelData() (list []*data_manage.ExcelStyle, err error) {
  1431. //o := orm.NewOrmUsingDB("edb")
  1432. sql := `SELECT * FROM excel_style `
  1433. //_, err = o.Raw(sql).QueryRows(&list)
  1434. err = global.DmSQL["edb"].Raw(sql).Find(&list).Error
  1435. return
  1436. }
  1437. // AddExcelData 添加excel样式数据
  1438. func AddExcelData(item *data_manage.ExcelStyle) (id int64, err error) {
  1439. //o := orm.NewOrmUsingDB("edb")
  1440. //id, err = o.Insert(item)
  1441. err = global.DmSQL["edb"].Create(item).Error
  1442. return
  1443. }
  1444. type EdbdataFloat struct {
  1445. TradeCode string `gorm:"column:TRADE_CODE"` //`orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标编码"`
  1446. Dt string `gorm:"column:DT"` //`orm:"column(DT)" description:"日期"`
  1447. Close float64 `gorm:"column:CLOSE"` //`orm:"column(CLOSE)" description:"值"`
  1448. ModifyTime time.Time `gorm:"column:modify_time"` //`orm:"column(modify_time)" description:"修改时间"`
  1449. }
  1450. func GetTargetsDataFloat(tradeCode, dt string) (item *EdbdataFloat, err error) {
  1451. sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  1452. //o := orm.NewOrmUsingDB("edb")
  1453. //err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
  1454. err = global.DmSQL["edb"].Raw(sql, tradeCode, dt).First(&item).Error
  1455. return
  1456. }
  1457. func ModifyEdbinfo(tradeCode, unit, frequency string, classifyId int) (err error) {
  1458. sql := `UPDATE edbinfo SET UNIT = ?,frequency=?, classify_id=?, create_date=NOW() WHERE TRADE_CODE=? `
  1459. //o := orm.NewOrmUsingDB("edb")
  1460. //_, err = o.Raw(sql, unit, frequency, classifyId, tradeCode).Exec()
  1461. err = global.DmSQL["edb"].Exec(sql, unit, frequency, classifyId, tradeCode).Error
  1462. return
  1463. }
  1464. func DeleteTargetsDataByImport(tradeCode, dt string) (err error) {
  1465. sql := `DELETE FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  1466. //o := orm.NewOrmUsingDB("edb")
  1467. //_, err = o.Raw(sql, tradeCode, dt).Exec()
  1468. err = global.DmSQL["edb"].Exec(sql, tradeCode, dt).Error
  1469. return
  1470. }
  1471. // GetEdbinfoListByCodeListGroupByUserId 根据指标code列表、用户分组获取指标信息
  1472. func GetEdbinfoListByCodeListGroupByUserId(edbCodeList []string) (items []*Edbinfo, err error) {
  1473. num := len(edbCodeList)
  1474. if num <= 0 {
  1475. return
  1476. }
  1477. //o := orm.NewOrmUsingDB("edb")
  1478. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) GROUP BY user_id `
  1479. //_, err = o.Raw(sql, edbCodeList).QueryRows(&items)
  1480. err = global.DmSQL["edb"].Raw(sql, edbCodeList).Find(&items).Error
  1481. return
  1482. }
  1483. // GetEdbinfoListByCodeListByCodeIdList
  1484. // @Description: 根据指标code列表获取列表信息
  1485. // @param edbCodeList
  1486. // @return items
  1487. // @return err
  1488. func GetEdbinfoListByCodeListByCodeIdList(edbCodeList []string) (items []*Edbinfo, err error) {
  1489. num := len(edbCodeList)
  1490. if num <= 0 {
  1491. return
  1492. }
  1493. //o := orm.NewOrmUsingDB("edb")
  1494. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  1495. //_, err = o.Raw(sql, edbCodeList).QueryRows(&items)
  1496. err = global.DmSQL["edb"].Raw(sql, edbCodeList).Find(&items).Error
  1497. return
  1498. }
  1499. // GetEdbinfoListByCodeListByUserId
  1500. // @Description: 根据用户id列表获取指标列表信息
  1501. // @param userIdList
  1502. // @return items
  1503. // @return err
  1504. func GetEdbinfoListByCodeListByUserId(userIdList []int) (items []*Edbinfo, err error) {
  1505. num := len(userIdList)
  1506. if num <= 0 {
  1507. return
  1508. }
  1509. //o := orm.NewOrmUsingDB("edb")
  1510. sql := `SELECT * FROM edbinfo WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
  1511. //_, err = o.Raw(sql, userIdList).QueryRows(&items)
  1512. err = global.DmSQL["edb"].Raw(sql, userIdList).Find(&items).Error
  1513. return
  1514. }
  1515. // ModifyEdbinfoUserIdByCodeList 根据指标code列表修改创建人
  1516. func ModifyEdbinfoUserIdByCodeList(edbCodeList []string, userId int, userName string) (err error) {
  1517. num := len(edbCodeList)
  1518. if num <= 0 {
  1519. return
  1520. }
  1521. //o := orm.NewOrmUsingDB("edb")
  1522. sql := `UPDATE edbinfo SET user_id = ?,user_name = ? WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  1523. //_, err = o.Raw(sql, userId, userName, edbCodeList).Exec()
  1524. err = global.DmSQL["edb"].Exec(sql, userId, userName, edbCodeList).Error
  1525. return
  1526. }
  1527. // ModifyEdbinfoUserIdByOldUserId
  1528. // @Description: 根据旧用户id修改新用户id
  1529. // @author: Roc
  1530. // @datetime 2024-03-25 17:59:32
  1531. // @param oldUserId int
  1532. // @param userId int
  1533. // @return err error
  1534. func ModifyEdbinfoUserIdByOldUserId(oldUserIdList []int, userId int) (err error) {
  1535. num := len(oldUserIdList)
  1536. if num <= 0 {
  1537. return
  1538. }
  1539. //o := orm.NewOrmUsingDB("edb")
  1540. sql := `UPDATE edbinfo SET user_id=? WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
  1541. //_, err = o.Raw(sql, userId, oldUserIdList).Exec()
  1542. err = global.DmSQL["edb"].Exec(sql, userId, oldUserIdList).Error
  1543. return
  1544. }
  1545. func GetEdbInfoAdminList() (list []int, err error) {
  1546. sql := `SELECT user_id FROM edbinfo GROUP BY user_id `
  1547. //o := orm.NewOrmUsingDB("edb")
  1548. //_, err = o.Raw(sql).QueryRows(&list)
  1549. err = global.DmSQL["edb"].Raw(sql).Find(&list).Error
  1550. return
  1551. }
  1552. // GetAllChildManualEdbClassify
  1553. // @Description: 获取手工数据中所有的子分类
  1554. // @author: Roc
  1555. // @datetime 2024-07-16 13:27:28
  1556. // @return items []*EdbdataClassify
  1557. // @return err error
  1558. func GetAllChildManualEdbClassify() (items []*EdbdataClassify, err error) {
  1559. //o := orm.NewOrmUsingDB("edb")
  1560. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id > 0 `
  1561. //_, err = o.Raw(sql).QueryRows(&items)
  1562. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1563. return
  1564. }
  1565. // GetChildManualEdbClassifyByIdList
  1566. // @Description: 获取手工数据中所有的子分类
  1567. // @author: Roc
  1568. // @datetime 2024-07-16 13:33:57
  1569. // @param idList []int
  1570. // @return items []*EdbdataClassify
  1571. // @return err error
  1572. func GetChildManualEdbClassifyByIdList(idList []int) (items []*EdbdataClassify, err error) {
  1573. num := len(idList)
  1574. if num <= 0 {
  1575. return
  1576. }
  1577. //o := orm.NewOrmUsingDB("edb")
  1578. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id in (` + utils.GetOrmInReplace(num) + `) `
  1579. //_, err = o.Raw(sql, idList).QueryRows(&items)
  1580. err = global.DmSQL["edb"].Raw(sql, idList).Find(&items).Error
  1581. return
  1582. }
  1583. // EdbinfoMaxMinDate
  1584. // @Description: 手工指标的最小最大日期
  1585. type EdbinfoMaxMinDate struct {
  1586. MinDate string `gorm:"column:min_date"`
  1587. MaxDate string `gorm:"column:max_date"`
  1588. }
  1589. // GetEdbdataMaxMinDate
  1590. // @Description: 获取手工指标的最小最大日期
  1591. // @author: Roc
  1592. // @datetime 2024-08-01 14:27:20
  1593. // @param tradeCode string
  1594. // @return item EdbinfoMaxMinDate
  1595. // @return err error
  1596. func GetEdbdataMaxMinDate(tradeCode string) (item EdbinfoMaxMinDate, err error) {
  1597. //o := orm.NewOrmUsingDB("edb")
  1598. sql := ` SELECT MIN(DT) min_date,MAX(DT) max_date FROM edbdata WHERE TRADE_CODE = ? `
  1599. //err = o.Raw(sql, tradeCode).QueryRow(&item)
  1600. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&item).Error
  1601. return
  1602. }
  1603. // GetEdbdataLatestValue
  1604. // @Description: 获取手工数据的最新值
  1605. // @author: Roc
  1606. // @datetime 2024-08-02 10:33:22
  1607. // @param tradeCode string
  1608. // @return latestValue float64
  1609. // @return err error
  1610. func GetEdbdataLatestValue(tradeCode string) (latestValue float64, err error) {
  1611. //o := orm.NewOrmUsingDB("edb")
  1612. sql := ` SELECT CLOSE FROM edbdata WHERE TRADE_CODE = ? ORDER BY DT DESC LIMIT 1`
  1613. //err = o.Raw(sql, tradeCode).QueryRow(&latestValue)
  1614. err = global.DmSQL["edb"].Raw(sql, tradeCode).Scan(&latestValue).Error
  1615. return
  1616. }
  1617. // ModifyEdbinfoMaxMinDate
  1618. // @Description: 修改手工指标的最小最大日期
  1619. // @author: Roc
  1620. // @datetime 2024-08-01 15:33:45
  1621. // @param startDate string
  1622. // @param endDate string
  1623. // @param tradeCode string
  1624. // @return err error
  1625. func ModifyEdbinfoMaxMinDate(tradeCode, startDate, endDate string, latestValue float64) (err error) {
  1626. //o := orm.NewOrmUsingDB("edb")
  1627. sql := ` UPDATE edbinfo SET start_date = ?, end_date = ?, latest_value = ? , modify_time = now() WHERE TRADE_CODE = ? `
  1628. //_, err = o.Raw(sql, startDate, endDate, latestValue, tradeCode).Exec()
  1629. err = global.DmSQL["edb"].Exec(sql, startDate, endDate, latestValue, tradeCode).Error
  1630. return
  1631. }