using AngleSharp.Dom; using log4net.Core; using Mapster; using Masuit.Tools; using SqlSugar; using System.Collections; using System.Collections.Generic; using System.Drawing.Printing; using System.Linq.Expressions; using System.Threading.Tasks; using WIDESEA_Common; using WIDESEA_Core; using WIDESEA_Model.Models; namespace WIDESEA_StorageBasicService; public class VV_PalletStockInfoService : ServiceBase, IVV_PalletStockInfoService { private readonly IDt_PalletStockInfoRepository _PalletStockInfoRepository; private readonly IDt_PalletStockInfoDetailRepository _PalletStockInfoDetailRepository; private readonly IDt_PalletStockInfo_htyRepository _PalletStockInfo_HtyRepository; private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository; private readonly IUnitOfWorkManage _unitOfWorkManage; public VV_PalletStockInfoService(IVV_PalletStockInfoRepository BaseDal, IDt_PalletStockInfoRepository palletStockInfoRepository, IDt_PalletStockInfoDetailRepository palletStockInfoDetailRepository, IUnitOfWorkManage unitOfWorkManage, ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository) : base(BaseDal) { _PalletStockInfoRepository = palletStockInfoRepository; _PalletStockInfoDetailRepository = palletStockInfoDetailRepository; _unitOfWorkManage = unitOfWorkManage; _locationStatusChangeRecordRepository = locationStatusChangeRecordRepository; } public override WebResponseContent DeleteData(object key) { try { var stock = _PalletStockInfoRepository.QueryFirstNavAsync(x => x.Id == key.ObjToInt()).Result; var stockHty = stock.Adapt(); stockHty.FinishTime = DateTime.Now; stockHty.OperateType = (int)OperateTypeEnum.人工删除; stockHty.Modifier = App.User.UserName; var location = SqlSugarHelper.DbWMS.Queryable().FirstAsync(x => x.LocationCode == stock.LocationCode).Result; location.LocationStatus = (int)LocationEnum.Free; var hty = BaseDal.Db.InsertNav(stockHty) .Include(x => x.StockInfoDetails) .ExecuteCommand(); var locationd = SqlSugarHelper.DbWMS.Updateable(location).ExecuteCommandHasChange(); _PalletStockInfoRepository.DeleteDataById(stock.Id); return base.DeleteData(key); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } /// /// 批量删除 /// /// /// public override WebResponseContent DeleteData(object[] keys) { WebResponseContent content = new WebResponseContent(); try { foreach (var item in keys) { var stock = _PalletStockInfoRepository.QueryFirstNavAsync(x => x.Id == item.ObjToInt()).Result; Dt_PalletStockInfo_hty stockHty = stock.Adapt(); stockHty.FinishTime = DateTime.Now; stockHty.OperateType = (int)OperateTypeEnum.人工删除; stockHty.Modifier = App.User.UserName; //_PalletStockInfoRepository.AddData(stockHty); _PalletStockInfoRepository.DeleteDataById(stock.Id); List detail = _PalletStockInfoDetailRepository.QueryData(x => x.StockId == stock.Id).ToList(); if (detail is not null && detail.Count() > 0) { List details = detail.Adapt>(); var ids = details.Select(x => (object)x.Id).ToArray(); var isStockDetailUpdated = _PalletStockInfoDetailRepository.DeleteDataByIds(ids); var isStockAdd = SqlSugarHelper.DbWMS.Insertable(details).ExecuteCommand(); } var location = SqlSugarHelper.DbWMS.Queryable().FirstAsync(x => x.LocationCode == stock.LocationCode).Result; int beforeStatue = location.LocationStatus; location.LocationStatus = (int)LocationEnum.Lock; SqlSugarHelper.DbWMS.Updateable(location).ExecuteCommandHasChange(); _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, beforeStatue, (int)StatusChangeTypeEnum.ManualOperation, 0); } return content.OK("删除成功"); } catch (Exception ex) { return content.Error(ex.Message); } } }