You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
386 lines
17 KiB
386 lines
17 KiB
using AutoMapper.Internal.Mappers;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.Application.Services;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.Identity;
|
|
using Volo.Abp;
|
|
using Shentun.Peis.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using NPOI.SS.UserModel;
|
|
using System.Reflection;
|
|
using NUglify.JavaScript.Syntax;
|
|
using System.Collections;
|
|
using System.Linq.Dynamic.Core;
|
|
using SqlSugar;
|
|
using Volo.Abp.Application.Dtos;
|
|
using Volo.Abp.Users;
|
|
using Volo.Abp.ObjectMapping;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.IO;
|
|
using Shentun.Peis.HelperDto;
|
|
using Shentun.Peis.PlugIns;
|
|
using Volo.Abp.Threading;
|
|
|
|
namespace Shentun.Peis.ColumnReferences
|
|
{
|
|
/// <summary>
|
|
/// 字段对照主表
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "Work")]
|
|
[Authorize]
|
|
public class ColumnReferenceAppService : ApplicationService
|
|
{
|
|
private readonly IRepository<ColumnReference, Guid> _repository;
|
|
private readonly IRepository<ColumnReferenceCode, Guid> _columnReferenceCodeRepository;
|
|
private readonly IRepository<ColumnReferenceInterface, Guid> _columnReferenceInterfaceRepository;
|
|
private readonly ColumnReferenceManager _manager;
|
|
private readonly CacheService _cacheService;
|
|
private readonly IRepository<IdentityUser, Guid> _userRepository;
|
|
|
|
public ColumnReferenceAppService(
|
|
IRepository<ColumnReference, Guid> repository,
|
|
ColumnReferenceManager manager,
|
|
CacheService cacheService,
|
|
IRepository<IdentityUser, Guid> userRepository,
|
|
IRepository<ColumnReferenceCode, Guid> columnReferenceCodeRepository,
|
|
IRepository<ColumnReferenceInterface, Guid> columnReferenceInterfaceRepository
|
|
)
|
|
{
|
|
_repository = repository;
|
|
_manager = manager;
|
|
_cacheService = cacheService;
|
|
_userRepository = userRepository;
|
|
_columnReferenceCodeRepository = columnReferenceCodeRepository;
|
|
_columnReferenceInterfaceRepository = columnReferenceInterfaceRepository;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据ID查实体内容
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/Get")]
|
|
public async Task<ColumnReferenceDto> GetAsync(Guid id)
|
|
{
|
|
var entity = await _repository.GetAsync(id);
|
|
var entityDto = ObjectMapper.Map<ColumnReference, ColumnReferenceDto>(entity);
|
|
entityDto.CreatorName = _cacheService.GetUserNameAsync(entityDto.CreatorId).Result;
|
|
entityDto.LastModifierName = _cacheService.GetUserNameAsync(entityDto.LastModifierId).Result;
|
|
|
|
return entityDto;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 查询列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/GetList")]
|
|
public async Task<List<ColumnReferenceDto>> GetListAsync()
|
|
{
|
|
var userQueryable = await _userRepository.GetQueryableAsync();
|
|
|
|
var entlist = (from a in await _repository.GetQueryableAsync()
|
|
join b in userQueryable on a.CreatorId equals b.Id into bb
|
|
from ab in bb.DefaultIfEmpty()
|
|
join c in userQueryable on a.LastModifierId equals c.Id into cc
|
|
from ac in cc.DefaultIfEmpty()
|
|
select new
|
|
{
|
|
a,
|
|
CreatorName = ab != null ? ab.UserName : "",
|
|
LastModifierName = ac != null ? ac.UserName : ""
|
|
|
|
})
|
|
.Select(s => new ColumnReferenceDto
|
|
{
|
|
CreationTime = s.a.CreationTime,
|
|
CreatorId = s.a.CreatorId,
|
|
LastModifierId = s.a.LastModifierId,
|
|
Id = s.a.Id,
|
|
DisplayOrder = s.a.DisplayOrder,
|
|
DisplayName = s.a.DisplayName,
|
|
ParmValue = s.a.ParmValue,
|
|
LastModificationTime = s.a.LastModificationTime,
|
|
CreatorName = s.CreatorName,
|
|
LastModifierName = s.LastModifierName
|
|
}).OrderBy(o => o.DisplayOrder).ToList();
|
|
|
|
return entlist;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/Create")]
|
|
public async Task<ColumnReferenceDto> CreateAsync(CreateColumnReferenceDto input)
|
|
{
|
|
var createEntity = ObjectMapper.Map<CreateColumnReferenceDto, ColumnReference>(input);
|
|
var entity = await _manager.CreateAsync(createEntity);
|
|
entity = await _repository.InsertAsync(entity);
|
|
var dto = ObjectMapper.Map<ColumnReference, ColumnReferenceDto>(entity);
|
|
return dto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/Update")]
|
|
public async Task<ColumnReferenceDto> UpdateAsync(UpdateColumnReferenceDto input)
|
|
{
|
|
var entity = await _repository.GetAsync(input.Id);
|
|
var sourceEntity = ObjectMapper.Map<UpdateColumnReferenceDto, ColumnReference>(input);
|
|
await _manager.UpdateAsync(sourceEntity, entity);
|
|
entity = await _repository.UpdateAsync(entity);
|
|
return ObjectMapper.Map<ColumnReference, ColumnReferenceDto>(entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/Delete")]
|
|
public async Task DeleteAsync(Guid id)
|
|
{
|
|
var entity = await _repository.GetAsync(id);
|
|
await _manager.CheckAndDeleteAsync(entity);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 修改排序 置顶,置底
|
|
/// </summary>
|
|
/// <param name="id">需要修改的ID</param>
|
|
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/UpdateManySort")]
|
|
public async Task UpdateManySortAsync(Guid id, int SortType)
|
|
{
|
|
await _manager.UpdateManySortAsync(id, SortType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改排序 拖拽
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/UpdateSortMany")]
|
|
public async Task UpdateSortManyAsync(UpdateSortManyDto input)
|
|
{
|
|
await _manager.UpdateSortManyAsync(input);
|
|
}
|
|
/// <summary>
|
|
///获取字段对照本系统所有列名
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/GetAppColumnNames")]
|
|
public async Task<List<string>> GetAppColumnNamesAsync(ColumnReferenceIdInputDto input)
|
|
{
|
|
var entity = await _repository.GetAsync(input.Id);
|
|
var parmValue = entity.ParmValue;
|
|
var configurationBuilder = new ConfigurationBuilder()
|
|
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
|
|
var config = configurationBuilder.Build();
|
|
var assemblyName = config.GetSection("Interface").GetSection("AssemblyName").Value;
|
|
var className = config.GetSection("Interface").GetSection("ClassName").Value;
|
|
object objectValue = await InvokeAsync(assemblyName, className, parmValue, "GetAppColumnNames");
|
|
List<string> list = new List<string>();
|
|
|
|
if (objectValue is IEnumerable enumerableObject)
|
|
{
|
|
list = enumerableObject.Cast<string>().ToList();
|
|
}
|
|
return list;
|
|
}
|
|
public async Task<string> GetAppFilterColumnName(ColumnReferenceIdInputDto input)
|
|
{
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
///获取字段对照第三方系统所有列名
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/GetInterfaceColumnNames")]
|
|
public async Task<List<string>> GetInterfaceColumnNamesAsync(ColumnReferenceIdInputDto input)
|
|
{
|
|
var entity = await _repository.GetAsync(input.Id);
|
|
var parmValue = entity.ParmValue;
|
|
var configurationBuilder = new ConfigurationBuilder()
|
|
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
|
|
var config = configurationBuilder.Build();
|
|
var assemblyName = config.GetSection("Interface").GetSection("AssemblyName").Value;
|
|
var className = config.GetSection("Interface").GetSection("ClassName").Value;
|
|
object objectValue = await InvokeAsync(assemblyName, className, parmValue, "GetInterfaceColumnNames");
|
|
List<string> list = new List<string>();
|
|
|
|
if (objectValue is IEnumerable enumerableObject)
|
|
{
|
|
list = enumerableObject.Cast<string>().ToList();
|
|
}
|
|
return list;
|
|
}
|
|
/// <summary>
|
|
///获取字段对照本系统所有数据
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/GetAppCodeValues")]
|
|
public async Task<List<ColumnReferenceCodeValue>> GetAppCodeValuesAsync(ColumnReferenceIdInputDto input)
|
|
{
|
|
//var columnReferenceCodes = await _columnReferenceCodeRepository.GetListAsync(o => o.CodeValue == input.Id.ToString());
|
|
|
|
var entity = await _repository.GetAsync(input.Id);
|
|
var parmValue = entity.ParmValue;
|
|
var configurationBuilder = new ConfigurationBuilder()
|
|
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
|
|
var config = configurationBuilder.Build();
|
|
var assemblyName = config.GetSection("Interface").GetSection("AssemblyName").Value;
|
|
var className = config.GetSection("Interface").GetSection("ClassName").Value;
|
|
var list = await InvokeListAsync(assemblyName, className, parmValue, "GetAppCodeValuesAsync");
|
|
|
|
return list;
|
|
}
|
|
|
|
public async Task<List<ColumnReferenceFilterCodeValue>> GetAppFilterCodeValues(ColumnReferenceIdInputDto input)
|
|
{
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
///获取字段对照第三方系统所有数据
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/GetInterfaceCodeValues")]
|
|
public async Task<List<ColumnReferenceCodeValue>> GetInterfaceCodeValuesAsync(ColumnReferenceIdInputDto input)
|
|
{
|
|
var entity = await _repository.GetAsync(input.Id);
|
|
var parmValue = entity.ParmValue;
|
|
var configurationBuilder = new ConfigurationBuilder()
|
|
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
|
|
var config = configurationBuilder.Build();
|
|
var assemblyName = config.GetSection("Interface").GetSection("AssemblyName").Value;
|
|
var className = config.GetSection("Interface").GetSection("ClassName").Value;
|
|
var list = await InvokeListAsync(assemblyName, className, parmValue, "GetInterfaceCodeValuesAsync");
|
|
|
|
|
|
|
|
return list;
|
|
}
|
|
/// <summary>
|
|
/// 通过本系统编码获取第三方系统编码
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/ColumnReference/GetInterfaceCodeValuesByAppCode")]
|
|
public async Task<List<ColumnReferenceInterfaceCodeValueDto>> GetInterfaceCodeValuesByAppCode(ColumnReferenceInterfaceCodeValuesInputDto input)
|
|
{
|
|
var columnReferenceCode = await _columnReferenceCodeRepository.FirstOrDefaultAsync(o => o.CodeValue == input.Code);
|
|
if(columnReferenceCode == null)
|
|
{
|
|
return null;
|
|
}
|
|
var items = await _columnReferenceInterfaceRepository.GetListAsync(o => o.ColumnReferenceCodeId == columnReferenceCode.Id);
|
|
|
|
var entity = await _repository.GetAsync(input.ColumnReferenceId);
|
|
var parmValue = entity.ParmValue;
|
|
var configurationBuilder = new ConfigurationBuilder()
|
|
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
|
|
var config = configurationBuilder.Build();
|
|
var assemblyName = config.GetSection("Interface").GetSection("AssemblyName").Value;
|
|
var className = config.GetSection("Interface").GetSection("ClassName").Value;
|
|
var list = await InvokeListAsync(assemblyName, className, parmValue, "GetInterfaceCodeValuesAsync");
|
|
var result = new List<ColumnReferenceInterfaceCodeValueDto>();
|
|
foreach ( var item in items)
|
|
{
|
|
var columnReferenceInterfaceCodeValueDto = new ColumnReferenceInterfaceCodeValueDto()
|
|
{
|
|
CodeValue = item.InterfaceCodeValue,
|
|
};
|
|
var interfaceItem = list.Where(o => o.Code == item.InterfaceCodeValue).FirstOrDefault();
|
|
if(interfaceItem != null)
|
|
{
|
|
columnReferenceInterfaceCodeValueDto.DisplayName = interfaceItem.DisplayName;
|
|
}
|
|
result.Add(columnReferenceInterfaceCodeValueDto);
|
|
}
|
|
return result;
|
|
}
|
|
public async Task<List<ColumnReferenceCodeValue>> GetColumnReferenceInterfaceCodeValues(ColumnReferenceIdInputDto input)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public async Task CreateColumnReferenceValue(CreateColumnReferenceValue input)
|
|
{
|
|
|
|
}
|
|
|
|
private async Task<object> InvokeAsync(string assemblyName, string className,string classConstructorArg, string methodName, object[] args = null)
|
|
{
|
|
Assembly assembly = Assembly.Load(assemblyName);
|
|
Type type = assembly.GetType(className);
|
|
// 创建类的实例
|
|
object instance = Activator.CreateInstance(type, classConstructorArg);
|
|
// 获取方法信息
|
|
MethodInfo method = type.GetMethod(methodName);
|
|
// 调用方法,如果方法需要参数,可以传入对应的参数数组,例如: new object[] { arg1, arg2 }
|
|
object returnValue;
|
|
var isAsync = (method.ReturnType == typeof(Task) ||
|
|
(method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>)));
|
|
if (isAsync)
|
|
{
|
|
// 使用反射调用方法
|
|
|
|
//object returnValue = method.Invoke(instance, args);
|
|
returnValue = await(Task<object>)method.Invoke(instance, args);
|
|
}
|
|
else
|
|
{
|
|
returnValue = method.Invoke(instance, args);
|
|
|
|
}
|
|
return returnValue;
|
|
}
|
|
private async Task<List<ColumnReferenceCodeValue>> InvokeListAsync(string assemblyName, string className, string classConstructorArg, string methodName, object[] args = null)
|
|
{
|
|
Assembly assembly = Assembly.Load(assemblyName);
|
|
Type type = assembly.GetType(className);
|
|
// 创建类的实例
|
|
object instance = Activator.CreateInstance(type, classConstructorArg);
|
|
// 获取方法信息
|
|
MethodInfo method = type.GetMethod(methodName);
|
|
// 调用方法,如果方法需要参数,可以传入对应的参数数组,例如: new object[] { arg1, arg2 }
|
|
List<ColumnReferenceCodeValue> returnValue;
|
|
var isAsync = (method.ReturnType == typeof(Task) ||
|
|
(method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>)));
|
|
if (isAsync)
|
|
{
|
|
// 使用反射调用方法
|
|
|
|
//object returnValue = method.Invoke(instance, args);
|
|
returnValue = await (Task<List<ColumnReferenceCodeValue>>)method.Invoke(instance, args);
|
|
}
|
|
else
|
|
{
|
|
returnValue = (List<ColumnReferenceCodeValue>)method.Invoke(instance, args);
|
|
|
|
}
|
|
return returnValue;
|
|
}
|
|
|
|
}
|
|
}
|