diff --git a/.gitignore b/.gitignore index e84c9d1..2af6ce7 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,8 @@ bld/ .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot #wwwroot/ +wwwroot/upload + # Visual Studio 2017 auto generated files Generated\ Files/ @@ -338,4 +340,5 @@ ASALocalRun/ # BeatPulse healthcheck temp database healthchecksdb -/SolarPower/wwwroot/js/bower_components + + diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index a0f1a6f..93560f4 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -680,6 +680,50 @@ namespace SolarPower.Controllers return apiResult; } + public async Task> DeleteOperationRecodeFile(PostOperationRecodeIdAndSelectedId post) + { + ApiResult apiResult = new ApiResult(); + + OperationRecode operationRecode = null; + OperationRecodeFile operationRecodeFile = null; + + try + { + operationRecode = await operationRepository.GetOneOperationRecodeAsync(post.ReocdeId); + + if (operationRecode == null) + { + apiResult.Code = "9989"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + operationRecodeFile = await operationRepository.GetOneOperationRecodeFileAsync(post.SelectedId); + + if (operationRecodeFile == null) + { + apiResult.Code = "9988"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + await operationRepository.DeleteOneOperationRecodeFile(post.SelectedId); + + apiResult.Code = "0000"; + apiResult.Msg = "刪除成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + string json = System.Text.Json.JsonSerializer.Serialize(post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + public async Task>> ExportOperationRecodeExcel(PostOperationRecodeFilter post) { ApiResult> apiResult = new ApiResult>(); diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 10e6a89..faf03fe 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -250,7 +250,7 @@ namespace SolarPower.Controllers var tempSerialNumber = GetLastSerialNumber(currentSerialNumber); - var codeFormat = "{0}-{1}-{2}"; + var codeFormat = "{0}{1}{2}"; powerStation = new PowerStation() { diff --git a/SolarPower/Controllers/UserController.cs b/SolarPower/Controllers/UserController.cs index 8c133cb..cae29c4 100644 --- a/SolarPower/Controllers/UserController.cs +++ b/SolarPower/Controllers/UserController.cs @@ -296,6 +296,15 @@ namespace SolarPower.Controllers } #region 新增使用者 + //判斷帳號 是否已存在 + var exist = userRepository.GetOneByAccountAsync(post.Account); + if(exist != null) + { + apiResult.Code = "9987"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + EDFunction edFunction = new EDFunction(); //隨機產生亂數密碼 diff --git a/SolarPower/DBSchema/solar_power_schema.sql b/SolarPower/DBSchema/solar_power_schema.sql index 1d4cc01..11c524c 100644 --- a/SolarPower/DBSchema/solar_power_schema.sql +++ b/SolarPower/DBSchema/solar_power_schema.sql @@ -484,14 +484,13 @@ CREATE TABLE IF NOT EXISTS `company` ( `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', PRIMARY KEY (`Id`), KEY `IDX_01` (`Deleted`,`Status`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='公司資料'; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='公司資料'; -- 正在傾印表格 solar_power.company 的資料:~-1 rows (近似值) DELETE FROM `company`; /*!40000 ALTER TABLE `company` DISABLE KEYS */; INSERT INTO `company` (`Id`, `Deleted`, `Status`, `Name`, `Logo`, `TaxIDNumber`, `Phone`, `Address`, `RegisterUpperLimit`, `SPStationAmount`, `RelationalDB`, `CreatedBy`, `CreatedAt`, `UpdatedBy`, `UpdatedAt`) VALUES - (1, 0, 1, '大眾電腦', NULL, '20840777', '02-87518751', '臺北市內湖區陽光街300號1至9樓', 100, 0, NULL, 1, '2021-06-14 14:52:20', NULL, '2021-06-14 14:52:37'), - (2, 0, 1, '台積電', '2.png', '11223345', NULL, NULL, 10, 0, 'solar_com_0002', 1, '2021-06-14 17:38:49', NULL, '2021-06-14 17:39:00'); + (1, 0, 1, '大眾電腦', NULL, '20840777', '02-87518751', '臺北市內湖區陽光街300號1至9樓', 100, 0, NULL, 1, '2021-06-14 14:52:20', NULL, '2021-06-14 14:52:37'); /*!40000 ALTER TABLE `company` ENABLE KEYS */; -- 傾印 資料表 solar_power.company_auth_page 結構 @@ -822,6 +821,80 @@ INSERT INTO `variable` (`id`, `name`, `value`, `remark`) VALUES -- 設備流水號 - 2021/6/18 12:21:00 ALTER TABLE `device` ADD COLUMN `SerialNumber` VARCHAR(3) NULL DEFAULT NULL COMMENT '單一設備流水號' COLLATE 'utf8mb4_unicode_ci' AFTER `PowerStationId`; +-- 修改 公司子資料庫的欄位名稱 20210628 +ALTER TABLE `company` + CHANGE COLUMN `RelationalDB` `SiteDB` VARCHAR(50) NULL DEFAULT NULL COMMENT '公司各自資料庫' COLLATE 'utf8mb4_unicode_ci' AFTER `SPStationAmount`; + +-- 創建 定期計畫建立資料表 20210628 +CREATE TABLE `operation_plan_create` ( + `Id` INT(10) NOT NULL AUTO_INCREMENT COMMENT '流水號', + `Deleted` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否刪除, 0:否 1:是', + `PlanId` VARCHAR(50) NULL DEFAULT NULL COMMENT '計畫單號' COLLATE 'utf8mb4_unicode_ci', + `PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號', + `SerialNumber` VARCHAR(4) NULL DEFAULT NULL COMMENT '計畫單號用流水號' COLLATE 'utf8mb4_unicode_ci', + `ScheduleNum` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '排程數字', + `ScheduleType` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT '排程屬性,0:天 1:周 2:月 3:季 4:年', + `WorkDay` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '預期工作天數', + `StartTime` TIMESTAMP NULL DEFAULT NULL COMMENT '開始時間', + `Type` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT '項目, 0:清洗 1:巡檢', + `EmailType` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'email提醒種類,0:當天 1:前一天 2:前兩天 3:前三天', + `Description` MEDIUMTEXT NULL DEFAULT NULL COMMENT '描述' COLLATE 'utf8mb4_unicode_ci', + `CreatedBy` INT(10) NULL DEFAULT '0', + `CreatedAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `UpdatedBy` INT(10) NULL DEFAULT '0', + `UpdatedAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`Id`) USING BTREE, + INDEX `IDX_01` (`Deleted`, `PowerStationId`, `CreatedBy`, `StartTime`, `PlanId`) USING BTREE +) +COMMENT='運維計劃建立' +COLLATE='utf8_general_ci' +ENGINE=InnoDB; + +-- 創建 運維作業記錄資料表 20210628 +CREATE TABLE `operation_record` ( + `Id` INT(10) NOT NULL AUTO_INCREMENT COMMENT '流水號', + `Deleted` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否刪除 0:否 1:是', + `FormId` VARCHAR(20) NULL DEFAULT NULL COMMENT '表單號' COLLATE 'utf8mb4_unicode_ci', + `SerialNumber` VARCHAR(4) NULL DEFAULT NULL COMMENT '表單流水號' COLLATE 'utf8_general_ci', + `PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號', + `WorkType` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '工作項目, 0:清洗 1:巡檢 2:維修', + `ErrorCode` VARCHAR(50) NULL DEFAULT NULL COMMENT '異常代號' COLLATE 'utf8mb4_unicode_ci', + `FixDo` VARCHAR(50) NULL DEFAULT '0' COMMENT '維修項目' COLLATE 'utf8mb4_unicode_ci', + `Status` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '狀態 0:未完成 1:完成 2:未完成-過期 3:完成-過期', + `WorkPersonId` INT(10) NULL DEFAULT '0' COMMENT '工作人員編號', + `StartTime` TIMESTAMP NULL DEFAULT NULL COMMENT '預計開始時間', + `EndTime` TIMESTAMP NULL DEFAULT NULL COMMENT '預計結束時間', + `FinishTime` TIMESTAMP NULL DEFAULT NULL COMMENT '完成時間', + `WorkTime` TIMESTAMP NULL DEFAULT NULL COMMENT '作業時間', + `Notice` MEDIUMTEXT NULL DEFAULT NULL COMMENT '注意事項' COLLATE 'utf8mb4_unicode_ci', + `Description` MEDIUMTEXT NULL DEFAULT NULL COMMENT '結果描述' COLLATE 'utf8mb4_unicode_ci', + `CreatedBy` INT(10) NULL DEFAULT NULL, + `CreatedAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `UpdatedBy` INT(10) NULL DEFAULT NULL, + `UpdatedAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`Id`) USING BTREE, + INDEX `IDX_01` (`Deleted`, `FormId`, `WorkPersonId`) USING BTREE +) +COMMENT='運維作業紀錄' +COLLATE='utf8_general_ci' +ENGINE=InnoDB; + +-- 創建 運維作業記錄檔案資料表 20210628 +CREATE TABLE `operation_record_file` ( + `Id` INT(10) NOT NULL AUTO_INCREMENT, + `Deleted` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否刪除, 0:否 1:是', + `RecordId` INT(10) NULL DEFAULT NULL COMMENT '主表流水號', + `FileName` VARCHAR(100) NULL DEFAULT NULL COMMENT '檔案名稱' COLLATE 'utf8_general_ci', + `CreatedBy` INT(10) UNSIGNED NOT NULL COMMENT '建立者', + `CreatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立時間', + PRIMARY KEY (`Id`) USING BTREE, + INDEX `IDX_01` (`RecordId`, `Deleted`) USING BTREE +) +COMMENT='運維紀錄 檔案 or 圖片' +COLLATE='utf8_general_ci' +ENGINE=InnoDB; + + /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; diff --git a/SolarPower/Models/ErrorCode.cs b/SolarPower/Models/ErrorCode.cs index 26e2197..83ed964 100644 --- a/SolarPower/Models/ErrorCode.cs +++ b/SolarPower/Models/ErrorCode.cs @@ -17,6 +17,8 @@ namespace SolarPower.Models { { "0000", "OK" }, { "0001", "傳入參數錯誤。" }, + { "9987", "該帳號已被註冊,請重新輸入"}, + { "9988", "查無該運維作業記錄檔案"}, { "9989", "查無該運維作業記錄"}, { "9990", "查無該圖片"}, { "9991", "查無該土地房屋資訊"}, diff --git a/SolarPower/Models/Operation.cs b/SolarPower/Models/Operation.cs index fd93849..cf0f372 100644 --- a/SolarPower/Models/Operation.cs +++ b/SolarPower/Models/Operation.cs @@ -299,4 +299,13 @@ namespace SolarPower.Models public string Notice { get; set; } public string Description { get; set; } } + + /// + /// 針對運維作業記錄檔案 + /// + public class PostOperationRecodeIdAndSelectedId + { + public int ReocdeId { get; set; } + public int SelectedId { get; set; } + } } diff --git a/SolarPower/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index 63099ce..5b7e4be 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -429,5 +429,70 @@ namespace SolarPower.Repository.Implement return count; } } + + /// + /// 透過Id,取得單一運維作業記錄檔案 + /// + /// + /// + public async Task GetOneOperationRecodeFileAsync(int id) + { + OperationRecodeFile result; + + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + try + { + var sql = @$"SELECT * + FROM operation_record_file + WHERE Deleted = 0 AND Id = @Id"; + + result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return result; + } + } + + /// + /// 透過Id,軟刪除運維作業記錄檔案 + /// + /// + /// + public async Task DeleteOneOperationRecodeFile(int id) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + var sql = $"UPDATE operation_record_file 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(); + } + } + } + } } } diff --git a/SolarPower/Repository/Interface/IOperationRepository.cs b/SolarPower/Repository/Interface/IOperationRepository.cs index 57d97ef..fcecab3 100644 --- a/SolarPower/Repository/Interface/IOperationRepository.cs +++ b/SolarPower/Repository/Interface/IOperationRepository.cs @@ -53,6 +53,20 @@ namespace SolarPower.Repository.Interface /// /// Task AddOperationRecodeFilesAsync(List entity, List properties); + + /// + /// 透過Id,取得單一運維作業記錄檔案 + /// + /// + /// + Task GetOneOperationRecodeFileAsync(int id); + + /// + /// 透過Id,軟刪除運維作業記錄檔案 + /// + /// + /// + Task DeleteOneOperationRecodeFile(int id); } } diff --git a/SolarPower/Views/Company/Index.cshtml b/SolarPower/Views/Company/Index.cshtml index 3048d38..be3aefa 100644 --- a/SolarPower/Views/Company/Index.cshtml +++ b/SolarPower/Views/Company/Index.cshtml @@ -89,7 +89,7 @@ -