解決衝突

This commit is contained in:
Kai 2021-07-07 17:23:57 +08:00
commit e99c39d5ba
7 changed files with 209 additions and 29 deletions

View File

@ -988,7 +988,10 @@ namespace SolarPower.Controllers
CreatedBy = myUser.Id,
TypeName = Device.TypeName,
SerialNumber = Newnum,
ControllerId = Device.ControllerId
ControllerId = Device.ControllerId,
Status = Device.Status,
Enabled = Device.Enabled,
InstallDate = Device.InstallDate
};
List<string> properties = new List<string>()
{
@ -996,17 +999,18 @@ namespace SolarPower.Controllers
"ColName",
"PowerStationId",
"DBName",
"Id",
"Name",
"ProductModel",
"Remark",
"TableName",
"Type",
"UID",
"CreatedBy",
"TypeName",
"SerialNumber",
"ControllerId"
"ControllerId",
"Status",
"Enabled",
"InstallDate"
};
await powerStationRepository.AddDevice(DeviceInfo, properties, powerStation.SiteDB);
@ -1030,7 +1034,10 @@ namespace SolarPower.Controllers
Type = Device.Type,
CreatedBy = myUser.Id,
TypeName = Device.TypeName,
ControllerId = Device.ControllerId
ControllerId = Device.ControllerId,
Status = Device.Status,
Enabled = Device.Enabled,
InstallDate = Device.InstallDate
};
List<string> properties = new List<string>()
{
@ -1041,12 +1048,14 @@ namespace SolarPower.Controllers
"Id",
"Name",
"ProductModel",
"Remark",
"TableName",
"Type",
"CreatedBy",
"TypeName",
"ControllerId"
"ControllerId",
"Status",
"Enabled",
"InstallDate"
};
await powerStationRepository.UpdateDevice(DeviceInfo, properties, powerStation.SiteDB);
apiResult.Code = "0000";
@ -1083,6 +1092,25 @@ namespace SolarPower.Controllers
a.Function = @"
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'></button>
<button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'></button>";
a.StatusName = a.Status switch
{
0 => "未啟用",
1 => "正常",
2 => "異常",
_ => "無資料",
};
switch (a.Enabled)
{
case 0:
a.EnabledName = "未啟用";
break;
case 1:
a.EnabledName = "啟用";
break;
default:
a.EnabledName = "無資料";
break;
}
}
apiResult.Data = deviceTables;
}
@ -2161,14 +2189,43 @@ namespace SolarPower.Controllers
if(inverter1 == null)
{
apiResult.Msg = "找不到資料";
apiResult.Code = "0001";
}
else
{
Inverter inverter = new Inverter()
{
Id = post.Id,
Status = post.Status,
Brand = post.Brand,
Capacity = post.Capacity,
Enabled = post.Enabled,
Model = post.Model,
InstallDate = post.InstallDate,
InverterName = post.InverterName,
Pyrheliometer = post.Pyrheliometer,
ControllerId = post.ControllerId,
UpdatedBy = myUser.Id
};
List<string> properties = new List<string>()
{
"Id",
"Status",
"Brand",
"Capacity",
"Enabled",
"Model",
"InstallDate",
"InverterName",
"Pyrheliometer",
"ControllerId",
"UpdatedBy"
};
await powerStationRepository.UpdateInverter(inverter, properties, powerStation.SiteDB);
apiResult.Code = "0000";
apiResult.Msg = "更新成功";
}
}
}
catch (Exception exception)
{
@ -2226,7 +2283,7 @@ namespace SolarPower.Controllers
a.EnabledName = "啟用";
break;
default:
a.StatusName = "無資料";
a.EnabledName = "無資料";
break;
}
if(a.PyrheliometerName == null)
@ -2397,6 +2454,33 @@ namespace SolarPower.Controllers
sharedeviceTables = await powerStationRepository.shareDeviceTables(stationId, powerStation.SiteDB);
foreach (DeviceTable a in sharedeviceTables)
{
switch (a.Status)
{
case 0:
a.StatusName = "未啟用";
break;
case 1:
a.StatusName = "正常";
break;
case 2:
a.StatusName = "異常";
break;
default:
a.StatusName = "無資料";
break;
}
switch (a.Enabled)
{
case 0:
a.EnabledName = "未啟用";
break;
case 1:
a.EnabledName = "啟用";
break;
default:
a.EnabledName = "無資料";
break;
}
a.Function = @"
<button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'></button>";
}
@ -2433,6 +2517,13 @@ namespace SolarPower.Controllers
powerStation = await powerStationRepository.GetOneAsync(post.PowerStationId);
var ShareDevice = await powerStationRepository.GetOneWithCustomDBNameAndTableAsync<Sharedevice>(post.SelectedId, powerStation.SiteDB, "sharedevice");
var div = await powerStationRepository.Getonediv<DeviceInfo>("inv.Deleted = 0 AND con.PowerStationId = sh.PowerStationId", powerStation.SiteDB, $"sharedevice sh INNER JOIN {powerStation.SiteDB}.inverter inv ON inv.Pyrheliometer = sh.DeviceId INNER JOIN {powerStation.SiteDB}.controller con ON con.Id = inv.ControllerId");
if (div != null)
{
apiResult.Code = "0004";
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
if (ShareDevice == null)
{

View File

@ -19,6 +19,7 @@ namespace SolarPower.Models
{ "0001", "傳入參數錯誤。" },
{ "0002","請先刪除相關逆變器"},
{ "0003","請先刪除相關設備"},
{ "0004","請先移除相關逆變器綁定"},
{ "9986", "該帳號已被註冊,請重新輸入"},
{ "9987", "查無該運維作業記錄檔案"},
{ "9988", "查無該資料紀錄"},

View File

@ -360,9 +360,9 @@ namespace SolarPower.Models.PowerStation
/// <summary>
/// 設備
/// </summary>
public class DeviceInfo
public class DeviceInfo : UserInfo
{
public int Id { get; set; }
private string installDate;
public int PowerStationId { get; set; }//所屬電站編號
public string Name { get; set; }//名稱
public string Type { get; set; }//類型
@ -371,15 +371,16 @@ namespace SolarPower.Models.PowerStation
public string DBName { get; set; }
public string TableName { get; set; }
public string ColName { get; set; }
public string Remark { get; set; }
public int ControllerId { get; set; }
public string TypeName { get; set; }//類型名稱
public int Enabled { get; set; }//啟用
public int Status { get; set; }//狀態
public string InstallDate { get { return Convert.ToDateTime(installDate).ToString("yyyy-MM-dd"); } set { installDate = value; } } //安裝日期
}
public class Device : DeviceInfo
{
public string UID { get; set; }//設備編號
public int CreatedBy { get; set; }//建立者
public string SerialNumber { get; set; }
public string PowerStationName { get; set; }
}
@ -393,6 +394,8 @@ namespace SolarPower.Models.PowerStation
public string UID { get; set; }//設備編號
public string Function { get; set; }//功能
public string PowerStationName { get; set; }
public string EnabledName { get; set; }//啟用
public string StatusName { get; set; }//狀態
}
/// <summary>

View File

@ -1691,7 +1691,9 @@ namespace SolarPower.Repository.Implement
{
try
{
var sql = $@"SELECT Id AS Value, UID AS Text FROM {db_name}.device WHERE Deleted = 0 AND PowerStationId = {stationId} AND Type = 'PYR' ";
var sql = $@"SELECT dd.Id AS Value, dd.UID AS Text FROM {db_name}.device dd WHERE dd.Deleted = 0 AND dd.PowerStationId = {stationId} AND dd.Type = 'PYR'
UNION SELECT dd.Id AS Value, dd.UID AS Text FROM {db_name}.sharedevice sh LEFT JOIN {db_name}.device dd ON sh.DeviceId = dd.Id
WHERE dd.Deleted = 0 AND sh.PowerStationId = {stationId};";
result = (await conn.QueryAsync<PowerstationOption>(sql)).ToList();
}
@ -2143,6 +2145,37 @@ namespace SolarPower.Repository.Implement
}
}
public async Task<int> UpdateInverter(Inverter entity, List<string> properties,string db_name)
{
int count;
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
string sql = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, "inverter");
count = await conn.ExecuteAsync(sql, entity, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
return count;
}
}
public async Task<List<DeviceInfo>> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name)
{
List<DeviceInfo> result;
@ -2430,5 +2463,24 @@ namespace SolarPower.Repository.Implement
return count;
}
}
public async Task<A> Getonediv<A>(string where, string db_name, string table_name)
{
A result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $"SELECT sh.*,inv.*,con.Id,con.PowerStationId FROM {db_name}.{table_name} WHERE {where}";
result = await conn.QueryFirstOrDefaultAsync<A>(sql);
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
}
}

