曹衍涛
2 years ago
426 changed files with 61620 additions and 0 deletions
@ -0,0 +1,12 @@
|
||||
{ |
||||
"version": 1, |
||||
"isRoot": true, |
||||
"tools": { |
||||
"dotnet-ef": { |
||||
"version": "5.0.0", |
||||
"commands": [ |
||||
"dotnet-ef" |
||||
] |
||||
} |
||||
} |
||||
} |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
{ |
||||
"ExpandedNodes": [ |
||||
"" |
||||
], |
||||
"SelectedNode": "\\DbContextExtensions.cs", |
||||
"PreviewInSolutionExplorer": false |
||||
} |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00 |
||||
# Visual Studio Version 17 |
||||
VisualStudioVersion = 17.3.32825.248 |
||||
MinimumVisualStudioVersion = 10.0.40219.1 |
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AX.FireTrainingSys", "AX.FireTrainingSys.csproj", "{496FE679-02A7-4E97-BE50-2C8C0471DAD3}" |
||||
EndProject |
||||
Global |
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
Debug|Any CPU = Debug|Any CPU |
||||
Release|Any CPU = Release|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
{496FE679-02A7-4E97-BE50-2C8C0471DAD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{496FE679-02A7-4E97-BE50-2C8C0471DAD3}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{496FE679-02A7-4E97-BE50-2C8C0471DAD3}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{496FE679-02A7-4E97-BE50-2C8C0471DAD3}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(SolutionProperties) = preSolution |
||||
HideSolutionNode = FALSE |
||||
EndGlobalSection |
||||
GlobalSection(ExtensibilityGlobals) = postSolution |
||||
SolutionGuid = {9FE37BCA-2ECD-49EC-A37F-84006BF3A4F0} |
||||
EndGlobalSection |
||||
EndGlobal |
@ -0,0 +1,72 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
<PropertyGroup> |
||||
<TargetFramework>net6.0</TargetFramework> |
||||
<Version>1.4.0</Version> |
||||
<UserSecretsId>30084039-e333-4fc8-aea1-c97fd410def1</UserSecretsId> |
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> |
||||
<NoWarn>1701;1702;1591</NoWarn> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> |
||||
<NoWarn>1701;1702;1591</NoWarn> |
||||
<DocumentationFile> |
||||
</DocumentationFile> |
||||
<OutputPath>bin\Debug\</OutputPath> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Compile Remove="ReplayTemp\**" /> |
||||
<Content Remove="ReplayTemp\**" /> |
||||
<EmbeddedResource Remove="ReplayTemp\**" /> |
||||
<None Remove="ReplayTemp\**" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2" /> |
||||
<PackageReference Include="Mapster" Version="7.0.0" /> |
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" /> |
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.2.0" /> |
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.0" /> |
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" /> |
||||
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.2.0" /> |
||||
<PackageReference Include="Minio.AspNetCore" Version="3.1.13" /> |
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> |
||||
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="5.6.3" /> |
||||
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.346202"> |
||||
<PrivateAssets>all</PrivateAssets> |
||||
</PackageReference> |
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.17" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<TrimmerRootAssembly Include="System.IO.Compression.FileSystem" /> |
||||
<TrimmerRootAssembly Include="System.IO.Compression.ZipFile" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<None Update="Banners\0.txt"> |
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> |
||||
</None> |
||||
<None Update="Banners\1.txt"> |
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> |
||||
</None> |
||||
<None Update="Banners\2.txt"> |
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> |
||||
</None> |
||||
<None Update="Banners\3.txt"> |
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> |
||||
</None> |
||||
<None Update="Banners\4.txt"> |
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> |
||||
</None> |
||||
<None Update="Banners\5.txt"> |
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> |
||||
</None> |
||||
<None Update="Banners\6.txt"> |
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> |
||||
</None> |
||||
<None Update="Banners\7.txt"> |
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
||||
</None> |
||||
<None Update="License.dat"> |
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
||||
</None> |
||||
</ItemGroup> |
||||
</Project> |
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> |
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor> |
||||
</PropertyGroup> |
||||
<PropertyGroup> |
||||
<ActiveDebugProfile>AX.CloudDrive</ActiveDebugProfile> |
||||
</PropertyGroup> |
||||
</Project> |
@ -0,0 +1,22 @@
|
||||
//////////////////////////////////////////////////////////////////// |
||||
// _ooOoo_ // |
||||
// o8888888o // |
||||
// 88" . "88 // |
||||
// (| ^_^ |) // |
||||
// O\ = /O // |
||||
// ____/`---'\____ // |
||||
// .' \\| |// `. // |
||||
// / \\||| : |||// \ // |
||||
// / _||||| -:- |||||- \ // |
||||
// | | \\\ - /// | | // |
||||
// | \_| ''\---/'' | | // |
||||
// \ .-\__ `-` ___/-. / // |
||||
// ___`. .' /--.--\ `. . ___ // |
||||
// ."" '< `.___\_<|>_/___.' >'"". // |
||||
// | | : `- \`.;`\ _ /`;.`/ - ` : | | // |
||||
// \ \ `-. \_ __\ /__ _/ .-` / / // |
||||
// ========`-.____`-.___\_____/___.-`____.-'======== // |
||||
// `=---=' // |
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // |
||||
// 佛祖保佑 永不宕机 永无BUG // |
||||
//////////////////////////////////////////////////////////////////// |
@ -0,0 +1,30 @@
|
||||
// _ooOoo_ |
||||
// o8888888o |
||||
// 88" . "88 |
||||
// (| -_- |) |
||||
// O\ = /O |
||||
// ____/`---'\____ |
||||
// . ' \\| |// `. |
||||
// / \\||| : |||// \ |
||||
// / _||||| -:- |||||- \ |
||||
// | | \\\ - /// | | |
||||
// | \_| ''\---/'' | | |
||||
// \ .-\__ `-` ___/-. / |
||||
// ___`. .' /--.--\ `. . __ |
||||
// ."" '< `.___\_<|>_/___.' >'"". |
||||
// | | : `- \`.;`\ _ /`;.`/ - ` : | | |
||||
// \ \ `-. \_ __\ /__ _/ .-` / / |
||||
// ======`-.____`-.___\_____/___.-`____.-'====== |
||||
// `=---=' |
||||
// |
||||
// ............................................. |
||||
// 佛祖保佑 永无BUG |
||||
// 佛曰: |
||||
// 写字楼里写字间,写字间里程序员; |
||||
// 程序人员写程序,又拿程序换酒钱。 |
||||
// 酒醒只在网上坐,酒醉还来网下眠; |
||||
// 酒醉酒醒日复日,网上网下年复年。 |
||||
// 但愿老死电脑间,不愿鞠躬老板前; |
||||
// 奔驰宝马贵者趣,公交自行程序员。 |
||||
// 别人笑我忒疯癫,我笑自己命太贱; |
||||
// 不见满街漂亮妹,哪个归得程序员? |
@ -0,0 +1,24 @@
|
||||
/** |
||||
************************************************************** |
||||
* * |
||||
* .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. * |
||||
* | ______ | * |
||||
* | .-" "-. | * |
||||
* | / \ | * |
||||
* | _ | | _ | * |
||||
* | ( \ |, .-. .-. ,| / ) | * |
||||
* | > "=._ | )(__/ \__)( | _.=" < | * |
||||
* | (_/"=._"=._ |/ /\ \| _.="_.="\_) | * |
||||
* | "=._"(_ ^^ _)"_.=" | * |
||||
* | "=\__|IIIIII|__/=" | * |
||||
* | _.="| \IIIIII/ |"=._ | * |
||||
* | _ _.="_.="\ /"=._"=._ _ | * |
||||
* | ( \_.="_.=" `--------` "=._"=._/ ) | * |
||||
* | > _.=" "=._ < | * |
||||
* | (_/ \_) | * |
||||
* | | * |
||||
* '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' * |
||||
* * |
||||
* LASCIATE OGNI SPERANZA, VOI CH'ENTRATE * |
||||
************************************************************** |
||||
*/ |
@ -0,0 +1,18 @@
|
||||
// .::::. |
||||
// .::::::::. |
||||
// ::::::::::: |
||||
// ..:::::::::::' |
||||
// '::::::::::::' |
||||
// .:::::::::: |
||||
// '::::::::::::::.. |
||||
// ..::::::::::::. |
||||
// ``:::::::::::::::: |
||||
// ::::``:::::::::' .:::. |
||||
// ::::' ':::::' .::::::::. |
||||
// .::::' :::: .:::::::'::::. |
||||
// .:::' ::::: .:::::::::' ':::::. |
||||
// .::' :::::.:::::::::' ':::::. |
||||
// .::' ::::::::::::::' ``::::. |
||||
// ...::: ::::::::::::' ``::. |
||||
// ```` ':. ':::::::::' ::::.. |
||||
// '.:::::' ':'````.. |
@ -0,0 +1,47 @@
|
||||
......................................&&......................... |
||||
....................................&&&.......................... |
||||
.................................&&&&............................ |
||||
...............................&&&&.............................. |
||||
.............................&&&&&&.............................. |
||||
...........................&&&&&&....&&&..&&&&&&&&&&&&&&&........ |
||||
..................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.............. |
||||
................&...&&&&&&&&&&&&&&&&&&&&&&&&&&&&................. |
||||
.......................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&......... |
||||
...................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&............... |
||||
..................&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&............ |
||||
...............&&&&&@ &&&&&&&&&&..&&&&&&&&&&&&&&&&&&&........... |
||||
..............&&&&&&&&&&&&&&&.&&....&&&&&&&&&&&&&..&&&&&......... |
||||
..........&&&&&&&&&&&&&&&&&&...&.....&&&&&&&&&&&&&...&&&&........ |
||||
........&&&&&&&&&&&&&&&&&&&.........&&&&&&&&&&&&&&&....&&&....... |
||||
.......&&&&&&&&.....................&&&&&&&&&&&&&&&&.....&&...... |
||||
........&&&&&.....................&&&&&&&&&&&&&&&&&&............. |
||||
..........&...................&&&&&&&&&&&&&&&&&&&&&&&............ |
||||
................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&............ |
||||
..................&&&&&&&&&&&&&&&&&&&&&&&&&&&&..&&&&&............ |
||||
..............&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&....&&&&&............ |
||||
...........&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&......&&&&............ |
||||
.........&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.........&&&&............ |
||||
.......&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&...........&&&&............ |
||||
......&&&&&&&&&&&&&&&&&&&...&&&&&&...............&&&............. |
||||
.....&&&&&&&&&&&&&&&&............................&&.............. |
||||
....&&&&&&&&&&&&&&&.................&&........................... |
||||
...&&&&&&&&&&&&&&&.....................&&&&...................... |
||||
...&&&&&&&&&&.&&&........................&&&&&................... |
||||
..&&&&&&&&&&&..&&..........................&&&&&&&............... |
||||
..&&&&&&&&&&&&...&............&&&.....&&&&...&&&&&&&............. |
||||
..&&&&&&&&&&&&&.................&&&.....&&&&&&&&&&&&&&........... |
||||
..&&&&&&&&&&&&&&&&..............&&&&&&&&&&&&&&&&&&&&&&&&......... |
||||
..&&.&&&&&&&&&&&&&&&&&.........&&&&&&&&&&&&&&&&&&&&&&&&&&&....... |
||||
...&&..&&&&&&&&&&&&.........&&&&&&&&&&&&&&&&...&&&&&&&&&&&&...... |
||||
....&..&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&...........&&&&&&&&..... |
||||
.......&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&..............&&&&&&&.... |
||||
.......&&&&&.&&&&&&&&&&&&&&&&&&..&&&&&&&&...&..........&&&&&&.... |
||||
........&&&.....&&&&&&&&&&&&&.....&&&&&&&&&&...........&..&&&&... |
||||
.......&&&........&&&.&&&&&&&&&.....&&&&&.................&&&&... |
||||
.......&&&...............&&&&&&&.......&&&&&&&&............&&&... |
||||
........&&...................&&&&&&.........................&&&.. |
||||
.........&.....................&&&&........................&&.... |
||||
...............................&&&.......................&&...... |
||||
................................&&......................&&....... |
||||
.................................&&.............................. |
||||
..................................&.............................. |
@ -0,0 +1,16 @@
|
||||
/** |
||||
* ┌─────────────────────────────────────────────────────────────┐ |
||||
* │┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐│ |
||||
* ││Esc│!1 │@2 │#3 │$4 │%5 │^6 │&7 │*8 │(9 │)0 │_- │+= │|\ │`~ ││ |
||||
* │├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴───┤│ |
||||
* ││ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{[ │}] │ BS ││ |
||||
* │├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤│ |
||||
* ││ Ctrl │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter ││ |
||||
* │├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────┬───┤│ |
||||
* ││ Shift │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│Shift │Fn ││ |
||||
* │└─────┬──┴┬──┴──┬┴───┴───┴───┴───┴───┴──┬┴───┴┬──┴┬─────┴───┘│ |
||||
* │ │Fn │ Alt │ Space │ Alt │Win│ HHKB │ |
||||
* │ └───┴─────┴───────────────────────┴─────┴───┘ │ |
||||
* └─────────────────────────────────────────────────────────────┘ |
||||
* Happy Hacking auto coding |
||||
*/ |
@ -0,0 +1,18 @@
|
||||
WW WW WW +W. WW WW |
||||
WW WW WW :WWWWWWWWWWWWWWW, ,WW######WW###### |
||||
WW WW WWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWW+ WW*WWWWWWWWWWWWWW |
||||
WW WW WWWWWWWWWWWWWWWWWWW WW .WW WW |
||||
WW WW WW WW WWW |
||||
#WWWWWWWW WWWWWWWW WWWWWWWWWWWWWWWWW, WW WW, WWWW #WWWWWWWWWWWW |
||||
#WWWWWWWW WWWWWWWW WW#############WWW WW WW WWWW *############ |
||||
WW WW WW WW WWWWWWWWWWWWWWWWWWW W WW |
||||
WW WW WW WW WWWWWWWWWWWWWWWWWWW WW WWWWWWWWWWWWWW |
||||
WW WW WWWWWWWWWWWWWWWWW# WW WW WW WWWWWWWWWWWWWW |
||||
WW WW #WWWWWWWWWWWWWWWW WW WW WW |
||||
WW WW WW WW WW WW WWWWWWWWWWWW |
||||
WW WW WW WW WW @WWW WWW* WW WWWWWWWWWWWWW, |
||||
WW WW WW WW .W+ .WWWW WWWW. WW WW +W. |
||||
WW WW WW WW WW ,WWWWWWW , WW WW +W. |
||||
WWW WW: WW .WW WW, ,WWWWWWWWW , WW WW+ WW. |
||||
+WWWWWWW @WWWWWWW WWW WWW* .WW WWWWWWWW. :WWWWWWWW WW :WWWWWWWWWWWW |
||||
+WWWWW# WWWWWW @ WW # WWW+ +WWW ## ########## |
@ -0,0 +1,21 @@
|
||||
using AX.FireTrainingSys; |
||||
|
||||
namespace Microsoft.AspNetCore.Mvc |
||||
{ |
||||
/// <summary> |
||||
/// 控制器扩展类。 |
||||
/// </summary> |
||||
public static class ControllerExtensions |
||||
{ |
||||
/// <summary> |
||||
/// 返回错误码和错误消息。 |
||||
/// </summary> |
||||
/// <param name="controller"></param> |
||||
/// <param name="errorCode"></param> |
||||
/// <returns></returns> |
||||
public static ObjectResult ErrorCode(this ControllerBase controller, int errorCode) |
||||
{ |
||||
return controller.StatusCode(errorCode, ErrorCodes.Messages[errorCode]); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,280 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Security.Claims; |
||||
using System.Threading.Tasks; |
||||
using AX.FireTrainingSys.DTOs; |
||||
using AX.FireTrainingSys.Models; |
||||
using AX.FireTrainingSys.Services; |
||||
using Microsoft.AspNetCore.Authorization; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using Microsoft.Extensions.Caching.Memory; |
||||
using Microsoft.Extensions.Logging; |
||||
using Microsoft.Extensions.Options; |
||||
using static BCrypt.Net.BCrypt; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 帐号控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
//[Authorize(Roles = "Profile")] |
||||
[ApiController] |
||||
public class AccountController : ControllerBase |
||||
{ |
||||
private readonly IOptionsMonitor<JwtOptions> jwtOptions; |
||||
private readonly IJwtService jwtService; |
||||
private readonly IMemoryCache memoryCache; |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
|
||||
public AccountController(IJwtService jwtService, |
||||
IOptionsMonitor<JwtOptions> jwtOptions, |
||||
IMemoryCache memoryCache, |
||||
DriveDbContext dbContext) |
||||
{ |
||||
this.jwtService = jwtService; |
||||
this.jwtOptions = jwtOptions; |
||||
this.memoryCache = memoryCache; |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 登录系统。 |
||||
/// </summary> |
||||
/// <param name="roleType">角色类型</param> |
||||
/// <param name="info">登录信息</param> |
||||
/// <returns></returns> |
||||
//[ProducesResponseType(ErrorCodes.E600)] |
||||
//[ProducesResponseType(ErrorCodes.E611)] |
||||
//[ProducesResponseType(ErrorCodes.E612)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[AllowAnonymous] |
||||
[HttpPost("SignIn")] |
||||
public async Task<ActionResult<IdentityInfo>> AccountSignIn([FromQuery, BindRequired] RoleType roleType, [FromBody] SignInInfo info) |
||||
{ |
||||
var name = info.Name; |
||||
|
||||
var user = await dbContext.Users |
||||
.AsNoTracking() |
||||
.Where(e => e.Name == name && e.RoleType == roleType) |
||||
.FirstOrDefaultAsync(); |
||||
|
||||
if (user == default) |
||||
return this.ErrorCode(ErrorCodes.E611); |
||||
|
||||
if (!Verify(info.Password, user.Password)) |
||||
return this.ErrorCode(ErrorCodes.E611); |
||||
|
||||
if (!user.Enabled) |
||||
return this.ErrorCode(ErrorCodes.E612); |
||||
|
||||
var userid = user.Id; |
||||
var realname = user.RealName; |
||||
var rolename = default(string); |
||||
|
||||
if (user.RoleType == RoleType.Admin) |
||||
rolename = nameof(RoleType.Admin); |
||||
else if (user.RoleType == RoleType.Teacher) |
||||
rolename = nameof(RoleType.Teacher); |
||||
else |
||||
rolename = nameof(RoleType.Student); |
||||
|
||||
var claims = new[] |
||||
{ |
||||
new Claim(JwtClaimTypes.Subject, userid), |
||||
new Claim(JwtClaimTypes.Name, realname), |
||||
new Claim(JwtClaimTypes.Role, rolename), |
||||
new Claim(JwtClaimTypes.Role, "Profile") |
||||
}; |
||||
|
||||
var identity = new ClaimsIdentity(claims); |
||||
|
||||
var token = jwtService.Create(identity); |
||||
var refreshToken = Guid.NewGuid().ToString("N"); |
||||
var options = jwtOptions.CurrentValue; |
||||
|
||||
memoryCache.Set(refreshToken, userid, DateTimeOffset.Now.AddMinutes(options.RefreshExpires)); |
||||
|
||||
var result = new IdentityInfo() |
||||
{ |
||||
Token = token, |
||||
RefreshToken = refreshToken, |
||||
Expires = options.Expires, |
||||
UserId = userid, |
||||
RealName = realname, |
||||
RoleType = roleType |
||||
}; |
||||
|
||||
return Ok(result); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 登出系统。 |
||||
/// </summary> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[HttpPost("SignOut")] |
||||
public Microsoft.AspNetCore.Mvc.ActionResult AccountSignOut() |
||||
{ |
||||
//TODO: 把 JWT 放入黑名单,其它地方则验证黑名单,将来再处理 |
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 修改密码。 |
||||
/// </summary> |
||||
/// <param name="info">修改密码信息</param> |
||||
//[ProducesResponseType(ErrorCodes.E611)] |
||||
//[ProducesResponseType(ErrorCodes.E612)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[HttpPut("[action]")]
|
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Password([FromBody] ModifyPasswordInfo info) |
||||
{ |
||||
var userid = HttpContext.User.FindFirstValue(JwtClaimTypes.Subject); |
||||
|
||||
var user = await dbContext.Users.FirstOrDefaultAsync(e => e.Id == userid); |
||||
|
||||
if (user == null) |
||||
return NotFound(); |
||||
|
||||
if (!Verify(info.Password, user.Password)) |
||||
return this.ErrorCode(ErrorCodes.E611); |
||||
|
||||
if (!user.Enabled) |
||||
return this.ErrorCode(ErrorCodes.E612); |
||||
|
||||
user.Password = HashPassword(info.NewPassword); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 刷新令牌。 |
||||
/// </summary> |
||||
//[ProducesResponseType(ErrorCodes.E613)] |
||||
//[ProducesResponseType(ErrorCodes.E614)] |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[AllowAnonymous] |
||||
[HttpPost("[action]")]
|
||||
public async Task<ActionResult<IdentityInfo>> RefreshToken([FromBody] RefreshTokenInfo info) |
||||
{ |
||||
if (string.IsNullOrEmpty(info.RefreshToken) || |
||||
string.IsNullOrEmpty(info.Token)) |
||||
return this.ErrorCode(ErrorCodes.E613); |
||||
|
||||
//校验缓存中是否有该刷新令牌 |
||||
if (memoryCache.TryGetValue<string>(info.RefreshToken, out var userid)) |
||||
{ |
||||
//校验令牌是否有效 |
||||
if (!jwtService.Validate(info.Token, out var principal)) |
||||
return this.ErrorCode(ErrorCodes.E613); |
||||
|
||||
var options = jwtOptions.CurrentValue; |
||||
var identity = principal.Identity as ClaimsIdentity; |
||||
var realname = principal.FindFirstValue(JwtClaimTypes.Name); |
||||
var roletype = RoleType.Student; |
||||
|
||||
if (principal.IsInRole(nameof(RoleType.Admin))) |
||||
roletype = RoleType.Admin; |
||||
else if (principal.IsInRole(nameof(RoleType.Teacher))) |
||||
roletype = RoleType.Teacher; |
||||
else if (principal.IsInRole(nameof(RoleType.Student))) |
||||
roletype = RoleType.Student; |
||||
|
||||
var newToken = jwtService.Create(identity); |
||||
|
||||
var result = new IdentityInfo() |
||||
{ |
||||
Token = newToken, |
||||
RefreshToken = info.RefreshToken, |
||||
Expires = options.Expires, |
||||
RealName = realname, |
||||
RoleType = roletype |
||||
}; |
||||
|
||||
return Ok(result); |
||||
} |
||||
|
||||
//专用于数据同步 |
||||
//假设刷新令牌和令牌都有效,模拟登录流程 |
||||
try |
||||
{ |
||||
var jwt = jwtService.Decode(info.Token); |
||||
var name = jwt.Claims.FirstOrDefault(e => e.Type == JwtClaimTypes.Name)?.Value; |
||||
|
||||
if (name is null) |
||||
return this.ErrorCode(ErrorCodes.E613); |
||||
|
||||
var user = await dbContext.Users |
||||
.AsNoTracking() |
||||
.Where(e => e.Name == name) |
||||
.FirstOrDefaultAsync(); |
||||
|
||||
if (user == default) |
||||
return this.ErrorCode(ErrorCodes.E611); |
||||
|
||||
if (!user.Enabled) |
||||
return this.ErrorCode(ErrorCodes.E612); |
||||
|
||||
userid = user.Id; |
||||
var roleType = user.RoleType; |
||||
var realname = user.RealName; |
||||
var rolename = default(string); |
||||
|
||||
if (roleType == RoleType.Admin) |
||||
rolename = nameof(RoleType.Admin); |
||||
else if (roleType == RoleType.Teacher) |
||||
rolename = nameof(RoleType.Teacher); |
||||
else |
||||
rolename = nameof(RoleType.Student); |
||||
|
||||
var claims = new[] |
||||
{ |
||||
new Claim(JwtClaimTypes.Subject, userid), |
||||
new Claim(JwtClaimTypes.Name, realname), |
||||
new Claim(JwtClaimTypes.Role, rolename), |
||||
new Claim(JwtClaimTypes.Role, "Profile") |
||||
}; |
||||
|
||||
var identity = new ClaimsIdentity(claims); |
||||
|
||||
var token = jwtService.Create(identity); |
||||
var refreshToken = Guid.NewGuid().ToString("N"); |
||||
var options = jwtOptions.CurrentValue; |
||||
|
||||
memoryCache.Set(refreshToken, userid, DateTimeOffset.Now.AddMinutes(options.RefreshExpires)); |
||||
|
||||
var result = new IdentityInfo() |
||||
{ |
||||
Token = token, |
||||
RefreshToken = refreshToken, |
||||
Expires = options.Expires, |
||||
UserId = userid, |
||||
RealName = realname, |
||||
RoleType = roleType |
||||
}; |
||||
|
||||
return Ok(result); |
||||
} |
||||
catch |
||||
{ |
||||
return this.ErrorCode(ErrorCodes.E613); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,242 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using System.Text.Json; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 毗邻控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class BuildingAdjoinsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public BuildingAdjoinsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.BuildingAdjoins |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.BuildingAdjoins.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.BuildingAdjoins.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new BuildingAdjoin |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.BuildingAdjoins.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.BuildingAdjoins |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.BuildingAdjoins.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new BuildingAdjoin |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.BuildingAdjoins.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.BuildingAdjoins.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.BuildingAdjoins.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.BuildingAdjoins.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, BuildingAdjoin)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.BuildingAdjoins.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 基本信息控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class BuildingBasicInfosController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public BuildingBasicInfosController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的基本信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.BuildingBasicInfos.FindAsync(coursewareId); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的基本信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.BuildingBasicInfos.FindAsync(coursewareId); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new BuildingBasicInfo |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.BuildingBasicInfos.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 建筑特点控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class BuildingFeaturesController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public BuildingFeaturesController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的建筑特点。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.BuildingFeatures.FindAsync(coursewareId); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的建筑特点。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.BuildingFeatures.FindAsync(coursewareId); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new BuildingFeature |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.BuildingFeatures.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,197 @@
|
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 课件基本信息控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class CoursewareBaseInfosController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public CoursewareBaseInfosController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有相关基本信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Get([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest($"{nameof(coursewareId)}:{coursewareId}"); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//暂未找到在 EF Core 中合适的临时表方案 |
||||
//或许可以使用 Dapper 写临时表查询 |
||||
|
||||
var buildingAdjoins = await dbContext.BuildingAdjoins |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var buildingBasicInfos = await dbContext.BuildingBasicInfos |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var buildingFeatures = await dbContext.BuildingFeatures |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var exits = await dbContext.Exits |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var fireControlRooms = await dbContext.FireControlRooms |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var fireLifts = await dbContext.FireLifts |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var fireWaterMonitors = await dbContext.FireWaterMonitors |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var foamHydrants = await dbContext.FoamHydrants |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var foamPumpRooms = await dbContext.FoamPumpRooms |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var imageMarkers = await dbContext.ImageMarkers |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var importantLocations = await dbContext.ImportantLocations |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var municipalFireHydrants = await dbContext.MunicipalFireHydrants |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var noParkingAreas = await dbContext.NoParkingAreas |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var outdoorFireHydrants = await dbContext.OutdoorFireHydrants |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var protectedStairways = await dbContext.ProtectedStairways |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var pumpRooms = await dbContext.PumpRooms |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var siameseConnections = await dbContext.SiameseConnections |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var storageTanks = await dbContext.StorageTanks |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var waterTanks = await dbContext.WaterTanks |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
var result = new Dictionary<string, List<string>> |
||||
{ |
||||
{ nameof(buildingAdjoins), buildingAdjoins }, |
||||
{ nameof(buildingBasicInfos), buildingBasicInfos }, |
||||
{ nameof(buildingFeatures), buildingFeatures }, |
||||
{ nameof(exits), exits }, |
||||
{ nameof(fireControlRooms), fireControlRooms }, |
||||
{ nameof(fireLifts), fireLifts }, |
||||
{ nameof(fireWaterMonitors), fireWaterMonitors }, |
||||
{ nameof(foamHydrants), foamHydrants }, |
||||
{ nameof(foamPumpRooms), foamPumpRooms }, |
||||
{ nameof(imageMarkers), imageMarkers }, |
||||
{ nameof(importantLocations), importantLocations }, |
||||
{ nameof(municipalFireHydrants), municipalFireHydrants }, |
||||
{ nameof(noParkingAreas), noParkingAreas }, |
||||
{ nameof(outdoorFireHydrants), outdoorFireHydrants }, |
||||
{ nameof(protectedStairways), protectedStairways }, |
||||
{ nameof(pumpRooms), pumpRooms }, |
||||
{ nameof(siameseConnections), siameseConnections }, |
||||
{ nameof(storageTanks), storageTanks }, |
||||
{ nameof(waterTanks), waterTanks }, |
||||
}; |
||||
|
||||
transaction.Commit(); |
||||
|
||||
return Ok(result); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class BaseInfo |
||||
{ |
||||
public string CoursewareId { get; set; } |
||||
public string Id { get; set; } |
||||
public string Content { get; set; } |
||||
public string Type { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 行车路线控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class DriveRoutesController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public DriveRoutesController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的行车路线信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.DriveRoutes.FindAsync(coursewareId); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的行车路线信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.DriveRoutes.FindAsync(coursewareId); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new DriveRoute |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.DriveRoutes.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 安全出口控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class ExitsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public ExitsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.Exits |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.Exits.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.Exits.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new Exit |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.Exits.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.Exits |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.Exits.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new Exit |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.Exits.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.Exits.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.Exits.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.Exits.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, Exit)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.Exits.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 消防控制室控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class FireControlRoomsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public FireControlRoomsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.FireControlRooms |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FireControlRooms.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FireControlRooms.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new FireControlRoom |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.FireControlRooms.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.FireControlRooms |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.FireControlRooms.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new FireControlRoom |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.FireControlRooms.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.FireControlRooms.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FireControlRooms.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.FireControlRooms.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, FireControlRoom)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.FireControlRooms.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,197 @@
|
||||
using AX.FireTrainingSys.DTOs; |
||||
using AX.FireTrainingSys.Models; |
||||
using Mapster; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 消防力量控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class FireForcesController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public FireForcesController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有消防力量信息或者指定机构的所有消防力量信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">课件编号</param> |
||||
/// <param name="organizationId">机构编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<FireForceInfo>>> Get([FromQuery, BindRequired]string coursewareId, [FromQuery]string organizationId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest($"{nameof(coursewareId)}:{coursewareId}"); |
||||
|
||||
IEnumerable<FireForceInfo> result = default; |
||||
|
||||
if (string.IsNullOrEmpty(organizationId)) |
||||
{ |
||||
result = await dbContext.FireForces |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.ToDTO()) |
||||
.ToListAsync(); |
||||
} |
||||
else |
||||
{ |
||||
|
||||
result = await dbContext.FireForces |
||||
.AsNoTracking() |
||||
.Where(e => (e.OrganizationId == organizationId && e.CoursewareId == coursewareId)) |
||||
.Select(e => e.ToDTO()) |
||||
.ToListAsync(); |
||||
} |
||||
|
||||
return Ok(result); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条消防力量。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">课件编号</param> |
||||
/// <param name="id">消防力量编号</param> |
||||
/// <param name="dto">要保存的消防力量数据</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody] FireForceInfo dto) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest($"{nameof(coursewareId)}:{coursewareId}"); |
||||
|
||||
if (string.IsNullOrEmpty(id)) |
||||
return BadRequest(id); |
||||
|
||||
if (id != dto.Id) |
||||
return BadRequest($"id: {id} is not equal to dto: {dto.Id}."); |
||||
|
||||
var model = await dbContext.FireForces.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = dto.ToModel(coursewareId); |
||||
|
||||
dbContext.FireForces.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
dto.MapTo(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量更新指定课件的消防力量信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="list">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpPut] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PutAll([FromQuery, BindRequired]string coursewareId, [FromBody]IEnumerable<FireForceInfo> list) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//依次更新信息 |
||||
await foreach (var (model, dto) in AsAsyncEnumerable(coursewareId, list)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(); |
||||
|
||||
dto.MapTo(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条消防力量信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定课件编号</param> |
||||
/// <param name="id">组织机构编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FireForces.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(); |
||||
|
||||
dbContext.FireForces.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(FireForce, FireForceInfo)> AsAsyncEnumerable(string coursewareId, IEnumerable<FireForceInfo> data) |
||||
{ |
||||
foreach (var dto in data) |
||||
{ |
||||
var model = await dbContext.FireForces.FindAsync(coursewareId, dto.Id); |
||||
yield return (model, dto); |
||||
} |
||||
} |
||||
} |
||||
|
||||
internal static class FireForceExtensions |
||||
{ |
||||
public static FireForce ToModel(this FireForceInfo dto, string coursewareId) |
||||
{ |
||||
var model = dto.Adapt<FireForce>(); |
||||
model.CoursewareId = coursewareId; |
||||
return model; |
||||
} |
||||
|
||||
public static FireForceInfo ToDTO(this FireForce model) |
||||
{ |
||||
var dto = model.Adapt<FireForceInfo>(); |
||||
return dto; |
||||
} |
||||
|
||||
public static void MapTo(this FireForceInfo dto, FireForce model) |
||||
{ |
||||
dto.Adapt(model); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 消防电梯控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class FireLiftsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public FireLiftsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.FireLifts |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FireLifts.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FireLifts.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new FireLift |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.FireLifts.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.FireLifts |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.FireLifts.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new FireLift |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.FireLifts.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.FireLifts.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FireLifts.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.FireLifts.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, FireLift)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.FireLifts.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 消防水炮控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class FireWaterMonitorsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public FireWaterMonitorsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.FireWaterMonitors |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FireWaterMonitors.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FireWaterMonitors.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new FireWaterMonitor |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.FireWaterMonitors.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.FireWaterMonitors |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.FireWaterMonitors.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new FireWaterMonitor |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.FireWaterMonitors.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.FireWaterMonitors.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FireWaterMonitors.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.FireWaterMonitors.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, FireWaterMonitor)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.FireWaterMonitors.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 泡沫栓控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class FoamHydrantsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public FoamHydrantsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.FoamHydrants |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FoamHydrants.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FoamHydrants.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new FoamHydrant |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.FoamHydrants.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.FoamHydrants |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.FoamHydrants.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new FoamHydrant |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.FoamHydrants.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.FoamHydrants.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FoamHydrants.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.FoamHydrants.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, FoamHydrant)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.FoamHydrants.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 泡沫泵房控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class FoamPumpRoomsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public FoamPumpRoomsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.FoamPumpRooms |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FoamPumpRooms.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FoamPumpRooms.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new FoamPumpRoom |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.FoamPumpRooms.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.FoamPumpRooms |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.FoamPumpRooms.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new FoamPumpRoom |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.FoamPumpRooms.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.FoamPumpRooms.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.FoamPumpRooms.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.FoamPumpRooms.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, FoamPumpRoom)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.FoamPumpRooms.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 图片标记控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class ImageMarkersController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public ImageMarkersController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.ImageMarkers |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.ImageMarkers.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.ImageMarkers.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new ImageMarker |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.ImageMarkers.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.ImageMarkers |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.ImageMarkers.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new ImageMarker |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.ImageMarkers.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.ImageMarkers.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.ImageMarkers.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.ImageMarkers.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, ImageMarker)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.ImageMarkers.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 重点部位控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class ImportantLocationsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public ImportantLocationsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.ImportantLocations |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.ImportantLocations.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.ImportantLocations.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new ImportantLocation |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.ImportantLocations.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.ImportantLocations |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.ImportantLocations.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new ImportantLocation |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.ImportantLocations.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.ImportantLocations.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.ImportantLocations.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.ImportantLocations.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, ImportantLocation)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.ImportantLocations.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 市政消火栓控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class MunicipalFireHydrantsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public MunicipalFireHydrantsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.MunicipalFireHydrants |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.MunicipalFireHydrants.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.MunicipalFireHydrants.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new MunicipalFireHydrant |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.MunicipalFireHydrants.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.MunicipalFireHydrants |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.MunicipalFireHydrants.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new MunicipalFireHydrant |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.MunicipalFireHydrants.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.MunicipalFireHydrants.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.MunicipalFireHydrants.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.MunicipalFireHydrants.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, MunicipalFireHydrant)> AsAsyncEnumerable(string coursewareId, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.MunicipalFireHydrants.FindAsync(coursewareId, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 禁停区控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class NoParkingAreasController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public NoParkingAreasController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有禁停区信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.NoParkingAreas |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条禁停区信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.NoParkingAreas.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条禁停区信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.NoParkingAreas.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new NoParkingArea |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.NoParkingAreas.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的禁停区信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.NoParkingAreas |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.NoParkingAreas.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new NoParkingArea |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.NoParkingAreas.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的禁停区信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.NoParkingAreas.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条禁停区信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.NoParkingAreas.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.NoParkingAreas.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, NoParkingArea)> AsAsyncEnumerable(string coursewareId, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.NoParkingAreas.FindAsync(coursewareId, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,140 @@
|
||||
using AX.FireTrainingSys.DTOs; |
||||
using AX.FireTrainingSys.Models; |
||||
using Mapster; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 组织机构控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class OrganizationsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public OrganizationsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有组织机构信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<OrganizationInfo>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.Organizations |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.OrderByDescending(e => e.Order) |
||||
.Select(e => e.ToDTO()) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条组织机构信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定课件编号</param> |
||||
/// <param name="id">组织机构编号</param> |
||||
/// <param name="dto">要保存的组织机构信息</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody] OrganizationInfo dto) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(id)) |
||||
return BadRequest(id); |
||||
|
||||
if (id != dto.Id) |
||||
return BadRequest($"id: {id} is not equal to dto: {dto.Id}."); |
||||
|
||||
var model = await dbContext.Organizations.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = dto.ToModel(coursewareId); |
||||
dbContext.Organizations.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
dto.MapTo(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条组织机构信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定课件编号</param> |
||||
/// <param name="id">组织机构编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.Organizations.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(); |
||||
|
||||
dbContext.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
} |
||||
|
||||
internal static class OrganizationExtensions |
||||
{ |
||||
public static Organization ToModel(this OrganizationInfo dto, string coursewareId) |
||||
{ |
||||
var model = dto.Adapt<Organization>(); |
||||
model.CoursewareId = coursewareId; |
||||
return model; |
||||
} |
||||
|
||||
public static OrganizationInfo ToDTO(this Organization model) |
||||
{ |
||||
var dto = model.Adapt<OrganizationInfo>(); |
||||
return dto; |
||||
} |
||||
|
||||
public static void MapTo(this OrganizationInfo dto, Organization model) |
||||
{ |
||||
dto.Adapt(model); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 室外消火栓控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class OutdoorFireHydrantsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public OutdoorFireHydrantsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.OutdoorFireHydrants |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.OutdoorFireHydrants.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.OutdoorFireHydrants.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new OutdoorFireHydrant |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.OutdoorFireHydrants.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.OutdoorFireHydrants |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.OutdoorFireHydrants.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new OutdoorFireHydrant |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.OutdoorFireHydrants.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.OutdoorFireHydrants.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.OutdoorFireHydrants.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.OutdoorFireHydrants.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, OutdoorFireHydrant)> AsAsyncEnumerable(string coursewareId, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.OutdoorFireHydrants.FindAsync(coursewareId, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 周边水源控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class PeripheralWaterSourcesController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public PeripheralWaterSourcesController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的周边水源信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.PeripheralWaterSources.FindAsync(coursewareId); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的周边水源信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.PeripheralWaterSources.FindAsync(coursewareId); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new PeripheralWaterSource |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.PeripheralWaterSources.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 疏散楼梯控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class ProtectedStairwaysController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public ProtectedStairwaysController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.ProtectedStairways |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.ProtectedStairways.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.ProtectedStairways.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new ProtectedStairway |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.ProtectedStairways.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.ProtectedStairways |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.ProtectedStairways.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new ProtectedStairway |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.ProtectedStairways.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.ProtectedStairways.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.ProtectedStairways.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.ProtectedStairways.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, ProtectedStairway)> AsAsyncEnumerable(string coursewareId, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.ProtectedStairways.FindAsync(coursewareId, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 泵房/水箱控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class PumpRoomsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public PumpRoomsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.PumpRooms |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.PumpRooms.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.PumpRooms.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new PumpRoom |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.PumpRooms.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.PumpRooms |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.PumpRooms.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new PumpRoom |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.PumpRooms.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.PumpRooms.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.PumpRooms.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.PumpRooms.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, PumpRoom)> AsAsyncEnumerable(string coursewareId, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.PumpRooms.FindAsync(coursewareId, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 水泵接合器控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class SiameseConnectionsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public SiameseConnectionsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.SiameseConnections |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.SiameseConnections.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.SiameseConnections.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new SiameseConnection |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.SiameseConnections.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.SiameseConnections |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.SiameseConnections.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new SiameseConnection |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.SiameseConnections.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.SiameseConnections.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param coursewareId="coursewareId">指定的课件编号</param> |
||||
/// <param coursewareId="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.SiameseConnections.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.SiameseConnections.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, SiameseConnection)> AsAsyncEnumerable(string coursewareId, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.SiameseConnections.FindAsync(coursewareId, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 储罐控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class StorageTanksController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public StorageTanksController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有储罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.StorageTanks |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条储罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.StorageTanks.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条储罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.StorageTanks.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new StorageTank |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.StorageTanks.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的储罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.StorageTanks |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.StorageTanks.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new StorageTank |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.StorageTanks.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的储罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.StorageTanks.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条储罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.StorageTanks.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.StorageTanks.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, StorageTank)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.StorageTanks.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 水罐控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class WaterTanksController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public WaterTanksController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的所有水罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var models = await dbContext.WaterTanks |
||||
.AsNoTracking() |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定课件的单条水罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.WaterTanks.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定课件的单条水罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string coursewareId, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.WaterTanks.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new WaterTank |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.WaterTanks.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定课件的水罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.WaterTanks |
||||
.Where(e => e.CoursewareId == coursewareId) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.WaterTanks.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new WaterTank |
||||
{ |
||||
CoursewareId = coursewareId, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.WaterTanks.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定课件的水罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string coursewareId, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(coursewareId, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.WaterTanks.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定课件的单条水罐信息。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">指定的课件编号</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string coursewareId, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var model = await dbContext.WaterTanks.FindAsync(coursewareId, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.WaterTanks.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, WaterTank)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.WaterTanks.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,512 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Security.Claims; |
||||
using System.Threading.Tasks; |
||||
using AX.FireTrainingSys.DTOs; |
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Authorization; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using Mapster; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 课件库控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
//[Authorize(Roles = "Profile")] |
||||
[ApiController] |
||||
public class CoursewaresController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public CoursewaresController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得课件列表。 |
||||
/// </summary> |
||||
/// <param name="options"></param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<Page<CoursewareInfo>>> Get([FromQuery] CoursewareQueryOptions options) |
||||
{ |
||||
if (options.PageNumber == null) |
||||
options.PageNumber = 1; |
||||
|
||||
if (options.PageSize == null) |
||||
options.PageSize = 10; |
||||
|
||||
var username = HttpContext.User.FindFirstValue(JwtClaimTypes.Subject); |
||||
|
||||
var queryable = dbContext.Coursewares |
||||
.Include(e => e.User) |
||||
.Include(e => e.BuildingTypes) |
||||
.AsNoTracking(); |
||||
|
||||
if (options.Others != null) |
||||
queryable = queryable.Where(e => options.Others.Value ? e.UserId != username : e.UserId == username); |
||||
|
||||
if (options.IsPublic != null) |
||||
queryable = queryable.Where(e => e.IsPublic == options.IsPublic.Value); |
||||
|
||||
if (options.Name != null) |
||||
queryable = queryable.Where(e => e.Name.Contains(options.Name)); |
||||
|
||||
if (options.ModifiedTime != null) |
||||
{ |
||||
var modifiedTime = options.ModifiedTime.Value.UtcDateTime; |
||||
queryable = queryable.Where(e => e.ModifiedTime >= modifiedTime); |
||||
} |
||||
|
||||
if (options.BuildingType != null) |
||||
queryable = queryable.Where(e => e.BuildingTypes.Any(c => c.BuildingTypeId == options.BuildingType)); |
||||
|
||||
if (!string.IsNullOrEmpty(options.CompanyName)) |
||||
queryable = queryable.Where(e => e.CompanyName.Contains(options.CompanyName)); |
||||
|
||||
var count = await queryable.CountAsync(); |
||||
|
||||
queryable = queryable.OrderByDescending(e => e.ModifiedTime); |
||||
|
||||
if (options.PageNumber > 1) |
||||
queryable = queryable.Skip((options.PageNumber.Value - 1) * options.PageSize.Value - 1); |
||||
|
||||
queryable = queryable.Take(options.PageSize.Value); |
||||
|
||||
var list = await queryable.Select(e => e.ToDTO()) |
||||
.ToListAsync(); |
||||
|
||||
var result = new Page<CoursewareInfo> |
||||
{ |
||||
PageNumber = (int)options.PageNumber, |
||||
PageSize = (int)options.PageSize, |
||||
TotalPages = (int)Math.Ceiling((double)count / (int)options.PageSize), |
||||
TotalCount = count, |
||||
Items = list |
||||
}; |
||||
|
||||
return Ok(result); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 新建一个课件。 |
||||
/// </summary> |
||||
/// <param name="companyName">单位/场景名称</param> |
||||
/// <param name="info"></param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status201Created)] |
||||
[HttpPost] |
||||
public async Task<ActionResult<CoursewareInfo>> Post([FromQuery] string companyName, [FromBody] CoursewareInfo info) |
||||
{ |
||||
if (string.IsNullOrEmpty(info.Name)) |
||||
return BadRequest(nameof(info.Name)); |
||||
|
||||
if (info.BuildingTypes == null || info.BuildingTypes.Length == 0) |
||||
return BadRequest(nameof(info.BuildingTypes)); |
||||
|
||||
var username = HttpContext.User.FindFirstValue(JwtClaimTypes.Subject); |
||||
var realname = HttpContext.User.FindFirstValue(JwtClaimTypes.Name); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
var model = info.ToModel(username); |
||||
|
||||
dbContext.Coursewares.Add(model); |
||||
|
||||
var buildingTypes = info.Create(model.Id); |
||||
|
||||
dbContext.Set<CoursewareBuildingType>().AddRange(buildingTypes); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
info.Id = model.Id; |
||||
info.Creator = realname; |
||||
info.ModifiedTime = model.ModifiedTime.ToLocalTime(); |
||||
info.Referenced = false; |
||||
|
||||
//从模板数据库中初始化课件数据 |
||||
await dbContext.Database.ExecuteSqlInterpolatedAsync($@"
|
||||
INSERT INTO BuildingAdjoins (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateBuildingAdjoins |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO BuildingBasicInfos (CoursewareId, Content) |
||||
SELECT {info.Id}, Content FROM TemplateBuildingBasicInfos |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO BuildingFeatures (CoursewareId, Content) |
||||
SELECT {info.Id}, Content FROM TemplateBuildingFeatures |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO Exits (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateExits |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO FireControlRooms (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateFireControlRooms |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO FireLifts (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateFireLifts |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO FireWaterMonitors (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateFireWaterMonitors |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO FoamHydrants (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateFoamHydrants |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO FoamPumpRooms (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateFoamPumpRooms |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO ImageMarkers (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateImageMarkers |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO ImportantLocations (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateImportantLocations |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO MunicipalFireHydrants (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateMunicipalFireHydrants |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO NoParkingAreas (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateNoParkingAreas |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO OutdoorFireHydrants (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateOutdoorFireHydrants |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO ProtectedStairways (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateProtectedStairways |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO PumpRooms (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplatePumpRooms |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO SiameseConnections (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateSiameseConnections |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO StorageTanks (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateStorageTanks |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO WaterTanks (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM TemplateWaterTanks |
||||
WHERE CompanyName == {companyName}; |
||||
|
||||
INSERT INTO Organizations(CoursewareId, Id, Name, Level, [Order], X, Y, Z, ParentId) |
||||
SELECT {info.Id}, Id, Name, Level, [Order], X, Y, Z, ParentId FROM TemplateOrganizations; |
||||
|
||||
INSERT INTO FireForces(CoursewareId, Id, Type, Content, OrganizationId) |
||||
SELECT {info.Id}, Id, Type, Content, OrganizationId FROM TemplateFireForces; |
||||
|
||||
");
|
||||
|
||||
transaction.Commit(); |
||||
|
||||
return CreatedAtAction(nameof(Post), info); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 另存为一个课件。 |
||||
/// </summary> |
||||
/// <param name="coursewareId">课件编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status201Created)] |
||||
[HttpPost("[action]")]
|
||||
public async Task<ActionResult<CoursewareInfo>> SaveAs([FromQuery] string coursewareId) |
||||
{ |
||||
if (string.IsNullOrEmpty(coursewareId)) |
||||
return BadRequest(coursewareId); |
||||
|
||||
var m = await dbContext.Coursewares |
||||
.Include(e => e.BuildingTypes) |
||||
.Include(e => e.User) |
||||
.AsNoTracking() |
||||
.Where(e => e.Id == coursewareId) |
||||
.FirstOrDefaultAsync(); |
||||
|
||||
if (m == null) |
||||
return NotFound(coursewareId); |
||||
|
||||
var info = m.ToDTO(); |
||||
|
||||
var username = HttpContext.User.FindFirstValue(JwtClaimTypes.Subject); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
var model = info.ToModel(username); |
||||
|
||||
dbContext.Coursewares.Add(model); |
||||
|
||||
var buildingTypes = info.Create(model.Id); |
||||
|
||||
dbContext.Set<CoursewareBuildingType>().AddRange(buildingTypes); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
info.Id = model.Id; |
||||
info.Creator = username; |
||||
info.ModifiedTime = model.ModifiedTime.ToLocalTime(); |
||||
info.Referenced = false; |
||||
|
||||
//从相关数据库中初始化课件数据 |
||||
await dbContext.Database.ExecuteSqlInterpolatedAsync($@"
|
||||
INSERT INTO BuildingAdjoins (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM BuildingAdjoins |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO BuildingBasicInfos (CoursewareId, Content) |
||||
SELECT {info.Id}, Content FROM BuildingBasicInfos |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO BuildingFeatures (CoursewareId, Content) |
||||
SELECT {info.Id}, Content FROM BuildingFeatures |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO Exits (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM Exits |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO FireControlRooms (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM FireControlRooms |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO FireLifts (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM FireLifts |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO FireWaterMonitors (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM FireWaterMonitors |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO FoamHydrants (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM FoamHydrants |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO FoamPumpRooms (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM FoamPumpRooms |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO ImageMarkers (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM ImageMarkers |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO ImportantLocations (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM ImportantLocations |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO MunicipalFireHydrants (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM MunicipalFireHydrants |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO NoParkingAreas (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM NoParkingAreas |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO OutdoorFireHydrants (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM OutdoorFireHydrants |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO ProtectedStairways (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM ProtectedStairways |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO PumpRooms (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM PumpRooms |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO SiameseConnections (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM SiameseConnections |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO StorageTanks (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM StorageTanks |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO WaterTanks (CoursewareId, Id, Content) |
||||
SELECT {info.Id}, Id, Content FROM WaterTanks |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO Organizations(CoursewareId, Id, Name, Level, [Order], X, Y, Z, ParentId) |
||||
SELECT {info.Id}, Id, Name, Level, [Order], X, Y, Z, ParentId FROM Organizations |
||||
WHERE CoursewareId == {coursewareId}; |
||||
|
||||
INSERT INTO FireForces(CoursewareId, Id, Type, Content, OrganizationId) |
||||
SELECT {info.Id}, Id, Type, Content, OrganizationId FROM FireForces |
||||
WHERE CoursewareId == {coursewareId}; |
||||
");
|
||||
|
||||
transaction.Commit(); |
||||
|
||||
return CreatedAtAction(nameof(Post), info); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 修改指定的课件信息。 |
||||
/// </summary> |
||||
/// <param name="id"></param> |
||||
/// <param name="info"></param> |
||||
/// <returns></returns> |
||||
//[ProducesResponseType(ErrorCodes.E620)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[HttpPut("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Put(string id, [FromBody] CoursewareInfo info) |
||||
{ |
||||
if (id != info.Id) |
||||
return BadRequest(id); |
||||
|
||||
var username = HttpContext.User.FindFirstValue(JwtClaimTypes.Subject); |
||||
|
||||
var model = await dbContext.Coursewares |
||||
.Include(e => e.BuildingTypes) |
||||
.FirstOrDefaultAsync(e => e.Id == id); |
||||
|
||||
if (model == null) |
||||
return NotFound(); |
||||
|
||||
// 不能修改他人课件 |
||||
if (model.UserId != username) |
||||
return Forbid(); |
||||
|
||||
// 不能撤销已被引用的公开课件 |
||||
if (model.IsPublic && |
||||
model.Referenced > 0 && |
||||
info.IsPublic != null && |
||||
info.IsPublic == false) |
||||
return this.ErrorCode(ErrorCodes.E620); |
||||
|
||||
info.MapTo(model); |
||||
|
||||
var currItems = model.BuildingTypes; |
||||
var newItems = info.Create(model.Id); |
||||
|
||||
var removedItems = currItems.Except(newItems); |
||||
var addedItems = newItems.Except(currItems); |
||||
|
||||
dbContext.Set<CoursewareBuildingType>().RemoveRange(removedItems); |
||||
dbContext.Set<CoursewareBuildingType>().AddRange(addedItems); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定的课件信息。 |
||||
/// </summary> |
||||
/// <param name="id"></param> |
||||
/// <returns></returns> |
||||
//[ProducesResponseType(ErrorCodes.E621)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete(string id) |
||||
{ |
||||
var username = HttpContext.User.FindFirstValue(JwtClaimTypes.Subject); |
||||
var model = await dbContext.Coursewares.FindAsync(id); |
||||
|
||||
if (model == null) |
||||
return NotFound(); |
||||
|
||||
// 不能删除他人课件 |
||||
if (model.UserId != username) |
||||
return Forbid(); |
||||
|
||||
// 不能删除已被引用的公开课件 |
||||
if (model.IsPublic && |
||||
model.Referenced > 0) |
||||
return this.ErrorCode(ErrorCodes.E621); |
||||
|
||||
model.Deleted = true; |
||||
model.Name = model.Name + "-" + ObjectId.NewId().ToString(); |
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
} |
||||
|
||||
internal static class CoursewareExtensions |
||||
{ |
||||
public static Courseware ToModel(this CoursewareInfo dto, string creator) |
||||
{ |
||||
var model = dto.Adapt<Courseware>(); |
||||
model.UserId = creator; |
||||
return model; |
||||
} |
||||
|
||||
public static CoursewareInfo ToDTO(this Courseware model) |
||||
{ |
||||
var buildingTypes = new int[model.BuildingTypes.Count]; |
||||
|
||||
var i = 0; |
||||
|
||||
foreach (var type in model.BuildingTypes) |
||||
buildingTypes[i++] = type.BuildingTypeId; |
||||
|
||||
var dto = model.Adapt<CoursewareInfo>(); |
||||
|
||||
dto.BuildingTypes = buildingTypes; |
||||
|
||||
return dto; |
||||
} |
||||
|
||||
public static void MapTo(this CoursewareInfo dto, Courseware model) |
||||
{ |
||||
dto.Adapt(model); |
||||
model.ModifiedTime = DateTime.UtcNow; |
||||
} |
||||
|
||||
public static IEnumerable<CoursewareBuildingType> Create(this CoursewareInfo dto, string id) |
||||
{ |
||||
var buildingTypes = new List<CoursewareBuildingType>(dto.BuildingTypes.Length); |
||||
|
||||
for (var i = 0; i < dto.BuildingTypes.Length; ++i) |
||||
{ |
||||
var buildingType = new CoursewareBuildingType |
||||
{ |
||||
CoursewareId = id, |
||||
BuildingTypeId = dto.BuildingTypes[i] |
||||
}; |
||||
|
||||
buildingTypes.Add(buildingType); |
||||
} |
||||
|
||||
return buildingTypes; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,310 @@
|
||||
using AX.FireTrainingSys.DTOs; |
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using System.Linq; |
||||
using System.Text.RegularExpressions; |
||||
using System.Threading.Tasks; |
||||
using static BCrypt.Net.BCrypt; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 数据同步控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class DataSyncController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public DataSyncController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得所有用户信息。 |
||||
/// </summary> |
||||
/// <param name="options">查询条件</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[HttpGet("Users")] |
||||
public async Task<ActionResult<Page<UserInfo>>> Get([FromQuery] UserQueryOptions options) |
||||
{ |
||||
if (options.PageNumber == default) |
||||
options.PageNumber = 1; |
||||
|
||||
if (options.PageSize == default) |
||||
options.PageSize = 10; |
||||
|
||||
if (options.RoleType == default) |
||||
options.RoleType = RoleType.Student; |
||||
|
||||
var query = dbContext.Users |
||||
.Include(e => e.Posts).ThenInclude(e => e.Post) |
||||
.AsNoTracking(); |
||||
|
||||
query = query.Where(e => e.RoleType == options.RoleType); |
||||
|
||||
if (!string.IsNullOrEmpty(options.Name)) |
||||
query = query.Where(e => e.Name.Contains(options.Name)); |
||||
|
||||
if (!string.IsNullOrEmpty(options.RealName)) |
||||
query = query.Where(e => e.RealName.Contains(options.RealName)); |
||||
|
||||
var count = await query.CountAsync(); |
||||
|
||||
query = query.OrderByDescending(e => e.CreationTime); |
||||
|
||||
if (options.PageNumber > 1) |
||||
query = query.Skip((options.PageNumber.Value - 1) * options.PageSize.Value); |
||||
|
||||
query = query.Take(options.PageSize.Value); |
||||
|
||||
var items = await query.Select(e => e.ToDTO()) |
||||
.ToListAsync(); |
||||
|
||||
var page = new Page<UserInfo> |
||||
{ |
||||
PageNumber = (int)options.PageNumber, |
||||
PageSize = (int)options.PageSize, |
||||
TotalPages = (int)Math.Ceiling((double)count / (int)options.PageSize), |
||||
TotalCount = count, |
||||
Items = items |
||||
}; |
||||
|
||||
return Ok(page); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建用户。 |
||||
/// </summary> |
||||
/// <param name="info">用户信息</param> |
||||
/// <returns></returns> |
||||
//[ProducesResponseType(ErrorCodes.E610)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status201Created)] |
||||
[HttpPost("Users")] |
||||
public async Task<ActionResult<UserInfo>> Post([FromBody] UserInfo info) |
||||
{ |
||||
if (string.IsNullOrEmpty(info.Name)) |
||||
return BadRequest(info); |
||||
|
||||
/* |
||||
* 同步放开限制 |
||||
if (info.RoleType == RoleType.Teacher) |
||||
{ |
||||
if (!Regex.IsMatch(info.Name, RegexHelper.Username)) |
||||
return BadRequest(info); |
||||
} |
||||
else if (info.RoleType == RoleType.Student) |
||||
{ |
||||
if (!Regex.IsMatch(info.Name, RegexHelper.IdentityCard)) |
||||
return BadRequest(info); |
||||
} |
||||
else |
||||
return BadRequest(info); |
||||
*/ |
||||
|
||||
await using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
var model = await dbContext.Users |
||||
.AsNoTracking() |
||||
.Where(e => e.Name == info.Name) |
||||
.FirstOrDefaultAsync(); |
||||
|
||||
if (model != default) |
||||
return this.ErrorCode(ErrorCodes.E610); |
||||
|
||||
model = info.ToModel2(); |
||||
|
||||
//处理多对多关系 |
||||
if (info.Posts != default && info.Posts.Any()) |
||||
{ |
||||
var list = new List<UserPost>(info.Posts.Count); |
||||
|
||||
foreach (var post in info.Posts) |
||||
{ |
||||
list.Add(new UserPost |
||||
{ |
||||
User = model, |
||||
PostId = post.Id |
||||
}); |
||||
} |
||||
|
||||
dbContext.Set<UserPost>().AddRange(list); |
||||
} |
||||
|
||||
dbContext.Users.Add(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
await transaction.CommitAsync(); |
||||
|
||||
var result = model.ToDTO(); |
||||
|
||||
return CreatedAtAction(nameof(Post), result); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 修改用户。 |
||||
/// </summary> |
||||
/// <param name="name">用户帐号(身份证号)</param> |
||||
/// <param name="info">用户信息</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[HttpPut("Users/{name}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Put(string name, [FromBody] UserInfo info) |
||||
{ |
||||
if (name != info.Name) |
||||
return BadRequest($"{nameof(name)} and {nameof(info.Name)} are not equal."); |
||||
|
||||
/* |
||||
* 同步放开限制 |
||||
if (info.RoleType == RoleType.Admin) |
||||
return BadRequest(info); |
||||
*/ |
||||
|
||||
await using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
var model = await dbContext.Users |
||||
.Include(e => e.Posts) |
||||
.Where(e => e.Name == info.Name) |
||||
.FirstOrDefaultAsync(); |
||||
|
||||
if (model == default) |
||||
return NotFound(); |
||||
|
||||
info.MapTo(model); |
||||
|
||||
//处理多对多关系 |
||||
if (info.Posts != default && info.Posts.Any()) |
||||
{ |
||||
var list = new List<UserPost>(info.Posts.Count); |
||||
|
||||
foreach (var post in info.Posts) |
||||
{ |
||||
list.Add(new UserPost |
||||
{ |
||||
UserId = model.Id, |
||||
PostId = post.Id |
||||
}); |
||||
} |
||||
|
||||
model.Posts = list; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
await transaction.CommitAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 重置密码。 |
||||
/// </summary> |
||||
/// <param name="name">用户帐号(身份证号)</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[HttpPut("Users/{name}/ResetPassword")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Put(string name) |
||||
{ |
||||
var model = await dbContext.Users.FirstOrDefaultAsync(e => e.Name == name); |
||||
|
||||
if (model == default) |
||||
return NotFound(); |
||||
|
||||
model.ResetPassword(); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 修改密码。 |
||||
/// </summary> |
||||
/// <param name="name">用户帐号</param> |
||||
/// <param name="pwd">密码信息</param> |
||||
//[ProducesResponseType(ErrorCodes.E611)] |
||||
//[ProducesResponseType(ErrorCodes.E612)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[HttpPut("Users/{name}/[action]")]
|
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Password(string name, [FromBody] PasswordInfo pwd) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var user = await dbContext.Users.FirstOrDefaultAsync(e => e.Name == name); |
||||
|
||||
if (user == null) |
||||
return NotFound(); |
||||
|
||||
/* |
||||
* 同步放开限制。 |
||||
if (!user.Enabled) |
||||
return this.ErrorCode(ErrorCodes.E612); |
||||
*/ |
||||
|
||||
user.Password = HashPassword(pwd.Password); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除用户。 |
||||
/// </summary> |
||||
/// <param name="name">用户帐号(身份证号)</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[HttpDelete("Users/{name}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete(string name) |
||||
{ |
||||
if (name == "admin") |
||||
return Forbid(); |
||||
|
||||
var model = await dbContext.Users |
||||
.Where(e => e.Name == name) |
||||
.FirstOrDefaultAsync(); |
||||
|
||||
if (model == default) |
||||
return NotFound(); |
||||
|
||||
model.Deleted = true; |
||||
model.Name = $"{model.Name}-{ObjectId.NewId()}"; |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
using AX.FireTrainingSys.DTOs; |
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 职务控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class PostsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public PostsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得所有职务。 |
||||
/// </summary> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<List<PostInfo>>> Get() |
||||
{ |
||||
var result = await dbContext.Posts |
||||
.AsNoTracking() |
||||
.Select(e => e.ToDTO()) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(result); |
||||
} |
||||
} |
||||
|
||||
internal static partial class Extensions |
||||
{ |
||||
public static PostInfo ToDTO(this Post model) => new PostInfo { Id = model.Id, Name = model.Name }; |
||||
} |
||||
} |
@ -0,0 +1,207 @@
|
||||
using AX.FireTrainingSys.DTOs; |
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Authorization; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Security.Claims; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 学习记录控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class StudyRecordsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public StudyRecordsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得所有学习记录。 |
||||
/// </summary> |
||||
/// <param name="options">查询条件</param> |
||||
/// <returns></returns> |
||||
[Authorize(Roles = nameof(RoleType.Admin))] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<Page<StudyRecordInfo>>> Get([FromQuery] StudyRecordQueryOptions options) |
||||
{ |
||||
var rangeEnd = DateTimeOffset.Now; |
||||
var rangeStart = rangeEnd.AddYears(-1); |
||||
|
||||
if (string.IsNullOrEmpty(options.Name)) |
||||
return BadRequest($"{nameof(options.Name)} can not be empty."); |
||||
|
||||
if (options.StartTime != default && (options.StartTime < rangeStart || options.StartTime > rangeEnd)) |
||||
return BadRequest($"{nameof(options.StartTime)} is out of range."); |
||||
|
||||
if (options.EndTime != default && (options.EndTime < rangeStart || options.EndTime > rangeEnd)) |
||||
return BadRequest($"{nameof(options.EndTime)} is out of range."); |
||||
|
||||
if (options.EndTime == default) |
||||
options.EndTime = rangeEnd; |
||||
|
||||
if (options.StartTime == default) |
||||
options.StartTime = options.EndTime.Value.AddMonths(-1); |
||||
|
||||
if (options.PageNumber == default) |
||||
options.PageNumber = 1; |
||||
|
||||
if (options.PageSize == default) |
||||
options.PageSize = 100; |
||||
|
||||
var query = dbContext.StudyRecords |
||||
.Include(e => e.User) |
||||
.AsNoTracking(); |
||||
|
||||
query = query.Where(e => e.User.Name == options!.Name); |
||||
query = query.Where(e => e.CreationTime >= options.StartTime!.Value.UtcDateTime); |
||||
query = query.Where(e => e.CreationTime <= options.EndTime!.Value.UtcDateTime); |
||||
|
||||
if (!string.IsNullOrEmpty(options.PostName)) |
||||
query = query.Where(e => e.PostName == options.PostName); |
||||
|
||||
if (!string.IsNullOrEmpty(options.Catalog)) |
||||
query = query.Where(e => e.Catalog == options.Catalog); |
||||
|
||||
var count = await query.CountAsync(); |
||||
|
||||
query = query.OrderByDescending(e => e.CreationTime); |
||||
|
||||
if (options.PageNumber > 1) |
||||
query = query.Skip((options.PageNumber.Value - 1) * options.PageSize.Value); |
||||
|
||||
query = query.Take(options.PageSize.Value); |
||||
|
||||
var items = await query.Select(e => e.ToDTO()) |
||||
.ToListAsync(); |
||||
|
||||
var page = new Page<StudyRecordInfo> |
||||
{ |
||||
PageNumber = (int)options.PageNumber, |
||||
PageSize = (int)options.PageSize, |
||||
TotalPages = (int)Math.Ceiling((double)count / (int)options.PageSize), |
||||
TotalCount = count, |
||||
Items = items |
||||
}; |
||||
|
||||
return Ok(page); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 统计学习记录。 |
||||
/// </summary> |
||||
/// <param name="options">查询条件</param> |
||||
/// <returns></returns> |
||||
[Authorize(Roles = nameof(RoleType.Admin))] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[HttpGet("[action]")]
|
||||
public async Task<ActionResult<List<StudyStatisticsInfo>>> Statistics([FromQuery] StudyStatisticsQueryOptions options) |
||||
{ |
||||
var rangeEnd = DateTimeOffset.Now; |
||||
var rangeStart = rangeEnd.AddYears(-1); |
||||
|
||||
if (string.IsNullOrEmpty(options.Name)) |
||||
return BadRequest($"{nameof(options.Name)} can not be empty."); |
||||
|
||||
if (options.StartTime != default && (options.StartTime < rangeStart || options.StartTime > rangeEnd)) |
||||
return BadRequest($"{nameof(options.StartTime)} is out of range."); |
||||
|
||||
if (options.EndTime != default && (options.EndTime < rangeStart || options.EndTime > rangeEnd)) |
||||
return BadRequest($"{nameof(options.EndTime)} is out of range."); |
||||
|
||||
if (options.EndTime == default) |
||||
options.EndTime = rangeEnd; |
||||
|
||||
if (options.StartTime == default) |
||||
options.StartTime = options.EndTime.Value.AddMonths(-1); |
||||
|
||||
var query = dbContext.StudyRecords |
||||
.Include(e => e.User) |
||||
.AsNoTracking(); |
||||
|
||||
query = query.Where(e => e.User.Name == options!.Name); |
||||
query = query.Where(e => e.CreationTime >= options.StartTime!.Value.UtcDateTime); |
||||
query = query.Where(e => e.CreationTime <= options.EndTime!.Value.UtcDateTime); |
||||
|
||||
var result = await query.GroupBy(e => new { e.PostName, e.Catalog }) |
||||
.Select(g => new StudyStatisticsInfo |
||||
{ |
||||
PostName = g.Key.PostName, |
||||
Catalog = g.Key.Catalog, |
||||
Count = g.Count() |
||||
}) |
||||
.OrderBy(e => e.PostName) |
||||
.ThenBy(e => e.Catalog) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(result); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建学习记录。 |
||||
/// </summary> |
||||
/// <param name="info">用户信息</param> |
||||
/// <returns></returns> |
||||
[Authorize(Roles = "Profile")] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status201Created)] |
||||
[HttpPost] |
||||
public async Task<ActionResult<StudyRecordInfo>> Post([FromBody] StudyRecordInfo info) |
||||
{ |
||||
var userid = HttpContext.User.FindFirstValue(JwtClaimTypes.Subject); |
||||
var model = info.ToModel(userid); |
||||
|
||||
dbContext.StudyRecords.Add(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
info.Id = model.Id; |
||||
info.CreationTime = model.CreationTime.ToLocalTime(); |
||||
|
||||
return CreatedAtAction(nameof(Post), info); |
||||
} |
||||
} |
||||
|
||||
internal static partial class Extensions |
||||
{ |
||||
public static StudyRecord ToModel(this StudyRecordInfo info, string userid) => new StudyRecord |
||||
{ |
||||
Operation = info.Operation, |
||||
PostName = info.PostName, |
||||
Catalog = info.Catalog, |
||||
Target = info.Target, |
||||
UserId = userid |
||||
}; |
||||
|
||||
public static StudyRecordInfo ToDTO(this StudyRecord model) => new StudyRecordInfo |
||||
{ |
||||
Id = model.Id, |
||||
CreationTime = model.CreationTime.ToLocalTime(), |
||||
Operation = model.Operation, |
||||
PostName = model.PostName, |
||||
Catalog = model.Catalog, |
||||
Target = model.Target |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,242 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using System.Text.Json; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 毗邻控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateBuildingAdjoinsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateBuildingAdjoinsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateBuildingAdjoins |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateBuildingAdjoins.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateBuildingAdjoins.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateBuildingAdjoin |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateBuildingAdjoins.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateBuildingAdjoins |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateBuildingAdjoins.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateBuildingAdjoin |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateBuildingAdjoins.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateBuildingAdjoins.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条毗邻信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateBuildingAdjoins.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateBuildingAdjoins.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateBuildingAdjoin)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateBuildingAdjoins.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 基本信息控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateBuildingBasicInfosController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateBuildingBasicInfosController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的基本信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateBuildingBasicInfos.FindAsync(name); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的基本信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateBuildingBasicInfos.FindAsync(name); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateBuildingBasicInfo |
||||
{ |
||||
CompanyName = name, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateBuildingBasicInfos.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 建筑特点控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateBuildingFeaturesController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateBuildingFeaturesController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的建筑特点。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateBuildingFeatures.FindAsync(name); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的建筑特点。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateBuildingFeatures.FindAsync(name); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateBuildingFeature |
||||
{ |
||||
CompanyName = name, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateBuildingFeatures.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 行车路线控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateDriveRoutesController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateDriveRoutesController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的行车路线信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateDriveRoutes.FindAsync(name); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的行车路线信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateDriveRoutes.FindAsync(name); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateDriveRoute |
||||
{ |
||||
CompanyName = name, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateDriveRoutes.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 安全出口控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateExitsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateExitsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateExits |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateExits.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateExits.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateExit |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateExits.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateExits |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateExits.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateExit |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateExits.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateExits.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条安全出口信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateExits.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateExits.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateExit)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateExits.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 消防控制室控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateFireControlRoomsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateFireControlRoomsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateFireControlRooms |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFireControlRooms.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFireControlRooms.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateFireControlRoom |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateFireControlRooms.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateFireControlRooms |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateFireControlRooms.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateFireControlRoom |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateFireControlRooms.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateFireControlRooms.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条消防控制室信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFireControlRooms.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateFireControlRooms.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateFireControlRoom)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateFireControlRooms.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,130 @@
|
||||
using AX.FireTrainingSys.DTOs; |
||||
using AX.FireTrainingSys.Models; |
||||
using Mapster; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 消防力量控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateFireForcesController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateFireForcesController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定组织机构的所有消防力量信息。 |
||||
/// </summary> |
||||
/// <param name="organizationId">机构编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<FireForceInfo>>> Get([FromQuery, BindRequired]string organizationId) |
||||
{ |
||||
if (string.IsNullOrEmpty(organizationId)) |
||||
return BadRequest($"{nameof(organizationId)}:{organizationId}"); |
||||
|
||||
var result = await dbContext.TemplateFireForces |
||||
.AsNoTracking() |
||||
.Where(e => e.OrganizationId == organizationId) |
||||
.Select(e => e.ToDTO()) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(result); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新单条消防力量。 |
||||
/// </summary> |
||||
/// <param name="id">消防力量编号</param> |
||||
/// <param name="dto">要保存的消防力量数据</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status201Created)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<ActionResult<FireForceInfo>> PostOrPut(string id, [FromBody] FireForceInfo dto) |
||||
{ |
||||
if (string.IsNullOrEmpty(id)) |
||||
return BadRequest(id); |
||||
|
||||
if (id != dto.Id) |
||||
return BadRequest($"id: {id} is not equal to dto: {dto.Id}."); |
||||
|
||||
var model = await dbContext.TemplateFireForces.FindAsync(dto.Id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = dto.ToModel(); |
||||
dbContext.TemplateFireForces.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
dto.MapTo(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除单条消防力量信息。 |
||||
/// </summary> |
||||
/// <param name="id">组织机构编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete(string id) |
||||
{ |
||||
var model = await dbContext.TemplateFireForces.FindAsync(id); |
||||
|
||||
if (model == null) |
||||
return NotFound(); |
||||
|
||||
dbContext.TemplateFireForces.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
} |
||||
|
||||
internal static class TemplateFireForceExtensions |
||||
{ |
||||
public static TemplateFireForce ToModel(this FireForceInfo dto) |
||||
{ |
||||
var model = dto.Adapt<TemplateFireForce>(); |
||||
return model; |
||||
} |
||||
|
||||
public static FireForceInfo ToDTO(this TemplateFireForce model) |
||||
{ |
||||
var dto = model.Adapt<FireForceInfo>(); |
||||
return dto; |
||||
} |
||||
|
||||
public static void MapTo(this FireForceInfo dto, TemplateFireForce model) |
||||
{ |
||||
dto.Adapt(model); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 消防电梯控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateFireLiftsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateFireLiftsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateFireLifts |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFireLifts.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFireLifts.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateFireLift |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateFireLifts.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateFireLifts |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateFireLifts.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateFireLift |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateFireLifts.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateFireLifts.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条消防电梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFireLifts.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateFireLifts.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateFireLift)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateFireLifts.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1.Template |
||||
{ |
||||
/// <summary> |
||||
/// 消防水炮。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateFireWaterMonitorsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateFireWaterMonitorsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateFireWaterMonitors |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFireWaterMonitors.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFireWaterMonitors.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateFireWaterMonitor |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateFireWaterMonitors.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateFireWaterMonitors |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateFireWaterMonitors.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateFireWaterMonitor |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateFireWaterMonitors.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateFireWaterMonitors.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条消防水炮信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFireWaterMonitors.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateFireWaterMonitors.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateFireWaterMonitor)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateFireWaterMonitors.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1.Template |
||||
{ |
||||
/// <summary> |
||||
/// 泡沫栓控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateFoamHydrantsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateFoamHydrantsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateFoamHydrants |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFoamHydrants.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFoamHydrants.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateFoamHydrant |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateFoamHydrants.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateFoamHydrants |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateFoamHydrants.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateFoamHydrant |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateFoamHydrants.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateFoamHydrants.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条泡沫栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFoamHydrants.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateFoamHydrants.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateFoamHydrant)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateFoamHydrants.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 泡沫泵房控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateFoamPumpRoomsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateFoamPumpRoomsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateFoamPumpRooms |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFoamPumpRooms.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFoamPumpRooms.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateFoamPumpRoom |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateFoamPumpRooms.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateFoamPumpRooms |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateFoamPumpRooms.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateFoamPumpRoom |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateFoamPumpRooms.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateFoamPumpRooms.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条泡沫泵房信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateFoamPumpRooms.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateFoamPumpRooms.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateFoamPumpRoom)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateFoamPumpRooms.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 图片标记控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateImageMarkersController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateImageMarkersController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateImageMarkers |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateImageMarkers.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateImageMarkers.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateImageMarker |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateImageMarkers.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateImageMarkers |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateImageMarkers.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateImageMarker |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateImageMarkers.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateImageMarkers.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条图片标记信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateImageMarkers.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateImageMarkers.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateImageMarker)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateImageMarkers.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 重点部位控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateImportantLocationsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateImportantLocationsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateImportantLocations |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateImportantLocations.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateImportantLocations.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateImportantLocation |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateImportantLocations.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateImportantLocations |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateImportantLocations.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateImportantLocation |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateImportantLocations.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateImportantLocations.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条重点部位信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateImportantLocations.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateImportantLocations.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateImportantLocation)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateImportantLocations.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 市政消火栓控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateMunicipalFireHydrantsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateMunicipalFireHydrantsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateMunicipalFireHydrants |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateMunicipalFireHydrants.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateMunicipalFireHydrants.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateMunicipalFireHydrant |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateMunicipalFireHydrants.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateMunicipalFireHydrants |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateMunicipalFireHydrants.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateMunicipalFireHydrant |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateMunicipalFireHydrants.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateMunicipalFireHydrants.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条市政消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateMunicipalFireHydrants.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateMunicipalFireHydrants.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateMunicipalFireHydrant)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateMunicipalFireHydrants.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 禁停区控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateNoParkingAreasController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateNoParkingAreasController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有禁停区信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateNoParkingAreas |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条禁停区信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateNoParkingAreas.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条禁停区信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateNoParkingAreas.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateNoParkingArea |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateNoParkingAreas.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的禁停区信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateNoParkingAreas |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateNoParkingAreas.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateNoParkingArea |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateNoParkingAreas.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的禁停区信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateNoParkingAreas.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条禁停区信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateNoParkingAreas.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateNoParkingAreas.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateNoParkingArea)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateNoParkingAreas.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,125 @@
|
||||
using AX.FireTrainingSys.DTOs; |
||||
using AX.FireTrainingSys.Models; |
||||
using Mapster; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 组织机构控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateOrganizationsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateOrganizationsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得所有组织机构信息。 |
||||
/// </summary> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<OrganizationInfo>>> GetAll() |
||||
{ |
||||
var models = await dbContext.TemplateOrganizations |
||||
.AsNoTracking() |
||||
.OrderByDescending(e => e.Order) |
||||
.Select(e => e.ToDTO()) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新单条组织机构信息。 |
||||
/// </summary> |
||||
/// <param name="id">组织机构编号</param> |
||||
/// <param name="dto">要保存的组织机构信息</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<ActionResult<OrganizationInfo>> PostOrPut(string id, [FromBody] OrganizationInfo dto) |
||||
{ |
||||
if (string.IsNullOrEmpty(id)) |
||||
return BadRequest(id); |
||||
|
||||
if (id != dto.Id) |
||||
return BadRequest($"id: {id} is not equal to dto: {dto.Id}."); |
||||
|
||||
var model = await dbContext.TemplateOrganizations.FindAsync(id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = dto.ToModel(); |
||||
dbContext.TemplateOrganizations.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
dto.MapTo(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除单条组织机构信息。 |
||||
/// </summary> |
||||
/// <param name="id">组织机构编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete(string id) |
||||
{ |
||||
var model = await dbContext.TemplateOrganizations.FindAsync(id); |
||||
|
||||
if (model == null) |
||||
return NotFound(); |
||||
|
||||
dbContext.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
} |
||||
|
||||
internal static class TemplateOrganizationExtensions |
||||
{ |
||||
public static TemplateOrganization ToModel(this OrganizationInfo dto) |
||||
{ |
||||
var model = dto.Adapt<TemplateOrganization>(); |
||||
return model; |
||||
} |
||||
|
||||
public static OrganizationInfo ToDTO(this TemplateOrganization model) |
||||
{ |
||||
var dto = model.Adapt<OrganizationInfo>(); |
||||
return dto; |
||||
} |
||||
|
||||
public static void MapTo(this OrganizationInfo dto, TemplateOrganization model) |
||||
{ |
||||
dto.Adapt(model); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 室外消火栓控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateOutdoorFireHydrantsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateOutdoorFireHydrantsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateOutdoorFireHydrants |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateOutdoorFireHydrants.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateOutdoorFireHydrants.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateOutdoorFireHydrant |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateOutdoorFireHydrants.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateOutdoorFireHydrants |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateOutdoorFireHydrants.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateOutdoorFireHydrant |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateOutdoorFireHydrants.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateOutdoorFireHydrants.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条室外消火栓信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateOutdoorFireHydrants.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateOutdoorFireHydrants.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateOutdoorFireHydrant)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateOutdoorFireHydrants.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 周边水源控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplatePeripheralWaterSourcesController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplatePeripheralWaterSourcesController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的周边水源信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplatePeripheralWaterSources.FindAsync(name); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的周边水源信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplatePeripheralWaterSources.FindAsync(name); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplatePeripheralWaterSource |
||||
{ |
||||
CompanyName = name, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplatePeripheralWaterSources.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 疏散楼梯控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateProtectedStairwaysController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateProtectedStairwaysController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateProtectedStairways |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateProtectedStairways.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateProtectedStairways.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateProtectedStairway |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateProtectedStairways.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateProtectedStairways |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateProtectedStairways.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateProtectedStairway |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateProtectedStairways.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateProtectedStairways.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条疏散楼梯信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateProtectedStairways.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateProtectedStairways.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateProtectedStairway)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateProtectedStairways.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 泵房/水箱控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplatePumpRoomsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplatePumpRoomsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplatePumpRooms |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplatePumpRooms.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplatePumpRooms.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplatePumpRoom |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplatePumpRooms.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplatePumpRooms |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplatePumpRooms.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplatePumpRoom |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplatePumpRooms.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplatePumpRooms.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条泵房/水箱信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplatePumpRooms.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplatePumpRooms.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplatePumpRoom)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplatePumpRooms.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 水泵接合器控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateSiameseConnectionsController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateSiameseConnectionsController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateSiameseConnections |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateSiameseConnections.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateSiameseConnections.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateSiameseConnection |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateSiameseConnections.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateSiameseConnections |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateSiameseConnections.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateSiameseConnection |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateSiameseConnections.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateSiameseConnections.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条水泵接合器信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateSiameseConnections.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateSiameseConnections.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateSiameseConnection)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateSiameseConnections.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1.Template |
||||
{ |
||||
/// <summary> |
||||
/// 储罐控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateStorageTanksController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateStorageTanksController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有储罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateStorageTanks |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条储罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateStorageTanks.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条储罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateStorageTanks.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateStorageTank |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateStorageTanks.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的储罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateStorageTanks |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateStorageTanks.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateStorageTank |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateStorageTanks.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的储罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateStorageTanks.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条储罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateStorageTanks.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateStorageTanks.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateStorageTank)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateStorageTanks.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,241 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text.Json; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers.V1 |
||||
{ |
||||
/// <summary> |
||||
/// 水管控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[ApiController] |
||||
public class TemplateWaterTanksController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public TemplateWaterTanksController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的所有水罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<IEnumerable<string>>> GetAll([FromQuery, BindRequired]string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var models = await dbContext.TemplateWaterTanks |
||||
.AsNoTracking() |
||||
.Where(e => e.CompanyName == name) |
||||
.Select(e => e.Content) |
||||
.ToListAsync(); |
||||
|
||||
return Ok(models); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得指定单位的单条水罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpGet("{id}")] |
||||
public async Task<ActionResult<string>> Get([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateWaterTanks.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(name); |
||||
|
||||
return Ok(model.Content); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建或更新指定单位的单条水罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPut([FromQuery, BindRequired]string name, string id, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateWaterTanks.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
{ |
||||
model = new TemplateWaterTank |
||||
{ |
||||
CompanyName = name, |
||||
Id = id, |
||||
Content = content |
||||
}; |
||||
|
||||
dbContext.TemplateWaterTanks.Add(model); |
||||
} |
||||
else |
||||
{ |
||||
model.Content = content; |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量创建或更新指定单位的水罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要保存的内容</param> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[HttpPost] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> PostOrPutAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
//首先删除所有该单位的相关信息 |
||||
var olds = await dbContext |
||||
.TemplateWaterTanks |
||||
.Where(e => e.CompanyName == name) |
||||
.ToListAsync(); |
||||
|
||||
dbContext.TemplateWaterTanks.RemoveRange(olds); |
||||
|
||||
//依次插入新信息 |
||||
foreach (var item in data) |
||||
{ |
||||
var model = new TemplateWaterTank |
||||
{ |
||||
CompanyName = name, |
||||
Id = item.Key, |
||||
Content = item.Value |
||||
}; |
||||
|
||||
dbContext.TemplateWaterTanks.Add(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return Ok(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 批量删除指定单位的水罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="content">要删除的内容</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> DeleteAll([FromQuery, BindRequired]string name, [FromBody]string content) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
if (string.IsNullOrEmpty(content)) |
||||
return BadRequest(content); |
||||
|
||||
var data = JsonSerializer.Deserialize<string[]>(content); |
||||
|
||||
if (data == null) |
||||
return BadRequest(content); |
||||
|
||||
using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
await foreach (var (id, model) in AsAsyncEnumerable(name, data)) |
||||
{ |
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateWaterTanks.Remove(model); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
transaction.Commit(); |
||||
} |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除指定单位的单条水罐信息。 |
||||
/// </summary> |
||||
/// <param name="name">指定的单位名称</param> |
||||
/// <param name="id">指定的相关编号</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[HttpDelete("{id}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete([FromQuery, BindRequired]string name, string id) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return BadRequest(name); |
||||
|
||||
var model = await dbContext.TemplateWaterTanks.FindAsync(name, id); |
||||
|
||||
if (model == null) |
||||
return NotFound(id); |
||||
|
||||
dbContext.TemplateWaterTanks.Remove(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
private async IAsyncEnumerable<(string, TemplateWaterTank)> AsAsyncEnumerable(string name, string[] data) |
||||
{ |
||||
foreach (var item in data) |
||||
{ |
||||
var model = await dbContext.TemplateWaterTanks.FindAsync(name, item); |
||||
yield return (item, model); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,336 @@
|
||||
using AX.FireTrainingSys.DTOs; |
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Authorization; |
||||
using Microsoft.AspNetCore.Http; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics.CodeAnalysis; |
||||
using System.Linq; |
||||
using System.Text.RegularExpressions; |
||||
using System.Threading.Tasks; |
||||
using static BCrypt.Net.BCrypt; |
||||
|
||||
namespace AX.FireTrainingSys.Controllers |
||||
{ |
||||
/// <summary> |
||||
/// 用户控制器。 |
||||
/// </summary> |
||||
[Produces("application/json")] |
||||
[Route("api/[controller]")]
|
||||
[ApiVersion("1.0")] |
||||
[Authorize(Roles = nameof(RoleType.Admin))] |
||||
[ApiController] |
||||
public class UsersController : ControllerBase |
||||
{ |
||||
private readonly DriveDbContext dbContext; |
||||
|
||||
public UsersController(DriveDbContext dbContext) |
||||
{ |
||||
this.dbContext = dbContext; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 获得所有用户信息。 |
||||
/// </summary> |
||||
/// <param name="options">查询条件</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status200OK)] |
||||
[HttpGet] |
||||
public async Task<ActionResult<Page<UserInfo>>> Get([FromQuery] UserQueryOptions options) |
||||
{ |
||||
if (options.PageNumber == default) |
||||
options.PageNumber = 1; |
||||
|
||||
if (options.PageSize == default) |
||||
options.PageSize = 10; |
||||
|
||||
if (options.RoleType == default) |
||||
options.RoleType = RoleType.Student; |
||||
|
||||
var query = dbContext.Users |
||||
.Include(e => e.Posts).ThenInclude(e => e.Post) |
||||
.AsNoTracking(); |
||||
|
||||
query = query.Where(e => e.RoleType == options.RoleType); |
||||
|
||||
if (!string.IsNullOrEmpty(options.Name)) |
||||
query = query.Where(e => e.Name.Contains(options.Name)); |
||||
|
||||
if (!string.IsNullOrEmpty(options.RealName)) |
||||
query = query.Where(e => e.RealName.Contains(options.RealName)); |
||||
|
||||
var count = await query.CountAsync(); |
||||
|
||||
query = query.OrderByDescending(e => e.CreationTime); |
||||
|
||||
if (options.PageNumber > 1) |
||||
query = query.Skip((options.PageNumber.Value - 1) * options.PageSize.Value); |
||||
|
||||
query = query.Take(options.PageSize.Value); |
||||
|
||||
var items = await query.Select(e => e.ToDTO()) |
||||
.ToListAsync(); |
||||
|
||||
var page = new Page<UserInfo> |
||||
{ |
||||
PageNumber = (int)options.PageNumber, |
||||
PageSize = (int)options.PageSize, |
||||
TotalPages = (int)Math.Ceiling((double)count / (int)options.PageSize), |
||||
TotalCount = count, |
||||
Items = items |
||||
}; |
||||
|
||||
return Ok(page); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 创建用户。 |
||||
/// </summary> |
||||
/// <param name="info">用户信息</param> |
||||
/// <returns></returns> |
||||
//[ProducesResponseType(ErrorCodes.E610)] |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status201Created)] |
||||
[HttpPost] |
||||
public async Task<ActionResult<UserInfo>> Post([FromBody] UserInfo info) |
||||
{ |
||||
if (string.IsNullOrEmpty(info.Name)) |
||||
return BadRequest(info); |
||||
|
||||
if (info.RoleType == RoleType.Teacher) |
||||
{ |
||||
if (!Regex.IsMatch(info.Name, RegexHelper.Username)) |
||||
return BadRequest(info); |
||||
} |
||||
else if (info.RoleType == RoleType.Student) |
||||
{ |
||||
if (!Regex.IsMatch(info.Name, RegexHelper.IdentityCard)) |
||||
return BadRequest(info); |
||||
} |
||||
else |
||||
return BadRequest(info); |
||||
|
||||
await using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
var model = await dbContext.Users |
||||
.AsNoTracking() |
||||
.Where(e => e.Name == info.Name) |
||||
.FirstOrDefaultAsync(); |
||||
|
||||
if (model != default) |
||||
return this.ErrorCode(ErrorCodes.E610); |
||||
|
||||
model = info.ToModel(); |
||||
|
||||
//处理多对多关系 |
||||
if (info.Posts != default && info.Posts.Any()) |
||||
{ |
||||
var list = new List<UserPost>(info.Posts.Count); |
||||
|
||||
foreach (var post in info.Posts) |
||||
{ |
||||
list.Add(new UserPost |
||||
{ |
||||
User = model, |
||||
PostId = post.Id |
||||
}); |
||||
} |
||||
|
||||
dbContext.Set<UserPost>().AddRange(list); |
||||
} |
||||
|
||||
dbContext.Users.Add(model); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
await transaction.CommitAsync(); |
||||
|
||||
var result = model.ToDTO(); |
||||
|
||||
return CreatedAtAction(nameof(Post), result); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 修改用户。 |
||||
/// </summary> |
||||
/// <param name="name">用户帐号(身份证号)</param> |
||||
/// <param name="info">用户信息</param> |
||||
/// <returns></returns> |
||||
//[ProducesResponseType(ErrorCodes.E610)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[HttpPut("{name}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Put(string name, [FromBody] UserInfo info) |
||||
{ |
||||
if (name != info.Name) |
||||
return BadRequest($"{nameof(name)} and {nameof(info.Name)} are not equal."); |
||||
|
||||
if (info.RoleType == RoleType.Admin) |
||||
return BadRequest(info); |
||||
|
||||
await using (var transaction = dbContext.Database.BeginTransaction()) |
||||
{ |
||||
var model = await dbContext.Users |
||||
.Include(e => e.Posts) |
||||
.Where(e => e.Name == info.Name) |
||||
.FirstOrDefaultAsync(); |
||||
|
||||
if (model == default) |
||||
return NotFound(); |
||||
|
||||
info.MapTo(model); |
||||
|
||||
//处理多对多关系 |
||||
if (info.Posts != default && info.Posts.Any()) |
||||
{ |
||||
var posts = model.Posts; |
||||
|
||||
var list = new List<UserPost>(info.Posts.Count); |
||||
|
||||
foreach (var post in info.Posts) |
||||
{ |
||||
list.Add(new UserPost |
||||
{ |
||||
UserId = model.Id, |
||||
PostId = post.Id |
||||
}); |
||||
} |
||||
|
||||
var comparer = new UserPostComparer(); |
||||
|
||||
var removeItems = posts.Except(list, comparer); |
||||
var addItems = list.Except(posts, comparer); |
||||
|
||||
dbContext.Set<UserPost>().RemoveRange(removeItems); |
||||
dbContext.Set<UserPost>().AddRange(addItems); |
||||
} |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
await transaction.CommitAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 重置密码。 |
||||
/// </summary> |
||||
/// <param name="name">用户帐号(身份证号)</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)] |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[HttpPut("{name}/ResetPassword")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Put(string name) |
||||
{ |
||||
var model = await dbContext.Users.FirstOrDefaultAsync(e => e.Name == name); |
||||
|
||||
if (model == default) |
||||
return NotFound(); |
||||
|
||||
model.ResetPassword(); |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 删除用户。 |
||||
/// </summary> |
||||
/// <param name="name">用户帐号(身份证号)</param> |
||||
/// <returns></returns> |
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)] |
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)] |
||||
[ProducesResponseType(StatusCodes.Status404NotFound)] |
||||
[ProducesResponseType(StatusCodes.Status204NoContent)] |
||||
[HttpDelete("{name}")] |
||||
public async Task<Microsoft.AspNetCore.Mvc.ActionResult> Delete(string name) |
||||
{ |
||||
if (name == "admin") |
||||
return Forbid(); |
||||
|
||||
var model = await dbContext.Users |
||||
.Where(e => e.Name == name) |
||||
.FirstOrDefaultAsync(); |
||||
|
||||
if (model == default) |
||||
return NotFound(); |
||||
|
||||
model.Deleted = true; |
||||
model.Name = $"{model.Name}-{ObjectId.NewId()}"; |
||||
|
||||
await dbContext.SaveChangesAsync(); |
||||
|
||||
return NoContent(); |
||||
} |
||||
} |
||||
|
||||
internal static partial class Extensions |
||||
{ |
||||
private const string DefaultPassword = "12345678"; |
||||
|
||||
public static UserInfo ToDTO(this User model) => new UserInfo |
||||
{ |
||||
Name = model.Name, |
||||
RealName = model.RealName, |
||||
RoleType = model.RoleType, |
||||
Enabled = model.Enabled, |
||||
CreationTime = model.CreationTime.ToLocalTime(), |
||||
Posts = model.Posts?.Select(e => e.Post?.ToDTO()).ToList() |
||||
}; |
||||
|
||||
public static ProfileInfo ToDTO2(this User model) => new ProfileInfo |
||||
{ |
||||
Id = model.Id, |
||||
Name = model.Name, |
||||
RealName = model.RealName, |
||||
RoleType = model.RoleType, |
||||
Enabled = model.Enabled, |
||||
CreationTime = model.CreationTime.ToLocalTime(), |
||||
Posts = model.Posts.Select(e => e.Post?.ToDTO()).ToList() |
||||
}; |
||||
|
||||
public static User ToModel(this UserInfo dto) => new User |
||||
{ |
||||
Name = dto.Name, |
||||
Password = HashPassword(DefaultPassword), |
||||
RealName = dto.RealName, |
||||
RoleType = dto.RoleType |
||||
}; |
||||
|
||||
//专用于数据同步 |
||||
public static User ToModel2(this UserInfo dto) => new User |
||||
{ |
||||
Name = dto.Name, |
||||
Password = HashPassword(DefaultPassword), |
||||
RealName = dto.RealName, |
||||
RoleType = dto.RoleType, |
||||
Enabled = dto.Enabled ?? true |
||||
}; |
||||
|
||||
public static void MapTo(this UserInfo dto, User model) |
||||
{ |
||||
model.RealName = dto.RealName; |
||||
model.RoleType = dto.RoleType; |
||||
model.Enabled = dto.Enabled ?? true; |
||||
} |
||||
|
||||
public static void ResetPassword(this User model) |
||||
{ |
||||
model.Password = HashPassword(DefaultPassword); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys |
||||
{ |
||||
/// <summary> |
||||
/// 类型转换辅助类。 |
||||
/// </summary> |
||||
public static class ConverterHelper |
||||
{ |
||||
/// <summary> |
||||
/// DateTime 到 string 的类型转换。 |
||||
/// </summary> |
||||
/// <returns></returns> |
||||
public static ValueConverter<DateTime, string> DateTimeToStringConverter() => new ValueConverter<DateTime, string>( |
||||
v => v.ToString("yyyy-MM-dd HH:mm:ss"), |
||||
v => DateTime.SpecifyKind(DateTime.Parse(v), DateTimeKind.Utc)); |
||||
} |
||||
} |
@ -0,0 +1,65 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 课件信息。 |
||||
/// </summary> |
||||
public class CoursewareInfo |
||||
{ |
||||
/// <summary> |
||||
/// Id。 |
||||
/// </summary> |
||||
[MaxLength(24)] |
||||
public string Id { get; set; } |
||||
/// <summary> |
||||
/// 题目名称。 |
||||
/// </summary> |
||||
[MaxLength(128)] |
||||
public string Name { get; set; } |
||||
/// <summary> |
||||
/// 作者。 |
||||
/// </summary> |
||||
public string Creator { get; set; } |
||||
/// <summary> |
||||
/// 单位类型列表。 |
||||
/// </summary> |
||||
public int[] BuildingTypes { get; set; } |
||||
/// <summary> |
||||
/// 简介。 |
||||
/// </summary> |
||||
public string Introduction { get; set; } |
||||
/// <summary> |
||||
/// 修改时间。 |
||||
/// </summary> |
||||
public DateTimeOffset? ModifiedTime { get; set; } |
||||
/// <summary> |
||||
/// 是否公开。 |
||||
/// </summary> |
||||
public bool? IsPublic { get; set; } |
||||
/// <summary> |
||||
/// 图片地址。 |
||||
/// </summary> |
||||
public string ImageUrl { get; set; } |
||||
/// <summary> |
||||
/// 灾情设置地址。 |
||||
/// </summary> |
||||
public string QuestionUrl { get; set; } |
||||
/// <summary> |
||||
/// 标准答案地址。 |
||||
/// </summary> |
||||
public string StandardAnswerUrl { get; set; } |
||||
/// <summary> |
||||
/// 是否被引用。 |
||||
/// </summary> |
||||
public bool? Referenced { get; set; } |
||||
/// <summary> |
||||
/// 单位名称。 |
||||
/// </summary> |
||||
public string CompanyName { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 课件查询条件。 |
||||
/// </summary> |
||||
public class CoursewareQueryOptions : QueryOptions |
||||
{ |
||||
/// <summary> |
||||
/// 名称。 |
||||
/// </summary> |
||||
public string Name { get; set; } |
||||
/// <summary> |
||||
/// 单位类型编号。 |
||||
/// </summary> |
||||
public int? BuildingType { get; set; } |
||||
/// <summary> |
||||
/// 单位名称。 |
||||
/// </summary> |
||||
public string CompanyName { get; set; } |
||||
/// <summary> |
||||
/// 题目作者。 |
||||
/// </summary> |
||||
public string Creator { get; set; } |
||||
/// <summary> |
||||
/// 是否公开。 |
||||
/// </summary> |
||||
public bool? IsPublic { get; set; } |
||||
/// <summary> |
||||
/// 是否他人。 |
||||
/// </summary> |
||||
public bool? Others { get; set; } |
||||
/// <summary> |
||||
/// 修改时间。 |
||||
/// </summary> |
||||
public DateTimeOffset? ModifiedTime { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 灾情信息。 |
||||
/// </summary> |
||||
public class DisasterInfo |
||||
{ |
||||
/// <summary> |
||||
/// Id。 |
||||
/// </summary> |
||||
[MaxLength(24)] |
||||
public string Id { get; set; } |
||||
/// <summary> |
||||
/// 灾情名称。 |
||||
/// </summary> |
||||
[MaxLength(128)] |
||||
[Required] |
||||
public string Name { get; set; } |
||||
/// <summary> |
||||
/// 用户编号。 |
||||
/// </summary> |
||||
public string UserId { get; set; } |
||||
/// <summary> |
||||
/// 真实姓名。 |
||||
/// </summary> |
||||
public string RealName { get; set; } |
||||
/// <summary> |
||||
/// 单位类型列表。 |
||||
/// </summary> |
||||
public int[] BuildingTypes { get; set; } |
||||
/// <summary> |
||||
/// 简介。 |
||||
/// </summary> |
||||
public string Introduction { get; set; } |
||||
/// <summary> |
||||
/// 创建时间。 |
||||
/// </summary> |
||||
public DateTimeOffset? CreationTime { get; set; } |
||||
/// <summary> |
||||
/// 单位名称。 |
||||
/// </summary> |
||||
public string CompanyName { get; set; } |
||||
/// <summary> |
||||
/// 推演状态。 |
||||
/// </summary> |
||||
[BindRequired] |
||||
public DisasterState State { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 消防力量。 |
||||
/// </summary> |
||||
public class FireForceInfo |
||||
{ |
||||
/// <summary> |
||||
/// Id。 |
||||
/// </summary> |
||||
public string Id { get; set; } |
||||
/// <summary> |
||||
/// 类型。 |
||||
/// </summary> |
||||
public string Type { get; set; } |
||||
/// <summary> |
||||
/// 内容。 |
||||
/// </summary> |
||||
public string Content { get; set; } |
||||
/// <summary> |
||||
/// 组织机构编号。 |
||||
/// </summary> |
||||
public string OrganizationId { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 身份信息。 |
||||
/// </summary> |
||||
public class IdentityInfo |
||||
{ |
||||
/// <summary> |
||||
/// JWT。 |
||||
/// </summary> |
||||
public string Token { get; set; } |
||||
/// <summary> |
||||
/// 刷新令牌。 |
||||
/// </summary> |
||||
public string RefreshToken { get; set; } |
||||
/// <summary> |
||||
/// 到期时间。 |
||||
/// </summary> |
||||
public double Expires { get; set; } |
||||
/// <summary> |
||||
/// 用户编号。 |
||||
/// </summary> |
||||
public string UserId { get; set; } |
||||
/// <summary> |
||||
/// 真实姓名。 |
||||
/// </summary> |
||||
public string RealName { get; set; } |
||||
/// <summary> |
||||
/// 角色类型。 |
||||
/// </summary> |
||||
public RoleType RoleType { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 修改密码信息。 |
||||
/// </summary> |
||||
public class ModifyPasswordInfo |
||||
{ |
||||
/// <summary> |
||||
/// 旧密码。 |
||||
/// </summary> |
||||
[Required] |
||||
public string Password { get; set; } |
||||
/// <summary> |
||||
/// 新密码。 |
||||
/// </summary> |
||||
[RegularExpression(RegexHelper.Password)] |
||||
[Required] |
||||
public string NewPassword { get; set; } |
||||
} |
||||
|
||||
//专用于数据同步 |
||||
public class PasswordInfo |
||||
{ |
||||
/// <summary> |
||||
/// 新密码。 |
||||
/// </summary> |
||||
[Required] |
||||
public string Password { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,52 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
public struct Vector3 |
||||
{ |
||||
public float X { get; set; } |
||||
public float Y { get; set; } |
||||
public float Z { get; set; } |
||||
|
||||
public Vector3(float x, float y, float z) |
||||
{ |
||||
this.X = x; |
||||
this.Y = y; |
||||
this.Z = z; |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 组织机构。 |
||||
/// </summary> |
||||
public class OrganizationInfo |
||||
{ |
||||
/// <summary> |
||||
/// 机构编号。 |
||||
/// </summary> |
||||
public string Id { get; set; } |
||||
/// <summary> |
||||
/// 机构名称。 |
||||
/// </summary> |
||||
public string Name { get; set; } |
||||
/// <summary> |
||||
/// 机构级别。 |
||||
/// </summary> |
||||
public int Level { get; set; } |
||||
/// <summary> |
||||
/// 顺序。 |
||||
/// </summary> |
||||
public int? Order { get; set; } |
||||
/// <summary> |
||||
/// 位置。 |
||||
/// </summary> |
||||
public Vector3 Position { get; set; } |
||||
/// <summary> |
||||
/// 父级机构编号。 |
||||
/// </summary> |
||||
public string ParentId { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 职务。 |
||||
/// </summary> |
||||
public class PostInfo |
||||
{ |
||||
/// <summary> |
||||
/// 编号。 |
||||
/// </summary> |
||||
public int Id { get; set; } |
||||
/// <summary> |
||||
/// 名称。 |
||||
/// </summary> |
||||
public string Name { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 查询条件。 |
||||
/// </summary> |
||||
public class QueryOptions |
||||
{ |
||||
/// <summary> |
||||
/// 分页页数。 |
||||
/// </summary> |
||||
public int? PageNumber { get; set; } |
||||
/// <summary> |
||||
/// 一页多少条。 |
||||
/// </summary> |
||||
public int? PageSize { get; set; } |
||||
|
||||
/// <summary> |
||||
/// 排序选项。 |
||||
/// </summary> |
||||
public string Sort { get; set; } |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 分页结果集。 |
||||
/// </summary> |
||||
/// <typeparam name="T"></typeparam> |
||||
public class Page<T> |
||||
{ |
||||
/// <summary> |
||||
/// 当前页。 |
||||
/// </summary> |
||||
public int PageNumber { get; set; } |
||||
/// <summary> |
||||
/// 每页个数。 |
||||
/// </summary> |
||||
public int PageSize { get; set; } |
||||
/// <summary> |
||||
/// 总页数。 |
||||
/// </summary> |
||||
public int TotalPages { get; set; } |
||||
/// <summary> |
||||
/// 总个数。 |
||||
/// </summary> |
||||
public int TotalCount { get; set; } |
||||
/// <summary> |
||||
/// 查询集合。 |
||||
/// </summary> |
||||
public IEnumerable<T> Items { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 刷新令牌信息。 |
||||
/// </summary> |
||||
public class RefreshTokenInfo |
||||
{ |
||||
/// <summary> |
||||
/// JWT令牌。 |
||||
/// </summary> |
||||
public string Token { get; set; } |
||||
/// <summary> |
||||
/// 刷新令牌。 |
||||
/// </summary> |
||||
public string RefreshToken { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 登录信息。 |
||||
/// </summary> |
||||
public class SignInInfo |
||||
{ |
||||
/// <summary> |
||||
/// 帐号名称。 |
||||
/// </summary> |
||||
[Required] |
||||
public string Name { get; set; } |
||||
/// <summary> |
||||
/// 密码。 |
||||
/// </summary> |
||||
[Required] |
||||
public string Password { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 学习记录。 |
||||
/// </summary> |
||||
public class StudyRecordInfo |
||||
{ |
||||
/// <summary> |
||||
/// 编号。 |
||||
/// </summary> |
||||
public string Id { get; set; } |
||||
/// <summary> |
||||
/// 创建时间。 |
||||
/// </summary> |
||||
public DateTimeOffset? CreationTime { get; set; } |
||||
/// <summary> |
||||
/// 操作。 |
||||
/// </summary> |
||||
public string Operation { get; set; } |
||||
/// <summary> |
||||
/// 职务名称。 |
||||
/// </summary> |
||||
public string PostName { get; set; } |
||||
/// <summary> |
||||
/// 目录。 |
||||
/// </summary> |
||||
public string Catalog { get; set; } |
||||
/// <summary> |
||||
/// 目标。 |
||||
/// </summary> |
||||
public string Target { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 学习记录查询条件。 |
||||
/// </summary> |
||||
public class StudyRecordQueryOptions : QueryOptions |
||||
{ |
||||
/// <summary> |
||||
/// 用户帐号(身份证号)。 |
||||
/// </summary> |
||||
[Required] |
||||
public string Name { get; set; } |
||||
/// <summary> |
||||
/// 开始时间。 |
||||
/// </summary> |
||||
public DateTimeOffset? StartTime { get; set; } |
||||
/// <summary> |
||||
/// 结束时间。 |
||||
/// </summary> |
||||
public DateTimeOffset? EndTime { get; set; } |
||||
/// <summary> |
||||
/// 职务名称。 |
||||
/// </summary> |
||||
public string PostName { get; set; } |
||||
/// <summary> |
||||
/// 目录。 |
||||
/// </summary> |
||||
public string Catalog { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 学习统计信息。 |
||||
/// </summary> |
||||
public class StudyStatisticsInfo |
||||
{ |
||||
/// <summary> |
||||
/// 职务名称。 |
||||
/// </summary> |
||||
public string PostName { get; set; } |
||||
/// <summary> |
||||
/// 目录。 |
||||
/// </summary> |
||||
public string Catalog { get; set; } |
||||
/// <summary> |
||||
/// 计数。 |
||||
/// </summary> |
||||
public int Count { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 学习统计查询条件。 |
||||
/// </summary> |
||||
public class StudyStatisticsQueryOptions |
||||
{ |
||||
/// <summary> |
||||
/// 用户帐号(身份证号)。 |
||||
/// </summary> |
||||
[Required] |
||||
public string Name { get; set; } |
||||
/// <summary> |
||||
/// 开始时间。 |
||||
/// </summary> |
||||
public DateTimeOffset? StartTime { get; set; } |
||||
/// <summary> |
||||
/// 结束时间。 |
||||
/// </summary> |
||||
public DateTimeOffset? EndTime { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.AspNetCore.Mvc.ModelBinding; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
/// <summary> |
||||
/// 用户信息。 |
||||
/// </summary> |
||||
public class UserInfo |
||||
{ |
||||
/// <summary> |
||||
/// 用户帐号(身份证号)。 |
||||
/// </summary> |
||||
[Required] |
||||
public string Name { get; set; } |
||||
/// <summary> |
||||
/// 真实姓名。 |
||||
/// </summary> |
||||
[MaxLength(100)] |
||||
public string RealName { get; set; } |
||||
/// <summary> |
||||
/// 角色类型。 |
||||
/// </summary> |
||||
[BindRequired] |
||||
public RoleType RoleType { get; set; } |
||||
/// <summary> |
||||
/// 是否已启用。 |
||||
/// </summary> |
||||
public bool? Enabled { get; set; } |
||||
/// <summary> |
||||
/// 创建时间。 |
||||
/// </summary> |
||||
public DateTimeOffset? CreationTime { get; set; } |
||||
/// <summary> |
||||
/// 职务。 |
||||
/// </summary> |
||||
public List<PostInfo> Posts { get; set; } |
||||
} |
||||
|
||||
/// <summary> |
||||
/// 个人帐号信息。 |
||||
/// </summary> |
||||
public class ProfileInfo : UserInfo |
||||
{ |
||||
/// <summary> |
||||
/// 用户编号。 |
||||
/// </summary> |
||||
public string Id { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.DTOs |
||||
{ |
||||
public class UserQueryOptions : QueryOptions |
||||
{ |
||||
/// <summary> |
||||
/// 用户帐号(身份证号)。 |
||||
/// </summary> |
||||
public string Name { get; set; } |
||||
/// <summary> |
||||
/// 真实姓名。 |
||||
/// </summary> |
||||
public string RealName { get; set; } |
||||
/// <summary> |
||||
/// 角色类型。 |
||||
/// </summary> |
||||
public RoleType? RoleType { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,105 @@
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure; |
||||
using Microsoft.EntityFrameworkCore.Storage; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using AX.FireTrainingSys.Models; |
||||
using static BCrypt.Net.BCrypt; |
||||
using AX.FireTrainingSys.Services; |
||||
|
||||
namespace AX.FireTrainingSys |
||||
{ |
||||
/// <summary> |
||||
/// DbContext 扩展类。 |
||||
/// </summary> |
||||
public static class DbContextExtensions |
||||
{ |
||||
private const string DefaultPassword = "12345678"; |
||||
|
||||
/// <summary> |
||||
/// 向数据库内置一些数据。 |
||||
/// </summary> |
||||
/// <param name="context"></param> |
||||
public static void SeedDatabase(this DriveDbContext context) |
||||
{ |
||||
if (!(context.GetService<IDatabaseCreator>() as RelationalDatabaseCreator).Exists()) |
||||
throw new InvalidOperationException("请先创建数据库!"); |
||||
|
||||
context.SetupAccount(); |
||||
} |
||||
|
||||
private static void SetupAccount(this DriveDbContext dbContext) |
||||
{ |
||||
//内置管理员帐号 |
||||
if (!dbContext.Users.Any()) |
||||
{ |
||||
var admin = new User |
||||
{ |
||||
Name = "admin", |
||||
RealName = "管理员", |
||||
Password = HashPassword(DefaultPassword), |
||||
RoleType = RoleType.Admin, |
||||
}; |
||||
|
||||
dbContext.Users.Add(admin); |
||||
dbContext.SaveChanges(); |
||||
} |
||||
|
||||
//内置职务 |
||||
if (!dbContext.Posts.Any()) |
||||
{ |
||||
var list = new List<Post> |
||||
{ |
||||
//支队级 |
||||
new Post { Id = 1000, Name = "支队级/主官" }, |
||||
new Post { Id = 1001, Name = "支队级/副官" }, |
||||
new Post { Id = 1002, Name = "支队级/灭火救援指挥岗位" }, |
||||
new Post { Id = 1003, Name = "支队级/政工岗位" }, |
||||
new Post { Id = 1004, Name = "支队级/后勤与保障岗位" }, |
||||
new Post { Id = 1005, Name = "支队级/防火监督岗位" }, |
||||
new Post { Id = 1006, Name = "支队级/指挥中心" }, |
||||
new Post { Id = 1007, Name = "支队级/安全员" }, |
||||
//大队级 |
||||
new Post { Id = 2000, Name = "大队级/主官" }, |
||||
new Post { Id = 2001, Name = "大队级/副官" }, |
||||
new Post { Id = 2002, Name = "大队级/灭火救援指挥岗位" }, |
||||
new Post { Id = 2003, Name = "大队级/政工岗位" }, |
||||
new Post { Id = 2004, Name = "大队级/后勤与保障岗位" }, |
||||
new Post { Id = 2005, Name = "大队级/防火监督岗位" }, |
||||
new Post { Id = 2006, Name = "大队级/安全员" }, |
||||
//消防救援站 |
||||
new Post { Id = 3000, Name = "消防救援站/消防站指挥员" }, |
||||
new Post { Id = 3001, Name = "消防救援站/站长助理" }, |
||||
new Post { Id = 3002, Name = "消防救援站/战斗员" }, |
||||
new Post { Id = 3003, Name = "消防救援站/供水员" }, |
||||
new Post { Id = 3004, Name = "消防救援站/训导员" }, |
||||
new Post { Id = 3005, Name = "消防救援站/通信员" }, |
||||
new Post { Id = 3006, Name = "消防救援站/无人机飞手" }, |
||||
new Post { Id = 3007, Name = "消防救援站/消防车驾驶员" }, |
||||
new Post { Id = 3008, Name = "消防救援站/装备技师" }, |
||||
new Post { Id = 3009, Name = "消防救援站/安全员" } |
||||
}; |
||||
|
||||
dbContext.Posts.AddRange(list); |
||||
dbContext.SaveChanges(); |
||||
} |
||||
|
||||
//内置单位类型 |
||||
if (!dbContext.BuildingTypes.Any()) |
||||
{ |
||||
var type0 = new BuildingType() { Id = 1, Name = "高层" }; |
||||
var type1 = new BuildingType() { Id = 2, Name = "大型城市综合体" }; |
||||
var type2 = new BuildingType() { Id = 3, Name = "地下建筑" }; |
||||
var type3 = new BuildingType() { Id = 4, Name = "石油化工" }; |
||||
var type4 = new BuildingType() { Id = 5, Name = "地铁" }; |
||||
var type5 = new BuildingType() { Id = 6, Name = "堆场、仓库、厂房" }; |
||||
var type6 = new BuildingType() { Id = 7, Name = "隧道" }; |
||||
var type7 = new BuildingType() { Id = 8, Name = "人员密集" }; |
||||
|
||||
dbContext.BuildingTypes.AddRange(type0, type1, type2, type3, type4, type5, type6, type7); |
||||
dbContext.SaveChanges(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,321 @@
|
||||
using AX.FireTrainingSys.EntityConfigurations; |
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys |
||||
{ |
||||
/// <summary> |
||||
/// 灭火救援指挥培训系统数据库上下文。 |
||||
/// </summary> |
||||
public class DriveDbContext : DbContext |
||||
{ |
||||
#region 公用部分 |
||||
/// <summary> |
||||
/// 用户。 |
||||
/// </summary> |
||||
public DbSet<User> Users { get; set; } |
||||
/// <summary> |
||||
/// 职务。 |
||||
/// </summary> |
||||
public DbSet<Post> Posts { get; set; } |
||||
/// <summary> |
||||
/// 学习记录。 |
||||
/// </summary> |
||||
public DbSet<StudyRecord> StudyRecords { get; set; } |
||||
#endregion |
||||
|
||||
#region 指挥员战术战法培训子系统 - 模板基本信息 |
||||
/// <summary> |
||||
/// 基本信息。 |
||||
/// </summary> |
||||
public DbSet<TemplateBuildingBasicInfo> TemplateBuildingBasicInfos { get; set; } |
||||
/// <summary> |
||||
/// 建筑特点。 |
||||
/// </summary> |
||||
public DbSet<TemplateBuildingFeature> TemplateBuildingFeatures { get; set; } |
||||
/// <summary> |
||||
/// 毗邻。 |
||||
/// </summary> |
||||
public DbSet<TemplateBuildingAdjoin> TemplateBuildingAdjoins { get; set; } |
||||
/// <summary> |
||||
/// 图片标记。 |
||||
/// </summary> |
||||
public DbSet<TemplateImageMarker> TemplateImageMarkers { get; set; } |
||||
/// <summary> |
||||
/// 禁停区。 |
||||
/// </summary> |
||||
public DbSet<TemplateNoParkingArea> TemplateNoParkingAreas { get; set; } |
||||
/// <summary> |
||||
/// 重点部位/重点提示。 |
||||
/// </summary> |
||||
public DbSet<TemplateImportantLocation> TemplateImportantLocations { get; set; } |
||||
/// <summary> |
||||
/// 消防控制室。 |
||||
/// </summary> |
||||
public DbSet<TemplateFireControlRoom> TemplateFireControlRooms { get; set; } |
||||
/// <summary> |
||||
/// 安全出口。 |
||||
/// </summary> |
||||
public DbSet<TemplateExit> TemplateExits { get; set; } |
||||
/// <summary> |
||||
/// 疏散楼梯。 |
||||
/// </summary> |
||||
public DbSet<TemplateProtectedStairway> TemplateProtectedStairways { get; set; } |
||||
/// <summary> |
||||
/// 消防电梯。 |
||||
/// </summary> |
||||
public DbSet<TemplateFireLift> TemplateFireLifts { get; set; } |
||||
/// <summary> |
||||
/// 泵房/水箱。 |
||||
/// </summary> |
||||
public DbSet<TemplatePumpRoom> TemplatePumpRooms { get; set; } |
||||
/// <summary> |
||||
/// 水泵接合器。 |
||||
/// </summary> |
||||
public DbSet<TemplateSiameseConnection> TemplateSiameseConnections { get; set; } |
||||
/// <summary> |
||||
/// 室外消火栓。 |
||||
/// </summary> |
||||
public DbSet<TemplateOutdoorFireHydrant> TemplateOutdoorFireHydrants { get; set; } |
||||
/// <summary> |
||||
/// 市政消火栓。 |
||||
/// </summary> |
||||
public DbSet<TemplateMunicipalFireHydrant> TemplateMunicipalFireHydrants { get; set; } |
||||
/// <summary> |
||||
/// 周边水源。 |
||||
/// </summary> |
||||
public DbSet<TemplatePeripheralWaterSource> TemplatePeripheralWaterSources { get; set; } |
||||
/// <summary> |
||||
/// 行车路线。 |
||||
/// </summary> |
||||
public DbSet<TemplateDriveRoute> TemplateDriveRoutes { get; set; } |
||||
/// <summary> |
||||
/// 储罐。 |
||||
/// </summary> |
||||
public DbSet<TemplateStorageTank> TemplateStorageTanks { get; set; } |
||||
/// <summary> |
||||
/// 泡沫泵房。 |
||||
/// </summary> |
||||
public DbSet<TemplateFoamPumpRoom> TemplateFoamPumpRooms { get; set; } |
||||
/// <summary> |
||||
/// 水罐。 |
||||
/// </summary> |
||||
public DbSet<TemplateWaterTank> TemplateWaterTanks { get; set; } |
||||
/// <summary> |
||||
/// 消防水炮。 |
||||
/// </summary> |
||||
public DbSet<TemplateFireWaterMonitor> TemplateFireWaterMonitors { get; set; } |
||||
/// <summary> |
||||
/// 泡沫栓。 |
||||
/// </summary> |
||||
public DbSet<TemplateFoamHydrant> TemplateFoamHydrants { get; set; } |
||||
|
||||
/// <summary> |
||||
/// 组织机构。 |
||||
/// </summary> |
||||
public DbSet<TemplateOrganization> TemplateOrganizations { get; set; } |
||||
/// <summary> |
||||
/// 消防力量。 |
||||
/// </summary> |
||||
public DbSet<TemplateFireForce> TemplateFireForces { get; set; } |
||||
#endregion |
||||
|
||||
#region 指挥员战术战法培训子系统 - 基本信息 |
||||
/// <summary> |
||||
/// 基本信息。 |
||||
/// </summary> |
||||
public DbSet<BuildingBasicInfo> BuildingBasicInfos { get; set; } |
||||
/// <summary> |
||||
/// 建筑特点。 |
||||
/// </summary> |
||||
public DbSet<BuildingFeature> BuildingFeatures { get; set; } |
||||
/// <summary> |
||||
/// 毗邻。 |
||||
/// </summary> |
||||
public DbSet<BuildingAdjoin> BuildingAdjoins { get; set; } |
||||
/// <summary> |
||||
/// 图片标记。 |
||||
/// </summary> |
||||
public DbSet<ImageMarker> ImageMarkers { get; set; } |
||||
/// <summary> |
||||
/// 禁停区。 |
||||
/// </summary> |
||||
public DbSet<NoParkingArea> NoParkingAreas { get; set; } |
||||
/// <summary> |
||||
/// 重点部位/重点提示。 |
||||
/// </summary> |
||||
public DbSet<ImportantLocation> ImportantLocations { get; set; } |
||||
/// <summary> |
||||
/// 消防控制室。 |
||||
/// </summary> |
||||
public DbSet<FireControlRoom> FireControlRooms { get; set; } |
||||
/// <summary> |
||||
/// 安全出口。 |
||||
/// </summary> |
||||
public DbSet<Exit> Exits { get; set; } |
||||
/// <summary> |
||||
/// 疏散楼梯。 |
||||
/// </summary> |
||||
public DbSet<ProtectedStairway> ProtectedStairways { get; set; } |
||||
/// <summary> |
||||
/// 消防电梯。 |
||||
/// </summary> |
||||
public DbSet<FireLift> FireLifts { get; set; } |
||||
/// <summary> |
||||
/// 泵房/水箱。 |
||||
/// </summary> |
||||
public DbSet<PumpRoom> PumpRooms { get; set; } |
||||
/// <summary> |
||||
/// 水泵接合器。 |
||||
/// </summary> |
||||
public DbSet<SiameseConnection> SiameseConnections { get; set; } |
||||
/// <summary> |
||||
/// 室外消火栓。 |
||||
/// </summary> |
||||
public DbSet<OutdoorFireHydrant> OutdoorFireHydrants { get; set; } |
||||
/// <summary> |
||||
/// 市政消火栓。 |
||||
/// </summary> |
||||
public DbSet<MunicipalFireHydrant> MunicipalFireHydrants { get; set; } |
||||
/// <summary> |
||||
/// 周边水源。 |
||||
/// </summary> |
||||
public DbSet<PeripheralWaterSource> PeripheralWaterSources { get; set; } |
||||
/// <summary> |
||||
/// 行车路线。 |
||||
/// </summary> |
||||
public DbSet<DriveRoute> DriveRoutes { get; set; } |
||||
/// <summary> |
||||
/// 储罐。 |
||||
/// </summary> |
||||
public DbSet<StorageTank> StorageTanks { get; set; } |
||||
/// <summary> |
||||
/// 泡沫泵房。 |
||||
/// </summary> |
||||
public DbSet<FoamPumpRoom> FoamPumpRooms { get; set; } |
||||
/// <summary> |
||||
/// 水罐。 |
||||
/// </summary> |
||||
public DbSet<WaterTank> WaterTanks { get; set; } |
||||
/// <summary> |
||||
/// 消防水炮。 |
||||
/// </summary> |
||||
public DbSet<FireWaterMonitor> FireWaterMonitors { get; set; } |
||||
/// <summary> |
||||
/// 泡沫栓。 |
||||
/// </summary> |
||||
public DbSet<FoamHydrant> FoamHydrants { get; set; } |
||||
/// <summary> |
||||
/// 组织机构。 |
||||
/// </summary> |
||||
public DbSet<Organization> Organizations { get; set; } |
||||
/// <summary> |
||||
/// 消防力量。 |
||||
/// </summary> |
||||
public DbSet<FireForce> FireForces { get; set; } |
||||
#endregion |
||||
|
||||
#region 指挥员战术战法培训子系统 |
||||
/// <summary> |
||||
/// 单位类型。 |
||||
/// </summary> |
||||
public DbSet<BuildingType> BuildingTypes { get; set; } |
||||
/// <summary> |
||||
/// 课件。 |
||||
/// </summary> |
||||
public DbSet<Courseware> Coursewares { get; set; } |
||||
#endregion |
||||
|
||||
#region 多角色桌面推演 |
||||
/// <summary> |
||||
/// 灾情。 |
||||
/// </summary> |
||||
public DbSet<Disaster> Disasters { get; set; } |
||||
#endregion |
||||
|
||||
/// <summary> |
||||
/// 创建一个数据库上下文实例。 |
||||
/// </summary> |
||||
/// <param name="options"></param> |
||||
public DriveDbContext(DbContextOptions<DriveDbContext> options) |
||||
: base(options) |
||||
{ |
||||
} |
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder) |
||||
{ |
||||
#region 公用部分 |
||||
modelBuilder.ApplyConfiguration(new UserConfig()); |
||||
modelBuilder.ApplyConfiguration(new UserPostConfig()); |
||||
modelBuilder.ApplyConfiguration(new StudyRecordConfig()); |
||||
#endregion |
||||
|
||||
#region 指挥员战术战法培训子系统 - 模板基本信息 |
||||
modelBuilder.ApplyConfiguration(new TemplateBuildingAdjoinConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateImageMarkerConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateNoParkingAreaConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateImportantLocationConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateFireControlRoomConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateExitConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateProtectedStairwayConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateFireLiftConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplatePumpRoomConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateSiameseConnectionConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateOutdoorFireHydrantConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateMunicipalFireHydrantConfig()); |
||||
|
||||
modelBuilder.ApplyConfiguration(new TemplateStorageTankConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateFoamPumpRoomConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateWaterTankConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateFireWaterMonitorConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateFoamHydrantConfig()); |
||||
|
||||
modelBuilder.ApplyConfiguration(new TemplateOrganizationConfig()); |
||||
modelBuilder.ApplyConfiguration(new TemplateFireForceConfig()); |
||||
#endregion |
||||
|
||||
#region 指挥员战术战法培训子系统 - 基本信息 |
||||
modelBuilder.ApplyConfiguration(new BuildingBasicInfoConfig()); |
||||
modelBuilder.ApplyConfiguration(new BuildingFeatureConfig()); |
||||
modelBuilder.ApplyConfiguration(new DriveRouteConfig()); |
||||
modelBuilder.ApplyConfiguration(new PeripheralWaterSourceConfig()); |
||||
|
||||
modelBuilder.ApplyConfiguration(new BuildingAdjoinConfig()); |
||||
modelBuilder.ApplyConfiguration(new ImageMarkerConfig()); |
||||
modelBuilder.ApplyConfiguration(new NoParkingAreaConfig()); |
||||
modelBuilder.ApplyConfiguration(new ImportantLocationConfig()); |
||||
modelBuilder.ApplyConfiguration(new FireControlRoomConfig()); |
||||
modelBuilder.ApplyConfiguration(new ExitConfig()); |
||||
modelBuilder.ApplyConfiguration(new ProtectedStairwayConfig()); |
||||
modelBuilder.ApplyConfiguration(new FireLiftConfig()); |
||||
modelBuilder.ApplyConfiguration(new PumpRoomConfig()); |
||||
modelBuilder.ApplyConfiguration(new SiameseConnectionConfig()); |
||||
modelBuilder.ApplyConfiguration(new OutdoorFireHydrantConfig()); |
||||
modelBuilder.ApplyConfiguration(new MunicipalFireHydrantConfig()); |
||||
|
||||
modelBuilder.ApplyConfiguration(new StorageTankConfig()); |
||||
modelBuilder.ApplyConfiguration(new FoamPumpRoomConfig()); |
||||
modelBuilder.ApplyConfiguration(new WaterTankConfig()); |
||||
modelBuilder.ApplyConfiguration(new FireWaterMonitorConfig()); |
||||
modelBuilder.ApplyConfiguration(new FoamHydrantConfig()); |
||||
|
||||
modelBuilder.ApplyConfiguration(new OrganizationConfig()); |
||||
modelBuilder.ApplyConfiguration(new FireForceConfig()); |
||||
#endregion |
||||
|
||||
#region 指挥员战术战法培训子系统 |
||||
modelBuilder.ApplyConfiguration(new CoursewareConfig()); |
||||
modelBuilder.ApplyConfiguration(new CoursewareBuildingTypeConfig()); |
||||
#endregion |
||||
|
||||
#region 多角色桌面推演 |
||||
modelBuilder.ApplyConfiguration(new DisasterConfig()); |
||||
modelBuilder.ApplyConfiguration(new DisasterBuildingTypeConfig()); |
||||
#endregion |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.EntityConfigurations |
||||
{ |
||||
public class BuildingAdjoinConfig : IEntityTypeConfiguration<BuildingAdjoin> |
||||
{ |
||||
public void Configure(EntityTypeBuilder<BuildingAdjoin> entity) |
||||
{ |
||||
//组合键 |
||||
entity.HasKey(key => new { key.CoursewareId, key.Id }); |
||||
|
||||
entity.Property(e => e.CoursewareId) |
||||
.IsUnicode(false) |
||||
.IsFixedLength(); |
||||
|
||||
entity.Property(e => e.Id) |
||||
.IsUnicode(false); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.EntityConfigurations |
||||
{ |
||||
public class BuildingBasicInfoConfig : IEntityTypeConfiguration<BuildingBasicInfo> |
||||
{ |
||||
public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder<BuildingBasicInfo> entity) |
||||
{ |
||||
entity.Property(e => e.CoursewareId) |
||||
.IsUnicode(false) |
||||
.IsFixedLength(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,20 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.EntityConfigurations |
||||
{ |
||||
public class BuildingFeatureConfig : IEntityTypeConfiguration<BuildingFeature> |
||||
{ |
||||
public void Configure(EntityTypeBuilder<BuildingFeature> entity) |
||||
{ |
||||
entity.Property(e => e.CoursewareId) |
||||
.IsUnicode(false) |
||||
.IsFixedLength(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.EntityConfigurations |
||||
{ |
||||
public class CoursewareBuildingTypeConfig : IEntityTypeConfiguration<CoursewareBuildingType> |
||||
{ |
||||
public void Configure(EntityTypeBuilder<CoursewareBuildingType> entity) |
||||
{ |
||||
// 组合键 |
||||
entity.HasKey(key => new { key.BuildingTypeId, key.CoursewareId }); |
||||
|
||||
// 多对多关系映射 |
||||
entity.HasOne(e => e.Courseware) |
||||
.WithMany(e => e.BuildingTypes) |
||||
.HasForeignKey(e => e.CoursewareId) |
||||
.IsRequired(false); |
||||
|
||||
entity.HasOne(e => e.BuildingType) |
||||
.WithMany(e => e.Coursewares) |
||||
.HasForeignKey(e => e.BuildingTypeId); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.EntityConfigurations |
||||
{ |
||||
public class CoursewareConfig : IEntityTypeConfiguration<Courseware> |
||||
{ |
||||
public void Configure(EntityTypeBuilder<Courseware> entity) |
||||
{ |
||||
entity.Property(e => e.Id) |
||||
.IsUnicode(false) |
||||
.IsFixedLength() |
||||
.HasValueGenerator<ObjectIdGenerator>(); |
||||
|
||||
entity.Property(e => e.ImageUrl) |
||||
.IsUnicode(false); |
||||
|
||||
entity.Property(e => e.QuestionUrl) |
||||
.IsUnicode(false); |
||||
|
||||
entity.Property(e => e.StandardAnswerUrl) |
||||
.IsUnicode(false); |
||||
|
||||
entity.Property(e => e.ModifiedTime) |
||||
.HasConversion(ConverterHelper.DateTimeToStringConverter()); |
||||
|
||||
entity.HasIndex(e => e.ModifiedTime); |
||||
entity.HasIndex(e => e.Name); |
||||
entity.HasIndex(e => e.CompanyName); |
||||
|
||||
entity.HasQueryFilter(e => !e.Deleted); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.EntityConfigurations |
||||
{ |
||||
public class DisasterBuildingTypeConfig : IEntityTypeConfiguration<DisasterBuildingType> |
||||
{ |
||||
public void Configure(EntityTypeBuilder<DisasterBuildingType> entity) |
||||
{ |
||||
// 组合键 |
||||
entity.HasKey(key => new { key.BuildingTypeId, key.DisasterId }); |
||||
|
||||
// 多对多关系映射 |
||||
entity.HasOne(e => e.Disaster) |
||||
.WithMany(e => e.BuildingTypes) |
||||
.HasForeignKey(e => e.DisasterId) |
||||
.IsRequired(false); |
||||
|
||||
entity.HasOne(e => e.BuildingType) |
||||
.WithMany(e => e.Disasters) |
||||
.HasForeignKey(e => e.BuildingTypeId); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,31 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.EntityConfigurations |
||||
{ |
||||
public class DisasterConfig : IEntityTypeConfiguration<Disaster> |
||||
{ |
||||
public void Configure(EntityTypeBuilder<Disaster> entity) |
||||
{ |
||||
entity.Property(e => e.Id) |
||||
.IsUnicode(false) |
||||
.IsFixedLength() |
||||
.HasValueGenerator<ObjectIdGenerator>(); |
||||
|
||||
entity.Property(e => e.CreationTime) |
||||
.HasConversion(ConverterHelper.DateTimeToStringConverter()); |
||||
|
||||
entity.HasIndex(e => e.CreationTime); |
||||
entity.HasIndex(e => e.Name); |
||||
entity.HasIndex(e => e.CompanyName); |
||||
entity.HasIndex(e => e.State); |
||||
|
||||
entity.HasQueryFilter(e => !e.Deleted); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,20 @@
|
||||
using AX.FireTrainingSys.Models; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace AX.FireTrainingSys.EntityConfigurations |
||||
{ |
||||
public class DriveRouteConfig : IEntityTypeConfiguration<DriveRoute> |
||||
{ |
||||
public void Configure(EntityTypeBuilder<DriveRoute> entity) |
||||
{ |
||||
entity.Property(e => e.CoursewareId) |
||||
.IsUnicode(false) |
||||
.IsFixedLength(); |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue