using SqlSugar.Extensions;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common.PLSEnum;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_DTO;
|
using WIDESEA_DTO.PLS;
|
using WIDESEA_IBasicRepository;
|
using WIDESEA_IBasicService;
|
using WIDESEA_IInboundRepository;
|
using WIDESEA_IInboundService;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_InboundService
|
{
|
public class MoInboundOrderService : ServiceBase<Dt_MoInboundOrder, IMoInboundOrderRepository>, IMoInboundOrderService
|
{
|
|
public IMoInboundOrderRepository Repository => BaseDal;
|
|
public MoInboundOrderService(IMoInboundOrderRepository BaseDal) : base(BaseDal)
|
{
|
}
|
|
|
/// <summary>
|
/// PLS同步MO票信息
|
/// </summary>
|
public ApiResponseContent ReceiveMoStatus(MoInboundOrderDTO model)
|
{
|
// 1. 基础参数校验
|
if (model == null || model.Data == null || !model.Data.Any())
|
{
|
return ApiResponseContent.Instance.Error("MO票传入参数为空");
|
}
|
|
var dataList = new List<LabelNoData>();
|
int successCount = 0;
|
int totalCount = model.Data.Count;
|
|
try
|
{
|
foreach (var item in model.Data)
|
{
|
var itemResult = new LabelNoData
|
{
|
LabelNo = item.LabelNo
|
};
|
try
|
{
|
// 参数校验
|
if (string.IsNullOrWhiteSpace(item.LabelNo))
|
{
|
throw new Exception("标签号 LabelNo 不能为空");
|
}
|
|
// 查询MO票是否已存在
|
var existMo = BaseDal.QueryFirst(x => x.LabelNo == item.LabelNo);
|
|
if (existMo == null)
|
{
|
var addEntity = new Dt_MoInboundOrder()
|
{
|
OrgId = item.OrgId,
|
LabelNo = item.LabelNo,
|
Status = item.Status,
|
BarcodeNumber = item.BarcodeNumber,
|
SupplierCode = item.SupplierCode,
|
ItemCode = item.ItemCode,
|
Qty = item.Qty,
|
WorkOrderName = item.WorkOrderName,
|
DeleteFlag = item.DeleteFlag,
|
ReturnToPlsStatus = ReturnToPlsStatusEnum.未推送.ObjToInt(),
|
CreateDate = item.CreateDate,
|
Creater = item.CreateUser,
|
Modifier = item.UpdateUser,
|
ModifyDate = item.UpdateDate
|
};
|
BaseDal.AddData(addEntity);
|
}
|
else
|
{
|
existMo.OrgId = item.OrgId;
|
existMo.Status = item.Status;
|
existMo.BarcodeNumber = item.BarcodeNumber;
|
existMo.SupplierCode = item.SupplierCode;
|
existMo.ItemCode = item.ItemCode;
|
existMo.Qty = item.Qty;
|
existMo.WorkOrderName = item.WorkOrderName;
|
existMo.DeleteFlag = item.DeleteFlag;
|
existMo.Modifier = item.UpdateUser;
|
existMo.ModifyDate = item.UpdateDate;
|
|
BaseDal.UpdateData(existMo);
|
}
|
|
// 单条处理成功
|
itemResult.Success = 0;
|
successCount++;
|
}
|
catch (Exception ex)
|
{
|
// 单条处理失败
|
itemResult.Success = 1;
|
itemResult.Msg = ex.Message;
|
}
|
finally
|
{
|
// 每条无论成功/失败,都加入返回列表
|
dataList.Add(itemResult);
|
}
|
}
|
|
// 全部处理完成,返回结果
|
return ApiResponseContent.Instance.OK(
|
dataList,
|
$"处理完成:共{totalCount}条,成功{successCount}条,失败{totalCount - successCount}条"
|
);
|
}
|
catch (Exception ex)
|
{
|
return ApiResponseContent.Instance.Error($"MO票同步整体异常:{ex.Message}");
|
}
|
}
|
|
}
|
}
|