Jelajahi Sumber

Merge branch 'cygx_4.0' of hongze/hongze_cygx into master

hongze 3 tahun lalu
induk
melakukan
5401371da5

+ 1 - 1
controllers/activity.go

@@ -1628,7 +1628,7 @@ func (this *ActivityCoAntroller) LabelList() {
 	//	pageSize = utils.PageSize20
 	//}
 	//currentIndex = 1
-	pageSize = 16
+	pageSize = 15
 	//startSize = utils.StartIndex(currentIndex, pageSize)
 	var condition string
 	var sortTime string

+ 2 - 0
controllers/article.go

@@ -224,9 +224,11 @@ func (this *ArticleController) Detail() {
 			br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 			return
 		}
+		fmt.Println(detail.SellerAndMobile)
 		if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
 			strnum := strings.Index(detail.SellerAndMobile, "-")
 			detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
+			fmt.Println(detail.SellerAndMobile)
 			if strnum > 0 {
 				nickName := detail.SellerAndMobile[0:strnum]
 				sellerAndMobile := &models.SellerRep{

+ 167 - 6
controllers/report.go

@@ -633,10 +633,11 @@ func (this *ReportController) IndustryListByDepartment() {
 	uid := user.UserId
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
-	chartPermissionId, _ := this.GetInt("ChartPermissionId")
+	//chartPermissionId, _ := this.GetInt("ChartPermissionId")
 	var startSize int
 	var condition string
-	condition = `	AND a.is_report = 1  AND a.publish_status=1  AND m.chart_permission_id =` + strconv.Itoa(chartPermissionId)
+	//condition = `  AND a.publish_status=1  AND m.chart_permission_id =` + strconv.Itoa(chartPermissionId)
+	condition = `  AND a.publish_status=1 `
 	if pageSize <= 0 {
 		pageSize = utils.PageSize20
 	}
@@ -701,19 +702,53 @@ func (this *ReportController) IndustryListByDepartment() {
 			subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
 			artList[k2].SubjectName = subjectNamesNew
 			artList[k2].DepartmentId = v.DepartmentId
-			artList[k2].IndustryName = industryName + "-" + subjectNamesNew
+			if subjectNamesNew == "" {
+				artList[k2].IndustryName = industryName
+			} else {
+				artList[k2].IndustryName = industryName + "-" + subjectNamesNew
+			}
+			if artList[k2].IsReport == "1" {
+				artList[k2].IndustryName = "【观点】" + artList[k2].IndustryName
+			} else {
+				artList[k2].IndustryName = "【纪要】" + artList[k2].IndustryName
+			}
 		}
 		list[k].List = artList
 		if v.FollowNum > 0 {
 			list[k].IsMyFollow = true
 		}
 	}
-	resp.ListnNew, err = models.GetIndustrialSubjectByDepartmentNew()
+	listnNew, err := models.GetIndustrialSubjectByDepartmentNew()
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 		return
 	}
+	if len(listnNew) > 0 {
+		for _, v := range listnNew {
+			firstStr := strings.Index(v.IndustrialAndSubjectIds, "—")
+			Management := new(models.IndustrialManagementIdInt)
+			if firstStr == 0 {
+				Management.IndustryName = v.IndustryName
+			} else {
+				listSub, err := models.GetIndustrialManagementSubjectList(v.ArticleId)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取关联标的列表失败,Err:" + err.Error()
+					return
+				}
+				var subjectNamesNew string
+				for _, v1 := range listSub {
+					subjectNamesNew += v1.SubjectName + "/"
+				}
+				subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
+				Management.IndustryName = subjectNamesNew
+			}
+			Management.IndustrialManagementId = v.IndustrialManagementId
+			Management.ArticleId = v.ArticleId
+			resp.ListnNew = append(resp.ListnNew, Management)
+		}
+	}
 	resp.List = list
 	resp.Paging = page
 	br.Ret = 200
@@ -903,7 +938,7 @@ func (this *ReportController) ReportList() {
 		return
 	}
 	page = paging.GetPaging(currentIndex, pageSize, total)
-	condition += ` AND art.is_report =1 	GROUP BY art.article_id ORDER BY art.publish_date DESC`
+	condition += `  GROUP BY art.article_id ORDER BY art.publish_date DESC`
 	list, err := models.IndustrialToArticleWhichDepartment(condition, pars, uid, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取失败"
@@ -938,7 +973,133 @@ func (this *ReportController) ReportList() {
 		}
 		subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
 		list[k].SubjectName = subjectNamesNew
-		list[k].IndustryName = industryName + "-" + subjectNamesNew
+		if subjectNamesNew != "" {
+			list[k].IndustryName = industryName + "-" + subjectNamesNew
+		} else {
+			list[k].IndustryName = industryName
+		}
+		resp.IndustryName = industryName
+	}
+	resp.List = list
+	resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 研选最新主题关键词文章列表接口
+// @Description 获取研选最新主题关键词文章列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ArticleId      query   int  true       "文章id"
+// @Success 200 {object} models.ReportArticleWhichIndustrialRepList
+// @router /industry/reportListNew [get]
+func (this *ReportController) ReportListNew() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	articleId, _ := this.GetInt("ArticleId")
+	var condition string
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+	var pars []interface{}
+	var total int
+	resp := new(models.ReportArticleWhichIndustrialRepList)
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	userType, _, err := services.GetUserType(user.CompanyId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	if userType == 1 {
+		resp.Paging = page
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
+	}
+	resp.HaveResearch = true
+	if articleId > 0 {
+		detail, err := models.GetArticleDetailById(articleId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取信息失败,Err:" + err.Error()
+			return
+		}
+		firstStr := strings.Index(detail.IndustrialAndSubjectIds, "—")
+		if firstStr == 0 {
+			condition += ` AND art.industrial_management_id = '` + strconv.Itoa(detail.IndustrialManagementId) + `'`
+		} else {
+			condition += ` AND art.industrial_and_subject_ids = '` + detail.IndustrialAndSubjectIds + `'`
+		}
+	}
+	total, err = models.GetWhichDepartmentCount(condition)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
+		return
+	}
+	page = paging.GetPaging(currentIndex, pageSize, total)
+	condition += `  GROUP BY art.article_id ORDER BY art.publish_date DESC`
+	list, err := models.IndustrialToArticleWhichDepartment(condition, pars, uid, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	for k, v := range list {
+		if v.Readnum == 0 {
+			list[k].IsRed = true
+		}
+		list[k].IsResearch = true
+		subjectNames, err := models.GetSubjectNames(v.ArticleId)
+		if err != nil {
+			br.Msg = "获取失败" + strconv.Itoa(v.ArticleId)
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		var subjectNamesNew string
+		if len(subjectNames) > 0 {
+			slice := strings.Split(subjectNames, "/")
+			for k3, v3 := range slice {
+				if k3 < 4 {
+					subjectNamesNew += v3 + "/"
+				}
+			}
+		}
+		industryName, err := models.GetIndustrialNames(v.ArticleId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败" + strconv.Itoa(v.ArticleId)
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
+		list[k].SubjectName = subjectNamesNew
+		if subjectNamesNew != "" {
+			list[k].IndustryName = industryName + "-" + subjectNamesNew
+		} else {
+			list[k].IndustryName = industryName
+		}
 		resp.IndustryName = industryName
 	}
 	resp.List = list

+ 79 - 0
models/activity.go

@@ -403,6 +403,13 @@ type SignupExportRep struct {
 	SellerName     string `description:"销售姓名"`
 }
 
+type ActivityMsgExportRep struct {
+	RealName    string `description:"姓名"`
+	CompanyName string `description:"公司名称"`
+	Content     string `description:"内容"`
+	CreateTime  string `description:"提交时间"`
+}
+
 func GetSignupExport(activityId int) (item []*SignupExportRep, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT s.*  ,a.is_limit_people,u.real_name,
@@ -448,3 +455,75 @@ func GetActivityLabelListAll(condition, sortTime string, pars []interface{}, sta
 type GetCygxActivityLabelListRep struct {
 	List []*CygxActivityLabelList
 }
+
+//获取研选系列专家电话会,会前1小时,满足推送的活动ID数量
+func GetCountActivityResearchToSendFile(condition, endDate string) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	COUNT(1) count
+FROM
+	cygx_activity AS a
+	INNER JOIN cygx_activity_help_ask AS k ON k.activity_id = a.activity_id 
+WHERE
+	1 = 1 ` + condition + `
+	AND a.is_send_ask_msg = 0 
+	AND a.activity_time <= ? 
+	AND a.activity_time >= NOW()`
+	err = o.Raw(sql, endDate).QueryRow(&count)
+	return
+}
+
+//获取研选系列专家电话会,会前1小时,满足推送的活动ID
+func GetActivityResearchToSendFile(condition, endDate string) (items []*ActivityIdRep, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	* 
+FROM
+	cygx_activity AS a
+	INNER JOIN cygx_activity_help_ask AS k ON k.activity_id = a.activity_id 
+WHERE
+	1 = 1 ` + condition + `
+	AND a.is_send_ask_msg = 0 
+	AND a.activity_time <= ? 
+	AND a.activity_time >= NOW() 
+GROUP BY
+	a.activity_id `
+	_, err = o.Raw(sql, endDate).QueryRows(&items)
+	return
+}
+
+func GetActivityMsgExport(activityId int) (item []*ActivityMsgExportRep, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			k.*,
+			u.real_name 
+			FROM
+			cygx_activity_help_ask AS k
+			LEFT JOIN wx_user AS u ON u.user_id = k.user_id 
+			WHERE
+			k.activity_id = ? 
+			GROUP BY
+			k.ask_id`
+	_, err = o.Raw(sql, activityId).QueryRows(&item)
+	return
+}
+
+//修改文件带问消息是否推送状态
+func UPdateActivityMsgToSendFile(activityId int) (err error) {
+	sql := ` UPDATE cygx_activity SET  is_send_ask_msg= 1  WHERE activity_id = ?`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, activityId).Exec()
+	return
+}
+
+type AskEmailRep struct {
+	Name  string `description:"姓名"`
+	Email string `description:"邮箱"`
+}
+
+func GetAskEmail() (item []*AskEmailRep, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_activity_ask_email`
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}

+ 38 - 36
models/article.go

@@ -84,42 +84,44 @@ type HomeArticle struct {
 }
 
 type ArticleDetail struct {
-	ArticleId            int    `description:"报告id"`
-	Title                string `description:"标题"`
-	TitleEn              string `description:"英文标题 "`
-	UpdateFrequency      string `description:"更新周期"`
-	CreateDate           string `description:"创建时间"`
-	PublishDate          string `description:"发布时间"`
-	Body                 string `description:"内容"`
-	Abstract             string `description:"摘要"`
-	CategoryName         string `description:"一级分类"`
-	SubCategoryName      string `description:"二级分类"`
-	IsCollect            bool   `description:"是否收藏:true,已收藏,false:未收藏"`
-	IsInterviewApply     bool   `description:"是否申请访谈:true,已申请,false:未申请"`
-	BodyText             string `description:"内容"`
-	InterviewApplyStatus string `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
-	InterviewDate        string `description:"访谈时间"`
-	ExpertBackground     string `description:"专家背景"`
-	ExpertNumber         string `description:"专家编号"`
-	Department           string `description:"作者"`
-	SellerMobile         string `description:"销售手机号"`
-	SellerName           string `description:"销售名称"`
-	ArticleIdMd5         string `description:"纪要id"`
-	IsClass              int    `description:"是否归类,1是,0否"`
-	CategoryId           int    `description:"分类ID"`
-	IsSummary            int    `description:"是否是纪要库,1是,0否"`
-	IsReport             int    `description:"是否属于报告,1是,0否"`
-	IsResearch           bool   `description:"是否属于研选"`
-	FileLink             string `description:"下载预览链接"`
-	SellerAndMobile      string `description:"销售和手机号"`
-	IsFollow             bool   `description:"是否关注,1是,0否"`
-	IsBelongSummary      bool   `description:"是否属于纪要库"`
-	IsBelongReport       bool   `description:"是否属于报告"`
-	FollowNum            int    `description:"关注数量"`
-	CollectionNum        int    `description:"收藏数量"`
-	DepartmentId         int    `description:"作者ID"`
-	SubjectIds           string `description:"文章关联标的的ID字符串"`
-	SellerList           []*SellerRep
+	ArticleId               int    `description:"报告id"`
+	Title                   string `description:"标题"`
+	TitleEn                 string `description:"英文标题 "`
+	UpdateFrequency         string `description:"更新周期"`
+	CreateDate              string `description:"创建时间"`
+	PublishDate             string `description:"发布时间"`
+	Body                    string `description:"内容"`
+	Abstract                string `description:"摘要"`
+	CategoryName            string `description:"一级分类"`
+	SubCategoryName         string `description:"二级分类"`
+	IsCollect               bool   `description:"是否收藏:true,已收藏,false:未收藏"`
+	IsInterviewApply        bool   `description:"是否申请访谈:true,已申请,false:未申请"`
+	BodyText                string `description:"内容"`
+	InterviewApplyStatus    string `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
+	InterviewDate           string `description:"访谈时间"`
+	ExpertBackground        string `description:"专家背景"`
+	ExpertNumber            string `description:"专家编号"`
+	Department              string `description:"作者"`
+	SellerMobile            string `description:"销售手机号"`
+	SellerName              string `description:"销售名称"`
+	ArticleIdMd5            string `description:"纪要id"`
+	IsClass                 int    `description:"是否归类,1是,0否"`
+	CategoryId              int    `description:"分类ID"`
+	IsSummary               int    `description:"是否是纪要库,1是,0否"`
+	IsReport                int    `description:"是否属于报告,1是,0否"`
+	IsResearch              bool   `description:"是否属于研选"`
+	FileLink                string `description:"下载预览链接"`
+	SellerAndMobile         string `description:"销售和手机号"`
+	IsFollow                bool   `description:"是否关注,1是,0否"`
+	IsBelongSummary         bool   `description:"是否属于纪要库"`
+	IsBelongReport          bool   `description:"是否属于报告"`
+	FollowNum               int    `description:"关注数量"`
+	CollectionNum           int    `description:"收藏数量"`
+	DepartmentId            int    `description:"作者ID"`
+	SubjectIds              string `description:"文章关联标的的ID字符串"`
+	IndustrialAndSubjectIds string `description:"文章关联产业和标的的ID字符串"`
+	IndustrialManagementId  int    `description:"文章关联产业ID"`
+	SellerList              []*SellerRep
 }
 
 type ArticleDetailFileLink struct {

+ 22 - 15
models/article_department.go

@@ -113,21 +113,28 @@ func GetIndustrialSubjectByDepartment(departmentId int) (items []*IndustrialMana
 }
 
 //最新产业列表
-func GetIndustrialSubjectByDepartmentNew() (items []*IndustrialManagementIdInt, err error) {
+func GetIndustrialSubjectByDepartmentNew() (items []*IndustrialManagementIdInts, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT m.*, MAX( a.publish_date ) art_time
-			FROM
-			cygx_article_department AS d
-			INNER JOIN cygx_article AS a ON a.department_id = d.department_id
-			INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
-			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id 
-			WHERE 1 = 1
-			AND a.publish_status=1 
-			AND a.subject_ids != ''
-			AND a.is_report=1 
-			GROUP BY
-			m.industrial_management_id 
-			ORDER BY art_time DESC LIMIT 6 `
+	sql := `SELECT
+	a.article_id,
+	a.industrial_and_subject_ids,
+	m.*,
+	MAX( a.publish_date ) art_time
+FROM
+	cygx_article_department AS d
+	INNER  JOIN cygx_article AS a ON a.department_id = d.department_id
+	LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
+	LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id 
+	LEFT JOIN cygx_industrial_article_group_subject AS sg  ON sg.article_id = a.article_id
+WHERE
+	1 = 1 
+	AND a.publish_status = 1 
+	AND a.industrial_and_subject_ids != '' 
+GROUP BY
+	a.industrial_and_subject_ids 
+ORDER BY
+	art_time DESC 
+	LIMIT 6 `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
@@ -185,7 +192,7 @@ func GetIndustrialSubjectNewListByDepartmentId(departmentId, industrialManagemen
 //最新标的列表
 func GetArticleByDepartmentId(departmentId int) (items []*IndustrialManagementIdName, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT article_id,	MAX( publish_date ) art_time  FROM cygx_article WHERE department_id = ? AND  publish_status = 1 AND subject_ids != '' GROUP  BY subject_ids  ORDER BY art_time DESC  LIMIT 4 `
+	sql := `SELECT article_id,is_report,MAX( publish_date ) art_time  FROM cygx_article WHERE department_id = ? AND  publish_status = 1 AND subject_ids != '' GROUP  BY subject_ids  ORDER BY art_time DESC  LIMIT 4 `
 	_, err = o.Raw(sql, departmentId).QueryRows(&items)
 	return
 }

+ 44 - 0
models/industrial_management.go

@@ -222,6 +222,15 @@ type IndustrialManagementIdInt struct {
 	IndustrialManagementId int    `description:"产业Id"`
 	IndustryName           string `description:"产业名称"`
 	SubjectName            string `description:"标的名称"`
+	ArticleId              int    `description:"文章ID"`
+}
+
+type IndustrialManagementIdInts struct {
+	IndustrialManagementId  int    `description:"产业Id"`
+	IndustryName            string `description:"产业名称"`
+	SubjectNames            string `description:"标的名称"`
+	ArticleId               int    `description:"文章ID"`
+	IndustrialAndSubjectIds string `description:"关联标的以及产业ID"`
 }
 
 type IndustrialManagementIdName struct {
@@ -229,6 +238,7 @@ type IndustrialManagementIdName struct {
 	ArticleId    int    `description:"文章id"`
 	IndustryName string `description:"产业名称"`
 	SubjectName  string `description:"标的名称"`
+	IsReport     string `description:"1观点,0纪要"`
 }
 
 //获取归类产业报告数量大于10的
@@ -291,3 +301,37 @@ func GetIndustrialManagementHot3(chartPermissionId int) (item *IndustrialManagem
 	err = o.Raw(sql, chartPermissionId).QueryRow(&item)
 	return
 }
+
+//获取产业关联标的的数量
+func GetIndustrialManagementSubjectCount(industrialManagementId int) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count FROM
+				cygx_industrial_subject AS s 
+				INNER JOIN cygx_industrial_article_group_subject as sg ON sg.industrial_subject_id = s.industrial_subject_id
+				INNER JOIN cygx_article as a ON a.article_id = sg.article_id
+				WHERE a.industrial_management_id = ?
+				AND a.publish_status = 1`
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, industrialManagementId).QueryRow(&count)
+	return
+}
+
+//获取产业关联标的列表
+func GetIndustrialManagementSubjectList(articleId int) (items []*IndustrialSubject, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	s.subject_name 
+FROM
+	cygx_industrial_subject AS s
+	INNER JOIN cygx_industrial_article_group_subject AS sg ON sg.industrial_subject_id = s.industrial_subject_id
+	INNER JOIN cygx_article AS a 
+WHERE
+	sg.article_id = ? 
+	AND a.publish_status = 1 
+GROUP BY
+	s.industrial_subject_id 
+ORDER BY
+	sg.create_time DESC 
+	LIMIT 4`
+	_, err = o.Raw(sql, articleId).QueryRows(&items)
+	return
+}

+ 243 - 0
services/activity.go

@@ -393,3 +393,246 @@ func GetHavePower(activityInfo *models.ActivityDetail, permissionStr, companyDet
 	}
 	return
 }
+
+//研选系列专家电话会,会前1小时将问题列表发送给邮箱
+func SendEmailFileForAskMsgResearch(cont context.Context) (err error) {
+	var msg string
+	var touser string
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
+			utils.FileLog.Info("发送附件模版消息失败,Err:%s", err.Error())
+		}
+		if msg != "" {
+			fmt.Println(msg)
+			utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
+		}
+	}()
+	endDate := time.Now().Add(+time.Minute * 60).Format("2006-01-02 15:04:05")
+	condition := `AND  a.activity_type_id = 1 AND a.chart_permission_name = '研选' `
+	total, err := models.GetCountActivityResearchToSendFile(condition, endDate)
+	if total == 0 {
+		fmt.Println("发送附件完成0")
+		return nil
+	}
+	if err != nil {
+		msg = "发送附件模版消息失败 Err:" + err.Error()
+		return
+	}
+	listActivity, err := models.GetActivityResearchToSendFile(condition, endDate)
+	if err != nil {
+		msg = "发送附件模版消息失败 Err:" + err.Error()
+		return
+	}
+	for _, v := range listActivity {
+		fmt.Println(v.ActivityId)
+		activityInfo, _ := models.GetAddActivityInfoById(v.ActivityId)
+		if activityInfo == nil {
+			msg = "活动不存在,Err:activityId:" + strconv.Itoa(v.ActivityId)
+			return
+		}
+		list, errFile := models.GetActivityMsgExport(v.ActivityId)
+		if errFile != nil {
+			msg = "获取失败,Err:" + errFile.Error()
+			return
+		}
+		//创建excel
+		dir, errFile := os.Executable()
+		exPath := filepath.Dir(dir)
+		downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".xlsx"
+		xlsxFile := xlsx.NewFile()
+		if errFile != nil {
+			msg = "生成文件失败Err:" + errFile.Error()
+			return
+		}
+		style := xlsx.NewStyle()
+		alignment := xlsx.Alignment{
+			Horizontal: "center",
+			Vertical:   "center",
+			WrapText:   true,
+		}
+		style.Alignment = alignment
+		style.ApplyAlignment = true
+		sheet, errFile := xlsxFile.AddSheet("外呼名单")
+		if errFile != nil {
+			msg = "新增Sheet失败,Err:" + errFile.Error()
+			return
+		}
+		//标头
+		rowTitle := sheet.AddRow()
+		cellA := rowTitle.AddCell()
+		cellA.Value = "姓名"
+		cellB := rowTitle.AddCell()
+		cellB.Value = "公司名称"
+		cellC := rowTitle.AddCell()
+		cellC.Value = "问题"
+		cellD := rowTitle.AddCell()
+		cellD.Value = "提交时间"
+
+		for _, item := range list {
+			row := sheet.AddRow()
+			cellA := row.AddCell()
+			cellA.Value = item.RealName
+			cellB := row.AddCell()
+			cellB.Value = item.CompanyName
+			cellC := row.AddCell()
+			cellC.Value = item.Content
+			cellD := row.AddCell()
+			cellD.Value = item.CreateTime
+		}
+		errFile = xlsxFile.Save(downLoadnFilePath)
+		if errFile != nil {
+			msg = "保存文件失败Err:" + errFile.Error()
+			return
+		}
+		title := activityInfo.ActivityName + "-活动带问"
+		content := "活动带问详情"
+		fileName := downLoadnFilePath
+		if utils.WxMsgTemplateIdAskMsgMobile == "" {
+			touser = "cxzhang@hzinsights.com;ywang@hzinsights.com"
+		} else {
+			touser = "cxzhang@hzinsights.com;jhwang@hzinsights.com;tshen@hzinsights.com"
+		}
+		sendResult := utils.SendEmailByHongze(title, content, touser, fileName, title+".xlsx")
+		if sendResult {
+			errFile = models.UPdateActivityMsgToSendFile(v.ActivityId)
+			if errFile != nil {
+				msg = "获取失败,Err:" + errFile.Error()
+				return
+			}
+			os.Remove(downLoadnFilePath)
+		} else {
+			go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+activityInfo.ActivityName, utils.EmailSendToUsers)
+			utils.FileLog.Info("发送附件模版消息失败,Err:%s", activityInfo.ActivityName)
+		}
+	}
+	return
+}
+
+//非研选系列专家电话会,根据主持人姓名,会前15分钟将问题列表发送给至该主持人对应邮箱
+func SendEmailFileForAskMsg(cont context.Context) (err error) {
+	var msg string
+	var touser string
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
+			utils.FileLog.Info("发送附件模版消息失败,Err:%s", err.Error())
+		}
+		if msg != "" {
+			fmt.Println(msg)
+			utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
+		}
+	}()
+	endDate := time.Now().Add(+time.Minute * 15).Format("2006-01-02 15:04:05")
+	condition := `AND  a.activity_type_id = 1 AND  a.chart_permission_name != '研选' `
+	total, err := models.GetCountActivityResearchToSendFile(condition, endDate)
+	if total == 0 {
+		fmt.Println("发送附件完成0")
+		return nil
+	}
+	if err != nil {
+		msg = "发送附件模版消息失败 Err:" + err.Error()
+		return
+	}
+	listActivity, err := models.GetActivityResearchToSendFile(condition, endDate)
+	if err != nil {
+		msg = "发送附件模版消息失败 Err:" + err.Error()
+		return
+	}
+	listEmail, errEmail := models.GetAskEmail()
+	if errEmail != nil {
+		msg = "获取失败,Err:" + errEmail.Error()
+		return
+	}
+	for _, v := range listActivity {
+		fmt.Println(v.ActivityId)
+		activityInfo, _ := models.GetAddActivityInfoById(v.ActivityId)
+		if activityInfo == nil {
+			msg = "活动不存在,Err:activityId:" + strconv.Itoa(v.ActivityId)
+			return
+		}
+		list, errFile := models.GetActivityMsgExport(v.ActivityId)
+		if errFile != nil {
+			msg = "获取失败,Err:" + errFile.Error()
+			return
+		}
+		for _, v := range listEmail {
+			if strings.Index(activityInfo.Host, v.Name) > 0 {
+				touser += v.Email + ";"
+			}
+		}
+		if touser != "" {
+			touser = strings.TrimRight(touser, ";")
+		} else {
+			fmt.Println("没有对应的邮箱")
+			return
+		}
+		//创建excel
+		dir, errFile := os.Executable()
+		exPath := filepath.Dir(dir)
+		downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".xlsx"
+		xlsxFile := xlsx.NewFile()
+		if errFile != nil {
+			msg = "生成文件失败Err:" + errFile.Error()
+			return
+		}
+		style := xlsx.NewStyle()
+		alignment := xlsx.Alignment{
+			Horizontal: "center",
+			Vertical:   "center",
+			WrapText:   true,
+		}
+		style.Alignment = alignment
+		style.ApplyAlignment = true
+		sheet, errFile := xlsxFile.AddSheet("外呼名单")
+		if errFile != nil {
+			msg = "新增Sheet失败,Err:" + errFile.Error()
+			return
+		}
+		//标头
+		rowTitle := sheet.AddRow()
+		cellA := rowTitle.AddCell()
+		cellA.Value = "姓名"
+		cellB := rowTitle.AddCell()
+		cellB.Value = "公司名称"
+		cellC := rowTitle.AddCell()
+		cellC.Value = "问题"
+		cellD := rowTitle.AddCell()
+		cellD.Value = "提交时间"
+		for _, item := range list {
+			row := sheet.AddRow()
+			cellA := row.AddCell()
+			cellA.Value = item.RealName
+			cellB := row.AddCell()
+			cellB.Value = item.CompanyName
+			cellC := row.AddCell()
+			cellC.Value = item.Content
+			cellD := row.AddCell()
+			cellD.Value = item.CreateTime
+		}
+		errFile = xlsxFile.Save(downLoadnFilePath)
+		if errFile != nil {
+			msg = "保存文件失败Err:" + errFile.Error()
+			return
+		}
+		title := activityInfo.ActivityName + "-活动带问"
+		content := "活动带问详情"
+		fileName := downLoadnFilePath
+		//haveSuccess := utils.SendEmailHaveFile(title, content, fileName, touser)
+		sendResult := utils.SendEmailByHongze(title, content, touser, fileName, title+".xlsx")
+		if sendResult {
+			errFile = models.UPdateActivityMsgToSendFile(v.ActivityId)
+			if errFile != nil {
+				msg = "获取失败,Err:" + errFile.Error()
+				return
+			}
+			os.Remove(downLoadnFilePath)
+		} else {
+			go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+activityInfo.ActivityName, utils.EmailSendToUsers)
+			utils.FileLog.Info("发送附件模版消息失败,Err:%s", activityInfo.ActivityName)
+		}
+	}
+	return
+}

