bugfix: 更新待发任务时,同时修改最后一次指派人和进行中的任务数量和已完成任务数量。
员工手动点击完成任务,同时更新任务管理表中进行中的任务和代办任务数量。如果当前登录人查询自己已完成任务,就返回当初指派时的数量,而不是待完成任务。
This commit is contained in:
parent
5cdcf7376d
commit
be78b69db4
@ -424,23 +424,94 @@ func GetEmployeeAssignedTasks(req *EmployeeTaskQueryRequest) ([]*model.TaskAssig
|
|||||||
return records, total, nil
|
return records, total, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompleteTaskManually 员工手动点击完成任务
|
// CompleteTaskManually 员工手动点击完成任务(同时同步任务管理表的进度与完成数量)
|
||||||
func CompleteTaskManually(assignRecordsUUID string) error {
|
func CompleteTaskManually(assignRecordsUUID string) error {
|
||||||
|
// 开启事务,确保指派记录更新与任务管理同步原子性
|
||||||
|
tx := app.ModuleClients.TaskBenchDB.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 1) 查询该指派记录,获取艺人信息
|
||||||
|
var assignRecord model.TaskAssignRecords
|
||||||
|
if err := tx.Where("assign_records_uuid = ?", assignRecordsUUID).First(&assignRecord).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
tx.Rollback()
|
||||||
|
return commonErr.ReturnError(nil, "未找到任务记录", "未找到指派记录: ")
|
||||||
|
}
|
||||||
|
tx.Rollback()
|
||||||
|
return commonErr.ReturnError(err, "查询指派记录失败", "查询指派记录失败: ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) 更新该记录为完成状态
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
updateData := map[string]interface{}{
|
updateData := map[string]interface{}{
|
||||||
"status": 2, // 2:完成
|
"status": 2, // 2:完成
|
||||||
"complete_time": &now,
|
"complete_time": &now,
|
||||||
"updated_at": now,
|
"updated_at": now,
|
||||||
}
|
}
|
||||||
|
if err := tx.Model(&assignRecord).Updates(updateData).Error; err != nil {
|
||||||
err := app.ModuleClients.TaskBenchDB.Model(&model.TaskAssignRecords{}).
|
tx.Rollback()
|
||||||
Where("assign_records_uuid = ?", assignRecordsUUID).
|
|
||||||
Updates(updateData).Error
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return commonErr.ReturnError(err, "更新任务完成状态失败", "更新任务完成状态失败: ")
|
return commonErr.ReturnError(err, "更新任务完成状态失败", "更新任务完成状态失败: ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3) 统计该艺人(按手机号)当前进行中与已完成数量
|
||||||
|
var stats struct {
|
||||||
|
ProgressTaskCount int
|
||||||
|
CompleteTaskCount int
|
||||||
|
}
|
||||||
|
if err := tx.Table("task_assign_records").
|
||||||
|
Select("sum(status = 1) as progress_task_count, sum(status = 2) as complete_task_count").
|
||||||
|
Where("sub_num = ?", assignRecord.SubNum).
|
||||||
|
First(&stats).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
stats.ProgressTaskCount, stats.CompleteTaskCount = 0, 0
|
||||||
|
} else {
|
||||||
|
tx.Rollback()
|
||||||
|
return commonErr.ReturnError(err, "查询艺人任务指派记录失败", "查询艺人任务指派记录失败: ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4) 同步任务管理表的进行中与已完成数量(若不存在则创建)
|
||||||
|
var taskManagement model.TaskManagement
|
||||||
|
if err := tx.Where("sub_num = ? AND tel_num = ?", assignRecord.SubNum, assignRecord.TelNum).First(&taskManagement).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
// 创建新记录
|
||||||
|
taskManagement = model.TaskManagement{
|
||||||
|
SubNum: assignRecord.SubNum,
|
||||||
|
TelNum: assignRecord.TelNum,
|
||||||
|
ArtistName: assignRecord.ArtistName,
|
||||||
|
ProgressCount: stats.ProgressTaskCount,
|
||||||
|
CompleteCount: stats.CompleteTaskCount,
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
UpdatedAt: time.Now(),
|
||||||
|
}
|
||||||
|
if err := tx.Create(&taskManagement).Error; err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return commonErr.ReturnError(err, "创建任务记录失败", "创建任务记录失败: ")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tx.Rollback()
|
||||||
|
return commonErr.ReturnError(err, "查询任务记录失败", "查询任务记录失败: ")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
updateTM := map[string]interface{}{
|
||||||
|
"ProgressCount": stats.ProgressTaskCount,
|
||||||
|
"CompleteCount": stats.CompleteTaskCount,
|
||||||
|
"UpdatedAt": time.Now(),
|
||||||
|
}
|
||||||
|
if err := tx.Model(&taskManagement).Updates(updateTM).Error; err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return commonErr.ReturnError(err, "更新任务记录失败", "更新任务记录失败: ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5) 提交事务
|
||||||
|
if err := tx.Commit().Error; err != nil {
|
||||||
|
return commonErr.ReturnError(err, "提交事务失败", "提交事务失败: ")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1061,6 +1132,48 @@ func UpdatePendingCount(req *UpdatePendingCountRequest) error {
|
|||||||
return commonErr.ReturnError(err, "更新任务余额失败", "更新任务余额失败: ")
|
return commonErr.ReturnError(err, "更新任务余额失败", "更新任务余额失败: ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 同步更新任务管理表(视为一次指派操作)
|
||||||
|
var taskManagement model.TaskManagement
|
||||||
|
err := tx.Where("sub_num = ? AND tel_num = ?", req.SubNum, req.TelNum).First(&taskManagement).Error
|
||||||
|
if err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
taskManagement = model.TaskManagement{
|
||||||
|
SubNum: req.SubNum,
|
||||||
|
TelNum: req.TelNum,
|
||||||
|
ArtistName: req.ArtistName,
|
||||||
|
ProgressCount: 0,
|
||||||
|
CompleteCount: 0,
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
UpdatedAt: time.Now(),
|
||||||
|
}
|
||||||
|
if err = tx.Create(&taskManagement).Error; err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return commonErr.ReturnError(err, "创建任务记录失败", "创建任务记录失败: ")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tx.Rollback()
|
||||||
|
return commonErr.ReturnError(err, "查询任务记录失败", "查询任务记录失败: ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
progressTaskCount, completeTaskCount, err := GetArtistTaskStatsBySubNum(req.SubNum)
|
||||||
|
if err != nil {
|
||||||
|
// 查询不到的话,给一个默认值
|
||||||
|
progressTaskCount, completeTaskCount = 0, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
updateData := map[string]interface{}{
|
||||||
|
"ProgressCount": progressTaskCount + 1,
|
||||||
|
"CompleteCount": completeTaskCount,
|
||||||
|
"LastTaskAssignee": req.TaskAssignee,
|
||||||
|
"TaskAssigneeNum": req.TaskAssigneeNum,
|
||||||
|
"UpdatedAt": time.Now(),
|
||||||
|
}
|
||||||
|
if err = tx.Model(&taskManagement).Updates(updateData).Error; err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return commonErr.ReturnError(err, "更新任务记录失败", "更新任务记录失败: ")
|
||||||
|
}
|
||||||
|
|
||||||
// 写入操作日志(修改待发数量)
|
// 写入操作日志(修改待发数量)
|
||||||
assignRecord := &model.TaskAssignRecords{
|
assignRecord := &model.TaskAssignRecords{
|
||||||
AssignRecordsUUID: uuid.New().String(),
|
AssignRecordsUUID: uuid.New().String(),
|
||||||
@ -1179,7 +1292,7 @@ func GetTaskAssignRecordsList(req *TaskAssignRecordsQueryRequest) ([]*model.Task
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 按更新时间倒序排序
|
// 按更新时间倒序排序
|
||||||
err := query.Order("updated_at DESC").Find(&records).Error
|
err := query.Order("operator_time DESC").Find(&records).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, commonErr.ReturnError(err, "查询操作记录失败", "查询操作记录失败: ")
|
return nil, 0, commonErr.ReturnError(err, "查询操作记录失败", "查询操作记录失败: ")
|
||||||
}
|
}
|
||||||
@ -1235,28 +1348,53 @@ func GetValidArtistList() ([]ValidArtistInfo, error) {
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据员工的工号从指派任务记录表中查询这名员工,进行中任务数量和已经完成的任务数量
|
// // 根据艺人的手机号从指派任务记录表中查询这名艺人,进行中指派记录数量和已经完成的指派记录数量
|
||||||
func GetTaskAssigneeInfo(taskAssigneeNum string) (int, int, error) {
|
// func GetTaskAssigneeInfo(taskAssigneeNum string) (int, int, error) {
|
||||||
// 如果taskAssigneeNum为空,直接返回默认值
|
// // 如果tel为空,直接返回默认值
|
||||||
if taskAssigneeNum == "" {
|
// if taskAssigneeNum == "" {
|
||||||
|
// return 0, 0, nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var taskAssignRecords TaskAssignRecords
|
||||||
|
// err := app.ModuleClients.TaskBenchDB.Table("task_assign_records").
|
||||||
|
// Select("task_assignee_num, count(*) as progress_task_count, sum(status = 2) as complete_task_count").
|
||||||
|
// Where("task_assignee_num = ?", taskAssigneeNum).
|
||||||
|
// Group("task_assignee_num").
|
||||||
|
// First(&taskAssignRecords).Error
|
||||||
|
|
||||||
|
// // 如果查询不到记录,返回默认值而不是错误
|
||||||
|
// if err != nil {
|
||||||
|
// if err == gorm.ErrRecordNotFound {
|
||||||
|
// return 0, 0, nil
|
||||||
|
// }
|
||||||
|
// return 0, 0, commonErr.ReturnError(err, "查询任务指派记录失败", "查询任务指派记录失败: ")
|
||||||
|
// }
|
||||||
|
// return taskAssignRecords.ProgressTaskCount, taskAssignRecords.CompleteTaskCount, nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 新增:根据艺人手机号统计进行中的与已完成任务数量
|
||||||
|
func GetArtistTaskStatsBySubNum(SubNum string) (int, int, error) {
|
||||||
|
if SubNum == "" {
|
||||||
return 0, 0, nil
|
return 0, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var taskAssignRecords TaskAssignRecords
|
var res struct {
|
||||||
err := app.ModuleClients.TaskBenchDB.Table("task_assign_records").
|
ProgressTaskCount int
|
||||||
Select("task_assignee_num, count(*) as progress_task_count, sum(status = 2) as complete_task_count").
|
CompleteTaskCount int
|
||||||
Where("task_assignee_num = ?", taskAssigneeNum).
|
}
|
||||||
Group("task_assignee_num").
|
|
||||||
First(&taskAssignRecords).Error
|
err := app.ModuleClients.TaskBenchDB.Table("task_assign_records").
|
||||||
|
Select("sum(status = 1) as progress_task_count, sum(status = 2) as complete_task_count").
|
||||||
|
Where("sub_num = ?", SubNum).
|
||||||
|
First(&res).Error
|
||||||
|
|
||||||
// 如果查询不到记录,返回默认值而不是错误
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == gorm.ErrRecordNotFound {
|
if err == gorm.ErrRecordNotFound {
|
||||||
return 0, 0, nil
|
return 0, 0, nil
|
||||||
}
|
}
|
||||||
return 0, 0, commonErr.ReturnError(err, "查询任务指派记录失败", "查询任务指派记录失败: ")
|
return 0, 0, commonErr.ReturnError(err, "查询艺人任务记录失败", "查询艺人任务记录失败: ")
|
||||||
}
|
}
|
||||||
return taskAssignRecords.ProgressTaskCount, taskAssignRecords.CompleteTaskCount, nil
|
return res.ProgressTaskCount, res.CompleteTaskCount, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新被指派员工为 taskAssigneeNum 的记录中的ProgressCount + 1 和CompleteCount - 1
|
// 更新被指派员工为 taskAssigneeNum 的记录中的ProgressCount + 1 和CompleteCount - 1
|
||||||
|
@ -82,8 +82,8 @@ func GetPendingTaskList(req *dao.TaskQueryRequest) ([]*dao.TaskQueryResponse, in
|
|||||||
// 从TaskBalance表计算待发任务数量:任务余额 - 消耗数量
|
// 从TaskBalance表计算待发任务数量:任务余额 - 消耗数量
|
||||||
videoTotal, imageTotal, dataTotal := calculatePendingFromTaskBalance(record.SubNum)
|
videoTotal, imageTotal, dataTotal := calculatePendingFromTaskBalance(record.SubNum)
|
||||||
|
|
||||||
// 根据 SubNum 和 TelNum 查询对应的员工正在进行中的任务和已完成任务数量
|
// 根据 SubNum 查询对应的艺人正在进行中的任务和已完成任务数量
|
||||||
progressTaskCount, completeTaskCount, err := dao.GetTaskAssigneeInfo(record.TaskAssigneeNum)
|
progressTaskCount, completeTaskCount, err := dao.GetArtistTaskStatsBySubNum(record.SubNum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
recordResponse = append(recordResponse, &dao.TaskQueryResponse{
|
recordResponse = append(recordResponse, &dao.TaskQueryResponse{
|
||||||
SubNum: record.SubNum,
|
SubNum: record.SubNum,
|
||||||
@ -188,10 +188,10 @@ func AssignTask(req *dao.TaskAssignRequest) error {
|
|||||||
return commonErr.ReturnError(nil, "员工不能被指派任务", "该员工不在可指派任务的员工列表中")
|
return commonErr.ReturnError(nil, "员工不能被指派任务", "该员工不在可指派任务的员工列表中")
|
||||||
}
|
}
|
||||||
|
|
||||||
progressTaskCount, completeTaskCount, err := dao.GetTaskAssigneeInfo(req.TaskAssigneeNum)
|
progressTaskCount, completeTaskCount, err := dao.GetArtistTaskStatsBySubNum(req.SubNum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 查询不到的话,给一个默认值
|
// 查询不到的话,给一个默认值
|
||||||
progressTaskCount, completeTaskCount = 1, 0
|
progressTaskCount, completeTaskCount = 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 调用DAO层执行指派任务
|
// 2. 调用DAO层执行指派任务
|
||||||
@ -257,6 +257,35 @@ func GetEmployeeAssignedTasks(req *dao.EmployeeTaskQueryRequest) ([]*dao.TaskAss
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果查询的 status = 2 的话,待发数量就为指派时,指派的数量
|
||||||
|
if req.Status == 2 {
|
||||||
|
var recordResponse []*dao.TaskAssignRecordsResponse
|
||||||
|
for _, record := range record {
|
||||||
|
recordResponse = append(recordResponse, &dao.TaskAssignRecordsResponse{
|
||||||
|
AssignRecordsUUID: record.AssignRecordsUUID,
|
||||||
|
SubNum: record.SubNum,
|
||||||
|
TelNum: record.TelNum,
|
||||||
|
ArtistName: record.ArtistName,
|
||||||
|
Status: record.Status,
|
||||||
|
ActualStatus: record.ActualStatus,
|
||||||
|
CompleteTime: record.CompleteTime,
|
||||||
|
OperatorType: record.OperatorType,
|
||||||
|
Operator: record.Operator,
|
||||||
|
OperatorNum: record.OperatorNum,
|
||||||
|
OperatorTime: record.OperatorTime,
|
||||||
|
TaskAssignee: record.TaskAssignee,
|
||||||
|
TaskAssigneeNum: record.TaskAssigneeNum,
|
||||||
|
PendingVideoCount: record.AssignVideoCount,
|
||||||
|
PendingPostCount: record.AssignPostCount,
|
||||||
|
PendingDataCount: record.AssignDataCount,
|
||||||
|
// todo: 将更新时间转换成人类可读的格式
|
||||||
|
UpdatedAt: record.UpdatedAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return recordResponse, total, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 2. 转换为响应结构体
|
// 2. 转换为响应结构体
|
||||||
var recordResponse []*dao.TaskAssignRecordsResponse
|
var recordResponse []*dao.TaskAssignRecordsResponse
|
||||||
for _, record := range record {
|
for _, record := range record {
|
||||||
|
@ -13,7 +13,7 @@ type TaskManagement struct {
|
|||||||
ArtistName string `gorm:"column:artist_name;comment:艺人名称;index:idx_artist_name" json:"artistName"`
|
ArtistName string `gorm:"column:artist_name;comment:艺人名称;index:idx_artist_name" json:"artistName"`
|
||||||
|
|
||||||
LastTaskAssignee string `gorm:"column:last_task_assignee;comment:最后一次的任务指派人" json:"lastTaskAssignee"`
|
LastTaskAssignee string `gorm:"column:last_task_assignee;comment:最后一次的任务指派人" json:"lastTaskAssignee"`
|
||||||
TaskAssigneeNum string `gorm:"column:task_assignee_num;comment:任务指派人账号" json:"taskAssigneeNum"`
|
TaskAssigneeNum string `gorm:"column:task_assignee_num;comment:最后一次的任务指派人账号" json:"taskAssigneeNum"`
|
||||||
ProgressCount int `gorm:"column:progress_count;comment:进行中的任务数量" json:"progressCount"`
|
ProgressCount int `gorm:"column:progress_count;comment:进行中的任务数量" json:"progressCount"`
|
||||||
CompleteCount int `gorm:"column:complete_count;comment:已完成的任务数量" json:"completeCount"`
|
CompleteCount int `gorm:"column:complete_count;comment:已完成的任务数量" json:"completeCount"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
||||||
|
Loading…
Reference in New Issue
Block a user