user.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygxzs/models"
  5. "hongze/hongze_cygxzs/services"
  6. "hongze/hongze_cygxzs/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. type UserController struct {
  12. BaseAuthController
  13. }
  14. type UserCommonController struct {
  15. BaseCommonController
  16. }
  17. // @Title 获取用户的选择详情
  18. // @Description 获取用户的选择详情接口
  19. // @Success 200 {object} models.CygxXzsChooseSendResp
  20. // @router /choose/detail [get]
  21. func (this *UserController) ChooseDetail() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. user := this.User
  28. if user == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,用户信息为空"
  31. br.Ret = 408
  32. return
  33. }
  34. resp := new(models.CygxXzsChooseSendResp)
  35. var condition string
  36. var pars []interface{}
  37. mobile := user.Mobile
  38. if mobile == "" {
  39. br.Ret = 200
  40. br.Success = true
  41. br.Msg = "获取成功"
  42. br.Data = resp
  43. }
  44. permissionId, err := models.GetCompanyPermissionId(user.CompanyId)
  45. if err != nil {
  46. br.Msg = "获取信息失败"
  47. br.ErrMsg = "GetCompanyPermissionId,Err:" + err.Error()
  48. return
  49. }
  50. if permissionId == "" {
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. br.Data = resp
  55. }
  56. mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
  57. mapFllow := make(map[int]int)
  58. mapCategory := make(map[int]int)
  59. ampCheckList := make(map[int][]int, 0)
  60. permissionIdList := make([]string, 0)
  61. fllowList, err := models.GetCygxIndustryFllowList(mobile)
  62. if err != nil && err.Error() != utils.ErrNoRow() {
  63. br.Msg = "获取信息失败"
  64. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  65. return
  66. }
  67. for _, v := range fllowList {
  68. mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
  69. }
  70. //策略的处理
  71. categoryList, err := models.GetCygxXzsChooseCategoryList(mobile)
  72. if err != nil && err.Error() != utils.ErrNoRow() {
  73. br.Msg = "获取信息失败"
  74. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  75. return
  76. }
  77. for _, v := range categoryList {
  78. mapCategory[v.CategoryId] = v.CategoryId
  79. }
  80. celueList, err := models.GetReportMappingStrategyAll()
  81. if err != nil {
  82. br.Msg = "获取信息失败"
  83. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  84. return
  85. }
  86. for k, v := range celueList {
  87. if v.ChartPermissionId == utils.GU_SHOU_ID {
  88. v.ChartPermissionId = utils.CE_LUE_ID
  89. }
  90. if mapCategory[v.IndustrialManagementId] > 0 {
  91. celueList[k].IsFllow = true
  92. //添加所关注的行业赛道
  93. ampCheckList[v.ChartPermissionId] = append(ampCheckList[v.ChartPermissionId], v.IndustrialManagementId)
  94. }
  95. }
  96. //策略的处理 end
  97. industrialList, err := models.GetindustrialManagement()
  98. if err != nil {
  99. br.Msg = "获取信息失败"
  100. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  101. return
  102. }
  103. for _, v := range industrialList {
  104. if mapFllow[v.IndustrialManagementId] > 0 {
  105. v.IsFllow = true
  106. //添加所关注的行业赛道
  107. ampCheckList[v.ChartPermissionId] = append(ampCheckList[v.ChartPermissionId], v.IndustrialManagementId)
  108. }
  109. mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
  110. }
  111. slicepermissionId := strings.Split(permissionId, ",")
  112. if len(slicepermissionId) > 0 {
  113. for _, v := range slicepermissionId {
  114. permissionIdList = append(permissionIdList, v)
  115. }
  116. condition += ` AND chart_permission_id IN (` + utils.GetOrmInReplace(len(slicepermissionId)) + ` ) `
  117. pars = append(pars, permissionIdList)
  118. }
  119. permissionList, err := models.GetChartPermissionAll(condition, pars)
  120. if err != nil {
  121. br.Msg = "获取信息失败"
  122. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  123. return
  124. }
  125. for k, v := range permissionList {
  126. if v.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  127. v.PermissionName = utils.MAI_FANG_YAN_XUAN_NAME
  128. }
  129. if v.PermissionName == utils.CE_LUE_NAME {
  130. permissionList[k].List = celueList
  131. permissionList[k].AllTracks = "全系列报告"
  132. } else {
  133. permissionList[k].AllTracks = "全部赛道"
  134. if len(mapIndustrial[v.ChartPermissionId]) == 0 {
  135. permissionList[k].List = make([]*models.IndustrialManagementRep, 0)
  136. } else {
  137. permissionList[k].List = mapIndustrial[v.ChartPermissionId]
  138. }
  139. }
  140. if len(ampCheckList[v.ChartPermissionId]) == 0 {
  141. permissionList[k].CheckList = make([]int, 0)
  142. } else {
  143. permissionList[k].CheckList = ampCheckList[v.ChartPermissionId]
  144. }
  145. }
  146. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  147. if err != nil {
  148. br.Msg = "获取信息失败"
  149. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  150. return
  151. }
  152. if count == 0 {
  153. resp.IsObjective = 1
  154. resp.IsSubjective = 1
  155. } else {
  156. detail, err := models.GetCygxXzsChooseSendByMobile(mobile)
  157. if err != nil {
  158. br.Msg = "获取信息失败"
  159. br.ErrMsg = "GetCygxXzsChooseSendByMobile,Err:" + err.Error()
  160. return
  161. }
  162. resp.IsObjective = detail.IsObjective
  163. resp.IsSubjective = detail.IsSubjective
  164. resp.IsRefuse = detail.IsRefuse
  165. }
  166. resp.List = permissionList
  167. br.Ret = 200
  168. br.Success = true
  169. br.Msg = "获取成功"
  170. br.Data = resp
  171. }
  172. // @Title 提交用户的选择详情
  173. // @Description 提交用户的选择详情接口
  174. // @Param request body models.SubmitChooseSendResp true "type json string"
  175. // @Success 200 {object} models.CygxXzsChooseSendResp
  176. // @router /choose/submit [post]
  177. func (this *UserController) ChooseSubmit() {
  178. br := new(models.BaseResponse).Init()
  179. defer func() {
  180. this.Data["json"] = br
  181. this.ServeJSON()
  182. }()
  183. user := this.User
  184. if user == nil {
  185. br.Msg = "请登录"
  186. br.ErrMsg = "请登录,用户信息为空"
  187. br.Ret = 408
  188. return
  189. }
  190. if user.Mobile == "" {
  191. br.Msg = "提交失败!"
  192. br.ErrMsg = "提交失败,手机号不能为空"
  193. return
  194. }
  195. var req models.SubmitChooseSendResp
  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. var industrialManagementIds string
  203. var categoryIds string
  204. industrialManagementList := req.IndustrialManagementIds
  205. isRefuse := req.IsRefuse
  206. isSubjective := req.IsSubjective
  207. isObjective := req.IsObjective
  208. if isRefuse == 0 && isSubjective == 0 && isObjective == 0 {
  209. br.Msg = "请至少选择一项主客观内容"
  210. return
  211. }
  212. listMap, err := models.GetCygxXzsChooseCategoryMapList()
  213. if err != nil {
  214. br.Msg = "操作失败!"
  215. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  216. return
  217. }
  218. mapReport := make(map[int]int)
  219. for _, v := range listMap {
  220. mapReport[v.CategoryId] = v.Id
  221. }
  222. var itemsFllow []*models.CygxIndustryFllow
  223. var itemsCategory []*models.CygxXzsChooseCategory
  224. industrialFllowNum := make(map[int]int) // 提交过来的不同行业的下对应的产业数量
  225. //如果为1 则不做任何推送 ,主观客观默认改成0
  226. if isRefuse == 1 {
  227. isSubjective = 0
  228. isObjective = 0
  229. } else {
  230. for _, v := range industrialManagementList {
  231. //如果为空就不做拼接处理
  232. if v.IndustrialManagementIds == "" {
  233. continue
  234. }
  235. if v.ChartPermissionId != utils.CE_LUE_ID {
  236. industrialManagementIds += v.IndustrialManagementIds + ","
  237. } else {
  238. categoryIds += v.IndustrialManagementIds + ","
  239. }
  240. industrialFllowNum[v.ChartPermissionId] = strings.Count(v.IndustrialManagementIds, ",") + 1
  241. }
  242. industrialManagementIds = strings.TrimRight(industrialManagementIds, ",")
  243. if industrialManagementIds != "" {
  244. sliceIndustrial := strings.Split(industrialManagementIds, ",")
  245. for _, v := range sliceIndustrial {
  246. item := new(models.CygxIndustryFllow)
  247. industrialManagementId, _ := strconv.Atoi(v)
  248. item.IndustrialManagementId = industrialManagementId
  249. item.UserId = user.UserId
  250. item.Mobile = user.Mobile
  251. item.Email = user.Email
  252. item.CompanyId = user.CompanyId
  253. item.CompanyName = user.CompanyName
  254. item.RealName = user.RealName
  255. item.Type = 1
  256. item.CreateTime = time.Now()
  257. item.ModifyTime = time.Now()
  258. item.Source = 2
  259. itemsFllow = append(itemsFllow, item)
  260. }
  261. }
  262. //处理策略
  263. categoryIds = strings.TrimRight(categoryIds, ",")
  264. if categoryIds != "" {
  265. sliceCategoryId := strings.Split(categoryIds, ",")
  266. for _, v := range sliceCategoryId {
  267. item := new(models.CygxXzsChooseCategory)
  268. categoryId, _ := strconv.Atoi(v)
  269. item.CategoryId = categoryId
  270. item.IdCygx = mapReport[categoryId]
  271. item.UserId = user.UserId
  272. item.Mobile = user.Mobile
  273. item.Email = user.Email
  274. item.CompanyId = user.CompanyId
  275. item.CompanyName = user.CompanyName
  276. item.RealName = user.RealName
  277. item.CreateTime = time.Now()
  278. item.ModifyTime = time.Now()
  279. itemsCategory = append(itemsCategory, item)
  280. }
  281. }
  282. }
  283. //医药、消费、科技、智造、研选下的产业赛道
  284. mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
  285. industrialList, err := models.GetindustrialManagement()
  286. if err != nil {
  287. br.Msg = "获取信息失败"
  288. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  289. return
  290. }
  291. for _, v := range industrialList {
  292. mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
  293. }
  294. //策略下的产业赛道
  295. celueList, err := models.GetReportMappingStrategyAll()
  296. if err != nil {
  297. br.Msg = "获取信息失败"
  298. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  299. return
  300. }
  301. mobile := user.Mobile
  302. item := new(models.CygxXzsChooseSend)
  303. item.UserId = user.UserId
  304. item.Mobile = user.Mobile
  305. item.Email = user.Email
  306. item.CompanyId = user.CompanyId
  307. item.CompanyName = user.CompanyName
  308. item.RealName = user.RealName
  309. item.CreateTime = time.Now()
  310. item.ModifyTime = time.Now()
  311. item.IsRefuse = req.IsRefuse
  312. item.IsSubjective = isSubjective
  313. item.IsObjective = isObjective
  314. if industrialFllowNum[utils.YI_YAO_ID] == len(mapIndustrial[utils.YI_YAO_ID]) {
  315. item.AllInYiYao = 1 //如果医药全选则设为1
  316. }
  317. if industrialFllowNum[utils.XIAO_FEI_ID] == len(mapIndustrial[utils.XIAO_FEI_ID]) {
  318. item.AllInXiaoFei = 1 //如果消费全选则设为1
  319. }
  320. if industrialFllowNum[utils.KE_JI_ID] == len(mapIndustrial[utils.KE_JI_ID]) {
  321. item.AllInKeJi = 1 //如果科技全选则设为1
  322. }
  323. if industrialFllowNum[utils.ZHI_ZAO_ID] == len(mapIndustrial[utils.ZHI_ZAO_ID]) {
  324. item.AllInZhiZao = 1 //如果智造全选则设为1
  325. }
  326. if industrialFllowNum[utils.CHART_PERMISSION_ID_YANXUAN] == len(mapIndustrial[utils.CHART_PERMISSION_ID_YANXUAN]) {
  327. item.AllInYanXuan = 1 //如果研选全选则设为1
  328. }
  329. if industrialFllowNum[utils.CE_LUE_ID] == len(celueList) {
  330. item.AllInCeLue = 1 //如果策略全选则设为1
  331. }
  332. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  333. if err != nil {
  334. br.Msg = "获取信息失败"
  335. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  336. return
  337. }
  338. //如果有记录就新增,没有记录就修改
  339. if count == 0 {
  340. err = models.AddCygxXzsChooseSend(item, itemsFllow, itemsCategory)
  341. } else {
  342. err = models.UpdateCygxXzsChooseSend(item, itemsFllow, itemsCategory)
  343. }
  344. if err != nil {
  345. br.Msg = "保存失败!"
  346. br.ErrMsg = "保存失败!,Err:" + err.Error()
  347. return
  348. }
  349. go services.UserSubmit(itemsFllow, itemsCategory, user.UserId)
  350. br.Ret = 200
  351. br.Success = true
  352. br.Msg = "保存成功"
  353. }