target.go 53 KB

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