|
@ -1,10 +1,13 @@ |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
|
|
|
using System.Linq.Dynamic.Core; |
|
|
using System.Text; |
|
|
using System.Text; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
using Volo.Abp.Application.Services; |
|
|
using Volo.Abp.Application.Services; |
|
|
using Volo.Abp.Domain.Repositories; |
|
|
using Volo.Abp.Domain.Repositories; |
|
|
using Volo.Abp.Uow; |
|
|
using Volo.Abp.Uow; |
|
@ -17,9 +20,11 @@ namespace WY.NewJit.MsgBaseData |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
[Route("api/newjit/baseconfig")] |
|
|
[Route("api/newjit/baseconfig")] |
|
|
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.基础数据)] |
|
|
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.基础数据)] |
|
|
public class BaseGonfigService : ApplicationService |
|
|
public class BaseGonfigService : ApplicationService, IBaseGonfigService |
|
|
{ |
|
|
{ |
|
|
private readonly IRepository<BaseConfig, Guid> _repository; |
|
|
public readonly IRepository<BaseConfig, Guid> _repository; |
|
|
|
|
|
|
|
|
|
|
|
private readonly BaseGonfigDomainService _baseConfigDomainService; |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 日志
|
|
|
/// 日志
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
@ -41,11 +46,13 @@ namespace WY.NewJit.MsgBaseData |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public BaseGonfigService( |
|
|
public BaseGonfigService( |
|
|
IRepository<BaseConfig, Guid> repository, |
|
|
IRepository<BaseConfig, Guid> repository, |
|
|
ILogger<BaseGonfigService> logger |
|
|
ILogger<BaseGonfigService> logger, |
|
|
|
|
|
BaseGonfigDomainService baseConfigDomainService |
|
|
) |
|
|
) |
|
|
{ |
|
|
{ |
|
|
_repository = repository; |
|
|
_repository = repository; |
|
|
_logger = logger; |
|
|
_logger = logger; |
|
|
|
|
|
_baseConfigDomainService = baseConfigDomainService; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -57,25 +64,171 @@ namespace WY.NewJit.MsgBaseData |
|
|
[HttpGet] |
|
|
[HttpGet] |
|
|
[UnitOfWork(false)] |
|
|
[UnitOfWork(false)] |
|
|
[Route("list")] |
|
|
[Route("list")] |
|
|
public virtual async Task<ListResultDto<BaseConfigDto>> GetBaseConfigListAsync() |
|
|
public virtual async Task<PagedResultDto<BaseConfigDto>> GetListAsync(QueryBaseConfigDto input) |
|
|
{ |
|
|
{ |
|
|
_logger.LogDebug(_errorMessagePrefix + "GetBaseConfigListAsync 进入"); |
|
|
_logger.LogDebug(_errorMessagePrefix + "GetListAsync 进入"); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
var lst = await _repository.GetListAsync(); |
|
|
var page = (PagedAndSortedBase)input; |
|
|
|
|
|
IQueryable<BaseConfig> qry1 = QueryByCondition(input); |
|
|
|
|
|
if (string.IsNullOrEmpty(page.Sorting)) |
|
|
|
|
|
{ |
|
|
|
|
|
page.Sorting = "ParamName"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int totalCount = await qry1.CountAsync(); //返回总记录数而不是当前页记录数
|
|
|
|
|
|
if (totalCount == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return new PagedResultDto<BaseConfigDto>(0, new List<BaseConfigDto>()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var query = qry1.OrderBy(page.Sorting).Skip(page.SkipCount).Take(page.MaxResultCount); |
|
|
|
|
|
|
|
|
|
|
|
List<BaseConfig> lst = await query.ToListAsync(); |
|
|
|
|
|
|
|
|
var items = ObjectMapper.Map<List<BaseConfig>, List<BaseConfigDto>>(lst); |
|
|
var items = ObjectMapper.Map<List<BaseConfig>, List<BaseConfigDto>>(lst); |
|
|
|
|
|
|
|
|
return new ListResultDto<BaseConfigDto>(items); |
|
|
return new PagedResultDto<BaseConfigDto>(totalCount, items); |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
string errMsg = _errorMessagePrefix + "GetBaseConfigListAsync 执行出错:" + ex.Message; |
|
|
string errMsg = _errorMessagePrefix + "GetListAsync 执行出错:" + ex.Message; |
|
|
_logger.LogError(errMsg); |
|
|
_logger.LogError(errMsg); |
|
|
return new ListResultDto<BaseConfigDto>(new List<BaseConfigDto>()); |
|
|
return new PagedResultDto<BaseConfigDto>(0, new List<BaseConfigDto>()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加实体
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input">添加内容</param>
|
|
|
|
|
|
/// <returns>执行成功返回真</returns>
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
[UnitOfWork] |
|
|
|
|
|
[Route("create")] |
|
|
|
|
|
public async Task<ObjectResultDto<Guid>> CreateAsync(BaseConfigCreateDto input) |
|
|
|
|
|
{ |
|
|
|
|
|
_logger.LogDebug(_errorMessagePrefix + "CreateAsync 进入"); |
|
|
|
|
|
ObjectResultDto<Guid> ret = new ObjectResultDto<Guid>(); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
var checkitem = await _repository.FirstOrDefaultAsync(r => r.ParamName == input.ParamName); |
|
|
|
|
|
|
|
|
|
|
|
if (checkitem != null) |
|
|
|
|
|
{ |
|
|
|
|
|
ret.Status = false; |
|
|
|
|
|
ret.Message = $"参数名称【{input.ParamName}】已存,在无法添加!"; |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
BaseConfig obj = ObjectMapper.Map<BaseConfigCreateDto, BaseConfig>(input); |
|
|
|
|
|
var obj2 = await _repository.InsertAsync(obj); |
|
|
|
|
|
ret.Item = obj2.Id; //返回添加对象的主键
|
|
|
|
|
|
await _baseConfigDomainService.UpdateBaseConfigCache(); |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
ret.Status = false; |
|
|
|
|
|
ret.Message = _errorMessagePrefix + "CreateAsync 执行出错:" + ex.Message; |
|
|
|
|
|
_logger.LogError(ret.Message); |
|
|
|
|
|
return ret; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改实体
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">更新主键</param>
|
|
|
|
|
|
/// <param name="input">修改内容</param>
|
|
|
|
|
|
/// <returns>执行成功返回真</returns>
|
|
|
|
|
|
[HttpPut] |
|
|
|
|
|
[UnitOfWork] |
|
|
|
|
|
[Route("update/{id}")] |
|
|
|
|
|
public async Task<ObjectResultDto> UpdateAsync(Guid id, BaseConfigCreateDto input) |
|
|
|
|
|
{ |
|
|
|
|
|
_logger.LogDebug(_errorMessagePrefix + "UpdateAsync 进入"); |
|
|
|
|
|
ObjectResultDto ret = new ObjectResultDto(); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
var checkitem = await _repository.FirstOrDefaultAsync(r => r.ParamName == input.ParamName && r.Id != id); |
|
|
|
|
|
if (checkitem != null) |
|
|
|
|
|
{ |
|
|
|
|
|
ret.Status = false; |
|
|
|
|
|
ret.Message = $"参数名称【{input.ParamName}】已存,在无法添加!"; |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
var item = await _repository.GetAsync(id); |
|
|
|
|
|
ObjectMapper.Map<BaseConfigCreateDto, BaseConfig>(input, item); |
|
|
|
|
|
await _repository.UpdateAsync(item); |
|
|
|
|
|
await _baseConfigDomainService.UpdateBaseConfigCache(); |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
ret.Status = false; |
|
|
|
|
|
ret.Message = _errorMessagePrefix + "UpdateAsync 执行出错:" + ex.Message; |
|
|
|
|
|
_logger.LogError(ret.Message); |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除实体
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">删除主键</param>
|
|
|
|
|
|
/// <returns>执行成功返回真</returns>
|
|
|
|
|
|
[UnitOfWork] |
|
|
|
|
|
[HttpDelete] |
|
|
|
|
|
[Route("delete/{id}")]//delete/
|
|
|
|
|
|
public async Task<ObjectResultDto> DeleteAsync(string id) |
|
|
|
|
|
{ |
|
|
|
|
|
_logger.LogDebug(_errorMessagePrefix + "DeleteAsync 进入"); |
|
|
|
|
|
ObjectResultDto ret = new ObjectResultDto(); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
Guid guid = Guid.Parse(id); |
|
|
|
|
|
await _repository.DeleteAsync(guid); |
|
|
|
|
|
await _baseConfigDomainService.UpdateBaseConfigCache(); |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
ret.Status = false; |
|
|
|
|
|
ret.Message = _errorMessagePrefix + "DeleteAsync 执行出错:" + ex.Message; |
|
|
|
|
|
_logger.LogError(ret.Message); |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 私有方法
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据筛选条件获取实体列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private IQueryable<BaseConfig> QueryByCondition(QueryBaseConfigDto input) |
|
|
|
|
|
{ |
|
|
|
|
|
IQueryable<BaseConfig> ret = _repository.Where(itm => 1 == 1); |
|
|
|
|
|
if (!string.IsNullOrEmpty(input.ParamName)) |
|
|
|
|
|
{ |
|
|
|
|
|
ret = ret.Where(itm => itm.ParamName.Contains(input.ParamName)); |
|
|
|
|
|
} |
|
|
|
|
|
if (!string.IsNullOrEmpty(input.ParamValue)) |
|
|
|
|
|
{ |
|
|
|
|
|
ret = ret.Where(itm => itm.ParamValue.Contains(input.ParamValue)); |
|
|
|
|
|
} |
|
|
|
|
|
if (input.State.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
ret = ret.Where(itm => input.State.Contains(itm.State)); |
|
|
|
|
|
} |
|
|
|
|
|
if (!string.IsNullOrEmpty(input.Remark)) |
|
|
|
|
|
{ |
|
|
|
|
|
ret = ret.Where(itm => itm.Remark.Contains(input.Remark)); |
|
|
|
|
|
} |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|