This commit is contained in:
Kai 2021-09-01 16:27:44 +08:00
commit ec046e2700
10 changed files with 580 additions and 264 deletions

View File

@ -412,6 +412,22 @@ namespace SolarPower.Controllers
foreach (var record in records)
{
if(post.Status == 2)
{
record.Function = "<button class='btn btn-primary redu-btn'>還原</button>";
if (string.IsNullOrEmpty(record.FormId))
{
record.FormId = "";
}
else
{
record.FormId = record.FormId;
}
}
else
{
record.Function = "<button class='btn btn-danger del-btn'>刪除</button>";
if (string.IsNullOrEmpty(record.FormId))
{
record.FormId = @$"<a href='javascript:;' class='btn btn-success waves-effect waves-themed mb-3 mr-2 edit-btn'>填寫表單</a>";
@ -420,7 +436,7 @@ namespace SolarPower.Controllers
{
record.FormId = @$"<a href='javascript:;' class='waves-effect waves-themed mb-3 mr-2 edit-btn'>{record.FormId}</a>";
}
}
if (record.RecordFiles != null && record.RecordFiles.Count > 0)
{
foreach (var file in record.RecordFiles)
@ -428,6 +444,7 @@ namespace SolarPower.Controllers
file.FileName = Path.Combine(operationRecordFilePath, record.Id.ToString()) + "/" + file.FileName;
}
}
}
totalRecords = records.Count();
@ -955,6 +972,37 @@ namespace SolarPower.Controllers
return apiResult;
}
public async Task<ApiResult<string>> ReductionOneOperationRecord(int id)
{
ApiResult<string> apiResult = new ApiResult<string>();
try
{
//var operationRecord = await operationRepository.GetOneOperationRecordAsync(id);
//if (operationRecord == null)
//{
// apiResult.Code = "9989";
// apiResult.Msg = errorCode.GetString(apiResult.Code);
// return apiResult;
//}
await operationRepository.ReductionOneOperationRecordAsync(id);
apiResult.Code = "0000";
apiResult.Msg = "還原成功";
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = errorCode.GetString(apiResult.Code);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 儲存運維作業記錄檔案
/// </summary>

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; }
@ -273,6 +272,7 @@ namespace SolarPower.Models
}
} //本次作業預計
public List<string> HyperLinks { get; set; }
public string Function { get; set; }
}
public class PostOperationRecord

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

