作者 tangxvhui

后台登录时检查/设置公司的初始数据

测试环境服务端域名 http://sumifcc-discuss-test.sumifcc.com/
\ No newline at end of file
... ...
... ... @@ -93,12 +93,70 @@ func (l *SystemUserInfoLogic) SystemUserInfo(req *types.SystemUserInfoRequest) (
}
}
}
err = l.initSystemData(companyId)
if err != nil {
return nil, err
}
return
}
// 后台登录时检查/设置公司的初始数据
// 后台登录时检查/设置公司的初始数据
func (l *SystemUserInfoLogic) initSystemData(companyId int64) error {
// TODO 初始设置文章标签
// 初始设置文章标签
queryOption := domain.NewQueryOptions().WithCountOnly()
conn := l.svcCtx.DefaultDBConn()
cnt, _, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, companyId, queryOption)
if err != nil {
return xerr.NewErrMsgErr("初始话公司数据失败", err)
}
if cnt == 0 {
articleTags := []*domain.ArticleTag{
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Name: "紧急重要", Category: "紧急重要", Remark: "优先解决", SortBy: 1,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Name: "不紧急不重要", Category: "紧急重要", Remark: "给别人做", SortBy: 2,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Name: "紧急不重要", Category: "紧急重要", Remark: "有空再做", SortBy: 3,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Name: "不紧急重要", Category: "紧急重要", Remark: "制定计划去做", SortBy: 4,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Name: "大机会高风险", Category: "机会风险", Remark: "谨慎考虑专项讨论", SortBy: 5,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Name: "大机会中风险", Category: "机会风险", Remark: "加大关注值得尝试", SortBy: 6,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Name: "大机会低风险", Category: "机会风险", Remark: "全员投入抓紧落实", SortBy: 7,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Name: "中机会高风险", Category: "机会风险", Remark: "专人跟踪成立项目", SortBy: 8,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Name: "中机会中风险", Category: "机会风险", Remark: "讨论落实", SortBy: 9,
},
{
Id: 0, CompanyId: companyId, Image: domain.Image{Url: "", Width: 0, Height: 0},
Name: "中机会低风险", Category: "机会风险", Remark: "解决问题多手准备", SortBy: 10,
},
}
err = l.svcCtx.ArticleTagRepository.CreateInBatches(l.ctx, conn, articleTags)
if err != nil {
return xerr.NewErrMsgErr("初始话公司数据失败", err)
}
}
return nil
}
... ...
... ... @@ -33,7 +33,28 @@ func (repository *ArticleTagRepository) Insert(ctx context.Context, conn transac
}
// func (repository *ArticleTagRepository) CreateInBatches
func (repository *ArticleTagRepository) CreateInBatches(ctx context.Context, conn transaction.Conn, dm []*domain.ArticleTag) error {
var (
ms = []*models.ArticleTag{}
tx = conn.DB()
)
for _, val := range dm {
m, err := repository.DomainModelToModel(val)
if err != nil {
return err
}
ms = append(ms, m)
}
if tx = tx.CreateInBatches(ms, 100); tx.Error != nil {
return tx.Error
}
for i, val := range ms {
dm[i].Id = val.Id
}
return nil
}
func (repository *ArticleTagRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.ArticleTag) (*domain.ArticleTag, error) {
var (
... ...
... ... @@ -24,6 +24,7 @@ type ArticleTag struct {
}
type ArticleTagRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
CreateInBatches(ctx context.Context, conn transaction.Conn, dm []*ArticleTag) error
Update(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
Delete(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
... ...