wangxinhui
4 天以前 a0a0df2e824b6fe7e5a3c0afce78127fecf84fc9
ÏîÄ¿´úÂë/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService.cs
@@ -33,14 +33,19 @@
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO;
using WIDESEA_DTO.ERP;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.MES;
using WIDESEA_DTO.Stock;
using WIDESEA_DTO.Task;
using WIDESEA_External.ERPService;
using WIDESEA_External.Model;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_IInboundRepository;
using WIDESEA_IInboundService;
using WIDESEA_InboundRepository;
using WIDESEA_IOutboundRepository;
using WIDESEA_IOutboundService;
using WIDESEA_IRecordService;
using WIDESEA_IStockRepository;
using WIDESEA_IStockService;
@@ -55,15 +60,16 @@
    {
        private readonly IMapper _mapper;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly IStockRepository _stockRepository;
        private readonly IBasicService _basicService;
        private readonly IRecordService _recordService;
        private readonly IStockRepository _stockRepository;
        private readonly IStockService _stockService;
        private readonly IBasicRepository _basicRepository;
        private readonly IApiInfoRepository _apiInfoRepository;
        private readonly IBasicService _basicService;
        private readonly IInvokeERPService _invokeERPService;
        private readonly IPalletTypeInfoRepository _palletTypeInfoRepository;
        private readonly IAGVStationInfoRepository _agvStationInfoRepository;
        private readonly IOutboundRepository _outboundRepository;
        private readonly IOutboundService _outboundService;
        private readonly IInboundRepository _inboundRepository;
        private readonly IInboundService _inboundService;
        public ITaskRepository Repository => BaseDal;
        private Dictionary<string, OrderByType> _taskOrderBy = new()
@@ -76,7 +82,7 @@
        public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 100 && x < 500).ToList();
        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockRepository stockRepository, IBasicService basicService, IRecordService recordService, IStockService stockService, IBasicRepository basicRepository, IApiInfoRepository apiInfoRepository, IInvokeERPService invokeERPService, IPalletTypeInfoRepository palletTypeInfoRepository, IAGVStationInfoRepository agvStationInfoRepository) : base(BaseDal)
        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockRepository stockRepository, IBasicService basicService, IRecordService recordService, IStockService stockService, IBasicRepository basicRepository, IInvokeERPService invokeERPService,  IOutboundRepository outboundRepository, IOutboundService outboundService, IInboundRepository inboundRepository,IInboundService inboundService) : base(BaseDal)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
@@ -85,10 +91,11 @@
            _recordService = recordService;
            _stockService = stockService;
            _basicRepository = basicRepository;
            _apiInfoRepository = apiInfoRepository;
            _invokeERPService = invokeERPService;
            _palletTypeInfoRepository = palletTypeInfoRepository;
            _agvStationInfoRepository = agvStationInfoRepository;
            _outboundRepository = outboundRepository;
            _outboundService = outboundService;
            _inboundRepository = inboundRepository;
            _inboundService = inboundService;
        }
        /// <summary>
@@ -99,6 +106,10 @@
        {
            try
            {
                if (tasks==null || tasks.Count == 0)
                {
                    return WebResponseContent.Instance.Error($"传入任务为空");
                }
                List<WMSTaskDTO> taskDTOs = _mapper.Map<List<WMSTaskDTO>>(tasks);
                taskDTOs.ForEach(x =>
                {
@@ -141,105 +152,32 @@
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        private readonly static object lockerAddSG = new object();
        public WebResponseContent AddOutSGOrder(List<SGOutOrderDTO> outOrderDTOs)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                lock (lockerAddSG)
                {
                    int outDetailId = _outboundRepository.OutSGOrderDetailRepository.QueryData().OrderByDescending(x=>x.Id).FirstOrDefault()?.Id ?? 0;
                    content = _outboundService.OutSGOrderService.AddOutSGOrder(outOrderDTOs);
                    if (!content.Status)
                    {
                        return content;
                    }
                    List<int> ints = _outboundRepository.OutSGOrderDetailRepository.QueryData(x=>x.Id>outDetailId).Select(x=>x.Id).ToList();
                    int[] reseponse= new int[ints.Count];
                    for (int i = 0; i < ints.Count; i++)
                    {
                        reseponse[i] = ints[i];
                    }
                    content.Message = CreateSGOutboundTasks(reseponse).Message;
                }
        /// <summary>
        /// æˆå“ä»“入库任务完成
        /// </summary>
        public WebResponseContent InProductCompleted(Dt_Task task)
        {
            WebResponseContent content=new WebResponseContent();
            try
            {
                switch (task.TaskType)
                {
                    case (int)TaskTypeEnum.EmptyProductBack:
                        content = EmptyProBackCompleted(task);
                        break;
                    case (int)TaskTypeEnum.InProductBack:
                        content = InProBackCompleted(task);
                        break;
                    default:
                        content.Error("未知任务类型");
                        break;
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        public WebResponseContent EmptyProBackCompleted(Dt_Task task)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                //更新入库状态
                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                _unitOfWorkManage.BeginTran();
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.人工完成 : OperateTypeEnum.自动完成);
                _unitOfWorkManage.CommitTran();
                content.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// æˆå“ä½™æ–™é€€åº“任务完成
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent InProBackCompleted(Dt_Task task)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                //获取组盘信息
                Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x => x.PalletCode == task.PalletCode).Includes(x => x.proStockInfoDetails).First();
                if (proStockInfo == null)
                {
                    return content.Error($"未找到胶框为{task.PalletCode}组盘信息");
                }
                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                if (locationInfo == null)
                {
                    return content.Error($"未找到目标货位信息");
                }
                if (locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
                {
                    return content.Error($"货位状态不正确");
                }
                if (proStockInfo.StockStatus!=StockStatusEmun.成品余料回库.ObjToInt())
                {
                    return content.Error($"胶框{proStockInfo.PalletCode}库存状态不正确");
                }
                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
                locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                proStockInfo.LocationCode = locationInfo.LocationCode;
                proStockInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                proStockInfo.proStockInfoDetails.ForEach(x =>
                {
                    x.ProOutDetailStatus = StockStatusEmun.入库完成.ObjToInt();
                });
                //更新入库状态
                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                _unitOfWorkManage.BeginTran();
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.人工完成 : OperateTypeEnum.自动完成);
                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, proStockInfo.PalletType, LocationStatusEnum.InStock, locationInfo.WarehouseId);
                _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo);
                _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfo.proStockInfoDetails);
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted);
                _unitOfWorkManage.CommitTran();
                content.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;