作者 tangxvhui

更新

@@ -11,6 +11,7 @@ import ( @@ -11,6 +11,7 @@ import (
11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/adapter" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/adapter"
12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command" 12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command"
13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  14 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
14 ) 15 )
15 16
16 // 个人信息提示 17 // 个人信息提示
@@ -136,15 +137,75 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G @@ -136,15 +137,75 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G
136 } 137 }
137 return resp, nil 138 return resp, nil
138 } 139 }
139 -  
140 - // TDOD 140 + userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
  141 + // 针对任务负责人
  142 + taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
  143 + leaderIds := []string{strconv.Itoa(param.UserId)}
  144 + taskStageList, err := taskDao.TaskStageAnomaly(leaderIds)
  145 + if err != nil {
  146 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
  147 + }
  148 + childUser, err := userDao.AllChildUser(param.UserId)
  149 + if err != nil {
  150 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取下级员工"+err.Error())
  151 + }
  152 + childUserId := []string{}
  153 + for _, val := range childUser {
  154 + if val.Level == 2 {
  155 + childUserId = append(childUserId, strconv.Itoa(val.Id))
  156 + }
  157 + }
  158 + // 针对上级
  159 + var taskStageList2 []dao.TaskStageData
  160 + if len(childUserId) == 0 {
  161 + taskStageList2, err = taskDao.TaskStageAnomaly(childUserId)
  162 + if err != nil {
  163 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
  164 + }
  165 + }
  166 + childUserId2 := []string{}
  167 + for _, val := range childUser {
  168 + if val.Level == 3 {
  169 + childUserId = append(childUserId, strconv.Itoa(val.Id))
  170 + }
  171 + }
  172 + // 针对上上级
  173 + var taskStageList3 []dao.TaskStageData
  174 + if len(childUserId) == 0 {
  175 + taskStageList2, err = taskDao.TaskStageAnomaly(childUserId2)
  176 + if err != nil {
  177 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
  178 + }
  179 + }
  180 + msgList := []adapter.MessageListAdapter{}
  181 + for _, val := range taskStageList {
  182 + s := fmt.Sprintf("【您负责的项目【%s】里程碑未按时完成,请重点关注,积极寻找上级辅导。】", val.Name)
  183 + msgList = append(msgList, adapter.MessageListAdapter{
  184 + Content: s,
  185 + })
  186 + }
  187 + for _, val := range taskStageList2 {
  188 + s := fmt.Sprintf("您下级%s负责的项目【%s】里程碑未按时完成,请前往辅导。", val.LeaderName, val.Name)
  189 + msgList = append(msgList, adapter.MessageListAdapter{
  190 + Content: s,
  191 + })
  192 + }
  193 + for _, val := range taskStageList3 {
  194 + s := fmt.Sprintf("【您下级%s关注的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.Name)
  195 + msgList = append(msgList, adapter.MessageListAdapter{
  196 + Content: s,
  197 + })
  198 + }
141 if err := transactionContext.CommitTransaction(); err != nil { 199 if err := transactionContext.CommitTransaction(); err != nil {
142 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 200 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
143 } 201 }
144 202
145 resp := map[string]interface{}{ 203 resp := map[string]interface{}{
146 - "needNotify": false,  
147 - "list": []adapter.MessageListAdapter{}, 204 + "needNotify": true,
  205 + "list": msgList,
  206 + }
  207 + if len(msgList) == 0 {
  208 + resp["needNotify"] = false
148 } 209 }
149 return resp, nil 210 return resp, nil
150 } 211 }
@@ -181,15 +242,80 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command. @@ -181,15 +242,80 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.
181 } 242 }
182 return resp, nil 243 return resp, nil
183 } 244 }
  245 + userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
