manual_edb.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. package controllers
  2. import (
  3. "eta/eta_api/models"
  4. "eta/eta_api/models/data_manage"
  5. "eta/eta_api/utils"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. // EdbDetail
  9. // @Title 指标列表
  10. // @Description 指标列表
  11. // @Param TradeCode query string true "指标编码"
  12. // @Success 200 {object} models.TargetDetailResp
  13. // @router /target/edb/detail [get]
  14. func (this *TargetController) EdbDetail() {
  15. br := new(models.BaseResponse).Init()
  16. defer func() {
  17. this.Data["json"] = br
  18. this.ServeJSON()
  19. }()
  20. sysUser := this.SysUser
  21. if sysUser == nil {
  22. br.Msg = "请重新登录"
  23. return
  24. }
  25. // 指标编码
  26. tradeCode := this.GetString("TradeCode")
  27. if tradeCode == `` {
  28. br.Msg = "请输入指标编码"
  29. br.IsSendEmail = false
  30. return
  31. }
  32. manualEdbInfo, err := models.GetTargetByTradeCode(tradeCode)
  33. if err != nil {
  34. br.Msg = "获取指标失败"
  35. br.ErrMsg = "获取指标失败,err:" + err.Error()
  36. return
  37. }
  38. // 如果不是超管账号,那么得校验下当前用户是否有该指标的权限
  39. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  40. //获取账户所拥有权限的分类id集合
  41. count, err := models.GetCountManualUserClassify(sysUser.AdminId, manualEdbInfo.ClassifyId)
  42. if err != nil {
  43. br.Msg = "获取分类数据失败"
  44. br.ErrMsg = "获取分类数据失败,err:" + err.Error()
  45. return
  46. }
  47. if count <= 0 {
  48. br.Msg = "无权访问"
  49. br.ErrMsg = "无权访问"
  50. br.IsSendEmail = false
  51. return
  52. }
  53. }
  54. classifyList := make([]*models.EdbdataClassify, 0)
  55. {
  56. classify, err := models.GetManualClassifyByClassifyId(manualEdbInfo.ClassifyId)
  57. if err != nil {
  58. br.Msg = "获取分类信息失败"
  59. br.ErrMsg = "获取分类信息失败,err:" + err.Error()
  60. return
  61. }
  62. parentClassify, err := models.GetManualClassifyByClassifyId(classify.ParentId)
  63. if err != nil {
  64. br.Msg = "获取分类信息失败"
  65. br.ErrMsg = "获取父级分类信息失败,err:" + err.Error()
  66. return
  67. }
  68. classifyList = []*models.EdbdataClassify{
  69. parentClassify, classify,
  70. }
  71. }
  72. dataList, err := models.GetEdbDataListByCode(manualEdbInfo.TradeCode)
  73. if err != nil {
  74. br.Msg = "获取明细数据失败"
  75. br.ErrMsg = "获取明细数据失败,err:" + err.Error()
  76. return
  77. }
  78. manualEdbInfo.DataList = dataList
  79. resp := models.TargetDetailResp{
  80. Detail: manualEdbInfo,
  81. ClassifyList: classifyList,
  82. }
  83. br.Ret = 200
  84. br.Success = true
  85. br.Msg = "获取成功"
  86. //br.Data = resp
  87. br.Data = resp
  88. }
  89. // ClassifyEdbList
  90. // @Title 分类指标列表
  91. // @Description 指标列表
  92. // @Param ClassifyId query string true "分类id"
  93. // @Success 200 {object} models.TargetDetailResp
  94. // @router /target/classify/edb/list [get]
  95. func (this *TargetController) ClassifyEdbList() {
  96. br := new(models.BaseResponse).Init()
  97. defer func() {
  98. this.Data["json"] = br
  99. this.ServeJSON()
  100. }()
  101. sysUser := this.SysUser
  102. if sysUser == nil {
  103. br.Msg = "请登录"
  104. br.Ret = 408
  105. return
  106. }
  107. resp := new(models.EdbdataClassifyResp)
  108. classifyId, _ := this.GetInt("ClassifyId") //分类
  109. if classifyId <= 0 {
  110. br.Msg = "请传入分类"
  111. br.ErrMsg = "请传入分类"
  112. br.IsSendEmail = false
  113. }
  114. var condition string
  115. var pars []interface{}
  116. // 如果不是超管账号,那么得校验下当前用户是否有该指标的权限
  117. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  118. //获取账户所拥有权限的分类id集合
  119. count, err := models.GetCountManualUserClassify(sysUser.AdminId, classifyId)
  120. if err != nil {
  121. br.Msg = "获取分类数据失败"
  122. br.ErrMsg = "获取分类数据失败,err:" + err.Error()
  123. return
  124. }
  125. if count <= 0 {
  126. br.Msg = "无权访问"
  127. br.ErrMsg = "无权访问"
  128. br.IsSendEmail = false
  129. return
  130. }
  131. }
  132. list := make([]*models.EdbdataClassifyList, 0)
  133. condition += ` AND a.classify_id = ? `
  134. pars = append(pars, classifyId)
  135. tmpList, err := models.GetEdbInfoList(condition, pars, 0, 0)
  136. if err != nil {
  137. br.Msg = "获取失败"
  138. br.ErrMsg = "获取失败,Err:" + err.Error()
  139. return
  140. }
  141. for _, v := range tmpList {
  142. list = append(list, &models.EdbdataClassifyList{
  143. ClassifyId: 0,
  144. ClassifyName: v.SecName,
  145. ParentId: v.ClassifyId,
  146. Child: nil,
  147. TradeCode: v.TradeCode,
  148. UniqueCode: utils.MD5(v.TradeCode),
  149. })
  150. }
  151. resp.List = list
  152. br.Ret = 200
  153. br.Success = true
  154. br.Msg = "获取成功"
  155. br.Data = resp
  156. }
  157. // EdbSearch
  158. // @Title 指标搜索
  159. // @Description 指标搜索
  160. // @Param Keyword query string false "关键字搜索"
  161. // @Success 200 {object} models.TargetItemListResp
  162. // @router /target/edb/search [get]
  163. func (this *TargetController) EdbSearch() {
  164. br := new(models.BaseResponse).Init()
  165. defer func() {
  166. this.Data["json"] = br
  167. this.ServeJSON()
  168. }()
  169. sysUser := this.SysUser
  170. if sysUser == nil {
  171. br.Msg = "请重新登录"
  172. return
  173. }
  174. pageSize, _ := this.GetInt("PageSize")
  175. currentIndex, _ := this.GetInt("CurrentIndex")
  176. var startSize int
  177. if pageSize <= 0 {
  178. pageSize = utils.PageSize20
  179. }
  180. if currentIndex <= 0 {
  181. currentIndex = 1
  182. }
  183. startSize = utils.StartIndex(currentIndex, pageSize)
  184. //关键字
  185. keyword := this.GetString("Keyword")
  186. var condition string
  187. var pars []interface{}
  188. userId := sysUser.AdminId
  189. //超管账号可以查看分类下的所有频度数据
  190. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  191. classifyList, err := models.GetEdbdataClassify(int64(userId))
  192. if err != nil {
  193. br.Msg = "获取分类数据失败"
  194. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  195. return
  196. }
  197. num := len(classifyList)
  198. if num > 0 {
  199. classifyIdList := make([]int, 0)
  200. for _, v := range classifyList {
  201. classifyIdList = append(classifyIdList, v.ClassifyId)
  202. }
  203. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  204. pars = append(pars, classifyIdList)
  205. }
  206. }
  207. if keyword != "" {
  208. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  209. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  210. }
  211. total, err := models.GetCountEdbInfoList(condition, pars)
  212. if err != nil {
  213. br.Msg = "获取失败"
  214. br.ErrMsg = "获取失败,Err:" + err.Error()
  215. return
  216. }
  217. list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize)
  218. if err != nil {
  219. br.Msg = "获取失败"
  220. br.ErrMsg = "获取失败,Err:" + err.Error()
  221. return
  222. }
  223. for _, v := range list {
  224. v.UniqueCode = utils.MD5(v.TradeCode)
  225. }
  226. resp := models.EdbListResp{
  227. List: list,
  228. Paging: paging.GetPaging(currentIndex, pageSize, total),
  229. }
  230. br.Ret = 200
  231. br.Success = true
  232. br.Msg = "获取成功"
  233. br.Data = resp
  234. }
  235. // EdbList
  236. // @Title 获取研究员指标
  237. // @Description 获取研究员指标
  238. // @Param Frequency query string false "频度;枚举值:日度、周度、月度、季度、半年度、年度"
  239. // @Param Keyword query string false "关键字搜索"
  240. // @Param TradeCode query string false "指标唯一编码"
  241. // @Param ClassifyId query int false "分类id"
  242. // @Param EdbShowType query string true "指标展示类型:0,1,2; 0:不管有没有数据,指标都展示出来, 1:只展示有数据的指标, 2:只展示没有数据的指标"
  243. // @Success 200 {object} models.TargetItemListResp
  244. // @router /target/edb/list [get]
  245. func (this *TargetController) EdbList() {
  246. br := new(models.BaseResponse).Init()
  247. defer func() {
  248. this.Data["json"] = br
  249. this.ServeJSON()
  250. }()
  251. sysUser := this.SysUser
  252. if sysUser == nil {
  253. br.Msg = "请重新登录"
  254. return
  255. }
  256. pageSize, _ := this.GetInt("PageSize")
  257. currentIndex, _ := this.GetInt("CurrentIndex")
  258. var startSize int
  259. if pageSize <= 0 {
  260. pageSize = utils.PageSize20
  261. }
  262. if currentIndex <= 0 {
  263. currentIndex = 1
  264. }
  265. startSize = utils.StartIndex(currentIndex, pageSize)
  266. //关键字
  267. keyword := this.GetString("Keyword")
  268. //关键字
  269. classifyId, _ := this.GetInt("ClassifyId", 0)
  270. var condition string
  271. var pars []interface{}
  272. userId := sysUser.AdminId
  273. //超管账号可以查看分类下的所有频度数据
  274. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  275. classifyList, err := models.GetEdbdataClassify(int64(userId))
  276. if err != nil {
  277. br.Msg = "获取分类数据失败"
  278. br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
  279. return
  280. }
  281. num := len(classifyList)
  282. if num > 0 {
  283. classifyIdList := make([]int, 0)
  284. for _, v := range classifyList {
  285. classifyIdList = append(classifyIdList, v.ClassifyId)
  286. }
  287. condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
  288. pars = append(pars, classifyIdList)
  289. }
  290. }
  291. // 关键词
  292. if keyword != "" {
  293. condition += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  294. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  295. }
  296. // 所属分类
  297. if classifyId > 0 {
  298. condition += ` AND a.classify_id = ? `
  299. pars = append(pars, classifyId)
  300. }
  301. total, err := models.GetCountEdbInfoList(condition, pars)
  302. if err != nil {
  303. br.Msg = "获取失败"
  304. br.ErrMsg = "获取失败,Err:" + err.Error()
  305. return
  306. }
  307. list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize)
  308. if err != nil {
  309. br.Msg = "获取失败"
  310. br.ErrMsg = "获取失败,Err:" + err.Error()
  311. return
  312. }
  313. edbCodeMap := make(map[string]bool)
  314. listNum := len(list)
  315. if listNum > 0 {
  316. tradeCodeList := make([]string, 0)
  317. for _, v := range list {
  318. v.UniqueCode = utils.MD5(v.TradeCode)
  319. tradeCodeList = append(tradeCodeList, v.TradeCode)
  320. }
  321. // 查找是否加入到指标库
  322. {
  323. var edbCondition string
  324. var edbPars []interface{}
  325. edbCondition = ` AND source = ? AND edb_code in (` + utils.GetOrmInReplace(listNum) + `) `
  326. edbPars = append(pars, utils.DATA_SOURCE_MANUAL, tradeCodeList)
  327. edbInfoList, err := data_manage.GetEdbInfoListByCond(edbCondition, edbPars)
  328. if err != nil {
  329. br.Msg = "获取失败"
  330. br.ErrMsg = "获取失败,Err:" + err.Error()
  331. return
  332. }
  333. for _, v := range edbInfoList {
  334. edbCodeMap[v.EdbCode] = true
  335. }
  336. }
  337. for _, v := range list {
  338. // 如果能通过指标编码下标找到,那么说明是加到指标库中
  339. if _, ok := edbCodeMap[v.TradeCode]; ok {
  340. v.EdbExist = 1
  341. }
  342. }
  343. }
  344. resp := models.EdbListResp{
  345. List: list,
  346. Paging: paging.GetPaging(currentIndex, pageSize, total),
  347. }
  348. br.Ret = 200
  349. br.Success = true
  350. br.Msg = "获取成功"
  351. br.Data = resp
  352. }