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.
328 lines
12 KiB
C#
328 lines
12 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.System.Dtos;
|
|
using DS.WMS.Core.System.Entity;
|
|
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;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class WmsInPlanService : IWmsInPlanService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public WmsInPlanService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public DataResult<List<WmsInPlanListPageModel>> GetListByPage(PageRequest request)
|
|
{
|
|
var companyId = user.GetCompanyId();
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = db.Queryable<OP_WMS_IN_PLAN>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b) => a.STOREHOUSE == b.AREACODE)
|
|
.Select((a, b) => new WmsInPlanListPageModel()
|
|
{
|
|
STOREHOUSENAME = b.AREANAME //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
// .Select<WmsInPlanListPageModel>()
|
|
.Where(whereList).Where(a=>a.AuditStatus != AuditStatus.NoAudit.ToEnumInt()).ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
|
|
public DataResult<WmsInPlanInfoViewModel> GetWmsInPlanInfo(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
var planFiles = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE == "预约入库")
|
|
.Select(it => new fileinfo
|
|
{
|
|
FileName = it.FILENAME,
|
|
FilePath = it.IMGPATH
|
|
}).ToArray();
|
|
var data = db.Queryable<OP_WMS_IN_PLAN>().Where(a=>a.WMSPLANID == gid)
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b) => a.STOREHOUSE == b.AREACODE)
|
|
.Select((a, b) => new WmsInPlanInfoViewModel()
|
|
{
|
|
STOREHOUSENAME = b.AREANAME //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.Mapper(it =>
|
|
{
|
|
//只能写在Select后面
|
|
it.File = planFiles;
|
|
// it.List = db.Queryable<OP_WMS_IN_PLAN_GOODS>().Select<WmsInPlanGoodsListViewModel>()
|
|
// .Where(x => x.WMSPLANID == gid).ToList();
|
|
})
|
|
.First();
|
|
return DataResult<WmsInPlanInfoViewModel>.Success(data);
|
|
}
|
|
|
|
public DataResult EditWmsInPlanInfo(WmsInPlanInput model)
|
|
{
|
|
var companyId = user.GetCompanyId();
|
|
if (model.WMSPLANID.ToString().IsNullOrEmpty())
|
|
{
|
|
return DataResult.Failed("非法操作!");
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
|
|
var gid = (Guid)model.WMSPLANID;
|
|
var exitInfo = db.Queryable<OP_WMS_IN_PLAN>().First(x => x.WMSPLANID == gid);
|
|
if (exitInfo.AuditStatus == (short)AuditStatus.Auditing)
|
|
{
|
|
return DataResult.Failed("已提交审核,不能修改!");
|
|
}
|
|
|
|
if (exitInfo.AuditStatus == (short)AuditStatus.Approve)
|
|
{
|
|
return DataResult.Failed("已审核通过,不能修改!");
|
|
}
|
|
|
|
//开启事务
|
|
db.Ado.BeginTran();
|
|
var plan = model.Adapt(exitInfo);
|
|
if (model.List.Count() > 0)
|
|
{
|
|
var record = model.List.First();
|
|
plan.GOODSNAME = record.GOODSNAME;
|
|
plan.TRUCKNO = record.TRUCKNO;
|
|
plan.GOODSMODEL = record.GOODSMODEL;
|
|
}
|
|
|
|
db.Updateable(plan).IgnoreColumns(ignoreAllNullColumns: true)
|
|
.IgnoreColumns(x => new { x.AuditStatus, x.AuditNote }).ExecuteCommand();
|
|
|
|
#region 处理文件
|
|
|
|
var infoList = new List<INFO_FILES>();
|
|
if (model.File.IsNotNull())
|
|
{
|
|
#region
|
|
|
|
//先删除
|
|
var existFiles = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE == "预约入库")
|
|
.Select(n => n.IMGPATH).ToArray();
|
|
var planFiles = model.File.Select(x => x.FilePath).ToArray();
|
|
IEnumerable<string> delFiles = existFiles.AsQueryable().Except(planFiles);
|
|
if (delFiles.Count() > 0)
|
|
{
|
|
foreach (var item in delFiles)
|
|
{
|
|
var existInfo = db.Queryable<INFO_FILES>()
|
|
.Where(x => x.PID == gid && x.IMGPATH == item).First();
|
|
db.Deleteable(existInfo).ExecuteCommand();
|
|
}
|
|
}
|
|
|
|
//2.添加新的
|
|
IEnumerable<string> addFiles = planFiles.AsQueryable().Except(existFiles);
|
|
if (addFiles.Count() > 0)
|
|
{
|
|
foreach (var item in addFiles)
|
|
{
|
|
var infoFile = new INFO_FILES
|
|
{
|
|
GID = Guid.NewGuid(),
|
|
PID = gid,
|
|
FILENAME = model.File.Where(x => x.FilePath == item).Select(x => x.FileName).First(),
|
|
IMGPATH = item,
|
|
FILETYPE = "预约入库",
|
|
CORPID = user.CompanyId.ToString(),
|
|
CreateDate = DateTime.Now,
|
|
ModifyDate = DateTime.Now,
|
|
UPLOADEMPLY = ""
|
|
};
|
|
db.Insertable(infoFile).ExecuteCommand();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 处理计划明细
|
|
|
|
if (model.List.Count() > 0)
|
|
{
|
|
//先删除 计划明细
|
|
var existGoods = db.Queryable<OP_WMS_IN_PLAN_GOODS>().Where(x => x.WMSPLANID == gid)
|
|
.Select(n => n.GID.ToString()).ToArray();
|
|
var inGoods = model.List.Select(x => x.GID.ToString().ToUpper()).ToArray();
|
|
IEnumerable<string> delGoods = existGoods.AsQueryable().Except(inGoods);
|
|
if (delGoods.Count() > 0)
|
|
{
|
|
foreach (var item in delGoods)
|
|
{
|
|
var existInfo = db.Queryable<OP_WMS_IN_PLAN_GOODS>()
|
|
.Where(x => x.WMSPLANID == gid && x.GID == Guid.Parse(item)).First();
|
|
db.Deleteable(existInfo).ExecuteCommand();
|
|
}
|
|
}
|
|
|
|
//更新 计划明细
|
|
var updateList = model.List.Where(x => x.GID != null && !delGoods.Contains(x.GID.ToString()))
|
|
.ToList();
|
|
|
|
foreach (var item in updateList)
|
|
{
|
|
var detail = item.Adapt<OP_WMS_IN_PLAN_GOODS>();
|
|
|
|
db.Updateable(detail).ExecuteCommand();
|
|
}
|
|
|
|
//追加 计划明细
|
|
var addList = model.List.Where(x => x.GID == null).ToList();
|
|
|
|
foreach (var item in addList)
|
|
{
|
|
item.GID = Guid.NewGuid();
|
|
item.WMSPLANID = gid;
|
|
var detail = item.Adapt<OP_WMS_IN_PLAN_GOODS>();
|
|
|
|
db.Insertable(detail).ExecuteCommand();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("更新成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("更新失败!" + ex);
|
|
}
|
|
}
|
|
}
|
|
|
|
public DataResult AuditWmsInPlan(CommonAuditInput model)
|
|
{
|
|
var userId = user.UserId;
|
|
|
|
var gid = Guid.Parse(model.Id);
|
|
var plan = db.Queryable<OP_WMS_IN_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_IN_PLAN_GOODS>().Where(x=>x.WMSPLANID == gid).ToList();
|
|
if (goods.Count() == 0)
|
|
{
|
|
return DataResult.Failed("入库计划明细为空,不能审批!");
|
|
}
|
|
var storehouse = db.Queryable<OP_WMS_STOREHOUSE>().First(x => x.AREACODE == plan.STOREHOUSE);
|
|
if (storehouse.IsNull())
|
|
{
|
|
return DataResult.Failed("未选择仓库!");
|
|
}
|
|
|
|
if (!(bool)storehouse.ISBONDED && plan.BILLTYPE =="1")
|
|
{
|
|
return DataResult.Failed("当前单据为保税单据,但仓库为非保税仓库!");
|
|
}
|
|
if ((bool)storehouse.ISBONDED && plan.BILLTYPE =="0")
|
|
{
|
|
return DataResult.Failed("当前单据为非保税单据,但仓库为保税仓库!");
|
|
}
|
|
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 生成进出记录许可
|
|
|
|
|
|
|
|
#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 GetWmsInPlanGoodsList(string id)
|
|
{
|
|
var data = db.Queryable<OP_WMS_IN_PLAN_GOODS>()
|
|
.Select<WmsInPlanGoodsListViewModel>()
|
|
.Mapper(it =>
|
|
{
|
|
//只能写在Select后面
|
|
it.EDITABLE = true;
|
|
})
|
|
.Where(a => a.WMSPLANID == Guid.Parse(id)).ToList();
|
|
return DataResult.Successed("查询成功!", data);
|
|
}
|
|
|
|
|
|
public DataResult GetWmsInPlanFeeRateList(string id)
|
|
{
|
|
var data = db.Queryable<OP_WMS_FEERATE_IN_DETAIL>()
|
|
.Where(a => a.FEERATEID == Guid.Parse(id)).ToList();
|
|
return DataResult.Successed("查询成功!", data);
|
|
}
|
|
} |