private async Task <CheckLogEntity> PrepareCheckLog(DeviceInputData model, List <CheckLogItemEntity> items) { var data = new CheckLogEntity() { OrgUID = model.OrgUID, UserUID = model.UserUID, DeviceUID = model.DeviceUID, StatusOK = items.All(x => x.StatusOK > 0).ToBoolInt(), Tips = new List <string>() { } }.InitSelf("cklg"); //汇总所有提示 items.ForEach(x => data.Tips.AddWhenNotEmpty(x.Tips)); if (!data.IsValid(out var msg)) { throw new MsgException(msg); } data.DeviceModel = await this._deviceRepo.GetFirstAsync(x => x.UID == data.DeviceUID); if (data.DeviceModel == null) { throw new MsgException("设备不存在"); } return(await Task.FromResult(data)); }
private async Task <List <CheckLogItemEntity> > PrepareCheckLogItem(DeviceInputData model) { var param_uids = model.Data.NotEmptyAndDistinct(x => x.ParamUID).ToList(); var all_params = await this._paramRepo.GetListAsync(x => x.DeviceUID == model.DeviceUID); if (param_uids.Count != all_params.Count) { throw new MsgException("部分参数丢失"); } var list = new List <CheckLogItemEntity>(); foreach (var m in model.Data) { var p = all_params.FirstOrDefault(x => x.UID == m.ParamUID) ?? throw new MsgException("参数错误,部分设备参数不存在"); var value = m.ValueJson; var entity = new CheckLogItemEntity() { DeviceUID = p.DeviceUID, ParameterUID = p.UID, ParameterName = p.ParameterName, Rule = p.Rule, InputDataJson = value, InputType = p.InputType, Tips = new List <string>(), }; entity = await this.ValidParamsValues(entity, p, value); list.Add(entity); } return(list.Select(x => x.InitSelf("log-item")).ToList()); }
public async Task <_ <List <CheckInputDataResult> > > SubmitCheckLog(DeviceInputData model) { var data = new _ <List <CheckInputDataResult> >(); try { //检查输入 this.CheckInputData(model); //拼接数据 var items = await this.PrepareCheckLogItem(model); var log = await this.PrepareCheckLog(model, items); var issue = await this.PrepareIssue(log, items); //数据关联 foreach (var m in items) { m.CheckUID = log.UID; } //保存数据 var count = await this._logRepo.PrepareSessionAsync(async db => { db.Set <CheckLogEntity>().Add(log); db.Set <CheckLogItemEntity>().AddRange(items); if (issue != null) { db.Set <IssueEntity>().Add(issue); } return(await db.SaveChangesAsync()); }); //获取返回 var res = items.Select(x => new CheckInputDataResult() { ParamUID = x.ParameterUID, ParamName = x.ParameterName, StatusOk = x.StatusOK.ToBool(), Tips = x.Tips }).ToList(); data.SetSuccessData(res); return(data); } catch (MsgException e) { data.SetErrorMsg(e.Message); return(data); } catch (Exception e) { throw new Exception($"提交点检数据错误:{model?.ToJson()}", e); } }
private void CheckInputData(DeviceInputData model) { if (!ValidateHelper.IsPlumpString(model.OrgUID)) { throw new MsgException("组织UID为空"); } if (!ValidateHelper.IsPlumpString(model.DeviceUID)) { throw new MsgException("设备UID为空"); } if (!ValidateHelper.IsPlumpString(model.UserUID)) { throw new MsgException("用户UID为空"); } if (!ValidateHelper.IsPlumpList(model.Data)) { throw new MsgException("数据为空"); } if (!model.Data.All(x => ValidateHelper.IsAllPlumpString(x.ParamUID, x.ValueJson))) { throw new MsgException("提交数据存在错误"); } }
public async Task <_ <List <CheckInputDataResult> > > SubmitCheckLog(DeviceInputData model) { var data = new _ <List <CheckInputDataResult> >(); var steps = new List <string>(); try { steps.Add($"设备点检参数:{model?.ToJson()}"); //检查输入 this.__CheckInputData(model); steps.Add("数据检查没有问题"); //生成详情 var items = await this.__PrepareCheckLogItem(model); steps.Add($"生成点检详细数据:{items?.ToJson()}"); //生成点检主记录 var log = await this.__PrepareCheckLog(model, items); steps.Add($"生成点检数据:{log?.ToJson()}"); //生成工单 var issue = await this.__PrepareIssue(log, items); steps.Add($"生成工单:{issue?.ToJson()}"); //数据关联 foreach (var m in items) { m.CheckUID = log.UID; } //保存数据 await this.__SaveCheckLogDataOrThrow(log, items, issue : issue); steps.Add("保存数据"); //获取返回 var res = items.Select(x => new CheckInputDataResult() { ParamUID = x.ParameterUID, ParamName = x.ParameterName, StatusOk = x.StatusOK.ToBool(), Tips = x.Tips }).ToList(); data.SetSuccessData(res); return(data); } catch (MsgException e) { steps.Add(e.Message); data.SetErrorMsg(e.Message); return(data); } catch (Exception e) { steps.Add($"捕获异常信息:{e.GetInnerExceptionAsJson()}"); throw new Exception($"提交点检数据错误:{steps.ToJson()}", e); } }