Commit 1902a33d by zxw

补充删除的第三方调用接口

parent 2b894b1a
......@@ -8,11 +8,10 @@ using Microsoft.EntityFrameworkCore;
namespace JmpModel.Model
{
[Keyless]
[Table("common_jp_user_info")]
public partial class CommonJpUserInfo
{
[Required]
[Key]
[Column("id")]
[StringLength(64)]
public string Id { get; set; }
......
......@@ -146,7 +146,7 @@ namespace JmpModel.Model.DataContext
if (!optionsBuilder.IsConfigured)
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
optionsBuilder.UseMySql("data source=192.168.2.15;port=13306;initial catalog=junmppolicesqlb;user id=root;password=Junmp123;charset=utf8;treattinyasboolean=false", Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.7.38-mysql"));
optionsBuilder.UseMySql("data source=192.168.2.105;port=13306;initial catalog=junmppolicesqlb;user id=root;password=Junmp123;charset=utf8;treattinyasboolean=false", Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.7.38-mysql"));
}
}
......
......@@ -54,6 +54,616 @@ namespace JunmpPoliceStation.Controllers
}
/// <summary>
/// 第三方生成单据信息
/// </summary>
/// <remarks>
/// ## 例子
///
/// {
/// "type":"订单类型",purchase采购,borrow借用,recipients领用,transfer调拨,fix维修,scrap报废,
/// "warehouseId":"仓库ID"调拨时为请求仓库,其他业务为当前业务仓库,
/// "orgId":"",//调拨时为申请调拨的组织机构
/// "transferId":""//调拨出库的组织机构//仅限调拨使用
/// "orderNo":"订单号,
/// "expectedReturnTime":"借用归还时间"//借用时使用,其他业务不做处理
/// "detailList":[//实际出货
/// {
/// "detailQuantity":""
/// "epc":""//维修,报废时使用,其他业务不做处理
/// "sendWarehouseId":"发货仓库代码",//调拨时使用,其他业务不做处理
/// "equipmentSizeId":"",
/// "equipmentDetailId":"",
/// "supplierId":""//采购不做处理
/// "warehouseList":[{//调拨时使用
/// "warehouseId":"",
/// "quantity":""
/// }]
/// }]
/// }
///
/// </remarks>
/// <param name="jdata"></param>
/// <returns></returns>
[HttpPost("CreateOrder")]
//[NoSign]
public async Task<HttpResponseMessage> CreateOrder([FromBody] JObject jdata)
{
return await Task.Run(() =>
{
try
{
if (jdata != null)
{
var entity = JsonManager.GetJsonEntity(jdata);
//第三方调用接口验证orgId正确性
if (!string.IsNullOrEmpty(entity._PUSHORG))
{
if (entity.orgId?.ToString() != entity._PUSHORG.ToString())
{
return JsonManager.SimpleStatusResponse(ResultCode.ORGANIZATION_ERROR);
}
}
string note = entity.note;
string type = entity.type;
string warehouseId = entity.warehouseId;
string orgId = entity.orgId;
string orderNo = entity.orderNo;
string expectedReturnTime = entity.expectedReturnTime;
string orderState = entity.orderState;
//List<string> tmpList = JsonManager.GetDetailIds(entity.detailList);
//if (entity.detailList == null)
//{
// return JsonManager.SimpleCustResponse($"detailList is require");
//}
switch (type)
{
case "purchase":
CommonJpPurchaseOrder queryOrder = _unitOfWork.PurchaseOrderyRepository.Get(p => p.OrderCode.Equals(orderNo));
if (queryOrder != null)
{
return JsonManager.SimpleStatusResponse(ResultCode.ORDER_IS_EXIST);
}
if (!orderNo.Contains("CG"))
{
return JsonManager.SimpleStatusResponse(ResultCode.ORDER_ERROR);
}
CommonJpPurchaseOrder purchaseOrder = new CommonJpPurchaseOrder()
{
ApplyTime = DateTime.Now,
ApprovalResult = (int)ApproveType.已审批,
ApprovalTime = null,
CreateTime = DateTime.Now,
ApplyId = entity.applyId,
WarehouseId = entity.warehouseId,
Id = Guid.NewGuid().ToString(),
OrgId = entity.orgId,
ApplyName = entity.applyName,
OrderCode = orderNo,
CurrentState = 0,
};
List<CommonJpPurchaseDetail> detailsList = new List<CommonJpPurchaseDetail>();
foreach (var item in entity.detailList)
{
if (!int.TryParse(item.detailQuantity, out int detailQuantity))
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
detailsList.Add(new CommonJpPurchaseDetail()
{
Id = Guid.NewGuid().ToString(),
EquipmentId = item.equipmentDetailId,
SizeId = item.equipmentSizeId,
Note = item.note,
OrderId = purchaseOrder.Id,
Quantity = detailQuantity,
SupplierId = null,
CreateTime = DateTime.Now,
State = 0
});
}
purchaseOrder.CommonJpPurchaseDetails = detailsList;
bool result = _unitOfWork.PurchaseOrderyRepository.Insert(purchaseOrder);
if (result)
{
return JsonManager.ReturnSuccessResponse(new
{
purchaseOrder.ApplyTime,
purchaseOrder.ApprovalResult,
purchaseOrder.ApprovalTime,
purchaseOrder.CreateTime,
purchaseOrder.ApplyId,
purchaseOrder.WarehouseId,
purchaseOrder.Id,
purchaseOrder.OrgId,
purchaseOrder.ApplyName,
purchaseOrder.OrderCode,
purchaseOrder.CurrentState,
Details = purchaseOrder.CommonJpPurchaseDetails.Select(x => new
{
x.Id,
x.EquipmentId,
x.SizeId,
x.Note,
x.OrderId,
x.Quantity,
x.SupplierId,
x.CreateTime,
x.State
})
});
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
case "borrow":
case "recipients":
CommonJpBorrowReturnApply borrowQuery = _unitOfWork.BorrowReturnApplyRepository.Get(p => p.OrderCode.Equals(orderNo));
if (borrowQuery != null)
{
return JsonManager.SimpleStatusResponse(ResultCode.ORDER_IS_EXIST);
}
if (type.Equals("borrow"))
{
if (!orderNo.Contains("JY"))
{
return JsonManager.SimpleStatusResponse(ResultCode.ORDER_ERROR);
}
}
else if (type.Equals("recipients"))
{
if (!orderNo.Contains("LY"))
{
return JsonManager.SimpleStatusResponse(ResultCode.ORDER_ERROR);
}
}
if (string.IsNullOrEmpty(expectedReturnTime) && type.Equals("borrow"))
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
CommonJpBorrowReturnApply borrowApplyOrder = new CommonJpBorrowReturnApply();
if (type.Equals("borrow"))
{
borrowApplyOrder = new CommonJpBorrowReturnApply()
{
ExpectedReturnTime = DateTime.Parse(expectedReturnTime.ToString()),
ChangeFlag = 0,
ActionType = 1,
ApplyTime = DateTime.Now,
CreateTime = DateTime.Now,
WarehouseId = entity.warehouseId,
Id = Guid.NewGuid().ToString(),
OrgId = entity.orgId,
OrderCode = orderNo,
};
}
else if (type.Equals("recipients"))
{
borrowApplyOrder = new CommonJpBorrowReturnApply()
{
ChangeFlag = 0,
ActionType = 1,
ApplyTime = DateTime.Now,
CreateTime = DateTime.Now,
WarehouseId = entity.warehouseId,
Id = Guid.NewGuid().ToString(),
OrgId = entity.orgId,
OrderCode = orderNo,
};
}
CommonJpBorrowReturn borrowOrder = new CommonJpBorrowReturn()
{
Id = Guid.NewGuid().ToString(),
ActionType = type.Equals("borrow") ? 0 : 1,
WarehouseId = entity.warehouseId,
OrderCode = orderNo,
CurrentState = (int)CurrentState.未出去,
OrgId = entity.orgId,
CreateTime = DateTime.Now,
IsWork = false,
};
List<CommonJpBorrowReturnDetailEstimate> borrowEsDetailsList = new List<CommonJpBorrowReturnDetailEstimate>();
List<CommonJpBorrowReturnDetailReality> borrowReDetailsList = new List<CommonJpBorrowReturnDetailReality>();
foreach (var item in entity.detailList)
{
borrowEsDetailsList.Add(new CommonJpBorrowReturnDetailEstimate()
{
Id = Guid.NewGuid().ToString(),
EquipmentId = item.equipmentDetailId,
SizeId = item.equipmentSizeId,
EstimateId = borrowApplyOrder.Id,
EquipmentCount = int.Parse(item.detailQuantity),
//SupplierId = item.supplierId==null?null:item.supplierId
});
borrowReDetailsList.Add(new CommonJpBorrowReturnDetailReality()
{
Id = Guid.NewGuid().ToString(),
SizeId = item.equipmentSizeId,
EquipmentDetailId = item.equipmentDetailId,
RealityId = borrowOrder.Id,
State = (int)CurrentState.未出去,
EstimateId = borrowApplyOrder.Id,
EquipmentCount = int.Parse(item.detailQuantity),
//SupplierId = item.supplierId == null ? null : item.supplierId
});
}
borrowOrder.CommonJpBorrowReturnDetailRealities = borrowReDetailsList;
borrowApplyOrder.CommonJpBorrowReturnDetailEstimates = borrowEsDetailsList;
bool borrowResult = _unitOfWork.BorrowReturnApplyRepository.Insert(borrowApplyOrder, false);
borrowResult = _unitOfWork.BorrowReturnRepository.Insert(borrowOrder, true);
if (borrowResult)
{
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_SUCCESS);
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
case "transfer":
CommonJpTransferApply transferQuery = _unitOfWork.TransferApplyRepository.Get(p => p.Order.Equals(orderNo));
if (transferQuery != null)
{
return JsonManager.SimpleStatusResponse(ResultCode.ORDER_IS_EXIST);
}
if (!orderNo.Contains("DB"))
{
return JsonManager.SimpleStatusResponse(ResultCode.ORDER_ERROR);
}
CommonJpTransferApply transferApplyOrder = new CommonJpTransferApply()
{
Id = Guid.NewGuid().ToString(),
ActionType = 0,
TransferId = entity.transferId,
TargetId = orgId,
TransferWarehouse = warehouseId,
ApplyTime = DateTime.Now,
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
Order = orderNo,
};
CommonJpTransfer transferOrder = new CommonJpTransfer()
{
Id = Guid.NewGuid().ToString(),
ActionType = 0,
ReceiveOrgizationId = orgId,
SendOrgizationId = entity.transferId,
ReceiveWarehouseId = entity.warehouseId,
Order = orderNo,
CurrentState = (int)CurrentState.未出去,
UpdateTime = DateTime.Now,
CreateTime = DateTime.Now,
IsWork = false,
};
List<CommonJpTransferDetailEstimate> transferEsDetailsList = new List<CommonJpTransferDetailEstimate>();
List<CommonJpTransferDetailReality> transferReDetailsList = new List<CommonJpTransferDetailReality>();
foreach (var item in entity.detailList)
{
var warehouseList = item.warehouseList;
foreach (var warehouseItem in warehouseList)
{
string sendWarehouseId = warehouseItem.warehouseId;
string count = warehouseItem.quantity;
if (count != null && count != "0")
{
transferEsDetailsList.Add(new CommonJpTransferDetailEstimate()
{
Id = Guid.NewGuid().ToString(),
EquipmentDetailId = item.equipmentDetailId,
EquipmentSizeId = item.equipmentSizeId,
EstimateId = transferApplyOrder.Id,
EquipmentCount = int.Parse(count),
});
transferReDetailsList.Add(new CommonJpTransferDetailReality()
{
Id = Guid.NewGuid().ToString(),
SizeId = item.equipmentSizeId,
EquipmentDetailId = item.equipmentDetailId,
RealityId = transferOrder.Id,
State = (int)CurrentState.未出去,
EstimateId = transferApplyOrder.Id,
EquipmentCount = int.Parse(count),
RealCount = 0,
IsWork = false,
WarehouseId = sendWarehouseId,
InsideRealCount = 0,
});
}
}
}
transferOrder.CommonJpTransferDetailRealities = transferReDetailsList;
transferApplyOrder.CommonJpTransferDetailEstimates = transferEsDetailsList;
bool transferResult = _unitOfWork.TransferApplyRepository.Insert(transferApplyOrder, false);
transferResult = _unitOfWork.TransferRepository.Insert(transferOrder, true);
if (transferResult)
{
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_SUCCESS);
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
case "fix":
case "scrap":
using (var scope = _unitOfWork.BeginTransaction())
{
try
{
CommonJpFixReceiveApply fixQuery = _unitOfWork.FixReceiveApplyRepository.Get(p => p.OrderCode.Equals(orderNo));
if (fixQuery != null)
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.ORDER_IS_EXIST);
}
if (type.Equals("fix"))
{
if (!orderNo.Contains("WX"))
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.ORDER_ERROR);
}
}
else if (type.Equals("scrap"))
{
if (!orderNo.Contains("BF"))
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.ORDER_ERROR);
}
}
CommonJpFixReceiveApply FixOrder = new CommonJpFixReceiveApply()
{
Action = type.Equals("fix") ? 0 : 1,
ApplyTime = DateTime.Now,
CreateTime = DateTime.Now,
ApprovalResult = (int)ApproveType.已审批,
WarehouseId = warehouseId,
Id = Guid.NewGuid().ToString(),
OrgId = entity.orgId,
OrderCode = orderNo,
ApprovalTime = DateTime.Now,
CurrentState = 1
};
CommonJpFixUseless useless = new CommonJpFixUseless()
{
Id = Guid.NewGuid().ToString(),
Action = type.Equals("fix") ? 0 : 1,
CreateTime = DateTime.Now,
CreateUser = "",
FixTime = DateTime.Now,
EstimateId = FixOrder.Id,
OrderCode = orderNo,
OrgId = entity.orgId,
WarehouseId = warehouseId,
CommonJpFixUselessDetails = new List<CommonJpFixUselessDetail>(),
CurrentState = 1
};
List<CommonJpFixReceiveApplyDetail> FixDetailsList = new List<CommonJpFixReceiveApplyDetail>();
foreach (var item in entity.detailList)
{
if (string.IsNullOrEmpty(item.supplierId) || string.IsNullOrEmpty(item.epc))
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
FixDetailsList.Add(new CommonJpFixReceiveApplyDetail()
{
Id = Guid.NewGuid().ToString(),
EquipmentId = item.equipmentDetailId,
SizeId = item.equipmentSizeId,
OrderId = FixOrder.Id,
Quantity = 1,
SupplierId = item.supplierId,
Epc = item.epc ?? "",
State = 1
});
var tmpEntity = new CommonJpFixUselessDetail()
{
Id = Guid.NewGuid().ToString(),
OrderId = useless.Id,
Quantity = item.Quantity,
State = 1,
Epc = item.epc,
EquipmentId = item.equipmentDetailId,
SizeId = item.equipmentSizeId,
SupplierId = item.supplierId,
RealCount = 1
};
useless.CommonJpFixUselessDetails.Add(tmpEntity);
var tmpState = GenerateState(tmpEntity.Epc, useless.Action, tmpEntity.Id, useless.WarehouseId, useless.OrgId, useless.OrderCode);
if (tmpState != null)
{
tmpEntity.CommonJpEquipmentStates.Add(tmpState);
}
}
//反写库存状态
var updateList = UpdateInvState(FixDetailsList.Select(x => x.Epc).ToList(), type.Equals("fix") ? 0 : 1, orderNo);
FixOrder.CommonJpFixReceiveApplyDetails = FixDetailsList;
bool FixResult = _unitOfWork.FixReceiveApplyRepository.Insert(FixOrder, false);
FixResult = _unitOfWork.FixUselessRepository.Insert(useless, true);
if (FixResult)
{
//上报数据
var pushData = new List<object>();
pushData.AddRange(updateList.Select(x => new
{
editType = "UPDATE",
id = x.Id,
supplierCode = x.SupplierCode,
epc = x.Epc,
policeCode = x.PoliceCode,
equipmentCode = x.EquipmentCode,
warehouseCode = x.WarehouseCode,
cabinetId = x.CabinetId,
equipmentSizecode = x.EquipmentSizecode,
equipmentLocation = x.EquipmentLocation,
currentState = x.CurrentState,
createTime = x.CreateTime,
warrantyCycle = x.WarrantyCycle,
repairCycle = x.RepairCycle,
productTime = x.ProductTime,
useTime = x.UseTime,
price = x.Price,
isBorrowed = x.IsBorrowed,
lostFlag = x.LostFlag,
inventoryState = x.InventoryState,
isInBox = x.IsInBox,
boxMarkId = x.BoxMarkId,
instantiationState = x.InstantiationState,
}));
var httpResult = _httpHelper.GetHtml(new HttpItem()
{
URL = _httpHelper._centerServerAddress + "/api/Print/EditInventory",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Timeout = 5000,
Postdata = _httpHelper.CreatePostData(JsonConvert.SerializeObject(new
{
data = pushData
}))
});
if (httpResult.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(httpResult.Html))
{
scope.Rollback();
return JsonManager.SimpleCustResponse("远端上报数据失败");
}
var obj = JsonConvert.DeserializeObject<JmpBaseResponse<object>>(httpResult.Html);
if (obj.code != "10000")
{
scope.Rollback();
return JsonManager.SimpleCustResponse(obj.msg);
}
scope.Commit();
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_SUCCESS);
}
else
{
scope.Rollback();
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
}
catch (Exception e)
{
scope.Rollback();
throw;
}
}
default:
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_FAILED);
}
}
catch (Exception ex)
{
_logger.LogError("Inventory/CreateOrder 错误:" + ex.ToString());
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_FAILED);
}
});
}
/// <summary>
/// 更新库存信息
/// </summary>
/// <param name="epcList"></param>
/// <param name="action"></param>
/// <param name="orderCode"></param>
private List<CommonJpEquipmentInventory> UpdateInvState(List<string> epcList, int action, string orderCode)
{
if (epcList == null || epcList.Count == 0)
{
_logger.LogError($"[维修报废]未找到维修报废明细,{orderCode}");
}
var wz_info = _unitOfWork.DbContext.CommonJpEquipmentInventories.Where(t => epcList.Contains(t.Epc)).ToList();
if (wz_info != null && wz_info.Count() > 0)
{
wz_info.ForEach(x =>
{
x.CurrentState = action == 0 ? 4 : 6;
_unitOfWork.EquipmentInventoryRepository.Update(x, false);
});
}
return wz_info;
}
/// <summary>
/// 状态更新
/// </summary>
/// <param name="epc"></param>
/// <param name="action"></param>
/// <param name="detailId"></param>
/// <param name="warehouseId"></param>
/// <param name="orgId"></param>
/// <returns></returns>
private CommonJpEquipmentState GenerateState(string epc, int action, string detailId, string warehouseId, string orgId, string ordercode)
{
var invInfo = _unitOfWork.DbContext.CommonJpEquipmentInventories.FirstOrDefault(t => t.Epc.Contains(epc));
if (invInfo != null)
{
CommonJpEquipmentState equState = new CommonJpEquipmentState()
{
Id = Guid.NewGuid().ToString(),
State = 2,
OrderCode = ordercode,
ActionState = action == 0 ? 6 : 7,
EqiupmentId = invInfo.Id,
OutInState = 0,
FixId = detailId,
WarehouseId = warehouseId,
CreateTime = DateTime.Now,
OrgId = orgId,
OutTime = DateTime.Now,
HistorySafeLevel = invInfo.SafeLevel
};
return equState;
}
else { return default; }
}
/// <summary>
/// 获取出入库表单的详细信息
/// </summary>
/// <remarks>
......@@ -2237,6 +2847,414 @@ namespace JunmpPoliceStation.Controllers
}
/// <summary>
/// 第三方/充电台出入库
/// </summary>
/// <remarks>
///
/// ## 例子
///
/// {
/// "orgId": "0320200512000808",
/// "warehouseId": "",
/// "orderNo": "",//订单号
/// "type": "类型",采购,调拨,借用,领用,维修,跨库借用,跨库归还
/// "outInState": "","当前出入库状态",//出库,入库
/// "policeId": "",//警员ID
/// "picUrl": "出入库图片路径",
/// "RFIDList": [{
/// "RFID": "A12C621596CDF8A02B18538A"
/// },{
/// "RFID": "A12C6215BCE9F863C2896E0A"
/// },{
/// "RFID": "A12C6215BCE9F863C284DF0A"
/// }]
/// }
///
///
///
/// </remarks>
/// <param name="jdata"></param>
/// <returns></returns>
[HttpPost("UploadRFIDDevelop")]
//[NoSign]
public async Task<HttpResponseMessage> UploadRFIDDevelop([FromBody] JObject jdata)
{
return await Task.Run(() =>
{
try
{
_logger.LogDebug("Inventory/UploadRFIDDevelop第三方/充电台出入库:" + jdata.ToString());
if (jdata != null)
{
var entity = JsonManager.GetJsonEntity(jdata);
if (entity == null)
{
return JsonManager.SimpleCustResponse($"model is null");
}
//第三方调用接口验证orgId正确性
if (!string.IsNullOrEmpty(entity._PUSHORG))
{
if (entity.orgId?.ToString() != entity._PUSHORG.ToString())
{
return JsonManager.SimpleStatusResponse(ResultCode.ORGANIZATION_ERROR);
}
}
else if (string.IsNullOrEmpty(entity.orgId ?? ""))
{
return JsonManager.SimpleCustResponse($"orgId is require");
}
else if (string.IsNullOrEmpty(entity.warehouseId ?? ""))
{
return JsonManager.SimpleCustResponse($"warehouseId is require");
}
var param = new string[] {
};
List<string> Rfids = new List<string>();//本次入库的所有EPC
foreach (var item in entity.RFIDList)
{
string rfidItem = item.RFID;
if (!string.IsNullOrEmpty(rfidItem))
{
Rfids.Add(rfidItem);
}
}
string picUrl = entity.picUrl;
string orderNo = entity.orderNo;
string type = entity.type;
string orgId = entity.orgId;
string policeId = entity.policeId;
string warehouseId = entity.warehouseId;
string outInState = entity.outInState;
var warehouseInfo = _unitOfWork.WarehouseRepository.Get(p => p.Id == warehouseId);
if (warehouseInfo.IsLocked == true)//检查仓库是否被锁
{
return JsonManager.SimpleStatusResponse(ResultCode.WAREHOUSE_LOCK);
}
List<string> ErrorEq = new List<string>();
List<CommonJpEquipmentInventory> UpdateEpc = new List<CommonJpEquipmentInventory>();//更新库存内
List<CommonJpEquipmentInventory> InsertEpc = new List<CommonJpEquipmentInventory>();//新增库存
if (outInState.Equals("出库"))//出库
{
List<CommonJpEquipmentInventory> OuterInvens = _unitOfWork.EquipmentInventoryRepository.GetList(p => p.WarehouseCode.Equals(warehouseId) && p.CurrentState != 5 && p.CurrentState != 6 && p.CurrentState.Equals(0) && Rfids.Contains(p.Epc)).ToList();//取出在库存中的库存信息,表示要出库的物资
if (type.Equals("库存调拨") || type.Equals("跨库借用") || type.Equals("跨库归还"))//0采购,1调拨,2借用,3领用,4维修,5跨库借用,6跨库归还
{
List<CommonJpEquipmentInventory> trOutRealEpcList = new List<CommonJpEquipmentInventory>();
List<CommonJpTransferDetailReality> tempReality = new List<CommonJpTransferDetailReality>();
param = new string[] {
"CommonJpTransferDetailRealities",
"CommonJpTransferDetailRealities.Estimate"
//"Estimate"
};
List<CommonJpTransferDetailReality> UpdateTrReal = new List<CommonJpTransferDetailReality>();//需要更新的调拨数据
List<CommonJpTransferDetailReality> trOutRealDetailEpcList = new List<CommonJpTransferDetailReality>();
var transferOrders = _unitOfWork.TransferRepository.GetList(p => p.Order.Equals(orderNo), null, false, param).FirstOrDefault().CommonJpTransferDetailRealities.ToList();
foreach (var item in transferOrders)
{
var outList = OuterInvens.Where(x => !trOutRealEpcList.Contains(x)
&& x.EquipmentCode.Equals(item.EquipmentDetailId) && x.CurrentState.Equals(0)).ToList();//找出本批物资中调拨出库的物资
trOutRealEpcList.AddRange(outList);
if (!trOutRealDetailEpcList.Contains(item) && item.State.Equals(0))
{
trOutRealDetailEpcList.Add(item);
}
}
if (trOutRealDetailEpcList.Count > 0)
{
if (type.Equals("库存调拨"))
{
tempReality = Extensions.ChannelExtension.TransferOut(trOutRealDetailEpcList, trOutRealEpcList, ref UpdateTrReal, tempReality, ref OuterInvens, ref UpdateEpc, picUrl, policeId, warehouseId, orgId);
}
else if (type.Equals("跨库归还"))
{
tempReality = Extensions.ChannelExtension.ReturnTransferOut(tempReality, trOutRealDetailEpcList, trOutRealEpcList, ref UpdateTrReal, ref OuterInvens, ref UpdateEpc, picUrl, policeId, warehouseId, orgId);
}
else if (type.Equals("跨库借用"))
{
tempReality = Extensions.ChannelExtension.BorrowTransferOut(tempReality, trOutRealDetailEpcList, trOutRealEpcList, ref UpdateTrReal, ref OuterInvens, ref UpdateEpc, picUrl, policeId, warehouseId, orgId);
}
}
if (UpdateTrReal.Count > 0)
{
_unitOfWork.TransferDetailRealityRepository.Update(UpdateTrReal, false);
}
if (UpdateEpc.Count > 0)//同时有插入和更新的数据
{
_unitOfWork.EquipmentInventoryRepository.Update(UpdateEpc, true);
}
}
else if (type.Equals("借用") || type.Equals("领用"))
{
List<CommonJpEquipmentInventory> boOutRealEpcList = new List<CommonJpEquipmentInventory>();
List<CommonJpBorrowReturnDetailReality> tempReality = new List<CommonJpBorrowReturnDetailReality>();
param = new string[] {
"CommonJpBorrowReturnDetailRealities",
"CommonJpBorrowReturnDetailRealities.Estimate"
};
List<CommonJpBorrowReturnDetailReality> UpdateBoReal = new List<CommonJpBorrowReturnDetailReality>();//需要更新的调拨数据
List<CommonJpBorrowReturnDetailReality> boOutRealDetailEpcList = new List<CommonJpBorrowReturnDetailReality>();
var borrowOrders = _unitOfWork.BorrowReturnRepository.GetList(p => p.OrderCode.Equals(orderNo), null, false, param).FirstOrDefault().CommonJpBorrowReturnDetailRealities.ToList();
if (borrowOrders.Count() > 0)
{
if (type.Equals("借用"))
{
UpdateBoReal = Extensions.ChannelExtension.BorrowOut(borrowOrders, boOutRealDetailEpcList, boOutRealEpcList, ref OuterInvens, ref UpdateEpc, UpdateBoReal, picUrl, policeId, warehouseId, orgId);
}
else if (type.Equals("领用"))
{
UpdateBoReal = Extensions.ChannelExtension.Recipients(_unitOfWork, UpdateBoReal, borrowOrders, ref UpdateEpc, ref boOutRealEpcList, boOutRealDetailEpcList, ref OuterInvens, picUrl, policeId, warehouseId, orgId);
}
}
if (UpdateBoReal.Count > 0)
{
_unitOfWork.BorrowReturnDetailRealityRepository.Update(UpdateBoReal, false);
}
if (UpdateEpc.Count > 0)//同时有插入和更新的数据
{
_unitOfWork.EquipmentInventoryRepository.Update(UpdateEpc, true);
}
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
}
else if (outInState.Equals("入库"))
{
param = new string[] {
"CommonJpEquipmentStates" ,
"CommonJpEquipmentStates.Borrow",
"CommonJpEquipmentStates.Borrow.Estimate",
"CommonJpEquipmentStates.Transfer",
"CommonJpEquipmentStates.Transfer.Estimate"
};
List<CommonJpEquipmentInventory> InsideInvens = _unitOfWork.EquipmentInventoryRepository.GetList(p => !p.CurrentState.Equals(0) && p.CurrentState != 5 && p.CurrentState != 6 && !p.CurrentState.Equals(7) && !p.CurrentState.Equals(3) && !p.CurrentState.Equals(10) && Rfids.Contains(p.Epc), null, false, param).ToList();//取出不在库存中的RFID信息,表示要入库的物资
#region 采购
if (type.Equals("采购"))
{
var paramPurchase = new string[] {
"Detail" ,
"Detail.Order",
"Detail.Order.CommonJpPurchaseDetails"
};
List<CommonJpPurchaseEpc> purchaseEpcList = _unitOfWork.PurchaseEpcsRepository.GetList(p => p.Detail.Order.WarehouseId.Equals(warehouseId) && p.CurrentState.Equals(1), null, false, paramPurchase).ToList();//本仓库的全部采购入库EPC
if (purchaseEpcList.Count > 0)
{
List<CommonJpEquipmentInventory> OuterInvens = new List<CommonJpEquipmentInventory>();
List<CommonJpPurchaseEpc> purchaseEpc = new List<CommonJpPurchaseEpc>();
purchaseEpc = Extensions.ChannelExtension.Purchase(purchaseEpcList, OuterInvens, InsideInvens, Rfids, picUrl, policeId, warehouseId, orgId, ref InsertEpc, ref ErrorEq, _unitOfWork);
if (purchaseEpc.Count > 0)
{
_unitOfWork.PurchaseEpcsRepository.Update(purchaseEpc, false);
}
if (InsertEpc.Count > 0)
{
_unitOfWork.EquipmentInventoryRepository.Insert(InsertEpc, true);
}
}
}
#endregion
#region 维修
if (type.Equals("维修"))
{
List<CommonJpFixUselessDetail> UpdateFixReal = new List<CommonJpFixUselessDetail>();//需要更新的维修数据
param = new string[] {
"Order" ,
};
var fixInRealList = _unitOfWork.FixUselessDetailRepository.GetList(p => p.Order.WarehouseId.Equals(warehouseId) && (p.State.Equals(1)), null, false, param).ToList();//当前仓库的所有维修入库详情表
if (fixInRealList.Count > 0)
{
UpdateFixReal = Extensions.ChannelExtension.Fix(UpdateFixReal, fixInRealList, ref UpdateEpc, ref InsideInvens, picUrl, policeId, warehouseId, orgId);
}
if (UpdateFixReal.Count > 0)
{
_unitOfWork.FixUselessDetailRepository.Update(UpdateFixReal, false);
}
if (UpdateEpc.Count > 0)
{
_unitOfWork.EquipmentInventoryRepository.Update(UpdateEpc, true);
}
}
#endregion
#region 借用
if (type.Equals("借用"))
{
List<CommonJpBorrowReturnDetailReality> UpdateBoReal = new List<CommonJpBorrowReturnDetailReality>();//需要更新的借用领用数据
param = new string[] {
"Reality" ,
"Estimate",
"CommonJpEquipmentStates"
};
List<CommonJpBorrowReturnDetailReality> boIntoRealDetailEpcList = _unitOfWork.BorrowReturnDetailRealityRepository.GetList(p => p.State < 2 && p.Reality.WarehouseId.Equals(warehouseId), null, false, param).ToList();//找出本仓库的全部借用入库计划表
if (boIntoRealDetailEpcList.Count > 0)
{
UpdateBoReal = Extensions.ChannelExtension.BorrowIn(ref UpdateEpc, UpdateBoReal, boIntoRealDetailEpcList, ref InsideInvens, picUrl, policeId, warehouseId, orgId);
}
if (UpdateBoReal.Count > 0)
{
_unitOfWork.BorrowReturnDetailRealityRepository.Update(UpdateBoReal, false);
}
if (UpdateEpc.Count > 0)
{
_unitOfWork.EquipmentInventoryRepository.Update(UpdateEpc, true);
}
}
#endregion
#region 调拨入库/借用跨库入库/归还入库
if (type.Equals("库存调拨") || type.Equals("跨库借用") || type.Equals("跨库归还"))
{
List<CommonJpTransferDetailReality> UpdateTrReal = new List<CommonJpTransferDetailReality>();//需要更新的调拨数据
param = new string[] {
"Reality" ,
"Estimate",
"CommonJpEquipmentStates"
};
List<CommonJpTransferDetailReality> trIntoRealDetailEpcList = new List<CommonJpTransferDetailReality>();
if (type.Equals("库存调拨"))
{
trIntoRealDetailEpcList = _unitOfWork.TransferDetailRealityRepository.GetList(p => (p.State.Equals(1) || p.State.Equals(0)) && p.Reality.ActionType.Equals(0) && (p.Reality.ReceiveWarehouseId.Equals(warehouseId)
|| p.WarehouseId.Equals(warehouseId)), null, false, param).ToList();//找出本仓库的全部调拨入库计划表
}
else if (type.Equals("跨库借用"))
{
trIntoRealDetailEpcList = _unitOfWork.TransferDetailRealityRepository.GetList(p => (p.State.Equals(1) || p.State.Equals(0)) && p.Reality.ActionType.Equals(1) && (p.Reality.ReceiveWarehouseId.Equals(warehouseId)
|| p.WarehouseId.Equals(warehouseId)), null, false, param).ToList();//找出本仓库的全部借用跨库入库计划表
}
else if (type.Equals("跨库归还"))
{
trIntoRealDetailEpcList = _unitOfWork.TransferDetailRealityRepository.GetList(p => (p.State.Equals(1) || p.State.Equals(0)) && p.Reality.ActionType.Equals(2) && (p.Reality.ReceiveWarehouseId.Equals(warehouseId)
|| p.WarehouseId.Equals(warehouseId) || p.ReceivedWarehouseId.Equals(warehouseId)), null, false, param).ToList();//找出本仓库的全部归还跨库入库计划表
}
if (InsideInvens.Count > 0 && trIntoRealDetailEpcList.Count() > 0)
{
if (type.Equals("库存调拨"))
{
UpdateTrReal = Extensions.ChannelExtension.TransferIn(UpdateTrReal, trIntoRealDetailEpcList.ToList(), ref UpdateEpc, ref InsideInvens, picUrl, policeId, warehouseId, orgId);
}
else if (type.Equals("跨库借用"))
{
UpdateTrReal = Extensions.ChannelExtension.BorrowTransferIn(UpdateTrReal, trIntoRealDetailEpcList.ToList(), ref UpdateEpc, ref InsideInvens, picUrl, policeId, warehouseId, orgId);
}
else if (type.Equals("跨库归还"))
{
UpdateTrReal = Extensions.ChannelExtension.ReturnTransferIn(UpdateTrReal, trIntoRealDetailEpcList.ToList(), ref UpdateEpc, ref InsideInvens, picUrl, policeId, warehouseId, orgId);
}
}
if (UpdateTrReal.Count > 0)
{
_unitOfWork.TransferDetailRealityRepository.Update(UpdateTrReal, false);
}
if (UpdateEpc.Count > 0)
{
_unitOfWork.EquipmentInventoryRepository.Update(UpdateEpc, true);
}
}
#endregion
}
//#endregion
var resultEpc = UpdateEpc?.Select(p => new
{
p.Epc,
p.CurrentState
}).ToList();//更新的库存信息
var resultInsertEpc = InsertEpc?.Select(p => new
{
p.Epc,
p.CurrentState
}).ToList();//新增的库存信息
var resultErrorEpc = ErrorEq?.Select(p => new
{
Epc = p,
CurrentState = 11
}).ToList();//不在该仓库的物资信息
resultEpc.AddRange(resultInsertEpc);
resultEpc.AddRange(resultErrorEpc);
//跨仓库出库业务清空存放位置(只有update.currentState=1:调拨中 8:领用中 15跨仓库借用中 17跨仓库归还中)
if (outInState.Equals("出库"))
{
foreach (var inventory in UpdateEpc.Where(x => new[] { 1, 8, 15, 17 }.Contains(x.CurrentState)))
{
inventory.ShelfId = null;
inventory.ShelfRange = null;
inventory.ShelfRow = null;
inventory.ShelfColumn = null;
}
_unitOfWork.EquipmentInventoryRepository.Update(UpdateEpc);
}
//计算阈值
var sizeList = InsertEpc.Select(x => x.EquipmentSizecode).ToList();
sizeList.AddRange(UpdateEpc.Select(x => x.EquipmentSizecode).ToList());
_unitOfWork.CalcThreshold(sizeList.Distinct().ToList(), orgId, warehouseId);
return JsonManager.ReturnSuccessResponse(resultEpc);
}
else
{
return JsonManager.SimpleStatusResponse(ResultCode.REQUEST_DATA_ERROR);
}
}
catch (Exception ex)
{
_logger.LogError(ex.ToString());
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_FAILED);
}
});
}
/// <summary>
/// Rfid数据上报
/// </summary>
/// <remarks>
......
......@@ -1422,6 +1422,644 @@ namespace JunmpPoliceStation.Controllers
}
/// <summary>
/// 生成打印入库信息
/// </summary>
/// <param name="jdata"></param>
/// <returns></returns>
[HttpPost("GenerateInventory")]
public async Task<HttpResponseMessage> GenerateInventory([FromBody] JObject jdata)
{
return await Task.Run(() =>
{
lock (_insertLockObj)
{
try
{
if (jdata != null)
{
var entity = JsonManager.GetJsonEntity(jdata);
if (entity == null)
{
return JsonManager.SimpleCustResponse($"无效参数");
}
//todo 第三方调用接口验证orgId正确性 将来打印程序接口切换后取消注释
//if (!string.IsNullOrEmpty(entity._PUSHORG))
//{
// if (string.IsNullOrEmpty(entity.warehouseId)
// || _unitOfWork.WarehouseRepository.Get(entity.warehouseId)?.OrgizationId != entity._PUSHORG.ToString()
// )
// {
// return JsonManager.SimpleStatusResponse(ResultCode.ORGANIZATION_ERROR);
// }
//}
string sizeId = entity?.sizeId ?? "";
string equId = entity?.equId ?? "";
string epc = entity?.epc ?? "";
string supplierId = entity?.supplierId ?? "";
string warehouseId = entity?.warehouseId ?? "";
bool bProduct = DateTime.TryParse(entity?.productTime ?? "", out DateTime productTime);
bool bWarranty = int.TryParse(entity?.warrantyCycle ?? "0", out int warrantyCycle);
bool bPrice = decimal.TryParse(entity?.price ?? "0", out decimal price);
bool bUse = DateTime.TryParse(entity?.useTime ?? "", out DateTime useTime);
bool bRepair = int.TryParse(entity?.repairCycle ?? "0", out int repairCycle);
bool.TryParse(entity.isUnboxingLabel, out bool isUnboxingLabel);
if (string.IsNullOrEmpty(sizeId))
{
return JsonManager.SimpleCustResponse($"无效号型");
}
else if (string.IsNullOrEmpty(equId))
{
return JsonManager.SimpleCustResponse($"无效装备");
}
else if (string.IsNullOrEmpty(epc))
{
return JsonManager.SimpleCustResponse($"无效EPC");
}
else if (!CheckEpc(epc, equId))
{
return JsonManager.SimpleCustResponse($"EPC与装备不匹配");
}
else if (string.IsNullOrEmpty(supplierId))
{
return JsonManager.SimpleCustResponse($"无效供应商");
}
else if (string.IsNullOrEmpty(warehouseId))
{
return JsonManager.SimpleCustResponse($"无效仓库");
}
else if (!bRepair || repairCycle <= 0)
{
return JsonManager.SimpleCustResponse($"无效的装维保周期");
}
else if (!bPrice || price <= 0)
{
return JsonManager.SimpleCustResponse($"无效的购入单价");
}
else if (!bWarranty || warrantyCycle < 0) //质保周期可以为0
{
return JsonManager.SimpleCustResponse($"无效的质保周期");
}
else if (warrantyCycle > 999)
{
return JsonManager.SimpleCustResponse($"质保周期不能超过999个月");
}
else if (repairCycle > 999)
{
return JsonManager.SimpleCustResponse($"维保周期不能超过999个月");
}
else if (!bUse || useTime == default)
{
return JsonManager.SimpleCustResponse($"无效使用日期");
}
else if (!bProduct || productTime == default)
{
return JsonManager.SimpleCustResponse($"无效生产日期");
}
else if (isUnboxingLabel == false && _unitOfWork.EquipmentInventoryRepository.Any(t => t.Epc.ToUpper() == epc.ToUpper()))
{
return JsonManager.SimpleCustResponse($"生成库存失败,库存内已存在此EPC");
}
else
{
using (var scope = _unitOfWork.BeginTransaction())
{
try
{
bool res = false;
if (isUnboxingLabel)
{
var inv = _unitOfWork.EquipmentInventoryRepository.Get(t =>
t.Epc.ToUpper() == epc.ToUpper());
if (inv == null)
{
return JsonManager.SimpleCustResponse($"物资异常");
}
inv.InstantiationState = 2;
res = _unitOfWork.EquipmentInventoryRepository.Update(inv);
if (res)
{
//上报更新物资
var httpResult = _httpHelper.GetHtml(new HttpItem()
{
URL = _httpHelper._centerServerAddress + "/api/Print/EditInventory",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Timeout = 5000,
Postdata = _httpHelper.CreatePostData(JsonConvert.SerializeObject(new
{
data = new List<object>()
{
new
{
editType="UPDATE",
id = inv.Id,
policeCode=inv.PoliceCode,
warehouseCode=inv.WarehouseCode,
cabinetId=inv.CabinetId,
equipmentLocation=inv.EquipmentLocation,
currentState=inv.CurrentState,
warrantyCycle=inv.WarrantyCycle,
repairCycle=inv.RepairCycle,
productTime=inv.ProductTime,
useTime=inv.UseTime,
price=inv.Price,
isBorrowed=inv.IsBorrowed,
lostFlag=inv.LostFlag,
inventoryState = inv.InventoryState,
isInBox=inv.IsInBox,
boxMarkId=inv.BoxMarkId,
instantiationState=inv.InstantiationState,
}
}
}))
});
if (httpResult.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(httpResult.Html))
{
scope.Rollback();
return JsonManager.SimpleCustResponse("远端上报数据失败");
}
var obj = JsonConvert.DeserializeObject<JmpBaseResponse<object>>(httpResult.Html);
if (obj.code != "10000")
{
scope.Rollback();
return JsonManager.SimpleCustResponse(obj.msg);
}
}
}
else
{
var ent = new CommonJpEquipmentInventory
{
Id = Guid.NewGuid().ToString(),
Epc = epc,
SupplierCode = supplierId,
EquipmentCode = equId,
WarehouseCode = warehouseId,
EquipmentLocation = 0,
CurrentState = 0,
CreateTime = DateTime.Now,
CreateUser = "internal",
EquipmentSizecode = sizeId,
UpdateUser = "internal",
Price = price,
ProductTime = productTime,
UseTime = useTime,
UseDirection = 0,
WarrantyCycle = warrantyCycle,
RepairCycle = repairCycle,
IsBorrowed = false,
InstantiationState = 2,
};
//上报新增物资
var httpResult = _httpHelper.GetHtml(new HttpItem()
{
URL = _httpHelper._centerServerAddress + "/api/Print/EditInventory",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Timeout = 5000,
Postdata = _httpHelper.CreatePostData(JsonConvert.SerializeObject(new
{
data = new List<object>()
{
new
{
editType = "ADD",
id = ent.Id,
supplierCode = ent.SupplierCode,
epc = ent.Epc,
policeCode = ent.PoliceCode,
equipmentCode = ent.EquipmentCode,
warehouseCode = ent.WarehouseCode,
cabinetId = ent.CabinetId,
equipmentSizecode = ent.EquipmentSizecode,
equipmentLocation = ent.EquipmentLocation,
currentState = ent.CurrentState,
createTime = ent.CreateTime,
warrantyCycle = ent.WarrantyCycle,
repairCycle = ent.RepairCycle,
productTime = ent.ProductTime,
useTime = ent.UseTime,
price = ent.Price,
isBorrowed = ent.IsBorrowed,
lostFlag = ent.LostFlag,
inventoryState = ent.InventoryState,
isInBox = ent.IsInBox,
boxMarkId = ent.BoxMarkId,
instantiationState = ent.InstantiationState,
}
}
}))
});
if (httpResult.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(httpResult.Html))
{
scope.Rollback();
return JsonManager.SimpleCustResponse("远端上报数据失败");
}
var obj = JsonConvert.DeserializeObject<JmpBaseResponse<object>>(httpResult.Html);
if (obj.code != "10000")
{
scope.Rollback();
return JsonManager.SimpleCustResponse(obj.msg);
}
res = _unitOfWork.EquipmentInventoryRepository.Insert(ent);
}
if (res)
{
scope.Commit();
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_SUCCESS);
}
else
{
scope.Rollback();
return JsonManager.SimpleCustResponse("数据写入失败");
}
}
catch (Exception e)
{
scope.Rollback();
throw;
}
}
}
}
else
{
return JsonManager.SimpleCustResponse($"无效参数");
}
}
catch (Exception ex)
{
_logger.LogError(ex.ToString());
if (ex.Message == "CRC校验失败")
{
return JsonManager.SimpleCustResponse($"EPC CRC校验失败");
}
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_FAILED);
}
}
});
}
/// <summary>
/// 生成打印入库信息(多个epc,第三方使用)
/// </summary>
/// <param name="jdata"></param>
/// <returns></returns>
/// <remarks>
/// ## 例子
///
/// {
/// "epcList":[{
/// "epc": "",
/// "equId": "",
/// "sizeId": "",
/// "supplierId": "",
/// "warehouseId": "",
/// "productTime": "",
/// "warrantyCycle": "",
/// "price": "",
/// "useTime": "",
/// "repairCycle": ""
/// }]
/// }
/// </remarks>
[HttpPost("GenerateRangeInventoryDevelop")]
public async Task<HttpResponseMessage> GenerateRangeInventoryDevelop([FromBody] JObject jdata)
{
return await Task.Run(() =>
{
lock (_insertLockObj)
{
try
{
if (jdata != null)
{
var entity = JsonManager.GetJsonEntity(jdata);
if (entity == null)
{
return JsonManager.SimpleCustResponse($"无效参数");
}
else
{
var list = new List<dynamic>(entity.epcList);
if (list.Count == 0)
{
return JsonManager.SimpleCustResponse($"epcList is require");
}
var warehouseIdList = list.GroupBy(x => x.warehouseId);
foreach (var warehouseIdData in warehouseIdList)
{
if (!string.IsNullOrEmpty(warehouseIdData.Key))
{
//第三方调用接口验证orgId正确性
if (!string.IsNullOrEmpty(entity._PUSHORG))
{
if (string.IsNullOrEmpty(warehouseIdData.Key)
|| _unitOfWork.WarehouseRepository.Get(warehouseIdData.Key)?.OrgizationId != entity._PUSHORG.ToString()
)
{
return JsonManager.SimpleStatusResponse(ResultCode.ORGANIZATION_ERROR);
}
}
}
}
//检查epc是否重复
var distinct = list.Select(x => (string)x.epc ?? "").Distinct();
if (distinct.Count() != list.Count)
{
return JsonManager.SimpleCustResponse("上报数据存在重复EPC");
}
using (var scope = _unitOfWork.BeginTransaction())
{
try
{
var addList = new List<CommonJpEquipmentInventory>();
var updateList = new List<CommonJpEquipmentInventory>();
foreach (dynamic obj in list)
{
string sizeId = obj?.sizeId ?? "";
string equId = obj?.equId ?? "";
string epc = obj?.epc ?? "";
string supplierId = obj?.supplierId ?? "";
string warehouseId = obj?.warehouseId ?? "";
bool bProduct = DateTime.TryParse(obj?.productTime ?? "", out DateTime productTime);
bool bWarranty = int.TryParse(obj?.warrantyCycle ?? "0", out int warrantyCycle);
bool bPrice = decimal.TryParse(obj?.price ?? "0", out decimal price);
bool bUse = DateTime.TryParse(obj?.useTime ?? "", out DateTime useTime);
bool bRepair = int.TryParse(obj?.repairCycle ?? "0", out int repairCycle);
bool.TryParse(obj.isUnboxingLabel, out bool isUnboxingLabel);
if (string.IsNullOrEmpty(sizeId))
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"无效号型 epc:" + epc);
}
else if (string.IsNullOrEmpty(equId))
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"无效装备 epc:" + epc);
}
else if (string.IsNullOrEmpty(epc))
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"无效EPC epc:" + epc);
}
try
{
if (!CheckEpc(epc, equId))
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"EPC与装备不匹配 epc:" + epc);
}
}
catch (Exception e)
{
if (e.Message == "CRC校验失败")
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"EPC CRC校验失败 epc:" + epc);
}
throw;
}
if (string.IsNullOrEmpty(supplierId))
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"无效供应商 epc:" + epc);
}
else if (string.IsNullOrEmpty(warehouseId))
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"无效仓库 epc:" + epc);
}
else if (!bRepair || repairCycle <= 0)
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"无效的装维保周期 epc:" + epc);
}
else if (!bPrice || price <= 0)
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"无效的购入单价 epc:" + epc);
}
else if (!bWarranty || warrantyCycle < 0) //质保周期可以为0
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"无效的质保周期 epc:" + epc);
}
else if (warrantyCycle > 999)
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"质保周期不能超过999个月");
}
else if (repairCycle > 999)
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"维保周期不能超过999个月");
}
else if (!bUse || useTime == default)
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"无效使用日期 epc:" + epc);
}
else if (!bProduct || productTime == default)
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"无效生产日期 epc:" + epc);
}
else if (isUnboxingLabel == false && _unitOfWork.EquipmentInventoryRepository.Any(t => t.Epc.ToUpper() == epc.ToUpper()))
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"生成库存失败,库存内已存在此EPC epc:" + epc);
}
else
{
if (isUnboxingLabel)
{
var inv = _unitOfWork.EquipmentInventoryRepository.Get(t =>
t.Epc.ToUpper() == epc.ToUpper());
if (inv == null)
{
scope.Rollback();
return JsonManager.SimpleCustResponse($"物资异常");
}
inv.InstantiationState = 2;
_unitOfWork.EquipmentInventoryRepository.Update(inv, false);
updateList.Add(inv);
}
else
{
var warehouse = _unitOfWork.WarehouseRepository.Get(warehouseId);
var ent = new CommonJpEquipmentInventory
{
Id = Guid.NewGuid().ToString(),
Epc = epc,
SupplierCode = supplierId,
EquipmentCode = equId,
WarehouseCode = warehouseId,
EquipmentLocation = 0,
CurrentState = 0,
CreateTime = DateTime.Now,
CreateUser = "internal",
EquipmentSizecode = sizeId,
UpdateUser = "internal",
Price = price,
ProductTime = productTime,
UseTime = useTime,
UseDirection = 0,
WarrantyCycle = warrantyCycle,
RepairCycle = repairCycle,
IsBorrowed = false,
InstantiationState = 2,
};
_unitOfWork.EquipmentInventoryRepository.Insert(ent, false);
addList.Add(ent);
}
}
}
var res = _unitOfWork.SaveChanges() > 0;
if (res)
{
//上报数据
var pushData = new
{
data = new List<object>(),
};
pushData.data.AddRange(addList.Select(x => new
{
editType = "ADD",
id = x.Id,
supplierCode = x.SupplierCode,
epc = x.Epc,
policeCode = x.PoliceCode,
equipmentCode = x.EquipmentCode,
warehouseCode = x.WarehouseCode,
cabinetId = x.CabinetId,
equipmentSizecode = x.EquipmentSizecode,
equipmentLocation = x.EquipmentLocation,
currentState = x.CurrentState,
createTime = x.CreateTime,
warrantyCycle = x.WarrantyCycle,
repairCycle = x.RepairCycle,
productTime = x.ProductTime,
useTime = x.UseTime,
price = x.Price,
isBorrowed = x.IsBorrowed,
lostFlag = x.LostFlag,
inventoryState = x.InventoryState,
isInBox = x.IsInBox,
boxMarkId = x.BoxMarkId,
instantiationState = x.InstantiationState,
}));
pushData.data.AddRange(updateList.Select(x => new
{
editType = "UPDATE",
id = x.Id,
supplierCode = x.SupplierCode,
epc = x.Epc,
policeCode = x.PoliceCode,
equipmentCode = x.EquipmentCode,
warehouseCode = x.WarehouseCode,
cabinetId = x.CabinetId,
equipmentSizecode = x.EquipmentSizecode,
equipmentLocation = x.EquipmentLocation,
currentState = x.CurrentState,
createTime = x.CreateTime,
warrantyCycle = x.WarrantyCycle,
repairCycle = x.RepairCycle,
productTime = x.ProductTime,
useTime = x.UseTime,
price = x.Price,
isBorrowed = x.IsBorrowed,
lostFlag = x.LostFlag,
inventoryState = x.InventoryState,
isInBox = x.IsInBox,
boxMarkId = x.BoxMarkId,
instantiationState = x.InstantiationState,
}));
var httpResult = _httpHelper.GetHtml(new HttpItem()
{
URL = _httpHelper._centerServerAddress + "/api/Print/EditInventory",
Encoding = Encoding.UTF8,
Method = "POST",
ContentType = "application/json",
Timeout = 5000,
Postdata = _httpHelper.CreatePostData(JsonConvert.SerializeObject(pushData))
});
if (httpResult.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(httpResult.Html))
{
scope.Rollback();
return JsonManager.SimpleCustResponse("远端上报数据失败");
}
var obj = JsonConvert.DeserializeObject<JmpBaseResponse<object>>(httpResult.Html);
if (obj.code != "10000")
{
scope.Rollback();
return JsonManager.SimpleCustResponse(obj.msg);
}
scope.Commit();
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_SUCCESS);
}
else
{
scope.Rollback();
return JsonManager.SimpleCustResponse("数据写入失败");
}
}
catch (Exception e)
{
scope.Rollback();
throw;
}
}
}
}
else
{
return JsonManager.SimpleCustResponse($"无效参数");
}
}
catch (Exception ex)
{
_logger.LogError(ex.ToString());
if (ex.Message == "CRC校验失败")
{
return JsonManager.SimpleCustResponse($"EPC CRC校验失败");
}
return JsonManager.SimpleStatusResponse(ResultCode.OPERATE_FAILED);
}
}
});
}
/// <summary>
/// 生成打印入库信息(打印程序内部使用)
/// </summary>
/// <param name="jdata"></param>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论