public void AddMeterRecord(MeterRecord record) { if (record != null) { MeterRecords.Insert(0, record); } }
/// <summary> /// 任务回调 /// </summary> /// <param name="deviceId"></param> /// <param name="record"></param> public void SetConfirmationTask(string deviceId, MeterRecord record = null, bool flag = true) { var taskType = record == null ? null : record.TaskType; var fistTask = GetFistTask(deviceId, taskType); if (fistTask == null) { return; } if (flag) { fistTask.F_State = (int)TaskStateEnum.Finish; } else { fistTask.F_State = (int)TaskStateEnum.Error; } fistTask.F_ExecuteTime = DateTime.Now; fistTask.F_Value = record == null ? null : record.Value; switch (fistTask.F_TaskType) { case (int)TaskTypeEnum.Pay: { var payOrder = _payOrderApp.FindEntity(deviceId); if (payOrder != null) { payOrder.F_State = ((int)PayStateEnum.Finish).ToString(); _service.SubmitRechargeMoney(fistTask, payOrder); } } break; case (int)TaskTypeEnum.SetBaseDosage: { var changeMeter = new ChangeMeterApp().GetForm(fistTask.F_WorkId); if (fistTask.F_WorkId != "xxxxxxxx-xxxx-xxxx-xxxx-000000000005" && changeMeter != null) { _service.SubmitChangeMeter(fistTask, changeMeter); } else { _service.Update(fistTask); } } break; default: { _service.Update(fistTask); } break; } }
public void ServiceSubmit(MeterRecord record, string imsi = "") { decimal balance = 0; //正在换表不记录数 if (_readTaskApp.GetLastEntity((int)TaskTypeEnum.SetBaseDosage, record.MeterCode) != null) { return; } //获取表信息 var meter = _meterApp.GetFormByMeterCode(record.MeterCode); if (meter == null) { return; } //表计倍率处理 if (meter.F_MeterRate != null) { record.Value = (double.Parse(record.Value) * (double)meter.F_MeterRate).ToString(CultureInfo.InvariantCulture); } const int read = (int)TaskTypeEnum.Read; const int task = (int)TaskTypeEnum.Task; var readTask = _readTaskApp.GetLastEntity(task, record.MeterCode) ?? _readTaskApp.GetLastEntity(read, record.MeterCode); var lastDosage = decimal.Parse(GetLastReadRecord(meter.F_Id, DateTime.Now)); //本次用量 var thisDosage = decimal.Parse(record.Value) - lastDosage; //过滤异常数据并加载到异常信息表内 //if (lastDosage != 0 && (thisDosage > 2000 || thisDosage < -2000)) if (1 > 1) { var readUnusualEntity = new ReadUnusualEntity() { F_Id = Common.GuId(), F_CreatorTime = DateTime.Now, F_ErrorType = ((int)ReadUnusualEnum.Read).ToString(), F_MeterCode = meter.F_MeterCode, F_MeterType = meter.F_MeterType, F_Description = meter.F_Description, F_CustomerAddress = meter.F_CustomerAddress, F_CustomerName = meter.F_CustomerName, F_Factor = meter.F_Factor, F_MobilePhone = meter.F_MobilePhone, F_OwnerId = meter.F_OwnerId, F_UserCard = meter.F_UserCard, F_Value = thisDosage, }; _readUnusualApp.SubmitForm(readUnusualEntity, ""); return; } else { var readRecordEntity = new ReadRecordEntity { F_TaskId = readTask == null ? "" : readTask.F_Id, F_ReadTime = record.ReadingTime, F_ArchiveId = meter.F_Id, F_ReadType = readTask == null ? "-1" : readTask.F_TaskType.ToString(), F_TotalDosage = decimal.Parse(record.Value), F_CreatorTime = DateTime.Now, F_Id = Common.GuId(), F_ThisDosage = thisDosage, F_Details = record.Data == null ? "" : record.Data.ToJson(), F_Settlement = record.Settlement == null ? "" : record.Settlement.ToJson(), F_Imsi = imsi }; ReadTaskEntity controlTask = null; PayOrderEntity payOrderEntity = null; ChargeRecordEntity chargeRecordEntity = null; MoneyAlarmEntity moneyAlarmEntity = null; //获取计费信息 var meterCharging = _meterChargingApp.GetForm(readRecordEntity.F_ArchiveId); var subsistenceCharging = _subsistenceSecurityApp.GetFormByArchiveId(readRecordEntity.F_ArchiveId); //0.判断表是否为IC卡预付费表 //获取当前周期开始时间 var cycleStartTime = _priceApp.GetCycleStartTime(subsistenceCharging != null && subsistenceCharging.F_PriceId != null ? subsistenceCharging.F_PriceId : meterCharging.F_PriceModel); //获取当前周期开始时间前一天最后一条抄表记录 var cycleDosage = cycleStartTime == DateTime.MinValue ? 0 : decimal.Parse(GetLastReadRecord(readRecordEntity.F_ArchiveId, cycleStartTime)); //单位价格 var uintPrice = _priceApp.GetPriceValue(subsistenceCharging != null && subsistenceCharging.F_PriceId != null ? subsistenceCharging.F_PriceId : meterCharging.F_PriceModel, ((readRecordEntity.F_TotalDosage ?? 0) - cycleDosage).ToString(CultureInfo.InvariantCulture)); if (meterCharging.F_MeterModel != "3") { //扣费后的余额 balance = _meterChargingApp.UpdateBalance(readRecordEntity.F_ArchiveId, (readRecordEntity.F_ThisDosage ?? 0) * uintPrice); } else { var count = _payOrderApp.GetPayOrderCount(record.MeterCode); if (record.Data != null && record.Data.Keys.Contains("充值次数") && (count + 1).ToString() == record.Data["充值次数"]) { payOrderEntity = _payOrderApp.GetLastPayOrder(record.MeterCode); if (payOrderEntity != null) { payOrderEntity.F_State = "1"; } } if (record.Data != null && record.Data.Keys.Contains("余额")) { decimal money; //上传的余额 balance = decimal.TryParse(record.Data["余额"], out money) ? _meterChargingApp.SetBalance(readRecordEntity.F_ArchiveId, money) : 0; } } chargeRecordEntity = new ChargeRecordEntity { F_ThisBill = (readRecordEntity.F_ThisDosage ?? 0) * uintPrice, F_ReadId = readRecordEntity.F_Id, F_UnitPrice = uintPrice, F_Description = "", F_Balance = balance, F_ChargeTime = DateTime.Now }; //1.设备是否阀控,是否报警 if (meterCharging.F_EnableClose == true && balance <= meterCharging.F_CloseAmount) { //2. 判断设备类型+是否可以阀控 if (meter.F_MeterType == MeterTypeEnum.WattMeter.ToString()) //电表关阀命令 { controlTask = new ReadTaskEntity { F_MeterCode = meter.F_MeterCode, F_Factor = meter.F_Factor, F_MeterType = meter.F_MeterType, F_State = (int)TaskStateEnum.Wait, F_Id = Common.GuId(), F_CreatorTime = DateTime.Now, F_TaskType = (int)TaskTypeEnum.TripSwitch }; } else //水表、燃气表、热表关阀命令 { //判断是否应急或关阀状态 if (!IsEmergency(readRecordEntity)) { controlTask = new ReadTaskEntity { F_MeterCode = meter.F_MeterCode, F_Factor = meter.F_Factor, F_MeterType = meter.F_MeterType, F_State = (int)TaskStateEnum.Wait, F_Id = Common.GuId(), F_CreatorTime = DateTime.Now, F_TaskType = (int)TaskTypeEnum.CloseValve }; } } } if (meterCharging.F_EnableClose == true && balance > meterCharging.F_CloseAmount) { if (meter.F_MeterType == MeterTypeEnum.WattMeter.ToString()) //电表开阀命令 { //电表充值自动开阀,不启用 //controlTask = new ReadTaskEntity //{ // F_MeterCode = meter.F_MeterCode, // F_Factor = meter.F_Factor, // F_MeterType = meter.F_MeterType, // F_State = (int)TaskStateEnum.Wait, // F_Id = Common.GuId(), // F_CreatorTime = DateTime.Now, // F_TaskType = (int)TaskTypeEnum.CloseSwitch //}; } else //水表、燃气表、热表开阀命令 { //判断是否应急或关阀状态 if (IsEmergency(readRecordEntity)) { controlTask = new ReadTaskEntity { F_MeterCode = meter.F_MeterCode, F_Factor = meter.F_Factor, F_MeterType = meter.F_MeterType, F_State = (int)TaskStateEnum.Wait, F_Id = Common.GuId(), F_CreatorTime = DateTime.Now, F_TaskType = (int)TaskTypeEnum.OpenValve }; } } } if (meterCharging.F_EnableAlarm == true && balance <= meterCharging.F_AlarmAmount) { if (_moneyAlarmApp.IsCanSend(meter.F_Id))//判断是否可报警 { var dataItems = (Dictionary <string, object>) new ItemsDetailApp().GetDataItemList(); var content = SmsHelper.UrlEncode("#name#=" + meter.F_CustomerName + "&#time#=" + DateTime.Now.ToString("yyyy年MM月dd日") + "&#meter#=" + meter.F_CustomerAddress + ((Dictionary <string, string>)dataItems["DeviceType"])[meter.F_MeterType] + "&#balance#=" + balance.ToString("#0.00")); var content2 = SmsHelper.UrlEncode("#name#=" + meter.F_CustomerName + "&#time#=" + DateTime.Now.ToString("yyyy年MM月dd日") + "&#meter#=" + ((Dictionary <string, string>)dataItems["DeviceType"])[meter.F_MeterType] + "&#balance#=" + balance.ToString("#0.00")); moneyAlarmEntity = new MoneyAlarmEntity { F_Id = Common.GuId(), F_ArchiveId = meter.F_Id, F_AlarmMonry = balance, F_AlarmState = (meter.F_OwnerId == "ff92def0-dabe-4878-915b-1b8cd0560ce4" && SmsHelper.Send(meter.F_MobilePhone, "58698", content, "c9eb4d0f54ad274842ef562d79f67e59")) || (meter.F_OwnerId == "bd602a97-eb06-4a5e-9c36-30eb45bc717b" && SmsHelper.Send(meter.F_MobilePhone, "96473", content2, "f73188115023c7e37955b095fefe0bb7")), //发送短信 F_SureState = false, F_CreatorTime = DateTime.Now, }; } } else { _moneyAlarmApp.SureAlarm(meter.F_Id); } //3.插入抄表信息、计费信息、阀控命令/报警命令 _service.SubmitService(readRecordEntity, chargeRecordEntity, readTask, controlTask, payOrderEntity, moneyAlarmEntity); } }