1. bug fix
2. 運維作業紀錄 預設改為未完成 3. company 加入 v_company_inv
This commit is contained in:
parent
f2daab258d
commit
3060aa64ce
@ -401,6 +401,11 @@ namespace SolarPower.Controllers
|
||||
await companyRepository.UpdateCompany(updateCompany, properties);
|
||||
|
||||
await companyRepository.CreatCompanyDB(siteDB);
|
||||
|
||||
//取得所有的公司DBName
|
||||
var siteDBs = await companyRepository.GetAllCompanyDBName();
|
||||
await companyRepository.AlterViewCompanyInv(siteDBs);
|
||||
|
||||
#endregion
|
||||
|
||||
apiResult.Code = "0000";
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,11 +208,9 @@ namespace SolarPower.Repository.Implement
|
||||
var sql = @$"SELECT aa.* FROM (
|
||||
SELECT
|
||||
opr.*,
|
||||
ps.Name AS PowerStationName,
|
||||
u.Name AS WorkPersonName
|
||||
ps.Name AS PowerStationName
|
||||
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 opr.Status = {filter.Status}
|
||||
AND ps.Id IN @PowerStationIds";
|
||||
|
||||
@ -236,11 +234,9 @@ namespace SolarPower.Repository.Implement
|
||||
sql += @" UNION";
|
||||
sql += @$" SELECT
|
||||
opr.*,
|
||||
ps.Name AS PowerStationName,
|
||||
u.Name AS WorkPersonName
|
||||
ps.Name AS PowerStationName
|
||||
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 opr.Status = {filter.Status}
|
||||
AND ps.Id IN @PowerStationIds
|
||||
AND opr.WorkType = 2";
|
||||
@ -267,18 +263,34 @@ namespace SolarPower.Repository.Implement
|
||||
sql += " ) aa ORDER BY aa.CreatedAt DESC";
|
||||
|
||||
result = (await conn.QueryAsync<OperationRecordDataTable>(sql,
|
||||
new {
|
||||
new
|
||||
{
|
||||
PowerStationIds = filter.PowerStationIds,
|
||||
WorkType = filter.WorkType,
|
||||
StartDate = filter.StartTime,
|
||||
EndDate = filter.EndTime
|
||||
})).ToList();
|
||||
|
||||
if (result != null && result.Count > 0)
|
||||
{
|
||||
|
||||
|
||||
var sql_file = "SELECT * FROM operation_record_file WHERE Deleted = 0 AND RecordId = @RecordId";
|
||||
foreach (var x in result)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
@ -4176,7 +4176,8 @@ namespace SolarPower.Repository.Implement
|
||||
c.Name AS CityName,
|
||||
ps.Name AS PowerStationName,
|
||||
inv.InverterName AS InverterName,
|
||||
inv.InverterId AS InverterId
|
||||
inv.InverterId AS InverterId,
|
||||
inv.CreatedAt
|
||||
FROM power_station ps
|
||||
LEFT JOIN `city` c ON ps.CityId = c.Id
|
||||
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 = "(" + sql + ") ORDER BY c.Priority, inv.CreatedAt";
|
||||
sql = "(" + sql + ") ORDER BY Priority, CreatedAt";
|
||||
|
||||
result = (await conn.QueryAsync<PowerStationInverter>(sql, new { Filter = filter })).ToList();
|
||||
}
|
||||
|
||||
@ -101,5 +101,9 @@ namespace SolarPower.Repository.Interface
|
||||
/// <param name="dbName"></param>
|
||||
/// <returns></returns>
|
||||
Task CreatCompanyDB(string dbName);
|
||||
|
||||
Task<List<string>> GetAllCompanyDBName();
|
||||
|
||||
Task AlterViewCompanyInv(List<string> db_names);
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,8 +24,8 @@
|
||||
<div class="row mb-3 d-flex justify-content-start px-3">
|
||||
<div class="pr-3">
|
||||
<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(0,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-success waves-effect waves-themed status-type" onclick="CheckStatus(0,this)">未完成</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pr-3">
|
||||
@ -200,7 +200,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3 fix-div">
|
||||
<div class="row mb-3">
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="fix_firm_modal">負責廠商</label>
|
||||
@ -274,7 +274,7 @@
|
||||
var datepicker;
|
||||
var AllpoweridsType = true;
|
||||
var AllidsType = true;
|
||||
var status = 1; //1:完成 0:未完成
|
||||
var status = 0; //1:完成 0:未完成
|
||||
var Searchtype = false;
|
||||
|
||||
//#region Array.Remove
|
||||
|
||||
Loading…
Reference in New Issue
Block a user