Browse Source

添加统计

user_lt 1 year ago
parent
commit
c91a7f558b

+ 5 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/QueryViewModel.cs

@@ -30,7 +30,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private readonly IMenuService _menuService;
 
         private List<SchDtlWithResultModel> allConfigList = new List<SchDtlWithResultModel>();//所有方案
-        private List<SchDtlWithResultModel> conditionConfig = new List<SchDtlWithResultModel>();//所有方案
+        private List<SchDtlWithResultModel> conditionConfig = new List<SchDtlWithResultModel>();//符合条件的方案
 
         private const int PageCount = 1; //每一页显示个数
         public QueryViewModel(IDialogService dialog, IMenuService menuService, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordDtlService iBizTestRecordDtlService,IMapper mapper, ILogger logger)
@@ -209,7 +209,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     var recordDetail=_iBizTestRecordDtlService.FindRecordDetailBySchDtlID(item.scheme_dtl_id);
                     if(recordDetail != null)
                     {
-                        switch(recordDetail.test_result)
+                        basicPlcTestSchemeDto.StartTestTime = recordDetail.start_test_time.Value;
+                        basicPlcTestSchemeDto.FinishTestTime = recordDetail.finish_test_time.Value;
+                        basicPlcTestSchemeDto.TestMode= recordDetail.test_mode;
+                        switch (recordDetail.test_result)
                         {
                             case 0:
                                 basicPlcTestSchemeDto.TestResult = "不通过";

+ 176 - 3
BlankApp1/BlankApp1/ViewModels/StatisticsViewModel.cs

@@ -1,9 +1,17 @@
-using LiveCharts;
+using AutoMapper;
+using BizService;
+using LiveCharts;
 using LiveCharts.Defaults;
 using LiveCharts.Wpf;
+using Microsoft.Extensions.Logging;
+using Model.Dto;
+using Model.Entities;
+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;
@@ -12,18 +20,141 @@ namespace BlankApp1.ViewModels
 {
     public  class StatisticsViewModel:BindableBase
     {
-        public StatisticsViewModel()
+        private readonly IDialogService _dialog;
+        private readonly IOptionConfigService _optionConfigService;
+        private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
+        private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
+        private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
+        private readonly ILogger _logger;
+        private readonly IMapper _mapper;
+        private List<SchDtlWithResultModel> allConfigList = new List<SchDtlWithResultModel>();//所有方案
+        private List<SchDtlWithResultModel> conditionConfig = new List<SchDtlWithResultModel>();//符合条件的方案
+        public StatisticsViewModel(IDialogService dialog, IMenuService menuService, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordDtlService iBizTestRecordDtlService, IMapper mapper, ILogger logger)
         {
+            _dialog = dialog;
+            _optionConfigService = optionConfigService;
+            _basicPlcTestSchemeService = basicPlcTestSchemeService;
+            _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
+            _iBizTestRecordDtlService = iBizTestRecordDtlService;
+            _logger = logger;
+            _mapper = mapper;
             PieSeriesCollectionDone = new SeriesCollection();
             PieSeriesCollectionFail= new SeriesCollection();
             PieSeriesCollectionEveryday = new SeriesCollection();
             PieSeriesCollectionPLC = new SeriesCollection();
+            OnLoadCommand = new DelegateCommand(OnLoad);
             GetPieSeriesDone();
             GetPieSeriesPLC();
             GetPieSeriesEveryDay();
             GetPieSeriesFail();
         }
-       
+
+        private void OnLoad()
+        {
+            GetContent();
+        }
+        /// <summary>
+        /// 获取解决方案
+        /// </summary>
+        private void GetContent()
+        {
+            //所有测试方案
+            var schlist = _basicPlcTestSchemeService.QueryList();
+            var configList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
+            //清空集合
+            BaseConfigList.Clear();
+            allConfigList.Clear();
+            conditionConfig.Clear();
+            //查找测试项名称
+            foreach (var sch in configList)
+            {
+                long schId = sch.SchemeId;
+                //在解决方案详细表中查找所有的测试项
+                var items = _basicPlcTestSchemeDtlService.FindAllBySchId(schId);
+                foreach (var item in items)
+                {
+                    //上面是测试方案明细
+                    SchDtlWithResultModel basicPlcTestSchemeDto = new SchDtlWithResultModel();
+                    basicPlcTestSchemeDto.SchemeId = item.scheme_dtl_id;
+                    basicPlcTestSchemeDto.SchemeName = sch.SchemeName;
+                    basicPlcTestSchemeDto.DeviceName = sch.DeviceName;
+                    switch (item.item_type)
+                    {
+                        case 0:
+                            basicPlcTestSchemeDto.ItemType = "前置项";
+                            break;
+                        case 1:
+                            basicPlcTestSchemeDto.ItemType = "PLC点位测试项";
+                            break;
+                        case 2:
+                            basicPlcTestSchemeDto.ItemType = "Robot动作测试";
+                            break;
+                    }
+
+                    basicPlcTestSchemeDto.ItemName = item.item_name;
+                    basicPlcTestSchemeDto.CreateBy = sch.CreateBy;
+                    basicPlcTestSchemeDto.CreateTime = sch.CreateTime;
+                    //这里是测试项 结果和 测试记录明细状态
+                    var recordDetail = _iBizTestRecordDtlService.FindRecordDetailBySchDtlID(item.scheme_dtl_id);
+                    if (recordDetail != null)
+                    {
+                        basicPlcTestSchemeDto.StartTestTime = recordDetail.start_test_time.Value;
+                        basicPlcTestSchemeDto.FinishTestTime = recordDetail.finish_test_time.Value;
+                        basicPlcTestSchemeDto.TestMode = recordDetail.test_mode;
+                        switch (recordDetail.test_result)
+                        {
+                            case 0:
+                                basicPlcTestSchemeDto.TestResult = "不通过";
+                                break;
+                            case 1:
+                                basicPlcTestSchemeDto.TestResult = "通过";
+                                break;
+                        }
+
+                        switch (recordDetail.status)
+                        {
+                            case 0:
+                                basicPlcTestSchemeDto.TestStatus = "未测试";
+                                break;
+                            case 99:
+                                basicPlcTestSchemeDto.TestStatus = "已测试";
+                                break;
+                        }
+                    }
+                    allConfigList.Add(basicPlcTestSchemeDto);
+                    conditionConfig.Add(basicPlcTestSchemeDto);
+
+                }
+                //默认显示的第一页
+                Getpage();
+            }
+
+        }
+
+        /// <summary>
+        /// 获取页面
+        /// </summary>
+        private void Getpage()
+        {
+            CurrentPage = 1;
+            TotalCount = conditionConfig.Count;
+            CurrentPageChanged();
+
+
+        }
+        /// <summary>
+        /// 页面变化
+        /// </summary>
+        private void CurrentPageChanged()
+        {
+
+            BaseConfigList.Clear();
+
+            foreach (var i in conditionConfig.Skip((CurrentPage - 1) * CountPerPage).Take(CountPerPage))
+            {
+                BaseConfigList.Add(i);
+            }
+        }
         private void GetPieSeriesDone()
         {
             ChartValues<int> chartvalue = new ChartValues<int>();
@@ -99,6 +230,10 @@ namespace BlankApp1.ViewModels
             PieSeriesCollectionEveryday.Add(series2);
 
         }
+        #region 数据绑定
+
+
+
         /// <summary>
         /// 图标数据
         /// </summary>
@@ -129,5 +264,43 @@ namespace BlankApp1.ViewModels
             get { return pieSeriesCollectionFail; }
             set { pieSeriesCollectionFail = value; RaisePropertyChanged(); }
         }
+        /// <summary>
+        /// 总条数
+        /// </summary>
+        private int totalCount;
+        public int TotalCount
+        {
+            get { return totalCount; }
+            set { totalCount = value; RaisePropertyChanged(); CurrentPageChanged(); }
+        }
+        /// <summary>
+        /// 每页数量
+        /// </summary>
+        private int countPerPage = 1;
+        public int CountPerPage
+        {
+            get { return countPerPage; }
+            set { countPerPage = value; RaisePropertyChanged(); CurrentPageChanged(); }
+        }
+        /// <summary>
+        /// 单前页
+        /// </summary>
+        private int currentPage = 1;
+        public int CurrentPage
+        {
+            get { return currentPage; }
+            set { currentPage = value; RaisePropertyChanged(); CurrentPageChanged(); }
+        }
+
+        private ObservableCollection<SchDtlWithResultModel> baseConfigList = new ObservableCollection<SchDtlWithResultModel>();
+        public ObservableCollection<SchDtlWithResultModel> BaseConfigList
+        {
+            get { return baseConfigList; }
+            set { SetProperty(ref baseConfigList, value); }
+        }
+        #endregion
+        #region 命令绑定
+        public DelegateCommand OnLoadCommand { set; get; }
+        #endregion
     }
 }

+ 27 - 11
BlankApp1/BlankApp1/Views/StatisticsView.xaml

@@ -5,12 +5,20 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
              xmlns:local="clr-namespace:BlankApp1.Views"
+             xmlns:wpfdev="https://github.com/WPFDevelopersOrg/WPFDevelopers"
+             xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
     <Grid>
+        <b:Interaction.Triggers>
+            <b:EventTrigger EventName="Loaded">
+                <b:InvokeCommandAction Command="{Binding OnLoadCommand}"/>
+            </b:EventTrigger>
+        </b:Interaction.Triggers>
         <Grid.RowDefinitions>
             <RowDefinition/>
             <RowDefinition Height="1.5*"/>
+            <RowDefinition Height="50"/>
         </Grid.RowDefinitions>
         <Grid Grid.Row="0">
             <Grid.RowDefinitions>
@@ -60,22 +68,30 @@
             </UniformGrid>
         </Grid>
         <Grid Grid.Row="1" Margin="5">
-            <DataGrid  Grid.Row="1"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0"
-         ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}" x:Name="DeviceDataGrid" RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
-        ItemsSource="{Binding BaseConfigList}" IsReadOnly="True"  >
+            <DataGrid  Grid.Row="2"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0"
+        ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"  RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
+       ItemsSource="{Binding BaseConfigList}" IsReadOnly="True"  Padding="0">
                 <DataGrid.Columns >