@ -205,13 +205,24 @@ namespace SolarPower.Repository.Implement
{
try
{
string where = "";
if(filter.Status == 2 )
{
where = $"opr.Deleted = 1 ";
}
else
{
where = $"opr.Deleted = 0 AND opr.Status = {filter.Status} ";
}
var sql = @$"SELECT aa.* FROM (
SELECT
opr.*,
ps.Name AS PowerStationName
FROM operation_record opr
LEFT JOIN power_station ps ON opr.PowerStationId = ps.Id
WHERE opr.Deleted = 0 AND opr.Status = {filter.Status}
WHERE {where}
AND ps.Id IN @PowerStationIds";
if (!string.IsNullOrEmpty(filter.Range))
@ -237,7 +248,7 @@ namespace SolarPower.Repository.Implement
ps.Name AS PowerStationName
FROM operation_record opr
LEFT JOIN power_station ps ON opr.PowerStationId = ps.Id
WHERE opr.Deleted = 0 AND opr.Status = {filter.Status}
WHERE {where}
AND ps.Id IN @PowerStationIds
AND opr.WorkType = 2";
if (!string.IsNullOrEmpty(filter.Range))
@ -449,6 +460,35 @@ namespace SolarPower.Repository.Implement
}
}
public async Task ReductionOneOperationRecordAsync(int id)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var sql = $"UPDATE operation_record SET deleted = 0 WHERE Id = @Id";
await conn.ExecuteAsync(sql, new { Id = id }, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
/// <summary>
/// 新增運維作業記錄的檔案
/// </summary>
@ -694,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

@ -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

@ -15,7 +15,7 @@ namespace SolarPower.Repository.Interface
Task UpdateOperationPlan(OperationCreatePlan OperationPlan, List<string> properties);
Task AddToRecord(PlanToRecord record, List<string> properties2);
Task ReductionOneOperationRecordAsync(int id);
/// <summary>
/// 透過搜尋條件,查詢過濾後的運維作業記錄
/// </summary>
@ -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

@ -24,8 +24,9 @@
<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-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>
<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(2,this)">刪除區</button>
</div>
</div>
<div class="pr-3">
@ -98,6 +99,7 @@
<th>檔案</th>
<th>完成時間</th>
<th>創建時間</th>
<th>刪除時間</th>
@if (ViewBag.myUser.Role.Layer != (int)RoleLayerEnum.CompanyUser)
{
<th>功能</th>
@ -276,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) {
@ -354,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();
})
@ -451,8 +460,10 @@
},{
"data": "createdAt"
}, {
"data": null,
"defaultContent": '<button class="btn btn-danger del-btn">刪除</button>'
"data": "updatedAt",
//"defaultContent": '<button class="btn btn-danger del-btn">刪除</button>'
}, {
"data": "function"
}],
"columnDefs": [{
'targets': 7,
@ -552,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();
}
@ -559,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
@ -628,6 +651,12 @@
powerids = [];
powerids = Newpowerids;
})
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}
@ -698,6 +727,12 @@
powerids = [];
}
})
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
})
}
@ -721,6 +756,12 @@
powerids = [];
}
})
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}
//#endregion
@ -771,6 +812,12 @@
powerids = [];
powerids = Newpowerids;
})
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
})
//#endregion
@ -786,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();
})
@ -944,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();
}
}
@ -967,7 +1030,7 @@
}
//#endregion
//#region 刪除公司
//#region 刪除運維紀錄
$('#operation_record_table').on("click", "button.del-btn", function () {
selected_id = $(this).parents('tr').attr('data-id');
@ -998,6 +1061,56 @@
}
toast_ok(rel.msg);
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}, 'json');
}
});
});
//#endregion
//#region 還原運維紀錄
$('#operation_record_table').on("click", "button.redu-btn", function () {
selected_id = $(this).parents('tr').attr('data-id');
Swal.fire(
{
title: "還原",
text: "你確定是否還原此筆資料?",
type: "warning",
icon: 'warning',
showCancelButton: true,
confirmButtonText: "是",
cancelButtonText: "否"
}).then(function (result) {
if (result.value) {
//還原單一運維紀錄
var url = "/Operation/ReductionOneOperationRecord/";
var send_data = {
Id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
else if (rel.code == "9998") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
if (status == 2) {
operationRecordTable.column(10).visible(true);
}
else {
operationRecordTable.column(10).visible(false);
}
operationRecordTable.ajax.reload();
}, 'json');
}
@ -1207,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

@ -101,7 +101,9 @@
var countPowerStationImage = 0; var countPowerStationSingleLine = 0;
var upper = 0;
var stationDB = "";
var station_infocreate = false;
$(function () {
$('#power_station_operation_personnel-error').hide();
var url = new URL(location.href);
stationId = url.searchParams.get('stationId');
@ -1020,6 +1022,10 @@
//#region 儲存電站基本資料資訊
function SaveStationInfo() {
if ($("#station-created-form").valid() && $('#power_station_operation_personnel').val().length != 0) {
station_infocreate = false;
$(".select2-selection__choice").each(function () {
$(this).children(".select2-selection__choice__remove").show();
})
@ -1063,6 +1069,18 @@
PostPowerStationData();
</text>
}
}
else {
if ($('#power_station_operation_personnel').val().length == 0) {
$('#power_station_operation_personnel-error').show();
}
}
}
@ -1296,7 +1314,7 @@
//#endregion
} else {
//修改
station_infocreate = true;
//#region 電站基本資料 文字
$("#address_detail_text").hide();
@ -2963,6 +2981,49 @@
}
}
});
$("#station-created-form").validate({
rules: {
address_detail: {
required: true
},
power_station_name: {
required: true
},
coordinate: {
required: true
},
estimate_efficacy:
{
required: true
},
estimate_kwh:
{
required: true
},
estimated_recovery_time:
{
required: true
},
generating_capacity:
{
required: true
}
}
});
$('#power_station_operation_personnel').change(function () {
//$(this).valid();
if (stationId == 'new' || station_infocreate) {
console.log($('#power_station_operation_personnel').val().length);
if ($('#power_station_operation_personnel').val().length == 0) {
$('#power_station_operation_personnel-error').show();
} else {
$('#power_station_operation_personnel-error').hide();
}
}
});
$("#Inverter-form").validate({
rules: {
Inverter_ControllerId_modal: {
@ -2985,6 +3046,8 @@
},
}
});
$("#Operation-form").validate({
rules: {
Operation_factory_modal: {

View File

@ -17,9 +17,10 @@
</div>
</div>
<div class="card-body">
<form id="station-created-form">
<div class="row mb-3 d-flex justify-content-between">
<div class="col-xl-3 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="city_label">縣市</label>
<label class="col-xl-4 form-label" id="city_label"><span class="text-danger">*</span>縣市</label>
<div class="col-xl-8">
<select class="form-control" id="select_city">
<option value="0" selected>全部</option>
@ -27,7 +28,7 @@
</div>
</div>
<div class="col-xl-3 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="area_label">地區</label>
<label class="col-xl-4 form-label" id="area_label"><span class="text-danger">*</span>地區</label>
<div class="col-xl-8">
<select class="form-control" id="select_area">
<option value="0" selected>全部</option>
@ -35,14 +36,14 @@
</div>
</div>
<div class="col-xl-3 row align-items-center">
<label class="col-xl-4 form-label" id="area_label">地址</label>
<label class="col-xl-4 form-label" id="area_label"><span class="text-danger">*</span>地址</label>
<div class="col-xl-8">
<label id="address_detail_text" class="color-info-600"></label>
<input type="text" id="address_detail" name="address_detail" class="form-control">
</div>
</div>
<div class="col-xl-3 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="solar_tpye_label">電站類型</label>
<label class="col-xl-4 form-label" id="solar_tpye_label"><span class="text-danger">*</span>電站類型</label>
<div class="col-xl-8">
<select class="form-control" id="select_solar_tpye">
<option value="0" selected>自建躉售</option>
@ -62,7 +63,7 @@
</div>
</div>
<div class="col-xl-3 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="power_station_name_label" for="power_station_name">電站名稱</label>
<label class="col-xl-4 form-label" id="power_station_name_label" for="power_station_name"><span class="text-danger">*</span>電站名稱</label>
<div class="col-xl-8">
<label id="power_station_name_text" class="color-info-600"></label>
<input type="text" id="power_station_name" name="power_station_name" class="form-control">
@ -91,7 +92,7 @@
<div class="row mb-3 d-flex justify-content-between">
<div class="col-xl-3 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="generating_capacity_label" for="generating_capacity">
裝置容量(kWp)
<span class="text-danger">*</span>裝置容量(kWp)
</label>
<div class="col-xl-8">
<label id="generating_capacity_text" class="color-info-600"></label>
@ -100,7 +101,7 @@
</div>
<div class="col-xl-3 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="estimate_efficacy_label" for="estimate_efficacy">
預估發電效能
<span class="text-danger">*</span>預估發電效能
</label>
<div class="col-xl-8">
<label id="estimate_efficacy_text" class="color-info-600"></label>
@ -109,7 +110,7 @@
</div>
<div class="col-xl-3 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="estimate_kwh_label" for="estimate_kwh">
預估發電度數(kW/日)
<span class="text-danger">*</span>預估發電度數(kW/日)
</label>
<div class="col-xl-8">
<label id="estimate_kwh_text" class="color-info-600"></label>
@ -118,7 +119,7 @@
</div>
<div class="col-xl-3 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="estimated_recovery_time_label" for="estimated_recovery_time">
預計回收年限
<span class="text-danger">*</span>預計回收年限
</label>
<div class="col-xl-8">
<label id="estimated_recovery_time_text" class="color-info-600"></label>
@ -129,14 +130,15 @@
<div class="row mb-5 d-flex justify-content-between ">
<div class="col-xl-6 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="power_station_operation_personnel_label">運維人員</label>
<div class="col-xl-8">
<label class="col-xl-4 form-label" id="power_station_operation_personnel_label"><span class="text-danger">*</span>運維人員</label>
<div class="col-xl-8" id="power_station_operation_personnel_div">
<select class="js-example-basic-multiple form-control" id="power_station_operation_personnel" multiple="multiple">
</select>
<label id="power_station_operation_personnel-error" class="" style="z-index:1;color:red;display:none">此為必填欄位</label>
</div>
</div>
<div class="col-xl-3 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="coordinate_label" for="coordinate">座標</label>
<label class="col-xl-4 form-label" id="coordinate_label" for="coordinate"><span class="text-danger">*</span>座標</label>
<div class="col-xl-8">
<label id="coordinate_text" class="color-info-600"></label>
<input type="text" id="coordinate" name="coordinate" class="form-control">
@ -149,15 +151,12 @@
<input type="text" id="line_token" name="line_token" class="form-control">
</div>
</div>
</div>
<div class="row mb-5 d-flex justify-content-between ">
<div class="col-xl-6 row justify-content-center align-items-center">
<label class="col-xl-4 form-label" id="select_power_station_company_title">
電站歸屬
<span class="text-danger">*</span>電站歸屬
</label>
<div class="col-xl-8">
<select class="form-control" id="select_power_station_company">
@ -176,38 +175,9 @@
<label id="created_at_text" class="color-info-600"></label>
</div>
</div>
</div>
<div class="row align-items-end">
@*
<div class="col-xl-6">
<h5 class="border-bottom font-weight-bold mb-3 pl-5 pb-3">逆變器</h5>
<div class="row d-flex justify-content-between px-5">
<div class="col-xl-4 row">
<label class="col-xl-4 form-label" id="inverter_brand_label" for="inverter_brand">廠牌</label>
<div class="col-xl-8">
<label id="inverter_brand_text" class="color-info-600"></label>
<input type="text" id="inverter_brand" name="inverter_brand" class="form-control">
</div>
</div>
<div class="col-xl-4 row">
<label class="col-xl-4 form-label" id="inverter_product_model_label" for="inverter_product_model">型號</label>
<div class="col-xl-8">
<label id="inverter_product_model_text" class="color-info-600"></label>
<input type="text" id="inverter_product_model" name="inverter_product_model" class="form-control">
</div>
</div>
<div class="col-xl-4 row">
<label class="col-xl-4 form-label" id="inverter_amount_label" for="inverter_amount">數量</label>
<div class="col-xl-8">
<label id="inverter_amount_text" class="color-info-600"></label>
<input type="text" id="inverter_amount" name="inverter_amount" class="form-control">
</div>
</div>
</div>
</div>
*@
<div class="col-xl-8">
<h5 class="border-bottom font-weight-bold mb-3 pl-5 pb-3">光電板</h5>
<div class="row d-flex justify-content-between px-5">
@ -245,6 +215,7 @@
</div>
</div>
</div>
</form>
</div>
</div>
</div>