task_controller.go 9.5 KB
package controllers

import (
	"github.com/linmadan/egglib-go/core/application"
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/command"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/task/service"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)

type TaskController struct {
	beego.BaseController
}

// 获取任务
func (c *TaskController) GetTaskInfo() {
	srv := service.NewTaskService()
	paramReq := &command.GetTaskCommand{}
	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)
	data, err := srv.GetTaskInfo(paramReq)
	c.Response(data, err)
}

// 更新任务
func (c *TaskController) UpdateTask() {
	srv := service.NewTaskService()
	paramReq := &command.UpdateTaskCommand{}
	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)
	data, err := srv.UpdateTask(paramReq)
	c.Response(data, err)
}

// 更新任务
func (c *TaskController) CreateTask() {
	srv := service.NewTaskService()
	paramReq := &command.CreateTaskCommand{}
	err := c.BindJSON(paramReq)
	if err != nil {
		e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
		c.Response(nil, e)
		return
	}

	resp, err := srv.CreateTask(paramReq)
	c.Response(resp, err)
}

// 启动任务
func (c *TaskController) RunTask() {
	srv := service.NewTaskService()
	paramReq := &command.RunTaskCommand{}
	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)
	data, err := srv.RunTask(paramReq)
	c.Response(data, err)
}

// 启动任务
func (c *TaskController) StopTask() {
	srv := service.NewTaskService()
	paramReq := &command.StopTaskCommand{}
	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)
	data, err := srv.StopTask(paramReq)
	c.Response(data, err)
}

// 任务列表
func (c *TaskController) ListTask() {
	srv := service.NewTaskService()
	paramReq := &command.ListTaskCommand{}
	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)
	data, err := srv.ListTask(paramReq)
	c.Response(data, err)
}

// CancelAttention 员工绩效-任务管理列表-取消关注的任务
func (c *TaskController) CancelAttention() {
	srv := service.NewTaskService()
	paramReq := &command.CancelAttentionCommand{}
	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.UserId = int(userReq.UserId)
	paramReq.CompanyId = int(userReq.CompanyId)
	err = srv.CancelAttention(paramReq)
	c.Response(nil, err)
}

// ListTask2 员工绩效-任务管理列表
func (c *TaskController) ListTask2() {
	srv := service.NewTaskService()
	paramReq := &command.SearchTaskCommand{}
	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)
	paramReq.UserId = int(userReq.UserId)
	result, err := srv.ListTask3(paramReq)
	c.Response(result, err)
}

// ListTaskRecord 员工绩效-获取任务反馈列表
func (c *TaskController) ListTaskRecord() {
	srv := service.NewTaskService()
	paramReq := &command.ListTaskRecordCommand{}
	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)
	result, err := srv.ListTaskRecord(paramReq)
	c.Response(result, err)
}

// DeleteTask 删除任务
func (c *TaskController) DeleteTask() {
	srv := service.NewTaskService()
	paramReq := &command.GetTaskCommand{}
	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)
	data, err := srv.DeleteTaskInfo(paramReq)
	c.Response(data, err)
}

// SelectCondition 员工绩效-任务管理-任务列表-筛选条件
func (c *TaskController) SelectCondition() {
	srv := service.NewTaskService()
	paramReq := &command.GetSelcetCommand{}
	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)
	paramReq.UserId = int(userReq.UserId)
	data, err := srv.ConditionForListTask2(paramReq)
	c.Response(data, err)
}

// 优先级
func (c *TaskController) LevelList() {
	srv := service.NewTaskService()
	userReq := middlewares.GetUser(c.Ctx)
	companyId := int(userReq.CompanyId)
	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)
}

// 取消关注的任务列表
func (c *TaskController) ListTaskIgnore() {
	srv := service.NewTaskService()
	paramReq := &command.SearchTaskCommand{}
	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.UserId = int(userReq.UserId)
	paramReq.CompanyId = int(userReq.CompanyId)
	result, err := srv.ListTaskIgnore(paramReq)
	c.Response(result, err)
}

// 从取消关注的任务列表中移除
func (c *TaskController) CancelIgnore() {
	srv := service.NewTaskService()
	paramReq := &command.CancelIgnoreCommand{}
	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)
	paramReq.UserId = int(userReq.UserId)
	_, err = srv.CancleTaskIgnore(paramReq)
	c.Response(nil, err)

}

// 我负责的任务,异常列表
func (c *TaskController) TaskAnomalyList1() {
	srv := service.NewTaskService()
	paramReq := &command.ListTaskAnomalyCommand{}
	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)
	paramReq.UserId = int(userReq.UserId)
	resp, err := srv.ListTaskAnomaly1(paramReq)
	c.Response(resp, err)
}

// 我负责的任务,异常列表
func (c *TaskController) TaskAnomalyList3() {
	srv := service.NewTaskService()
	paramReq := &command.ListTaskAnomalyCommand{}
	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)
	paramReq.UserId = int(userReq.UserId)
	resp, err := srv.ListTaskAnomaly3(paramReq)
	c.Response(resp, err)
}

// 我的下级负责任务,异常列表
func (c *TaskController) TaskAnomalyList2() {
	srv := service.NewTaskService()
	paramReq := &command.ListTaskAnomalyCommand{}
	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)
	paramReq.UserId = int(userReq.UserId)
	resp, err := srv.ListTaskAnomaly2(paramReq)
	c.Response(resp, err)
}

func (c *TaskController) UserSelect() {
	srv := service.NewTaskService()
	paramReq := &command.UserSelectCommand{}
	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)
	paramReq.UserId = int(userReq.UserId)
	resp := srv.UserSelect(paramReq)
	c.Response(resp, nil)

}

// 点击操作
func (c *TaskController) TaskAnomalyMark() {
	srv := service.NewTaskService()
	paramReq := &command.MarkTaskAnomalyCommand{}
	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)
	resp, err := srv.MarkTaskAnomaly(paramReq)
	c.Response(resp, err)

}