|
@@ -2,8 +2,11 @@ package services
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "github.com/tealeg/xlsx"
|
|
|
"hongze/hongze_cygx/models"
|
|
|
"hongze/hongze_cygx/utils"
|
|
|
+ "os"
|
|
|
+ "path/filepath"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -119,3 +122,119 @@ func SendActivityBeginMsgMeeting() (err error) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+//预约外呼名单,会前1小时自动发送邮件给专家组
|
|
|
+func SendEmailFileToExpert() (err error) {
|
|
|
+ var msg 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)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ fmt.Println("发送附件")
|
|
|
+ endDate := time.Now().Add(-time.Minute * 6000000).Format("2006-01-02 15:04:05")
|
|
|
+ total, err := models.GetCountActivityIdToSendFile(endDate)
|
|
|
+ if err != nil {
|
|
|
+ msg = "发送附件模版消息失败 Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if total == 0 {
|
|
|
+ fmt.Println("发送附件完成0")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ listActivity, err := models.GetActivityIdToSendFile(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.GetSignupExport(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) + ".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.Mobile
|
|
|
+ cellC := row.AddCell()
|
|
|
+ if item.CountryCode == "" {
|
|
|
+ cellC.Value = "86"
|
|
|
+ } else {
|
|
|
+ cellC.Value = item.CountryCode
|
|
|
+ }
|
|
|
+ cellD := row.AddCell()
|
|
|
+ cellD.Value = item.CompanyName
|
|
|
+ }
|
|
|
+ errFile = xlsxFile.Save(downLoadnFilePath)
|
|
|
+ if errFile != nil {
|
|
|
+ msg = "保存文件失败Err:" + errFile.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println(activityInfo.ActivityName)
|
|
|
+ title := activityInfo.ActivityName + "外呼名单"
|
|
|
+ content := "外呼名单详情"
|
|
|
+ fileName := downLoadnFilePath
|
|
|
+ touser := utils.EmailSendToExpert
|
|
|
+ go utils.SendEmailHaveFile(title, content, fileName, touser)
|
|
|
+ defer func() {
|
|
|
+ os.Remove(downLoadnFilePath)
|
|
|
+ }()
|
|
|
+ time.Sleep(time.Duration(2) * time.Second)
|
|
|
+ errFile = models.UPdateActivityIdToSendFile(v.ActivityId)
|
|
|
+ if errFile != nil {
|
|
|
+ msg = "获取失败,Err:" + errFile.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fmt.Println("发送附件完成")
|
|
|
+ return
|
|
|
+}
|