184 246
185 - // TODO 247 + taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
  248 + // 针对任务负责人
  249 + leaderIds := []string{strconv.Itoa(param.UserId)}
  250 + taskStageList, err := taskDao.TaskAnomaly(leaderIds, 2)
  251 + if err != nil {
  252 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
  253 + }
  254 + childUser, err := userDao.AllChildUser(param.UserId)
  255 + if err != nil {
  256 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取下级员工"+err.Error())
  257 + }
  258 + childUserId := []string{}
  259 + for _, val := range childUser {
  260 + if val.Level == 2 {
  261 + childUserId = append(childUserId, strconv.Itoa(val.Id))
  262 + }
  263 + }
  264 + // 针对上级
  265 + var taskStageList2 []dao.TaskStageData
  266 + if len(childUserId) == 0 {
  267 + taskStageList2, err = taskDao.TaskAnomaly(childUserId, 4)
  268 + if err != nil {
  269 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
  270 + }
  271 + }
  272 + childUserId2 := []string{}
  273 + for _, val := range childUser {
  274 + if val.Level == 3 {
  275 + childUserId = append(childUserId, strconv.Itoa(val.Id))
  276 + }
  277 + }
  278 + // 针对上上级
  279 + var taskStageList3 []dao.TaskStageData
  280 + if len(childUserId) == 0 {
  281 + taskStageList2, err = taskDao.TaskAnomaly(childUserId2, 5)
  282 + if err != nil {
  283 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
  284 + }
  285 + }
  286 + if err := transactionContext.CommitTransaction(); err != nil {
  287 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  288 + }
  289 + msgList := []adapter.MessageListAdapter{}
  290 + for _, val := range taskStageList {
  291 + s := fmt.Sprintf("【您负责的项目【%s】已超过N日未反馈进度,请前往该战略任务进行反馈。】", val.Name)
  292 + msgList = append(msgList, adapter.MessageListAdapter{
  293 + Content: s,
  294 + })
  295 + }
  296 + for _, val := range taskStageList2 {
  297 + s := fmt.Sprintf("【您下级%s负责的项目【%s】已超过N日未反馈进度,请前往辅导。】", val.LeaderName, val.Name)
  298 + msgList = append(msgList, adapter.MessageListAdapter{
  299 + Content: s,
  300 + })
  301 + }
  302 + for _, val := range taskStageList3 {
  303 + s := fmt.Sprintf("【您下级%s关注的项目【%s】已超过N日未反馈进度,请前往辅导。】", val.LeaderName, val.Name)
  304 + msgList = append(msgList, adapter.MessageListAdapter{
  305 + Content: s,
  306 + })
  307 + }
186 if err := transactionContext.CommitTransaction(); err != nil { 308 if err := transactionContext.CommitTransaction(); err != nil {
187 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 309 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
188 } 310 }
189 311
190 resp := map[string]interface{}{ 312 resp := map[string]interface{}{
191 - "needNotify": false,  
192 - "list": []adapter.MessageListAdapter{}, 313 + "needNotify": true,
  314 + "list": msgList,
  315 + }
  316 + if len(msgList) == 0 {
  317 + resp["needNotify"] = false
193 } 318 }
194 return resp, nil 319 return resp, nil
  320 +
195 } 321 }
@@ -10,6 +10,7 @@ import ( @@ -10,6 +10,7 @@ import (
10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  13 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" 14 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
14 ) 15 )
15 16
@@ -131,7 +132,8 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat @@ -131,7 +132,8 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
131 assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{"transactionContext": transactionContext}) 132 assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{"transactionContext": transactionContext})
132 //保存 员工的需要填写的每日任务型 指标项 133 //保存 员工的需要填写的每日任务型 指标项
133 taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{"transactionContext": transactionContext}) 134 taskRecordRepo := factory.CreateTaskRecordRepository(map[string]interface{}{"transactionContext": transactionContext})
134 - 135 + // 保存 员工的需要填写的每日任务型 指标项
  136 + taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
