You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
326 lines
12 KiB
C#
326 lines
12 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.User;
|
|
using DS.WMS.Common.Enum;
|
|
using DS.WMS.Core.App.Entity;
|
|
using DS.WMS.Core.System.Dtos;
|
|
using DS.WMS.Core.System.Entity;
|
|
using DS.WMS.Core.WmsModule.Dtos;
|
|
using DS.WMS.Core.WmsModule.Entity;
|
|
using DS.WMS.Core.WmsModule.Interface;
|
|
using Mapster;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.WmsModule.Method;
|
|
|
|
public class WmsInDoService:IWmsInDoService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
|
|
private readonly IWmsCommonService _wmsCommonService;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public WmsInDoService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
_wmsCommonService = _serviceProvider.GetRequiredService<IWmsCommonService>();
|
|
}
|
|
public DataResult<List<WmsInDoListPageModel>> GetListByPage(PageRequest request)
|
|
{
|
|
var companyId = user.GetCompanyId();
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = db.Queryable<OP_WMS_IN_DO>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b) => a.STOREHOUSE == b.AREACODE)
|
|
.Select((a, b) => new WmsInDoListPageModel()
|
|
{
|
|
STOREHOUSENAME = b.AREANAME //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.Where(whereList).ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
|
|
public DataResult<WmsInDoInfoViewModel> GetWmsInDoInfo(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
var data = db.Queryable<OP_WMS_IN_DO>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b) => a.STOREHOUSE == b.AREACODE)
|
|
.Where(a => a.WMSDOID == gid)
|
|
.Select((a, b) => new WmsInDoInfoViewModel()
|
|
{
|
|
STOREHOUSENAME = b.AREANAME //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.First();
|
|
return DataResult<WmsInDoInfoViewModel>.Success(data);
|
|
}
|
|
|
|
public DataResult EditWmsInDoInfo(WmsInDoInput model)
|
|
{
|
|
// var companyId = user.GetCompanyId();
|
|
if (model.WMSDOID.ToString().IsNullOrEmpty())
|
|
{
|
|
// var exitInfo = db.Queryable<OP_WMS_IN_DO>().Where(x => x.MBLNO == model.MBLNO && x.CONTRACTNO == model.CONTRACTNO && x.ClientId == companyId).First();
|
|
// if (exitInfo.IsNotNull())
|
|
// {
|
|
// return DataResult.Failed("存在同一提单号合同号的预约单!");
|
|
// }
|
|
|
|
try
|
|
{
|
|
//开启事务
|
|
db.Ado.BeginTran();
|
|
|
|
var gid = Guid.NewGuid();
|
|
model.WMSDOID = gid;
|
|
var wmsInDo = model.Adapt<OP_WMS_IN_DO>();
|
|
wmsInDo.BSNO = NumUtil.GetBillNo(db,"WM02");
|
|
// wmsInDo.ClientId = companyId;
|
|
wmsInDo.BSSTATUS = false;
|
|
wmsInDo.BILLSTATUS = "1000";
|
|
wmsInDo.FEESTATUS = false;
|
|
// wmsInDo.CORPID = "Comcab2d43f60454327af30a131fc1d3abd";
|
|
|
|
if (model.List.Count()>0)
|
|
{
|
|
var record = model.List.First();
|
|
wmsInDo.GOODSNAME = record.GOODSNAME;
|
|
wmsInDo.GOODSCODE = record.GOODSCODE;
|
|
// wmsInDo.GOODSMODEL = record.GOODSMODEL;
|
|
wmsInDo.TRUCKNO = record.TRUCKNO;
|
|
}
|
|
db.Insertable(wmsInDo).ExecuteCommand();
|
|
|
|
#region 处理计划明细
|
|
|
|
if (model.List.Count()>0)
|
|
{
|
|
foreach (var item in model.List)
|
|
{
|
|
item.WMSDODETAILID = Guid.NewGuid();
|
|
item.WMSDOID = gid;
|
|
// item.WMSPLANID = gid;
|
|
var detail = item.Adapt<OP_WMS_IN_DO_GOODS>();
|
|
|
|
db.Insertable(detail).ExecuteCommand();
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("添加成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("添加失败!" + ex);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
|
|
var doInfo = model.Adapt<OP_WMS_IN_DO>();
|
|
var gid = doInfo.WMSDOID;
|
|
var exitInfo = db.Queryable<OP_WMS_IN_DO>().First(x => x.WMSDOID == gid);
|
|
if (exitInfo.BILLSTATUS == "1002" )
|
|
{
|
|
return DataResult.Failed("已审核通过,不能修改!");
|
|
}
|
|
if (exitInfo.BILLSTATUS == "1003" )
|
|
{
|
|
return DataResult.Failed("已执行入库,不能修改!");
|
|
}
|
|
// if (exitInfo.BSSTATUS == true )
|
|
// {
|
|
// return DataResult.Failed("已审核通过,不能修改!");
|
|
// }
|
|
//开启事务
|
|
db.Ado.BeginTran();
|
|
|
|
if (model.List.Count()>0)
|
|
{
|
|
var record = model.List.First();
|
|
doInfo.GOODSNAME = record.GOODSNAME;
|
|
doInfo.GOODSCODE = record.GOODSCODE;
|
|
// wmsInDo.GOODSMODEL = record.GOODSMODEL;
|
|
doInfo.TRUCKNO = record.TRUCKNO;
|
|
}
|
|
|
|
db.Updateable(doInfo).IgnoreColumns(ignoreAllNullColumns:true).IgnoreColumns(x=> new {x.ClientId,x.CORPID}).ExecuteCommand();
|
|
|
|
|
|
|
|
#region 处理入库确认明细
|
|
if (model.List.Count()>0)
|
|
{
|
|
//先删除 计划明细
|
|
var existGoods = db.Queryable<OP_WMS_IN_DO_GOODS>().Where(x => x.WMSDOID == gid).Select(n=>n.WMSDODETAILID.ToString()).ToArray();
|
|
var inGoods = model.List.Select(x => x.WMSDODETAILID.ToString().ToUpper()).ToArray();
|
|
IEnumerable<string> delGoods = existGoods.AsQueryable().Except(inGoods);
|
|
if (delGoods.Count()>0)
|
|
{
|
|
foreach (var item in delGoods)
|
|
{
|
|
var existInfo = db.Queryable<OP_WMS_IN_DO_GOODS>()
|
|
.Where(x => x.WMSDOID == gid && x.WMSDODETAILID ==Guid.Parse(item)).First();
|
|
db.Deleteable(existInfo).ExecuteCommand();
|
|
}
|
|
}
|
|
//更新 计划明细
|
|
var updateList = model.List.Where(x => x.WMSDODETAILID != null && !delGoods.Contains(x.WMSDODETAILID.ToString())).ToList();
|
|
|
|
foreach (var item in updateList)
|
|
{
|
|
var detail = item.Adapt<OP_WMS_IN_DO_GOODS>();
|
|
|
|
db.Updateable(detail).ExecuteCommand();
|
|
}
|
|
|
|
//追加 计划明细
|
|
var addList = model.List.Where(x => x.WMSDODETAILID == null).ToList();
|
|
|
|
foreach (var item in addList)
|
|
{
|
|
item.WMSDODETAILID = Guid.NewGuid();
|
|
item.WMSDOID = gid;
|
|
var detail = item.Adapt<OP_WMS_IN_DO_GOODS>();
|
|
|
|
db.Insertable(detail).ExecuteCommand();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("更新成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("更新失败!" + ex);
|
|
}
|
|
}
|
|
}
|
|
|
|
public DataResult GetWmsInDoGoodsList(string id)
|
|
{
|
|
var data = db.Queryable<OP_WMS_IN_DO_GOODS>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE_AREA>((a, b) => a.AREACODE == b.AREACODE)
|
|
.Select<WmsInDoGoodsListViewModel>()
|
|
.Mapper(it =>
|
|
{
|
|
//只能写在Select后面
|
|
it.EDITABLE = true;
|
|
})
|
|
.Where(a => a.WMSDOID == Guid.Parse(id)).ToList();
|
|
return DataResult.Successed("查询成功!", data);
|
|
}
|
|
|
|
public DataResult AuditWmsInDo(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
var exitInfo = db.Queryable<OP_WMS_IN_DO>().First(x => x.WMSDOID == gid);
|
|
if (exitInfo.BILLSTATUS == "1002" )
|
|
{
|
|
return DataResult.Failed("已审核通过,不能修改!");
|
|
}
|
|
if (exitInfo.BILLSTATUS == "1003" )
|
|
{
|
|
return DataResult.Failed("已执行入库!");
|
|
}
|
|
|
|
var detail = db.Queryable<OP_WMS_IN_DO_GOODS>().Where(x => x.WMSDOID == gid);
|
|
if (detail.Count()==0)
|
|
{
|
|
return DataResult.Failed("执行明细不能为空!");
|
|
}
|
|
|
|
exitInfo.BILLSTATUS = "1002";
|
|
db.Updateable(exitInfo).ExecuteCommand();
|
|
return DataResult.Successed("审核成功");
|
|
}
|
|
|
|
public DataResult CancelAuditWmsInDo(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
var exitInfo = db.Queryable<OP_WMS_IN_DO>().First(x => x.WMSDOID == gid);
|
|
|
|
if (exitInfo.BILLSTATUS == "1003" )
|
|
{
|
|
return DataResult.Failed("已执行入库!");
|
|
}
|
|
exitInfo.BILLSTATUS = "1000";
|
|
db.Updateable(exitInfo).ExecuteCommand();
|
|
return DataResult.Successed("取消审核成功");
|
|
}
|
|
|
|
|
|
public DataResult AccountWmsInDo(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
var wmsInDo = db.Queryable<OP_WMS_IN_DO>().First(x => x.WMSDOID == gid);
|
|
if (wmsInDo.BILLSTATUS == "1000" )
|
|
{
|
|
return DataResult.Failed("未审核,不能执行!");
|
|
}
|
|
if (wmsInDo.BILLSTATUS == "1003" )
|
|
{
|
|
return DataResult.Failed("已执行入库!");
|
|
}
|
|
|
|
var detail = db.Queryable<OP_WMS_IN_DO_GOODS>().Where(x => x.WMSDOID == gid).ToList();
|
|
if (detail.Count()==0)
|
|
{
|
|
return DataResult.Failed("执行明细不能为空!");
|
|
}
|
|
|
|
try
|
|
{
|
|
//开启事务
|
|
db.Ado.BeginTran();
|
|
|
|
foreach (var item in detail)
|
|
{
|
|
#region 初始化相关信息
|
|
|
|
// var comomService = new WmsCommonService();
|
|
var wms = _wmsCommonService.InitOpWms(wmsInDo,item).Data;
|
|
db.Insertable(wms).ExecuteCommand();
|
|
var wmsBase = _wmsCommonService.InitOpWmsBase(wms,item,null).Data;
|
|
db.Insertable(wmsBase).ExecuteCommand();
|
|
var wmsPhysics = _wmsCommonService.InitOpWmsPhysics(wms,wmsInDo,item).Data;
|
|
db.Insertable(wmsPhysics).ExecuteCommand();
|
|
var wmsChange = _wmsCommonService.InitOpWmsChange(wms,wmsInDo,item).Data;
|
|
db.Insertable(wmsChange).ExecuteCommand();
|
|
|
|
var wmsPhysicsChange = _wmsCommonService.InitOpWmsPhysicsChange(wms.WMSID,wmsPhysics.WMSPHYSICSID,wmsInDo.DODATE,item).Data;
|
|
db.Insertable(wmsPhysicsChange).ExecuteCommand();
|
|
#endregion
|
|
|
|
}
|
|
|
|
wmsInDo.BILLSTATUS = "1003";
|
|
db.Updateable(wmsInDo).ExecuteCommand();
|
|
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("执行成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("执行失败!" + ex);
|
|
}
|
|
}
|
|
} |