作者 tangxvhui

异常中心

... ... @@ -8,5 +8,5 @@ type ListTaskAnomalyCommand struct {
TaskName string `json:"taskName"`
DayTime string `json:"dayTime"` //发生异常的日期
Category int `json:"category"` //异常分类
leaderId string `json:"leaderId"` //任务负责人id
LeaderId string `json:"leaderId"` //任务负责人id
}
... ...
... ... @@ -42,7 +42,6 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) (
}
listData := []adapter.TaskAnomalyItem{}
nowTime := time.Now()
for _, val := range anomalyList {
item := adapter.TaskAnomalyItem{
Id: val.Id,
... ... @@ -99,7 +98,7 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) (
if val.TaskStageCheck.RealCompletedAt == 0 && val.TaskStageCheck.Id > 0 {
//逾期未完成
planCompletedAt := time.Unix(val.TaskStageCheck.PlanCompletedAt, 0)
subDay := xtime.SubDayAbs(nowTime, planCompletedAt)
subDay := xtime.SubDayAbs(val.CreatedAt, planCompletedAt)
item.AnomalyDesc = fmt.Sprintf("里程碑%s已逾期%d天", val.TaskStageCheck.Name, subDay)
} else if val.TaskStageCheck.RealCompletedAt > 0 && val.TaskStageCheck.Id > 0 {
//逾期完成
... ... @@ -113,7 +112,7 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) (
//反馈异常
{
recordBegin := time.Unix(val.RecordBegin, 0)
subDay := xtime.SubDayAbs(nowTime, recordBegin)
subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
item.AnomalyDesc = fmt.Sprintf(
"本任务自%s未正常反馈项目进度,已异常%d天",
recordBegin.Local().Format("2006-01-02"),
... ... @@ -124,7 +123,7 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) (
//辅导异常
{
recordBegin := time.Unix(val.RecordBegin, 0)
subDay := xtime.SubDayAbs(nowTime, recordBegin)
subDay := xtime.SubDayAbs(val.CreatedAt, recordBegin)
item.AnomalyDesc = fmt.Sprintf(
"本任务计划于%s完成辅导,已逾期%d天",
recordBegin.Local().Format("2006-01-02"),
... ... @@ -141,13 +140,253 @@ func (srv TaskService) ListTaskAnomaly1(param *command.ListTaskAnomalyCommand) (
}
// 我的下级负责任务,异常列表
func (srv TaskService) ListTaskAnomaly2() error {
return nil
func (srv TaskService) ListTaskAnomaly2(param *command.ListTaskAnomalyCommand) (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()
}()
taskAnomalyDao := dao.NewTaskAnomalyDao(map[string]interface{}{
"transactionContext": transactionContext,
})
limit := 500
offset := 0
cnt, anomalyList, err := taskAnomalyDao.List2(param.UserId, param.CompanyId, param.TaskName, param.Category, param.DayTime, param.LeaderId, limit, offset)
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,
RecordBegin: val.RecordBegin,
MarkA: "",
MarkB: "",
MarkC: "",
MarkD: "",
}
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")
}
switch val.Category {
case 1:
{
//里程碑异常
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)
} 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)
}
}
case 2:
//反馈异常
{
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,
)
}
case 3:
//辅导异常
{
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,
)
}
}
listData = append(listData, item)
}
result := tool_funs.SimpleWrapGridMap(int64(cnt), listData)
return result, nil
}
// 与我有关的任务,异常列表
func (srv TaskService) ListTaskAnomaly3() error {
return nil
func (srv TaskService) ListTaskAnomaly3(param *command.ListTaskAnomalyCommand) (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()
}()
taskAnomalyDao := dao.NewTaskAnomalyDao(map[string]interface{}{
"transactionContext": transactionContext,
})
limit := 500
offset := 0
cnt, anomalyList, err := taskAnomalyDao.List3(param.UserId, param.CompanyId, param.TaskName, param.Category, param.DayTime, param.LeaderId, limit, offset)
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,
RecordBegin: val.RecordBegin,
MarkA: "",
MarkB: "",
MarkC: "",
MarkD: "",
}
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")
}
switch val.Category {
case 1:
{
//里程碑异常
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)
} 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)
}
}
case 2:
//反馈异常
{
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,
)
}
case 3:
//辅导异常
{
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,
)
}
}
listData = append(listData, item)
}
result := tool_funs.SimpleWrapGridMap(int64(cnt), listData)
return result, nil
}
// 对异常记录的操作标记
... ...
... ... @@ -2,6 +2,7 @@ package dao
import (
"fmt"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -31,6 +32,7 @@ type ListTaskAnomaly struct {
CurrentStage domain.TaskStage `pg:"current_stage"` // 计划执行的里程碑
LastStage domain.TaskStage `pg:"last_stage"` // 上一个完成的里程碑
TaskStageCheck domain.TaskStage `pg:"task_stage_check"` //
CreatedAt time.Time `pg:"created_at"`
AssessFlag int `pg:"assess_flag"`
WarnFlag int `pg:"warn_flag"`
AssistFlag int `pg:"assist_flag"`
... ... @@ -70,6 +72,7 @@ func (d *TaskAnomalyDao) List1(userId int, companyId int, taskName string, categ
task_anomaly.record_begin,
task_anomaly.marks,
task_anomaly.notice_who,
task_anomaly.created_at,
task.alias as "task_alias",
task."name" as "task_name",
task.end_time as "task_end_time",
... ... @@ -131,9 +134,138 @@ func (d *TaskAnomalyDao) List1(userId int, companyId int, taskName string, categ
// dayTime 搜索条件日期 ,例:"2006-01-02"
// pageSize 分页大小
// pageNumber 分页页码
func (d *TaskAnomalyDao) List2(userId int, companyId int, leaderId string, dayTime string, pageSize int, pageNumber int) error {
func (d *TaskAnomalyDao) List2(userId int, companyId int, taskName string, category int, leaderId string, dayTime string, limit int, offset int) (int, []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.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 where t_user."level">0
)
)
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.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 `
sqlStr2 := `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.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 where t_user."level">0
)
)
select count(*) as cnt
from t_task
join task_anomaly on t_task.task_id= task_anomaly.task_id `
condition := []interface{}{userId, userId, companyId}
if len(dayTime) > 0 {
condition = append(condition, dayTime)
sqlStr2 += ` and to_char(task_anomaly.created_at,'yyyy-MM-dd') =? `
sqlStr1 += ` and to_char(task_anomaly.created_at,'yyyy-MM-dd') =? `
}
if len(taskName) > 0 {
condition = append(condition, "%"+taskName+"%")
sqlStr2 += ` and t_task.task_alias like ? `
sqlStr1 += ` and t_task.task_alias like ? `
}
if category > 0 {
condition = append(condition, category)
sqlStr1 += ` and task_anomaly.category=? `
sqlStr2 += ` and task_anomaly.category=? `
}
condition = append(condition, limit, offset)
sqlStr1 += ` order by task_anomaly.id desc limit ? offset ? `
return nil
result := []ListTaskAnomaly{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr1, condition...)
if err != nil {
return 0, result, err
}
var cnt int
_, err = tx.QueryOne(pg.Scan(&cnt), sqlStr2, condition...)
return cnt, result, err
}
// 异常的任务记录,我作为相关人的任务
... ... @@ -161,6 +293,7 @@ func (d *TaskAnomalyDao) List3(userId int, companyId int, taskName string, categ
task_anomaly.record_begin,
task_anomaly.marks,
task_anomaly.notice_who,
task_anomaly.created_at,
task.alias as "task_alias",
task."name" as "task_name",
task.end_time as "task_end_time",
... ...
... ... @@ -251,6 +251,7 @@ func (c *TaskController) CancelIgnore() {
}
// 我负责的任务,异常列表
func (c *TaskController) TaskAnomalyList1() {
srv := service.NewTaskService()
paramReq := &command.ListTaskAnomalyCommand{}
... ... @@ -266,3 +267,37 @@ func (c *TaskController) TaskAnomalyList1() {
resp, err := srv.ListTaskAnomaly1(paramReq)
c.Response(resp, err)
}
// 我负责的任务,异常列表
func (c *TaskController) TaskAnomalyList3() {
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.ListTaskAnomaly3(paramReq)
c.Response(resp, err)
}
// 我的下级负责任务,异常列表
func (c *TaskController) TaskAnomalyList2() {
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.ListTaskAnomaly2(paramReq)
c.Response(resp, err)
}
... ...
... ... @@ -37,6 +37,8 @@ func init() {
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.AddNamespace(taskAnomalyNS)
}
... ...