From d939a0ebfd9ed4df3fd1c197c7b1078eb3cee5dd Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 1 Sep 2021 11:04:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E9=9B=BB=E7=AB=99?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/Implement/OverviewRepository.cs | 1 + .../Repository/Implement/PowerStationRepository.cs | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/SolarPower/Repository/Implement/OverviewRepository.cs b/SolarPower/Repository/Implement/OverviewRepository.cs index 708d96b..98c97de 100644 --- a/SolarPower/Repository/Implement/OverviewRepository.cs +++ b/SolarPower/Repository/Implement/OverviewRepository.cs @@ -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(sql, new { PowerStationIds = powerStationIds })).ToList(); diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 88a8412..b724770 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -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(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(sql, new { Filter = filter })).ToList(); } catch (Exception exception) From 73fb4da5faaa8d1a852e450e880656f48b5c3387 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Wed, 1 Sep 2021 11:41:45 +0800 Subject: [PATCH 2/3] =?UTF-8?q?60=E5=A4=A9=E5=88=AA=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Models/Operation.cs | 3 +- .../Quartz/Jobs/CalcAvgPowerStationJob.cs | 15 ++- .../Implement/OperationRepository.cs | 29 ++++++ .../Repository/Implement/RepositoryBase.cs | 29 ++++++ .../Interface/IOperationRepository.cs | 2 + .../Repository/Interface/IRepositoryBase.cs | 2 + .../Views/Operation/OperationRecord.cshtml | 92 +++++++++++++++++-- 7 files changed, 163 insertions(+), 9 deletions(-) diff --git a/SolarPower/Models/Operation.cs b/SolarPower/Models/Operation.cs index bdf4416..47ef2c1 100644 --- a/SolarPower/Models/Operation.cs +++ b/SolarPower/Models/Operation.cs @@ -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; } diff --git a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs index f57a33b..014bd16 100644 --- a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs @@ -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 logger, IPowerStationRepository powerStationRepository, IUserRepository userRepository, INoticeScheduleRepository noticeScheduleRepository, IStationReportRepository stationReportRepository) + public CalcAvgPowerStationJob(ILogger 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("operation_record", "Deleted = 1"); + List deleteoperations = new List(); + 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) { diff --git a/SolarPower/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index b790383..17e4b7b 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -734,5 +734,34 @@ namespace SolarPower.Repository.Implement } } } + + public async Task DeleteRecord(List 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(); + } + } + } + } + } } diff --git a/SolarPower/Repository/Implement/RepositoryBase.cs b/SolarPower/Repository/Implement/RepositoryBase.cs index 31ed10c..07cdd16 100644 --- a/SolarPower/Repository/Implement/RepositoryBase.cs +++ b/SolarPower/Repository/Implement/RepositoryBase.cs @@ -659,5 +659,34 @@ namespace SolarPower.Repository.Implement } } } + /// + /// 取條件 的所有資料 + /// + /// + /// + /// + public async Task> GetAllDataList(string tableName, string where) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + try + { + var sql = @$"SELECT Id FROM {tableName} WHERE {where}"; + + result = (await conn.QueryAsync(sql)).ToList(); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return result; + } + } } } diff --git a/SolarPower/Repository/Interface/IOperationRepository.cs b/SolarPower/Repository/Interface/IOperationRepository.cs index 71b1da2..9630b39 100644 --- a/SolarPower/Repository/Interface/IOperationRepository.cs +++ b/SolarPower/Repository/Interface/IOperationRepository.cs @@ -81,6 +81,8 @@ namespace SolarPower.Repository.Interface Task> GetOperationRecordPersonnelIdsByOperationRecordId(int operationRecordId); Task DeleteOperationRecordPersonnel(List operationRecordPersonnels); + + Task DeleteRecord(List operations); } } diff --git a/SolarPower/Repository/Interface/IRepositoryBase.cs b/SolarPower/Repository/Interface/IRepositoryBase.cs index 183cbbf..5f936d4 100644 --- a/SolarPower/Repository/Interface/IRepositoryBase.cs +++ b/SolarPower/Repository/Interface/IRepositoryBase.cs @@ -113,5 +113,7 @@ namespace SolarPower.Repository.Interface Task PurgeOneByIdWithCustomDBNameAndTable(int id, string db_name, string table_name); Task AddAnyThing(A result, List properties, string tableName); + + Task> GetAllDataList(string tableName, string where); } } diff --git a/SolarPower/Views/Operation/OperationRecord.cshtml b/SolarPower/Views/Operation/OperationRecord.cshtml index 11552c0..9dfc243 100644 --- a/SolarPower/Views/Operation/OperationRecord.cshtml +++ b/SolarPower/Views/Operation/OperationRecord.cshtml @@ -99,6 +99,7 @@ 檔案 完成時間 創建時間 + 刪除時間 @if (ViewBag.myUser.Role.Layer != (int)RoleLayerEnum.CompanyUser) { 功能 @@ -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": '' + }, { + "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 From 4a04e22ce2197a86e83325ffad4332a4b8447caa Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 1 Sep 2021 16:27:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=202.=20=E6=8B=BF=E6=8E=89=E9=9B=BB=E7=AB=99=20icon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Repository/Implement/PowerStationRepository.cs | 4 ++++ SolarPower/Views/AnalysisInverter/Index.cshtml | 4 ++-- SolarPower/Views/AnalysisStationCombine/Index.cshtml | 2 +- SolarPower/Views/AnalysisStationInfo/Index.cshtml | 4 ++-- SolarPower/Views/ElectricitySoldRecord/Index.cshtml | 4 ++-- SolarPower/Views/NoticeSchedule/Index.cshtml | 4 ++-- SolarPower/Views/PowerGeneration/Index.cshtml | 4 ++-- SolarPower/Views/StationReport/Index.cshtml | 4 ++-- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index b724770..8b569d6 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -5192,6 +5192,8 @@ namespace SolarPower.Repository.Implement { sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')"; } + + sql += @" ORDER BY city.Priority"; result = (await conn.QueryAsync(sql, new { Filter = filter })).ToList(); } catch (Exception exception) @@ -5226,6 +5228,8 @@ namespace SolarPower.Repository.Implement { sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')"; } + + sql += @" ORDER BY city.Priority"; result = (await conn.QueryAsync(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, Filter = filter })).ToList(); } catch (Exception exception) diff --git a/SolarPower/Views/AnalysisInverter/Index.cshtml b/SolarPower/Views/AnalysisInverter/Index.cshtml index 8542746..de50d1d 100644 --- a/SolarPower/Views/AnalysisInverter/Index.cshtml +++ b/SolarPower/Views/AnalysisInverter/Index.cshtml @@ -466,8 +466,8 @@ '' + '' + '' + - '
' + powerStationkey + '
' + - '
' + powerStationkey + '
' + + '
' + powerStationkey + '
' + + '
' + powerStationkey + '
' + '
' + '' + '
' + diff --git a/SolarPower/Views/AnalysisStationCombine/Index.cshtml b/SolarPower/Views/AnalysisStationCombine/Index.cshtml index 39f8cea..e1efa34 100644 --- a/SolarPower/Views/AnalysisStationCombine/Index.cshtml +++ b/SolarPower/Views/AnalysisStationCombine/Index.cshtml @@ -661,7 +661,7 @@ '
' + '' + '
' + - '
' + powerStation.powerStationName + '
' + + '
' + powerStation.powerStationName + '
' + '
' + ''; }); diff --git a/SolarPower/Views/AnalysisStationInfo/Index.cshtml b/SolarPower/Views/AnalysisStationInfo/Index.cshtml index 07f6eee..19821f1 100644 --- a/SolarPower/Views/AnalysisStationInfo/Index.cshtml +++ b/SolarPower/Views/AnalysisStationInfo/Index.cshtml @@ -481,8 +481,8 @@ '' + '' + '' + - '
' + powerStationkey + '
' + - '
' + powerStationkey + '
' + + '
' + powerStationkey + '
' + + '
' + powerStationkey + '
' + '
' + '' + '
' + diff --git a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml index 45757ca..c26f100 100644 --- a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml +++ b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml @@ -398,7 +398,7 @@ '
' + '' + '
' + - '
' + inverter.powerStationName + '
' + + '
' + inverter.powerStationName + '
' + '
' + ''; } @@ -408,7 +408,7 @@ '
' + '' + '
' + - '
' + inverter.powerStationName + '
' + + '
' + inverter.powerStationName + '
' + '' + ''; } diff --git a/SolarPower/Views/NoticeSchedule/Index.cshtml b/SolarPower/Views/NoticeSchedule/Index.cshtml index 6af5479..f7e9f1e 100644 --- a/SolarPower/Views/NoticeSchedule/Index.cshtml +++ b/SolarPower/Views/NoticeSchedule/Index.cshtml @@ -502,7 +502,7 @@ '
' + '' + '
' + - '
' + inverter.powerStationName + '
' + + '
' + inverter.powerStationName + '
' + '' + ''; } @@ -512,7 +512,7 @@ '
' + '' + '
' + - '
' + inverter.powerStationName + '
' + + '
' + inverter.powerStationName + '
' + '' + ''; } diff --git a/SolarPower/Views/PowerGeneration/Index.cshtml b/SolarPower/Views/PowerGeneration/Index.cshtml index b346b87..f638032 100644 --- a/SolarPower/Views/PowerGeneration/Index.cshtml +++ b/SolarPower/Views/PowerGeneration/Index.cshtml @@ -420,7 +420,7 @@ '
' + '' + '
' + - '
' + inverter.powerStationName + '
' + + '
' + inverter.powerStationName + '
' + '' + ''; } @@ -430,7 +430,7 @@ '
' + '' + '
' + - '
' + inverter.powerStationName + '
' + + '
' + inverter.powerStationName + '
' + '' + ''; } diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index f3bb283..0911b06 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -614,7 +614,7 @@ '
' + '' + '
' + - '
' + inverter.powerStationName + '
' + + '
' + inverter.powerStationName + '
' + '' + ''; } @@ -624,7 +624,7 @@ '
' + '' + '
' + - '
' + inverter.powerStationName + '
' + + '
' + inverter.powerStationName + '
' + '' + ''; }