作者 tangxvhui

优化

... ... @@ -15,7 +15,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
func messageTaskStageAnomaly(companyId int) ([]*domain.MessagePersonal, error) {
func messageTaskStageAnomaly() ([]*domain.MessagePersonal, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -28,7 +28,7 @@ func messageTaskStageAnomaly(companyId int) ([]*domain.MessagePersonal, error) {
}()
taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
taskData, err := taskDao.TaskStageAnomalyAll(companyId)
taskData, err := taskDao.TaskStageAnomalyAll()
if err != nil {
return nil, fmt.Errorf("获取任务信息%s", err)
}
... ... @@ -112,36 +112,14 @@ func saveAllMessagePersonal(msgList []*domain.MessagePersonal) error {
return nil
}
// 发送手机端通知
func appMessageSend() error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
//获取公司id
companyIds, err := taskDao.TaskStageAnomalyForCompany()
if err != nil {
return fmt.Errorf("获取公司id%s", err)
}
if err := transactionContext.CommitTransaction(); err != nil {
return err
}
var appMessage []*domain.MessagePersonal
for _, val := range companyIds {
messageList, err := messageTaskStageAnomaly(val)
messageList, err := messageTaskStageAnomaly()
if err != nil {
return fmt.Errorf("生成里程碑异常的消息通知失败%s", err)
}
appMessage = append(appMessage, messageList...)
}
openApi := serviceGateway.NewHttplibMmmOpenApiServiceGateway()
for _, val := range appMessage {
_, err := openApi.PushInfo(1, constant.APP_MESSAGE_KEY, []int64{int64(val.TargetUserId)}, val.Title, val.Content)
... ... @@ -149,7 +127,6 @@ func appMessageSend() error {
log.Logger.Error("发送远端openApi关于里程碑异常的消息通知:" + err.Error())
}
}
err = saveAllMessagePersonal(appMessage)
if err != nil {
return fmt.Errorf("保存里程碑异常的消息通知失败%s", err)
... ...
... ... @@ -596,7 +596,7 @@ type TaskData4 struct {
}
// TaskStageAnomalyAll 获取所有异常的里程碑任务,
func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) {
func (d TaskDao) TaskStageAnomalyAll() ([]TaskData4, error) {
sqlStr := `select distinct
task.id as task_id,
task."name" as task_name ,
... ... @@ -608,11 +608,10 @@ func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) {
where 1=1
and task_stage.real_completed_at=0
and task_stage.plan_completed_at<extract(epoch from now())
and task.company_id =?
`
result := []TaskData4{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, companyId)
_, err := tx.Query(&result, sqlStr)
return result, err
}
... ...