135 for i := range assessList { 137 for i := range assessList {
136 assessList[i].StaffAssessTaskId = assessTaskData.Id 138 assessList[i].StaffAssessTaskId = assessTaskData.Id
137 _, err = assessRepo.Save(&assessList[i]) 139 _, err = assessRepo.Save(&assessList[i])
@@ -154,6 +156,10 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat @@ -154,6 +156,10 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
154 if err != nil { 156 if err != nil {
155 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人任务型指标项"+err.Error()) 157 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人任务型指标项"+err.Error())
156 } 158 }
  159 + err = taskDao.IncreaseAnomaly([]int{val2.TaskId}, 1)
  160 + if err != nil {
  161 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人任务型指标项"+err.Error())
  162 + }
157 } 163 }
158 } 164 }
159 } 165 }
@@ -409,3 +409,50 @@ func (d *TaskDao) CountTaskStageAnomalyByHrbp(param ListTaskCondition) (int, err @@ -409,3 +409,50 @@ func (d *TaskDao) CountTaskStageAnomalyByHrbp(param ListTaskCondition) (int, err
409 _, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...) 409 _, err := tx.QueryOne(pg.Scan(&cnt), sqlStr, condition...)
410 return cnt, err 410 return cnt, err
411 } 411 }
  412 +
  413 +func (d *TaskDao) IncreaseAnomaly(id []int, incr int) error {
  414 + sqlStr := `update task set anomaly=task.anomaly+?
  415 + where id in(?)`
  416 + tx := d.transactionContext.PgTx
  417 + _, err := tx.Exec(sqlStr, incr, pg.In(id))
  418 + return err
  419 +}
  420 +
  421 +// TaskStageData
  422 +type TaskStageData struct {
  423 + Id int
  424 + Name string
  425 + LeaderName string
  426 +}
  427 +
  428 +// 异常的里程碑任务
  429 +func (d *TaskDao) TaskStageAnomaly(leaderId []string) ([]TaskStageData, error) {
  430 + sqlStr := `select
  431 + task_stage.id,
  432 + task_stage."name" ,
  433 + task.leader ->>'name' as leader_name
  434 + from task_stage
  435 + join task on task.id=task_stage.task_id
  436 + where 1=1
  437 + and task_stage.real_completed_at=0 and task_stage.plan_completed_at<extract(epoch from now())
  438 + and task.leader ->>'id' in(?) `
  439 + result := []TaskStageData{}
  440 + tx := d.transactionContext.PgTx
  441 + _, err := tx.Query(&result, sqlStr, pg.In(leaderId))
  442 + return result, err
  443 +}
  444 +
  445 +// 异常的里程碑任务
  446 +func (d *TaskDao) TaskAnomaly(leaderId []string, anomaly int) ([]TaskStageData, error) {
  447 + sqlStr := `select
  448 + task."name" ,
  449 + task.alias ,
  450 + task.leader ->>'name' as leader_name,
  451 + task.anomaly
  452 + from task
  453 + where task.anomaly >=? and task.leader ->'id'='?' `
  454 + result := []TaskStageData{}
  455 + tx := d.transactionContext.PgTx
  456 + _, err := tx.Query(&result, sqlStr, anomaly, pg.In(leaderId))
  457 + return result, err
  458 +}
  1 +package dao
  2 +
  3 +import pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  4 +
  5 +type UserDao struct {
  6 + transactionContext *pgTransaction.TransactionContext
  7 +}
  8 +
  9 +func NewUserDao(options map[string]interface{}) *UserDao {
  10 + var transactionContext *pgTransaction.TransactionContext
  11 + if value, ok := options["transactionContext"]; ok {
  12 + transactionContext = value.(*pgTransaction.TransactionContext)
  13 + }
  14 + return &UserDao{
  15 + transactionContext: transactionContext,
  16 + }
  17 +}
  18 +
  19 +type UserData1 struct {
  20 + Id int `pg:"id"`
  21 + ParentId int `pg:"parent_id"`
  22 + Account string `pg:"account"` // 用户账号
  23 + Name string `pg:"name"` // 用户姓名
  24 + Level int `pg:"level"`
  25 +}
  26 +
  27 +func (d *UserDao) AllChildUser(userId int) ([]UserData1, error) {
  28 + sqlStr := `with
  29 + -- 人员自身以及全下级
  30 + recursive t_user as (
  31 + (
  32 + select "user".id,"user".parent_id ,"user".account,"user".name, 1 as "level"
  33 + from "user"
  34 + where "user".id=3422174102828544
  35 + )
  36 + union
  37 + (
  38 + select "child_user".id,"child_user".parent_id,"child_user".account,"child_user".name,
  39 + "parent_user"."level"+1 as "level"
  40 + from "user" as "child_user"
  41 + join t_user as "parent_user" on "parent_user".id="child_user".parent_id
  42 + )
  43 + )select * from t_user `
  44 + result := []UserData1{}
  45 + tx := d.transactionContext.PgTx
  46 + _, err := tx.Query(&result, sqlStr, userId)
  47 + return result, err
  48 +}
  49 +
  50 +func (d *UserDao) ChildUser(userId int) ([]UserData1, error) {
  51 + sqlStr := `select "user".id,"user".parent_id ,"user".account,"user".name
  52 + from "user"
  53 + where "user".parent_id=?`
  54 + result := []UserData1{}
  55 + tx := d.transactionContext.PgTx
  56 + _, err := tx.Query(&result, sqlStr, userId)
  57 + return result, err
  58 +}
