target.go 56 KB

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