作者 tangxvhui

添加接口

... ... @@ -1114,3 +1114,162 @@ func (srv TaskService) MarkTaskAnomalyByTask(param *command.MarkTaskAnomalyComma
}
return result, nil
}
// 搜索和我有关的异常列表
func (srv TaskService) ListTaskAnomaly4(param *command.ListTaskAnomalyCommand) (map[string]interface{}, error) {
param.TaskName = strings.TrimSpace(param.TaskName)
if len(param.TaskName) == 0 {
return tool_funs.SimpleWrapGridMap(0, []adapter.TaskAnomalyItem{}), nil
}
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()
}()
taskAnomalyDao := dao.NewTaskAnomalyDao(map[string]interface{}{
"transactionContext": transactionContext,
})
anomalyList, err := taskAnomalyDao.SearchForUser(param.UserId, param.CompanyId, param.TaskName)
if err != nil {
return map[string]interface{}{}, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
listData := []adapter.TaskAnomalyItem{}
for _, val := range anomalyList {
item := adapter.TaskAnomalyItem{
Id: val.Id,
TaskId: val.TaskId,
TaskRecordId: val.TaskRecordId,
Category: val.Category,
Leader: val.LeaderName,
CurrentStage: adapter.TaskStage{
Id: val.CurrentStage.Id,
Name: val.CurrentStage.Name,
StatusDescription: val.CurrentStage.StatusDescription(),
SortBy: val.CurrentStage.SortBy,
PlanCompletedAt: time.Unix(val.CurrentStage.PlanCompletedAt, 0).Local().Format("2006-01-02"),
RealCompletedAt: "",
},
LastStage: adapter.TaskStage{
Id: val.LastStage.Id,
Name: val.LastStage.Name,
StatusDescription: val.LastStage.StatusDescription(),
SortBy: val.LastStage.SortBy,
PlanCompletedAt: time.Unix(val.LastStage.PlanCompletedAt, 0).Local().Format("2006-01-02"),
RealCompletedAt: "",
},
AssessFlag: val.AssessFlag,
WarnFlag: val.WarnFlag,
AssistFlag: val.AssistFlag,
TaskLevel: val.LevelName,
TaskName: val.TaskName,
TaskAlias: val.TaskAlias,
TaskEndTime: int64(val.TaskEndTime),
TaskSortBy: val.TaskSortBy,
CreatedAt: val.CreatedAt.Local().Format("2006-01-02"),
RecordBegin: val.RecordBegin,
MarkA: "",
MarkB: "",
MarkC: "",
MarkD: "",
AnomalyDesc2: map[string]string{},
}
if len(val.Marks) > 0 {
item.MarkA = val.Marks["a"]
item.MarkB = val.Marks["b"]
item.MarkC = val.Marks["c"]
item.MarkD = val.Marks["d"]
}
if val.CurrentStage.RealCompletedAt > 0 {
item.CurrentStage.RealCompletedAt = time.Unix(val.CurrentStage.RealCompletedAt, 0).Local().Format("2006-01-02")
}
if val.LastStage.RealCompletedAt > 0 {
item.LastStage.RealCompletedAt = time.Unix(val.LastStage.RealCompletedAt, 0).Local().Format("2006-01-02")
}
noticeWho := []string{}
for _, val2 := range val.NoticeWho {
if name, ok := val2["name"]; ok {
noticeWho = append(noticeWho, name)
}
}
switch val.Category {
case domain.AnomalyCategoryType1:
{
//里程碑异常
if val.TaskStageCheck.RealCompletedAt == 0 && val.TaskStageCheck.Id > 0 {
//逾期未完成
planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0)
subDay := xtime.SubDayAbs(val.CreatedAt, planCompletedAt)
item.AnomalyDesc = fmt.Sprintf("里程碑%s已逾期%d天", val.TaskStageCheck.Name, subDay)
item.AnomalyDesc2 = map[string]string{
"types": "10",
"stageName": val.TaskStageCheck.Name,
"interval": strconv.Itoa(subDay),
"noticeWho": strings.Join(noticeWho, ","),
}
} else if val.TaskStageCheck.RealCompletedAt > 0 && val.TaskStageCheck.Id > 0 {
//逾期完成
planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0)
realCompletedAt := time.Unix(val.TaskStageCheck.RealCompletedAt, 0)
subDay := xtime.SubDayAbs(realCompletedAt, planCompletedAt)
item.AnomalyDesc = fmt.Sprintf("里程碑%s逾期%d天完成", val.TaskStageCheck.Name, subDay)
item.AnomalyDesc2 = map[string]string{
"types": "11",
"stageName": val.TaskStageCheck.Name,
"interval": strconv.Itoa(subDay),
"noticeWho": strings.Join(noticeWho, ","),
}
}
}
case domain.AnomalyCategoryType2:
//反馈异常
{
recordBegin := time.Unix(val.RecordBegin, 0)
subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
item.AnomalyDesc = fmt.Sprintf(
"本任务自%s未正常反馈项目进度,已异常%d天",
recordBegin.Local().Format("2006-01-02"),
subDay,
)
item.AnomalyDesc2 = map[string]string{
"types": "2",
"dayTime": recordBegin.Local().Format("2006-01-02"),
"interval": strconv.Itoa(subDay),
"noticeWho": strings.Join(noticeWho, ","),
}
}
case domain.AnomalyCategoryType3:
//辅导异常
{
recordBegin := time.Unix(val.RecordBegin, 0)
subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
item.AnomalyDesc = fmt.Sprintf(
"本任务计划于%s完成辅导,已逾期%d天",
recordBegin.Local().Format("2006-01-02"),
subDay,
)
item.AnomalyDesc2 = map[string]string{
"types": "3",
"dayTime": recordBegin.Local().Format("2006-01-02"),
"interval": strconv.Itoa(subDay),
"noticeWho": strings.Join(noticeWho, ","),
}
}
}
listData = append(listData, item)
}
result := tool_funs.SimpleWrapGridMap(int64(len(listData)), listData)
return result, nil
}
... ...
... ... @@ -369,7 +369,76 @@ func (d *TaskAnomalyDao) List3(userId int, companyId int, taskName string, categ
}
func (srv TaskAnomalyDao) Search(userId int, companyId int, taskName string) []ListTaskAnomaly {
return nil
func (d TaskAnomalyDao) SearchForUser(userId int, companyId int, taskName string) ([]ListTaskAnomaly, error) {
sqlStr1 := `with
-- 人员自身以及全下级
recursive t_user as (
(
select "user".id,"user".parent_id ,"user".account,"user".name, 1 as "level"
from "user"
where "user".id=? and "user".deleted_at isnull
)
union
(
select "child_user".id,"child_user".parent_id,"child_user".account,"child_user".name,
"parent_user"."level"+1 as "level"
from "user" as "child_user"
join t_user as "parent_user" on "parent_user".id="child_user".parent_id
where "child_user".deleted_at isnull
)
),
t_task_ignore as (
select task_ignore.id ,task_ignore.task_id
from task_ignore
where user_id = ?
),
t_task as (
select
task.id as "task_id",
task.alias as "task_alias",
task."name" as "task_name",
task.end_time as "task_end_time",
task.sort_by as "task_sort_by",
task.leader->>'name' as "leader_name",
task.leader->>'id' as "leader_id",
task.level_name
from task
left join t_task_ignore on task.id=t_task_ignore.task_id
where task.company_id=?
and t_task_ignore.id isnull
and task.deleted_at isnull
and (
(task.leader ->>'id' in (select t_user.id::text from t_user))
or task.related_user@> ?)
)
select
t_task.task_alias,t_task.task_name,t_task.task_end_time,
t_task.task_sort_by,t_task.leader_name,t_task.leader_id,
t_task.level_name,
task_anomaly.id,
task_anomaly.task_id,
task_anomaly.task_record_id,
task_anomaly.category,
task_anomaly.current_stage,
task_anomaly.last_stage,
task_anomaly.task_stage_check,
task_anomaly.assess_flag,
task_anomaly.warn_flag,
task_anomaly.assist_flag,
task_anomaly.record_begin,
task_anomaly.marks,
task_anomaly.notice_who,
task_anomaly.created_at
from t_task
join task_anomaly on t_task.task_id= task_anomaly.task_id
where t_task.task_alias like ?`
condition := []interface{}{userId, userId, companyId, fmt.Sprintf("[%d]", userId)}
condition = append(condition, "%"+taskName+"%")
result := []ListTaskAnomaly{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr1, condition...)
if err != nil {
return result, err
}
return result, nil
}
... ...
... ... @@ -403,3 +403,19 @@ func (c *TaskController) TaskAnomalyMarkByTask() {
c.Response(resp, err)
}
func (c *TaskController) SearchTaskAnomaly() {
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.ListTaskAnomaly4(paramReq)
c.Response(resp, err)
}
... ...
... ... @@ -45,6 +45,7 @@ func init() {
web.NSCtrlPost("/select/user", (*controllers.TaskController).UserSelect), //人员下拉选择列表
web.NSCtrlPost("/mark", (*controllers.TaskController).TaskAnomalyMark), //
web.NSCtrlPost("/info", (*controllers.TaskController).TaskAnomalyInfo), //异常记录详情
web.NSCtrlPost("/search_1", (*controllers.TaskController).SearchTaskAnomaly), //搜索异常列表
)
web.AddNamespace(taskAnomalyNS)
}
... ...