/// <summary> /// 执行点火操作,更新表点火状态,并更新表信息为点火指定参数同时提交点火任务给通信层 /// </summary> /// <param name="meters"></param> /// <returns></returns> public string Do(List <IoT_Meter> meters) { MeterManageService _mms = new MeterManageService(); DianhuoDA dhDA = new DianhuoDA(); TaskManageDA tmd = new TaskManageDA(); foreach (IoT_Meter m in meters) { if (m.MeterState.ToString() == "5") { IoT_Meter _oldMeter = MeterManageService.QueryMeter(m.MeterNo); if (_oldMeter == null) { return(string.Format("点火失败,表{0}信息不存在!", m.MeterNo)); } if (_oldMeter.MeterState == '0') { return(string.Format("表{0}已点火完成,不能重复操作。", m.MeterNo)); } Meter _meter = tmd.QueryMeter(m.MeterNo.Trim()); tmd.UpdateMeter(m); IoT_SetAlarm alarmPar = new IoT_SetAlarm(); alarmPar.SwitchTag = "000000000 "; alarmPar.Par1 = 30; alarmPar.Par2 = 10; alarmPar.Par3 = 30; alarmPar.Par4 = ""; alarmPar.Par5 = 10; alarmPar.Par6 = 30; alarmPar.Par7 = 30; alarmPar.Par8 = 30; alarmPar.Par9 = "00"; new SetAlarmService().UpdateMeterAlarmPar(m.MeterNo.Trim(), alarmPar); //点火状态,需要修改表的通讯密钥 Message msg = _mms.Edit(m); if (msg.Result == false) { return(string.Format("点火失败,原因:登记表{0}点火信息失败,原因:{1}", m.MeterNo, msg.TxtMessage)); } string result = dhDA.SubmitDianHuoASK(_oldMeter); new UserManageService().UpadteUserStatus("2", m.UserID);//用户表状态置为 撤销点火 if (result != "") { _mms.Edit(_oldMeter); } } } return(""); }
/// <summary> /// 任务执行完成 /// </summary> /// <param name="task"></param> public string TaskCompletes(Task task, decimal ljGas = 0) { string result = ""; lock (_readlock) { //任务完成,设置表状态点火完成 try { //根据任务类型,处理《任务类型,点火任务(DH),换表登记(HB)、开阀(KF)、关阀(GF)、充值(CZ)、调整价格(TJ)等 》 switch (task.TaskType) { case TaskType.TaskType_点火: MeterManageService mms = new MeterManageService(); IoT_Meter m = new DianHuoService().QueryMeter(task.MeterMac); m.MeterState = '0'; m.TotalAmount = ljGas; CY.IotM.Common.Message msg = mms.Edit(m); //更新mongo层Meter对象计价参数 new UserManageService().UpadteUserStatus("3", m.UserID); //用户表状态置为 正常使用 if (msg.Result == false) { throw new Exception(msg.TxtMessage); } break; case TaskType.TaskType_换表登记: //在此实现换表完成代码 new HuanBiaoService().ChangeMeterFinished(task.TaskID, TaskState.Finished); break; case TaskType.TaskType_开阀: case TaskType.TaskType_关阀: ValveControlService valveControl = new ValveControlService(); valveControl.ValveControlFinished(task.TaskID, task.TaskType, TaskState.Finished); break; case TaskType.TaskType_充值: //充值完成 TopUpService tps = new TopUpService(); string topup = tps.TopupFinished(task.TaskID, task.TaskState, ""); if (topup != "") { throw new Exception($"表号:{task.MeterMac} 充值完成,但更新mongo内存数据失败,原因:{topup}"); } break; case TaskType.TaskType_调整价格: //表具已接受调价指令 new PricingManageService().UpdatePricingTaskState(task.TaskID, TaskState.Finished); break; case TaskType.TaskType_校准: //系统自动发送和完成,无需做其他处理 new M_SetParameterService().XZFinished(task.TaskID); break; case TaskType.TaskType_设置报警参数: new SetAlarmService().UpdateAlarmMeterState(task.TaskID, ((byte)TaskState.Finished).ToString()); break; case TaskType.TaskType_设置结算日期: //修改结算日期完成 new SettlementService().SettlementDaySetFinished(task.TaskID, TaskState.Finished); break; case TaskType.TaskType_设置上传周期: // new SetUploadCycleService().UpdateUploadCycleState(task.TaskID, TaskState.Finished); break; case TaskType.TaskType_发布广告: if (task.TaskState != TaskState.Waitting) { new AdInfoService().ADPublishFinished(task); } break; //case TaskType.TaskType_编辑广告配置: // new AdInfoService().UpdateTaskStatus(task.TaskID, TaskState.Finished); // break; } new CY.IoTM.MongoDataHelper.TaskManageDA().TaskCompile(task); } catch (Exception e) { Console.WriteLine(e.Message); Log.getInstance().Write(MsgType.Error, "TaskCompletes 任务完成状态更新失败,原因:" + e.Message); Log.getInstance().Write(new OneMeterDataLogMsg(task.MeterMac, e.Message)); } return(result); } }