business_edb.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_hub/models"
  5. "eta/eta_hub/models/data_manage"
  6. "eta/eta_hub/services/data"
  7. "eta/eta_hub/utils"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "strings"
  10. )
  11. // Push
  12. // @Title 指标数据
  13. // @Description 指标数据
  14. // @Success 200 {object} data.BaseFromBusinessIndexResp
  15. // @router /push [post]
  16. func (c *EdbController) Push() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. c.Data["json"] = br
  20. c.ServeJSON()
  21. }()
  22. body := c.Ctx.Input.RequestBody
  23. var req data_manage.PushBusinessIndexReq
  24. err := json.Unmarshal(body, &req)
  25. if err != nil {
  26. br.Msg = "参数解析异常!"
  27. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  28. return
  29. }
  30. //if req.IndexCode == `` {
  31. // br.Msg = "指标编码不能为空"
  32. // return
  33. //}
  34. if req.IndexName == `` {
  35. br.Msg = "指标名称不能为空"
  36. return
  37. }
  38. if req.Unit == `` {
  39. br.Msg = "指标单位不能为空"
  40. return
  41. }
  42. if req.Frequency == `` {
  43. br.Msg = "指标频度不能为空"
  44. return
  45. }
  46. if req.SourceName == `` {
  47. br.Msg = "数据来源名称不能为空"
  48. return
  49. }
  50. // 兼容频度缺少度的字段
  51. if !strings.Contains(req.Frequency, "度") {
  52. req.Frequency = req.Frequency + "度"
  53. }
  54. if !utils.VerifyFrequency(req.Frequency) {
  55. br.Msg = "指标频度不合法:" + req.Frequency
  56. return
  57. }
  58. reqJson, err := json.Marshal(req)
  59. if err != nil {
  60. br.Msg = "参数解析异常!"
  61. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  62. return
  63. }
  64. respItem, err := data.PushEdb(string(reqJson))
  65. if err != nil {
  66. br.Msg = "处理失败"
  67. br.ErrMsg = "处理失败,Err:" + err.Error()
  68. return
  69. }
  70. if respItem.Ret != 200 {
  71. br.Msg = respItem.Msg
  72. br.ErrMsg = respItem.ErrMsg
  73. return
  74. }
  75. br.Data = respItem.Data
  76. br.Ret = 200
  77. br.Msg = "处理成功"
  78. }
  79. // BusinessEdbList
  80. // @Title 获取自有数据列表
  81. // @Description 获取自有数据列表
  82. // @Success 200 {object} data_manage.BaseFromBusinessIndexResp
  83. // @router /business/edb/list [get]
  84. func (c *EdbController) BusinessEdbList() {
  85. br := new(models.BaseResponse).Init()
  86. defer func() {
  87. c.Data["json"] = br
  88. c.ServeJSON()
  89. }()
  90. pageSize, _ := c.GetInt("PageSize")
  91. currentIndex, _ := c.GetInt("CurrentIndex")
  92. var startSize int
  93. if pageSize <= 0 {
  94. pageSize = utils.PageSize20
  95. }
  96. if currentIndex <= 0 {
  97. currentIndex = 1
  98. }
  99. startSize = utils.StartIndex(currentIndex, pageSize)
  100. //通过指标ID、指标名称、渠道、单位、频度查询匹配自有数据中已有的指标;
  101. indexCode := c.GetString("IndexCode")
  102. indexName := c.GetString("IndexName")
  103. //if indexName == `` && indexCode == `` {
  104. // br.Msg = "IndexCode与IndexName不能同时为空"
  105. // br.ErrMsg = "IndexCode与IndexName不能同时为空"
  106. // return
  107. //}
  108. cond := ``
  109. pars := make([]interface{}, 0)
  110. if indexCode != `` {
  111. cond += ` AND index_code = ?`
  112. pars = append(pars, indexCode)
  113. }
  114. if indexName != `` {
  115. cond += ` AND index_name like ?`
  116. pars = utils.GetLikeKeywordPars(pars, indexName, 1)
  117. }
  118. sourceName := c.GetString("SourceName")
  119. if sourceName != `` {
  120. cond += ` AND source_name = ?`
  121. pars = append(pars, sourceName)
  122. }
  123. unit := c.GetString("Unit")
  124. if unit != `` {
  125. cond += ` AND unit = ?`
  126. pars = append(pars, unit)
  127. }
  128. frequency := c.GetString("Frequency")
  129. if frequency != `` {
  130. cond += ` AND frequency = ?`
  131. pars = append(pars, frequency)
  132. }
  133. edbOb := new(data_manage.BaseFromBusinessIndex)
  134. total, edbList, e := edbOb.GetItemsByCondition(cond, pars, []string{"index_code", "index_name", "frequency", "unit", "source_name"}, "base_from_business_index_id DESC", startSize, pageSize)
  135. if e != nil {
  136. br.Msg = "获取失败"
  137. br.ErrMsg = "EdbList GetItemsByCondition err: " + e.Error()
  138. return
  139. }
  140. page := paging.GetPaging(currentIndex, pageSize, total)
  141. resp := data_manage.BaseFromBusinessIndexResp{
  142. Paging: page,
  143. List: edbList,
  144. }
  145. br.Data = resp
  146. br.Ret = 200
  147. br.Msg = "获取成功"
  148. }
  149. // BusinessEdbDel
  150. // @Title 删除指标数据
  151. // @Description 删除指标数据
  152. // @Success 200 {object} data_manage.EdbInfoItem
  153. // @router /business/edb/del [post]
  154. func (c *EdbController) BusinessEdbDel() {
  155. br := new(models.BaseResponse).Init()
  156. defer func() {
  157. c.Data["json"] = br
  158. c.ServeJSON()
  159. }()
  160. body := c.Ctx.Input.RequestBody
  161. var req data_manage.DelBusinessIndexReq
  162. err := json.Unmarshal(body, &req)
  163. if err != nil {
  164. br.Msg = "参数解析异常!"
  165. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  166. return
  167. }
  168. if len(req.IndexCodeList) < 0 {
  169. br.Msg = "指标编码不允许为空"
  170. return
  171. }
  172. reqJson, err := json.Marshal(req)
  173. if err != nil {
  174. br.Msg = "参数解析异常!"
  175. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  176. return
  177. }
  178. respItem, err := data.DelBusinessIndex(string(reqJson))
  179. if err != nil {
  180. br.Msg = "删除失败"
  181. br.ErrMsg = "删除失败,Err:" + err.Error()
  182. return
  183. }
  184. if respItem.Ret != 200 {
  185. br.Msg = respItem.Msg
  186. br.ErrMsg = respItem.ErrMsg
  187. return
  188. }
  189. br.Data = respItem.Data
  190. br.Ret = 200
  191. br.Msg = "删除成功"
  192. }
  193. // BusinessEdbDataDel
  194. // @Title 删除指标数据
  195. // @Description 删除指标数据
  196. // @Success 200 {object} data_manage.EdbInfoItem
  197. // @router /business/data/del [post]
  198. func (c *EdbController) BusinessEdbDataDel() {
  199. br := new(models.BaseResponse).Init()
  200. defer func() {
  201. c.Data["json"] = br
  202. c.ServeJSON()
  203. }()
  204. body := c.Ctx.Input.RequestBody
  205. var req data_manage.DelBusinessDataReq
  206. err := json.Unmarshal(body, &req)
  207. if err != nil {
  208. br.Msg = "参数解析异常!"
  209. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  210. return
  211. }
  212. if req.IndexCode == `` {
  213. br.Msg = "指标编码不能为空"
  214. return
  215. }
  216. if req.StartDate == `` && req.EndDate == `` {
  217. br.Msg = "开始日期和结束日期不允许同时为空"
  218. return
  219. }
  220. reqJson, err := json.Marshal(req)
  221. if err != nil {
  222. br.Msg = "参数解析异常!"
  223. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  224. return
  225. }
  226. respItem, err := data.DelBusinessIndexData(string(reqJson))
  227. if err != nil {
  228. br.Msg = "删除失败"
  229. br.ErrMsg = "删除失败,Err:" + err.Error()
  230. return
  231. }
  232. if respItem.Ret != 200 {
  233. br.Msg = respItem.Msg
  234. br.ErrMsg = respItem.ErrMsg
  235. return
  236. }
  237. br.Data = respItem.Data
  238. br.Ret = 200
  239. br.Msg = "删除成功"
  240. }