|
|
package notify
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
...
|
...
|
@@ -20,7 +23,7 @@ func NewMessagePersonalService() *MessagePersonalService { |
|
|
}
|
|
|
|
|
|
// 获取今天的周期综合自评消息提示
|
|
|
func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *command.GetUserMessageCommand) (interface{}, error) {
|
|
|
func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *command.GetUserMessageCommand) (map[string]interface{}, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
@@ -41,11 +44,61 @@ func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *comm |
|
|
"types": domain.EvaluationSelf,
|
|
|
"beginTime": nowTime,
|
|
|
"endTime": nowTime,
|
|
|
"limit": 20,
|
|
|
})
|
|
|
_ = evaluationList
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "周期综合自评"+err.Error())
|
|
|
}
|
|
|
resp := map[string]interface{}{
|
|
|
"needNotify": false,
|
|
|
"content": "",
|
|
|
}
|
|
|
if len(evaluationList) == 0 {
|
|
|
return resp, nil
|
|
|
}
|
|
|
|
|
|
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
newMessageList := []domain.MessagePersonal{}
|
|
|
for _, val := range evaluationList {
|
|
|
payload := map[string]string{
|
|
|
"id": strconv.Itoa(val.Id),
|
|
|
}
|
|
|
payloadStr, _ := json.Marshal(payload)
|
|
|
cnt, _, err := messageRepo.Find(map[string]interface{}{
|
|
|
"types": domain.MessageTypesOther,
|
|
|
"targetUserId": param.UserId,
|
|
|
"playload": string(payloadStr),
|
|
|
"limit": 1,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查自评消息记录"+err.Error())
|
|
|
}
|
|
|
if cnt == 0 {
|
|
|
newMessageList = append(newMessageList, domain.MessagePersonal{
|
|
|
Id: 0,
|
|
|
Types: domain.MessageTypesOther,
|
|
|
TargetUserId: val.TargetUser.UserId,
|
|
|
ReadFlag: domain.MessageIsRead,
|
|
|
Title: fmt.Sprintf("%s综合自评已开启,请前往进行评估", val.CycleName),
|
|
|
Content: fmt.Sprintf("%s综合自评已开启,请前往进行评估", val.CycleName),
|
|
|
CreatedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
Payload: string(payloadStr),
|
|
|
})
|
|
|
resp["needNotify"] = true
|
|
|
resp["content"] = fmt.Sprintf("%s综合自评已开启,请前往进行评估", val.CycleName)
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
for i := range newMessageList {
|
|
|
err = messageRepo.Save(&newMessageList[i])
|
|
|
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())
|
|
|
}
|
|
|
return nil, nil
|
|
|
return resp, nil
|
|
|
} |
...
|
...
|
|