优化错误提示

This commit is contained in:
chejiulong 2023-03-22 15:10:42 +08:00
parent 7c83e5c87d
commit 457bf15a0f
3 changed files with 63 additions and 67 deletions

Binary file not shown.

Binary file not shown.

22
main.go
View File

@ -53,7 +53,6 @@ func init() {
applogger.Info(fmt.Sprintf("程序启动,加载%s环境尝试执行...", env))
go downloadDecompression() // 启动立即执行一次数据下载、处理
go queryBatchState()
}
func main() {
@ -436,12 +435,13 @@ func downloadDecompression() {
func batchInsert(fileName string, isLastCall bool, excludedFilename string) int {
start := time.Now()
db, _ := connectToDB()
db, err := connectToDB()
handleError(err, "连接数据库失败")
file, err := os.Open(path.Join(executableDir, txtPath, fileName))
if err != nil {
return -1
} else {
handleError(err, fmt.Sprintf("打开文件失败: %s", fileName))
defer file.Close()
reader := csv.NewReader(bufio.NewReader(file))
reader.Read()
batchRows := 0
@ -455,8 +455,7 @@ func batchInsert(fileName string, isLastCall bool, excludedFilename string) int
templateID, _ := strconv.ParseUint(strings.TrimSpace(record[3]), 10, 32)
status := 1
t := time.Now()
s := t.Format("2006-01-02 15:04:05")
s := time.Now().Format("2006-01-02 15:04:05")
var batchName, dataFileName string
if isLastCall {
@ -473,16 +472,13 @@ func batchInsert(fileName string, isLastCall bool, excludedFilename string) int
IsPersonal: 0,
Message: record[4],
IsInternational: 0,
IsSchedule: 0, //点发
IsSchedule: 0,
ScheduleTime: s,
Token: token,
}
sid, err := CreateBatch(batchParams)
if err != nil {
fmt.Println(err)
return -1
}
handleError(err, "创建批次失败")
batch := Batch{
CommunicationChannelID: record[0],
@ -507,7 +503,7 @@ func batchInsert(fileName string, isLastCall bool, excludedFilename string) int
applogger.Info(fmt.Sprintf("%s批次文件入库完成", fileName))
applogger.Info(fmt.Sprintf("%s批次文件执行时间%s 插入批次次数:%d", fileName, elapsed, batchRows))
return 0
}
}
func CreateBatch(batchParams BatchParams) (int, error) {