target.go 55 KB

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