任务分配维护相关

usertest
zhangxiaofeng 4 months ago
parent 1bd75eb122
commit 6b3f94ab6e

@ -2,7 +2,8 @@
namespace DS.WMS.Core.TaskPlat.Dtos
{
public class SaveTaskAllocationSettingDto
public class TaskAllocationtSetSaveDto
{
/// <summary>
/// 分配对象编码 Operator=操作 VouchingClerk=单证 Sale=销售 Custom=报关员 FinancialStaff=财务 CustomerService=客服 Driver=司机 Dispatcher=派车调度人员

@ -14,7 +14,7 @@ namespace DS.WMS.Core.TaskPlat.Dtos
public TaskBaseTypeEnum TaskType { get; set; }
/// <summary>
/// 校验任务类型重复是否判断任务类型
/// 校验任务重复是否判断任务类型
/// </summary>
public bool IsCheckExistsByTaskType { get; set; }

@ -10,7 +10,7 @@ namespace DS.WMS.Core.TaskPlat.Entity
public class TaskAllocationtSet : BaseModelV2<long>
{
/// <summary>
/// 任务类型
/// 任务类型编码
/// </summary>
[SugarColumn(ColumnDescription = "任务类型编码", IsNullable = false, Length = 40)]
public string TaskTypeCode { get; set; }

@ -1,11 +0,0 @@
using DS.Module.Core;
using DS.Module.DjyServiceStatus;
using DS.WMS.Core.TaskPlat.Dtos;
using Microsoft.AspNetCore.Http;
namespace DS.WMS.Core.TaskPlat.Interface
{
public interface ITaskAllocation
{
}
}

@ -0,0 +1,23 @@
using DS.Module.Core;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
namespace DS.WMS.Core.TaskPlat.Interface
{
public interface ITaskAllocationService
{
/// <summary>
/// 获取任务分配列表中已存在的船公司列表(用于查询)
/// </summary>
Task<DataResult<List<CarrierInfoDto>>> GetContainsCarrierList();
/// <summary>
/// 获取任务分配列表
/// </summary>
/// <param name="carrierId">船公司Id可选</param>
Task<DataResult<List<TaskAllocationtSet>>> GetList(long? carrierId);
/// <summary>
/// 保存任务分配设置
/// </summary>
Task<DataResult> Save(TaskAllocationtSetSaveDto saveDto);
}
}

@ -67,9 +67,5 @@ namespace DS.WMS.Core.TaskPlat.Interface
/// <param name="userInfos">要转交的人员信息列表</param>
Task<DataResult> TransferTask(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, List<RecvUserInfo> userInfos);
/// <summary>
/// 保存任务分配设置
/// </summary>
Task<DataResult> SaveTaskAllocationSetting(SaveTaskAllocationSettingDto saveDto);
}
}

@ -1,31 +1,150 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.Module.Core.Helpers;
using DS.Module.DjyServiceStatus;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
using DS.WMS.Core.TaskPlat.Interface;
using Mapster;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using LanguageExt.Pipes;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using SqlSugar;
namespace DS.WMS.Core.TaskPlat.Method
{
public class TaskAllocationService : ITaskAllocation
/// <summary>
/// 任务分配设置维护服务
/// </summary>
public class TaskAllocationService : ITaskAllocationService
{
private readonly IUser user;
private readonly ILogger<TaskManageBCService> logger;
private readonly ISaasDbService saasDbService;
public TaskAllocationService(IUser user,
ILogger<TaskAllocationService> logger,
ISaasDbService saasDbService,
IServiceProvider serviceProvider,
IWebHostEnvironment environment)
{ }
ILogger<TaskManageBCService> logger,
ISaasDbService saasDbService)
{
this.user = user;
this.logger = logger;
this.saasDbService = saasDbService;
}
/// <summary>
/// 获取任务分配列表
/// </summary>
/// <param name="carrierId">船公司Id可选</param>
public async Task<DataResult<List<TaskAllocationtSet>>> GetList(long? carrierId)
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var list = await tenantDb.Queryable<TaskAllocationtSet>()
.Where(x => x.CarrierId == carrierId)
.ToListAsync();
return DataResult<List<TaskAllocationtSet>>.Success(list);
}
/// <summary>
/// 获取任务分配列表中已存在的船公司列表(用于查询)
/// </summary>
public async Task<DataResult<List<CarrierInfoDto>>> GetContainsCarrierList()
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var carrierList = await tenantDb.Queryable<TaskAllocationtSet>().Select(x => new CarrierInfoDto()
{
CarrierId = x.CarrierId,
Carrier = x.Carrier,
CarrierCode = x.CarrierCode
}).Where(x => x.CarrierId != null).Distinct().ToListAsync();
return DataResult<List<CarrierInfoDto>>.Success(carrierList);
}
/// <summary>
/// 保存任务分配设置
/// </summary>
public async Task<DataResult> Save(TaskAllocationtSetSaveDto saveDto)
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
if (string.IsNullOrEmpty(saveDto.CarrierCode))
{
saveDto.CarrierCode = null;
}
if (string.IsNullOrEmpty(saveDto.Carrier))
{
saveDto.Carrier = null;
}
if (saveDto.CarrierId == 0)
{
saveDto.CarrierId = null;
}
var fieldName = saveDto.AllocationTargetCode switch
{
"Operator" => nameof(TaskAllocationtSet.IsAllotOperator),
"VouchingClerk" => nameof(TaskAllocationtSet.IsAllotVouchingClerk),
"Sale" => nameof(TaskAllocationtSet.IsAllotSale),
"Custom" => nameof(TaskAllocationtSet.IsAllotCustom),
"FinancialStaff" => nameof(TaskAllocationtSet.IsAllotFinancialStaff),
"CustomerService" => nameof(TaskAllocationtSet.IsAllotCustomerService),
"Driver" => nameof(TaskAllocationtSet.IsAllotDriver),
"Dispatcher" => nameof(TaskAllocationtSet.IsAllotDispatcher),
_ => throw new NotImplementedException(),
};
try
{
// 先查出来已有的、指定船公司的配置
var oldSettingList = await tenantDb.Queryable<TaskAllocationtSet>().Where(x => x.CarrierId == saveDto.CarrierId).Select(x => new { x.Id, x.TaskTypeCode }).ToListAsync();
var oldSettingIdList = oldSettingList.Select(x => x.Id);
var oldSettingTypeCodeList = oldSettingList.Select(x => x.TaskTypeCode);
await tenantDb.Ado.BeginTranAsync();
// 将原有的状态设置为未分配
await tenantDb.Updateable<TaskAllocationtSet>()
.SetColumns(fieldName, false)
.Where(x => oldSettingIdList.Contains(x.Id))
.ExecuteCommandAsync();
// 补充缺少的任务类型
if (saveDto.TaskTypeList?.Any() == true)
{
var waitAddTypeCodeList = saveDto.TaskTypeList.Select(x => x.TaskTypeCode).Except(oldSettingTypeCodeList).ToList();
if (waitAddTypeCodeList.Count > 0)
{
var waitAddSetList = waitAddTypeCodeList.Select(x => new TaskAllocationtSet()
{
CarrierId = saveDto.CarrierId,
Carrier = saveDto.Carrier,
CarrierCode = saveDto.CarrierCode,
TaskTypeCode = x,
TaskTypeName = saveDto.TaskTypeList.First(t => t.TaskTypeCode == x).TaskTypeName,
}).ToList();
await tenantDb.Insertable(waitAddSetList).ExecuteCommandAsync();
}
var setTaskCodeList = saveDto.TaskTypeList.Select(x => x.TaskTypeCode);
// 更新指定船公司的配置
await tenantDb.Updateable<TaskAllocationtSet>()
.SetColumns(fieldName, true)
.Where(x => x.CarrierId == saveDto.CarrierId && setTaskCodeList.Contains(x.TaskTypeCode))
.ExecuteCommandAsync();
}
await tenantDb.Ado.CommitTranAsync();
}
catch (Exception ex)
{
await tenantDb.Ado.RollbackTranAsync();
logger.LogError(ex, "保存任务分配设置异常");
throw;
}
return DataResult.Successed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataUpdateSuccess)));
}
}
}

