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.
253 lines
11 KiB
C#
253 lines
11 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Common.Enum;
|
|
using DS.WMS.Core.App.Dtos;
|
|
using DS.WMS.Core.App.Interface;
|
|
using DS.WMS.Core.BaseInfo.Entity;
|
|
using DS.WMS.Core.System.Entity;
|
|
using DS.WMS.Core.WmsModule.Entity;
|
|
using Mapster;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
using OP_WMS_STOREHOUSE = DS.WMS.Core.App.Entity.OP_WMS_STOREHOUSE;
|
|
using OP_WMS_STOREHOUSE_AREA = DS.WMS.Core.App.Entity.OP_WMS_STOREHOUSE_AREA;
|
|
|
|
namespace DS.WMS.Core.App.Method;
|
|
|
|
public class AppStockInService : IAppStockInService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public AppStockInService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
}
|
|
|
|
public DataResult<List<StockInPlanListViewModel>> GetStockInPlanList(StockInPlanQueryModel model)
|
|
{
|
|
var trucklist = db.Queryable<OP_WMS_IN_PLAN_GOODS>().Select(a => new { a.WMSPLANID, a.TRUCKNO })
|
|
.Where(a => a.TRUCKNO != "" && a.TRUCKNO != null).Distinct();
|
|
var data = db.Queryable<OP_WMS_IN_PLAN>()
|
|
.LeftJoin(trucklist, (a, b) => a.WMSPLANID == b.WMSPLANID)
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b, c) => a.STOREHOUSE == c.AREACODE)
|
|
.Where((a, b, c) => a.AuditStatus == AuditStatus.Approve.ToEnumInt() && a.ISEND == false)
|
|
.Select((a, b, c) => new StockInPlanListViewModel()
|
|
{
|
|
STOREHOUSENAME = c.AREANAME //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.WhereIF(!model.MBLNO.IsNullOrEmpty(), a => a.MBLNO.Contains(model.MBLNO))
|
|
.WhereIF(!model.TRUCKNO.IsNullOrEmpty(), a => a.TRUCKNO.Contains(model.TRUCKNO))
|
|
.ToList();
|
|
// .Select<StockInPlanListViewModel>()
|
|
if (data.Count() == 0)
|
|
{
|
|
return DataResult<List<StockInPlanListViewModel>>.Failed("未检索到数据!");
|
|
}
|
|
|
|
return DataResult<List<StockInPlanListViewModel>>.Success("获取数据成功", data);
|
|
}
|
|
|
|
public DataResult GetStockInSummaryInfo(StockInPlanQueryModel model)
|
|
{
|
|
var data = new StockInPlanViewModel();
|
|
|
|
var info = db.Queryable<OP_WMS_IN_PLAN>().First(x => x.WMSPLANID == model.WMSPLANID);
|
|
var store = db.Queryable<OP_WMS_STOREHOUSE>().First(x => x.AREACODE == info.STOREHOUSE);
|
|
data.WMSPLANID = model.WMSPLANID;
|
|
data.TRUCKNO = model.TRUCKNO;
|
|
data.MBLNO = info.MBLNO;
|
|
data.STOREHOUSENAME = store.AREANAME;
|
|
|
|
// var goods = db.Queryable<OP_WMS_IN_PLAN_GOODS>().Where(a=>a.WMSPLANID == model.WMSPLANID)
|
|
// .LeftJoin(
|
|
// db.SqlQueryable<StockDoGoods>(
|
|
// "select WMSPLANDETAILID, sum(PKGS) AS PKGS,SUM(STORAGEUNITCOUNT) AS STORAGEUNITCOUNT from OP_WMS_IN_DO_GOODS WHERE WMSPLANDETAILID is not null GROUP BY WMSPLANDETAILID"),
|
|
// (a, b) => a.GID == b.WMSPLANDETAILID)
|
|
// .Select((a, b) => new StockInPlanGoodsViewModel()
|
|
// {
|
|
// PKGS = a.PKGS,
|
|
// STORAGEUNITCOUNT = a.STORAGEUNITCOUNT,
|
|
// DOSTORAGEUNITCOUNT = b.STORAGEUNITCOUNT,
|
|
// DOPKGS = b.PKGS //手动指定一列在自动映射
|
|
// },
|
|
// true)
|
|
// // .Select<StockInPlanGoodsViewModel>()
|
|
// // .Where(a => a.STORAGEUNITCOUNT > b.DOSTORAGEUNITCOUNT)
|
|
// .ToList();
|
|
// // data.GoodsList = goods.Where(x => x.STORAGEUNITCOUNT > x.DOSTORAGEUNITCOUNT).ToList();
|
|
// data.GoodsList = goods.ToList();
|
|
data.AreaList = db.Queryable<OP_WMS_STOREHOUSE_AREA>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b) => a.Pid == b.Id)
|
|
.Where((a, b) => b.AREACODE == info.STOREHOUSE)
|
|
.Select(a => new AreaListViewModel
|
|
{
|
|
text = a.AREANAME,
|
|
value = a.AREACODE
|
|
})
|
|
.ToList();
|
|
return DataResult.Successed("获取数据成功", data);
|
|
}
|
|
|
|
public DataResult GetStockInGoodsInfo(StockGoodsQueryModel model)
|
|
{
|
|
var goods = db.Queryable<OP_WMS_IN_PLAN_GOODS>()
|
|
.Where(a => a.WMSPLANID == model.WMSPLANID && a.ISEXECUTE == false)
|
|
.LeftJoin<code_goods>((a, b) => a.GoodsId == b.GID && b.ISSTOP == false)
|
|
.Where((a, b) => b.PinYinCode.Contains(model.Code))
|
|
.LeftJoin<OP_WMS_GOODSFEETYPE>((a, b, c) => b.GoodsFeeTypeGID == c.GID)
|
|
.LeftJoin(
|
|
db.SqlQueryable<StockDoGoods>(
|
|
"select WMSPLANDETAILID,isnull(sum(PKGS),0) AS PKGS,isnull(SUM(STORAGEUNITCOUNT),0) AS STORAGEUNITCOUNT, isnull(sum(KGS),0) AS KGS,isnull(SUM(NETWEIGHT),0) AS NETWEIGHT,isnull(SUM(MINPKGS),0) AS MINPKGS from OP_WMS_IN_DO_GOODS WHERE WMSPLANDETAILID is not null GROUP BY WMSPLANDETAILID"),
|
|
(a, b, c, StockInDoGoods) => a.GID == StockInDoGoods.WMSPLANDETAILID)
|
|
.Select((a, b, c, StockInDoGoods) => new StockInPlanGoodsViewModel()
|
|
{
|
|
SUMPKGS = a.PKGS,
|
|
PKGS = a.PKGS -(StockInDoGoods.PKGS == null ?0 :StockInDoGoods.PKGS) ,
|
|
KGS = a.KGS - (StockInDoGoods.KGS == null ?0 :StockInDoGoods.KGS),
|
|
NETWEIGHT = a.NETWEIGHT - (StockInDoGoods.NETWEIGHT == null ?0 :StockInDoGoods.NETWEIGHT),
|
|
MINPKGS = a.MINPKGS - (StockInDoGoods.MINPKGS == null ?0 :StockInDoGoods.MINPKGS),
|
|
STORAGEUNITCOUNT = a.STORAGEUNITCOUNT - (StockInDoGoods.STORAGEUNITCOUNT == null ?0 :StockInDoGoods.STORAGEUNITCOUNT),
|
|
DOSTORAGEUNITCOUNT = StockInDoGoods.STORAGEUNITCOUNT== null ?0 :StockInDoGoods.STORAGEUNITCOUNT,
|
|
StorageUnitType = c.STORAGEUNIT_TYPE,
|
|
DOPKGS = StockInDoGoods.PKGS== null ?0 :StockInDoGoods.PKGS //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
// .Select<StockInPlanGoodsViewModel>()
|
|
// .Where(a => a.STORAGEUNITCOUNT > b.DOSTORAGEUNITCOUNT)
|
|
.Take(5).ToList();
|
|
if (goods.Count == 0)
|
|
{
|
|
return DataResult.Failed("未检索到数据!");
|
|
}
|
|
|
|
return DataResult.Successed("获取数据成功", goods);
|
|
}
|
|
|
|
|
|
public DataResult StockInBatch(StockInPlanGoodsBatchInput model)
|
|
{
|
|
var userId = user.UserId;
|
|
if (model.Goods.Count == 0)
|
|
{
|
|
return DataResult.Failed("执行明细不能为空!");
|
|
}
|
|
|
|
var WMSPLANID = model.WMSPLANID;
|
|
//检测入库计划状态
|
|
var plan = db.Queryable<OP_WMS_IN_PLAN>().Where(s => s.WMSPLANID == WMSPLANID).First();
|
|
if (plan == null)
|
|
{
|
|
return DataResult.Failed("入库计划不存在!");
|
|
}
|
|
|
|
if (plan.ISEND == true)
|
|
{
|
|
return DataResult.Failed("入库计划已完成!");
|
|
}
|
|
|
|
try
|
|
{
|
|
//开启事务
|
|
db.Ado.BeginTran();
|
|
var doId = Guid.NewGuid();
|
|
//var stockDo = plan.MapTo<OP_WMS_IN_PLAN,OP_WMS_IN_DO>();
|
|
var stockDo = plan.Adapt<OP_WMS_IN_DO>();
|
|
stockDo.BSNO = NumUtil.GetBillNo(db, "WM02");
|
|
stockDo.BILLSTATUS = "1000";
|
|
stockDo.BSSTATUS = false;
|
|
stockDo.TRUCKNO = model.TRUCKNO;
|
|
stockDo.MBLNO = model.MBLNO;
|
|
stockDo.WMSDOID = doId;
|
|
stockDo.GOODSOWNER = stockDo.CUSTOMERNAME;
|
|
stockDo.APCLIENTWMSOUT = stockDo.CUSTOMERNAME;
|
|
stockDo.ARCLIENTWMSOUT = stockDo.CUSTOMERNAME;
|
|
var now = DateTime.Now;
|
|
stockDo.DODATE = new DateTime(now.Year, now.Month, now.Day);
|
|
stockDo.FEESTARTDATE = DateTime.Now;
|
|
|
|
stockDo.CORPID = user.GetCompanyId();
|
|
// stockDo.CreateID = Guid.Parse(userId);
|
|
// stockDo.Creator = userinfo.UserTrueName;
|
|
// stockDo.CreateDate = DateTime.Now;
|
|
|
|
//写入OP_WMS_IN_DO
|
|
db.Insertable(stockDo).ExecuteCommand();
|
|
|
|
var doGoodsList = new List<OP_WMS_IN_DO_GOODS>();
|
|
foreach (var item in model.Goods)
|
|
{
|
|
var planGood = db.Queryable<OP_WMS_IN_PLAN_GOODS>().Where(s => s.GID == item.GID).First();
|
|
|
|
var doGoods = planGood.Adapt<OP_WMS_IN_DO_GOODS>();
|
|
doGoods.WMSDODETAILID = Guid.NewGuid();
|
|
doGoods.WMSDOID = doId;
|
|
doGoods.WMSPLANID = WMSPLANID;
|
|
doGoods.WMSPLANDETAILID = item.GID;
|
|
doGoods.MBLNO = plan.MBLNO;
|
|
doGoods.GOODSMODEL2 = item.GOODSMODEL2;
|
|
doGoods.PKGS = item.PKGS;
|
|
doGoods.MINPKGS = item.MINPKGS;
|
|
doGoods.KGS = item.KGS;
|
|
doGoods.CBM = item.CBM;
|
|
doGoods.NETWEIGHT = item.NETWEIGHT;
|
|
doGoods.STORAGEUNITCOUNT = item.STORAGEUNITCOUNT;
|
|
doGoods.ACCEPT_PKGS = item.PKGS;
|
|
doGoods.ACCEPT_MINPKGS = item.MINPKGS;
|
|
doGoods.ACCEPT_KGS = item.KGS;
|
|
doGoods.ACCEPT_CBM = item.CBM;
|
|
doGoods.ACCEPT_NETWEIGHT = item.NETWEIGHT;
|
|
doGoods.ACCEPT_STORAGEUNITCOUNT = item.STORAGEUNITCOUNT;
|
|
// doGoods.ACCEPT_RULEUNITCOUNT = item.RULEUNITCOUNT;
|
|
|
|
doGoods.STOREHOUSE = stockDo.STOREHOUSE;
|
|
doGoods.ACCEPT_STOREHOUSE = stockDo.STOREHOUSE;
|
|
//更新库位信息
|
|
doGoods.AREACODE = item.AREACODE;
|
|
//更新原箱号
|
|
doGoods.OLD_CNTRNO = item.OLD_CNTRNO;
|
|
// doGoods.CNTRNO = item.CNTRNO;
|
|
//添加到List
|
|
doGoodsList.Add(doGoods);
|
|
|
|
//最后处理 计划明细 ISEXECUTE 是否执行入库执行标识
|
|
// planGood.ISEXECUTE = true;
|
|
// db.Updateable(planGood).ExecuteCommand();
|
|
}
|
|
|
|
//写入 OP_WMS_IN_DO_GOODS
|
|
db.Insertable(doGoodsList).ExecuteCommand();
|
|
|
|
#region 处理费率 // TODO 入库执行费率
|
|
|
|
var infee = db.Queryable<OP_WMS_FEERATE_IN_DETAIL>().Where(x => x.PID == WMSPLANID).ToList();
|
|
|
|
|
|
foreach (var item in infee)
|
|
{
|
|
var dofee = item.Adapt<OP_WMS_FEERATE_DO_DETAIL>();
|
|
dofee.PID = doId;
|
|
db.Insertable(dofee).ExecuteCommand();
|
|
}
|
|
|
|
#endregion
|
|
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("入库确认成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("入库确认失败!" + ",请联系管理员!");
|
|
}
|
|
}
|
|
} |