瀏覽代碼

添加角色和项目关联

ltwork 1 年之前
父節點
當前提交
39517a0674

+ 1 - 0
BlankApp1/BizService/IRoleProjectService.cs

@@ -10,5 +10,6 @@ namespace BizService
     public  interface IRoleProjectService : IBaseService<RoleProject>
     public  interface IRoleProjectService : IBaseService<RoleProject>
     {
     {
         public List<RoleProject> FindAllByRoleId(int roleId);
         public List<RoleProject> FindAllByRoleId(int roleId);
+        public RoleProject FindByRoleIdAndPro(int roleId,int projectId);
     }
     }
 }
 }

+ 4 - 0
BlankApp1/BizService/RoleProjectService.cs

@@ -13,5 +13,9 @@ namespace BizService
         {
         {
             return base.GetList(x => x.RoleId == roleId);
             return base.GetList(x => x.RoleId == roleId);
         }
         }
+        public RoleProject FindByRoleIdAndPro(int roleId, int projectId)
+        {
+            return base.GetFirst(x => (x.RoleId == roleId)&&(x.ProjectId==projectId));
+        }
     }
     }
 }
 }

+ 1 - 0
BlankApp1/BlankApp1/Common/Appsession.cs

@@ -12,6 +12,7 @@ namespace PLCTool.Common
         public static string UserName = "Admin"; 
         public static string UserName = "Admin"; 
 
 
         public static int RoleId = -1;
         public static int RoleId = -1;
+  
     }
     }
   
   
 }
 }

+ 18 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ProjectTestResultViewModel.cs

@@ -3,6 +3,7 @@ using BizService;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Logging;
 using Model.Dto;
 using Model.Dto;
 using Model.Entities;
 using Model.Entities;
+using PLCTool.Common;
 using PLCTool.Events;
 using PLCTool.Events;
 using PLCTool.Models;
 using PLCTool.Models;
 using PLCTool.Views.BusinessManageView;
 using PLCTool.Views.BusinessManageView;
@@ -25,6 +26,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private readonly IBasicDeviceKindService _iBasicDeviceKindService;
         private readonly IBasicDeviceKindService _iBasicDeviceKindService;
         private readonly IBasicProjectService _iBasicProjectService;
         private readonly IBasicProjectService _iBasicProjectService;
         private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
         private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
+        private readonly IRoleProjectService _iRoleProjectService;
         private readonly IMapper _mapper;
         private readonly IMapper _mapper;
         private readonly IDialogService _dialog;
         private readonly IDialogService _dialog;
         private readonly ILogger _logger;
         private readonly ILogger _logger;
@@ -36,7 +38,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private ObservableCollection<DeviceResultCardView> allProjectResultPicList = new ObservableCollection<DeviceResultCardView>();
         private ObservableCollection<DeviceResultCardView> allProjectResultPicList = new ObservableCollection<DeviceResultCardView>();
         private int eachColumNum = 4; //每行展示卡片个数
         private int eachColumNum = 4; //每行展示卡片个数
         private List<CrumbViewModel> breadCrumbs = new List<CrumbViewModel>();
         private List<CrumbViewModel> breadCrumbs = new List<CrumbViewModel>();
-        public ProjectTestResultViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordService iBizTestRecordService, IBasicPlcTestSchemeDtlService iBasicPlcTestSchemeDtlService, IBizTestRecordDtlService iBizTestRecordDtlService,IMapper mapper, IDialogService dialog, ILogger logger, IEventAggregator aggregator, ObservableCollection<DeviceResultCardView> allProjectResultPicList)
+        public ProjectTestResultViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordService iBizTestRecordService, IBasicPlcTestSchemeDtlService iBasicPlcTestSchemeDtlService, IBizTestRecordDtlService iBizTestRecordDtlService, IRoleProjectService iRoleProjectService,IMapper mapper, IDialogService dialog, ILogger logger, IEventAggregator aggregator, ObservableCollection<DeviceResultCardView> allProjectResultPicList)
         {
         {
             _iBasicDeviceService = iBasicDeviceService;
             _iBasicDeviceService = iBasicDeviceService;
             _iBasicDeviceKindService = iBasicDeviceKindService;
             _iBasicDeviceKindService = iBasicDeviceKindService;
@@ -45,6 +47,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             _iBizTestRecordService = iBizTestRecordService;
             _iBizTestRecordService = iBizTestRecordService;
             _iBasicPlcTestSchemeDtlService = iBasicPlcTestSchemeDtlService;
             _iBasicPlcTestSchemeDtlService = iBasicPlcTestSchemeDtlService;
             _iBizTestRecordDtlService = iBizTestRecordDtlService;
             _iBizTestRecordDtlService = iBizTestRecordDtlService;
+            _iRoleProjectService = iRoleProjectService;
             _mapper = mapper;
             _mapper = mapper;
             _dialog = dialog;
             _dialog = dialog;
             _logger = logger;
             _logger = logger;
@@ -205,7 +208,20 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 }
                 }
 
 
                 //所有新项目
                 //所有新项目
