/*
|
*所有关于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);
|
}
|
|
|
/// <summary>
|
/// 给入库请求分配货位(获取指定的层)
|
/// </summary>
|
/// <returns></returns>
|
public WebResponseContent GetEmptyLocation(WIDESEAContext dbcontext, string desLayer)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Dt_locationinfoRepository locationinfoRepository = new Dt_locationinfoRepository(dbcontext);
|
|
List<Dt_locationinfo> 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;
|
}
|
|
|
/// <summary>
|
/// 锁定或者取消锁定货位
|
/// </summary>
|
/// <param name="locationId">货位Id</param>
|
/// <param name="lockFlag">是否锁定</param>
|
/// <returns></returns>
|
public WebResponseContent DoLocationLockOperate(SaveModel saveModel)
|
{
|
WebResponseContent responseContent = repository.DbContextBeginTransaction(() =>
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
List<Dt_locationinfo> locationinfos = new List<Dt_locationinfo>();
|
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<Func<Dt_locationinfo, object>> 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<Dt_locationinfo> GetPageData(PageDataOptions options)
|
{
|
|
|
PageGridData<Dt_locationinfo> queryData = new PageGridData<Dt_locationinfo>();
|
List<SearchParameters> searchParametersList = new List<SearchParameters>();
|
int[] col = { };
|
if (!string.IsNullOrEmpty(options.Wheres))
|
{
|
try
|
{
|
searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
|
List<Dt_locationinfo> 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<Dt_locationinfo> queryable = listLocation.FindAll(r => true).AsQueryable();
|
|
string sort = string.IsNullOrEmpty(options.Sort) ? "location_id" : options.Sort;
|
string order = options.Order;
|
IOrderedQueryable<Dt_locationinfo> queryableOrderBy = null;
|
// Dictionary<string, QueryOrderBy> orderBySelector = new Dictionary<string, QueryOrderBy>() {{
|
// options.Sort, options.Order?.ToLower() == "asc"? QueryOrderBy.Asc: QueryOrderBy.Desc
|
//} };
|
queryableOrderBy = options.Order?.ToLower() == "desc" ? queryable.OrderByDescending(sort.GetExpression<Dt_locationinfo>()) :
|
queryable.OrderBy(sort.GetExpression<Dt_locationinfo>());
|
|
queryData.total = listLocation.Count;
|
queryData.rows = queryableOrderBy.Skip((options.Page - 1) * options.Rows).Take(options.Rows).ToList();
|
}
|
catch
|
{
|
|
|
}
|
}
|
return queryData;
|
}
|
}
|
}
|