first commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using JSMachine.WMS.App.Dto;
|
||||
using JSMachine.WMS.App.IService;
|
||||
using JSMachine.WMS.Domain.Entity;
|
||||
using JSMachine.WMS.Domain.IRepository;
|
||||
|
||||
namespace JSMachine.WMS.App.ServiceImpl
|
||||
{
|
||||
public class AGVTaskService : BaseService<AGVTaskDto, AGVTask>, IAGVTaskService
|
||||
{
|
||||
private IAGVTaskRepository _agvTaskRepository;
|
||||
public AGVTaskService(IAGVTaskRepository repository) : base(repository)
|
||||
{
|
||||
_agvTaskRepository = repository;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAgvTaskStatus(AGVTaskDto agvTask)
|
||||
{
|
||||
return await base.EditSingalWithSpecificCols(agvTask, [nameof(AGVTask.TaskStatus)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
using AutoMapper;
|
||||
using JSMachine.WMS.App.Dto;
|
||||
using JSMachine.WMS.App.IService;
|
||||
using JSMachine.WMS.Domain.Entity;
|
||||
using JSMachine.WMS.Domain.IRepository;
|
||||
using JSMachine.WMS.Domain.Repository;
|
||||
using JSMachine.WMS.Infrastructure;
|
||||
using JSMachine.WMS.Infrastructure.LambdaHelp;
|
||||
using SqlSugar;
|
||||
using System.Data;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace JSMachine.WMS.App.ServiceImpl
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用层通用服务基类,负责 DTO 与领域实体之间的映射,
|
||||
/// 并将增删改查请求委托给对应的领域仓储。
|
||||
/// </summary>
|
||||
/// <typeparam name="TDTO">应用层数据传输对象类型。</typeparam>
|
||||
/// <typeparam name="TAggregateRoot">领域聚合根类型。</typeparam>
|
||||
public class BaseService<TDTO, TAggregateRoot> : IBaseService<TDTO, TAggregateRoot>
|
||||
where TAggregateRoot : AggregateRoot, IAggregateRoot
|
||||
where TDTO : IRootDto
|
||||
{
|
||||
private IBaseRepository<TAggregateRoot> IBaseRepository;
|
||||
private static IMapper _mapper = GlobalServericeProvidor.GetService<IMapper>();
|
||||
public BaseService(IBaseRepository<TAggregateRoot> baseRepository)
|
||||
{
|
||||
IBaseRepository = baseRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加单个 DTO;当 DTO 未提供标识时生成新标识,并维护创建时间和修改时间。
|
||||
/// </summary>
|
||||
/// <param name="dto">待保存的数据传输对象。</param>
|
||||
/// <param name="sqlSugarScope">可选的数据库作用域;为空时使用仓储默认作用域。</param>
|
||||
/// <returns>数据库插入是否成功。</returns>
|
||||
public async virtual Task<bool> Add(TDTO dto, SqlSugarScope sqlSugarScope=null)
|
||||
{
|
||||
if (dto.Id == Guid.Empty)
|
||||
dto.Id = Guid.NewGuid();
|
||||
dto.CreationTime = DateTime.Now;
|
||||
dto.LastModifiedTime = DateTime.Now;
|
||||
|
||||
return await IBaseRepository.Add(_mapper.Map<TAggregateRoot>(dto),sqlSugarScope);
|
||||
}
|
||||
|
||||
public async virtual Task<bool> Add(TDTO dto, params string[] ignoreColumns)
|
||||
{
|
||||
if (dto.Id == Guid.Empty)
|
||||
dto.Id = Guid.NewGuid();
|
||||
dto.CreationTime = DateTime.Now;
|
||||
dto.LastModifiedTime = DateTime.Now;
|
||||
|
||||
return await IBaseRepository.Add(_mapper.Map<TAggregateRoot>(dto), ignoreColumns);
|
||||
}
|
||||
|
||||
public async virtual Task<bool> Add(List<TDTO> entities)
|
||||
{
|
||||
if (entities == null || entities.Count == 0)
|
||||
return false;
|
||||
|
||||
entities.ForEach(p =>
|
||||
{
|
||||
|
||||
if (p.Id == Guid.Empty)
|
||||
p.Id = Guid.NewGuid();
|
||||
|
||||
p.CreationTime = DateTime.Now;
|
||||
p.LastModifiedTime = DateTime.Now;
|
||||
});
|
||||
|
||||
return await IBaseRepository.Add(_mapper.Map<List<TAggregateRoot>>(entities));
|
||||
}
|
||||
|
||||
public async Task<bool> Add(string tableName, Dictionary<string, object> dic)
|
||||
{
|
||||
if (dic.ContainsKey("Id"))
|
||||
dic.Add("Id", Guid.NewGuid().ToString("N"));
|
||||
|
||||
return await IBaseRepository.Add(tableName, dic);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加之前判断指定字段是否存在,不存在则添加
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddIfNotExist(TDTO entity, Expression<Func<TDTO, bool>> expression)
|
||||
{
|
||||
return await IBaseRepository.AddIfNotExist(_mapper.Map<TAggregateRoot>(entity),
|
||||
_mapper.Map<Expression<Func<TAggregateRoot, bool>>>(expression));
|
||||
}
|
||||
|
||||
public async Task<int> Count()
|
||||
{
|
||||
return await IBaseRepository.Count();
|
||||
}
|
||||
|
||||
public async Task<int> Count(Expression<Func<TDTO, bool>> expression)
|
||||
{
|
||||
return await IBaseRepository.Count(_mapper.Map<Expression<Func<TAggregateRoot, bool>>>(expression));
|
||||
}
|
||||
|
||||
public async Task<bool> DeleByExpression(Expression<Func<TAggregateRoot, bool>> expression)
|
||||
{
|
||||
return await IBaseRepository.DeleByExpression(expression);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteBatch(Guid[] ids)
|
||||
{
|
||||
return await IBaseRepository.DeleteBatch(ids);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteByEntity(TDTO aggregateRoot)
|
||||
{
|
||||
return await IBaseRepository.DeleteByEntity(_mapper.Map<TAggregateRoot>(aggregateRoot));
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteByEntity(List<TDTO> aggregateRoot)
|
||||
{
|
||||
return await IBaseRepository.DeleteByEntity(_mapper.Map<List<TAggregateRoot>>(aggregateRoot));
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteById(Guid id, SqlSugarScope sqlSugarScope=null)
|
||||
{
|
||||
return await IBaseRepository.DeleteById(id,sqlSugarScope);
|
||||
}
|
||||
|
||||
public async Task<bool> EditBatch(List<TDTO> dtos)
|
||||
{
|
||||
dtos.ForEach(p => p.LastModifiedTime = DateTime.Now);
|
||||
|
||||
return await IBaseRepository.EditBatch(_mapper.Map<List<TAggregateRoot>>(dtos));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 快速批量更新
|
||||
/// </summary>
|
||||
/// <param name="dtos"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> EditBatchFast(List<TDTO> dtos)
|
||||
{
|
||||
dtos.ForEach(p => p.LastModifiedTime = DateTime.Now);
|
||||
return await IBaseRepository.EditBatchFast(_mapper.Map<List<TAggregateRoot>>(dtos));
|
||||
}
|
||||
|
||||
public async Task<bool> EditByDic(string tableName, Dictionary<string, object> dic)
|
||||
{
|
||||
return await IBaseRepository.EditByDic(tableName, dic);
|
||||
}
|
||||
|
||||
public async Task<bool> EditByDic(string tableName, List<Dictionary<string, object>> dic)
|
||||
{
|
||||
return await IBaseRepository.EditByDic(tableName, dic);
|
||||
}
|
||||
|
||||
public async virtual Task<bool> EditSingal(TDTO aggregateRoot)
|
||||
{
|
||||
aggregateRoot.LastModifiedTime = DateTime.Now;
|
||||
|
||||
//更新的时候不能够更改数据的添加时间
|
||||
return await IBaseRepository.EditSingal(_mapper.Map<TAggregateRoot>(aggregateRoot), new string[] { "CreationTime" });
|
||||
}
|
||||
|
||||
public async Task<bool> EditSingal(TDTO dto, Expression<Func<TDTO, object>> ignoredColumns)
|
||||
{
|
||||
dto.LastModifiedTime = DateTime.Now;
|
||||
return await IBaseRepository.EditSingal(_mapper.Map<TAggregateRoot>(dto), _mapper.Map<Expression<Func<TAggregateRoot, object>>>(ignoredColumns));
|
||||
}
|
||||
|
||||
public async Task<bool> EditSingal(TDTO dto, string[] ignoredColumns)
|
||||
{
|
||||
dto.LastModifiedTime = DateTime.Now;
|
||||
return await IBaseRepository.EditSingal(_mapper.Map<TAggregateRoot>(dto), ignoredColumns);
|
||||
}
|
||||
|
||||
public async Task<bool> EditSingalWithSpecificCols(TDTO dto, string[] columns)
|
||||
{
|
||||
dto.LastModifiedTime = DateTime.Now;
|
||||
return await IBaseRepository.EditSingalWithSpecificCols(_mapper.Map<TAggregateRoot>(dto), columns);
|
||||
}
|
||||
|
||||
public async Task<bool> Exist(Expression<Func<TDTO, bool>> expression)
|
||||
{
|
||||
return await IBaseRepository.Exist(_mapper.Map<Expression<Func<TAggregateRoot, bool>>>(expression));
|
||||
}
|
||||
|
||||
public async Task<List<TDTO>> GetAll()
|
||||
{
|
||||
List<TAggregateRoot> data = await IBaseRepository.GetAll();
|
||||
|
||||
return _mapper.Map<List<TDTO>>(data);
|
||||
}
|
||||
|
||||
public async Task<List<TDTO>> GetAll(string orderByFiled, OrderByType orderByType)
|
||||
{
|
||||
List<TAggregateRoot> data = await IBaseRepository.GetAll(LambdaHelper<TAggregateRoot>.GetOrderExpression<object>(orderByFiled),
|
||||
orderByType);
|
||||
|
||||
return _mapper.Map<List<TDTO>>(data);
|
||||
}
|
||||
|
||||
public async Task<List<TDTO>> GetAllFragment(int fragmentSize = 50000)
|
||||
{
|
||||
List<TAggregateRoot> data = await IBaseRepository.GetAllFragment(fragmentSize);
|
||||
|
||||
return _mapper.Map<List<TDTO>>(data);
|
||||
}
|
||||
|
||||
public async Task<List<TDTO>> GetAllFragment(string orderByFiled, OrderByType orderByType, int fragmentSize = 200)
|
||||
{
|
||||
List<TAggregateRoot> data = await IBaseRepository.GetAllFragment(
|
||||
LambdaHelper<TAggregateRoot>.GetOrderExpression<object>(orderByFiled),
|
||||
orderByType,
|
||||
fragmentSize);
|
||||
return _mapper.Map<List<TDTO>>(data);
|
||||
}
|
||||
|
||||
public async Task<List<TDTO>> GetBySql(string sql)
|
||||
{
|
||||
List<TAggregateRoot> data = await IBaseRepository.GetBySql(sql);
|
||||
return _mapper.Map<List<TDTO>>(data);
|
||||
}
|
||||
|
||||
public async Task<List<TDTO>> GetBySql(string sql, Dictionary<string, object> sqlParam)
|
||||
{
|
||||
List<TAggregateRoot> data = await IBaseRepository.GetBySql(sql, sqlParam);
|
||||
return _mapper.Map<List<TDTO>>(data);
|
||||
}
|
||||
|
||||
public async Task<DataTable> GetDataTableBysql(string sql)
|
||||
{
|
||||
return await IBaseRepository.GetDataTableBysql(sql);
|
||||
}
|
||||
|
||||
public async Task<DataTable> GetDataTableBysql(string sql, Dictionary<string, object> sqlParam)
|
||||
{
|
||||
return await IBaseRepository.GetDataTableBysql(sql, sqlParam);
|
||||
}
|
||||
|
||||
public async Task<List<dynamic>> GetDynamicsBysql(string sql)
|
||||
{
|
||||
return await IBaseRepository.GetDynamicsBysql(sql);
|
||||
}
|
||||
|
||||
public async Task<List<dynamic>> GetDynamicsBysql(string sql, Dictionary<string, object> sqlParam)
|
||||
{
|
||||
return await IBaseRepository.GetDynamicsBysql(sql, sqlParam);
|
||||
}
|
||||
|
||||
public async Task<List<TDTO>> GetListByExpression(Expression<Func<TDTO, bool>> expression)
|
||||
{
|
||||
List<TAggregateRoot> data = await IBaseRepository.GetListByExpression(
|
||||
_mapper.Map<Expression<Func<TAggregateRoot, bool>>>(expression));
|
||||
|
||||
return _mapper.Map<List<TDTO>>(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询满足条件的所有实体(带排序功能)
|
||||
/// </summary>
|
||||
/// <param name="expression"></param>
|
||||
/// <param name="orderByExpress"></param>
|
||||
/// <param name="orderByType">Asc = 0,Desc = 1</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TDTO>> GetListByExpression(Expression<Func<TAggregateRoot, bool>> expression,
|
||||
string filedName,
|
||||
OrderByType orderByType = OrderByType.Desc)
|
||||
{
|
||||
List<TAggregateRoot> data = await IBaseRepository.GetListByExpression(
|
||||
_mapper.Map<Expression<Func<TAggregateRoot, bool>>>(expression),
|
||||
filedName,
|
||||
orderByType);
|
||||
|
||||
return _mapper.Map<List<TDTO>>(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过实体查询满足条件的数据
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<TDTO>> GetListWhereClass(TDTO dto)
|
||||
{
|
||||
List<TAggregateRoot> data = await IBaseRepository.GetListWhereClass(
|
||||
_mapper.Map<TAggregateRoot>(dto));
|
||||
return _mapper.Map<List<TDTO>>(data);
|
||||
}
|
||||
|
||||
public async Task<TDTO> GetSingalByExpression(Expression<Func<TDTO, bool>> expression)
|
||||
{
|
||||
TAggregateRoot data = await IBaseRepository.GetSingalByExpression(
|
||||
_mapper.Map<Expression<Func<TAggregateRoot, bool>>>(expression));
|
||||
|
||||
return _mapper.Map<TDTO>(data);
|
||||
}
|
||||
|
||||
public async Task<TDTO> GetSingalByExpression(
|
||||
Expression<Func<TDTO, bool>> expression,
|
||||
Expression<Func<TAggregateRoot, object>> orderByExpress,
|
||||
OrderByType orderByType)
|
||||
{
|
||||
TAggregateRoot data = await IBaseRepository.GetSingalByExpression(
|
||||
_mapper.Map<Expression<Func<TAggregateRoot, bool>>>(expression), orderByExpress, orderByType);
|
||||
|
||||
return _mapper.Map<TDTO>(data);
|
||||
}
|
||||
|
||||
public async Task<List<TDTO>> QueryByIds(Guid[] ids)
|
||||
{
|
||||
List<TAggregateRoot> data = await IBaseRepository.QueryByIds(ids);
|
||||
return _mapper.Map<List<TDTO>>(data);
|
||||
}
|
||||
|
||||
public async Task<TDTO> QueryByKey(string key)
|
||||
{
|
||||
TAggregateRoot data = await IBaseRepository.QueryByKey(key);
|
||||
return _mapper.Map<TDTO>(data);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<TDTO>> QueryByPage(PageQueryCondition pageQueryCondition)
|
||||
{
|
||||
PagedResult<TAggregateRoot> dataPage = await IBaseRepository.QueryByPage(pageQueryCondition);
|
||||
|
||||
return new PagedResult<TDTO>(dataPage.TotalRecords,
|
||||
dataPage.PageSize,
|
||||
dataPage.PageNumber,
|
||||
_mapper.Map<List<TDTO>>(dataPage.PageData));
|
||||
}
|
||||
|
||||
public async Task<bool> ExcuteSql(string sql, params SugarParameter[] @params)
|
||||
{
|
||||
return await IBaseRepository.ExcuteSql(sql, @params);
|
||||
}
|
||||
|
||||
#region 事务操作
|
||||
public async Task BeginTran(SqlSugarScope sqlSugarScope)
|
||||
{
|
||||
await IBaseRepository.BeginTran(sqlSugarScope);
|
||||
}
|
||||
|
||||
public async Task CommitTran(SqlSugarScope sqlSugarScope)
|
||||
{
|
||||
await IBaseRepository.CommitTran(sqlSugarScope);
|
||||
}
|
||||
|
||||
public async Task RollbackTran(SqlSugarScope sqlSugarScope)
|
||||
{
|
||||
await IBaseRepository.RollbackTran(sqlSugarScope);
|
||||
}
|
||||
|
||||
public SqlSugarTransaction UseTranAsync()
|
||||
{
|
||||
return IBaseRepository.UseTranAsync();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using JSMachine.WMS.App.Dto;
|
||||
using JSMachine.WMS.App.IService;
|
||||
using JSMachine.WMS.Domain.Entity;
|
||||
using JSMachine.WMS.Domain.IRepository;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.App.ServiceImpl
|
||||
{
|
||||
public class ERPTaskService : BaseService<ERPTaskDto, ERPTask>, IERPTaskService
|
||||
{
|
||||
private IERPTaskRepository _erpTaskRepository;
|
||||
public ERPTaskService(IERPTaskRepository repository) : base(repository)
|
||||
{
|
||||
_erpTaskRepository = repository;
|
||||
}
|
||||
|
||||
public Task<bool> UpdateTaskMsg(Guid id, string taskMsg)
|
||||
{
|
||||
return _erpTaskRepository.ExcuteSql($"update ERPTask set TaskMsg='{taskMsg}' where Id='{id}'");
|
||||
}
|
||||
|
||||
public Task<bool> UpdateTaskStatus(ERPTaskDto erpTask)
|
||||
{
|
||||
erpTask.LastModifiedTime = DateTime.Now;
|
||||
return base.EditSingalWithSpecificCols(erpTask, [nameof(ERPTaskDto.TaskStatus), nameof(ERPTaskDto.LastModifiedTime)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using JSMachine.WMS.App.Dto;
|
||||
using JSMachine.WMS.App.IService;
|
||||
using JSMachine.WMS.Domain.Entity;
|
||||
using JSMachine.WMS.Domain.IRepository;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.App.ServiceImpl
|
||||
{
|
||||
public class ElevatorCountService : BaseService<ElevatorCountDto, ElevatorCount>, IElevatorCountService
|
||||
{
|
||||
public ElevatorCountService(IBaseRepository<ElevatorCount> baseRepository) : base(baseRepository)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计数自增
|
||||
/// </summary>
|
||||
/// <param name="elevatorNo"></param>
|
||||
/// <param name="channel"></param>
|
||||
/// <returns></returns>
|
||||
public async Task IncrementCount(int elevatorNo, int channel)
|
||||
{
|
||||
ElevatorCountDto elevatorCount = await GetSingalByExpression(p =>
|
||||
p.CreationTime >= DateTime.Now.Date &&
|
||||
p.ElevatorNo == elevatorNo &&
|
||||
p.ElevatorChannel == channel);
|
||||
if (elevatorCount == null)
|
||||
{
|
||||
elevatorCount = new()
|
||||
{
|
||||
ElevatorNo = elevatorNo,
|
||||
ElevatorChannel = channel,
|
||||
Count = 1
|
||||
};
|
||||
|
||||
await Add(elevatorCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
elevatorCount.Count++;
|
||||
await EditSingal(elevatorCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using JSMachine.WMS.App.Dto;
|
||||
using JSMachine.WMS.App.Dto.Enum;
|
||||
using JSMachine.WMS.App.IService;
|
||||
using JSMachine.WMS.Domain.Entity;
|
||||
using JSMachine.WMS.Domain.IRepository;
|
||||
using JSMachine.WMS.Infrastructure.Helper;
|
||||
|
||||
namespace JSMachine.WMS.App.ServiceImpl
|
||||
{
|
||||
public class ElevatorPlcQueueService : BaseService<ElevatorPlcQueueDto, ElevatorPlcQueue>, IElevatorPlcQueueService
|
||||
{
|
||||
private IElevatorPlcQueueRepository _elevatorPlcQueueRepository;
|
||||
public ElevatorPlcQueueService(IElevatorPlcQueueRepository repository) : base(repository)
|
||||
{
|
||||
_elevatorPlcQueueRepository = repository;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using JSMachine.WMS.App.ServiceImpl;
|
||||
using JSMachine.WMS.Application.Dto;
|
||||
using JSMachine.WMS.Application.IService;
|
||||
using JSMachine.WMS.Domain.Entity;
|
||||
using JSMachine.WMS.Domain.IRepository;
|
||||
|
||||
namespace JSMachine.WMS.Application.ServiceImpl
|
||||
{
|
||||
public class OperationLogService : BaseService<OperationLogDto, OperationLog>, IOperationLogService
|
||||
{
|
||||
private readonly IOperationLogRepository _operationLogRepository;
|
||||
|
||||
public OperationLogService(IOperationLogRepository repository) : base(repository)
|
||||
{
|
||||
_operationLogRepository = repository;
|
||||
}
|
||||
|
||||
// 可根据业务需求添加自定义操作方法
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using JSMachine.WMS.App.Dto;
|
||||
using JSMachine.WMS.App.IService;
|
||||
using JSMachine.WMS.Domain.Entity;
|
||||
using JSMachine.WMS.Domain.IRepository;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.App.ServiceImpl
|
||||
{
|
||||
public class RcsTaskService : BaseService<RcsTaskDto, RcsTask>, IRcsTaskService
|
||||
{
|
||||
private IRcsTaskRepository _rcsTaskRepository;
|
||||
public RcsTaskService(IRcsTaskRepository rcsTaskRepository) : base(rcsTaskRepository)
|
||||
{
|
||||
_rcsTaskRepository = rcsTaskRepository;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
using JSMachine.WMS.App.Dto;
|
||||
using JSMachine.WMS.App.Dto.Enum;
|
||||
using JSMachine.WMS.App.IService;
|
||||
using JSMachine.WMS.Domain.Entity;
|
||||
using JSMachine.WMS.Domain.IRepository;
|
||||
using JSMachine.WMS.Infrastructure;
|
||||
using JSMachine.WMS.Infrastructure.Helper;
|
||||
using SqlSugar;
|
||||
using static JSMachine.WMS.App.Dto.StorageRackDto;
|
||||
|
||||
namespace JSMachine.WMS.App.ServiceImpl
|
||||
{
|
||||
public class StorageRackService : BaseService<StorageRackDto, StorageRack>, IStorageRackService
|
||||
{
|
||||
private IStorageRackRepository _storageRackRepository;
|
||||
public StorageRackService(IStorageRackRepository repository) : base(repository)
|
||||
{
|
||||
_storageRackRepository = repository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据库位号查询库位信息
|
||||
/// </summary>
|
||||
/// <param name="storageRackNo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<StorageRackDto> GetByStorageRackNo(string storageRackNo)
|
||||
{
|
||||
return await GetSingalByExpression(p => p.StorageRackNo == storageRackNo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据批次号计算目标存储区库位
|
||||
/// </summary>
|
||||
/// <param name="materiaBatch"></param>
|
||||
/// <returns></returns>
|
||||
//public async Task<StorageRackDto> CalculateDestWarehouse(string materiaBatch, FloorEnum floor)
|
||||
//{
|
||||
// //如果某一列有一个库位被锁定,说明该列有未完成的任务(任务完成会解锁库位),因此该列不可以再生成新的任务
|
||||
|
||||
// //获取楼层的所有库位
|
||||
// List<StorageRackDto> wareHouses = await GetListByExpression(p =>
|
||||
// p.Floor == floor && p.Transport == TransportEnum.NormalArea);
|
||||
|
||||
// if (wareHouses.IsNullOrEmpty())
|
||||
// {
|
||||
// LogHelper.Warn($"{floor} 层没有空余库位");
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// wareHouses = wareHouses.OrderBy(p => p.AreaNumSort).OrderBy(p => p.ReservoirAreaColumnId).ToList();
|
||||
|
||||
// List<StorageRackDto> sameBatchWarehouses = wareHouses.Where(p => p.MateriaBatch == materiaBatch).ToList();
|
||||
// StorageRackDto destStorageRack = null;
|
||||
|
||||
// //没有相同批次则任选一个空白的列
|
||||
// if (sameBatchWarehouses.IsNullOrEmpty())
|
||||
// {
|
||||
// var groupByColumn = wareHouses.GroupBy(p => p.ReservoirAreaColumnId);
|
||||
|
||||
// foreach (var columnGroup in groupByColumn)
|
||||
// {
|
||||
// bool emptyColumn = columnGroup.All(p => !p.IsLock && !p.IsDisabled && string.IsNullOrEmpty(p.BarCode));
|
||||
// if (emptyColumn)
|
||||
// {
|
||||
// destStorageRack = columnGroup.OrderByDescending(p => p.NumSort).First();
|
||||
// break;
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else //存在相同批次则搜寻该批次所在的列下是否还有空库位
|
||||
// {
|
||||
// foreach (StorageRackDto sameBatchWarehous in sameBatchWarehouses)
|
||||
// {
|
||||
// var sameColumnWarehouse = wareHouses.Where(p => p.ReservoirAreaColumnId == sameBatchWarehous.ReservoirAreaColumnId);
|
||||
// //同批次的列中也不能有任何库位被锁定
|
||||
// if (sameColumnWarehouse.All(p => !p.IsLock && !p.IsDisabled))
|
||||
// {
|
||||
// destStorageRack = sameColumnWarehouse
|
||||
// .OrderByDescending(p => p.NumSort)
|
||||
// .FirstOrDefault(p => string.IsNullOrEmpty(p.BarCode));
|
||||
|
||||
// if (destStorageRack != null)
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// //如果同批次下都没有合适的库位,则需要找空列
|
||||
// if (destStorageRack == null)
|
||||
// {
|
||||
// List<StorageRackDto> remain = wareHouses.Except(sameBatchWarehouses, new StorageRackDtoIEqualityComparer()).ToList();
|
||||
// if (remain.IsNullOrEmpty())
|
||||
// {
|
||||
// LogHelper.Warn("排除相同批次库位后没有剩余可用库位");
|
||||
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// var groupByColumn = remain.GroupBy(p => p.ReservoirAreaColumnId);
|
||||
|
||||
// foreach (var columnGroup in groupByColumn)
|
||||
// {
|
||||
// bool emptyColumn = columnGroup.All(p => !p.IsLock && !p.IsDisabled && string.IsNullOrEmpty(p.BarCode));
|
||||
// if (emptyColumn)
|
||||
// {
|
||||
// destStorageRack = columnGroup.OrderByDescending(p => p.NumSort).First();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
// return destStorageRack;
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据批次号判断是否存在空余库位
|
||||
/// </summary>
|
||||
/// <param name="materialBatch"></param>
|
||||
/// <returns></returns>
|
||||
//public async Task<bool> HasEmptyWareHouse(string materiaBatch, TaskTypeEnum taskType, FloorEnum floor)
|
||||
//{
|
||||
// //直接调用目标库位计算方法,能够计算出目标库位则有库位,否则就是没有
|
||||
// //一楼采用完全不混放模式
|
||||
// //二楼视配置
|
||||
|
||||
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 获取可用的提升机库位
|
||||
/// </summary>
|
||||
/// <param name="floor"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<StorageRackDto>> GetUsableElevatorWareHouse(FloorEnum floor)
|
||||
{
|
||||
List<long?> reservoirAreaIds = floor == FloorEnum.FirstFloor ? [1091, 1092] : [2091, 2092];
|
||||
|
||||
List<StorageRackDto> elevatorWarehouse = await
|
||||
GetListByExpression(p =>
|
||||
reservoirAreaIds.Contains(p.ReservoirAreaId)
|
||||
&&
|
||||
!p.IsLock && !p.IsDisabled
|
||||
);
|
||||
return elevatorWarehouse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据提升机编号和通道号获取提所属库位信息
|
||||
/// </summary>
|
||||
/// <param name="elevatorNo"></param>
|
||||
/// <param name="channel"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<StorageRackDto> GetElevatorWareHouse(int elevatorNo, int channel)
|
||||
{
|
||||
string nameMatch = elevatorNo == 1 ? "1号" : "2号";
|
||||
StorageRackDto storageRack = await GetSingalByExpression(p => p.ElevatorChannel == channel && p.StorageRackName.Contains(nameMatch));
|
||||
|
||||
return storageRack;
|
||||
}
|
||||
|
||||
public async Task<bool> Lock(StorageRackDto storageRack)
|
||||
{
|
||||
storageRack.IsLock = true;
|
||||
|
||||
LogHelper.Info($"锁定库位{storageRack.StorageRackNo}");
|
||||
|
||||
return await base.EditSingalWithSpecificCols(storageRack, ["IsLock"]);
|
||||
}
|
||||
|
||||
public async Task<bool> Unlock(StorageRackDto storageRack)
|
||||
{
|
||||
storageRack.IsLock = false;
|
||||
LogHelper.Info($"解锁库位{storageRack.StorageRackNo}");
|
||||
|
||||
return await base.EditSingalWithSpecificCols(storageRack, ["IsLock"]);
|
||||
}
|
||||
|
||||
public Task<bool> UpdateLockStatus(Guid id, bool isLock)
|
||||
{
|
||||
return base.ExcuteSql($"update StorageRack set IsLock = {isLock} where Id = '{id}'");
|
||||
}
|
||||
|
||||
public Task<bool> UpdateDisableStatus(Guid id, bool isDisable)
|
||||
{
|
||||
return base.ExcuteSql($"update StorageRack set IsDisabled = {isDisable} where Id = '{id}'");
|
||||
}
|
||||
|
||||
private static readonly SemaphoreSlim SemaphoreSlim = new(1,1);
|
||||
public async Task<StorageRackDto> GetUsableTransferStorageRack()
|
||||
{
|
||||
await SemaphoreSlim.WaitAsync();
|
||||
|
||||
StorageRackDto storageRackDto = await
|
||||
base.GetSingalByExpression(p =>
|
||||
p.Transport == TransportEnum.TransitArea &&
|
||||
!p.IsLock &&
|
||||
!p.IsDisabled &&
|
||||
string.IsNullOrEmpty(p.BarCode));
|
||||
|
||||
if (storageRackDto != null)
|
||||
await Lock(storageRackDto);
|
||||
|
||||
SemaphoreSlim.Release();
|
||||
return storageRackDto;
|
||||
}
|
||||
|
||||
//public async Task<int> PreCalUsableStorageRackCount(FloorEnum floor)
|
||||
//{
|
||||
// //1. 一楼不混放,需要查找同批次,或者空白列
|
||||
// //2.二楼可以混放,仅需要查找到一个空库位即可
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using JSMachine.WMS.App.Dto;
|
||||
using JSMachine.WMS.App.IService;
|
||||
using JSMachine.WMS.Domain.Entity;
|
||||
using JSMachine.WMS.Domain.IRepository;
|
||||
|
||||
namespace JSMachine.WMS.App.ServiceImpl
|
||||
{
|
||||
public class UserInfoService : BaseService<UserInfoDto, UserInfo>, IUserInfoService
|
||||
{
|
||||
private IUserInfoRepository _userInfoRepository;
|
||||
|
||||
public UserInfoService(IUserInfoRepository repository) : base(repository)
|
||||
{
|
||||
_userInfoRepository = repository;
|
||||
}
|
||||
|
||||
// 可以在这里添加UserInfo特有的方法实现
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user