using Model.ModelDto;
|
using Model.ModelVm;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using WMS.BLL.LogServer;
|
using WMS.DAL;
|
using WMS.Entity.BllAsnEntity;
|
using WMS.Entity.Context;
|
using WMS.IBLL.IBllAsnServer;
|
|
namespace WMS.BLL.BllAsnServer
|
{
|
public class BllBoxInfoServer:DbHelper<BllBoxInfo>,IBllBoxInfoServer
|
{
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
|
public BllBoxInfoServer():base(Db)
|
{
|
}
|
|
//添加箱码信息
|
public string AddBoxInfo(BoxInfoVm model)
|
{
|
string strMessage = "";
|
string sqlString = string.Empty;
|
try
|
{
|
if (string.IsNullOrEmpty(model.BoxNo))
|
{
|
strMessage = "-1:箱码不可为空!";
|
return strMessage;
|
}
|
//if (string.IsNullOrEmpty(model.BoxNo2))
|
//{
|
// strMessage = "-1:盒码不可为空!";
|
// return strMessage;
|
//}
|
if (string.IsNullOrEmpty(model.BoxNo3))
|
{
|
strMessage = "-1:支码不可为空!";
|
return strMessage;
|
}
|
if (string.IsNullOrEmpty(model.SkuNo))
|
{
|
strMessage = "-1:物料编码不可为空!";
|
return strMessage;
|
}
|
if (string.IsNullOrEmpty(model.LotNo))
|
{
|
strMessage = "-1:批次号不可为空!";
|
return strMessage;
|
}
|
if (model.Qty == null || model.Qty <= 0)
|
{
|
strMessage = "-1:实际数量必须大于0!";
|
return strMessage;
|
}
|
if (string.IsNullOrEmpty(model.ProductionTime))
|
{
|
strMessage = "-1:生产日期不可为空!";
|
return strMessage;
|
}
|
|
// 验证是否重复 支/袋码
|
sqlString += $@"select count(id) from BllBoxInfo where BoxNo3 = '{model.BoxNo3}' and IsDel = 0 ";
|
int rowCount = Db.Ado.GetInt(sqlString);
|
if (rowCount > 0)
|
{
|
strMessage = "-1:重复数据!";
|
return strMessage;
|
}
|
// 获取物料信息
|
sqlString = "select tb1.SkuNo,tb1.SkuName,tb1.Warranty, ";
|
sqlString += "case tb2.level when 5 then tb2.L4Num when 4 then tb2.L3Num when 3 then tb2.L2Num else 0 end as FullQty ";
|
sqlString += "from SysMaterials as tb1 left join SysPackag as tb2 on tb1.PackagNo = tb2.PackagNo ";
|
sqlString += $"where SkuNo = '{model.SkuNo}' and tb1.IsDel = '0';";
|
var materialModel = Db.Ado.SqlQuery<BoxInfoVm>(sqlString);
|
if (materialModel.Count <= 0)
|
{
|
strMessage = "-1:该物料信息不存在!";
|
return strMessage;
|
}
|
DateTime Ptime = DateTime.Parse(model.ProductionTime);
|
double dayNum = (int)materialModel[0].Warranty;
|
model.ExpirationTime = Ptime.AddDays(dayNum);
|
if (string.IsNullOrEmpty(model.InspectMark))
|
{
|
model.InspectMark = "0";
|
}
|
if (string.IsNullOrEmpty(model.BitBoxMark))
|
{
|
model.BitBoxMark = "0";
|
}
|
|
// 插入信息
|
sqlString = "Insert into BllBoxInfo (BoxNo,BoxNo2,BoxNo3,SkuNo,SkuName,LotNo,LotText,";
|
sqlString += "Qty,FullQty,ProductionTime,ExpirationTime,InspectMark,InspectStatus,BitBoxMark,Origin,Status,CreateUser) values ( ";
|
sqlString += $"'{model.BoxNo}','{model.BoxNo2}','{model.BoxNo3}','{model.SkuNo}', ";
|
sqlString += $"'{materialModel[0].SkuName}','{model.LotNo}','{model.LotText}','{model.Qty}','{materialModel[0].FullQty}',";
|
sqlString += $"'{model.ProductionTime}','{model.ExpirationTime}','{model.InspectMark}','1','{model.BitBoxMark}','{model.Origin}','0','{model.CreateUser}');";
|
|
rowCount = Db.Ado.ExecuteCommand(sqlString);
|
if (rowCount <= 0)
|
{
|
strMessage = "-1:添加失败!";
|
}
|
else
|
{
|
if (model.Origin == "录入")
|
{
|
new OperationASNServer().AddLogOperationAsn("入库作业", "物料信息录入", model.BoxNo3, "添加", $"添加了箱码:{model.BoxNo}、追溯码:{model.BoxNo3}的箱支物料信息", Convert.ToInt32(model.CreateUser));
|
}
|
}
|
|
return strMessage;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
//删除箱码信息
|
public string DelBoxInfo(BoxInfoVm model)
|
{
|
string sqlString = string.Empty;
|
try
|
{
|
var boxInfo = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.Id == model.Id);
|
if (boxInfo == null)
|
{
|
throw new Exception("未查询到信息");
|
}
|
// 删除明细单
|
sqlString += $"UPDATE BllBoxInfo SET IsDel = '1',";
|
sqlString += $"UpdateTime = GETDATE(),UpdateUser = '{model.CreateUser}' ";
|
sqlString += $"WHERE Id = '{model.Id}' and Status = '0';";
|
|
int rowCount = Db.Ado.ExecuteCommand(sqlString);
|
if (rowCount <= 0)
|
{
|
return "-1:状态已变更无法删除!";
|
}
|
new OperationASNServer().AddLogOperationAsn("入库作业", "物料信息录入", boxInfo.BoxNo3, "删除", $"删除了箱码:{boxInfo.BoxNo}、追溯码:{boxInfo.BoxNo3}的箱支物料信息", Convert.ToInt32(model.CreateUser));
|
return "";
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
//获取箱码信息(未绑定托盘的箱码)
|
public List<BoxInfoDto> GetBoxInfoList(BoxInfoVm model, out int count)
|
{
|
string sqlString = string.Empty;
|
string sqlCount = string.Empty;
|
string sqlPub = string.Empty;
|
try
|
{
|
if (model.Page == 0)
|
{
|
model.Page = 1;
|
}
|
sqlCount += $"select tb1.* ,tb2.RealName as CreateUserName,tb3.RealName as UpdateUserName from BllBoxInfo as tb1 ";
|
sqlString += "select tb1.* ,tb2.RealName as CreateUserName,tb3.RealName as UpdateUserName from BllBoxInfo as tb1 ";
|
sqlPub += "left join SysUserInfor as tb2 on tb1.CreateUser = tb2.id ";
|
sqlPub += "left join SysUserInfor as tb3 on tb1.CreateUser = tb3.id ";
|
sqlPub += $"WHERE tb1.BoxNo LIKE '%{model.BoxNo}%' AND tb1.BoxNo2 LIKE '%{model.BoxNo2}%' ";
|
sqlPub += $"AND tb1.BoxNo3 LIKE '%{model.BoxNo3}%' AND tb1.SkuNo LIKE '%{model.SkuNo}%' ";
|
sqlPub += $"AND tb1.LotNo LIKE '%{model.LotNo}%' AND tb1.LotText LIKE '%{model.LotText}%' ";
|
|
if (!string.IsNullOrEmpty(model.ProductionTime))
|
{
|
sqlPub += $"AND tb1.ProductionTime >= '{model.ProductionTime}' ";
|
}
|
if (!string.IsNullOrEmpty(model.InspectMark))
|
{
|
sqlPub += $"AND tb1.InspectMark = '{model.InspectMark}' ";
|
}
|
if (!string.IsNullOrEmpty(model.BitBoxMark))
|
{
|
sqlPub += $"AND tb1.BitBoxMark = '{model.BitBoxMark}' ";
|
}
|
//if (!string.IsNullOrEmpty(model.Origin))
|
//{
|
// sqlPub += $"AND tb1.Origin = '{model.Origin}' ";
|
//}
|
|
sqlPub += $"AND tb1.IsDel = '0' and tb1.Status = '0' order by tb1.CreateTime desc ";
|
sqlString += sqlPub + $"offset {((model.Page - 1) * model.Limit)} rows fetch next {model.Limit} rows only;";
|
|
count = Db.Ado.GetInt(sqlCount + sqlPub);
|
List<BoxInfoDto> modelList = new List<BoxInfoDto>();
|
if (count != 0)
|
{
|
modelList = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
|
}
|
|
return modelList;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
//导入箱码信息
|
public string ImportBoxInfo(BoxInfoVms models)
|
{
|
string strMessage = "";
|
try
|
{
|
if (models.ListBoxInfo.Count <= 0)
|
{
|
strMessage = "-1:文件内无数据请核实!";
|
}
|
|
var num = 0;
|
foreach (BoxInfoVm model in models.ListBoxInfo)
|
{
|
try
|
{
|
model.CreateUser = models.CreateUser;
|
model.Origin = "导入";
|
var msg = AddBoxInfo(model);
|
strMessage += msg;
|
if (msg == "")
|
{
|
num += 1;
|
new OperationASNServer().AddLogOperationAsn("入库作业", "物料信息录入", model.BoxNo3, "导入", $"导入了箱码:{model.BoxNo}、追溯码:{model.BoxNo3}箱支物料信息", Convert.ToInt32(model.CreateUser));
|
}
|
}
|
catch
|
{
|
// ignored
|
}
|
}
|
|
if (strMessage.Contains("-1") && num > 0)
|
{
|
return "部分导入成功" + strMessage;
|
}
|
if (num>0)
|
{
|
return "导入成功" + strMessage;
|
}
|
|
return strMessage;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
}
|
}
|