|
@@ -19,48 +19,48 @@ import (
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
-type ContractDao struct {
|
|
|
|
|
|
+type PersonnelDao struct {
|
|
table string
|
|
table string
|
|
group string
|
|
group string
|
|
}
|
|
}
|
|
|
|
|
|
-// NewContractDao creates and returns a new DAO object for table data access.
|
|
|
|
-func NewContractDao() *ContractDao {
|
|
|
|
- return &ContractDao{
|
|
|
|
|
|
+// NewPersonnelDao creates and returns a new DAO object for table data access.
|
|
|
|
+func NewPersonnelDao() *PersonnelDao {
|
|
|
|
+ return &PersonnelDao{
|
|
table: g.Cfg().MustGet(gctx.New(), "table").String(),
|
|
table: g.Cfg().MustGet(gctx.New(), "table").String(),
|
|
group: g.Cfg().MustGet(gctx.New(), "group").String(),
|
|
group: g.Cfg().MustGet(gctx.New(), "group").String(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// DB database management object of current DAO.
|
|
// DB database management object of current DAO.
|
|
-func (dao *ContractDao) DB() gdb.DB {
|
|
|
|
|
|
+func (dao *PersonnelDao) DB() gdb.DB {
|
|
log.Println(dao.group, "-------------")
|
|
log.Println(dao.group, "-------------")
|
|
return g.DB(dao.group)
|
|
return g.DB(dao.group)
|
|
}
|
|
}
|
|
|
|
|
|
// Table .
|
|
// Table .
|
|
-func (dao *ContractDao) Table(suffix string) string {
|
|
|
|
|
|
+func (dao *PersonnelDao) Table(suffix string) string {
|
|
return fmt.Sprintf("%s_%s", dao.table, suffix)
|
|
return fmt.Sprintf("%s_%s", dao.table, suffix)
|
|
}
|
|
}
|
|
|
|
|
|
// Group .
|
|
// Group .
|
|
-func (dao *ContractDao) Group(chainName string) string {
|
|
|
|
|
|
+func (dao *PersonnelDao) Group(chainName string) string {
|
|
if chainName != "" {
|
|
if chainName != "" {
|
|
return chainName
|
|
return chainName
|
|
}
|
|
}
|
|
return dao.group
|
|
return dao.group
|
|
}
|
|
}
|
|
|
|
|
|
-func (dao *ContractDao) Ctx(ctx context.Context) *gdb.Model {
|
|
|
|
|
|
+func (dao *PersonnelDao) Ctx(ctx context.Context) *gdb.Model {
|
|
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
|
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
|
}
|
|
}
|
|
|
|
|
|
-func (dao *ContractDao) CtxWithDatabase(ctx context.Context, database string) *gdb.Model {
|
|
|
|
|
|
+func (dao *PersonnelDao) CtxWithDatabase(ctx context.Context, database string) *gdb.Model {
|
|
return dao.DB().Model(database + "." + dao.table).Safe().Ctx(ctx)
|
|
return dao.DB().Model(database + "." + dao.table).Safe().Ctx(ctx)
|
|
}
|
|
}
|
|
|
|
|
|
// ExecInsert 保存行为记录
|
|
// ExecInsert 保存行为记录
|
|
-func (dao *ContractDao) ExecInsert(ctx context.Context, in model.ContractInsertInput, chainName string) (err error) {
|
|
|
|
|
|
+func (dao *PersonnelDao) ExecInsert(ctx context.Context, in model.PersonnelInsertInput, chainName string) (err error) {
|
|
var (
|
|
var (
|
|
dimSqlDML bytes.Buffer
|
|
dimSqlDML bytes.Buffer
|
|
now = time.Now()
|
|
now = time.Now()
|
|
@@ -68,10 +68,13 @@ func (dao *ContractDao) ExecInsert(ctx context.Context, in model.ContractInsertI
|
|
)
|
|
)
|
|
dimSqlDML.WriteString("insert into ")
|
|
dimSqlDML.WriteString("insert into ")
|
|
dimSqlDML.WriteString(dao.Group(chainName) + "." + dao.Table(ym))
|
|
dimSqlDML.WriteString(dao.Group(chainName) + "." + dao.Table(ym))
|
|
- dimSqlDML.WriteString(" (userid,create_time,phone,ip,platform,os,browser,position_id) values ( ")
|
|
|
|
|
|
+ dimSqlDML.WriteString(" (user_id,position_id,phone,ip,platform,os,os_version,browser," +
|
|
|
|
+ "browser_version,date,action_id,action_type,breaker_id,breaker_name,click_time,date,order_id," +
|
|
|
|
+ "order_time,pay_time,pay_way,price,product,product_name,page_id,page_name,bidding_id,desc," +
|
|
|
|
+ "url,source,user_agent) values ( ")
|
|
dimSqlDML.WriteString("'" + in.UserId + "'")
|
|
dimSqlDML.WriteString("'" + in.UserId + "'")
|
|
dimSqlDML.WriteString(",")
|
|
dimSqlDML.WriteString(",")
|
|
- dimSqlDML.WriteString("'" + date.FormatDate(&now, date.Date_Full_Layout) + "'")
|
|
|
|
|
|
+ dimSqlDML.WriteString(strconv.FormatInt(in.PositionId, 10))
|
|
dimSqlDML.WriteString(",")
|
|
dimSqlDML.WriteString(",")
|
|
dimSqlDML.WriteString("'" + in.Phone + "'")
|
|
dimSqlDML.WriteString("'" + in.Phone + "'")
|
|
dimSqlDML.WriteString(",")
|
|
dimSqlDML.WriteString(",")
|
|
@@ -81,9 +84,53 @@ func (dao *ContractDao) ExecInsert(ctx context.Context, in model.ContractInsertI
|
|
dimSqlDML.WriteString(",")
|
|
dimSqlDML.WriteString(",")
|
|
dimSqlDML.WriteString("'" + in.Os + "'")
|
|
dimSqlDML.WriteString("'" + in.Os + "'")
|
|
dimSqlDML.WriteString(",")
|
|
dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.OsVersion + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
dimSqlDML.WriteString("'" + in.Browser + "'")
|
|
dimSqlDML.WriteString("'" + in.Browser + "'")
|
|
dimSqlDML.WriteString(",")
|
|
dimSqlDML.WriteString(",")
|
|
- dimSqlDML.WriteString(strconv.FormatInt(in.PositionId, 10))
|
|
|
|
|
|
+ dimSqlDML.WriteString("'" + in.BrowserVersion + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + date.FormatDate(&now, date.Date_Full_Layout) + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.ActionId + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.ActionType + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.BreakerId + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.BreakerName + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + date.FormatDate(&now, date.Date_Full_Layout) + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + date.FormatDate(&now, date.Date_Full_Layout) + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.OrderId + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + date.FormatDate(&now, date.Date_Full_Layout) + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + date.FormatDate(&now, date.Date_Full_Layout) + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.PayWay + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString(strconv.FormatInt(in.Price, 10))
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.Product + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.ProductName + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.PageId + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.PageName + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.BiddingId + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.Desc + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.Url + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.Source + "'")
|
|
|
|
+ dimSqlDML.WriteString(",")
|
|
|
|
+ dimSqlDML.WriteString("'" + in.UserAgent + "'")
|
|
dimSqlDML.WriteString(")")
|
|
dimSqlDML.WriteString(")")
|
|
log.Println("insert sql :", dimSqlDML.String())
|
|
log.Println("insert sql :", dimSqlDML.String())
|
|
_, err = g.DB().Exec(ctx, dimSqlDML.String())
|
|
_, err = g.DB().Exec(ctx, dimSqlDML.String())
|
|
@@ -95,7 +142,7 @@ func (dao *ContractDao) ExecInsert(ctx context.Context, in model.ContractInsertI
|
|
}
|
|
}
|
|
|
|
|
|
// IsExists 当前表是否存在
|
|
// IsExists 当前表是否存在
|
|
-func (dao *ContractDao) IsExists(ctx context.Context, chainName string) (err error) {
|
|
|
|
|
|
+func (dao *PersonnelDao) IsExists(ctx context.Context, chainName string) (err error) {
|
|
var (
|
|
var (
|
|
ym = utils.GetYearMonth(0)
|
|
ym = utils.GetYearMonth(0)
|
|
isExistsTableSql = fmt.Sprintf(IsExistsTableSql, dao.Group(chainName), dao.Table(ym))
|
|
isExistsTableSql = fmt.Sprintf(IsExistsTableSql, dao.Group(chainName), dao.Table(ym))
|
|
@@ -118,7 +165,7 @@ func (dao *ContractDao) IsExists(ctx context.Context, chainName string) (err err
|
|
}
|
|
}
|
|
|
|
|
|
// UpdateRedis 更新redis表信息--无效
|
|
// UpdateRedis 更新redis表信息--无效
|
|
-func (dao *ContractDao) UpdateRedis(ctx context.Context, chainName string) (err error) {
|
|
|
|
|
|
+func (dao *PersonnelDao) UpdateRedis(ctx context.Context, chainName string) (err error) {
|
|
var (
|
|
var (
|
|
month = strconv.Itoa(int(time.Now().Month()))
|
|
month = strconv.Itoa(int(time.Now().Month()))
|
|
redisKey = fmt.Sprintf(RedisPersonnelTable, dao.Group(chainName), dao.Table(month))
|
|
redisKey = fmt.Sprintf(RedisPersonnelTable, dao.Group(chainName), dao.Table(month))
|
|
@@ -131,7 +178,7 @@ func (dao *ContractDao) UpdateRedis(ctx context.Context, chainName string) (err
|
|
}
|
|
}
|
|
|
|
|
|
// CreateTable 创建表
|
|
// CreateTable 创建表
|
|
-func (dao *ContractDao) CreateTable(ctx context.Context, chainName string) (err error) {
|
|
|
|
|
|
+func (dao *PersonnelDao) CreateTable(ctx context.Context, chainName string) (err error) {
|
|
var (
|
|
var (
|
|
ym = utils.GetYearMonth(0)
|
|
ym = utils.GetYearMonth(0)
|
|
createSql = fmt.Sprintf(PersonnelTable, dao.Group(chainName), dao.Table(ym))
|
|
createSql = fmt.Sprintf(PersonnelTable, dao.Group(chainName), dao.Table(ym))
|
|
@@ -152,7 +199,7 @@ func (dao *ContractDao) CreateTable(ctx context.Context, chainName string) (err
|
|
}
|
|
}
|
|
|
|
|
|
// DropTable 创建表
|
|
// DropTable 创建表
|
|
-func (dao *ContractDao) DropTable(ctx context.Context) (err error) {
|
|
|
|
|
|
+func (dao *PersonnelDao) DropTable(ctx context.Context) (err error) {
|
|
var (
|
|
var (
|
|
ym = utils.GetYearMonth(do.TaskConfig.DropTask.DataMonth)
|
|
ym = utils.GetYearMonth(do.TaskConfig.DropTask.DataMonth)
|
|
dropSql = fmt.Sprintf(DropTable, dao.Group(""), dao.Table(ym))
|
|
dropSql = fmt.Sprintf(DropTable, dao.Group(""), dao.Table(ym))
|