using HH.WCS.JingyuNongfu.device;
|
using HH.WCS.JingyuNongfu.wms;
|
using HH.WCS.JingyuNongfu.process;
|
using HH.WCS.JingyuNongfu.util;
|
using Newtonsoft.Json;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading;
|
using static HH.WCS.JingyuNongfu.api.ApiModel;
|
using static HH.WCS.JingyuNongfu.util.Settings;
|
using System;
|
|
namespace HH.WCS.JingyuNongfu.api
|
{
|
/// <summary>
|
/// api接口辅助类
|
/// </summary>
|
public class ApiHelper
|
{
|
static ApiHelper()
|
{
|
|
}
|
|
/// <summary>
|
/// 绑定托盘物料
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static ReturnResult BindArea(BindArea model)
|
{
|
ReturnResult result = new ReturnResult { ResultCode = 0, ResultMsg = "绑定成功" };
|
var db = new SqlHelper<object>().GetInstance();
|
|
try
|
{
|
|
var locList = db.Queryable<Location>().Where(a => a.S_AREA_CODE == model.AreaCode).ToList();
|
if (locList.Count > 0)
|
{
|
var IsLoct = locList.Find(a => a.S_LOCK_STATE.Trim() != "无");
|
if (IsLoct != null)
|
{
|
result.ResultCode = -1;
|
result.ResultMsg = "库区存在货位有锁,不允许绑定托盘物料";
|
return result;
|
}
|
locList.ForEach(a =>
|
{
|
if (a.N_CURRENT_NUM == 0)
|
{
|
LogHelper.Info($"货位{a.S_LOC_CODE}库区绑定,绑定物料{model.ItemCode}");
|
var traylist = ContainerHelper.GenerateCntrNo();
|
ContainerHelper.CreateCntrItem(a.S_LOC_CODE, traylist, model.ItemCode);
|
}
|
|
});
|
|
}
|
else
|
{
|
result.ResultCode = -1;
|
result.ResultMsg = "根据库区找不到货位";
|
return result;
|
}
|
return result;
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = -1;
|
result.ResultMsg = ex.ToString();
|
return result;
|
}
|
|
}
|
|
/// <summary>
|
/// 解绑库区
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static ReturnResult UntieArea(UntieArea model)
|
{
|
ReturnResult result = new ReturnResult { ResultCode = 0, ResultMsg = "解绑成功" };
|
var db = new SqlHelper<object>().GetInstance();
|
try
|
{
|
|
var locList = db.Queryable<Location>().Where(a => a.S_AREA_CODE == model.AreaCode).ToList();
|
if (locList.Count > 0)
|
{
|
var IsLoct = locList.Find(a => a.S_LOCK_STATE.Trim() != "无");
|
if (IsLoct != null)
|
{
|
result.ResultCode = -1;
|
result.ResultMsg = "库区存在货位有锁,不允许解绑托盘";
|
return result;
|
}
|
locList.ForEach(a =>
|
{
|
if (a.N_CURRENT_NUM > 0)
|
{
|
var cntr = db.Queryable<LocCntrRel>().Where(b => b.S_LOC_CODE == a.S_LOC_CODE).First();
|
if (cntr != null)
|
{
|
//起点终点解绑 删除托盘表托盘
|
LogHelper.Info($"货位{a.S_LOC_CODE}库区解绑,删除容器{cntr.S_CNTR_CODE}");
|
LocationHelper.UnBindingLoc(a.S_LOC_CODE, cntr.S_CNTR_CODE.Split(',').ToList());
|
var tpid = cntr.S_CNTR_CODE.Split(',');
|
foreach (var item in tpid)
|
{
|
ContainerHelper.delCntrAndItem(item);
|
}
|
}
|
|
}
|
|
});
|
|
}
|
else
|
{
|
result.ResultCode = -1;
|
result.ResultMsg = "根据库区找不到货位";
|
return result;
|
}
|
return result;
|
}
|
catch (Exception ex)
|
{
|
result.ResultCode = -1;
|
result.ResultMsg = ex.ToString();
|
return result;
|
}
|
|
|
}
|
internal static Location FindEndcolByLocList(List<Location> locations)
|
{
|
try
|
{
|
Location end = null;
|
var db = new SqlHelper<object>().GetInstance();
|
//根据终点货位找空闲货位
|
var rows = locations.Select(a => a.N_ROW).Distinct().ToList();
|
for (int i = 0; i < rows.Count; i++)
|
{
|
var rowList = locations.Where(r => r.N_ROW == rows[i]).ToList();
|
if (rowList.Count(a => a.S_LOCK_STATE != "无") == 0 && rowList.Count(a => a.N_CURRENT_NUM == 0) > 0)
|
{
|
Location other = null;
|
//当前排没有锁并且有空位置
|
//先找满位,然后后面一位要么是空,要么不存在
|
var full = rowList.OrderByDescending(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 1).FirstOrDefault();
|
if (full == null)
|
{
|
|
//没有满位,那就找最小的空位
|
other = rowList.OrderBy(a => a.N_COL).FirstOrDefault();
|
}
|
else
|
{
|
other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_COL > full.N_COL).FirstOrDefault();
|
}
|
if (other != null && (!string.IsNullOrEmpty(other.C_ENABLE) && other.C_ENABLE == "禁用"))
|
{
|
//禁用了选择后面一个货位
|
other = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => (string.IsNullOrEmpty(a.C_ENABLE) || a.C_ENABLE.Trim() != "禁用") && a.S_AREA_CODE == other.S_AREA_CODE && a.N_ROW == other.N_ROW && a.N_COL > other.N_COL).First();
|
|
//LogHelper.Info($"禁用选择后一个货位{result}", "成品");
|
}
|
if (other != null)
|
{
|
end = other;
|
break;
|
|
}
|
|
}
|
}
|
return end;
|
}
|
catch (Exception)
|
{
|
|
throw;
|
}
|
|
}
|
/// <summary>
|
/// 清洁空框位
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static SimpleResult CleanReport(LocationModel model)
|
{
|
var result = new SimpleResult() { resultMsg = $"货位{model.location}清洁报工成功" };
|
//1\3\4 可清洁
|
var cntr = LocationHelper.GetLocCntr(model.location);
|
if (cntr.Count > 0)
|
{
|
ContainerHelper.UpdateCntrState(new List<string> { cntr[0].S_CNTR_CODE.Trim() }, "已清洁");
|
}
|
else
|
{
|
result.resultCode = 1;
|
result.resultMsg = $"货位{model.location}不存在,或者没有容器";
|
}
|
JingyuNongfu.LogHelper.Debug("CleanReport Response:" + JsonConvert.SerializeObject(result));
|
return result;
|
}
|
|
|
/// <summary>
|
/// 重置信号
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static SimpleResult ResetDevice(DeviceModel model)
|
{
|
var result = new SimpleResult();
|
deviceInfo plc = null;
|
if (string.IsNullOrEmpty(model.type))
|
{
|
plc = Settings.deviceInfos.Where(a => a.deviceName == model.deviceName).FirstOrDefault();
|
}
|
else
|
{
|
if (model.type == "下满复位")
|
{
|
plc = Settings.deviceInfos.Where(a => a.deviceName == model.deviceName && a.deviceNo[0] == "1").FirstOrDefault();
|
}
|
else
|
{
|
plc = Settings.deviceInfos.Where(a => a.deviceName == model.deviceName && a.deviceNo[0] == "2").FirstOrDefault();
|
}
|
}
|
|
if (plc != null)
|
{
|
if (model.deviceName.Contains("无菌"))
|
{
|
LogHelper.Info($"调用接口发送信号", "发送信号");
|
if (PlcHelper.SendHex(plc.address, "3F00100D0A"))
|
{
|
Thread.Sleep(300);
|
PlcHelper.SendHex(plc.address, "3F00200D0A");
|
|
}
|
else
|
{
|
result.resultCode = 2;
|
result.resultMsg = "满托重置信号发送失败";
|
}
|
|
}
|
else if (model.deviceName.Contains("翻斗机"))
|
{
|
if (PlcHelper.SendHex(plc.address, "3F0010200D0A"))
|
{
|
|
}
|
else
|
{
|
result.resultCode = 2;
|
result.resultMsg = "重置信号发送失败";
|
}
|
}
|
else if (model.deviceName.Contains("成品"))
|
{
|
if (model.type == "下满复位")
|
{
|
if (model.deviceName.Contains("靖宇成品仓E12输送线"))
|
{
|
PlcHelper.SendHex(plc.address, "3F00200D0A");
|
}
|
else
|
{
|
PlcHelper.SendHex(plc.address, "3F00100D0A");
|
}
|
|
}
|
else
|
{
|
PlcHelper.SendHex(plc.address, "3F00200D0A");
|
}
|
}
|
else
|
{
|
if (PlcHelper.SendHex(plc.address, "3F00100D0A"))
|
{
|
|
}
|
else
|
{
|
result.resultCode = 2;
|
result.resultMsg = "重置信号发送失败";
|
}
|
|
}
|
|
}
|
else
|
{
|
result.resultCode = 1;
|
result.resultMsg = "设备不存在,请检查设备名称";
|
}
|
return result;
|
}
|
|
|
internal static void AddTask(AddTaskModel model)
|
{
|
if (!TaskHelper.CheckExist(model.No))
|
{
|
if (LocationHelper.CheckExist(model.From) && LocationHelper.CheckExist(model.To))
|
{
|
TaskHelper.CreateTask(model.No, model.From, model.To, "搬运", 99, "");
|
}
|
|
}
|
}
|
|
public class AddTaskModel
|
{
|
public string From { get; set; }
|
public string To { get; set; }
|
public string No { get; set; }
|
}
|
public class LocationModel
|
{
|
public string location { get; set; }
|
}
|
public class DeviceModel
|
{
|
/// <summary>
|
/// 瓶盖机名称
|
/// </summary>
|
public string deviceName { get; set; }
|
/// <summary>
|
/// 1 、2
|
/// </summary>
|
//public int order { get; set; }
|
public string type { get; set; }
|
}
|
public class RowInfo
|
{
|
public string area { get; set; }
|
public int row { get; set; }
|
}
|
|
}
|
}
|