manual_edb.go 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/services/data"
  8. "eta_gn/eta_api/utils"
  9. "fmt"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. "github.com/shopspring/decimal"
  12. "os"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type ManualEdbController struct {
  18. controllers.BaseAuthController
  19. }
  20. // @router /target/edb/detail [get]
  21. func (c *ManualEdbController) EdbDetail() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. c.Data["json"] = br
  25. c.ServeJSON()
  26. }()
  27. sysUser := c.SysUser
  28. if sysUser == nil {
  29. br.Msg = "请重新登录"
  30. return
  31. }
  32. tradeCode := c.GetString("TradeCode")
  33. if tradeCode == `` {
  34. br.Msg = "请输入指标编码"
  35. br.IsSendEmail = false
  36. return
  37. }
  38. manualEdbInfo, err := models.GetTargetByTradeCode(tradeCode)
  39. if err != nil {
  40. br.Msg = "获取指标失败"
  41. br.ErrMsg = "获取指标失败,err:" + err.Error()
  42. return
  43. }
  44. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  45. count, err := models.GetCountManualUserClassify(sysUser.AdminId, manualEdbInfo.ClassifyId)
  46. if err != nil {
  47. br.Msg = "获取分类数据失败"
  48. br.ErrMsg = "获取分类数据失败,err:" + err.Error()
  49. return
  50. }
  51. if count <= 0 {
  52. br.Msg = "无权访问"
  53. br.ErrMsg = "无权访问"
  54. br.IsSendEmail = false
  55. return
  56. }
  57. }
  58. classifyList := make([]*models.EdbdataClassify, 0)
  59. {
  60. classify, err := models.GetManualClassifyByClassifyId(manualEdbInfo.ClassifyId)
  61. if err != nil {
  62. br.Msg = "获取分类信息失败"
  63. br.ErrMsg = "获取分类信息失败,err:" + err.Error()
  64. return
  65. }
  66. parentClassify, err := models.GetManualClassifyByClassifyId(classify.ParentId)
  67. if err != nil {
  68. br.Msg = "获取分类信息失败"
  69. br.ErrMsg = "获取父级分类信息失败,err:" + err.Error()
  70. return
  71. }
  72. classifyList = []*models.EdbdataClassify{
  73. parentClassify, classify,
  74. }
  75. }
  76. {
  77. dataList, err := models.GetEdbDataListByCode(manualEdbInfo.TradeCode)
  78. if err != nil {
  79. br.Msg = "获取明细数据失败"
  80. br.ErrMsg = "获取明细数据失败,err:" + err.Error()
  81. return
  82. }
  83. manualEdbInfo.DataList = dataList
  84. }
  85. resp := models.TargetDetailResp{
  86. Detail: manualEdbInfo,
  87. ClassifyList: classifyList,
  88. }
  89. br.Ret = 200
  90. br.Success = true
  91. br.Msg = "获取成功"
  92. br.Data = resp
  93. }
  94. // @router /target/classify/edb/list [get]
  95. func (c *ManualEdbController) ClassifyEdbList() {
  96. br := new(models.BaseResponse).Init()
  97. defer func() {
  98. c.Data["json"] = br
  99. c.ServeJSON()
  100. }()
  101. sysUser := c.SysUser
  102. if sysUser == nil {
  103. br.Msg = "请登录"
  104. br.Ret = 408
  105. return
  106. }
  107. resp := new(models.EdbdataClassifyResp)
  108. classifyId, _ := c.GetInt("ClassifyId") //分类
  109. if classifyId <= 0 {
  110. br.Msg = "请传入分类"
  111. br.ErrMsg = "请传入分类"
  112. br.IsSendEmail = false
  113. }
  114. frequency := c.GetString("Frequency")
  115. var condition string
  116. var pars []interface{}
  117. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  118. count, err := models.GetCountManualUserClassify(sysUser.AdminId, classifyId)
  119. if err != nil {
  120. br.Msg = "获取分类数据失败"
  121. br.ErrMsg = "获取分类数据失败,err:" + err.Error()
  122. return
  123. }
  124. if count <= 0 {
  125. br.Msg = "无权访问"
  126. br.ErrMsg = "无权访问"
  127. br.IsSendEmail = false
  128. return
  129. }
  130. }
  131. list := make([]*models.EdbdataClassifyList, 0)
  132. condition += ` AND a.classify_id = ? `
  133. pars = append(pars, classifyId)
  134. if frequency != "" {
  135. condition += ` AND a.frequency = ?`
  136. pars = append(pars, frequency)
  137. }
  138. tmpList, err := models.GetEdbInfoList(condition, pars, 0, 0)
  139. if err != nil {
  140. br.Msg = "获取失败"
  141. br.ErrMsg = "获取失败,Err:" + err.Error()
  142. return
  143. }
  144. for _, v := range tmpList {
  145. list = append(list, &models.EdbdataClassifyList{
  146. ClassifyId: 0,
  147. ClassifyName: v.SecName,
  148. ParentId: v.ClassifyId,
  149. Child: nil,
  150. TradeCode: v.TradeCode,
  151. UniqueCode: utils.MD5(v.TradeCode),
  152. })
  153. }
  154. resp.List = list
  155. br.Ret = 200
  156. br.Success = true
  157. br.Msg = "获取成功"
  158. br.Data = resp
  159. }
  160. // @router /target/edb/search [get]
  161. func (c *ManualEdbController) EdbSearch() {
  162. br := new(models.BaseResponse).Init()
  163. defer func() {
  164. c.Data["json"] = br
  165. c.ServeJSON()
  166. }()
  167. sysUser := c.SysUser
  168. if sysUser == nil {
  169. br.Msg = "请重新登录"
  170. return
  171. }
  172. pageSize, _ := c.GetInt("PageSize")
  173. currentIndex, _ := c.GetInt("CurrentIndex")
  174. var startSize int
  175. if pageSize <= 0 {
  176. pageSize = utils.PageSize20
  177. }
  178. if currentIndex <= 0 {
  179. currentIndex = 1
  180. }
  181. startSize = utils.StartIndex(currentIndex, pageSize)
  182. keyword := c.GetString("Keyword")
  183. var condition string
  184. var pars []interface{}
  185. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  186. classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId)
  187. if err != nil {
  188. br.Msg = "获取分类数据失败"
  189. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  190. return
  191. }
  192. num := len(classifyIdList)
  193. if num > 0 {
  194. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  195. pars = append(pars, classifyIdList)
  196. }
  197. }
  198. if keyword != "" {
  199. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  200. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  201. }
  202. total, err := models.GetCountEdbInfoList(condition, pars)
  203. if err != nil {
  204. br.Msg = "获取失败"
  205. br.ErrMsg = "获取失败,Err:" + err.Error()
  206. return
  207. }
  208. list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize)
  209. if err != nil {
  210. br.Msg = "获取失败"
  211. br.ErrMsg = "获取失败,Err:" + err.Error()
  212. return
  213. }
  214. for _, v := range list {
  215. v.UniqueCode = utils.MD5(v.TradeCode)
  216. }
  217. resp := models.EdbListResp{
  218. List: list,
  219. Paging: paging.GetPaging(currentIndex, pageSize, total),
  220. }
  221. br.Ret = 200
  222. br.Success = true
  223. br.Msg = "获取成功"
  224. br.Data = resp
  225. }
  226. // @router /target/edb/list [get]
  227. func (c *ManualEdbController) EdbList() {
  228. br := new(models.BaseResponse).Init()
  229. defer func() {
  230. c.Data["json"] = br
  231. c.ServeJSON()
  232. }()
  233. sysUser := c.SysUser
  234. if sysUser == nil {
  235. br.Msg = "请重新登录"
  236. return
  237. }
  238. pageSize, _ := c.GetInt("PageSize")
  239. currentIndex, _ := c.GetInt("CurrentIndex")
  240. var startSize int
  241. if pageSize <= 0 {
  242. pageSize = utils.PageSize20
  243. }
  244. if currentIndex <= 0 {
  245. currentIndex = 1
  246. }
  247. startSize = utils.StartIndex(currentIndex, pageSize)
  248. frequency := c.GetString("Frequency")
  249. keyword := c.GetString("Keyword")
  250. classifyId, _ := c.GetInt("ClassifyId", 0)
  251. userId, _ := c.GetInt("UserId", 0)
  252. var condition string
  253. var pars []interface{}
  254. permissionUserId := sysUser.AdminId
  255. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  256. classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId)
  257. if err != nil {
  258. br.Msg = "获取分类数据失败"
  259. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  260. return
  261. }
  262. num := len(classifyIdList)
  263. if num > 0 {
  264. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  265. pars = append(pars, classifyIdList)
  266. }
  267. } else {
  268. permissionUserId = 0
  269. }
  270. if keyword != "" {
  271. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  272. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  273. }
  274. if frequency != "" {
  275. condition += ` AND a.frequency = ?`
  276. pars = append(pars, frequency)
  277. }
  278. if classifyId > 0 {
  279. classifyList, err := models.GetEdbdataClassify(int64(permissionUserId))
  280. if err != nil {
  281. return
  282. }
  283. var isParent bool
  284. classifyIdList := make([]int, 0)
  285. for _, v := range classifyList {
  286. if v.ClassifyId == classifyId {
  287. isParent = true
  288. classifyIdList = append(classifyIdList, v.ClassifyId)
  289. if v.Child != nil && len(v.Child) > 0 {
  290. for _, vv := range v.Child {
  291. classifyIdList = append(classifyIdList, vv.ClassifyId)
  292. }
  293. }
  294. break
  295. }
  296. }
  297. num := len(classifyIdList)
  298. if num > 0 && isParent {
  299. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  300. pars = append(pars, classifyIdList)
  301. } else {
  302. condition += ` AND a.classify_id = ? `
  303. pars = append(pars, classifyId)
  304. }
  305. }
  306. if userId > 0 {
  307. condition += ` AND a.user_id = ? `
  308. pars = append(pars, userId)
  309. }
  310. total, err := models.GetCountEdbInfoList(condition, pars)
  311. if err != nil {
  312. br.Msg = "获取失败"
  313. br.ErrMsg = "获取失败,Err:" + err.Error()
  314. return
  315. }
  316. list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize)
  317. if err != nil {
  318. br.Msg = "获取失败"
  319. br.ErrMsg = "获取失败,Err:" + err.Error()
  320. return
  321. }
  322. resp := models.EdbListResp{
  323. List: list,
  324. Paging: paging.GetPaging(currentIndex, pageSize, total),
  325. }
  326. br.Ret = 200
  327. br.Success = true
  328. br.Msg = "获取成功"
  329. br.Data = resp
  330. }
  331. // @router /target/edb/excel_style/edit [post]
  332. func (c *ManualEdbController) EditExcelData() {
  333. br := new(models.BaseResponse).Init()
  334. var err error
  335. errs := make([]string, 0)
  336. defer func() {
  337. if len(errs) > 0 {
  338. utils.FileLog.Info("编辑EXCEL数据 新增或修改数据失败,Err:" + strings.Join(errs, "\n"))
  339. }
  340. c.Data["json"] = br
  341. c.ServeJSON()
  342. }()
  343. sysUser := c.SysUser
  344. if sysUser == nil {
  345. br.Msg = "请重新登录"
  346. return
  347. }
  348. var req data_manage.ManualEdbExcelStyleEditReq
  349. err = json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  350. if err != nil {
  351. br.Msg = "参数解析异常!"
  352. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  353. return
  354. }
  355. if req.TradeCode == `` {
  356. br.Msg = "指标编码异常!"
  357. br.ErrMsg = "指标编码异常!"
  358. return
  359. }
  360. if req.Unit == `` {
  361. br.Msg = "单位填写异常!"
  362. br.ErrMsg = "单位填写异常!"
  363. return
  364. }
  365. if req.Frequency == `` {
  366. br.Msg = "频度填写异常!"
  367. br.ErrMsg = "频度填写异常!"
  368. return
  369. }
  370. if req.ClassifyId <= 0 {
  371. br.Msg = "品种填写异常!"
  372. br.ErrMsg = "品种填写异常!"
  373. return
  374. }
  375. manualEdbInfo, err := models.GetEdbinfoByTradeCode(req.TradeCode)
  376. if err != nil {
  377. br.Msg = `找不到该指标`
  378. br.Msg = `找不到该指标,ERR:` + err.Error()
  379. return
  380. }
  381. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  382. count, err := models.GetCountManualUserClassify(sysUser.AdminId, manualEdbInfo.ClassifyId)
  383. if err != nil {
  384. br.Msg = "获取分类数据失败"
  385. br.ErrMsg = "获取分类数据失败,err:" + err.Error()
  386. return
  387. }
  388. if count <= 0 {
  389. br.Msg = "无权访问"
  390. br.ErrMsg = "无权访问"
  391. br.IsSendEmail = false
  392. return
  393. }
  394. }
  395. dateValueMap := make(map[string]string)
  396. for _, dateValue := range req.Data {
  397. dateValueMap[dateValue.Date] = strconv.FormatFloat(dateValue.Value, 'f', -1, 64)
  398. }
  399. {
  400. var isUpdateEdb, isUpdateData bool
  401. secName := strings.TrimSpace(req.EdbName)
  402. frequency := strings.TrimSpace(req.Frequency)
  403. unit := strings.TrimSpace(req.Unit)
  404. {
  405. updateCols := make([]string, 0)
  406. if manualEdbInfo.SecName != secName {
  407. var condition string
  408. var pars []interface{}
  409. condition += " AND SEC_NAME=? AND left(TRADE_CODE,1)='W' AND REMARK='手动' AND TRADE_CODE != ? "
  410. pars = append(pars, secName, req.TradeCode)
  411. count, err := models.GetManualEdbCountByCondition(condition, pars)
  412. if err != nil {
  413. br.Msg = `指标保存失败`
  414. br.ErrMsg = `获取同名指标信息异常,ERR:` + err.Error()
  415. return
  416. }
  417. if count > 0 {
  418. br.Msg = `已存在同名指标`
  419. br.ErrMsg = `已存在同名指标`
  420. br.IsSendEmail = false
  421. return
  422. }
  423. updateCols = append(updateCols, "SecName")
  424. manualEdbInfo.SecName = secName
  425. }
  426. if manualEdbInfo.ClassifyId != req.ClassifyId {
  427. updateCols = append(updateCols, "ClassifyId")
  428. manualEdbInfo.ClassifyId = req.ClassifyId
  429. }
  430. if manualEdbInfo.Frequency != frequency {
  431. updateCols = append(updateCols, "Frequency")
  432. manualEdbInfo.Frequency = frequency
  433. }
  434. if manualEdbInfo.Unit != unit {
  435. updateCols = append(updateCols, "Unit")
  436. manualEdbInfo.Unit = unit
  437. }
  438. if len(updateCols) > 0 {
  439. isUpdateEdb = true
  440. manualEdbInfo.ModifyTime = time.Now().Format(utils.FormatDateTime)
  441. updateCols = append(updateCols, "ModifyTime")
  442. err = manualEdbInfo.Update(updateCols)
  443. if err != nil {
  444. br.Msg = `指标保存失败`
  445. br.ErrMsg = `指标保存失败,ERR:` + err.Error()
  446. return
  447. }
  448. }
  449. }
  450. targetDataList, tmpErr := models.GetTargetsDataList(manualEdbInfo.TradeCode)
  451. if tmpErr != nil {
  452. err = tmpErr
  453. }
  454. existDataMap := make(map[string]string)
  455. deleteDataMap := make(map[string]string)
  456. for _, tmpData := range targetDataList {
  457. existDataMap[tmpData.Dt] = tmpData.Close
  458. deleteDataMap[tmpData.Dt] = tmpData.Dt
  459. }
  460. addDataList := make([]*models.Edbdata, 0)
  461. for createDate, closeVal := range dateValueMap {
  462. if createDate == "" || closeVal == "" {
  463. continue
  464. }
  465. tmpVal, ok3 := existDataMap[createDate]
  466. if !ok3 {
  467. addDataList = append(addDataList, &models.Edbdata{
  468. TradeCode: manualEdbInfo.TradeCode,
  469. Dt: createDate,
  470. Close: closeVal,
  471. ModifyTime: time.Now(),
  472. })
  473. continue
  474. }
  475. delete(deleteDataMap, createDate)
  476. tmpValDecimal, tmpErr := decimal.NewFromString(tmpVal)
  477. if tmpErr != nil {
  478. fmt.Println("tmpVal Parse err:", tmpErr.Error())
  479. err = tmpErr
  480. continue
  481. }
  482. closeValDecimal, tmpErr := decimal.NewFromString(closeVal)
  483. if tmpErr != nil {
  484. fmt.Println("closeVal Parse err:", tmpErr.Error())
  485. err = tmpErr
  486. continue
  487. }
  488. if !tmpValDecimal.Equal(closeValDecimal) {
  489. isUpdateData = true
  490. fmt.Println("更新数值")
  491. err = models.ModifyTargetsDataByImport(manualEdbInfo.TradeCode, createDate, closeVal)
  492. if err != nil {
  493. fmt.Println("ModifyTargetsDataByImport err:", err.Error())
  494. errs = append(errs, err.Error())
  495. }
  496. }
  497. }
  498. if len(addDataList) > 0 {
  499. isUpdateData = true
  500. err = models.OnlyMultiAddEdbdata(addDataList)
  501. if err != nil {
  502. fmt.Println("MultiAddEdbdata err:", err.Error())
  503. errs = append(errs, err.Error())
  504. }
  505. }
  506. num := len(deleteDataMap)
  507. if num > 0 {
  508. isUpdateData = true
  509. deleteDateList := make([]string, 0)
  510. for date := range deleteDataMap {
  511. deleteDateList = append(deleteDateList, date)
  512. }
  513. err = models.DelEdbdataByCodeAndDateList(manualEdbInfo.TradeCode, deleteDateList)
  514. if err != nil {
  515. fmt.Println("DelEdbdataByCodeAndDateList err:", err.Error())
  516. errs = append(errs, err.Error())
  517. }
  518. }
  519. if isUpdateEdb {
  520. record := &models.EdbinfoOpRecord{
  521. TradeCode: manualEdbInfo.TradeCode,
  522. Remark: "编辑指标",
  523. UserId: sysUser.AdminId,
  524. UserName: sysUser.RealName,
  525. CreateTime: time.Now(),
  526. }
  527. go func() {
  528. _ = record.Create()
  529. }()
  530. }
  531. if isUpdateData {
  532. record := &models.EdbinfoOpRecord{
  533. TradeCode: manualEdbInfo.TradeCode,
  534. Remark: "更新数据",
  535. UserId: sysUser.AdminId,
  536. UserName: sysUser.RealName,
  537. CreateTime: time.Now(),
  538. }
  539. go func() {
  540. data.ModifyManualEdbMaxMinDate(manualEdbInfo.TradeCode)
  541. _ = record.Create()
  542. }()
  543. }
  544. if utils.Re == nil {
  545. err := utils.Rc.LPush(utils.CACHE_IMPORT_MANUAL_DATA, manualEdbInfo.TradeCode)
  546. if err != nil {
  547. fmt.Println("CACHE_IMPORT_MANUAL_DATA LPush Err:" + err.Error())
  548. }
  549. }
  550. }
  551. br.Ret = 200
  552. br.Success = true
  553. br.Msg = "保存成功"
  554. }
  555. // @router /target/edb/batch/list [post]
  556. func (c *ManualEdbController) BatchEdbList() {
  557. br := new(models.BaseResponse).Init()
  558. defer func() {
  559. c.Data["json"] = br
  560. c.ServeJSON()
  561. }()
  562. sysUser := c.SysUser
  563. if sysUser == nil {
  564. br.Msg = "请重新登录"
  565. return
  566. }
  567. var req models.BatchManualEdbReq
  568. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  569. pageSize := req.PageSize
  570. currentIndex := req.CurrentIndex
  571. var startSize int
  572. if pageSize <= 0 {
  573. pageSize = utils.PageSize20
  574. }
  575. if currentIndex <= 0 {
  576. currentIndex = 1
  577. }
  578. startSize = utils.StartIndex(currentIndex, pageSize)
  579. req.Keyword = strings.TrimSpace(req.Keyword)
  580. var condition string
  581. var pars []interface{}
  582. condition += ` AND a.is_join_edb = ? `
  583. pars = append(pars, 0)
  584. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  585. classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId)
  586. if err != nil {
  587. br.Msg = "获取分类数据失败"
  588. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  589. return
  590. }
  591. num := len(classifyIdList)
  592. if num > 0 {
  593. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  594. pars = append(pars, classifyIdList)
  595. }
  596. }
  597. if req.Keyword != "" {
  598. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  599. pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2)
  600. }
  601. lenFrequency := len(req.FrequencyList)
  602. if lenFrequency > 0 {
  603. condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) `
  604. pars = append(pars, req.FrequencyList)
  605. }
  606. lenClassify := len(req.ClassifyIdList)
  607. if lenClassify > 0 {
  608. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) `
  609. pars = append(pars, req.ClassifyIdList)
  610. }
  611. lenUser := len(req.UserIdList)
  612. if lenUser > 0 {
  613. condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) `
  614. pars = append(pars, req.UserIdList)
  615. }
  616. total, err := models.GetCountEdbInfoList(condition, pars)
  617. if err != nil {
  618. br.Msg = "获取失败"
  619. br.ErrMsg = "获取失败,Err:" + err.Error()
  620. return
  621. }
  622. list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize)
  623. if err != nil {
  624. br.Msg = "获取失败"
  625. br.ErrMsg = "获取失败,Err:" + err.Error()
  626. return
  627. }
  628. resp := models.EdbListResp{
  629. List: list,
  630. Paging: paging.GetPaging(currentIndex, pageSize, total),
  631. }
  632. br.Ret = 200
  633. br.Success = true
  634. br.Msg = "获取成功"
  635. br.Data = resp
  636. br.IsAddLog = false
  637. }
  638. // @router /target/edb/batch/add/check [post]
  639. func (c *ManualEdbController) BatchAddEdbCheck() {
  640. br := new(models.BaseResponse).Init()
  641. defer func() {
  642. if br.ErrMsg == "" {
  643. br.IsSendEmail = false
  644. }
  645. c.Data["json"] = br
  646. c.ServeJSON()
  647. }()
  648. sysUser := c.SysUser
  649. if sysUser == nil {
  650. br.Msg = "请登录"
  651. br.ErrMsg = "请登录,SysUser Is Empty"
  652. br.Ret = 408
  653. return
  654. }
  655. codeMax := 30
  656. var req models.BatchManualEdbReq
  657. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  658. req.Keyword = strings.TrimSpace(req.Keyword)
  659. var condition string
  660. var pars []interface{}
  661. condition += ` AND a.is_join_edb = 0 `
  662. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  663. classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId)
  664. if err != nil {
  665. br.Msg = "获取分类数据失败"
  666. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  667. return
  668. }
  669. num := len(classifyIdList)
  670. if num > 0 {
  671. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  672. pars = append(pars, classifyIdList)
  673. }
  674. }
  675. if req.ListAll {
  676. if req.Keyword != "" {
  677. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  678. pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2)
  679. }
  680. lenFrequency := len(req.FrequencyList)
  681. if lenFrequency > 0 {
  682. condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) `
  683. pars = append(pars, req.FrequencyList)
  684. }
  685. lenClassify := len(req.ClassifyIdList)
  686. if lenClassify > 0 {
  687. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) `
  688. pars = append(pars, req.ClassifyIdList)
  689. }
  690. lenUser := len(req.UserIdList)
  691. if lenUser > 0 {
  692. condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) `
  693. pars = append(pars, req.UserIdList)
  694. }
  695. lenTradeList := len(req.TradeCodeList)
  696. if lenTradeList > 0 {
  697. condition += ` AND a.TRADE_CODE not in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  698. pars = append(pars, req.TradeCodeList)
  699. }
  700. } else {
  701. lenTradeList := len(req.TradeCodeList)
  702. if lenTradeList <= 0 {
  703. br.Msg = "请选择指标"
  704. br.ErrMsg = "请选择指标"
  705. return
  706. }
  707. if lenTradeList > 0 {
  708. condition += ` AND a.TRADE_CODE in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  709. pars = append(pars, req.TradeCodeList)
  710. }
  711. }
  712. list, err := models.GetEdbInfoList(condition, pars, 0, 0)
  713. if err != nil {
  714. br.Msg = "获取失败"
  715. br.ErrMsg = "获取失败,Err:" + err.Error()
  716. return
  717. }
  718. if len(list) > codeMax {
  719. br.Msg = fmt.Sprintf("最多只能选择%d个指标", codeMax)
  720. return
  721. }
  722. br.Data = list
  723. br.Msg = "校验成功"
  724. br.Ret = 200
  725. br.Success = true
  726. }
  727. // @router /target/edb/batch/add/name_check [post]
  728. func (c *ManualEdbController) NameCheck() {
  729. br := new(models.BaseResponse).Init()
  730. defer func() {
  731. if br.ErrMsg == "" {
  732. br.IsSendEmail = false
  733. }
  734. c.Data["json"] = br
  735. c.ServeJSON()
  736. }()
  737. sysUser := c.SysUser
  738. if sysUser == nil {
  739. br.Msg = "请登录"
  740. br.ErrMsg = "请登录,SysUser Is Empty"
  741. br.Ret = 408
  742. return
  743. }
  744. var req []*data_manage.AddEdbInfoReq
  745. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  746. br.Msg = "参数解析异常!"
  747. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  748. return
  749. }
  750. if len(req) == 0 {
  751. br.Msg = "请选择指标"
  752. return
  753. }
  754. type NameCheckResult struct {
  755. EdbCode string
  756. EdbName string
  757. Exist bool
  758. }
  759. indexNames := make([]string, 0)
  760. resp := make([]*NameCheckResult, 0)
  761. for _, v := range req {
  762. v.EdbCode = strings.TrimSpace(v.EdbCode)
  763. if v.EdbCode == "" {
  764. br.Msg = "指标ID不可为空"
  765. return
  766. }
  767. v.EdbName = strings.TrimSpace(v.EdbName)
  768. if v.EdbName == "" {
  769. br.Msg = "请输入指标名称"
  770. return
  771. }
  772. indexNames = append(indexNames, v.EdbName)
  773. resp = append(resp, &NameCheckResult{
  774. EdbCode: v.EdbCode,
  775. EdbName: v.EdbName,
  776. })
  777. }
  778. edbList, e := data_manage.GetEdbInfoByNameArr(indexNames, utils.EDB_INFO_TYPE)
  779. if e != nil {
  780. br.Msg = "操作失败"
  781. br.ErrMsg = "获取重名指标失败, Err: " + e.Error()
  782. return
  783. }
  784. nameExists := make(map[string]bool)
  785. for _, v := range edbList {
  786. nameExists[v.EdbName] = true
  787. }
  788. if len(nameExists) > 0 {
  789. for _, v := range resp {
  790. v.Exist = nameExists[v.EdbName]
  791. }
  792. }
  793. br.Data = resp
  794. br.Msg = "操作成功"
  795. br.Ret = 200
  796. br.Success = true
  797. }
  798. // @router /target/edb/batch/add [post]
  799. func (c *ManualEdbController) BatchAdd2Edb() {
  800. br := new(models.BaseResponse).Init()
  801. defer func() {
  802. if br.ErrMsg == "" {
  803. br.IsSendEmail = false
  804. }
  805. c.Data["json"] = br
  806. c.ServeJSON()
  807. }()
  808. sysUser := c.SysUser
  809. if sysUser == nil {
  810. br.Msg = "请登录"
  811. br.ErrMsg = "请登录,SysUser Is Empty"
  812. br.Ret = 408
  813. return
  814. }
  815. codeMax := 30
  816. deleteCache := true
  817. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_MANUAL_" + strconv.Itoa(sysUser.AdminId)
  818. defer func() {
  819. if deleteCache {
  820. _ = utils.Rc.Delete(cacheKey)
  821. }
  822. }()
  823. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  824. deleteCache = false
  825. br.Msg = "系统处理中,请稍后重试!"
  826. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  827. return
  828. }
  829. var req []*data_manage.AddEdbInfoReq
  830. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  831. br.Msg = "参数解析异常!"
  832. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  833. return
  834. }
  835. if len(req) == 0 {
  836. br.Msg = "请选择指标"
  837. return
  838. }
  839. if len(req) > codeMax {
  840. br.Msg = "批量添加指标数量不得超过30个"
  841. return
  842. }
  843. indexNames := make([]string, 0)
  844. for _, v := range req {
  845. v.EdbCode = strings.TrimSpace(v.EdbCode)
  846. if v.EdbCode == "" {
  847. br.Msg = "指标ID不可为空"
  848. return
  849. }
  850. v.EdbName = strings.TrimSpace(v.EdbName)
  851. if v.EdbName == "" {
  852. br.Msg = "请输入指标名称"
  853. return
  854. }
  855. indexNames = append(indexNames, v.EdbName)
  856. v.Frequency = strings.TrimSpace(v.Frequency)
  857. if v.Frequency == "" {
  858. br.Msg = "请选择频度"
  859. return
  860. }
  861. v.Unit = strings.TrimSpace(v.Unit)
  862. if v.Unit == "" {
  863. br.Msg = "请输入单位"
  864. return
  865. }
  866. if v.ClassifyId <= 0 {
  867. br.Msg = "请选择分类"
  868. return
  869. }
  870. }
  871. for _, v := range req {
  872. var r data.ManualIndexSource2EdbReq
  873. r.EdbCode = v.EdbCode
  874. r.EdbName = v.EdbName
  875. r.Frequency = v.Frequency
  876. r.Unit = v.Unit
  877. r.ClassifyId = v.ClassifyId
  878. r.AdminId = sysUser.AdminId
  879. r.AdminRealName = sysUser.RealName
  880. edbInfo, e, errMsg, skip := data.ManualIndexSource2Edb(r, c.Lang)
  881. if e != nil {
  882. br.Msg = "操作失败"
  883. if errMsg != "" {
  884. br.Msg = errMsg
  885. }
  886. br.ErrMsg = e.Error()
  887. return
  888. }
  889. if skip {
  890. continue
  891. }
  892. {
  893. edbLog := new(data_manage.EdbInfoLog)
  894. edbLog.EdbInfoId = edbInfo.EdbInfoId
  895. edbLog.SourceName = edbInfo.SourceName
  896. edbLog.Source = edbInfo.Source
  897. edbLog.EdbCode = edbInfo.EdbCode
  898. edbLog.EdbName = edbInfo.EdbName
  899. edbLog.ClassifyId = edbInfo.ClassifyId
  900. edbLog.SysUserId = sysUser.AdminId
  901. edbLog.SysUserRealName = sysUser.RealName
  902. edbLog.CreateTime = time.Now()
  903. edbLog.Content = string(c.Ctx.Input.RequestBody)
  904. edbLog.Status = "新增指标"
  905. edbLog.Method = c.Ctx.Input.URI()
  906. go data_manage.AddEdbInfoLog(edbLog)
  907. }
  908. }
  909. br.Msg = "操作成功"
  910. br.Ret = 200
  911. br.Success = true
  912. br.IsAddLog = true
  913. }
  914. // @router /target/edb/batch/del/check [post]
  915. func (c *ManualEdbController) BatchDelEdbCheck() {
  916. br := new(models.BaseResponse).Init()
  917. defer func() {
  918. if br.ErrMsg == "" {
  919. br.IsSendEmail = false
  920. }
  921. c.Data["json"] = br
  922. c.ServeJSON()
  923. }()
  924. sysUser := c.SysUser
  925. if sysUser == nil {
  926. br.Msg = "请登录"
  927. br.ErrMsg = "请登录,SysUser Is Empty"
  928. br.Ret = 408
  929. return
  930. }
  931. var req models.BatchManualEdbReq
  932. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  933. req.Keyword = strings.TrimSpace(req.Keyword)
  934. var condition string
  935. var pars []interface{}
  936. condition += ` AND a.is_join_edb = ? `
  937. pars = append(pars, 1)
  938. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  939. classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId)
  940. if err != nil {
  941. br.Msg = "获取分类数据失败"
  942. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  943. return
  944. }
  945. num := len(classifyIdList)
  946. if num > 0 {
  947. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  948. pars = append(pars, classifyIdList)
  949. }
  950. }
  951. if req.ListAll {
  952. if req.Keyword != "" {
  953. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  954. pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2)
  955. }
  956. lenFrequency := len(req.FrequencyList)
  957. if lenFrequency > 0 {
  958. condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) `
  959. pars = append(pars, req.FrequencyList)
  960. }
  961. lenClassify := len(req.ClassifyIdList)
  962. if lenClassify > 0 {
  963. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) `
  964. pars = append(pars, req.ClassifyIdList)
  965. }
  966. lenUser := len(req.UserIdList)
  967. if lenUser > 0 {
  968. condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) `
  969. pars = append(pars, req.UserIdList)
  970. }
  971. lenTradeList := len(req.TradeCodeList)
  972. if lenTradeList > 0 {
  973. condition += ` AND a.TRADE_CODE not in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  974. pars = append(pars, req.TradeCodeList)
  975. }
  976. } else {
  977. lenTradeList := len(req.TradeCodeList)
  978. if lenTradeList <= 0 {
  979. br.Msg = "请选择指标"
  980. br.ErrMsg = "请选择指标"
  981. return
  982. }
  983. if lenTradeList > 0 {
  984. condition += ` AND a.TRADE_CODE in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  985. pars = append(pars, req.TradeCodeList)
  986. }
  987. }
  988. list, err := models.GetEdbInfoList(condition, pars, 0, 0)
  989. if err != nil {
  990. br.Msg = "获取失败"
  991. br.ErrMsg = "获取失败,Err:" + err.Error()
  992. return
  993. }
  994. br.Data = list
  995. br.Msg = "校验成功"
  996. br.Ret = 200
  997. br.Success = true
  998. }
  999. // @router /target/edb/batch/del [post]
  1000. func (c *ManualEdbController) BatchDel() {
  1001. br := new(models.BaseResponse).Init()
  1002. defer func() {
  1003. if br.ErrMsg == "" {
  1004. br.IsSendEmail = false
  1005. }
  1006. c.Data["json"] = br
  1007. c.ServeJSON()
  1008. }()
  1009. sysUser := c.SysUser
  1010. if sysUser == nil {
  1011. br.Msg = "请登录"
  1012. br.ErrMsg = "请登录,SysUser Is Empty"
  1013. br.Ret = 408
  1014. return
  1015. }
  1016. deleteCache := true
  1017. cacheKey := "CACHE_EDB_INFO_BATCH_ADD_MANUAL_" + strconv.Itoa(sysUser.AdminId)
  1018. defer func() {
  1019. if deleteCache {
  1020. _ = utils.Rc.Delete(cacheKey)
  1021. }
  1022. }()
  1023. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1024. deleteCache = false
  1025. br.Msg = "系统处理中,请稍后重试!"
  1026. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  1027. return
  1028. }
  1029. var req models.BatchManualEdbReq
  1030. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1031. req.Keyword = strings.TrimSpace(req.Keyword)
  1032. var condition string
  1033. var pars []interface{}
  1034. condition += ` AND a.is_join_edb = ? `
  1035. pars = append(pars, 0)
  1036. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1037. classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId)
  1038. if err != nil {
  1039. br.Msg = "获取分类数据失败"
  1040. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  1041. return
  1042. }
  1043. num := len(classifyIdList)
  1044. if num > 0 {
  1045. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  1046. pars = append(pars, classifyIdList)
  1047. }
  1048. }
  1049. if req.ListAll {
  1050. if req.Keyword != "" {
  1051. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  1052. pars = utils.GetLikeKeywordPars(pars, req.Keyword, 2)
  1053. }
  1054. lenFrequency := len(req.FrequencyList)
  1055. if lenFrequency > 0 {
  1056. condition += ` AND a.frequency in (` + utils.GetOrmInReplace(lenFrequency) + `) `
  1057. pars = append(pars, req.FrequencyList)
  1058. }
  1059. lenClassify := len(req.ClassifyIdList)
  1060. if lenClassify > 0 {
  1061. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(lenClassify) + `) `
  1062. pars = append(pars, req.ClassifyIdList)
  1063. }
  1064. lenUser := len(req.UserIdList)
  1065. if lenUser > 0 {
  1066. condition += ` AND a.user_id in (` + utils.GetOrmInReplace(lenUser) + `) `
  1067. pars = append(pars, req.UserIdList)
  1068. }
  1069. lenTradeList := len(req.TradeCodeList)
  1070. if lenTradeList > 0 {
  1071. condition += ` AND a.TRADE_CODE not in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  1072. pars = append(pars, req.TradeCodeList)
  1073. }
  1074. } else {
  1075. lenTradeList := len(req.TradeCodeList)
  1076. if lenTradeList <= 0 {
  1077. br.Msg = "请选择指标"
  1078. br.ErrMsg = "请选择指标"
  1079. return
  1080. }
  1081. if lenTradeList > 0 {
  1082. condition += ` AND a.TRADE_CODE in (` + utils.GetOrmInReplace(lenTradeList) + `) `
  1083. pars = append(pars, req.TradeCodeList)
  1084. }
  1085. }
  1086. list, err := models.GetEdbInfoList(condition, pars, 0, 0)
  1087. if err != nil {
  1088. br.Msg = "删除失败"
  1089. br.ErrMsg = "删除失败,Err:" + err.Error()
  1090. return
  1091. }
  1092. {
  1093. codeList := make([]string, 0)
  1094. for _, v := range list {
  1095. codeList = append(codeList, v.TradeCode)
  1096. }
  1097. err = models.DelManualIndexByCodeList(codeList)
  1098. if err != nil {
  1099. br.Msg = "删除失败"
  1100. br.ErrMsg = "删除失败,Err:" + err.Error()
  1101. return
  1102. }
  1103. }
  1104. br.Msg = "删除成功"
  1105. br.Ret = 200
  1106. br.Success = true
  1107. br.IsAddLog = true
  1108. }
  1109. // @router /import/data [post]
  1110. func (c *ManualEdbController) ImportData() {
  1111. br := new(models.BaseResponse).Init()
  1112. defer func() {
  1113. c.Data["json"] = br
  1114. c.ServeJSON()
  1115. }()
  1116. sysUser := c.SysUser
  1117. if sysUser == nil {
  1118. br.Msg = "请重新登录"
  1119. return
  1120. }
  1121. file, _, err := c.GetFile("EntryFile")
  1122. if err != nil {
  1123. br.Msg = "获取文件失败"
  1124. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  1125. return
  1126. }
  1127. path := "./static/数据导入_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1128. defer file.Close()
  1129. err = c.SaveToFile("EntryFile", path)
  1130. if err != nil {
  1131. br.Msg = "文件保存失败"
  1132. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  1133. return
  1134. }
  1135. if utils.RunMode == "debug" {
  1136. defer os.Remove(path)
  1137. }
  1138. successCount, failCount, err, errMsg := data.ImportManualData(path, sysUser)
  1139. if err != nil {
  1140. br.Msg = errMsg
  1141. br.ErrMsg = err.Error()
  1142. return
  1143. }
  1144. resp := models.EdbdataImportResp{
  1145. SuccessCount: successCount,
  1146. FailCount: failCount,
  1147. }
  1148. if failCount > 0 {
  1149. if successCount == 0 {
  1150. resp.Status = -1
  1151. resp.Msg = "导入失败"
  1152. } else {
  1153. resp.Status = 1
  1154. resp.Msg = "存在部分导入失败"
  1155. }
  1156. } else {
  1157. resp.Status = 0
  1158. }
  1159. br.Msg = "导入成功"
  1160. br.Ret = 200
  1161. br.Success = true
  1162. br.Data = resp
  1163. }
  1164. // @router /target/edb/op/record/list [get]
  1165. func (c *ManualEdbController) RecordList() {
  1166. br := new(models.BaseResponse).Init()
  1167. defer func() {
  1168. c.Data["json"] = br
  1169. c.ServeJSON()
  1170. }()
  1171. sysUser := c.SysUser
  1172. if sysUser == nil {
  1173. br.Msg = "请重新登录"
  1174. return
  1175. }
  1176. pageSize, _ := c.GetInt("PageSize")
  1177. currentIndex, _ := c.GetInt("CurrentIndex")
  1178. var startSize int
  1179. if pageSize <= 0 {
  1180. pageSize = utils.PageSize20
  1181. }
  1182. if currentIndex <= 0 {
  1183. currentIndex = 1
  1184. }
  1185. startSize = utils.StartIndex(currentIndex, pageSize)
  1186. tradeCode := c.GetString("TradeCode")
  1187. if tradeCode == `` {
  1188. br.Msg = `请选择指标`
  1189. br.ErrMsg = `请选择指标`
  1190. br.IsSendEmail = false
  1191. return
  1192. }
  1193. total, list, err := models.GetEdbinfoOpRecordPageList(tradeCode, startSize, pageSize)
  1194. if err != nil {
  1195. br.Msg = "获取失败"
  1196. br.ErrMsg = "获取失败,Err:" + err.Error()
  1197. return
  1198. }
  1199. resp := models.EdbinfoOpRecordListResp{
  1200. List: list,
  1201. Paging: paging.GetPaging(currentIndex, pageSize, total),
  1202. }
  1203. br.Ret = 200
  1204. br.Success = true
  1205. br.Msg = "获取成功"
  1206. br.Data = resp
  1207. }