From 83f622663235d5b77d3f3cf53d455485de656871 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Thu, 5 Sep 2024 20:06:22 +0800 Subject: [PATCH 1/2] update --- src/dao/generate_wx_ad_data_dao.go | 5 -- src/super/dao/master_data_statistics_dao.go | 13 ++++ .../master_data_statistics_implement.go | 62 +++++++++++++++++++ src/super/model/master_data_statistics.go | 21 +++++++ 4 files changed, 96 insertions(+), 5 deletions(-) delete mode 100644 src/dao/generate_wx_ad_data_dao.go create mode 100644 src/super/dao/master_data_statistics_dao.go create mode 100644 src/super/implement/master_data_statistics_implement.go create mode 100644 src/super/model/master_data_statistics.go diff --git a/src/dao/generate_wx_ad_data_dao.go b/src/dao/generate_wx_ad_data_dao.go deleted file mode 100644 index c6ee26b..0000000 --- a/src/dao/generate_wx_ad_data_dao.go +++ /dev/null @@ -1,5 +0,0 @@ -package dao - -type GenerateWxAdDataDao interface { - //TODO:: You can add specific method definitions here -} diff --git a/src/super/dao/master_data_statistics_dao.go b/src/super/dao/master_data_statistics_dao.go new file mode 100644 index 0000000..366f825 --- /dev/null +++ b/src/super/dao/master_data_statistics_dao.go @@ -0,0 +1,13 @@ +package dao + +import ( + "code.fnuoos.com/zhimeng/model.git/src/super/model" + "xorm.io/xorm" +) + +type MasterDataStatisticsDao interface { + GetMasterDataStatistics(uuid int, date string) (data *model.MasterDataStatistics, err error) + UpdateMasterDataStatistics(m *model.MasterDataStatistics, columns ...string) (int64, error) + UpdateMasterDataStatisticsBySession(session *xorm.Session, m *model.MasterDataStatistics, columns ...string) (int64, error) + FindMasterDataStatisticsList(uuid, startDate, endDate string, page, limit int) (list []model.MasterDataStatistics, total int64, err error) +} diff --git a/src/super/implement/master_data_statistics_implement.go b/src/super/implement/master_data_statistics_implement.go new file mode 100644 index 0000000..b573f80 --- /dev/null +++ b/src/super/implement/master_data_statistics_implement.go @@ -0,0 +1,62 @@ +package implement + +import ( + "code.fnuoos.com/zhimeng/model.git/src/super/dao" + "code.fnuoos.com/zhimeng/model.git/src/super/model" + zhios_order_relate_logx "code.fnuoos.com/zhimeng/model.git/utils/logx" + "xorm.io/xorm" +) + +func NewMasterDataStatisticsDb(engine *xorm.Engine) dao.MasterDataStatisticsDao { + return &MasterDataStatisticsDb{Db: engine} +} + +type MasterDataStatisticsDb struct { + Db *xorm.Engine +} + +func (m MasterDataStatisticsDb) GetMasterDataStatistics(uuid int, date string) (data *model.MasterDataStatistics, err error) { + data = new(model.MasterDataStatistics) + has, err := m.Db.Where("uuid =? and date =?", uuid, date).Get(data) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return data, nil +} + +func (m MasterDataStatisticsDb) UpdateMasterDataStatistics(mm *model.MasterDataStatistics, columns ...string) (int64, error) { + affected, err := m.Db.Where("id =?", mm.Id).Cols(columns...).Update(mm) + if err != nil { + return 0, err + } + return affected, nil +} + +func (m MasterDataStatisticsDb) UpdateMasterDataStatisticsBySession(session *xorm.Session, mm *model.MasterDataStatistics, columns ...string) (int64, error) { + affected, err := session.Where("id =?", mm.Id).Cols(columns...).Update(mm) + if err != nil { + return 0, err + } + return affected, nil +} + +func (m MasterDataStatisticsDb) FindMasterDataStatisticsList(uuid, startDate, endDate string, page, limit int) (list []model.MasterDataStatistics, total int64, err error) { + sess := m.Db.OrderBy("date desc,id desc").Limit(limit, (page-1)*limit) + if uuid != "" { + sess.And("uuid = ?", uuid) + } + if startDate != "" { + sess.And("date>=", startDate) + } + if endDate != "" { + sess.And("date<=", endDate) + } + total, err = sess.FindAndCount(&list) + if err != nil { + return nil, 0, err + } + return +} diff --git a/src/super/model/master_data_statistics.go b/src/super/model/master_data_statistics.go new file mode 100644 index 0000000..a23f73b --- /dev/null +++ b/src/super/model/master_data_statistics.go @@ -0,0 +1,21 @@ +package model + +type MasterDataStatistics struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Uuid int `json:"uuid" xorm:"not null default 0 comment('站长id') index INT(11)"` + TodayIncome int `json:"today_income" xorm:"not null default 0 comment('今日收益(分)') INT(11)"` + SevenDayIncome int `json:"seven_day_income" xorm:"not null default 0 comment('七日收益(分)') INT(11)"` + ThisMonthIncome int `json:"this_month_income" xorm:"not null default 0 comment('本月收益(分)') INT(11)"` + LastMonthIncome int `json:"last_month_income" xorm:"not null default 0 comment('上月收益(分)') INT(11)"` + MediumTodayIncome int `json:"medium_today_income" xorm:"not null default 0 comment('媒体今日收益(分)') INT(11)"` + MediumSevenDayIncome int `json:"medium_seven_day_income" xorm:"not null default 0 comment('媒体七日收益(分)') INT(11)"` + MediumThisMonthIncome int `json:"medium_this_month_income" xorm:"not null default 0 comment('媒体本月收益(分)') INT(11)"` + MediumLastMonthIncome int `json:"medium_last_month_income" xorm:"not null default 0 comment('媒体上月收益(分)') INT(11)"` + MediumTodayExposureCount int `json:"medium_today_exposure_count" xorm:"not null default 0 comment('媒体今日曝光量') INT(11)"` + MediumSevenDayExposureCount int `json:"medium_seven_day_exposure_count" xorm:"not null default 0 comment('媒体七日曝光量') INT(11)"` + MediumThisMonthExposureCount int `json:"medium_this_month_exposure_count" xorm:"not null default 0 comment('媒体本月曝光量') INT(11)"` + MediumLastMonthExposureCount int `json:"medium_last_month_exposure_count" xorm:"not null default 0 comment('媒体上月曝光量') INT(11)"` + Date string `json:"date" xorm:"not null comment('日期') DATE"` + CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` +} From a065b68a46f8f2132842d343de79550f7d76eeac Mon Sep 17 00:00:00 2001 From: dengbiao Date: Thu, 12 Sep 2024 17:30:53 +0800 Subject: [PATCH 2/2] 1 --- src/db.go | 3 ++- src/super/dao/master_data_statistics_dao.go | 1 + src/super/implement/master_data_statistics_implement.go | 8 ++++++++ src/super/model/master_data_statistics.go | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/db.go b/src/db.go index 00630e8..ab04e26 100644 --- a/src/db.go +++ b/src/db.go @@ -16,8 +16,9 @@ import ( var Db *xorm.Engine -//根据DB配置文件初始化数据库 +// 根据DB配置文件初始化数据库 func InitDB(c *cfg.DBCfg) error { + fmt.Println("db host::::", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4", c.User, c.Psw, c.Host, c.Name)) var ( err error f *os.File diff --git a/src/super/dao/master_data_statistics_dao.go b/src/super/dao/master_data_statistics_dao.go index 366f825..f8077ef 100644 --- a/src/super/dao/master_data_statistics_dao.go +++ b/src/super/dao/master_data_statistics_dao.go @@ -10,4 +10,5 @@ type MasterDataStatisticsDao interface { UpdateMasterDataStatistics(m *model.MasterDataStatistics, columns ...string) (int64, error) UpdateMasterDataStatisticsBySession(session *xorm.Session, m *model.MasterDataStatistics, columns ...string) (int64, error) FindMasterDataStatisticsList(uuid, startDate, endDate string, page, limit int) (list []model.MasterDataStatistics, total int64, err error) + MasterDataStatisticsInsert(m *model.MasterDataStatistics) (int64, error) } diff --git a/src/super/implement/master_data_statistics_implement.go b/src/super/implement/master_data_statistics_implement.go index b573f80..06a7cc4 100644 --- a/src/super/implement/master_data_statistics_implement.go +++ b/src/super/implement/master_data_statistics_implement.go @@ -15,6 +15,14 @@ type MasterDataStatisticsDb struct { Db *xorm.Engine } +func (m MasterDataStatisticsDb) MasterDataStatisticsInsert(mm *model.MasterDataStatistics) (int64, error) { + insertAffected, err := m.Db.InsertOne(m) + if err != nil { + return 0, err + } + return insertAffected, nil +} + func (m MasterDataStatisticsDb) GetMasterDataStatistics(uuid int, date string) (data *model.MasterDataStatistics, err error) { data = new(model.MasterDataStatistics) has, err := m.Db.Where("uuid =? and date =?", uuid, date).Get(data) diff --git a/src/super/model/master_data_statistics.go b/src/super/model/master_data_statistics.go index a23f73b..758d09b 100644 --- a/src/super/model/master_data_statistics.go +++ b/src/super/model/master_data_statistics.go @@ -11,6 +11,10 @@ type MasterDataStatistics struct { MediumSevenDayIncome int `json:"medium_seven_day_income" xorm:"not null default 0 comment('媒体七日收益(分)') INT(11)"` MediumThisMonthIncome int `json:"medium_this_month_income" xorm:"not null default 0 comment('媒体本月收益(分)') INT(11)"` MediumLastMonthIncome int `json:"medium_last_month_income" xorm:"not null default 0 comment('媒体上月收益(分)') INT(11)"` + AgentTodayIncome int `json:"agent_today_income" xorm:"not null default 0 comment('代理今日收益(分)') INT(11)"` + AgentSevenDayIncome int `json:"agent_seven_day_income" xorm:"not null default 0 comment('代理七日收益(分)') INT(11)"` + AgentThisMonthIncome int `json:"agent_this_month_income" xorm:"not null default 0 comment('代理本月收益(分)') INT(11)"` + AgentLastMonthIncome int `json:"agent_last_month_income" xorm:"not null default 0 comment('代理上月收益(分)') INT(11)"` MediumTodayExposureCount int `json:"medium_today_exposure_count" xorm:"not null default 0 comment('媒体今日曝光量') INT(11)"` MediumSevenDayExposureCount int `json:"medium_seven_day_exposure_count" xorm:"not null default 0 comment('媒体七日曝光量') INT(11)"` MediumThisMonthExposureCount int `json:"medium_this_month_exposure_count" xorm:"not null default 0 comment('媒体本月曝光量') INT(11)"`