作者 郑周

格式格式化

... ... @@ -2,17 +2,16 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"time"
)
type CreateCycleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"周期名称" json:"name" valid:"Required"`
TimeStart *time.Time `cname:"起始时间" json:"timeStart"`
TimeEnd *time.Time `cname:"截至时间" json:"timeEnd"`
KpiCycle int `cname:"考核周期" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"周期名称" json:"name" valid:"Required"`
TimeStart string `cname:"起始时间" json:"timeStart"`
TimeEnd string `cname:"截至时间" json:"timeEnd"`
KpiCycle int `cname:"考核周期" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
}
func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
... ... @@ -33,11 +32,11 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
return
}
if in.TimeStart == nil {
if len(in.TimeStart) == 0 {
validation.SetError("timeStart", "请选择考核周期的开始时间")
return
}
if in.TimeEnd == nil {
if len(in.TimeEnd) == 0 {
validation.SetError("timeEnd", "请选择考核周期的结束时间")
return
}
... ...
... ... @@ -2,17 +2,16 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"time"
)
type UpdateCycleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
Id int64 `cname:"周期ID" json:"id,string" valid:"Required"`
Name string `cname:"周期名称" json:"name" valid:"Required"`
TimeStart *time.Time `cname:"起始时间" json:"timeStart"`
TimeEnd *time.Time `cname:"截至时间" json:"timeEnd"`
KpiCycle int `cname:"考核周期(0日、1周、2月)" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
Id int64 `cname:"周期ID" json:"id,string" valid:"Required"`
Name string `cname:"周期名称" json:"name" valid:"Required"`
TimeStart string `cname:"起始时间" json:"timeStart"`
TimeEnd string `cname:"截至时间" json:"timeEnd"`
KpiCycle int `cname:"考核周期(0日、1周、2月)" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
}
func (in *UpdateCycleCommand) Valid(validation *validation.Validation) {
... ... @@ -20,11 +19,11 @@ func (in *UpdateCycleCommand) Valid(validation *validation.Validation) {
validation.SetError("name", "角色名称最大长度40个字符")
return
}
if in.TimeStart == nil {
if len(in.TimeStart) == 0 {
validation.SetError("timeStart", "请选择考核周期的开始时间")
return
}
if in.TimeEnd == nil {
if len(in.TimeEnd) == 0 {
validation.SetError("timeEnd", "请选择考核周期的结束时间")
return
}
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"strconv"
"time"
)
type EvaluationCycleService struct {
... ... @@ -49,12 +50,21 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择")
}
start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 生成新周期数据
newCycle := &domain.EvaluationCycle{
Id: 0,
Name: in.Name,
TimeStart: in.TimeStart,
TimeEnd: in.TimeEnd,
TimeStart: &start,
TimeEnd: &end,
CompanyId: in.CompanyId,
CreatorId: in.CreatorId,
KpiCycle: in.KpiCycle,
... ... @@ -210,9 +220,18 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
}
}
start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local)
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.TimeStart = &start
cycle.TimeEnd = &end
cycle.KpiCycle = in.KpiCycle
cycle, err = cycleRepository.Insert(cycle)
if err != nil {
... ...
... ... @@ -2,16 +2,15 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"time"
)
type QueryTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"模板名称" json:"name"`
State int `cname:"模板状态" json:"state"`
CreatedAt *time.Time `cname:"创建时间" json:"createdAt"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"模板名称" json:"name"`
State int `cname:"模板状态" json:"state"`
CreatedAt string `cname:"创建时间" json:"createdAt"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -190,7 +190,7 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int
}()
queryOptions := tool_funs.SimpleStructToMap(in)
if in.CreatedAt == nil {
if len(in.CreatedAt) == 0 {
delete(queryOptions, "createdAt") // 删除创建时间
}
... ...
... ... @@ -142,12 +142,15 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
}
if v, ok := queryOptions["createdAt"]; ok {
t := v.(*time.Time)
year, month, day := t.Date()
begin := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
end := time.Date(year, month, day, 23, 59, 59, 0, time.Local)
query.Where("created_at >= ?", begin)
query.Where("created_at <= ?", end)
ts := v.(string)
t, err := time.ParseInLocation("2006-01-02", ts, time.Local)
if err == nil {
year, month, day := t.Date()
begin := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
end := time.Date(year, month, day, 23, 59, 59, 0, time.Local)
query.Where("created_at >= ?", begin)
query.Where("created_at <= ?", end)
}
}
if v, ok := queryOptions["limit"].(int64); ok {
... ...