@@ -21,3 +21,21 @@ func (c *MessagePersonalController) TodayMessageSummaryEvaluation() { @@ -21,3 +21,21 @@ func (c *MessagePersonalController) TodayMessageSummaryEvaluation() {
21 data, err := srv.TodayMessageSummaryEvaluationSelf(&param) 21 data, err := srv.TodayMessageSummaryEvaluationSelf(&param)
22 c.Response(data, err) 22 c.Response(data, err)
23 } 23 }
  24 +
  25 +func (c *MessagePersonalController) TodayMessageTaskStageAnomaly() {
  26 + srv := service.NewMessagePersonalService()
  27 + userReq := middlewares.GetUser(c.Ctx)
  28 + param := command.GetUserMessageCommand{}
  29 + param.UserId = int(userReq.UserId)
  30 + data, err := srv.TodayMessageTaskStageAnomaly(&param)
  31 + c.Response(data, err)
  32 +}
  33 +
  34 +func (c *MessagePersonalController) TodayMessageTaskRecordAnomaly() {
  35 + srv := service.NewMessagePersonalService()
  36 + userReq := middlewares.GetUser(c.Ctx)
  37 + param := command.GetUserMessageCommand{}
  38 + param.UserId = int(userReq.UserId)
  39 + data, err := srv.TodayMessageTaskRecordAnomaly(&param)
  40 + c.Response(data, err)
  41 +}
@@ -11,6 +11,8 @@ func init() { @@ -11,6 +11,8 @@ func init() {
11 ns := web.NewNamespace("/v1/message-personal", 11 ns := web.NewNamespace("/v1/message-personal",
12 web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()), 12 web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()),
13 web.NSCtrlGet("/summary-evaluation/self/today", (*controllers.MessagePersonalController).TodayMessageSummaryEvaluation), 13 web.NSCtrlGet("/summary-evaluation/self/today", (*controllers.MessagePersonalController).TodayMessageSummaryEvaluation),
  14 + web.NSCtrlGet("/summary-evaluation/task_stage/today", (*controllers.MessagePersonalController).TodayMessageTaskStageAnomaly),
  15 + web.NSCtrlGet("/summary-evaluation/task_record/today", (*controllers.MessagePersonalController).TodayMessageTaskRecordAnomaly),
14 ) 16 )
15 web.AddNamespace(ns) 17 web.AddNamespace(ns)
16 } 18 }