base_from_ths_hf.go 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/mgo"
  8. "eta/eta_api/services/data"
  9. "eta/eta_api/utils"
  10. "fmt"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. "github.com/shopspring/decimal"
  13. "go.mongodb.org/mongo-driver/bson"
  14. "sort"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // BaseFromThsHfController 同花顺高频数据
  20. type BaseFromThsHfController struct {
  21. controllers.BaseAuthController
  22. }
  23. // Search
  24. // @Title 新增指标-查询指标信息接口
  25. // @Description 新增指标-查询指标信息接口
  26. // @Param request body data_manage.ThsHfSearchEdbReq true "type json string"
  27. // @Success 200 {object} data_manage.ThsHfSearchEdbResp
  28. // @router /ths_hf/index/search [get]
  29. func (this *BaseFromThsHfController) Search() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. if br.ErrMsg == "" {
  33. br.IsSendEmail = false
  34. }
  35. this.Data["json"] = br
  36. this.ServeJSON()
  37. }()
  38. sysUser := this.SysUser
  39. if sysUser == nil {
  40. br.Msg = "请登录"
  41. br.ErrMsg = "请登录,SysUser Is Empty"
  42. br.Ret = 408
  43. return
  44. }
  45. var params data_manage.ThsHfSearchEdbReq
  46. if e := this.ParseForm(&params); e != nil {
  47. br.Msg = "参数解析失败"
  48. br.ErrMsg = fmt.Sprintf("参数解析失败, err: %v", e)
  49. return
  50. }
  51. params.StockCode = strings.TrimSpace(params.StockCode)
  52. if params.StockCode == "" {
  53. br.Msg = "请输入证券代码"
  54. return
  55. }
  56. stockCodes := strings.Split(params.StockCode, ",")
  57. if len(stockCodes) == 0 {
  58. br.Msg = "请输入证券代码"
  59. return
  60. }
  61. if len(stockCodes) > 10 {
  62. br.Msg = "最多输入10个证券代码"
  63. return
  64. }
  65. params.EdbCode = strings.TrimSpace(params.EdbCode)
  66. if params.EdbCode == "" {
  67. br.Msg = "请输入指标代码"
  68. return
  69. }
  70. edbCodes := strings.Split(params.EdbCode, ",")
  71. if len(edbCodes) == 0 {
  72. br.Msg = "请输入指标代码"
  73. return
  74. }
  75. if len(edbCodes) > 20 {
  76. br.Msg = "最多选择/输入20个指标代码"
  77. return
  78. }
  79. if params.StartTime == "" {
  80. br.Msg = "请选择起始时间"
  81. return
  82. }
  83. _, e := time.ParseInLocation(utils.FormatDateTime, params.StartTime, time.Local)
  84. if e != nil {
  85. br.Msg = "起始时间格式有误"
  86. br.ErrMsg = fmt.Sprintf("起始时间格式有误, %v", e)
  87. return
  88. }
  89. // 结束时间选填, 不填则为当前时间
  90. if params.EndTime != "" {
  91. _, e := time.ParseInLocation(utils.FormatDateTime, params.EndTime, time.Local)
  92. if e != nil {
  93. br.Msg = "截止时间格式有误"
  94. br.ErrMsg = fmt.Sprintf("截止时间格式有误, %v", e)
  95. return
  96. }
  97. }
  98. if params.EndTime == "" {
  99. params.EndTime = time.Now().Local().Format(utils.FormatDateTime)
  100. }
  101. if !utils.InArrayByInt(data_manage.ThsHfPeriodArr, params.Interval) {
  102. br.Msg = "时间周期有误"
  103. br.ErrMsg = fmt.Sprintf("时间周期有误, Interval: %d", params.Interval)
  104. return
  105. }
  106. if params.CPS != "" && !utils.InArrayByStr(data_manage.ThsHfCPSArr, params.CPS) {
  107. br.Msg = "复权方式有误"
  108. br.ErrMsg = fmt.Sprintf("复权方式有误, CPS: %s", params.CPS)
  109. return
  110. }
  111. if params.BaseDate != "" {
  112. _, e = time.ParseInLocation(utils.FormatDate, params.BaseDate, time.Local)
  113. if e != nil {
  114. br.Msg = "复权基点格式有误"
  115. br.ErrMsg = fmt.Sprintf("复权基点格式有误, %v", e)
  116. return
  117. }
  118. }
  119. if params.Fill != "" && !utils.InArrayByStr(data_manage.ThsHfFillArr, params.Fill) {
  120. br.Msg = "非交易间隔处理有误"
  121. br.ErrMsg = fmt.Sprintf("非交易间隔处理有误, Fill: %s", params.Fill)
  122. return
  123. }
  124. // 校验已入库的指标
  125. checkResp, indexExists, e := data.CheckExistThsHfEdb(stockCodes, edbCodes)
  126. if e != nil {
  127. br.Msg = "获取失败"
  128. br.ErrMsg = fmt.Sprintf("校验已存在的高频指标失败, %v", e)
  129. return
  130. }
  131. if len(checkResp.ExistIndex) > 0 && checkResp.ExistAll {
  132. br.Msg = "指标均已存在"
  133. return
  134. }
  135. resp := make([]*data_manage.ThsHfSearchEdbResp, 0)
  136. // 请求API获取数据
  137. indexes, e := data.GetEdbDataThsHf(params)
  138. if e != nil {
  139. br.Msg = "未搜索到指标"
  140. br.ErrMsg = fmt.Sprintf("获取高频指标失败, %v", e)
  141. return
  142. }
  143. if len(indexes) == 0 {
  144. br.Msg = "未搜索到指标"
  145. return
  146. }
  147. for _, v := range indexes {
  148. // 忽略掉校验出来的已入库指标
  149. k := fmt.Sprintf("%s-%s", v.StockCode, v.EdbCode)
  150. if indexExists[k] {
  151. continue
  152. }
  153. // 默认指标名称
  154. suffix := data_manage.ThsHfEdbCodeCn[v.EdbCode]
  155. if suffix == "" {
  156. suffix = v.EdbCode
  157. }
  158. indexName := fmt.Sprintf("%s%dm%s", v.StockCode, params.Interval, suffix)
  159. item := new(data_manage.ThsHfSearchEdbResp)
  160. item.StockCode = v.StockCode
  161. item.EdbCode = v.EdbCode
  162. item.IndexName = indexName
  163. item.Frequency = params.Interval
  164. // 搜索只展示100条数据
  165. var limit int
  166. sort.Slice(v.IndexData, func(i, j int) bool {
  167. return v.IndexData[i].DataTime.After(v.IndexData[j].DataTime)
  168. })
  169. for _, d := range v.IndexData {
  170. if limit > 100 {
  171. break
  172. }
  173. limit += 1
  174. strVal := decimal.NewFromFloat(d.Value).Round(4).String()
  175. item.IndexData = append(item.IndexData, data_manage.ThsHfSearchEdbData{
  176. DataTime: d.DataTime.Format(utils.FormatDateTime),
  177. Value: strVal,
  178. })
  179. }
  180. resp = append(resp, item)
  181. }
  182. br.Data = resp
  183. br.Ret = 200
  184. br.Success = true
  185. br.Msg = "获取成功"
  186. }
  187. // ExistCheck
  188. // @Title 新增指标-指标存在校验
  189. // @Description 新增指标-指标存在校验
  190. // @Param request body data_manage.ThsHfSearchEdbReq true "type json string"
  191. // @Success 200 {object} data_manage.ThsHfExistCheckResp
  192. // @router /ths_hf/index/exist_check [get]
  193. func (this *BaseFromThsHfController) ExistCheck() {
  194. br := new(models.BaseResponse).Init()
  195. defer func() {
  196. if br.ErrMsg == "" {
  197. br.IsSendEmail = false
  198. }
  199. this.Data["json"] = br
  200. this.ServeJSON()
  201. }()
  202. sysUser := this.SysUser
  203. if sysUser == nil {
  204. br.Msg = "请登录"
  205. br.ErrMsg = "请登录,SysUser Is Empty"
  206. br.Ret = 408
  207. return
  208. }
  209. var params data_manage.ThsHfSearchEdbReq
  210. if e := this.ParseForm(&params); e != nil {
  211. br.Msg = "参数解析失败"
  212. br.ErrMsg = fmt.Sprintf("参数解析失败, err: %v", e)
  213. return
  214. }
  215. params.StockCode = strings.TrimSpace(params.StockCode)
  216. if params.StockCode == "" {
  217. br.Msg = "请输入证券代码"
  218. return
  219. }
  220. stockCodes := strings.Split(params.StockCode, ",")
  221. if len(stockCodes) == 0 {
  222. br.Msg = "请输入证券代码"
  223. return
  224. }
  225. params.EdbCode = strings.TrimSpace(params.EdbCode)
  226. if params.EdbCode == "" {
  227. br.Msg = "请输入指标代码"
  228. return
  229. }
  230. edbCodes := strings.Split(params.EdbCode, ",")
  231. if len(edbCodes) == 0 {
  232. br.Msg = "请输入指标代码"
  233. return
  234. }
  235. // 校验已存在的高频指标
  236. resp, _, e := data.CheckExistThsHfEdb(stockCodes, edbCodes)
  237. if e != nil {
  238. br.Msg = "获取失败"
  239. br.ErrMsg = fmt.Sprintf("校验已存在的高频指标失败, %v", e)
  240. return
  241. }
  242. br.Data = resp
  243. br.Ret = 200
  244. br.Success = true
  245. br.Msg = "获取成功"
  246. }
  247. // List
  248. // @Title 列表
  249. // @Description 列表
  250. // @Param request body data_manage.ThsHfIndexListForm true "type json string"
  251. // @Success 200 {object} data_manage.ThsHfIndexPageListResp
  252. // @router /ths_hf/index/list [get]
  253. func (this *BaseFromThsHfController) List() {
  254. br := new(models.BaseResponse).Init()
  255. defer func() {
  256. if br.ErrMsg == "" {
  257. br.IsSendEmail = false
  258. }
  259. this.Data["json"] = br
  260. this.ServeJSON()
  261. }()
  262. sysUser := this.SysUser
  263. if sysUser == nil {
  264. br.Msg = "请登录"
  265. br.ErrMsg = "请登录,SysUser Is Empty"
  266. br.Ret = 408
  267. return
  268. }
  269. var params data_manage.ThsHfIndexListForm
  270. if e := this.ParseForm(&params); e != nil {
  271. br.Msg = "参数解析失败"
  272. br.ErrMsg = fmt.Sprintf("参数解析失败, err: %v", e)
  273. return
  274. }
  275. if params.SortField > 0 && !utils.InArrayByInt([]int{1, 2, 3, 4}, params.SortField) {
  276. br.Msg = "参数有误"
  277. br.ErrMsg = fmt.Sprintf("参数有误, SortField: %d", params.SortField)
  278. return
  279. }
  280. if params.SortType > 0 && !utils.InArrayByInt([]int{1, 2}, params.SortType) {
  281. br.Msg = "参数有误"
  282. br.ErrMsg = fmt.Sprintf("参数有误, SortType: %d", params.SortType)
  283. return
  284. }
  285. resp := new(data_manage.ThsHfIndexPageListResp)
  286. resp.List = make([]*data_manage.BaseFromThsHfIndexItem, 0)
  287. // 查询所有分类-分类查询/分类完整路径用
  288. classifyOb := new(data_manage.BaseFromThsHfClassify)
  289. //classifies := make([]*data_manage.BaseFromThsHfClassify, 0)
  290. classifyIdItem := make(map[int]*data_manage.BaseFromThsHfClassify)
  291. {
  292. list, e := classifyOb.GetItemsByCondition(``, make([]interface{}, 0), []string{classifyOb.Cols().PrimaryId, classifyOb.Cols().ClassifyName, classifyOb.Cols().ClassifyNameEn, classifyOb.Cols().LevelPath}, "")
  293. if e != nil {
  294. br.Msg = "获取失败"
  295. br.ErrMsg = fmt.Sprintf("获取分类列表失败, %v", e)
  296. return
  297. }
  298. for _, v := range list {
  299. classifyIdItem[v.BaseFromThsHfClassifyId] = v
  300. }
  301. //classifies = list
  302. }
  303. // 筛选项
  304. var (
  305. cond string
  306. pars []interface{}
  307. listOrder string
  308. )
  309. indexOb := new(data_manage.BaseFromThsHfIndex)
  310. {
  311. // 分类
  312. if params.ClassifyId != "" {
  313. classifyIdArr := strings.Split(params.ClassifyId, ",")
  314. classifyIds := make([]int, 0)
  315. for _, v := range classifyIdArr {
  316. t, _ := strconv.Atoi(v)
  317. if t > 0 {
  318. classifyIds = append(classifyIds, t)
  319. }
  320. }
  321. if len(classifyIds) == 0 {
  322. page := paging.GetPaging(params.CurrentIndex, params.PageSize, 0)
  323. resp.Paging = page
  324. br.Ret = 200
  325. br.Success = true
  326. br.Msg = "获取成功"
  327. return
  328. }
  329. cond += fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().BaseFromThsHfClassifyId, utils.GetOrmInReplace(len(classifyIds)))
  330. pars = append(pars, classifyIds)
  331. //// 不包含子分类
  332. //if len(classifyIds) > 0 && !params.IncludeChild {
  333. // cond += fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().BaseFromThsHfClassifyId, utils.GetOrmInReplace(len(classifyIds)))
  334. // pars = append(pars, classifyIds)
  335. //}
  336. //
  337. //// 包含子分类
  338. //if len(classifyIds) > 0 && params.IncludeChild {
  339. // queryClassifyIds := make([]int, 0)
  340. // queryClassifyExist := make(map[int]bool)
  341. //
  342. // for _, v := range classifyIds {
  343. // // 遍历所有分类从LevelPath中找含有查询分类ID的...=_=!
  344. // for _, cv := range classifies {
  345. // if queryClassifyExist[cv.BaseFromThsHfClassifyId] {
  346. // continue
  347. // }
  348. // if cv.LevelPath == "" {
  349. // continue
  350. // }
  351. // strArr := strings.Split(cv.LevelPath, ",")
  352. // if len(strArr) == 0 {
  353. // continue
  354. // }
  355. // for _, sv := range strArr {
  356. // tv, _ := strconv.Atoi(sv)
  357. // if tv == v {
  358. // queryClassifyIds = append(queryClassifyIds, cv.BaseFromThsHfClassifyId)
  359. // queryClassifyExist[cv.BaseFromThsHfClassifyId] = true
  360. // break
  361. // }
  362. // }
  363. // }
  364. // }
  365. //
  366. // if len(queryClassifyIds) == 0 {
  367. // page := paging.GetPaging(params.CurrentIndex, params.PageSize, 0)
  368. // resp.Paging = page
  369. // br.Ret = 200
  370. // br.Success = true
  371. // br.Msg = "获取成功"
  372. // return
  373. // }
  374. // cond += fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().BaseFromThsHfClassifyId, utils.GetOrmInReplace(len(queryClassifyIds)))
  375. // pars = append(pars, queryClassifyIds)
  376. //}
  377. }
  378. if params.Frequency != "" {
  379. frequencyArr := strings.Split(params.Frequency, ",")
  380. if len(frequencyArr) > 0 {
  381. cond += fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().Frequency, utils.GetOrmInReplace(len(frequencyArr)))
  382. pars = append(pars, frequencyArr)
  383. }
  384. }
  385. if params.SysAdminId != "" {
  386. adminIdArr := strings.Split(params.SysAdminId, ",")
  387. adminIds := make([]int, 0)
  388. for _, v := range adminIdArr {
  389. t, _ := strconv.Atoi(v)
  390. if t > 0 {
  391. adminIds = append(adminIds, t)
  392. }
  393. }
  394. if len(adminIds) > 0 {
  395. cond += fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().SysUserId, utils.GetOrmInReplace(len(adminIds)))
  396. pars = append(pars, adminIds)
  397. }
  398. }
  399. params.Keywords = strings.TrimSpace(params.Keywords)
  400. if params.Keywords != "" {
  401. cond += fmt.Sprintf(" AND (%s LIKE ? OR %s LIKE ?)", indexOb.Cols().IndexCode, indexOb.Cols().IndexName)
  402. kw := fmt.Sprint("%", params.Keywords, "%")
  403. pars = append(pars, kw, kw)
  404. }
  405. // 排序
  406. if params.SortField > 0 && params.SortType > 0 {
  407. fieldMap := map[int]string{1: indexOb.Cols().StartDate, 2: indexOb.Cols().EndDate, 3: indexOb.Cols().ModifyTime, 4: indexOb.Cols().LatestValue}
  408. typeMap := map[int]string{1: "ASC", 2: "DESC"}
  409. listOrder = fmt.Sprintf("%s %s", fieldMap[params.SortField], typeMap[params.SortType])
  410. }
  411. }
  412. // 列表总计
  413. total, e := indexOb.GetCountByCondition(cond, pars)
  414. if e != nil {
  415. br.Msg = "获取失败"
  416. br.ErrMsg = fmt.Sprintf("获取指标总数失败, %v", e)
  417. return
  418. }
  419. if total <= 0 {
  420. page := paging.GetPaging(params.CurrentIndex, params.PageSize, 0)
  421. resp.Paging = page
  422. br.Data = resp
  423. br.Ret = 200
  424. br.Success = true
  425. br.Msg = "获取成功"
  426. return
  427. }
  428. // 分页查询
  429. var startSize int
  430. if params.PageSize <= 0 {
  431. params.PageSize = utils.PageSize20
  432. }
  433. if params.CurrentIndex <= 0 {
  434. params.CurrentIndex = 1
  435. }
  436. startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
  437. items, e := indexOb.GetPageItemsByCondition(cond, pars, []string{}, listOrder, startSize, params.PageSize)
  438. if e != nil {
  439. br.Msg = "获取失败"
  440. br.ErrMsg = fmt.Sprintf("获取指标列表失败, %v", e)
  441. return
  442. }
  443. for _, v := range items {
  444. t := v.Format2Item()
  445. // 分类完整路径
  446. classify := classifyIdItem[v.BaseFromThsHfClassifyId]
  447. levelArr := make([]string, 0)
  448. if classify != nil && classify.LevelPath != "" {
  449. arr := strings.Split(classify.LevelPath, ",")
  450. for _, a := range arr {
  451. i, _ := strconv.Atoi(a)
  452. if classifyIdItem[i] != nil {
  453. if this.Lang == utils.EnLangVersion {
  454. levelArr = append(levelArr, classifyIdItem[i].ClassifyNameEn)
  455. } else {
  456. levelArr = append(levelArr, classifyIdItem[i].ClassifyName)
  457. }
  458. }
  459. }
  460. }
  461. t.ClassifyPath = strings.Join(levelArr, "/")
  462. resp.List = append(resp.List, t)
  463. }
  464. page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
  465. resp.Paging = page
  466. br.Data = resp
  467. br.Ret = 200
  468. br.Success = true
  469. br.Msg = "获取成功"
  470. }
  471. // Add
  472. // @Title 新增指标
  473. // @Description 新增指标
  474. // @Param request body data_manage.ThsHfAddEdbReq true "type json string"
  475. // @Success 200 string "操作成功"
  476. // @router /ths_hf/index/add [post]
  477. func (this *BaseFromThsHfController) Add() {
  478. br := new(models.BaseResponse).Init()
  479. defer func() {
  480. if br.ErrMsg == "" {
  481. br.IsSendEmail = false
  482. }
  483. this.Data["json"] = br
  484. this.ServeJSON()
  485. }()
  486. sysUser := this.SysUser
  487. if sysUser == nil {
  488. br.Msg = "请登录"
  489. br.ErrMsg = "请登录,SysUser Is Empty"
  490. br.Ret = 408
  491. return
  492. }
  493. var params data_manage.ThsHfAddEdbReq
  494. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &params); e != nil {
  495. br.Msg = "参数解析异常"
  496. br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
  497. return
  498. }
  499. if params.StartTime == "" {
  500. br.Msg = "请选择起始时间"
  501. return
  502. }
  503. _, e := time.ParseInLocation(utils.FormatDateTime, params.StartTime, time.Local)
  504. if e != nil {
  505. br.Msg = "起始时间格式有误"
  506. br.ErrMsg = fmt.Sprintf("起始时间格式有误, %v", e)
  507. return
  508. }
  509. if params.EndTime != "" {
  510. _, e := time.ParseInLocation(utils.FormatDateTime, params.EndTime, time.Local)
  511. if e != nil {
  512. br.Msg = "截止时间格式有误"
  513. br.ErrMsg = fmt.Sprintf("截止时间格式有误, %v", e)
  514. return
  515. }
  516. }
  517. if !utils.InArrayByInt(data_manage.ThsHfPeriodArr, params.Interval) {
  518. br.Msg = "时间周期有误"
  519. br.ErrMsg = fmt.Sprintf("时间周期有误, Interval: %d", params.Interval)
  520. return
  521. }
  522. if params.CPS != "" && !utils.InArrayByStr(data_manage.ThsHfCPSArr, params.CPS) {
  523. br.Msg = "复权方式有误"
  524. br.ErrMsg = fmt.Sprintf("复权方式有误, CPS: %s", params.CPS)
  525. return
  526. }
  527. if params.BaseDate != "" {
  528. _, e = time.ParseInLocation(utils.FormatDate, params.BaseDate, time.Local)
  529. if e != nil {
  530. br.Msg = "复权基点格式有误"
  531. br.ErrMsg = fmt.Sprintf("复权基点格式有误, %v", e)
  532. return
  533. }
  534. }
  535. if params.Fill != "" && !utils.InArrayByStr(data_manage.ThsHfFillArr, params.Fill) {
  536. br.Msg = "非交易间隔处理有误"
  537. br.ErrMsg = fmt.Sprintf("非交易间隔处理有误, Fill: %s", params.Fill)
  538. return
  539. }
  540. if len(params.IndexList) == 0 {
  541. br.Msg = "请选择指标"
  542. return
  543. }
  544. formExist := make(map[string]bool)
  545. indexNames := make([]string, 0)
  546. classifyIds := make([]int, 0)
  547. for _, v := range params.IndexList {
  548. if v.ClassifyId <= 0 {
  549. br.Msg = "请选择分类"
  550. return
  551. }
  552. if !utils.InArrayByInt(classifyIds, v.ClassifyId) {
  553. classifyIds = append(classifyIds, v.ClassifyId)
  554. }
  555. if v.Unit == "" {
  556. br.Msg = "请输入单位"
  557. return
  558. }
  559. v.IndexName = strings.TrimSpace(v.IndexName)
  560. if v.IndexName == "" {
  561. br.Msg = "请输入指标名称"
  562. return
  563. }
  564. if formExist[v.IndexName] {
  565. br.Msg = "指标名称重复, 请重新输入"
  566. return
  567. }
  568. formExist[v.IndexName] = true
  569. indexNames = append(indexNames, v.IndexName)
  570. }
  571. // 校验指标分类
  572. classifyOb := new(data_manage.BaseFromThsHfClassify)
  573. {
  574. cond := fmt.Sprintf(` AND %s IN (%s)`, classifyOb.Cols().PrimaryId, utils.GetOrmInReplace(len(classifyIds)))
  575. pars := make([]interface{}, 0)
  576. pars = append(pars, classifyIds)
  577. list, e := classifyOb.GetItemsByCondition(cond, pars, []string{classifyOb.Cols().PrimaryId, classifyOb.Cols().ClassifyName}, "")
  578. if e != nil {
  579. br.Msg = "操作失败"
  580. br.ErrMsg = fmt.Sprintf("查询分类失败, %v", e)
  581. return
  582. }
  583. classifyMap := make(map[int]*data_manage.BaseFromThsHfClassify)
  584. for _, v := range list {
  585. classifyMap[v.BaseFromThsHfClassifyId] = v
  586. }
  587. for _, v := range params.IndexList {
  588. t := classifyMap[v.ClassifyId]
  589. if t == nil {
  590. br.Msg = fmt.Sprintf("%s分类不存在, 请重新选择或刷新页面", t.ClassifyName)
  591. return
  592. }
  593. }
  594. }
  595. // 校验指标名称
  596. indexOb := new(data_manage.BaseFromThsHfIndex)
  597. {
  598. cond := fmt.Sprintf(` AND %s IN (%s)`, indexOb.Cols().IndexName, utils.GetOrmInReplace(len(indexNames)))
  599. pars := make([]interface{}, 0)
  600. pars = append(pars, indexNames)
  601. list, e := indexOb.GetItemsByCondition(cond, pars, []string{indexOb.Cols().IndexName}, "")
  602. if e != nil {
  603. br.Msg = "操作失败"
  604. br.ErrMsg = fmt.Sprintf("查询指标名称失败, %v", e)
  605. return
  606. }
  607. if len(list) > 0 {
  608. tips := "以下指标名称重复, 请重新输入: \n"
  609. for _, v := range list {
  610. tips += fmt.Sprintf("%s\n", v.IndexName)
  611. }
  612. br.Msg = tips
  613. return
  614. }
  615. }
  616. // 新增指标
  617. for _, v := range params.IndexList {
  618. var req data_manage.ThsHfBaseAddReq
  619. req.StartTime = params.StartTime
  620. req.EndTime = params.EndTime
  621. req.Interval = params.Interval
  622. req.Fill = params.Fill
  623. req.CPS = params.CPS
  624. req.BaseDate = params.BaseDate
  625. req.SysAdminId = sysUser.AdminId
  626. req.SysAdminName = sysUser.RealName
  627. req.ClassifyId = v.ClassifyId
  628. req.Unit = v.Unit
  629. req.IndexName = v.IndexName
  630. req.Frequency = v.Frequency
  631. req.StockCode = v.StockCode
  632. req.EdbCode = v.EdbCode
  633. _, e = data.BaseAddThsHf(req)
  634. if e != nil {
  635. utils.FileLog.Info(fmt.Sprintf("BaseAddThsHf err: %v", e))
  636. continue
  637. }
  638. }
  639. br.Ret = 200
  640. br.Success = true
  641. br.Msg = "操作成功"
  642. }
  643. // Edit
  644. // @Title 编辑指标
  645. // @Description 编辑指标
  646. // @Param request body data_manage.ThsHfIndexEditReq true "type json string"
  647. // @Success 200 string "操作成功"
  648. // @router /ths_hf/index/edit [post]
  649. func (this *BaseFromThsHfController) Edit() {
  650. br := new(models.BaseResponse).Init()
  651. defer func() {
  652. if br.ErrMsg == "" {
  653. br.IsSendEmail = false
  654. }
  655. this.Data["json"] = br
  656. this.ServeJSON()
  657. }()
  658. sysUser := this.SysUser
  659. if sysUser == nil {
  660. br.Msg = "请登录"
  661. br.ErrMsg = "请登录,SysUser Is Empty"
  662. br.Ret = 408
  663. return
  664. }
  665. var params data_manage.ThsHfIndexEditReq
  666. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &params); e != nil {
  667. br.Msg = "参数解析异常"
  668. br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
  669. return
  670. }
  671. if params.IndexId <= 0 {
  672. br.Msg = "参数有误"
  673. br.ErrMsg = fmt.Sprintf("参数有误, IndexId: %d", params.IndexId)
  674. return
  675. }
  676. params.IndexName = strings.TrimSpace(params.IndexName)
  677. if params.IndexName == "" {
  678. br.Msg = "请输入指标名称"
  679. return
  680. }
  681. if params.ClassifyId <= 0 {
  682. br.Msg = "请选择分类"
  683. return
  684. }
  685. params.Unit = strings.TrimSpace(params.Unit)
  686. if params.Unit == "" {
  687. br.Msg = "请输入单位"
  688. return
  689. }
  690. indexOb := new(data_manage.BaseFromThsHfIndex)
  691. item, e := indexOb.GetItemById(params.IndexId)
  692. if e != nil {
  693. if e.Error() == utils.ErrNoRow() {
  694. br.Msg = "指标不存在, 请刷新页面"
  695. return
  696. }
  697. br.Msg = "操作失败"
  698. br.ErrMsg = fmt.Sprintf("获取指标失败, %v", e)
  699. return
  700. }
  701. classifyOb := new(data_manage.BaseFromThsHfClassify)
  702. _, e = classifyOb.GetItemById(params.ClassifyId)
  703. if e != nil {
  704. br.Msg = "分类有误"
  705. br.ErrMsg = fmt.Sprintf("分类信息有误, %v", e)
  706. return
  707. }
  708. // 重名验证
  709. {
  710. cond := fmt.Sprintf(" AND %s = ? AND %s <> ?", indexOb.Cols().IndexName, indexOb.Cols().PrimaryId)
  711. pars := make([]interface{}, 0)
  712. pars = append(pars, params.IndexName, params.IndexId)
  713. count, e := indexOb.GetCountByCondition(cond, pars)
  714. if e != nil {
  715. br.Msg = "操作失败"
  716. br.ErrMsg = fmt.Sprintf("获取重名指标失败, %v", e)
  717. return
  718. }
  719. if count > 0 {
  720. br.Msg = "指标名称已存在, 请重新输入"
  721. return
  722. }
  723. }
  724. item.IndexName = params.IndexName
  725. item.BaseFromThsHfClassifyId = params.ClassifyId
  726. item.Unit = params.Unit
  727. item.ModifyTime = time.Now().Local()
  728. updateCols := []string{item.Cols().IndexName, item.Cols().BaseFromThsHfClassifyId, item.Cols().Unit, item.Cols().ModifyTime}
  729. if e = item.Update(updateCols); e != nil {
  730. br.Msg = "操作失败"
  731. br.ErrMsg = fmt.Sprintf("更新指标信息失败, %v", e)
  732. return
  733. }
  734. br.Ret = 200
  735. br.Success = true
  736. br.Msg = "操作成功"
  737. }
  738. // Detail
  739. // @Title 详情
  740. // @Description 详情
  741. // @Param IndexId query int true "指标ID"
  742. // @Param DataDate query string false "数据日期"
  743. // @Success 200 {object} data_manage.ThsHfSearchEdbResp
  744. // @router /ths_hf/index/detail [get]
  745. func (this *BaseFromThsHfController) Detail() {
  746. br := new(models.BaseResponse).Init()
  747. defer func() {
  748. if br.ErrMsg == "" {
  749. br.IsSendEmail = false
  750. }
  751. this.Data["json"] = br
  752. this.ServeJSON()
  753. }()
  754. sysUser := this.SysUser
  755. if sysUser == nil {
  756. br.Msg = "请登录"
  757. br.ErrMsg = "请登录,SysUser Is Empty"
  758. br.Ret = 408
  759. return
  760. }
  761. indexId, _ := this.GetInt("IndexId")
  762. if indexId <= 0 {
  763. br.Msg = "参数有误"
  764. br.ErrMsg = fmt.Sprintf("参数有误, IndexId: %d", indexId)
  765. return
  766. }
  767. dataDate := this.GetString("DataDate")
  768. if dataDate != "" {
  769. _, e := time.Parse(utils.FormatDate, dataDate)
  770. if e != nil {
  771. br.Msg = "数据日期格式有误"
  772. br.ErrMsg = fmt.Sprintf("数据日期格式有误, DataDate: %s", dataDate)
  773. return
  774. }
  775. }
  776. indexOb := new(data_manage.BaseFromThsHfIndex)
  777. item, e := indexOb.GetItemById(indexId)
  778. if e != nil {
  779. if e.Error() == utils.ErrNoRow() {
  780. br.Msg = "指标不存在, 请刷新页面"
  781. return
  782. }
  783. br.Msg = "获取失败"
  784. br.ErrMsg = fmt.Sprintf("获取指标失败, %v", e)
  785. return
  786. }
  787. indexItem := item.Format2Item()
  788. if item.EndDate.IsZero() {
  789. item.EndDate = time.Now()
  790. }
  791. // 默认取有数据的最新日期
  792. if dataDate == "" {
  793. dataDate = item.EndDate.Format(utils.FormatDate)
  794. }
  795. startTime := fmt.Sprintf("%s 00:00:00", dataDate)
  796. endTime := fmt.Sprintf("%s 23:59:59", dataDate)
  797. // 获取数据
  798. dataList, e := data.GetThsHfBaseIndexData(indexItem.IndexCode, startTime, endTime)
  799. if e != nil {
  800. br.Msg = "获取失败"
  801. br.ErrMsg = fmt.Sprintf("获取指标数据失败, %v", e)
  802. return
  803. }
  804. type DetailResp struct {
  805. Index *data_manage.BaseFromThsHfIndexItem
  806. DataDate string `description:"数据日期"`
  807. DataList []*data_manage.BaseFromThsHfDataItem
  808. }
  809. resp := new(DetailResp)
  810. resp.Index = indexItem
  811. resp.DataDate = dataDate
  812. resp.DataList = dataList
  813. br.Data = resp
  814. br.Ret = 200
  815. br.Success = true
  816. br.Msg = "获取成功"
  817. }
  818. // Refresh
  819. // @Title 刷新指标
  820. // @Description 刷新指标
  821. // @Param request body data_manage.ThsHfIndexOptReq true "type json string"
  822. // @Success 200 string "操作成功"
  823. // @router /ths_hf/index/refresh [post]
  824. func (this *BaseFromThsHfController) Refresh() {
  825. br := new(models.BaseResponse).Init()
  826. defer func() {
  827. if br.ErrMsg == "" {
  828. br.IsSendEmail = false
  829. }
  830. this.Data["json"] = br
  831. this.ServeJSON()
  832. }()
  833. sysUser := this.SysUser
  834. if sysUser == nil {
  835. br.Msg = "请登录"
  836. br.ErrMsg = "请登录,SysUser Is Empty"
  837. br.Ret = 408
  838. return
  839. }
  840. var params data_manage.ThsHfIndexOptReq
  841. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &params); e != nil {
  842. br.Msg = "参数解析异常"
  843. br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
  844. return
  845. }
  846. if params.IndexId <= 0 {
  847. br.Msg = "参数有误"
  848. br.ErrMsg = fmt.Sprintf("参数有误, IndexId: %d", params.IndexId)
  849. return
  850. }
  851. indexOb := new(data_manage.BaseFromThsHfIndex)
  852. _, e := indexOb.GetItemById(params.IndexId)
  853. if e != nil {
  854. if e.Error() == utils.ErrNoRow() {
  855. br.Msg = "指标不存在, 请刷新页面"
  856. return
  857. }
  858. br.Msg = "操作失败"
  859. br.ErrMsg = fmt.Sprintf("获取指标失败, %v", e)
  860. return
  861. }
  862. // 指标刷新逻辑
  863. indexIds := []int{params.IndexId}
  864. _, e = data.RefreshBaseThsHfIndex(indexIds, 1)
  865. if e != nil {
  866. br.Msg = "刷新失败"
  867. br.ErrMsg = fmt.Sprintf("刷新指标失败, %v", e)
  868. return
  869. }
  870. br.Ret = 200
  871. br.Success = true
  872. br.Msg = "操作成功"
  873. }
  874. // Remove
  875. // @Title 删除指标
  876. // @Description 删除指标
  877. // @Param request body data_manage.ThsHfIndexOptReq true "type json string"
  878. // @Success 200 string "操作成功"
  879. // @router /ths_hf/index/remove [post]
  880. func (this *BaseFromThsHfController) Remove() {
  881. br := new(models.BaseResponse).Init()
  882. defer func() {
  883. if br.ErrMsg == "" {
  884. br.IsSendEmail = false
  885. }
  886. this.Data["json"] = br
  887. this.ServeJSON()
  888. }()
  889. sysUser := this.SysUser
  890. if sysUser == nil {
  891. br.Msg = "请登录"
  892. br.ErrMsg = "请登录,SysUser Is Empty"
  893. br.Ret = 408
  894. return
  895. }
  896. var params data_manage.ThsHfIndexOptReq
  897. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &params); e != nil {
  898. br.Msg = "参数解析异常"
  899. br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
  900. return
  901. }
  902. if params.IndexId <= 0 {
  903. br.Msg = "参数有误"
  904. br.ErrMsg = fmt.Sprintf("参数有误, IndexId: %d", params.IndexId)
  905. return
  906. }
  907. indexOb := new(data_manage.BaseFromThsHfIndex)
  908. item, e := indexOb.GetItemById(params.IndexId)
  909. if e != nil {
  910. if e.Error() == utils.ErrNoRow() {
  911. br.Ret = 200
  912. br.Success = true
  913. br.Msg = "操作成功"
  914. return
  915. }
  916. br.Msg = "操作失败"
  917. br.ErrMsg = fmt.Sprintf("获取指标失败, %v", e)
  918. return
  919. }
  920. // 删除校验, 指标库存在不可删除
  921. edbMappingOb := new(data_manage.BaseFromEdbMapping)
  922. {
  923. cond := fmt.Sprintf(" AND %s = ?", edbMappingOb.Cols().BaseIndexCode)
  924. pars := make([]interface{}, 0)
  925. pars = append(pars, item.IndexCode)
  926. count, e := edbMappingOb.GetCountByCondition(cond, pars)
  927. if e != nil {
  928. br.Msg = "操作失败"
  929. br.ErrMsg = fmt.Sprintf("获取源指标关联失败, %v", e)
  930. return
  931. }
  932. if count > 0 {
  933. br.Msg = "指标已被引用, 不允许删除"
  934. return
  935. }
  936. }
  937. if e = item.Remove(); e != nil {
  938. br.Msg = "操作失败"
  939. br.ErrMsg = fmt.Sprintf("删除指标失败, %v", e)
  940. return
  941. }
  942. if utils.UseMongo {
  943. mogDataObj := mgo.BaseFromThsHfData{}
  944. if e = mogDataObj.RemoveMany(bson.M{"index_code": item.IndexCode}); e != nil {
  945. br.Msg = "操作失败"
  946. br.ErrMsg = fmt.Sprintf("删除指标数据失败-Mgo, %v", e)
  947. return
  948. }
  949. } else {
  950. dataOb := new(data_manage.BaseFromThsHfData)
  951. cond := fmt.Sprintf(" %s = ?", dataOb.Cols().BaseFromThsHfIndexId)
  952. pars := make([]interface{}, 0)
  953. pars = append(pars, params.IndexId)
  954. if e = dataOb.RemoveByCondition(cond, pars); e != nil {
  955. br.Msg = "操作失败"
  956. br.ErrMsg = fmt.Sprintf("删除指标数据失败, %v", e)
  957. return
  958. }
  959. }
  960. br.Ret = 200
  961. br.Success = true
  962. br.Msg = "操作成功"
  963. }
  964. // ListChoice
  965. // @Title 列表选择
  966. // @Description 列表选择
  967. // @Param request body data_manage.ThsHfIndexMultiOptReq true "type json string"
  968. // @Success 200 string "获取成功"
  969. // @router /ths_hf/index/list_choice [get]
  970. func (this *BaseFromThsHfController) ListChoice() {
  971. br := new(models.BaseResponse).Init()
  972. defer func() {
  973. if br.ErrMsg == "" {
  974. br.IsSendEmail = false
  975. }
  976. this.Data["json"] = br
  977. this.ServeJSON()
  978. }()
  979. sysUser := this.SysUser
  980. if sysUser == nil {
  981. br.Msg = "请登录"
  982. br.ErrMsg = "请登录,SysUser Is Empty"
  983. br.Ret = 408
  984. return
  985. }
  986. var params data_manage.ThsHfIndexListChoiceReq
  987. if e := this.ParseForm(&params); e != nil {
  988. br.Msg = "参数解析失败"
  989. br.ErrMsg = fmt.Sprintf("参数解析失败, err: %v", e)
  990. return
  991. }
  992. var listIds []int
  993. if params.ListIds != "" {
  994. strArr := strings.Split(params.ListIds, ",")
  995. for _, v := range strArr {
  996. t, _ := strconv.Atoi(v)
  997. if t > 0 {
  998. listIds = append(listIds, t)
  999. }
  1000. }
  1001. }
  1002. var (
  1003. cond string
  1004. pars []interface{}
  1005. )
  1006. indexOb := new(data_manage.BaseFromThsHfIndex)
  1007. resp := make([]*data_manage.ThsHfIndexListChoiceItem, 0)
  1008. // 非列表全选
  1009. if !params.SelectAll {
  1010. if len(listIds) > 0 {
  1011. cond += fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().PrimaryId, utils.GetOrmInReplace(len(listIds)))
  1012. pars = append(pars, listIds)
  1013. }
  1014. }
  1015. // 列表全选, 根据条件筛选列表并过滤params.ListIds中选择的ID
  1016. if params.SelectAll {
  1017. // 查询所有分类-分类查询用
  1018. classifyOb := new(data_manage.BaseFromThsHfClassify)
  1019. classifies := make([]*data_manage.BaseFromThsHfClassify, 0)
  1020. classifyIdItem := make(map[int]*data_manage.BaseFromThsHfClassify)
  1021. {
  1022. list, e := classifyOb.GetItemsByCondition(``, make([]interface{}, 0), []string{classifyOb.Cols().PrimaryId, classifyOb.Cols().ClassifyName, classifyOb.Cols().ClassifyNameEn, classifyOb.Cols().LevelPath}, "")
  1023. if e != nil {
  1024. br.Msg = "获取失败"
  1025. br.ErrMsg = fmt.Sprintf("获取分类列表失败, %v", e)
  1026. return
  1027. }
  1028. for _, v := range list {
  1029. classifyIdItem[v.BaseFromThsHfClassifyId] = v
  1030. }
  1031. classifies = list
  1032. }
  1033. // 筛选项
  1034. if params.ClassifyId != "" {
  1035. classifyIdArr := strings.Split(params.ClassifyId, ",")
  1036. classifyIds := make([]int, 0)
  1037. for _, v := range classifyIdArr {
  1038. t, _ := strconv.Atoi(v)
  1039. if t > 0 {
  1040. classifyIds = append(classifyIds, t)
  1041. }
  1042. }
  1043. // 不包含子分类
  1044. if len(classifyIds) > 0 && !params.IncludeChild {
  1045. cond += fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().BaseFromThsHfClassifyId, utils.GetOrmInReplace(len(classifyIds)))
  1046. pars = append(pars, classifyIds)
  1047. }
  1048. // 包含子分类
  1049. if len(classifyIds) > 0 && params.IncludeChild {
  1050. queryClassifyIds := make([]int, 0)
  1051. queryClassifyExist := make(map[int]bool)
  1052. for _, v := range classifyIds {
  1053. // 遍历所有分类从LevelPath中找含有查询分类ID的...=_=!
  1054. for _, cv := range classifies {
  1055. if queryClassifyExist[cv.BaseFromThsHfClassifyId] {
  1056. continue
  1057. }
  1058. if cv.LevelPath == "" {
  1059. continue
  1060. }
  1061. strArr := strings.Split(cv.LevelPath, ",")
  1062. if len(strArr) == 0 {
  1063. continue
  1064. }
  1065. for _, sv := range strArr {
  1066. tv, _ := strconv.Atoi(sv)
  1067. if tv == v {
  1068. queryClassifyIds = append(queryClassifyIds, cv.BaseFromThsHfClassifyId)
  1069. queryClassifyExist[cv.BaseFromThsHfClassifyId] = true
  1070. break
  1071. }
  1072. }
  1073. }
  1074. }
  1075. if len(queryClassifyIds) == 0 {
  1076. br.Data = resp
  1077. br.Ret = 200
  1078. br.Success = true
  1079. br.Msg = "获取成功"
  1080. return
  1081. }
  1082. cond += fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().BaseFromThsHfClassifyId, utils.GetOrmInReplace(len(queryClassifyIds)))
  1083. pars = append(pars, queryClassifyIds)
  1084. }
  1085. }
  1086. if params.Frequency != "" {
  1087. frequencyArr := strings.Split(params.Frequency, ",")
  1088. if len(frequencyArr) > 0 {
  1089. cond += fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().Frequency, utils.GetOrmInReplace(len(frequencyArr)))
  1090. pars = append(pars, frequencyArr)
  1091. }
  1092. }
  1093. if params.SysAdminId != "" {
  1094. adminIdArr := strings.Split(params.SysAdminId, ",")
  1095. adminIds := make([]int, 0)
  1096. for _, v := range adminIdArr {
  1097. t, _ := strconv.Atoi(v)
  1098. if t > 0 {
  1099. adminIds = append(adminIds, t)
  1100. }
  1101. }
  1102. if len(adminIds) > 0 {
  1103. cond += fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().SysUserId, utils.GetOrmInReplace(len(adminIds)))
  1104. pars = append(pars, adminIds)
  1105. }
  1106. }
  1107. params.Keywords = strings.TrimSpace(params.Keywords)
  1108. if params.Keywords != "" {
  1109. cond += fmt.Sprintf(" AND (%s LIKE ? OR %s LIKE ?)", indexOb.Cols().IndexCode, indexOb.Cols().IndexName)
  1110. kw := fmt.Sprint("%", params.Keywords, "%")
  1111. pars = append(pars, kw, kw)
  1112. }
  1113. // 过滤掉选择的指标
  1114. if len(listIds) > 0 {
  1115. cond += fmt.Sprintf(" AND %s NOT IN (%s)", indexOb.Cols().PrimaryId, utils.GetOrmInReplace(len(listIds)))
  1116. pars = append(pars, listIds)
  1117. }
  1118. }
  1119. fields := []string{indexOb.Cols().PrimaryId, indexOb.Cols().IndexCode, indexOb.Cols().IndexName}
  1120. list, e := indexOb.GetItemsByCondition(cond, pars, fields, "")
  1121. if e != nil {
  1122. br.Msg = "获取失败"
  1123. br.ErrMsg = fmt.Sprintf("获取指标失败, %v", e)
  1124. return
  1125. }
  1126. if len(list) > 500 {
  1127. br.Msg = "选择指标超过500个, 请重新选择"
  1128. return
  1129. }
  1130. for _, v := range list {
  1131. resp = append(resp, &data_manage.ThsHfIndexListChoiceItem{
  1132. IndexId: v.BaseFromThsHfIndexId,
  1133. IndexCode: v.IndexCode,
  1134. IndexName: v.IndexName,
  1135. })
  1136. }
  1137. br.Data = resp
  1138. br.Ret = 200
  1139. br.Success = true
  1140. br.Msg = "获取成功"
  1141. }
  1142. // MultiOpt
  1143. // @Title 批量操作-移动分类/删除/刷新
  1144. // @Description 批量操作-移动分类/删除/刷新
  1145. // @Param request body data_manage.ThsHfIndexMultiOptReq true "type json string"
  1146. // @Success 200 string "操作成功"
  1147. // @router /ths_hf/index/multi_opt [post]
  1148. func (this *BaseFromThsHfController) MultiOpt() {
  1149. br := new(models.BaseResponse).Init()
  1150. defer func() {
  1151. if br.ErrMsg == "" {
  1152. br.IsSendEmail = false
  1153. }
  1154. this.Data["json"] = br
  1155. this.ServeJSON()
  1156. }()
  1157. sysUser := this.SysUser
  1158. if sysUser == nil {
  1159. br.Msg = "请登录"
  1160. br.ErrMsg = "请登录,SysUser Is Empty"
  1161. br.Ret = 408
  1162. return
  1163. }
  1164. var params data_manage.ThsHfIndexMultiOptReq
  1165. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &params); e != nil {
  1166. br.Msg = "参数解析异常"
  1167. br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
  1168. return
  1169. }
  1170. if !utils.InArrayByInt([]int{1, 2, 3}, params.OptType) {
  1171. br.Msg = "请选择操作类型"
  1172. return
  1173. }
  1174. if len(params.IndexIds) == 0 {
  1175. br.Msg = "请选择指标"
  1176. return
  1177. }
  1178. if params.OptType == 1 && params.MoveClassifyId <= 0 {
  1179. br.Msg = "请选择分类"
  1180. return
  1181. }
  1182. if params.OptType == 3 && !utils.InArrayByInt([]int{1, 2}, params.RefreshType) {
  1183. br.Msg = "请选择刷新方式"
  1184. return
  1185. }
  1186. resp := new(data_manage.ThsHfIndexMultiOptResp)
  1187. // 指标名称
  1188. indexOb := new(data_manage.BaseFromThsHfIndex)
  1189. indexMap := make(map[int]*data_manage.BaseFromThsHfIndex)
  1190. {
  1191. cond := fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().PrimaryId, utils.GetOrmInReplace(len(params.IndexIds)))
  1192. pars := make([]interface{}, 0)
  1193. pars = append(pars, params.IndexIds)
  1194. list, e := indexOb.GetItemsByCondition(cond, pars, []string{indexOb.Cols().PrimaryId, indexOb.Cols().IndexCode, indexOb.Cols().IndexName}, "")
  1195. if e != nil {
  1196. br.Msg = "删除失败"
  1197. br.ErrMsg = fmt.Sprintf("获取源指标列表失败, %v", e)
  1198. return
  1199. }
  1200. for _, v := range list {
  1201. indexMap[v.BaseFromThsHfIndexId] = v
  1202. }
  1203. }
  1204. // 批量移动
  1205. if params.OptType == 1 {
  1206. if e := indexOb.UpdateClassifyMulti(params.IndexIds, params.MoveClassifyId); e != nil {
  1207. br.Msg = "移动失败"
  1208. br.ErrMsg = fmt.Sprintf("批量移动分类失败, %v", e)
  1209. return
  1210. }
  1211. }
  1212. // 批量删除
  1213. if params.OptType == 2 {
  1214. // 被引用的指标需要提示出来, 未被引用的直接删除
  1215. usedIndexIds := make([]int, 0)
  1216. {
  1217. edbMappingOb := new(data_manage.BaseFromEdbMapping)
  1218. cond := fmt.Sprintf(" AND %s IN (%s)", edbMappingOb.Cols().BaseFromIndexId, utils.GetOrmInReplace(len(params.IndexIds)))
  1219. pars := make([]interface{}, 0)
  1220. pars = append(pars, params.IndexIds)
  1221. list, e := edbMappingOb.GetItemsByCondition(cond, pars, []string{}, "")
  1222. if e != nil {
  1223. br.Msg = "删除失败"
  1224. br.ErrMsg = fmt.Sprintf("获取源指标关联失败, %v", e)
  1225. return
  1226. }
  1227. for _, v := range list {
  1228. if !utils.InArrayByInt(usedIndexIds, v.BaseFromIndexId) {
  1229. usedIndexIds = append(usedIndexIds, v.BaseFromIndexId)
  1230. }
  1231. }
  1232. }
  1233. // 可删除的指标
  1234. removeIndexIds := params.IndexIds
  1235. if len(usedIndexIds) > 0 {
  1236. removeIndexIds = utils.MinusInt(params.IndexIds, usedIndexIds)
  1237. // 标记不允许删除的
  1238. for _, v := range usedIndexIds {
  1239. t := indexMap[v]
  1240. if t == nil {
  1241. continue
  1242. }
  1243. resp.Fail = append(resp.Fail, &data_manage.ThsHfIndexBaseInfo{
  1244. IndexId: v,
  1245. IndexCode: t.IndexCode,
  1246. IndexName: t.IndexName,
  1247. })
  1248. }
  1249. }
  1250. if len(removeIndexIds) > 0 {
  1251. if e := indexOb.MultiRemove(removeIndexIds); e != nil {
  1252. br.Msg = "删除失败"
  1253. br.ErrMsg = fmt.Sprintf("批量删除指标失败, %v", e)
  1254. return
  1255. }
  1256. if utils.UseMongo {
  1257. mogDataObj := mgo.BaseFromThsHfData{}
  1258. for _, v := range removeIndexIds {
  1259. if e := mogDataObj.RemoveMany(bson.M{"base_from_ths_hf_index_id": v}); e != nil {
  1260. br.Msg = "操作失败"
  1261. br.ErrMsg = fmt.Sprintf("批量删除指标数据失败-Mgo, %v", e)
  1262. return
  1263. }
  1264. }
  1265. } else {
  1266. dataOb := new(data_manage.BaseFromThsHfData)
  1267. cond := fmt.Sprintf(" %s IN (%s)", dataOb.Cols().BaseFromThsHfIndexId, utils.GetOrmInReplace(len(removeIndexIds)))
  1268. pars := make([]interface{}, 0)
  1269. pars = append(pars, removeIndexIds)
  1270. if e := dataOb.RemoveByCondition(cond, pars); e != nil {
  1271. br.Msg = "删除失败"
  1272. br.ErrMsg = fmt.Sprintf("批量删除指标数据失败, %v", e)
  1273. return
  1274. }
  1275. }
  1276. // 标记删除成功的
  1277. for _, v := range removeIndexIds {
  1278. t := indexMap[v]
  1279. if t == nil {
  1280. continue
  1281. }
  1282. resp.Success = append(resp.Success, &data_manage.ThsHfIndexBaseInfo{
  1283. IndexId: v,
  1284. IndexCode: t.IndexCode,
  1285. IndexName: t.IndexName,
  1286. })
  1287. }
  1288. }
  1289. }
  1290. // 批量刷新
  1291. if params.OptType == 3 {
  1292. isAsync, e := data.RefreshBaseThsHfIndex(params.IndexIds, params.RefreshType)
  1293. if e != nil {
  1294. br.Msg = "刷新失败"
  1295. br.ErrMsg = fmt.Sprintf("批量刷新指标失败, %v", e)
  1296. return
  1297. }
  1298. if isAsync {
  1299. br.Ret = 200
  1300. br.Success = true
  1301. br.Msg = "操作成功, 刷新指标较多, 请10分钟后查看"
  1302. return
  1303. }
  1304. }
  1305. br.Data = resp
  1306. br.Ret = 200
  1307. br.Success = true
  1308. br.Msg = "操作成功"
  1309. }
  1310. // Save2EdbPre
  1311. // @Title 批量新增指标库-前置
  1312. // @Description 批量新增指标库-前置
  1313. // @Param request body data_manage.ThsHfIndexMultiSave2EdbReq true "type json string"
  1314. // @Success 200 string "操作成功"
  1315. // @router /ths_hf/index/save2edb_pre [post]
  1316. func (this *BaseFromThsHfController) Save2EdbPre() {
  1317. br := new(models.BaseResponse).Init()
  1318. defer func() {
  1319. if br.ErrMsg == "" {
  1320. br.IsSendEmail = false
  1321. }
  1322. this.Data["json"] = br
  1323. this.ServeJSON()
  1324. }()
  1325. sysUser := this.SysUser
  1326. if sysUser == nil {
  1327. br.Msg = "请登录"
  1328. br.ErrMsg = "请登录,SysUser Is Empty"
  1329. br.Ret = 408
  1330. return
  1331. }
  1332. var params data_manage.ThsHfIndexMultiSave2EdbPreReq
  1333. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &params); e != nil {
  1334. br.Msg = "参数解析异常"
  1335. br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
  1336. return
  1337. }
  1338. if len(params.IndexIds) == 0 {
  1339. br.Msg = "请选择指标"
  1340. return
  1341. }
  1342. convertRule := params.ConvertRule
  1343. if convertRule.ConvertType != 1 && convertRule.ConvertType != 2 {
  1344. br.Msg = "请选择数据转换方式"
  1345. return
  1346. }
  1347. // 生成的指标名称后缀
  1348. var (
  1349. suffixName string
  1350. startTimeCn string
  1351. endTimeCn string
  1352. calculateCn string
  1353. )
  1354. dayMap := map[int]string{1: "当日", 2: "前日"}
  1355. calculateMap := map[int]string{1: "均值", 2: "最大值", 3: "最小值"}
  1356. if convertRule.ConvertType == 1 {
  1357. if convertRule.ConvertFixed.FixedDay != 1 && convertRule.ConvertFixed.FixedDay != 2 {
  1358. br.Msg = "请选择指定时间"
  1359. return
  1360. }
  1361. if convertRule.ConvertFixed.FixedTime == "" {
  1362. br.Msg = "请选择指定时间"
  1363. return
  1364. }
  1365. timePrefix := time.Now().Local().Format(utils.FormatDate)
  1366. st := fmt.Sprintf("%s %s", timePrefix, convertRule.ConvertFixed.FixedTime)
  1367. startTime, e := time.Parse(utils.FormatDateTime, st)
  1368. if e != nil {
  1369. br.Msg = "指定时间格式有误"
  1370. return
  1371. }
  1372. startTimeCn = fmt.Sprintf("%s%s", dayMap[convertRule.ConvertFixed.FixedDay], startTime.Format("15点04"))
  1373. }
  1374. if convertRule.ConvertType == 2 {
  1375. if convertRule.ConvertArea.StartDay != 1 && convertRule.ConvertArea.StartDay != 2 {
  1376. br.Msg = "请选择起始时间"
  1377. return
  1378. }
  1379. if convertRule.ConvertArea.StartTime == "" {
  1380. br.Msg = "请选择起始时间"
  1381. return
  1382. }
  1383. var startTimePre string
  1384. if convertRule.ConvertArea.StartDay == 1 {
  1385. startTimePre = time.Now().Local().Format(utils.FormatDate)
  1386. }
  1387. if convertRule.ConvertArea.StartDay == 2 {
  1388. startTimePre = time.Now().Local().AddDate(0, 0, -1).Format(utils.FormatDate)
  1389. }
  1390. st := fmt.Sprintf("%s %s", startTimePre, convertRule.ConvertArea.StartTime)
  1391. startTime, e := time.Parse(utils.FormatDateTime, st)
  1392. if e != nil {
  1393. br.Msg = "起始时间格式有误"
  1394. return
  1395. }
  1396. startTimeCn = fmt.Sprintf("%s%s", dayMap[convertRule.ConvertArea.StartDay], startTime.Format("15点04"))
  1397. if convertRule.ConvertArea.EndDay != 1 && convertRule.ConvertArea.EndDay != 2 {
  1398. br.Msg = "请选择截止时间"
  1399. return
  1400. }
  1401. if convertRule.ConvertArea.EndTime == "" {
  1402. br.Msg = "请选择截止时间"
  1403. return
  1404. }
  1405. var endTimePre string
  1406. if convertRule.ConvertArea.EndDay == 1 {
  1407. endTimePre = time.Now().Local().Format(utils.FormatDate)
  1408. }
  1409. if convertRule.ConvertArea.EndDay == 2 {
  1410. endTimePre = time.Now().Local().AddDate(0, 0, -1).Format(utils.FormatDate)
  1411. }
  1412. ed := fmt.Sprintf("%s %s", endTimePre, convertRule.ConvertArea.EndTime)
  1413. endTime, e := time.Parse(utils.FormatDateTime, ed)
  1414. if e != nil {
  1415. br.Msg = "截止时间格式有误"
  1416. return
  1417. }
  1418. endTimeCn = fmt.Sprintf("至%s%s", dayMap[convertRule.ConvertArea.EndDay], endTime.Format("15点04"))
  1419. if startTime.After(endTime) {
  1420. br.Msg = "起始日期不可早于截止日期"
  1421. return
  1422. }
  1423. calculateCn = calculateMap[convertRule.ConvertArea.CalculateType]
  1424. }
  1425. suffixName = fmt.Sprint(startTimeCn, endTimeCn, calculateCn)
  1426. // 查询指标
  1427. indexOb := new(data_manage.BaseFromThsHfIndex)
  1428. cond := fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().PrimaryId, utils.GetOrmInReplace(len(params.IndexIds)))
  1429. pars := make([]interface{}, 0)
  1430. pars = append(pars, params.IndexIds)
  1431. list, e := indexOb.GetItemsByCondition(cond, pars, []string{}, "")
  1432. if e != nil {
  1433. br.Msg = "获取失败"
  1434. br.ErrMsg = fmt.Sprintf("获取指标失败, %v", e)
  1435. return
  1436. }
  1437. resp := make([]*data_manage.ThsHfIndexMultiSave2EdbPreItem, 0)
  1438. for _, v := range list {
  1439. t := new(data_manage.ThsHfIndexMultiSave2EdbPreItem)
  1440. t.IndexId = v.BaseFromThsHfIndexId
  1441. t.IndexCode = v.IndexCode
  1442. t.IndexName = v.IndexName
  1443. edbCn := data_manage.ThsHfEdbCodeCn[v.Indicator]
  1444. if edbCn == "" {
  1445. edbCn = v.Indicator
  1446. }
  1447. t.NewIndexName = fmt.Sprint(v.StockCode, v.Frequency, edbCn, suffixName)
  1448. t.StockCode = v.StockCode
  1449. t.EdbCode = v.Indicator
  1450. t.Unit = v.Unit
  1451. t.Frequency = v.Frequency
  1452. t.NewFrequency = "日度"
  1453. resp = append(resp, t)
  1454. }
  1455. br.Data = resp
  1456. br.Ret = 200
  1457. br.Success = true
  1458. br.Msg = "获取成功"
  1459. }
  1460. // Save2Edb
  1461. // @Title 批量新增指标库
  1462. // @Description 批量新增指标库
  1463. // @Param request body data_manage.ThsHfIndexMultiSave2EdbReq true "type json string"
  1464. // @Success 200 string "操作成功"
  1465. // @router /ths_hf/index/save2edb [post]
  1466. func (this *BaseFromThsHfController) Save2Edb() {
  1467. br := new(models.BaseResponse).Init()
  1468. defer func() {
  1469. if br.ErrMsg == "" {
  1470. br.IsSendEmail = false
  1471. }
  1472. this.Data["json"] = br
  1473. this.ServeJSON()
  1474. }()
  1475. sysUser := this.SysUser
  1476. if sysUser == nil {
  1477. br.Msg = "请登录"
  1478. br.ErrMsg = "请登录,SysUser Is Empty"
  1479. br.Ret = 408
  1480. return
  1481. }
  1482. var params data_manage.ThsHfIndexMultiSave2EdbReq
  1483. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &params); e != nil {
  1484. br.Msg = "参数解析异常"
  1485. br.ErrMsg = fmt.Sprintf("参数解析异常, %v", e)
  1486. return
  1487. }
  1488. if len(params.NewIndexes) == 0 {
  1489. br.Msg = "请选择指标"
  1490. return
  1491. }
  1492. convertRule := params.ConvertRule
  1493. if convertRule.ConvertType != 1 && convertRule.ConvertType != 2 {
  1494. br.Msg = "请选择数据转换方式"
  1495. return
  1496. }
  1497. if convertRule.ConvertType == 1 {
  1498. if convertRule.ConvertFixed.FixedDay != 1 && convertRule.ConvertFixed.FixedDay != 2 {
  1499. br.Msg = "请选择指定时间"
  1500. return
  1501. }
  1502. if convertRule.ConvertFixed.FixedTime == "" {
  1503. br.Msg = "请选择指定时间"
  1504. return
  1505. }
  1506. timePrefix := time.Now().Local().Format(utils.FormatDate)
  1507. st := fmt.Sprintf("%s %s", timePrefix, convertRule.ConvertFixed.FixedTime)
  1508. _, e := time.Parse(utils.FormatDateTime, st)
  1509. if e != nil {
  1510. br.Msg = "指定时间格式有误"
  1511. return
  1512. }
  1513. }
  1514. if convertRule.ConvertType == 2 {
  1515. if convertRule.ConvertArea.StartDay != 1 && convertRule.ConvertArea.StartDay != 2 {
  1516. br.Msg = "请选择起始时间"
  1517. return
  1518. }
  1519. if convertRule.ConvertArea.StartTime == "" {
  1520. br.Msg = "请选择起始时间"
  1521. return
  1522. }
  1523. var startTimePre string
  1524. if convertRule.ConvertArea.StartDay == 1 {
  1525. startTimePre = time.Now().Local().Format(utils.FormatDate)
  1526. }
  1527. if convertRule.ConvertArea.StartDay == 2 {
  1528. startTimePre = time.Now().Local().AddDate(0, 0, -1).Format(utils.FormatDate)
  1529. }
  1530. st := fmt.Sprintf("%s %s", startTimePre, convertRule.ConvertArea.StartTime)
  1531. startTime, e := time.Parse(utils.FormatDateTime, st)
  1532. if e != nil {
  1533. br.Msg = "起始时间格式有误"
  1534. return
  1535. }
  1536. if convertRule.ConvertArea.EndDay != 1 && convertRule.ConvertArea.EndDay != 2 {
  1537. br.Msg = "请选择截止时间"
  1538. return
  1539. }
  1540. if convertRule.ConvertArea.EndTime == "" {
  1541. br.Msg = "请选择截止时间"
  1542. return
  1543. }
  1544. var endTimePre string
  1545. if convertRule.ConvertArea.EndDay == 1 {
  1546. endTimePre = time.Now().Local().Format(utils.FormatDate)
  1547. }
  1548. if convertRule.ConvertArea.EndDay == 2 {
  1549. endTimePre = time.Now().Local().AddDate(0, 0, -1).Format(utils.FormatDate)
  1550. }
  1551. ed := fmt.Sprintf("%s %s", endTimePre, convertRule.ConvertArea.EndTime)
  1552. endTime, e := time.Parse(utils.FormatDateTime, ed)
  1553. if e != nil {
  1554. br.Msg = "截止时间格式有误"
  1555. return
  1556. }
  1557. if startTime.After(endTime) {
  1558. br.Msg = "起始日期不可早于截止日期"
  1559. return
  1560. }
  1561. }
  1562. resp := new(data_manage.ThsHfIndexMultiSave2EdbResp)
  1563. // 判断指标名称是否重复
  1564. edbNameExist := make(map[string]bool)
  1565. {
  1566. items, e := data_manage.GetEdbInfoFieldList(``, make([]interface{}, 0), []string{"edb_name"})
  1567. if e != nil {
  1568. br.Msg = "操作失败"
  1569. br.ErrMsg = fmt.Sprintf("获取指标名称列表失败, %v", e)
  1570. return
  1571. }
  1572. for _, v := range items {
  1573. edbNameExist[v.EdbName] = true
  1574. }
  1575. }
  1576. for _, v := range params.NewIndexes {
  1577. if edbNameExist[v.NewIndexName] {
  1578. resp.Exist = append(resp.Exist, v)
  1579. }
  1580. }
  1581. if len(resp.Exist) > 0 {
  1582. br.Data = resp
  1583. br.Ret = 200
  1584. br.Success = true
  1585. br.Msg = "含重复指标名称"
  1586. return
  1587. }
  1588. // 请求指标库新增
  1589. for _, v := range params.NewIndexes {
  1590. var r data_manage.ThsHfIndexMultiSave2EdbLibReq
  1591. r.ConvertRule = convertRule
  1592. v.SysAdminId = sysUser.AdminId
  1593. v.SysAdminName = sysUser.RealName
  1594. r.NewIndex = v
  1595. b, e := json.Marshal(r)
  1596. if e != nil {
  1597. v.Tips = "新增失败"
  1598. v.ErrMsg = e.Error()
  1599. resp.Fail = append(resp.Fail, v)
  1600. continue
  1601. }
  1602. res, e := data.AddBaseEdbInfo(string(b), utils.DATA_SOURCE_THS, utils.DATA_SUB_SOURCE_HIGH_FREQUENCY, this.Lang)
  1603. if e != nil {
  1604. v.Tips = "新增失败"
  1605. v.ErrMsg = fmt.Sprintf("AddBaseEdbInfo, err: %v", e)
  1606. resp.Fail = append(resp.Fail, v)
  1607. continue
  1608. }
  1609. if res.Ret != 200 {
  1610. v.Tips = res.Msg
  1611. v.ErrMsg = fmt.Sprintf("AddBaseEdbInfo, Ret: %d, ErrMsg: %s", res.Ret, res.ErrMsg)
  1612. resp.Fail = append(resp.Fail, v)
  1613. continue
  1614. }
  1615. v.Tips = "新增成功"
  1616. resp.Success = append(resp.Success, v)
  1617. }
  1618. br.Data = resp
  1619. br.Ret = 200
  1620. br.Success = true
  1621. br.Msg = "操作成功"
  1622. }