using MES.Service.DB;
|
using MES.Service.Dto.service;
|
using MES.Service.Modes;
|
|
namespace MES.Service.service.Warehouse;
|
|
public class XbRackingTaskSyxtLogManager : Repository<XbRackingTaskSyxtLog>
|
{
|
/// <summary>
|
/// 核验任务单号是否存在
|
/// </summary>
|
/// <param name="dto">任务完成上报参数</param>
|
/// <returns>任务单号是否存在</returns>
|
public bool ValidateTaskExists(TaskCompleteReportDto dto)
|
{
|
if (dto == null || string.IsNullOrWhiteSpace(dto.TaskCode))
|
{
|
return false;
|
}
|
|
var task = Context.Queryable<XbRackingTaskSyxtLog>()
|
.Where(t => t.TaskCode == dto.TaskCode)
|
.Any();
|
|
return task;
|
}
|
|
/// <summary>
|
/// 任务完成上报
|
/// </summary>
|
/// <param name="dto">任务完成上报参数</param>
|
/// <returns>统一响应结果</returns>
|
public RackingTaskResponse TaskCompleteReport(TaskCompleteReportDto dto)
|
{
|
if (dto == null)
|
{
|
return RackingTaskResponse.Fail("参数不能为空");
|
}
|
|
if (string.IsNullOrWhiteSpace(dto.TaskCode))
|
{
|
return RackingTaskResponse.Fail("任务号不能为空");
|
}
|
|
if (string.IsNullOrWhiteSpace(dto.PalletCode))
|
{
|
return RackingTaskResponse.Fail("托盘编码不能为空");
|
}
|
|
try
|
{
|
// 步骤1:验证任务号是否存在
|
var task = Context.Queryable<XbRackingTaskSyxtLog>()
|
.Where(t => t.TaskCode == dto.TaskCode)
|
.First();
|
|
if (task == null)
|
{
|
return RackingTaskResponse.Fail($"任务号[{dto.TaskCode}]不存在");
|
}
|
|
// 步骤2:验证托盘编码是否匹配
|
if (task.PalletCode != dto.PalletCode)
|
{
|
return RackingTaskResponse.Fail($"托盘编码不匹配,期望[{task.PalletCode}],实际[{dto.PalletCode}]");
|
}
|
|
// 步骤3:转换库位编码为中文
|
string? locCodeChinese = null;
|
if (!string.IsNullOrEmpty(dto.LocCode))
|
{
|
// 验证库位编码格式
|
if (dto.LocCode.Length != 6 || !dto.LocCode.All(char.IsDigit))
|
{
|
return RackingTaskResponse.Fail("库位编码格式错误,应为6位数字");
|
}
|
|
// 转换库位编码
|
locCodeChinese = ConvertLocCodeToChinese(dto.LocCode);
|
}
|
|
// 步骤4:更新任务日志表
|
var updateResult = Context.Updateable<XbRackingTaskSyxtLog>()
|
.SetColumns(t => t.LocCode == dto.LocCode)
|
.SetColumns(t => t.LocCodeChinese == locCodeChinese)
|
.SetColumns(t => t.Code == "200")
|
.SetColumns(t => t.JsonMessage == "任务完成")
|
.SetColumns(t => t.CodeMessage == "任务完成")
|
.Where(t => t.TaskCode == dto.TaskCode)
|
.ExecuteCommand();
|
|
if (updateResult <= 0)
|
{
|
return RackingTaskResponse.Fail("更新任务日志失败");
|
}
|
|
return RackingTaskResponse.Success();
|
}
|
catch (Exception ex)
|
{
|
return RackingTaskResponse.Fail($"更新任务日志失败:{ex.Message}");
|
}
|
}
|
|
/// <summary>
|
/// 将库位编码转换为中文描述
|
/// </summary>
|
/// <param name="locCode">库位编码,格式如"010203"</param>
|
/// <returns>中文描述,格式如"1排2层3列"</returns>
|
private string ConvertLocCodeToChinese(string locCode)
|
{
|
// 解析排号(前两位)
|
int row = int.Parse(locCode.Substring(0, 2));
|
// 解析层号(中间两位)
|
int level = int.Parse(locCode.Substring(2, 2));
|
// 解析列号(后两位)
|
int column = int.Parse(locCode.Substring(4, 2));
|
|
return $"{row}排{level}层{column}列";
|
}
|
|
|
/// <summary>
|
/// 异常任务上报
|
/// </summary>
|
/// <param name="dto">异常任务上报参数</param>
|
/// <returns>统一响应结果</returns>
|
public RackingTaskResponse TaskErrorReport(TaskErrorReportDto dto)
|
{
|
if (dto == null)
|
{
|
return RackingTaskResponse.Fail("参数不能为空");
|
}
|
|
if (string.IsNullOrWhiteSpace(dto.TaskCode))
|
{
|
return RackingTaskResponse.Fail("任务号不能为空");
|
}
|
|
if (string.IsNullOrWhiteSpace(dto.PalletCode))
|
{
|
return RackingTaskResponse.Fail("托盘编码不能为空");
|
}
|
|
if (string.IsNullOrWhiteSpace(dto.ErrorMessage))
|
{
|
return RackingTaskResponse.Fail("错误信息不能为空");
|
}
|
|
try
|
{
|
// 步骤1:验证任务号是否存在
|
var task = Context.Queryable<XbRackingTaskSyxtLog>()
|
.Where(t => t.TaskCode == dto.TaskCode)
|
.First();
|
|
if (task == null)
|
{
|
return RackingTaskResponse.Fail($"任务号[{dto.TaskCode}]不存在");
|
}
|
|
// 步骤2:验证托盘编码是否匹配
|
if (task.PalletCode != dto.PalletCode)
|
{
|
return RackingTaskResponse.Fail($"托盘编码不匹配,期望[{task.PalletCode}],实际[{dto.PalletCode}]");
|
}
|
|
// 步骤3:更新任务日志表
|
var updateResult = Context.Updateable<XbRackingTaskSyxtLog>()
|
.SetColumns(t => t.Code == "500")
|
.SetColumns(t => t.JsonMessage == dto.ErrorMessage)
|
.SetColumns(t => t.CodeMessage == dto.ErrorMessage)
|
.Where(t => t.TaskCode == dto.TaskCode)
|
.ExecuteCommand();
|
|
if (updateResult <= 0)
|
{
|
return RackingTaskResponse.Fail("更新任务日志失败");
|
}
|
|
return RackingTaskResponse.Success();
|
}
|
catch (Exception ex)
|
{
|
return RackingTaskResponse.Fail($"更新任务日志失败:{ex.Message}");
|
}
|
}
|
}
|