|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Data.Entity.Core;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using CK.SCP.Models;
|
|
|
|
using CK.SCP.Models.Enums;
|
|
|
|
using CK.SCP.Models.ScpEntity;
|
|
|
|
using CK.SCP.Models.UniApiEntity;
|
|
|
|
using CK.SCP.Utils;
|
|
|
|
|
|
|
|
namespace CK.SCP.Controller
|
|
|
|
{
|
|
|
|
public static class UniApiController
|
|
|
|
{
|
|
|
|
public static void Get_TS_UNI_API_List(TS_UNI_API p_entity, Action<ResultObject<IQueryable<TS_UNI_API>>> p_action)
|
|
|
|
{
|
|
|
|
ResultObject<IQueryable<TS_UNI_API>> _ret = new ResultObject<IQueryable<TS_UNI_API>>();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (Models.ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
|
|
{
|
|
|
|
IQueryable<TS_UNI_API> q = db.TS_UNI_API;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.PartCode))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.PartCode.Contains(p_entity.PartCode));
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.VendId))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.VendId == p_entity.VendId);
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(p_entity.BillNum))
|
|
|
|
{
|
|
|
|
q = q.Where(p => p.BillNum == p_entity.BillNum);
|
|
|
|
}
|
|
|
|
q = q.Where(p => p.State == p_entity.State);
|
|
|
|
q = q.Where(p => p.InterfaceType == p_entity.InterfaceType);
|
|
|
|
_ret.State = ReturnStatus.Succeed;
|
|
|
|
_ret.Result = q;
|
|
|
|
p_action(_ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
|
|
|
|
{
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
foreach (var error in dbEx.EntityValidationErrors.ToList())
|
|
|
|
{
|
|
|
|
error.ValidationErrors.ToList().ForEach(i =>
|
|
|
|
{
|
|
|
|
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.ErrorList.Add(dbEx);
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(UniApiController), "Get_TS_UNI_API_List", sb.ToString());
|
|
|
|
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
|
|
|
|
}
|
|
|
|
catch (OptimisticConcurrencyException ex)//并发冲突异常
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.ErrorList.Add(ex);
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(UniApiController), "Get_TS_UNI_API_List", ex.ToString());
|
|
|
|
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
|
|
|
|
}
|
|
|
|
catch (ScpException ex)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.ErrorList.Add(ex);
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(UniApiController), "Get_TS_UNI_API_List", ex.ToString());
|
|
|
|
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
|
|
|
|
{
|
|
|
|
var inner = (UpdateException)ex.InnerException;
|
|
|
|
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ex.InnerException != null) throw ex.InnerException;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
_ret.ErrorList.Add(e);
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(UniApiController), "Get_TS_UNI_API_List", e.Message);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static void RemoveList(ScpEntities db, List<TS_UNI_API> uniApiList)
|
|
|
|
{
|
|
|
|
db.TS_UNI_API.RemoveRange(uniApiList);
|
|
|
|
}
|
|
|
|
public static void AddHisList(ScpEntities db, List<TS_UNI_API_HIS> uniApiHisList)
|
|
|
|
{
|
|
|
|
|
|
|
|
db.TS_UNI_API_HIS.AddRange(uniApiHisList);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void AddApiData(ScpEntities wdb, TS_UNI_API apiData)
|
|
|
|
{
|
|
|
|
wdb.TS_UNI_API.Add(apiData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void AddApiDataList(ScpEntities wdb, List<TS_UNI_API> apiDataList)
|
|
|
|
{
|
|
|
|
wdb.TS_UNI_API.AddRange(apiDataList);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static WmsTableName GetTableName(UniApiType uniApiType)
|
|
|
|
{
|
|
|
|
WmsTableName tableName;
|
|
|
|
switch (uniApiType)
|
|
|
|
{
|
|
|
|
case UniApiType.PO:
|
|
|
|
tableName = WmsTableName.TS_UNI_API;//中间表的名字
|
|
|
|
break;
|
|
|
|
case UniApiType.Receive:
|
|
|
|
tableName = WmsTableName.TS_UNI_API;
|
|
|
|
break;
|
|
|
|
case UniApiType.BarCode:
|
|
|
|
tableName = WmsTableName.TS_UNI_API;
|
|
|
|
break;
|
|
|
|
case UniApiType.Invoice:
|
|
|
|
tableName = WmsTableName.TS_UNI_API;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(uniApiType), uniApiType, null);
|
|
|
|
}
|
|
|
|
return tableName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//创建采购订单
|
|
|
|
public static TS_UNI_API CreateBy(TB_PO bill, TB_PO_DETAIL detail, UniApiType uniApiType)
|
|
|
|
{
|
|
|
|
var tableName = GetTableName(uniApiType);
|
|
|
|
var apiData = new TS_UNI_API
|
|
|
|
{
|
|
|
|
InterfaceType = uniApiType.ToString(),
|
|
|
|
TableName = tableName.ToString(),
|
|
|
|
BillNum = bill.PoBillNum,
|
|
|
|
PartCode = detail.PartCode,
|
|
|
|
Batch = "",
|
|
|
|
Qty = detail.PlanQty,
|
|
|
|
PoUnit = detail.PoUnit,
|
|
|
|
LocUnit = detail.LocUnit,
|
|
|
|
State = detail.State,
|
|
|
|
CreateOper = bill.CreateUser,
|
|
|
|
CreateTime = bill.CreateTime,
|
|
|
|
PutTime = ScpCache.GetServerTime(),
|
|
|
|
VendId = bill.VendId,
|
|
|
|
BillType = (int)BillType.PuchaseOrder,
|
|
|
|
SubBillType = 0,
|
|
|
|
ValidDate = (DateTime)detail.EndTime,
|
|
|
|
ErpBillNum = bill.ErpBillNum,
|
|
|
|
ErpLineNum = int.Parse(detail.PoBillNum),
|
|
|
|
VendBatch = "",
|
|
|
|
SourceBillNum = "",
|
|
|
|
Price = detail.Price,
|
|
|
|
PackQty = detail.PackQty,
|
|
|
|
Currency = detail.Currency,
|
|
|
|
Attn = "",//TODO
|
|
|
|
Buyer = bill.Buyer,
|
|
|
|
BuyerPhone = bill.BuyerPhone,
|
|
|
|
ModType = bill.ModType.ToString(),
|
|
|
|
Receiver = "",//TODO
|
|
|
|
UmConv = (decimal)detail.UnConv,
|
|
|
|
};
|
|
|
|
return apiData;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ScpEntities db = EntitiesFactory.CreateScpInstance();
|
|
|
|
public static TS_UNI_API CreateBy(TB_PO bill, List<TB_PO_DETAIL> detail, UniApiType uniApiType)
|
|
|
|
{
|
|
|
|
var tableName = GetTableName(uniApiType);
|
|
|
|
TS_UNI_API asp = new TS_UNI_API();
|
|
|
|
foreach (var item in detail)
|
|
|
|
{
|
|
|
|
asp.InterfaceType = uniApiType.ToString();
|
|
|
|
asp.TableName = tableName.ToString();
|
|
|
|
|
|
|
|
asp.BillNum = bill.PoBillNum;
|
|
|
|
asp.Batch = string.Empty;
|
|
|
|
asp.CreateOper = bill.CreateUser;
|
|
|
|
asp.CreateTime = bill.CreateTime;
|
|
|
|
asp.PutTime = ScpCache.GetServerTime();
|
|
|
|
asp.VendId = bill.VendId;
|
|
|
|
asp.BillType = (int)BillType.PO;
|
|
|
|
asp.SubBillType = 0;
|
|
|
|
asp.VendBatch = string.Empty;
|
|
|
|
asp.SourceBillNum = string.Empty;
|
|
|
|
asp.Attn = "";//TODO
|
|
|
|
asp.Buyer = bill.Buyer;
|
|
|
|
asp.BuyerPhone = bill.BuyerPhone;
|
|
|
|
asp.ModType = bill.ModType.ToString();
|
|
|
|
asp.Receiver = "";//TODO
|
|
|
|
asp.PartCode = item.PartCode;
|
|
|
|
|
|
|
|
asp.Qty = item.PlanQty;
|
|
|
|
asp.PoUnit = item.PoUnit;
|
|
|
|
asp.LocUnit = item.LocUnit;
|
|
|
|
asp.State = item.State;
|
|
|
|
|
|
|
|
asp.ValidDate = (DateTime)item.EndTime;
|
|
|
|
asp.ErpBillNum = bill.ErpBillNum;//暂时跟billnum 一样 后期可能会改 预留
|
|
|
|
asp.ErpLineNum = item.PoLine;
|
|
|
|
|
|
|
|
asp.Price = item.Price;
|
|
|
|
asp.PackQty = item.PackQty;
|
|
|
|
asp.Currency = item.Currency;
|
|
|
|
|
|
|
|
asp.UmConv = (decimal)item.UnConv;
|
|
|
|
|
|
|
|
db.TS_UNI_API.Add(asp);
|
|
|
|
db.SaveChanges();
|
|
|
|
}
|
|
|
|
|
|
|
|
return asp;
|
|
|
|
}
|
|
|
|
|
|
|
|
//创建发货单
|
|
|
|
public static TS_UNI_API CreateBy(V_TB_ASN bill, V_TB_ASN_DETAIL detail, UniApiType uniApiType)
|
|
|
|
{
|
|
|
|
var tableName = GetTableName(uniApiType);
|
|
|
|
var apiData = new TS_UNI_API();
|
|
|
|
|
|
|
|
apiData.InterfaceType = uniApiType.ToString();
|
|
|
|
apiData.TableName = tableName.ToString();
|
|
|
|
apiData.BillNum = bill.AsnBillNum;
|
|
|
|
apiData.PartCode = detail.PartCode;
|
|
|
|
apiData.Batch = detail.Batch;
|
|
|
|
apiData.Qty = detail.Qty;
|
|
|
|
apiData.PoUnit = detail.PoUnit;
|
|
|
|
apiData.LocUnit = detail.LocUnit;
|
|
|
|
apiData.State = (int)detail.State;
|
|
|
|
apiData.CreateOper = bill.CreateUser;
|
|
|
|
apiData.CreateTime = bill.CreateTime;
|
|
|
|
apiData.PutTime = ScpCache.GetServerTime();
|
|
|
|
apiData.VendId = bill.VendId;
|
|
|
|
apiData.BillType = (int)BillType.PuchaseOrder;
|
|
|
|
apiData.SubBillType = 0;
|
|
|
|
apiData.ValidDate = (DateTime)detail.ProduceDate;
|
|
|
|
apiData.ErpBillNum = bill.PoBillNum;
|
|
|
|
apiData.ErpLineNum = detail.PoLine;
|
|
|
|
|
|
|
|
if (bill.Site == "BJCIAI")
|
|
|
|
{
|
|
|
|
apiData.VendBatch = detail.Batch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
apiData.VendBatch = detail.VendBatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
apiData.Price = detail.Price;
|
|
|
|
apiData.PackQty = detail.PackQty;
|
|
|
|
apiData.Currency = detail.Currency;
|
|
|
|
apiData.UmConv = (decimal) detail.UnConv;
|
|
|
|
apiData.Buyer = bill.Buyer;
|
|
|
|
apiData.BuyerPhone = bill.BuyerPhone;
|
|
|
|
apiData.Domain = bill.Site;
|
|
|
|
apiData.Site = bill.SubSite;
|
|
|
|
|
|
|
|
apiData.Extend1 = Utils.JsonHelper.GetJson(bill);
|
|
|
|
apiData.Extend2 = Utils.JsonHelper.GetJson(detail);
|
|
|
|
|
|
|
|
|
|
|
|
return apiData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//创建条码
|
|
|
|
public static TS_UNI_API CreateBy(TB_ASN bill, TS_BARCODE detail, UniApiType uniApiType)
|
|
|
|
{
|
|
|
|
var tableName = GetTableName(uniApiType);
|
|
|
|
var apiData = new TS_UNI_API();
|
|
|
|
|
|
|
|
apiData.Barcode = detail.BarCode;
|
|
|
|
apiData.InterfaceType = uniApiType.ToString();
|
|
|
|
apiData.TableName = tableName.ToString();
|
|
|
|
apiData.BillNum = bill.AsnBillNum;
|
|
|
|
apiData.PartCode = detail.PartCode;
|
|
|
|
apiData.Batch = detail.Batch;
|
|
|
|
apiData.Qty = detail.Qty;
|
|
|
|
apiData.PoUnit = detail.PoUnit;
|
|
|
|
apiData.LocUnit = detail.LocUnit;
|
|
|
|
apiData.State = detail.State;
|
|
|
|
apiData.CreateOper = bill.CreateUser;
|
|
|
|
apiData.CreateTime = bill.CreateTime;
|
|
|
|
apiData.PutTime = ScpCache.GetServerTime();
|
|
|
|
apiData.VendId = bill.VendId;
|
|
|
|
apiData.BillType = (int)BillType.PuchaseOrder;
|
|
|
|
apiData.SubBillType = 0;
|
|
|
|
apiData.ValidDate = detail.ProduceDate;
|
|
|
|
apiData.ErpBillNum = bill.PoBillNum;
|
|
|
|
apiData.ErpLineNum = detail.PoBillLine;
|
|
|
|
apiData.VendBatch = detail.VendBatch;
|
|
|
|
apiData.SourceBillNum = bill.AsnBillNum;
|
|
|
|
apiData.Domain = bill.Site;
|
|
|
|
if(bill.Site=="")
|
|
|
|
|
|
|
|
apiData.Site = bill.Remark;
|
|
|
|
//detail.FullBarCode;
|
|
|
|
apiData.PackQty = detail.PackQty;
|
|
|
|
|
|
|
|
return apiData;
|
|
|
|
}
|
|
|
|
|
|
|
|
//创建发票
|
|
|
|
public static TS_UNI_API CreateBy(V_TB_INVOICE bill, V_TB_INVOICE_DETAIL detail, UniApiType uniApiType)
|
|
|
|
{
|
|
|
|
var tableName = GetTableName(uniApiType);
|
|
|
|
var apiData = new TS_UNI_API
|
|
|
|
{
|
|
|
|
InterfaceType = uniApiType.ToString(),
|
|
|
|
TableName = tableName.ToString(),
|
|
|
|
BillNum = bill.InvcBillNum,
|
|
|
|
PartCode = detail.PartCode,
|
|
|
|
Batch = "",
|
|
|
|
Qty = detail.Qty,
|
|
|
|
PoUnit = detail.PoUnit,
|
|
|
|
LocUnit = detail.PoUnit,
|
|
|
|
State = (int)detail.State,
|
|
|
|
CreateOper = bill.CreateUser,
|
|
|
|
CreateTime = (DateTime)bill.CreateTime,
|
|
|
|
PutTime = ScpCache.GetServerTime(),
|
|
|
|
VendId = bill.VendId,
|
|
|
|
BillType = (int)BillType.PuchaseOrder,
|
|
|
|
SubBillType = 0,
|
|
|
|
ValidDate = DateTime.Now,//暂时添上
|
|
|
|
ErpBillNum = detail.PoBillNum,
|
|
|
|
ErpLineNum = detail.PoLineNum,
|
|
|
|
VendBatch = detail.ProjectId,
|
|
|
|
SourceBillNum = detail.AsnBillNum,
|
|
|
|
Price = detail.Price,
|
|
|
|
PackQty = (decimal)detail.PackQty,
|
|
|
|
Currency = detail.Currency,
|
|
|
|
Invoice = bill.InvoiceNum,
|
|
|
|
Receiver = detail.ErpRecvBillNum,
|
|
|
|
Tax = (decimal)bill.Tax,
|
|
|
|
TaxAmt = (decimal)(detail.Price * bill.Tax),
|
|
|
|
Domain = bill.Site,
|
|
|
|
Site = bill.Site,
|
|
|
|
Attn = Utils.JsonHelper.GetJson(bill),
|
|
|
|
Extend1 = Utils.JsonHelper.GetJson(bill),
|
|
|
|
Extend2 = Utils.JsonHelper.GetJson(detail)
|
|
|
|
};
|
|
|
|
return apiData;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<TS_UNI_API> GetNewInterfaceList(ScpEntities wdb)
|
|
|
|
{
|
|
|
|
return wdb.TS_UNI_API.Where(p => p.State == (int)BillState.New).OrderBy(p => p.UID).ToList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|