-                List<string> projectNames = allDeviceList.Select(x => x.ProjectName).Distinct().ToList();
+                //List<string> projectNames = allDeviceList.Select(x => x.ProjectName).Distinct().ToList();
+                //所有的项目
+                List<string> projectNames = new List<string>();
+                //根据角色显示所拥有的项目
+                var roleProjectIds = _iRoleProjectService.FindAllByRoleId(Appsession.RoleId);
+                foreach (var item in roleProjectIds)
+                {
+                    var finPro = _iBasicProjectService.Find((int)item.ProjectId);
+                    if (finPro != null)
+                    {
+                        projectNames.Add(finPro.project_name);
+                    }
+                }
+                //遍历项目
                 foreach (var project in projectNames)
                 foreach (var project in projectNames)
                 {
                 {
                     int projectId = (int)allDeviceList?.FirstOrDefault(x => x.ProjectName == project)?.ProjectId;
                     int projectId = (int)allDeviceList?.FirstOrDefault(x => x.ProjectName == project)?.ProjectId;

+ 16 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ProjectTestViewModel.cs

@@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
 using Model;
 using Model;
 using Model.Dto;
 using Model.Dto;
 using Model.Entities;
 using Model.Entities;
+using PLCTool.Common;
 using PLCTool.Events;
 using PLCTool.Events;
 using PLCTool.Models;
 using PLCTool.Models;
 using PLCTool.Views.BusinessManageView;
 using PLCTool.Views.BusinessManageView;
@@ -30,6 +31,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private readonly IBasicDeviceKindService _iBasicDeviceKindService;
         private readonly IBasicDeviceKindService _iBasicDeviceKindService;
         private readonly IBasicProjectService _iBasicProjectService;
         private readonly IBasicProjectService _iBasicProjectService;
         private readonly IBizTestRecordService _iBizTestRecordService;
         private readonly IBizTestRecordService _iBizTestRecordService;
+        private readonly IRoleProjectService _iRoleProjectService;
         private readonly IMapper _mapper;
         private readonly IMapper _mapper;
         private readonly IDialogService _dialog;
         private readonly IDialogService _dialog;
         private readonly ILogger _logger;
         private readonly ILogger _logger;
@@ -37,12 +39,13 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private ObservableCollection<DeviceTestCardView> allProjectePicList = new ObservableCollection<DeviceTestCardView>();
         private ObservableCollection<DeviceTestCardView> allProjectePicList = new ObservableCollection<DeviceTestCardView>();
         private int eachColumNum = 4; //每行展示卡片个数
         private int eachColumNum = 4; //每行展示卡片个数
         private List<CrumbViewModel> breadCrumbs = new List<CrumbViewModel>();
         private List<CrumbViewModel> breadCrumbs = new List<CrumbViewModel>();
-        public ProjectTestViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBizTestRecordService iBizTestRecordService, IMapper mapper, IDialogService dialog, ILogger logger, IEventAggregator aggregator)
+        public ProjectTestViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBizTestRecordService iBizTestRecordService, IRoleProjectService iRoleProjectService,IMapper mapper, IDialogService dialog, ILogger logger, IEventAggregator aggregator)
         {
         {
             _iBasicDeviceService = iBasicDeviceService;
             _iBasicDeviceService = iBasicDeviceService;
             _iBasicDeviceKindService = iBasicDeviceKindService;
             _iBasicDeviceKindService = iBasicDeviceKindService;
             _iBasicProjectService = iBasicProjectService;
             _iBasicProjectService = iBasicProjectService;
             _iBizTestRecordService = iBizTestRecordService;
             _iBizTestRecordService = iBizTestRecordService;
+            _iRoleProjectService= iRoleProjectService;
             _mapper = mapper;
             _mapper = mapper;
             _dialog = dialog;
             _dialog = dialog;
             _logger = logger;
             _logger = logger;
@@ -121,7 +124,18 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
 
                 }
                 }
                 //所有的项目
                 //所有的项目
