package cygx

import (
	"encoding/json"
	"fmt"
	"github.com/rdlucklib/rdluck_tools/paging"
	"github.com/tealeg/xlsx"
	"hongze/hz_crm_api/controllers"
	"hongze/hz_crm_api/models"
	"hongze/hz_crm_api/models/company"
	"hongze/hz_crm_api/models/cygx"
	"hongze/hz_crm_api/models/roadshow"
	"hongze/hz_crm_api/models/system"
	"hongze/hz_crm_api/services"
	cygxService "hongze/hz_crm_api/services/cygx"
	"hongze/hz_crm_api/utils"
	"os"
	"path/filepath"
	"sort"
	"strconv"
	"strings"
	"time"
)

// 权益用户管理
type UserController struct {
	controllers.BaseAuthController
}

// List
// @Title 用户列表
// @Description 用户列表接口
// @Param   PageSize   query   int  true       "每页数据条数"
// @Param   CurrentIndex   query   int  true       "当前页页码，从1开始"
// @Param   Status   query   string  true       "状态：”试用','永续','冻结','流失','正式'"
// @Param   IsMaker   query   int  false       "是否决策人，1:是，0:否 ，2：全部'"
// @Param   IsRegister   query   int  false       "是否决策人，1:是，0:否 ，2：全部'"
// @Param   AdminId   query   string  true       "销售id，多个用英文逗号隔开，空字符串为全部"
// @Param   KeyWord   query   string  true       "搜索关键词"
// @Param   Label   query   string  true       "搜索用户标签"
// @Param   TryStage   query   int  false       "试用客户子标签：0全部、1未分类、2 推进、3 跟踪、4 预备。正式：套餐类型，0：无，1：大套餐，2：小套餐"
// @Param   SortType   query   string  true       "如何排序，是正序还是倒序，枚举值：`asc 正序`,`desc 倒叙`"
// @Param   IsSubscribeCygx   query   int  true       "是否关注了查研观向小助手公众号: -1-默认全部; 0-未关注; 1-已关注"
// @Success 200 {object} cygx.CompanyUserListResp
// @router /user/list [get]
func (this *UserController) List() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	roleTypeCode := sysUser.RoleTypeCode
	pageSize, _ := this.GetInt("PageSize")
	currentIndex, _ := this.GetInt("CurrentIndex")
	isMaker, _ := this.GetInt("IsMaker")
	isRegister, _ := this.GetInt("IsRegister")
	status := this.GetString("Status")
	adminId := this.GetString("AdminId")
	keyWord := this.GetString("KeyWord")
	label := this.GetString("Label")
	tryStage, _ := this.GetInt("TryStage") //试用客户标签
	sortType := this.GetString("SortType") //试用客户标签
	// 套餐类型
	//packageType, _ := this.GetInt("PackageType")
	keyWord = strings.Trim(keyWord, " ")
	keyWord = strings.Replace(keyWord, "'", "", -1)
	isSubscribeCygx, _ := this.GetInt("IsSubscribeCygx", -1)

	if status == "X类试用" {
		status = "永续"
	}
	var total int
	page := paging.GetPaging(currentIndex, pageSize, total)

	//statusItems := make([]*company.CompanyStatus, 0)
	//var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}

	var startSize int
	if pageSize <= 0 {
		pageSize = utils.PageSize20
	}
	if currentIndex <= 0 {
		currentIndex = 1
	}
	startSize = paging.StartIndex(currentIndex, pageSize)
	var condition string
	var sqlOrder string
	var usercondition string
	var kwywordcondition string
	var pars []interface{}
	var parsUser []interface{}

	//流失
	var lossCondition string
	//var lossPars []interface{}

	//状态分类查询条件
	//var permissionCondition string
	if adminId != "" {
		condition += ` AND b.seller_id IN (` + adminId + `) `
	}

	lossCondition = condition
	//lossPars = pars
	//permissionCondition = condition

	//流失客户统计
	lossCondition += ` AND status='流失' `

	if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER { //权益销售的查询逻辑
		condition += ` AND ( cp.seller_id = ` + strconv.Itoa(sysUser.AdminId) + `  OR cp.share_seller_id = ` + strconv.Itoa(sysUser.AdminId) + `)`
	} else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP { // 权益销售组长查询逻辑
		adminList, err := system.GetAdminListByGroupId(sysUser.GroupId)
		if err != nil {
			br.Msg = "获取失败"
			br.ErrMsg = "获取失败，GetAdminListByGroupIdErr:" + err.Error()
			return
		}
		var adminIds []string
		var companyIdsStr []string
		for _, v := range adminList {
			adminIds = append(adminIds, strconv.Itoa(v.AdminId))
		}
		//再获取组员下被共享的公司
		var parsShare []interface{}
		var conditionShare string
		conditionShare = "  AND  share_seller_id  IN (" + strings.Join(adminIds, ",") + ")  "
		listCompanyProduct, err := company.GetCompanyProductList(conditionShare, parsShare)
		if err != nil {
			br.Msg = "获取失败"
			br.ErrMsg = "获取失败，GetCompanyProductList:" + err.Error()
			return
		}
		for _, v := range listCompanyProduct {
			companyIdsStr = append(companyIdsStr, strconv.Itoa(v.CompanyId))
		}
		companyIdsStr = append(companyIdsStr, "0")
		//本组的或者被分享到本组下面的公司
		condition += ` AND (cp.group_id = ` + strconv.Itoa(sysUser.GroupId) + `  OR cp.company_id IN (` + strings.Join(companyIdsStr, ",") + `) )`
	}

	//状态控制
	if status != "" && status != "全部" {
		condition += ` AND b.status= '` + status + `'`
		usercondition += ` AND cp.status= '` + status + `'`
	} else {
		condition += ` AND b.status IN ('正式','试用','冻结','永续') `
	}

	// 试用客户标签
	if (status == "试用" || status == "永续") && tryStage > 0 {
		condition += ` AND b.try_stage= '` + strconv.Itoa(tryStage) + `'`
		usercondition += ` AND cp.try_stage= '` + strconv.Itoa(tryStage) + `'`
	}
	//套餐类型 权益客户除了大套餐就是小套餐
	if status == "正式" && tryStage > 0 {
		if tryStage == 1 {
			condition += ` AND b.package_type= '` + strconv.Itoa(tryStage) + `'`
			usercondition += ` AND cp.package_type= '` + strconv.Itoa(tryStage) + `'`
		} else {
			condition += ` AND b.package_type!= 1 `
			usercondition += ` AND cp.package_type != 1 `
		}
	}

	if isMaker != 2 {
		if isMaker == 1 {
			usercondition += ` AND u.is_maker = 1 `
		} else {
			//部分脏数据
			usercondition += ` AND u.is_maker != 1 `
		}
		//parsUser = append(parsUser, isMaker)
	}

	if isRegister != 2 {
		if isRegister == 1 {
			usercondition += `  AND u.register_time IS NOT NULL`
		} else {
			//部分脏数据
			usercondition += ` AND u.register_time IS NULL`
		}

		//parsUser = append(parsUser, isRegister)
	}
	kwywordcondition = condition
	if keyWord != "" {
		companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
		if err != nil {
			br.Msg = "获取客户信息失败"
			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
			return
		}
		if companyIdStr != "" {
			condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' AND  a.company_id IN(` + companyIdStr + `)) `
		} else {
			condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' ) `
		}
	}
	if label != "" {
		usercondition += ` AND u.user_label LIKE '%` + label + `%'`
	}
	//
	usercondition += ` AND cp.product_id = 2  	AND sr.product_id = 2  `

	// 是否关注弘则研究公众号
	if isSubscribeCygx == 0 {
		usercondition += ` AND (u.cygx_subscribe = 0 OR ISNULL(u.cygx_subscribe)) `
	}
	if isSubscribeCygx == 1 {
		usercondition += ` AND u.cygx_subscribe = 1 `
	}
	condition += ` AND cp.product_id = 2  `
	total, err := cygx.GetCompanyListCount(usercondition, keyWord, kwywordcondition, condition, roleTypeCode, pars)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取数据总数失败，Err:" + err.Error()
		return
	}
	if sortType == "" {
		sqlOrder = ` GROUP by u.user_id  ORDER BY c.created_time  DESC, u.register_time  DESC `
	} else {
		if sortType == "asc" {
			sqlOrder = ` GROUP by u.user_id  ORDER BY u.interaction_num  ASC , u.register_time  DESC `
		} else {
			sqlOrder = ` GROUP by u.user_id  ORDER BY u.interaction_num  DESC , u.register_time  DESC  `
		}
	}

	list, err := cygx.GetCygxCompanyUserList(usercondition, keyWord, kwywordcondition, condition, roleTypeCode, sqlOrder, parsUser, startSize, pageSize)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取数据失败，Err:" + err.Error()
		return
	}
	var isAdminRole bool
	//如果不是管理员身份或者研究员身份则需要添加可见范围处理
	if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
		isAdminRole = true
	}
	var userIds string
	var userIdArr []int
	var companyIds []int
	if list != nil {
		for k, v := range list {
			if v.RegisterTime != "" {
				list[k].IsRegister = true
			} else {
				list[k].IsRegister = false
			}
			if v.IsShowSeeNum > 0 {
				list[k].IsShowSee = true
			}
			if v.Status == "正式" {
				if v.PackageType == 1 {
					list[k].Status += "(大套餐)"
				} else {
					list[k].Status += "(小套餐)"
				}
			}
			if v.Status == "试用" {
				if v.TryStage == 1 {
					list[k].Status += "(未分类)"
				} else if v.TryStage == 2 {
					list[k].Status += "(推进)"
				} else if v.TryStage == 3 {
					list[k].Status += "(跟踪)"
				} else if v.TryStage == 4 {
					list[k].Status += "(预备)"
				}
			}
			if v.Status == "永续" {
				v.Status = "X类试用"
			}
			userIds += strconv.Itoa(int(v.UserId)) + ","
			userIdArr = append(userIdArr, int(v.UserId))

			if !isAdminRole {
				list[k].CompanyInteractionNum = v.CompanyInteractionNumSeller
			}
			companyIds = append(companyIds, v.CompanyId)
		}
		userIds = strings.TrimRight(userIds, ",")
		splitList, err := cygx.GetCygxCompanyUserListSplit(userIds)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取失败"
			br.ErrMsg = "获取数据失败，Err:" + err.Error()
			return
		}
		//用户备注
		userRemarksList, err := cygx.GetUserRemarksListByUserIds(userIds)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取失败"
			br.ErrMsg = "获取数据失败，Err:" + err.Error()
			return
		}
		mapUserRemarks := make(map[int]string)
		for _, v := range userRemarksList {
			if mapUserRemarks[v.UserId] == "" {
				mapUserRemarks[v.UserId] = v.Content
			}
		}

		UserRemindListMap := cygxService.GetCygxUserRemindListMap(userIdArr)
		mapIsUserMaker := cygxService.GetCompanyProductIsUserMakerByCompanyIds(companyIds) //根据公司ID获取近四周之内有决策人互动的客户
		for k, v := range list {
			for _, vsplit := range splitList {
				if vsplit.UserId == v.UserId {
					list[k].HistoryNum = vsplit.HistoryNum
					list[k].CountNum = vsplit.CountNum
					list[k].IndustryFllowNum = vsplit.IndustryFllowNum
					list[k].DepartmentFollowNum = vsplit.DepartmentFollowNum
					list[k].KeyWordNum = vsplit.KeyWordNum
					list[k].OnLineNum = vsplit.OnLineNum
					list[k].OfficeNum = vsplit.OfficeNum
					list[k].ChartNum = vsplit.ChartNum
					list[k].TripNum = vsplit.TripNum
					list[k].RoadshowVideoNum = vsplit.RoadshowVideoNum
					list[k].ActivityVideoNum = vsplit.ActivityVideoNum
					list[k].ActivityVoiceNum = vsplit.ActivityVoiceNum
					list[k].YanxuanspecialNum = vsplit.YanxuanspecialNum
				}
			}
			if mapUserRemarks[int(v.UserId)] != "" {
				list[k].Content = mapUserRemarks[int(v.UserId)]
			}
			list[k].IsRemind = UserRemindListMap[int(v.UserId)]
			list[k].IsUserMaker = mapIsUserMaker[v.CompanyId]
		}
		for k := range list {
			list[k].InteractionNum = list[k].HistoryNum + list[k].CountNum + list[k].IndustryFllowNum + list[k].DepartmentFollowNum + list[k].KeyWordNum + list[k].OnLineNum + list[k].OfficeNum + list[k].ChartNum + list[k].TripNum + list[k].RoadshowVideoNum + list[k].ActivityVideoNum + list[k].ActivityVoiceNum + list[k].YanxuanspecialNum
		}
	} else {
		list = make([]*cygx.CygxCompanyUser, 0)
	}
	page = paging.GetPaging(currentIndex, pageSize, total)
	resp := new(cygx.CompanyUserListResp)
	resp.List = list
	resp.Paging = page
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 新增备注接口
// @Description 新增备注
// @Param	request	body cygx.UserRemarAddReq true "type json string"
// @Success 200 新增成功
// @router /user/addRemarks [post]
func (this *UserController) Add() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	var req cygx.UserRemarAddReq
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
	if err != nil {
		br.Msg = "参数解析异常！"
		br.ErrMsg = "参数解析失败，Err:" + err.Error()
		return
	}
	if req.Content == "" {
		br.Msg = "请填写内容"
		return
	}
	item := new(cygx.UserRemarks)
	item.UserId = req.UserId
	item.AdminId = sysUser.AdminId
	item.Content = req.Content
	item.CreateTime = time.Now()
	err = cygx.AddUserRemarks(item)
	if err != nil {
		br.Msg = "新增失败."
		br.ErrMsg = "新增失败,Err:" + err.Error()
		return
	}
	br.Ret = 200
	br.Success = true
	br.Msg = "新增成功"
}

// @Title 备注列表
// @Description 备注列表接口
// @Param  UserId   query   int  true       "用户id"
// @Success 200 {object} cygx.UserRemarksListResp
// @router /user/remark/list [get]
func (this *UserController) RemarkList() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	userId, _ := this.GetInt("UserId")
	if userId < 1 {
		br.Msg = "用户不存在"
		return
	}
	list, err := cygx.GetUserRemarksList(userId)
	if err != nil && err.Error() != utils.ErrNoRow() {
		br.Msg = "获取信息失败"
		br.ErrMsg = "获取备注信息失败,Err:" + err.Error()
		return
	}
	resp := new(cygx.UserRemarksListResp)
	resp.List = list
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp

}

