This commit is contained in:
JiaHao Liu 2021-09-01 16:43:02 +08:00
commit 3080cb64d2
16 changed files with 189 additions and 26 deletions

View File

@ -123,10 +123,9 @@ namespace SolarPower.Models
public string EndTime { get; set; }
}
public class OperationRecord : Created
public class OperationRecord : UserInfo
{
private string startTime, endTime, finishTime, workTime;
public int Id { get; set; }
public string FormId { get; set; }
public string SerialNumber { get; set; }
public int PowerStationId { get; set; }

View File

@ -20,14 +20,16 @@ namespace SolarPower.Quartz.Jobs
private readonly IUserRepository userRepository;
private readonly INoticeScheduleRepository noticeScheduleRepository;
private readonly IStationReportRepository stationReportRepository;
private readonly IOperationRepository operationRepository;
public CalcAvgPowerStationJob(ILogger<CalcAvgPowerStationJob> logger, IPowerStationRepository powerStationRepository, IUserRepository userRepository, INoticeScheduleRepository noticeScheduleRepository, IStationReportRepository stationReportRepository)
public CalcAvgPowerStationJob(ILogger<CalcAvgPowerStationJob> logger, IPowerStationRepository powerStationRepository, IUserRepository userRepository, INoticeScheduleRepository noticeScheduleRepository, IStationReportRepository stationReportRepository,IOperationRepository operationRepository)
{
this.logger = logger;
this.powerStationRepository = powerStationRepository;
this.userRepository = userRepository;
this.noticeScheduleRepository = noticeScheduleRepository;
this.stationReportRepository = stationReportRepository;
this.operationRepository = operationRepository;
}
public async Task Execute(IJobExecutionContext context)
@ -309,6 +311,17 @@ namespace SolarPower.Quartz.Jobs
};
await powerStationRepository.AddWeatherForecast(weatherForecasts, weather_forecast_properties);
var OperationDeletes = await powerStationRepository.GetAllDataList<OperationRecord>("operation_record", "Deleted = 1");
List<int> deleteoperations = new List<int>();
foreach(var deletes in OperationDeletes)
{
if(DateTime.Now.AddDays(-60) > Convert.ToDateTime(deletes.UpdatedAt))
{
deleteoperations.Add(deletes.Id);
}
}
await operationRepository.DeleteRecord(deleteoperations);
#region step2.
foreach (var powerStation in powerStations)
{

View File

@ -734,5 +734,34 @@ namespace SolarPower.Repository.Implement
}
}
}
public async Task DeleteRecord(List<int> operations)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var sql = $"UPDATE operation_record SET Deleted = 2 WHERE Id IN @Ids";
await conn.ExecuteAsync(sql, new { Ids = operations }, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
}
}

View File

@ -88,6 +88,7 @@ namespace SolarPower.Repository.Implement
LEFT JOIN city c ON ps.CityId = c.Id
WHERE ps.Id IN @PowerStationIds
GROUP BY ps.CityId
ORDER BY c.Priority
";
result = (await conn.QueryAsync<CapacityDataTable>(sql, new { PowerStationIds = powerStationIds })).ToList();

View File