+ 6 - 0
services/task.go

@@ -39,6 +39,12 @@ func Task() {
 	sendEmailFileToExpert := task.NewTask("sendEmailFileToExpert", "0 */5 8-22 * * *", SendEmailFileToExpert) //预约外呼名单,会前1小时自动发送邮件给专家组
 	task.AddTask("sendEmailFileToExpert", sendEmailFileToExpert)
 
+	sendEmailFileForAskMsgResearch := task.NewTask("sendEmailFileForAskMsgResearch", "0 */5 8-22 * * *", SendEmailFileForAskMsgResearch) //研选系列专家电话会,会前1小时将问题列表发送给邮箱
+	task.AddTask("sendEmailFileForAskMsgResearch", sendEmailFileForAskMsgResearch)
+
+	sendEmailFileForAskMsg := task.NewTask("sendEmailFileForAskMsg", "0 */5 8-22 * * *", SendEmailFileForAskMsg) //非研选系列专家电话会,根据主持人姓名,会前15分钟将问题列表发送给至该主持人对应邮箱
+	task.AddTask("sendEmailFileForAskMsg", sendEmailFileForAskMsg)
+
 	////白名单发送
 	//sendEmailUserWhiteList := task.NewTask("sendEmailUserWhiteList", "0 27 17 * * *", SendEmailUserWhiteList) //白名单发送
 	//task.AddTask("sendEmailUserWhiteList", sendEmailUserWhiteList)

+ 56 - 45
services/user.go

@@ -670,29 +670,33 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	cellA := rowTitle.AddCell()
 	cellA.Value = "姓名"
 	cellB := rowTitle.AddCell()
-	cellB.Value = "手机号"
+	cellB.Value = "国际代码1"
 	cellC := rowTitle.AddCell()
-	cellC.Value = "国际代码"
+	cellC.Value = "手机号"
 	cellD := rowTitle.AddCell()
-	cellD.Value = "公司"
+	cellD.Value = "国际代码2"
 	cellE := rowTitle.AddCell()
-	cellE.Value = "职位"
+	cellE.Value = "备用号"
 	cellF := rowTitle.AddCell()
-	cellF.Value = "邮箱"
+	cellF.Value = "电子邮箱"
 	cellG := rowTitle.AddCell()
-	cellG.Value = "客户类型"
+	cellG.Value = "公司名称"
 	cellH := rowTitle.AddCell()
-	cellH.Value = "对口销售"
+	cellH.Value = "职位名称"
 	cellI := rowTitle.AddCell()
-	cellI.Value = "有效开始时间"
+	cellI.Value = "客户类型"
 	cellJ := rowTitle.AddCell()
-	cellJ.Value = "有效结束时间"
+	cellJ.Value = "对口销售"
 	cellK := rowTitle.AddCell()
 	cellK.Value = "归属部门"
 	cellL := rowTitle.AddCell()
-	cellL.Value = "备注"
+	cellL.Value = "有效开始时间"
 	cellM := rowTitle.AddCell()
-	cellM.Value = "权限(消费,医药,智造,科技,策略)"
+	cellM.Value = "有效结束时间"
+	cellN := rowTitle.AddCell()
+	cellN.Value = "备注"
+	cellO := rowTitle.AddCell()
+	cellO.Value = "权限(消费,医药,智造,科技,策略)"
 
 	if len(rep.List) > 0 {
 		for _, item := range rep.List {
@@ -700,35 +704,39 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 			cellA := row.AddCell()
 			cellA.Value = item.RealName
 			cellB := row.AddCell()
-			cellB.Value = item.Mobile
-			cellC := row.AddCell()
-			cellC.Value = item.CountryCode
+			cellB.Value = item.CountryCode
 			if len(item.Mobile) >= 11 && item.CountryCode == "" {
-				cellC.Value = "86"
+				cellB.Value = "86"
 			}
+			cellC := row.AddCell()
+			cellC.Value = item.Mobile
 			cellD := row.AddCell()
-			cellD.Value = item.CompanyName
+			cellD.Value = ""
 			cellE := row.AddCell()
 			cellE.Value = ""
 			cellF := row.AddCell()
 			cellF.Value = ""
 			cellG := row.AddCell()
-			cellG.Value = ""
+			cellG.Value = item.CompanyName
 			cellH := row.AddCell()
-			cellH.Value = item.SellerName
+			cellH.Value = ""
 			cellI := row.AddCell()
 			cellI.Value = ""
 			cellJ := row.AddCell()
-			cellJ.Value = ""
+			cellJ.Value = item.SellerName
 			cellK := row.AddCell()
 			cellK.Value = ""
 			cellL := row.AddCell()
 			cellL.Value = ""
 			cellM := row.AddCell()
+			cellM.Value = ""
+			cellN := row.AddCell()
+			cellN.Value = ""
+			cellO := row.AddCell()
 			if item.Permission == "" {
 				item.Permission = "专家/医药/智造/消费/研选/科技/策略/路演服务"
 			}
-			cellM.Value = item.Permission
+			cellO.Value = item.Permission
 		}
 	}
 	errFile = xlsxFile.Save(downLoadnFilePath)
@@ -773,29 +781,33 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	cellA = rowTitle.AddCell()
 	cellA.Value = "姓名"
 	cellB = rowTitle.AddCell()
-	cellB.Value = "手机号"
+	cellB.Value = "国际代码1"
 	cellC = rowTitle.AddCell()
-	cellC.Value = "国际代码"
+	cellC.Value = "手机号"
 	cellD = rowTitle.AddCell()
-	cellD.Value = "公司"
+	cellD.Value = "国际代码2"
 	cellE = rowTitle.AddCell()
-	cellE.Value = "职位"
+	cellE.Value = "备用号"
 	cellF = rowTitle.AddCell()
-	cellF.Value = "邮箱"
+	cellF.Value = "电子邮箱"
 	cellG = rowTitle.AddCell()
-	cellG.Value = "客户类型"
+	cellG.Value = "公司名称"
 	cellH = rowTitle.AddCell()
-	cellH.Value = "对口销售"
+	cellH.Value = "职位名称"
 	cellI = rowTitle.AddCell()
-	cellI.Value = "有效开始时间"
+	cellI.Value = "客户类型"
 	cellJ = rowTitle.AddCell()
-	cellJ.Value = "有效结束时间"
+	cellJ.Value = "对口销售"
 	cellK = rowTitle.AddCell()
 	cellK.Value = "归属部门"
 	cellL = rowTitle.AddCell()
-	cellL.Value = "备注"
+	cellL.Value = "有效开始时间"
 	cellM = rowTitle.AddCell()
-	cellM.Value = "权限(消费,医药,智造,科技,策略)"
+	cellM.Value = "有效结束时间"
+	cellN = rowTitle.AddCell()
+	cellN.Value = "备注"
+	cellO = rowTitle.AddCell()
+	cellO.Value = "权限(消费,医药,智造,科技,策略)"
 	//手机号冻结
 	listFrozen, err := models.GetFrozenUserWhiteList()                 //手机号用户修改
 	listFrozenOutbound, err := models.GetFrozenUserWhiteListOutbound() //外呼手机号用户修改
@@ -814,37 +826,36 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 			cellA := row.AddCell()
 			cellA.Value = item.RealName
 			cellB := row.AddCell()
-			if item.Mobile != "" {
-				cellB.Value = item.Mobile
-			} else {
-				cellB.Value = item.OutboundMobile
+			cellB.Value = item.CountryCode
+			if len(item.Mobile) >= 11 && item.CountryCode == "" {
+				cellB.Value = "86"
 			}
 			cellC := row.AddCell()
-			if item.CountryCode != "" {
-				cellC.Value = item.CountryCode
-			} else {
-				cellC.Value = item.OutboundCountryCode
-			}
+			cellC.Value = item.Mobile
 			cellD := row.AddCell()
-			cellD.Value = item.CompanyName
+			cellD.Value = ""
 			cellE := row.AddCell()
 			cellE.Value = ""
 			cellF := row.AddCell()
 			cellF.Value = ""
 			cellG := row.AddCell()
-			cellG.Value = ""
+			cellG.Value = item.CompanyName
 			cellH := row.AddCell()
-			cellH.Value = item.SellerName
+			cellH.Value = ""
 			cellI := row.AddCell()
 			cellI.Value = ""
 			cellJ := row.AddCell()
-			cellJ.Value = ""
+			cellJ.Value = item.SellerName
 			cellK := row.AddCell()
 			cellK.Value = ""
 			cellL := row.AddCell()
 			cellL.Value = ""
 			cellM := row.AddCell()
-			cellM.Value = item.PermissionName
+			cellM.Value = ""
+			cellN := row.AddCell()
+			cellN.Value = ""
+			cellO := row.AddCell()
+			cellO.Value = item.PermissionName
 		}
 	}
 	errFile = xlsxFile.Save(downLoadnFilePaths)