作者 tangxvhui

优化

... ... @@ -86,6 +86,79 @@ func messageTaskStageAnomaly() ([]*domain.MessagePersonal, error) {
return allMessage, nil
}
// messageTaskRecordAnomaly 反馈异常
func messageTaskRecordAnomaly() ([]*domain.MessagePersonal, 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()
// }()
// taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
// userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
// taskData, err := taskDao.TaskRecordAnomalyAll()
// if err != nil {
// return nil, fmt.Errorf("获取任务信息%s", err)
// }
// if len(taskData) == 0 {
// return nil, nil
// }
// var allMessage []*domain.MessagePersonal
// for _, val := range taskData {
// //获取我全上级
// userList, err := userDao.AllParentUser(val.LeaderId)
// if err != nil {
// return nil, fmt.Errorf("获取上级人员信息%s", err)
// }
// if len(userList) == 0 {
// continue
// }
// //通知相关人员
// //通知负责人
// for _, val2 := range userList {
// content := ""
// if val2.Level == 1 {
// content = fmt.Sprintf("【您负责的项目【%s】已超过%s日未反馈进度,请前往该战略任务进行反馈。】", val.TaskName)
// } else if val2.Level == 2 {
// content = fmt.Sprintf("【您下级%s负责的项目【%s】已超过%s日未反馈进度,请前往辅导。】", val.LeaderName, val.TaskName)
// } else if val2.Level == 3 {
// content = fmt.Sprintf("【您下级%s关注的项目【%s】已超过%s日未反馈进度,请前往辅导。】", val.LeaderName, val.TaskName)
// }
// if content == "" {
// continue
// }
// payload := map[string]string{
// "task_id": strconv.Itoa(val.TaskId),
// "task_alias": val.TaskAlias,
// "task_name": val.TaskName,
// }
// payloadStr, _ := json.Marshal(payload)
// newMessage := domain.MessagePersonal{
// Id: 0,
// Types: domain.MessageTypesTaskStageApp,
// TargetUserId: val2.Id,
// ReadFlag: domain.MessageIsRead,
// Title: content,
// Content: content,
// CreatedAt: time.Time{},
// UpdatedAt: time.Time{},
// Payload: string(payloadStr),
// }
// allMessage = append(allMessage, &newMessage)
// }
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, err
// }
// return allMessage, nil
return nil, nil
}
func saveAllMessagePersonal(msgList []*domain.MessagePersonal) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ...
... ... @@ -602,20 +602,8 @@ type TaskData4 struct {
LeaderId int `pg:"leader_id"`
}
// TaskStageAnomalyAll 获取所有异常的里程碑任务,
// TaskStageAnomalyAll 获取所有里程碑异常的任务,
func (d TaskDao) TaskStageAnomalyAll() ([]TaskData4, error) {
// sqlStr := `select distinct
// task.id as task_id,
// task."name" as task_name ,
// task.alias as task_alias,
// task.leader ->>'id' as leader_id,
// task.leader ->>'name' as leader_name
// from task
// join task_stage on task.id=task_stage.task_id
// where 1=1
// and task_stage.real_completed_at=0
// and task_stage.plan_completed_at<extract(epoch from now())
// `
sqlStr := `select
task.id as task_id,
task."name" as task_name ,
... ... @@ -635,6 +623,33 @@ and (
return result, err
}
type TaskData5 struct {
TaskId int `pg:"task_id"`
TaskName string `pg:"task_name"`
TaskAlias string `pg:"task_alias"`
LeaderName string `pg:"leader_name"`
LeaderId int `pg:"leader_id"`
Anomaly int `pg:"anomaly"`
}
// TaskRecordAnomalyAll 获取所有反馈异常的任务,
func (d TaskDao) TaskRecordAnomalyAll() ([]TaskData5, error) {
sqlStr := `select
task.id as task_id,
task."name" as task_name ,
task.alias as task_alias,
task.anomaly,
task.leader ->>'id' as leader_id,
task.leader ->>'name' as leader_name
from task where 1=1
and task.deleted_at isnull
and task.anomaly>0 `
result := []TaskData5{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr)
return result, err
}
type ListTask struct {
SortBy1 int `pg:"sort_by_1"`
CPlanCompletedAt int `pg:"c_plan_completed_at"`
... ...