industrial_analyst.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. "strconv"
  8. "time"
  9. )
  10. // 分析师管理
  11. type IndustrialAnalystController struct {
  12. controllers.BaseAuthController
  13. }
  14. // @Title 添加分析师
  15. // @Description 添加分析师接口
  16. // @Param request body cygx.IndustrialAnalystAdd true "type json string"
  17. // @Success Ret=200 添加分析师成功
  18. // @router /industrialAnalyst/add [post]
  19. func (this *IndustrialAnalystController) IndustrialAnalystAdd() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. sysUser := this.SysUser
  26. if sysUser == nil {
  27. br.Msg = "请登录"
  28. br.ErrMsg = "请登录,SysUser Is Empty"
  29. br.Ret = 408
  30. return
  31. }
  32. var req cygx.IndustrialAnalystAdd
  33. var pars []interface{}
  34. var condition string
  35. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  36. if err != nil {
  37. br.Msg = "参数解析异常!"
  38. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  39. return
  40. }
  41. if req.AnalystName == "" {
  42. br.Msg = "请输分析师名称"
  43. return
  44. }
  45. condition = `AND analyst_name = '` + req.AnalystName + `' AND industrial_management_id = ` + strconv.Itoa(req.IndustrialManagementId)
  46. total, _ := cygx.GetIndustrialAnalystCount(condition, pars)
  47. if total > 0 {
  48. br.Msg = "名称已经存在,请重新填写"
  49. br.ErrMsg = "名称已经存在,请重新填写:" + req.AnalystName
  50. return
  51. }
  52. condition = `AND industrial_management_id = ` + strconv.Itoa(req.IndustrialManagementId)
  53. totalIndustrialManagement, _ := cygx.GetIndustrialManagementCount(condition, pars)
  54. if totalIndustrialManagement < 1 {
  55. br.Msg = "产业分类名称不存在,请重新填写"
  56. br.ErrMsg = "产业分类名称不存在,请重新填写:" + strconv.Itoa(req.IndustrialManagementId)
  57. return
  58. }
  59. item := new(cygx.CygxIndustrialAnalyst)
  60. item.IndustrialManagementId = req.IndustrialManagementId
  61. item.AnalystName = req.AnalystName
  62. item.CreateTime = time.Now()
  63. err = cygx.AddIndustrialAnalyst(item)
  64. if err != nil {
  65. br.Msg = "新增失败"
  66. br.ErrMsg = "新增失败 Err:" + err.Error()
  67. return
  68. }
  69. br.Ret = 200
  70. br.Success = true
  71. br.Msg = "新增成功"
  72. br.IsAddLog = true
  73. }
  74. // @Title 获取分析师列表
  75. // @Description 获取分析师列表接口
  76. // @Param IndustrialManagementId query int true "分类ID"
  77. // @Success Ret=200 {object} cygx.GetIndustrialAnalystList
  78. // @router /industrialAnalyst/list [get]
  79. func (this *IndustrialAnalystController) IndustrialAnalystlist() {
  80. br := new(models.BaseResponse).Init()
  81. defer func() {
  82. this.Data["json"] = br
  83. this.ServeJSON()
  84. }()
  85. sysUser := this.SysUser
  86. if sysUser == nil {
  87. br.Msg = "请登录"
  88. br.ErrMsg = "请登录,SysUser Is Empty"
  89. br.Ret = 408
  90. return
  91. }
  92. IndustrialManagementId, _ := this.GetInt("IndustrialManagementId")
  93. if IndustrialManagementId < 1 {
  94. br.Msg = "请输入分类ID"
  95. return
  96. }
  97. list, err := cygx.GetIndustrialAnalystAll(IndustrialManagementId)
  98. if err != nil {
  99. br.Msg = "获取信息失败"
  100. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  101. return
  102. }
  103. resp := new(cygx.GetIndustrialAnalystList)
  104. resp.List = list
  105. br.Ret = 200
  106. br.Success = true
  107. br.Msg = "获取成功"
  108. br.Data = resp
  109. }
  110. // @Title 修改
  111. // @Description 修改接口
  112. // @Param request body cygx.CygxIndustrialAnalyst true "type json string"
  113. // @Success Ret=200 修改成功
  114. // @router /industrialAnalyst/edit [post]
  115. func (this *IndustrialAnalystController) IndustrialAnalystEdit() {
  116. br := new(models.BaseResponse).Init()
  117. defer func() {
  118. this.Data["json"] = br
  119. this.ServeJSON()
  120. }()
  121. sysUser := this.SysUser
  122. if sysUser == nil {
  123. br.Msg = "请登录"
  124. br.ErrMsg = "请登录,SysUser Is Empty"
  125. br.Ret = 408
  126. return
  127. }
  128. var req cygx.CygxIndustrialAnalyst
  129. var pars []interface{}
  130. var condition string
  131. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  132. if err != nil {
  133. br.Msg = "参数解析异常!"
  134. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  135. return
  136. }
  137. if req.AnalystName == "" {
  138. br.Msg = "请输入名称"
  139. return
  140. }
  141. condition = `AND industrial_analyst_id = ` + strconv.Itoa(req.IndustrialAnalystId)
  142. totalIndustrialAnalyst, _ := cygx.GetIndustrialAnalystCount(condition, pars)
  143. if totalIndustrialAnalyst < 1 {
  144. br.Msg = "修改失败"
  145. br.ErrMsg = "修改失败,信息不存在:"
  146. return
  147. }
  148. condition = `AND industrial_management_id = ` + strconv.Itoa(req.IndustrialManagementId)
  149. totalIndustrialManagement, _ := cygx.GetIndustrialManagementCount(condition, pars)
  150. if totalIndustrialManagement < 1 {
  151. br.Msg = "修改失败"
  152. br.ErrMsg = "修改失败,分析师不存在"
  153. return
  154. }
  155. condition = `AND analyst_name = '` + req.AnalystName + `' AND industrial_analyst_id != ` + strconv.Itoa(req.IndustrialAnalystId)
  156. total, _ := cygx.GetIndustrialAnalystCount(condition, pars)
  157. if total > 0 {
  158. br.Msg = "名称已经存在,请重新填写"
  159. br.ErrMsg = "名称已经存在,请重新填写:" + req.AnalystName
  160. return
  161. }
  162. item := new(cygx.CygxIndustrialAnalyst)
  163. item.IndustrialManagementId = req.IndustrialManagementId
  164. item.AnalystName = req.AnalystName
  165. item.IndustrialAnalystId = req.IndustrialAnalystId
  166. err = cygx.EditIndustrialAnalyst(item)
  167. if err != nil {
  168. br.Msg = "修改失败"
  169. br.ErrMsg = "修改失败 Err:" + err.Error()
  170. return
  171. }
  172. br.Ret = 200
  173. br.Success = true
  174. br.Msg = "修改成功"
  175. br.IsAddLog = true
  176. }
  177. // @Title 删除分析师
  178. // @Description 删除分析师接口
  179. // @Param IndustrialAnalystId query int true "分析师ID"
  180. // @Success Ret=200
  181. // @router /industrialAnalyst/delete [post]
  182. func (this *IndustrialAnalystController) IndustrialAnalystDelete() {
  183. br := new(models.BaseResponse).Init()
  184. defer func() {
  185. this.Data["json"] = br
  186. this.ServeJSON()
  187. }()
  188. sysUser := this.SysUser
  189. if sysUser == nil {
  190. br.Msg = "请登录"
  191. br.ErrMsg = "请登录,SysUser Is Empty"
  192. br.Ret = 408
  193. return
  194. }
  195. var req cygx.IndustrialAnalystDelete
  196. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  197. if err != nil {
  198. br.Msg = "参数解析异常!"
  199. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  200. return
  201. }
  202. IndustrialAnalystId := req.IndustrialAnalystId
  203. if IndustrialAnalystId < 1 {
  204. br.Msg = "请输入分析师ID"
  205. return
  206. }
  207. err = cygx.DeleteIndustrialAnalyst(IndustrialAnalystId)
  208. if err != nil {
  209. br.Msg = "删除信息失败"
  210. br.ErrMsg = "删除信息失败,Err:" + err.Error()
  211. return
  212. }
  213. br.Ret = 200
  214. br.Success = true
  215. br.Msg = "删除成功"
  216. br.IsAddLog = true
  217. }