297 lines
8.9 KiB
Go
297 lines
8.9 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"micro-bundle/internal/dao"
|
|
"micro-bundle/internal/logic"
|
|
"micro-bundle/pb/bundle"
|
|
)
|
|
|
|
// GetPendingTaskList 查询待指派任务记录
|
|
func (b *BundleProvider) GetPendingTaskList(_ context.Context, req *bundle.TaskQueryRequest) (*bundle.TaskQueryResponse, error) {
|
|
// 转换请求参数
|
|
daoReq := &dao.TaskQueryRequest{
|
|
Keyword: req.Keyword,
|
|
Page: int(req.Page),
|
|
PageSize: int(req.PageSize),
|
|
SortBy: req.SortBy,
|
|
SortType: req.SortType,
|
|
}
|
|
|
|
// 调用logic层
|
|
tasks, total, err := logic.GetPendingTaskList(daoReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 转换响应数据
|
|
var taskInfos []*bundle.TaskManagementInfo
|
|
for _, task := range tasks {
|
|
taskInfo := &bundle.TaskManagementInfo{
|
|
SubNum: task.SubNum,
|
|
TelNum: task.TelNum,
|
|
ArtistName: task.ArtistName,
|
|
PendingVideoCount: int32(task.PendingVideoCount),
|
|
PendingPostCount: int32(task.PendingPostCount),
|
|
PendingDataCount: int32(task.PendingDataCount),
|
|
ProgressTaskCount: int32(task.ProgressTaskCount),
|
|
CompleteTaskCount: int32(task.CompleteTaskCount),
|
|
LastTaskAssignee: task.LastTaskAssignee,
|
|
TaskAssigneeNum: task.TaskAssigneeNum,
|
|
}
|
|
taskInfos = append(taskInfos, taskInfo)
|
|
}
|
|
|
|
return &bundle.TaskQueryResponse{
|
|
Tasks: taskInfos,
|
|
Total: total,
|
|
Page: req.Page,
|
|
PageSize: req.PageSize,
|
|
}, nil
|
|
}
|
|
|
|
// AssignTask 指派某位员工完成某个艺人的任务
|
|
// AssignTask 指派某位员工完成某个艺人的任务
|
|
func (b *BundleProvider) AssignTask(_ context.Context, req *bundle.TaskAssignRequest) (*bundle.CommonResponse, error) {
|
|
// 转换请求参数
|
|
daoReq := &dao.TaskAssignRequest{
|
|
SubNum: req.SubNum,
|
|
TelNum: req.TelNum,
|
|
ArtistName: req.ArtistName, // 添加缺失的ArtistName字段
|
|
TaskAssignee: req.TaskAssignee,
|
|
TaskAssigneeNum: req.TaskAssigneeNum,
|
|
Operator: req.Operator,
|
|
OperatorNum: req.OperatorNum,
|
|
AssignVideoCount: int(req.AssignVideoCount),
|
|
AssignPostCount: int(req.AssignPostCount),
|
|
AssignDataCount: int(req.AssignDataCount),
|
|
}
|
|
|
|
// 调用logic层
|
|
err := logic.AssignTask(daoReq)
|
|
if err != nil {
|
|
return &bundle.CommonResponse{
|
|
Msg: err.Error(),
|
|
}, err
|
|
}
|
|
|
|
return &bundle.CommonResponse{
|
|
Msg: "任务指派成功",
|
|
}, nil
|
|
}
|
|
|
|
// UpdatePendingCount 修改待发数量
|
|
func (b *BundleProvider) UpdatePendingCount(_ context.Context, req *bundle.UpdatePendingCountRequest) (*bundle.CommonResponse, error) {
|
|
// 转换请求参数
|
|
daoReq := &dao.UpdatePendingCountRequest{
|
|
SubNum: req.SubNum,
|
|
TelNum: req.TelNum,
|
|
ArtistName: req.ArtistName, // 添加缺失的ArtistName字段
|
|
PendingVideoCount: int(req.PendingVideoCount),
|
|
PendingPostCount: int(req.PendingPostCount),
|
|
PendingDataCount: int(req.PendingDataCount),
|
|
Operator: req.Operator,
|
|
OperatorNum: req.OperatorNum,
|
|
}
|
|
|
|
// 调用logic层
|
|
err := logic.UpdatePendingCount(daoReq)
|
|
if err != nil {
|
|
return &bundle.CommonResponse{
|
|
Msg: err.Error(),
|
|
}, err
|
|
}
|
|
|
|
return &bundle.CommonResponse{
|
|
Msg: "待发数量修改成功",
|
|
}, nil
|
|
}
|
|
|
|
// GetRecentAssignRecords 查询最近被指派记录
|
|
func (b *BundleProvider) GetRecentAssignRecords(_ context.Context, req *bundle.RecentAssignRecordsRequest) (*bundle.RecentAssignRecordsResponse, error) {
|
|
limit := int(req.Limit)
|
|
if limit == 0 {
|
|
limit = 3 // 默认查询3条
|
|
}
|
|
|
|
// 调用logic层
|
|
operatorList, err := logic.GetRecentAssignRecords(limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &bundle.RecentAssignRecordsResponse{
|
|
OperatorList: operatorList,
|
|
}, nil
|
|
}
|
|
|
|
// GetEmployeeAssignedTasks 根据登录人信息查询被指派给该员工的任务
|
|
func (b *BundleProvider) GetEmployeeAssignedTasks(_ context.Context, req *bundle.EmployeeTaskQueryRequest) (*bundle.EmployeeTaskQueryResponse, error) {
|
|
// 转换请求参数
|
|
daoReq := &dao.EmployeeTaskQueryRequest{
|
|
TaskAssigneeNum: req.TaskAssigneeNum,
|
|
Keyword: req.Keyword,
|
|
Operator: req.Operator,
|
|
SortBy: req.SortBy,
|
|
StartTime: req.StartTime,
|
|
EndTime: req.EndTime,
|
|
StartCompleteTime: req.StartCompleteTime,
|
|
EndCompleteTime: req.EndCompleteTime,
|
|
Status: int(req.Status),
|
|
Page: int(req.Page),
|
|
PageSize: int(req.PageSize),
|
|
}
|
|
|
|
// 调用logic层
|
|
records, total, err := logic.GetEmployeeAssignedTasks(daoReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 转换响应数据
|
|
var recordInfos []*bundle.TaskAssignRecordInfo
|
|
for _, record := range records {
|
|
recordInfo := convertToTaskAssignRecordInfo(record)
|
|
recordInfos = append(recordInfos, recordInfo)
|
|
}
|
|
|
|
return &bundle.EmployeeTaskQueryResponse{
|
|
Records: recordInfos,
|
|
Total: total,
|
|
Page: req.Page,
|
|
PageSize: req.PageSize,
|
|
}, nil
|
|
}
|
|
|
|
// CompleteTaskManually 员工手动点击完成任务
|
|
func (b *BundleProvider) CompleteTaskManually(_ context.Context, req *bundle.CompleteTaskManuallyRequest) (*bundle.CommonResponse, error) {
|
|
// 调用logic层
|
|
err := logic.CompleteTaskManually(req.AssignRecordsUUID, req.TaskAssigneeNum)
|
|
if err != nil {
|
|
return &bundle.CommonResponse{
|
|
Msg: err.Error(),
|
|
}, err
|
|
}
|
|
|
|
return &bundle.CommonResponse{
|
|
Msg: "任务完成状态更新成功",
|
|
}, nil
|
|
}
|
|
|
|
// UpdateTaskProgress 员工实际完成任务状态更新
|
|
func (b *BundleProvider) UpdateTaskProgress(_ context.Context, req *bundle.UpdateTaskProgressRequest) (*bundle.CommonResponse, error) {
|
|
// 转换请求参数
|
|
daoReq := &dao.CompleteTaskRequest{
|
|
AssignRecordsUUID: req.AssignRecordsUUID,
|
|
EmployeeName: req.EmployeeName,
|
|
EmployeeNum: req.EmployeeNum,
|
|
TaskType: req.TaskType,
|
|
CompleteCount: int(req.CompleteCount),
|
|
}
|
|
|
|
// 调用logic层
|
|
err := logic.UpdateTaskProgress(daoReq)
|
|
if err != nil {
|
|
return &bundle.CommonResponse{
|
|
Msg: err.Error(),
|
|
}, err
|
|
}
|
|
|
|
return &bundle.CommonResponse{
|
|
Msg: "任务进度更新成功",
|
|
}, nil
|
|
}
|
|
|
|
// GetTaskAssignRecordsList 多条件查询操作记录表
|
|
func (b *BundleProvider) GetTaskAssignRecordsList(_ context.Context, req *bundle.TaskAssignRecordsQueryRequest) (*bundle.TaskAssignRecordsQueryResponse, error) {
|
|
// 转换请求参数
|
|
daoReq := &dao.TaskAssignRecordsQueryRequest{
|
|
Keyword: req.Keyword,
|
|
TaskAssignee: req.TaskAssignee,
|
|
Operator: req.Operator,
|
|
OperatorNum: req.OperatorNum,
|
|
StartTime: req.StartTime,
|
|
EndTime: req.EndTime,
|
|
Status: int(req.Status),
|
|
ActualStatus: int(req.ActualStatus),
|
|
Page: int(req.Page),
|
|
PageSize: int(req.PageSize),
|
|
}
|
|
|
|
// 调用logic层
|
|
records, total, err := logic.GetTaskAssignRecordsList(daoReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 转换响应数据
|
|
var recordInfos []*bundle.TaskAssignRecordInfo
|
|
for _, record := range records {
|
|
recordInfo := convertToTaskAssignRecordInfo(record)
|
|
recordInfos = append(recordInfos, recordInfo)
|
|
}
|
|
|
|
return &bundle.TaskAssignRecordsQueryResponse{
|
|
Records: recordInfos,
|
|
Total: total,
|
|
Page: req.Page,
|
|
PageSize: req.PageSize,
|
|
}, nil
|
|
}
|
|
|
|
// convertToTaskAssignRecordInfo 转换TaskAssignRecords模型为proto消息
|
|
func convertToTaskAssignRecordInfo(record *dao.TaskAssignRecordsResponse) *bundle.TaskAssignRecordInfo {
|
|
var completeTime string
|
|
if record.CompleteTime != nil {
|
|
completeTime = record.CompleteTime.Format("2006-01-02 15:04:05")
|
|
}
|
|
|
|
return &bundle.TaskAssignRecordInfo{
|
|
AssignRecordsUUID: record.AssignRecordsUUID,
|
|
SubNum: record.SubNum,
|
|
TelNum: record.TelNum,
|
|
ArtistName: record.ArtistName,
|
|
Status: int32(record.Status),
|
|
ActualStatus: int32(record.ActualStatus),
|
|
CompleteTime: completeTime,
|
|
OperatorType: int32(record.OperatorType),
|
|
Operator: record.Operator,
|
|
OperatorNum: record.OperatorNum,
|
|
OperatorTime: record.OperatorTime.Format("2006-01-02 15:04:05"),
|
|
TaskAssignee: record.TaskAssignee,
|
|
TaskAssigneeNum: record.TaskAssigneeNum,
|
|
PendingVideoCount: int32(record.PendingVideoCount),
|
|
PendingPostCount: int32(record.PendingPostCount),
|
|
PendingDataCount: int32(record.PendingDataCount),
|
|
UpdatedAt: record.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
}
|
|
}
|
|
|
|
// GetArtistBundleBalance 查询艺人套餐剩余数量
|
|
func (b *BundleProvider) GetArtistBundleBalance(_ context.Context, req *bundle.ArtistBundleBalanceRequest) (*bundle.ArtistBundleBalanceResponse, error) {
|
|
// 参数验证
|
|
if req.CustomerNum == "" && req.TelNum == "" {
|
|
return nil, fmt.Errorf("艺人编号和手机号不能同时为空")
|
|
}
|
|
|
|
// 转换请求参数
|
|
daoReq := &dao.ArtistBundleBalanceRequest{
|
|
CustomerNum: req.CustomerNum,
|
|
TelNum: req.TelNum,
|
|
}
|
|
|
|
// 调用logic层
|
|
result, err := logic.GetArtistBundleBalance(daoReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 转换响应数据
|
|
return &bundle.ArtistBundleBalanceResponse{
|
|
RemainingVideoCount: int32(result.RemainingVideoCount),
|
|
RemainingImageCount: int32(result.RemainingImageCount),
|
|
RemainingDataAnalysisCount: int32(result.RemainingDataAnalysisCount),
|
|
}, nil
|
|
}
|