1
yangpeixing
2 天以前 c69b6892e9e004db9cf5d0edc69bbd2fcc1d83db
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs
@@ -23,6 +23,7 @@
using WIDESEA_DTO.Stock;
using WIDESEA_DTO.WMS;
using WIDESEA_IOrderRepository;
using WIDESEA_IOrderServices;
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.Order;
using WIDESEA_OrderRepository;
@@ -33,8 +34,10 @@
public class StockInfoService : ServiceBase<DtStockInfo, IStockInfoRepository>, IStockInfoService
{
    private readonly LogFactory LogFactory = new LogFactory();
    private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository;
    private readonly IDt_InboundOrderRepository _inboundOrderRepository;
    private readonly IDt_InboundOrderService _inboundOrderService;
    private readonly IUnitOfWorkManage _unitOfWorkManage;
    private readonly IStockInfoDetailRepository _stockInfoDetailRepository;
    private readonly IDt_TaskService _taskService;
@@ -52,7 +55,8 @@
                                ILocationInfoRepository locationRepository,
                                IDt_TaskRepository taskRepository,
                                IDt_OrderOutDetailsRepository outDetailsRepository,
                                IDt_Task_HtyRepository task_HtyRepository) : base(BaseDal)
                                IDt_Task_HtyRepository task_HtyRepository,
                                IDt_InboundOrderService inboundOrderService) : base(BaseDal)
    {
        _locationStatusChangeRecordRepository = locationStatusChangeRecordRepository;
        _inboundOrderRepository = inboundOrderRepository;
@@ -63,6 +67,7 @@
        _taskRepository = taskRepository;
        _outDetailsRepository = outDetailsRepository;
        _task_HtyRepository = task_HtyRepository;
        _inboundOrderService = inboundOrderService;
    }
    #region æ–¹æ³•重写
    /// <summary>
@@ -120,11 +125,11 @@
            }
            else if (item.Name.Contains("materielCode"))
            {
                materielCode = x => x.StockInfoDetails.Any(d => d.MaterielCode == item.Value);
                materielCode = x => x.StockInfoDetails.Any(d => d.MaterielCode.Contains(item.Value));
            }
            else if (item.Name.Contains("materielName"))
            {
                materielName = x => x.StockInfoDetails.Any(d => d.MaterielName == item.Value);
                materielName = x => x.StockInfoDetails.Any(d => d.MaterielName.Contains(item.Value));
            }
        }
        //.IncludesAllFirstLayer()
