1. bug fix

2. 運維作業紀錄 預設改為未完成
3. company 加入 v_company_inv
This commit is contained in:
Kai 2021-08-27 11:05:52 +08:00
parent f2daab258d
commit 3060aa64ce
6 changed files with 110 additions and 19 deletions

View File

@ -401,6 +401,11 @@ namespace SolarPower.Controllers
await companyRepository.UpdateCompany(updateCompany, properties); await companyRepository.UpdateCompany(updateCompany, properties);
await companyRepository.CreatCompanyDB(siteDB); await companyRepository.CreatCompanyDB(siteDB);
//取得所有的公司DBName
var siteDBs = await companyRepository.GetAllCompanyDBName();
await companyRepository.AlterViewCompanyInv(siteDBs);
#endregion #endregion
apiResult.Code = "0000"; apiResult.Code = "0000";

View File

@ -686,5 +686,74 @@ namespace SolarPower.Repository.Implement
} }
} }
} }
public async Task<List<string>> GetAllCompanyDBName()
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
var result = new List<string>();
try
{
var sql = $@"SELECT DISTINCT SiteDB FROM company c WHERE c.Deleted = 0 AND c.Status = 1";
result = (await conn.QueryAsync<string>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
return result;
}
}
public async Task AlterViewCompanyInv(List<string> db_names)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var temp_sub_sql = new List<string>();
foreach (var db_name in db_names)
{
var sub_sql = $@"select '{db_name}' AS `dbName`,(`{db_name}`.`inverter`.`InverterId` collate utf8mb4_unicode_ci) AS `InverterId`,
(`{db_name}`.`inverter`.`Brand` collate utf8mb4_unicode_ci) AS `Brand`,`{db_name}`.`inverter`.`Enabled` AS `enabled`,
`{db_name}`.`inverter`.`Status` AS status
from `{db_name}`.`inverter`";
temp_sub_sql.Add(sub_sql);
}
var temp_sql = string.Join(" UNION ALL ", temp_sub_sql);
var sql = $@"alter view v_company_inv
AS {temp_sql}";
await conn.ExecuteAsync(sql, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
} }
} }

View File

