using Admin.Core.IRepository; using Admin.Core.IService; using Admin.Core.Model; using System.Collections.Generic; using System.Linq.Expressions; using System; using log4net; using StackExchange.Profiling.Internal; using Admin.Core.Common; using System.Threading.Tasks; namespace Admin.Core.Service { public class BaseSpaceDetailServices : BaseServices, IBaseSpaceDetailServices { private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(BaseSpaceDetailServices)); private readonly IBaseRepository _dal; public BaseSpaceDetailServices(IBaseRepository dal) { this._dal = dal; base.BaseDal = dal; } /// /// 根据物料编号删除货道明细 /// /// /// public async Task DeleteSpaceDetailByMaterialCode(string materialCode) { bool result = false; try { BaseSpaceDetail spaceDetail =await this.GetSpaceDetailByMaterialCode(materialCode); result = _dal.Delete(spaceDetail); } catch (Exception ex) { logHelper.Error("根据物料编号删除货道明细异常", ex); } return result; } /// /// 通过物料编号获取货道明细 /// /// /// public async Task GetSpaceDetailByMaterialCode(string materialCode) { BaseSpaceDetail spaceDetail = null; try { Expression> exp = s1 => true; exp = exp.And(x => x.MaterialCode == materialCode); spaceDetail =await _dal.FirstAsync(exp); logHelper.Info($"根据物料编号{materialCode};获取到的货道明细信息:{spaceDetail.ToJson()}"); } catch (Exception ex) { logHelper.Error("通过物料编号获取货道明细", ex); } return spaceDetail; } /// /// 根据物料类型获取可用的货道明细 /// /// /// /// public async Task> GetSpaceDetailsByMaterialTypeAsync(string storeCode, string materialType) { List spaceDetails = null; try { Expression> exp = s1 => true; exp = exp.And(x => x.StoreCode == storeCode && x.MaterialType == materialType && x.IsFlag != 1); spaceDetails = await _dal.QueryAsync(exp); logHelper.Info($"根据仓库编号:{storeCode};物料类型:{materialType};获取到的货道明细:{spaceDetails}"); } catch (Exception ex) { logHelper.Error("通过物料类型获取货道明细异常", ex); } return spaceDetails; } /// /// 通过货道号获取货道明细 /// /// /// /// public async Task> GetSpaceDetailsBySpaceCode(string storeCode, string spaceCode) { List spaceDetails = null; try { Expression> exp = s1 => true; exp = exp.And(x => x.StoreCode == storeCode && x.SpaceCode == spaceCode); spaceDetails =await _dal.QueryAsync(exp); logHelper.Info($"根据仓库编号:{storeCode};货道编号:{spaceCode};获取到的执货道明细:{spaceDetails.ToJson()}"); } catch (Exception ex) { logHelper.Error("通过货道号获取货道明细异常", ex); } return spaceDetails; } /// /// 添加货道明细 /// /// /// public async Task InsertSpaceDetail(BaseSpaceDetail spaceDetail) { bool result = false; try { int r=await _dal.AddAsync(spaceDetail); if (r > 0) { result = true; } } catch (Exception ex) { logHelper.Error("添加货道明细异常", ex); } return result; } /// /// 更新货道明细 /// /// /// public async Task UpdateSpaceDetail(BaseSpaceDetail spaceDetail) { bool result = false; try { result =await _dal.UpdateAsync(spaceDetail); } catch (Exception ex) { logHelper.Error("更新货道明细异常", ex); } return result; } } }