20231206新增获取全部安全巡检接口

This commit is contained in:
2023-12-06 14:41:12 +08:00
parent 88d09e2602
commit 4ba87f6ffd
6 changed files with 178 additions and 19 deletions
@@ -125,5 +125,51 @@ namespace WebAPI.Controllers
return responeData;
}
#endregion
#region
/// <summary>
/// 获取总安全巡检
/// </summary>
/// <returns></returns>
public Model.ResponeData getHazardRegisterTotalCount()
{
var responeData = new Model.ResponeData();
try
{
//总数
responeData.data = Funs.DB.HSSE_Hazard_HazardRegister.Where(x => x.ProjectId != null && x.States != null).Count();
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
#region
/// <summary>
/// 获取总安全巡检
/// </summary>
/// <param name="pageIndex">页码</param>
/// <returns></returns>
public Model.ResponeData getHazardRegisterByProjectIdStates(int pageIndex)
{
var responeData = new Model.ResponeData();
try
{
responeData.data = APIHazardRegisterService.getHazardRegisterByProjectIdStates(pageIndex);
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
#endregion
}
}
+24 -17
View File
@@ -23,9 +23,11 @@ namespace WebAPI.Filter
bool isOk = false;
actionContext.Request.Headers.TryGetValues("token", out IEnumerable<string> token);
string strValues = actionContext.ActionDescriptor.ControllerDescriptor.ControllerName + "*" + ((ReflectedHttpActionDescriptor)actionContext.ActionDescriptor).ActionName;
bool isWithOut = false;
if (lists.FirstOrDefault(x => x == strValues) != null)
{
isOk = true;
isWithOut = true;
}
if (!isOk && token != null)
@@ -46,24 +48,29 @@ namespace WebAPI.Filter
}
// base.OnActionExecuting(actionContext);
if (isOk)
{ // 在调用 Action 方法之前执行的代码,可获取请求的接口名称和参数
IDictionary<string, object> arguments = actionContext.ActionArguments; // 获取参数
foreach (KeyValuePair<string, object> item in arguments)
{
if (!isWithOut)
{
if (item.Key == "projectid" || item.Key == "ProjectId" || item.Key == "projectId" || item.Key == "Projectid")
{
var ProjectItems = APIProjectService.geProjectsByUserId(token.FirstOrDefault());
List<string> projects = new List<string>();
if (ProjectItems.Count > 0)
{
projects = ProjectItems.Select(x => x.ProjectId).ToList();
}
if (item.Value != null && !projects.Contains(item.Value.ToString()))
{
actionContext.Response = actionContext.Request.CreateResponse(System.Net.HttpStatusCode.OK,
new { code = "0", message = "您没有该项目权限!" }, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
return;
// 在调用 Action 方法之前执行的代码,可获取请求的接口名称和参数
IDictionary<string, object> arguments = actionContext.ActionArguments; // 获取参数
foreach (KeyValuePair<string, object> item in arguments)
{
if (item.Key == "projectid" || item.Key == "ProjectId" || item.Key == "projectId" || item.Key == "Projectid")
{
var ProjectItems = APIProjectService.geProjectsByUserId(token.FirstOrDefault());
List<string> projects = new List<string>();
if (ProjectItems.Count > 0)
{
projects = ProjectItems.Select(x => x.ProjectId).ToList();
}
if (item.Value != null && !projects.Contains(item.Value.ToString()))
{
actionContext.Response = actionContext.Request.CreateResponse(System.Net.HttpStatusCode.OK,
new { code = "0", message = "您没有该项目权限!" }, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
return;
}
}
}
}
@@ -79,7 +86,7 @@ namespace WebAPI.Filter
/// <summary>
///
/// </summary>
public static List<string> lists = new List<string> { "User*postLoginOn", "get*token" };
public static List<string> lists = new List<string> { "User*postLoginOn", "get*token", "HazardRegister*getHazardRegisterTotalCount", "HazardRegister*getHazardRegisterByProjectIdStates" };
/// <summary>
///
+2 -2
View File
@@ -322,9 +322,9 @@
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>7040</DevelopmentServerPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:7040/</IISUrl>
<IISUrl>http://localhost:10684/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>