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#

using DS.Module.Core;
using DS.Module.Core.Extensions;
2 years ago
using DS.Module.UserModule;
using DS.WMS.Common.Enum;
2 years ago
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;
2 years ago
using DS.WMS.Core.WmsModule.Interface;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
2 years ago
namespace DS.WMS.Core.WmsModule.Method;
/// <summary>
///
/// </summary>
public class WmsInPlanService : IWmsInPlanService
2 years ago
{
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>
2 years ago
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())
{
2 years ago
return DataResult.Failed("非法操作!");
}
else
{
try
{
2 years ago
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();
2 years ago
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);
}
}
}
2 years ago
public DataResult AuditWmsInPlan(CommonAuditInput model)
{
2 years ago
var userId = user.UserId;
2 years ago
var gid = Guid.Parse(model.Id);
var plan = db.Queryable<OP_WMS_IN_PLAN>().Where(x => x.WMSPLANID == gid).First();
if (plan.IsNull())
{
2 years ago
return DataResult.Failed("预约信息不存在!");
}
2 years ago
if (plan.AuditStatus == AuditStatus.Approve.ToEnumInt())
{
2 years ago
return DataResult.Failed("已审批通过!");
}
2 years ago
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)
{
2 years ago
return DataResult.Failed("入库计划明细为空,不能审批!");
}
var storehouse = db.Queryable<OP_WMS_STOREHOUSE>().First(x => x.AREACODE == plan.STOREHOUSE);
if (storehouse.IsNull())
{
return DataResult.Failed("未选择仓库!");
}
2 years ago
if (!(bool)storehouse.ISBONDED && plan.BILLTYPE =="1")
{
return DataResult.Failed("当前单据为保税单据,但仓库为非保税仓库!");
}
if ((bool)storehouse.ISBONDED && plan.BILLTYPE =="0")
{
return DataResult.Failed("当前单据为非保税单据,但仓库为保税仓库!");
}
2 years ago
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();
2 years ago
#region 生成进出记录许可
2 years ago
#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("驳回成功!");
}
}
2 years ago
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);
}
2 years ago
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);
}
2 years ago
}