@ -4448,8 +4448,8 @@ namespace SolarPower.Repository.Implement
{
try
{
var sql = $@"SELECT ps.Id AS PowerStationId , ps.`Name` AS PowerStationName,city.Name AS CityName FROM {tableName} ps
LEFT JOIN city ON city.Id = ps.CityId";
var sql = $@"SELECT ps.Id AS PowerStationId , ps.`Name` AS PowerStationName,c.Name AS CityName FROM {tableName} ps
LEFT JOIN city c ON c.Id = ps.CityId";
if (myUser.Role.Layer == 2)
{
@ -4465,6 +4465,8 @@ namespace SolarPower.Repository.Implement
{
sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')";
}
sql += " ORDER BY c.Priority";
result = (await conn.QueryAsync<PowerStationIdAndCity>(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, Filter = filter })).ToList();
}
catch (Exception exception)
@ -4482,14 +4484,16 @@ namespace SolarPower.Repository.Implement
{
try
{
var sql = @$"SELECT ps.Id AS PowerStationId , ps.`Name` AS PowerStationName,city.Name AS CityName FROM {tableName} ps
LEFT JOIN city ON city.Id = ps.CityId WHERE ps.Deleted = 0";
var sql = @$"SELECT ps.Id AS PowerStationId , ps.`Name` AS PowerStationName,c.Name AS CityName FROM {tableName} ps
LEFT JOIN city c ON c.Id = ps.CityId WHERE ps.Deleted = 0 ";
if (!string.IsNullOrEmpty(filter))
{
sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')";
}
sql += " ORDER BY c.Priority";
result = (await conn.QueryAsync<PowerStationIdAndCity>(sql, new { Filter = filter })).ToList();
}
catch (Exception exception)
@ -5188,6 +5192,8 @@ namespace SolarPower.Repository.Implement
{
sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')";
}
sql += @" ORDER BY city.Priority";
result = (await conn.QueryAsync<PowerStationIdAndCity>(sql, new { Filter = filter })).ToList();
}
catch (Exception exception)
@ -5222,6 +5228,8 @@ namespace SolarPower.Repository.Implement
{
sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')";
}
sql += @" ORDER BY city.Priority";
result = (await conn.QueryAsync<PowerStationIdAndCity>(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, Filter = filter })).ToList();
}
catch (Exception exception)

View File

@ -659,5 +659,34 @@ namespace SolarPower.Repository.Implement
}
}
}
/// <summary>
/// 取條件 的所有資料
/// </summary>
/// <param name="tableName"></param>
/// <param name="where"></param>
/// <returns></returns>
public async Task<List<A>> GetAllDataList<A>(string tableName, string where)
{
List<A> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
try
{
var sql = @$"SELECT Id FROM {tableName} WHERE {where}";
result = (await conn.QueryAsync<A>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
return result;
}
}
}
}

View File

@ -81,6 +81,8 @@ namespace SolarPower.Repository.Interface
Task<List<int>> GetOperationRecordPersonnelIdsByOperationRecordId(int operationRecordId);
Task DeleteOperationRecordPersonnel(List<OperationRecordPersonnel> operationRecordPersonnels);
Task DeleteRecord(List<int> operations);
}
}

View File

@ -113,5 +113,7 @@ namespace SolarPower.Repository.Interface
Task PurgeOneByIdWithCustomDBNameAndTable(int id, string db_name, string table_name);
Task AddAnyThing<A>(A result, List<string> properties, string tableName);
Task<List<A>> GetAllDataList<A>(string tableName, string where);
}
}

View File

@ -466,8 +466,8 @@
'<input type="checkbox" class="" name="selectedInverterLayer2[]" >' +
'</div>' +
'<a href="javascript:;" class="" data-toggle="collapse" data-target="#cp-' + index1 + '-' + index2 + ' > .card-body" aria-expanded="true">' +
'<span class="collapsed-hidden"><h5 class="font-weight-bold mb-0"><i class="fal fa-charging-station"></i>' + powerStationkey + '<i class="fal fa-chevron-down fs-xl ml-2"></i></h5></span>' +
'<span class="collapsed-reveal"><h5 class="font-weight-bold mb-0"><i class="fal fa-charging-station"></i>' + powerStationkey + '<i class="fal fa-chevron-up fs-xl ml-2"></i></h5></span>' +
'<span class="collapsed-hidden"><h5 class="font-weight-bold mb-0">' + powerStationkey + '<i class="fal fa-chevron-down fs-xl ml-2"></i></h5></span>' +
'<span class="collapsed-reveal"><h5 class="font-weight-bold mb-0">' + powerStationkey + '<i class="fal fa-chevron-up fs-xl ml-2"></i></h5></span>' +
'</a>' +
'</div>' +
'<div class="card-body p-0">' +

View File

