Merge branch 'master' into kai

This commit is contained in:
Kai 2021-06-18 12:39:25 +08:00
commit eaf6a4e9c6
9 changed files with 60 additions and 20 deletions

View File

@ -829,6 +829,18 @@ namespace SolarPower.Controllers
{ {
if (Device.Id == 0) if (Device.Id == 0)
{ {
PowerStation powerStation = null;
powerStation = await powerStationRepository.GetOneAsync(Device.PowerStationId);
string Number = await powerStationRepository.GetFinalSerialNumber(Device.PowerStationId, Device.Type);
var tempSerialNumber = 0;
if (!string.IsNullOrEmpty(Number))
{
tempSerialNumber = Convert.ToInt32(Number) + 1;
}
else
{
tempSerialNumber = 1;
}
Device DeviceInfo = new Device() Device DeviceInfo = new Device()
{ {
Brand = Device.Brand, Brand = Device.Brand,
@ -841,9 +853,10 @@ namespace SolarPower.Controllers
Remark = Device.Remark, Remark = Device.Remark,
TableName = Device.TableName, TableName = Device.TableName,
Type = Device.Type, Type = Device.Type,
UID = Device.PowerStationId + "-" + Device.Type, UID = powerStation.Code + "-" + Device.Type + "-" + tempSerialNumber.ToString().PadLeft(3,'0'),
CreatedBy = myUser.Id, CreatedBy = myUser.Id,
TypeName = Device.TypeName TypeName = Device.TypeName,
SerialNumber = tempSerialNumber.ToString().PadLeft(3, '0')
}; };
List<string> properties = new List<string>() List<string> properties = new List<string>()
{ {
@ -859,7 +872,8 @@ namespace SolarPower.Controllers
"Type", "Type",
"UID", "UID",
"CreatedBy", "CreatedBy",
"TypeName" "TypeName",
"SerialNumber"
}; };
await powerStationRepository.AddDevice(DeviceInfo,properties); await powerStationRepository.AddDevice(DeviceInfo,properties);
@ -878,9 +892,6 @@ namespace SolarPower.Controllers
Name = Device.Name, Name = Device.Name,
ProductModel = Device.ProductModel, ProductModel = Device.ProductModel,
Remark = Device.Remark, Remark = Device.Remark,
TableName = Device.TableName,
Type = Device.Type,
UID = Device.PowerStationId + "-" + Device.Type,
CreatedBy = myUser.Id, CreatedBy = myUser.Id,
TypeName = Device.TypeName TypeName = Device.TypeName
}; };
@ -894,9 +905,6 @@ namespace SolarPower.Controllers
"Name", "Name",
"ProductModel", "ProductModel",
"Remark", "Remark",
"TableName",
"Type",
"UID",
"CreatedBy", "CreatedBy",
"TypeName" "TypeName"
}; };

View File

@ -819,6 +819,7 @@ INSERT INTO `variable` (`id`, `name`, `value`, `remark`) VALUES
/****************************** /******************************
** SQL修改從以下開始新增 ** ** SQL修改從以下開始新增 **
*******************************/ *******************************/
ALTER TABLE `device` ADD COLUMN `SerialNumber` VARCHAR(3) NULL DEFAULT NULL COMMENT '單一設備流水號' COLLATE 'utf8mb4_unicode_ci' AFTER `PowerStationId`;/* 設備流水號 - 2021/6/18 12:21:00 */

View File

@ -37,7 +37,7 @@ namespace SolarPower.Helper
var passwordStr = ed.DESDecrypt(dbConfig.Password); var passwordStr = ed.DESDecrypt(dbConfig.Password);
//var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;";
var connStr = @"server=127.0.0.1;database=solar_power;user=root;password=000000;charset=utf8;"; var connStr = @"server=127.0.0.1;port=3308;database=solar_power;user=root;password=00000000;charset=utf8;";
this._connectionString = connStr; this._connectionString = connStr;
} }

View File

@ -330,6 +330,7 @@ namespace SolarPower.Models.PowerStation
{ {
public string UID { get; set; }//設備編號 public string UID { get; set; }//設備編號
public int CreatedBy { get; set; }//建立者 public int CreatedBy { get; set; }//建立者
public string SerialNumber { get; set; }
} }
/// <summary> /// <summary>
///設備dataTable ///設備dataTable

