|
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Logging;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Threading.Tasks;
- using HealthMonitor.Core.Aop;
- using HealthMonitor.Core.Cache;
- using HealthMonitor.Core.Dal;
- using HealthMonitor.Core.Dal.Factory;
- using HealthMonitor.Core.Operator;
- using HealthMonitor.Core.Query;
- using HealthMonitor.Core.Query.Extensions;
- using HealthMonitor.Util.Common;
- using HealthMonitor.Util.Common.Operator;
- using HealthMonitor.Util.Entities.Base;
- using HealthMonitor.Util.Models;
- using HealthMonitor.Util.QueryObjects;
- using HealthMonitor.WebApi.Filters;
-
- namespace HealthMonitor.WebApi.Controllers.Base
- {
- [Produces("application/json")]
- [Route("api/HealthMonitor/[controller]/[action]")]
- [ApiController]
- public abstract class HealthMonitorControllerBase<T> : DefaultControllerBase<T> where T : HealthMonitorEntityBase
- {
-
-
-
- protected readonly IHealthMonitorDataAccessor _dataAccessor;
- protected readonly IHealthMonitorOperatorManager _operatorManager;
- protected readonly IDurableEntityManager _durableManager;
- protected readonly ILogger _logger;
-
- protected HealthMonitorControllerBase(
- IHealthMonitorDataAccessor dataAccessor,
- //IGpsCardDataAccessor gpsCardDataAccessor,
- IHealthMonitorOperatorManager operatorGpsCardManager,
- IDurableEntityManager durableManager,
- ILogger logger)
- {
- _dataAccessor = dataAccessor;
- _operatorManager = operatorGpsCardManager;
- _durableManager = durableManager;
- _logger = logger;
- }
-
-
-
-
-
-
-
- [HttpGet]
-
- public async virtual Task<T> GetById([Required] string id, [FromHeader] string requestId)
- {
- AssertModelStateIsValid();
-
-
- return await _dataAccessor.GetByIDAsync<T>(id);
- }
-
-
-
-
-
-
-
- [HttpPost]
-
-
- public async virtual Task<T?> GetFirst([FromBody] GeneralParam conditions, [FromHeader] string requestId)
- {
- AssertModelStateIsValid();
-
- var parser = new QueryExpressionParser<T>();
- var expression = parser.ParserConditions(conditions.Filters!);
- var list = await _dataAccessor.GetMany(expression).OrderConditions(conditions.OrderBys!).Take(1).ToListAsync();
-
- return list.Count > 0 ? list[0] : null;
- }
-
-
-
-
-
-
-
- [HttpPost]
-
-
- public async virtual Task<PageData<T>> GetPageList([FromBody] Paging page, [FromHeader] string requestId)
- {
- AssertModelStateIsValid();
-
-
- var all = _dataAccessor.GetAll<T>();
- var list = await all.Skip((page.CurPage - 1) * page.PageSize).Take(page.PageSize).ToListAsync();
- int totals = await all.CountAsync();
- return new PageData<T> { Totals= totals, Rows =list};
- }
-
- [HttpPost]
-
- public async virtual Task<IEnumerable<T>> GetList([FromBody] GeneralParam conditions, [FromHeader] string requestId)
- {
- AssertModelStateIsValid();
- var parser = new QueryExpressionParser<T>();
- var expression = parser.ParserConditions(conditions.Filters!);
- var list = await _dataAccessor.GetMany(expression).OrderConditions(conditions.OrderBys!).Take(100).ToListAsync();
- return list;
-
-
- }
-
- [HttpPost]
- public async virtual Task<IEnumerable<T>> GetPages([FromBody] GeneralParam conditions, [FromHeader] string requestId)
- {
- AssertModelStateIsValid();
-
-
-
-
-
-
- var pageSize = 1;
- var pageIdx = 1;
-
- var list = await _dataAccessor.GetAll<T>().OrderConditions(conditions.OrderBys!).Skip(pageSize * (pageIdx - 1)).Take(pageSize).ToListAsync();
- return list;
- }
-
-
-
-
-
-
-
- [HttpPost]
-
- public virtual void Add([FromBody] T model, [FromHeader] string requestId)
- {
- AssertModelStateIsValid(model);
-
- _dataAccessor.Add(model);
- _dataAccessor.Save();
- }
-
-
-
-
-
-
- [HttpPut]
-
- public virtual void Update([FromBody] T model, [FromHeader] string requestId)
- {
- AssertModelStateIsValid(model);
-
- _dataAccessor.Update(model);
- _dataAccessor.Save();
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
- [HttpDelete]
-
-
- public virtual void Delete([FromBody] T model, [FromHeader] string requestId)
- {
-
-
-
-
-
- _dataAccessor.Delete(model);
- _dataAccessor.Save();
-
-
-
-
-
-
-
-
-
- }
- }
- }
|