/* *所有关于Dt_locationinfo类的业务代码应在此处编写 *可使用repository.调用常用方法,获取EF/Dapper等信息 *如果需要事务请使用repository.DbContextBeginTransaction *也可使用DBServerProvider.手动获取数据库相关信息 *用户信息、权限、角色等使用UserContext.Current操作 *Dt_locationinfoService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter */ using WIDESEA.Core.BaseProvider; using WIDESEA.Core.Extensions.AutofacManager; using WIDESEA.Entity.DomainModels; using System.Linq; using WIDESEA.Core.Utilities; using System.Linq.Expressions; using WIDESEA.Core.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Http; using WIDESEA.Services.IRepositories; using System.Threading.Tasks; using System.Collections.Generic; using Newtonsoft.Json; using System; using WIDESEA.Common.CustomModels; using WIDESEA.Core.Enums; using WIDESEA.Core.Services; using WIDESEA.Common; using WIDESEA.Services.Repositories; using WIDESEA.Core.EFDbContext; namespace WIDESEA.Services.Services { public partial class Dt_locationinfoService { private readonly IHttpContextAccessor _httpContextAccessor; private readonly IDt_locationinfoRepository _repository;//访问数据库 [ActivatorUtilitiesConstructor] public Dt_locationinfoService( IDt_locationinfoRepository dbRepository, IHttpContextAccessor httpContextAccessor ) : base(dbRepository) { _httpContextAccessor = httpContextAccessor; _repository = dbRepository; //多租户会用到这init代码,其他情况可以不用 //base.Init(dbRepository); } /// /// 给入库请求分配货位(获取指定的层) /// /// public WebResponseContent GetEmptyLocation(WIDESEAContext dbcontext, string desLayer) { WebResponseContent content = new WebResponseContent(); try { Dt_locationinfoRepository locationinfoRepository = new Dt_locationinfoRepository(dbcontext); List locationinfos = locationinfoRepository.Find( x => x.location_state == LocationState.LocationState_Empty.ToString() && x.location_islocked == false && x.location_layer == int.Parse(desLayer)) .OrderBy(x => x.location_column) .ToList(); if (locationinfos.Count() > 0) { return content.OK(data: locationinfos[0]); } else { content.Error("暂无货位可分配"); } } catch (Exception ex) { content.Error(ex.Message); } return content; } /// /// 锁定或者取消锁定货位 /// /// 货位Id /// 是否锁定 /// public WebResponseContent DoLocationLockOperate(SaveModel saveModel) { WebResponseContent responseContent = repository.DbContextBeginTransaction(() => { WebResponseContent content = new WebResponseContent(); try { List locationinfos = new List(); for (int i = 0; i < saveModel.DelKeys.Count(); i++) { Dt_locationinfo locationinfo = new Dt_locationinfo(); Guid id = new Guid(saveModel.DelKeys[i].ToString()); locationinfo = repository.FindFirst(a => a.location_pkid == id); locationinfo.location_islocked = Convert.ToBoolean(saveModel.Extra); locationinfos.Add(locationinfo); } Expression> expression; expression = a => a.location_islocked; content = repository.UpdateRange(locationinfos, expression, true) > 0 ? content.OK() : content.Error("修改失败"); Logger.Info(LoggerType.EditUserInfo, saveModel.ToString(), content.ToString(), "解锁成功"); } catch (Exception ex) { content.Status = false; content.Message = ex.Message; Logger.Info(LoggerType.EditUserInfo, saveModel.ToString(), content.ToString(), "解锁失败"); } return content; }); return responseContent; } public override PageGridData GetPageData(PageDataOptions options) { PageGridData queryData = new PageGridData(); List searchParametersList = new List(); int[] col = { }; if (!string.IsNullOrEmpty(options.Wheres)) { try { searchParametersList = options.Wheres.DeserializeObject>(); List listLocation = repository.Find(r => !(r.location_line == 1 && (col.Contains(r.location_column)))); //int[] rightCol = { 48, 49 }; int[] rightCol = { 50, 51 }; listLocation= listLocation.FindAll(r => !(r.location_line == 2 && (rightCol.Contains(r.location_column)))); if (searchParametersList.Count > 0) { SearchParameters searchParameters = searchParametersList.Find(r => r.Name == "location_id"); if (null != searchParameters) listLocation = listLocation.FindAll(r => r.location_id.Contains(searchParameters.Value)); searchParameters = searchParametersList.Find(r => r.Name == "location_state"); if (null != searchParameters) listLocation = listLocation.FindAll(r => r.location_state.Contains(searchParameters.Value)); searchParameters = searchParametersList.Find(r => r.Name == "location_islocked"); if (null != searchParameters) listLocation = listLocation.FindAll(r => r.location_islocked == bool.Parse(searchParameters.Value)); searchParameters = searchParametersList.Find(r => r.Name == "location_line"); if (null != searchParameters) listLocation = listLocation.FindAll(r => r.location_line == int.Parse(searchParameters.Value)); searchParameters = searchParametersList.Find(r => r.Name == "location_column"); if (null != searchParameters) listLocation = listLocation.FindAll(r => r.location_column == int.Parse(searchParameters.Value)); searchParameters = searchParametersList.Find(r => r.Name == "location_layer"); if (null != searchParameters) listLocation = listLocation.FindAll(r => r.location_layer == int.Parse(searchParameters.Value)); } IQueryable queryable = listLocation.FindAll(r => true).AsQueryable(); string sort = string.IsNullOrEmpty(options.Sort) ? "location_id" : options.Sort; string order = options.Order; IOrderedQueryable queryableOrderBy = null; // Dictionary orderBySelector = new Dictionary() {{ // options.Sort, options.Order?.ToLower() == "asc"? QueryOrderBy.Asc: QueryOrderBy.Desc //} }; queryableOrderBy = options.Order?.ToLower() == "desc" ? queryable.OrderByDescending(sort.GetExpression()) : queryable.OrderBy(sort.GetExpression()); queryData.total = listLocation.Count; queryData.rows = queryableOrderBy.Skip((options.Page - 1) * options.Rows).Take(options.Rows).ToList(); } catch { } } return queryData; } } }