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.
167 lines
6.1 KiB
C#
167 lines
6.1 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Common.Enum;
|
|
using DS.WMS.Core.BaseInfo.Dtos;
|
|
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 WmsOutPlanService : IWmsOutPlanService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public WmsOutPlanService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
}
|
|
|
|
public DataResult<List<WmsOutPlanListPageModel>> GetListByPage(PageRequest request)
|
|
{
|
|
var companyId = user.GetCompanyId();
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = db.Queryable<OP_WMS_OUT_PLAN>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b) => a.STOREHOUSE == b.AREACODE)
|
|
.Select((a, b) => new WmsOutPlanListPageModel()
|
|
{
|
|
STOREHOUSENAME = b.AREANAME //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.Where(whereList).Where(a=>a.AuditStatus != AuditStatus.NoAudit.ToEnumInt()).ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
|
|
public DataResult<WmsOutPlanInfoViewModel> GetWmsOutPlanInfo(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
|
|
var data = db.Queryable<OP_WMS_OUT_PLAN>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b) => a.STOREHOUSE == b.AREACODE)
|
|
.Select((a, b) => new WmsOutPlanInfoViewModel()
|
|
{
|
|
STOREHOUSENAME = b.AREANAME //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.Where((a) => a.WMSPLANID == gid)
|
|
.First();
|
|
return DataResult<WmsOutPlanInfoViewModel>.Success(data);
|
|
}
|
|
|
|
public DataResult AuditWmsOutPlan(CommonAuditInput model)
|
|
{
|
|
var userId = user.UserId;
|
|
|
|
var gid = Guid.Parse(model.Id);
|
|
var plan = db.Queryable<OP_WMS_OUT_PLAN>().Where(x => x.WMSPLANID == gid).First();
|
|
|
|
if (plan.IsNull())
|
|
{
|
|
return DataResult.Failed("预约信息不存在!");
|
|
}
|
|
if (plan.AuditStatus == AuditStatus.Approve.ToEnumInt())
|
|
{
|
|
return DataResult.Failed("已审批通过!");
|
|
}
|
|
if (plan.TRUCKNO.IsNullOrEmpty())
|
|
{
|
|
return DataResult.Failed("承运车辆不能为空!");
|
|
}
|
|
var goods = db.Queryable<OP_WMS_OUT_PLAN_DETAIL>().Where(x=>x.WMSPLANID == gid).ToList();
|
|
if (goods.Count() == 0)
|
|
{
|
|
return DataResult.Failed("出库计划明细为空,不能审批!");
|
|
}
|
|
|
|
var stockids = goods.Select(x => x.WMSPHYSICSID).ToList();
|
|
var stocklist = db.Queryable<OP_WMS_PHYSICS>().Where(x => stockids.Contains(x.WMSPHYSICSID)).ToList();
|
|
|
|
foreach (var item in goods)
|
|
{
|
|
var stockinfo = stocklist.Where(x => x.WMSPHYSICSID == item.WMSPHYSICSID).First();
|
|
if (item.PKGS > stockinfo.PKGS)
|
|
{
|
|
return DataResult.Failed("出库计划明细商品[" + item.GOODSNAME +"]库存数量:" + stockinfo.PKGS +" 不足,不能审批!");
|
|
}
|
|
if (item.STORAGEUNITCOUNT > stockinfo.STORAGEUNITCOUNT)
|
|
{
|
|
return DataResult.Failed("出库计划明细商品[" + item.GOODSNAME +"]计费数量:" + stockinfo.STORAGEUNITCOUNT +" 不足,不能审批!");
|
|
}
|
|
}
|
|
|
|
if (model.Status == 1)
|
|
{
|
|
try
|
|
{
|
|
//开启事务
|
|
db.Ado.BeginTran();
|
|
plan.AuditStatus = model.Status;
|
|
plan.AuditTime = DateTime.Now;
|
|
plan.AuditBy = userId;
|
|
plan.AuditNote = model.AuditNote;
|
|
db.Updateable(plan).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
|
|
#region 处理锁库数量
|
|
|
|
foreach (var item in stocklist)
|
|
{
|
|
var plangoods = goods.Where(x => x.WMSPHYSICSID == item.WMSPHYSICSID).First();
|
|
|
|
item.PKGS -= plangoods.PKGS;
|
|
item.STORAGEUNITCOUNT -= plangoods.STORAGEUNITCOUNT;
|
|
item.LOCKPKGS += plangoods.PKGS;
|
|
item.LOCKSTORAGEUNITCOUNT += plangoods.STORAGEUNITCOUNT;
|
|
db.Updateable(item).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("审批成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("审批失败!" + ",请联系管理员!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
plan.AuditStatus = model.Status;
|
|
plan.AuditTime = DateTime.Now;
|
|
plan.AuditBy = userId;
|
|
plan.AuditNote = model.AuditNote;
|
|
db.Updateable(plan).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
return DataResult.Successed("驳回成功!");
|
|
}
|
|
}
|
|
|
|
public DataResult GetWmsOutPlanGoodsList(string id)
|
|
{
|
|
var data = db.Queryable<OP_WMS_OUT_PLAN_DETAIL>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE_AREA>((a, b) => a.AREACODE == b.AREACODE)
|
|
.Select((a, b) => new WmsOutPlanGoodsListViewModel()
|
|
{
|
|
AREANAME = b.AREANAME //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.Where(a => a.WMSPLANID == Guid.Parse(id)).ToList();
|
|
return DataResult.Successed("查询成功!", data);
|
|
}
|
|
} |