-                    <DataGridTextColumn Header="测试时间" Binding="{Binding Id}" CellStyle="{StaticResource MyDataGridCellStyle}" />
-                    <DataGridTextColumn Header="测试人" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                    <DataGridTextColumn Header="测试方案编码" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                    <DataGridTextColumn Header="测试记录编码" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                    <DataGridTextColumn Header="测试方式" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                    <DataGridTextColumn Header="测试结果" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                    <DataGridTextColumn Header="测试时间" Binding="{Binding StartTestTime,StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                    <DataGridTextColumn Header="测试人" Binding="{Binding CreateBy}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                    <DataGridTextColumn Header="测试方案名称" Binding="{Binding SchemeName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                    <DataGridTextColumn Header="测试项类型" Binding="{Binding ItemType}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                    <DataGridTextColumn Header="测试项名称" Binding="{Binding ItemName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                    <DataGridTextColumn Header="测试方式" Binding="{Binding TestMode}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                    <DataGridTextColumn Header="测试结果" Binding="{Binding TestResult}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                 
+                   
+
                 </DataGrid.Columns>
 
             </DataGrid>
 
-
         </Grid>
-              
+        <Grid Grid.Row="2">
+            <wpfdev:Pagination IsLite="False"    Margin="0"  Width="auto" Height="30" HorizontalAlignment="Center"  
+         Count="{Binding TotalCount,Mode=TwoWay}" 
+         CountPerPage="{Binding CountPerPage,Mode=TwoWay}"
+         Current="{Binding CurrentPage,Mode=TwoWay}"/>
+        </Grid>    
     </Grid>
 </UserControl>

+ 10 - 0
BlankApp1/Model/Dto/SchDtlWithResultModel.cs

@@ -11,6 +11,14 @@ namespace Model.Dto
     /// </summary>
     public  class SchDtlWithResultModel: BasicPlcTestSchemeDto
     {
+        public DateTime StartTestTime { get; set; }
+
+        public DateTime FinishTestTime { get; set; }
+
+        /// <summary>
+        /// 测试模式
+        /// </summary>
+        public string TestMode { get; set; }
         public string TestResult { get; set; }
 
         /// <summary>
@@ -19,5 +27,7 @@ namespace Model.Dto
         /// Nullable:True
         /// </summary>           
         public string TestStatus { get; set; }
+
+        
     }
 }