作者 Your Name
... ... @@ -2,15 +2,14 @@ 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"`
TimeStart string `cname:"起始时间" json:"timeStart"`
TimeEnd string `cname:"截至时间" json:"timeEnd"`
KpiCycle int `cname:"考核周期" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
}
... ... @@ -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,15 +2,14 @@ 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"`
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"`
}
... ... @@ -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,7 +2,6 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"time"
)
type UpdateProjectCommand struct {
... ... @@ -22,10 +21,10 @@ type UpdateProjectTemplateCommand struct {
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string"`
Recipients []string `cname:"被评估人ID" json:"recipients"`
TimeStart *time.Time `cname:"自评起始时间" json:"timeStart" valid:"Required"`
TimeEnd *time.Time `cname:"自评截止时间" json:"timeEnd" valid:"Required"`
TimeStart string `cname:"自评起始时间" json:"timeStart" valid:"Required"`
TimeEnd string `cname:"自评截止时间" json:"timeEnd" valid:"Required"`
KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"`
KpiResultStart *time.Time `cname:"绩效结果开始查看时间" json:"kpiResultStart"`
KpiResultStart string `cname:"绩效结果开始查看时间" json:"kpiResultStart"`
Activate int `cname:"启动项目" json:"activate"`
}
... ... @@ -48,4 +47,13 @@ func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation)
validation.SetError("recipients", "请添加被评估人")
return
}
if len(in.TimeStart) == 0 {
validation.SetError("timeEnd", "请选择开始时间")
return
}
if len(in.TimeEnd) == 0 {
validation.SetError("timeEnd", "请选择结束时间")
return
}
}
... ...
... ... @@ -9,6 +9,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"strconv"
"time"
)
type EvaluationProjectService struct {
... ... @@ -177,18 +178,31 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
project.State = domain.ProjectStateEnable
}
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())
}
kpiStart, err := time.ParseInLocation("2006-01-02 15:04:05", in.KpiResultStart, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
project.Recipients = in.Recipients
project.Template = cycleTemplate.Template
for i := range project.Template.LinkNodes {
node := project.Template.LinkNodes[i]
node.KpiCycle = in.KpiCycle // 设置周期
if node.Type == domain.LinkNodeViewResult {
if in.KpiResultStart != nil {
node.TimeStart = in.KpiResultStart
if len(in.KpiResultStart) > 0 {
node.TimeStart = &kpiStart
}
} else {
node.TimeStart = in.TimeStart
node.TimeEnd = in.TimeEnd
node.TimeStart = &start
node.TimeEnd = &end
}
}
... ... @@ -404,5 +418,5 @@ func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCo
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return repeatNum, nil
return map[string]interface{}{"repeatNum": repeatNum}, nil
}
... ...
... ... @@ -2,14 +2,13 @@ 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"`
CreatedAt string `cname:"创建时间" json:"createdAt"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
... ...
... ... @@ -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") // 删除创建时间
}
... ...
... ... @@ -119,7 +119,7 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{})
query := tx.Model(&m).Where("deleted_at isnull")
if v, ok := queryOptions["name"]; ok && len(v.(string)) > 0 {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name LIKE ?", v)
}
... ... @@ -170,7 +170,7 @@ func (repo *EvaluationCycleRepository) Count(queryOptions map[string]interface{}
query.Where("id != ?", notId)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
... ... @@ -186,7 +186,7 @@ func (repo *EvaluationCycleTemplateRepository) Count(queryOptions map[string]int
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
... ... @@ -131,7 +131,7 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{
query.ExcludeColumn(excludeColumns...)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ... @@ -192,7 +192,7 @@ func (repo *EvaluationProjectRepository) Count(queryOptions map[string]interface
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
... ... @@ -127,7 +127,7 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
query.Where("id in(?)", pg.In(v))
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ... @@ -176,7 +176,7 @@ func (repo *EvaluationRuleRepository) Count(queryOptions map[string]interface{})
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
... ... @@ -129,7 +129,7 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok && len(v.(string)) > 0 {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name LIKE ?", v)
}
... ... @@ -142,13 +142,16 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
}
if v, ok := queryOptions["createdAt"]; ok {
t := v.(*time.Time)
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 {
query.Limit(int(v))
... ... @@ -183,7 +186,7 @@ func (repo *EvaluationTemplateRepository) Count(queryOptions map[string]interfac
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
... ... @@ -113,8 +113,8 @@ func (repo *RoleRepository) Find(queryOptions map[string]interface{}) (int64, []
var m []*models.Role
query := tx.Model(&m).Where("deleted_at isnull")
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
... ... @@ -154,8 +154,8 @@ func (repo *RoleRepository) Count(queryOptions map[string]interface{}) (int64, e
query.Where("id != ?", notId)
}
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
... ...
... ... @@ -161,8 +161,8 @@ func (repo *RoleUserRepository) Count(queryOptions map[string]interface{}) (int6
query.Where("id != ?", notId)
}
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
... ...
... ... @@ -116,7 +116,7 @@ func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*d
if v, ok := queryOptions["account"]; ok {
query.Where("account like ?", v)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name like ?", fmt.Sprintf("%%%v%%", v))
}
if v, ok := queryOptions["offset"]; ok {
... ...