作者 郑周

优化分页

周期接口调试
... ... @@ -19,8 +19,7 @@ type CycleTemplateListCommand struct {
}
type CycleTemplateCommand struct {
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string" valid:"Required"`
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
}
func (in *QueryCycleCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -321,6 +321,10 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface
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 tool_funs.SimpleWrapGridMap(total, cycles), nil
}
... ... @@ -333,7 +337,7 @@ func (rs *EvaluationCycleService) StatisticCycleUser(in *command.StatisticCycleP
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
_, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -347,8 +351,8 @@ func (rs *EvaluationCycleService) StatisticCycleUser(in *command.StatisticCycleP
userIdMap[userId] = userId
}
}
for _, v := range userIdMap {
userIds = append(userIds, v)
for k := range userIdMap {
userIds = append(userIds, k)
}
userTotal := 0
... ... @@ -412,7 +416,7 @@ func (rs *EvaluationCycleService) CycleTemplate(in *command.CycleTemplateCommand
}()
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId})
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -132,7 +132,7 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "linkNodes")
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -271,7 +271,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
total, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
total, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -371,7 +371,7 @@ func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCo
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "linkNodes")
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -34,7 +34,7 @@ func (rs *RoleUserService) Create(in *command.UserRoleCreateCommand) (interface{
// int64Array = append(int64Array, int64Num)
//}
// 检测已存在的关联用户
_, rus, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.RoleId, "companyId": in.CompanyId, "userIds": in.UserIds, "limit": 9999999})
_, rus, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.RoleId, "companyId": in.CompanyId, "userIds": in.UserIds, "limit": int64(9999999)})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -127,11 +127,11 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{})
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
if v, ok := queryOptions["timeStart"]; ok {
... ...
... ... @@ -153,11 +153,11 @@ func (repo *EvaluationCycleTemplateRepository) Find(queryOptions map[string]inte
query.Where("cycle_id = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
count, err := query.SelectAndCount()
... ...
... ... @@ -159,11 +159,11 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{
}
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
count, err := query.SelectAndCount()
... ...
... ... @@ -143,11 +143,11 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
query.Where("type = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
count, err := query.SelectAndCount()
... ...
... ... @@ -150,11 +150,11 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
query.Where("created_at <= ?", end)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
count, err := query.SelectAndCount()
... ...
... ... @@ -121,11 +121,11 @@ func (repo *RoleRepository) Find(queryOptions map[string]interface{}) (int64, []
query.Where("company_id = ?", companyId)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
count, err := query.SelectAndCount()
... ...
... ... @@ -128,11 +128,11 @@ func (repo *RoleUserRepository) Find(queryOptions map[string]interface{}) (int64
query.Where("user_id in (?)", pg.In(userIds))
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
count, err := query.SelectAndCount()
... ...
... ... @@ -99,9 +99,10 @@ func (controller *CycleController) CycleTemplateList() {
func (controller *CycleController) CycleTemplate() {
ruService := service.NewEvaluationCycleService()
in := &command.CycleTemplateCommand{}
if err := controller.Unmarshal(in); err != nil {
if id, err := controller.GetInt64(":Id"); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.Id = id
controller.Response(ruService.CycleTemplate(in))
}
}
... ...
... ... @@ -17,6 +17,7 @@ func init() {
web.NSRouter("/list", &controllers.CycleController{}, "Post:ListCycle"),
web.NSRouter("/statistic", &controllers.CycleController{}, "Post:StatisticCycleUser"),
web.NSRouter("/templates", &controllers.CycleController{}, "Post:CycleTemplateList"),
web.NSRouter("/template/:Id", &controllers.CycleController{}, "Get:CycleTemplate"),
)
web.AddNamespace(ns)
}
... ...