calendar_meeting_user.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. package roadshow
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hz_crm_api/controllers"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/cygx"
  8. "hongze/hz_crm_api/models/roadshow"
  9. "hongze/hz_crm_api/utils"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. // 日历参会名单
  15. type CalendarMeetingUserController struct {
  16. controllers.BaseAuthController
  17. }
  18. // @Title 新增路演活动参会名单接口
  19. // @Description 新增路演活动参会名单接口
  20. // @Param request body roadshow.AddRsCalendarMeetingUserReq true "type json string"
  21. // @Success Ret=200 保存成功
  22. // @router /rs_calendar_meeting_user/add [post]
  23. func (this *CalendarMeetingUserController) Add() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. br.Ret = 408
  34. return
  35. }
  36. var req roadshow.AddRsCalendarMeetingUserReq
  37. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  38. if err != nil {
  39. br.Msg = "参数解析异常!"
  40. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  41. return
  42. }
  43. rsCalendarId := req.RsCalendarId
  44. userIds := req.UserId
  45. tagList := req.TagList
  46. roadShowTheme := req.RoadShowTheme
  47. if rsCalendarId == 0 {
  48. br.Msg = "路演信息错误!"
  49. return
  50. }
  51. if roadShowTheme == "" {
  52. br.Msg = "请输入路演主题名称!"
  53. return
  54. }
  55. var itemsGroup []*roadshow.RsCalendarMeetingLabelGroup
  56. for _, v := range tagList {
  57. itemGroup := new(roadshow.RsCalendarMeetingLabelGroup)
  58. itemGroup.RsCalendarId = rsCalendarId
  59. itemGroup.TagType = v.TagType
  60. itemGroup.TagId = v.TagId
  61. itemGroup.AdminId = sysUser.AdminId
  62. itemGroup.AdminName = sysUser.RealName
  63. itemGroup.CreateTime = time.Now()
  64. itemGroup.ModifyTime = time.Now()
  65. itemsGroup = append(itemsGroup, itemGroup)
  66. }
  67. err = roadshow.AddRsCalendarMeetingLabelGroupMulti(itemsGroup, rsCalendarId)
  68. if err != nil {
  69. br.Msg = "获取信息失败!"
  70. br.ErrMsg = "获取信息失败-AddRsCalendarMeetingLabelGroupMulti!Err:" + err.Error()
  71. return
  72. }
  73. var items []*roadshow.RsCalendarMeetingUser
  74. if len(userIds) > 0 {
  75. var userIdsStr []string
  76. for _, v := range userIds {
  77. userIdsStr = append(userIdsStr, strconv.Itoa(v))
  78. }
  79. listUser, err := models.GetWxUserListByUserIdsHaveCompany(strings.Join(userIdsStr, ","))
  80. if err != nil {
  81. br.Msg = "获取用户信息失败!"
  82. br.ErrMsg = "获取用户信息失败-GetWxUserListByUserIdsHaveCompany!Err:" + err.Error()
  83. return
  84. }
  85. for _, v := range listUser {
  86. item := new(roadshow.RsCalendarMeetingUser)
  87. item.RsCalendarId = rsCalendarId
  88. item.UserId = v.UserId
  89. item.Mobile = v.Mobile
  90. item.Email = v.Email
  91. item.CompanyId = v.CompanyId
  92. item.CompanyName = v.CompanyName
  93. item.RealName = v.RealName
  94. item.Position = v.Position
  95. item.AdminId = sysUser.AdminId
  96. item.AdminName = sysUser.RealName
  97. item.RoadShowTheme = req.RoadShowTheme
  98. item.CreateTime = time.Now()
  99. item.ModifyTime = time.Now()
  100. items = append(items, item)
  101. }
  102. }
  103. err = roadshow.MultiAddRsCalendarMeetingUser(items, roadShowTheme, rsCalendarId)
  104. if err != nil {
  105. br.Msg = "操作失败!"
  106. br.ErrMsg = "操作失败-MultiAddRsCalendarMeetingUser!Err:" + err.Error()
  107. return
  108. }
  109. br.Ret = 200
  110. br.Success = true
  111. br.Msg = "添加成功"
  112. br.IsAddLog = true
  113. }
  114. // @Title 路演活动参会名单列表接口
  115. // @Description 路演活动参会名单列表接口
  116. // @Param RsCalendarId query int true "路演活动id"
  117. // @Success 200 {object} roadshow.CalendarListResp
  118. // @router /rs_calendar_meeting_user/list [get]
  119. func (this *CalendarMeetingUserController) List() {
  120. br := new(models.BaseResponse).Init()
  121. defer func() {
  122. this.Data["json"] = br
  123. this.ServeJSON()
  124. }()
  125. sysUser := this.SysUser
  126. if sysUser == nil {
  127. br.Msg = "请登录"
  128. br.ErrMsg = "请登录,SysUser Is Empty"
  129. br.Ret = 408
  130. return
  131. }
  132. rsCalendarId, _ := this.GetInt("RsCalendarId")
  133. resp := new(roadshow.RsCalendarMeetingUserListResp)
  134. list, err := roadshow.GetRsCalendarMeetingUserListByRsCalendarId(rsCalendarId)
  135. if err != nil {
  136. br.Msg = "获取失败!"
  137. br.ErrMsg = "操作失败-GetRsCalendarMeetingUserListByRsCalendarId!Err:" + err.Error()
  138. return
  139. }
  140. totalGroup, err := roadshow.GetRsCalendarMeetingLabelGroupByRsCalendarId(rsCalendarId)
  141. if err != nil {
  142. br.Msg = "获取信息失败!"
  143. br.ErrMsg = "获取用户信息失败-GetRsCalendarMeetingLabelGroupByRsCalendarId!Err:" + err.Error()
  144. return
  145. }
  146. var lebelDetail []*cygx.RaiServeTagResp
  147. if totalGroup > 0 {
  148. listGroup, err := roadshow.GetRsCalendarMeetingLabelGroupListByRsCalendarId(rsCalendarId)
  149. if err != nil {
  150. br.Msg = "获取信息失败!"
  151. br.ErrMsg = "获取用户信息失败-GetRsCalendarMeetingLabelGroupListByRsCalendarId!Err:" + err.Error()
  152. return
  153. }
  154. var industrialManagementIds []int
  155. var industrialSubjectIds []int
  156. mapindustrialManagementName := make(map[int]string)
  157. mapindustrialSubjectName := make(map[int]string)
  158. mapCelueName := make(map[int]string)
  159. for _, v := range listGroup {
  160. switch v.TagType {
  161. case 1:
  162. industrialManagementIds = append(industrialManagementIds, v.TagId)
  163. case 2:
  164. industrialSubjectIds = append(industrialSubjectIds, v.TagId)
  165. case 3:
  166. mapCelueName[v.TagId] = "策略"
  167. }
  168. }
  169. if len(industrialManagementIds) > 0 {
  170. IndustryList, err := cygx.GetIndustryListByConditionByIds(industrialManagementIds)
  171. if err != nil {
  172. br.Msg = "获取信息失败!"
  173. br.ErrMsg = "获取用户信息失败-GetIndustryListByConditionByIds!Err:" + err.Error()
  174. return
  175. }
  176. for _, v := range IndustryList {
  177. mapindustrialManagementName[v.IndustrialManagementId] = v.IndustryName
  178. }
  179. }
  180. if len(industrialSubjectIds) > 0 {
  181. SubjectList, err := cygx.GetIndustrialSubjectDetailByIds(industrialSubjectIds)
  182. if err != nil {
  183. br.Msg = "获取信息失败!"
  184. br.ErrMsg = "获取用户信息失败-GetIndustryListByConditionByIds!Err:" + err.Error()
  185. return
  186. }
  187. for _, v := range SubjectList {
  188. mapindustrialSubjectName[v.IndustrialSubjectId] = v.SubjectName
  189. }
  190. }
  191. for _, v := range listGroup {
  192. item := new(cygx.RaiServeTagResp)
  193. item.TagType = v.TagType
  194. item.TagId = v.TagId
  195. item.Md5Key = utils.MD5(fmt.Sprintf("K_", v.TagType, "V_", v.TagId))
  196. switch v.TagType {
  197. case 1:
  198. item.TagName = mapindustrialManagementName[v.TagId]
  199. case 2:
  200. item.TagName = mapindustrialSubjectName[v.TagId]
  201. case 3:
  202. item.TagName = mapCelueName[v.TagId]
  203. }
  204. lebelDetail = append(lebelDetail, item)
  205. }
  206. }
  207. if len(list) == 0 {
  208. list = make([]*roadshow.RsCalendarMeetingUserResp, 0)
  209. } else {
  210. for _, v := range list {
  211. resp.RoadShowTheme = v.RoadShowTheme
  212. }
  213. }
  214. if len(lebelDetail) == 0 {
  215. lebelDetail = make([]*cygx.RaiServeTagResp, 0)
  216. }
  217. resp.List = list
  218. resp.ListLebel = lebelDetail
  219. br.Ret = 200
  220. br.Success = true
  221. br.Data = resp
  222. br.Msg = "获取成功"
  223. }
  224. // @Title 路演活动参会删除接口
  225. // @Description 路演活动参会删除接口
  226. // @Param RsCalendarMeetingUserId query int true "参会名单主键ID"
  227. // @Success Ret=200 删除成功
  228. // @router /rs_calendar_meeting_user/delete [post]
  229. func (this *CalendarMeetingUserController) Delete() {
  230. br := new(models.BaseResponse).Init()
  231. defer func() {
  232. this.Data["json"] = br
  233. this.ServeJSON()
  234. }()
  235. sysUser := this.SysUser
  236. if sysUser == nil {
  237. br.Msg = "请登录"
  238. br.ErrMsg = "请登录,SysUser Is Empty"
  239. br.Ret = 408
  240. return
  241. }
  242. var req roadshow.DeleteRsCalendarMeetingUserReq
  243. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  244. if err != nil {
  245. br.Msg = "参数解析异常!"
  246. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  247. return
  248. }
  249. rsCalendarMeetingUserId := req.RsCalendarMeetingUserId
  250. err = roadshow.DeleteRsCalendarMeetingUser(rsCalendarMeetingUserId)
  251. if err != nil {
  252. br.Msg = "删除失败!"
  253. br.ErrMsg = "删除失败-DeleteRsCalendarMeetingUser!Err:" + err.Error()
  254. return
  255. }
  256. br.Ret = 200
  257. br.Success = true
  258. br.Msg = "删除成功"
  259. br.IsAddLog = true
  260. }