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.
269 lines
10 KiB
C#
269 lines
10 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.User;
|
|
using DS.WMS.Common.Enum;
|
|
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<WmsInPlanListViewModel>> 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_YARD_COMPANY>((a, b) => a.ClientId == b.GID.ToString())
|
|
.Select((a, b) => new WmsInPlanListViewModel()
|
|
{
|
|
ClientName = b.DESCRIPTION //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
// .Select<WmsInPlanListViewModel>()
|
|
.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)
|
|
.Select<WmsInPlanInfoViewModel>()
|
|
.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 plan = model.MapTo<WmsInPlanInput, OP_WMS_IN_PLAN>();
|
|
var gid = plan.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();
|
|
|
|
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 SubmitWmsInPlan(string id)
|
|
{
|
|
var gid = Guid.Parse(id);
|
|
var inPlan = db.Queryable<OP_WMS_IN_PLAN>().First(x => x.WMSPLANID == gid);
|
|
|
|
if (inPlan.AuditStatus == AuditStatus.Approve.ToEnumInt() ||
|
|
inPlan.AuditStatus == AuditStatus.Auditing.ToEnumInt())
|
|
{
|
|
return DataResult.Failed("审核通过或待审批状态不能提交!");
|
|
}
|
|
|
|
if (inPlan.BILLTYPE == "1")
|
|
{
|
|
var files = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE == "预约入库").ToList();
|
|
if (files.Count() == 0)
|
|
{
|
|
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("入库计划明细为空,不能提交!");
|
|
}
|
|
|
|
//更新状态为待审批
|
|
inPlan.AuditStatus = AuditStatus.Auditing.ToEnumInt();
|
|
db.Updateable(inPlan).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);
|
|
}
|
|
} |