-                List<string> projectNames = allDeviceList.Select(x => x.ProjectName).Distinct().ToList();
+                List<string> projectNames = new List<string>();
+                //根据角色显示所拥有的项目
+                var roleProjectIds=_iRoleProjectService.FindAllByRoleId(Appsession.RoleId);
+                foreach(var item in roleProjectIds)
+                {
+                    var finPro= _iBasicProjectService.Find((int)item.ProjectId);
+                    if(finPro!=null)
+                    {
+                        projectNames.Add(finPro.project_name);
+                    }
+                }
+                //遍历项目
                 foreach (var project in projectNames)
                 foreach (var project in projectNames)
                 {
                 {
                     int noTestCount = 0;
                     int noTestCount = 0;

+ 1 - 0
BlankApp1/BlankApp1/ViewModels/LoginViewModel.cs

@@ -71,6 +71,7 @@ namespace PLCTool.ViewModels
                 if(userRole!=null)
                 if(userRole!=null)
                 {
                 {
                     Appsession.RoleId = (int)userRole.RoleId;
                     Appsession.RoleId = (int)userRole.RoleId;
+                    Appsession.UserName=userName;
                 }
                 }
                 RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
                 RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
             }
             }

+ 9 - 4
BlankApp1/BlankApp1/ViewModels/MainWindowViewModel.cs

@@ -52,6 +52,7 @@ namespace BlankApp1.ViewModels
 
 
             aggregator.GetEvent<BreadEvent>().Subscribe(RecvBreadMsg);
             aggregator.GetEvent<BreadEvent>().Subscribe(RecvBreadMsg);
             aggregator.GetEvent<MaskEvent>().Subscribe(DisplayMask);
             aggregator.GetEvent<MaskEvent>().Subscribe(DisplayMask);
+         
         }
         }
 
 
         private void DisplayMask(bool isVis)
         private void DisplayMask(bool isVis)
@@ -115,10 +116,7 @@ namespace BlankApp1.ViewModels
             _regionManager.Regions["ContentRegion"].RequestNavigate("LogView");
             _regionManager.Regions["ContentRegion"].RequestNavigate("LogView");
             _regionManager.Regions["MenuRegion"].RequestNavigate("TreeMenuView");
             _regionManager.Regions["MenuRegion"].RequestNavigate("TreeMenuView");
             _regionManager.Regions["ContentRegion"].RequestNavigate("StatisticsView");
             _regionManager.Regions["ContentRegion"].RequestNavigate("StatisticsView");
-         
-        
-           
-
+            UserName=Appsession.UserName;
         }
         }
         /// <summary>
         /// <summary>
         /// 连接PLC
         /// 连接PLC
@@ -183,7 +181,14 @@ namespace BlankApp1.ViewModels
             set { isMaskVisible = value; RaisePropertyChanged(); }
             set { isMaskVisible = value; RaisePropertyChanged(); }
         }
         }
 
 
+        private string userName ;
+        public string UserName
+        {
+            get { return userName; }
+            set { userName = value; RaisePropertyChanged(); }
+        }
         
         
+
         #endregion
         #endregion
     }
     }
 }
 }

+ 13 - 29
BlankApp1/BlankApp1/ViewModels/StatisticsViewModel.cs

@@ -6,6 +6,7 @@ using LiveCharts.Wpf;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Logging;
 using Model.Dto;
 using Model.Dto;
 using Model.Entities;
 using Model.Entities;
