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;
///
///
///
///
public WmsStoreAreaPositionService(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.AreaCode == b.AREACODE)
.LeftJoin((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()
.Where(whereList).ToQueryPage(request.PageCondition);
return data;
}
public DataResult GetStoreAreaPositionInfo(string id)
{
var data = db.Queryable().Where(a => a.Id == id)
.LeftJoin((a, b) => a.AreaCode == b.AREACODE)
.LeftJoin((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.Success(data);
}
public DataResult EditStoreAreaPositionInfo(StoreAreaPositionInput model)
{
if (model.Id.IsNullOrEmpty())
{
var isExist = db.Queryable().Where(x => x.AreaCode == model.AreaCode.Trim()).First();
if (isExist != null)
{
return DataResult.Failed("库位编码重复,请检查!");
}
try
{
//开启事务
db.Ado.BeginTran();
var data = model.Adapt();
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().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().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);
}
}
}