作者 tangxvhui

更新

... ... @@ -277,7 +277,7 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.
"transactionContext": transactionContext,
})
cnt, _, err := messageRepo.Find(map[string]interface{}{
"types": domain.MessageTypesTaskStage,
"types": domain.MessageTypesTaskRecord,
"targetUserId": param.UserId,
"limit": 1,
})
... ... @@ -415,3 +415,52 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.
}
return resp, nil
}
// TodayMessage 任务里程碑变更通知
func (srv *MessagePersonalService) TodayMessageTaskStageModify(param *command.GetUserMessageCommand) (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()
}()
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, messageList, err := messageRepo.Find(map[string]interface{}{
"types": domain.MessageTypesTaskModify,
"targetUserId": param.UserId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查个人消息的消息"+err.Error())
}
for _, val := range messageList {
val.ReadFlag = domain.MessageIsRead
err = messageRepo.Save(val)
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())
}
msgList := []adapter.MessageListAdapter{}
for _, val := range messageList {
msgList = append(msgList, adapter.MessageListAdapter{
Content: val.Content,
})
}
resp := map[string]interface{}{
"needNotify": true,
"list": msgList,
}
if len(msgList) == 0 {
resp["needNotify"] = false
}
return resp, nil
}
... ...
package service
import (
"encoding/json"
"fmt"
"strconv"
"time"
... ... @@ -231,6 +233,8 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
}
lastPlanCompletedAt := time.Time{}
newStageList := []*domain.TaskStage{}
//标记完成时间变更的里程碑
markStage := []domain.TaskStage{}
for i, val2 := range param.StageList {
t, err := time.ParseInLocation("2006-01-02", val2.PlanCompletedAt, time.Local)
if err != nil {
... ... @@ -262,10 +266,30 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
oldStage.DeletedAt = nil
oldStage.SortBy = i + 1
oldStage.Name = val2.Name
oldStage.PlanCompleted(t)
if ok := oldStage.PlanCompleted(t); ok {
markStage = append(markStage, *oldStage)
}
}
stageList = append(stageList, newStageList...)
//查询是否已经有每日评估
taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
cnt, _, err := taskRecordRepo.Find(map[string]interface{}{
"taskId": taskData.Id,
"limit": 1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "相关联的任务反馈信息"+err.Error())
}
if cnt > 0 {
for _, v := range stageList {
if v.DeletedAt != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有日评数据,不能删除里程碑")
}
}
}
err = taskStageRepo.Save(stageList)
if err != nil {
... ... @@ -275,6 +299,33 @@ func (srv TaskService) UpdateTask(param *command.UpdateTaskCommand) (map[string]
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//更具markStage 记录的里程碑数据生成通知
for _, val := range markStage {
for _, val2 := range taskData.RelatedUser {
t1 := time.Unix(val.PlanCompletedAt, 0).Format("2006-01-02")
s := fmt.Sprintf("【%s 任务里程碑 %s 完成时间变更为 %s,请知晓", taskData.Name, val.Name, t1)
payload := map[string]string{
"id": strconv.Itoa(val.Id),
}
payloadStr, _ := json.Marshal(payload)
newMessage := domain.MessagePersonal{
Id: 0,
Types: domain.MessageTypesTaskModify,
TargetUserId: val2,
ReadFlag: domain.MessageUnread,
Title: s,
Content: s,
Payload: string(payloadStr),
}
err = messageRepo.Save(&newMessage)
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())
}
... ... @@ -420,7 +471,6 @@ func (srv TaskService) RunTask(param *command.RunTaskCommand) (map[string]interf
if taskData.Status == domain.TaskRunning {
return map[string]interface{}{"id": param.TaskId}, nil
}
taskData.Status = domain.TaskRunning
taskData.RunAt = time.Now().Unix()
err = taskRepo.Save(taskData)
... ...
... ... @@ -52,8 +52,17 @@ func (t TaskStage) StatusDescription() string {
return str
}
func (t *TaskStage) PlanCompleted(now time.Time) {
t.PlanCompletedAt = t.dayEndTime(now).Unix()
// 计划完成是否变更
func (t *TaskStage) PlanCompleted(now time.Time) bool {
if t.RealCompletedAt != 0 {
return false
}
newTime := t.dayEndTime(now).Unix()
if t.PlanCompletedAt == newTime {
return false
}
t.PlanCompletedAt = newTime
return true
}
func (t TaskStage) dayEndTime(now time.Time) time.Time {
... ...
... ... @@ -39,3 +39,12 @@ func (c *MessagePersonalController) TodayMessageTaskRecordAnomaly() {
data, err := srv.TodayMessageTaskRecordAnomaly(&param)
c.Response(data, err)
}
func (c *MessagePersonalController) TodayMessageTaskStageModify() {
srv := service.NewMessagePersonalService()
userReq := middlewares.GetUser(c.Ctx)
param := command.GetUserMessageCommand{}
param.UserId = int(userReq.UserId)
data, err := srv.TodayMessageTaskStageModify(&param)
c.Response(data, err)
}
... ...
... ... @@ -13,6 +13,8 @@ func init() {
web.NSCtrlGet("/summary-evaluation/self/today", (*controllers.MessagePersonalController).TodayMessageSummaryEvaluation),
web.NSCtrlGet("/summary-evaluation/task_stage/today", (*controllers.MessagePersonalController).TodayMessageTaskStageAnomaly),
web.NSCtrlGet("/summary-evaluation/task_record/today", (*controllers.MessagePersonalController).TodayMessageTaskRecordAnomaly),
web.NSCtrlGet("/summary-evaluation/task_modify/today", (*controllers.MessagePersonalController).TodayMessageTaskStageModify),
//
)
web.AddNamespace(ns)
}
... ...