industry_map.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/services"
  8. "time"
  9. )
  10. // 权益小程序
  11. type IndustryMapController struct {
  12. controllers.BaseAuthController
  13. }
  14. // @Title 行业图谱
  15. // @Description 行业图谱接口
  16. // @Success 200 {object} cygx.CygxIndustryMapResp
  17. // @router /industry/map/list [get]
  18. func (this *IndustryMapController) List() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. sysUser := this.SysUser
  25. if sysUser == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,SysUser Is Empty"
  28. br.Ret = 408
  29. return
  30. }
  31. list, err := cygx.GetCygxIndustryMapByParentId(0)
  32. if err != nil {
  33. br.Msg = "获取失败"
  34. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  35. return
  36. }
  37. rootNode := list[0]
  38. allNodes, err := cygx.GetCygxIndustryMapAll()
  39. if err != nil {
  40. br.Msg = "获取失败"
  41. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  42. return
  43. }
  44. services.MakeTree(allNodes, rootNode)
  45. resp := new(cygx.CygxIndustryMapResp)
  46. resp.Node = rootNode
  47. br.Ret = 200
  48. br.Success = true
  49. br.Msg = "获取成功"
  50. br.Data = resp
  51. }
  52. // @Title 新增图谱
  53. // @Description 新增图谱接口
  54. // @Param request body cygx.IndustryMapAddReq true "type json string"
  55. // @Success Ret=200 新增图谱成功
  56. // @router /industry/map/add [post]
  57. func (this *IndustryMapController) IndustryMapAdd() {
  58. br := new(models.BaseResponse).Init()
  59. defer func() {
  60. this.Data["json"] = br
  61. this.ServeJSON()
  62. }()
  63. sysUser := this.SysUser
  64. if sysUser == nil {
  65. br.Msg = "请登录"
  66. br.ErrMsg = "请登录,SysUser Is Empty"
  67. br.Ret = 408
  68. return
  69. }
  70. var req cygx.IndustryMapAddReq
  71. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  72. if err != nil {
  73. br.Msg = "参数解析异常!"
  74. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  75. return
  76. }
  77. item := new(cygx.CygxIndustryMap)
  78. item.IndustryMapName = req.IndustryMapName
  79. item.ParentId = req.IndustryMapId
  80. item.CreateTime = time.Now()
  81. item.ModifyTime = time.Now()
  82. item.Level = req.Level + 1
  83. err = cygx.AddCygxIndustryMap(item)
  84. if err != nil {
  85. br.Msg = "新增失败"
  86. br.ErrMsg = "新增失败 Err:" + req.IndustryMapName
  87. return
  88. }
  89. br.Ret = 200
  90. br.Success = true
  91. br.Msg = "新增成功"
  92. br.IsAddLog = true
  93. }
  94. // @Title 编辑图谱
  95. // @Description 编辑图谱接口
  96. // @Param request body cygx.IndustryMapEditReq true "type json string"
  97. // @Success Ret=200 新增图谱成功
  98. // @router /industry/map/edit [post]
  99. func (this *IndustryMapController) IndustryMapEdit() {
  100. br := new(models.BaseResponse).Init()
  101. defer func() {
  102. this.Data["json"] = br
  103. this.ServeJSON()
  104. }()
  105. sysUser := this.SysUser
  106. if sysUser == nil {
  107. br.Msg = "请登录"
  108. br.ErrMsg = "请登录,SysUser Is Empty"
  109. br.Ret = 408
  110. return
  111. }
  112. var req cygx.IndustryMapEditReq
  113. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  114. if err != nil {
  115. br.Msg = "参数解析异常!"
  116. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  117. return
  118. }
  119. err = cygx.EditCygxIndustryMap(&req)
  120. if err != nil {
  121. br.Msg = "修改失败"
  122. br.ErrMsg = "修改失败 Err:" + err.Error()
  123. return
  124. }
  125. br.Ret = 200
  126. br.Success = true
  127. br.Msg = "修改成功"
  128. br.IsAddLog = true
  129. }
  130. // @Title 删除图谱
  131. // @Description 删除图谱接口
  132. // @Param request body cygx.IndustryMapDeleteReq true "type json string"
  133. // @Success Ret=200 删除成功
  134. // @router /industry/map/delete [post]
  135. func (this *IndustryMapController) IndustryMapDelete() {
  136. br := new(models.BaseResponse).Init()
  137. defer func() {
  138. this.Data["json"] = br
  139. this.ServeJSON()
  140. }()
  141. sysUser := this.SysUser
  142. if sysUser == nil {
  143. br.Msg = "请登录"
  144. br.ErrMsg = "请登录,SysUser Is Empty"
  145. br.Ret = 408
  146. return
  147. }
  148. var req cygx.IndustryMapDeleteReq
  149. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  150. if err != nil {
  151. br.Msg = "参数解析异常!"
  152. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  153. return
  154. }
  155. err = cygx.DeleteCygxIndustryMap(req.IndustryMapId)
  156. if err != nil {
  157. br.Msg = "删除失败"
  158. br.ErrMsg = "删除失败 Err:" + err.Error()
  159. return
  160. }
  161. br.Ret = 200
  162. br.Success = true
  163. br.Msg = "删除成功"
  164. br.IsAddLog = true
  165. }