123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730 |
- 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)
- mapIndustrialFollow := make(map[int][]*models.IndustrialManagementRep) // 重点关注的行业下的数组结构
- mapIndustrialPush := make(map[int][]*models.IndustrialManagementRep) // 接受推送的行业下的数组结构
- mapIndustrialUninterested := make(map[int][]*models.IndustrialManagementRep) // 不感兴趣的行业下的数组结构
- //mapFllow := make(map[int]int)
- checkListFollow := make(map[int]int) // 重点关注的ID
- checkListPush := make(map[int]int) // 接受推送的ID
- checkListUninterested := make(map[int]int) // 不感兴趣的ID
- mapCategory := make(map[int]int)
- //ampCheckList := make(map[int][]int, 0)
- ampCheckListFollow := make(map[int][]int, 0) // 重点关注的ID
- ampCheckListPush := make(map[int][]int, 0) // 接受推送的ID
- ampCheckListUninterested := make(map[int][]int, 0) // 不感兴趣的ID
- //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
- switch v.FollowType {
- case 1:
- checkListFollow[v.IndustrialManagementId] = v.IndustrialManagementId
- case 0:
- checkListPush[v.IndustrialManagementId] = v.IndustrialManagementId
- case 3:
- checkListUninterested[v.IndustrialManagementId] = v.IndustrialManagementId
- }
- }
- industrialList, err := models.GetindustrialManagement()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
- return
- }
- for _, v := range industrialList {
- if v.ChartPermissionId == utils.ZHOU_QI_ID {
- continue
- }
- //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)
- v.IsFllow = true
- if checkListFollow[v.IndustrialManagementId] > 0 {
- //添加重点关注的行业赛道
- ampCheckListFollow[v.ChartPermissionId] = append(ampCheckListFollow[v.ChartPermissionId], v.IndustrialManagementId)
- mapIndustrialFollow[v.ChartPermissionId] = append(mapIndustrialFollow[v.ChartPermissionId], v)
- } else if checkListUninterested[v.IndustrialManagementId] > 0 {
- //添加不感兴趣的行业赛道
- ampCheckListUninterested[v.ChartPermissionId] = append(ampCheckListUninterested[v.ChartPermissionId], v.IndustrialManagementId)
- mapIndustrialUninterested[v.ChartPermissionId] = append(mapIndustrialUninterested[v.ChartPermissionId], v)
- } else {
- //添加接受推送的行业赛道
- mapIndustrialPush[v.ChartPermissionId] = append(mapIndustrialPush[v.ChartPermissionId], v)
- ampCheckListPush[v.ChartPermissionId] = append(ampCheckListPush[v.ChartPermissionId], v.IndustrialManagementId)
- }
- }
- 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
- }
- //策略固收的处理
- categoryListFollow, err := models.GetCygxXzsChooseCategoryList(mobile)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- checkListCelueFollow := make(map[int]int) // 重点关注的ID
- checkListCeluePush := make(map[int]int) // 接受推送的ID
- checkListCelueUninterested := make(map[int]int) // 不感兴趣的ID
- for _, v := range categoryListFollow {
- //mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
- switch v.FollowType {
- case 1:
- checkListCelueFollow[v.CategoryId] = v.CategoryId
- case 0:
- checkListCeluePush[v.CategoryId] = v.CategoryId
- case 3:
- checkListCelueUninterested[v.CategoryId] = v.CategoryId
- }
- }
- for _, v := range categoryListFollow {
- mapCategory[v.CategoryId] = v.CategoryId
- }
- celueList, err := models.GetReportMappingStrategyAll()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
- return
- }
- for _, v := range celueList {
- v.IsFllow = true
- if checkListCelueFollow[v.IndustrialManagementId] > 0 {
- //添加重点关注的行业赛道
- ampCheckListFollow[v.ChartPermissionId] = append(ampCheckListFollow[v.ChartPermissionId], v.IndustrialManagementId)
- mapIndustrialFollow[v.ChartPermissionId] = append(mapIndustrialFollow[v.ChartPermissionId], v)
- } else if checkListCelueUninterested[v.IndustrialManagementId] > 0 {
- //添加不感兴趣的行业赛道
- ampCheckListUninterested[v.ChartPermissionId] = append(ampCheckListUninterested[v.ChartPermissionId], v.IndustrialManagementId)
- mapIndustrialUninterested[v.ChartPermissionId] = append(mapIndustrialUninterested[v.ChartPermissionId], v)
- } else {
- //添加接受推送的行业赛道
- mapIndustrialPush[v.ChartPermissionId] = append(mapIndustrialPush[v.ChartPermissionId], v)
- ampCheckListPush[v.ChartPermissionId] = append(ampCheckListPush[v.ChartPermissionId], v.IndustrialManagementId)
- }
- }
- //策略、固收的处理 end
- //周期的处理
- zhouqiListFollow, err := models.GetCygxXzsChooseCategoryZhouqiList(mobile)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- checkListZhouqiFollow := make(map[int]int) // 重点关注的ID
- checkListZhouqiPush := make(map[int]int) // 接受推送的ID
- checkListZhouqiUninterested := make(map[int]int) // 不感兴趣的ID
- for _, v := range zhouqiListFollow {
- //mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
- switch v.FollowType {
- case 1:
- checkListZhouqiFollow[v.CategoryId] = v.CategoryId
- case 0:
- checkListZhouqiPush[v.CategoryId] = v.CategoryId
- case 3:
- checkListZhouqiUninterested[v.CategoryId] = v.CategoryId
- }
- }
- zhouqiList, err := models.GetCygxZhouqiArticleMapFirst()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
- return
- }
- for _, vZhouqi := range zhouqiList {
- v := new(models.IndustrialManagementRep)
- v.IsFllow = true
- v.IndustrialManagementId = vZhouqi.CategoryId
- v.IndustryName = vZhouqi.MatchTypeName
- v.ChartPermissionId = utils.ZHOU_QI_ID
- if checkListZhouqiFollow[v.IndustrialManagementId] > 0 {
- //添加重点关注的行业赛道
- ampCheckListFollow[v.ChartPermissionId] = append(ampCheckListFollow[v.ChartPermissionId], v.IndustrialManagementId)
- mapIndustrialFollow[v.ChartPermissionId] = append(mapIndustrialFollow[v.ChartPermissionId], v)
- } else if checkListZhouqiUninterested[v.IndustrialManagementId] > 0 {
- //添加不感兴趣的行业赛道
- ampCheckListUninterested[v.ChartPermissionId] = append(ampCheckListUninterested[v.ChartPermissionId], v.IndustrialManagementId)
- mapIndustrialUninterested[v.ChartPermissionId] = append(mapIndustrialUninterested[v.ChartPermissionId], v)
- } else {
- //添加接受推送的行业赛道
- mapIndustrialPush[v.ChartPermissionId] = append(mapIndustrialPush[v.ChartPermissionId], v)
- ampCheckListPush[v.ChartPermissionId] = append(ampCheckListPush[v.ChartPermissionId], v.IndustrialManagementId)
- }
- }
- //周期的处理end
- 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 || v.PermissionName == utils.GU_SHOU_NAME {
- // permissionList[k].List = celueList
- // //permissionList[k].AllTracks = "全系列报告"
- //} else if v.PermissionName == utils.ZHOU_QI_NAME {
- //
- //} 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(mapIndustrialFollow[v.ChartPermissionId]) == 0 {
- permissionList[k].ListFollow = make([]*models.IndustrialManagementRep, 0)
- } else {
- permissionList[k].ListFollow = mapIndustrialFollow[v.ChartPermissionId]
- }
- if len(mapIndustrialPush[v.ChartPermissionId]) == 0 {
- permissionList[k].ListPush = make([]*models.IndustrialManagementRep, 0)
- } else {
- permissionList[k].ListPush = mapIndustrialPush[v.ChartPermissionId]
- }
- if len(mapIndustrialUninterested[v.ChartPermissionId]) == 0 {
- permissionList[k].ListUninterested = make([]*models.IndustrialManagementRep, 0)
- } else {
- permissionList[k].ListUninterested = mapIndustrialUninterested[v.ChartPermissionId]
- }
- //}
- //if len(ampCheckList[v.ChartPermissionId]) == 0 {
- // permissionList[k].CheckList = make([]int, 0)
- //} else {
- // permissionList[k].CheckList = ampCheckList[v.ChartPermissionId]
- //}
- if len(ampCheckListFollow[v.ChartPermissionId]) == 0 {
- permissionList[k].CheckListFollow = make([]int, 0)
- } else {
- permissionList[k].CheckListFollow = ampCheckListFollow[v.ChartPermissionId]
- }
- if len(ampCheckListPush[v.ChartPermissionId]) == 0 {
- permissionList[k].CheckListPush = make([]int, 0)
- } else {
- permissionList[k].CheckListPush = ampCheckListPush[v.ChartPermissionId]
- }
- if len(ampCheckListUninterested[v.ChartPermissionId]) == 0 {
- permissionList[k].CheckListUninterested = make([]int, 0)
- } else {
- permissionList[k].CheckListUninterested = ampCheckListUninterested[v.ChartPermissionId]
- }
- v.HasCheck = utils.InArrayByStr(slicepermissionId, strconv.Itoa(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.IsPush = 1 - resp.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 = "保存成功"
- }
- // @Title 提交用户的选择关注的类型
- // @Description 提交用户的选择关注的类型接口
- // @Param request body models.SubmitChooseSendResp true "type json string"
- // @Success 200 {object} models.CygxXzsChooseSendResp
- // @router /choose/submit_follow_type [post]
- func (this *UserController) ChooseSubmitFollowType() {
- 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.SubmitChooseSendFollowTypeResp
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- 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
- }
- followType := req.FollowType
- listReq := req.List
- var itemsFllow []*models.CygxIndustryFllow
- var itemsCategory []*models.CygxXzsChooseCategory
- var itemsZhouqi []*models.CygxXzsChooseCategoryZhouqi
- var zhouqiIds []int
- var celueIds []int
- var industryIds []int
- for _, vChartPermissionn := range listReq {
- if vChartPermissionn.ChartPermissionName == utils.CE_LUE_NAME || vChartPermissionn.ChartPermissionName == utils.GU_SHOU_NAME {
- //策略与固收
- for _, v := range vChartPermissionn.CheckList {
- item := new(models.CygxXzsChooseCategory)
- categoryId := v
- item.CategoryId = v
- 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.FollowType = followType
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- itemsCategory = append(itemsCategory, item)
- celueIds = append(celueIds, v)
- }
- } else if vChartPermissionn.ChartPermissionName == utils.ZHOU_QI_NAME {
- //周期
- for _, v := range vChartPermissionn.CheckList {
- item := new(models.CygxXzsChooseCategoryZhouqi)
- item.CategoryId = v
- item.UserId = user.UserId
- item.Email = user.Email
- item.Mobile = user.Mobile
- item.RealName = user.RealName
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.FollowType = followType
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- itemsZhouqi = append(itemsZhouqi, item)
- zhouqiIds = append(zhouqiIds, v)
- }
- } else {
- //正常带有产业的行业
- for _, v := range vChartPermissionn.CheckList {
- item := new(models.CygxIndustryFllow)
- item.IndustrialManagementId = v
- 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.FollowType = followType
- if followType == 3 {
- item.FollowTypeOrder = -1
- } else {
- item.FollowTypeOrder = followType
- }
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.Source = 2
- itemsFllow = append(itemsFllow, item)
- industryIds = append(industryIds, v)
- }
- }
- }
- err = models.AddCygxXzsChooseSendFollow(user.Mobile, itemsFllow, itemsCategory, itemsZhouqi, industryIds, celueIds, zhouqiIds)
- if err != nil {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // @Title 推送更新内容
- // @Description 推送更新内容接口
- // @Param request body models.SubmitChooseSendResp true "type json string"
- // @Success 200 {object} models.CygxXzsChooseSendResp
- // @router /choose/submit_push [post]
- func (this *UserController) ChooseSubmitPush() {
- 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
- }
- isPush := req.IsPush // 是否接受推送
- //isRefuse := req.IsRefuse
- isSubjective := req.IsSubjective
- isObjective := req.IsObjective
- req.IsRefuse = 1 - isPush // 是否拒绝推送,与是否接收推送进行取反(兼容老的数据库字段)
- isRefuse := req.IsRefuse
- if isRefuse == 0 && isSubjective == 0 && isObjective == 0 {
- br.Msg = "请至少选择一项主客观内容"
- return
- }
- //如果为1 则不做任何推送 ,主观客观默认改成0
- if isRefuse == 1 {
- isSubjective = 0
- isObjective = 0
- }
- 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 = isRefuse
- item.IsSubjective = isSubjective
- item.IsObjective = isObjective
- count, err := models.GetXzsChooseSendCountByMobile(mobile)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
- return
- }
- //如果有记录就新增,没有记录就修改
- if count == 0 {
- err = models.AddCygxXzsChooseSendPush(item)
- } else {
- err = models.UpdateCygxXzsChooseSendPush(item)
- }
- if err != nil {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
|