|
@@ -0,0 +1,504 @@
|
|
|
+using AutoMapper;
|
|
|
+using BizService;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
+using Model.Dto;
|
|
|
+using Model.Entities;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using PLCTool.Common;
|
|
|
+using Prism.Commands;
|
|
|
+using Prism.Events;
|
|
|
+using Prism.Mvvm;
|
|
|
+using Prism.Services.Dialogs;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
|
|
|
+
|
|
|
+namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
+{
|
|
|
+
|
|
|
+ public class TestResultDetailViewModel : BindableBase, IDialogAware
|
|
|
+ {
|
|
|
+ private readonly IDialogService _dialog;
|
|
|
+ private readonly IEventAggregator _aggregator;
|
|
|
+ private readonly IOptionConfigService _optionConfigService;
|
|
|
+ private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
|
|
|
+ private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
|
|
|
+ private readonly IBizTestRecordService _iBizTestRecordService;
|
|
|
+ private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly ILogger _logger;
|
|
|
+ private List<OptionConfigDto> _optionConfigs;
|
|
|
+
|
|
|
+ private DateTime startTime = DateTime.Now;
|
|
|
+ private DateTime endTime = DateTime.Now;
|
|
|
+ private int testStatus = 0; //测试状态
|
|
|
+ private int testResult = 0; //测试结果
|
|
|
+ private long schDetailId = 0; //测试方案明细ID
|
|
|
+
|
|
|
+
|
|
|
+ public TestResultDetailViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService, IMapper mapper)
|
|
|
+ {
|
|
|
+ _dialog = dialog;
|
|
|
+ _aggregator = aggregator;
|
|
|
+ _optionConfigService = optionConfigService;
|
|
|
+ _basicPlcTestSchemeService = basicPlcTestSchemeService;
|
|
|
+ _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
|
|
|
+ _iBizTestRecordDtlService = iBizTestRecordDtlService;
|
|
|
+ _iBizTestRecordService = iBizTestRecordService;
|
|
|
+ _mapper = mapper;
|
|
|
+
|
|
|
+
|
|
|
+ BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ InConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ OutConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ GetConfigOption();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #region idialog接口实现
|
|
|
+ public string Title { set; get; } = "测试结果查询";
|
|
|
+
|
|
|
+ public event Action<IDialogResult> RequestClose;
|
|
|
+
|
|
|
+ public bool CanCloseDialog()
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnDialogClosed()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnDialogOpened(IDialogParameters parameters)
|
|
|
+ {
|
|
|
+ //编辑
|
|
|
+ var getMsg = parameters.GetValues<long>("Key");
|
|
|
+ ///值不为空,表示修改
|
|
|
+ if (getMsg != null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ foreach (var item in getMsg)
|
|
|
+ {
|
|
|
+ schDetailId = item; //测试方案明细ID
|
|
|
+ int schDtlId = Convert.ToInt32(item);
|
|
|
+ //根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
|
|
|
+ var findEntity = _basicPlcTestSchemeDtlService.Find(schDtlId);
|
|
|
+ var findresult = _mapper.Map<bas_plc_test_scheme_dtl, BasicPlcTestSchemeDtlDto>(findEntity);
|
|
|
+ if (findresult != null)
|
|
|
+ {
|
|
|
+ //根据方案id 在方案表中查找方案名 设备名
|
|
|
+ int schID = Convert.ToInt32(findresult.SchemeId);
|
|
|
+ var findSch = _basicPlcTestSchemeService.Find(schID);
|
|
|
+ if (findSch != null)
|
|
|
+ {
|
|
|
+ ScheduleName = findSch.scheme_name;
|
|
|
+ DeviceName = findSch.device_name;
|
|
|
+
|
|
|
+ }
|
|
|
+ TestName = findresult.ItemName;
|
|
|
+ SelectTest = findresult.ItemType;
|
|
|
+
|
|
|
+ //这里是测试项 结果和 测试记录明细状态
|
|
|
+ //根据测试方案明细id查找结果
|
|
|
+ var recordDetail = _iBizTestRecordDtlService.FindRecordDetailBySchDtlID(schDtlId);
|
|
|
+ if (recordDetail != null)
|
|
|
+ { //前置项结果解析
|
|
|
+ string preconStr = recordDetail.precondition_final?.ToString();
|
|
|
+ if (!string.IsNullOrEmpty(preconStr))
|
|
|
+ {
|
|
|
+ JsonModel preconditionModel = JsonConvert.DeserializeObject<JsonModel>(preconStr);
|
|
|
+ BeforeSelectJudge = preconditionModel.ItemType;
|
|
|
+ SelectLogic = preconditionModel.ItemLogical;
|
|
|
+ BeforeDetail = preconditionModel.Description;
|
|
|
+ BeforeConList.Clear();
|
|
|
+ foreach (var detail in preconditionModel.DetailInfo)
|
|
|
+ {
|
|
|
+ BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
|
|
|
+ basPlcItemConfigDto.Id = detail.Id;
|
|
|
+ basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
|
|
|
+ basPlcItemConfigDto.PlcItem = detail.PlcItem;
|
|
|
+ basPlcItemConfigDto.PlcValue = detail.PlcValue;
|
|
|
+ basPlcItemConfigDto.Remark = detail.Remark;
|
|
|
+ basPlcItemConfigDto.TestTime = detail.TestTime;
|
|
|
+ basPlcItemConfigDto.RealValue = detail.RealValue;
|
|
|
+ basPlcItemConfigDto.TestResult = detail.TestResult;
|
|
|
+ beforeConList.Add(basPlcItemConfigDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //输入项解析
|
|
|
+ string inStr = recordDetail.action_final?.ToString();
|
|
|
+ if (!string.IsNullOrEmpty(inStr))
|
|
|
+ {
|
|
|
+ JsonModel inModel = JsonConvert.DeserializeObject<JsonModel>(inStr);
|
|
|
+ SelectInJudge = inModel.ItemType;
|
|
|
+ InSelectLogic = inModel.ItemLogical;
|
|
|
+ InDetail = inModel.Description;
|
|
|
+ InConList.Clear();
|
|
|
+ foreach (var detail in inModel.DetailInfo)
|
|
|
+ {
|
|
|
+ BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
|
|
|
+ basPlcItemConfigDto.Id = detail.Id;
|
|
|
+ basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
|
|
|
+ basPlcItemConfigDto.PlcItem = detail.PlcItem;
|
|
|
+ basPlcItemConfigDto.PlcValue = detail.PlcValue;
|
|
|
+ basPlcItemConfigDto.Remark = detail.Remark;
|
|
|
+ basPlcItemConfigDto.TestTime = detail.TestTime;
|
|
|
+ basPlcItemConfigDto.RealValue = detail.RealValue;
|
|
|
+ basPlcItemConfigDto.TestResult = detail.TestResult;
|
|
|
+ InConList.Add(basPlcItemConfigDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //输出项解析
|
|
|
+ string outStr = recordDetail.judgement_result_final?.ToString();
|
|
|
+ if (!string.IsNullOrEmpty(outStr))
|
|
|
+ {
|
|
|
+ JsonModel outModel = JsonConvert.DeserializeObject<JsonModel>(outStr);
|
|
|
+ SelectOutJudge = outModel.ItemType;
|
|
|
+ OutSelectLogic = outModel.ItemLogical;
|
|
|
+ OutDetail = outModel.Description;
|
|
|
+ OutConList.Clear();
|
|
|
+ foreach (var detail in outModel.DetailInfo)
|
|
|
+ {
|
|
|
+ BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
|
|
|
+ basPlcItemConfigDto.Id = detail.Id;
|
|
|
+ basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
|
|
|
+ basPlcItemConfigDto.PlcItem = detail.PlcItem;
|
|
|
+ basPlcItemConfigDto.PlcValue = detail.PlcValue;
|
|
|
+ basPlcItemConfigDto.Remark = detail.Remark;
|
|
|
+ basPlcItemConfigDto.TestTime = detail.TestTime;
|
|
|
+ basPlcItemConfigDto.RealValue = detail.RealValue;
|
|
|
+ basPlcItemConfigDto.TestResult = detail.TestResult;
|
|
|
+ OutConList.Add(basPlcItemConfigDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex)
|
|
|
+ {
|
|
|
+ _logger.LogError(ex.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 私有发方法
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 开始检测
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ private void Start(object obj)
|
|
|
+ {
|
|
|
+ //开始时间
|
|
|
+ startTime = DateTime.Now;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取配置
|
|
|
+ /// </summary>
|
|
|
+ private void GetConfigOption()
|
|
|
+ {
|
|
|
+ var configList = _optionConfigService.QueryList();
|
|
|
+ _optionConfigs = _mapper.Map<List<OptionConfig>, List<OptionConfigDto>>(configList);
|
|
|
+ var tests = _optionConfigs.FindAll(x => x.TypeID == 1);
|
|
|
+ TestKinds = new List<string>();
|
|
|
+ foreach (var test in tests)
|
|
|
+ {
|
|
|
+ TestKinds.Add(test.ContentOption);
|
|
|
+ }
|
|
|
+
|
|
|
+ //测试项类型
|
|
|
+ var judges = _optionConfigs.FindAll(x => x.TypeID == 2);
|
|
|
+ foreach (var judge in judges)
|
|
|
+ {
|
|
|
+ BeforeJudgeKinds.Add(judge.ContentOption);
|
|
|
+ InJudgeKinds.Add(judge.ContentOption);
|
|
|
+ OutJudgeKinds.Add(judge.ContentOption);
|
|
|
+ }
|
|
|
+
|
|
|
+ //判定逻辑
|
|
|
+ var logics = _optionConfigs.FindAll(x => x.TypeID == 3);
|
|
|
+ foreach (var logic in logics)
|
|
|
+ {
|
|
|
+ JudgeLogicKinds.Add(logic.ContentOption);
|
|
|
+ InJudgeLogicKinds.Add(logic.ContentOption);
|
|
|
+ OutJudgeLogicKinds.Add(logic.ContentOption);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 关闭按钮
|
|
|
+ /// </summary>
|
|
|
+ private void Close()
|
|
|
+ {
|
|
|
+ RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// mode转json
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="itemType"></param>
|
|
|
+ /// <param name="itemLogical"></param>
|
|
|
+ /// <param name="description"></param>
|
|
|
+ /// <param name="conList"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+
|
|
|
+ private string ModelToJsonToStr(string itemType, string itemLogical, string description, ObservableCollection<BasPlcItemConfigDto> conList)
|
|
|
+ {
|
|
|
+ JsonModel prefixJsonModel = new JsonModel();
|
|
|
+ prefixJsonModel.ItemType = itemType;
|
|
|
+ prefixJsonModel.ItemLogical = itemLogical;
|
|
|
+ prefixJsonModel.Description = description;
|
|
|
+ prefixJsonModel.DetailInfo = new List<DetailPLC>();
|
|
|
+ foreach (var item in conList)
|
|
|
+ {
|
|
|
+ DetailPLC plcItem = new DetailPLC();
|
|
|
+ plcItem.Id = item.Id;
|
|
|
+ plcItem.PlcItem = item.PlcItem;
|
|
|
+ plcItem.PlcAddress = item.PlcAddress;
|
|
|
+ plcItem.PlcAddType = item.PlcAddType;
|
|
|
+ plcItem.PlcValue = item.PlcValue;
|
|
|
+ plcItem.Remark = item.Remark;
|
|
|
+ prefixJsonModel.DetailInfo.Add(plcItem);
|
|
|
+
|
|
|
+ }
|
|
|
+ string prefixJsonStr = JsonConvert.SerializeObject(prefixJsonModel);
|
|
|
+ return prefixJsonStr;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+ #region 命令绑定
|
|
|
+
|
|
|
+
|
|
|
+ public DelegateCommand<object> StartCommand { set; get; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ #region 变量绑定
|
|
|
+ /// <summary>
|
|
|
+ /// 测试方案编码
|
|
|
+ /// </summary>
|
|
|
+ private string scheduleName;
|
|
|
+ public string ScheduleName
|
|
|
+ {
|
|
|
+ get { return scheduleName; }
|
|
|
+ set { scheduleName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 设备名称
|
|
|
+ /// </summary>
|
|
|
+ private string deviceName;
|
|
|
+ public string DeviceName
|
|
|
+ {
|
|
|
+ get { return deviceName; }
|
|
|
+ set { deviceName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 测试项名称
|
|
|
+ /// </summary>
|
|
|
+ private string testName;
|
|
|
+ public string TestName
|
|
|
+ {
|
|
|
+ get { return testName; }
|
|
|
+ set { testName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 测试项类型
|
|
|
+ /// </summary>
|
|
|
+ private List<string> testKinds = new List<string>();
|
|
|
+ public List<string> TestKinds
|
|
|
+ {
|
|
|
+ get { return testKinds; }
|
|
|
+ set { testKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ private string selectTest;
|
|
|
+ public string SelectTest
|
|
|
+ {
|
|
|
+ get { return selectTest; }
|
|
|
+ set { selectTest = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 判定类型(前置项)
|
|
|
+ /// </summary>
|
|
|
+ private List<string> beforeJudgeKinds = new List<string>();
|
|
|
+ public List<string> BeforeJudgeKinds
|
|
|
+ {
|
|
|
+ get { return beforeJudgeKinds; }
|
|
|
+ set { beforeJudgeKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string beforeSelectJudge;
|
|
|
+ public string BeforeSelectJudge
|
|
|
+ {
|
|
|
+ get { return beforeSelectJudge; }
|
|
|
+ set { beforeSelectJudge = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 逻辑判断
|
|
|
+ /// </summary>
|
|
|
+ private List<string> judgeLogicKinds = new List<string>();
|
|
|
+ public List<string> JudgeLogicKinds
|
|
|
+ {
|
|
|
+ get { return judgeLogicKinds; }
|
|
|
+ set { judgeLogicKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string selectLogic;
|
|
|
+ public string SelectLogic
|
|
|
+ {
|
|
|
+ get { return selectLogic; }
|
|
|
+ set { selectLogic = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string beforeDetail;
|
|
|
+ public string BeforeDetail
|
|
|
+ {
|
|
|
+ get { return beforeDetail; }
|
|
|
+ set { beforeDetail = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ObservableCollection<BasPlcItemConfigDto> beforeConList;
|
|
|
+ public ObservableCollection<BasPlcItemConfigDto> BeforeConList
|
|
|
+ {
|
|
|
+ get { return beforeConList; }
|
|
|
+ set { beforeConList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 判定类型(输入项)
|
|
|
+ /// </summary>
|
|
|
+ private List<string> inJudgeKinds = new List<string>();
|
|
|
+ public List<string> InJudgeKinds
|
|
|
+ {
|
|
|
+ get { return inJudgeKinds; }
|
|
|
+ set { inJudgeKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string selectInJudge;
|
|
|
+ public string SelectInJudge
|
|
|
+ {
|
|
|
+ get { return selectInJudge; }
|
|
|
+ set { selectInJudge = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 逻辑判断
|
|
|
+ /// </summary>
|
|
|
+ private List<string> inJudgeLogicKinds = new List<string>();
|
|
|
+ public List<string> InJudgeLogicKinds
|
|
|
+ {
|
|
|
+ get { return inJudgeLogicKinds; }
|
|
|
+ set { inJudgeLogicKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string inSelectLogic;
|
|
|
+ public string InSelectLogic
|
|
|
+ {
|
|
|
+ get { return inSelectLogic; }
|
|
|
+ set { inSelectLogic = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string inDetail;
|
|
|
+ public string InDetail
|
|
|
+ {
|
|
|
+ get { return inDetail; }
|
|
|
+ set { inDetail = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ObservableCollection<BasPlcItemConfigDto> inConList;
|
|
|
+ public ObservableCollection<BasPlcItemConfigDto> InConList
|
|
|
+ {
|
|
|
+ get { return inConList; }
|
|
|
+ set { inConList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 判定类型(结果项)
|
|
|
+ /// </summary>
|
|
|
+ private List<string> outJudgeKinds = new List<string>();
|
|
|
+ public List<string> OutJudgeKinds
|
|
|
+ {
|
|
|
+ get { return outJudgeKinds; }
|
|
|
+ set { outJudgeKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string selectOutJudge;
|
|
|
+ public string SelectOutJudge
|
|
|
+ {
|
|
|
+ get { return selectOutJudge; }
|
|
|
+ set { selectOutJudge = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 逻辑判断
|
|
|
+ /// </summary>
|
|
|
+ private List<string> outJudgeLogicKinds = new List<string>();
|
|
|
+ public List<string> OutJudgeLogicKinds
|
|
|
+ {
|
|
|
+ get { return outJudgeLogicKinds; }
|
|
|
+ set { outJudgeLogicKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string outSelectLogic;
|
|
|
+ public string OutSelectLogic
|
|
|
+ {
|
|
|
+ get { return outSelectLogic; }
|
|
|
+ set { outSelectLogic = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string outDetail;
|
|
|
+ public string OutDetail
|
|
|
+ {
|
|
|
+ get { return outDetail; }
|
|
|
+ set { outDetail = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private ObservableCollection<BasPlcItemConfigDto> outConList;
|
|
|
+ public ObservableCollection<BasPlcItemConfigDto> OutConList
|
|
|
+ {
|
|
|
+ get { return outConList; }
|
|
|
+ set { outConList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int stepIndex = 0;
|
|
|
+ public int StepIndex
|
|
|
+ {
|
|
|
+ get { return stepIndex; }
|
|
|
+ set { stepIndex = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ }
|
|
|
+}
|