@ -208,11 +208,9 @@ namespace SolarPower.Repository.Implement
var sql = @$"SELECT aa.* FROM ( var sql = @$"SELECT aa.* FROM (
SELECT SELECT
opr.*, opr.*,
ps.Name AS PowerStationName, ps.Name AS PowerStationName
u.Name AS WorkPersonName
FROM operation_record opr FROM operation_record opr
LEFT JOIN power_station ps ON opr.PowerStationId = ps.Id LEFT JOIN power_station ps ON opr.PowerStationId = ps.Id
LEFT JOIN user u ON opr.WorkPersonId = u.ID
WHERE opr.Deleted = 0 AND opr.Status = {filter.Status} WHERE opr.Deleted = 0 AND opr.Status = {filter.Status}
AND ps.Id IN @PowerStationIds"; AND ps.Id IN @PowerStationIds";
@ -236,11 +234,9 @@ namespace SolarPower.Repository.Implement
sql += @" UNION"; sql += @" UNION";
sql += @$" SELECT sql += @$" SELECT
opr.*, opr.*,
ps.Name AS PowerStationName, ps.Name AS PowerStationName
u.Name AS WorkPersonName
FROM operation_record opr FROM operation_record opr
LEFT JOIN power_station ps ON opr.PowerStationId = ps.Id LEFT JOIN power_station ps ON opr.PowerStationId = ps.Id
LEFT JOIN user u ON opr.WorkPersonId = u.ID
WHERE opr.Deleted = 0 AND opr.Status = {filter.Status} WHERE opr.Deleted = 0 AND opr.Status = {filter.Status}
AND ps.Id IN @PowerStationIds AND ps.Id IN @PowerStationIds
AND opr.WorkType = 2"; AND opr.WorkType = 2";
@ -267,18 +263,34 @@ namespace SolarPower.Repository.Implement
sql += " ) aa ORDER BY aa.CreatedAt DESC"; sql += " ) aa ORDER BY aa.CreatedAt DESC";
result = (await conn.QueryAsync<OperationRecordDataTable>(sql, result = (await conn.QueryAsync<OperationRecordDataTable>(sql,
new { new
{
PowerStationIds = filter.PowerStationIds, PowerStationIds = filter.PowerStationIds,
WorkType = filter.WorkType, WorkType = filter.WorkType,
StartDate = filter.StartTime, StartDate = filter.StartTime,
EndDate = filter.EndTime EndDate = filter.EndTime
})).ToList(); })).ToList();
if (result != null && result.Count > 0)
{
var sql_file = "SELECT * FROM operation_record_file WHERE Deleted = 0 AND RecordId = @RecordId"; var sql_file = "SELECT * FROM operation_record_file WHERE Deleted = 0 AND RecordId = @RecordId";
foreach (var x in result) foreach (var x in result)
{ {
x.RecordFiles = (await conn.QueryAsync<OperationRecordFile>(sql_file, new { RecordId = x.Id })).ToList(); x.RecordFiles = (await conn.QueryAsync<OperationRecordFile>(sql_file, new { RecordId = x.Id })).ToList();
} }
var sql_WorkPersonId = @"SELECT GROUP_CONCAT(DISTINCT u.`Name` SEPARATOR ', ')
FROM operation_record_personnel op
LEFT JOIN user u ON u.deleted = 0 AND op.UserId = u.Id
WHERE op.Deleted = 0 AND op.OperationRecordId = @RecordId
GROUP BY op.OperationRecordId ";
foreach (var x in result)
{
x.WorkPersonName = await conn.QueryFirstOrDefaultAsync<string>(sql_WorkPersonId, new { RecordId = x.Id });
}
}
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -580,7 +592,7 @@ namespace SolarPower.Repository.Implement
{ {
try try
{ {
List<string> value = new List<string>() ; List<string> value = new List<string>();
foreach (MyUser a in personal) foreach (MyUser a in personal)
{ {
value.Add($@"(1,'{a.Name}','{a.Email}','{Title}','{content}',{a.Id},3)"); value.Add($@"(1,'{a.Name}','{a.Email}','{Title}','{content}',{a.Id},3)");
@ -589,7 +601,7 @@ namespace SolarPower.Repository.Implement
var sql = $"INSERT INTO `notice_schedule` (`Type`, `RecipientName`, `RecipientEmail`, `Subject`, `Content`,`UserId`,`EmailType`) VALUES {values};"; var sql = $"INSERT INTO `notice_schedule` (`Type`, `RecipientName`, `RecipientEmail`, `Subject`, `Content`,`UserId`,`EmailType`) VALUES {values};";
await conn.ExecuteAsync(sql,trans); await conn.ExecuteAsync(sql, trans);
trans.Commit(); trans.Commit();
} }

View File

@ -4176,7 +4176,8 @@ namespace SolarPower.Repository.Implement
c.Name AS CityName, c.Name AS CityName,
ps.Name AS PowerStationName, ps.Name AS PowerStationName,
inv.InverterName AS InverterName, inv.InverterName AS InverterName,
inv.InverterId AS InverterId inv.InverterId AS InverterId,
inv.CreatedAt
FROM power_station ps FROM power_station ps
LEFT JOIN `city` c ON ps.CityId = c.Id LEFT JOIN `city` c ON ps.CityId = c.Id
LEFT JOIN {powerStationDic.Key}.controller con ON ps.Id = con.PowerStationId LEFT JOIN {powerStationDic.Key}.controller con ON ps.Id = con.PowerStationId
@ -4192,7 +4193,7 @@ namespace SolarPower.Repository.Implement
} }
sql = string.Join(" UNION ", sql_perSiteDB); sql = string.Join(" UNION ", sql_perSiteDB);
sql = "(" + sql + ") ORDER BY c.Priority, inv.CreatedAt"; sql = "(" + sql + ") ORDER BY Priority, CreatedAt";
result = (await conn.QueryAsync<PowerStationInverter>(sql, new { Filter = filter })).ToList(); result = (await conn.QueryAsync<PowerStationInverter>(sql, new { Filter = filter })).ToList();
} }

View File

@ -101,5 +101,9 @@ namespace SolarPower.Repository.Interface
/// <param name="dbName"></param> /// <param name="dbName"></param>
/// <returns></returns> /// <returns></returns>
Task CreatCompanyDB(string dbName); Task CreatCompanyDB(string dbName);
Task<List<string>> GetAllCompanyDBName();
Task AlterViewCompanyInv(List<string> db_names);
} }
} }

View File

@ -24,8 +24,8 @@
<div class="row mb-3 d-flex justify-content-start px-3"> <div class="row mb-3 d-flex justify-content-start px-3">
<div class="pr-3"> <div class="pr-3">
<div class="btn-group btn-group-md"> <div class="btn-group btn-group-md">
<button type="button" class="btn btn-success waves-effect waves-themed status-type" onclick="CheckStatus(1,this)">完成</button> <button type="button" class="btn btn-secondary waves-effect waves-themed status-type" onclick="CheckStatus(1,this)">完成</button>
<button type="button" class="btn btn-secondary waves-effect waves-themed status-type" onclick="CheckStatus(0,this)">未完成</button> <button type="button" class="btn btn-success waves-effect waves-themed status-type" onclick="CheckStatus(0,this)">未完成</button>
</div> </div>
</div> </div>
<div class="pr-3"> <div class="pr-3">
@ -200,7 +200,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row mb-3 fix-div"> <div class="row mb-3">
<div class="col-lg-6"> <div class="col-lg-6">
<div class="form-group"> <div class="form-group">
<label class="form-label" for="fix_firm_modal">負責廠商</label> <label class="form-label" for="fix_firm_modal">負責廠商</label>
@ -274,7 +274,7 @@
var datepicker; var datepicker;
var AllpoweridsType = true; var AllpoweridsType = true;
var AllidsType = true; var AllidsType = true;
var status = 1; //1:完成 0:未完成 var status = 0; //1:完成 0:未完成
var Searchtype = false; var Searchtype = false;
//#region Array.Remove //#region Array.Remove