@ -1846,126 +1846,6 @@ namespace DS.WMS.Core.TaskPlat.Method
//var sql = queryable.Select<dynamic>(t => t).Distinct().ToSqlString();
//.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1)
}
#region 任务分配相关
/// <summary>
/// 获取任务分配保存列表
/// </summary>
/// <param name="carrierId">船公司Id可选</param>
public async Task<DataResult<List<TaskAllocationtSet>>> GetTaskAllocationSettingList(long? carrierId)
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var list = await tenantDb.Queryable<TaskAllocationtSet>()
.WhereIF(carrierId != null, x => x.CarrierId == carrierId)
.ToListAsync();
return DataResult<List<TaskAllocationtSet>>.Success(list);
}
/// <summary>
/// 获取任务分配表中已存在的船公司列表(用于查询)
/// </summary>
public async Task<DataResult<List<CarrierInfoDto>>> GetTaskAllocationSettingCarrierList()
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var carrierList = await tenantDb.Queryable<TaskAllocationtSet>().Select(x => new CarrierInfoDto()
{
CarrierId = x.CarrierId,
Carrier = x.Carrier,
CarrierCode = x.CarrierCode
}).Distinct().ToListAsync();
return DataResult<List<CarrierInfoDto>>.Success(carrierList);
}
/// <summary>
/// 保存任务分配设置
/// </summary>
public async Task<DataResult> SaveTaskAllocationSetting(SaveTaskAllocationSettingDto saveDto)
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
if (string.IsNullOrEmpty(saveDto.CarrierCode))
{
saveDto.CarrierCode = null;
}
if (string.IsNullOrEmpty(saveDto.Carrier))
{
saveDto.Carrier = null;
}
if (saveDto.CarrierId == 0)
{
saveDto.CarrierId = null;
}
var fieldName = saveDto.AllocationTargetCode switch
{
"Operator" => nameof(TaskAllocationtSet.IsAllotOperator),
"VouchingClerk" => nameof(TaskAllocationtSet.IsAllotVouchingClerk),
"Sale" => nameof(TaskAllocationtSet.IsAllotSale),
"Custom" => nameof(TaskAllocationtSet.IsAllotCustom),
"FinancialStaff" => nameof(TaskAllocationtSet.IsAllotFinancialStaff),
"CustomerService" => nameof(TaskAllocationtSet.IsAllotCustomerService),
"Driver" => nameof(TaskAllocationtSet.IsAllotDriver),
"Dispatcher" => nameof(TaskAllocationtSet.IsAllotDispatcher),
_ => throw new NotImplementedException(),
};
try
{
// 先查出来已有的、指定船公司的配置
var oldSettingList = await tenantDb.Queryable<TaskAllocationtSet>().Where(x => x.CarrierId == saveDto.CarrierId).Select(x => new { x.Id, x.TaskTypeCode }).ToListAsync();
var oldSettingIdList = oldSettingList.Select(x => x.Id);
var oldSettingTypeCodeList = oldSettingList.Select(x => x.TaskTypeCode);
await tenantDb.Ado.BeginTranAsync();
// 将原有的状态设置为未分配
await tenantDb.Updateable<TaskAllocationtSet>()
.SetColumns(fieldName, false)
.Where(x => oldSettingIdList.Contains(x.Id))
.ExecuteCommandAsync();
// 补充缺少的任务类型
if (saveDto.TaskTypeList?.Any() == true)
{
var waitAddTypeCodeList = saveDto.TaskTypeList.Select(x => x.TaskTypeCode).Except(oldSettingTypeCodeList).ToList();
if (waitAddTypeCodeList.Count > 0)
{
waitAddTypeCodeList.Select(x => new TaskAllocationtSet()
{
CarrierId = saveDto.CarrierId,
Carrier = saveDto.Carrier,
CarrierCode = saveDto.CarrierCode,
TaskTypeCode = x,
TaskTypeName = saveDto.TaskTypeList.First(t => t.TaskTypeCode == x).TaskTypeName,
});
await tenantDb.Insertable(waitAddTypeCodeList).ExecuteCommandAsync();
}
var setTaskCodeList = saveDto.TaskTypeList.Select(x => x.TaskTypeCode);
// 更新指定船公司的配置
await tenantDb.Updateable<TaskAllocationtSet>()
.SetColumns(fieldName, true)
.Where(x => x.CarrierId == saveDto.CarrierId && setTaskCodeList.Contains(x.TaskTypeCode))
.ExecuteCommandAsync();
}
await tenantDb.Ado.CommitTranAsync();
}
catch (Exception ex)
{
await tenantDb.Ado.RollbackTranAsync();
logger.LogError(ex, "保存任务分配设置异常");
throw;
}
return DataResult.Successed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataUpdateSuccess)));
}
#endregion
}
}

