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.
196 lines
7.7 KiB
C#
196 lines
7.7 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 AppStockOutService:IAppStockOutService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public AppStockOutService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
}
|
|
|
|
public DataResult GetStockOutPlanList(StockOutPlanQueryModel model)
|
|
{
|
|
var data = db.Queryable<OP_WMS_OUT_PLAN>()
|
|
.Where(a => a.AuditStatus == AuditStatus.Approve.ToEnumInt() && a.ISEND == false)
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b) => a.STOREHOUSE == b.AREACODE)
|
|
.LeftJoin(
|
|
db.SqlQueryable<StockTruckListViewModel>(
|
|
"select DISTINCT TRUCKNO, WMSPLANID from OP_WMS_OUT_PLAN_DETAIL WHERE TRUCKNO is not null"),
|
|
(a, b, c) => a.WMSPLANID == c.WMSPLANID)
|
|
.Select((a, b, c) => new StockOutPlanListViewModel()
|
|
{
|
|
MBLNO = a.MBLNO,
|
|
STOREHOUSENAME = b.AREANAME, //手动指定一列在自动映射
|
|
TRUCKNO = c.TRUCKNO
|
|
},
|
|
true)
|
|
.WhereIF(!model.MBLNO.IsNullOrEmpty(), a => a.MBLNO.Contains(model.MBLNO))
|
|
.WhereIF(!model.TRUCKNO.IsNullOrEmpty(), a => a.TRUCKNO.Contains(model.TRUCKNO))
|
|
.ToList();
|
|
if (data.Count() == 0)
|
|
{
|
|
return DataResult.Failed("未检索到数据!");
|
|
}
|
|
|
|
return DataResult.Successed("获取数据成功", data);
|
|
}
|
|
|
|
|
|
public DataResult GetStockOutSummaryInfo(StockOutPlanQueryModel model)
|
|
{
|
|
var data = new StockOutPlanViewModel();
|
|
|
|
var info = db.Queryable<OP_WMS_OUT_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;
|
|
|
|
// 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 GetStockOutGoodsInfo(StockGoodsQueryModel model)
|
|
{
|
|
var goods = db.Queryable<OP_WMS_OUT_PLAN_DETAIL>().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(
|
|
db.SqlQueryable<StockDoGoods>(
|
|
"select WMSPLANDETAILID, sum(PKGS) AS PKGS,SUM(STORAGEUNITCOUNT) AS STORAGEUNITCOUNT from OP_WMS_OUT_DO_GOODS WHERE WMSPLANDETAILID is not null GROUP BY WMSPLANDETAILID"),
|
|
(a, b, StockDoGoods) => a.WMSOUTDETAILID == StockDoGoods.WMSPLANDETAILID)
|
|
.LeftJoin<OP_WMS_STOREHOUSE_AREA>((a, b, StockDoGoods, d) => a.AREACODE == d.AREACODE)
|
|
.LeftJoin<OP_WMS_GOODSFEETYPE>((a, b, StockDoGoods, d,f) => b.GoodsFeeTypeGID == f.GID)
|
|
.Select((a, b, StockDoGoods, d,f) => new StockOutPlanGoodsViewModel()
|
|
{
|
|
PKGS = a.PKGS,
|
|
STORAGEUNITCOUNT = a.STORAGEUNITCOUNT,
|
|
DOSTORAGEUNITCOUNT = StockDoGoods.STORAGEUNITCOUNT,
|
|
DOPKGS = StockDoGoods.PKGS, //手动指定一列在自动映射
|
|
AREANAME = d.AREANAME,
|
|
StorageUnitType = f.STORAGEUNIT_TYPE,
|
|
},
|
|
true)
|
|
.Take(5).ToList();
|
|
if (goods.Count == 0)
|
|
{
|
|
return DataResult.Failed("未检索到数据!");
|
|
}
|
|
|
|
return DataResult.Successed("获取数据成功", goods);
|
|
}
|
|
|
|
|
|
public DataResult StockOutBatch(StockOutPlanGoodsBatchInput model)
|
|
{
|
|
var userId = user.UserId;
|
|
if (model.Goods.Count == 0)
|
|
{
|
|
return DataResult.Failed("执行明细不能为空!");
|
|
}
|
|
|
|
var WMSPLANID = model.WMSPLANID;
|
|
//检测出库计划状态
|
|
var plan = db.Queryable<OP_WMS_OUT_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_OUT_DO>();
|
|
stockDo.WMSNO = NumUtil.GetBillNo(db, "WM04");
|
|
stockDo.BILLSTATUS = "1010";
|
|
stockDo.StockOutType = 0;//正常出库
|
|
stockDo.BSSTATUS = false;
|
|
stockDo.TRUCKNO = model.TRUCKNO;
|
|
stockDo.MBLNO = model.MBLNO;
|
|
stockDo.ISEND = false;
|
|
stockDo.FEESTATUS = false;
|
|
stockDo.BSSTATUS = false;
|
|
stockDo.WMSDOID = doId;
|
|
var now = DateTime.Now;
|
|
stockDo.DODATE = new DateTime(now.Year, now.Month, now.Day);
|
|
|
|
stockDo.CORPID = user.GetCompanyId();
|
|
stockDo.CUSTOMNO_IMPORT = plan.CUSTOMNO;
|
|
//写入OP_WMS_OUT_DO
|
|
db.Insertable(stockDo).ExecuteCommand();
|
|
// TODO 出库执行费率
|
|
var doGoodsList = new List<OP_WMS_OUT_DO_GOODS>();
|
|
foreach (var item in model.Goods)
|
|
{
|
|
var planGood = db.Queryable<OP_WMS_OUT_PLAN_DETAIL>()
|
|
.Where(s => s.WMSOUTDETAILID == item.WMSOUTDETAILID).First();
|
|
|
|
var doGoods = planGood.Adapt<OP_WMS_OUT_DO_GOODS>();
|
|
doGoods.WMSDODETAILID = Guid.NewGuid();
|
|
doGoods.WMSDOID = doId;
|
|
doGoods.WMSPLANDETAILID = item.WMSOUTDETAILID;
|
|
doGoods.PKGS = item.PKGS;
|
|
doGoods.MINPKGS = item.MINPKGS;
|
|
doGoods.KGS = item.KGS;
|
|
doGoods.NETWEIGHT = item.NETWEIGHT;
|
|
doGoods.KINDPKGS = item.KINDPKGS;
|
|
doGoods.STORAGEUNITCOUNT = item.STORAGEUNITCOUNT;
|
|
doGoods.STOREHOUSE = stockDo.STOREHOUSE;
|
|
doGoods.GOODSMODEL2 = item.GOODSMODEL2;
|
|
doGoodsList.Add(doGoods);
|
|
}
|
|
|
|
//写入 OP_WMS_OUT_DO_GOODS
|
|
db.Insertable(doGoodsList).ExecuteCommand();
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("出库确认成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("出库确认失败!" + ",请联系管理员!");
|
|
}
|
|
}
|
|
|
|
} |