+using PLCTool.Common;
 using PLCTool.Events;
 using PLCTool.Events;
 using PLCTool.Models;
 using PLCTool.Models;
 using Prism.Commands;
 using Prism.Commands;
@@ -33,6 +34,7 @@ namespace BlankApp1.ViewModels
         private readonly IBasicProjectService _iBasicProjectService;
         private readonly IBasicProjectService _iBasicProjectService;
         private readonly IBizTestRecordService _iBizTestRecordService;
         private readonly IBizTestRecordService _iBizTestRecordService;
         private readonly IBasicPlcTestSchemeDtlService _iBasicPlcTestSchemeDtlService;
         private readonly IBasicPlcTestSchemeDtlService _iBasicPlcTestSchemeDtlService;
+        private readonly IRoleProjectService _iRoleProjectService;
         private readonly ILogger _logger;
         private readonly ILogger _logger;
         private readonly IMapper _mapper;
         private readonly IMapper _mapper;
         private readonly IEventAggregator _aggregator;
         private readonly IEventAggregator _aggregator;
@@ -40,7 +42,7 @@ namespace BlankApp1.ViewModels
         private List<DeviceDtlWithResultModel> conditionDevices = new List<DeviceDtlWithResultModel>();//符合条件的方案
         private List<DeviceDtlWithResultModel> conditionDevices = new List<DeviceDtlWithResultModel>();//符合条件的方案
         private int allSchCount = 0; //所有测试项
         private int allSchCount = 0; //所有测试项
         private List<CrumbViewModel> breadCrumbs = new List<CrumbViewModel>();
         private List<CrumbViewModel> breadCrumbs = new List<CrumbViewModel>();