// @Title 互动详情table栏
// @Description 互动详情table栏接口
// @Param  UserId   query   int  true       "用户id"
// @Param  ClassType   query   int  true       "列表类型，1：权益，2：研选，默认1"
// @Success 200 {object} cygx.UserRemarksListResp
// @router /user/table/list [get]
func (this *UserController) TableList() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	userId, _ := this.GetInt("UserId")
	if userId < 1 {
		br.Msg = "用户不存在"
		return
	}
	classType, _ := this.GetInt("ClassType", 1)
	wxUser, err := models.GetWxUserByUserId(userId)
	if err != nil {
		br.ErrMsg = "获取信息失败，Err:" + err.Error()
		br.Msg = "获取信息失败"
		return
	}
	comanyDetail, err := company.GetCompanyDetailById(wxUser.CompanyId)
	if err != nil {
		br.Msg = "获取信息失败"
		br.ErrMsg = "获取数据失败，Err:" + err.Error()
		return
	}

	resp := new(cygx.CygxUserTableListRep)
	if classType == 1 {
		countDetail, err := cygx.GetUserInteractionTableCount(userId)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取各个阅读总数失败，Err:" + err.Error()
			return
		}

		calendarTotal, err := roadshow.GetRsCalendarMeetingUserCountByUserId(userId)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "GetCygxUserFeedbackCountByUserId，Err:" + err.Error()
			return
		}
		List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: countDetail.HistoryNum},
			{PermissionName: "活动互动记录", Source: 2, TotalNum: countDetail.OnLineNum + countDetail.OfficeNum},
			{PermissionName: "专项调研", Source: 8, TotalNum: countDetail.TripNum},
			{PermissionName: "1v1路演", Source: 15, TotalNum: calendarTotal},
			{PermissionName: "收藏的报告", Source: 3, TotalNum: countDetail.CountNum},
			{PermissionName: "收藏的图表", Source: 4, TotalNum: countDetail.ChartNum},
			{PermissionName: "关注的产业", Source: 5, TotalNum: countDetail.IndustryFllowNum},
			{PermissionName: "搜索", Source: 7, TotalNum: countDetail.KeyWordNum},
			{PermissionName: "音视频播放", Source: 9, TotalNum: countDetail.RoadshowVideoNum + countDetail.ActivityVideoNum + countDetail.ActivityVoiceNum},
			{PermissionName: "首页标签点击", Source: 10, TotalNum: countDetail.TagNum},
			{PermissionName: "交流反馈", Source: 14, TotalNum: countDetail.FeedbackNum}}
		resp.List = List
	} else {
		countDetail, err := cygx.GetUserInteractionTableCountByYanXuan(userId)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取各个阅读总数失败，Err:" + err.Error()
			return
		}

		List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: countDetail.HistoryNum},
			{PermissionName: "活动互动记录", Source: 2, TotalNum: countDetail.OnLineNum + countDetail.OfficeNum},
			{PermissionName: "收藏的报告", Source: 3, TotalNum: countDetail.CountNum},
			{PermissionName: "关注的产业", Source: 5, TotalNum: countDetail.IndustryFllowNum},
			{PermissionName: "关注的作者", Source: 6, TotalNum: countDetail.DepartmentFollowNum},
			{PermissionName: "专栏文章阅读记录", Source: 11, TotalNum: countDetail.YanxuanSpecialNum},
			{PermissionName: "收藏的专栏文章", Source: 12, TotalNum: countDetail.YanxuanSpecialCollectNum},
			{PermissionName: "关注的专栏作者", Source: 13, TotalNum: countDetail.YanxuanSpecialFollowNum},
			{PermissionName: "搜索", Source: 7, TotalNum: countDetail.KeyWordNum}}
		resp.List = List
	}

	//阅读记录总数

	resp.UserName = wxUser.RealName
	resp.Mobile = wxUser.Mobile
	resp.ComapnyName = comanyDetail.CompanyName
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 互动详情
// @Description 互动详情接口
// @Param  UserId   query   int  true       "用户id"
// @Param  Source   query   int  true       "来源"
// @Param   IdentityType   query   int  true       "身份类型，1：用户，2机构。默认1 （图表分页使用）"
// @Param   IsMeeting   query   string  true       "是否到会 1到会、2未到会"
// @Param   MeetType   query   string  true       "参会方式 1线上，2线下 默认为线上"
// @Param   PageSize   query   int  true       "每页数据条数"
// @Param   CurrentIndex   query   int  true       "当前页页码，从1开始"
// @Param   StartDate   query   string  true       "开始时间"
// @Param   EndDate   query   string  true       "结束时间"
// @Param   KeyWord   query   string  true       "搜索关键词"
// @Param   ClassType   query   int  true       "列表类型，1：权益，2：研选，默认1"
// @Param   IsExport   query   bool  false       "是否导出excel，默认是false"
// @Success 200 {object} cygx.UserInteractionListResp
// @router /user/interaction/detail [get]
func (this *UserController) TableDetail() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	pageSize, _ := this.GetInt("PageSize")
	currentIndex, _ := this.GetInt("CurrentIndex")
	var startSize int
	if pageSize <= 0 {
		pageSize = utils.PageSize20
	}
	if currentIndex <= 0 {
		currentIndex = 1
	}
	startSize = paging.StartIndex(currentIndex, pageSize)
	userId, _ := this.GetInt("UserId")
	isMeeting := this.GetString("IsMeeting")
	meetType := this.GetString("MeetType")
	startDate := this.GetString("StartDate")
	endDate := this.GetString("EndDate")
	keyWord := this.GetString("KeyWord")
	source, _ := this.GetInt("Source")
	identityType, _ := this.GetInt("IdentityType")
	classType, _ := this.GetInt("ClassType", 1)
	//是否导出报表
	isExport, _ := this.GetBool("IsExport")
	if isExport {
		pageSize = 10000
		currentIndex = 1
	}
	if userId < 1 {
		br.Msg = "用户不存在"
		return
	}
	// 1.标记用户表
	//操作权限校验
	var err error
	wxUser, err := models.GetWxUserByUserId(userId)
	if err != nil {
		br.Msg = "获取信息失败"
		br.ErrMsg = "获取信息失败，Err:" + err.Error()
		return
	}
	mobile := wxUser.Mobile

	//var checkSource bool
	var MeetingNum int
	var NoMeetingNum int
	var list []*cygx.UserInteraction

	var total int
	var condition string
	var pars []interface{}
	if source == 1 {
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}
		if wxUser.Mobile == "" {
			wxUser.Mobile = wxUser.Email
		}
		//total, err = cygx.GetCygxArticleHistoryCount(wxUser.Mobile, wxUser.Email, condition)
		//if err != nil {
		//	br.Msg = "获取信息失败"
		//	br.ErrMsg = "获取用户阅读记录总数失败，Err:" + err.Error()
		//	return
		//}

		if classType == 1 {
			condition += "  AND art.article_type_id =  0 "
		} else {
			condition += "  AND art.article_type_id >  0 "
		}
		condition += " 	AND (r.mobile = '" + wxUser.Mobile + "'  OR  r.email = '" + wxUser.Mobile + "')  "

		total, list, err = cygx.GetCygxArticleHistoryRecordByUserNew(condition, startSize, pageSize)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}
		var articleIds string
		var articleIdArr []int
		if len(list) > 0 {
			articleIds = ""
			mapAricleId := make(map[int]int)
			mapAricleIndustrialSubjectName := make(map[int]*cygx.ArticleIndustrialSubjectNameResp)
			for k, v := range list {
				if v.ArticleId >= utils.SummaryArticleId {
					list[k].ArticleType = 1
				} else {
					list[k].ArticleType = 2
				}
				if mapAricleId[v.ArticleId] == 0 {
					articleIds += strconv.Itoa(v.ArticleId) + ","
					mapAricleId[v.ArticleId] = v.ArticleId
				}
				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
				list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
				articleIdArr = append(articleIdArr, v.ArticleId)
			}
			articleIds = strings.TrimRight(articleIds, ",")

			listArticleIndustrialSubjectList, err := cygx.GetCygxArticleIndustrialSubjectName(articleIds)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
			if len(listArticleIndustrialSubjectList) > 0 {
				for _, v := range listArticleIndustrialSubjectList {
					mapAricleIndustrialSubjectName[v.ArticleId] = v
				}
				for k, v := range list {
					if mapAricleIndustrialSubjectName[v.ArticleId] != nil {
						list[k].IndustryName = mapAricleIndustrialSubjectName[v.ArticleId].IndustryName     // 产业
						list[k].SubjectNameStr = mapAricleIndustrialSubjectName[v.ArticleId].SubjectNameStr // 标的
					}
				}
			}

			//行业
			mapPerssionName := cygxService.GetCygxArticlePerssionNameListMap(articleIdArr)
			for k, v := range list {
				if v.SpecialType > 0 {
					list[k].PermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
				} else {
					list[k].PermissionName = mapPerssionName[v.ArticleId]
				}
				if classType == 1 {
					list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
				} else {
					list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
				}
			}
		}

	} else if source == 2 {
		if mobile != "" {
			condition = ` AND s.mobile = '` + mobile + `' `
			if classType == 1 {
				condition += "  AND  a.chart_permission_id  != 31 "
			} else {
				condition += "  AND  a.chart_permission_id  = 31 "
			}

			if isMeeting == "1" {
				condition += ` AND s.is_meeting = 1 `
			}
			if isMeeting == "2" {
				condition += ` AND s.is_meeting = 0 `
			}

			if meetType == "1" {
				condition += ` AND t.activity_type = 1 `
			}
			if meetType == "2" {
				condition += ` AND t.activity_type = 0 `
			}
			if startDate != "" {
				startDate += " 00:00:00"
				condition += ` AND a.activity_time >= '` + startDate + `' `
			}

			if endDate != "" {
				endDate += " 23:59:59"
				condition += ` AND a.activity_time <= '` + endDate + `' `
			}

			if keyWord != "" {
				condition += ` AND a.activity_name LIKE '%` + keyWord + `%' `
			}

			total, err = cygx.GetActivityMeetByUserCount(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取参会总数失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetActivityMeetByUser(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取参会人数列表失败"
				return
			}
			if len(list) > 0 {
				for k, v := range list {
					if v.ActivityType == 1 {
						if v.SignupType == "2" {
							list[k].InteractionType = "自主拨入"
						} else {
							list[k].InteractionType = "预约外呼"
						}
						if v.ReminderNum > 0 {
							list[k].InteractionType += "会议提醒"
						}
					}
					if v.IsMeeting == 0 {
						list[k].FirstMeetingTime = ""
						list[k].LastMeetingTime = ""
					}
					if v.FirstMeetingTime == "0000-00-00 00:00:00" {
						list[k].FirstMeetingTime = ""
						list[k].LastMeetingTime = ""
					}
				}
			}
		}
	} else if source == 3 {
		if classType == 1 {
			condition += "  AND art.article_type_id =  0 "
		} else {
			condition += "  AND art.article_type_id >  0 "
		}

		total, err = cygx.GetCygxArticleCollectCount(userId, condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户收藏记录总数失败，Err:" + err.Error()
			return
		}
		list, err = cygx.GetCygxArticleCollectByUser(userId, startSize, pageSize, condition)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户搜藏记录失败，Err:" + err.Error()
			return
		}
		if len(list) > 0 {
			for k, v := range list {
				if v.ArticleId >= utils.SummaryArticleId {
					list[k].ArticleType = 1
				} else {
					list[k].ArticleType = 2
				}
				if classType == 1 {
					list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
				} else {
					list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
				}
			}
		}
	} else if source == 4 {
		if identityType == 2 {
			condition += ` AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
		}
		condition += ` AND a.publish_status = 1  AND  user_id =  ` + strconv.Itoa(userId)
		var err error
		total, err = cygx.GetChartCountByUser(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取总数失败，Err:" + err.Error()
			return
		}
		list, err = cygx.GetChartListCollectionWithCygx(condition, startSize, pageSize)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			return
		}
		for k, v := range list {
			if v.PtagName != "" {
				list[k].CtagNamePc = v.PtagName
			}
			if v.CtagName != "" {
				list[k].CtagNamePc += "," + v.CtagName
			}
			if v.PtagNameTwo != "" {
				list[k].CtagNamePc += "," + v.PtagNameTwo
			}
			if v.CtagNameTwo != "" {
				list[k].CtagNamePc += "," + v.CtagNameTwo
			}
		}
	} else if source == 5 {

		if classType == 1 {
			condition += "  AND a.chart_permission_id  = 31 "
		} else {
			condition += "  AND a.chart_permission_id  = 31 "
		}

		total, err = cygx.GetCygxIndustryFllowCount(userId, condition)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取用户关注总数失败"
			return
		}
		list, err = cygx.GetCygxIndustryFllowByUser(userId, startSize, pageSize, condition)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取用户关注总数失败"
			return
		}
	} else if source == 6 {
		total, err = cygx.GetCygArticleDepartmentFollowCount(userId)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取关注作者总数失败"
			return
		}
		list, err = cygx.GetCygArticleDepartmentFollowByUser(userId, startSize, pageSize)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取关注作者列表失败"
			return
		}
		if len(list) > 0 {
			for k, v := range list {
				var condition string
				var pars []interface{}
				condition += ` WHERE art.source = 1 AND art.is_summary = 1 AND art.department_id =  ` + strconv.Itoa(v.DepartmentId)
				listArt, errList := cygx.GetSummaryManageList(condition, pars, 0, 20)
				if errList != nil && errList.Error() != utils.ErrNoRow() {
					br.Msg = "获取失败"
					br.ErrMsg = "获取失败，Err:" + errList.Error()
					return
				}
				if len(listArt) > 0 {
					mapIndustryName := make(map[string]string)
					mapSubjectName := make(map[string]string)
					var articleIdStr string
					for _, vArt := range listArt {
						if vArt.IndustryName != "" && mapIndustryName[vArt.IndustryName] == "" {
							list[k].IndustryName += vArt.IndustryName + "/"
							mapIndustryName[vArt.IndustryName] = vArt.IndustryName
						}
						articleIdStr += strconv.Itoa(vArt.ArticleId) + ","
					}
					list[k].IndustryName = strings.TrimRight(list[k].IndustryName, "/")
					articleIdStr = strings.TrimRight(articleIdStr, ",")
					listSubject, err := cygx.GetArticleSubjectList(articleIdStr)
					if err != nil {
						br.Msg = "获取失败"
						br.ErrMsg = "获取失败，Err:" + err.Error()
						return
					}
					if len(listSubject) > 0 {
						for _, vSub := range listSubject {
							if vSub.SubjectName != "" && mapSubjectName[vSub.SubjectName] == "" {
								list[k].SubjectNameStr += vSub.SubjectName + "/"
								mapSubjectName[vSub.SubjectName] = vSub.SubjectName
							}
						}
						list[k].SubjectNameStr = strings.TrimRight(list[k].SubjectNameStr, "/")
					}
				}
			}
		}
	} else if source == 7 {
		if classType == 1 {
			condition += "  AND register_platform IN  (1,2)  "
		} else {
			condition += "  AND register_platform IN  (5,6)  "
		}
		total, err = cygx.GetCygxSearchKeyWordCount(userId, condition)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录失败"
			return
		}
		list, err = cygx.GetCygxSearchKeyWordByUser(condition, userId, startSize, pageSize)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录列表失败"
			return
		}
	} else if source == 8 {
		condition += ` 	AND h.user_id = ? `
		pars = append(pars, userId)
		total, err = cygx.GetCygxActivitySpecialTripCount(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录失败"
			return
		}
		list, err = cygx.GetCygxActivitySpecialTripByUser(userId, startSize, pageSize)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录列表失败"
			return
		}
	} else if source == 9 {
		total, err = cygx.GetCygxRoadshowCount(userId)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录失败"
			return
		}
		list, err = cygx.GetCygxRoadshowByUser(userId, startSize, pageSize)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录列表失败"
			return
		}
	} else if source == 10 { //标签点击记录
		total, err = cygx.GetCygxTagHistoryCountByUserId(userId)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录失败"
			return
		}
		list, err = cygx.GetCygxTagHistoryByUserId(userId, startSize, pageSize)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录列表失败"
			return
		}
	} else if source == 11 { //专栏文章阅读记录
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}
		if wxUser.Mobile == "" {
			wxUser.Mobile = wxUser.Email
		}
		condition += " 	AND (r.mobile = '" + wxUser.Mobile + "'  OR  r.email = '" + wxUser.Mobile + "')  "
		total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, startSize, pageSize)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}
		if len(list) > 0 {
			for k, v := range list {
				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
				list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
			}
		}
	} else if source == 12 { //收藏的专栏文章
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}
		if wxUser.Mobile == "" {
			wxUser.Mobile = wxUser.Email
		}
		condition += " 	AND (r.mobile = '" + wxUser.Mobile + "'  OR  r.email = '" + wxUser.Mobile + "')  "
		total, list, err = cygx.GetCygxYanxuanSpecialCollectByUser(condition, startSize, pageSize)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}
		if len(list) > 0 {
			for k, v := range list {
				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
				list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
			}
		}
	} else if source == 13 { //关注的专栏作者
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}
		if wxUser.Mobile == "" {
			wxUser.Mobile = wxUser.Email
		}
		condition += " 	AND (r.mobile = '" + wxUser.Mobile + "'  OR  r.email = '" + wxUser.Mobile + "')  "
		total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUser(condition, startSize, pageSize)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}
		if len(list) > 0 {
			for k, v := range list {
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/view/" + strconv.Itoa(v.DepartmentId)
			}
		}
	} else if source == 14 { //交流反馈
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}
		if wxUser.Mobile == "" {
			wxUser.Mobile = wxUser.Email
		}
		condition += " 	AND (r.mobile = '" + wxUser.Mobile + "'  OR  r.email = '" + wxUser.Mobile + "')  "
		total, list, err = cygx.GetCygxUserFeedback(condition, startSize, pageSize)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}
	} else if source == 15 { //1V1路演
		if startDate != "" {
			//startDate += " 00:00:00"
			condition += ` AND b.start_date >= '` + startDate + `' `
		}
		if endDate != "" {
			//endDate += " 23:59:59"
			condition += ` AND b.start_date <= '` + endDate + `' `
		}
		if wxUser.Mobile == "" {
			wxUser.Mobile = wxUser.Email
		}
		condition += " 	AND (r.mobile = '" + wxUser.Mobile + "'  OR  r.email = '" + wxUser.Mobile + "')  "
		totalRsCalendar, listRsCalendar, err := roadshow.GetRsCalendarMeetingUserByRai(condition, startSize, pageSize)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，GetRsCalendarMeetingUserByRai Err:" + err.Error()
			return
		}

		total = totalRsCalendar
		list, err = cygxService.HandleListRsCalendar(listRsCalendar)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "HandleListRsCalendar，Err:" + err.Error()
			return
		}

		//导出excel
		if isExport {
			exportListRsCalendar(this, list, 1, br)
			return
		}

	}
	page := paging.GetPaging(currentIndex, pageSize, total)
	resp := new(cygx.UserInteractionListResp)
	if len(list) == 0 {
		list = make([]*cygx.UserInteraction, 0)
	}
	resp.MeetingNum = MeetingNum
	resp.NoMeetingNum = NoMeetingNum
	resp.List = list
	resp.Paging = page
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// EnterScoreScoreListExport 导出Excel
func exportListRsCalendar(this *UserController, list []*cygx.UserInteraction, excelType int, br *models.BaseResponse) {

	dir, err := os.Executable()
	exPath := filepath.Dir(dir)
	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
	xlsxFile := xlsx.NewFile()
	if err != nil {
		br.Msg = "生成文件失败"
		br.ErrMsg = "生成文件失败"
		return
	}
	style := xlsx.NewStyle()
	border := xlsx.NewBorder("thin", "thin", "thin", "thin")
	alignment := xlsx.Alignment{
		Horizontal: "center",
		Vertical:   "center",
		WrapText:   true,
	}

	redStyle := xlsx.NewStyle()
	redStyle.Alignment = alignment
	redStyle.ApplyAlignment = true
	redStyle.Font.Color = "ff0000"
	redStyle.Border = *border

	style.Alignment = alignment
	style.ApplyAlignment = true

	sheel, err := xlsxFile.AddSheet("1V1路演")
	if err != nil {
		br.Msg = "新增Sheet失败"
		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
		return
	}
	sheel.SetColWidth(0, 0, 30)
	sheel.SetColWidth(1, 1, 15)
	sheel.SetColWidth(2, 2, 15)
	sheel.SetColWidth(3, 3, 18)

	titleRow := sheel.AddRow()

	if excelType > 2 {
		cellA := titleRow.AddCell()
		cellA.SetStyle(style)
		cellA.SetValue("客户名称")
	}

	if excelType > 1 {
		cellB := titleRow.AddCell()
		cellB.SetStyle(style)
		cellB.SetValue("姓名")

		cellC := titleRow.AddCell()
		cellC.SetStyle(style)
		cellC.SetValue("手机号")
	}

	cellD := titleRow.AddCell()
	cellD.SetStyle(style)
	cellD.SetValue("路演时间")

	cellE := titleRow.AddCell()
	cellE.SetStyle(style)
	cellE.SetValue("研究员")

	cellF := titleRow.AddCell()
	cellF.SetStyle(style)
	cellF.SetValue("路演形式")

	cellG := titleRow.AddCell()
	cellG.SetStyle(style)
	cellG.SetValue("主题标签")

	for _, v := range list {
		dataRow := sheel.AddRow()
		dataRow.SetHeight(20)

		if excelType > 2 {
			cellAData := dataRow.AddCell()
			cellAData.SetStyle(style)
			cellAData.Value = v.CompanyName
		}

		if excelType > 1 {
			cellBData := dataRow.AddCell()
			cellBData.SetStyle(style)
			cellBData.Value = v.RealName

			cellCData := dataRow.AddCell()
			cellCData.SetStyle(style)
			cellCData.Value = v.Mobile
		}

		cellDData := dataRow.AddCell()
		cellDData.SetStyle(style)
		cellDData.Value = v.ActivityTimeText

		cellEData := dataRow.AddCell()
		cellEData.SetStyle(style)
		cellEData.Value = v.ResearcherName

		cellFData := dataRow.AddCell()
		cellFData.SetStyle(style)
		if v.ActivityType == 1 {
			cellFData.Value = "线上"
		} else {
			cellFData.Value = "线下"
		}

		cellGData := dataRow.AddCell()
		cellGData.SetStyle(style)
		cellGData.Value = v.LabelKeyWord

	}
	err = xlsxFile.Save(downLoadnFilePath)
	if err != nil {
		br.Msg = "保存文件失败"
		br.ErrMsg = "保存文件失败"
		return
	}
	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
	downloadFileName := "1V1路演导出数据_" + randStr + ".xlsx"
	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
	defer func() {
		os.Remove(downLoadnFilePath)
	}()
	br.Ret = 200
	br.Success = true
	br.Msg = "导出成功"
}

// @Title 获取用户标签详情
// @Description 获取用户标签详情接口
// @Param  UserId   query   int  true       "用户id"
// @Success 200 {object} cygx.UserLabel
// @router /user/label/detail [get]
func (this *UserController) LabelDetail() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	userId, _ := this.GetInt("UserId")
	if userId < 1 {
		br.Msg = "用户不存在"
		return
	}
	wxUser, err := models.GetWxUserByUserId(userId)
	if err != nil {
		br.ErrMsg = "获取信息失败，Err:" + err.Error()
		br.Msg = "获取信息失败"
		return
	}

	if userId > 0 {
		resp := new(cygx.UserLabel)
		resp.Label = wxUser.UserLabel
		br.Ret = 200
		br.Success = true
		br.Msg = "获取成功"
		br.Data = resp
		return
	}

	list, err := cygx.GetCygxCompanyUserListSplit(strconv.Itoa(userId))
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取数据失败，Err:" + err.Error()
		return
	}
	mapLabels := make(map[string]string)
	var labelsListStr []*cygx.UserLabel

	mapActivityLabels := make(map[string]string)

	for k := range list {
		labels := list[k].Labels
		labelsList := strings.Split(labels, ",")
		for _, vL := range labelsList {
			if mapLabels[vL] == "" && vL != "" {
				mapLabels[vL] = vL
				item := new(cygx.UserLabel)
				item.Label = vL
				labelsListStr = append(labelsListStr, item)
			}
		}
	}
	dateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
	listArticlePv, err := cygx.GetArticlePvCount(wxUser.Mobile, wxUser.Email, dateTime)
	if err != nil && err.Error() != utils.ErrNoRow() {
		br.Msg = "获取失败"
		br.ErrMsg = "获取数据失败，Err:" + err.Error()
		return
	}
	var articleIds string
	mapArticleIdLabelTotal := make(map[string]int)
	mapArticleIdPv := make(map[int]int)
	if len(listArticlePv) > 0 {
		for _, v := range listArticlePv {
			articleIds += strconv.Itoa(v.ArticleId) + ","
			mapArticleIdPv[v.ArticleId] = v.Pv
		}
		articleIds = strings.TrimRight(articleIds, ",")
		//产业、标的标签
		listLabelName, err := cygx.GetArticleGroupyIndustryName(articleIds)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取失败"
			br.ErrMsg = "获取数据失败，Err:" + err.Error()
			return
		}
		if len(listLabelName) > 0 {
			for _, v := range listLabelName {
				labelsIndustryList := strings.Split(v.IndustryName, "/")
				labelsSubjectList := strings.Split(v.SubjectName, "/")
				//添加产业统计
				if len(labelsIndustryList) > 0 {
					for _, vIn := range labelsIndustryList {
						if mapActivityLabels[vIn] != "" {
							mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
						} else {
							mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
							mapActivityLabels[vIn] = vIn
						}
					}
				}
				if len(labelsSubjectList) > 0 {
					//添加标的统计
					for _, vIn := range labelsSubjectList {
						if mapActivityLabels[vIn] != "" {
							mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
						} else {
							mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
							mapActivityLabels[vIn] = vIn
						}
					}
				}
			}
		}
	}

	articleIds, err = cygx.GetCygxArticleCollectId(userId, dateTime)
	if err != nil && err.Error() != utils.ErrNoRow() {
		br.ErrMsg = "获取信息失败，Err:" + err.Error()
		br.Msg = "获取用户搜藏记录失败"
		return
	}
	if articleIds != "" {
		//产业、标的标签
		listLabelName, err := cygx.GetArticleGroupyIndustryName(articleIds)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取失败"
			br.ErrMsg = "获取数据失败，Err:" + err.Error()
			return
		}
		if len(listLabelName) > 0 {
			for _, v := range listLabelName {
				labelsIndustryList := strings.Split(v.IndustryName, "/")
				labelsSubjectList := strings.Split(v.SubjectName, "/")
				//添加产业统计
				if len(labelsIndustryList) > 0 {
					for _, vIn := range labelsIndustryList {
						if mapActivityLabels[vIn] != "" {
							mapArticleIdLabelTotal[vIn] += 1
						} else {
							mapArticleIdLabelTotal[vIn] = 1
							mapActivityLabels[vIn] = vIn
						}
					}
				}
				if len(labelsSubjectList) > 0 {
					//添加标的统计
					for _, vIn := range labelsSubjectList {
						if mapActivityLabels[vIn] != "" {
							mapArticleIdLabelTotal[vIn] += 1
						} else {
							mapArticleIdLabelTotal[vIn] = 1
							mapActivityLabels[vIn] = vIn
						}
					}
				}
			}
		}
	}

	//活动标签计算
	listActivityPv, err := cygx.GetActivitySignCount(wxUser.Mobile, dateTime)
	if err != nil && err.Error() != utils.ErrNoRow() {
		br.Msg = "获取失败"
		br.ErrMsg = "获取数据失败，Err:" + err.Error()
		return
	}
	if len(listActivityPv) > 0 {
		for _, v := range listActivityPv {
			labelsList := strings.Split(v.Label, "-")
			for _, v2 := range labelsList {
				labelsListSon := strings.Split(v2, "/")
				for _, v3 := range labelsListSon {
					if mapActivityLabels[v3] != "" {
						mapArticleIdLabelTotal[v3] += 1
					} else {
						mapArticleIdLabelTotal[v3] = 1
						mapActivityLabels[v3] = v3
					}
				}
			}
		}
	}
	//会议提醒部分标签
	listActivityPvByReminder, err := cygx.GetActivityMeetingReminder(wxUser.Mobile, dateTime)
	if err != nil && err.Error() != utils.ErrNoRow() {
		br.Msg = "获取失败"
		br.ErrMsg = "获取数据失败，Err:" + err.Error()
		return
	}
	if len(listActivityPvByReminder) > 0 {
		for _, v := range listActivityPvByReminder {
			labelsList := strings.Split(v.Label, "-")
			for _, v2 := range labelsList {
				labelsListSon := strings.Split(v2, "/")
				for _, v3 := range labelsListSon {
					if mapActivityLabels[v3] != "" {
						mapArticleIdLabelTotal[v3] += 1
					} else {
						mapArticleIdLabelTotal[v3] = 1
						mapActivityLabels[v3] = v3
					}
				}
			}
		}
	}

	//对标签数量进行排序
	type KvPair struct {
		Key string
		Val int
	}
	tmpList := make([]KvPair, 0)
	for k, v := range mapArticleIdLabelTotal {
		tmpList = append(tmpList, KvPair{Key: k, Val: v})
	}
	sort.Slice(tmpList, func(i, j int) bool {
		return tmpList[i].Val > tmpList[j].Val // 降序
	})
	for _, v := range tmpList {
		if v.Key != "" {
			mapLabels[v.Key] = v.Key
			item := new(cygx.UserLabel)
			item.Label = v.Key
			labelsListStr = append(labelsListStr, item)
		}
	}

	var labelNew string
	for _, v := range labelsListStr {
		labelNew += v.Label + ","
	}
	labelNew = strings.TrimRight(labelNew, ",")
	resp := new(cygx.UserLabel)
	resp.Label = labelNew
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 状态搜索栏
// @Description 状态搜索栏接口
// @Success 200 {object} cygx.CygxUserTableStatusListRep
// @router /user/status/table [get]
func (this *UserController) StatusTable() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	listType := []*cygx.CygxTryStageRep{{Name: "大套餐", TryStage: 1}, {Name: "小套餐", TryStage: 2}}
	listStatus := []*cygx.CygxTryStageRep{{Name: "未分类", TryStage: 1}, {Name: "推进", TryStage: 2}, {Name: "跟踪", TryStage: 3}, {Name: "预备", TryStage: 4}}
	List := []*cygx.CygxUserTableStatusRep{{Name: "正式", List: listType, TryStage: "正式"}, {Name: "试用", List: listStatus, TryStage: "试用"}, {Name: "冻结", List: []*cygx.CygxTryStageRep{}, TryStage: "冻结"}, {Name: "X类试用", List: []*cygx.CygxTryStageRep{}, TryStage: "X类试用"}}
	resp := new(cygx.CygxUserTableStatusListRep)
	resp.List = List

	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 用户互动量
// @Description 状态搜索栏接口
// @Param  UserId   query   int  true       "用户id"
// @Success 200 {object} cygx.CygxUserTableStatusListRep
// @router /user/interactionNum [get]
func (this *UserController) InteractionNum() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	userId, _ := this.GetInt("UserId")
	if userId < 1 {
		br.Msg = "用户不存在"
		return
	}
	wxUser, err := models.GetWxUserByUserId(userId)
	if err != nil {
		br.ErrMsg = "获取信息失败，Err:" + err.Error()
		br.Msg = "获取信息失败"
		return
	}
	cp, err := company.GetCompanyProductByCompanyIdAndProductId(wxUser.CompanyId, 2)
	if err != nil && err.Error() != utils.ErrNoRow() {
		br.Msg = "获取客户信息失败"
		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
		return
	}
	resp := new(cygx.CygxCygxInteractionNumRespListResp)
	for i := 0; i < 4; i++ {
		item := new(cygx.CygxInteractionNumResp)
		if cp != nil && cp.Status == "正式" {
			//阅读记录总数
			var startDate, endDate string
			item.DateTime = time.Now().AddDate(0, -i, 0).Format("2006.01")
			startDate = utils.GetOneMonthFirstDay(time.Now().AddDate(0, -i, 0)).Format(utils.FormatDate)
			endDate = utils.GetOneMonthLastDay(time.Now().AddDate(0, -i, 0)).Format(utils.FormatDate)

			countDetail, err := cygx.GetCompanyInteractionTableCountBytime(wxUser.CompanyId, startDate, endDate)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取各个阅读总数失败，Err:" + err.Error()
				return
			}
			item.InteractionNum = countDetail.HistoryNum + countDetail.CountNum + countDetail.IndustryFllowNum + countDetail.DepartmentFollowNum + countDetail.KeyWordNum + countDetail.OnLineNum + countDetail.OfficeNum + countDetail.ChartNum
		} else {
			var weekStr string
			switch i {
			case 0:
				weekStr = "本周（"
			case 1:
				weekStr = "上周（"
			case 2:
				weekStr = "上两周（"
			case 3:
				weekStr = "上三周（"
			}
			item.DateTime = weekStr + utils.GetNowWeekMonday().AddDate(0, 0, -i*7).Format("01.02") + "~" + utils.GetNowWeekMonday().AddDate(0, 0, -i*7+6).Format("01.02") + "）"
			var startDate, endDate string
			startDate = utils.GetNowWeekMonday().AddDate(0, 0, -i*7).Format(utils.FormatDate)
			endDate = utils.GetNowWeekMonday().AddDate(0, 0, -i*7+6).Format(utils.FormatDate)
			countDetail, err := cygx.GetCompanyInteractionTableCountBytime(wxUser.CompanyId, startDate, endDate)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取各个阅读总数失败，Err:" + err.Error()
				return
			}
			item.InteractionNum = countDetail.HistoryNum + countDetail.CountNum + countDetail.IndustryFllowNum + countDetail.DepartmentFollowNum + countDetail.KeyWordNum + countDetail.OnLineNum + countDetail.OfficeNum + countDetail.ChartNum + countDetail.TripNum + countDetail.RoadshowVideoNum + countDetail.ActivityVideoNum + countDetail.ActivityVoiceNum
		}
		resp.List = append(resp.List, item)
	}
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 标签检索用户相关互动
// @Description 标签检索用户相关互动接口
// @Param  UserId   query   int  true       "用户id"
// @Param   KeyWord   query   string  true       "搜索关键词"
// @Param  Source   query   int  true       "来源 1：报告阅读，2：报告收藏，3：相关活动,4:专项产业调研"
// @Success 200 {object} cygx.UserInteractionrelevantListResp
// @router /user/interaction/relevant [get]
func (this *UserController) InteractionRelevant() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	userId, _ := this.GetInt("UserId")
	source, _ := this.GetInt("Source")
	keyWord := this.GetString("KeyWord")
	if userId < 1 {
		br.Msg = "用户不存在"
		return
	}
	wxUser, err := models.GetWxUserByUserId(userId)
	if err != nil {
		br.ErrMsg = "获取信息失败，Err:" + err.Error()
		br.Msg = "获取信息失败"
		return
	}
	managementIds, err := cygx.GetManagementIdsByName(keyWord)
	if err != nil {
		br.Msg = "获取信息失败"
		br.ErrMsg = "获取产业信息失败，Err:" + err.Error()
		return
	}

	subjectIds, err := cygx.GetIndustrialSubjectIdsByName(keyWord)
	if err != nil {
		br.Msg = "获取信息失败"
		br.ErrMsg = "获取标的信息失败，Err:" + err.Error()
		return
	}

	resp := new(cygx.UserInteractionrelevantListResp)
	var condition string

	if source == 1 || source == 2 {
		var articleIds string
		if managementIds != "" || subjectIds != "" {
			var articleIdmanagement string
			var articleIdsubject string
			if managementIds != "" {
				articleIdmanagement, err = cygx.GetArticleIdsByIndustrialManagementId(managementIds)
				if err != nil {
					br.Msg = "获取信息失败"
					br.ErrMsg = "获取活动ID信息失败，Err:" + err.Error()
					return
				}
			}
			if subjectIds != "" {
				articleIdsubject, err = cygx.GetArticleIdsBySubjectId(subjectIds)
				if err != nil {
					br.Msg = "获取信息失败"
					br.ErrMsg = "获取活动ID信息失败，Err:" + err.Error()
					return
				}
			}
			if articleIdmanagement != "" && articleIdsubject != "" {
				articleIds = articleIdmanagement + "," + articleIdsubject
			} else if articleIdmanagement != "" && articleIdsubject == "" {
				articleIds = articleIdmanagement
			} else if articleIdmanagement == "" && articleIdsubject != "" {
				articleIds = articleIdsubject
			}
		} else {
			matchDetail, err := cygx.GetCygxReportMappingCygxDetailByName(keyWord)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "GetCygxReportMappingCygxDetail，Err:" + err.Error()
				return
			}
			if matchDetail != nil {
				var condition string
				var pars []interface{}
				condition = ` AND id_cygx = ? `
				pars = append(pars, matchDetail.Id)
				listGroup, err := cygx.GetCygxReportMappingGroupList(condition, pars, 0, 999)
				if err != nil && err.Error() != utils.ErrNoRow() {
					br.Msg = "获取失败"
					br.ErrMsg = "获取失败，Err:" + err.Error()
					return
				}
				var categoryIds []int
				for _, v := range listGroup {
					categoryIds = append(categoryIds, v.CategoryIdCelue)
				}
				pars = make([]interface{}, 0)
				condition = ` AND category_id IN (` + utils.GetOrmInReplace(len(categoryIds)) + `)`
				pars = append(pars, categoryIds)
				listArticle, err := cygx.GetArticlList(condition, pars, 0, 999)
				if err != nil && err.Error() != utils.ErrNoRow() {
					br.Msg = "获取失败"
					br.ErrMsg = "获取失败，Err:" + err.Error()
					return
				}
				for _, v := range listArticle {
					articleIds += strconv.Itoa(v.ArticleId) + ","
				}
				articleIds = strings.TrimRight(articleIds, ",")
			}
		}
		if articleIds != "" {
			condition = ` AND r.article_id IN (` + articleIds + `)`
			if source == 1 {
				condition += ` AND r.stop_time > 4 `
				resp.List, err = cygx.GetCygxArticleHistoryRecordByUser(wxUser.Mobile, wxUser.Email, condition, 0, 0)
			} else {
				resp.List, err = cygx.GetCygxArticleCollectByUser(userId, 0, 0, condition)
			}
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取用户阅读记录"
				return
			}
			if len(resp.List) > 0 {
				for k, v := range resp.List {
					resp.List[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
					resp.List[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
					if v.ArticleId >= utils.SummaryArticleId {
						resp.List[k].ArticleType = 1
					} else {
						resp.List[k].ArticleType = 2
					}
				}
			}
		}
	} else if source == 3 {
		activityIdByLabel, err := cygx.GetactivityIdsByLabel(keyWord)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取活动ID信息失败，Err:" + err.Error()
			return
		}
		activityId := activityIdByLabel
		if activityId != "" {
			condition = ` AND s.is_meeting = 1 AND s.activity_id IN (` + activityId + `) AND s.mobile = ` + wxUser.Mobile
			resp.List, err = cygx.GetActivityMeetByUser(condition, 0, 0)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户搜藏记录失败，Err:" + err.Error()
				return
			}
		}
	} else if source == 4 {
		activityIdByLabel, err := cygx.GetactivitySpecilIdsByLabel(keyWord)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取活动ID信息失败，Err:" + err.Error()
			return
		}
		activityId := activityIdByLabel
		if activityId != "" {
			condition = ` AND s.is_meeting = 1 AND s.activity_id IN (` + activityId + `) AND s.mobile = ` + wxUser.Mobile
			resp.List, err = cygx.GetActivitySpecialMeetByUser(condition, 0, 0)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户搜藏记录失败，Err:" + err.Error()
				return
			}
		}
	}

	if len(resp.List) == 0 {
		resp.List = make([]*cygx.UserInteraction, 0)
	}
	resp.IndustryName = keyWord
	if managementIds != "" {
		count, err := cygx.GetCygxIndustryFllowCountByUser(userId, managementIds)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户是否关注失败，Err:" + err.Error()
			return
		}
		if count > 0 {
			resp.IsFllow = true
		}
	}
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 用户相关互动下载
// @Description 用户相关互动下载接口
// @Param  UserId   query   int  true       "用户id"
// @Param  Source   query   int  true       "来源 报告阅读列表: 1,  活动互动记录: 2"
// @Param   IsMeeting   query   string  true       "是否到会 1到会、2未到会"
// @Param   MeetType   query   string  true       "参会方式 1线上，2线下 默认为线上"
// @Param   StartDate   query   string  true       "开始时间"
// @Param   EndDate   query   string  true       "结束时间"
// @Param   KeyWord   query   string  true       "搜索关键词"
// @Param  ClassType   query   int  true       "列表类型，1：权益，2：研选，默认1"
// @Success 200 {object} cygx.CygxUserTableStatusListRep
// @router /user/export/interaction [get]
func (this *UserController) ExportInteraction() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	userId, _ := this.GetInt("UserId")
	isMeeting := this.GetString("IsMeeting")
	meetType := this.GetString("MeetType")
	startDate := this.GetString("StartDate")
	endDate := this.GetString("EndDate")
	keyWord := this.GetString("KeyWord")
	source, _ := this.GetInt("Source")
	classType, _ := this.GetInt("ClassType", 1)
	if userId < 1 {
		br.Msg = "用户不存在"
		return
	}
	wxUser, err := models.GetWxUserByUserId(userId)
	if err != nil {
		br.ErrMsg = "获取信息失败，Err:" + err.Error()
		br.Msg = "获取信息失败"
		return
	}

	mobile := wxUser.Mobile
	var list []*cygx.UserInteraction

	var condition string
	var sheetName string
	if source == 1 {
		sheetName = "报告阅读列表"
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}

		if wxUser.Mobile == "" {
			wxUser.Mobile = wxUser.Email
		}
		//total, err = cygx.GetCygxArticleHistoryCount(wxUser.Mobile, wxUser.Email, condition)
		//if err != nil {
		//	br.Msg = "获取信息失败"
		//	br.ErrMsg = "获取用户阅读记录总数失败，Err:" + err.Error()
		//	return
		//}
		if classType == 1 {
			condition += "  AND art.article_type_id =  0 "
		} else {
			condition += "  AND art.article_type_id >  0 "
		}

		condition += " 	AND (r.mobile = '" + wxUser.Mobile + "'  OR  r.email = '" + wxUser.Mobile + "')  "
		_, list, err = cygx.GetCygxArticleHistoryRecordByUserNew(condition, 0, 9999)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}
		var articleIds []int
		if len(list) > 0 {
			for k, v := range list {
				if v.ArticleId >= utils.SummaryArticleId {
					list[k].ArticleType = 1
				} else {
					list[k].ArticleType = 2
				}
				if list[k].PermissionName == "" {
					list[k].PermissionName = v.CategoryName
				}
				if v.SpecialType == 0 {
					articleIds = append(articleIds, v.ArticleId)
				}
			}
			mapIndustrialLabel := cygxService.GetArticleIndustrialLabelByArticleId(articleIds) // 关联产业
			mapSubjectLabel := cygxService.GetArticleSubjectLabelByArticleId(articleIds)       // 关联标的
			for _, v := range list {
				v.IndustryName = strings.Join(mapIndustrialLabel[v.ArticleId], "/")
				v.SubjectNameStr = strings.Join(mapSubjectLabel[v.ArticleId], "/")
			}
		}

	} else if source == 2 {
		sheetName = "到会管理名单"
		if mobile != "" {
			condition = ` AND s.mobile = '` + mobile + `' `
			if classType == 1 {
				condition += "  AND  a.chart_permission_id  != 31 "
			} else {
				condition += "  AND  a.chart_permission_id  = 31 "
			}

			if isMeeting == "1" {
				condition += ` AND s.is_meeting = 1 `
			}
			if isMeeting == "2" {
				condition += ` AND s.is_meeting = 0 `
			}
			if meetType == "1" {
				condition += ` AND t.activity_type = 1 `
			}
			if meetType == "2" {
				condition += ` AND t.activity_type = 0 `
			}
			if startDate != "" {
				startDate += " 00:00:00"
				condition += ` AND a.activity_time >= '` + startDate + `' `
			}
			if endDate != "" {
				endDate += " 23:59:59"
				condition += ` AND a.activity_time <= '` + endDate + `' `
			}
			if keyWord != "" {
				condition += ` AND a.activity_name LIKE '%` + keyWord + `%' `
			}
			list, err = cygx.GetActivityMeetByUser(condition, 0, 0)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取参会人数列表失败"
				return
			}
			if len(list) > 0 {
				for k, v := range list {
					if v.ActivityType == 1 {
						if v.SignupType == "2" {
							list[k].InteractionType = "自主拨入"
						} else {
							list[k].InteractionType = "预约外呼"
						}
						if v.ReminderNum > 0 {
							list[k].InteractionType += ",会议提醒"
						}
					}
				}
			}
		}
	} else if source == 11 {
		sheetName = "专栏文章阅读记录"
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}
		if wxUser.Mobile == "" {
			wxUser.Mobile = wxUser.Email
		}
		condition += " 	AND (r.mobile = '" + wxUser.Mobile + "'  OR  r.email = '" + wxUser.Mobile + "')  "
		_, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, 0, 9999)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}
	}

	//创建excel
	dir, err := os.Executable()
	exPath := filepath.Dir(dir)
	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
	xlsxFile := xlsx.NewFile()
	if err != nil {
		br.Msg = "生成文件失败"
		br.ErrMsg = "生成文件失败"
		return
	}
	style := xlsx.NewStyle()
	alignment := xlsx.Alignment{
		Horizontal: "center",
		Vertical:   "center",
		WrapText:   true,
	}
	style.Alignment = alignment
	style.ApplyAlignment = true
	sheet, err := xlsxFile.AddSheet(sheetName)
	if err != nil {
		br.Msg = "新增Sheet失败"
		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
		return
	}
	if source == 1 {
		//标头
		rowTitle := sheet.AddRow()
		cellA := rowTitle.AddCell()
		cellA.Value = "报告标题"
		cellB := rowTitle.AddCell()
		cellB.Value = "所属行业"
		cellC := rowTitle.AddCell()
		cellC.Value = "所属产业"
		cellD := rowTitle.AddCell()
		cellD.Value = "关联标的"
		cellE := rowTitle.AddCell()
		cellE.Value = "发布时间"
		cellF := rowTitle.AddCell()
		cellF.Value = "阅读时间"
		cellG := rowTitle.AddCell()
		cellG.Value = "阅读时长"

		for _, item := range list {
			row := sheet.AddRow()
			cellA := row.AddCell()
			cellA.Value = item.Title
			cellB := row.AddCell()
			cellB.Value = item.PermissionName
			cellC := row.AddCell()
			cellC.Value = item.IndustryName
			cellD := row.AddCell()
			cellD.Value = item.SubjectNameStr
			cellE := row.AddCell()
			cellE.Value = item.PublishDate
			cellF := row.AddCell()
			cellF.Value = item.CreateTime
			cellG := row.AddCell()
			cellG.Value = item.StopTime
		}
	} else if source == 2 {
		//标头
		rowTitle := sheet.AddRow()
		cellA := rowTitle.AddCell()
		cellA.Value = "活动名称"
		cellB := rowTitle.AddCell()
		cellB.Value = "所属行业"
		cellC := rowTitle.AddCell()
		cellC.Value = "活动类型"
		cellD := rowTitle.AddCell()
		cellD.Value = "活动主题"
		cellE := rowTitle.AddCell()
		cellE.Value = "活动时间"
		cellF := rowTitle.AddCell()
		cellF.Value = "是否到会"
		cellG := rowTitle.AddCell()
		cellG.Value = "首次入会时间"
		cellH := rowTitle.AddCell()
		cellH.Value = "最后退出时间"
		cellI := rowTitle.AddCell()
		cellI.Value = "参与总时长"
		cellJ := rowTitle.AddCell()
		cellJ.Value = "参会方式"
		cellK := rowTitle.AddCell()
		cellK.Value = "参会权鉴"
		cellL := rowTitle.AddCell()
		cellL.Value = "参会状态"

		for _, item := range list {
			row := sheet.AddRow()
			cellA := row.AddCell()
			cellA.Value = item.ActivityName
			cellB := row.AddCell()
			cellB.Value = item.PermissionName
			cellC := row.AddCell()
			cellC.Value = item.ActivityTypeName
			cellD := row.AddCell()
			cellD.Value = item.Label
			cellE := row.AddCell()
			cellE.Value = item.ActivityTime
			cellF := row.AddCell()
			if item.IsMeeting == 1 {
				cellF.Value = "到会"
				cellG := row.AddCell()
				cellG.Value = item.FirstMeetingTime
				cellH := row.AddCell()
				cellH.Value = item.LastMeetingTime
				cellI := row.AddCell()
				cellI.Value = item.Duration
				cellJ := row.AddCell()
				cellJ.Value = item.LastMeetingTime
				cellK := row.AddCell()
				cellK.Value = item.MeetingTypeStr
				cellL := row.AddCell()
				cellL.Value = item.MeetingStatusStr
			} else {
				cellF.Value = "未到会"
			}
		}
	} else if source == 11 {
		//标头
		rowTitle := sheet.AddRow()
		cellA := rowTitle.AddCell()
		cellA.Value = "文章标题"
		cellB := rowTitle.AddCell()
		cellB.Value = "文章类型"
		cellC := rowTitle.AddCell()
		cellC.Value = "标签"
		cellD := rowTitle.AddCell()
		cellD.Value = "发布时间"
		cellE := rowTitle.AddCell()
		cellE.Value = "阅读时间"
		cellF := rowTitle.AddCell()
		cellF.Value = "阅读时长"
		cellG := rowTitle.AddCell()
		cellG.Value = "阅读来源"

		for _, item := range list {
			row := sheet.AddRow()
			cellA := row.AddCell()
			cellA.Value = item.Title
			cellB := row.AddCell()
			if item.SpecialType == 1 {
				cellB.Value = "笔记"
			} else {
				cellB.Value = "观点"
			}
			cellC := row.AddCell()
			cellC.Value = item.IndustryName
			cellD := row.AddCell()
			cellD.Value = item.PublishDate
			cellE := row.AddCell()
			cellE.Value = item.CreateTime
			cellF := row.AddCell()
			cellF.Value = item.StopTime
			cellG := row.AddCell()
			cellG.Value = cygxService.GetArticleSourcePlatformText(item.RegisterPlatform)
		}
	} else if source == 11 {
		//标头
		rowTitle := sheet.AddRow()
		cellA := rowTitle.AddCell()
		cellA.Value = "文章标题"
		cellB := rowTitle.AddCell()
		cellB.Value = "文章类型"
		cellC := rowTitle.AddCell()
		cellC.Value = "标签"
		cellD := rowTitle.AddCell()
		cellD.Value = "发布时间"
		cellE := rowTitle.AddCell()
		cellE.Value = "阅读时间"
		cellF := rowTitle.AddCell()
		cellF.Value = "阅读时长"
		cellG := rowTitle.AddCell()
		cellG.Value = "阅读来源"

		for _, item := range list {
			row := sheet.AddRow()
			cellA := row.AddCell()
			cellA.Value = item.Title
			cellB := row.AddCell()
			if item.SpecialType == 1 {
				cellB.Value = "笔记"
			} else {
				cellB.Value = "观点"
			}
			cellC := row.AddCell()
			cellC.Value = item.IndustryName
			cellD := row.AddCell()
			cellD.Value = item.PublishDate
			cellE := row.AddCell()
			cellE.Value = item.CreateTime
			cellF := row.AddCell()
			cellF.Value = item.StopTime
			cellG := row.AddCell()
			cellG.Value = cygxService.GetArticleSourcePlatformText(item.RegisterPlatform)
		}
	}
	err = xlsxFile.Save(downLoadnFilePath)
	if err != nil {
		br.Msg = "保存文件失败"
		br.ErrMsg = "保存文件失败"
		return
	}
	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
	downloadFileName := wxUser.RealName + randStr + ".xlsx"
	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
	defer func() {
		os.Remove(downLoadnFilePath)
	}()
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
}

// @Title 机构互动详情table栏
// @Description 互动详情table栏接口
// @Param  CompanyId   query   int  true       "公司ID"
// @Param  ClassType   query   int  true       "列表类型，1：权益，2：研选，默认1"
// @Success 200 {object} cygx.UserRemarksListResp
// @router /user/company/table/list [get]
func (this *UserController) CompanyTableList() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	companyId, _ := this.GetInt("CompanyId")
	classType, _ := this.GetInt("ClassType", 1)
	if companyId < 1 {
		br.Msg = "机构不存在"
		return
	}

	comanyDetail, err := company.GetCompanyDetailById(companyId)
	if err != nil {
		br.Msg = "获取信息失败"
		br.ErrMsg = "获取数据失败，Err:" + err.Error()
		return
	}
	resp := new(cygx.CygxUserTableListRep)
	var isAdminRole bool
	//如果不是管理员身份或者研究员身份则需要添加可见范围处理
	if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
		isAdminRole = true
	}

	var pars []interface{}
	condition := ` AND r.company_id  IN  (   ` + strconv.Itoa(companyId) + `  ) AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' ` //过滤当天时间
	//totalEs, _, err := services.SearcCygxArticleHistoryData(utils.IndexNameArticleHistory, "", "", "", strconv.Itoa(companyId), 0, 0)
	//if err != nil {
	//	br.Msg = "获取信息失败"
	//	br.ErrMsg = "获取Es文章阅读数量失败，Err:" + err.Error()
	//	return
	//}
	conditionArtcile := condition       //文章搜索条件
	conditionActivityMeet := condition  //活动到会搜索条件
	conditionIndustryFllow := condition //产业关注搜索条件
	conditionKeyWord := condition       //关键词记录搜索条件
	if classType == 1 {
		conditionArtcile += " AND art.article_type_id = 0  "
		conditionActivityMeet += " AND a.chart_permission_id  != 31  "
		conditionIndustryFllow += " AND m.chart_permission_id  != 31  "
		conditionKeyWord += " AND r.register_platform IN (1,2)  "
	} else {
		conditionArtcile += " AND art.article_type_id > 0  "
		conditionActivityMeet += " AND a.chart_permission_id  = 31  "
		conditionIndustryFllow += " AND m.chart_permission_id  = 31  "
		conditionKeyWord += " AND r.register_platform IN (5,6)  "
	}

	var historyNum int               //报告阅读列表
	var activityNum int              //活动互动记录
	var triptotal int                //专项调研
	var articleCollect int           //收藏的报告
	var chartNum int                 //收藏图表
	var industryFllowNum int         //关注的产业
	var departmentFollowNum int      //关注的作者
	var keyWordNum int               //搜索
	var roadshowTotal int            //音视频播放
	var tagNum int                   //首页标签点击
	var yanxuanSpecialNum int        //专栏文章阅读记录
	var yanxuanSpecialCollectNum int //收藏的专栏文章
	var yanxuanSpecialFollowNum int  //关注的专栏作者
	var feedbackNum int              //交流反馈数量
	var calendarMeetingNum int       //1v1 路演数量

	if isAdminRole {
		historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCount(conditionArtcile, pars)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录数量失败，Err:" + err.Error()
			return
		}

		activityNum, err = cygx.GetActivityMeetByCompanyCount(conditionActivityMeet)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取参会总数失败，Err:" + err.Error()
			return
		}
		//获取用户收藏记录总数
		articleCollect, err = cygx.GetCygxArticleCollectCountByCompany(conditionArtcile)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户收藏记录总数失败，Err:" + err.Error()
			return
		}
		//获取用户关注总数
		industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompany(conditionIndustryFllow)
		if err != nil {
			br.Msg = "获取信息失败 "
			br.ErrMsg = "获取用户关注总数失败，Err:" + err.Error()
			return
		}
		//获取关注作者总数
		departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取关注作者总数失败，Err:" + err.Error()
			return
		}
		//获取搜索记录
		keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompany(conditionKeyWord)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}

		chartNum, err = cygx.GetChartCountByUserMobile(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取总数失败，Err:" + err.Error()
			return
		}

		triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}

		roadshowTotal, err = cygx.GetCygxRoadshowCountByCompany(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}
		tagNum, err = cygx.GetCygxTagHistoryCount(condition)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录失败"
			return
		}
		yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCount(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取研选专栏阅读数量失败"
			return
		}

		yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCount(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取收藏的专栏文章数量失败"
			return
		}

		yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCount(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取关注的专栏作者数量失败"
			return
		}

		feedbackNum, err = cygx.GetCygxUserFeedbackCountByUserModel(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取交流反馈数量失败"
			return
		}

		calendarMeetingNum, err = roadshow.GetRsCalendarMeetingUserCountByUserModel(condition, pars)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "GetRsCalendarMeetingUserCountByUserModel，Err:" + err.Error()
			return
		}

	} else {
		historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(conditionArtcile, pars)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录数量失败，Err:" + err.Error()
			return
		}
		activityNum, err = cygx.GetActivityMeetByCompanyCountWeekly(conditionActivityMeet)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取参会总数失败，Err:" + err.Error()
			return
		}
		//获取用户收藏记录总数
		articleCollect, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(conditionArtcile)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户收藏记录总数失败，Err:" + err.Error()
			return
		}
		//获取用户关注总数
		industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(condition)
		if err != nil {
			br.Msg = "获取信息失败 "
			br.ErrMsg = "获取用户关注总数失败，Err:" + err.Error()
			return
		}
		//获取关注作者总数
		departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取关注作者总数失败，Err:" + err.Error()
			return
		}
		//获取搜索记录
		keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(conditionKeyWord)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}

		chartNum, err = cygx.GetChartCountByUserMobileWeekly(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取总数失败，Err:" + err.Error()
			return
		}

		triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}

		roadshowTotal, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}
		tagNum, err = cygx.GetCygxTagHistoryCountWeekly(condition)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录失败"
			return
		}

		yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCountWeekly(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取研选专栏阅读数量失败"
			return
		}

		yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCountWeekly(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取收藏的专栏文章数量失败"
			return
		}

		yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCountWeekly(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取关注的专栏作者数量失败"
			return
		}

		feedbackNum, err = cygx.GetCygxUserFeedbackCountByUserModelWeekly(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取交流反馈数量失败"
			return
		}

		calendarMeetingNum, err = roadshow.GetRsCalendarMeetingUserCountByUserModelWeekly(condition, pars)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "GetRsCalendarMeetingUserCountByUserModelWeekly，Err:" + err.Error()
			return
		}

	}

	if classType == 1 {
		List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
			{PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
			{PermissionName: "专项调研", Source: 8, TotalNum: triptotal},
			{PermissionName: "1v1路演", Source: 15, TotalNum: calendarMeetingNum},
			{PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
			{PermissionName: "收藏图表", Source: 4, TotalNum: chartNum},
			{PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
			{PermissionName: "搜索", Source: 7, TotalNum: keyWordNum},
			{PermissionName: "音视频播放", Source: 9, TotalNum: roadshowTotal},
			{PermissionName: "首页标签点击", Source: 10, TotalNum: tagNum},
			{PermissionName: "交流反馈", Source: 14, TotalNum: feedbackNum}}
		resp.List = List
	} else {
		List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
			{PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
			{PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
			{PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
			{PermissionName: "关注的作者", Source: 6, TotalNum: departmentFollowNum},
			{PermissionName: "专栏文章阅读记录", Source: 11, TotalNum: yanxuanSpecialNum},
			{PermissionName: "收藏的专栏文章", Source: 12, TotalNum: yanxuanSpecialCollectNum},
			{PermissionName: "关注的专栏作者", Source: 13, TotalNum: yanxuanSpecialFollowNum},
			{PermissionName: "搜索", Source: 7, TotalNum: keyWordNum}}
		resp.List = List
	}

	resp.ComapnyName = comanyDetail.CompanyName
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 机构互动详情
// @Description 机构互动详情接口
// @Param  CompanyId   query   int  true       "公司ID"
// @Param  Source   query   int  true       "来源"
// @Param   IsMeeting   query   string  false       "是否到会 1到会、2未到会"
// @Param   MeetType   query   string  false       "参会方式 1线上，2线下 默认为线上"
// @Param   PageSize   query   int  true       "每页数据条数"
// @Param   CurrentIndex   query   int  true       "当前页页码，从1开始"
// @Param   StartDate   query   string  false       "开始时间"
// @Param   EndDate   query   string  false       "结束时间"
// @Param   KeyWord   query   string  false       "搜索关键词"
// @Param   ActivityName    query   string  false       "活动名称"
// @Param  ClassType   query   int  true       "列表类型，1：权益，2：研选，默认1"
// @Param   IsExport   query   bool  false       "是否导出excel，默认是false"
// @Success 200 {object} cygx.UserInteractionListResp
// @router /user/company/interaction/detail [get]
func (this *UserController) CompanyTableDetail() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	pageSize, _ := this.GetInt("PageSize")
	currentIndex, _ := this.GetInt("CurrentIndex")
	var startSize int
	if pageSize <= 0 {
		pageSize = utils.PageSize20
	}
	if currentIndex <= 0 {
		currentIndex = 1
	}
	startSize = paging.StartIndex(currentIndex, pageSize)
	companyId, _ := this.GetInt("CompanyId")
	isMeeting := this.GetString("IsMeeting")
	meetType := this.GetString("MeetType")
	startDate := this.GetString("StartDate")
	endDate := this.GetString("EndDate")
	keyWord := this.GetString("KeyWord")
	activityName := this.GetString("ActivityName")
	source, _ := this.GetInt("Source")
	classType, _ := this.GetInt("ClassType", 1)
	if companyId < 1 {
		br.Msg = "用户不存在"
		return
	}
	isExport, _ := this.GetBool("IsExport")
	if isExport {
		pageSize = 10000
		currentIndex = 1
	}

	// 1.标记用户表
	//操作权限校验
	resp := new(cygx.UserInteractionListResp)
	var err error

	var list []*cygx.UserInteraction
	var total int
	var condition string
	var pars []interface{}
	condition += ` AND r.company_id  =   ` + strconv.Itoa(companyId) + ` AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' `
	if keyWord != "" {
		condition += ` AND ( r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%')`
	}

	var isAdminRole bool
	//如果不是管理员身份或者研究员身份则需要添加可见范围处理
	if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
		isAdminRole = true
	}

	if source == 1 {
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}
		condition += " AND r.source = 'article'  "
		if classType == 1 {
			condition += " AND art.article_type_id = 0  "
		} else {
			condition += " AND art.article_type_id > 0  "
		}
		condition += "  ORDER BY r.create_time DESC "
		var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
		if isAdminRole {
			total, err = cygx.GetCygxArticleAndYanxuanRecordCount(condition, pars)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录数量失败，Err:" + err.Error()
				return
			}
			listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			total, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(condition, pars)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录数量失败，Err:" + err.Error()
				return
			}
			listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		//处理查询信息回显
		list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}

		for k, v := range list {
			if classType == 1 {
				list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
			} else {
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
			}
		}
	} else if source == 2 {

		if isMeeting == "1" {
			condition += ` AND r.is_meeting = 1 `
		}
		if isMeeting == "2" {
			condition += ` AND r.is_meeting = 0 `
		}

		if meetType == "1" {
			condition += ` AND t.activity_type = 1 `
		}
		if meetType == "2" {
			condition += ` AND t.activity_type = 0 `
		}
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND a.activity_time >= '` + startDate + `' `
		}

		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND a.activity_time <= '` + endDate + `' `
		}
		if activityName != "" {
			condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
		}

		if classType == 1 {
			condition += "  AND a.chart_permission_id  != 31  "
		} else {
			condition += "  AND a.chart_permission_id  = 31  "
		}

		if isAdminRole {
			total, err = cygx.GetActivityMeetByCompanyCount(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取参会总数失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetActivityMeetByCompany(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取参会人数列表失败"
				return
			}
		} else {
			total, err = cygx.GetActivityMeetByCompanyCountWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取参会总数失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetActivityMeetByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取参会人数列表失败"
				return
			}
		}
		if len(list) > 0 {
			for k, v := range list {
				if v.ActivityType == 1 {
					if v.SignupType == "2" {
						list[k].InteractionType = "自主拨入"
					} else {
						list[k].InteractionType = "预约外呼"
					}
					if v.ReminderNum > 0 {
						list[k].InteractionType += ",会议提醒"
					}
				}
				if v.IsMeeting == 0 || v.FirstMeetingTime == "0000-00-00 00:00:00" {
					list[k].FirstMeetingTime = ""
					list[k].LastMeetingTime = ""
				}
				if v.FirstMeetingTime == "0000-00-00 00:00:00" {
					list[k].FirstMeetingTime = ""
					list[k].LastMeetingTime = ""
				}
			}
		}
	} else if source == 3 {
		if classType == 1 {
			condition += " AND art.article_type_id = 0  "
		} else {
			condition += " AND art.article_type_id > 0  "
		}
		if isAdminRole {
			total, err = cygx.GetCygxArticleCollectCountByCompany(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户收藏记录总数失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxArticleCollectByCompany(startSize, pageSize, condition)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户搜藏记录失败，Err:" + err.Error()
				return
			}
		} else {
			total, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户收藏记录总数失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxArticleCollectByCompanyWeekly(startSize, pageSize, condition)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户搜藏记录失败，Err:" + err.Error()
				return
			}
		}

		if len(list) > 0 {
			for k, v := range list {
				if v.ArticleId >= utils.SummaryArticleId {
					list[k].ArticleType = 1
				} else {
					list[k].ArticleType = 2
				}
				if classType == 1 {
					list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
				} else {
					list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
				}
			}
		}
	} else if source == 4 {
		if isAdminRole {
			list, err = cygx.GetChartCollectList(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				return
			}
		} else {
			list, err = cygx.GetChartCollectListWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				return
			}
		}

		if len(list) > 0 {
			for k, v := range list {
				var err error
				condition = ` AND a.publish_status = 1  AND r.company_id =  ` + strconv.Itoa(companyId) + ` AND  r.mobile =  ` + v.Mobile + `  AND r.create_time  < '` + time.Now().Format(utils.FormatDate) + `' ` //过滤当天时间
				total, err = cygx.GetChartCountByUserMobile(condition)
				if err != nil {
					br.Msg = "获取信息失败"
					br.ErrMsg = "获取总数失败，Err:" + err.Error()
					return
				}
				listChart, err := cygx.GetChartListCollectionWithCygxByMobile(condition, 0, 18)
				if err != nil {
					br.Msg = "获取信息失败"
					br.ErrMsg = "获取信息失败，Err:" + err.Error()
					return
				}
				for k, vChart := range listChart {
					if vChart.PtagName != "" {
						listChart[k].CtagNamePc = vChart.PtagName
					}
					if vChart.CtagName != "" {
						listChart[k].CtagNamePc += "," + vChart.CtagName
					}
					if vChart.PtagNameTwo != "" {
						listChart[k].CtagNamePc += "," + vChart.PtagNameTwo
					}
					if vChart.CtagNameTwo != "" {
						listChart[k].CtagNamePc += "," + vChart.CtagNameTwo
					}
				}
				pageChart := paging.GetPaging(currentIndex, 18, total)
				list[k].ListChart = listChart
				list[k].Paging = pageChart
				list[k].IsEnd = pageChart.IsEnd
				list[k].CurrentIndex = pageChart.CurrentIndex
			}
		}

	} else if source == 5 {
		if classType == 1 {
			condition += " AND m.chart_permission_id  != 31 "
		} else {
			condition += " AND m.chart_permission_id  = 31 "
		}
		if isAdminRole {
			total, err = cygx.GetCygxIndustryFllowCountByCompany(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取用户关注总数失败"
				return
			}
			list, err = cygx.GetCygxIndustryFllowByCompany(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取用户关注总数失败"
				return
			}
		} else {
			total, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取用户关注总数失败"
				return
			}
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取用户关注总数失败"
				return
			}
			list, err = cygx.GetCygxIndustryFllowByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取用户关注总数失败"
				return
			}
		}
	} else if source == 6 {
		if isAdminRole {
			total, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取关注作者总数失败"
				return
			}
			list, err = cygx.GetCygArticleDepartmentFollowByCompany(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取关注作者列表失败"
				return
			}
		} else {
			total, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取关注作者总数失败"
				return
			}
			list, err = cygx.GetCygArticleDepartmentFollowByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取关注作者列表失败"
				return
			}
		}
		if len(list) > 0 {
			var departmentIds []int
			for _, v := range list {
				departmentIds = append(departmentIds, v.DepartmentId)
			}
			mapIndustrialLabel := cygxService.GetArticleIndustrialLabelByDepartmentId(departmentIds) // 关联产业
			for _, v := range list {
				v.SubjectNameStr = strings.Join(mapIndustrialLabel[v.DepartmentId], "/")
			}
		}
	} else if source == 7 {
		if classType == 1 {
			condition += " AND r.register_platform IN (1,2) "
		} else {
			condition += " AND r.register_platform IN (5,6) "
		}
		if isAdminRole {
			total, err = cygx.GetCygxSearchKeyWordCountBuCompany(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxSearchKeyWordByCompany(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		} else {
			total, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxSearchKeyWordByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		}
	} else if source == 8 {
		if isAdminRole {
			total, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.CygxActivitySpecialTripByCompany(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		} else {
			total, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.CygxActivitySpecialTripByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		}
	} else if source == 9 {
		if isAdminRole {
			total, err = cygx.GetCygxRoadshowCountByCompany(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxRoadshowByCompany(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		} else {
			total, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxRoadshowByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		}
	} else if source == 10 { //标签点击记录
		if isAdminRole {
			total, err = cygx.GetCygxTagHistoryCount(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取搜索记录失败"
				return
			}
			list, err = cygx.GetCygxTagHistoryListBycondition(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取搜索记录列表失败"
				return
			}
		} else {
			total, err = cygx.GetCygxTagHistoryCountWeekly(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取搜索记录失败"
				return
			}
			list, err = cygx.GetCygxTagHistoryListByconditionWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取搜索记录列表失败"
				return
			}
		}
	} else if source == 11 { //专栏文章阅读记录
		if isAdminRole {
			total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		if len(list) > 0 {
			for k, v := range list {
				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
				list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
			}
		}
	} else if source == 12 { //收藏的专栏文章
		if isAdminRole {
			total, list, err = cygx.GetCygxYanxuanSpecialCollectByUser(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			total, list, err = cygx.GetCygxYanxuanSpecialCollectByUserWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		if len(list) > 0 {
			for k, v := range list {
				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
				list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
			}
		}
	} else if source == 13 { //关注的专栏作者
		if isAdminRole {
			total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUser(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUserWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		if len(list) > 0 {
			for k, v := range list {
				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
				list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/view/" + strconv.Itoa(v.DepartmentId)
			}
		}
	} else if source == 14 { //交流反馈
		if isAdminRole {
			total, list, err = cygx.GetCygxUserFeedback(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户交流反馈，Err:" + err.Error()
				return
			}
		} else {
			total, list, err = cygx.GetCygxUserFeedbackWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户交流反馈，Err:" + err.Error()
				return
			}
		}
	} else if source == 15 { //1V1路演
		var totalRsCalendar int
		var listRsCalendar []*roadshow.RsCalendarMeetingUserByRai
		if isAdminRole {
			totalRsCalendar, listRsCalendar, err = roadshow.GetRsCalendarMeetingUserByRai(condition, startSize, pageSize)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			totalRsCalendar, listRsCalendar, err = roadshow.GetRsCalendarMeetingUserByRaiWeekly(condition, startSize, pageSize)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		total = totalRsCalendar
		list, err = cygxService.HandleListRsCalendar(listRsCalendar)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "HandleListRsCalendar，Err:" + err.Error()
			return
		}
		//导出excel
		if isExport {
			exportListRsCalendar(this, list, 2, br)
			return
		}
	}

	page := paging.GetPaging(currentIndex, pageSize, total)

	if len(list) == 0 {
		list = make([]*cygx.UserInteraction, 0)
	}
	resp.List = list
	resp.Paging = page
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 机构相关互动下载
// @Description 机构相关互动下载接口
// @Param  CompanyId   query   int  true       "公司id"
// @Param  Source   query   int  true       "来源 报告阅读列表: 1,  活动互动记录: 2"
// @Param   IsMeeting   query   string  true       "是否到会 1到会、2未到会"
// @Param   MeetType   query   string  true       "参会方式 1线上，2线下 默认为线上"
// @Param   StartDate   query   string  true       "开始时间"
// @Param   EndDate   query   string  true       "结束时间"
// @Param   KeyWord   query   string  true       "搜索关键词"
// @Param   ActivityName   query   string  true       "活动名称"
// @Param  ClassType   query   int  true       "列表类型，1：权益，2：研选，默认1"
// @Success 200 {object} cygx.CygxUserTableStatusListRep
// @router /user/company/export/interaction [get]
func (this *UserController) CompanyExportInteraction() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	companyId, _ := this.GetInt("CompanyId")
	isMeeting := this.GetString("IsMeeting")
	meetType := this.GetString("MeetType")
	startDate := this.GetString("StartDate")
	endDate := this.GetString("EndDate")
	keyWord := this.GetString("KeyWord")
	activityName := this.GetString("ActivityName")
	source, _ := this.GetInt("Source")
	classType, _ := this.GetInt("ClassType", 1)
	if companyId < 1 {
		br.Msg = "用户不存在"
		return
	}
	//获取企业客户信息
	companyInfo, err := company.GetCompanyById(companyId)
	if err != nil {
		br.Msg = "获取信息失败"
		br.ErrMsg = "GetCompanyById，Err:" + err.Error()
		return
	}
	var isAdminRole bool
	//如果不是管理员身份或者研究员身份则需要添加可见范围处理
	if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
		isAdminRole = true
	}
	var pageSize = 9999
	var list []*cygx.UserInteraction

	var condition string
	condition += ` AND r.company_id  =   ` + strconv.Itoa(companyId) + ` AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
	if keyWord != "" {
		//condition += ` AND r.user_id IN (SELECT user_id FROM wx_user WHERE mobile LIKE '%` + keyWord + `%' OR email LIKE '%` + keyWord + `%' OR real_name LIKE '%` + keyWord + `%')`
		condition += ` AND ( r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%')`
	}
	if source == 1 {
		if classType == 1 {
			condition += "  AND art.article_type_id =  0 "
		} else {
			condition += "  AND art.article_type_id >  0 "
		}
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}
		condition += ` ORDER BY r.create_time DESC  `
		var pars []interface{}
		var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
		if isAdminRole {
			listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, 0, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, 0, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		//处理查询信息回显
		list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}
		if len(list) > 0 {
			var articleIds string
			mapAricleId := make(map[int]int)
			mapAricleIndustrialSubjectName := make(map[int]*cygx.ArticleIndustrialSubjectNameResp)
			for k, v := range list {
				if v.ArticleId >= utils.SummaryArticleId {
					list[k].ArticleType = 1
				} else {
					list[k].ArticleType = 2
				}
				if list[k].PermissionName == "" {
					list[k].PermissionName = v.CategoryName
				}
				if mapAricleId[v.ArticleId] == 0 {
					articleIds += strconv.Itoa(v.ArticleId) + ","
					mapAricleId[v.ArticleId] = v.ArticleId
				}
			}
			articleIds = strings.TrimRight(articleIds, ",")
			if articleIds != "" {
				listArticleIndustrialSubjectList, err := cygx.GetCygxArticleIndustrialSubjectName(articleIds)
				if err != nil && err.Error() != utils.ErrNoRow() {
					br.Msg = "获取信息失败"
					br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
					return
				}
				if len(listArticleIndustrialSubjectList) > 0 {
					for _, v := range listArticleIndustrialSubjectList {
						mapAricleIndustrialSubjectName[v.ArticleId] = v
					}
					for k, v := range list {
						if mapAricleIndustrialSubjectName[v.ArticleId] != nil {
							list[k].IndustryName = mapAricleIndustrialSubjectName[v.ArticleId].IndustryName
							list[k].SubjectNameStr = mapAricleIndustrialSubjectName[v.ArticleId].SubjectNameStr
						}
					}
				}
			}
		}
	} else if source == 2 {
		if classType == 1 {
			condition += "  AND  a.chart_permission_id  != 31 "
		} else {
			condition += "  AND  a.chart_permission_id  = 31 "
		}
		if isMeeting == "1" {
			condition += ` AND r.is_meeting = 1 `
		}
		if isMeeting == "2" {
			condition += ` AND r.is_meeting = 0 `
		}
		if meetType == "1" {
			condition += ` AND t.activity_type = 1 `
		}
		if meetType == "2" {
			condition += ` AND t.activity_type = 0 `
		}
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND a.activity_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND a.activity_time <= '` + endDate + `' `
		}
		if activityName != "" {
			condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
		}
		if isAdminRole {
			list, err = cygx.GetActivityMeetByCompany(condition, 0, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取参会人数列表失败"
				return
			}
		} else {
			list, err = cygx.GetActivityMeetByCompanyWeekly(condition, 0, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取参会人数列表失败"
				return
			}
		}
		if len(list) > 0 {
			for k, v := range list {
				if v.ActivityType == 1 {
					if v.SignupType == "2" {
						list[k].InteractionType = "自主拨入"
					} else {
						list[k].InteractionType = "预约外呼"
					}
					if v.ReminderNum > 0 {
						list[k].InteractionType += ",会议提醒"
					}
				}
			}
		}
	} else if source == 11 {
		if isAdminRole {
			_, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, 0, 9999)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			_, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition, 0, 9999)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
	}
	//创建excel
	dir, err := os.Executable()
	exPath := filepath.Dir(dir)
	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
	xlsxFile := xlsx.NewFile()
	if err != nil {
		br.Msg = "生成文件失败"
		br.ErrMsg = "生成文件失败"
		return
	}
	style := xlsx.NewStyle()
	alignment := xlsx.Alignment{
		Horizontal: "center",
		Vertical:   "center",
		WrapText:   true,
	}
	style.Alignment = alignment
	style.ApplyAlignment = true
	sheet, err := xlsxFile.AddSheet("用户名单")
	if err != nil {
		br.Msg = "新增Sheet失败"
		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
		return
	}
	var excelName string
	if source == 1 {
		excelName = "阅读记录"
		//标头
		rowTitle := sheet.AddRow()
		cellA := rowTitle.AddCell()
		cellA.Value = "姓名"
		cellB := rowTitle.AddCell()
		cellB.Value = "手机号"
		cellC := rowTitle.AddCell()
		cellC.Value = "报告标题"
		cellD := rowTitle.AddCell()
		cellD.Value = "所属行业"
		cellE := rowTitle.AddCell()
		cellE.Value = "所属产业"
		cellF := rowTitle.AddCell()
		cellF.Value = "关联标的"
		cellG := rowTitle.AddCell()
		cellG.Value = "发布时间"
		cellH := rowTitle.AddCell()
		cellH.Value = "阅读时间"
		cellI := rowTitle.AddCell()
		cellI.Value = "阅读时长"
		for _, item := range list {
			row := sheet.AddRow()
			cellA := row.AddCell()
			cellA.Value = item.RealName
			cellB := row.AddCell()
			cellB.Value = item.Mobile
			cellC := row.AddCell()
			cellC.Value = item.Title
			cellD := row.AddCell()
			cellD.Value = item.PermissionName
			cellE := row.AddCell()
			cellE.Value = item.IndustryName
			cellF := row.AddCell()
			cellF.Value = item.SubjectNameStr
			cellG := row.AddCell()
			cellG.Value = item.PublishDate
			cellH := row.AddCell()
			cellH.Value = item.CreateTime
			cellI := row.AddCell()
			cellI.Value = item.StopTime
		}
	} else if source == 2 {
		excelName = "参会记录"
		//标头
		rowTitle := sheet.AddRow()
		cellA := rowTitle.AddCell()
		cellA.Value = "姓名"
		cellB := rowTitle.AddCell()
		cellB.Value = "手机号"
		cellC := rowTitle.AddCell()
		cellC.Value = "活动名称"
		cellD := rowTitle.AddCell()
		cellD.Value = "所属行业"
		cellE := rowTitle.AddCell()
		cellE.Value = "活动类型"
		cellF := rowTitle.AddCell()
		cellF.Value = "活动主题"
		cellG := rowTitle.AddCell()
		cellG.Value = "活动时间"
		cellH := rowTitle.AddCell()
		cellH.Value = "是否到会"
		cellI := rowTitle.AddCell()
		cellI.Value = "首次入会时间"
		cellJ := rowTitle.AddCell()
		cellJ.Value = "最后退出时间"
		cellK := rowTitle.AddCell()
		cellK.Value = "参与总时长"
		cellL := rowTitle.AddCell()
		cellL.Value = "参会方式"
		cellM := rowTitle.AddCell()
		cellM.Value = "参会权鉴"
		cellN := rowTitle.AddCell()
		cellN.Value = "参会状态"
		for _, item := range list {
			row := sheet.AddRow()
			cellA := row.AddCell()
			cellA.Value = item.RealName
			cellB := row.AddCell()
			cellB.Value = item.Mobile
			cellC := row.AddCell()
			cellC.Value = item.ActivityName
			cellD := row.AddCell()
			cellD.Value = item.PermissionName
			cellE := row.AddCell()
			cellE.Value = item.ActivityTypeName
			cellF := row.AddCell()
			cellF.Value = item.Label
			cellG := row.AddCell()
			cellG.Value = item.ActivityTime
			cellH := row.AddCell()
			if item.IsMeeting == 1 {
				cellH.Value = "到会"
			} else {
				cellH.Value = "未到会"
			}
			cellI := row.AddCell()
			cellI.Value = item.FirstMeetingTime
			cellJ := row.AddCell()
			cellJ.Value = item.LastMeetingTime
			cellK := row.AddCell()
			cellK.Value = item.Duration
			cellL := row.AddCell()
			cellL.Value = item.LastMeetingTime
			cellM := row.AddCell()
			cellM.Value = item.MeetingTypeStr
			cellN := row.AddCell()
			cellN.Value = item.MeetingStatusStr
		}
	} else if source == 11 {
		//标头
		rowTitle := sheet.AddRow()
		cellA := rowTitle.AddCell()
		cellA.Value = "文章标题"
		cellB := rowTitle.AddCell()
		cellB.Value = "文章类型"
		cellC := rowTitle.AddCell()
		cellC.Value = "标签"
		cellD := rowTitle.AddCell()
		cellD.Value = "发布时间"
		cellE := rowTitle.AddCell()
		cellE.Value = "阅读时间"
		cellF := rowTitle.AddCell()
		cellF.Value = "阅读时长"
		cellG := rowTitle.AddCell()
		cellG.Value = "阅读来源"

		for _, item := range list {
			row := sheet.AddRow()
			cellA := row.AddCell()
			cellA.Value = item.Title
			cellB := row.AddCell()
			if item.SpecialType == 1 {
				cellB.Value = "笔记"
			} else {
				cellB.Value = "观点"
			}
			cellC := row.AddCell()
			cellC.Value = item.IndustryName
			cellD := row.AddCell()
			cellD.Value = item.PublishDate
			cellE := row.AddCell()
			cellE.Value = item.CreateTime
			cellF := row.AddCell()
			cellF.Value = item.StopTime
			cellG := row.AddCell()
			cellG.Value = cygxService.GetArticleSourcePlatformText(item.RegisterPlatform)
		}
	}
	err = xlsxFile.Save(downLoadnFilePath)
	if err != nil {
		br.Msg = "保存文件失败"
		br.ErrMsg = "保存文件失败"
		return
	}

	randStr := time.Now().Format(utils.FormatDate)
	downloadFileName := excelName + companyInfo.CompanyName + randStr + ".xlsx"
	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
	defer func() {
		os.Remove(downLoadnFilePath)
	}()
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
}

// @Title 全机构互动列表
// @Description 全机构互动列表接口
// @Param  Source   query   int  true       "来源"
// @Param   AdminId   query   string  true       "销售id，多个用英文逗号隔开，空字符串为全部"
// @Param   IsMeeting   query   string  false       "是否到会 1到会、2未到会"
// @Param   MeetType   query   string  false       "参会方式 1线上，2线下 默认为线上"
// @Param   PageSize   query   int  true       "每页数据条数"
// @Param   CurrentIndex   query   int  true       "当前页页码，从1开始"
// @Param   StartDate   query   string  false       "开始时间"
// @Param   EndDate   query   string  false       "结束时间"
// @Param   KeyWord   query   string  false       "搜索关键词"
// @Param   ActivityName    query   string  false       "活动名称"
// @Param  ClassType   query   int  true       "列表类型，1：权益，2：研选，默认1"
// @Param   IsExport   query   bool  false       "是否导出excel，默认是false"
// @Success 200 {object} cygx.UserInteractionListResp
// @router /user/company/list [get]
func (this *UserController) CompanyList() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	roleTypeCode := sysUser.RoleTypeCode
	pageSize, _ := this.GetInt("PageSize")
	currentIndex, _ := this.GetInt("CurrentIndex")
	adminId := this.GetString("AdminId")
	keyWord := this.GetString("KeyWord")
	isMeeting := this.GetString("IsMeeting")
	meetType := this.GetString("MeetType")
	startDate := this.GetString("StartDate")
	endDate := this.GetString("EndDate")
	activityName := this.GetString("ActivityName")
	source, _ := this.GetInt("Source")
	status := this.GetString("Status")
	classType, _ := this.GetInt("ClassType", 1)
	// 套餐类型
	//packageType, _ := this.GetInt("PackageType")
	keyWord = strings.Trim(keyWord, " ")
	keyWord = strings.Replace(keyWord, "'", "", -1)
	isExport, _ := this.GetBool("IsExport")
	if isExport {
		pageSize = 10000
		currentIndex = 1
	}

	var total int

	//statusItems := make([]*company.CompanyStatus, 0)
	//var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}

	var startSize int
	if pageSize <= 0 {
		pageSize = utils.PageSize20
	}
	if currentIndex <= 0 {
		currentIndex = 1
	}
	startSize = paging.StartIndex(currentIndex, pageSize)
	var condition string

	resp := new(cygx.UserInteractionListResp)
	var err error

	var list []*cygx.UserInteraction

	//流失
	var lossCondition string
	//var lossPars []interface{}

	//状态分类查询条件
	var permissionCondition string
	if adminId != "" {
		condition += ` AND b.seller_id IN (` + adminId + `) `
	}

	lossCondition = condition
	//lossPars = pars
	permissionCondition = condition

	//流失客户统计
	lossCondition += ` AND status='流失' `
	//productId := services.GetProductId(roleTypeCode)
	productId := 2
	//权限控制
	{
		//如果不是超级管理员或者财务
		if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
			//如果是部门管理员
			if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
				condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

			} else {
				condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				if status == "全部" {
					////如果是筛选了流失客户状态
					if sysUser.Authority <= 0 {
						condition += ` AND (b.seller_id= '` + strconv.Itoa(sysUser.AdminId) + `' OR status='流失')  `

						permissionCondition += ` AND b.seller_id= ` + strconv.Itoa(sysUser.AdminId)
					} else {
						if sysUser.Authority == 1 {
							condition += ` AND (b.department_id=` + strconv.Itoa(sysUser.DepartmentId) + `  OR status='流失')`
							permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
						}
						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND (b.group_id=` + strconv.Itoa(sysUser.GroupId) + `  OR status='流失') `
							}
							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)

						}

						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
							pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
							if err != nil {
								br.Msg = "获取失败"
								br.ErrMsg = "查询父级id异常" + err.Error()
								return
							}
							var ids []*string
							if pid != nil {
								if *pid != 0 {
									//销售主管放在三级列表中
									ids, err = company.GetGroupIdsByParentId(*pid)
									if err != nil {
										fmt.Println(err.Error())
									}
								} else {
									//销售主管放在二级列表中
									ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
									if err != nil {
										fmt.Println(err.Error())
									}
								}
							}
							var idSlice []string
							var sid string
							for _, id := range ids {
								idSlice = append(idSlice, *id)
							}
							//加入父级groupId
							if *pid > 0 {
								idSlice = append(idSlice, strconv.Itoa(*pid))
							} else {
								idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
							}

							sid = strings.Join(idSlice, ",")
							if len(sid) > 0 {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
								}

								permissionCondition += ` AND b.group_id IN (` + sid + `) `
							} else {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
								}
								permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
							}
						}
						if sysUser.Authority == 4 {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND (b.group_id =` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
								//pars = append(pars, sysUser.GroupId)
							}
							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
							//permissionPars = append(permissionPars, sysUser.GroupId)
						}
					}
				} else {
					//如果没有筛选了流失客户状态，那么需要加客户归属条件加入到查询中去
					if sysUser.Authority <= 0 {
						if status != utils.COMPANY_STATUS_LOSE {
							condition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
							//pars = append(pars, sysUser.AdminId)
						}

						permissionCondition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
						//permissionPars = append(permissionPars, sysUser.AdminId)
					} else {
						if sysUser.Authority == 1 {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
								//pars = append(pars, sysUser.DepartmentId)
							}
							permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
							//permissionPars = append(permissionPars, sysUser.DepartmentId)
						}
						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND b.group_id= ` + strconv.Itoa(sysUser.GroupId)
								//pars = append(pars, sysUser.GroupId)
							}
							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
							//permissionPars = append(permissionPars, sysUser.GroupId)
						}
						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
							pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
							if err != nil {
								br.Msg = "获取失败"
								br.ErrMsg = "查询父级id异常" + err.Error()
								return
							}
							var ids []*string
							if pid != nil {
								if *pid != 0 {
									//销售主管放在三级列表中
									ids, err = company.GetGroupIdsByParentId(*pid)
									if err != nil {
										fmt.Println(err.Error())
									}
								} else {
									//销售主管放在二级列表中
									ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
									if err != nil {
										fmt.Println(err.Error())
									}
								}
							}
							var idSlice []string
							var sid string
							for _, id := range ids {
								idSlice = append(idSlice, *id)
							}
							//加入父级groupId
							if *pid > 0 {
								idSlice = append(idSlice, strconv.Itoa(*pid))
							} else {
								idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
							}

							sid = strings.Join(idSlice, ",")
							if len(sid) > 0 {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
									//pars = append(pars, sysUser.GroupId)
								}

								permissionCondition += ` AND b.group_id IN (` + sid + `) `
							} else {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
									//pars = append(pars, sysUser.GroupId)
								}

								permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
							}
						}

						if sysUser.Authority == 4 {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND b.group_id =` + strconv.Itoa(sysUser.GroupId)
								//pars = append(pars, sysUser.GroupId)
							}

							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
							//permissionPars = append(permissionPars, sysUser.GroupId)
						}
					}
				}
			}
		}
	}

	condition += ` AND b.status IN ('正式','试用','冻结') `
	companyCondition := `SELECT a.company_id FROM company AS a  INNER JOIN company_product AS b ON a.company_id=b.company_id   WHERE a.enabled=1  `
	companyIdsCondition := `SELECT GROUP_CONCAT( DISTINCT  a.company_id SEPARATOR ',' )  AS company_ids   FROM company AS a  INNER JOIN company_product AS b ON a.company_id=b.company_id   WHERE a.enabled=1  `
	if condition != "" {
		companyCondition += condition
	}
	companyIdsCondition += condition
	var companyIds string
	companyIds, err = cygx.GetCompanyIdsCondition(companyIdsCondition)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取公司ID数据失败，Err:" + err.Error()
		return
	}
	condition = ` AND r.company_id  IN  (   ` + companyIds + `  ) AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' ` // 过滤当天查询时间
	if keyWord != "" {
		condition += ` AND  (r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%'` + ` OR r.company_name LIKE '%` + keyWord + `%') `
	}
	var isAdminRole bool
	//如果不是管理员身份或者研究员身份则需要添加可见范围处理
	if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
		isAdminRole = true
	}
	if source == 1 {
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}

		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}
		if classType == 1 {
			condition += " AND art.article_type_id = 0  "
		} else {
			condition += " AND art.article_type_id > 0  "
		}

		condition += " AND r.source =  'article' "
		var pars []interface{}
		condition += "  ORDER BY r.create_time DESC "
		var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
		if isAdminRole {
			listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
			total, err = cygx.GetCygxArticleAndYanxuanRecordCount(condition, pars)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录数量失败，Err:" + err.Error()
				return
			}
		} else {
			listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
			total, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(condition, pars)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录数量失败，Err:" + err.Error()
				return
			}
		}

		//处理查询信息回显
		list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}
		for k, v := range list {
			if classType == 1 {
				list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
			} else {
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
			}
		}
	} else if source == 2 {

		if isMeeting == "1" {
			condition += ` AND r.is_meeting = 1 `
		}
		if isMeeting == "2" {
			condition += ` AND r.is_meeting = 0 `
		}

		if meetType == "1" {
			condition += ` AND t.activity_type = 1 `
		}
		if meetType == "2" {
			condition += ` AND t.activity_type = 0 `
		}
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND a.activity_time >= '` + startDate + `' `
		}

		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND a.activity_time <= '` + endDate + `' `
		}
		if activityName != "" {
			condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
		}
		if classType == 1 {
			condition += "  AND a.chart_permission_id  != 31  "
		} else {
			condition += "  AND a.chart_permission_id  = 31  "
		}
		if isAdminRole {
			total, err = cygx.GetActivityMeetByCompanyCount(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取参会总数失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetActivityMeetByCompanyList(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取参会人数列表失败"
				return
			}
		} else {
			total, err = cygx.GetActivityMeetByCompanyCountWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取参会总数失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetActivityMeetByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取参会人数列表失败"
				return
			}
		}
		//根据公司ID获取对应销售
		var sellerCompanyIds []int
		for _, v := range list {
			sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
		}
		sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)

		if len(list) > 0 {
			for k, v := range list {
				if v.ActivityType == 1 {
					if v.SignupType == "2" {
						list[k].InteractionType = "自主拨入"
					} else {
						list[k].InteractionType = "预约外呼"
					}
					if v.ReminderNum > 0 {
						list[k].InteractionType += ",会议提醒"
					}
				}
				if v.IsMeeting == 0 {
					list[k].FirstMeetingTime = ""
					list[k].LastMeetingTime = ""
				}
				v.SellerName = sellNameMap[v.CompanyId]
			}
		}
	} else if source == 3 {
		if classType == 1 {
			condition += " AND art.article_type_id = 0  "
		} else {
			condition += " AND art.article_type_id > 0  "
		}
		if isAdminRole {
			total, err = cygx.GetCygxArticleCollectCountByCompany(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户收藏记录总数失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxArticleCollectByCompanyList(startSize, pageSize, condition)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户搜藏记录失败，Err:" + err.Error()
				return
			}
		} else {
			total, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户收藏记录总数失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxArticleCollectByCompanyWeekly(startSize, pageSize, condition)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户搜藏记录失败，Err:" + err.Error()
				return
			}
		}
		//根据公司ID获取对应销售
		var sellerCompanyIds []int
		for _, v := range list {
			sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
		}
		sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)

		if len(list) > 0 {
			for k, v := range list {
				if v.ArticleId >= utils.SummaryArticleId {
					list[k].ArticleType = 1
				} else {
					list[k].ArticleType = 2
				}
				v.SellerName = sellNameMap[v.CompanyId]
				if classType == 1 {
					list[k].HttpUrl = utils.CYGX_WEB_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
				} else {
					list[k].HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.ArticleId)
				}
			}
		}
	} else if source == 4 {
		if isAdminRole {
			total, err = cygx.GetChartCountByUserCount(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取总数失败，Err:" + err.Error()
				return
			}
			//condition += ` AND  r.company_id =  ` + strconv.Itoa(companyId) + `  AND r.create_time < date_format(now(),'%Y-%m-%d')` //过滤当天时间
			list, err = cygx.GetChartCollectBycompanyList(condition, startSize, pageSize)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				return
			}
		} else {
			total, err = cygx.GetChartCountByUserMobileWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取总数失败，Err:" + err.Error()
				return
			}
			//condition += ` AND  r.company_id =  ` + strconv.Itoa(companyId) + `  AND r.create_time < date_format(now(),'%Y-%m-%d')` //过滤当天时间
			list, err = cygx.GetChartCollectBycompanyListWeekly(condition, startSize, pageSize)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				return
			}
		}
		if len(list) > 0 {
			for k, v := range list {
				var err error
				condition = ` AND a.publish_status = 1   AND  r.mobile =  ` + v.Mobile + `  AND r.create_time < date_format(now(),'%Y-%m-%d')` //过滤当天时间
				totalUser, err := cygx.GetChartCountByUserMobile(condition)
				if err != nil {
					br.Msg = "获取信息失败"
					br.ErrMsg = "获取总数失败，Err:" + err.Error()
					return
				}
				listChart, err := cygx.GetChartListCollectionWithCygxByMobile(condition, 0, 18)
				if err != nil {
					br.Msg = "获取信息失败"
					br.ErrMsg = "获取信息失败，Err:" + err.Error()
					return
				}
				for k, vChart := range listChart {
					if vChart.PtagName != "" {
						listChart[k].CtagNamePc = vChart.PtagName
					}
					if vChart.CtagName != "" {
						listChart[k].CtagNamePc += "," + vChart.CtagName
					}
					if vChart.PtagNameTwo != "" {
						listChart[k].CtagNamePc += "," + vChart.PtagNameTwo
					}
					if vChart.CtagNameTwo != "" {
						listChart[k].CtagNamePc += "," + vChart.CtagNameTwo
					}
				}
				pageChart := paging.GetPaging(currentIndex, pageSize, totalUser)
				list[k].ListChart = listChart
				list[k].Paging = pageChart
				list[k].IsEnd = pageChart.IsEnd
				list[k].CurrentIndex = pageChart.CurrentIndex
			}
		}

	} else if source == 5 {
		if classType == 1 {
			condition += " AND m.chart_permission_id  != 31 "
		} else {
			condition += " AND m.chart_permission_id  = 31 "
		}
		if isAdminRole {
			total, err = cygx.GetCygxIndustryFllowCountByCompany(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取用户关注总数失败"
				return
			}
			list, err = cygx.GetCygxIndustryFllowByCompanyList(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取用户关注总数失败"
				return
			}
		} else {
			total, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取用户关注总数失败"
				return
			}
			list, err = cygx.GetCygxIndustryFllowByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取用户关注总数失败"
				return
			}
		}
		//根据公司ID获取对应销售
		var sellerCompanyIds []int
		for _, v := range list {
			sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
		}
		sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
		for _, v := range list {
			v.SellerName = sellNameMap[v.CompanyId]
		}

	} else if source == 6 {
		if isAdminRole {
			total, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取关注作者总数失败"
				return
			}
			list, err = cygx.GetCygArticleDepartmentFollowByCompanyList(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取关注作者列表失败"
				return
			}
		} else {
			total, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取关注作者总数失败"
				return
			}
			list, err = cygx.GetCygArticleDepartmentFollowByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取关注作者列表失败"
				return
			}
		}
		if len(list) > 0 {
			//根据公司ID获取对应销售
			var sellerCompanyIds []int
			var departmentIds []int
			for _, v := range list {
				sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
				departmentIds = append(departmentIds, v.DepartmentId)
			}

			sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
			mapIndustrialLabel := cygxService.GetArticleIndustrialLabelByDepartmentId(departmentIds) // 关联产业
			for _, v := range list {
				v.SellerName = sellNameMap[v.CompanyId]
				v.SubjectNameStr = strings.Join(mapIndustrialLabel[v.DepartmentId], "/")
			}
		}
	} else if source == 7 {
		if classType == 1 {
			condition += " AND r.register_platform IN (1,2) "
		} else {
			condition += " AND r.register_platform IN (5,6) "
		}
		if isAdminRole {
			total, err = cygx.GetCygxSearchKeyWordCountBuCompany(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxSearchKeyWordByCompanyList(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		} else {
			total, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxSearchKeyWordByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		}
		//根据公司ID获取对应销售
		var sellerCompanyIds []int
		for _, v := range list {
			sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
		}
		sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
		for _, v := range list {
			v.SellerName = sellNameMap[v.CompanyId]
		}
	} else if source == 8 {
		if isAdminRole {
			total, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxActivitySpecialTripByCompanyList(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		} else {
			total, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.CygxActivitySpecialTripByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		}
	} else if source == 9 {
		if isAdminRole {
			total, err = cygx.GetCygxRoadshowCountByCompany(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxRoadshowByCompanyList(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		} else {
			total, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
				return
			}
			list, err = cygx.GetCygxRoadshowByCompanyWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取搜索记录列表失败，Err:" + err.Error()
				return
			}
		}

		//根据公司ID获取对应销售
		var sellerCompanyIds []int
		for _, v := range list {
			sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
		}
		sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
		for _, v := range list {
			v.SellerName = sellNameMap[v.CompanyId]
		}

	} else if source == 10 { //标签点击记录
		if isAdminRole {
			total, err = cygx.GetCygxTagHistoryCount(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取搜索记录失败"
				return
			}
			list, err = cygx.GetCygxTagHistoryListBycondition(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取搜索记录列表失败"
				return
			}
		} else {
			total, err = cygx.GetCygxTagHistoryCountWeekly(condition)
			if err != nil {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取搜索记录失败"
				return
			}
			list, err = cygx.GetCygxTagHistoryListByconditionWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取搜索记录列表失败"
				return
			}
		}
	} else if source == 11 { //专栏文章阅读记录
		if isAdminRole {
			total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		if len(list) > 0 {
			for k, v := range list {
				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
				list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
			}
		}
	} else if source == 12 { //收藏的专栏文章
		if isAdminRole {
			total, list, err = cygx.GetCygxYanxuanSpecialCollectByUser(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			total, list, err = cygx.GetCygxYanxuanSpecialCollectByUserWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		if len(list) > 0 {
			for k, v := range list {
				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
				list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.ArticleId)
			}
		}
	} else if source == 13 { //关注的专栏作者
		if isAdminRole {
			total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUser(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUserWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		if len(list) > 0 {
			for k, v := range list {
				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
				list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
				list[k].HttpUrl = utils.CYGX_MFYX_URL + "/column/view/" + strconv.Itoa(v.DepartmentId)
			}
		}
	} else if source == 14 { //交流反馈
		if isAdminRole {
			total, list, err = cygx.GetCygxUserFeedback(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			total, list, err = cygx.GetCygxUserFeedbackWeekly(condition, startSize, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
	} else if source == 15 {
		var totalRsCalendar int
		var listRsCalendar []*roadshow.RsCalendarMeetingUserByRai
		if isAdminRole {
			totalRsCalendar, listRsCalendar, err = roadshow.GetRsCalendarMeetingUserByRai(condition, startSize, pageSize)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			totalRsCalendar, listRsCalendar, err = roadshow.GetRsCalendarMeetingUserByRaiWeekly(condition, startSize, pageSize)
			if err != nil {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		total = totalRsCalendar
		list, err = cygxService.HandleListRsCalendar(listRsCalendar)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "HandleListRsCalendar，Err:" + err.Error()
			return
		}
		//导出excel
		if isExport {
			exportListRsCalendar(this, list, 3, br)
			return
		}
	}
	page := paging.GetPaging(currentIndex, pageSize, total)

	if len(list) == 0 {
		list = make([]*cygx.UserInteraction, 0)
	}
	resp.List = list
	resp.Paging = page
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 机构列表相关互动下载
// @Description 机构相关互动下载接口
// @Param  Source   query   int  true       "来源 报告阅读列表: 1,  活动互动记录: 2"
// @Param   IsMeeting   query   string  true       "是否到会 1到会、2未到会"
// @Param   MeetType   query   string  true       "参会方式 1线上，2线下 默认为线上"
// @Param   StartDate   query   string  true       "开始时间"
// @Param   EndDate   query   string  true       "结束时间"
// @Param   KeyWord   query   string  true       "搜索关键词"
// @Param   ActivityName   query   string  true       "活动名称"
// @Param  ClassType   query   int  true       "列表类型，1：权益，2：研选，默认1"
// @Success 200 {object} cygx.CygxUserTableStatusListRep
// @router /user/companyList/export/interaction [get]
func (this *UserController) CompanyExportInteractionList() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}

	roleTypeCode := sysUser.RoleTypeCode
	adminId := this.GetString("AdminId")
	keyWord := this.GetString("KeyWord")
	isMeeting := this.GetString("IsMeeting")
	meetType := this.GetString("MeetType")
	startDate := this.GetString("StartDate")
	endDate := this.GetString("EndDate")
	activityName := this.GetString("ActivityName")
	source, _ := this.GetInt("Source")
	status := this.GetString("Status")
	classType, _ := this.GetInt("ClassType", 1)
	// 套餐类型
	//packageType, _ := this.GetInt("PackageType")
	keyWord = strings.Trim(keyWord, " ")
	keyWord = strings.Replace(keyWord, "'", "", -1)

	var list []*cygx.UserInteraction
	var err error

	var condition string
	//流失
	var lossCondition string
	//var lossPars []interface{}

	//状态分类查询条件
	var permissionCondition string
	if adminId != "" {
		condition += ` AND b.seller_id IN (` + adminId + `) `
	}

	lossCondition = condition
	//lossPars = pars
	permissionCondition = condition

	//流失客户统计
	lossCondition += ` AND status='流失' `
	//productId := services.GetProductId(roleTypeCode)
	productId := 2
	//权限控制
	{
		//如果不是超级管理员或者财务
		if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
			//如果是部门管理员
			if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
				condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

			} else {
				condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				if status == "全部" {
					////如果是筛选了流失客户状态
					if sysUser.Authority <= 0 {
						condition += ` AND (b.seller_id= '` + strconv.Itoa(sysUser.AdminId) + `' OR status='流失')  `

						permissionCondition += ` AND b.seller_id= ` + strconv.Itoa(sysUser.AdminId)
					} else {
						if sysUser.Authority == 1 {
							condition += ` AND (b.department_id=` + strconv.Itoa(sysUser.DepartmentId) + `  OR status='流失')`
							permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
						}
						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND (b.group_id=` + strconv.Itoa(sysUser.GroupId) + `  OR status='流失') `
							}
							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)

						}

						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
							pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
							if err != nil {
								br.Msg = "获取失败"
								br.ErrMsg = "查询父级id异常" + err.Error()
								return
							}
							var ids []*string
							if pid != nil {
								if *pid != 0 {
									//销售主管放在三级列表中
									ids, err = company.GetGroupIdsByParentId(*pid)
									if err != nil {
										fmt.Println(err.Error())
									}
								} else {
									//销售主管放在二级列表中
									ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
									if err != nil {
										fmt.Println(err.Error())
									}
								}
							}
							var idSlice []string
							var sid string
							for _, id := range ids {
								idSlice = append(idSlice, *id)
							}
							//加入父级groupId
							if *pid > 0 {
								idSlice = append(idSlice, strconv.Itoa(*pid))
							} else {
								idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
							}

							sid = strings.Join(idSlice, ",")
							if len(sid) > 0 {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
								}

								permissionCondition += ` AND b.group_id IN (` + sid + `) `
							} else {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
								}
								permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
							}
						}
						if sysUser.Authority == 4 {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND (b.group_id =` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
								//pars = append(pars, sysUser.GroupId)
							}
							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
							//permissionPars = append(permissionPars, sysUser.GroupId)
						}
					}
				} else {
					//如果没有筛选了流失客户状态，那么需要加客户归属条件加入到查询中去
					if sysUser.Authority <= 0 {
						if status != utils.COMPANY_STATUS_LOSE {
							condition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
							//pars = append(pars, sysUser.AdminId)
						}

						permissionCondition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
						//permissionPars = append(permissionPars, sysUser.AdminId)
					} else {
						if sysUser.Authority == 1 {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
								//pars = append(pars, sysUser.DepartmentId)
							}
							permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
							//permissionPars = append(permissionPars, sysUser.DepartmentId)
						}
						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND b.group_id= ` + strconv.Itoa(sysUser.GroupId)
								//pars = append(pars, sysUser.GroupId)
							}
							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
							//permissionPars = append(permissionPars, sysUser.GroupId)
						}
						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
							pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
							if err != nil {
								br.Msg = "获取失败"
								br.ErrMsg = "查询父级id异常" + err.Error()
								return
							}
							var ids []*string
							if pid != nil {
								if *pid != 0 {
									//销售主管放在三级列表中
									ids, err = company.GetGroupIdsByParentId(*pid)
									if err != nil {
										fmt.Println(err.Error())
									}
								} else {
									//销售主管放在二级列表中
									ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
									if err != nil {
										fmt.Println(err.Error())
									}
								}
							}
							var idSlice []string
							var sid string
							for _, id := range ids {
								idSlice = append(idSlice, *id)
							}
							//加入父级groupId
							if *pid > 0 {
								idSlice = append(idSlice, strconv.Itoa(*pid))
							} else {
								idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
							}

							sid = strings.Join(idSlice, ",")
							if len(sid) > 0 {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
									//pars = append(pars, sysUser.GroupId)
								}

								permissionCondition += ` AND b.group_id IN (` + sid + `) `
							} else {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
									//pars = append(pars, sysUser.GroupId)
								}

								permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
							}
						}

						if sysUser.Authority == 4 {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND b.group_id =` + strconv.Itoa(sysUser.GroupId)
								//pars = append(pars, sysUser.GroupId)
							}

							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
							//permissionPars = append(permissionPars, sysUser.GroupId)
						}
					}
				}
			}
		}
	}

	//condition += ` AND b.status IN ('正式','试用','冻结') `
	//companyCondition := `SELECT a.company_id FROM company AS a  INNER JOIN company_product AS b ON a.company_id=b.company_id   WHERE a.enabled=1  `
	//if condition != "" {
	//	companyCondition += condition
	//}

	condition += ` AND b.status IN ('正式','试用','冻结') `
	companyCondition := `SELECT a.company_id FROM company AS a  INNER JOIN company_product AS b ON a.company_id=b.company_id   WHERE a.enabled=1  `
	companyIdsCondition := `SELECT GROUP_CONCAT( DISTINCT  a.company_id SEPARATOR ',' )  AS company_ids   FROM company AS a  INNER JOIN company_product AS b ON a.company_id=b.company_id   WHERE a.enabled=1  `
	if condition != "" {
		companyCondition += condition
	}
	companyIdsCondition += condition
	var companyIds string
	companyIds, err = cygx.GetCompanyIdsCondition(companyIdsCondition)

	companyIds, err = cygx.GetCompanyIdsCondition(companyIdsCondition)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取公司ID数据失败，Err:" + err.Error()
		return
	}

	condition = ` AND r.company_id  IN  (   ` + companyIds + `  )AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
	if keyWord != "" {
		condition += ` AND  (r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%'` + ` OR r.company_name LIKE '%` + keyWord + `%') `
	}
	var isAdminRole bool
	var pageSize = 9999
	//如果不是管理员身份或者研究员身份则需要添加可见范围处理
	if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
		isAdminRole = true
	}
	if source == 1 {
		if classType == 1 {
			condition += "  AND art.article_type_id =  0 "
		} else {
			condition += "  AND art.article_type_id >  0 "
		}
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND r.create_time >= '` + startDate + `' `
		}

		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND r.create_time <= '` + endDate + `' `
		}
		condition += ` ORDER BY r.create_time DESC  `
		var pars []interface{}
		var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
		if isAdminRole {
			listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, 0, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, 0, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
		//处理查询信息回显
		list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
			return
		}
		if len(list) > 0 {
			var articleIds string
			mapAricleId := make(map[int]int)
			mapAricleIndustrialSubjectName := make(map[int]*cygx.ArticleIndustrialSubjectNameResp)
			for k, v := range list {
				if v.ArticleId >= utils.SummaryArticleId {
					list[k].ArticleType = 1
				} else {
					list[k].ArticleType = 2
				}
				if list[k].PermissionName == "" {
					list[k].PermissionName = v.CategoryName
				}
				if mapAricleId[v.ArticleId] == 0 {
					articleIds += strconv.Itoa(v.ArticleId) + ","
					mapAricleId[v.ArticleId] = v.ArticleId
				}
			}
			articleIds = strings.TrimRight(articleIds, ",")
			if articleIds != "" {
				listArticleIndustrialSubjectList, err := cygx.GetCygxArticleIndustrialSubjectName(articleIds)
				if err != nil && err.Error() != utils.ErrNoRow() {
					br.Msg = "获取信息失败"
					br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
					return
				}
				if len(listArticleIndustrialSubjectList) > 0 {
					for _, v := range listArticleIndustrialSubjectList {
						mapAricleIndustrialSubjectName[v.ArticleId] = v
					}
					for k, v := range list {
						if mapAricleIndustrialSubjectName[v.ArticleId] != nil {
							fmt.Println(mapAricleIndustrialSubjectName[v.ArticleId].IndustryName)
							list[k].IndustryName = mapAricleIndustrialSubjectName[v.ArticleId].IndustryName
							list[k].SubjectNameStr = mapAricleIndustrialSubjectName[v.ArticleId].SubjectNameStr
						}
					}
				}
			}
		}
	} else if source == 2 {
		if classType == 1 {
			condition += "  AND  a.chart_permission_id  != 31 "
		} else {
			condition += "  AND  a.chart_permission_id  = 31 "
		}
		if isMeeting == "1" {
			condition += ` AND r.is_meeting = 1 `
		}
		if isMeeting == "2" {
			condition += ` AND r.is_meeting = 0 `
		}
		if meetType == "1" {
			condition += ` AND t.activity_type = 1 `
		}
		if meetType == "2" {
			condition += ` AND t.activity_type = 0 `
		}
		if startDate != "" {
			startDate += " 00:00:00"
			condition += ` AND a.activity_time >= '` + startDate + `' `
		}
		if endDate != "" {
			endDate += " 23:59:59"
			condition += ` AND a.activity_time <= '` + endDate + `' `
		}
		if activityName != "" {
			condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
		}
		if isAdminRole {
			list, err = cygx.GetActivityMeetByCompany(condition, 0, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取参会人数列表失败"
				return
			}
		} else {
			list, err = cygx.GetActivityMeetByCompanyWeekly(condition, 0, pageSize)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.ErrMsg = "获取信息失败，Err:" + err.Error()
				br.Msg = "获取参会人数列表失败"
				return
			}
		}
		if len(list) > 0 {
			for k, v := range list {
				if v.ActivityType == 1 {
					if v.SignupType == "2" {
						list[k].InteractionType = "自主拨入"
					} else {
						list[k].InteractionType = "预约外呼"
					}
					if v.ReminderNum > 0 {
						list[k].InteractionType += ",会议提醒"
					}
				}
			}
		}
	} else if source == 11 {
		if isAdminRole {
			_, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, 0, 9999)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		} else {
			_, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition, 0, 9999)
			if err != nil && err.Error() != utils.ErrNoRow() {
				br.Msg = "获取信息失败"
				br.ErrMsg = "获取用户阅读记录，Err:" + err.Error()
				return
			}
		}
	}
	//创建excel
	dir, err := os.Executable()
	exPath := filepath.Dir(dir)
	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
	xlsxFile := xlsx.NewFile()
	if err != nil {
		br.Msg = "生成文件失败"
		br.ErrMsg = "生成文件失败"
		return
	}
	style := xlsx.NewStyle()
	alignment := xlsx.Alignment{
		Horizontal: "center",
		Vertical:   "center",
		WrapText:   true,
	}
	var excelName string
	style.Alignment = alignment
	style.ApplyAlignment = true
	sheet, err := xlsxFile.AddSheet("到会管理名单")
	if err != nil {
		br.Msg = "新增Sheet失败"
		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
		return
	}
	if source == 1 {
		excelName = "客户阅读记录"
		//标头
		rowTitle := sheet.AddRow()
		cellA := rowTitle.AddCell()
		cellA.Value = "客户名称"
		cellB := rowTitle.AddCell()
		cellB.Value = "所属销售"
		cellC := rowTitle.AddCell()
		cellC.Value = "姓名"
		cellD := rowTitle.AddCell()
		cellD.Value = "手机号"
		cellE := rowTitle.AddCell()
		cellE.Value = "报告标题"
		cellF := rowTitle.AddCell()
		cellF.Value = "所属行业"
		cellG := rowTitle.AddCell()
		cellG.Value = "所属产业"
		cellH := rowTitle.AddCell()
		cellH.Value = "关联标的"
		cellI := rowTitle.AddCell()
		cellI.Value = "发布时间"
		cellJ := rowTitle.AddCell()
		cellJ.Value = "阅读时间"
		cellK := rowTitle.AddCell()
		cellK.Value = "阅读时长"

		for _, item := range list {
			row := sheet.AddRow()
			cellA := row.AddCell()
			cellA.Value = item.CompanyName
			cellB := row.AddCell()
			cellB.Value = item.SellerName
			cellC := row.AddCell()
			cellC.Value = item.RealName
			cellD := row.AddCell()
			cellD.Value = item.Mobile
			cellE := row.AddCell()
			cellE.Value = item.Title
			cellF := row.AddCell()
			cellF.Value = item.PermissionName
			cellG := row.AddCell()
			cellG.Value = item.IndustryName
			cellH := row.AddCell()
			cellH.Value = item.SubjectNameStr
			cellI := row.AddCell()
			cellI.Value = item.PublishDate
			cellJ := row.AddCell()
			cellJ.Value = item.CreateTime
			cellK := row.AddCell()
			cellK.Value = item.StopTime
		}
	} else if source == 2 {
		excelName = "客户参会记录"
		//标头
		rowTitle := sheet.AddRow()
		cellA := rowTitle.AddCell()
		cellA.Value = "客户名称"
		cellB := rowTitle.AddCell()
		cellB.Value = "所属销售"
		cellC := rowTitle.AddCell()
		cellC.Value = "姓名"
		cellD := rowTitle.AddCell()
		cellD.Value = "手机号"

		cellE := rowTitle.AddCell()
		cellE.Value = "活动名称"
		cellF := rowTitle.AddCell()
		cellF.Value = "所属行业"
		cellG := rowTitle.AddCell()
		cellG.Value = "活动类型"
		cellH := rowTitle.AddCell()
		cellH.Value = "活动主题"
		cellI := rowTitle.AddCell()
		cellI.Value = "活动时间"
		cellJ := rowTitle.AddCell()
		cellJ.Value = "是否到会"
		cellK := rowTitle.AddCell()
		cellK.Value = "首次入会时间"
		cellL := rowTitle.AddCell()
		cellL.Value = "最后退出时间"
		cellM := rowTitle.AddCell()
		cellM.Value = "参与总时长"
		cellN := rowTitle.AddCell()
		cellN.Value = "参会方式"
		cellO := rowTitle.AddCell()
		cellO.Value = "参会权鉴"
		cellP := rowTitle.AddCell()
		cellP.Value = "参会状态"

		for _, item := range list {
			row := sheet.AddRow()
			cellA := row.AddCell()
			cellA.Value = item.CompanyName
			cellB := row.AddCell()
			cellB.Value = item.SellerName
			cellC := row.AddCell()
			cellC.Value = item.RealName
			cellD := row.AddCell()
			cellD.Value = item.Mobile

			cellE := row.AddCell()
			cellE.Value = item.ActivityName
			cellF := row.AddCell()
			cellF.Value = item.PermissionName
			cellG := row.AddCell()
			cellG.Value = item.ActivityTypeName
			cellH := row.AddCell()
			cellH.Value = item.Label
			cellI := row.AddCell()
			cellI.Value = item.ActivityTime
			cellJ := row.AddCell()
			if item.IsMeeting == 1 {
				cellJ.Value = "到会"
			} else {
				cellJ.Value = "未到会"
			}
			cellK := row.AddCell()
			cellK.Value = item.FirstMeetingTime
			cellL := row.AddCell()
			cellL.Value = item.LastMeetingTime
			cellM := row.AddCell()
			cellM.Value = item.Duration
			cellN := row.AddCell()
			cellN.Value = item.LastMeetingTime
			cellO := row.AddCell()
			cellO.Value = item.MeetingTypeStr
			cellP := row.AddCell()
			cellP.Value = item.MeetingStatusStr
		}
	} else if source == 11 {
		//标头
		rowTitle := sheet.AddRow()
		cellA := rowTitle.AddCell()
		cellA.Value = "文章标题"
		cellB := rowTitle.AddCell()
		cellB.Value = "文章类型"
		cellC := rowTitle.AddCell()
		cellC.Value = "标签"
		cellD := rowTitle.AddCell()
		cellD.Value = "发布时间"
		cellE := rowTitle.AddCell()
		cellE.Value = "阅读时间"
		cellF := rowTitle.AddCell()
		cellF.Value = "阅读时长"
		cellG := rowTitle.AddCell()
		cellG.Value = "阅读来源"

		for _, item := range list {
			row := sheet.AddRow()
			cellA := row.AddCell()
			cellA.Value = item.Title
			cellB := row.AddCell()
			if item.SpecialType == 1 {
				cellB.Value = "笔记"
			} else {
				cellB.Value = "观点"
			}
			cellC := row.AddCell()
			cellC.Value = item.IndustryName
			cellD := row.AddCell()
			cellD.Value = item.PublishDate
			cellE := row.AddCell()
			cellE.Value = item.CreateTime
			cellF := row.AddCell()
			cellF.Value = item.StopTime
			cellG := row.AddCell()
			cellG.Value = cygxService.GetArticleSourcePlatformText(item.RegisterPlatform)
		}
	}
	err = xlsxFile.Save(downLoadnFilePath)
	if err != nil {
		br.Msg = "保存文件失败"
		br.ErrMsg = "保存文件失败"
		return
	}
	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
	downloadFileName := excelName + randStr + ".xlsx"
	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
	defer func() {
		os.Remove(downLoadnFilePath)
	}()
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
}

