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.
193 lines
7.0 KiB
C#
193 lines
7.0 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.User;
|
|
using DS.WMS.Core.BaseInfo.Entity;
|
|
using DS.WMS.Core.WmsModule.Dtos;
|
|
using DS.WMS.Core.WmsModule.Entity;
|
|
using DS.WMS.Core.WmsModule.Interface;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.WmsModule.Method;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class WmsOutDoService:IWmsOutDoService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
|
|
private readonly IWmsCommonService _wmsCommonService;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public WmsOutDoService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
_wmsCommonService = _serviceProvider.GetRequiredService<IWmsCommonService>();
|
|
}
|
|
public DataResult<List<WmsOutDoListPageModel>> GetListByPage(PageRequest request)
|
|
{
|
|
var companyId = user.GetCompanyId();
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = db.Queryable<OP_WMS_OUT_DO>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b) => a.STOREHOUSE == b.AREACODE)
|
|
.Select((a, b) => new WmsOutDoListPageModel()
|
|
{
|
|
STOREHOUSENAME = b.AREANAME //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.Where(whereList).ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
|
|
public DataResult<WmsOutDoInfoViewModel> GetWmsOutDoInfo(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
var data = db.Queryable<OP_WMS_OUT_DO>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b) => a.STOREHOUSE == b.AREACODE)
|
|
.Where(a => a.WMSDOID == gid)
|
|
.Select((a, b) => new WmsOutDoInfoViewModel()
|
|
{
|
|
STOREHOUSENAME = b.AREANAME //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.First();
|
|
return DataResult<WmsOutDoInfoViewModel>.Success(data);
|
|
}
|
|
|
|
public DataResult GetWmsOutDoGoodsList(string id)
|
|
{
|
|
var data = db.Queryable<OP_WMS_OUT_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 AuditWmsOutDo(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
var exitInfo = db.Queryable<OP_WMS_OUT_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_OUT_DO_GOODS>().Where(x => x.WMSDOID == gid).ToList();
|
|
if (detail.Count()==0)
|
|
{
|
|
return DataResult.Failed("执行明细不能为空!");
|
|
}
|
|
|
|
|
|
var stockids = detail.Select(x => x.WMSPHYSICSID).ToList();
|
|
var stocklist = db.Queryable<OP_WMS_PHYSICS>().Where(x => stockids.Contains(x.WMSPHYSICSID)).ToList();
|
|
foreach (var item in detail)
|
|
{
|
|
var stockinfo = stocklist.Where(x => x.WMSPHYSICSID == item.WMSPHYSICSID).First();
|
|
if (item.PKGS > stockinfo.LOCKPKGS)
|
|
{
|
|
return DataResult.Failed("出库确认明细商品[" + item.GOODSNAME +"]锁定库存数量:" + stockinfo.LOCKPKGS +" 不足,不能审批!");
|
|
}
|
|
if (item.STORAGEUNITCOUNT > stockinfo.LOCKSTORAGEUNITCOUNT)
|
|
{
|
|
return DataResult.Failed("出库确认明细商品[" + item.GOODSNAME +"]锁定计费数量:" + stockinfo.LOCKSTORAGEUNITCOUNT +" 不足,不能审批!");
|
|
}
|
|
}
|
|
|
|
exitInfo.BILLSTATUS = "1002";
|
|
db.Updateable(exitInfo).ExecuteCommand();
|
|
return DataResult.Successed("审核成功");
|
|
}
|
|
|
|
public DataResult CancelAuditWmsOutDo(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
var exitInfo = db.Queryable<OP_WMS_OUT_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 AccountWmsOutDo(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
var wmsOutDo = db.Queryable<OP_WMS_OUT_DO>().First(x => x.WMSDOID == gid);
|
|
if (wmsOutDo.BILLSTATUS == "1000" )
|
|
{
|
|
return DataResult.Failed("未审核,不能执行!");
|
|
}
|
|
if (wmsOutDo.BILLSTATUS == "1003" )
|
|
{
|
|
return DataResult.Failed("已执行出库!");
|
|
}
|
|
|
|
var detail = db.Queryable<OP_WMS_OUT_DO_GOODS>().Where(x => x.WMSDOID == gid).ToList();
|
|
if (detail.Count()==0)
|
|
{
|
|
return DataResult.Failed("执行明细不能为空!");
|
|
}
|
|
|
|
try
|
|
{
|
|
//开启事务
|
|
db.Ado.BeginTran();
|
|
|
|
var stockids = detail.Select(x => x.WMSPHYSICSID).ToList();
|
|
var stocklist = db.Queryable<OP_WMS_PHYSICS>().Where(x => stockids.Contains(x.WMSPHYSICSID)).ToList();
|
|
foreach (var item in detail)
|
|
{
|
|
var wmsinfo = db.Queryable<OP_WMS>().Where(x => x.WMSID == item.WMSID).First();
|
|
var stockinfo = stocklist.Where(x => x.WMSPHYSICSID == item.WMSPHYSICSID).First();
|
|
#region 处理相关信息
|
|
var wmsChange = _wmsCommonService.OpWmsOutChange(wmsinfo,wmsOutDo,item).Data;
|
|
db.Insertable(wmsChange).ExecuteCommand();
|
|
|
|
var wms = _wmsCommonService.OpWmsOutReduce(wmsinfo,item).Data;
|
|
db.Updateable(wms).ExecuteCommand();
|
|
|
|
var wmsPhysicsChange = _wmsCommonService.OpWmsPhysicsOutChange(stockinfo,wmsOutDo,item).Data;
|
|
db.Insertable(wmsPhysicsChange).ExecuteCommand();
|
|
|
|
var physics = _wmsCommonService.OpWmsPhysicsOutReduce(stockinfo,item).Data;
|
|
db.Updateable(physics).ExecuteCommand();
|
|
|
|
//TODO处理计划信息
|
|
#endregion
|
|
|
|
}
|
|
|
|
wmsOutDo.BILLSTATUS = "1003";
|
|
db.Updateable(wmsOutDo).ExecuteCommand();
|
|
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("执行成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("执行失败!" + ex);
|
|
}
|
|
}
|
|
} |