You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
3.0 KiB
Go
150 lines
3.0 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"joybuywork/internal/consts/ckey"
|
|
"joybuywork/internal/repository/cache"
|
|
"joybuywork/internal/repository/model"
|
|
"joybuywork/internal/repository/mtype"
|
|
"joybuywork/internal/repository/withdefault"
|
|
"joybuywork/internal/utils/lockdo"
|
|
"joybuywork/internal/utils/logic"
|
|
"joybuywork/internal/utils/merr"
|
|
)
|
|
|
|
type FissionConfig struct {
|
|
logic.Context
|
|
|
|
project *model.Project
|
|
|
|
conf *model.FissionConfig
|
|
}
|
|
|
|
func NewFissionConfig(ctx context.Context, project *model.Project) (conf *FissionConfig, err error) {
|
|
conf = &FissionConfig{
|
|
project: project,
|
|
}
|
|
|
|
conf.BaseInit(ctx, merr.NewBE(ctx))
|
|
|
|
err = conf._init()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *FissionConfig) _init() (err error) {
|
|
return lockdo.FindNilDo(
|
|
s.Ctx,
|
|
ckey.FissionConfigOnce(s.project.ID),
|
|
func() (none bool, err error) {
|
|
s.conf, err = cache.NewFissionConfig(s.Ctx).FindByProjectId(s.project.ID)
|
|
if err != nil {
|
|
err = s.BE().CacheError(err)
|
|
return
|
|
}
|
|
|
|
return s.conf == nil, nil
|
|
|
|
},
|
|
func() (err error) {
|
|
s.conf = withdefault.FissionConfig(&model.FissionConfig{
|
|
ProjectID: s.project.ID,
|
|
})
|
|
|
|
if err = s.GetDao().FissionConfig.WithContext(s.Ctx).Create(s.conf); err != nil {
|
|
return s.BE().MysqlError(err)
|
|
}
|
|
return
|
|
},
|
|
)
|
|
}
|
|
|
|
func (s *FissionConfig) Config() (conf *model.FissionConfig) {
|
|
return s.conf
|
|
}
|
|
|
|
func (s *FissionConfig) SetPushCampaignTask(pv int32) (err error) {
|
|
conf := s.Config()
|
|
|
|
if conf.PushCampaignTask == int8(pv) {
|
|
return
|
|
}
|
|
|
|
m := s.GetDao().FissionConfig
|
|
_, err = m.WithContext(s.Ctx).Where(m.ID.Eq(conf.ID)).UpdateSimple(m.PushCampaignTask.Value(int8(pv)))
|
|
if err != nil {
|
|
err = s.BE().MysqlError(err)
|
|
return
|
|
}
|
|
|
|
_ = cache.NewFissionConfig(s.Ctx).Clear(conf)
|
|
|
|
return
|
|
}
|
|
|
|
func (s *FissionConfig) SetPushVisit(pv int32) (err error) {
|
|
conf := s.Config()
|
|
|
|
if conf.PushVisit == int8(pv) {
|
|
return
|
|
}
|
|
|
|
m := s.GetDao().FissionConfig
|
|
_, err = m.WithContext(s.Ctx).Where(m.ID.Eq(conf.ID)).UpdateSimple(m.PushVisit.Value(int8(pv)))
|
|
if err != nil {
|
|
err = s.BE().MysqlError(err)
|
|
return
|
|
}
|
|
|
|
_ = cache.NewFissionConfig(s.Ctx).Clear(conf)
|
|
|
|
return
|
|
}
|
|
|
|
func (s *FissionConfig) GetLvUrl() (url *model.NotifyURL, err error) {
|
|
conf := s.Config()
|
|
|
|
if conf.LvURLID == 0 || !s._canDo() {
|
|
return
|
|
}
|
|
|
|
url, err = cache.NewNotifyURL(s.Ctx).FindById(conf.LvURLID)
|
|
if err != nil {
|
|
err = s.BE().CacheError(err)
|
|
return
|
|
}
|
|
|
|
if url.IsDel == mtype.Yes {
|
|
return nil, nil
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *FissionConfig) SetLvUrl(urlId int64) (err error) {
|
|
conf := s.Config()
|
|
|
|
if conf.LvURLID == urlId || !s._canDo() {
|
|
return
|
|
}
|
|
|
|
m := s.GetDao().FissionConfig
|
|
_, err = m.WithContext(s.Ctx).Where(m.ID.Eq(conf.ID)).UpdateSimple(m.LvURLID.Value(urlId))
|
|
if err != nil {
|
|
err = s.BE().MysqlError(err)
|
|
return
|
|
}
|
|
|
|
_ = cache.NewFissionConfig(s.Ctx).Clear(conf)
|
|
|
|
return
|
|
}
|
|
|
|
func (s *FissionConfig) _canDo() bool {
|
|
status, _ := NewCompanyMade(s.Ctx, s.project.CompanyID, logic.WithDao(s.GetDao())).GetMade(mtype.CompanyMadeMarkLvApi)
|
|
return status.Open
|
|
}
|