添加接口:领取任务到当前登陆人(可批量)

dev
zhangxiaofeng 2 months ago
parent 42a38dc2e9
commit bb89b21bd9

@ -79,5 +79,10 @@ namespace DS.WMS.Core.TaskPlat.Interface
/// 测试用 /// 测试用
/// </summary> /// </summary>
Task<DataResult> TestTaskFlow(string taskType, long taskId, int testType); Task<DataResult> TestTaskFlow(string taskType, long taskId, int testType);
/// <summary>
/// 领取任务到当前登陆人(可批量)
/// </summary>
Task<DataResult> PullTask(long[] ids);
} }
} }

@ -148,7 +148,6 @@ namespace DS.WMS.Core.TaskPlat.Method
} }
// 用于更新工作流的任务 // 用于更新工作流的任务
var userIdStr = string.Join(',', userInfo.Select(x => x.RecvUserId)); var userIdStr = string.Join(',', userInfo.Select(x => x.RecvUserId));
var businessIdList = taskList.Where(x => x.OUT_BS_NO != null && x.OUT_BS_NO != 0).Select(x => x.OUT_BS_NO).Distinct().ToList();
//await tenantDb.Ado.BeginTranAsync(); //await tenantDb.Ado.BeginTranAsync();
await tenantDb.AsTenant().BeginTranAsync(); await tenantDb.AsTenant().BeginTranAsync();
@ -171,17 +170,17 @@ namespace DS.WMS.Core.TaskPlat.Method
.Where(x => x.BusinessId == item.OUT_BS_NO && x.TaskType == (TaskBaseTypeEnum)taskType) .Where(x => x.BusinessId == item.OUT_BS_NO && x.TaskType == (TaskBaseTypeEnum)taskType)
.ExecuteCommandAsync(); .ExecuteCommandAsync();
var id = await db.Queryable<FlowInstance>() var flowInstanceId = await db.Queryable<FlowInstance>()
.ClearFilter(typeof(ITenantId)) .ClearFilter(typeof(ITenantId))
.Where(y => y.BusinessId == item.OUT_BS_NO && y.AuditType == (TaskBaseTypeEnum)taskType) .Where(y => y.BusinessId == item.OUT_BS_NO && y.AuditType == (TaskBaseTypeEnum)taskType)
.OrderByDescending(y => y.Id) .OrderByDescending(y => y.Id)
.Select(y => y.Id) .Select(y => y.Id)
.FirstAsync(); .FirstAsync();
if (id != 0) if (flowInstanceId != 0)
{ {
await db.Updateable<FlowInstance>() await db.Updateable<FlowInstance>()
.SetColumns(x => x.MakerList == userIdStr) .SetColumns(x => x.MakerList == userIdStr)
.Where(x => x.Id == id) .Where(x => x.Id == flowInstanceId)
.ExecuteCommandAsync(); .ExecuteCommandAsync();
} }
} }

