target.go 59 KB

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