作者 tangxvhui

更新

... ... @@ -247,3 +247,11 @@ func CreateTaskRecordRepository(options map[string]interface{}) domain.TaskRecor
}
return repository.NewTaskRecordRepository(transactionContext)
}
func CreateTaskLevelRepository(options map[string]interface{}) domain.TaskLevelRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewTaskLevelRepository(transactionContext)
}
... ...
... ... @@ -45,7 +45,9 @@ func messageTaskStageAnomaly(companyId int) ([]*domain.MessagePersonal, error) {
if len(userList) == 0 {
continue
}
//通知相关人员
//通知负责人
for _, val2 := range userList {
content := ""
if val2.Level == 1 {
... ...
... ... @@ -351,7 +351,7 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.
taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
// 我作为任务负责人
leaderIds := []string{strconv.Itoa(param.UserId)}
taskStageList, err := taskDao.TaskAnomalyByLeader(leaderIds, 2)
taskStageList, err := taskDao.TaskAnomalyByLeader(leaderIds, 1)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
}
... ... @@ -369,7 +369,7 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.
//我作为上级, 获取我的下一级的异常任务
var taskStageList2 []dao.TaskData2
if len(childUserId) > 0 {
taskStageList2, err = taskDao.TaskAnomalyByLeader(childUserId, 4)
taskStageList2, err = taskDao.TaskAnomalyByLeader(childUserId, 3)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
}
... ...
package command
type UpdateTaskCommand struct {
CompanyId int `json:"-"`
Id int `json:"id,string"`
Alias string `json:"alias"` //任务名称
LevelName string `json:"levelName"` //优先级
... ...
... ... @@ -349,11 +349,61 @@ 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 {
defalutLevel := domain.DefaultTaskLevel()
for _, val := range defalutLevel {
if val.LevelName == levelName {
return nil
}
}
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()
}()
taskLevelRepo := factory.CreateTaskLevelRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
cnt, _, err := taskLevelRepo.Find(map[string]interface{}{
"companyId": companyId,
"levelName": levelName,
"limit": 1,
})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务优先级失败:"+err.Error())
}
if cnt > 0 {
return nil
}
newTaskLevel := domain.TaskLevel{
Id: 0,
LevelName: levelName,
CompanyId: companyId,
}
err = taskLevelRepo.Save(&newTaskLevel)
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
}
// 获取任务详情
func (srv TaskService) GetTaskInfo(param *command.GetTaskCommand) (*adapter.TaskInfoAdapter, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -1471,3 +1521,37 @@ func (srv TaskService) listTask3ForHrbp(param *command.SearchTaskCommand) (map[s
}
return result, nil
}
func (srv TaskService) ListTaskLevel(companyId int) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
taskLevelRepo := factory.CreateTaskLevelRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, taskLevelList, err := taskLevelRepo.Find(map[string]interface{}{
"companyId": companyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务优先级失败:"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
taskLevelAll := []*domain.TaskLevel{}
taskLevelAll = append(taskLevelAll, domain.DefaultTaskLevel()...)
taskLevelAll = append(taskLevelAll, taskLevelList...)
result := map[string]interface{}{
"list": taskLevelAll,
}
return result, nil
}
... ...
package domain
// 任务有优先级
type TaskLevel struct {
Id int `json:"id"`
LevelName string `json:"levelName"`
CompanyId int `json:"companyId"`
}
type TaskLevelRepository interface {
Save(t *TaskLevel) error
// Remove(t *TaskLevel) (*TaskLevel, error)
// FindOne(queryOptions map[string]interface{}) (*TaskLevel, error)
Find(queryOptions map[string]interface{}) (int, []*TaskLevel, error)
}
func DefaultTaskLevel() []*TaskLevel {
return []*TaskLevel{
{
Id: 0,
LevelName: "战略任务",
CompanyId: 0,
},
{
Id: 0,
LevelName: "重点任务",
CompanyId: 0,
},
{
Id: 0,
LevelName: "常规任务",
CompanyId: 0,
},
}
}
... ...
... ... @@ -595,7 +595,7 @@ type TaskData4 struct {
LeaderId int `pg:"leader_id"`
}
// TaskStageAnomalyAll 获取所有异常的里程碑任务
// TaskStageAnomalyAll 获取所有异常的里程碑任务
func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) {
sqlStr := `select distinct
task.id as task_id,
... ...
... ... @@ -56,6 +56,7 @@ func init() {
&models.TaskStage{},
&models.TaskIgnore{},
&models.TaskRecord{},
&models.TaskLevel{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
... ...
package models
// 任务优先级
type TaskLevel struct {
tableName struct{} `comment:"任务优先级" pg:"task_level"`
Id int `pg:"id"`
LevelName string `pg:"level_name"`
CompanyId int `pg:"company_id"`
}
... ...
package repository
import (
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
//任务
type TaskLevelRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.TaskLevelRepository = (*TaskLevelRepository)(nil)
func NewTaskLevelRepository(transactionContext *pgTransaction.TransactionContext) *TaskLevelRepository {
return &TaskLevelRepository{transactionContext: transactionContext}
}
func (repo *TaskLevelRepository) TransformToDomain(d *models.TaskLevel) *domain.TaskLevel {
return &domain.TaskLevel{
Id: d.Id,
LevelName: d.LevelName,
CompanyId: d.CompanyId,
}
}
func (repo *TaskLevelRepository) Save(param *domain.TaskLevel) error {
m := models.TaskLevel{
Id: param.Id,
LevelName: param.LevelName,
CompanyId: param.CompanyId,
}
db := repo.transactionContext.PgTx
if m.Id == 0 {
_, err := db.Model(&m).Insert()
if err != nil {
return err
}
} else {
_, err := db.Model(&m).WherePK().Update()
if err != nil {
return err
}
}
param.Id = m.Id
return nil
}
func (repo *TaskLevelRepository) Find(queryOptions map[string]interface{}) (int, []*domain.TaskLevel, error) {
tx := repo.transactionContext.PgTx
var m []*models.TaskLevel
query := tx.Model(&m)
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id=?", v)
}
if v, ok := queryOptions["levelName"]; ok {
query.Where("level_name=?", v)
}
query.Order("id desc")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var datas []*domain.TaskLevel
for _, v := range m {
d := repo.TransformToDomain(v)
datas = append(datas, d)
}
return count, datas, nil
}
... ...
... ... @@ -39,7 +39,8 @@ func (c *TaskController) UpdateTask() {
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
data, err := srv.UpdateTask(paramReq)
c.Response(data, err)
}
... ... @@ -189,3 +190,11 @@ func (c *TaskController) SelectCondition() {
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)
}
... ...
... ... @@ -17,6 +17,7 @@ func init() {
web.NSCtrlPost("/run", (*controllers.TaskController).RunTask),
web.NSCtrlPost("/stop", (*controllers.TaskController).StopTask),
web.NSCtrlPost("/list", (*controllers.TaskController).ListTask),
web.NSCtrlGet("/level/list", (*controllers.TaskController).LevelList),
)
web.AddNamespace(taskAdminNS)
// 员工绩效模块
... ...