package controllers import ( "encoding/json" "hongze/hongze_cygxzs/models" "hongze/hongze_cygxzs/services" "hongze/hongze_cygxzs/utils" "strconv" "strings" "time" ) type UserController struct { BaseAuthController } type UserCommonController struct { BaseCommonController } // @Title 获取用户的选择详情 // @Description 获取用户的选择详情接口 // @Success 200 {object} models.CygxXzsChooseSendResp // @router /choose/detail [get] func (this *UserController) ChooseDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } resp := new(models.CygxXzsChooseSendResp) var condition string var pars []interface{} mobile := user.Mobile if mobile == "" { br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } permissionId, err := models.GetCompanyPermissionId(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "GetCompanyPermissionId,Err:" + err.Error() return } if permissionId == "" { br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } mapIndustrial := make(map[int][]*models.IndustrialManagementRep) mapFllow := make(map[int]int) mapCategory := make(map[int]int) ampCheckList := make(map[int][]int, 0) permissionIdList := make([]string, 0) fllowList, err := models.GetCygxIndustryFllowList(mobile) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "获取客户信息失败,Err:" + err.Error() return } for _, v := range fllowList { mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId } //策略的处理 categoryList, err := models.GetCygxXzsChooseCategoryList(mobile) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "获取客户信息失败,Err:" + err.Error() return } for _, v := range categoryList { mapCategory[v.CategoryId] = v.CategoryId } celueList, err := models.GetReportMappingStrategyAll() if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取产业信息失败,Err:" + err.Error() return } for k, v := range celueList { if v.ChartPermissionId == utils.GU_SHOU_ID { v.ChartPermissionId = utils.CE_LUE_ID } if mapCategory[v.IndustrialManagementId] > 0 { celueList[k].IsFllow = true //添加所关注的行业赛道 ampCheckList[v.ChartPermissionId] = append(ampCheckList[v.ChartPermissionId], v.IndustrialManagementId) } } //策略的处理 end industrialList, err := models.GetindustrialManagement() if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取产业信息失败,Err:" + err.Error() return } for _, v := range industrialList { if mapFllow[v.IndustrialManagementId] > 0 { v.IsFllow = true //添加所关注的行业赛道 ampCheckList[v.ChartPermissionId] = append(ampCheckList[v.ChartPermissionId], v.IndustrialManagementId) } mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v) } slicepermissionId := strings.Split(permissionId, ",") if len(slicepermissionId) > 0 { for _, v := range slicepermissionId { permissionIdList = append(permissionIdList, v) } condition += ` AND chart_permission_id IN (` + utils.GetOrmInReplace(len(slicepermissionId)) + ` ) ` pars = append(pars, permissionIdList) } permissionList, err := models.GetChartPermissionAll(condition, pars) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取产业信息失败,Err:" + err.Error() return } for k, v := range permissionList { if v.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN { v.PermissionName = utils.MAI_FANG_YAN_XUAN_NAME } if v.PermissionName == utils.CE_LUE_NAME { permissionList[k].List = celueList permissionList[k].AllTracks = "全系列报告" } else { permissionList[k].AllTracks = "全部赛道" if len(mapIndustrial[v.ChartPermissionId]) == 0 { permissionList[k].List = make([]*models.IndustrialManagementRep, 0) } else { permissionList[k].List = mapIndustrial[v.ChartPermissionId] } } if len(ampCheckList[v.ChartPermissionId]) == 0 { permissionList[k].CheckList = make([]int, 0) } else { permissionList[k].CheckList = ampCheckList[v.ChartPermissionId] } } count, err := models.GetXzsChooseSendCountByMobile(mobile) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error() return } if count == 0 { resp.IsObjective = 1 resp.IsSubjective = 1 } else { detail, err := models.GetCygxXzsChooseSendByMobile(mobile) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "GetCygxXzsChooseSendByMobile,Err:" + err.Error() return } resp.IsObjective = detail.IsObjective resp.IsSubjective = detail.IsSubjective resp.IsRefuse = detail.IsRefuse } resp.List = permissionList br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 提交用户的选择详情 // @Description 提交用户的选择详情接口 // @Param request body models.SubmitChooseSendResp true "type json string" // @Success 200 {object} models.CygxXzsChooseSendResp // @router /choose/submit [post] func (this *UserController) ChooseSubmit() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } if user.Mobile == "" { br.Msg = "提交失败!" br.ErrMsg = "提交失败,手机号不能为空" return } var req models.SubmitChooseSendResp err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } var industrialManagementIds string var categoryIds string industrialManagementList := req.IndustrialManagementIds isRefuse := req.IsRefuse isSubjective := req.IsSubjective isObjective := req.IsObjective if isRefuse == 0 && isSubjective == 0 && isObjective == 0 { br.Msg = "请至少选择一项主客观内容" return } listMap, err := models.GetCygxXzsChooseCategoryMapList() if err != nil { br.Msg = "操作失败!" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } mapReport := make(map[int]int) for _, v := range listMap { mapReport[v.CategoryId] = v.Id } var itemsFllow []*models.CygxIndustryFllow var itemsCategory []*models.CygxXzsChooseCategory industrialFllowNum := make(map[int]int) // 提交过来的不同行业的下对应的产业数量 //如果为1 则不做任何推送 ,主观客观默认改成0 if isRefuse == 1 { isSubjective = 0 isObjective = 0 } else { for _, v := range industrialManagementList { //如果为空就不做拼接处理 if v.IndustrialManagementIds == "" { continue } if v.ChartPermissionId != utils.CE_LUE_ID { industrialManagementIds += v.IndustrialManagementIds + "," } else { categoryIds += v.IndustrialManagementIds + "," } industrialFllowNum[v.ChartPermissionId] = strings.Count(v.IndustrialManagementIds, ",") + 1 } industrialManagementIds = strings.TrimRight(industrialManagementIds, ",") if industrialManagementIds != "" { sliceIndustrial := strings.Split(industrialManagementIds, ",") for _, v := range sliceIndustrial { item := new(models.CygxIndustryFllow) industrialManagementId, _ := strconv.Atoi(v) item.IndustrialManagementId = industrialManagementId item.UserId = user.UserId item.Mobile = user.Mobile item.Email = user.Email item.CompanyId = user.CompanyId item.CompanyName = user.CompanyName item.RealName = user.RealName item.Type = 1 item.CreateTime = time.Now() item.ModifyTime = time.Now() item.Source = 2 itemsFllow = append(itemsFllow, item) } } //处理策略 categoryIds = strings.TrimRight(categoryIds, ",") if categoryIds != "" { sliceCategoryId := strings.Split(categoryIds, ",") for _, v := range sliceCategoryId { item := new(models.CygxXzsChooseCategory) categoryId, _ := strconv.Atoi(v) item.CategoryId = categoryId item.IdCygx = mapReport[categoryId] item.UserId = user.UserId item.Mobile = user.Mobile item.Email = user.Email item.CompanyId = user.CompanyId item.CompanyName = user.CompanyName item.RealName = user.RealName item.CreateTime = time.Now() item.ModifyTime = time.Now() itemsCategory = append(itemsCategory, item) } } } //医药、消费、科技、智造、研选下的产业赛道 mapIndustrial := make(map[int][]*models.IndustrialManagementRep) industrialList, err := models.GetindustrialManagement() if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取产业信息失败,Err:" + err.Error() return } for _, v := range industrialList { mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v) } //策略下的产业赛道 celueList, err := models.GetReportMappingStrategyAll() if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取产业信息失败,Err:" + err.Error() return } mobile := user.Mobile item := new(models.CygxXzsChooseSend) item.UserId = user.UserId item.Mobile = user.Mobile item.Email = user.Email item.CompanyId = user.CompanyId item.CompanyName = user.CompanyName item.RealName = user.RealName item.CreateTime = time.Now() item.ModifyTime = time.Now() item.IsRefuse = req.IsRefuse item.IsSubjective = isSubjective item.IsObjective = isObjective if industrialFllowNum[utils.YI_YAO_ID] == len(mapIndustrial[utils.YI_YAO_ID]) { item.AllInYiYao = 1 //如果医药全选则设为1 } if industrialFllowNum[utils.XIAO_FEI_ID] == len(mapIndustrial[utils.XIAO_FEI_ID]) { item.AllInXiaoFei = 1 //如果消费全选则设为1 } if industrialFllowNum[utils.KE_JI_ID] == len(mapIndustrial[utils.KE_JI_ID]) { item.AllInKeJi = 1 //如果科技全选则设为1 } if industrialFllowNum[utils.ZHI_ZAO_ID] == len(mapIndustrial[utils.ZHI_ZAO_ID]) { item.AllInZhiZao = 1 //如果智造全选则设为1 } if industrialFllowNum[utils.CHART_PERMISSION_ID_YANXUAN] == len(mapIndustrial[utils.CHART_PERMISSION_ID_YANXUAN]) { item.AllInYanXuan = 1 //如果研选全选则设为1 } if industrialFllowNum[utils.CE_LUE_ID] == len(celueList) { item.AllInCeLue = 1 //如果策略全选则设为1 } count, err := models.GetXzsChooseSendCountByMobile(mobile) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error() return } //如果有记录就新增,没有记录就修改 if count == 0 { err = models.AddCygxXzsChooseSend(item, itemsFllow, itemsCategory) } else { err = models.UpdateCygxXzsChooseSend(item, itemsFllow, itemsCategory) } if err != nil { br.Msg = "保存失败!" br.ErrMsg = "保存失败!,Err:" + err.Error() return } go services.UserSubmit(itemsFllow, itemsCategory, user.UserId) br.Ret = 200 br.Success = true br.Msg = "保存成功" }