using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.UserModule; using DS.WMS.Common.Enum; using DS.WMS.Core.App.Entity; using DS.WMS.Core.BaseInfo.Dtos; 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 WmsClearanceService:IWmsClearanceService { private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; private readonly IUser user; /// /// /// /// public WmsClearanceService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); } public DataResult> GetListByPage(PageRequest request) { //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = db.Queryable() .LeftJoin((a, b) => a.STOREHOUSE == b.AREACODE) .Select((a, b) => new WmsClearanceListPageModel() { STOREHOUSENAME = b.AREANAME //手动指定一列在自动映射 }, true) .Where(whereList).Where(a=>a.AuditStatus != AuditStatus.NoAudit.ToEnumInt()).ToQueryPage(request.PageCondition); return data; } public DataResult GetWmsClearanceInfo(string id) { var gid = Guid.Parse(id); var data = db.Queryable() .LeftJoin((a, b) => a.STOREHOUSE == b.AREACODE) .LeftJoin((a, b,c) => a.MoveStoreHouse == c.AREACODE) .Select((a, b,c) => new WmsClearanceInfoViewModel() { STOREHOUSENAME = b.AREANAME, //手动指定一列在自动映射 MoveStoreHouseName = c.AREANAME }, true) .Where((a) => a.WMSPLANID == gid) .First(); return DataResult.Success(data); } public DataResult AuditWmsClearance(CommonAuditInput model) { var userId = user.UserId; var gid = Guid.Parse(model.Id); var plan = db.Queryable().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().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().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 goods) { var stockinfo = stocklist.Where(x => x.WMSPHYSICSID == item.WMSPHYSICSID).First(); stockinfo.PKGS -= item.PKGS; stockinfo.STORAGEUNITCOUNT -= item.STORAGEUNITCOUNT; stockinfo.LOCKPKGS += item.PKGS; stockinfo.LOCKSTORAGEUNITCOUNT += item.STORAGEUNITCOUNT; db.Updateable(stockinfo).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 GetWmsClearanceGoodsList(string id) { var data = db.Queryable() .LeftJoin((a, b) => a.AREACODE == b.AREACODE) .Select((a, b) => new WmsClearanceGoodsListViewModel() { AREANAME = b.AREANAME //手动指定一列在自动映射 }, true) .Where(a => a.WMSPLANID == Guid.Parse(id)).ToList(); return DataResult.Successed("查询成功!", data); } }