作者 郑周

1.周期模型 业务逻辑编写

package adapter
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type CycleTemplateAdapter struct {
*domain.EvaluationCycle
TemplateSimples []*domain.TemplateSimple `json:"templates" comment:"模板"`
}
... ...
... ... @@ -3,9 +3,10 @@ package command
import "github.com/beego/beego/v2/core/validation"
type QueryCycleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"周期名称" json:"name"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryCycleCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -3,10 +3,12 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_cycle/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"strconv"
)
type EvaluationCycleService struct {
... ... @@ -27,6 +29,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
transactionContext.RollbackTransaction()
}()
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复
... ... @@ -54,16 +57,30 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
CompanyId: in.CompanyId,
CreatorId: in.CreatorId,
KpiCycle: in.KpiCycle,
Templates: templates,
}
rule, err := cycleRepository.Insert(newCycle)
cycle, err := cycleRepository.Insert(newCycle)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range templates {
v := templates[i]
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
Template: v,
CycleId: cycle.Id,
}
_, err := cycleTemplateRepository.Insert(cycleTemplate)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return rule, nil
return cycle, nil
}
... ... @@ -77,6 +94,7 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
}()
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复(排除自己)
... ... @@ -93,19 +111,58 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, templates, err := templateRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "ids": in.TemplateIds})
_, oldCycleTemplates, err := cycleTemplateRepository.Find(map[string]interface{}{"cycleId": cycle.Id}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(templates) == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择")
// 当前周期的所有模板数据
oldTemplateMap := map[int64]*domain.EvaluationCycleTemplate{}
for i := range oldCycleTemplates {
oldTemplateMap[oldCycleTemplates[i].Id] = oldCycleTemplates[i]
}
// 拆离新旧模板Id
newTemplateIds := make([]int64, 0)
for i := range in.TemplateIds {
int64Id, _ := strconv.ParseInt(in.TemplateIds[i], 10, 64)
if _, ok := oldTemplateMap[int64Id]; ok {
delete(oldTemplateMap, int64Id) // 旧模板继续被引用
} else {
newTemplateIds = append(newTemplateIds, int64Id) // 增加新模板ID
}
}
// 旧模板未被引用,则进行删除处理
for k := range oldTemplateMap {
_, err := cycleTemplateRepository.Remove(oldTemplateMap[k])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
// 增加新模板数据
if len(newTemplateIds) > 0 {
_, templates, err := templateRepository.Find(map[string]interface{}{"companyId": cycle.CompanyId, "ids": newTemplateIds})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range templates {
v := templates[i]
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
Template: v,
CycleId: cycle.Id,
}
_, err := cycleTemplateRepository.Insert(cycleTemplate)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
cycle.Name = in.Name
cycle.TimeStart = in.TimeStart
cycle.TimeEnd = in.TimeEnd
cycle.KpiCycle = in.KpiCycle
cycle.Templates = templates
cycle, err = cycleRepository.Insert(cycle)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -126,11 +183,28 @@ func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{},
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return cycle, nil
_, cycleTemplates, err := cycleTemplateRepository.Find(map[string]interface{}{"cycleId": cycle.Id}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
ctAdapter := &adapter.CycleTemplateAdapter{}
ctAdapter.EvaluationCycle = cycle
for i := range cycleTemplates {
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplates[i].Id,
Name: cycleTemplates[i].Name,
CreatedAt: cycleTemplates[i].CreatedAt,
})
}
return ctAdapter, nil
}
func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interface{}, error) {
... ... @@ -143,6 +217,7 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf
}()
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
... ... @@ -152,6 +227,11 @@ func (rs *EvaluationCycleService) Remove(in *command.DeleteCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// FIXME 删除周期关联的所有模板... 还需要删除关联的定时内容
if err := cycleTemplateRepository.BatchDeleteByCycleId(cycle.Id); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -167,8 +247,12 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface
transactionContext.RollbackTransaction()
}()
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
inMap := tool_funs.SimpleStructToMap(in)
if len(in.Name) > 0 {
inMap["name"] = "%" + in.Name + "%"
}
// FIXME 总数量是否使用Count获取一个总数量
count, cycles, err := cycleRepository.Find(tool_funs.SimpleStructToMap(in), "templates")
count, cycles, err := cycleRepository.Find(inMap)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -105,6 +105,14 @@ func CreateEvaluationCycleRepository(options map[string]interface{}) domain.Eval
return repository.NewEvaluationCycleRepository(transactionContext)
}
func CreateEvaluationCycleTemplateRepository(options map[string]interface{}) domain.EvaluationCycleTemplateRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewEvaluationCycleTemplateRepository(transactionContext)
}
func CreateEvaluationProjectRepository(options map[string]interface{}) domain.EvaluationProjectRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
... ...
... ... @@ -4,24 +4,29 @@ import (
"time"
)
type TemplateSimple struct {
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
}
type EvaluationCycle struct {
Id int64 `json:"id,string" comment:"ID"`
Name string `json:"name" comment:"名称"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"`
Templates []*EvaluationTemplate `json:"templates" comment:"周期使用模板"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
Id int64 `json:"id,string" comment:"ID"`
Name string `json:"name" comment:"名称"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
KpiCycle int `json:"state" comment:"考核周期(0日、1周、2月)"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
type EvaluationCycleRepository interface {
Insert(cycle *EvaluationCycle) (*EvaluationCycle, error)
Remove(cycle *EvaluationCycle) (*EvaluationCycle, error)
FindOne(queryOptions map[string]interface{}) (*EvaluationCycle, error)
Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*EvaluationCycle, error)
Find(queryOptions map[string]interface{}) (int64, []*EvaluationCycle, error)
Count(queryOptions map[string]interface{}) (int64, error)
}
... ...
package domain
import (
"time"
)
type EvaluationCycleTemplate struct {
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
Template *EvaluationTemplate `json:"template" comment:"模板数据"`
CycleId int64 `json:"cycleId,string" comment:"周期ID"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
type EvaluationCycleTemplateRepository interface {
Insert(cycle *EvaluationCycleTemplate) (*EvaluationCycleTemplate, error)
Remove(cycle *EvaluationCycleTemplate) (*EvaluationCycleTemplate, error)
FindOne(queryOptions map[string]interface{}) (*EvaluationCycleTemplate, error)
Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*EvaluationCycleTemplate, error)
Count(queryOptions map[string]interface{}) (int64, error)
BatchDeleteByCycleId(cycleId int64) error
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"time"
)
type EvaluationCycle struct {
tableName struct{} `pg:"evaluation_cycle" comment:"评估周期"`
Id int64 `pg:"pk:id" comment:"周期ID"`
Name string `comment:"名称"`
TimeStart *time.Time `comment:"起始时间"`
TimeEnd *time.Time `comment:"截至时间"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
KpiCycle int `comment:"考核周期(0日、1周、2月)"`
Templates []*domain.EvaluationTemplate `comment:"周期使用模板"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
tableName struct{} `pg:"evaluation_cycle" comment:"评估周期"`
Id int64 `pg:"pk:id" comment:"周期ID"`
Name string `comment:"名称"`
TimeStart *time.Time `comment:"起始时间"`
TimeEnd *time.Time `comment:"截至时间"`
CompanyId int64 `comment:"公司ID"`
CreatorId int64 `comment:"创建人ID"`
KpiCycle int `comment:"考核周期(0日、1周、2月)"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"time"
)
type EvaluationCycleTemplate struct {
tableName struct{} `pg:"evaluation_cycle_template" comment:"评估周期模板"`
Id int64 `pg:"pk:id" comment:"模板ID"`
Name string `comment:"模板名称"`
Template *domain.EvaluationTemplate `comment:"模板数据"`
CycleId int64 `comment:"周期ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
... ... @@ -29,7 +29,6 @@ func (repo *EvaluationCycleRepository) TransformToDomain(m *models.EvaluationCyc
CompanyId: m.CompanyId,
CreatorId: m.CreatorId,
KpiCycle: m.KpiCycle,
Templates: m.Templates,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: m.DeletedAt,
... ... @@ -45,7 +44,6 @@ func (repo *EvaluationCycleRepository) TransformToModel(d *domain.EvaluationCycl
CompanyId: d.CompanyId,
CreatorId: d.CreatorId,
KpiCycle: d.KpiCycle,
Templates: d.Templates,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
... ... @@ -114,23 +112,18 @@ func (repo *EvaluationCycleRepository) FindOne(queryOptions map[string]interface
return &u, nil
}
func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*domain.EvaluationCycle, error) {
func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.EvaluationCycle, error) {
tx := repo.transactionContext.PgTx
var m []*models.EvaluationCycle
// 排除掉保存模板的列[templates], 减少数据赋值
query := tx.Model(&m).Where("deleted_at isnull").Limit(20)
query := tx.Model(&m).Where("deleted_at isnull")
if len(excludeColumns) > 0 {
query.ExcludeColumn(excludeColumns...)
if v, ok := queryOptions["name"]; ok && len(v.(string)) > 0 {
query.Where("name LIKE ?", v)
}
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
... ... @@ -166,12 +159,12 @@ func (repo *EvaluationCycleRepository) Count(queryOptions map[string]interface{}
query.Where("id != ?", notId)
}
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
count, err := query.Count()
... ...
package repository
import (
"errors"
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"time"
)
type EvaluationCycleTemplateRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func NewEvaluationCycleTemplateRepository(transactionContext *pgTransaction.TransactionContext) *EvaluationCycleTemplateRepository {
return &EvaluationCycleTemplateRepository{transactionContext: transactionContext}
}
func (repo *EvaluationCycleTemplateRepository) TransformToDomain(m *models.EvaluationCycleTemplate) domain.EvaluationCycleTemplate {
return domain.EvaluationCycleTemplate{
Id: m.Id,
Name: m.Name,
Template: m.Template,
CycleId: m.CycleId,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: m.DeletedAt,
}
}
func (repo *EvaluationCycleTemplateRepository) TransformToModel(d *domain.EvaluationCycleTemplate) models.EvaluationCycleTemplate {
return models.EvaluationCycleTemplate{
Id: d.Id,
Name: d.Name,
Template: d.Template,
CycleId: d.CycleId,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
}
}
func (repo *EvaluationCycleTemplateRepository) nextIdentify() (int64, error) {
return utils.NewSnowflakeId()
}
func (repo *EvaluationCycleTemplateRepository) Insert(d *domain.EvaluationCycleTemplate) (*domain.EvaluationCycleTemplate, error) {
var isCreate = d.Id == 0
if isCreate {
id, err := repo.nextIdentify()
if err != nil {
return d, err
}
d.Id = id
d.CreatedAt = time.Now()
d.UpdatedAt = d.CreatedAt
} else {
d.UpdatedAt = time.Now()
}
m := repo.TransformToModel(d)
tx := repo.transactionContext.PgTx
var err error
if isCreate {
_, err = tx.Model(&m).Returning("id").Insert()
} else {
_, err = tx.Model(&m).Returning("id").WherePK().Update() // 更新和删除必须增加条件
}
if err != nil {
return nil, err
}
d.Id = m.Id
return d, nil
}
func (repo *EvaluationCycleTemplateRepository) Remove(d *domain.EvaluationCycleTemplate) (*domain.EvaluationCycleTemplate, error) {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
m := repo.TransformToModel(d)
m.DeletedAt = &nowTime
if _, err := tx.Model(&m).WherePK().Update(); err != nil {
return d, err
}
return d, nil
}
func (repo *EvaluationCycleTemplateRepository) BatchDeleteByCycleId(cycleId int64) error {
tx := repo.transactionContext.PgTx
_, err := tx.Model(&models.EvaluationCycleTemplate{}).Where("cycle_id = ?", cycleId).Delete()
return err
}
func (repo *EvaluationCycleTemplateRepository) FindOne(queryOptions map[string]interface{}) (*domain.EvaluationCycleTemplate, error) {
tx := repo.transactionContext.PgTx
m := new(models.EvaluationCycleTemplate)
query := tx.Model(m)
// 包含删除项
if _, ok := queryOptions["includeDeleted"]; ok {
} else {
query.Where("deleted_at isnull")
}
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
u := repo.TransformToDomain(m)
return &u, nil
}
func (repo *EvaluationCycleTemplateRepository) Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*domain.EvaluationCycleTemplate, error) {
tx := repo.transactionContext.PgTx
var m []*models.EvaluationCycleTemplate
query := tx.Model(&m)
// 包含删除项
if _, ok := queryOptions["includeDeleted"]; ok {
} else {
query.Where("deleted_at isnull")
}
// 排除掉保存模板的列[template], 减少数据赋值
if len(excludeColumns) > 0 {
query.ExcludeColumn(excludeColumns...)
}
if v, ok := queryOptions["ids"]; ok {
query.Where("id in(?)", pg.In(v))
}
if v, ok := queryOptions["id"]; ok {
query.Where("id = ?", v)
}
if v, ok := queryOptions["cycleId"]; ok {
query.Where("cycle_id = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var arrays []*domain.EvaluationCycleTemplate
for _, v := range m {
d := repo.TransformToDomain(v)
arrays = append(arrays, &d)
}
return int64(count), arrays, nil
}
func (repo *EvaluationCycleTemplateRepository) Count(queryOptions map[string]interface{}) (int64, error) {
tx := repo.transactionContext.PgTx
m := new(models.EvaluationCycleTemplate)
query := sqlbuilder.BuildQuery(tx.Model(m), queryOptions)
query.Where("deleted_at isnull")
if v, ok := queryOptions["id"]; ok {
query.Where("id = ?", v)
}
if v, ok := queryOptions["notId"]; ok {
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
count, err := query.Count()
if err != nil {
return 0, err
}
return int64(count), nil
}
... ...
... ... @@ -119,16 +119,14 @@ func (repo *EvaluationProjectRepository) FindOne(queryOptions map[string]interfa
func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.EvaluationProject, error) {
tx := repo.transactionContext.PgTx
var m []*models.EvaluationProject
query := tx.Model(&m).
Where("deleted_at isnull").
Limit(20)
query := tx.Model(&m).Where("deleted_at isnull")
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
... ... @@ -156,20 +154,20 @@ func (repo *EvaluationProjectRepository) Count(queryOptions map[string]interface
query := sqlbuilder.BuildQuery(tx.Model(m), queryOptions)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id = ?", id)
if v, ok := queryOptions["id"]; ok {
query.Where("id = ?", v)
}
if notId, ok := queryOptions["notId"]; ok {
query.Where("id != ?", notId)
if v, ok := queryOptions["notId"]; ok {
query.Where("id != ?", v)
}
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
count, err := query.Count()
... ...
... ... @@ -117,18 +117,18 @@ func (repo *EvaluationRuleRepository) FindOne(queryOptions map[string]interface{
func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.EvaluationRule, error) {
tx := repo.transactionContext.PgTx
var m []*models.EvaluationRule
query := tx.Model(&m).Where("deleted_at isnull").Limit(20)
query := tx.Model(&m).Where("deleted_at isnull")
if nameOrRemark, ok := queryOptions["nameOrRemark"]; ok && len(nameOrRemark.(string)) > 0 {
query.Where("name LIKE ? or remark LIKE ?", nameOrRemark, nameOrRemark)
if v, ok := queryOptions["nameOrRemark"]; ok && len(v.(string)) > 0 {
query.Where("name LIKE ? or remark LIKE ?", v, v)
}
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
... ... @@ -138,7 +138,6 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
query.Offset(v)
}
query.Count()
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ... @@ -157,20 +156,20 @@ func (repo *EvaluationRuleRepository) Count(queryOptions map[string]interface{})
query := sqlbuilder.BuildQuery(tx.Model(m), queryOptions)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id = ?", id)
if v, ok := queryOptions["id"]; ok {
query.Where("id = ?", v)
}
if notId, ok := queryOptions["notId"]; ok {
query.Where("id != ?", notId)
if v, ok := queryOptions["notId"]; ok {
query.Where("id != ?", v)
}
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
count, err := query.Count()
... ...
... ... @@ -115,9 +115,7 @@ func (repo *EvaluationTemplateRepository) FindOne(queryOptions map[string]interf
func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*domain.EvaluationTemplate, error) {
tx := repo.transactionContext.PgTx
var m []*models.EvaluationTemplate
query := tx.Model(&m).
Where("deleted_at isnull").
Limit(20)
query := tx.Model(&m).Where("deleted_at isnull")
if len(excludeColumns) > 0 {
query.ExcludeColumn(excludeColumns...)
... ... @@ -127,16 +125,16 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
query.Where("id in(?)", pg.In(v))
}
if name, ok := queryOptions["name"]; ok && len(name.(string)) > 0 {
query.Where("name LIKE ?", name)
if v, ok := queryOptions["name"]; ok && len(v.(string)) > 0 {
query.Where("name LIKE ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
if state, ok := queryOptions["state"]; ok {
query.Where("state = ?", state)
if v, ok := queryOptions["state"]; ok {
query.Where("state = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
... ... @@ -164,24 +162,24 @@ func (repo *EvaluationTemplateRepository) Count(queryOptions map[string]interfac
query := sqlbuilder.BuildQuery(tx.Model(m), queryOptions)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id = ?", id)
if v, ok := queryOptions["id"]; ok {
query.Where("id = ?", v)
}
if notId, ok := queryOptions["notId"]; ok {
query.Where("id != ?", notId)
if v, ok := queryOptions["notId"]; ok {
query.Where("id != ?", v)
}
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
if state, ok := queryOptions["state"]; ok {
query.Where("state = ?", state)
if v, ok := queryOptions["state"]; ok {
query.Where("state = ?", v)
}
count, err := query.Count()
... ...
... ... @@ -111,9 +111,7 @@ func (repo *RoleRepository) FindOne(queryOptions map[string]interface{}) (*domai
func (repo *RoleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Role, error) {
tx := repo.transactionContext.PgTx
var m []*models.Role
query := tx.Model(&m).
Where("deleted_at isnull").
Limit(20)
query := tx.Model(&m).Where("deleted_at isnull")
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
... ...