| | |
| | | var targetEPD = db.Queryable<TN_EquipProDetail>().LeftJoin<TN_CG_Detail>((o, i) => o.S_ID == i.S_ID). |
| | | Where((o, i) => o.ITEMSTATE != i.S_ITEM_STATE && i.S_ITEM_STATE != "待检" && i.N_ITEM_STATE != 1).First(); |
| | | |
| | | if (targetEPD != null) |
| | | if (targetEPD != null)//同步货品状态 |
| | | { |
| | | targetEPD.ITEMSTATE = db.Queryable<TN_CG_Detail>().First(a => a.S_ID == targetEPD.S_ID).S_ITEM_STATE; |
| | | db.Updateable<TN_EquipProDetail>(targetEPD).UpdateColumns(it => new { it.ITEMSTATE }).ExecuteCommand(); |
| | |
| | | targetEPD = db.Queryable<TN_EquipProDetail>().LeftJoin<TN_CG_Detail>((o, i) => o.S_ID == i.S_ID). |
| | | Where((o, i) => System.DateTime.Now >= o.EXPIRATION && i.S_ITEM_STATE == "待检" && i.N_ITEM_STATE == 1).First(); |
| | | |
| | | if (targetEPD != null) |
| | | if (targetEPD != null)//检测出过期的货品 |
| | | { |
| | | targetEPD.ITEMSTATE = "过期"; |
| | | db.Updateable<TN_EquipProDetail>(targetEPD).UpdateColumns(it => new { it.ITEMSTATE }).ExecuteCommand(); |
| | |
| | | var targetInM = db.Queryable<TN_InventoryM>().LeftJoin<TN_CG_Detail>((o, i) => o.S_ID == i.S_ID). |
| | | Where((o, i) => o.ITEMSTATE != i.S_ITEM_STATE && i.S_ITEM_STATE != "待检" && i.N_ITEM_STATE != 1).First(); |
| | | |
| | | if (targetInM != null) |
| | | if (targetInM != null)//同步货品状态 |
| | | { |
| | | targetInM.ITEMSTATE = db.Queryable<TN_CG_Detail>().First(a => a.S_ID == targetInM.S_ID).S_ITEM_STATE; |
| | | db.Updateable<TN_InventoryM>(targetInM).UpdateColumns(it => new { it.ITEMSTATE }).ExecuteCommand(); |
| | |
| | | targetInM = db.Queryable<TN_InventoryM>().LeftJoin<TN_CG_Detail>((o, i) => o.S_ID == i.S_ID). |
| | | Where((o, i) => System.DateTime.Now >= o.EXPIRATION && i.S_ITEM_STATE == "待检" && i.N_ITEM_STATE == 1).First(); |
| | | |
| | | if (targetInM != null) |
| | | if (targetInM != null)//检测出已过期的货品 |
| | | { |
| | | targetInM.ITEMSTATE = "过期"; |
| | | targetInM.EXPIRATION_DAY = 0; |
| | | db.Updateable<TN_InventoryM>(targetInM).UpdateColumns(it => new { it.ITEMSTATE }).ExecuteCommand(); |
| | | |
| | | var cginfo = db.Queryable<TN_CG_Detail>().First(a => a.S_ID == targetInM.S_ID); |
| | |
| | | cginfo.N_ITEM_STATE = 3; |
| | | db.Updateable<TN_CG_Detail>(cginfo).UpdateColumns(it => new { it.S_ITEM_STATE, it.N_ITEM_STATE }).ExecuteCommand(); |
| | | } |
| | | |
| | | |
| | | targetInM = db.Queryable<TN_InventoryM>().LeftJoin<TN_CG_Detail>((o, i) => o.S_ID == i.S_ID). |
| | | Where((o, i) => System.DateTime.Now < o.EXPIRATION && i.S_ITEM_STATE == "待检" && i.N_ITEM_STATE == 1).First(); |
| | | |
| | | if (targetInM != null)//检测出快过期的货品 |
| | | { |
| | | targetInM.EXPIRATION_DAY = SpecHelper.CalculateDaysDifference(System.DateTime.Now,targetInM.EXPIRATION); |
| | | db.Updateable<TN_InventoryM>(targetInM).UpdateColumns(it => new { it.EXPIRATION_DAY }).ExecuteCommand(); |
| | | } |
| | | |
| | | |
| | | // 同步 TN_DayProDetail |
| | | var curDay = System.DateTime.Now.Date; |
| | | var targetDay = db.Queryable<TN_DayProDetail>().First(a => a.DAYTIME == curDay); |
| | | if (targetDay == null) |
| | | { |
| | | targetDay = new TN_DayProDetail() |
| | | { |
| | | DAYTIME = curDay, |
| | | }; |
| | | db.Insertable(targetDay).ExecuteCommand(); |
| | | } |
| | | |
| | | var targetEPDs = db.Queryable<TN_EquipProDetail>().Where(a => a.DOWNLINETIME >= curDay && a.DOWNLINETIME <= curDay.AddDays(1)).ToList(); |
| | | |
| | | var sumWeight = targetEPDs.Sum(a => a.WEIGHT); |
| | | var specList = targetEPDs.Select(a => a.SPEC).Distinct().ToList();//当天的货品有哪些规格 |
| | | |
| | | if (targetEPDs.Count > 0) |
| | | if (specList.Count>0) |
| | | { |
| | | if (targetDay.WEIGHT != sumWeight) |
| | | foreach (var item in specList) |
| | | { |
| | | targetDay.WEIGHT = sumWeight; |
| | | db.Updateable(targetDay).ExecuteCommand(); |
| | | } |
| | | var targetDay = db.Queryable<TN_DayProDetail>().First(a => a.DAYTIME == curDay && a.SPEC == item); |
| | | if (targetDay == null) |
| | | { |
| | | targetDay = new TN_DayProDetail() |
| | | { |
| | | DAYTIME = curDay, |
| | | SPEC = item, |
| | | }; |
| | | db.Insertable(targetDay).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | var sumWeight = targetEPDs.Where(b=>b.SPEC == item).Sum(a => a.WEIGHT); |
| | | |
| | | if (targetDay.WEIGHT != sumWeight) |
| | | { |
| | | targetDay.WEIGHT = sumWeight; |
| | | db.Updateable(targetDay).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("重量相等,同步TN_DayProDetail跳过"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("当天的货品规格列表为0,同步TN_DayProDetail跳过"); |
| | | } |
| | | |
| | | // 同步 TN_WeekProSpcDetail |
| | | var curWeek = System.DateTime.Now.Date.AddDays(-(int)System.DateTime.Now.DayOfWeek + 1); |
| | | var targetWeek = db.Queryable<TN_WeekProDetail>().First(a => a.DAYTIME == curWeek); |
| | | if (targetWeek == null) |
| | | { |
| | | targetWeek = new TN_WeekProDetail() |
| | | { |
| | | DAYTIME = curWeek, |
| | | }; |
| | | db.Insertable(targetWeek).ExecuteCommand(); |
| | | } |
| | | |
| | | targetEPDs = db.Queryable<TN_EquipProDetail>().Where(a => a.DOWNLINETIME >= curWeek && a.DOWNLINETIME <= curWeek.AddDays(7)).ToList(); |
| | | if (targetEPDs.Count > 0) |
| | | specList = targetEPDs.Select(a => a.SPEC).Distinct().ToList();//当周的货品有哪些规格 |
| | | if (specList.Count > 0) |
| | | { |
| | | if (targetWeek.WEIGHT != sumWeight) |
| | | foreach (var item in specList) |
| | | { |
| | | targetWeek.WEIGHT = sumWeight; |
| | | db.Updateable(targetWeek).ExecuteCommand(); |
| | | var targetWeek = db.Queryable<TN_WeekProDetail>().First(a => a.DAYTIME == curWeek && a.SPEC == item); |
| | | if (targetWeek == null) |
| | | { |
| | | targetWeek = new TN_WeekProDetail() |
| | | { |
| | | DAYTIME = curWeek, |
| | | SPEC = item, |
| | | }; |
| | | db.Insertable(targetWeek).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | var sumWeight = targetEPDs.Where(b => b.SPEC == item).Sum(a => a.WEIGHT); |
| | | if (targetWeek.WEIGHT != sumWeight) |
| | | { |
| | | targetWeek.WEIGHT = sumWeight; |
| | | db.Updateable(targetWeek).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("重量相等,同步TN_WeekProSpcDetail跳过"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("当周的货品规格列表为0,同步TN_WeekProSpcDetail跳过"); |
| | | } |
| | | |
| | | // 同步 TN_MonthProSpcDetail |
| | | var curMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).Date; |
| | | var targetMonth = db.Queryable<TN_MonthProDetail>().First(a => a.DAYTIME == curMonth); |
| | | if (targetMonth == null) |
| | | { |
| | | targetMonth = new TN_MonthProDetail() |
| | | { |
| | | DAYTIME = curMonth, |
| | | }; |
| | | db.Insertable(targetMonth).ExecuteCommand(); |
| | | } |
| | | targetEPDs = db.Queryable<TN_EquipProDetail>().Where(a => a.DOWNLINETIME >= curMonth && a.DOWNLINETIME <= curMonth.AddMonths(1)).ToList(); |
| | | if (targetEPDs.Count > 0) |
| | | specList = targetEPDs.Select(a => a.SPEC).Distinct().ToList();//当月的货品有哪些规格 |
| | | if (specList.Count > 0) |
| | | { |
| | | if (targetMonth.WEIGHT != sumWeight) |
| | | foreach (var item in specList) |
| | | { |
| | | targetMonth.WEIGHT = sumWeight; |
| | | db.Updateable(targetMonth).ExecuteCommand(); |
| | | var targetMonth = db.Queryable<TN_MonthProDetail>().First(a => a.DAYTIME == curMonth && a.SPEC == item); |
| | | if (targetMonth == null) |
| | | { |
| | | targetMonth = new TN_MonthProDetail() |
| | | { |
| | | DAYTIME = curMonth, |
| | | SPEC = item, |
| | | }; |
| | | db.Insertable(targetMonth).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | var sumWeight = targetEPDs.Where(b => b.SPEC == item).Sum(a => a.WEIGHT); |
| | | if (targetMonth.WEIGHT != sumWeight) |
| | | { |
| | | targetMonth.WEIGHT = sumWeight; |
| | | db.Updateable(targetMonth).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("重量相等,同步TN_MonthProSpcDetail跳过"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("当月的货品规格列表为0,同步TN_MonthProSpcDetail跳过"); |
| | | } |
| | | |
| | | // 同步 TN_YearProSpcDetail |
| | | var curYear = new DateTime(DateTime.Now.Year, 1, 1).Date; |
| | | var targetYear = db.Queryable<TN_YearProDetail>().First(a => a.DAYTIME == curYear); |
| | | if (targetYear == null) |
| | | { |
| | | targetYear = new TN_YearProDetail() |
| | | { |
| | | DAYTIME = curYear, |
| | | }; |
| | | db.Insertable(targetYear).ExecuteCommand(); |
| | | } |
| | | |
| | | targetEPDs = db.Queryable<TN_EquipProDetail>().Where(a => a.DOWNLINETIME >= curYear && a.DOWNLINETIME <= curYear.AddYears(1)).ToList(); |
| | | if (targetEPDs.Count > 0) |
| | | specList = targetEPDs.Select(a => a.SPEC).Distinct().ToList();//当年的货品有哪些规格 |
| | | if (specList.Count > 0) |
| | | { |
| | | if (targetYear.WEIGHT != sumWeight) |
| | | foreach (var item in specList) |
| | | { |
| | | targetYear.WEIGHT = sumWeight; |
| | | db.Updateable(targetYear).ExecuteCommand(); |
| | | var targetYear = db.Queryable<TN_YearProDetail>().First(a => a.DAYTIME == curYear && a.SPEC == item); |
| | | if (targetYear == null) |
| | | { |
| | | targetYear = new TN_YearProDetail() |
| | | { |
| | | DAYTIME = curYear, |
| | | SPEC = item, |
| | | }; |
| | | db.Insertable(targetYear).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | var sumWeight = targetEPDs.Where(b => b.SPEC == item).Sum(a => a.WEIGHT); |
| | | if (targetYear.WEIGHT != sumWeight) |
| | | { |
| | | targetYear.WEIGHT = sumWeight; |
| | | db.Updateable(targetYear).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("重量相等,同步TN_YearProSpcDetail跳过"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("当年的货品规格列表为0,同步TN_YearProSpcDetail跳过"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |