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.
135 lines
4.7 KiB
C#
135 lines
4.7 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Core.BaseInfo.Dtos;
|
|
using DS.WMS.Core.BaseInfo.Entity;
|
|
using DS.WMS.Core.BaseInfo.Interface;
|
|
using Mapster;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.BaseInfo.Method;
|
|
|
|
public class WmsStoreAreaPositionService:IWmsStoreAreaPositionService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public WmsStoreAreaPositionService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
}
|
|
|
|
public DataResult<List<StoreAreaPositionViewModel>> GetListByPage(PageRequest request)
|
|
{
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = db.Queryable<WmsStoreAreaPosition>()
|
|
.LeftJoin<OP_WMS_STOREHOUSE_AREA>((a, b) => a.AreaCode == b.AREACODE)
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b,c) => b.Pid == c.Id)
|
|
.Select((a, b,c) => new StoreAreaPositionViewModel()
|
|
{
|
|
AreaCode = a.AreaCode,
|
|
AreaName = b.AREANAME,
|
|
StoreHouse = c.AREACODE,
|
|
StoreHouseName = c.AREANAME, //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.MergeTable()
|
|
// .Select<StoreAreaPositionViewModel>()
|
|
.Where(whereList).ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
|
|
public DataResult<StoreAreaPositionViewModel> GetStoreAreaPositionInfo(string id)
|
|
{
|
|
var data = db.Queryable<WmsStoreAreaPosition>().Where(a => a.Id == id)
|
|
.LeftJoin<OP_WMS_STOREHOUSE_AREA>((a, b) => a.AreaCode == b.AREACODE)
|
|
.LeftJoin<OP_WMS_STOREHOUSE>((a, b,c) => b.Pid == c.Id)
|
|
.Select((a, b,c) => new StoreAreaPositionViewModel()
|
|
{
|
|
AreaCode = a.AreaCode,
|
|
AreaName = b.AREANAME,
|
|
StoreHouse = c.AREACODE,
|
|
StoreHouseName = c.AREANAME, //手动指定一列在自动映射
|
|
},
|
|
true)
|
|
.MergeTable()
|
|
.First();
|
|
return DataResult<StoreAreaPositionViewModel>.Success(data);
|
|
}
|
|
|
|
public DataResult EditStoreAreaPositionInfo(StoreAreaPositionInput model)
|
|
{
|
|
if (model.Id.IsNullOrEmpty())
|
|
{
|
|
var isExist = db.Queryable<WmsStoreAreaPosition>().Where(x => x.AreaCode == model.AreaCode.Trim()).First();
|
|
if (isExist != null)
|
|
{
|
|
return DataResult.Failed("库位编码重复,请检查!");
|
|
}
|
|
try
|
|
{
|
|
//开启事务
|
|
db.Ado.BeginTran();
|
|
var data = model.Adapt<WmsStoreAreaPosition>();
|
|
var position = db.Insertable(data).ExecuteReturnEntity();
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("添加成功!",position.Id);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("添加失败!" + ex);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
//开启事务
|
|
db.Ado.BeginTran();
|
|
var info = db.Queryable<WmsStoreAreaPosition>().First(x => x.Id == model.Id);
|
|
var data = model.Adapt(info);
|
|
db.Updateable(data).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommand();
|
|
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("更新成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("更新失败!" + ex);
|
|
}
|
|
}
|
|
}
|
|
|
|
public DataResult DelStoreAreaPosition(string id)
|
|
{
|
|
var info = db.Queryable<WmsStoreAreaPosition>().First(x => x.Id == id);
|
|
if (info.IsNullOrEmpty())
|
|
{
|
|
return DataResult.Failed("信息不存在!");
|
|
}
|
|
try
|
|
{
|
|
//开启事务
|
|
db.Ado.BeginTran();
|
|
db.Deleteable(info).ExecuteCommand();
|
|
db.Ado.CommitTran();
|
|
return DataResult.Successed("删除成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Ado.RollbackTran();
|
|
return DataResult.Failed("删除失败!" + ex);
|
|
}
|
|
}
|
|
} |