using AngleSharp.Dom; using Mapster; using Masuit.Tools; using SqlSugar; using System.Collections.Generic; using System.Drawing.Printing; using System.Linq.Expressions; using WIDESEA_Common; using WIDESEA_Core; using WIDESEA_Core.Enums; using WIDESEA_DTO; using WIDESEA_IRecordService; namespace WIDESEA_StorageBasicService; public class VV_StockInfoService : ServiceBase, IVV_StockInfoService { private readonly IDt_PalletStockInfoRepository _PalletStockInfoRepository; private readonly IStockQuantityChangeRecordService _stockQuantityChangeRecord; private readonly IDt_CarBodyInfoRepository _carBodyInfoRepository; private readonly ILocationInfoRepository _locationInfoRepository; private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository; private readonly IUnitOfWorkManage _unitOfWorkManage; public VV_StockInfoService(IVV_StockInfoRepository BaseDal, IDt_PalletStockInfoRepository PalletStockInfoRepository, IStockQuantityChangeRecordService stockQuantityChangeRecord, IDt_CarBodyInfoRepository carBodyInfoRepository, ILocationInfoRepository locationInfoRepository, ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) { _PalletStockInfoRepository = PalletStockInfoRepository; _stockQuantityChangeRecord = stockQuantityChangeRecord; _carBodyInfoRepository = carBodyInfoRepository; _locationInfoRepository = locationInfoRepository; _locationStatusChangeRecordRepository = locationStatusChangeRecordRepository; _unitOfWorkManage = unitOfWorkManage; } public WebResponseContent stockLock(object[] keys) { WebResponseContent content = new WebResponseContent(); try { foreach (var item in keys) { var stock = _PalletStockInfoRepository.QueryFirst(x => x.Id == Convert.ToInt32(item)); if (stock.LockOrder != 1) { stock.StockStatus = 1; _PalletStockInfoRepository.UpdateData(stock); } } return content.OK("锁定成功!"); } catch (Exception e) { return content.Error(e.Message); } } public WebResponseContent stockUnLock(object[] keys) { WebResponseContent content = new WebResponseContent(); try { foreach (var item in keys) { var stock = _PalletStockInfoRepository.QueryFirst(x => x.Id == Convert.ToInt32(item)); stock.StockStatus = 0; _PalletStockInfoRepository.UpdateData(stock); } return content.OK("解锁成功!"); } catch (Exception e) { return content.Error(e.Message); } } public override WebResponseContent DeleteData(object[] keys) { WebResponseContent content = new WebResponseContent(); try { var stockInfo = BaseDal.QueryFirst(x => x.Id == keys[0].ObjToInt()); var stock = _PalletStockInfoRepository.QueryFirst(x => x.Id == keys[0].ObjToInt()); var location = _locationInfoRepository.QueryFirst(x => x.LocationCode == stock.LocationCode); var carInfo = _carBodyInfoRepository.QueryData(x => x.Id == stock.carBodyID); int beforState = location.LocationStatus; stock.StockStatus = 5; location.LocationStatus = LocationEnum.Free.ObjToInt(); LocationChangeRecordDto changeRecordDto = new LocationChangeRecordDto() { AfterStatus = 0, BeforeStatus = beforState, TaskNum = 0, LocationId = location.Id, LocationCode = location.LocationCode, ChangeType = (int)StatusChangeTypeEnum.ManualOperation }; _unitOfWorkManage.BeginTran(); _PalletStockInfoRepository.DeleteData(stock); _locationInfoRepository.UpdateData(location); _carBodyInfoRepository.DeleteData(carInfo); _locationStatusChangeRecordRepository.AddStatusChangeRecord(changeRecordDto); _unitOfWorkManage.CommitTran(); return content.OK("删除成功"); } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return content.Error(ex.Message); } } }