|
@@ -0,0 +1,272 @@
|
|
|
+using AutoMapper;
|
|
|
+using BizService;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
+using Model.Dto;
|
|
|
+using Model.Entities;
|
|
|
+using PLCTool.Views.BusinessManageView;
|
|
|
+using Prism.Commands;
|
|
|
+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;
|
|
|
+
|
|
|
+namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
+{
|
|
|
+ class ProjectTestResultViewModel : BindableBase
|
|
|
+ {
|
|
|
+ private readonly IBasicDeviceService _iBasicDeviceService;
|
|
|
+ private readonly IBasicDeviceKindService _iBasicDeviceKindService;
|
|
|
+ private readonly IBasicProjectService _iBasicProjectService;
|
|
|
+ private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly IDialogService _dialog;
|
|
|
+ private readonly ILogger _logger;
|
|
|
+ private readonly IBizTestRecordService _iBizTestRecordService;
|
|
|
+ private readonly IBasicPlcTestSchemeDtlService _iBasicPlcTestSchemeDtlService;
|
|
|
+ private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
|
|
|
+ private ObservableCollection<DeviceResultCardView> allProjectResultPicList = new ObservableCollection<DeviceResultCardView>();
|
|
|
+ public ProjectTestResultViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordService iBizTestRecordService, IBasicPlcTestSchemeDtlService iBasicPlcTestSchemeDtlService, IBizTestRecordDtlService iBizTestRecordDtlService,IMapper mapper, IDialogService dialog, ILogger logger)
|
|
|
+ {
|
|
|
+ _iBasicDeviceService = iBasicDeviceService;
|
|
|
+ _iBasicDeviceKindService = iBasicDeviceKindService;
|
|
|
+ _iBasicProjectService = iBasicProjectService;
|
|
|
+ _basicPlcTestSchemeService = basicPlcTestSchemeService;
|
|
|
+ _iBizTestRecordService = iBizTestRecordService;
|
|
|
+ _iBasicPlcTestSchemeDtlService= iBasicPlcTestSchemeDtlService;
|
|
|
+ _iBizTestRecordDtlService = iBizTestRecordDtlService;
|
|
|
+ _mapper = mapper;
|
|
|
+ _dialog = dialog;
|
|
|
+ _logger = logger;
|
|
|
+ OnLoadCommand = new DelegateCommand(OnLoad);
|
|
|
+ QueryCommand = new DelegateCommand<object>(Query);
|
|
|
+ ResetCommand = new DelegateCommand<object>(Reset);
|
|
|
+ }
|
|
|
+ #region 私有方法
|
|
|
+ private void Reset(object obj)
|
|
|
+ {
|
|
|
+ ProjectNo = string.Empty;
|
|
|
+ ProjectLeader = string.Empty;
|
|
|
+ ProjectName = string.Empty;
|
|
|
+ StartTime = string.Empty;
|
|
|
+ EndTime = string.Empty;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Query(object obj)
|
|
|
+ {
|
|
|
+ var conditions = (from a in allProjectResultPicList
|
|
|
+ where (string.IsNullOrEmpty(ProjectNo) ? true : (a.txtProjectNo.Text == ProjectNo))
|
|
|
+ && (string.IsNullOrEmpty(ProjectName) ? true : (a.txtName.Text == ProjectName))
|
|
|
+ && (string.IsNullOrEmpty(ProjectLeader) ? true : (a.txtProjectLeader.Text == ProjectLeader))
|
|
|
+ select a).ToList();
|
|
|
+ ProjectResultPicList = new ObservableCollection<DeviceResultCardView>(conditions);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnLoad()
|
|
|
+ {
|
|
|
+ GetProjectConfig();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取所有项目
|
|
|
+ /// </summary>
|
|
|
+ private void GetProjectConfig()
|
|
|
+ {
|
|
|
+ allProjectResultPicList.Clear();
|
|
|
+ ProjectResultPicList.Clear();
|
|
|
+ List<DeviceDtlWithResultModel> allDeviceList = new List<DeviceDtlWithResultModel>();//所有方案
|
|
|
+ //所有测试方案
|
|
|
+ var schlist = _basicPlcTestSchemeService.QueryList();
|
|
|
+ var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
|
|
|
+ //测试记录中的所有设备
|
|
|
+ var deviceIds = _iBizTestRecordService.QueryList().Select(X => X.device_id).Distinct();
|
|
|
+ foreach (var deviceId in deviceIds)
|
|
|
+ {
|
|
|
+ List<DateTime> startDateTimes = new List<DateTime>();
|
|
|
+ var deviceMsg = _iBasicDeviceService.Find(((int)deviceId));
|
|
|
+ if (deviceMsg != null)
|
|
|
+ {
|
|
|
+ string deviceKind = _iBasicDeviceKindService.Find((int)deviceMsg.device_kind_id)?.devicekind_name;
|
|
|
+ string projectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name;
|
|
|
+ //记录设备下的方案通过个数
|
|
|
+ int deviceCountResult = 0;
|
|
|
+ string deviceTestResult = string.Empty;
|
|
|
+ //查找哦记录有的方案
|
|
|
+
|
|
|
+ var recordMsgs = _iBizTestRecordService.FindRecordByDeviceId(deviceId);
|
|
|
+ foreach (var sch in recordMsgs)
|
|
|
+ {
|
|
|
+
|
|
|
+ long schId = (long)_basicPlcTestSchemeService.FindByNameAndType(sch.scheme_name, deviceKind)?.scheme_id;
|
|
|
+ //计算测试结果
|
|
|
+ string testResult = string.Empty;
|
|
|
+ int countResult = 0;
|
|
|
+ var records = _iBizTestRecordDtlService.FindRecordDetailByRecordID(sch.record_id);
|
|
|
+ //
|
|
|
+ var schDtls = _iBasicPlcTestSchemeDtlService.FindAllBySchId(schId);
|
|
|
+ //循环所有测试项,有一个不合格,则整个测试方案不合格
|
|
|
+ foreach (var dtl in schDtls)
|
|
|
+ {
|
|
|
+ //选取开始时间最大的一个数据,查看测试结果
|
|
|
+ long schDtId = dtl.scheme_dtl_id;
|
|
|
+ var findRecords = records.FindAll(x => x.scheme_dtl_id == schDtId).OrderByDescending(x => x.start_test_time).ToArray();
|
|
|
+ if (findRecords.Length > 0)
|
|
|
+ {
|
|
|
+ int result = (int)findRecords[0]?.test_result.Value;
|
|
|
+ if (result == 0)
|
|
|
+ {
|
|
|
+ testResult = "不通过";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ countResult++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //测试结果
|
|
|
+ if (countResult == schDtls.Count)
|
|
|
+ {
|
|
|
+ testResult = "通过";
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算这个设备是否通过
|
|
|
+ if (testResult == "通过")
|
|
|
+ {
|
|
|
+ deviceCountResult++;
|
|
|
+ }
|
|
|
+ //加入时间集合
|
|
|
+ startDateTimes.Add(sch.start_test_time.Value);
|
|
|
+ }
|
|
|
+ //计算这个设备是否所有的方案都通过
|
|
|
+ if ((deviceCountResult != 0) && (deviceCountResult == recordMsgs.Count))
|
|
|
+ {
|
|
|
+ deviceTestResult = "通过";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ deviceTestResult = "不通过";
|
|
|
+ }
|
|
|
+ //这里不添加方案名称
|
|
|
+ allDeviceList.Add(new DeviceDtlWithResultModel()
|
|
|
+ {
|
|
|
+
|
|
|
+ DeviceId = deviceMsg.device_id,
|
|
|
+ DeviceNo = deviceMsg.device_no,
|
|
|
+ DeviceName = deviceMsg.device_name,
|
|
|
+ DeviceKindName = deviceKind,
|
|
|
+ ProjectName = projectName,
|
|
|
+ StartTestTime = startDateTimes.Min(),//取最小时间
|
|
|
+ TestResult = deviceTestResult
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //所有新项目
|
|
|
+ List<string> projectNames = allDeviceList.Select(x => x.ProjectName).Distinct().ToList();
|
|
|
+ foreach (var project in projectNames)
|
|
|
+ {
|
|
|
+ DeviceResultCardView deviceCard = new DeviceResultCardView();
|
|
|
+ deviceCard.txtName.Text = project;
|
|
|
+ deviceCard.txtProjectNo.Text = _iBasicProjectService.FindByProjectName(project)?.project_no;
|
|
|
+ deviceCard.txtProjectLeader.Text = _iBasicProjectService.FindByProjectName(project)?.project_leader;
|
|
|
+ //赋值
|
|
|
+ allProjectResultPicList.Add(deviceCard);
|
|
|
+ }
|
|
|
+ foreach (var item in allProjectResultPicList)
|
|
|
+ {
|
|
|
+ ProjectResultPicList.Add(item);
|
|
|
+ }
|
|
|
+ //计算行数
|
|
|
+ if (projectNames.Count % 4 == 0)
|
|
|
+ {
|
|
|
+ RowsCount = projectNames.Count / 4;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RowsCount = projectNames.Count / 4 + 1;
|
|
|
+ }
|
|
|
+ if (RowsCount < 2)
|
|
|
+ {
|
|
|
+ RowsCount = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 命令绑定
|
|
|
+ public DelegateCommand OnLoadCommand { set; get; }
|
|
|
+ public DelegateCommand<object> QueryCommand { set; get; }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public DelegateCommand<object> ResetCommand { set; get; }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 数据绑定
|
|
|
+ /// <summary>
|
|
|
+ /// 设备卡片
|
|
|
+ /// </summary>
|
|
|
+
|
|
|
+ private ObservableCollection<DeviceResultCardView> projectResultPicList = new ObservableCollection<DeviceResultCardView>();
|
|
|
+ public ObservableCollection<DeviceResultCardView> ProjectResultPicList
|
|
|
+ {
|
|
|
+ get { return projectResultPicList; }
|
|
|
+ set { projectResultPicList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int rowsCount = 2;
|
|
|
+ public int RowsCount
|
|
|
+ {
|
|
|
+ get { return rowsCount; }
|
|
|
+ set { rowsCount = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string projectNo;
|
|
|
+ public string ProjectNo
|
|
|
+ {
|
|
|
+ get { return projectNo; }
|
|
|
+ set { projectNo = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string projectName;
|
|
|
+ public string ProjectName
|
|
|
+ {
|
|
|
+ get { return projectName; }
|
|
|
+ set { projectName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string projectLeader;
|
|
|
+ public string ProjectLeader
|
|
|
+ {
|
|
|
+ get { return projectLeader; }
|
|
|
+ set { projectLeader = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 开始时间
|
|
|
+ /// </summary>
|
|
|
+ private string startTime = DateTime.Now.AddDays(-1).ToString();
|
|
|
+ public string StartTime
|
|
|
+ {
|
|
|
+ get { return startTime; }
|
|
|
+ set { startTime = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string endTime = DateTime.Now.ToString();
|
|
|
+ public string EndTime
|
|
|
+ {
|
|
|
+ get { return endTime; }
|
|
|
+ set { endTime = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|