“wwangchuanjin пре 5 година
родитељ
комит
dad3503bcf

+ 26 - 0
common/src/qfw/util/common.go

@@ -694,3 +694,29 @@ func XmlToMap(input string) map[string]string {
 	}
 	return m
 }
+
+func SimpleCrontab(flag bool, c string, f func()) {
+	array := strings.Split(c, ":")
+	if len(array) != 2 {
+		log.Fatalln("定时任务参数错误!", c)
+	}
+	if flag {
+		go f()
+	}
+	now := time.Now()
+	t := time.Date(now.Year(), now.Month(), now.Day(), IntAll(array[0]), IntAll(array[1]), 0, 0, time.Local)
+	if t.Before(now) {
+		t = t.AddDate(0, 0, 1)
+	}
+	sub := t.Sub(now)
+	log.Println(c, "run after", sub)
+	timer := time.NewTimer(sub)
+	for {
+		select {
+		case <-timer.C:
+			go f()
+			log.Println(c, "run after", 24*time.Hour)
+			timer.Reset(24 * time.Hour)
+		}
+	}
+}

+ 1 - 1
common/src/qfw/util/jy/entnichepush.go

@@ -4,9 +4,9 @@ import (
 	"encoding/json"
 	"fmt"
 	"log"
+	mg "qfw/mongodb"
 	. "qfw/util"
 	"qfw/util/elastic"
-	mg "qfw/util/mongodb"
 	"qfw/util/mysql"
 	"qfw/util/redis"
 	"strings"

+ 1 - 1
common/src/qfw/util/jy/subscribepush.go

@@ -4,9 +4,9 @@ import (
 	"encoding/json"
 	"fmt"
 	"log"
+	mg "qfw/mongodb"
 	. "qfw/util"
 	"qfw/util/elastic"
-	mg "qfw/util/mongodb"
 	"qfw/util/mysql"
 	"qfw/util/redis"
 	"strings"

+ 15 - 1
common/src/qfw/util/mysql/mysql.go

@@ -88,6 +88,16 @@ func (m *Mysql) InsertBySqlByTx(tx *sql.Tx, sql string, args ...interface{}) int
 	return id
 }
 
+//批量新增
+func (m *Mysql) InsertIgnoreBatch(tableName string, fields []string, values []interface{}) (int64, int64) {
+	return m.InsertIgnoreBatchByTx(nil, tableName, fields, values)
+}
+
+//带事务的批量新增
+func (m *Mysql) InsertIgnoreBatchByTx(tx *sql.Tx, tableName string, fields []string, values []interface{}) (int64, int64) {
+	return m.insertBatchByTx(tx, "IGNORE", tableName, fields, values)
+}
+
 //批量新增
 func (m *Mysql) InsertBatch(tableName string, fields []string, values []interface{}) (int64, int64) {
 	return m.InsertBatchByTx(nil, tableName, fields, values)
@@ -95,6 +105,10 @@ func (m *Mysql) InsertBatch(tableName string, fields []string, values []interfac
 
 //带事务的批量新增
 func (m *Mysql) InsertBatchByTx(tx *sql.Tx, tableName string, fields []string, values []interface{}) (int64, int64) {
+	return m.insertBatchByTx(tx, "", tableName, fields, values)
+}
+
+func (m *Mysql) insertBatchByTx(tx *sql.Tx, afterInsert, tableName string, fields []string, values []interface{}) (int64, int64) {
 	placeholders := []string{}
 	for range fields {
 		placeholders = append(placeholders, "?")
@@ -104,7 +118,7 @@ func (m *Mysql) InsertBatchByTx(tx *sql.Tx, tableName string, fields []string, v
 	for i := 0; i < len(values)/len(fields); i++ {
 		array = append(array, fmt.Sprintf("(%s)", placeholder))
 	}
-	q := fmt.Sprintf("INSERT INTO %s (%s) VALUES %s", tableName, strings.Join(fields, ","), strings.Join(array, ","))
+	q := fmt.Sprintf("INSERT %s INTO %s (%s) VALUES %s", afterInsert, tableName, strings.Join(fields, ","), strings.Join(array, ","))
 	result, _ := m.ExecBySqlByTx(tx, q, values...)
 	if result == nil {
 		return -1, -1