[FrontedWebApi][運維管理] sql 調整

This commit is contained in:
dev01 2022-11-12 12:07:12 +08:00
commit 1aa48f5297
2 changed files with 122 additions and 10 deletions

View File

@ -100,16 +100,16 @@ namespace FrontendWebApi.ApiControllers
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<List<BuildingList>>> AreaList()
public async Task<ApiResult<List<BuildingList>>> AreaList([FromBody] BuildingList b)
{
ApiResult<List<BuildingList>> apiResult = new ApiResult<List<BuildingList>>();
List<BuildingList> bl = new List<BuildingList>();
try
{
var sqlString = @$"select system_key as area_name, system_value as device_area_tag from variable where deleted = 0 and system_type = 'area'";
var sqlString = @$"select device_area_tag from device where deleted = 0 and device_system_tag = @main_system_tag and device_name_tag = @sub_system_tag";
bl = await backendRepository.GetAllAsync<BuildingList>(sqlString);
bl = await backendRepository.GetAllAsync<BuildingList>(sqlString, new { @main_system_tag = b.main_system_tag, @sub_system_tag = b.sub_system_tag });
apiResult.Code = "0000";
apiResult.Data = bl;
@ -142,7 +142,7 @@ namespace FrontendWebApi.ApiControllers
where d.deleted = 0 and d.device_area_tag = @device_area_tag
group by b.full_name, d.device_building_tag";
bl = await backendRepository.GetAllAsync<BuildingList>(sqlString, new { @device_area_tag = b.device_area_tag });
bl = await backendRepository.GetAllAsync<BuildingList>(sqlString, new { @device_area_tag = b.device_area_tag, @main_system_tag = b.main_system_tag, @sub_system_tag = b.sub_system_tag });
apiResult.Code = "0000";
apiResult.Data = bl;
@ -171,10 +171,10 @@ namespace FrontendWebApi.ApiControllers
{
var sqlString = @$"select d.device_floor_tag
from device d
where d.deleted = 0 and d.device_area_tag = @device_area_tag and d.device_building_tag = @device_building_tag
where d.deleted = 0 and d.device_area_tag = @device_area_tag and d.device_building_tag = @device_building_tag and d.device_system_tag = @main_system_tag and d.device_name_tag = @sub_system_tag
group by d.device_floor_tag";
bl = await backendRepository.GetAllAsync<BuildingList>(sqlString, new { @device_area_tag = b.device_area_tag, @device_building_tag = b.device_building_tag });
bl = await backendRepository.GetAllAsync<BuildingList>(sqlString, new { @device_area_tag = b.device_area_tag, @device_building_tag = b.device_building_tag, @main_system_tag = b.main_system_tag, @sub_system_tag = b.sub_system_tag });
apiResult.Code = "0000";
apiResult.Data = bl;
@ -202,9 +202,9 @@ namespace FrontendWebApi.ApiControllers
try
{
var sqlString = @$"select device_number, concat(device_floor_tag, ' ', device_last_name, ' ', device_serial_tag) as device_name
from device where deleted = 0 and device_area_tag = @device_area_tag and device_building_tag = @device_building_tag and device_floor_tag = @device_floor_tag";
from device where deleted = 0 and device_area_tag = @device_area_tag and device_building_tag = @device_building_tag and device_floor_tag = @device_floor_tag and d.device_system_tag = @main_system_tag and d.device_name_tag = @sub_system_tag ";
var param = new { @device_building_tag = bl.device_building_tag, @device_floor_tag = bl.device_floor_tag, @device_area_tag = bl.device_area_tag };
var param = new { @device_building_tag = bl.device_building_tag, @device_floor_tag = bl.device_floor_tag, @device_area_tag = bl.device_area_tag, @main_system_tag = bl.main_system_tag, @sub_system_tag = bl.sub_system_tag };
d = await backendRepository.GetAllAsync<Device>(sqlString, param);
@ -681,7 +681,6 @@ namespace FrontendWebApi.ApiControllers
left join variable v2 on v1.id = v2.system_parent_id and ofi.device_system_category_layer3 = v2.system_value and v2.system_type = @sub_system_type and v2.deleted = 0
where ofi.deleted = 0" + sWhere;
var param = new { @sub_system_type = sub_system_type, @start_created_at = ofl.start_created_at, @end_created_at = ofl.end_created_at, @sub_system_tag = ofl.sub_system_tag, @main_system_tag = ofl.main_system_tag };
opList = await backendRepository.GetAllAsync<Operation_Firm>(sqlString, param);
}
@ -704,6 +703,39 @@ namespace FrontendWebApi.ApiControllers
return apiResult;
}
/// <summary>
/// 廠商資料讀取(搜寻) / selection讀取 ofl = null
/// </summary>
/// <param name="ofl"></param>
/// <returns></returns>
public async Task<ApiResult<Operation_Firm>> OpeFirRead([FromBody] OperationFindList ofl)
{
ApiResult<Operation_Firm> apiResult = new ApiResult<Operation_Firm>();
Operation_Firm opList = new Operation_Firm();
try
{
var sqlString = @$"select of.*, v2.system_key
from operation_firm of
left join variable v1 on of.device_system_category_layer2 = v1.system_value and v1.system_type = @main_system_type and v1.deleted = 0 and of.device_system_category_layer2 = v1.system_value
left join variable v2 on v1.id = v2.system_parent_id and of.device_system_category_layer3 = v2.system_value and v2.deleted = 0
where of.deleted = 0 and of.id = @id";
var param = new { @id = ofl.id };
opList = await backendRepository.GetOneAsync<Operation_Firm>(sqlString, param);
apiResult.Code = "0000";
apiResult.Data = opList;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 新增一笔廠商資料
/// </summary>
@ -820,6 +852,36 @@ namespace FrontendWebApi.ApiControllers
return apiResult;
}
/// <summary>
/// 廠商---刪除
/// </summary>
/// <param name="or"></param>
/// <returns></returns>
public async Task<ApiResult<string>> DelOpeFirm([FromBody] Operation_Firm or)
{
ApiResult<string> apiResult = new ApiResult<string>();
try
{
var sqlString = @$"UPDATE operation_firm SET deleted = 1 WHERE id = @id";
var param = new { @id = or.id };
await backendRepository.ExecuteSql(sqlString, param);
apiResult.Code = "0000";
apiResult.Data = "刪除成功";
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
string json = System.Text.Json.JsonSerializer.Serialize(or);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
#endregion
#region /
@ -901,6 +963,52 @@ namespace FrontendWebApi.ApiControllers
return apiResult;
}
#region /
/// <summary>
/// 維修/保養 讀取(work_type)
/// </summary>
/// <param name="ofl"></param>
/// <returns></returns>
public async Task<ApiResult<Operation_Record>> OpeRecRead([FromBody] OperationFindList ofl)
{
ApiResult<Operation_Record> apiResult = new ApiResult<Operation_Record>();
Operation_Record orl = new Operation_Record();
try
{
var sqlString = $@"select opr.*, concat(d.device_floor_tag, ' ', d.device_last_name, ' ', d.device_serial_tag) as device_name, ui.full_name as user_full_name
from operation_record opr
left join device d on opr.fix_do_code = d.device_number
left join userinfo ui on opr.work_person_id = ui.id
where opr.deleted = 0 and opr.id = @id";
var param = new { @id = ofl.id };
orl = await backendRepository.GetOneAsync<Operation_Record>(sqlString, param);
if (orl != null)
{
sqlString = $@"select * from operation_record_file where record_id = @record_id and deleted = 0";
var oParam = new { @record_id = orl.id };
var orfl = await backendRepository.GetAllAsync<Operation_Record_File>(sqlString, oParam);
orl.lorf = orfl;
}
apiResult.Code = "0000";
apiResult.Data = orl;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
string json = System.Text.Json.JsonSerializer.Serialize(ofl);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
/// <summary>
/// 維修/保養---新增/編輯
/// </summary>

View File

@ -38,6 +38,7 @@ namespace FrontendWebApi.Models
public class OperationFindList
{
public int id { get; set; }
public string serial_number { get; set; } //表单号
public DateTime? start_created_at { get; set; }//开始建立时间
public DateTime? end_created_at { get; set; }//结束建立时间
@ -53,7 +54,10 @@ namespace FrontendWebApi.Models
public string device_area_tag { get; set; }
public string device_building_tag { get; set; }
public string device_floor_tag { get; set; }
public string full_name { get; set; }
public string area_name { get; set; }
public string building_name { get; set; }
public string main_system_tag { get; set; }//大类tag
public string sub_system_tag { get; set; }//小类tag
}
public class Operation_Record : Actor