1. 創建公司,加入創建公司資料庫

2. 修改圖片cache
This commit is contained in:
Kai 2021-06-14 18:03:14 +08:00
parent cf765a6699
commit 272b31a537
7 changed files with 235 additions and 15 deletions

View File

@ -114,10 +114,19 @@ namespace SolarPower.Controllers
if (myUser.IsGod == 1 || IsPlatformLayer(myUser.Role.Layer))
{ //只有超級使用者 及 平台 可以使用
company.Function = @"
<button type='button' class='btn btn-success btn-pills waves-effect waves-themed company-auth-btn'></button>
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'></button>
<button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'></button>";
if(company.Id == 1)
{ //平台公司不能被刪
company.Function = @"
<button type='button' class='btn btn-success btn-pills waves-effect waves-themed company-auth-btn'></button>
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'></button>";
}
else
{
company.Function = @"
<button type='button' class='btn btn-success btn-pills waves-effect waves-themed company-auth-btn'></button>
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'></button>
<button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'></button>";
}
}
else
{
@ -271,6 +280,8 @@ namespace SolarPower.Controllers
var id = await companyRepository.AddOneAsync(company, properties);
UpdateCompany updateCompany;
//處裡公司Logo圖片
if (post.LogoFile != null)
{
@ -284,7 +295,7 @@ namespace SolarPower.Controllers
post.LogoFile.CopyTo(stream);
}
UpdateCompany updateCompany = new UpdateCompany()
updateCompany = new UpdateCompany()
{
Id = id,
Logo = fileName
@ -319,7 +330,26 @@ namespace SolarPower.Controllers
await roleRepository.AddAsync(role, roleProperties);
#endregion
//TODO 自動新增公司DB及Table公司DB編號規則 solar_com_(公司編號共四碼)exsolar_com_0001。
#region DB及TableDB編號規則 solar_com_()exsolar_com_0001
var relationalDB = "solar_com_" + id.ToString().Trim().PadLeft(4, '0');
//修改
updateCompany = new UpdateCompany()
{
Id = id,
RelationalDB = relationalDB
};
properties = new List<string>()
{
"Id",
"RelationalDB"
};
await companyRepository.UpdateCompany(updateCompany, properties);
await companyRepository.CreatCompanyDB(relationalDB);
#endregion
apiResult.Code = "0000";
apiResult.Msg = "儲存成功";

View File

@ -51,6 +51,7 @@ namespace SolarPower.Models.Company
public string TaxIDNumber { get; set; } //統一編號
public string Phone { get; set; } //電話
public string Address { get; set; }
public string RelationalDB { get; set; } //關聯的公司自己資料庫
public int RegisterUpperLimit { get; set; } //註冊上限
}

View File

@ -409,5 +409,181 @@ namespace SolarPower.Repository.Implement
return count;
}
}
/// <summary>
/// 創建公司自己的DB
/// </summary>
/// <param name="dbName"></param>
/// <returns></returns>
public async Task CreatCompanyDB(string dbName)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var sql = @$"
--
CREATE DATABASE IF NOT EXISTS `{dbName}`;
USE `{dbName}`;
-- device
CREATE TABLE IF NOT EXISTS `device` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT ' 0: 1:',
`UID` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT ' ++(0001~9999)+(3) + SN(3)',
`PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '',
`Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`Type` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`Brand` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`ProductModel` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`DBName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`TableName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`ColName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`Remark` text COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`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`) USING BTREE,
KEY `IDX_02` (`UID`,`PowerStationId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='';
-- land_building
CREATE TABLE IF NOT EXISTS `land_building` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT ' 0: 1:',
`PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '',
`Address` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`LeaseNotarizationAt` timestamp NULL DEFAULT NULL COMMENT '',
`Landowner` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`Purpose` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`LeaseRate` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '(%)',
`Coordinate` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`phone` varchar(20) 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`,`PowerStationId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='';
-- operation_firm
CREATE TABLE IF NOT EXISTS `operation_firm` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT ' 0: 1:',
`PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '',
`Name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`Type` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0: 1: 2:',
`ContactPerson` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`Phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`Email` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Email',
`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`,`PowerStationId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='';
-- 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='';
-- power_station_image
CREATE TABLE IF NOT EXISTS `power_station_image` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT ' 0: 1:',
`PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '',
`IsMainDisplay` tinyint(4) NOT NULL DEFAULT 0 COMMENT ' 0: 1:',
` image` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`CreatedBy` int(10) unsigned NOT NULL COMMENT '',
`CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '',
PRIMARY KEY (`Id`),
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,
`Deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT ' 0: 1:',
`PowerStationId` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '',
` image` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`CreatedBy` int(10) unsigned NOT NULL COMMENT '',
`CreatedAt` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '',
PRIMARY KEY (`Id`),
KEY `IDX_01` (`Deleted`,`PowerStationId`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='';
";
await conn.ExecuteAsync(sql, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
}
}

