using Admin.NET.Core.BasicInformation.Enum;
|
using Admin.NET.Core.TaskModule.Enum;
|
using iWareCommon.Utils;
|
using iWareModel.Entity.MES;
|
using iWareModel.Entity.WCS;
|
using iWareModel.Struct;
|
using iWareSql.MyDbContext;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data.Entity;
|
using System.Linq;
|
|
|
namespace iWareCC.Common.Helper
|
{
|
|
/// <summary>
|
/// 增补创建的扩展帮助类 【EditBy shaocx,2022-02-05】
|
/// </summary>
|
public class MyExtendHelper
|
{
|
|
|
|
|
|
/// <summary>
|
/// 判断一二巷道堆垛机是否故障
|
/// </summary>
|
/// <param name="mycontext"></param>
|
/// <param name="ContainerCode"></param>
|
/// <returns></returns>
|
public static void GetDevicesInfo(MyDbContext mycontext, string WcsIp, ref List<int> useSrmList)
|
{
|
#region 检验堆垛机是否故障
|
WCSDevicesOutput data1 = null;
|
if (FormCC.IsSimulationPLC)
|
{//如果是模拟
|
data1 = MyExtendHelper.GetSimulationSrmDevicesOutput();
|
Log4NetHelper.WriteInfoLog(LogType.OutPlanTask, "出库处理的线程(OutPlanTaskHandler)查询堆垛机是否空闲,模拟环境");
|
SystemWarningMsg._lbl_Alert_OutPlanTaskHandler = "堆垛机状态查询模拟";
|
}
|
else
|
{
|
var utl = string.Format(WcsIp + @"GetDevicesInfo?Timestamp={0}&Creator={1}", DateTime.Now.ToString(), "cc");
|
//var result1 = HttpHelper.Post(utl, "");
|
IDictionary<string, string> parameter = new Dictionary<string, string>();
|
var result1 = new HTTPService(WcsIp).postContentForString(utl, parameter, "");
|
if (result1 == null)
|
{
|
SystemWarningMsg._lbl_Alert_OutPlanTaskHandler = "堆垛机状态查询失败,WCS返回NULL";
|
}
|
data1 = JsonConvert.DeserializeObject<WCSDevicesOutput>(result1);
|
if (data1 == null || !data1.Success || data1.Data == null)
|
{
|
SystemWarningMsg._lbl_Alert_OutPlanTaskHandler = "堆垛机状态查询失败,WCS返回" + result1;
|
}
|
}
|
|
bool SRM1 = false;
|
bool SRM2 = false;
|
var dev = data1.Data.SRM1;
|
if (dev == null || dev.Alram != "0" || dev.isConnect != "是")
|
{
|
SRM1 = true;
|
}
|
else
|
{
|
useSrmList.Add(1);
|
}
|
|
dev = data1.Data.SRM2;
|
if (dev == null || dev.Alram != "0" || dev.isConnect != "是")
|
{
|
SRM2 = true;
|
}
|
else
|
{
|
useSrmList.Add(2);
|
}
|
|
if (SRM2 == true && SRM1 == true)
|
{
|
SystemWarningMsg._lbl_Alert_OutPlanTaskHandler = "堆垛机1,堆垛机2故障,无法下发任务";
|
}
|
|
//这个逻辑是不对的 【Editby shaocx,2023-12-29】
|
//int a = 0;
|
//if (SRM1 == true)
|
//{
|
// a = 2;
|
//}
|
//if (SRM2 == true)
|
//{
|
// a = 1;
|
//}
|
//if (SRM1 == false && SRM2 == false)
|
//{
|
// var count = mycontext.wms_task.Where(x => x.Id > 0).ToList();
|
// a = count.Count() % 2 + 1;//1,2巷道评均入库
|
//}
|
//return a;
|
#endregion
|
}
|
|
/// <summary>
|
/// 获取 托盘类型
|
/// </summary>
|
/// <param name="mycontext"></param>
|
/// <param name="containerCode"></param>
|
/// <param name="arr"></param>
|
/// <param name="isLane3"></param>
|
/// <returns></returns>
|
public static int GetPalletType(MyDbContext mycontext, string containerCode, ref bool isLane3)
|
{
|
var containers2 = GetWareContainerType(mycontext, containerCode);//查询容器类型
|
isLane3 = false;
|
int PalletType = 0;
|
//if (containers2.WareMaterialTypeCode == "292302417842245" || containers2.WareMaterialTypeCode == "293486279884869")
|
if (containers2.WareMaterialTypeCode == WmsCarrierType.CarrierType_大料箱.ToString() || containers2.WareMaterialTypeCode == WmsCarrierType.CarrierType_塑料托盘.ToString())
|
{
|
PalletType = 1;//大料箱 或 塑料托盘
|
}
|
else
|
{
|
PalletType = 2;//小料箱 或 刚托盘
|
}
|
|
// if (containers2.WareMaterialTypeCode == "293486279884869" || containers2.WareMaterialTypeCode == "299120688255045")//判断是否为托盘
|
if (containers2.WareMaterialTypeCode == WmsCarrierType.CarrierType_塑料托盘.ToString() || containers2.WareMaterialTypeCode == WmsCarrierType.CarrierType_钢制托盘.ToString())//判断是否为托盘
|
{
|
isLane3 = true;//托盘入3巷道
|
}
|
|
return PalletType;
|
}
|
|
/// <summary>
|
/// 查找容器类型
|
/// </summary>
|
/// <param name="mycontext"></param>
|
/// <param name="ContainerCode"></param>
|
/// <returns></returns>
|
public static WareContainerType GetWareContainerType(MyDbContext mycontext, string ContainerCode)
|
{
|
return mycontext.wms_base_container_type.Join(mycontext.wms_base_container,
|
a => a.Id,
|
b => b.ContainerTypeId, (a, b) => new WareContainerType
|
{
|
WareMaterialTypeCode = a.Id.ToString(),
|
ContainerCode = b.ContainerCode
|
}).Where(x => x.ContainerCode == ContainerCode).FirstOrDefault();//查询容器类型
|
}
|
|
/// <summary>
|
/// 获取 字典数据的值
|
/// </summary>
|
/// <param name="_sysDictDataRep"></param>
|
/// <param name="sysDictDataEnum"></param>
|
/// <returns></returns>
|
public static string GetSysDictData(MyDbContext dbContext, SysDictDataEnum sysDictDataEnum)
|
{
|
var sysDictData = dbContext.SysDictData.Where(x => x.Code == sysDictDataEnum.ToString()).FirstOrDefault();
|
if (sysDictData != null)
|
return sysDictData.Value;
|
return string.Empty;
|
}
|
|
/// <summary>
|
/// 1和2 巷道的,预留出 移库的空闲数
|
/// </summary>
|
/// <param name="_sysDictDataRep"></param>
|
/// <param name="criterionContainerOutputs"></param>
|
/// <returns></returns>
|
public static List<CriterionContainerOutput> RemoveEmptyLocatonForReservedMoveLocationNumByLane12(MyDbContext dbContext, List<CriterionContainerOutput> criterionContainerOutputs)
|
{
|
if (criterionContainerOutputs == null || criterionContainerOutputs.Count == 0)
|
{
|
return criterionContainerOutputs;
|
}
|
var reservedLocationNum = GetSysDictData(dbContext, SysDictDataEnum.ReservedLocationNumForLan12);
|
if (string.IsNullOrEmpty(reservedLocationNum))
|
{//说明没有配置预留移库数
|
return criterionContainerOutputs;
|
}
|
int i_reservedLocationNum = Convert.ToInt32(reservedLocationNum);
|
//1、2巷道的空闲数判断
|
var lan1List = criterionContainerOutputs.Where(x => x.Lane == 1).ToList();
|
var lan2List = criterionContainerOutputs.Where(x => x.Lane == 2).ToList();
|
if (lan1List.Count <= i_reservedLocationNum)
|
{
|
//抛弃1巷道
|
criterionContainerOutputs.RemoveAll(x => x.Lane == 1);
|
}
|
if (lan2List.Count <= i_reservedLocationNum)
|
{
|
//抛弃2巷道
|
criterionContainerOutputs.RemoveAll(x => x.Lane == 2);
|
}
|
return criterionContainerOutputs;
|
}
|
|
|
|
|
/// <summary>
|
/// 锁定和解锁库位
|
/// </summary>
|
/// <param name="isLock">是否是锁定</param>
|
/// <param name="dbContext"></param>
|
/// <param name="location"></param>
|
/// <param name="lockRemark"></param>
|
public static void LockLocation(bool isLock, MyDbContext dbContext, string placeCode, string lockRemark)
|
{
|
//var _Location = dbContext.wms_base_place.Where(x => x.PlaceCode == placeCode ).FirstOrDefault();
|
//if (isLock)
|
//{
|
// //锁定库位
|
// _Location.PlaceStatus = 1;
|
// _Location.LockRemark = lockRemark;
|
// _Location.UpdatedTime = DateTime.Now;
|
//}
|
//else
|
//{
|
// //解锁库位
|
// _Location.IsLocked = 0;
|
// _Location.LockRemark = lockRemark;
|
// _Location.UpdatedTime = DateTime.Now;
|
//}
|
}
|
|
|
/// <summary>
|
/// 生成虚拟的堆垛机列表
|
/// </summary>
|
/// <returns></returns>
|
public static WCSDevicesOutput GetSimulationSrmDevicesOutput()
|
{
|
WCSDevicesOutput wCSDevicesOutput = new WCSDevicesOutput()
|
{
|
Success = true,
|
Data = new WDO_Dev()
|
{
|
SRM1 = new WDO_Data()
|
{
|
isfree = "1",
|
SrmNo = "1",
|
isConnect = "是",
|
Alram = "0"
|
},
|
SRM2 = new WDO_Data()
|
{
|
isfree = "1",
|
SrmNo = "2",
|
isConnect = "是",
|
Alram = "0"
|
},
|
SRM3 = new WDO_Data()
|
{
|
isfree = "1",
|
SrmNo = "3",
|
isConnect = "是",
|
Alram = "0"
|
},
|
}
|
};
|
return wCSDevicesOutput;
|
}
|
|
/// <summary>
|
/// 生成模拟的WCS返回结果
|
/// </summary>
|
/// <param name="model"></param>
|
public static List<TaskDatailsOutPut> CreateSimulationWcsData(List<wms_task> model)
|
{
|
List<string> str = new List<string>();
|
List<TaskDatailsOutPut> taskDatailsOutPutsList = new List<TaskDatailsOutPut>();
|
foreach (var item in model)
|
{
|
taskDatailsOutPutsList.Add(new TaskDatailsOutPut()
|
{
|
WmsTaskNo = item.TaskNo,
|
FinishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
StartTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
TaskState = 3,
|
ToPlace = item.ToPlaceCode,
|
});
|
}
|
return taskDatailsOutPutsList;
|
}
|
|
|
/// <summary>
|
/// 获取库位对象
|
/// </summary>
|
/// <param name="_wareContainerRep"></param>
|
/// <param name="containerCode"></param>
|
/// <param name="noFoundThrowException"></param>
|
/// <returns></returns>
|
public static wms_base_place GetWareLocationObject(MyDbContext dbContext, string placeCode, bool noFoundThrowException = true)
|
{
|
var wareLocations = dbContext.wms_base_place.Where(x => x.PlaceCode == placeCode).ToList();
|
if (wareLocations == null || wareLocations.Count == 0)
|
{
|
if (noFoundThrowException)
|
{
|
throw new Exception($"根据库位编号{placeCode}没有找到库位的基础数据!");
|
}
|
return null;
|
}
|
if (wareLocations.Count > 1)
|
{
|
throw new Exception($"根据库位编号{placeCode}找到库位的基础数据{wareLocations.Count}条!");
|
}
|
return wareLocations.First();
|
}
|
|
/// <summary>
|
/// 判断库位是否是平库
|
/// </summary>
|
/// <param name="dbContext"></param>
|
/// <param name="locationCode"></param>
|
/// <returns></returns>
|
public static bool IsPingku(MyDbContext dbContext, string locationCode)
|
{
|
//var vFromLocation = MyExtendHelper.GetWareLocationObject(dbContext, locationCode, false);
|
//if (vFromLocation != null)
|
//{
|
// if (vFromLocation.isPingKu == true) return true;
|
//}
|
return false;
|
}
|
}
|
}
|