View File

@ -786,5 +786,28 @@ namespace SolarPower.Repository.Implement
conn.Close(); conn.Close();
} }
} }
public async Task<string> GetFinalSerialNumber(int PowerStationId, string Type)
{
string Num;
using IDbConnection conn = _databaseHelper.GetConnection();
conn.Open();
var trans = conn.BeginTransaction();
try
{
var sql = "SELECT SerialNumber FROM device WHERE PowerStationId = @PowerStationId AND Type = @Type ORDER BY SerialNumber DESC";
Num = await conn.QueryFirstOrDefaultAsync<string>(sql, new { PowerStationId = PowerStationId, Type = Type });
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
return Num;
}
} }
} }

View File

@ -181,5 +181,12 @@ namespace SolarPower.Repository.Interface
/// <param name="properties"></param> /// <param name="properties"></param>
/// <returns></returns> /// <returns></returns>
Task UpdateException(ExceptionModal Exception, List<string> properties); Task UpdateException(ExceptionModal Exception, List<string> properties);
/// <summary>
/// 取最後一個設備流水號
/// </summary>
/// <param name="PowerStationId"></param>
/// <param name="Type"></param>
/// <returns></returns>
Task<string> GetFinalSerialNumber(int PowerStationId, string Type);
} }
} }

View File