// @Title 机构列表互动详情table栏
// @Description 机构列表互动详情table栏接口
// @Param  ClassType   query   int  true       "列表类型，1：权益，2：研选，默认1"
// @Success 200 {object} cygx.CygxUserTableListRep
// @router /user/table/companyList [get]
func (this *UserController) TableCompanyList() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}

	roleTypeCode := sysUser.RoleTypeCode
	status := this.GetString("Status")
	classType, _ := this.GetInt("ClassType", 1)
	//流失
	var lossCondition string
	var condition string
	//var lossPars []interface{}

	//状态分类查询条件
	var permissionCondition string

	lossCondition = condition
	//lossPars = pars
	permissionCondition = condition

	//流失客户统计
	lossCondition += ` AND status='流失' `
	//productId := services.GetProductId(roleTypeCode)
	productId := 2
	//权限控制
	{
		//如果不是超级管理员或者财务
		if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
			//如果是部门管理员
			if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
				condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

			} else {
				condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`

				if status == "全部" {
					////如果是筛选了流失客户状态
					if sysUser.Authority <= 0 {
						condition += ` AND (b.seller_id= '` + strconv.Itoa(sysUser.AdminId) + `' OR status='流失')  `

						permissionCondition += ` AND b.seller_id= ` + strconv.Itoa(sysUser.AdminId)
					} else {
						if sysUser.Authority == 1 {
							condition += ` AND (b.department_id=` + strconv.Itoa(sysUser.DepartmentId) + `  OR status='流失')`
							permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
						}
						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND (b.group_id=` + strconv.Itoa(sysUser.GroupId) + `  OR status='流失') `
							}
							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)

						}

						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
							pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
							if err != nil {
								br.Msg = "获取失败"
								br.ErrMsg = "查询父级id异常" + err.Error()
								return
							}
							var ids []*string
							if pid != nil {
								if *pid != 0 {
									//销售主管放在三级列表中
									ids, err = company.GetGroupIdsByParentId(*pid)
									if err != nil {
										fmt.Println(err.Error())
									}
								} else {
									//销售主管放在二级列表中
									ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
									if err != nil {
										fmt.Println(err.Error())
									}
								}
							}
							var idSlice []string
							var sid string
							for _, id := range ids {
								idSlice = append(idSlice, *id)
							}
							//加入父级groupId
							if *pid > 0 {
								idSlice = append(idSlice, strconv.Itoa(*pid))
							} else {
								idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
							}

							sid = strings.Join(idSlice, ",")
							if len(sid) > 0 {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
								}

								permissionCondition += ` AND b.group_id IN (` + sid + `) `
							} else {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
								}
								permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
							}
						}
						if sysUser.Authority == 4 {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND (b.group_id =` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
								//pars = append(pars, sysUser.GroupId)
							}
							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
							//permissionPars = append(permissionPars, sysUser.GroupId)
						}
					}
				} else {
					//如果没有筛选了流失客户状态，那么需要加客户归属条件加入到查询中去
					if sysUser.Authority <= 0 {
						if status != utils.COMPANY_STATUS_LOSE {
							condition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
							//pars = append(pars, sysUser.AdminId)
						}

						permissionCondition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
						//permissionPars = append(permissionPars, sysUser.AdminId)
					} else {
						if sysUser.Authority == 1 {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
								//pars = append(pars, sysUser.DepartmentId)
							}
							permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
							//permissionPars = append(permissionPars, sysUser.DepartmentId)
						}
						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND b.group_id= ` + strconv.Itoa(sysUser.GroupId)
								//pars = append(pars, sysUser.GroupId)
							}
							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
							//permissionPars = append(permissionPars, sysUser.GroupId)
						}
						if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
							pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
							if err != nil {
								br.Msg = "获取失败"
								br.ErrMsg = "查询父级id异常" + err.Error()
								return
							}
							var ids []*string
							if pid != nil {
								if *pid != 0 {
									//销售主管放在三级列表中
									ids, err = company.GetGroupIdsByParentId(*pid)
									if err != nil {
										fmt.Println(err.Error())
									}
								} else {
									//销售主管放在二级列表中
									ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
									if err != nil {
										fmt.Println(err.Error())
									}
								}
							}
							var idSlice []string
							var sid string
							for _, id := range ids {
								idSlice = append(idSlice, *id)
							}
							//加入父级groupId
							if *pid > 0 {
								idSlice = append(idSlice, strconv.Itoa(*pid))
							} else {
								idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
							}

							sid = strings.Join(idSlice, ",")
							if len(sid) > 0 {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
									//pars = append(pars, sysUser.GroupId)
								}

								permissionCondition += ` AND b.group_id IN (` + sid + `) `
							} else {
								if status != utils.COMPANY_STATUS_LOSE {
									condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
									//pars = append(pars, sysUser.GroupId)
								}

								permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
							}
						}

						if sysUser.Authority == 4 {
							if status != utils.COMPANY_STATUS_LOSE {
								condition += ` AND b.group_id =` + strconv.Itoa(sysUser.GroupId)
								//pars = append(pars, sysUser.GroupId)
							}

							permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
							//permissionPars = append(permissionPars, sysUser.GroupId)
						}
					}
				}
			}
		}
	}
	condition += ` AND b.status IN ('正式','试用','冻结') `
	companyCondition := ` AND  a.enabled=1  `
	if condition != "" {
		companyCondition += condition
	}
	resp := new(cygx.CygxUserTableListRep)
	var isAdminRole bool
	//如果不是管理员身份或者研究员身份则需要添加可见范围处理
	if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
		isAdminRole = true
	}
	var pars []interface{}
	lsitCompany, err := company.GetCompanyProductListBycondition(condition, pars)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取数据失败，GetCompanyProductListBycondition Err:" + err.Error()
		return
	}

	var companyIds []string
	for _, v := range lsitCompany {
		companyIds = append(companyIds, strconv.Itoa(v.CompanyId))
	}
	condition = " AND  r.company_id IN (" + strings.Join(companyIds, ",") + ")"
	condition += `  AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
	conditionArtcile := condition                                       //文章搜索条件
	conditionActivityMeet := condition                                  //活动到会搜索条件
	conditionIndustryFllow := condition                                 //产业关注搜索条件
	conditionKeyWord := condition                                       //关键词记录搜索条件
	if classType == 1 {
		conditionArtcile += " AND art.article_type_id = 0  "
		conditionActivityMeet += " AND a.chart_permission_id  != 31  "
		conditionIndustryFllow += " AND m.chart_permission_id  != 31  "
		conditionKeyWord += " AND r.register_platform IN (1,2)  "
	} else {
		conditionArtcile += " AND art.article_type_id > 0  "
		conditionActivityMeet += " AND a.chart_permission_id  = 31  "
		conditionIndustryFllow += " AND m.chart_permission_id  = 31  "
		conditionKeyWord += " AND r.register_platform IN (5,6)  "
	}

	var historyNum int               //报告阅读列表
	var activityNum int              //活动互动记录
	var triptotal int                //专项调研
	var articleCollect int           //收藏的报告
	var chartNum int                 //收藏图表
	var industryFllowNum int         //关注的产业
	var departmentFollowNum int      //关注的作者
	var keyWordNum int               //搜索
	var roadshowTotal int            //音视频播放
	var tagNum int                   //首页标签点击
	var yanxuanSpecialNum int        //专栏文章阅读记录
	var yanxuanSpecialCollectNum int //收藏的专栏文章
	var yanxuanSpecialFollowNum int  //关注的专栏作者
	var feedbackNum int              //交流反馈数量
	var calendarMeetingNum int       //1v1 路演数量

	if isAdminRole {
		historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCount(conditionArtcile, pars)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录数量失败，Err:" + err.Error()
			return
		}

		//获取参会总数
		activityNum, err = cygx.GetActivityMeetByCompanyCount(conditionActivityMeet)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取参会总数失败，Err:" + err.Error()
			return
		}
		//获取用户收藏记录总数
		articleCollect, err = cygx.GetCygxArticleCollectCountByCompany(conditionArtcile)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户收藏记录总数失败，Err:" + err.Error()
			return
		}
		//获取用户关注总数
		industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompany(conditionIndustryFllow)
		if err != nil {
			br.Msg = "获取信息失败 "
			br.ErrMsg = "获取用户关注总数失败，Err:" + err.Error()
			return
		}
		//获取关注作者总数
		departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取关注作者总数失败，Err:" + err.Error()
			return
		}
		//获取搜索记录
		keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompany(conditionKeyWord)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}

		chartNum, err = cygx.GetChartCountByUserMobile(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取总数失败，Err:" + err.Error()
			return
		}

		triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}

		roadshowTotal, err = cygx.GetCygxRoadshowCountByCompany(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}
		tagNum, err = cygx.GetCygxTagHistoryCount(condition)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录失败"
			return
		}

		yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCount(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取研选专栏阅读数量失败"
			return
		}

		yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCount(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取收藏的专栏文章数量失败"
			return
		}

		yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCount(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取关注的专栏作者数量失败"
			return
		}
		feedbackNum, err = cygx.GetCygxUserFeedbackCountByUserModel(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取交流反馈数量失败"
			return
		}

		calendarMeetingNum, err = roadshow.GetRsCalendarMeetingUserCountByUserModel(condition, pars)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "GetRsCalendarMeetingUserCountByUserModel，Err:" + err.Error()
			return
		}

	} else {
		historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(conditionArtcile, pars)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户阅读记录数量失败，Err:" + err.Error()
			return
		}

		//获取参会总数
		activityNum, err = cygx.GetActivityMeetByCompanyCountWeekly(conditionActivityMeet)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取参会总数失败，Err:" + err.Error()
			return
		}
		//获取用户收藏记录总数
		articleCollect, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(conditionArtcile)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取用户收藏记录总数失败，Err:" + err.Error()
			return
		}
		//获取用户关注总数
		industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(conditionIndustryFllow)
		if err != nil {
			br.Msg = "获取信息失败 "
			br.ErrMsg = "获取用户关注总数失败，Err:" + err.Error()
			return
		}
		//获取关注作者总数
		departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取关注作者总数失败，Err:" + err.Error()
			return
		}
		//获取搜索记录
		keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(conditionKeyWord)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}

		chartNum, err = cygx.GetChartCountByUserMobileWeekly(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取总数失败，Err:" + err.Error()
			return
		}

		triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}

		roadshowTotal, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "获取搜索记录失败，Err:" + err.Error()
			return
		}
		tagNum, err = cygx.GetCygxTagHistoryCountWeekly(condition)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取搜索记录失败"
			return
		}

		yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCountWeekly(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取研选专栏阅读数量失败"
			return
		}

		yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCountWeekly(condition, pars)
		if err != nil {
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			br.Msg = "获取收藏的专栏文章数量失败"
			return
		}

		yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCountWeekly(condition, pars)
		if err != nil {
			br.Msg = "获取关注的专栏作者数量失败"
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			return
		}
		feedbackNum, err = cygx.GetCygxUserFeedbackCountByUserModelWeekly(condition, pars)
		if err != nil {
			br.Msg = "获取交流反馈数量失败"
			br.ErrMsg = "获取信息失败，Err:" + err.Error()
			return
		}

		calendarMeetingNum, err = roadshow.GetRsCalendarMeetingUserCountByUserModelWeekly(condition, pars)
		if err != nil {
			br.Msg = "获取信息失败"
			br.ErrMsg = "GetRsCalendarMeetingUserCountByUserModelWeekly，Err:" + err.Error()
			return
		}

	}

	if classType == 1 {
		List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
			{PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
			{PermissionName: "专项调研", Source: 8, TotalNum: triptotal},
			{PermissionName: "1v1路演", Source: 15, TotalNum: calendarMeetingNum},
			{PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
			{PermissionName: "收藏图表", Source: 4, TotalNum: chartNum},
			{PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
			{PermissionName: "搜索", Source: 7, TotalNum: keyWordNum},
			{PermissionName: "音视频播放", Source: 9, TotalNum: roadshowTotal},
			{PermissionName: "首页标签点击", Source: 10, TotalNum: tagNum},
			{PermissionName: "交流反馈", Source: 14, TotalNum: feedbackNum}}
		resp.List = List
	} else {
		List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
			{PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
			{PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
			{PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
			{PermissionName: "关注的作者", Source: 6, TotalNum: departmentFollowNum},
			{PermissionName: "专栏文章阅读记录", Source: 11, TotalNum: yanxuanSpecialNum},
			{PermissionName: "收藏的专栏文章", Source: 12, TotalNum: yanxuanSpecialCollectNum},
			{PermissionName: "关注的专栏作者", Source: 13, TotalNum: yanxuanSpecialFollowNum},
			{PermissionName: "搜索", Source: 7, TotalNum: keyWordNum}}
		resp.List = List
	}
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 添加/取消用户提醒
// @Description 添加/取消用户提醒
// @Param	request	body cygx.UserRemarAddReq true "type json string"
// @Success 200 新增成功
// @router /user/remind [post]
func (this *UserController) UserRemind() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	var req cygx.UserRemarAddReq
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
	if err != nil {
		br.Msg = "参数解析异常！"
		br.ErrMsg = "参数解析失败，Err:" + err.Error()
		return
	}
	userId := req.UserId
	sourceType := req.SourceType
	doType := req.DoType
	wxUser, err := cygx.GetUserAndCompanyNameList(userId)
	if err != nil {
		br.Msg = "设置互动提醒失败"
		br.ErrMsg = "获取信息失败，Err:" + err.Error()
		return
	}
	if sourceType != 1 && sourceType != 2 {
		br.Msg = "设置互动提醒失败"
		br.ErrMsg = "设置互动提醒失败，sourceType:" + strconv.Itoa(sourceType)
		return
	}
	if doType != 1 && doType != 2 {
		br.Msg = "设置互动提醒失败"
		br.ErrMsg = "设置互动提醒失败，doType:" + strconv.Itoa(doType)
		return
	}
	count, err := cygx.GetCygxUserRemindCount(userId)
	if err != nil {
		br.Msg = "获取数据失败！"
		br.ErrMsg = "获取数据失败，Err:" + err.Error()
		return
	}
	resp := new(cygx.CygxUserRemindResp)
	if count <= 0 {
		var items []*cygx.CygxUserRemind
		if sourceType == 1 {
			item := new(cygx.CygxUserRemind)
			item.AdminId = sysUser.AdminId
			item.AdminName = sysUser.RealName
			item.UserId = userId
			item.Mobile = wxUser.Mobile
			item.Email = wxUser.Email
			item.CompanyId = wxUser.CompanyId
			item.CompanyName = wxUser.CompanyName
			item.RealName = wxUser.RealName
			item.CreateTime = time.Now()
			item.ModifyTime = time.Now()
			items = append(items, item)
		} else {
			//获取机构下所有的用户
			listUser, err := models.GetWxUserListCompanyId(wxUser.CompanyId)
			if err != nil {
				br.Msg = "获取数据失败！"
				br.ErrMsg = "获取数据失败，GetWxUserListCompanyId Err:" + err.Error()
				return
			}
			//获取已经添加消息提醒的
			listUserRemind, err := cygx.GetCygxUserRemindListByCompanyId(wxUser.CompanyId)
			if err != nil {
				br.Msg = "获取数据失败！"
				br.ErrMsg = "获取数据失败，GetCygxUserRemindListByCompanyId Err:" + err.Error()
				return
			}
			mapUserRemind := make(map[int]bool)
			for _, v := range listUserRemind {
				mapUserRemind[v.UserId] = true
			}
			for _, v := range listUser {
				//如果已经添加了提醒的用户就不做添加处理
				if mapUserRemind[v.UserId] {
					continue
				}
				item := new(cygx.CygxUserRemind)
				item.AdminId = sysUser.AdminId
				item.AdminName = sysUser.RealName
				item.UserId = v.UserId
				item.Mobile = v.Mobile
				item.Email = v.Email
				item.CompanyId = v.CompanyId
				item.CompanyName = v.CompanyName
				item.RealName = v.RealName
				item.CreateTime = time.Now()
				item.ModifyTime = time.Now()
				items = append(items, item)
			}
		}
		//批量加入
		err = cygx.AddCygxUserRemindMulti(items)
		if err != nil {
			br.Msg = "添加失败"
			br.ErrMsg = "添加失败,Err:" + err.Error()
			return
		}
		br.Msg = "收藏成功"
		resp.Status = 1
	} else {
		if sourceType == 1 {
			err = cygx.RemoveCygxUserRemind(userId) //取消个人提醒
		} else {
			err = cygx.RemoveCygxUserRemindByCompanyId(wxUser.CompanyId) //取消整个机构提醒
		}

		if err != nil {
			br.Msg = "取消失败"
			br.ErrMsg = "取消失败,Err:" + err.Error()
			return
		}
		br.Msg = "已取消收藏"
		resp.Status = 2
	}
	br.Ret = 200
	br.Success = true
	br.Data = resp
}
