diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index 593ee6a..086dbc0 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -13,20 +13,23 @@ namespace SolarPower.Controllers { public class OperationController : MyBaseController { - private readonly IUserRepository userRepository; private readonly IOperationRepository operationRepository; - private readonly IRoleRepository roleRepository; public OperationController( - IUserRepository userRepository, IOperationRepository operationRepository) : base() { - this.userRepository = userRepository; this.operationRepository = operationRepository; } + public IActionResult Index() { return View(); } + + public IActionResult Record() + { + return View("~/Views/Operation/OperationRecord.cshtml"); + } + /// /// 取得電站Option /// @@ -57,6 +60,7 @@ namespace SolarPower.Controllers return result; } + /// /// 儲存計畫 /// @@ -112,6 +116,7 @@ namespace SolarPower.Controllers apiResult.Msg = errorCode.GetString(apiResult.Code); return apiResult; } + /// /// 定時計畫datatable /// @@ -218,7 +223,7 @@ namespace SolarPower.Controllers return apiResult; } - await operationRepository.DeleteOneOtherTable(Id, "operation_plan_create"); + await operationRepository.DeleteOneByIdWithCustomTable(Id, "operation_plan_create"); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -233,5 +238,56 @@ namespace SolarPower.Controllers return apiResult; } + + + /// + /// 運維作業記錄列表 + /// + /// + /// + [HttpPost] + public async Task OperationRecodeListAsync(PostOperationRecodeFilter post) + { + ApiResult> apiResult = new ApiResult>(); + + int totalRecords = 0; //總資料筆數 + int recFilter = 0; //過濾後資料筆數 + + List recodes = null; + + try + { + + //if (!IsPlatformLayer(myUser.Role.Layer)) + //{ //如果只是身分公司管理員 或 公司使用者,就只能看自己公司的資料 + // post.SelectedCompanyId = myUser.CompanyId; + //} + + recodes = await operationRepository.GetAllRecodeByFilterAsync(post); + + totalRecords = recodes.Count(); + recFilter = recodes.Count(); + + apiResult.Code = "0000"; + apiResult.Data = recodes; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + string json = System.Text.Json.JsonSerializer.Serialize(post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + var result = Json(new + { + recordsTotal = totalRecords, + recordsFiltered = recFilter, + data = apiResult + }); + + return result; + } } } diff --git a/SolarPower/Helper/DatabaseHelper.cs b/SolarPower/Helper/DatabaseHelper.cs index e9aed88..69dbfdc 100644 --- a/SolarPower/Helper/DatabaseHelper.cs +++ b/SolarPower/Helper/DatabaseHelper.cs @@ -37,7 +37,7 @@ namespace SolarPower.Helper var passwordStr = ed.AESDecrypt(dbConfig.Password); //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; - var connStr = @"server=127.0.0.1;port=3308;database=solar_power;user=root;password=00000000;charset=utf8;"; + var connStr = @"server=127.0.0.1;database=solar_power;user=root;password=000000;charset=utf8;"; this._connectionString = connStr; } diff --git a/SolarPower/Models/Operation.cs b/SolarPower/Models/Operation.cs index 4ddacba..3e59c34 100644 --- a/SolarPower/Models/Operation.cs +++ b/SolarPower/Models/Operation.cs @@ -56,4 +56,92 @@ namespace SolarPower.Models public string StartTimeString { get; set; } public string CreateTimeString { get; set; } } + + /// + /// 運維作業記錄的搜尋條件 + /// + public class PostOperationRecodeFilter + { + public List CityIds { get; set; } //縣市編號 + public List PowerStationIds { get; set; } //電站編號 + public byte WorkType { get; set; } //工作項目 + public string Range { get; set; } //取得搜尋範圍 + } + + /// + /// 運維作業記錄的表單 + /// + public class OperationRecodeDataTable + { + private string startTime, endTime, finishTime; + public string PowerStationName { get; set; } //電站名稱 + public string FormId { get; set; } //表單號 + public byte WorkType { get; set; } //工作項目 + public string WorkTypeText { + get + { + Dictionary pairs = new Dictionary() + { + { 0, "清洗"}, + { 1, "巡檢"}, + { 2, "維修"}, + }; + + return pairs[WorkType]; + } + } //工作項目名稱 + public string FixDo { get; set; } //維修項目 + public byte Status { get; set; } //狀態 + public string StatusText { + get + { + Dictionary pairs = new Dictionary() + { + { 0, "未完成"}, + { 1, "完成"}, + { 2, "未完成-過期"}, + { 3, "完成-過期"}, + }; + + return pairs[Status]; + } + } //狀態名稱 + public string WorkPersonName { get; set; } //處理人員 + public string StartTime { + get + { + if (!string.IsNullOrEmpty(startTime)) + { + return Convert.ToDateTime(startTime).ToString("yyyy-MM-dd"); + } + else + { + return null; + } + } + set { startTime = value; } + } //開始時間 + public string EndTime { + get + { + if (!string.IsNullOrEmpty(endTime)) + { + return Convert.ToDateTime(endTime).ToString("yyyy-MM-dd"); + } + else + { + return null; + } + } + set { endTime = value; } + } // 結束時間 + public string OperationPredict { + get + { + return StartTime + " ~ " + EndTime; + } + } //本次作業預計 + public string FileList { get; set; } //本次作業預計 + public string FinishTime { get; set; } //本次作業預計 + } } diff --git a/SolarPower/Repository/Implement/CompanyRepository.cs b/SolarPower/Repository/Implement/CompanyRepository.cs index 3d77eb4..dd96f4f 100644 --- a/SolarPower/Repository/Implement/CompanyRepository.cs +++ b/SolarPower/Repository/Implement/CompanyRepository.cs @@ -578,19 +578,6 @@ namespace SolarPower.Repository.Implement KEY `IDX_01` (`Deleted`,`IsMainDisplay`,`PowerStationId`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站資料'; - -- 傾印 資料表 power_station_operation_personnel 結構 - CREATE TABLE IF NOT EXISTS `power_station_operation_personnel` ( - `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `Deleted` tinyint(4) NOT NULL DEFAULT 0, - `PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '電站編號', - `UserId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '人員編號', - `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', - `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', - PRIMARY KEY (`Id`), - KEY `IDX_01` (`Deleted`), - KEY `IDX_02` (`PowerStationId`,`UserId`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站運維人員'; - -- 傾印 資料表 power_station_single_line_diagram 結構 CREATE TABLE IF NOT EXISTS `power_station_single_line_diagram` ( `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, diff --git a/SolarPower/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index 063c5ad..d7f3115 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -116,5 +116,76 @@ namespace SolarPower.Repository.Implement return result; } } + + /// + /// 透過搜尋條件,查詢過濾後的運維作業記錄 + /// + /// + /// + public async Task> GetAllRecodeByFilterAsync(PostOperationRecodeFilter filter) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = @$"SELECT + ps.Name AS PowerStationName, + opr.FormId, + opr.WorkType, + opr.FixDO, + opr.Status, + u.Name AS WorkPersonName, + opr.StartTime, + opr.EndTime, + opr.FinishTime + FROM operation_record opr + LEFT JOIN power_station ps ON opr.PowerStationId = ps.Id + LEFT JOIN user u ON opr.WorkPersonId = u.ID + WHERE opr.Deleted = 0 + AND ps.CityId IN @CityIds + AND ps.Id IN @PowerStationIds"; + + if (filter.WorkType > 0) + { + sql += @" AND opr.WorkType = @WorkType"; + + if (!string.IsNullOrEmpty(filter.Range)) + { + + } + } + else + { + sql += @" AND opr.WorkType IN (0, 1)"; + sql += @" UNION"; + sql += @" SELECT + ps.Name AS PowerStationName, + opr.FormId, + opr.WorkType, + opr.FixDO, + opr.Status, + u.Name AS WorkPersonName, + opr.StartTime, + opr.EndTime, + opr.FinishTime + FROM operation_record opr + LEFT JOIN power_station ps ON opr.PowerStationId = ps.Id + LEFT JOIN user u ON opr.WorkPersonId = u.ID + WHERE opr.Deleted = 0 + AND ps.CityId IN @CityIds + AND ps.Id IN @PowerStationIds + AND opr.WorkType = 2"; + } + + result = (await conn.QueryAsync(sql, filter)).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } } } diff --git a/SolarPower/Repository/Implement/RepositoryBase.cs b/SolarPower/Repository/Implement/RepositoryBase.cs index 9062bc4..a0a2fe7 100644 --- a/SolarPower/Repository/Implement/RepositoryBase.cs +++ b/SolarPower/Repository/Implement/RepositoryBase.cs @@ -135,6 +135,42 @@ namespace SolarPower.Repository.Implement } } } + + /// + /// 透過table_name、Id,軟刪除指定資料表的單一筆資料 + /// + /// + /// + /// + public virtual async Task DeleteOneByIdWithCustomTable(int id, string table_name) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + var sql = $"UPDATE {table_name} SET Deleted = 1 WHERE Id = @Id"; + + await conn.ExecuteAsync(sql, new { Id = id }, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + + } + } + } + /// /// 透過Id、db_name、table_name,刪除指定的資料庫之資料表的一筆資料 /// diff --git a/SolarPower/Repository/Interface/IOperationRepository.cs b/SolarPower/Repository/Interface/IOperationRepository.cs index 284afb2..3dd0106 100644 --- a/SolarPower/Repository/Interface/IOperationRepository.cs +++ b/SolarPower/Repository/Interface/IOperationRepository.cs @@ -12,6 +12,13 @@ namespace SolarPower.Repository.Interface Task AddOperationPlan(OperationCreatePlan OperationPlan, List properties); Task> OperationPlanTable(List id); Task GetOneOperation(int id); + + /// + /// 透過搜尋條件,查詢過濾後的運維作業記錄 + /// + /// + /// + Task> GetAllRecodeByFilterAsync(PostOperationRecodeFilter filter); } } diff --git a/SolarPower/Repository/Interface/IRepositoryBase.cs b/SolarPower/Repository/Interface/IRepositoryBase.cs index 7107846..2b7f0c8 100644 --- a/SolarPower/Repository/Interface/IRepositoryBase.cs +++ b/SolarPower/Repository/Interface/IRepositoryBase.cs @@ -58,6 +58,14 @@ namespace SolarPower.Repository.Interface /// Task PurgeOneAsync(int id); + /// + /// 透過table_name、Id,軟刪除指定資料表的單一筆資料 + /// + /// + /// + /// + Task DeleteOneByIdWithCustomTable(int id, string table_name); + /// /// 透過Id、db_name、table_name,刪除指定的資料庫之資料表的一筆資料 /// diff --git a/SolarPower/Views/Operation/OperationRecord.cshtml b/SolarPower/Views/Operation/OperationRecord.cshtml new file mode 100644 index 0000000..ecbe6e9 --- /dev/null +++ b/SolarPower/Views/Operation/OperationRecord.cshtml @@ -0,0 +1,515 @@ +@{ + ViewData["MainNum"] = "6"; + ViewData["SubNum"] = "2"; + ViewData["Title"] = "運維作業記錄"; +} + + +
+

+ 運維作業記錄 +

+
+ + +
+
+
+
+
+
+ + + + +
+
+
+ +
+
+
+ +
+
+
+ + +
+ + + + 維修單 + +
+
+ + + + + + + + + + + + + @**@ + + + + @* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *@ + + +
電廠表單號項目類型狀態處理人員本次作業預計照片完成時間功能
新竹巨城站op20210630001維修逆變器異常 +
+ + +
+
王小明2021-03-5 + 修改 + +
新竹巨城站 + + 填寫表單 + + 維修逆變器異常 +
+ + +
+
王小明2021-03-5 + 修改 + +
新竹巨城站 + + 填寫表單 + + 維修逆變器異常 +
+ + +
+
王小明2021-03-5 + 修改 + +
+
+
+
+
+ +@section Scripts{ + +} \ No newline at end of file diff --git a/SolarPower/Views/Shared/_Layout.cshtml b/SolarPower/Views/Shared/_Layout.cshtml index a110fb7..f48f2b3 100644 --- a/SolarPower/Views/Shared/_Layout.cshtml +++ b/SolarPower/Views/Shared/_Layout.cshtml @@ -191,7 +191,7 @@
  • - + 運維作業記錄