public void TestGetStockWarningList() { List <Guid> realGoodsIds1 = null; var result = _stockWarning.GetStockWarningList(new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05"), Guid.Empty, Guid.Empty, 10, new GoodsInfo { GoodsId = new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2") }, ref realGoodsIds1); Assert.IsTrue(result.Count == 0); _stubIStockCenterSao.GetChildGoodsQuantityGuid = guid => new List <GoodsStockQuantityInfo> { new GoodsStockQuantityInfo { CurrentQuantity = 10, RealGoodsId = new Guid("9625D606-235F-409A-A9C8-6F4FAFF5E193"), GoodsId = new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2"), WarehouseId = new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05") }, new GoodsStockQuantityInfo { CurrentQuantity = 10, RealGoodsId = new Guid("9B19D606-235F-409A-A9C8-6F4FAFF5E193"), GoodsId = new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2"), WarehouseId = new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05") } }; _stubIStockWarning.GetStockWarningListGuidListOfGuidInt32 = (guid, list, arg3) => new List <StockWarningInfo> { new StockWarningInfo { GoodsId = new Guid("9625D606-235F-409A-A9C8-6F4FAFF5E193") }, new StockWarningInfo { GoodsId = new Guid("22785481-1F31-4F3F-9ED6-995C87FD5A52") } }; List <Guid> realGoodsIds = null; _stubIGoodsInfoSao.GetRealGoodsListByGoodsIdListOfGuid = list => new List <ChildGoodsInfo> { new ChildGoodsInfo { RealGoodsId = new Guid("9625D606-235F-409A-A9C8-6F4FAFF5E193") }, new ChildGoodsInfo { RealGoodsId = new Guid("9625D606-245D-409A-A9C8-6F4FAFF5E193") } }; _stockWarning = new StockWarning(_stubIStockWarning, _stubIGoodsInfoSao); var result1 = _stockWarning.GetStockWarningList(new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05"), Guid.Empty, new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2"), 10, new GoodsInfo { GoodsId = new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2") }, ref realGoodsIds); Assert.IsTrue(result1.Count > 0); }
static void Main(string[] args) { HomeCinemaContext context = new HomeCinemaContext(); //var movies = _moviesRepository.GetAll().ToList(); StockWarning s = new StockWarning(context); s.outOfStock(); //googleSmtpClient.Host = "smtp.gmail.com"; //Or Your SMTP Server Address //googleSmtpClient.Credentials = new System.Net.NetworkCredential // ("*****@*****.**", "stockwarning"); // ***use valid credentials*** //googleSmtpClient.Port = 587; ////Or your Smtp Email ID and Password //googleSmtpClient.EnableSsl = true; }
public void Init() { _stubIStockWarning.GetGoodsDaySalesInfosListOfGuidGuidInt32Int32 = (list, guid, arg3, arg4) => new List <GoodsDaySalesInfo> { new GoodsDaySalesInfo { RealGoodsID = new Guid("9625D606-235F-409A-A9C8-6F4FAFF5E193"), GoodsSales = 60 }, new GoodsDaySalesInfo { RealGoodsID = new Guid("22785481-1F31-4F3F-9ED6-995C87FD5A52"), GoodsSales = 60 } }; //22785481-1F31-4F3F-9ED6-995C87FD5A52 if (_stockWarning == null) { _stubIStockCenterSao.GetChildGoodsQuantityGuid = guid => new List <GoodsStockQuantityInfo>(); _stockWarning = new StockWarning(_stubIStockWarning, _stubIGoodsInfoSao); } }
public void WorkProcess() { try { var spBll = new StockProduct(); var swBll = new StockWarning(); var pBll = new Product(); while (true) { TimeSpan tsTimeout = TimeSpan.FromSeconds(Convert.ToDouble(ConfigurationManager.AppSettings["StockWarningTimer"])); var pageIndex = 1; var pageSize = 10000; var currTime = DateTime.Now; while (true) { var spList = spBll.GetList(pageIndex, pageSize, "", null); if (spList == null || spList.Count == 0) { pageIndex = 1; break; } var swList = swBll.GetList(); if (swList == null || swList.Count == 0) { break; } foreach (var item in spList) { List <string> oldWarnMsgList = null; if (!string.IsNullOrWhiteSpace(item.WarnMsg)) { oldWarnMsgList = item.WarnMsg.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); } List <string> warnMsgList = new List <string>(); #region 库存报警条件 var pInfo = pBll.GetModel(item.ProductId); if (pInfo.MaxStore > 0 && (item.Qty >= pInfo.MaxStore)) { if (!warnMsgList.Contains("最大库存量预警")) { warnMsgList.Add("最大库存量预警"); } } if (pInfo.MinStore > 0 && (item.Qty <= pInfo.MinStore)) { if (!warnMsgList.Contains("最小库存量预警")) { warnMsgList.Add("最小库存量预警"); } } if (!string.IsNullOrWhiteSpace(item.StockLocations)) { var pslaList = JsonConvert.DeserializeObject <List <ProductStockLocationAttrInfo> >(item.StockLocations); if (pslaList != null && pslaList.Count > 0) { foreach (var pslaInfo in pslaList) { var swInfo = swList.FirstOrDefault(m => m.StockLocationId.Equals(pslaInfo.StockLocationId)); if (swInfo == null) { continue; } if ((swInfo.MaxQty > 0) && (pslaInfo.Qty >= swInfo.MaxQty)) { if (!warnMsgList.Contains("最大库存量预警")) { warnMsgList.Add("最大库存量预警"); } } if ((swInfo.MinQty > 0) && (pslaInfo.Qty <= swInfo.MinQty)) { if (!warnMsgList.Contains("最小库存量预警")) { warnMsgList.Add("最小库存量预警"); } } if (swInfo.OverdueDay > 0) { if ((currTime - pslaInfo.LastUpdatedDate).TotalDays >= swInfo.OverdueDay) { if (!warnMsgList.Contains("超期预警")) { warnMsgList.Add("超期预警"); } } } } } } #endregion if (warnMsgList.Count > 0) { item.WarnMsg = string.Join(",", warnMsgList); } else { item.WarnMsg = ""; } #region 数据库操作 if (oldWarnMsgList == null && warnMsgList.Count > 0) { spBll.UpdateWarnMsg(item.ProductId, item.CustomerId, item.WarnMsg); } else if (oldWarnMsgList != null && oldWarnMsgList.Count > 0) { foreach (var s in oldWarnMsgList) { if (warnMsgList.Contains(s)) { warnMsgList.Remove(s); } } if (warnMsgList.Count > 0) { spBll.UpdateWarnMsg(item.ProductId, item.CustomerId, item.WarnMsg); } else { foreach (var s in warnMsgList) { if (oldWarnMsgList.Contains(s)) { oldWarnMsgList.Remove(s); } } if (oldWarnMsgList.Count > 0) { spBll.UpdateWarnMsg(item.ProductId, item.CustomerId, item.WarnMsg); } } } #endregion } pageIndex++; } Thread.Sleep(tsTimeout); } } catch (Exception ex) { new CustomException(string.Format("来自{0}异常:{1}", "StockWarningTimer", ex.Message), ex); } }
public void TestStockWarning() { _stubIStockCenterSao.GetChildGoodsQuantityGuid = guid => new List <GoodsStockQuantityInfo>(); _stockWarning = new StockWarning(_stubIStockWarning, _stubIGoodsInfoSao); }
public void TestGetStockWarningListNew() { var result2 = _stockWarning.GetStockWarningListNew(new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05"), Guid.Empty, Guid.Empty, 10, null); Assert.IsTrue(result2.Count == 0); _stubIStockCenterSao.GetChildGoodsQuantityGuid = guid => new List <GoodsStockQuantityInfo> { new GoodsStockQuantityInfo { CurrentQuantity = 10, RealGoodsId = new Guid("9625D606-235F-409A-A9C8-6F4FAFF5E193"), GoodsId = new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2"), WarehouseId = new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05") }, new GoodsStockQuantityInfo { CurrentQuantity = 10, RealGoodsId = new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2"), GoodsId = new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2"), WarehouseId = new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05") }, }; _stubIStockWarning.GetStockWarningListGuidListOfGuidInt32 = (guid, list, arg3) => new List <StockWarningInfo> { new StockWarningInfo { GoodsId = new Guid("9625D606-235F-409A-A9C8-6F4FAFF5E193") }, new StockWarningInfo { GoodsId = new Guid("22785481-1F31-4F3F-9ED6-995C87FD5A52") } }; _stubIGoodsInfoSao.GetRealGoodsListByGoodsIdListOfGuid = list => new List <ChildGoodsInfo> { new ChildGoodsInfo { RealGoodsId = new Guid("9625D606-235F-409A-A9C8-6F4FAFF5E193") }, new ChildGoodsInfo { RealGoodsId = new Guid("9625D606-245D-409A-A9C8-6F4FAFF5E193") } }; _stockWarning = new StockWarning(_stubIStockWarning, _stubIGoodsInfoSao); var result4 = _stockWarning.GetStockWarningListNew(new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05"), Guid.Empty, new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2"), 10, new GoodsInfo { GoodsId = new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2"), GoodsCode = "112", GoodsName = "自动报备01", IsOnShelf = true }); Assert.IsTrue(result4.Count > 0); //_stubIStockWarning.GetStockWarningListGuidListOfGuidInt32 = (guid, list, arg3) => new List<StockWarningInfo> //{ // new StockWarningInfo // { // GoodsId = new Guid("CA757573-B418-45AA-91DF-0005788D289C") // } //}; //var result1 = _stockWarning.GetStockWarningListNew(new Guid("B5BCDF6E-95D5-4AEE-9B19-6EE218255C05"), new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2"), 10, // new GoodsInfo // { // GoodsId = new Guid("6B9015C5-E2F2-4246-BA21-000229C38EF2"), // GoodsCode = "112", // GoodsName = "自动报备01", // IsOnShelf = true // }); //Assert.IsTrue(result1.Count > 0); }