/// <summary> /// 升级过期 /// </summary> private void UpgradeOverdued(Prc_UpgradeMessage msg, DbContext access) { Repository <Prc_UpgradeMessage> repositoryMsg = new Repository <Prc_UpgradeMessage>(access); var delMsg = repositoryMsg.Get(a => a.UpgradeInfoItem.ID == msg.UpgradeInfoItem.ID && a.MessageFlag == ErrorMsgFlag.UpgradeOverdued); if (delMsg != null) { repositoryMsg.Delete(delMsg); } Repository <Prc_UpgradeInfoItem> repositoryItem = new Repository <Prc_UpgradeInfoItem>(access); Repository <Prc_UpgradeInfo> repositoryInfo = new Repository <Prc_UpgradeInfo>(access); var item = repositoryItem.GetDBSet().Include(o => o.UpgradeInfo).First(a => a.ID == msg.UpgradeInfoItem.ID); item.UpgradeStatus = EnumUpgradeStatus.Canceled; item.EndUpgradeTime = msg.OccurTime; if (item.BusinessType == EnumBusinessType.Center || item.UpgradeInfo.IsSingle) { //更新主项的状态 item.UpgradeInfo.UpgradeStatus = EnumUpgradeStatus.Overdued; item.UpgradeInfo.EndUpgradeTime = msg.OccurTime; repositoryInfo.Update(item.UpgradeInfo); } repositoryItem.Update(item); CheckFinish(msg, access); }
/// <summary> /// 是否已升级完成 /// </summary> private void CheckFinish(Prc_UpgradeMessage msg, DbContext access) { Repository <Prc_UpgradeInfoItem> repositoryItem = new Repository <Prc_UpgradeInfoItem>(access); Repository <Prc_UpgradeInfo> repositoryInfo = new Repository <Prc_UpgradeInfo>(access); access.SaveChanges(); var item = repositoryItem.GetDBSet().Include(o => o.UpgradeInfo).First(a => a.ID == msg.UpgradeInfoItem.ID); if (item.UpgradeInfo.UpgradeStatus == EnumUpgradeStatus.Upgrading || item.UpgradeInfo.UpgradeStatus == EnumUpgradeStatus.Reserved) { var unFinish = repositoryItem.Get(a => (a.UpgradeStatus == EnumUpgradeStatus.Reserved || a.UpgradeStatus == EnumUpgradeStatus.Upgrading) && a.UpgradeInfo.ID == item.UpgradeInfo.ID); if (unFinish == null) { var failBus = repositoryItem.Get(a => a.UpgradeStatus == EnumUpgradeStatus.UpgradeFail && a.UpgradeInfo.ID == item.UpgradeInfo.ID); if (failBus == null) { item.UpgradeInfo.UpgradeStatus = EnumUpgradeStatus.UpgradeSucc; } else { item.UpgradeInfo.UpgradeStatus = EnumUpgradeStatus.UpgradeFail; } item.UpgradeInfo.EndUpgradeTime = msg.OccurTime; repositoryInfo.Update(item.UpgradeInfo); } } }
public DTOBackMallMessage ReceiveMessage([FromBody] DTOMallMessage dto) { DTOBackMallMessage result = new DTOBackMallMessage(); result.FailMessages = new Dictionary <Guid, string>(); if (dto.Messages == null || dto.Messages.Count == 0) { return(result); } List <Prc_UpgradeMessage> mallMegs = new List <Prc_UpgradeMessage>(); dto.Messages.ForEach(a => { Prc_UpgradeMessage msg = new Prc_UpgradeMessage() { ID = a.ID, BusinessNum = a.BusinessNum, Content = a.Content, MessageType = (EnumMessageType)a.MessageType, MessageFlag = a.MessageFlag, OccurTime = a.OccurTime, CreateOperateUser = BLLUpgrade.SystemUser, LastUpdateTime = DateTime.Now, CreateTime = DateTime.Now, HandleStatus = EnumHandleStatus.UnHandle }; mallMegs.Add(msg); }); result.FailMessages = BllUpgrade.SaveMallMessage(mallMegs, dto.PfInfoId); return(result); }
/// <summary> /// 完成下载 /// </summary> private void FinishDownloadUpgradeBag(Prc_UpgradeMessage msg, DbContext access) { Repository <Prc_UpgradeInfoItem> repositoryItem = new Repository <Prc_UpgradeInfoItem>(access); var item = repositoryItem.Get(a => a.ID == msg.UpgradeInfoItem.ID); item.UpgradeBagStatus = EnumUpgradeBagStatus.Downloaded; repositoryItem.Update(item); }
/// <summary> /// 升级成功 /// </summary> private void UpgradeSucc(Prc_UpgradeMessage msg, DbContext access) { Repository <Prc_UpgradeInfoItem> repositoryItem = new Repository <Prc_UpgradeInfoItem>(access); var item = repositoryItem.Get(a => a.ID == msg.UpgradeInfoItem.ID); item.UpgradeStatus = EnumUpgradeStatus.UpgradeSucc; item.EndUpgradeTime = msg.OccurTime; repositoryItem.Update(item); CheckFinish(msg, access); }
private void DataSynTaskHandle(Prc_UpgradeMessage msg, DbContext access) { Repository <Prc_UpgradeMessage> repositoryMsg = new Repository <Prc_UpgradeMessage>(access); var delMsg = repositoryMsg.Get(a => a.UpgradeInfoItem.ID == msg.UpgradeInfoItem.ID && a.MessageFlag == InfoMsgFlag.DataSynTaskWait); if (delMsg != null) { repositoryMsg.Delete(delMsg); } }
/// <summary> /// 修改处理结果 /// </summary> public ReturnResponse EditHandleResult(DTOEditMessageResult dto) { Repository <Prc_UpgradeMessage> repository = new Repository <Prc_UpgradeMessage>(DbContext); Prc_UpgradeMessage item = repository.Get(a => a.ID == dto.ID); item.Result = dto.HandleResult; item.HandleStatus = EnumHandleStatus.Handled; repository.Update(item); DbContext.SaveChanges(); return(new ReturnResponse()); }
/// <summary> /// 开始升级 /// </summary> private void StartUpgrade(Prc_UpgradeMessage msg, DbContext access) { Repository <Prc_UpgradeInfoItem> repositoryItem = new Repository <Prc_UpgradeInfoItem>(access); var item = repositoryItem.Get(a => a.ID == msg.UpgradeInfoItem.ID); if (item.UpgradeStatus == EnumUpgradeStatus.Reserved) { item.StartUpgradeTime = msg.OccurTime; item.UpgradeStatus = EnumUpgradeStatus.Upgrading; repositoryItem.Update(item); } }
/// <summary> /// 取消升级 /// </summary> private void UpgradeCancel(Prc_UpgradeMessage msg, DbContext access) { Repository <Prc_UpgradeMessage> repositoryMsg = new Repository <Prc_UpgradeMessage>(access); var delMsg = repositoryMsg.Get(a => a.UpgradeInfoItem.ID == msg.UpgradeInfoItem.ID && a.MessageFlag == ErrorMsgFlag.UpgradeCancel); if (delMsg != null) { repositoryMsg.Delete(delMsg); } Repository <Prc_UpgradeInfoItem> repositoryItem = new Repository <Prc_UpgradeInfoItem>(access); var item = repositoryItem.Get(a => a.ID == msg.UpgradeInfoItem.ID); item.UpgradeStatus = EnumUpgradeStatus.Canceled; repositoryItem.Update(item); CheckFinish(msg, access); }
/// <summary> /// 升级失败 /// </summary> private void UpgradeFail(Prc_UpgradeMessage msg, DbContext access) { Repository <Prc_UpgradeInfoItem> repositoryItem = new Repository <Prc_UpgradeInfoItem>(access); Repository <Prc_UpgradeInfo> repositoryInfo = new Repository <Prc_UpgradeInfo>(access); var item = repositoryItem.GetDBSet().Include(o => o.UpgradeInfo).First(a => a.ID == msg.UpgradeInfoItem.ID); item.UpgradeStatus = EnumUpgradeStatus.UpgradeFail; item.EndUpgradeTime = msg.OccurTime; if (item.BusinessType == EnumBusinessType.Center || item.UpgradeInfo.IsSingle) { //更新主项的状态 item.UpgradeInfo.UpgradeStatus = EnumUpgradeStatus.UpgradeFail; item.UpgradeInfo.EndUpgradeTime = msg.OccurTime; repositoryInfo.Update(item.UpgradeInfo); } repositoryItem.Update(item); CheckFinish(msg, DbContext); }
/// <summary> /// 消息处理 /// </summary> private void MessageHandle(Prc_UpgradeMessage msg, DbContext access) { switch (msg.MessageFlag) { case InfoMsgFlag.StartDownloadUpgradeBag: StartDownloadUpgradeBag(msg, access); break; case InfoMsgFlag.FinishDownloadUpgradeBag: FinishDownloadUpgradeBag(msg, access); break; case ErrorMsgFlag.UpgradeCancel: UpgradeCancel(msg, access); break; case ErrorMsgFlag.UpgradeFail: UpgradeFail(msg, access); break; case ErrorMsgFlag.UpgradeOverdued: UpgradeOverdued(msg, access); break; case InfoMsgFlag.StartUpgrade: StartUpgrade(msg, access); break; case InfoMsgFlag.UpgradeSucc: UpgradeSucc(msg, access); break; case InfoMsgFlag.DataSynTaskWait: case InfoMsgFlag.DataSynTaskFinish: DataSynTaskHandle(msg, access); break; } }
public Dictionary <Guid, string> SaveMallMessage(List <Prc_UpgradeMessage> mallMsgs, Guid infoId) { Dictionary <Guid, string> failMsg = new Dictionary <Guid, string>(); try { Repository <Prc_UpgradeMessage> repositoryMsg = new Repository <Prc_UpgradeMessage>(DbContext); Repository <Prc_UpgradeInfoItem> repositoryItem = new Repository <Prc_UpgradeInfoItem>(DbContext); Repository <Prc_UpgradeInfo> repositoryInfo = new Repository <Prc_UpgradeInfo>(DbContext); Prc_UpgradeInfo info = repositoryInfo.Get(a => a.ID == infoId && !a.IsDelete); if (info == null) { throw new Exception("未找到升级信息"); } List <string> busNum = new List <string>(); mallMsgs.ForEach(a => { busNum.Add(a.BusinessNum); }); List <Prc_UpgradeInfoItem> items = repositoryItem.Search(a => a.UpgradeInfo.ID == info.ID && busNum.Contains(a.BusinessNum) && !a.IsDelete); mallMsgs.ForEach(a => { try { if (repositoryMsg.Get(b => b.ID == a.ID) == null) { var item = items.Find(b => b.BusinessNum == a.BusinessNum); if (item == null) { throw new Exception(string.Format("未找到门店{0}的升级信息", a.BusinessNum)); } Prc_UpgradeMessage msg = new Prc_UpgradeMessage() { ID = a.ID, UpgradeInfoItem = item, Content = a.Content, MessageType = (EnumMessageType)a.MessageType, MessageFlag = a.MessageFlag, OccurTime = a.OccurTime, CreateOperateUser = "******", LastUpdateTime = DateTime.Now, CreateTime = DateTime.Now, HandleStatus = EnumHandleStatus.UnHandle }; MessageHandle(msg, DbContext); repositoryMsg.Add(msg); } } catch (Exception ex) { failMsg.Add(a.ID, ex.Message); } }); DbContext.SaveChanges(); } catch (Exception ex) { mallMsgs.ForEach(a => { if (!failMsg.ContainsKey(a.ID)) { failMsg.Add(a.ID, ex.Message); } }); } return(failMsg); }