@ -11,10 +11,12 @@ using DS.Module.UserModule;
using DS.WMS.Core.Code.Dtos; using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Entity; using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Code.Interface; using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.Flow.Entity;
using DS.WMS.Core.Map.Dtos; using DS.WMS.Core.Map.Dtos;
using DS.WMS.Core.Map.Interface; using DS.WMS.Core.Map.Interface;
using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Entity.TaskInteraction;
using DS.WMS.Core.Sys.Entity; using DS.WMS.Core.Sys.Entity;
using DS.WMS.Core.Sys.Interface; using DS.WMS.Core.Sys.Interface;
using DS.WMS.Core.TaskPlat.Dtos; using DS.WMS.Core.TaskPlat.Dtos;
@ -2805,7 +2807,7 @@ namespace DS.WMS.Core.TaskPlat.Method
// 下属任务统计 // 下属任务统计
/* /*
* *
* self_org * self_org
* all * all
* none * none
@ -3419,6 +3421,105 @@ namespace DS.WMS.Core.TaskPlat.Method
} }
/// <summary>
/// 领取任务到当前登陆人(可批量)
/// </summary>
public async Task<DataResult> PullTask(long[] ids)
{
if (ids == null || ids.Length == 0)
{
throw new ArgumentNullException(nameof(ids));
}
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
tenantDb.QueryFilter.Clear<IOrgId>();
var userId = long.Parse(user.UserId);
try
{
var taskList = await tenantDb.Queryable<TaskBaseInfo>().Where(x => ids.Contains(x.Id)).ToListAsync(x => new
{
x.Id,
x.STATUS,
x.STATUS_NAME,
x.TASK_TYPE,
x.OUT_BS_NO,
x.TASK_SOURCE
});
var taskIdList = taskList.Select(x => x.Id).ToList();
var taskTypeList = taskList.Where(x => x.TASK_SOURCE == TaskSourceEnum.WORK_FLOW.ToString() && x.OUT_BS_NO != null).Select(x => x.TASK_TYPE).Distinct().ToList();
var taskCompleteStatusCodeList = taskTypeList.Count > 0 ? await tenantDb.Queryable<TaskFlowModule>()
.Where(x => x.ModuleType == 2 && taskTypeList.Contains(x.TaskType))
.Select(x => new { x.TaskType, x.CompletedBusinessStatusCode })
.ToListAsync()
: [];
var userOrgId = await db.Queryable<SysUser>().Where(x => x.Id == userId).Select(x => x.DefaultOrgId).FirstAsync();
List<TaskBaseAllocation> allocationList = new();
foreach (var item in taskList)
{
allocationList.Add(new TaskBaseAllocation()
{
TaskId = item.Id,
UserId = userId,
UserName = user.UserName,
Status = item.STATUS,
StatusName = item.STATUS_NAME,
StatusTime = DateTime.Now,
BusinessId = item.OUT_BS_NO,
GoodStatusCode = taskCompleteStatusCodeList.FirstOrDefault(x => x.TaskType == item.TASK_TYPE)?.CompletedBusinessStatusCode,
OrgId = userOrgId
});
}
await tenantDb.AsTenant().BeginTranAsync();
var idList = await tenantDb.Queryable<TaskBaseAllocation>().Where(x => taskIdList.Contains(x.TaskId)).Select(x => x.Id).ToListAsync();
await tenantDb.Deleteable<TaskBaseAllocation>(x => idList.Contains(x.Id)).ExecuteCommandAsync();
await tenantDb.Insertable(allocationList).ExecuteCommandAsync();
await tenantDb.Updateable<TaskBaseInfo>()
.SetColumns(x => x.IS_PUBLIC == 0)
.Where(x => taskIdList.Contains(x.Id))
.ExecuteCommandAsync();
foreach (var item in taskList)
{
if (item.OUT_BS_NO is not null or 0 && Enum.TryParse(typeof(TaskBaseTypeEnum), item.TASK_TYPE, out object? taskType))
{
await tenantDb.Updateable<BusinessTask>()
.SetColumns(x => x.RecvUsers == user.UserId)
.Where(x => x.BusinessId == item.OUT_BS_NO && x.TaskType == (TaskBaseTypeEnum)taskType)
.ExecuteCommandAsync();
var flowInstanceId = await db.Queryable<FlowInstance>()
.ClearFilter(typeof(ITenantId))
.Where(y => y.BusinessId == item.OUT_BS_NO && y.AuditType == (TaskBaseTypeEnum)taskType)
.OrderByDescending(y => y.Id)
.Select(y => y.Id)
.FirstAsync();
if (flowInstanceId != 0)
{
await db.Updateable<FlowInstance>()
.SetColumns(x => x.MakerList == user.UserId)
.Where(x => x.Id == flowInstanceId)
.ExecuteCommandAsync();
}
}
}
await tenantDb.AsTenant().CommitTranAsync();
return DataResult.Successed("操作成功", MultiLanguageConst.OperationSuccess);
}
catch (Exception ex)
{
await tenantDb.AsTenant().RollbackTranAsync();
return DataResult.Failed("任务领取失败,原因:" + ex.Message);
}
}
@ -3451,15 +3552,16 @@ namespace DS.WMS.Core.TaskPlat.Method
try try
{ {
await tenantDb.Ado.BeginTranAsync(); await tenantDb.Ado.BeginTranAsync();
var t1 = tenantDb.ContextID; await tenantDb.Deleteable<SeaExport>().Where(x => x.BusinessStatus == "0123123").ExecuteCommandAsync();
var t2 = await tenantDb.Queryable<TaskFlowLogDetail>().Where(x => x.Id == taskId).ToListAsync(); //var t1 = tenantDb.ContextID;
var m = new TaskFlowLogDetail() //var t2 = await tenantDb.Queryable<TaskFlowLogDetail>().Where(x => x.Id == taskId).ToListAsync();
{ //var m = new TaskFlowLogDetail()
ModuleName = taskId.ToString() //{
}; // ModuleName = taskId.ToString()
var t3 = await tenantDb.Insertable(m).ExecuteCommandAsync(); //};
//var t3 = await tenantDb.Insertable(m).ExecuteCommandAsync();
var service = serviceProvider.GetRequiredService<ITaskManageBCService>();
//var service = serviceProvider.GetRequiredService<ITaskManageBCService>();
//await service.TestDelete(taskId); //await service.TestDelete(taskId);
await tenantDb.Ado.CommitTranAsync(); await tenantDb.Ado.CommitTranAsync();

@ -219,4 +219,13 @@ public class TaskManageController : ApiController
{ {
return await taskManageService.TestTaskFlow(taskType, taskId, testType); return await taskManageService.TestTaskFlow(taskType, taskId, testType);
} }
/// <summary>
/// 领取任务到当前登陆人(可批量)
/// </summary>
[HttpPost("PullTask")]
public async Task<DataResult> PullTask([FromBody] long[] Ids)
{
return await taskManageService.PullTask(Ids);
}
} }

@ -93,11 +93,9 @@ public class SaasDBUpdateTest
//tenantDb.CodeFirst.InitTables(typeof(TaskBaseAllocation)); //tenantDb.CodeFirst.InitTables(typeof(TaskBaseAllocation));
// SQL更新 // SQL更新
string sql = @"ALTER TABLE `task_base_allocation` string sql = @"update task_base_allocation b set OrgId = ifnull((select defaultOrgId from shippingweb8_dev.sys_user where id = b.UserId),0)";
MODIFY COLUMN `OrgId` bigint(0) NULL DEFAULT NULL COMMENT 'Id' AFTER `BusinessId`;";
tenantDb.Ado.ExecuteCommand(sql); tenantDb.Ado.ExecuteCommand(sql);
// DROP TRIGGER `tr_task_no`; // DROP TRIGGER `tr_task_no`;
} }

Loading…
Cancel
Save