using DS.Module.Core; using DS.Module.Core.Attributes; using DS.Module.Core.Data; using DS.Module.DjyServiceStatus; using DS.WMS.Core.Invoice.Dtos; using DS.WMS.Core.TaskPlat; using DS.WMS.Core.TaskPlat.Dtos; using DS.WMS.Core.TaskPlat.Interface; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; namespace DS.WMS.TaskApi.Controllers; /// /// 任务台相关接口 /// public class TaskManageController : ApiController { private readonly ITaskManageService taskManageService; public TaskManageController(ITaskManageService taskManageService) { this.taskManageService = taskManageService; } /// /// 创建任务 /// /// 任务详情 /// 返回回执 [HttpPost("CreateTaskJob")] [ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous] public async Task CreateTaskJob(TaskManageOrderMessageInfo info) { var result = await taskManageService.InitTaskJob(info); return result; } /// /// 创建BC任务 /// /// 文件 /// BC变更内容后文件 /// BC任务详情JSON /// 返回回执 [HttpPost("CreateBCTaskJob")] [ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous] public async Task CreateBCTaskJob(IFormFile file, IFormFile modifyFile, [FromForm] string jsonData) { TaskManageOrderMessageInfo? info = JsonConvert.DeserializeObject(jsonData); if (info == null) { throw new ArgumentException(nameof(jsonData)); } var result = await taskManageService.InitTaskJob(info, file, modifyFile); return result; } /// /// (测试)工作流设置任务在个人下的状态 /// [HttpPost("SetTaskUserStatus")] [ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous] public async Task SetTaskUserStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime, [FromBody] List userInfos) { var result = await taskManageService.SetTaskUserStatus(bsno, taskBaseTypeEnum, taskStatusEnum, statusTime, userInfos); return result; } /// /// (测试)工作流设置任务状态 /// [HttpPost("SetTaskStatus")] [ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous] public async Task SetTaskStatus(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, TaskStatusEnum taskStatusEnum, DateTime? statusTime) { var result = await taskManageService.SetTaskStatus(bsno, taskBaseTypeEnum, taskStatusEnum, statusTime); return result; } /// /// (测试)工作流转交任务 /// [HttpPost("TransferTask")] [ApiUser(ApiCode = "BCTaskManage"), AllowAnonymous] public async Task TransferTask(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, List userInfos) { var result = await taskManageService.TransferTask(bsno, taskBaseTypeEnum, userInfos); return result; } /// /// 任务台台账列表查询 /// [HttpPost("GetPageAsync")] public async Task>> GetPageAsync(PageRequest querySearch) { var result = await taskManageService.GetPageAsync(querySearch); return result; } /// /// 获取登陆人相关的任务统计信息 /// [HttpPost("GetCurrentTotalStat")] public async Task> GetCurrentTotalStat(GetCurrentTotalStatQueryDto querySearch) { var result = await taskManageService.GetCurrentTotalStat(querySearch); return result; } /// /// 完成任务(可批量) /// /// 任务主键数组 /// 返回结果 [HttpPost("CompleteTask")] public async Task> CompleteTask([FromBody] long[] Ids) { var result = await taskManageService.CompleteTask(Ids); return result; } /// /// 取消任务(可批量) /// /// 任务主键数组 /// 返回结果 [HttpPost("CancelTask")] public async Task> CancelTask([FromBody] long[] Ids) { var result = await taskManageService.CancelTask(Ids); return result; } /// /// 获取任务台相关的枚举类型的值 /// [HttpPost("GetTaskPlatEnumDict")] public DataResult GetTaskPlatEnumDict() { Dictionary> dict = new() { { "STATUS", EnumUtil.GetEnumDictionaryWithKey(typeof(TaskStatusEnum)) .Select(x => (x.Key.ToString(), x.Value)) .ToList() }, { "TASK_TYPE", EnumUtil.GetEnumDictionaryWithKey(typeof(TaskBaseTypeEnum)) .Select(x => (x.Key.ToString(), x.Value)) .ToList() }, { "SOURCE", EnumUtil.GetEnumDictionaryWithKey(typeof(TaskSourceEnum)) .Select(x => (x.Key.ToString(), x.Value)) .ToList() }, { "CATEGORY", EnumUtil.GetEnumDictionaryWithKey(typeof(TaskStatLevelEnum)) .Select(x => (x.Key.ToString(), x.Value)) .ToList() } }; var result = dict.Select(x => new { Type = x.Key, Data = x.Value.Select(y => new { Code = y.key, Name = y.value }) }); return DataResult.Success(result); } /// /// 设置任务处理人(可批量) /// /// /// [HttpPost("SetTaskOwner")] public async Task SetTaskOwner([FromQuery] long[] taskIds, [FromBody] List userInfo) { await taskManageService.SetTaskOwner(taskIds, userInfo); return DataResult.SuccessedWithDesc(nameof(MultiLanguageConst.OperationSuccess)); } /// /// 根据任务ID下载附件 /// /// 任务主键 /// 附件分类代码 /// 返回数据流 [HttpGet("DownloadFile")] public async Task DownloadFile([FromQuery] long taskId, [FromQuery] string fileCategory = "BC") { (string fileFullPath, string fileName) = await taskManageService.GetTaskFileInfo(taskId, fileCategory); return PhysicalFile(fileFullPath, "application/octet-stream", fileName); } /// /// 测试用 /// [HttpGet("TestTaskFlow")] public async Task TestTaskFlow([FromQuery] string taskType, [FromQuery] long taskId, [FromQuery] int testType) { return await taskManageService.TestTaskFlow(taskType, taskId, testType); } }