View File

@ -94,5 +94,12 @@ namespace SolarPower.Repository.Interface
/// <param name="post"></param>
/// <returns></returns>
Task<int> AddCompanyAuthAsync(List<CompanyAuth> entity, List<string> properties);
/// <summary>
/// 創建公司自己的DB
/// </summary>
/// <param name="dbName"></param>
/// <returns></returns>
Task CreatCompanyDB(string dbName);
}
}

View File

@ -101,7 +101,7 @@
</button>
</div>
<div class="modal-body">
<form class="company-form" id="company-form">
<form class="company-form" id="company-form" enctype="multipart/form-data">
<div class="row">
<div class="form-group col-lg-6">
<label class="form-label" for="company_name_modal"><span class="text-danger">*</span>名稱</label>
@ -247,7 +247,7 @@
'orderable': false,
'className': 'dt-body-center',
'render': function (data, type, full, meta) {
return '<img src="' + data + '" class="img-fluid">';
return '<img src="' + data + '?v=' + Date.now() + '" class="img-fluid">';
}
}],
"language": {
@ -486,7 +486,6 @@
type: "POST",
url: url,
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,

View File

@ -762,7 +762,7 @@
<div class="page-content-overlay" data-action="toggle" data-class="mobile-nav-on"></div> <!-- END Page Content -->
<!-- BEGIN Page Footer -->
<footer class="page-footer" role="contentinfo">
<div class="d-flex align-items-center flex-1 text-muted">
@*<div class="d-flex align-items-center flex-1 text-muted">
<span class="hidden-md-down fw-700">2020 © Rage by&nbsp;<a href='https://www.rage.com.tw' class='text-primary fw-500' title='rage.com.tw' target='_blank'>rage.com.tw</a></span>
</div>
<div>
@ -772,7 +772,7 @@
<li class="pl-3"><a href="info_app_docs.html" class="text-secondary fw-700">Documentation</a></li>
</ul>
</div>
</div>*@
</footer>
<!-- END Page Footer -->
<!-- BEGIN Shortcuts -->

View File

@ -113,7 +113,7 @@
return;
}
$("#company-logo").attr("src", rel.data.logo);
$("#company-logo").attr("src", rel.data.logo + "?v=" + Date.now());
$("#company-name").html(rel.data.name);
$("#company-modal").modal();
@ -399,7 +399,6 @@
"order": [[5, "desc"]],
"columns": [{
"data": null,
"target": 0
}, {
"data": "companyName"
}, {
@ -413,8 +412,16 @@
}, {
"data": null,
"defaultContent": '<button class="btn btn-danger del-btn">刪除</button>'
}
],
}],
"columnDefs": [{
'targets': 0,
'searchable': false,
'orderable': false,
'className': 'dt-body-center',
"createdCell": function (td, cellData, rowData, row, col) {
$(td).html(row + 1)
}
}],
"language": {
"emptyTable": "無資料...",
"processing": "處理中...",