public void GenerateFacilityMaintainPlan() { #region 取所有到时间的预防计划的设施 DetachedCriteria criteria = DetachedCriteria.For(typeof(FacilityMaintainPlan)); criteria.Add (Expression.And(Expression.IsNotNull("NextWarnDate"), Expression.Le("NextWarnDate", DateTime.Now))); IList<FacilityMaintainPlan> facilityMaintainPlanList = genericMgr.FindAll<FacilityMaintainPlan>(criteria); #endregion #region 生成ISI任务 if (facilityMaintainPlanList != null && facilityMaintainPlanList.Count > 0) { foreach (FacilityMaintainPlan facilityPlan in facilityMaintainPlanList) { #region 生成ISI任务 MaintainPlan maintainPlan = genericMgr.FindById<MaintainPlan>(facilityPlan.MaintainPlan.Code); FacilityOrderMaster facilityOrderMaster = new FacilityOrderMaster(); facilityOrderMaster.FacilityOrderNo = "FO" + DateTime.Now.ToString("yyyyMMddHHmmss"); facilityOrderMaster.Status = CodeMaster.FacilityOrderStatus.Submit; facilityOrderMaster.Type = CodeMaster.FacilityOrderType.Maintain; facilityOrderMaster.ReferenceNo = maintainPlan.Description; facilityOrderMaster.Region = string.Empty; genericMgr.Create(facilityOrderMaster); IList<MaintainPlanItem> maintainPlanItemList = genericMgr.FindAll<MaintainPlanItem>("from MaintainPlanItem m where m.MaintainPlanCode = ?", new object[] { facilityPlan.MaintainPlan.Code }); foreach (MaintainPlanItem maintainPlanItem in maintainPlanItemList) { FacilityOrderDetail facilityOrderDetail = new FacilityOrderDetail(); facilityOrderDetail.FacilityOrderNo = facilityOrderMaster.FacilityOrderNo; facilityOrderDetail.BaseUom = maintainPlanItem.BaseUom; facilityOrderDetail.FacilityId = facilityPlan.FCID; facilityOrderDetail.Item = maintainPlanItem.Item; facilityOrderDetail.ItemDescription = maintainPlanItem.ItemDescription; facilityOrderDetail.PlanQty = maintainPlanItem.Qty; facilityOrderDetail.Sequence = maintainPlanItem.Sequence; facilityOrderDetail.Uom = maintainPlanItem.Uom; genericMgr.Create(facilityOrderDetail); facilityOrderMaster.AddFacilityOrderDetail(facilityOrderDetail); } #endregion #region 更新下次时间、数量 if (facilityPlan.MaintainPlan.Type == CodeMaster.MaintainPlanType.Once) { facilityPlan.NextMaintainDate = null; facilityPlan.NextWarnDate = null; } else { #region 现在周期都维护 if (facilityPlan.MaintainPlan.Type == CodeMaster.MaintainPlanType.Minute) { facilityPlan.NextMaintainDate = facilityPlan.NextMaintainDate.Value.AddMinutes(facilityPlan.MaintainPlan.TypePeriod); facilityPlan.NextWarnDate = facilityPlan.NextWarnDate.Value.AddMinutes(facilityPlan.MaintainPlan.TypePeriod); } else if (facilityPlan.MaintainPlan.Type == CodeMaster.MaintainPlanType.Hour) { facilityPlan.NextMaintainDate = facilityPlan.NextMaintainDate.Value.AddHours(facilityPlan.MaintainPlan.TypePeriod); facilityPlan.NextWarnDate = facilityPlan.NextWarnDate.Value.AddHours(facilityPlan.MaintainPlan.TypePeriod); } else if (facilityPlan.MaintainPlan.Type == CodeMaster.MaintainPlanType.Day) { facilityPlan.NextMaintainDate = facilityPlan.NextMaintainDate.Value.AddDays(facilityPlan.MaintainPlan.TypePeriod); facilityPlan.NextWarnDate = facilityPlan.NextWarnDate.Value.AddDays(facilityPlan.MaintainPlan.TypePeriod); } else if (facilityPlan.MaintainPlan.Type == CodeMaster.MaintainPlanType.Week) { facilityPlan.NextMaintainDate = facilityPlan.NextMaintainDate.Value.AddDays(7 * facilityPlan.MaintainPlan.TypePeriod); facilityPlan.NextWarnDate = facilityPlan.NextWarnDate.Value.AddDays(7 * facilityPlan.MaintainPlan.TypePeriod); } else if (facilityPlan.MaintainPlan.Type == CodeMaster.MaintainPlanType.Month) { facilityPlan.NextMaintainDate = facilityPlan.NextMaintainDate.Value.AddMonths(facilityPlan.MaintainPlan.TypePeriod); facilityPlan.NextWarnDate = facilityPlan.NextWarnDate.Value.AddMonths(facilityPlan.MaintainPlan.TypePeriod); } else if (facilityPlan.MaintainPlan.Type == CodeMaster.MaintainPlanType.Year) { facilityPlan.NextMaintainDate = facilityPlan.NextMaintainDate.Value.AddYears(facilityPlan.MaintainPlan.TypePeriod); facilityPlan.NextWarnDate = facilityPlan.NextWarnDate.Value.AddYears(facilityPlan.MaintainPlan.TypePeriod); } #endregion } genericMgr.Update(facilityPlan); #endregion } } #endregion }
public void FinishFacilityOrder(FacilityOrderMaster facilityOrderMaster) { List<string> facilityList = new List<string>(); foreach (FacilityOrderDetail d in facilityOrderMaster.FacilityOrderDetails) { genericMgr.Update(d); if (!facilityList.Contains(d.FacilityId)) { facilityList.Add(d.FacilityId); #region 记设备事务 FacilityMaster facilityMaster = genericMgr.FindById<FacilityMaster>(d.FacilityId); FacilityTrans facilityTrans = new FacilityTrans(); facilityTrans.CreateDate = DateTime.Now; facilityTrans.CreateUserId = facilityMaster.CreateUserId; facilityTrans.CreateUserName = facilityMaster.CreateUserName; facilityTrans.EffDate = DateTime.Now.Date; facilityTrans.FCID = facilityMaster.FCID; facilityTrans.FromChargePersonId = facilityMaster.CurrChargePersonId; facilityTrans.FromChargePersonName = facilityMaster.CurrChargePersonName; facilityTrans.FromOrganization = facilityMaster.ChargeOrganization; facilityTrans.FromChargeSite = facilityMaster.ChargeSite; facilityTrans.ToChargePersonId = facilityMaster.CurrChargePersonId; facilityTrans.ToChargePersonName = facilityMaster.CurrChargePersonName; facilityTrans.ToOrganization = facilityMaster.ChargeOrganization; facilityTrans.ToChargeSite = facilityMaster.ChargeSite; facilityTrans.TransType = CodeMaster.FacilityTransType.FinishMaintain; facilityTrans.Remark = d.Note; facilityTrans.AssetNo = facilityMaster.AssetNo; facilityTrans.FacilityName = facilityMaster.Name; facilityTrans.FacilityCategory = facilityMaster.Category; genericMgr.Create(facilityTrans); #endregion } } facilityOrderMaster.Status = CodeMaster.FacilityOrderStatus.Close; genericMgr.Update(facilityOrderMaster); }
public void CreateFacilityOrder(string facilityName) { string useCounterStr = facilityName + "/UseCounter"; XmlElement useCounterXml = ObixHelper.Request_WebRequest(useCounterStr); XmlNodeList userCounterNodeList = useCounterXml.ChildNodes; decimal accQty = Decimal.Parse(userCounterNodeList[2].Attributes["val"].Value); IList<FacilityMaintainPlan> facilityMaintainPlanList = genericMgr.FindAll<FacilityMaintainPlan>("from FacilityMaintainPlan f where f.FCID = ? and f.NextMaintainQty > 0", new object[] { facilityName }); if (facilityMaintainPlanList != null && facilityMaintainPlanList.Count > 0) { FacilityMaintainPlan facilityMaintainPlan = facilityMaintainPlanList[0]; if (accQty >= facilityMaintainPlan.NextMaintainQty) { MaintainPlan maintainPlan = genericMgr.FindById<MaintainPlan>(facilityMaintainPlan.MaintainPlan.Code); FacilityOrderMaster facilityOrderMaster = new FacilityOrderMaster(); facilityOrderMaster.FacilityOrderNo = "FO" + DateTime.Now.ToString("yyyyMMddHHmmss"); facilityOrderMaster.Status = CodeMaster.FacilityOrderStatus.Submit; facilityOrderMaster.Type = CodeMaster.FacilityOrderType.Maintain; facilityOrderMaster.ReferenceNo = maintainPlan.Description; facilityOrderMaster.Region = string.Empty; genericMgr.Create(facilityOrderMaster); IList<MaintainPlanItem> maintainPlanItemList = genericMgr.FindAll<MaintainPlanItem>("from MaintainPlanItem m where m.MaintainPlanCode = ?", new object[] { facilityMaintainPlan.MaintainPlan.Code }); foreach (MaintainPlanItem maintainPlanItem in maintainPlanItemList) { FacilityOrderDetail facilityOrderDetail = new FacilityOrderDetail(); facilityOrderDetail.FacilityOrderNo = facilityOrderMaster.FacilityOrderNo; facilityOrderDetail.BaseUom = maintainPlanItem.BaseUom; facilityOrderDetail.FacilityId = facilityMaintainPlan.FCID; facilityOrderDetail.Item = maintainPlanItem.Item; facilityOrderDetail.ItemDescription = maintainPlanItem.ItemDescription; facilityOrderDetail.PlanQty = maintainPlanItem.Qty; facilityOrderDetail.Sequence = maintainPlanItem.Sequence; facilityOrderDetail.Uom = maintainPlanItem.Uom; genericMgr.Create(facilityOrderDetail); facilityOrderMaster.AddFacilityOrderDetail(facilityOrderDetail); } #region 更新下次保养数量 facilityMaintainPlan.NextMaintainQty += maintainPlan.TypePeriod; genericMgr.Update(facilityMaintainPlan); #endregion } } }