作者 tangxvhui

添加接口

不能预览此文件类型
... ... @@ -35,9 +35,9 @@ func (srv TaskService) listTaskAnomaly2(param *command.ListTaskAnomalyCommand) (
})
limit := 500
offset := 0
if param.SubLevel < 1 {
param.SubLevel = 2
}
// if param.SubLevel < 1 {
// param.SubLevel = 2
// }
cnt, anomalyList, err := taskAnomalyDao.List2(param.UserId, param.CompanyId, param.TaskName, param.Category, param.DayTime, param.LeaderId, param.SubLevel, limit, offset)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -657,11 +657,74 @@ func (srv TaskService) ListTreeTaskAnomaly2(param *command.ListTaskAnomalyComman
"list": []adapter.TaskAnomalyItem2{},
}, nil
}
// leaderMap := map[string]*adapter.TaskAnomalyItem2{}
// var treeList []*adapter.TaskAnomalyItem2
// for _, val := range taskAnomalyList {
// leader, ok := leaderMap[val.Leader]
leaderMap := map[string]*adapter.TaskAnomalyItem2{}
leaderList := []map[string]string{}
var treeList []*adapter.TaskAnomalyItem2
for _, val := range taskAnomalyList {
leader, ok := leaderMap[val.LeaderId]
if !ok {
item := &adapter.TaskAnomalyItem2{
Leader: map[string]string{
"id": val.LeaderId,
"name": val.Leader,
},
TaskAnomaly: []adapter.TaskAnomalyItem{val},
}
leaderMap[val.LeaderId] = item
treeList = append(treeList, item)
leaderList = append(leaderList, map[string]string{
"id": val.LeaderId,
"name": val.Leader})
} else {
leader.TaskAnomaly = append(leader.TaskAnomaly, val)
}
}
result := map[string]interface{}{
"list": treeList,
"leader": leaderList,
}
return result, nil
}
// }
return nil, nil
// 我相关的任务,异常列表
// 按任务负责人归类,列表整理成树形结构
func (srv TaskService) ListTreeTaskAnomaly3(param *command.ListTaskAnomalyCommand) (map[string]interface{}, error) {
_, taskAnomalyList, err := srv.listTaskAnomaly3(param)
if err != nil {
return map[string]interface{}{
"list": []adapter.TaskAnomalyItem2{},
}, nil
}
if len(taskAnomalyList) == 0 {
return map[string]interface{}{
"list": []adapter.TaskAnomalyItem2{},
}, nil
}
leaderMap := map[string]*adapter.TaskAnomalyItem2{}
leaderList := []map[string]string{}
var treeList []*adapter.TaskAnomalyItem2
for _, val := range taskAnomalyList {
leader, ok := leaderMap[val.LeaderId]
if !ok {
item := &adapter.TaskAnomalyItem2{
Leader: map[string]string{
"id": val.LeaderId,
"name": val.Leader,
},
TaskAnomaly: []adapter.TaskAnomalyItem{val},
}
leaderMap[val.LeaderId] = item
treeList = append(treeList, item)
leaderList = append(leaderList, map[string]string{
"id": val.LeaderId,
"name": val.Leader})
} else {
leader.TaskAnomaly = append(leader.TaskAnomaly, val)
}
}
result := map[string]interface{}{
"list": treeList,
"leader": leaderList,
}
return result, nil
}
... ...
... ... @@ -178,7 +178,7 @@ func (d *TaskAnomalyDao) List2(userId int, companyId int, taskName string, categ
and t_task_ignore.id isnull
and task.deleted_at isnull
and task.leader ->>'id' in (
select t_user.id::text from t_user where t_user."level"=?
select t_user.id::text from t_user where t_user."level">=?
)
)
select
... ... @@ -239,7 +239,7 @@ func (d *TaskAnomalyDao) List2(userId int, companyId int, taskName string, categ
and t_task_ignore.id isnull
and task.deleted_at isnull
and task.leader ->>'id' in (
select t_user.id::text from t_user where t_user."level"=?
select t_user.id::text from t_user where t_user."level">=?
)
)
select count(*) as cnt
... ...
... ... @@ -336,3 +336,37 @@ func (c *TaskController) TaskAnomalyMark() {
c.Response(resp, err)
}
// 我的下级负责任务,异常列表,结构变体
func (c *TaskController) TaskAnomalyList2Tree() {
srv := service.NewTaskService()
paramReq := &command.ListTaskAnomalyCommand{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
paramReq.UserId = int(userReq.UserId)
resp, err := srv.ListTreeTaskAnomaly2(paramReq)
c.Response(resp, err)
}
// 我相关的负责任务,异常列表,结构变体
func (c *TaskController) TaskAnomalyList3Tree() {
srv := service.NewTaskService()
paramReq := &command.ListTaskAnomalyCommand{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
paramReq.UserId = int(userReq.UserId)
resp, err := srv.ListTreeTaskAnomaly2(paramReq)
c.Response(resp, err)
}
... ...
... ... @@ -36,10 +36,12 @@ func init() {
web.AddNamespace(taskFontNS)
taskAnomalyNS := web.NewNamespace("/v1/font",
web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()),
web.NSCtrlPost("/task_anomaly/my_task", (*controllers.TaskController).TaskAnomalyList1), //我负责的任务
web.NSCtrlPost("/task_anomaly/my_relation", (*controllers.TaskController).TaskAnomalyList3), //和我有关的任务
web.NSCtrlPost("/task_anomaly/my_sub", (*controllers.TaskController).TaskAnomalyList2), //我的下级负责的任务
web.NSCtrlPost("/task_anomaly/select/user", (*controllers.TaskController).UserSelect), //人员下拉选择列表
web.NSCtrlPost("/task_anomaly/my_task", (*controllers.TaskController).TaskAnomalyList1), //我负责的任务
web.NSCtrlPost("/task_anomaly/my_relation", (*controllers.TaskController).TaskAnomalyList3), //和我有关的任务
web.NSCtrlPost("/task_anomaly/my_relation_1", (*controllers.TaskController).TaskAnomalyList3Tree), //和我有关的任务
web.NSCtrlPost("/task_anomaly/my_sub", (*controllers.TaskController).TaskAnomalyList2), //我的下级负责的任务
web.NSCtrlPost("/task_anomaly/my_sub_1", (*controllers.TaskController).TaskAnomalyList2Tree), //我的下级负责的任务
web.NSCtrlPost("/task_anomaly/select/user", (*controllers.TaskController).UserSelect), //人员下拉选择列表
web.NSCtrlPost("/task_anomaly/marks", (*controllers.TaskController).TaskAnomalyMark),
)
web.AddNamespace(taskAnomalyNS)
... ...