-        public StatisticsViewModel(IDialogService dialog, IMenuService menuService, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordDtlService iBizTestRecordDtlService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBizTestRecordService iBizTestRecordService, IBasicPlcTestSchemeDtlService iBasicPlcTestSchemeDtlService, IBasicDeviceService iBasicDeviceService,IMapper mapper, ILogger logger,IEventAggregator aggregator)
+        public StatisticsViewModel(IDialogService dialog, IMenuService menuService, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordDtlService iBizTestRecordDtlService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBizTestRecordService iBizTestRecordService, IBasicPlcTestSchemeDtlService iBasicPlcTestSchemeDtlService, IBasicDeviceService iBasicDeviceService, IRoleProjectService iRoleProjectService,IMapper mapper, ILogger logger,IEventAggregator aggregator)
         {
         {
             _dialog = dialog;
             _dialog = dialog;
             _optionConfigService = optionConfigService;
             _optionConfigService = optionConfigService;
@@ -53,6 +55,7 @@ namespace BlankApp1.ViewModels
             _iBizTestRecordService = iBizTestRecordService;
             _iBizTestRecordService = iBizTestRecordService;
             _iBasicPlcTestSchemeDtlService = iBasicPlcTestSchemeDtlService;
             _iBasicPlcTestSchemeDtlService = iBasicPlcTestSchemeDtlService;
             _iBasicDeviceService = iBasicDeviceService;
             _iBasicDeviceService = iBasicDeviceService;
+            _iRoleProjectService = iRoleProjectService;
             _logger = logger;
             _logger = logger;
             _mapper = mapper;
             _mapper = mapper;
             _aggregator=aggregator;
             _aggregator=aggregator;
@@ -95,9 +98,17 @@ namespace BlankApp1.ViewModels
                 List<DateTime> startDateTimes = new List<DateTime>();
                 List<DateTime> startDateTimes = new List<DateTime>();
                 var deviceMsg = _iBasicDeviceService.Find(((int)deviceId));
                 var deviceMsg = _iBasicDeviceService.Find(((int)deviceId));
                 if (deviceMsg != null)
                 if (deviceMsg != null)
-                {
+                { 
+                    //根据角色显示所拥有的项目
+                    var roleProject = _iRoleProjectService.FindByRoleIdAndPro(Appsession.RoleId, (int)deviceMsg.project_id);
+                    if(roleProject==null)
+                    {
+                        continue;
+                    }
                     string deviceKind = _iBasicDeviceKindService.Find((int)deviceMsg.device_kind_id)?.devicekind_name;
                     string deviceKind = _iBasicDeviceKindService.Find((int)deviceMsg.device_kind_id)?.devicekind_name;
                     string projectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name;
                     string projectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name;
+                   
+                    
                     //记录设备下的方案通过个数
                     //记录设备下的方案通过个数
                     int deviceCountResult = 0;
                     int deviceCountResult = 0;
                     string deviceTestResult = string.Empty;
                     string deviceTestResult = string.Empty;
@@ -145,33 +156,6 @@ namespace BlankApp1.ViewModels
                             testResult = "通过";
                             testResult = "通过";
                         }
                         }
 
 
-
-                        //allDeviceList.Add(new DeviceDtlWithResultModel()
-                        //{
-                        //    RecordId = sch.record_id,
-                        //    DeviceId = deviceMsg.device_id,
-                        //    DeviceNo = deviceMsg.device_no,
-                        //    DeviceName = deviceMsg.device_name,
-                        //    DeviceKindName = deviceKindName,
-                        //    ProjectName = projectName,
-                        //    SchemeName = sch.scheme_name,
-                        //    SchemeId= schId,
-                        //    StartTestTime = sch.start_test_time.Value,
-                        //    TestResult=testResult
-                        //}); 
-                        //conditionDevices.Add(new DeviceDtlWithResultModel()
-                        //{
-                        //    RecordId = sch.record_id,
-                        //    DeviceId = deviceMsg.device_id,
-                        //    DeviceNo = deviceMsg.device_no,
-                        //    DeviceName = deviceMsg.device_name,
-                        //    DeviceKindName = deviceKindName,
-                        //    ProjectName = projectName,
-                        //    SchemeName = sch.scheme_name,
-                        //    SchemeId = schId,
-                        //    StartTestTime = sch.start_test_time.Value,
-                        //    TestResult = testResult
-                        //});
                         //计算这个设备是否通过
                         //计算这个设备是否通过
                         if (testResult == "通过")
                         if (testResult == "通过")
                         {
                         {

+ 1 - 1
BlankApp1/BlankApp1/Views/MainWindow.xaml

@@ -106,7 +106,7 @@
             <StackPanel  Orientation="Horizontal" HorizontalAlignment="Right" Margin=" 0,0,14,0">
             <StackPanel  Orientation="Horizontal" HorizontalAlignment="Right" Margin=" 0,0,14,0">
                 <TextBlock x:Name="txtTime" Foreground="#ffffff" VerticalAlignment="Center" Margin="0,0,18,0"/>
                 <TextBlock x:Name="txtTime" Foreground="#ffffff" VerticalAlignment="Center" Margin="0,0,18,0"/>
                 <Image Source="../Assets/Images/register.png" Height="21" Width="21"></Image>
                 <Image Source="../Assets/Images/register.png" Height="21" Width="21"></Image>
-                <TextBlock Text="admin"  VerticalAlignment="Center" Margin="5,0,8,0"/>
+                <TextBlock Text="{Binding UserName}"  VerticalAlignment="Center" Margin="5,0,8,0"/>
                 <TextBlock Text="|" Style="{StaticResource txtHeadStyle}" Margin="0,0,17,0" Width="2" Height=" 20"></TextBlock>
                 <TextBlock Text="|" Style="{StaticResource txtHeadStyle}" Margin="0,0,17,0" Width="2" Height=" 20"></TextBlock>
                 <Button  x:Name="btnMin" Content="—"  Click="btnMin_Click"  Style="{StaticResource IconButtonStyle}"/>
                 <Button  x:Name="btnMin" Content="—"  Click="btnMin_Click"  Style="{StaticResource IconButtonStyle}"/>
                 <Button  x:Name="btnMax" Click="btnMax_Click" Content="&#xe60d;" FontFamily="../Assets/Fonts/#iconfont"   Style="{StaticResource IconButtonStyle}"/>
                 <Button  x:Name="btnMax" Click="btnMax_Click" Content="&#xe60d;" FontFamily="../Assets/Fonts/#iconfont"   Style="{StaticResource IconButtonStyle}"/>