@ -661,7 +661,7 @@
'<div class="">' +
'<input type="checkbox" class="mr-2" name="selectedPowerStationLayer2[]" value="' + powerStation.powerStationId + '" valueName ="' + powerStation.powerStationName + '">' +
'</div>' +
'<h5 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + powerStation.powerStationName + '</h5>' +
'<h5 class="font-weight-bold">' + powerStation.powerStationName + '</h5>' +
'</div>' +
'</li>';
});

View File

@ -481,8 +481,8 @@
'<input type="checkbox" class="" name="selectedDeviceLayer2[]" >' +
'</div>' +
'<a href="javascript:;" class="" data-toggle="collapse" data-target="#cp-' + index1 + '-' + index2 + ' > .card-body" aria-expanded="true">' +
'<span class="collapsed-hidden"><h5 class="font-weight-bold mb-0"><i class="fal fa-charging-station"></i>' + powerStationkey + '<i class="fal fa-chevron-down fs-xl ml-2"></i></h5></span>' +
'<span class="collapsed-reveal"><h5 class="font-weight-bold mb-0"><i class="fal fa-charging-station"></i>' + powerStationkey + '<i class="fal fa-chevron-up fs-xl ml-2"></i></h5></span>' +
'<span class="collapsed-hidden"><h5 class="font-weight-bold mb-0">' + powerStationkey + '<i class="fal fa-chevron-down fs-xl ml-2"></i></h5></span>' +
'<span class="collapsed-reveal"><h5 class="font-weight-bold mb-0">' + powerStationkey + '<i class="fal fa-chevron-up fs-xl ml-2"></i></h5></span>' +
'</a>' +
'</div>' +
'<div class="card-body p-0">' +

View File

@ -398,7 +398,7 @@
'<div class="mr-2">' +
'<input type="checkbox" class="" name="selectedInverterLayer2[]" value="' + inverter.powerStationId + '" valueName ="' + inverter.powerStationName + '" checked>' +
'</div>' +
'<h5 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + inverter.powerStationName + '</h5>' +
'<h5 class="font-weight-bold">' + inverter.powerStationName + '</h5>' +
'</div>' +
'</li>';
}
@ -408,7 +408,7 @@
'<div class="mr-2">' +
'<input type="checkbox" class="" name="selectedInverterLayer2[]" value="' + inverter.powerStationId + '" valueName ="' + inverter.powerStationName + '">' +
'</div>' +
'<h5 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + inverter.powerStationName + '</h5>' +
'<h5 class="font-weight-bold">' + inverter.powerStationName + '</h5>' +
'</div>' +
'</li>';
}

View File

@ -502,7 +502,7 @@
'<div class="mr-2">' +
'<input type="checkbox" class="" name="selectedInverterLayer2[]" value="' + inverter.powerStationId + '" valueName ="' + inverter.powerStationName + '" checked>' +
'</div>' +
'<h5 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + inverter.powerStationName + '</h5>' +
'<h5 class="font-weight-bold">' + inverter.powerStationName + '</h5>' +
'</div>' +
'</li>';
}
@ -512,7 +512,7 @@
'<div class="mr-2">' +
'<input type="checkbox" class="" name="selectedInverterLayer2[]" value="' + inverter.powerStationId + '" valueName ="' + inverter.powerStationName + '">' +
'</div>' +
'<h5 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + inverter.powerStationName + '</h5>' +
'<h5 class="font-weight-bold">' + inverter.powerStationName + '</h5>' +
'</div>' +
'</li>';
}

View File

