作者 tangxvhui

新建任务优先级

package command
type CreateTaskLevelCommand struct {
LevelName string `json:"levelName"`
CompanyId int `json:"-"`
}
... ...
... ... @@ -354,19 +354,15 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.SaveTaskLevel(param.LevelName, param.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存任务等级"+err.Error())
}
return map[string]interface{}{
"id": param.Id,
}, nil
}
func (srv TaskService) SaveTaskLevel(levelName string, companyId int) error {
func (srv TaskService) SaveTaskLevel(param *command.CreateTaskLevelCommand) error {
defalutLevel := domain.DefaultTaskLevel()
for _, val := range defalutLevel {
if val.LevelName == levelName {
if val.LevelName == param.LevelName {
return nil
}
}
... ... @@ -384,8 +380,8 @@ func (srv TaskService) SaveTaskLevel(levelName string, companyId int) error {
"transactionContext": transactionContext,
})
cnt, _, err := taskLevelRepo.Find(map[string]interface{}{
"companyId": companyId,
"levelName": levelName,
"companyId": param.CompanyId,
"levelName": param.LevelName,
"limit": 1,
})
if err != nil {
... ... @@ -396,8 +392,8 @@ func (srv TaskService) SaveTaskLevel(levelName string, companyId int) error {
}
newTaskLevel := domain.TaskLevel{
Id: 0,
LevelName: levelName,
CompanyId: companyId,
LevelName: param.LevelName,
CompanyId: param.CompanyId,
}
err = taskLevelRepo.Save(&newTaskLevel)
if err != nil {
... ...
... ... @@ -191,6 +191,7 @@ func (c *TaskController) SelectCondition() {
c.Response(data, err)
}
// 优先级
func (c *TaskController) LevelList() {
srv := service.NewTaskService()
userReq := middlewares.GetUser(c.Ctx)
... ... @@ -198,3 +199,19 @@ func (c *TaskController) LevelList() {
data, err := srv.ListTaskLevel(companyId)
c.Response(data, err)
}
// 新建任务优先级
func (c *TaskController) SaveTaskLevel() {
srv := service.NewTaskService()
paramReq := &command.CreateTaskLevelCommand{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
err = srv.SaveTaskLevel(paramReq)
c.Response(nil, err)
}
... ...
... ... @@ -18,6 +18,7 @@ func init() {
web.NSCtrlPost("/stop", (*controllers.TaskController).StopTask),
web.NSCtrlPost("/list", (*controllers.TaskController).ListTask),
web.NSCtrlGet("/level/list", (*controllers.TaskController).LevelList),
web.NSCtrlPost("/level", (*controllers.TaskController).SaveTaskLevel),
)
web.AddNamespace(taskAdminNS)
// 员工绩效模块
... ...