安睿特接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
11 KiB

using Newtonsoft.Json;
using System;
using XS_Model;
using XS_DAL;
using System.Collections.Generic;
using System.Linq;
using static XS_BLL.ZH_BLL;
using System.Data;
using System.Text;
namespace XS_BLL
{
/// <summary>
/// 原料截批申请
/// </summary>
public class WMS_TASK_APPLYRELEASE_BLL
{
#region 全局参数
/// <summary>
/// 接口名称,接口日志文件名
/// </summary>
public static string InterfaceName = "api_wms_task_bind";
/// <summary>
/// 接口描述
/// </summary>
public static string InterfaceNote = "物料任务启动/截批申请";
/// <summary>
/// 接口流向
/// </summary>
public static string InterfaceFlow = "WMS==>>WCS";
/// <summary>
/// 反馈JSON
/// </summary>
public static string retJson = string.Empty;
#endregion
/// <summary>
/// 原料截批申请
/// </summary>
/// <param name="recieveBuffer"></param>
/// <returns></returns>
public static string TASK_APPLYRELEASE(string recieveBuffer)
{
IO_INTERFACE_TASK_STATE_LOG model = new IO_INTERFACE_TASK_STATE_LOG();
IO_CONTROL iomode = new IO_CONTROL();
List<IO_CONTROL> iomodes = new List<IO_CONTROL>();
try
{
if (!string.IsNullOrEmpty(recieveBuffer))
{
string retEx = string.Empty;
bool bl = false;
IO_INTERFACE_TASK_STATE_LOG TASK_STATE_LOG = JsonConvert.DeserializeObject<IO_INTERFACE_TASK_STATE_LOG>(recieveBuffer);
//接口 true 开始作业;false 截批结束 转换为 本地 0 初始化/开始作业,1截批
int isbind = TASK_STATE_LOG.isbind ? 0 : 1;
List<IO_INTERFACE_TASK_STATE_LOG> temp = model.GetModelList(" productCode = '" + TASK_STATE_LOG.productCode + "' and taskId = '" + TASK_STATE_LOG.taskId + "' ");
if (isbind == 0)
{
List<IO_INTERFACE_TASK_STATE_LOG> temp2 = model.GetModelList(" productCode != '" + TASK_STATE_LOG.productCode + "' and isbind = 1");
if (temp2.Count > 0)
{
string msg = "存在其它未截批的物料任务:任务号:" + temp2[0].taskId + ",物料编码:" + temp2[0].productCode + ";添加作业失败。";
retJson = UtilityBLL.CreateJson(1, 0, false, msg);
}
else
{
//查询当前物料是否存在启动或截批任务
if (temp.Count == 0)
{
model = new IO_INTERFACE_TASK_STATE_LOG();
model.f_startTime = DateTime.Now;
model.taskId = TASK_STATE_LOG.taskId;
model.productCode = TASK_STATE_LOG.productCode;
model.isbind = TASK_STATE_LOG.isbind;
model.testingRandomPointCode = TASK_STATE_LOG.testingRandomPointCode;
bl = model.Insert(out retEx);
if (bl)
{
DBOperator.DelSql(" delete from IO_INTERFACE_TASK_STATE_LOG where isbind = 0 ", out string err);
}
string msg = "添加物料任务成功:任务号:" + TASK_STATE_LOG.taskId + ",物料编码:" + TASK_STATE_LOG.productCode;
retJson = UtilityBLL.CreateJson(1, 0, true, msg);
}
else
{
bool upBL = model.Update(out retEx, $" isbind = 1 ,testingRandomPointCode = '{TASK_STATE_LOG.testingRandomPointCode}'", " productCode = '" + TASK_STATE_LOG.productCode + "'");
if (upBL)
{
string msg = "物料任务已存在重新开始作业成功:任务号:" + TASK_STATE_LOG.taskId + ",物料编码:" + TASK_STATE_LOG.productCode;
retJson = UtilityBLL.CreateJson(1, 0, true, msg);
}
else
{
string msg = "任务重新开始作业失败:任务号:" + TASK_STATE_LOG.taskId + ",物料编码:" + TASK_STATE_LOG.productCode + ";" + retEx;
retJson = UtilityBLL.CreateJson(1, 0, false, msg);
}
}
}
//retJson = UtilityBLL.CreateJson(1, 1, false, "已经有启动的批次 该批次: 物料编号:" + temp.Select(c => c.productCode).First() + "任务号:" + temp.Select(c => c.taskId).First() + "无法启动");
}
else
{
if (temp.Count > 0)
{
bool blJP = true;
//截批成功 修改 ZH_pallet 状态为 GOODS_COUNT 完成
DataTable dt = DBOperator.GetTableSql("select* from T_Manage_Task where FSTARTDEVICE in (12041, 12045) or FENDDEVICE in (12041, 12045)");
DataTable dt1 = DBOperator.GetTableSql(" select * from ZH_pallet where GOODS_COUNT = 0 ");
if (dt1.Rows.Count > 0)
{
for (int i = 0; i < dt1.Rows.Count; i++)
{
bool bl2 = DBOperator.UpdateSql($"update ZH_pallet set GOODS_COUNT = 1 where Device = {dt1.Rows[i]["Device"]};", out string errer);
if (bl2)
{
//满垛任务申请
string dtime = DateTime.Now.ToString("u");
dtime = dtime.Substring(0, dtime.Length - 1);
StringBuilder sql = new StringBuilder();
sql.Remove(0, sql.Length);
sql.AppendLine(" INSERT INTO IO_CONTROL_APPLY ( ");
sql.AppendLine(" CONTROL_APPLY_TYPE, WAREHOUSE_CODE,DEVICE_CODE");//任务类型、库房编码、位置(起始站台)
sql.AppendLine(" , STOCK_BARCODE, APPLY_TASK_STATUS, CREATE_TIME ");//托盘条码、申请任务转态、申请时间
sql.AppendLine(" ,CONTROL_APPLY_REMARK,CONTROL_APPLY_PARAMETER ");//备注、纸箱条码信息
sql.AppendLine(" ) VALUES ( ");
sql.AppendLine($" 14 , 1 , '{dt1.Rows[i]["Device"]}'");// 14 满垛申请
sql.AppendLine($" ,'{dt1.Rows[i]["STOCK_BARCODE"]}',0, '{dtime}'");
sql.AppendLine($" ,'','{dt1.Rows[i]["SN"]}'");
sql.AppendLine(" ) ");
DBOperator.UpdateSql(sql.ToString(), out string err);
}
}
blJP = false;
}
//截批后是否存在码垛传输线任务,无任务,所有码垛站台强制满垛
if (dt == null || dt.Rows.Count <= 0 && dt1.Rows.Count <= 0)
{
bool bl2 = DBOperator.UpdateSql("update IO_INTERFACE_TASK_STATE_LOG set isbind = 0;", out string err);
}
else
{
blJP = false;
}
DataTable dt2 = DBOperator.GetTableSql("select * from IO_INTERFACE_TASK_STATE_LOG where isbind = 1 ");
if (blJP && dt2.Rows.Count <= 0 && dt1.Rows.Count <= 0)
{
if (DBOperator.DelSql(" delete from IO_INTERFACE_TASK_STATE_LOG where isbind = 0 ", out string err))
{
iomodes = iomode.GetModelList("taskflag=1");
foreach (var item in iomodes)
{
DBOperator.UpdateSql($" delete from T_Monitor_Task F_ManageTaskIndex={Convert.ToInt32(item.CONTROL_ID)}", out string erre);
DBOperator.UpdateSql($" delete from T_Manage_Task FID={Convert.ToInt32(item.CONTROL_ID)}", out string errt);
iomode.Delete($"CONTROL_ID='{item.CONTROL_ID}'");
}
string msg = "任务截批成功:任务号:" + TASK_STATE_LOG.taskId + ",物料编码:" + TASK_STATE_LOG.productCode;
retJson = UtilityBLL.CreateJson(1, 0, true, msg);
}
else
{
string msg = "任务截批失败:任务号:" + TASK_STATE_LOG.taskId + ",物料编码:" + TASK_STATE_LOG.productCode + ";" + retEx;
retJson = UtilityBLL.CreateJson(1, 0, false, msg);
}
}
else
{
string msg = "正在截单,请设备停止后工作后再次发起:任务号:" + TASK_STATE_LOG.taskId + ",物料编码:" + TASK_STATE_LOG.productCode + ";" + retEx;
retJson = UtilityBLL.CreateJson(1, 0, false, msg);
}
}
else
{
string msg = "任务截批失败:没有找到该物料编码:" + TASK_STATE_LOG.productCode + ",计划单号:" + TASK_STATE_LOG.taskId + "任务作业;";
retJson = UtilityBLL.CreateJson(1, 0, false, msg);
}
}
}
else
{
retJson = UtilityBLL.CreateJson(1, 1, false, "数据不能为空。。。");
}
UtilityBLL.CreateINTERFACE_LOG(InterfaceName, InterfaceFlow, recieveBuffer, retJson, InterfaceNote);
return retJson;
}
catch (Exception ex)
{
retJson = UtilityBLL.CreateJson(1, 1, false, "异常信息:" + ex.Message);
new DisplaySet().ErrorAddListBoxItem(InterfaceName, ex.Message);
//new DisplaySet().AddListBoxItem(InterfaceName, ex.Message);
LogHelper.LogOperation(InterfaceName, recieveBuffer, retJson);
LogHelper.ErrorLog(ex);
return retJson;
}
}
}
}