作者 Your Name

Merge branch 'test' into dev-tangxvhui

正在显示 31 个修改的文件 包含 666 行增加296 行删除
... ... @@ -11,7 +11,7 @@ type CreateCycleCommand struct {
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"`
KpiCycle int `cname:"考核周期" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
}
... ...
... ... @@ -9,9 +9,35 @@ type QueryCycleCommand struct {
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
}
type StatisticCycleProjectUserCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string"`
}
type CycleTemplateListCommand struct {
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
}
type CycleTemplateCommand struct {
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string" valid:"Required"`
}
func (in *QueryCycleCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
}
func (in *StatisticCycleProjectUserCommand) Valid(*validation.Validation) {
}
func (in *CycleTemplateListCommand) Valid(*validation.Validation) {
}
func (in *CycleTemplateCommand) Valid(*validation.Validation) {
}
... ...
... ... @@ -30,6 +30,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (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})
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复
count, err := cycleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
... ... @@ -48,6 +49,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择")
}
// 生成新周期数据
newCycle := &domain.EvaluationCycle{
Id: 0,
Name: in.Name,
... ... @@ -62,24 +64,65 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取所有模板中的规则对象数据
ruleIds := make([]int64, 0)
ruleMap := map[int64]*domain.EvaluationRule{}
for i := range templates {
v := templates[i]
for j := range v.LinkNodes {
node := v.LinkNodes[j]
for k := range node.NodeContents {
nodeContent := node.NodeContents[k]
ruleIds = append(ruleIds, nodeContent.RuleId)
}
}
}
_, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId})
for i := range rules {
ruleMap[rules[i].Id] = rules[i]
}
ctAdapter := &adapter.CycleTemplateAdapter{}
ctAdapter.EvaluationCycle = cycle
for i := range templates {
v := templates[i]
// 对评估模板中的评估规则进行数据赋值
for j := range v.LinkNodes {
node := v.LinkNodes[j]
for k := range node.NodeContents {
nodeContent := node.NodeContents[k]
if rule, ok := ruleMap[nodeContent.RuleId]; ok {
nodeContent.Rule = rule
}
}
}
// 周期模板数据表中插入数据
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
Template: v,
CycleId: cycle.Id,
Id: 0,
Name: v.Name,
TemplateCreatedAt: v.CreatedAt,
Template: v,
CycleId: cycle.Id,
}
_, err := cycleTemplateRepository.Insert(cycleTemplate)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 输出模板简单信息
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplate.Id,
Name: cycleTemplate.Name,
CreatedAt: cycleTemplate.TemplateCreatedAt, // 模板创建时间
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cycle, nil
return ctAdapter, nil
}
... ... @@ -146,10 +189,11 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
for i := range templates {
v := templates[i]
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
Template: v,
CycleId: cycle.Id,
Id: 0,
Name: v.Name,
TemplateCreatedAt: v.CreatedAt,
Template: v,
CycleId: cycle.Id,
}
_, err := cycleTemplateRepository.Insert(cycleTemplate)
if err != nil {
... ... @@ -166,10 +210,26 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, 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].TemplateCreatedAt,
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cycle, nil
return ctAdapter, nil
}
func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{}, error) {
... ... @@ -199,7 +259,7 @@ func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{},
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplates[i].Id,
Name: cycleTemplates[i].Name,
CreatedAt: cycleTemplates[i].CreatedAt,
CreatedAt: cycleTemplates[i].TemplateCreatedAt,
})
}
... ... @@ -255,3 +315,101 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface
}
return tool_funs.SimpleWrapGridMap(total, cycles), nil
}
func (rs *EvaluationCycleService) StatisticCycleUser(in *command.StatisticCycleProjectUserCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userIds := make([]int64, 0)
userIdMap := map[int64]int64{}
for i := range projects {
project := projects[i]
for j := range project.Recipients {
userId, _ := strconv.ParseInt(project.Recipients[j], 10, 64)
userIdMap[userId] = userId
}
}
for _, v := range userIdMap {
userIds = append(userIds, v)
}
userTotal := 0
departmentTotal := 0
if len(userIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": userIds, "limit": len(userIds)})
departmentIdMap := map[int]int{}
for i := range users {
for _, v := range users[i].DepartmentId {
departmentIdMap[v] = v
}
}
userTotal = len(users)
departmentTotal = len(departmentIdMap)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil
}
func (rs *EvaluationCycleService) CycleTemplateList(in *command.CycleTemplateListCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
_, cycleTemplates, err := cycleTemplateRepository.Find(map[string]interface{}{"cycleId": in.CycleId}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
list := make([]*domain.TemplateSimple, 0)
for i := range cycleTemplates {
list = append(list, &domain.TemplateSimple{
Id: cycleTemplates[i].Id,
Name: cycleTemplates[i].Name,
CreatedAt: cycleTemplates[i].TemplateCreatedAt,
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"list": list}, nil
}
func (rs *EvaluationCycleService) CycleTemplate(in *command.CycleTemplateCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId})
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 cycleTemplate.Template, nil
}
... ...
... ... @@ -2,25 +2,19 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type StateProjectCommand struct {
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
State int `cname:"项目状态" json:"state"`
type ActivateProjectCommand struct {
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
}
type CopyProjectCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
}
func (in *StateProjectCommand) Valid(validation *validation.Validation) {
switch in.State {
case domain.ProjectStateWaitConfig, domain.ProjectStateWaitActive, domain.ProjectStateEnable, domain.ProjectStateDisable:
default:
validation.SetError("state", "状态设置错误")
return
}
func (in *ActivateProjectCommand) Valid(validation *validation.Validation) {
}
func (in *CopyProjectCommand) Valid(*validation.Validation) {
... ...
... ... @@ -18,12 +18,3 @@ func (in *QueryProjectCommand) Valid(validation *validation.Validation) {
return
}
}
type StatisticCycleProjectUserCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string"`
}
func (in *StatisticCycleProjectUserCommand) Valid(*validation.Validation) {
}
... ...
... ... @@ -2,7 +2,7 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"time"
)
type UpdateProjectCommand struct {
... ... @@ -17,22 +17,25 @@ type UpdateProjectCommand struct {
}
type UpdateProjectTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
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"`
KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"`
KpiResultStart *time.Time `cname:"绩效结果开始查看时间" json:"kpiResultStart"`
Activate int `cname:"启动项目" json:"activate"`
}
type CheckRecipientCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string"`
Recipients []string `cname:"被评估人ID" json:"recipients"`
}
type UpdateProjectTemplateNodeCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string" valid:"Required"`
LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
Activate int `cname:"启动项目" json:"activate"`
}
func (in *UpdateProjectCommand) Valid(validation *validation.Validation) {
if len(in.Name) > 40 {
validation.SetError("name", "项目名称最大长度40个字符")
... ... @@ -46,10 +49,3 @@ func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation)
return
}
}
func (in *UpdateProjectTemplateNodeCommand) Valid(validation *validation.Validation) {
if len(in.LinkNodes) == 0 {
validation.SetError("linkNodes", "请添加评估流程")
return
}
}
... ...
... ... @@ -55,10 +55,19 @@ func (rs *EvaluationProjectService) Create(in *command.CreateProjectCommand) (in
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectAdapter := &adapter.EvaluationProjectAdapter{}
projectAdapter.EvaluationProject = project
if len(project.PmpIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)})
projectAdapter.TransformPmpAdapter(users)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
return projectAdapter, nil
}
... ... @@ -96,10 +105,19 @@ func (rs *EvaluationProjectService) Update(in *command.UpdateProjectCommand) (in
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectAdapter := &adapter.EvaluationProjectAdapter{}
projectAdapter.EvaluationProject = project
if len(project.PmpIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)})
projectAdapter.TransformPmpAdapter(users)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
return projectAdapter, nil
}
func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemplateCommand) (interface{}, error) {
... ... @@ -145,48 +163,33 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
project.Recipients = in.Recipients
project.Template = cycleTemplate.Template
project, err = projectRepository.Insert(project)
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 project, nil
}
func (rs *EvaluationProjectService) UpdateTemplateNode(in *command.UpdateProjectTemplateNodeCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// FIXME 启动时,需要激活定时任务
if in.Activate == 1 {
if len(in.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
project.State = domain.ProjectStateEnable
}
for i := range in.LinkNodes {
project.Template.LinkNodes[i].TimeStart = in.LinkNodes[i].TimeStart
project.Template.LinkNodes[i].TimeEnd = in.LinkNodes[i].TimeEnd
project.Template.LinkNodes[i].KpiCycle = in.LinkNodes[i].KpiCycle
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
}
} else {
node.TimeStart = in.TimeStart
node.TimeEnd = in.TimeEnd
}
}
project, err = projectRepository.Insert(project)
... ... @@ -290,7 +293,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
return tool_funs.SimpleWrapGridMap(total, projectAdapters), nil
}
func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (interface{}, error) {
func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
... ... @@ -300,13 +303,20 @@ func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (inte
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
project.State = in.State
if project.Template == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加评估模板")
}
if len(project.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
project.State = domain.TemplateStateEnable
project, err = projectRepository.Insert(project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -332,6 +342,10 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf
}
// ID重置
project.Id = 0
project.Name = project.Name + " 副本"
project.CreatorId = in.CreatorId
project.Recipients = make([]string, 0) // 重置被评估人
// 如果拷贝已经启用的模板,默认先设置为待启用
if project.State == domain.ProjectStateEnable {
project.State = domain.ProjectStateWaitActive
... ... @@ -346,7 +360,7 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf
return project, nil
}
func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycleProjectUserCommand) (interface{}, error) {
func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
... ... @@ -354,42 +368,41 @@ func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycl
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "linkNodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userIds := make([]int64, 0)
userIdMap := map[int64]int64{}
// 周期内的所有项目,员工不能重复被评估
rids := map[string]bool{}
for i := range projects {
project := projects[i]
for j := range project.Recipients {
userId, _ := strconv.ParseInt(project.Recipients[j], 10, 64)
userIdMap[userId] = userId
// 排除当前项目
if in.Id != projects[i].Id {
ids := projects[i].Recipients
for j := range ids {
rids[ids[j]] = true
}
}
}
for _, v := range userIdMap {
userIds = append(userIds, v)
}
userTotal := 0
departmentTotal := 0
if len(userIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": userIds, "limit": len(userIds)})
departmentIdMap := map[int]int{}
for i := range users {
for _, v := range users[i].DepartmentId {
departmentIdMap[v] = v
}
repeatNum := 0
for i := range in.Recipients {
id := in.Recipients[i]
if _, ok := rids[id]; ok {
repeatNum++
}
userTotal = len(users)
departmentTotal = len(departmentIdMap)
}
//if repeatNum > 0 {
// return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum))
//}
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 map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil
return repeatNum, nil
}
... ...
package command
type BatchRemove struct {
CompanyId int64 `json:"company_id"`
UserIds []int64 `json:"user_ids"`
DepartmentIds []int `json:"department_ids"`
}
... ...
... ... @@ -62,6 +62,13 @@ func (srv SyncDataUserService) FromBusinessAdmin(param *domain.MessageBody) erro
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.importUser(&param4)
case "employee/batchRemove":
batchRemove := &command.BatchRemove{}
err = json.Unmarshal(param.Data, batchRemove)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.BatchRemove(batchRemove)
default:
log.Logger.Error("action err:" + action)
}
... ... @@ -320,3 +327,38 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
return nil
}
// BatchRemove 调整部门
func (srv SyncDataUserService) BatchRemove(batchRemove *command.BatchRemove) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
if len(batchRemove.UserIds) > 0 {
for _, item := range batchRemove.UserIds {
user, err := userRepo.FindOne(map[string]interface{}{"id": item, "companyId": batchRemove.CompanyId})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
user.DepartmentId = batchRemove.DepartmentIds
user.UpdatedAt = time.Now()
_, err = userRepo.Update(user)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
... ...
... ... @@ -4,10 +4,20 @@ import (
"time"
)
const (
KpiCycleDay int = 1 // 考核周期-日
KpiCycleWeek int = 2 // 考核周期-周
KpiCycleOneMonth int = 3 // 考核周期-月
KpiCycleTwoMonth int = 4 // 考核周期-双月
KpiCycleThreeMonth int = 5 // 考核周期-季度
KpiCycleSixMonth int = 6 // 考核周期-半年
KpiCycleYear int = 7 // 考核周期-年
)
type TemplateSimple struct {
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
CreatedAt time.Time `json:"createdAt" comment:"模板创建时间"`
}
type EvaluationCycle struct {
... ... @@ -17,7 +27,7 @@ type EvaluationCycle struct {
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:"考核周期(1日、2周、3月)"`
KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
... ...
... ... @@ -5,13 +5,14 @@ import (
)
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:"删除时间"`
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
TemplateCreatedAt time.Time `json:"templateCreatedAt" 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 {
... ...
... ... @@ -24,16 +24,6 @@ const (
)
const (
KpiCycleDay int = 1 // 考核周期-日
KpiCycleWeek int = 2 // 考核周期-周
KpiCycleOneMonth int = 3 // 考核周期-月
KpiCycleTwoMonth int = 4 // 考核周期-双月
KpiCycleThreeMonth int = 5 // 考核周期-季度
KpiCycleSixMonth int = 6 // 考核周期-半年
KpiCycleYear int = 7 // 考核周期-年
)
type EntryItem struct {
Title string `json:"title" comment:"填写标题"`
HintText string `json:"hintText" comment:"文本内容提示"`
... ... @@ -41,12 +31,13 @@ type EntryItem struct {
// NodeContent 评估内容
type NodeContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId string `json:"ruleId" comment:"评估规则ID"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId" comment:"评估规则ID"`
Rule *EvaluationRule `json:"rule" comment:"评估规则对象"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
}
//// NodeAllInvite 360°邀请
... ...
... ... @@ -6,12 +6,13 @@ import (
)
type EvaluationCycleTemplate struct {
tableName struct{} `comment:"评估周期模板" pg:"evaluation_cycle_template"`
Id int64 `comment:"模板ID" pg:"pk:id"`
Name string `comment:"模板名称"`
Template *domain.EvaluationTemplate `comment:"模板数据"`
CycleId int64 `comment:"周期ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
tableName struct{} `comment:"评估周期模板" pg:"evaluation_cycle_template"`
Id int64 `comment:"模板ID" pg:"pk:id"`
Name string `comment:"模板名称"`
TemplateCreatedAt time.Time `comment:"模板创建时间"`
Template *domain.EvaluationTemplate `comment:"模板数据"`
CycleId int64 `comment:"周期ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
... ... @@ -92,7 +92,7 @@ func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) (
func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Department, error) {
tx := repo.transactionContext.PgTx
dparmentModel := []models.Department{}
query := tx.Model(&dparmentModel).Where("delete_at isnull")
query := tx.Model(&dparmentModel)
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
... ...
... ... @@ -22,25 +22,27 @@ func NewEvaluationCycleTemplateRepository(transactionContext *pgTransaction.Tran
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,
Id: m.Id,
Name: m.Name,
TemplateCreatedAt: m.TemplateCreatedAt,
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,
Id: d.Id,
Name: d.Name,
TemplateCreatedAt: d.TemplateCreatedAt,
Template: d.Template,
CycleId: d.CycleId,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
}
}
... ... @@ -58,9 +60,14 @@ func (repo *EvaluationCycleTemplateRepository) Insert(d *domain.EvaluationCycleT
d.Id = id
d.CreatedAt = time.Now()
d.UpdatedAt = d.CreatedAt
// 模板对象ID也更新
if d.Template != nil {
d.Template.Id = id
}
} else {
d.UpdatedAt = time.Now()
}
m := repo.TransformToModel(d)
tx := repo.transactionContext.PgTx
var err error
... ...
... ... @@ -123,6 +123,10 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
query.Where("name LIKE ? or remark LIKE ?", v, v)
}
if v, ok := queryOptions["ids"]; ok {
query.Where("id in(?)", pg.In(v))
}
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
}
... ...
... ... @@ -21,16 +21,18 @@ func NewUserRepository(tx *pgTransaction.TransactionContext) *UserRepository {
func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) {
userModel := models.User{
Id: user.Id,
Account: user.Account,
AvatarUrl: user.AvatarUrl,
CompanyId: user.CompanyId,
AdminType: user.AdminType,
Name: user.Name,
Status: user.Status,
UpdatedAt: user.UpdatedAt,
CreatedAt: user.CreatedAt,
DeletedAt: user.DeletedAt,
Id: user.Id,
Account: user.Account,
AvatarUrl: user.AvatarUrl,
CompanyId: user.CompanyId,
AdminType: user.AdminType,
DepartmentId: user.DepartmentId,
PositionId: user.PositionId,
Name: user.Name,
Status: user.Status,
UpdatedAt: user.UpdatedAt,
CreatedAt: user.CreatedAt,
DeletedAt: user.DeletedAt,
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(&userModel).Insert()
... ... @@ -43,17 +45,19 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) {
func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) {
userModel := models.User{
Id: user.Id,
Account: user.Account,
AvatarUrl: user.AvatarUrl,
CompanyId: user.CompanyId,
AdminType: user.AdminType,
Name: user.Name,
Email: user.Email,
Status: user.Status,
UpdatedAt: user.UpdatedAt,
CreatedAt: user.CreatedAt,
DeletedAt: user.DeletedAt,
Id: user.Id,
Account: user.Account,
AvatarUrl: user.AvatarUrl,
CompanyId: user.CompanyId,
AdminType: user.AdminType,
DepartmentId: user.DepartmentId,
PositionId: user.PositionId,
Name: user.Name,
Email: user.Email,
Status: user.Status,
UpdatedAt: user.UpdatedAt,
CreatedAt: user.CreatedAt,
DeletedAt: user.DeletedAt,
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(&userModel).WherePK().Update()
... ...
... ... @@ -12,14 +12,17 @@ type CycleController struct {
beego.BaseController
}
func (controller *RoleController) CreateCycle() {
func (controller *CycleController) CreateCycle() {
ruService := service.NewEvaluationCycleService()
in := &command.CreateCycleCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -30,7 +33,9 @@ func (controller *CycleController) UpdateCycle() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ... @@ -65,7 +70,40 @@ func (controller *CycleController) ListCycle() {
if len(in.Name) > 0 {
in.Name = "%" + in.Name + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
controller.Response(ruService.List(in))
}
}
func (controller *CycleController) StatisticCycleUser() {
ruService := service.NewEvaluationCycleService()
in := &command.StatisticCycleProjectUserCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
controller.Response(ruService.StatisticCycleUser(in))
}
}
func (controller *CycleController) CycleTemplateList() {
ruService := service.NewEvaluationCycleService()
in := &command.CycleTemplateListCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.CycleTemplateList(in))
}
}
func (controller *CycleController) CycleTemplate() {
ruService := service.NewEvaluationCycleService()
in := &command.CycleTemplateCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.CycleTemplate(in))
}
}
... ...
... ... @@ -12,14 +12,17 @@ type ProjectController struct {
beego.BaseController
}
func (controller *RoleController) CreateProject() {
func (controller *ProjectController) CreateProject() {
ruService := service.NewEvaluationProjectService()
in := &command.CreateProjectCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -30,7 +33,9 @@ func (controller *ProjectController) UpdateProject() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ... @@ -41,22 +46,13 @@ func (controller *ProjectController) UpdateProjectForTemplate() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.UpdateTemplate(in))
}
}
func (controller *ProjectController) UpdateProjectForTemplateNode() {
ruService := service.NewEvaluationProjectService()
in := &command.UpdateProjectTemplateNodeCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.UpdateTemplateNode(in))
}
}
func (controller *ProjectController) GetProject() {
ruService := service.NewEvaluationProjectService()
in := &command.GetProjectCommand{}
... ... @@ -88,18 +84,20 @@ func (controller *ProjectController) ListProject() {
if len(in.Name) > 0 {
in.Name = "%" + in.Name + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
func (controller *ProjectController) StateProject() {
func (controller *ProjectController) ActivateProject() {
ruService := service.NewEvaluationProjectService()
in := &command.StateProjectCommand{}
in := &command.ActivateProjectCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
controller.Response(ruService.State(in))
controller.Response(ruService.Activate(in))
}
}
... ... @@ -109,17 +107,20 @@ func (controller *ProjectController) CopyProject() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
ua := middlewares.GetUser(controller.Ctx)
in.CreatorId = ua.UserId
controller.Response(ruService.Copy(in))
}
}
func (controller *ProjectController) StatisticCycleUser() {
func (controller *ProjectController) CheckRecipients() {
ruService := service.NewEvaluationProjectService()
in := &command.StatisticCycleProjectUserCommand{}
in := &command.CheckRecipientCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.StatisticCycleUser(in))
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
controller.Response(ruService.CheckRecipients(in))
}
}
... ...
... ... @@ -18,8 +18,11 @@ func (controller *RuleController) CreateRule() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -30,8 +33,11 @@ func (controller *RuleController) UpdateRule() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ... @@ -82,7 +88,9 @@ func (controller *RuleController) ListRuleRelCreator() {
if len(in.NameOrRemark) > 0 {
in.NameOrRemark = "%" + in.NameOrRemark + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListRelCreator(in))
}
}
... ...
... ... @@ -13,14 +13,17 @@ type TemplateController struct {
beego.BaseController
}
func (controller *RoleController) CreateTemplate() {
func (controller *TemplateController) CreateTemplate() {
ruService := service.NewEvaluationTemplateService()
in := &command.CreateTemplateCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -31,7 +34,9 @@ func (controller *TemplateController) UpdateTemplate() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Update(in))
}
}
... ... @@ -67,7 +72,9 @@ func (controller *TemplateController) ListTemplate() {
if len(in.Name) > 0 {
in.Name = "%" + in.Name + "%"
}
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
... ... @@ -81,7 +88,9 @@ func (controller *TemplateController) ListEnableTemplate() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.List(in))
}
}
... ... @@ -92,7 +101,9 @@ func (controller *TemplateController) StateTemplate() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.State(in))
}
}
... ... @@ -103,8 +114,11 @@ func (controller *TemplateController) CopyTemplate() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
in.CreatorId = middlewares.GetUserId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
in.CreatorId = ua.UserId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
//in.CreatorId = middlewares.GetUserId(controller.Ctx)
controller.Response(ruService.Copy(in))
}
}
... ...
... ... @@ -51,7 +51,9 @@ func (controller *RoleController) ListForUserRole() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListForUser(in))
}
}
... ...
... ... @@ -18,7 +18,9 @@ func (controller *RoleUserController) CreateRoleUser() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Create(in))
}
}
... ... @@ -29,7 +31,9 @@ func (controller *RoleUserController) RemoveRoleUser() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.Remove(in))
}
}
... ... @@ -40,7 +44,9 @@ func (controller *RoleUserController) ListRoleUser() {
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
ua := middlewares.GetUser(controller.Ctx)
in.CompanyId = ua.CompanyId
//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListRole(in))
}
}
... ...
... ... @@ -6,6 +6,14 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
func GetUser(ctx *context.Context) *domain.UserAuth {
user := ctx.Input.GetData(domain.UserAuth{})
if user != nil {
return user.(*domain.UserAuth)
}
return nil
}
func CheckAdminToken() func(ctx *context.Context) {
return func(ctx *context.Context) {
adminToken := ctx.Input.Header("x-admin-token")
... ...
package middlewares
import (
"github.com/beego/beego/v2/server/web/context"
)
func setUserId(userId int64, ctx *context.Context) {
ctx.Input.SetData("_UserId", userId)
}
func GetUserId(ctx *context.Context) int64 {
userId := ctx.Input.GetData("_UserId")
return userId.(int64)
}
func setCompanyId(companyId int64, ctx *context.Context) {
ctx.Input.SetData("_CompanyId", companyId)
}
func GetCompanyId(ctx *context.Context) int64 {
companyId := ctx.Input.GetData("_CompanyId")
return companyId.(int64)
}
func setCompanyType(companyId int, ctx *context.Context) {
ctx.Input.SetData("_CompanyType", companyId)
}
func GetCompanyType(ctx *context.Context) int {
companyId := ctx.Input.GetData("_CompanyType")
return companyId.(int)
}
func invalidOrExpired(ctx *context.Context) {
resp := map[string]interface{}{
"code": 902,
"msg": "Authorization过期或无效,需要进行重新获取令牌",
}
_ = ctx.Output.JSON(resp, false, false)
}
func CheckToken() func(ctx *context.Context) {
return func(ctx *context.Context) {
tokenStr := ctx.Input.Header("x-mmm-accesstoken")
if tokenStr == "" { //没有带token
invalidOrExpired(ctx)
return
}
//userServe := service.UserService{}
//userTk, err := userServe.ValidLoginToken(tokenStr)
//if err != nil {
// invalidOrExpired(ctx)
// return
//}
//setUserId(userTk.UserId, ctx)
//setCompanyId(userTk.CompanyId, ctx)
//setCompanyType(userTk.CompanyType, ctx)
}
}
//
//import (
// "github.com/beego/beego/v2/server/web/context"
//)
//
//func setUserId(userId int64, ctx *context.Context) {
// ctx.Input.SetData("_UserId", userId)
//}
//
//func GetUserId(ctx *context.Context) int64 {
// userId := ctx.Input.GetData("_UserId")
// return userId.(int64)
//}
//
//func setCompanyId(companyId int64, ctx *context.Context) {
// ctx.Input.SetData("_CompanyId", companyId)
//}
//
//func GetCompanyId(ctx *context.Context) int64 {
// companyId := ctx.Input.GetData("_CompanyId")
// return companyId.(int64)
//}
//
//func setCompanyType(companyId int, ctx *context.Context) {
// ctx.Input.SetData("_CompanyType", companyId)
//}
//
//func GetCompanyType(ctx *context.Context) int {
// companyId := ctx.Input.GetData("_CompanyType")
// return companyId.(int)
//}
//
//func invalidOrExpired(ctx *context.Context) {
// resp := map[string]interface{}{
// "code": 902,
// "msg": "Authorization过期或无效,需要进行重新获取令牌",
// }
// _ = ctx.Output.JSON(resp, false, false)
//}
//
//func CheckToken() func(ctx *context.Context) {
// return func(ctx *context.Context) {
// tokenStr := ctx.Input.Header("x-mmm-accesstoken")
// if tokenStr == "" { //没有带token
// invalidOrExpired(ctx)
// return
// }
//
// //userServe := service.UserService{}
// //userTk, err := userServe.ValidLoginToken(tokenStr)
// //if err != nil {
// // invalidOrExpired(ctx)
// // return
// //}
// //setUserId(userTk.UserId, ctx)
// //setCompanyId(userTk.CompanyId, ctx)
// //setCompanyType(userTk.CompanyType, ctx)
// }
//}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/evaluation-cycle",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.CycleController{}, "Post:CreateCycle"),
web.NSRouter("/", &controllers.CycleController{}, "Put:UpdateCycle"),
web.NSRouter("/", &controllers.CycleController{}, "Delete:RemoveCycle"),
web.NSRouter("/:Id", &controllers.CycleController{}, "Get:GetCycle"),
web.NSRouter("/list", &controllers.CycleController{}, "Post:ListCycle"),
web.NSRouter("/statistic", &controllers.CycleController{}, "Post:StatisticCycleUser"),
web.NSRouter("/templates", &controllers.CycleController{}, "Post:CycleTemplateList"),
)
web.AddNamespace(ns)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/evaluation-project",
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.ProjectController{}, "Post:CreateProject"),
web.NSRouter("/", &controllers.ProjectController{}, "Put:UpdateProject"),
web.NSRouter("/", &controllers.ProjectController{}, "Delete:RemoveProject"),
web.NSRouter("/:Id", &controllers.ProjectController{}, "Get:GetProject"),
web.NSRouter("/list", &controllers.ProjectController{}, "Post:ListProject"),
web.NSRouter("/detail", &controllers.ProjectController{}, "Put:UpdateProjectForTemplate"),
web.NSRouter("/check-recipients", &controllers.ProjectController{}, "Post:CheckRecipients"),
web.NSRouter("/copy", &controllers.ProjectController{}, "Post:CopyProject"),
web.NSRouter("/activate", &controllers.ProjectController{}, "Post:ActivateProject"),
)
web.AddNamespace(ns)
}
... ...
... ... @@ -9,7 +9,7 @@ import (
func init() {
ns := web.NewNamespace("/v1/evaluation-rule",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.RuleController{}, "Post:CreateRule"),
web.NSRouter("/", &controllers.RuleController{}, "Put:UpdateRule"),
web.NSRouter("/", &controllers.RuleController{}, "Delete:RemoveRule"),
... ...
... ... @@ -9,8 +9,8 @@ import (
func init() {
ns := web.NewNamespace("/v1/evaluation-template",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
// web.NSRouter("/", &controllers.TemplateController{}, "Post:CreateTemplate"),
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.TemplateController{}, "Post:CreateTemplate"),
web.NSRouter("/", &controllers.TemplateController{}, "Put:UpdateTemplate"),
web.NSRouter("/", &controllers.TemplateController{}, "Delete:RemoveTemplate"),
web.NSRouter("/:Id", &controllers.TemplateController{}, "Get:GetTemplate"),
... ...
... ... @@ -9,7 +9,7 @@ import (
func init() {
ns := web.NewNamespace("/v1/role",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
//web.NSRouter("/", &controllers.RoleController{}, "Post:CreateRole"),
//web.NSRouter("/", &controllers.RoleController{}, "Put:UpdateRole"),
//web.NSRouter("/", &controllers.RoleController{}, "Delete:RemoveRole"),
... ...
... ... @@ -3,15 +3,16 @@ package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/role-user",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
// web.NSRouter("/", &controllers.RoleUserController{}, "Post:CreateRole"),
// web.NSRouter("/", &controllers.RoleUserController{}, "Delete:RemoveRole"),
// web.NSRouter("/all", &controllers.RoleUserController{}, "Post:ListRoleUser"),
web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()),
web.NSRouter("/", &controllers.RoleUserController{}, "Post:CreateRoleUser"),
web.NSRouter("/", &controllers.RoleUserController{}, "Delete:RemoveRoleUser"),
web.NSRouter("/all", &controllers.RoleUserController{}, "Post:ListRoleUser"),
)
web.AddNamespace(ns)
}
... ...