@@ -197,7 +202,7 @@
                }
                locationsNew.Add(item);
            }
            else if (item.AreaId == 2)
            else if (item.AreaId == 2 || item.AreaId == 7)
            {
                var locationLateral = _locationRepository.QueryData(x => x.Row == item.Row && x.Column > item.Column && x.Remark == item.Remark);
@@ -457,17 +462,33 @@
            DateTime firstDayOfMonth = new DateTime(utcNow.Year, utcNow.Month, 1);
            DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddSeconds(-1);
            // è®¡ç®—上月时间范围
            DateTime firstDayOfLastMonth = new DateTime(utcNow.Year, utcNow.Month, 1).AddMonths(-1);
            DateTime lastDayOfLastMonth = firstDayOfLastMonth.AddMonths(1).AddSeconds(-1);
            // è®¡ç®—当天时间范围
            DateTime todayStart = utcNow.Date;
            DateTime todayEnd = todayStart.AddDays(1).AddTicks(-1);
            // è®¡ç®—昨日时间范围
            DateTime startOfPreviousDay = utcNow.AddDays(-1).Date;  // å‰ä¸€å¤©çš„ 00:00:00
            DateTime endOfPreviousDay = startOfPreviousDay.AddDays(1).AddSeconds(-1);
            // æŸ¥è¯¢å½“月数据
            var currentMonthInStocks = stocks.Where(x => x.CreateDate >= firstDayOfMonth && x.CreateDate <= lastDayOfMonth).Sum(x => x.Quantity);
            var currentMonthOutStocks = orderdetail.Where(x => x.CreateDate >= firstDayOfMonth && x.CreateDate <= lastDayOfMonth).Sum(x => x.OutboundQuantity);
            // æŸ¥è¯¢å½“日数据
            //查询上月数据
            var currentMonthInStocksLastMonth = stocks.Where(x => x.CreateDate >= firstDayOfLastMonth && x.CreateDate <= lastDayOfLastMonth).Sum(x => x.Quantity);
            var currentMonthOutStocksLastMonth = orderdetail.Where(x => x.CreateDate >= firstDayOfLastMonth && x.CreateDate <= lastDayOfLastMonth).Sum(x => x.OutboundQuantity);
            // æŸ¥è¯¢ä»Šæ—¥æ•°æ®
            var currentDayInStocks = stocks.Where(x => x.CreateDate >= todayStart && x.CreateDate <= todayEnd).Sum(x => x.Quantity);
            var currentDayOutStocks = orderdetail.Where(x => x.CreateDate >= todayStart && x.CreateDate <= todayEnd).Sum(x => x.OutboundQuantity);
            // æŸ¥è¯¢æ˜¨å¤©æ—¥æ•°æ®
            var currentDayInStocksLast = stocks.Where(x => x.CreateDate >= startOfPreviousDay && x.CreateDate <= endOfPreviousDay).Sum(x => x.Quantity);
            var currentDayOutStocksLast = orderdetail.Where(x => x.CreateDate >= startOfPreviousDay && x.CreateDate <= endOfPreviousDay).Sum(x => x.OutboundQuantity);
            // ç”Ÿæˆæœ€è¿‘7天的出入库数据
            var last7Days = Enumerable.Range(0, 7)
@@ -483,7 +504,7 @@
            var inboundData = last7Days.Select(date => new
            {
                Date = date.ToString("MM-dd"),
                Value = stocks.Where(x => x.CreateDate.Date == date).Sum(x => x.Quantity)
                Value = stocks.Where(x => x.CreateDate.Date == date).Sum(x => x.Quantity),
            }).ToList();
            var outboundData = last7Days.Select(date => new
@@ -504,19 +525,23 @@
                metrics = new List<object>{
                new {
                    name = "今日进库量",
                    value = currentDayInStocks
                    value = currentDayInStocks,
                    compare =currentDayInStocks-currentDayInStocksLast,
                },
                new {
                    name = "今日出库量",
                    value = currentDayOutStocks
                    value = currentDayOutStocks,
                    compare =currentDayOutStocks-currentDayOutStocksLast,
                },
                new {
                    name = "本月进库量",
                    value = currentMonthInStocks
                    value = currentMonthInStocks,
                    compare =currentMonthInStocks-currentMonthInStocksLastMonth,
                },
                new {
                    name = "本月出库量",
                    value = currentMonthOutStocks
                    value = currentMonthOutStocks,
                    compare = currentMonthOutStocks - currentMonthOutStocksLastMonth,
                },
                new {
                    name = "库存总量",
@@ -558,6 +583,63 @@
            return content.Error("系统错误,请联系管理员");
        }
    }
    #endregion
    #region æ‰“印库存单个物料二维码
    public async Task<WebResponseContent> PrintOrder(object[] key)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            List<Dt_InboundOrder> inboundOrders = new List<Dt_InboundOrder>();
            foreach (var item in key)
            {
                var order = _inboundOrderRepository.QueryFirst(x => x.OrderNo == item.ToString());
                if (order != null)
                {
                    inboundOrders.Add(order);
                }
            }
            return _inboundOrderService.PrintInbound(inboundOrders); ;
        }
        catch (Exception ex)
        {
            return content.Error("未知错误,请联系管理员");
        }
    }
    /// <summary>
    /// ç‰¹æ®Šå‡ºåº“
    /// </summary>
    /// <param name="details"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    public WebResponseContent UpdateDataStockDetail(List<DtStockInfoDetail> details)
    {
        try
        {
            List<DtStockInfoDetail> dtStockInfoDetails = new List<DtStockInfoDetail>();
            foreach (var item in details)
            {
                DtStockInfoDetail dtStockInfoDetail = new DtStockInfoDetail();
                dtStockInfoDetail = _stockInfoDetailRepository.QueryFirst(it => it.Id == item.Id);
                dtStockInfoDetails.Add(dtStockInfoDetail);
            }
            LogFactory.GetLog("特殊任务").InfoFormat(true, "特殊任务前", JsonConvert.SerializeObject(dtStockInfoDetails));
            if (_stockInfoDetailRepository.UpdateData(details))
            {
               //记录日志
               LogFactory.GetLog("特殊任务").InfoFormat(true, "特殊任务后", JsonConvert.SerializeObject(details));
            }
        }
        catch(Exception ex)
        {
            return WebResponseContent.Instance.Error("出库失败");
        }
        return WebResponseContent.Instance.OK("出库成功");
    }
    #endregion
}