@ -99,6 +99,7 @@
<th>檔案</th>
<th>完成時間</th>
<th>創建時間</th>
<th>刪除時間</th>
@if (ViewBag.myUser.Role.Layer != (int)RoleLayerEnum.CompanyUser)
{
<th>功能</th>
@ -277,6 +278,7 @@
var AllidsType = true;
var status = 0; //1:完成 0:未完成
var Searchtype = false;
var Deleteshow = false;
//#region Array.Remove
Array.prototype.remove = function (val) {
@ -324,7 +326,7 @@
ids.push(String(rel.data[i].cityId));
Allids.push(String(rel.data[i].cityId));
}
var send_data = {
cityid: ids
}
@ -355,6 +357,12 @@
$("#power_station_select_modal").val($("#power_station_select_modal option:first").val()).trigger('change');
$('#Allcity').trigger("click");
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
})
@ -391,7 +399,7 @@
$("#work_person_select_modal").select2({ dropdownParent: $('#record-form-modal') });
});
//查詢該電站的廠商
@ -452,8 +460,10 @@
},{
"data": "createdAt"
}, {
"data": "function",
"data": "updatedAt",
//"defaultContent": '<button class="btn btn-danger del-btn">刪除</button>'
}, {
"data": "function"
}],
"columnDefs": [{
'targets': 7,
@ -553,6 +563,12 @@
document.getElementById(name).setAttribute("class", "btn btn-secondary waves-effect waves-themed");
}
document.getElementById("button" + type).setAttribute("class", "btn btn-success waves-effect waves-themed");
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}
@ -560,6 +576,12 @@
//#region 改變日期
$('#date-range').on('change', function () {
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
});
//#endregion
@ -629,6 +651,12 @@
powerids = [];
powerids = Newpowerids;
})
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}
@ -699,6 +727,12 @@
powerids = [];
}
})
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
})
}
@ -722,6 +756,12 @@
powerids = [];
}
})
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}
//#endregion
@ -772,6 +812,12 @@
powerids = [];
powerids = Newpowerids;
})
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
})
//#endregion
@ -787,6 +833,12 @@
else {
powerids.remove(classid[1]);
}
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
})
@ -945,13 +997,23 @@
toast_ok(rel.msg);
$('#record-form-modal').modal('hide');
recordFileDropzone.removeAllFiles();
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
});
} else {
$('#record-form-modal').modal('hide');
myDropzone.removeAllFiles();
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}
}
@ -964,7 +1026,7 @@
}
//#endregion
@ -999,6 +1061,12 @@
}
toast_ok(rel.msg);
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}, 'json');
}
@ -1037,6 +1105,12 @@
}
toast_ok(rel.msg);
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}, 'json');
}
@ -1246,6 +1320,12 @@
$(".status-type").removeClass("btn-success").addClass("btn-secondary");
}
$(e).removeClass("btn-secondary").addClass("btn-success");
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}
//#endregion

View File

@ -420,7 +420,7 @@
'<div class="mr-2">' +
'<input type="checkbox" class="" name="selectedInverterLayer2[]" value="' + inverter.powerStationId + '" valueName ="' + inverter.powerStationName + '" checked>' +
'</div>' +
'<h5 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + inverter.powerStationName + '</h5>' +
'<h5 class="font-weight-bold">' + inverter.powerStationName + '</h5>' +
'</div>' +
'</li>';
}
@ -430,7 +430,7 @@
'<div class="mr-2">' +
'<input type="checkbox" class="" name="selectedInverterLayer2[]" value="' + inverter.powerStationId + '" valueName ="' + inverter.powerStationName + '">' +
'</div>' +
'<h5 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + inverter.powerStationName + '</h5>' +
'<h5 class="font-weight-bold">' + inverter.powerStationName + '</h5>' +
'</div>' +
'</li>';
}

View File

@ -614,7 +614,7 @@
'<div class="mr-2">' +
'<input type="checkbox" class="" name="selectedInverterLayer2[]" value="' + inverter.powerStationId + '" valueName ="' + inverter.powerStationName + '" checked>' +
'</div>' +
'<h5 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + inverter.powerStationName + '</h5>' +
'<h5 class="font-weight-bold">' + inverter.powerStationName + '</h5>' +
'</div>' +
'</li>';
}
@ -624,7 +624,7 @@
'<div class="mr-2">' +
'<input type="checkbox" class="" name="selectedInverterLayer2[]" value="' + inverter.powerStationId + '" valueName ="' + inverter.powerStationName + '">' +
'</div>' +
'<h5 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + inverter.powerStationName + '</h5>' +
'<h5 class="font-weight-bold">' + inverter.powerStationName + '</h5>' +
'</div>' +
'</li>';
}