[Backend] 更新device_node
This commit is contained in:
parent
f95674cf15
commit
2568624e52
@ -755,6 +755,7 @@ namespace Backend.Controllers
|
||||
public async Task<ApiResult<string>> ImportDevForCor([FromBody] List<ImportDevForCoo> post)
|
||||
{
|
||||
ApiResult<string> apiResult = new ApiResult<string>();
|
||||
var device_guid_record = "";
|
||||
try
|
||||
{
|
||||
if (post != null)
|
||||
@ -762,38 +763,43 @@ namespace Backend.Controllers
|
||||
if (post.Count > 0)
|
||||
{
|
||||
//清空device_node資料表
|
||||
//await backendRepository.TruncateTable("device_node");
|
||||
await backendRepository.TruncateTable("device_node");
|
||||
|
||||
//int node_priority = 1;
|
||||
int node_priority = 1;
|
||||
foreach(var idfc in post)
|
||||
{
|
||||
//if(idfc.device_number.IndexOf("_LT_L1") > -1)
|
||||
//{
|
||||
// //取得device_guid
|
||||
// var sWhere = $@"where deleted = 0 and device_number = " + idfc.device_number;
|
||||
// var device_guid = await backendRepository.GetOneAsync<string>("device_node", sWhere, "device_guid");
|
||||
if (idfc.device_number.IndexOf("_LT_L1") > -1)
|
||||
{
|
||||
//取得device_guid
|
||||
var sWhere = $@" deleted = 0 and device_number = '" + idfc.device_number + "'";
|
||||
var device_guid = await backendRepository.GetOneColAsync("device", sWhere, "device_guid");
|
||||
if(device_guid.ToString() != device_guid_record)
|
||||
{
|
||||
device_guid_record = device_guid.ToString();
|
||||
node_priority = 1;
|
||||
}
|
||||
|
||||
// //燈具
|
||||
// Dictionary<string, object> device = new Dictionary<string, object>();
|
||||
// device.Add("@device_node_guid", Guid.NewGuid());
|
||||
// device.Add("@deleted", 0);
|
||||
// device.Add("@device_guid", device_guid);
|
||||
// device.Add("@device_node_coordinate_3d", idfc.device_coordinate_3d);
|
||||
// device.Add("@forge_dbid", idfc.forge_dbid);
|
||||
// device.Add("@priority", node_priority);
|
||||
// device.Add("@created_by", myUserInfo.Userinfo_guid);
|
||||
// device.Add("@created_at", DateTime.Now);
|
||||
//燈具
|
||||
Dictionary<string, object> device = new Dictionary<string, object>();
|
||||
device.Add("@device_node_guid", Guid.NewGuid());
|
||||
device.Add("@deleted", 0);
|
||||
device.Add("@device_guid", device_guid);
|
||||
device.Add("@device_node_coordinate_3d", idfc.device_coordinate_3d);
|
||||
device.Add("@forge_dbid", idfc.forge_dbid);
|
||||
device.Add("@priority", node_priority);
|
||||
device.Add("@created_by", myUserInfo.Userinfo_guid);
|
||||
device.Add("@created_at", DateTime.Now);
|
||||
|
||||
// node_priority++;
|
||||
// await backendRepository.AddOneByCustomTableReturnId(device, "device_node", false);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
node_priority++;
|
||||
await backendRepository.AddOneByCustomTableReturnId(device, "device_node", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, object> device = new Dictionary<string, object>();
|
||||
device.Add("@device_coordinate_3d", idfc.device_coordinate_3d);
|
||||
device.Add("@forge_dbid", idfc.forge_dbid);
|
||||
await backendRepository.UpdateOneByCustomTable(device, "device", $@" device_number = '{idfc.device_number}'");
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -270,6 +270,41 @@ namespace Repository.BaseRepository.Implement
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 取得單一筆資料某一欄位(排序)
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="sWhere"></param>
|
||||
/// <param name="selCol">填放欄位</param>
|
||||
/// <param name="param">參數值</param>
|
||||
/// <param name="sOrderBy"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GetOneColAsync(string tableName, string sWhere, string selCol, object param = null, string sOrderBy = "")
|
||||
{
|
||||
string result;
|
||||
using (IDbConnection conn = GetDbConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
var sql = $"SELECT {selCol} FROM {tableName}";
|
||||
if (!string.IsNullOrEmpty(sWhere))
|
||||
{
|
||||
sql += $" WHERE {sWhere}";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(sOrderBy))
|
||||
{
|
||||
sql += $" ORDER BY {sOrderBy}";
|
||||
}
|
||||
|
||||
result = await conn.QueryFirstOrDefaultAsync<string>(sql, param);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得單一筆資料(根據自訂SQL, 自訂參數)
|
||||
|
@ -95,6 +95,18 @@ namespace Repository.BaseRepository.Interface
|
||||
/// <returns></returns>
|
||||
Task<object> GetOneAsync(string tableName, string sWhere, string selCol, object param = null, string sOrderBy = "");
|
||||
/// <summary>
|
||||
/// 取得單一筆資料某一欄位(排序),不需sWhere及sOrderBy填""
|
||||
/// <para>
|
||||
/// SELECT {selCol} FROM {tableName} WHERE {sWhere} ORDER BY {sOrderBy}
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="sWhere"></param>
|
||||
/// <param name="sOrderBy"></param>
|
||||
/// <param name="selCol">填放欄位</param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetOneColAsync(string tableName, string sWhere, string selCol, object param = null, string sOrderBy = "");
|
||||
/// <summary>
|
||||
/// 取得單一筆資料(根據自訂SQL, 自訂參數)
|
||||
/// </summary>
|
||||
/// <param name="sqlString"></param>
|
||||
|
Loading…
Reference in New Issue
Block a user