@ -0,0 +1,50 @@
using DS.Module.Core;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Entity;
using DS.WMS.Core.TaskPlat.Interface;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.TaskApi.Controllers;
/// <summary>
/// 任务台分配设置维护接口
/// </summary>
public class TaskAllocationController : ApiController
{
private readonly ITaskAllocationService taskAllocationService;
public TaskAllocationController(ITaskAllocationService taskAllocationService)
{
this.taskAllocationService = taskAllocationService;
}
/// <summary>
/// 获取任务分配列表
/// </summary>
/// <param name="carrierId">船公司Id可选</param>
[HttpGet("GetList")]
public async Task<DataResult<List<TaskAllocationtSet>>> GetList(long? carrierId)
{
var result = await taskAllocationService.GetList(carrierId);
return result;
}
/// <summary>
/// 获取任务分配列表中已存在的船公司列表(用于查询)
/// </summary>
[HttpGet("GetContainsCarrierList")]
public async Task<DataResult<List<CarrierInfoDto>>> GetContainsCarrierList()
{
var result = await taskAllocationService.GetContainsCarrierList();
return result;
}
/// <summary>
/// 保存任务分配设置
/// </summary>
[HttpPost("Save")]
public async Task<DataResult> Save([FromBody] TaskAllocationtSetSaveDto saveDto)
{
var result = await taskAllocationService.Save(saveDto);
return result;
}
}

@ -208,13 +208,4 @@ public class TaskManageController : ApiController
return PhysicalFile(fileFullPath, "application/octet-stream", fileName);
}
///// <summary>
///// 保存任务分配设置
///// </summary>
//[HttpPost("SaveTaskAllocationSetting")]
//public async Task<DataResult> SaveTaskAllocationSetting(SaveTaskAllocationSettingDto saveDto)
//{
// var result = await taskManageService.SaveTaskAllocationSetting(saveDto);
// return result;
//}
}
Loading…
Cancel
Save