data_api.go 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  1. package ctrl_v1
  2. import (
  3. "gd_management_gateway/errors"
  4. "gd_management_gateway/params/param_base"
  5. "gd_management_gateway/params/param_v1_0"
  6. "gd_management_gateway/rpc_apis"
  7. "gd_management_gateway/rpc_apis/gd_admin"
  8. "gd_management_gateway/rpc_apis/gd_management"
  9. "encoding/json"
  10. "fmt"
  11. "time"
  12. "gd_management_gateway/common.in/httper"
  13. "gd_management_gateway/common.in/task"
  14. "gd_management_gateway/common.in/utils"
  15. "github.com/astaxie/beego"
  16. "github.com/tidwall/sjson"
  17. "go.uber.org/zap"
  18. )
  19. // Operations about data api
  20. type BaseDataApiController struct {
  21. metadata interface{} // 中继元数据
  22. beego.Controller
  23. LogID string
  24. }
  25. // @Title 添加数据api
  26. // @Description 添加数据api
  27. // @Param token header string true "token"
  28. // @Param uid header int64 true "admin id"
  29. // @Param body body rpc_apis.gd_management.ManagementDataApiAddApiReq true "参数"
  30. // @Success 200 {object} params.param_v1_0.ManagementDataApiAddApiResp "响应信息"
  31. // @Failure 500 服务器错误
  32. // @router /data_api [post]
  33. func (u *BaseDataApiController) ManagementDataApiAddApi() {
  34. u.LogID = fmt.Sprintf("ManagementDataApiAddApi[%d]", time.Now().UnixNano())
  35. req := &param_v1_0.ManagementDataApiAddApiReq{}
  36. getParamsTask := func() error {
  37. httper.FillRequireParams(u.Ctx, req, u.LogID)
  38. return nil
  39. }
  40. // 加入行为日志
  41. AddActionLogTask := func() error {
  42. go func() {
  43. // 构建json
  44. contentBytes, _ := json.Marshal(req.Body)
  45. areq := gd_admin.AddActionLogReq{
  46. Uid: req.Uid,
  47. Name: req.Body.DataApiName,
  48. Modules: "数据API",
  49. Func: "添加数据api",
  50. Content: string(contentBytes),
  51. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  52. }
  53. AddActionLog(areq)
  54. }()
  55. return nil
  56. }
  57. handleDataTask := func() error {
  58. reply, err := rpc_apis.Management.DataApiAddApi(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  59. if err != nil {
  60. l.Error("rpc",
  61. zap.String("call", "DataApiAddApi"),
  62. zap.String("args", utils.MarshalJsonString(req)),
  63. zap.String("error", err.Error()))
  64. return errors.ErrorTransform(err)
  65. }
  66. resp := param_v1_0.ManagementDataApiAddApiResp{
  67. SimpleResp: param_base.SimpleResp{
  68. Code: 0,
  69. Msg: "SUCCESS",
  70. },
  71. }
  72. resp.Data = reply
  73. httper.JSON(u.Ctx, resp, u.LogID)
  74. return nil
  75. }
  76. // 执行以上定义的任务
  77. task.Do(&task.PanicRecover{
  78. Ctx: u.Ctx,
  79. LogID: u.LogID}, u.Ctx,
  80. getParamsTask, AddActionLogTask, handleDataTask,
  81. )
  82. }
  83. // @Title 删除数据api
  84. // @Description 删除数据api
  85. // @Param token header string true "token"
  86. // @Param uid header int64 true "admin id"
  87. // @Param data_api_id query int64 true "数据api id"
  88. // @Success 200 {object} params.param_v1_0.ManagementDataApiDeleteApiResp "响应信息"
  89. // @Failure 500 服务器错误
  90. // @router /data_api [delete]
  91. func (u *BaseDataApiController) ManagementDataApiDeleteApi() {
  92. u.LogID = fmt.Sprintf("ManagementDataApiDeleteApi[%d]", time.Now().UnixNano())
  93. req := &param_v1_0.ManagementDataApiDeleteApiReq{}
  94. getParamsTask := func() error {
  95. httper.FillRequireParams(u.Ctx, req, u.LogID)
  96. return nil
  97. }
  98. // 加入行为日志
  99. AddActionLogTask := func() error {
  100. // 获取数据api内容
  101. mreq := gd_management.GetApiInfoReq{
  102. Id: req.DataApiId,
  103. }
  104. reply, err := rpc_apis.Management.GetDataApiInfo(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  105. if err != nil {
  106. l.Error("rpc",
  107. zap.String("call", "GetDataApiInfo"),
  108. zap.String("args", utils.MarshalJsonString(req)),
  109. zap.String("error", err.Error()))
  110. return errors.ErrorTransform(err)
  111. }
  112. // 构建json
  113. contentBytes, _ := json.Marshal(reply)
  114. areq := gd_admin.AddActionLogReq{
  115. Uid: req.Uid,
  116. Name: reply.DataApiName,
  117. Modules: "数据API",
  118. Func: "删除数据api",
  119. Content: string(contentBytes),
  120. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  121. }
  122. err = AddActionLog(areq)
  123. if err != nil {
  124. return err
  125. }
  126. return nil
  127. }
  128. handleDataTask := func() error {
  129. mreq := gd_management.ManagementDataApiDeleteApiReq{}
  130. mreq.DataApiId = req.DataApiId
  131. reply, err := rpc_apis.Management.DataApiDeleteApi(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  132. if err != nil {
  133. l.Error("rpc",
  134. zap.String("call", "DataApiDeleteApi"),
  135. zap.String("args", utils.MarshalJsonString(req)),
  136. zap.String("error", err.Error()))
  137. return errors.ErrorTransform(err)
  138. }
  139. resp := param_v1_0.ManagementDataApiDeleteApiResp{
  140. SimpleResp: param_base.SimpleResp{
  141. Code: 0,
  142. Msg: "SUCCESS",
  143. },
  144. }
  145. resp.Data = reply
  146. httper.JSON(u.Ctx, resp, u.LogID)
  147. return nil
  148. }
  149. // 执行以上定义的任务
  150. task.Do(&task.PanicRecover{
  151. Ctx: u.Ctx,
  152. LogID: u.LogID}, u.Ctx,
  153. getParamsTask, AddActionLogTask, handleDataTask,
  154. )
  155. }
  156. // @Title 修改数据api
  157. // @Description 修改数据api
  158. // @Param token header string true "token"
  159. // @Param uid header int64 true "admin id"
  160. // @Param body body rpc_apis.gd_management.ManagementDataApiModifyApiReq true "参数"
  161. // @Success 200 {object} params.param_v1_0.ManagementDataApiModifyApiResp "响应信息"
  162. // @Failure 500 服务器错误
  163. // @router /data_api [put]
  164. func (u *BaseDataApiController) ManagementDataApiModifyApi() {
  165. u.LogID = fmt.Sprintf("ManagementDataApiModifyApi[%d]", time.Now().UnixNano())
  166. req := &param_v1_0.ManagementDataApiModifyApiReq{}
  167. getParamsTask := func() error {
  168. httper.FillRequireParams(u.Ctx, req, u.LogID)
  169. return nil
  170. }
  171. // 加入行为日志
  172. AddActionLogTask := func() error {
  173. // 获取数据api内容
  174. mreq := gd_management.GetApiInfoReq{
  175. Id: req.Body.DataApiId,
  176. }
  177. reply, err := rpc_apis.Management.GetDataApiInfo(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  178. if err != nil {
  179. l.Error("rpc",
  180. zap.String("call", "GetDataApiInfo"),
  181. zap.String("args", utils.MarshalJsonString(req)),
  182. zap.String("error", err.Error()))
  183. return errors.ErrorTransform(err)
  184. }
  185. // 构建json
  186. beforeBytes, _ := json.Marshal(reply)
  187. contentBytes, _ := json.Marshal(req.Body)
  188. areq := gd_admin.AddActionLogReq{
  189. Uid: req.Uid,
  190. Name: reply.DataApiName,
  191. Modules: "数据API",
  192. Func: "修改数据api",
  193. Before: string(beforeBytes),
  194. Content: string(contentBytes),
  195. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  196. }
  197. err = AddActionLog(areq)
  198. if err != nil {
  199. return err
  200. }
  201. return nil
  202. }
  203. handleDataTask := func() error {
  204. reply, err := rpc_apis.Management.DataApiModifyApi(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  205. if err != nil {
  206. l.Error("rpc",
  207. zap.String("call", "DataApiModifyApi"),
  208. zap.String("args", utils.MarshalJsonString(req)),
  209. zap.String("error", err.Error()))
  210. return errors.ErrorTransform(err)
  211. }
  212. resp := param_v1_0.ManagementDataApiModifyApiResp{
  213. SimpleResp: param_base.SimpleResp{
  214. Code: 0,
  215. Msg: "SUCCESS",
  216. },
  217. }
  218. resp.Data = reply
  219. httper.JSON(u.Ctx, resp, u.LogID)
  220. return nil
  221. }
  222. // 执行以上定义的任务
  223. task.Do(&task.PanicRecover{
  224. Ctx: u.Ctx,
  225. LogID: u.LogID}, u.Ctx,
  226. getParamsTask, AddActionLogTask, handleDataTask,
  227. )
  228. }
  229. // @Title 获取数据api列表
  230. // @Description 获取数据api列表
  231. // @Param token header string true "token"
  232. // @Param uid header int64 true "admin id"
  233. // @Param page_size query int64 false "页大小"
  234. // @Param page_number query int64 false "页号"
  235. // @Param is_all query bool false "是否获取全部数据"
  236. // @Param search query string false "搜索字符串"
  237. // @Param data_api_type query string false ""
  238. // @Param merchant_id query int64 false ""
  239. // @Success 200 {object} params.param_v1_0.ManagementDataApiGetAllResp "响应信息"
  240. // @Failure 500 服务器错误
  241. // @router /data_api [get]
  242. func (u *BaseDataApiController) ManagementDataApiGetAll() {
  243. u.LogID = fmt.Sprintf("ManagementDataApiGetAll[%d]", time.Now().UnixNano())
  244. req := &param_v1_0.ManagementDataApiGetAllReq{}
  245. getParamsTask := func() error {
  246. httper.FillRequireParams(u.Ctx, req, u.LogID)
  247. return nil
  248. }
  249. handleDataTask := func() error {
  250. mreq := gd_management.ManagementDataApiGetAllReq{}
  251. mreq.PageSize = req.PageSize
  252. mreq.PageNumber = req.PageNumber
  253. mreq.IsAll = req.IsAll
  254. mreq.Search = req.Search
  255. mreq.DataApiType = req.DataApiType
  256. mreq.MerchantId = req.MerchantId
  257. reply, err := rpc_apis.Management.DataApiGetAll(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  258. if err != nil {
  259. l.Error("rpc",
  260. zap.String("call", "DataApiGetAll"),
  261. zap.String("args", utils.MarshalJsonString(req)),
  262. zap.String("error", err.Error()))
  263. return errors.ErrorTransform(err)
  264. }
  265. resp := param_v1_0.ManagementDataApiGetAllResp{
  266. SimpleResp: param_base.SimpleResp{
  267. Code: 0,
  268. Msg: "SUCCESS",
  269. },
  270. }
  271. resp.Data = reply
  272. httper.JSON(u.Ctx, resp, u.LogID)
  273. return nil
  274. }
  275. // 执行以上定义的任务
  276. task.Do(&task.PanicRecover{
  277. Ctx: u.Ctx,
  278. LogID: u.LogID}, u.Ctx,
  279. getParamsTask, handleDataTask,
  280. )
  281. }
  282. // @Title 获取数据api详情
  283. // @Description 获取数据api详情
  284. // @Param token header string true "token"
  285. // @Param uid header int64 true "admin id"
  286. // @Param data_api_id query int64 true "数据api id"
  287. // @Success 200 {object} params.param_v1_0.ManagementDataApiGetApiInfoResp "响应信息"
  288. // @Failure 500 服务器错误
  289. // @router /data_api_info [get]
  290. func (u *BaseDataApiController) ManagementDataApiGetApiInfo() {
  291. u.LogID = fmt.Sprintf("ManagementDataApiGetApiInfo[%d]", time.Now().UnixNano())
  292. req := &param_v1_0.ManagementDataApiGetApiInfoReq{}
  293. getParamsTask := func() error {
  294. httper.FillRequireParams(u.Ctx, req, u.LogID)
  295. return nil
  296. }
  297. handleDataTask := func() error {
  298. mreq := gd_management.ManagementDataApiGetApiInfoReq{}
  299. mreq.DataApiId = req.DataApiId
  300. reply, err := rpc_apis.Management.DataApiGetApiInfo(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  301. if err != nil {
  302. l.Error("rpc",
  303. zap.String("call", "DataApiGetApiInfo"),
  304. zap.String("args", utils.MarshalJsonString(req)),
  305. zap.String("error", err.Error()))
  306. return errors.ErrorTransform(err)
  307. }
  308. resp := param_v1_0.ManagementDataApiGetApiInfoResp{
  309. SimpleResp: param_base.SimpleResp{
  310. Code: 0,
  311. Msg: "SUCCESS",
  312. },
  313. }
  314. resp.Data = reply
  315. httper.JSON(u.Ctx, resp, u.LogID)
  316. return nil
  317. }
  318. // 执行以上定义的任务
  319. task.Do(&task.PanicRecover{
  320. Ctx: u.Ctx,
  321. LogID: u.LogID}, u.Ctx,
  322. getParamsTask, handleDataTask,
  323. )
  324. }
  325. // @Title 发布数据api
  326. // @Description 发布数据api
  327. // @Param token header string true "token"
  328. // @Param uid header int64 true "admin id"
  329. // @Param data_api_id path int64 true "数据api id"
  330. // @Param data body params.param_v1_0.DataApiReleaseBody true ""
  331. // @Success 200 {object} params.param_v1_0.ManagementDataApiReleaseApiResp "响应信息"
  332. // @Failure 500 服务器错误
  333. // @router /data_api_release/:data_api_id [put]
  334. func (u *BaseDataApiController) ManagementDataApiReleaseApi() {
  335. u.LogID = fmt.Sprintf("ManagementDataApiReleaseApi[%d]", time.Now().UnixNano())
  336. req := &param_v1_0.ManagementDataApiReleaseApiReq{}
  337. getParamsTask := func() error {
  338. httper.FillRequireParams(u.Ctx, req, u.LogID)
  339. return nil
  340. }
  341. // 加入行为日志
  342. AddActionLogTask := func() error {
  343. // 获取数据api内容
  344. mreq := gd_management.GetApiInfoReq{
  345. Id: req.DataApiId,
  346. }
  347. reply, err := rpc_apis.Management.GetDataApiInfo(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  348. if err != nil {
  349. l.Error("rpc",
  350. zap.String("call", "GetDataApiInfo"),
  351. zap.String("args", utils.MarshalJsonString(req)),
  352. zap.String("error", err.Error()))
  353. return errors.ErrorTransform(err)
  354. }
  355. // 构建json
  356. c := map[string]interface{}{
  357. "data_api_id": req.DataApiId,
  358. }
  359. contentBytes, _ := json.Marshal(c)
  360. areq := gd_admin.AddActionLogReq{
  361. Uid: req.Uid,
  362. Name: reply.DataApiName,
  363. Modules: "数据API",
  364. Func: "发布数据api",
  365. Content: string(contentBytes),
  366. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  367. }
  368. err = AddActionLog(areq)
  369. if err != nil {
  370. return err
  371. }
  372. return nil
  373. }
  374. handleDataTask := func() error {
  375. mreq := gd_management.ManagementDataApiReleaseApiReq{}
  376. mreq.DataApiId = req.DataApiId
  377. mreq.Status = req.Data.Status
  378. reply, err := rpc_apis.Management.DataApiReleaseApi(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  379. if err != nil {
  380. l.Error("rpc",
  381. zap.String("call", "DataApiReleaseApi"),
  382. zap.String("args", utils.MarshalJsonString(req)),
  383. zap.String("error", err.Error()))
  384. return errors.ErrorTransform(err)
  385. }
  386. resp := param_v1_0.ManagementDataApiReleaseApiResp{
  387. SimpleResp: param_base.SimpleResp{
  388. Code: 0,
  389. Msg: "SUCCESS",
  390. },
  391. }
  392. resp.Data = reply
  393. httper.JSON(u.Ctx, resp, u.LogID)
  394. return nil
  395. }
  396. // 执行以上定义的任务
  397. task.Do(&task.PanicRecover{
  398. Ctx: u.Ctx,
  399. LogID: u.LogID}, u.Ctx,
  400. getParamsTask, AddActionLogTask, handleDataTask,
  401. )
  402. }
  403. // @Title 填加数据api查询方式
  404. // @Description 填加数据api查询方式
  405. // @Param token header string true "token"
  406. // @Param uid header int64 true "admin id"
  407. // @Param body body rpc_apis.gd_management.ManagementDataApiAddQueryTypeReq true "参数"
  408. // @Success 200 {object} params.param_v1_0.ManagementDataApiAddQueryTypeResp "响应信息"
  409. // @Failure 500 服务器错误
  410. // @router /query_type [post]
  411. func (u *BaseDataApiController) ManagementDataApiAddQueryType() {
  412. u.LogID = fmt.Sprintf("ManagementDataApiAddQueryType[%d]", time.Now().UnixNano())
  413. req := &param_v1_0.ManagementDataApiAddQueryTypeReq{}
  414. getParamsTask := func() error {
  415. httper.FillRequireParams(u.Ctx, req, u.LogID)
  416. return nil
  417. }
  418. addActionLogTask := func() error {
  419. go func() {
  420. // 构建json
  421. contentBytes, _ := json.Marshal(req.Body)
  422. queryTypeNames := ""
  423. for _, v := range req.Body.QueryTypes {
  424. if queryTypeNames == "" {
  425. queryTypeNames = v.QueryTypeName
  426. continue
  427. }
  428. queryTypeNames = fmt.Sprintf("%s,%s", queryTypeNames)
  429. }
  430. areq := gd_admin.AddActionLogReq{
  431. Uid: req.Uid,
  432. Name: queryTypeNames,
  433. Modules: "数据API",
  434. Func: "数据api查询方式",
  435. Content: string(contentBytes),
  436. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  437. }
  438. AddActionLog(areq)
  439. }()
  440. return nil
  441. }
  442. handleDataTask := func() error {
  443. reply, err := rpc_apis.Management.DataApiAddQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  444. if err != nil {
  445. l.Error("rpc",
  446. zap.String("call", "DataApiAddQueryType"),
  447. zap.String("args", utils.MarshalJsonString(req)),
  448. zap.String("error", err.Error()))
  449. return errors.ErrorTransform(err)
  450. }
  451. resp := param_v1_0.ManagementDataApiAddQueryTypeResp{
  452. SimpleResp: param_base.SimpleResp{
  453. Code: 0,
  454. Msg: "SUCCESS",
  455. },
  456. }
  457. resp.Data = reply
  458. httper.JSON(u.Ctx, resp, u.LogID)
  459. return nil
  460. }
  461. // 执行以上定义的任务
  462. task.Do(&task.PanicRecover{
  463. Ctx: u.Ctx,
  464. LogID: u.LogID}, u.Ctx,
  465. getParamsTask, addActionLogTask, handleDataTask,
  466. )
  467. }
  468. // @Title 修改数据api查询方式
  469. // @Description 修改数据api查询方式
  470. // @Param token header string true "token"
  471. // @Param uid header int64 true "admin id"
  472. // @Param body body rpc_apis.gd_management.ManagementDataApiModifyQueryTypeReq true "参数"
  473. // @Success 200 {object} params.param_v1_0.ManagementDataApiModifyQueryTypeResp "响应信息"
  474. // @Failure 500 服务器错误
  475. // @router /query_type [put]
  476. func (u *BaseDataApiController) ManagementDataApiModifyQueryType() {
  477. u.LogID = fmt.Sprintf("ManagementDataApiModifyQueryType[%d]", time.Now().UnixNano())
  478. req := &param_v1_0.ManagementDataApiModifyQueryTypeReq{}
  479. getParamsTask := func() error {
  480. httper.FillRequireParams(u.Ctx, req, u.LogID)
  481. return nil
  482. }
  483. addActionLogTask := func() error {
  484. mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
  485. mreq.QueryTypeId = req.Body.QueryTypeId
  486. reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  487. if err != nil {
  488. l.Error("rpc",
  489. zap.String("call", "DataApiGetQueryType"),
  490. zap.String("args", utils.MarshalJsonString(req)),
  491. zap.String("error", err.Error()))
  492. return errors.ErrorTransform(err)
  493. }
  494. beforeBytes, _ := json.Marshal(reply.QueryTypeInfo)
  495. contentBytes, _ := json.Marshal(req.Body)
  496. areq := gd_admin.AddActionLogReq{
  497. Uid: req.Uid,
  498. Name: req.Body.QueryTypeName,
  499. Modules: "数据API",
  500. Func: "修改数据api查询方式",
  501. Before: string(beforeBytes),
  502. Content: string(contentBytes),
  503. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  504. }
  505. err = AddActionLog(areq)
  506. if err != nil {
  507. return err
  508. }
  509. return nil
  510. }
  511. handleDataTask := func() error {
  512. reply, err := rpc_apis.Management.DataApiModifyQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  513. if err != nil {
  514. l.Error("rpc",
  515. zap.String("call", "DataApiModifyQueryType"),
  516. zap.String("args", utils.MarshalJsonString(req)),
  517. zap.String("error", err.Error()))
  518. return errors.ErrorTransform(err)
  519. }
  520. resp := param_v1_0.ManagementDataApiModifyQueryTypeResp{
  521. SimpleResp: param_base.SimpleResp{
  522. Code: 0,
  523. Msg: "SUCCESS",
  524. },
  525. }
  526. resp.Data = reply
  527. httper.JSON(u.Ctx, resp, u.LogID)
  528. return nil
  529. }
  530. // 执行以上定义的任务
  531. task.Do(&task.PanicRecover{
  532. Ctx: u.Ctx,
  533. LogID: u.LogID}, u.Ctx,
  534. getParamsTask, addActionLogTask, handleDataTask,
  535. )
  536. }
  537. // @Title 删除数据api查询方式
  538. // @Description 删除数据api查询方式
  539. // @Param token header string true "token"
  540. // @Param uid header int64 true "admin id"
  541. // @Param query_type_id query int64 true "数据api查询方式id"
  542. // @Success 200 {object} params.param_v1_0.ManagementDataApiRemoveQueryTypeResp "响应信息"
  543. // @Failure 500 服务器错误
  544. // @router /query_type [delete]
  545. func (u *BaseDataApiController) ManagementDataApiRemoveQueryType() {
  546. u.LogID = fmt.Sprintf("ManagementDataApiRemoveQueryType[%d]", time.Now().UnixNano())
  547. req := &param_v1_0.ManagementDataApiRemoveQueryTypeReq{}
  548. getParamsTask := func() error {
  549. httper.FillRequireParams(u.Ctx, req, u.LogID)
  550. return nil
  551. }
  552. addActionLogTask := func() error {
  553. mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
  554. mreq.QueryTypeId = req.QueryTypeId
  555. reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  556. if err != nil {
  557. l.Error("rpc",
  558. zap.String("call", "DataApiGetQueryType"),
  559. zap.String("args", utils.MarshalJsonString(req)),
  560. zap.String("error", err.Error()))
  561. return errors.ErrorTransform(err)
  562. }
  563. beforeBytes, _ := json.Marshal(reply.QueryTypeInfo)
  564. areq := gd_admin.AddActionLogReq{
  565. Uid: req.Uid,
  566. Name: reply.QueryTypeInfo.QueryTypeName,
  567. Modules: "数据API",
  568. Func: "删除数据api查询方式",
  569. Before: string(beforeBytes),
  570. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  571. }
  572. err = AddActionLog(areq)
  573. if err != nil {
  574. return err
  575. }
  576. return nil
  577. }
  578. handleDataTask := func() error {
  579. mreq := gd_management.ManagementDataApiRemoveQueryTypeReq{}
  580. mreq.QueryTypeId = req.QueryTypeId
  581. reply, err := rpc_apis.Management.DataApiRemoveQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  582. if err != nil {
  583. l.Error("rpc",
  584. zap.String("call", "DataApiRemoveQueryType"),
  585. zap.String("args", utils.MarshalJsonString(req)),
  586. zap.String("error", err.Error()))
  587. return errors.ErrorTransform(err)
  588. }
  589. resp := param_v1_0.ManagementDataApiRemoveQueryTypeResp{
  590. SimpleResp: param_base.SimpleResp{
  591. Code: 0,
  592. Msg: "SUCCESS",
  593. },
  594. }
  595. resp.Data = reply
  596. httper.JSON(u.Ctx, resp, u.LogID)
  597. return nil
  598. }
  599. // 执行以上定义的任务
  600. task.Do(&task.PanicRecover{
  601. Ctx: u.Ctx,
  602. LogID: u.LogID}, u.Ctx,
  603. getParamsTask, addActionLogTask, handleDataTask,
  604. )
  605. }
  606. // @Title 获取数据api查询方式信息
  607. // @Description 获取数据api查询方式信息
  608. // @Param token header string true "token"
  609. // @Param uid header int64 true "admin id"
  610. // @Param query_type_id query int64 true "数据api查询方式id"
  611. // @Success 200 {object} params.param_v1_0.ManagementDataApiGetQueryTypeResp "响应信息"
  612. // @Failure 500 服务器错误
  613. // @router /query_type [get]
  614. func (u *BaseDataApiController) ManagementDataApiGetQueryType() {
  615. u.LogID = fmt.Sprintf("ManagementDataApiGetQueryType[%d]", time.Now().UnixNano())
  616. req := &param_v1_0.ManagementDataApiGetQueryTypeReq{}
  617. getParamsTask := func() error {
  618. httper.FillRequireParams(u.Ctx, req, u.LogID)
  619. return nil
  620. }
  621. handleDataTask := func() error {
  622. mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
  623. mreq.QueryTypeId = req.QueryTypeId
  624. reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  625. if err != nil {
  626. l.Error("rpc",
  627. zap.String("call", "DataApiGetQueryType"),
  628. zap.String("args", utils.MarshalJsonString(req)),
  629. zap.String("error", err.Error()))
  630. return errors.ErrorTransform(err)
  631. }
  632. resp := param_v1_0.ManagementDataApiGetQueryTypeResp{
  633. SimpleResp: param_base.SimpleResp{
  634. Code: 0,
  635. Msg: "SUCCESS",
  636. },
  637. }
  638. resp.Data = reply.QueryTypeInfo
  639. httper.JSON(u.Ctx, resp, u.LogID)
  640. return nil
  641. }
  642. // 执行以上定义的任务
  643. task.Do(&task.PanicRecover{
  644. Ctx: u.Ctx,
  645. LogID: u.LogID}, u.Ctx,
  646. getParamsTask, handleDataTask,
  647. )
  648. }
  649. // @Title 数据api添加基础api
  650. // @Description 数据api添加基础api
  651. // @Param token header string true "token"
  652. // @Param uid header int64 true "admin id"
  653. // @Param body body rpc_apis.gd_management.ManagementDataApiAddBaseApiReq true "参数"
  654. // @Success 200 {object} params.param_v1_0.ManagementDataApiAddBaseApiResp "响应信息"
  655. // @Failure 500 服务器错误
  656. // @router /base_api [post]
  657. func (u *BaseDataApiController) ManagementDataApiAddBaseApi() {
  658. u.LogID = fmt.Sprintf("ManagementDataApiAddBaseApi[%d]", time.Now().UnixNano())
  659. req := &param_v1_0.ManagementDataApiAddBaseApiReq{}
  660. getParamsTask := func() error {
  661. httper.FillRequireParams(u.Ctx, req, u.LogID)
  662. return nil
  663. }
  664. // 加入行为日志
  665. AddActionLogTask := func() error {
  666. go func() {
  667. mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
  668. mreq.QueryTypeId = req.Body.QueryTypeId
  669. reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  670. if err != nil {
  671. l.Error("rpc",
  672. zap.String("call", "DataApiGetQueryType"),
  673. zap.String("args", utils.MarshalJsonString(req)),
  674. zap.String("error", err.Error()))
  675. return
  676. }
  677. // 构建json
  678. contentBytes, _ := json.Marshal(req.Body)
  679. areq := gd_admin.AddActionLogReq{
  680. Uid: req.Uid,
  681. Name: reply.QueryTypeInfo.QueryTypeName,
  682. Modules: "数据API",
  683. Func: "数据api添加基础api",
  684. Content: string(contentBytes),
  685. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  686. }
  687. AddActionLog(areq)
  688. }()
  689. return nil
  690. }
  691. handleDataTask := func() error {
  692. _, err := rpc_apis.Management.DataApiAddBaseApi(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  693. if err != nil {
  694. l.Error("rpc",
  695. zap.String("call", "DataApiAddBaseApi"),
  696. zap.String("args", utils.MarshalJsonString(req)),
  697. zap.String("error", err.Error()))
  698. return errors.ErrorTransform(err)
  699. }
  700. resp := param_v1_0.ManagementDataApiAddBaseApiResp{
  701. SimpleResp: param_base.SimpleResp{
  702. Code: 0,
  703. Msg: "SUCCESS",
  704. },
  705. }
  706. httper.JSON(u.Ctx, resp, u.LogID)
  707. return nil
  708. }
  709. // 执行以上定义的任务
  710. task.Do(&task.PanicRecover{
  711. Ctx: u.Ctx,
  712. LogID: u.LogID}, u.Ctx,
  713. getParamsTask, AddActionLogTask, handleDataTask,
  714. )
  715. }
  716. // @Title 数据api删除基础api
  717. // @Description 数据api删除基础api
  718. // @Param token header string true "token"
  719. // @Param uid header int64 true "admin id"
  720. // @Param data_api_base_api_id query int64 true "数据api中基础api id"
  721. // @Success 200 {object} params.param_v1_0.ManagementDataApiRemoveBaseApiResp "响应信息"
  722. // @Failure 500 服务器错误
  723. // @router /base_api [delete]
  724. func (u *BaseDataApiController) ManagementDataApiRemoveBaseApi() {
  725. u.LogID = fmt.Sprintf("ManagementDataApiRemoveBaseApi[%d]", time.Now().UnixNano())
  726. req := &param_v1_0.ManagementDataApiRemoveBaseApiReq{}
  727. getParamsTask := func() error {
  728. httper.FillRequireParams(u.Ctx, req, u.LogID)
  729. return nil
  730. }
  731. addActionLogTask := func() error {
  732. mreq := gd_management.ManagementDataApiGetBaseApiReq{}
  733. mreq.DataApiBaseApiId = req.DataApiBaseApiId
  734. reply, err := rpc_apis.Management.DataApiGetBaseApi(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  735. if err != nil {
  736. l.Error("rpc",
  737. zap.String("call", "DataApiGetBaseApi"),
  738. zap.String("args", utils.MarshalJsonString(req)),
  739. zap.String("error", err.Error()))
  740. return errors.ErrorTransform(err)
  741. }
  742. beforeBytes, _ := json.Marshal(reply.DataApiBaseApis)
  743. areq := gd_admin.AddActionLogReq{
  744. Uid: req.Uid,
  745. Name: reply.DataApiBaseApis.SaleName,
  746. Modules: "数据API",
  747. Func: "数据api删除基础api",
  748. Before: string(beforeBytes),
  749. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  750. }
  751. err = AddActionLog(areq)
  752. if err != nil {
  753. return err
  754. }
  755. return nil
  756. }
  757. handleDataTask := func() error {
  758. mreq := gd_management.ManagementDataApiRemoveBaseApiReq{}
  759. mreq.DataApiBaseApiId = req.DataApiBaseApiId
  760. reply, err := rpc_apis.Management.DataApiRemoveBaseApi(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  761. if err != nil {
  762. l.Error("rpc",
  763. zap.String("call", "DataApiRemoveBaseApi"),
  764. zap.String("args", utils.MarshalJsonString(req)),
  765. zap.String("error", err.Error()))
  766. return errors.ErrorTransform(err)
  767. }
  768. resp := param_v1_0.ManagementDataApiRemoveBaseApiResp{
  769. SimpleResp: param_base.SimpleResp{
  770. Code: 0,
  771. Msg: "SUCCESS",
  772. },
  773. }
  774. resp.Data = reply
  775. httper.JSON(u.Ctx, resp, u.LogID)
  776. return nil
  777. }
  778. // 执行以上定义的任务
  779. task.Do(&task.PanicRecover{
  780. Ctx: u.Ctx,
  781. LogID: u.LogID}, u.Ctx,
  782. getParamsTask, addActionLogTask, handleDataTask,
  783. )
  784. }
  785. // @Title 数据api修改基础api信息
  786. // @Description 数据api修改基础api信息
  787. // @Param token header string true "token"
  788. // @Param uid header int64 true "admin id"
  789. // @Param body body rpc_apis.gd_management.ManagementDataApiModifyBaseApiReq true "参数"
  790. // @Success 200 {object} params.param_v1_0.ManagementDataApiModifyBaseApiResp "响应信息"
  791. // @Failure 500 服务器错误
  792. // @router /base_api [put]
  793. func (u *BaseDataApiController) ManagementDataApiModifyBaseApi() {
  794. u.LogID = fmt.Sprintf("ManagementDataApiModifyBaseApi[%d]", time.Now().UnixNano())
  795. req := &param_v1_0.ManagementDataApiModifyBaseApiReq{}
  796. getParamsTask := func() error {
  797. httper.FillRequireParams(u.Ctx, req, u.LogID)
  798. return nil
  799. }
  800. addActionLogTask := func() error {
  801. mreq := gd_management.ManagementDataApiGetBaseApiReq{}
  802. mreq.DataApiBaseApiId = req.Body.DataApiBaseApiId
  803. reply, err := rpc_apis.Management.DataApiGetBaseApi(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  804. if err != nil {
  805. l.Error("rpc",
  806. zap.String("call", "DataApiGetBaseApi"),
  807. zap.String("args", utils.MarshalJsonString(req)),
  808. zap.String("error", err.Error()))
  809. return errors.ErrorTransform(err)
  810. }
  811. beforeBytes, _ := json.Marshal(reply.DataApiBaseApis)
  812. contentBytes, _ := json.Marshal(req.Body)
  813. areq := gd_admin.AddActionLogReq{
  814. Uid: req.Uid,
  815. Name: reply.DataApiBaseApis.SaleName,
  816. Modules: "数据API",
  817. Func: "数据api修改基础api信息",
  818. Before: string(beforeBytes),
  819. Content: string(contentBytes),
  820. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  821. }
  822. err = AddActionLog(areq)
  823. if err != nil {
  824. return err
  825. }
  826. return nil
  827. }
  828. handleDataTask := func() error {
  829. reply, err := rpc_apis.Management.DataApiModifyBaseApi(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  830. if err != nil {
  831. l.Error("rpc",
  832. zap.String("call", "DataApiModifyBaseApi"),
  833. zap.String("args", utils.MarshalJsonString(req)),
  834. zap.String("error", err.Error()))
  835. return errors.ErrorTransform(err)
  836. }
  837. resp := param_v1_0.ManagementDataApiModifyBaseApiResp{
  838. SimpleResp: param_base.SimpleResp{
  839. Code: 0,
  840. Msg: "SUCCESS",
  841. },
  842. }
  843. resp.Data = reply
  844. httper.JSON(u.Ctx, resp, u.LogID)
  845. return nil
  846. }
  847. // 执行以上定义的任务
  848. task.Do(&task.PanicRecover{
  849. Ctx: u.Ctx,
  850. LogID: u.LogID}, u.Ctx,
  851. getParamsTask, addActionLogTask, handleDataTask,
  852. )
  853. }
  854. // @Title 数据api获取基础api
  855. // @Description 数据api获取基础api
  856. // @Param token header string true "token"
  857. // @Param uid header int64 true "admin id"
  858. // @Param data_api_base_api_id query int64 false "数据api中基础api id"
  859. // @Success 200 {object} params.param_v1_0.ManagementDataApiGetBaseApiResp "响应信息"
  860. // @Failure 500 服务器错误
  861. // @router /base_api [get]
  862. func (u *BaseDataApiController) ManagementDataApiGetBaseApi() {
  863. u.LogID = fmt.Sprintf("ManagementDataApiGetBaseApi[%d]", time.Now().UnixNano())
  864. req := &param_v1_0.ManagementDataApiGetBaseApiReq{}
  865. getParamsTask := func() error {
  866. httper.FillRequireParams(u.Ctx, req, u.LogID)
  867. return nil
  868. }
  869. handleDataTask := func() error {
  870. mreq := gd_management.ManagementDataApiGetBaseApiReq{}
  871. mreq.DataApiBaseApiId = req.DataApiBaseApiId
  872. reply, err := rpc_apis.Management.DataApiGetBaseApi(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  873. if err != nil {
  874. l.Error("rpc",
  875. zap.String("call", "DataApiGetBaseApi"),
  876. zap.String("args", utils.MarshalJsonString(req)),
  877. zap.String("error", err.Error()))
  878. return errors.ErrorTransform(err)
  879. }
  880. resp := param_v1_0.ManagementDataApiGetBaseApiResp{
  881. SimpleResp: param_base.SimpleResp{
  882. Code: 0,
  883. Msg: "SUCCESS",
  884. },
  885. }
  886. resp.Data = reply.DataApiBaseApis
  887. httper.JSON(u.Ctx, resp, u.LogID)
  888. return nil
  889. }
  890. // 执行以上定义的任务
  891. task.Do(&task.PanicRecover{
  892. Ctx: u.Ctx,
  893. LogID: u.LogID}, u.Ctx,
  894. getParamsTask, handleDataTask,
  895. )
  896. }
  897. /*
  898. // @Title 数据api基础api序号调整
  899. // @Description 数据api基础api序号调整
  900. // @Param token header string true "token"
  901. // @Param uid header int64 true "admin id"
  902. // @Param body body rpc_apis.gd_management.ManagementDataApiChangeBaseApiIndexReq true "参数"
  903. // @Success 200 {object} params.param_v1_0.ManagementDataApiChangeBaseApiIndexResp "响应信息"
  904. // @Failure 500 服务器错误
  905. // @router /base_api_change_index [put]
  906. func (u *BaseDataApiController) ManagementDataApiChangeBaseApiIndex() {
  907. u.LogID = fmt.Sprintf("ManagementDataApiChangeBaseApiIndex[%d]", time.Now().UnixNano())
  908. req := &param_v1_0.ManagementDataApiChangeBaseApiIndexReq{}
  909. getParamsTask := func() error {
  910. httper.FillRequireParams(u.Ctx, req, u.LogID)
  911. return nil
  912. }
  913. handleTokenCheck := func() error {
  914. uid, level, err := utils.ParseToken(req.Token)
  915. if err != nil {
  916. return err
  917. }
  918. if uid != req.Uid {
  919. return errors.UserTokenillegality
  920. }
  921. if level == 0 {
  922. return errors.AuthNotAllow
  923. }
  924. return nil
  925. }
  926. handleDataTask := func() error {
  927. reply, err := rpc_apis.Management.DataApiChangeBaseApiIndex(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  928. if err != nil {
  929. l.Error("rpc",
  930. zap.String("call", "DataApiChangeBaseApiIndex"),
  931. zap.String("args", utils.MarshalJsonString(req)),
  932. zap.String("error", err.Error()))
  933. return errors.ErrorTransform(err)
  934. }
  935. resp := param_v1_0.ManagementDataApiChangeBaseApiIndexResp{
  936. SimpleResp: param_base.SimpleResp{
  937. Code: 0,
  938. Msg: "SUCCESS",
  939. },
  940. }
  941. resp.Data = reply
  942. httper.JSON(u.Ctx, resp, u.LogID)
  943. return nil
  944. }
  945. // 执行以上定义的任务
  946. task.Do(&task.PanicRecover{
  947. Ctx: u.Ctx,
  948. LogID: u.LogID}, u.Ctx,
  949. getParamsTask, handleTokenCheck, handleDataTask,
  950. )
  951. }
  952. */
  953. // @Title 数据api添加数据套餐
  954. // @Description 数据api添加数据套餐
  955. // @Param token header string true "token"
  956. // @Param uid header int64 true "admin id"
  957. // @Param body body rpc_apis.gd_management.ManagementDataApiAddDataComboReq true "参数"
  958. // @Success 200 {object} params.param_v1_0.ManagementDataApiAddDataComboResp "响应信息"
  959. // @Failure 500 服务器错误
  960. // @router /data_combo [post]
  961. func (u *BaseDataApiController) ManagementDataApiAddDataCombo() {
  962. u.LogID = fmt.Sprintf("ManagementDataApiAddDataCombo[%d]", time.Now().UnixNano())
  963. req := &param_v1_0.ManagementDataApiAddDataComboReq{}
  964. getParamsTask := func() error {
  965. httper.FillRequireParams(u.Ctx, req, u.LogID)
  966. return nil
  967. }
  968. addActionLogTask := func() error {
  969. var queryTypeId int64
  970. for _, v := range req.Body.ManagementAddDataComboList {
  971. queryTypeId = v.QueryTypeId
  972. break
  973. }
  974. if queryTypeId == 0 {
  975. return nil
  976. }
  977. mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
  978. mreq.QueryTypeId = queryTypeId
  979. reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  980. if err != nil {
  981. l.Error("rpc",
  982. zap.String("call", "DataApiGetQueryType"),
  983. zap.String("args", utils.MarshalJsonString(req)),
  984. zap.String("error", err.Error()))
  985. return err
  986. }
  987. // 构建json
  988. contentBytes, _ := json.Marshal(req.Body)
  989. areq := gd_admin.AddActionLogReq{
  990. Uid: req.Uid,
  991. Name: reply.QueryTypeInfo.QueryTypeName,
  992. Modules: "数据API",
  993. Func: "数据api添加数据套餐",
  994. Content: string(contentBytes),
  995. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  996. }
  997. err = AddActionLog(areq)
  998. if err != nil {
  999. return err
  1000. }
  1001. return nil
  1002. }
  1003. handleDataTask := func() error {
  1004. _, err := rpc_apis.Management.DataApiAddDataCombo(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  1005. if err != nil {
  1006. l.Error("rpc",
  1007. zap.String("call", "DataApiAddDataCombo"),
  1008. zap.String("args", utils.MarshalJsonString(req.Body)),
  1009. zap.String("error", err.Error()))
  1010. return errors.ErrorTransform(err)
  1011. }
  1012. resp := param_v1_0.ManagementDataApiAddDataComboResp{
  1013. SimpleResp: param_base.SimpleResp{
  1014. Code: 0,
  1015. Msg: "SUCCESS",
  1016. },
  1017. }
  1018. //resp.Data = reply
  1019. httper.JSON(u.Ctx, resp, u.LogID)
  1020. return nil
  1021. }
  1022. // 执行以上定义的任务
  1023. task.Do(&task.PanicRecover{
  1024. Ctx: u.Ctx,
  1025. LogID: u.LogID}, u.Ctx,
  1026. getParamsTask, addActionLogTask, handleDataTask,
  1027. )
  1028. }
  1029. // @Title 数据api删除数据套餐
  1030. // @Description 数据api删除数据套餐
  1031. // @Param token header string true "token"
  1032. // @Param uid header int64 true "admin id"
  1033. // @Param combo_id query int64 true "数据api套餐id"
  1034. // @Param query_type_id query int64 true "数据apiid"
  1035. // @Success 200 {object} params.param_v1_0.ManagementDataApiRemoveDataComboResp "响应信息"
  1036. // @Failure 500 服务器错误
  1037. // @router /data_combo [delete]
  1038. func (u *BaseDataApiController) ManagementDataApiRemoveDataCombo() {
  1039. u.LogID = fmt.Sprintf("ManagementDataApiRemoveDataCombo[%d]", time.Now().UnixNano())
  1040. req := &param_v1_0.ManagementDataApiRemoveDataComboReq{}
  1041. getParamsTask := func() error {
  1042. httper.FillRequireParams(u.Ctx, req, u.LogID)
  1043. return nil
  1044. }
  1045. addActionLogTask := func() error {
  1046. mreq := gd_management.ManagementDataApiGetDataComboReq{
  1047. ComboId: req.ComboId,
  1048. }
  1049. reply, err := rpc_apis.Management.DataApiGetDataCombo(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  1050. if err != nil {
  1051. l.Error("rpc",
  1052. zap.String("call", "DataApiGetDataCombo"),
  1053. zap.String("args", utils.MarshalJsonString(mreq)),
  1054. zap.String("error", err.Error()))
  1055. return err
  1056. }
  1057. json := `{"count":,"price":,"type":,"total_day":}`
  1058. json, _ = sjson.Set(json, "count", reply.Count)
  1059. json, _ = sjson.Set(json, "price", reply.Price)
  1060. json, _ = sjson.Set(json, "type", reply.Type)
  1061. json, _ = sjson.Set(json, "total_day", reply.TotalDay)
  1062. areq := gd_admin.AddActionLogReq{
  1063. Uid: req.Uid,
  1064. Name: reply.QueryTypeName,
  1065. Modules: "数据API",
  1066. Func: "数据api删除数据套餐",
  1067. Content: json,
  1068. ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
  1069. }
  1070. err = AddActionLog(areq)
  1071. if err != nil {
  1072. return err
  1073. }
  1074. return nil
  1075. }
  1076. handleDataTask := func() error {
  1077. mreq := gd_management.ManagementDataApiRemoveDataComboReq{}
  1078. mreq.ComboId = req.ComboId
  1079. reply, err := rpc_apis.Management.DataApiRemoveDataCombo(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  1080. if err != nil {
  1081. l.Error("rpc",
  1082. zap.String("call", "DataApiRemoveDataCombo"),
  1083. zap.String("args", utils.MarshalJsonString(req)),
  1084. zap.String("error", err.Error()))
  1085. return errors.ErrorTransform(err)
  1086. }
  1087. resp := param_v1_0.ManagementDataApiRemoveDataComboResp{
  1088. SimpleResp: param_base.SimpleResp{
  1089. Code: 0,
  1090. Msg: "SUCCESS",
  1091. },
  1092. }
  1093. resp.Data = reply
  1094. httper.JSON(u.Ctx, resp, u.LogID)
  1095. return nil
  1096. }
  1097. // 执行以上定义的任务
  1098. task.Do(&task.PanicRecover{
  1099. Ctx: u.Ctx,
  1100. LogID: u.LogID}, u.Ctx,
  1101. getParamsTask, addActionLogTask, handleDataTask,
  1102. )
  1103. }
  1104. /*
  1105. // @Title 数据api选择三方数据源接口
  1106. // @Description 数据api选择三方数据源接口
  1107. // @Param token header string true "token"
  1108. // @Param uid header int64 true "admin id"
  1109. // @Param body body rpc_apis.gd_management.ManagementDataApiChooseProviderApiReq true "参数"
  1110. // @Success 200 {object} params.param_v1_0.ManagementDataApiChooseProviderApiResp "响应信息"
  1111. // @Failure 500 服务器错误
  1112. // @router /choose_provider_api [put]
  1113. func (u *BaseDataApiController) ManagementDataApiChooseProviderApi() {
  1114. u.LogID = fmt.Sprintf("ManagementDataApiChooseProviderApi[%d]", time.Now().UnixNano())
  1115. req := &param_v1_0.ManagementDataApiChooseProviderApiReq{}
  1116. getParamsTask := func() error {
  1117. httper.FillRequireParams(u.Ctx, req, u.LogID)
  1118. return nil
  1119. }
  1120. handleTokenCheck := func() error {
  1121. uid, level, err := utils.ParseToken(req.Token)
  1122. if err != nil {
  1123. return err
  1124. }
  1125. if uid != req.Uid {
  1126. return errors.UserTokenillegality
  1127. }
  1128. if level == 0 {
  1129. return errors.AuthNotAllow
  1130. }
  1131. return nil
  1132. }
  1133. handleDataTask := func() error {
  1134. reply, err := rpc_apis.Management.DataApiChooseProviderApi(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  1135. if err != nil {
  1136. l.Error("rpc",
  1137. zap.String("call", "DataApiChooseProviderApi"),
  1138. zap.String("args", utils.MarshalJsonString(req)),
  1139. zap.String("error", err.Error()))
  1140. return errors.ErrorTransform(err)
  1141. }
  1142. resp := param_v1_0.ManagementDataApiChooseProviderApiResp{
  1143. SimpleResp: param_base.SimpleResp{
  1144. Code: 0,
  1145. Msg: "SUCCESS",
  1146. },
  1147. }
  1148. resp.Data = reply
  1149. httper.JSON(u.Ctx, resp, u.LogID)
  1150. return nil
  1151. }
  1152. // 执行以上定义的任务
  1153. task.Do(&task.PanicRecover{
  1154. Ctx: u.Ctx,
  1155. LogID: u.LogID}, u.Ctx,
  1156. getParamsTask, handleTokenCheck, handleDataTask,
  1157. )
  1158. }
  1159. */
  1160. // @Title 数据api设置查询方式是否免费
  1161. // @Description 数据api设置查询方式是否免费
  1162. // @Param token header string true "token"
  1163. // @Param uid header int64 true "admin id"
  1164. // @Param body body rpc_apis.gd_management.ManagementDataApiSetFreeDataComboReq true "参数"
  1165. // @Success 200 {object} params.param_v1_0.ManagementDataApiSetFreeDataComboResp "响应信息"
  1166. // @Failure 500 服务器错误
  1167. // @router /set_free_combo [put]
  1168. func (u *BaseDataApiController) ManagementDataApiSetFreeDataCombo() {
  1169. u.LogID = fmt.Sprintf("ManagementDataApiSetFreeDataCombo[%d]", time.Now().UnixNano())
  1170. req := &param_v1_0.ManagementDataApiSetFreeDataComboReq{}
  1171. getParamsTask := func() error {
  1172. httper.FillRequireParams(u.Ctx, req, u.LogID)
  1173. return nil
  1174. }
  1175. handleDataTask := func() error {
  1176. reply, err := rpc_apis.Management.ManagementDataApiSetFreeDataCombo(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
  1177. if err != nil {
  1178. l.Error("rpc",
  1179. zap.String("call", "ManagementDataApiSetFreeDataCombo"),
  1180. zap.String("args", utils.MarshalJsonString(req)),
  1181. zap.String("error", err.Error()))
  1182. return errors.ErrorTransform(err)
  1183. }
  1184. resp := param_v1_0.ManagementDataApiSetFreeDataComboResp{
  1185. SimpleResp: param_base.SimpleResp{
  1186. Code: 0,
  1187. Msg: "SUCCESS",
  1188. },
  1189. }
  1190. resp.Data = reply
  1191. httper.JSON(u.Ctx, resp, u.LogID)
  1192. return nil
  1193. }
  1194. // 执行以上定义的任务
  1195. task.Do(&task.PanicRecover{
  1196. Ctx: u.Ctx,
  1197. LogID: u.LogID}, u.Ctx,
  1198. getParamsTask, handleDataTask,
  1199. )
  1200. }
  1201. // @Title 数据api获取查询方式列表
  1202. // @Description 数据api获取插叙方式列表
  1203. // @Param token header string true "token"
  1204. // @Param uid header int64 true "admin id"
  1205. // @Param data_api_id query int64 true "数据api id"
  1206. // @Success 200 {object} params.param_v1_0.ManagementDataApiGetQueryTypeListResp "响应信息"
  1207. // @Failure 500 服务器错误
  1208. // @router /query_type_list [get]
  1209. func (u *BaseDataApiController) ManagementDataApiGetQueryTypeListApi() {
  1210. u.LogID = fmt.Sprintf("ManagementDataApiGetQueryTypeListApi[%d]", time.Now().UnixNano())
  1211. req := &param_v1_0.ManagementDataApiGetQueryTypeListReq{}
  1212. getParamsTask := func() error {
  1213. httper.FillRequireParams(u.Ctx, req, u.LogID)
  1214. return nil
  1215. }
  1216. handleDataTask := func() error {
  1217. mreq := gd_management.ManagementDataApiGetQueryTypeListReq{}
  1218. mreq.DataApiId = req.DataApiId
  1219. reply, err := rpc_apis.Management.ManagementDataApiGetQueryTypeList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  1220. if err != nil {
  1221. l.Error("rpc",
  1222. zap.String("call", "MangementDataApiGetQueryTypeList"),
  1223. zap.String("args", utils.MarshalJsonString(req)),
  1224. zap.String("error", err.Error()))
  1225. return errors.ErrorTransform(err)
  1226. }
  1227. resp := param_v1_0.ManagementDataApiGetQueryTypeListResp{
  1228. SimpleResp: param_base.SimpleResp{
  1229. Code: 0,
  1230. Msg: "SUCCESS",
  1231. },
  1232. }
  1233. resp.Data = reply
  1234. httper.JSON(u.Ctx, resp, u.LogID)
  1235. return nil
  1236. }
  1237. // 执行以上定义的任务
  1238. task.Do(&task.PanicRecover{
  1239. Ctx: u.Ctx,
  1240. LogID: u.LogID}, u.Ctx,
  1241. getParamsTask, handleDataTask,
  1242. )
  1243. }
  1244. // @Title 数据api套餐列表
  1245. // @Description 数据api套餐列表
  1246. // @Param token header string true "token"
  1247. // @Param uid header int64 true "admin id"
  1248. // @Param query_type_id query int64 true "数据api id"
  1249. // @Success 200 {object} params.param_v1_0.ManagementDataApiComboListResp "响应信息"
  1250. // @Failure 500 服务器错误
  1251. // @router /combo_list [get]
  1252. func (u *BaseDataApiController) ManagementDataApiComboList() {
  1253. u.LogID = fmt.Sprintf("ManagementDataApiComboList[%d]", time.Now().UnixNano())
  1254. req := &param_v1_0.ManagementDataApiComboListReq{}
  1255. getParamsTask := func() error {
  1256. httper.FillRequireParams(u.Ctx, req, u.LogID)
  1257. return nil
  1258. }
  1259. handleDataTask := func() error {
  1260. mreq := gd_management.ManagementDataApiComboListReq{}
  1261. mreq.QueryTypeId = req.QueryTypeId
  1262. reply, err := rpc_apis.Management.ManagementDataApiComboList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  1263. if err != nil {
  1264. l.Error("rpc",
  1265. zap.String("call", "ManagementDataApiComboList"),
  1266. zap.String("args", utils.MarshalJsonString(req)),
  1267. zap.String("error", err.Error()))
  1268. return errors.ErrorTransform(err)
  1269. }
  1270. resp := param_v1_0.ManagementDataApiComboListResp{
  1271. SimpleResp: param_base.SimpleResp{
  1272. Code: 0,
  1273. Msg: "SUCCESS",
  1274. },
  1275. }
  1276. resp.Data = reply
  1277. httper.JSON(u.Ctx, resp, u.LogID)
  1278. return nil
  1279. }
  1280. // 执行以上定义的任务
  1281. task.Do(&task.PanicRecover{
  1282. Ctx: u.Ctx,
  1283. LogID: u.LogID}, u.Ctx,
  1284. getParamsTask, handleDataTask,
  1285. )
  1286. }
  1287. // @Title get filter rules
  1288. // @Description 获取参数过滤规则列表
  1289. // @Param token header string true "token"
  1290. // @Param uid header string true "uid"
  1291. // @Success 200 {object} params.param_v1_0.ManagementGetFilterRuleResp "响应信息"
  1292. // @Failure 500 服务器错误
  1293. // @router /param_filter_rules [get]
  1294. func (u *BaseDataApiController) ManagementGetFilterRule() {
  1295. u.LogID = fmt.Sprintf("ManagementGetFilterRule[%d]", time.Now().UnixNano())
  1296. req := &param_v1_0.ManagementGetFilterRuleReq{}
  1297. getParamsTask := func() error {
  1298. httper.FillRequireParams(u.Ctx, req, u.LogID)
  1299. return nil
  1300. }
  1301. handleDataTask := func() error {
  1302. mreq := gd_management.ManagementGetFilterRuleReq{}
  1303. reply, err := rpc_apis.Management.ManagementGetFilterRule(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
  1304. if err != nil {
  1305. l.Error("rpc",
  1306. zap.String("call", "ManagementSetBaseApiShowInfo"),
  1307. zap.String("args", utils.MarshalJsonString(req)),
  1308. zap.String("error", err.Error()))
  1309. return errors.ErrorTransform(err)
  1310. }
  1311. resp := param_v1_0.ManagementGetFilterRuleResp{
  1312. SimpleResp: param_base.SimpleResp{
  1313. Code: 0,
  1314. Msg: "SUCCESS",
  1315. },
  1316. }
  1317. resp.Rules = reply.Rules
  1318. httper.JSON(u.Ctx, resp, u.LogID)
  1319. return nil
  1320. }
  1321. // 执行以上定义的任务
  1322. task.Do(&task.PanicRecover{
  1323. Ctx: u.Ctx,
  1324. LogID: u.LogID}, u.Ctx,
  1325. getParamsTask, handleDataTask,
  1326. )
  1327. }