using Castle.Core.Resource;
|
using MES.Service.DB;
|
using MES.Service.Dto.webApi;
|
using MES.Service.Modes;
|
using SqlSugar;
|
|
namespace MES.Service.service.BasicData;
|
|
public class MesLineManager : Repository<MesLine>
|
{
|
|
public bool SaveList(List<ErpSb> devices)
|
{
|
var result = devices.Select(Save).ToList();
|
return result.All(b => b);
|
}
|
|
public bool Save(ErpSb device)
|
{
|
var entity = GetErpDevice(device);
|
|
return UseTransaction(db =>
|
{
|
switch (device.Type)
|
{
|
case "3":
|
return DeleteData(db, entity) ? 1 : 0;
|
case "0":
|
case "1":
|
case "2":
|
return SaveOrUpdateData(db, entity) ? 1 : 0;
|
default:
|
throw new NotImplementedException(
|
$"type没有{device.Type}这个类型");
|
}
|
}) > 0;
|
}
|
|
private bool SaveOrUpdateData(SqlSugarScope db, MesLine device)
|
{
|
if (device.Id != null) base.DeleteById(device.Id);
|
|
var orUpdate = base.Insert(device);
|
if (orUpdate) return true;
|
throw new NotImplementedException("插入或更新失败");
|
}
|
|
private bool DeleteData(SqlSugarScope db, MesLine device)
|
{
|
var update = base.DeleteById(device.Id);
|
|
if (update) return true;
|
throw new NotImplementedException("更新失败");
|
}
|
|
private MesLine GetErpDevice(ErpSb device)
|
{
|
var entity = new MesLine
|
{
|
FNUMBER = device.FNUMBER,
|
FFORBIDSTATUS = device.FFORBIDSTATUS,
|
LineName = device.FNAME,
|
Memo = device.FDESCRIPTION,
|
FCREATEORGID = device.FCREATEORGID,
|
FUSEORGID = device.FUSEORGID,
|
Departmentcode = device.F_WWC_BASE,
|
WorkType=0,
|
Factory="1000",
|
Company="1000",
|
CreateDate=DateTime.Now,
|
LineNo=device.FNUMBER,
|
FBILLHEAD=device.Id
|
};
|
|
var single = base.GetSingle(it => it.FNUMBER == entity.FNUMBER);
|
if (single != null) entity.Id = single.Id;
|
|
return entity;
|
}
|
|
}
|