target.go 56 KB

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