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; /// /// /// public class StoreAreaService:IStoreAreaService { private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; private readonly IUser user; /// /// /// /// public StoreAreaService(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() .Select() .Where(whereList).ToQueryPage(request.PageCondition); return data; } /// /// /// /// /// public DataResult GetStoreHouseInfo(int id) { var data = db.Queryable() .Where(a => a.Id == id) .Select() .First(); return DataResult.Success(data); } /// /// /// /// /// /// public DataResult EditStoreHouseInfo(StoreHouseInput model) { if (model.Id.ToString().IsNullOrEmpty()) { var isExist = db.Queryable().Where(x => x.AREACODE == model.AREACODE.Trim()).First(); if (isExist != null) { return DataResult.Failed("仓库编码重复,请检查!"); } var isNameExist = db.Queryable().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(); 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(); 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> GetStoreAreaList(PageRequest request) { //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = db.Queryable() .Select() .Where(whereList).ToQueryPage(request.PageCondition); return data; } /// /// /// /// /// public DataResult GetStoreAreaInfo(int id) { var data = db.Queryable() .Where(a => a.Id == id) .Select() .First(); return DataResult.Success(data); } /// /// /// /// /// public DataResult EditStoreAreaInfo(StoreAreaInput model) { if (model.Id.ToString().IsNullOrEmpty()) { var isExist = db.Queryable().Where(x => x.AREACODE == model.AREACODE.Trim()).First(); if (isExist != null) { return DataResult.Failed("库位编码重复,请检查!"); } var isNameExist = db.Queryable().Where(x => x.AREANAME == model.AREANAME.Trim()).First(); if (isNameExist != null) { return DataResult.Failed("库位名称重复,请检查!"); } try { //开启事务 db.Ado.BeginTran(); var data = model.MapTo(); 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(); 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 DelStoreAreaInfo(int id) { var info =db.Queryable() .Where(a => a.Id == id) .First(); if (info.IsNull()) { return DataResult.Failed("库位不存在!"); } db.Deleteable(info).ExecuteCommand(); return DataResult.Successed("删除成功!"); } }