fix:接口

This commit is contained in:
geh
2025-02-20 17:21:35 +08:00
parent 0a70ab9af7
commit edda376377
12 changed files with 778 additions and 38 deletions
@@ -0,0 +1,55 @@
using BLL;
using System;
using System.Linq;
using System.Web.Http;
namespace WebAPI.Controllers.HSSE
{
public class AwardStandardsController : ApiController
{
#region
/// <summary>
/// 获取集合
/// </summary>
/// <returns></returns>
public Model.ResponeData getAwardStandardsList()
{
var responeData = new Model.ResponeData();
try
{
responeData.data = AwardStandardsService.GetAwardStandardsList();
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region id获取
/// <summary>
/// 根据id获取
/// </summary>
/// <returns></returns>
public Model.ResponeData getAwardStandardsListById(string AwardStandardsId)
{
var responeData = new Model.ResponeData();
try
{
responeData.data = AwardStandardsService.GetAwardStandardsListById(AwardStandardsId);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
}
}
@@ -0,0 +1,55 @@
using BLL;
using System;
using System.Linq;
using System.Web.Http;
namespace WebAPI.Controllers.HSSE
{
public class ConstructionStandardsController : ApiController
{
#region
/// <summary>
/// 获取集合
/// </summary>
/// <returns></returns>
public Model.ResponeData getConstructionStandardsList()
{
var responeData = new Model.ResponeData();
try
{
responeData.data = ConstructionStandardsService.GetConstructionStandardsList();
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region id获取
/// <summary>
/// 根据id获取
/// </summary>
/// <returns></returns>
public Model.ResponeData getConstructionStandardsListById(string ConstructionStandardsId)
{
var responeData = new Model.ResponeData();
try
{
responeData.data = ConstructionStandardsService.GetConstructionStandardsListById(ConstructionStandardsId);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
}
}
@@ -0,0 +1,135 @@
using System;
using System.IO;
using RestSharp; //依赖版本106.15.0 https://www.nuget.org/packages/RestSharp/106.15.0
using Newtonsoft.Json; //https://www.nuget.org/packages/Newtonsoft.Json
using System.Web.Http;
using System.Collections.Generic;
namespace WebAPI.Controllers.HSSE
{
public class ImageRecognitionController : ApiController
{
const string API_KEY = "2pHOZ7ff76vYgYoIwQnTIB31";
const string SECRET_KEY = "8q4Oa8wLi6xorfYQgUlEBqM4OOHqFXL7";
[HttpPost]
public Model.ResponeData getImageContent([FromBody] ImageRequest imageRequest)
{
var responeData = new Model.ResponeData();
try
{
var client = new RestClient($"https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token={GetAccessToken()}");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
string image = imageRequest.Image;
var body = $@"{{""image"":""{image}"",""image_type"":""BASE64"",""max_face_num"":30}}";
request.AddParameter("application/json", body, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
string json = response.Content;
var responseData = JsonConvert.DeserializeObject<ResponseData>(json);
int errorCode = responseData.error_code;
if (errorCode != 0)
{
responeData.message = responseData.error_msg;
}
else
{
int faceNum = responseData.result.face_num;
responeData.data = faceNum;
}
}
catch (Exception ex)
{
responeData.code = 0;
}
return responeData;
}
/**
* 获取文件base64编码
* @param path 文件路径
* @return base64编码信息,不带文件头
*/
public string GetFileContentAsBase64(string path)
{
using (FileStream filestream = new FileStream(path, FileMode.Open))
{
byte[] arr = new byte[filestream.Length];
filestream.Read(arr, 0, (int)filestream.Length);
string base64 = Convert.ToBase64String(arr);
return base64;
}
}
/**
* 使用 AKSK 生成鉴权签名(Access Token
* @return 鉴权签名信息(Access Token
*/
public string GetAccessToken()
{
var client = new RestClient($"https://aip.baidubce.com/oauth/2.0/token");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddParameter("grant_type", "client_credentials");
request.AddParameter("client_id", API_KEY);
request.AddParameter("client_secret", SECRET_KEY);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
var result = JsonConvert.DeserializeObject<dynamic>(response.Content);
return result.access_token.ToString();
}
public class ImageRequest
{
public string Image { get; set; }
}
public class Location
{
public double left { get; set; }
public double top { get; set; }
public double width { get; set; }
public double height { get; set; }
public double rotation { get; set; }
}
public class Angle
{
public double yaw { get; set; }
public double pitch { get; set; }
public double roll { get; set; }
}
public class Face
{
public string face_token { get; set; }
public Location location { get; set; }
public double face_probability { get; set; }
public Angle angle { get; set; }
}
public class Result
{
public int face_num { get; set; }
public List<Face> face_list { get; set; }
}
public class ResponseData
{
public int error_code { get; set; }
public string error_msg { get; set; }
public long log_id { get; set; }
public long timestamp { get; set; }
public int cached { get; set; }
public Result result { get; set; }
}
}
}
@@ -0,0 +1,54 @@
using BLL;
using System;
using System.Linq;
using System.Web.Http;
namespace WebAPI.Controllers.HSSE
{
public class ProtectionStandardsController : ApiController
{
#region
/// <summary>
/// 获取集合
/// </summary>
/// <returns></returns>
public Model.ResponeData getProtectionStandardsList()
{
var responeData = new Model.ResponeData();
try
{
responeData.data = ProtectionStandardsService.GetProtectionStandardsList();
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region id获取
/// <summary>
/// 根据id获取
/// </summary>
/// <returns></returns>
public Model.ResponeData getProtectionStandardsListById(string ProtectionStandardsId)
{
var responeData = new Model.ResponeData();
try
{
responeData.data = ProtectionStandardsService.GetProtectionStandardsListById(ProtectionStandardsId);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
}
}
@@ -0,0 +1,53 @@
using BLL;
using System;
using System.Linq;
using System.Web.Http;
namespace WebAPI.Controllers.HSSE
{
public class RectifyController : ApiController
{
#region
/// <summary>
/// 获取集合
/// </summary>
/// <returns></returns>
public Model.ResponeData getRectifyList(string RectifyName, int PageNumber, int PageSize)
{
var responeData = new Model.ResponeData();
try
{
var query = (from x in Funs.DB.Technique_RectifyItem
join y in Funs.DB.Technique_Rectify
on x.RectifyId equals y.RectifyId
select new
{
y.RectifyId,
y.RectifyName,
x.HazardSourcePoint,
x.RiskAnalysis,
x.RiskPrevention
}).ToList();
if (!string.IsNullOrEmpty(RectifyName))
{
query = query.Where(x => x.RectifyName.Contains(RectifyName)).ToList();
}
var paginatedQuery = query
.Skip((PageNumber - 1) * PageSize)
.Take(PageSize)
.ToList();
responeData.data = paginatedQuery;
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
}
}
@@ -0,0 +1,55 @@
using BLL;
using System;
using System.Linq;
using System.Web.Http;
namespace WebAPI.Controllers.HSSE
{
public class SafetyResponsibilitiesController : ApiController
{
#region
/// <summary>
/// 获取集合
/// </summary>
/// <returns></returns>
public Model.ResponeData getSafetyResponsibilitiesList()
{
var responeData = new Model.ResponeData();
try
{
responeData.data = SafetyResponsibilitiesService.GetSafetyResponsibilitiesList();
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region id获取
/// <summary>
/// 根据id获取
/// </summary>
/// <returns></returns>
public Model.ResponeData getSafetyResponsibilitiesListById(string SafetyResponsibilitiesId)
{
var responeData = new Model.ResponeData();
try
{
responeData.data = SafetyResponsibilitiesService.GetSafetyResponsibilitiesListById(SafetyResponsibilitiesId);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
}
}