View File

@ -504,5 +504,9 @@ namespace SolarPower.Repository.Interface
Task<PyrheliometerHistory> GetOnePyrheliometerHistoryByMonth(string month, int powerStationId);
Task<int> AddPyrheliometerHistoryMonthList(List<PyrheliometerHistory> entity, List<string> properties);
Task<int> UpdatePyrheliometerHistoryMonthList(List<PyrheliometerHistory> entity);
Task<int> UpdateInverter(Inverter entity, List<string> properties, string db_name);
Task<A> Getonediv<A>(string where, string db_name, string table_name);
}
}

View File

@ -408,19 +408,27 @@
"info": true,
"autoWidth": false,
"responsive": true,
"order": [[9, "desc"]],
"order": [[13, "desc"]],
"columns": [{
"data": "powerStationName"
}, {
"data": "controllerName"
}, {
"data": "uid"
}, {
"data": "name"
},{
"data": "enabledName"
}, {
"data": "statusName"
},{
"data": "typeName"
},{
"data": "brand"
}, {
"data": "productModel"
}, {
"data": "installDate"
}, {
"data": "dbName"
}, {
@ -488,19 +496,27 @@
"info": true,
"autoWidth": false,
"responsive": true,
"order": [[9, "desc"]],
"order": [[13, "desc"]],
"columns": [{
"data": "powerStationName"
}, {
"data": "controllerName"
}, {
"data": "uid"
}, {
"data": "name"
},{
"data": "enabledName"
}, {
"data": "statusName"
},{
"data": "typeName"
},{
"data": "brand"
}, {
"data": "productModel"
}, {
"data": "installDate"
}, {
"data": "dbName"
}, {
@ -868,9 +884,11 @@
$("#Inverter_Pyrheliometer_modal").append($("<option />").val('0').text("無設備"));
}
else {
$("#Inverter_Pyrheliometer_modal").append($("<option />").val('0').text("無設備"));
$.each(rel.data, function (index, val) {
$("#Inverter_Pyrheliometer_modal").append($("<option />").val(val.value).text(val.text));
});
}
});
@ -1844,6 +1862,9 @@
//#region 新增裝置資料
function AddDevice() {
selected_id = 0;
document.getElementById('Device_Type_modal').disabled = false;
document.getElementById('Device_Status_modal').disabled = true;
document.getElementById('Device_Enabled_modal').disabled = true;
$("#Device-modal .modal-title").html("裝置資料 - 新增");
$("#Device-form").trigger("reset");
$("#Device-modal").modal();
@ -2037,7 +2058,9 @@
DBName: $("#Device_DBName_modal").val(),
TableName: $("#Device_TableName_modal").val(),
ColName: $("#Device_ColName_modal").val(),
Remark: $("#Device_Remark_modal").val()
InstallDate: $("#Device_InstallDate_modal").val(),
Status: $("#Device_Status_modal").val(),
Enabled: $("#Device_Enabled_modal").val(),
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
@ -2078,6 +2101,8 @@
return;
}
document.getElementById('Device_Type_modal').disabled = true;
document.getElementById('Device_Status_modal').disabled = false;
document.getElementById('Device_Enabled_modal').disabled = false;
$("#Device_Type_modal").val(rel.data.type);
$("#Device_Brand_modal").val(rel.data.brand);
$("#Device_ProductModel_modal").val(rel.data.productModel);
@ -2085,6 +2110,12 @@
$("#Device_TableName_modal").val(rel.data.tableName);
$("#Device_ColName_modal").val(rel.data.colName);
$("#Device_Controller_modal").val(rel.data.controllerId);
$("#Device_Status_modal").val(rel.data.status);
$("#Device_Enabled_modal").val(rel.data.enabled);
$("#Device_InstallDate_modal").val(rel.data.installDate);
$("#Device-modal").modal();
}, 'json');
@ -2096,22 +2127,20 @@
$("#Inverter-modal .modal-title").html("逆變器 - 編輯");
selected_id = $(this).parents('tr').attr('data-id');
//取得單一運維基本資料
var url = "/PowerStation/GetOneInverter/";
var send_data = {
SelectedId: selected_id,
PowerStationId: stationId,
}
PyrheliometerList(stationId);
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
PyrheliometerList(stationId);
document.getElementById('Inverter_Status_modal').disabled = false;
document.getElementById('Inverter_Enabled_modal').disabled = false;
$("#Inverter_ControllerId_modal").val(rel.data.controllerId);

View File

@ -294,11 +294,11 @@
</div>
</div>
<div class="form-group col-lg-6">
<label class="form-label" for="Inverter_InstallDate"><span class="text-danger">*</span>安裝日期</label>
<input type="date" id="Device_InstallDate_modal" name="Inverter_InstallDate" class="form-control">
<label class="form-label" for="Device_InstallDate_modal"><span class="text-danger">*</span>安裝日期</label>
<input type="date" id="Device_InstallDate_modal" name="Device_InstallDate_modal" class="form-control">
</div>
<div class="form-group col-lg-3">
<label class="form-label" for="Inverter_Status">狀態</label>
<label class="form-label" for="Device_Status_modal">狀態</label>
<select class="form-control" id="Device_Status_modal" disabled>
<option value="0" action>未啟用</option>
<option value="1">正常</option>
@ -306,7 +306,7 @@
</select>
</div>
<div class="form-group col-lg-3">
<label class="form-label" for="Inverter_Enabled">啟用</label>
<label class="form-label" for="Device_Enabled_modal">啟用</label>
<select class="form-control" id="Device_Enabled_modal" disabled>
<option value="0" action>未啟用</option>
<option value="1">啟用</option>