优化错误提示
This commit is contained in:
parent
7c83e5c87d
commit
457bf15a0f
BIN
iniDataForLinux
BIN
iniDataForLinux
Binary file not shown.
BIN
iniDataForMacOs
BIN
iniDataForMacOs
Binary file not shown.
130
main.go
130
main.go
@ -53,7 +53,6 @@ func init() {
|
|||||||
applogger.Info(fmt.Sprintf("程序启动,加载%s环境,尝试执行...", env))
|
applogger.Info(fmt.Sprintf("程序启动,加载%s环境,尝试执行...", env))
|
||||||
go downloadDecompression() // 启动立即执行一次数据下载、处理
|
go downloadDecompression() // 启动立即执行一次数据下载、处理
|
||||||
go queryBatchState()
|
go queryBatchState()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -436,78 +435,75 @@ func downloadDecompression() {
|
|||||||
|
|
||||||
func batchInsert(fileName string, isLastCall bool, excludedFilename string) int {
|
func batchInsert(fileName string, isLastCall bool, excludedFilename string) int {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
db, _ := connectToDB()
|
db, err := connectToDB()
|
||||||
|
handleError(err, "连接数据库失败")
|
||||||
|
|
||||||
file, err := os.Open(path.Join(executableDir, txtPath, fileName))
|
file, err := os.Open(path.Join(executableDir, txtPath, fileName))
|
||||||
if err != nil {
|
handleError(err, fmt.Sprintf("打开文件失败: %s", fileName))
|
||||||
return -1
|
defer file.Close()
|
||||||
} else {
|
|
||||||
defer file.Close()
|
|
||||||
reader := csv.NewReader(bufio.NewReader(file))
|
|
||||||
reader.Read()
|
|
||||||
batchRows := 0
|
|
||||||
for {
|
|
||||||
record, err := reader.Read()
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
TargetsMember, _ := strconv.ParseUint(strings.TrimSpace(record[2]), 10, 32)
|
reader := csv.NewReader(bufio.NewReader(file))
|
||||||
templateID, _ := strconv.ParseUint(strings.TrimSpace(record[3]), 10, 32)
|
reader.Read()
|
||||||
status := 1
|
batchRows := 0
|
||||||
|
for {
|
||||||
t := time.Now()
|
record, err := reader.Read()
|
||||||
s := t.Format("2006-01-02 15:04:05")
|
if err != nil {
|
||||||
var batchName, dataFileName string
|
break
|
||||||
|
|
||||||
if isLastCall {
|
|
||||||
batchName = fmt.Sprintf("lastCall-%s-%s-%s", record[1], record[0], excludedFilename)
|
|
||||||
dataFileName = fmt.Sprintf("lastCall-%s", excludedFilename)
|
|
||||||
} else {
|
|
||||||
batchName = fmt.Sprintf("%s-%s", record[1], record[0])
|
|
||||||
dataFileName = fileName[:len(fileName)-10]
|
|
||||||
}
|
|
||||||
|
|
||||||
batchParams := BatchParams{
|
|
||||||
BatchName: batchName,
|
|
||||||
BatchDesc: record[4],
|
|
||||||
IsPersonal: 0,
|
|
||||||
Message: record[4],
|
|
||||||
IsInternational: 0,
|
|
||||||
IsSchedule: 0, //点发
|
|
||||||
ScheduleTime: s,
|
|
||||||
Token: token,
|
|
||||||
}
|
|
||||||
|
|
||||||
sid, err := CreateBatch(batchParams)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
batch := Batch{
|
|
||||||
CommunicationChannelID: record[0],
|
|
||||||
CommunicationName: batchName,
|
|
||||||
TargetsMember: uint(TargetsMember),
|
|
||||||
TemplateID: uint(templateID),
|
|
||||||
Content: record[4],
|
|
||||||
Status: status,
|
|
||||||
DataFileName: dataFileName,
|
|
||||||
Sid: sid,
|
|
||||||
}
|
|
||||||
db.Create(&batch)
|
|
||||||
batchRows++
|
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second)
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
|
|
||||||
subject := "丝芙兰批次文件处理完成"
|
TargetsMember, _ := strconv.ParseUint(strings.TrimSpace(record[2]), 10, 32)
|
||||||
body := fmt.Sprintf("批次数:%d;\n批次文件:%s;\n处理完成,请前往管理平台查看处理。", batchRows, fileName)
|
templateID, _ := strconv.ParseUint(strings.TrimSpace(record[3]), 10, 32)
|
||||||
SendEmail(subject, body)
|
status := 1
|
||||||
|
|
||||||
applogger.Info(fmt.Sprintf("%s(批次文件)入库完成", fileName))
|
s := time.Now().Format("2006-01-02 15:04:05")
|
||||||
applogger.Info(fmt.Sprintf("%s(批次文件)执行时间%s 插入批次次数:%d", fileName, elapsed, batchRows))
|
var batchName, dataFileName string
|
||||||
return 0
|
|
||||||
|
if isLastCall {
|
||||||
|
batchName = fmt.Sprintf("lastCall-%s-%s-%s", record[1], record[0], excludedFilename)
|
||||||
|
dataFileName = fmt.Sprintf("lastCall-%s", excludedFilename)
|
||||||
|
} else {
|
||||||
|
batchName = fmt.Sprintf("%s-%s", record[1], record[0])
|
||||||
|
dataFileName = fileName[:len(fileName)-10]
|
||||||
|
}
|
||||||
|
|
||||||
|
batchParams := BatchParams{
|
||||||
|
BatchName: batchName,
|
||||||
|
BatchDesc: record[4],
|
||||||
|
IsPersonal: 0,
|
||||||
|
Message: record[4],
|
||||||
|
IsInternational: 0,
|
||||||
|
IsSchedule: 0,
|
||||||
|
ScheduleTime: s,
|
||||||
|
Token: token,
|
||||||
|
}
|
||||||
|
|
||||||
|
sid, err := CreateBatch(batchParams)
|
||||||
|
handleError(err, "创建批次失败")
|
||||||
|
|
||||||
|
batch := Batch{
|
||||||
|
CommunicationChannelID: record[0],
|
||||||
|
CommunicationName: batchName,
|
||||||
|
TargetsMember: uint(TargetsMember),
|
||||||
|
TemplateID: uint(templateID),
|
||||||
|
Content: record[4],
|
||||||
|
Status: status,
|
||||||
|
DataFileName: dataFileName,
|
||||||
|
Sid: sid,
|
||||||
|
}
|
||||||
|
db.Create(&batch)
|
||||||
|
batchRows++
|
||||||
}
|
}
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
elapsed := time.Since(start)
|
||||||
|
|
||||||
|
subject := "丝芙兰批次文件处理完成"
|
||||||
|
body := fmt.Sprintf("批次数:%d;\n批次文件:%s;\n处理完成,请前往管理平台查看处理。", batchRows, fileName)
|
||||||
|
SendEmail(subject, body)
|
||||||
|
|
||||||
|
applogger.Info(fmt.Sprintf("%s(批次文件)入库完成", fileName))
|
||||||
|
applogger.Info(fmt.Sprintf("%s(批次文件)执行时间%s 插入批次次数:%d", fileName, elapsed, batchRows))
|
||||||
|
return 0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateBatch(batchParams BatchParams) (int, error) {
|
func CreateBatch(batchParams BatchParams) (int, error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user