123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- package services
- import (
- "errors"
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/utils"
- "strconv"
- "strings"
- "time"
- )
- func AddCygxTagHistory(user *models.WxUserItem, tagId int) (err error) {
- if user.UserId == 0 {
- return
- }
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("tag点击信息记录失败"+err.Error()+"tagId"+strconv.Itoa(tagId)+"userId:"+strconv.Itoa(user.UserId), 2)
- }
- }()
- historyRecord := new(models.CygxTagHistory)
- historyRecord.UserId = user.UserId
- historyRecord.TagId = tagId
- historyRecord.CreateTime = time.Now()
- historyRecord.Mobile = user.Mobile
- historyRecord.Email = user.Email
- historyRecord.CompanyId = user.CompanyId
- historyRecord.CompanyName = user.CompanyName
- historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
- sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- historyRecord.RealName = user.RealName
- if sellerItem != nil {
- historyRecord.SellerName = sellerItem.RealName
- }
- _, err = models.AddCygxTagHistory(historyRecord)
- return
- }
- //func init() {
- // conditionInit, err := GetConditionInitByTagIds("43")
- // fmt.Println(err)
- // fmt.Println()
- // fmt.Println(conditionInit)
- //}
- func GetConditionInitByTagIds(tagIds string) (conditionInit string, err error) {
- if tagIds == "" {
- return
- }
- var condition string
- var pars []interface{}
- var searchTag, industries, subjectNames []string
- tagslice := strings.Split(tagIds, ",")
- condition = ` AND tag_id IN (` + utils.GetOrmInReplace(len(tagslice)) + `)`
- pars = append(pars, tagslice)
- listTag, e := models.GetCygxTagListCondition(condition, pars, 0, 0)
- if e != nil {
- err = errors.New("GetActivityListByCondition, Err: " + e.Error())
- return
- }
- for _, tagInfo := range listTag {
- //ActivityTypes 与 ArticleTypes 进行合并
- if tagInfo.ActivityTypes != "" {
- sliceObj := strings.Split(tagInfo.ActivityTypes, ",")
- for _, v := range sliceObj {
- searchTag = append(searchTag, v)
- }
- }
- if tagInfo.ArticleTypes != "" {
- sliceObj := strings.Split(tagInfo.ArticleTypes, ",")
- for _, v := range sliceObj {
- searchTag = append(searchTag, v)
- }
- }
- if tagInfo.Industries != "" {
- sliceObj := strings.Split(tagInfo.Industries, ",")
- for _, v := range sliceObj {
- industries = append(industries, v)
- }
- //industries = append(industries, tagInfo.Industries)
- }
- if tagInfo.SubjectNames != "" {
- sliceObj := strings.Split(tagInfo.SubjectNames, ",")
- for _, v := range sliceObj {
- subjectNames = append(subjectNames, v)
- }
- //subjectNames = append(subjectNames, tagInfo.SubjectNames)
- }
- }
- //拼接search_tag 搜索内容
- if len(searchTag) > 0 {
- //search_tag_two 兼容报告类型一对多的这种,时间不够,产品也有可能变先这么做
- conditionInit += " AND ( search_tag IN ('" + strings.Join(searchTag, "','") + "') OR search_tag_two IN( '" + strings.Join(searchTag, "','") + "' ) )"
- }
- var resourceDataIds []int //cygx_resource_data 主键ID
- //如果产业有组合,那么就去捞产业相关的内容
- if len(industries) > 0 {
- var conditionIndustry string
- var parsIndustry []interface{}
- conditionIndustry += " AND industry_name IN ('" + strings.Join(industries, "','") + "')"
- listIndustry, e := models.GetTopOneMonthArtReadNumIndustryAll(conditionIndustry, parsIndustry)
- if e != nil {
- err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
- return
- }
- var industrialManagementIds []int // 产业ID合集
- for _, v := range listIndustry {
- industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
- }
- var conditionIndustryResource string
- var parsIndustryResource []interface{}
- lenArrindustrial := len(industrialManagementIds)
- conditionIndustryResource = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(lenArrindustrial) + `)`
- parsIndustryResource = append(parsIndustryResource, industrialManagementIds)
- if lenArrindustrial > 0 {
- listResourceDataIndustrial, e := models.GetCygxResourceDataIndustrialGroupManagementList(conditionIndustryResource, parsIndustryResource, 0, 0)
- //return
- if e != nil {
- err = errors.New("GetCygxResourceDataIndustrialGroupManagementList, Err: " + e.Error())
- return
- }
- for _, v := range listResourceDataIndustrial {
- resourceDataIds = append(resourceDataIds, v.ResourceDataId)
- }
- }
- }
- //return
- //如果标的有组合,那么就去捞标的相关的内容
- if len(subjectNames) > 0 {
- var conditionsubject string
- var parssubject []interface{}
- conditionsubject += " AND subject_name IN ('" + strings.Join(subjectNames, "','") + "')"
- listsubject, e := models.GetCygxIndustrialSubjectListCondition(conditionsubject, parssubject)
- if e != nil {
- err = errors.New("GetTopOneMonthArtReadNumIndustry, Err: " + e.Error())
- return
- }
- var industrialsubjectIds []int // 标的ID集合
- for _, v := range listsubject {
- industrialsubjectIds = append(industrialsubjectIds, v.IndustrialSubjectId)
- }
- var conditionsubjectResource string
- var parssubjectResource []interface{}
- lenArrsubject := len(industrialsubjectIds)
- conditionsubjectResource = ` AND industrial_subject_id IN (` + utils.GetOrmInReplace(lenArrsubject) + `)`
- parssubjectResource = append(parssubjectResource, industrialsubjectIds)
- if lenArrsubject > 0 {
- listResourceDatasubject, e := models.GetCygxResourceDataIndustrialGroupSubjectList(conditionsubjectResource, parssubjectResource, 0, 0)
- if e != nil {
- err = errors.New("GetCygxResourceDataIndustrialGroupSubjectList, Err: " + e.Error())
- return
- }
- for _, v := range listResourceDatasubject {
- resourceDataIds = append(resourceDataIds, v.ResourceDataId)
- }
- }
- }
- //拼接 cygx_resource_data 表主键查询ID
- if len(resourceDataIds) > 0 {
- var resourceDataIdStrs []string
- resourceDataIdMap := make(map[int]bool)
- for _, v := range resourceDataIds {
- if resourceDataIdMap[v] {
- continue
- }
- resourceDataIdStrs = append(resourceDataIdStrs, strconv.Itoa(v))
- resourceDataIdMap[v] = true
- }
- conditionInit += " AND id IN (" + strings.Join(resourceDataIdStrs, ",") + ") "
- }
- return
- }
|