|
@@ -0,0 +1,138 @@
|
|
|
|
+package main
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "app.yhyue.com/moapp/jybase/mysql"
|
|
|
|
+ "context"
|
|
|
|
+ "fmt"
|
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
|
+ "regexp"
|
|
|
|
+ "strings"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+var Mysql *mysql.Mysql
|
|
|
|
+
|
|
|
|
+type config struct {
|
|
|
|
+ DbName string
|
|
|
|
+ Address string
|
|
|
|
+ UserName string
|
|
|
|
+ PassWord string
|
|
|
|
+ MaxOpenConns int
|
|
|
|
+ MaxIdleConns int
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func init() {
|
|
|
|
+ c := config{}
|
|
|
|
+ if err := g.Cfg().MustGet(context.Background(), "mysql").Structs(&c); err != nil {
|
|
|
|
+ panic(err)
|
|
|
|
+ }
|
|
|
|
+ Mysql = &mysql.Mysql{
|
|
|
|
+ Address: c.Address,
|
|
|
|
+ UserName: c.UserName,
|
|
|
|
+ PassWord: c.PassWord,
|
|
|
|
+ DBName: c.DbName,
|
|
|
|
+ MaxOpenConns: c.MaxOpenConns,
|
|
|
|
+ MaxIdleConns: c.MaxIdleConns,
|
|
|
|
+ }
|
|
|
|
+ Mysql.Init()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func main() {
|
|
|
|
+ //历史权益刷新
|
|
|
|
+ //flush_bigmember_service_marketAnalysis(context.Background())
|
|
|
|
+ //历史自定义大会员订单-权限刷新
|
|
|
|
+ flush_bigmember_order_marketAnalysis(context.Background())
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 大会员权益
|
|
|
|
+// <周报/月报/定制化市场分析报告> 拆分成 <周报/月报> + <定制化市场分析报告>
|
|
|
|
+// 10 = 10 +26
|
|
|
|
+func flush_bigmember_service_marketAnalysis(ctx context.Context) {
|
|
|
|
+ var total, insertCount int64 = 0, 0
|
|
|
|
+ Mysql.Select(100, func(l *[]map[string]interface{}) bool {
|
|
|
|
+ var fields = []string{"s_userid", "s_serviceid", "l_starttime", "l_endtime", "i_status", "l_createtime", "l_updatetime", "s_smainid"}
|
|
|
|
+ var val []interface{}
|
|
|
|
+ for _, m := range *l {
|
|
|
|
+ var vt []interface{}
|
|
|
|
+ for _, filed := range fields {
|
|
|
|
+ if filed == "s_serviceid" {
|
|
|
|
+ vt = append(vt, 26)
|
|
|
|
+ } else {
|
|
|
|
+ vt = append(vt, m[filed])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ val = append(val, vt...)
|
|
|
|
+ total++
|
|
|
|
+ }
|
|
|
|
+ if len(val) > 0 {
|
|
|
|
+ addRow, _ := Mysql.InsertBatch("bigmember_service_user_test", fields, val)
|
|
|
|
+ insertCount += addRow
|
|
|
|
+ }
|
|
|
|
+ return true
|
|
|
|
+ }, nil, "SELECT * FROM bigmember_service_user where i_status !=-1 and s_serviceid=10")
|
|
|
|
+ if total == insertCount {
|
|
|
|
+ g.Log().Infof(ctx, "插入成功,共插入%d条数据", total)
|
|
|
|
+ } else {
|
|
|
|
+ g.Log().Errorf(ctx, "共%d条,实际插入%d条", total, insertCount)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func flush_bigmember_order_marketAnalysis(ctx context.Context) {
|
|
|
|
+ var total, insertCount int64 = 0, 0
|
|
|
|
+ Mysql.Select(100, func(l *[]map[string]interface{}) bool {
|
|
|
|
+ var val [][]interface{}
|
|
|
|
+ var fields = []string{"id", "filter"}
|
|
|
|
+ for _, m := range *l {
|
|
|
|
+ id := gconv.Int64(m["id"])
|
|
|
|
+ filterStr := gconv.String(m["filter"])
|
|
|
|
+ newFilter := replaceServiceName(replaceServiceId(filterStr))
|
|
|
|
+ if newFilter != "" {
|
|
|
|
+ total++
|
|
|
|
+ val = append(val, []interface{}{id, newFilter})
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if len(val) > 0 {
|
|
|
|
+ addRow := Mysql.UpdateBathByTx(nil, "dataexport_order_wky", fields, val)
|
|
|
|
+ insertCount += addRow
|
|
|
|
+ }
|
|
|
|
+ return true
|
|
|
|
+ }, nil, "SELECT id,filter FROM dataexport_order_wky WHERE product_type='大会员' order by id desc")
|
|
|
|
+ if total == insertCount {
|
|
|
|
+ g.Log().Infof(ctx, "插入成功,更新%d条数据", total)
|
|
|
|
+ } else {
|
|
|
|
+ g.Log().Errorf(ctx, "共%d条,实际更新%d条", total, insertCount)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func replaceServiceId(data string) (newData string) {
|
|
|
|
+ if data == "" {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ re := regexp.MustCompile(`"serversId":"(.*?)"`)
|
|
|
|
+ matchArr, newVal := re.FindStringSubmatch(data), ""
|
|
|
|
+ if len(matchArr) == 2 && strings.Index(matchArr[1], "10") > -1 {
|
|
|
|
+ newVal = strings.ReplaceAll(matchArr[1], "10", "10,26")
|
|
|
|
+ }
|
|
|
|
+ if newVal != "" {
|
|
|
|
+ newData = re.ReplaceAllString(data, fmt.Sprintf(`"serversId":"%s"`, newVal))
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func replaceServiceName(data string) (newData string) {
|
|
|
|
+ if data == "" {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ re := regexp.MustCompile(`"serversName":"(.*?)"`)
|
|
|
|
+ matchArr, newVal := re.FindStringSubmatch(data), ""
|
|
|
|
+ if len(matchArr) == 2 && strings.Index(matchArr[1], "周报/月报/定制化市场分析报告") > -1 {
|
|
|
|
+ newVal = strings.ReplaceAll(matchArr[1], "周报/月报/定制化市场分析报告", "周报/月报,定制化市场分析报告")
|
|
|
|
+ }
|
|
|
|
+ if newVal != "" {
|
|
|
|
+ newData = re.ReplaceAllString(data, fmt.Sprintf(`"serversId":"%s"`, newVal))
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|