...
|
...
|
@@ -120,7 +120,7 @@ func (repository *ArticleTemplateRepository) Find(ctx context.Context, conn tran |
|
|
total int64
|
|
|
)
|
|
|
queryFunc := func() (interface{}, error) {
|
|
|
tx = tx.Model(&ms).Order("id desc")
|
|
|
tx = tx.Model(&ms).Order("id asc")
|
|
|
if v, ok := queryOptions["companyId"]; ok {
|
|
|
tx.Where("company_id = ? ", v)
|
|
|
}
|
...
|
...
|
@@ -133,8 +133,48 @@ func (repository *ArticleTemplateRepository) Find(ctx context.Context, conn tran |
|
|
if v, ok := queryOptions["templateClass"]; ok {
|
|
|
tx.Where("template_class = ? ", v)
|
|
|
}
|
|
|
if v, ok := queryOptions["target"]; ok {
|
|
|
tx.Where("target_who_read = ? ", v)
|
|
|
//if v, ok := queryOptions["target"]; ok {
|
|
|
// tx.Where("target_who_read = ? ", v)
|
|
|
//}
|
|
|
if v, ok := queryOptions["targetUser"]; ok {
|
|
|
tx.Where(`id in (select a.id from (
|
|
|
select id,json_array_elements_text(who_read::json)::integer user_id from article_template
|
|
|
) a where a.user_id in(
|
|
|
select id from "user" where name like ?
|
|
|
))`, fmt.Sprintf("%%%v%%", v))
|
|
|
}
|
|
|
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
|
|
|
return dms, tx.Error
|
|
|
}
|
|
|
return dms, nil
|
|
|
}
|
|
|
|
|
|
if _, err := repository.Query(queryFunc); err != nil {
|
|
|
return 0, nil, err
|
|
|
}
|
|
|
|
|
|
for _, item := range ms {
|
|
|
if dm, err := repository.ModelToDomainModel(item); err != nil {
|
|
|
return 0, dms, err
|
|
|
} else {
|
|
|
dms = append(dms, dm)
|
|
|
}
|
|
|
}
|
|
|
return total, dms, nil
|
|
|
}
|
|
|
|
|
|
func (repository *ArticleTemplateRepository) FindCompanyUnscoped(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.ArticleTemplate, error) {
|
|
|
var (
|
|
|
tx = conn.DB()
|
|
|
ms []*models.ArticleTemplate
|
|
|
dms = make([]*domain.ArticleTemplate, 0)
|
|
|
total int64
|
|
|
)
|
|
|
queryFunc := func() (interface{}, error) {
|
|
|
tx = tx.Model(&ms).Unscoped()
|
|
|
tx.Where("company_id = ? ", companyId)
|
|
|
if v, ok := queryOptions["templateClass"]; ok {
|
|
|
tx.Where("template_class = ? ", v)
|
|
|
}
|
|
|
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
|
|
|
return dms, tx.Error
|
...
|
...
|
|