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.

222 lines
7.0 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.User;
using DS.WMS.Core.BaseInfo.Dtos;
using DS.WMS.Core.BaseInfo.Entity;
using DS.WMS.Core.BaseInfo.Interface;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.BaseInfo.Method;
/// <summary>
///
/// </summary>
public class StoreAreaService:IStoreAreaService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public StoreAreaService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
}
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<StoreHouseViewModel>> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<OP_WMS_STOREHOUSE>()
.Select<StoreHouseViewModel>()
.Where(whereList).ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<StoreHouseViewModel> GetStoreHouseInfo(int id)
{
var data = db.Queryable<OP_WMS_STOREHOUSE>()
.Where(a => a.Id == id)
.Select<StoreHouseViewModel>()
.First();
return DataResult<StoreHouseViewModel>.Success(data);
}
/// <summary>
///
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public DataResult EditStoreHouseInfo(StoreHouseInput model)
{
if (model.Id.ToString().IsNullOrEmpty())
{
var isExist = db.Queryable<OP_WMS_STOREHOUSE>().Where(x => x.AREACODE == model.AREACODE.Trim()).First();
if (isExist != null)
{
return DataResult.Failed("仓库编码重复,请检查!");
}
var isNameExist = db.Queryable<OP_WMS_STOREHOUSE>().Where(x => x.AREANAME == model.AREANAME.Trim()).First();
if (isNameExist != null)
{
return DataResult.Failed("仓库名称重复,请检查!");
}
try
{
//开启事务
db.Ado.BeginTran();
var gid = Guid.NewGuid();
var data = model.MapTo<StoreHouseInput, OP_WMS_STOREHOUSE>();
data.CORPNAME = user.GetCompanyId();
db.Insertable(data).ExecuteCommand();
db.Ado.CommitTran();
return DataResult.Successed("添加成功!");
}
catch (Exception ex)
{
db.Ado.RollbackTran();
return DataResult.Failed("添加失败!" + ex);
}
}
else
{
try
{
//开启事务
db.Ado.BeginTran();
var data = model.MapTo<StoreHouseInput, OP_WMS_STOREHOUSE>();
db.Updateable(data).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommand();
db.Ado.CommitTran();
return DataResult.Successed("更新成功!");
}
catch (Exception ex)
{
db.Ado.RollbackTran();
return DataResult.Failed("更新失败!" + ex);
}
}
}
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<StoreAreaViewModel>> GetStoreAreaList(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<OP_WMS_STOREHOUSE_AREA>()
.Select<StoreAreaViewModel>()
.Where(whereList).ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<StoreAreaViewModel> GetStoreAreaInfo(int id)
{
var data = db.Queryable<OP_WMS_STOREHOUSE_AREA>()
.Where(a => a.Id == id)
.Select<StoreAreaViewModel>()
.First();
return DataResult<StoreAreaViewModel>.Success(data);
}
/// <summary>
///
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public DataResult EditStoreAreaInfo(StoreAreaInput model)
{
if (model.Id.ToString().IsNullOrEmpty())
{
var isExist = db.Queryable<OP_WMS_STOREHOUSE_AREA>().Where(x => x.AREACODE == model.AREACODE.Trim()).First();
if (isExist != null)
{
return DataResult.Failed("库位编码重复,请检查!");
}
var isNameExist = db.Queryable<OP_WMS_STOREHOUSE_AREA>().Where(x => x.AREANAME == model.AREANAME.Trim()).First();
if (isNameExist != null)
{
return DataResult.Failed("库位名称重复,请检查!");
}
try
{
//开启事务
db.Ado.BeginTran();
var data = model.MapTo<StoreAreaInput, OP_WMS_STOREHOUSE_AREA>();
db.Insertable(data).ExecuteCommand();
db.Ado.CommitTran();
return DataResult.Successed("添加成功!");
}
catch (Exception ex)
{
db.Ado.RollbackTran();
return DataResult.Failed("添加失败!" + ex);
}
}
else
{
try
{
//开启事务
db.Ado.BeginTran();
var data = model.MapTo<StoreAreaInput, OP_WMS_STOREHOUSE_AREA>();
db.Updateable(data).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommand();
db.Ado.CommitTran();
return DataResult.Successed("更新成功!");
}
catch (Exception ex)
{
db.Ado.RollbackTran();
return DataResult.Failed("更新失败!" + ex);
}
}
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult DelStoreAreaInfo(int id)
{
var info =db.Queryable<OP_WMS_STOREHOUSE_AREA>()
.Where(a => a.Id == id)
.First();
if (info.IsNull())
{
return DataResult.Failed("库位不存在!");
}
db.Deleteable(info).ExecuteCommand();
return DataResult.Successed("删除成功!");
}
}