From 7e9614c6ad0d2a68e1d9ae51b466a7884ad8bdb3 Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 14 Jun 2021 15:09:16 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E8=B3=87=E6=96=99?= =?UTF-8?q?=E5=BA=AB=E9=80=A3=E7=B7=9A=202.=20=E5=8A=A0=E5=85=A5db=20schem?= =?UTF-8?q?a=203.=20=E4=BF=AE=E6=94=B9=E6=AC=8A=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/.config/dotnet-tools.json | 5 + SolarPower/Controllers/CompanyController.cs | 71 ++++-- SolarPower/Controllers/MyBaseController.cs | 10 +- SolarPower/Controllers/RoleController.cs | 39 ++- SolarPower/Controllers/UserController.cs | 13 +- SolarPower/DBSchema/solar_power_schema.sql | 240 ++++++++++++++++++ SolarPower/Helper/DatabaseHelper.cs | 19 +- SolarPower/Models/MyBaseModel.cs | 3 +- SolarPower/Models/Role.cs | 1 + SolarPower/Models/Share.cs | 10 +- .../Repository/Implement/CompanyRepository.cs | 9 +- .../Interface/ICompanyRepository.cs | 2 +- SolarPower/SolarPower.csproj | 1 + SolarPower/Views/Company/Index.cshtml | 55 ++-- SolarPower/Views/User/Index.cshtml | 211 ++++----------- SolarPower/Views/User/_RoleAuth.cshtml | 9 +- SolarPower/appsettings.Development.json | 15 +- SolarPower/appsettings.json | 16 +- SolarPower/wwwroot/upload/company_logo/1.png | Bin 0 -> 2650 bytes SolarPower/wwwroot/upload/company_logo/2.png | Bin 907 -> 3996 bytes 20 files changed, 484 insertions(+), 245 deletions(-) create mode 100644 SolarPower/.config/dotnet-tools.json create mode 100644 SolarPower/DBSchema/solar_power_schema.sql create mode 100644 SolarPower/wwwroot/upload/company_logo/1.png diff --git a/SolarPower/.config/dotnet-tools.json b/SolarPower/.config/dotnet-tools.json new file mode 100644 index 0000000..b0e38ab --- /dev/null +++ b/SolarPower/.config/dotnet-tools.json @@ -0,0 +1,5 @@ +{ + "version": 1, + "isRoot": true, + "tools": {} +} \ No newline at end of file diff --git a/SolarPower/Controllers/CompanyController.cs b/SolarPower/Controllers/CompanyController.cs index 95dcf38..9d75961 100644 --- a/SolarPower/Controllers/CompanyController.cs +++ b/SolarPower/Controllers/CompanyController.cs @@ -27,8 +27,6 @@ namespace SolarPower.Controllers this.companyRepository = companyRepository; this.roleRepository = roleRepository; - var xxx = Directory.GetCurrentDirectory(); - logoSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "company_logo"); } @@ -48,7 +46,16 @@ namespace SolarPower.Controllers try { - var companySelectItemLists = await companyRepository.GetCompanySelectOptionListAsync(); + var companySelectItemLists = new List(); + + if (myUser.IsGod != 1 && !IsPlatformLayer(myUser.Role.Layer)) + { + companySelectItemLists = await companyRepository.GetCompanySelectOptionListAsync(myUser.CompanyId); + } + else + { + companySelectItemLists = await companyRepository.GetCompanySelectOptionListAsync(0); + } apiResult.Code = "0000"; apiResult.Data = companySelectItemLists; @@ -81,7 +88,7 @@ namespace SolarPower.Controllers try { - if(myUser.IsGod != 1 && !IsPlatformLayer(myUser.Role.Layer)) + if (myUser.IsGod != 1 && !IsPlatformLayer(myUser.Role.Layer)) { //如果只是身分公司管理員 或 公司使用者,就只能看自己公司的資料 post.SelectedCompanyId = myUser.CompanyId; } @@ -165,9 +172,9 @@ namespace SolarPower.Controllers apiResult.Msg = errorCode.GetString(apiResult.Code); return apiResult; } - else if(company.Id != myUser.CompanyId) + else if (company.Id != myUser.CompanyId) { - if(myUser.IsGod != 0 && !IsPlatformLayer(myUser.Role.Layer)) + if (myUser.IsGod != 0 && !IsPlatformLayer(myUser.Role.Layer)) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -175,6 +182,16 @@ namespace SolarPower.Controllers } } + //替換logo src + if (!string.IsNullOrEmpty(company.Logo)) + { + company.Logo = logoPath + company.Logo; + } + else + { + company.Logo = logoPath + "default.png"; + } + apiResult.Code = "0000"; apiResult.Data = company; @@ -515,29 +532,31 @@ namespace SolarPower.Controllers #region 新增公司權限池 //找出要新增的 - List insertCompanyAuthStrs = post.CheckAuths.Where(x => !origCompanyAuths.Select(y => y.AuthCode).Contains(x)).ToList(); - - List insertCompanyAuths = new List(); - - foreach (var checkAuth in insertCompanyAuthStrs) + if (post.CheckAuths != null) { - CompanyAuth companyAuth = new CompanyAuth(); - companyAuth.CompanyId = company.Id; - companyAuth.AuthCode = checkAuth; - companyAuth.CreatedBy = myUser.Id; + List insertCompanyAuthStrs = post.CheckAuths.Where(x => !origCompanyAuths.Select(y => y.AuthCode).Contains(x)).ToList(); - insertCompanyAuths.Add(companyAuth); + List insertCompanyAuths = new List(); + + foreach (var checkAuth in insertCompanyAuthStrs) + { + CompanyAuth companyAuth = new CompanyAuth(); + companyAuth.CompanyId = company.Id; + companyAuth.AuthCode = checkAuth; + companyAuth.CreatedBy = myUser.Id; + + insertCompanyAuths.Add(companyAuth); + } + + List properties = new List() + { + "CompanyId", + "AuthCode", + "CreatedBy", + }; + + await companyRepository.AddCompanyAuthAsync(insertCompanyAuths, properties); } - - List properties = new List() - { - "CompanyId", - "AuthCode", - "CreatedBy", - }; - - await companyRepository.AddCompanyAuthAsync(insertCompanyAuths, properties); - #endregion apiResult.Code = "0000"; diff --git a/SolarPower/Controllers/MyBaseController.cs b/SolarPower/Controllers/MyBaseController.cs index 0bbaa4a..f237307 100644 --- a/SolarPower/Controllers/MyBaseController.cs +++ b/SolarPower/Controllers/MyBaseController.cs @@ -89,10 +89,16 @@ namespace SolarPower.Controllers { ControllerName = controllerName, ActionName = actionName, - Parameter = content.CompareTo("{}") == 0? null : content, + Parameter = content.CompareTo("{}") == 0 ? null : content, CreatedBy = myUser.Id, }; + List removeParam = new List() { "ChangePassword" }; //移除不紀錄參數的actionName + if (removeParam.Any(x => actionName.Contains(x))) + { + operatorLog.Parameter = "{}"; + } + List properties = new List() { "ControllerName", @@ -111,7 +117,7 @@ namespace SolarPower.Controllers /// public bool IsPlatformLayer(byte roleLayer) { - if(roleLayer == (int)RoleLayerEnum.PlatformAdmin || roleLayer == (int)RoleLayerEnum.PlatformUser) + if (roleLayer == (int)RoleLayerEnum.PlatformAdmin || roleLayer == (int)RoleLayerEnum.PlatformUser) { return true; } diff --git a/SolarPower/Controllers/RoleController.cs b/SolarPower/Controllers/RoleController.cs index 92c0b77..471e630 100644 --- a/SolarPower/Controllers/RoleController.cs +++ b/SolarPower/Controllers/RoleController.cs @@ -69,6 +69,19 @@ namespace SolarPower.Controllers totalRecords = roles.Count(); recFilter = roles.Count(); + foreach(var role in roles) + { + if(role.Layer == (int)RoleLayerEnum.PlatformAdmin || role.Layer == (int)RoleLayerEnum.CompanyAdmin) + { //管理階層的角色無法被刪除 + role.Function = ""; + } + else + { + role.Function = @" + "; + } + } + apiResult.Code = "0000"; apiResult.Data = roles; } @@ -156,15 +169,31 @@ namespace SolarPower.Controllers return apiResult; } + + if(myUser.IsGod != 1 && !IsPlatformLayer(myUser.Role.Layer) && myUser.CompanyId != post.SelectedCompanyId) + { //非超級使用者或平台人員,就只能新增自己公司的角色 + apiResult.Code = "9993"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + #region 新增公司角色 role = new Role() { CompanyId = post.SelectedCompanyId, Name = post.Name, - Layer = 3, CreatedBy = myUser.Id, }; + if (IsPlatformLayer(myUser.Role.Layer)) + { //平台新增角色 Layer,為平台使用者階層 + role.Layer = 1; + } + else + { //公司新增角色 Layer,為公司使用者階層 + role.Layer = 3; + } + List properties = new List() { "CompanyId", @@ -182,6 +211,14 @@ namespace SolarPower.Controllers else { #region 修改公司角色 + + if (myUser.IsGod != 1 && !IsPlatformLayer(myUser.Role.Layer) && myUser.CompanyId != post.SelectedCompanyId) + { //非超級使用者或平台人員,就只能修改自己公司的角色 + apiResult.Code = "9993"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + UpdateRole update = new UpdateRole() { Id = post.Id, diff --git a/SolarPower/Controllers/UserController.cs b/SolarPower/Controllers/UserController.cs index 09f8784..ea85dc8 100644 --- a/SolarPower/Controllers/UserController.cs +++ b/SolarPower/Controllers/UserController.cs @@ -20,6 +20,7 @@ namespace SolarPower.Controllers { private readonly IUserRepository userRepository; + private string logoPath = "/upload/company_logo/"; public UserController(IUserRepository userRepository) : base() { this.userRepository = userRepository; @@ -175,7 +176,7 @@ namespace SolarPower.Controllers { apiResult.Code = "9999"; string json = System.Text.Json.JsonSerializer.Serialize(post); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】"); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } @@ -293,13 +294,21 @@ namespace SolarPower.Controllers #region 新增使用者 EDFunction edFunction = new EDFunction(); + //隨機產生亂數密碼 + Random random = new Random((int)DateTime.Now.Ticks); + const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789"; + string random_password = new string(Enumerable.Repeat(chars, 8).Select(s => s[random.Next(chars.Length)]).ToArray()); + + //TODO 新增的密碼要寄信 + random_password = edFunction.GetSHA256Encryption(random_password); + user = new User() { CompanyId = post.CompanyId, Name = post.Name, Email = post.Email, Account = post.Account, - Password = edFunction.GetSHA256Encryption(post.Account), + Password = random_password, RoleId = post.RoleId, Phone = post.Phone, CreatedBy = myUser.Id, diff --git a/SolarPower/DBSchema/solar_power_schema.sql b/SolarPower/DBSchema/solar_power_schema.sql new file mode 100644 index 0000000..c2cb5b1 --- /dev/null +++ b/SolarPower/DBSchema/solar_power_schema.sql @@ -0,0 +1,240 @@ +-- -------------------------------------------------------- +-- 主機: 127.0.0.1 +-- 伺服器版本: 10.5.6-MariaDB - mariadb.org binary distribution +-- 伺服器作業系統: Win64 +-- HeidiSQL 版本: 11.2.0.6213 +-- -------------------------------------------------------- + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET NAMES utf8 */; +/*!50503 SET NAMES utf8mb4 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + + +-- 傾印 solar_power 的資料庫結構 +CREATE DATABASE IF NOT EXISTS `solar_power` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */; +USE `solar_power`; + +-- 傾印 資料表 solar_power.auth_page 結構 +CREATE TABLE IF NOT EXISTS `auth_page` ( + `AuthCode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, + `MainName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '大項名稱', + `SubName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '功能名稱', + `ControlName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`AuthCode`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='設定權限頁面'; + +-- 正在傾印表格 solar_power.auth_page 的資料:~-1 rows (近似值) +DELETE FROM `auth_page`; + + +-- 傾印 資料表 solar_power.company 結構 +CREATE TABLE IF NOT EXISTS `company` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除,0:否 1:是', + `Status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '狀態,0:凍結 1:正常', + `Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '公司名稱', + `Logo` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '公司logo', + `TaxIDNumber` varchar(8) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '統一編號', + `Phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電話', + `Address` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址', + `RegisterUpperLimit` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '註冊上限', + `SPStationAmount` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '太陽能電站數量', + `RelationalDB` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '公司各自資料庫', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', + PRIMARY KEY (`Id`), + KEY `IDX_01` (`Deleted`,`Status`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='公司資料'; + +-- 正在傾印表格 solar_power.company 的資料:~-1 rows (近似值) +DELETE FROM `company`; +/*!40000 ALTER TABLE `company` DISABLE KEYS */; +/*!40000 ALTER TABLE `company` ENABLE KEYS */; + +-- 傾印 資料表 solar_power.company_auth_page 結構 +CREATE TABLE IF NOT EXISTS `company_auth_page` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `CompanyId` int(10) unsigned NOT NULL, + `AuthCode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `CreatedBy` int(10) unsigned DEFAULT NULL, + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`Id`), + KEY `IDX_01` (`CompanyId`,`AuthCode`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='公司擁有的權限池'; + +-- 正在傾印表格 solar_power.company_auth_page 的資料:~-1 rows (近似值) +DELETE FROM `company_auth_page`; +/*!40000 ALTER TABLE `company_auth_page` DISABLE KEYS */; +/*!40000 ALTER TABLE `company_auth_page` ENABLE KEYS */; + +-- 傾印 資料表 solar_power.operator_log 結構 +CREATE TABLE IF NOT EXISTS `operator_log` ( + `Id` bigint(19) unsigned NOT NULL AUTO_INCREMENT, + `ControllerName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `ActionName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `Parameter` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `CreatedBy` int(10) unsigned DEFAULT NULL, + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`Id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='操作紀錄'; + + +-- 傾印 資料表 solar_power.power_station 結構 +CREATE TABLE IF NOT EXISTS `power_station` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', + `CompanyId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '公司編號', + `Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名稱', + `Code` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電站代碼,縣市+區域+流水號 ', + `IsEscrow` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否為代管,0:否 1:是', + `EscrowName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '代管名稱', + `ElectricityMeterAt` timestamp NULL DEFAULT NULL COMMENT '台電掛錶日', + `EstimatedRecoveryTime` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '預估回收時間', + `GeneratingCapacity` decimal(10,1) NOT NULL DEFAULT 0.0 COMMENT '電廠發電容量,單位(千瓦)', + `PowerRate` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '受電費率', + `Coordinate` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '座標', + `InverterBrand` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逆變器廠牌', + `InverterProductModel` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逆變器型號', + `InverterAmount` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '逆變器數量', + `PhotovoltaicPanelBrand` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '光電板廠牌', + `PhotovoltaicPanelProductModel` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '光電板型號', + `PhotovoltaicPanelSpecification` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '光電板規格', + `PhotovoltaicPanelAmount` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '光電板數量', + `BoEFile` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '能源局檔案', + `BoEDiscountRate` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '能源局折扣率', + `BoEDeviceRegisterNumber` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '能源局設備登記編號', + `BoERentRatio` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '能源局租金比率,單位(%)', + `TPCContractNumber` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '台電契約編號', + `TPCContractAt` timestamp NULL DEFAULT NULL COMMENT '台電簽約日期', + `TPCSellDeadline` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '台電售電期限,單位(年)', + `TPCMeterReading` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '台電每期抄錶日', + `TPCPurchaseElectricityAt` timestamp NULL DEFAULT NULL COMMENT '台電正式購電日', + `TPCSellElectricityAt` timestamp NULL DEFAULT NULL COMMENT '台電正式售電日', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', + PRIMARY KEY (`Id`), + KEY `IDX_01` (`Deleted`), + KEY `IDX_02` (`CompanyId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站資料'; + +-- 正在傾印表格 solar_power.power_station 的資料:~-1 rows (近似值) +DELETE FROM `power_station`; +/*!40000 ALTER TABLE `power_station` DISABLE KEYS */; +/*!40000 ALTER TABLE `power_station` ENABLE KEYS */; + +-- 傾印 資料表 solar_power.role 結構 +CREATE TABLE IF NOT EXISTS `role` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', + `CompanyId` int(10) NOT NULL, + `Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '角色名稱', + `Layer` tinyint(4) NOT NULL DEFAULT -1 COMMENT '角色層級,0:平台(FIC)超級使用者 1:平台(FIC)使用者 2:公司管理員 3:公司一般人員', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', + PRIMARY KEY (`Id`), + KEY `IDX_01` (`Deleted`), + KEY `IDX_02` (`CompanyId`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='角色資料'; + +-- 正在傾印表格 solar_power.role 的資料:~-1 rows (近似值) +DELETE FROM `role`; +/*!40000 ALTER TABLE `role` DISABLE KEYS */; +/*!40000 ALTER TABLE `role` ENABLE KEYS */; + +-- 傾印 資料表 solar_power.role_auth 結構 +CREATE TABLE IF NOT EXISTS `role_auth` ( + `Id` int(10) unsigned NOT NULL, + `AuthCode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + PRIMARY KEY (`Id`,`AuthCode`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='角色權限'; + +-- 正在傾印表格 solar_power.role_auth 的資料:~-1 rows (近似值) +DELETE FROM `role_auth`; +/*!40000 ALTER TABLE `role_auth` DISABLE KEYS */; +/*!40000 ALTER TABLE `role_auth` ENABLE KEYS */; + +-- 傾印 資料表 solar_power.user 結構 +CREATE TABLE IF NOT EXISTS `user` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否刪除, 0:否 1:是', + `Status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '狀態,0:凍結 1:正常', + `Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '姓名', + `Account` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '帳號', + `Password` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '密碼', + `IsGod` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT '是否為超級使用者。1:是;0:否', + `CompanyId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '公司編號', + `DepartmentId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '部門編號', + `RoleId` int(10) unsigned DEFAULT 0 COMMENT '權限角色編號', + `JobTitle` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '職稱', + `Phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '手機', + `Tel` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '市話', + `Email` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電子信箱', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT '修改時間', + PRIMARY KEY (`Id`) USING BTREE, + KEY `IDX_01` (`Deleted`,`Status`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='使用者資料表'; + +-- 正在傾印表格 solar_power.user 的資料:~-1 rows (近似值) +DELETE FROM `user`; +/*!40000 ALTER TABLE `user` DISABLE KEYS */; + + +-- 傾印 資料表 solar_power.variable 結構 +CREATE TABLE IF NOT EXISTS `variable` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '變數名稱', + `value` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '變數內容值', + `remark` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '備註', + PRIMARY KEY (`id`), + KEY `IDX_01` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='設定變數'; + +-- 正在傾印表格 solar_power.variable 的資料:~-1 rows (近似值) +DELETE FROM `variable`; +/*!40000 ALTER TABLE `variable` DISABLE KEYS */; +/*!40000 ALTER TABLE `variable` ENABLE KEYS */; + +/*!40000 ALTER TABLE `auth_page` DISABLE KEYS */; +INSERT INTO `auth_page` (`AuthCode`, `MainName`, `SubName`, `ControlName`) VALUES + ('A', '系統管理', '帳號管理', 'User,Role'), + ('B', '系統管理', '公司管理', 'Company'), + ('C', '系統管理', '電站資料管理', 'AAA'), + ('D', '系統管理', '定時任務設定', 'Setting'), + ('E', '系統管理', '功能清單', 'ASDA'), + ('F', '總覽', '地圖總覽', 'BBB'), + ('G', '總攬', '電占總覽', 'CCC'), + ('H', '總覽', '運為總覽', 'HHH'), + ('J', '即時告警', '即時告警', 'JJJ'), + ('K', '交叉分析', '逆變器', 'KKK'), + ('L', '交叉分析', '電站運轉效率', 'LLL'); +/*!40000 ALTER TABLE `auth_page` ENABLE KEYS */; + +INSERT INTO `user` (`Id`, `Deleted`, `Status`, `Name`, `Account`, `Password`, `IsGod`, `CompanyId`, `DepartmentId`, `RoleId`, `JobTitle`, `Phone`, `Tel`, `Email`, `CreatedBy`, `CreatedAt`, `UpdatedBy`, `UpdatedAt`) VALUES + (1, 0, 1, '野原新之助', 'admin', 'Ki4SV2TZiQbvDjdEVLNMmVkJfZC9VyTh88DmLSXP+Iw=', 1, 1, 0, 1, NULL, '0987987987', NULL, 'god@admin.com', 1, '2021-06-07 19:19:08', NULL, '2021-06-13 19:08:22'); +/*!40000 ALTER TABLE `user` ENABLE KEYS */; + +-- 新增FIC平台公司 +INSERT INTO `solar_power`.`company` (`Name`, `TaxIDNumber`, `Phone`, `Address`, `RegisterUpperLimit`, `CreatedBy`) VALUES ('大眾電腦', '20840777', '02-87518751', '臺北市內湖區陽光街300號1至9樓', '100', '1'); + +-- 新增平台管理員角色 +INSERT INTO `solar_power`.`role` (`CompanyId`, `Name`, `Layer`, `CreatedBy`) VALUES ('1', '平台管理員', '0', '1'); + + +/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; +/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */; diff --git a/SolarPower/Helper/DatabaseHelper.cs b/SolarPower/Helper/DatabaseHelper.cs index f5da87f..0894d69 100644 --- a/SolarPower/Helper/DatabaseHelper.cs +++ b/SolarPower/Helper/DatabaseHelper.cs @@ -31,20 +31,13 @@ namespace SolarPower.Helper { EDFunction ed = new EDFunction(); - var serverStr1 = ed.AESEncrypt(dbConfig.Server); - var databaseStr1 = ed.DESEncrypt(dbConfig.Database); - var rootStr1 = ed.DESEncrypt(dbConfig.Root); - var passwordStr1 = ed.DESEncrypt(dbConfig.Password); + var serverStr = ed.AESDecrypt(dbConfig.Server); + var databaseStr = ed.DESDecrypt(dbConfig.Database); + var rootStr = ed.DESDecrypt(dbConfig.Root); + var passwordStr = ed.DESDecrypt(dbConfig.Password); - var serverStr = ed.AESDecrypt(serverStr1); - var databaseStr = ed.DESDecrypt(databaseStr1); - var rootStr = ed.DESDecrypt(rootStr1); - var passwordStr = ed.DESDecrypt(passwordStr1); - - //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; - var connStr = $"server=127.0.0.1;database=solar_power;user=root;password=000000;charset=utf8;"; - - //var connStr = @"data source=127.0.0.1;initial catalog=SolarPower;integrated security=true;"; + var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};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/MyBaseModel.cs b/SolarPower/Models/MyBaseModel.cs index 72cee8f..7ac2dbd 100644 --- a/SolarPower/Models/MyBaseModel.cs +++ b/SolarPower/Models/MyBaseModel.cs @@ -49,10 +49,11 @@ namespace SolarPower.Models /// public class MyCompany { + private string logo; public int Id { get; set; } public byte Status { get; set; } //狀態 public string Name { get; set; } //名稱 - public string Logo { get; set; } + public string Logo { get { return "/upload/company_logo/" + logo; } set { logo = value; } } } //當前登入使用者的角色權限 diff --git a/SolarPower/Models/Role.cs b/SolarPower/Models/Role.cs index dcf78bd..15223d3 100644 --- a/SolarPower/Models/Role.cs +++ b/SolarPower/Models/Role.cs @@ -29,6 +29,7 @@ namespace SolarPower.Models.Role { public string CompanyName { get; set; } public string CreatorName { get; set; } + public string Function { get; set; } } /// diff --git a/SolarPower/Models/Share.cs b/SolarPower/Models/Share.cs index a08b94c..1bccedd 100644 --- a/SolarPower/Models/Share.cs +++ b/SolarPower/Models/Share.cs @@ -15,12 +15,12 @@ namespace SolarPower.Models /// public class EDFunction { - const string SHA256_KEY = "SHA256_KEY"; //自訂金鑰 - const string DES_KEY = "SUMT_KEY"; //DES_KEY金鑰(8位字元) - const string DES_IV = "SUMMT_IV"; //DES_IV初始化向量字串(8位字元) + const string SHA256_KEY = "REWOPRALOS"; //自訂金鑰 + const string DES_KEY = "RALOSKEY"; //DES_KEY金鑰(8位字元) + const string DES_IV = "RALOS_IV"; //DES_IV初始化向量字串(8位字元) - const string AES_KEY = "SUMT_KEY"; //AES_KEY金鑰 - const string AES_IV = "SUMMT_IV"; //AES_IV初始化向量字串 + const string AES_KEY = "RALOSKEY"; //AES_KEY金鑰 + const string AES_IV = "RALOS_IV"; //AES_IV初始化向量字串 /// /// 單向加密SHA256 diff --git a/SolarPower/Repository/Implement/CompanyRepository.cs b/SolarPower/Repository/Implement/CompanyRepository.cs index d5f4109..a1db8f8 100644 --- a/SolarPower/Repository/Implement/CompanyRepository.cs +++ b/SolarPower/Repository/Implement/CompanyRepository.cs @@ -26,7 +26,7 @@ namespace SolarPower.Repository.Implement /// /// /// - public async Task> GetCompanySelectOptionListAsync() + public async Task> GetCompanySelectOptionListAsync(int companyId = 0) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -35,7 +35,12 @@ namespace SolarPower.Repository.Implement { var sql = $"SELECT Id AS Value, Name AS Text FROM {tableName} WHERE Deleted = 0"; - result = (await conn.QueryAsync(sql)).ToList(); + if(companyId > 0) + { + sql += " AND Id = @SelectedCompanyId"; + } + + result = (await conn.QueryAsync(sql, new { SelectedCompanyId = companyId})).ToList(); } catch (Exception exception) { diff --git a/SolarPower/Repository/Interface/ICompanyRepository.cs b/SolarPower/Repository/Interface/ICompanyRepository.cs index 2ce4dc5..2491197 100644 --- a/SolarPower/Repository/Interface/ICompanyRepository.cs +++ b/SolarPower/Repository/Interface/ICompanyRepository.cs @@ -30,7 +30,7 @@ namespace SolarPower.Repository.Interface /// /// /// - Task> GetCompanySelectOptionListAsync(); + Task> GetCompanySelectOptionListAsync(int companyId); /// /// 透過搜尋條件,查詢過濾後的公司 diff --git a/SolarPower/SolarPower.csproj b/SolarPower/SolarPower.csproj index 86fdf2c..cc2bb36 100644 --- a/SolarPower/SolarPower.csproj +++ b/SolarPower/SolarPower.csproj @@ -4,6 +4,7 @@ netcoreapp3.1 SolarPower SolarPower + 9c9a93c3-c4f5-4cc2-92ea-0ae0a51be5d3 diff --git a/SolarPower/Views/Company/Index.cshtml b/SolarPower/Views/Company/Index.cshtml index f4de9ab..41de1b3 100644 --- a/SolarPower/Views/Company/Index.cshtml +++ b/SolarPower/Views/Company/Index.cshtml @@ -3,6 +3,8 @@ ViewData["SubNum"] = "2"; ViewData["Title"] = "客戶公司管理"; } +@using SolarPower.Models.Role +@model RoleLayerEnum