|
|
|
|
|
using ATS.NonCustodial.Application.Base;
|
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.View;
|
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.View.Input;
|
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.View.Output;
|
|
|
|
|
|
using ATS.NonCustodial.Domain.Entities.Admins;
|
|
|
|
|
|
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore;
|
|
|
|
|
|
using ATS.NonCustodial.DynamicApi;
|
|
|
|
|
|
using ATS.NonCustodial.DynamicApi.Attributes;
|
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.Enums;
|
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.UnifiedResults;
|
|
|
|
|
|
using ATS.NonCustodial.Shared.Extensions;
|
|
|
|
|
|
using AutoMapper.QueryableExtensions;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ATS.NonCustodial.Application.Impl.Admins
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// Author:mxg
|
|
|
|
|
|
/// CreatedTimed:2022-05-15 10:08 PM
|
|
|
|
|
|
[DynamicApi(Area = "admin")]
|
|
|
|
|
|
public class ViewService : AdminAppServiceBase, IViewService, IDynamicApi
|
|
|
|
|
|
{
|
|
|
|
|
|
#region Identity
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IEfRepository<AppView?, long> _viewRepository;
|
|
|
|
|
|
|
|
|
|
|
|
public ViewService(IEfRepository<AppView?, long> moduleRepository)
|
|
|
|
|
|
{
|
|
|
|
|
|
_viewRepository = moduleRepository;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion Identity
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>ͼ
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<IResultOutput> GetAsync(long id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rtn = await base.GetAsync<AppView, ViewGetOutput, long>(_viewRepository, id);
|
|
|
|
|
|
return ResultOutput.Ok(rtn);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <EFBFBD><EFBFBD>ѯ<EFBFBD>б<EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<IResultOutput> GetListAsync(string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
var data = await _viewRepository.AsQueryable(false, true)
|
|
|
|
|
|
.WhereIf(key.NotNull(), a => a.Path.Contains(key) || a.Label.Contains(key))
|
|
|
|
|
|
.ProjectTo<ViewListOutput>(Mapper.ConfigurationProvider)
|
|
|
|
|
|
.OrderByDescending(r => r.CreatedTime)
|
|
|
|
|
|
.ToListAsync()
|
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Ok(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<IResultOutput> AddAsync(ViewAddInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var entity = Mapper.Map<AppView>(input);
|
|
|
|
|
|
await _viewRepository.InsertAsync(entity);
|
|
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Result(entity.Id > 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <EFBFBD><EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<IResultOutput> UpdateAsync(ViewUpdateInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!(input?.Id > 0)) return ResultOutput.NotOk();
|
|
|
|
|
|
|
|
|
|
|
|
var entity = await _viewRepository.FindAsync(input.Id);
|
|
|
|
|
|
if (!(entity?.Id > 0)) return ResultOutput.NotOk("<EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>");
|
|
|
|
|
|
|
|
|
|
|
|
Mapper.Map(input, entity);
|
|
|
|
|
|
await _viewRepository.UpdateAsync(entity);
|
|
|
|
|
|
return ResultOutput.Ok();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<IResultOutput> DeleteAsync(long id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = false;
|
|
|
|
|
|
if (id > 0) result = (await _viewRepository.DeleteAsync(m => m.Id == id)) > 0;
|
|
|
|
|
|
return ResultOutput.Result(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ɾ<EFBFBD><EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<IResultOutput> SoftDeleteAsync(long id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = await _viewRepository.DeleteAsync(w => w.Id == id);
|
|
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Result(result > 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IResultOutput> BatchSoftDeleteAsync(long[] ids)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = await _viewRepository.DeleteAsync(w => ids.Contains(w.Id));
|
|
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Result(result > 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ͬ<EFBFBD><EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<IResultOutput> SyncAsync(ViewSyncInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
//<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ
|
|
|
|
|
|
var views = await _viewRepository.AsQueryable(false, true).ToListAsync();
|
|
|
|
|
|
var names = views.Select(a => a.Name).ToList();
|
|
|
|
|
|
var paths = views.Select(a => a.Path).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
//path<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
foreach (var view in input.Views)
|
|
|
|
|
|
{
|
|
|
|
|
|
view.Path = view.Path?.Trim();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
{
|
|
|
|
|
|
var inputViews = (from a in input.Views where !(paths.Contains(a.Path) || names.Contains(a.Name)) select a).ToList();
|
|
|
|
|
|
if (inputViews.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var insertViews = Mapper.Map<List<AppView>>(inputViews);
|
|
|
|
|
|
foreach (var insertView in insertViews)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (insertView.Label.IsNull())
|
|
|
|
|
|
{
|
|
|
|
|
|
insertView.Label = insertView.Name;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
insertViews = await _viewRepository.InsertAsync(insertViews);
|
|
|
|
|
|
views.AddRange(insertViews);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
{
|
|
|
|
|
|
var inputPaths = input.Views.Select(a => a.Path).ToList();
|
|
|
|
|
|
var inputNames = input.Views.Select(a => a.Name).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
//<EFBFBD><EFBFBD>
|
|
|
|
|
|
var updateViews = (from a in views where inputPaths.Contains(a.Path) || inputNames.Contains(a.Name) select a).ToList();
|
|
|
|
|
|
if (updateViews.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var view in updateViews)
|
|
|
|
|
|
{
|
|
|
|
|
|
var inputView = input.Views.Where(a => a.Name == view.Name || a.Path == view.Path).FirstOrDefault();
|
|
|
|
|
|
if (view.Label.IsNull())
|
|
|
|
|
|
{
|
|
|
|
|
|
view.Label = inputView.Label ?? inputView.Name;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (view.Description.IsNull())
|
|
|
|
|
|
{
|
|
|
|
|
|
view.Description = inputView.Description;
|
|
|
|
|
|
}
|
|
|
|
|
|
view.Name = inputView.Name;
|
|
|
|
|
|
view.Path = inputView.Path;
|
|
|
|
|
|
view.DataStatus = DataStatusEnum.Normal;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
var disabledViews = (from a in views where (a.Path.NotNull() || a.Name.NotNull()) && (!inputPaths.Contains(a.Path) || !inputNames.Contains(a.Name)) select a).ToList();
|
|
|
|
|
|
if (disabledViews.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var view in disabledViews)
|
|
|
|
|
|
{
|
|
|
|
|
|
view.DataStatus = DataStatusEnum.Disable;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateViews.AddRange(disabledViews);
|
|
|
|
|
|
|
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
await _viewRepository.UpdateAsync(
|
|
|
|
|
|
updateViews,
|
|
|
|
|
|
UpdatingProps<AppView>(x => x.Label, x => x.Path, x => x.Name, x => x.Description, x => x.DataStatus)
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Ok();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|