313 lines
10 KiB
Go
313 lines
10 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 查询艺人的当前任务余额与待发数量(区分套餐/增值两类)
|
||
// 说明:
|
||
// - 查询条件优先使用艺人编号(customerNum),为空时使用手机号(telNum)
|
||
// - 返回同时包含“套餐类型”和“增值类型”的余额与待发数量,均按视频/图文/数据分析三类区分
|
||
func (b *BundleProvider) GetArtistBundleBalance(_ context.Context, req *bundle.ArtistBundleBalanceRequest) (*bundle.ArtistBundleBalanceResponse, error) {
|
||
// 参数校验
|
||
if req.CustomerNum == "" && req.TelNum == "" {
|
||
return nil, fmt.Errorf("艺人编号和手机号不能同时为空")
|
||
}
|
||
|
||
// 组装查询参数(逻辑层/DAO层使用 SubNum 与 TelNum)
|
||
pendingReq := &dao.PendingAndBalanceRequest{
|
||
SubNum: req.CustomerNum, // 映射 customerNum -> SubNum
|
||
TelNum: req.TelNum, // 映射 telNum -> TelNum
|
||
}
|
||
|
||
// 调用逻辑层:查询待发数量与任务余额(区分套餐/增值)
|
||
resp, err := logic.GetPendingAndTaskBalances(pendingReq)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
// 映射为proto响应结构(套餐/增值分别返回视频/图文/数据分析的余额与待发数量)
|
||
return &bundle.ArtistBundleBalanceResponse{
|
||
// 套餐类型余额
|
||
BundleVideoBalance: int32(resp.BundleVideoBalance),
|
||
BundleImageBalance: int32(resp.BundleImageBalance),
|
||
BundleDataAnalysisBalance: int32(resp.BundleDataAnalysisBalance),
|
||
// 增值类型余额
|
||
IncreaseVideoBalance: int32(resp.IncreaseVideoBalance),
|
||
IncreaseImageBalance: int32(resp.IncreaseImageBalance),
|
||
IncreaseDataAnalysisBalance: int32(resp.IncreaseDataAnalysisBalance),
|
||
// 套餐类型待发数量
|
||
BundlePendingVideoCount: int32(resp.PendingBundleVideoCount),
|
||
BundlePendingImageCount: int32(resp.PendingBundleImageCount),
|
||
BundlePendingDataAnalysisCount: int32(resp.PendingBundleDataAnalysisCount),
|
||
// 增值类型待发数量
|
||
IncreasePendingVideoCount: int32(resp.PendingIncreaseVideoCount),
|
||
IncreasePendingImageCount: int32(resp.PendingIncreaseImageCount),
|
||
IncreasePendingDataAnalysisCount: int32(resp.PendingIncreaseDataAnalysisCount),
|
||
}, nil
|
||
}
|