diff --git a/DeviceRepair.Api/Controllers/DeviceController.cs b/DeviceRepair.Api/Controllers/DeviceController.cs index 9fd797d..65c79fe 100644 --- a/DeviceRepair.Api/Controllers/DeviceController.cs +++ b/DeviceRepair.Api/Controllers/DeviceController.cs @@ -55,6 +55,34 @@ namespace DeviceRepair.Api.Controllers return apiResponseData; } + /// + /// 根据设备ID获取PM的设备信息 + /// + /// + /// + [HttpGet, Route("GetPMDeviceInfoModelByEquipmentID"), HttpAuthorize] + public APIResponseData GetPMDeviceInfoModelByEquipmentID(string EquipmentID) + { + + APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "未能获取到数据" }; + try + { + if (string.IsNullOrWhiteSpace(EquipmentID)) + { + throw new Exception("设备编号是必须的参数!"); + } + + return DeviceAccess.Instance.GetPMDeviceInfoModelByEquipmentID(EquipmentID); + } + catch (Exception ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message.ToString(); + } + return apiResponseData; + } + + /// /// 设备台账数据获取 /// @@ -152,5 +180,31 @@ namespace DeviceRepair.Api.Controllers return apiResponseData; } + + #region KH + + /// + /// 设备台账数据获取 + /// + /// + /// + [HttpGet,Route("GetQueryKH"), HttpAuthorize] + public APIResponseData GetQueryKH(string FilterString) + { + APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "未能获取到数据!" }; + try + { + return DeviceAccess.Instance.GetQueryKH(FilterString); + } + catch (Exception ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + + return apiResponseData; + } + + #endregion } } \ No newline at end of file diff --git a/DeviceRepair.Api/Controllers/OperationController.cs b/DeviceRepair.Api/Controllers/OperationController.cs new file mode 100644 index 0000000..5925f53 --- /dev/null +++ b/DeviceRepair.Api/Controllers/OperationController.cs @@ -0,0 +1,37 @@ +using DeviceRepair.Api.Common; +using DeviceRepair.Api.CustomAttribute; +using DeviceRepair.DataAccess; +using DeviceRepair.Models; +using DeviceRepair.Models.Logs; +using System; +using System.Web.Http; + + +namespace DeviceRepair.Api.Controllers +{ + [RoutePrefix("Api/Operation")] + public class OperationController : CFController + { + /// + /// 用户登录登出日志 + /// + /// + /// + [HttpPost, HttpAuthorize, Route("UserLoginContent")] + public APIResponseData UserLoginContent(OperationFilterModel FilterInfo) + { + APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "操作失败!" }; + try + { + apiResponseData = OperationAccess.Instance.UserLoginContent(FilterInfo); + } + catch (Exception ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + + return apiResponseData; + } + } +} \ No newline at end of file diff --git a/DeviceRepair.Api/Controllers/RoleController.cs b/DeviceRepair.Api/Controllers/RoleController.cs index c5fd76a..b08962d 100644 --- a/DeviceRepair.Api/Controllers/RoleController.cs +++ b/DeviceRepair.Api/Controllers/RoleController.cs @@ -103,7 +103,7 @@ namespace DeviceRepair.Api.Controllers if (string.IsNullOrWhiteSpace(Item.RoleCode)) { apiResponseData.Message = "角色编码不能为空!"; - return apiResponseData; + return apiResponseData; } if (string.IsNullOrWhiteSpace(Item.RoleName)) @@ -256,7 +256,7 @@ namespace DeviceRepair.Api.Controllers /// /// [HttpGet, Route("GetUserAuthsByUserID"), HttpAuthorize] - public IHttpActionResult GetUserAuthsByUserID(int UserAutoID) + public APIResponseData GetUserAuthsByUserID(int UserAutoID) { APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "操作失败!" }; try @@ -269,7 +269,7 @@ namespace DeviceRepair.Api.Controllers apiResponseData.Message = ex.Message; } - return new GzipCompressedResult(apiResponseData.ToJson(), Request); ; + return apiResponseData; } } } diff --git a/DeviceRepair.Api/DeviceRepair.Api.csproj b/DeviceRepair.Api/DeviceRepair.Api.csproj index 4f1f6cd..2d82e24 100644 --- a/DeviceRepair.Api/DeviceRepair.Api.csproj +++ b/DeviceRepair.Api/DeviceRepair.Api.csproj @@ -231,6 +231,7 @@ + @@ -310,6 +311,7 @@ + diff --git a/DeviceRepair.Api/DeviceRepair.Api.csproj.user b/DeviceRepair.Api/DeviceRepair.Api.csproj.user index cd58591..02419f9 100644 --- a/DeviceRepair.Api/DeviceRepair.Api.csproj.user +++ b/DeviceRepair.Api/DeviceRepair.Api.csproj.user @@ -16,8 +16,8 @@ False D:\UGit\DeviceManager\DeviceRepair.Api\Properties\PublishProfiles\FolderProfile.pubxml - ApiControllerEmptyScaffolder - root/Common/Web API + MvcControllerEmptyScaffolder + root/Common/MVC/Controller diff --git a/DeviceRepair.Api/Properties/PublishProfiles/FolderProfile.pubxml b/DeviceRepair.Api/Properties/PublishProfiles/FolderProfile.pubxml index 9475d73..0a3786f 100644 --- a/DeviceRepair.Api/Properties/PublishProfiles/FolderProfile.pubxml +++ b/DeviceRepair.Api/Properties/PublishProfiles/FolderProfile.pubxml @@ -10,7 +10,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Debug Any CPU FileSystem - C:\Users\Clove\Desktop\20240603_Release\WebApi_20240605 + C:\Users\Clove\Desktop\2024-06-07\WebApi_20240607 FileSystem diff --git a/DeviceRepair.Api/Properties/PublishProfiles/FolderProfile.pubxml.user b/DeviceRepair.Api/Properties/PublishProfiles/FolderProfile.pubxml.user index 55e57d1..c7031fe 100644 --- a/DeviceRepair.Api/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/DeviceRepair.Api/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,8 +4,8 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - <_PublishTargetUrl>C:\Users\Clove\Desktop\20240603_Release\WebApi_20240605 - True|2024-06-05T09:25:01.7658333Z;True|2024-06-05T15:19:15.9175825+08:00;True|2024-06-04T16:24:57.6501582+08:00;True|2024-06-04T14:30:31.7472780+08:00;True|2024-06-04T01:16:03.9124219+08:00;True|2024-06-03T15:22:33.9888519+08:00;True|2024-06-03T10:04:55.1562939+08:00;True|2024-06-03T09:51:46.3653303+08:00;True|2024-05-31T10:08:51.2865889+08:00;True|2024-05-31T01:21:35.1603933+08:00;True|2024-05-30T17:42:28.4008960+08:00;True|2024-05-30T17:35:13.0117556+08:00;True|2024-05-30T17:28:00.7834102+08:00;True|2024-05-30T17:10:05.9943745+08:00;True|2024-05-29T13:43:17.4797209+08:00; + <_PublishTargetUrl>C:\Users\Clove\Desktop\2024-06-07\WebApi_20240607 + True|2024-06-07T08:16:21.1052233Z;True|2024-06-07T14:29:10.5922517+08:00;True|2024-06-07T13:08:03.5723912+08:00;True|2024-06-07T11:57:27.3523385+08:00;True|2024-06-07T02:12:35.2135048+08:00;True|2024-06-06T17:34:12.0143579+08:00;True|2024-06-06T14:39:21.1746757+08:00;True|2024-06-06T13:08:18.5085671+08:00;True|2024-06-05T17:25:01.7658333+08:00;True|2024-06-05T15:19:15.9175825+08:00;True|2024-06-04T16:24:57.6501582+08:00;True|2024-06-04T14:30:31.7472780+08:00;True|2024-06-04T01:16:03.9124219+08:00;True|2024-06-03T15:22:33.9888519+08:00;True|2024-06-03T10:04:55.1562939+08:00;True|2024-06-03T09:51:46.3653303+08:00;True|2024-05-31T10:08:51.2865889+08:00;True|2024-05-31T01:21:35.1603933+08:00;True|2024-05-30T17:42:28.4008960+08:00;True|2024-05-30T17:35:13.0117556+08:00;True|2024-05-30T17:28:00.7834102+08:00;True|2024-05-30T17:10:05.9943745+08:00;True|2024-05-29T13:43:17.4797209+08:00; @@ -78,37 +78,37 @@ https://go.microsoft.com/fwlink/?LinkID=208121. 05/28/2024 22:39:54 - 06/05/2024 17:25:01 + 06/07/2024 15:10:30 - 06/05/2024 17:25:01 + 06/07/2024 15:10:30 - 06/05/2024 17:25:00 + 06/07/2024 15:10:30 05/30/2024 11:42:20 - 06/05/2024 17:25:00 + 06/07/2024 15:10:30 - 06/05/2024 17:24:54 + 06/07/2024 15:10:29 05/30/2024 11:42:20 - 06/05/2024 17:24:54 + 06/07/2024 15:10:29 - 06/05/2024 15:05:54 + 06/07/2024 15:10:29 05/30/2024 11:42:20 - 06/05/2024 15:05:54 + 06/07/2024 15:10:29 05/28/2024 22:39:54 @@ -414,7 +414,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. 04/16/2024 09:58:38 - 06/05/2024 17:25:01 + 06/07/2024 16:16:20 \ No newline at end of file diff --git a/DeviceRepair.DataAccess/DeviceAccess.cs b/DeviceRepair.DataAccess/DeviceAccess.cs index b1a840e..9d0168b 100644 --- a/DeviceRepair.DataAccess/DeviceAccess.cs +++ b/DeviceRepair.DataAccess/DeviceAccess.cs @@ -93,7 +93,7 @@ namespace DeviceRepair.DataAccess var exp = Expressionable.Create() .OrIF(aid > 0, t1 => t1.AutoID == aid) .OrIF(!string.IsNullOrEmpty(FilterValue), - t1 => t1.EquipmentID.Equals(FilterValue, StringComparison.CurrentCultureIgnoreCase) + t1 => t1.EquipmentID.Contains(FilterValue) || t1.EquipmentName.Contains(FilterValue) || t1.Remarks.Contains(FilterValue) || t1.Specification.Contains(FilterValue)).ToExpression();//拼接表达式 @@ -291,26 +291,45 @@ namespace DeviceRepair.DataAccess int aid = 0; int.TryParse(FilterValue, out aid); - List RootDatas = db.Queryable().Where(x => x.Status).OrderBy(x => x.AutoID).ToList(); + List RootDatas = null; if (OEMORKH != "ALL") { - List waitDel = new List(); - foreach (var item in RootDatas) - { - if (item.ParentID == 0 && item.Name != OEMORKH) - { - waitDel.Add(item.AutoID); - continue; - } + RootDatas = db.Ado.SqlQuery(@" + ;WITH cte + AS(SELECT AutoID + FROM dbo.DeviceRoute + WHERE [Name] = @Name + UNION ALL + SELECT dr.AutoID + FROM dbo.DeviceRoute dr + INNER JOIN cte + ON dr.ParentID = cte.AutoID) + SELECT DeviceRoute.* + FROM DeviceRoute + INNER JOIN cte on DeviceRoute.AutoID = cte.AutoID WHERE Status = 1", new { Name = OEMORKH }).ToList(); - if (waitDel.Any(x => x == item.ParentID)) - { - waitDel.Add(item.AutoID); - } - } - RootDatas.RemoveAll(x => waitDel.Contains(x.AutoID)); + + //List waitDel = new List(); + //foreach (var item in RootDatas) + //{ + // if (item.ParentID == 0 && item.Name != OEMORKH) + // { + // waitDel.Add(item.AutoID); + // continue; + // } + + // if (waitDel.Any(x => x == item.ParentID)) + // { + // waitDel.Add(item.AutoID); + // } + //} + //RootDatas.RemoveAll(x => waitDel.Contains(x.AutoID)); + } + else + { + RootDatas = db.Queryable().Where(x => x.Status).OrderBy(x => x.AutoID, OrderByType.Desc).ToList(); } var Root = RootDatas.ToDictionary(x => x.AutoID, x => x); @@ -406,6 +425,19 @@ namespace DeviceRepair.DataAccess Menus.RemoveAll(x => !HasValues.Contains(x.RouteAutoId) && x.ParentRouteId != Guid.Empty); Menus.AddRange(Datas); + + foreach (DeviceRouteInfo item in RootDatas) + { + DeviceInformationInfoTree Node = Menus.FirstOrDefault(x => x.RouteAutoId == item.GUID); + List Child = Menus.Where(x => x.Route == item.AutoID).ToList(); + if (Node != null && Child.Count > 0) + { + Node.Totalcapacity = Child.Sum(x => x.Totalcapacity); + Node.Weight = Child.Sum(x => x.Weight); + Node.EquipmentOriginalvalue = Child.Sum(x => x.EquipmentOriginalvalue); + } + } + apiResponseData.Code = 1; apiResponseData.Data = Menus; apiResponseData.Message = ""; @@ -433,5 +465,140 @@ namespace DeviceRepair.DataAccess } return value; } + + + #region PM + + public APIResponseData GetQueryKH(string FilterValue) + { + APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" }; + try + { + db.ChangeDatabase("main"); + + int aid = 0; + int.TryParse(FilterValue, out aid); + + int[] RootIds = db.Ado.SqlQuery(@" + ;WITH cte + AS(SELECT AutoID + FROM dbo.DeviceRoute + WHERE [Name] = @Name + UNION ALL + SELECT dr.AutoID + FROM dbo.DeviceRoute dr + INNER JOIN cte + ON dr.ParentID = cte.AutoID) + SELECT* + FROM cte", new { Name = "KH" }).ToArray(); + + var exp = Expressionable.Create() + .And(t1 => SqlFunc.ContainsArray(RootIds, t1.Route)) + .OrIF(aid > 0, t1 => t1.AutoID == aid) + .OrIF(!string.IsNullOrEmpty(FilterValue), + t1 => t1.EquipmentID.Equals(FilterValue, StringComparison.CurrentCultureIgnoreCase) + || t1.EquipmentName.Contains(FilterValue) + || t1.Remarks.Contains(FilterValue) + || t1.Specification.Contains(FilterValue)).ToExpression();//拼接表达式 + + var Datas = db.Queryable( + (t1, t2, t3) => new object[] { + JoinType.Left, t1.MaintenanceFormVersion == t2.AutoID, + JoinType.Left, t1.Route == t3.AutoID + }).Select((t1, t2, t3) => new View_DriveInfomationModel + { + AutoID = t1.AutoID, + ChangeDate = t1.ChangeDate, + ChangeUser = t1.ChangeUser, + CreatDate = t1.CreatDate, + CreatUser = t1.CreatUser, + EquipmentCategory = t1.EquipmentCategory, + EquipmentID = t1.EquipmentID, + EquipmentName = t1.EquipmentName, + EquipmentOriginalvalue = t1.EquipmentOriginalvalue, + EquipmentStatus = t1.EquipmentStatus, + InstallationLocation = t1.InstallationLocation, + MaintenanceFormVersion = t1.MaintenanceFormVersion, + MaintenanceFormVersionName = t2.FormName, + MaintenanceFormStatus = t2.FormStatus, + Manufacturer = t1.Manufacturer, + OperatingParameters = t1.OperatingParameters, + OwningUnit = t1.OwningUnit, + Remarks = t1.Remarks, + SerialNumber = t1.SerialNumber, + Specification = t1.Specification, + Totalcapacity = t1.Totalcapacity, + UsingDate = t1.UsingDate, + VersionCode = t2.VersionCode, + VersionRev = t2.VersionRev, + WarrantyPeriod = t1.WarrantyPeriod, + Route = t1.Route, + RouteText = t3.Name, + Weight = t1.Weight + }).Where(exp) + .ToList(); + + apiResponseData.Code = 1; + apiResponseData.Data = Datas; + apiResponseData.Message = ""; + } + catch (SqlSugarException ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + catch (Exception ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + return apiResponseData; + } + + /// + /// 通过设备编号查询设备信息 + /// + /// + /// + public APIResponseData GetPMDeviceInfoModelByEquipmentID(string EquipmentID) + { + APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" }; + try + { + db.ChangeDatabase("main"); + + int[] RootIds = db.Ado.SqlQuery(@" + ;WITH cte + AS(SELECT AutoID + FROM dbo.DeviceRoute + WHERE [Name] = @Name + UNION ALL + SELECT dr.AutoID + FROM dbo.DeviceRoute dr + INNER JOIN cte + ON dr.ParentID = cte.AutoID) + SELECT* + FROM cte", new { Name = "KH" }).ToArray(); + + DeviceInformationInfo Data = CurrentDb.AsQueryable().First(x => SqlFunc.ContainsArray(RootIds, x.Route) && x.EquipmentID.Equals(EquipmentID, StringComparison.CurrentCultureIgnoreCase)); + + apiResponseData.Code = 1; + apiResponseData.Data = Data; + apiResponseData.Message = ""; + } + catch (SqlSugarException ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + catch (Exception ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + return apiResponseData; + } + + #endregion } } diff --git a/DeviceRepair.DataAccess/DeviceRepair.DataAccess.csproj b/DeviceRepair.DataAccess/DeviceRepair.DataAccess.csproj index c49ee65..88879e3 100644 --- a/DeviceRepair.DataAccess/DeviceRepair.DataAccess.csproj +++ b/DeviceRepair.DataAccess/DeviceRepair.DataAccess.csproj @@ -49,6 +49,7 @@ + diff --git a/DeviceRepair.DataAccess/MaintenanceAccess.cs b/DeviceRepair.DataAccess/MaintenanceAccess.cs index 955e359..8b4227d 100644 --- a/DeviceRepair.DataAccess/MaintenanceAccess.cs +++ b/DeviceRepair.DataAccess/MaintenanceAccess.cs @@ -368,6 +368,8 @@ namespace DeviceRepair.DataAccess public APIResponseData ChangeDownStatus(int AutoID, bool Status, HeaderModel Operation) { APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = $"数据处理失败!" }; + db.ChangeDatabase("main"); + db.BeginTran(); try { if (AutoID <= 0) @@ -376,7 +378,12 @@ namespace DeviceRepair.DataAccess } DateTime CurrentTime = DateTime.Now; - db.ChangeDatabase("main"); + + + if (db.Queryable().Any(x => x.FormID == AutoID && x.SubmitBy > 0)) + { + throw new Exception("数据已被修改!"); + } DeviceWarrantyRequestForm Entity = db.Queryable().First(x => x.AutoID == AutoID); if (Entity == null) @@ -387,20 +394,24 @@ namespace DeviceRepair.DataAccess Entity.IsDown = Status; if (db.Updateable(Entity).UpdateColumns(it => new { it.IsDown }).ExecuteCommand() > 0) { + db.CommitTran(); apiResponseData.Code = 1; apiResponseData.Message = string.Empty; } } catch (SqlSugarException e) { + db.RollbackTran(); apiResponseData.Code = -1; apiResponseData.Message = e.Message; } catch (Exception ex) { + db.RollbackTran(); apiResponseData.Code = -1; apiResponseData.Message = ex.Message; } + db.RollbackTran(); return apiResponseData; } @@ -512,7 +523,7 @@ namespace DeviceRepair.DataAccess } else { - throw new Exception("待处理的停机单状态异常,请重试!"); + throw new Exception("待处理的停机单状态不正确,或已被其他用户处理,请重试!"); } @@ -568,6 +579,19 @@ namespace DeviceRepair.DataAccess try { db.ChangeDatabase("main"); + + Dictionary RootIds = db.Ado.SqlQuery(@" + ;WITH cte + AS(SELECT AutoID,Name + FROM dbo.DeviceRoute WHERE ParentID = 0 + UNION ALL + SELECT dr.AutoID,cte.Name + FROM dbo.DeviceRoute dr + INNER JOIN cte + ON dr.ParentID = cte.AutoID) + SELECT* + FROM cte").ToDictionary(x => x.AutoID, x => x.Name); + var exp = Expressionable.Create(); if (FilterInfo != null) { @@ -589,15 +613,17 @@ namespace DeviceRepair.DataAccess List Datas = CurrentDb.AsQueryable().With(SqlWith.NoLock).Where(exp.ToExpression()).ToList(); Dictionary Users = db.Queryable().ToList().ToDictionary(x => x.AutoID, x => x); Dictionary Fields = db.Queryable().ToList().ToDictionary(x => x.AutoID, x => x); + Dictionary devs = db.Queryable().ToList().ToDictionary(x => x.AutoID, x => x); int i = 1; List views = new List(); foreach (DeviceWarrantyRequestForm item in Datas) { + int Plant = RootIds[devs[item.EquipmentPK].Route] == "KH" ? 1303 : 9997; MaintainOrderView view = new MaintainOrderView { AutoNumber = i, - Plant = 1303, + Plant = Plant, AutoID = item.AutoID, EquipmentID = item.EquipmentID, EquipmentName = item.EquipmentName, @@ -613,7 +639,7 @@ namespace DeviceRepair.DataAccess DeviceWarrantyRequestMaintaionInfo repair = item.MaintaionItems; view.RepairPersonnel = Users[repair.SubmitBy].RealName; view.RepairStartDate = repair.MaintainStartTime.ToString("yyyy-M-dd"); - view.RepairStartDate = repair.MaintainEndTime.ToString("yyyy-M-dd"); + view.RepairFinishDate = repair.MaintainEndTime.ToString("yyyy-M-dd"); view.MaintainCause = repair.MaintainCause; view.MaintainContent = repair.MaintainContent; @@ -627,10 +653,10 @@ namespace DeviceRepair.DataAccess } TimeSpan Downtime = repair.MaintainEndTime - item.CreatOn.Value; - view.Downtime = Downtime.Hours; + view.Downtime = Convert.ToDecimal(Math.Round(Downtime.TotalHours, 2)); TimeSpan RepairDuration = repair.MaintainEndTime - repair.MaintainStartTime; - view.RepairDuration = RepairDuration.Hours; + view.RepairDuration = Convert.ToDecimal(Math.Round(RepairDuration.TotalHours)); view.Maintenance = Fields[repair.Maintenance].FieldText; view.SymptomlDistinction = Fields[repair.SymptomlDistinction].FieldText; diff --git a/DeviceRepair.DataAccess/OperationAccess.cs b/DeviceRepair.DataAccess/OperationAccess.cs new file mode 100644 index 0000000..ea5effa --- /dev/null +++ b/DeviceRepair.DataAccess/OperationAccess.cs @@ -0,0 +1,73 @@ +using DeviceRepair.Models; +using DeviceRepair.Models.History; +using DeviceRepair.Models.Logs; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace DeviceRepair.DataAccess +{ + public class OperationAccess : DbContext + { + private static OperationAccess manager; + public static OperationAccess Instance + { + get + { + if (manager == null) + manager = new OperationAccess(); + return manager; + } + } + + /// + /// 用户登录登出日志 + /// + /// + /// + public APIResponseData UserLoginContent(OperationFilterModel FilterInfo) + { + APIResponseData apiResponseData = new APIResponseData(); + try + { + db.ChangeDatabase("main"); + Dictionary userInfos = base.GetList().ToDictionary(x => x.LoginCode, x => x); + if (userInfos != null && userInfos.Count > 0) + { + db.ChangeDatabase("log"); + + var exp = Expressionable.Create(); + if (FilterInfo != null) + { + exp.AndIF(FilterInfo.sDate != DateTime.MinValue, x => x.OperationDate >= FilterInfo.sDate); + exp.AndIF(FilterInfo.eDate != DateTime.MinValue, x => x.OperationDate <= FilterInfo.eDate); + exp.AndIF(!string.IsNullOrWhiteSpace(FilterInfo.LoginCode), x => x.LoginCode.Contains(FilterInfo.LoginCode)); + exp.AndIF(!string.IsNullOrWhiteSpace(FilterInfo.OperationType), x => x.OperationType.Contains(FilterInfo.OperationType)); + exp.AndIF(!string.IsNullOrWhiteSpace(FilterInfo.ClientName), x => x.OperationComputer.Contains(FilterInfo.ClientName)); + } + + List userLogins = db.Queryable().With(SqlWith.NoLock).Where(exp.ToExpression()).ToList(); + foreach (UserLogin item in userLogins) + { + if (userInfos.ContainsKey(item.LoginCode)) + item.RealName = userInfos[item.LoginCode].RealName; + } + apiResponseData.Code = 1; + apiResponseData.Data = userLogins; + } + } + catch (SqlSugarException ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + catch (Exception ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + return apiResponseData; + } + } +} diff --git a/DeviceRepair.DataAccess/PlanAccess.cs b/DeviceRepair.DataAccess/PlanAccess.cs index 2e7bb7f..86034e6 100644 --- a/DeviceRepair.DataAccess/PlanAccess.cs +++ b/DeviceRepair.DataAccess/PlanAccess.cs @@ -203,7 +203,6 @@ namespace DeviceRepair.DataAccess try { db.ChangeDatabase("main"); - base.db.ChangeDatabase("main"); List tips = base.db.Queryable().ToList(); apiResponseData.Code = 1; @@ -326,7 +325,24 @@ namespace DeviceRepair.DataAccess int[] ids = Datas.Select(x => x.EquipmentID).ToArray(); Dictionary usDict = db.Queryable().With(SqlWith.NoLock).ToList().ToDictionary(x => x.AutoID, x => x); - List devLst = db.Queryable().With(SqlWith.NoLock).Where(x => SqlFunc.ContainsArray(ids, x.AutoID)).ToList(); + + int[] RootIds = db.Ado.SqlQuery(@" + ;WITH cte + AS(SELECT AutoID + FROM dbo.DeviceRoute + WHERE [Name] = @Name + UNION ALL + SELECT dr.AutoID + FROM dbo.DeviceRoute dr + INNER JOIN cte + ON dr.ParentID = cte.AutoID) + SELECT* + FROM cte", new { Name = "KH" }).ToArray(); + + + List devLst = db.Queryable().With(SqlWith.NoLock).Where(x => SqlFunc.ContainsArray(RootIds, x.Route) && SqlFunc.ContainsArray(ids, x.AutoID)).ToList(); + Datas = Datas.Where(x => devLst.Any(y => y.AutoID == x.EquipmentID)).ToList(); + int[] formIds = devLst.Select(x => x.MaintenanceFormVersion).ToArray(); Dictionary devDict = devLst.ToDictionary(x => x.AutoID, x => x); diff --git a/DeviceRepair.DataAccess/PreserveAccess.cs b/DeviceRepair.DataAccess/PreserveAccess.cs index 1ed7aec..e259da3 100644 --- a/DeviceRepair.DataAccess/PreserveAccess.cs +++ b/DeviceRepair.DataAccess/PreserveAccess.cs @@ -184,11 +184,25 @@ namespace DeviceRepair.DataAccess try { db.ChangeDatabase("main"); + + int[] RootIds = db.Ado.SqlQuery(@" + ;WITH cte + AS(SELECT AutoID + FROM dbo.DeviceRoute + WHERE [Name] = @Name + UNION ALL + SELECT dr.AutoID + FROM dbo.DeviceRoute dr + INNER JOIN cte + ON dr.ParentID = cte.AutoID) + SELECT* + FROM cte", new { Name = "KH" }).ToArray(); + lst = db.Queryable((t1, t2, t3, t4) => new object[] { JoinType.Inner,t1.CreateBy == t2.AutoID, JoinType.Inner,t1.EquipmentPrimaryID == t3.AutoID, JoinType.Inner,t1.FormPrimaryID == t4.AutoID - }).Select((t1, t2, t3, t4) => new View_MaintenanceRecordList + }).Where((t1, t2, t3, t4) => SqlFunc.ContainsArray(RootIds, t3.Route)).Select((t1, t2, t3, t4) => new View_MaintenanceRecordList { AutoID = t1.AutoID, EquipmentID = t3.AutoID, @@ -334,6 +348,11 @@ namespace DeviceRepair.DataAccess if (entity.Record.AutoID == 0) { + if (db.Queryable().Any(x => x.PlanPrimaryID == entity.Record.PlanPrimaryID)) + { + throw new Exception("当前数据已被其他用户录入 "); + } + entity.Record.ModifyDate = CurrentDate; entity.Record.ModifyBy = Operation.Operator; entity.Record.CreateDate = CurrentDate; @@ -406,6 +425,13 @@ namespace DeviceRepair.DataAccess #region 附件写入 //附件写入 + if (entity.Files == null || entity.Files.Count == 0) + { + int cCount = db.Updateable().UpdateColumns(x => new { x.Status }) + .SetColumns(x => x.Status == false) + .Where(x => x.Module == "Attachment" && x.TableName == "MaintenanceRecord" && x.PrimaryKey == "AutoID" && x.PrimaryValue == Identity + "").ExecuteCommand(); + } + foreach (var item in entity.Files) { if (item.AutoID != 0) diff --git a/DeviceRepair.DataAccess/TsSFCAccess.cs b/DeviceRepair.DataAccess/TsSFCAccess.cs index 62f251d..57a5a1d 100644 --- a/DeviceRepair.DataAccess/TsSFCAccess.cs +++ b/DeviceRepair.DataAccess/TsSFCAccess.cs @@ -66,7 +66,7 @@ namespace DeviceRepair.DataAccess List Datas = db.Queryable((t1, t2) => new object[] { JoinType.Left,t1.Post == t2.Guid - }).Select((t1, t2) => t2).ToList(); + }).Where((t1, t2) => t1.UserCode.Equals(UserCode, StringComparison.CurrentCultureIgnoreCase) && t2.Status == "A").Select((t1, t2) => t2).ToList(); int PostType = -1; diff --git a/DeviceRepair.Models/DeviceRepair.Models.csproj b/DeviceRepair.Models/DeviceRepair.Models.csproj index 771dabc..34b4e86 100644 --- a/DeviceRepair.Models/DeviceRepair.Models.csproj +++ b/DeviceRepair.Models/DeviceRepair.Models.csproj @@ -90,6 +90,7 @@ + diff --git a/DeviceRepair.Models/Logs/OperationFilterModel.cs b/DeviceRepair.Models/Logs/OperationFilterModel.cs new file mode 100644 index 0000000..52eff28 --- /dev/null +++ b/DeviceRepair.Models/Logs/OperationFilterModel.cs @@ -0,0 +1,32 @@ +using System; + +namespace DeviceRepair.Models.Logs +{ + public class OperationFilterModel + { + /// + /// 开始时间 + /// + public DateTime sDate { get; set; } + + /// + /// 结束时间 + /// + public DateTime eDate { get; set; } + + /// + /// 用户编号 + /// + public string LoginCode { get; set; } + + /// + /// 操作类型 + /// + public string OperationType { get; set; } + + /// + /// 客户端名称 + /// + public string ClientName { get; set; } + } +} diff --git a/DeviceRepair.Models/Logs/UserLogin.cs b/DeviceRepair.Models/Logs/UserLogin.cs index d87ecc3..ac8b930 100644 --- a/DeviceRepair.Models/Logs/UserLogin.cs +++ b/DeviceRepair.Models/Logs/UserLogin.cs @@ -25,6 +25,9 @@ namespace DeviceRepair.Models.History public string LoginCode { get; set; } + [SugarColumn(IsIgnore = true)] + public string RealName { get; set; } + public string OperationType { get; set; } [SugarColumn(IsOnlyIgnoreInsert = true)] diff --git a/DeviceRepair.Models/Plan/View/View_AnnualMaintenancePlan.cs b/DeviceRepair.Models/Plan/View/View_AnnualMaintenancePlan.cs index 134b9eb..24fb4eb 100644 --- a/DeviceRepair.Models/Plan/View/View_AnnualMaintenancePlan.cs +++ b/DeviceRepair.Models/Plan/View/View_AnnualMaintenancePlan.cs @@ -45,71 +45,96 @@ namespace DeviceRepair.Models [SugarColumn(ColumnName = "Jan")] public string Jan { get; set; } + [SugarColumn(IsIgnore = true)] + public bool JanStatus { get; set; } + /// /// 二月 /// [SugarColumn(ColumnName = "Feb")] public string Feb { get; set; } + [SugarColumn(IsIgnore = true)] + public bool FebStatus { get; set; } /// /// 三月 /// [SugarColumn(ColumnName = "Mar")] public string Mar { get; set; } + [SugarColumn(IsIgnore = true)] + public bool MarStatus { get; set; } /// /// 四月 /// [SugarColumn(ColumnName = "Apr")] public string Apr { get; set; } + [SugarColumn(IsIgnore = true)] + public bool AprStatus { get; set; } /// /// 五月 /// [SugarColumn(ColumnName = "May")] public string May { get; set; } + [SugarColumn(IsIgnore = true)] + public bool MayStatus { get; set; } /// /// 六月 /// [SugarColumn(ColumnName = "Jun")] public string Jun { get; set; } + [SugarColumn(IsIgnore = true)] + public bool JunStatus { get; set; } /// /// 七月 /// [SugarColumn(ColumnName = "Jul")] public string Jul { get; set; } + [SugarColumn(IsIgnore = true)] + public bool JulStatus { get; set; } /// /// 八月 /// [SugarColumn(ColumnName = "Aug")] public string Aug { get; set; } + [SugarColumn(IsIgnore = true)] + public bool AugStatus { get; set; } /// /// 九月 /// [SugarColumn(ColumnName = "Sep")] public string Sep { get; set; } + [SugarColumn(IsIgnore = true)] + public bool SepStatus { get; set; } /// /// 十月 /// [SugarColumn(ColumnName = "Oct")] public string Oct { get; set; } + [SugarColumn(IsIgnore = true)] + public bool OctStatus { get; set; } /// /// 十一月 /// [SugarColumn(ColumnName = "Nov")] public string Nov { get; set; } + [SugarColumn(IsIgnore = true)] + public bool NovStatus { get; set; } /// /// 十二月 /// [SugarColumn(ColumnName = "Dec")] public string Dec { get; set; } + [SugarColumn(IsIgnore = true)] + public bool DecStatus { get; set; } /// /// 新PM起始月份 diff --git a/DeviceRepair.Utils/Enum/EnumMaintenanceTypeHelper.cs b/DeviceRepair.Utils/Enum/EnumMaintenanceTypeHelper.cs index 28b432c..064df90 100644 --- a/DeviceRepair.Utils/Enum/EnumMaintenanceTypeHelper.cs +++ b/DeviceRepair.Utils/Enum/EnumMaintenanceTypeHelper.cs @@ -8,7 +8,7 @@ namespace DeviceRepair.Utils public static EnumMaintenanceType MatchToEnum(string value) { EnumMaintenanceType e = EnumMaintenanceType.None; - switch (value.ToLower()) + switch (value?.ToLower()) { case "annual": case "每年": diff --git a/DeviceRepairAndOptimization/Biz/DeviceManager.cs b/DeviceRepairAndOptimization/Biz/DeviceManager.cs index 67e7d3f..b28317c 100644 --- a/DeviceRepairAndOptimization/Biz/DeviceManager.cs +++ b/DeviceRepairAndOptimization/Biz/DeviceManager.cs @@ -233,5 +233,81 @@ namespace DeviceRepairAndOptimization.Biz } return apiResponseData; } + + + #region PM + + /// + /// KH设备台账数据获取 + /// + /// + /// + public APIResponseData GetQueryKH(string FilterValue) + { + APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "查询失败!" }; + try + { + switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower()) + { + case "api": + apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem + { + URL = $"{ServiceRouteConstValue.GetDeviceQueryKH}?FilterString={FilterValue}", + Method = "Get", + ContentType = "application/json;charset=utf-8", + }); + break; + + default: + apiResponseData = DeviceAccess.Instance.GetQueryKH(FilterValue); + break; + } + } + catch (Exception ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + return apiResponseData; + } + + /// + /// 通过设备编号查询设备信息 + /// + /// + /// + public APIResponseData GetPMDeviceInfoModelByEquipmentID(string EquipmentID) + { + APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" }; + try + { + switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower()) + { + case "api": + + apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem + { + URL = ServiceRouteConstValue.GetPMDeviceInfoModelByEquipmentID + "?EquipmentID=" + EncryptionHelper.UrlEncry(EquipmentID), + Method = "Get", + ContentType = "application/json; charset=utf-8" + }); + break; + case "sql": + apiResponseData = DeviceAccess.Instance.GetPMDeviceInfoModelByEquipmentID(EquipmentID); + break; + default: + break; + } + } + catch (Exception ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + return apiResponseData; + } + + + #endregion } } diff --git a/DeviceRepairAndOptimization/Biz/MaintenanceManager.cs b/DeviceRepairAndOptimization/Biz/MaintenanceManager.cs index 752bb2b..1180bde 100644 --- a/DeviceRepairAndOptimization/Biz/MaintenanceManager.cs +++ b/DeviceRepairAndOptimization/Biz/MaintenanceManager.cs @@ -230,7 +230,7 @@ namespace DeviceRepairAndOptimization.Biz break; default: - apiResponseData = MaintenanceAccess.Instance.GetDatas(FilterInfo); + apiResponseData = MaintenanceAccess.Instance.GetXlsxData(FilterInfo); break; } } diff --git a/DeviceRepairAndOptimization/Biz/OperationManager.cs b/DeviceRepairAndOptimization/Biz/OperationManager.cs new file mode 100644 index 0000000..933bdbd --- /dev/null +++ b/DeviceRepairAndOptimization/Biz/OperationManager.cs @@ -0,0 +1,63 @@ +using CsharpHttpHelper; +using DeviceRepair.DataAccess; +using DeviceRepair.Models; +using DeviceRepair.Models.Logs; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DeviceRepairAndOptimization.Biz +{ + public class OperationManager + { + private static OperationManager manager; + public static OperationManager Instance + { + get + { + if (manager == null) + manager = new OperationManager(); + return manager; + } + } + + /// + /// 用户登录登出日志 + /// + /// + /// + public APIResponseData UserLoginContent(OperationFilterModel FilterInfo) + { + APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" }; + try + { + switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower()) + { + case "api": + apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem + { + URL = ServiceRouteConstValue.UserLoginContent, + Method = "Post", + ContentType = "application/json; charset=utf-8", + Postdata = JsonConvert.SerializeObject(FilterInfo) + }); + break; + case "sql": + apiResponseData = OperationAccess.Instance.UserLoginContent(FilterInfo); + break; + default: + break; + } + } + catch (Exception ex) + { + apiResponseData.Code = -1; + apiResponseData.Message = ex.Message; + } + return apiResponseData; + } + } +} diff --git a/DeviceRepairAndOptimization/Biz/PlanManager.cs b/DeviceRepairAndOptimization/Biz/PlanManager.cs index d8566a7..1744d84 100644 --- a/DeviceRepairAndOptimization/Biz/PlanManager.cs +++ b/DeviceRepairAndOptimization/Biz/PlanManager.cs @@ -187,7 +187,7 @@ namespace DeviceRepairAndOptimization.Biz }); break; default: - apiResponseData = PlanAccess.Instance.GetAllPlans(); + apiResponseData = PlanAccess.Instance.GetDataByEquipmentAutoIdOnYear(Year,EquipmentAutoID); break; } diff --git a/DeviceRepairAndOptimization/Biz/UserManager.cs b/DeviceRepairAndOptimization/Biz/UserManager.cs index ff5d259..0dadd73 100644 --- a/DeviceRepairAndOptimization/Biz/UserManager.cs +++ b/DeviceRepairAndOptimization/Biz/UserManager.cs @@ -1,6 +1,7 @@ using CsharpHttpHelper; using DeviceRepair.DataAccess; using DeviceRepair.Models; +using DeviceRepair.Utils.Security; using Newtonsoft.Json; using System; @@ -197,7 +198,7 @@ namespace DeviceRepairAndOptimization.Biz apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem { - URL = $"{ServiceRouteConstValue.ReprovisionDefaultPassword}?LoginCode={LoginCode}&PassWord={PassWord}", + URL = $"{ServiceRouteConstValue.ReprovisionDefaultPassword}?LoginCode={EncryptionHelper.UrlEncry(LoginCode)}&PassWord={PassWord}", Method = "Post", ContentType = "application/x-www-form-urlencoded", }); @@ -513,11 +514,10 @@ namespace DeviceRepairAndOptimization.Biz URL = $"{ServiceRouteConstValue.GetUserAuthsByUserID}?UserAutoID={UserAutoID}", Method = "Get", ContentType = "application/json; charset=utf-8", - ResultType = CsharpHttpHelper.Enum.ResultType.Byte - }, true); + }, false); break; case "sql": - apiResponseData = UserAccess.Instance.GetAllUsers(); + apiResponseData = RoleAccess.Instance.GetUserAuthsByUserID(UserAutoID); break; default: break; diff --git a/DeviceRepairAndOptimization/DeviceRepairAndOptimization.csproj b/DeviceRepairAndOptimization/DeviceRepairAndOptimization.csproj index fa9e74e..7c235a0 100644 --- a/DeviceRepairAndOptimization/DeviceRepairAndOptimization.csproj +++ b/DeviceRepairAndOptimization/DeviceRepairAndOptimization.csproj @@ -347,6 +347,7 @@ + @@ -381,6 +382,12 @@ + + Form + + + dlgProgressBar.cs + Form @@ -459,6 +466,12 @@ Page_FormVersionDialog.cs + + Form + + + page_UserLoginLog.cs + Form @@ -667,6 +680,9 @@ frm_Launch.cs + + dlgProgressBar.cs + pageFieldCode.cs @@ -706,6 +722,9 @@ Page_FormVersionDialog.cs + + page_UserLoginLog.cs + dlgAccessoriesEdit.cs diff --git a/DeviceRepairAndOptimization/Labels/DeviceMaintenance.frx b/DeviceRepairAndOptimization/Labels/DeviceMaintenance.frx index ffc992a..b2aef39 100644 --- a/DeviceRepairAndOptimization/Labels/DeviceMaintenance.frx +++ b/DeviceRepairAndOptimization/Labels/DeviceMaintenance.frx @@ -1,163 +1,155 @@  - +