@ -389,12 +389,12 @@
</div> </div>
<div class=" d-flex justify-content-between"> <div class=" d-flex justify-content-between">
<p>逆變器數量</p> <p>逆變器數量</p>
<p><span id="kwhkwp" class="color-primary-400">2,5840</span> NT</p> <p><span id="kwhkwp" class="color-primary-400">2,5840</span></p>
</div> </div>
<div class=" d-flex justify-content-between"> <div class=" d-flex justify-content-between">
<p>台電掛表日</p> <p>台電掛表日</p>
<p><span id="PR" class="color-primary-400">90</span> %</p> <p><span id="PR" class="color-primary-400">90</span></p>
</div> </div>
</li> </li>
@ -448,7 +448,7 @@
//電站卡片 //電站卡片
$('#templateCard').find('.col-xl-2').attr('id', '001').clone().appendTo($('#solarCardnewtaipei')); $('#templateCard').find('.col-xl-2').attr('id', '001').clone().appendTo($('#solarCardnewtaipei'));
$('#001').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=1'); $('#001').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=1');
$('#001').find('#editSolarUrl').find('#Solarimg').attr('src', '~/upload/power_station/1/main.png'); $('#001').find('#editSolarUrl').find('#Solarimg').attr('src', '/upload/power_station/1/main.png');
$('#001').find('#solarName').text('三重慈濟站'); $('#001').find('#solarName').text('三重慈濟站');
$('#001').find('#today_kwh').text('1000'); $('#001').find('#today_kwh').text('1000');
$('#001').find('#kwhkwp').text('10'); $('#001').find('#kwhkwp').text('10');
@ -467,7 +467,7 @@
$('#templateCard').find('.col-xl-2').attr('id', '002').clone().appendTo($('#solarCardnewtaipei')); $('#templateCard').find('.col-xl-2').attr('id', '002').clone().appendTo($('#solarCardnewtaipei'));
$('#002').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=2'); $('#002').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=2');
$('#002').find('#editSolarUrl').find('#Solarimg').attr('src', '~/upload/power_station/2/main.png'); $('#002').find('#editSolarUrl').find('#Solarimg').attr('src', '/upload/power_station/2/main.png');
$('#002').find('#solarName').text('板橋慈濟站'); $('#002').find('#solarName').text('板橋慈濟站');
$('#002').find('#today_kwh').text('2000'); $('#002').find('#today_kwh').text('2000');
$('#002').find('#kwhkwp').text('110'); $('#002').find('#kwhkwp').text('110');
@ -484,7 +484,7 @@
$('#templateCard').find('.col-xl-2').attr('id', '003').clone().appendTo($('#solarCardHsinchu')); $('#templateCard').find('.col-xl-2').attr('id', '003').clone().appendTo($('#solarCardHsinchu'));
$('#003').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=3'); $('#003').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=3');
$('#003').find('#editSolarUrl').find('#Solarimg').attr('src', '~/upload/power_station/3/main.png'); $('#003').find('#editSolarUrl').find('#Solarimg').attr('src', '/upload/power_station/3/main.png');
$('#003').find('#solarName').text('新竹巨城站'); $('#003').find('#solarName').text('新竹巨城站');
$('#003').find('#today_kwh').text('3000'); $('#003').find('#today_kwh').text('3000');
$('#003').find('#kwhkwp').text('166'); $('#003').find('#kwhkwp').text('166');
@ -500,7 +500,7 @@
'</tr>'); '</tr>');
$('#templateCard').find('.col-xl-2').attr('id', '004').clone().appendTo($('#solarCardHsinchu')); $('#templateCard').find('.col-xl-2').attr('id', '004').clone().appendTo($('#solarCardHsinchu'));
$('#004').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=4'); $('#004').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=4');
$('#004').find('#editSolarUrl').find('#Solarimg').attr('src', '~/upload/power_station/4/main.png'); $('#004').find('#editSolarUrl').find('#Solarimg').attr('src', '/upload/power_station/4/main.png');
$('#004').find('#solarName').text('新竹交大站'); $('#004').find('#solarName').text('新竹交大站');
$('#004').find('#today_kwh').text('4000'); $('#004').find('#today_kwh').text('4000');
$('#004').find('#kwhkwp').text('205'); $('#004').find('#kwhkwp').text('205');
@ -517,7 +517,7 @@
$('#templateCard').find('.col-xl-2').attr('id', '005').clone().appendTo($('#solarCardHsinchu')); $('#templateCard').find('.col-xl-2').attr('id', '005').clone().appendTo($('#solarCardHsinchu'));
$('#005').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=5'); $('#005').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=5');
$('#005').find('#editSolarUrl').find('#Solarimg').attr('src', '~/upload/power_station/5/main.jpg'); $('#005').find('#editSolarUrl').find('#Solarimg').attr('src', '/upload/power_station/5/main.jpg');
$('#005').find('#solarName').text('新竹動物園站'); $('#005').find('#solarName').text('新竹動物園站');
$('#005').find('#today_kwh').text('123'); $('#005').find('#today_kwh').text('123');
$('#005').find('#kwhkwp').text('600'); $('#005').find('#kwhkwp').text('600');
@ -534,7 +534,7 @@
$('#templateCard').find('.col-xl-2').attr('id', '006').clone().appendTo($('#solarCardPingtung')); $('#templateCard').find('.col-xl-2').attr('id', '006').clone().appendTo($('#solarCardPingtung'));
$('#006').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=6'); $('#006').find('#editSolarUrl').attr('href', localurl + '/edit?stationId=6');
$('#006').find('#editSolarUrl').find('#Solarimg').attr('src', '~/upload/power_station/6/main.png'); $('#006').find('#editSolarUrl').find('#Solarimg').attr('src', '/upload/power_station/6/main.png');
$('#006').find('#solarName').text('屏東枋山海纜站'); $('#006').find('#solarName').text('屏東枋山海纜站');
$('#006').find('#today_kwh').text('4954'); $('#006').find('#today_kwh').text('4954');
$('#006').find('#kwhkwp').text('13'); $('#006').find('#kwhkwp').text('13');

View File

@ -1471,7 +1471,7 @@
toast_error(rel.msg); toast_error(rel.msg);
return; return;
} }
document.getElementById('Device_Type_modal').disabled = true;
$("#Device_Name_modal").val(rel.data.name); $("#Device_Name_modal").val(rel.data.name);
$("#Device_Type_modal").val(rel.data.type); $("#Device_Type_modal").val(rel.data.type);
$("#Device_Brand_modal").val(rel.data.brand); $("#Device_Brand_modal").val(rel.data.brand);

View File

@ -79,7 +79,7 @@
</div> </div>
<div class="form-group col-lg-6"> <div class="form-group col-lg-6">
<div style="margin-bottom: 0.3rem"> <div style="margin-bottom: 0.3rem">
<label class="form-label" for="Device_Remark_modal"><span class="text-danger">*</span>備註</label> <label class="form-label" for="Device_Remark_modal">備註</label>
<input type="text" id="Device_Remark_modal" name="Device_Remark_modal" class="form-control"> <input type="text" id="Device_Remark_modal" name="Device_Remark_modal" class="form-control">
</div> </div>
</div> </div>