178 lines
6.5 KiB
C#
178 lines
6.5 KiB
C#
using Infrastructure.Attribute;
|
|
using Microsoft.AspNetCore.Http;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Infrastructure;
|
|
using ARW.Model;
|
|
using ARW.Repository;
|
|
using ARW.Repository.Business.EmotionManage.EmoticonDatas;
|
|
using ARW.Service.Business.IBusinessService.EmotionManage.EmoticonDatas;
|
|
using ARW.Model.Dto.Business.EmotionManage.EmoticonDatas;
|
|
using ARW.Model.Models.Business.EmotionManage.EmoticonDatas;
|
|
using ARW.Model.Vo.Business.EmotionManage.EmoticonDatas;
|
|
using ARW.Model.Models.Business.EmotionManage.EmotionCategorys;
|
|
|
|
namespace ARW.Service.Business.BusinessService.EmotionManage.EmoticonDatas
|
|
{
|
|
/// <summary>
|
|
/// 表情包接口实现类
|
|
///
|
|
/// @author lwh
|
|
/// @date 2023-10-28
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IEmoticonDataService), ServiceLifetime = LifeTime.Transient)]
|
|
public class EmoticonDataServiceImpl : BaseService<EmoticonData>, IEmoticonDataService
|
|
{
|
|
private readonly EmoticonDataRepository _EmoticonDataRepository;
|
|
|
|
public EmoticonDataServiceImpl(EmoticonDataRepository EmoticonDataRepository)
|
|
{
|
|
this._EmoticonDataRepository = EmoticonDataRepository;
|
|
}
|
|
|
|
#region 业务逻辑代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询表情包分页列表
|
|
/// </summary>
|
|
public async Task<PagedInfo<EmoticonDataVo>> GetEmoticonDataList(EmoticonDataQueryDto parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<EmoticonData>();
|
|
|
|
predicate = predicate.AndIF(parm.EmoticonCategoryGuid != null, s => s.EmoticonCategoryGuid == parm.EmoticonCategoryGuid);
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.EmoticonDataName), s => s.EmoticonDataName.Contains(parm.EmoticonDataName));
|
|
var query = _EmoticonDataRepository
|
|
.Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.LeftJoin<EmotionCategory>((s, c) => s.EmoticonCategoryGuid == c.EmotionCategoryGuid)
|
|
.OrderBy(s => s.EmoticonDataSort, OrderByType.Asc)
|
|
.Select((s, c) => new EmoticonDataVo
|
|
{
|
|
EmoticonDataId = s.EmoticonDataId,
|
|
EmoticonDataGuid = s.EmoticonDataGuid,
|
|
EmoticonCategoryGuid = s.EmoticonCategoryGuid,
|
|
EmoticonCategoryName = c.EmotionCategoryName,
|
|
EmoticonDataName = s.EmoticonDataName,
|
|
EmoticonDataImg = s.EmoticonDataImg,
|
|
EmoticonDataSort = s.EmoticonDataSort,
|
|
});
|
|
|
|
|
|
return await query.ToPageAsync(parm);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加或修改表情包
|
|
/// </summary>
|
|
public async Task<string> AddOrUpdateEmoticonData(EmoticonData model)
|
|
{
|
|
if (model.EmoticonDataId != 0)
|
|
{
|
|
var response = await _EmoticonDataRepository.UpdateAsync(model);
|
|
return "修改成功!";
|
|
}
|
|
else
|
|
{
|
|
|
|
var response = await _EmoticonDataRepository.InsertReturnSnowflakeIdAsync(model);
|
|
return "添加成功!";
|
|
}
|
|
}
|
|
|
|
#region Excel处理
|
|
/// <summary>
|
|
/// 数据导入处理
|
|
/// </summary>
|
|
public async Task<EmoticonDataVo> HandleImportData(EmoticonDataVo EmoticonData)
|
|
{
|
|
return EmoticonData;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Excel导入
|
|
/// </summary>
|
|
public async Task<string> ImportExcel(EmoticonData EmoticonData, int index, bool isUpdateSupport, string user)
|
|
{
|
|
try
|
|
{
|
|
// 空值判断
|
|
// if (EmoticonData.EmoticonDataId == null) throw new CustomException("表情包不能为空");
|
|
|
|
if (isUpdateSupport)
|
|
{
|
|
// 判断唯一值
|
|
var model = await GetFirstAsync(s => s.EmoticonDataId == EmoticonData.EmoticonDataId);
|
|
|
|
// 如果为空就新增数据
|
|
if (model == null)
|
|
{
|
|
// 开启事务
|
|
var res = await UseTranAsync(async () =>
|
|
{
|
|
var addRes = await AddOrUpdateEmoticonData(EmoticonData);
|
|
});
|
|
var addStr = $"第 {index} 行 => 表情包:【{EmoticonData.EmoticonDataId}】<span style='color:#27af49'>新增成功!</span><br>";
|
|
return addStr;
|
|
}
|
|
else
|
|
{
|
|
// 如果有数据就进行修改
|
|
// 开启事务
|
|
await UseTranAsync(async () =>
|
|
{
|
|
EmoticonData.EmoticonDataId = model.EmoticonDataId;
|
|
EmoticonData.EmoticonDataGuid = model.EmoticonDataGuid;
|
|
EmoticonData.Update_by = user;
|
|
EmoticonData.Update_time = DateTime.Now;
|
|
var editRes = await AddOrUpdateEmoticonData(EmoticonData);
|
|
});
|
|
var editStr = $"第 {index} 行 => 表情包:【{EmoticonData.EmoticonDataId}】<span style='color:#e6a23c'>更新成功!</span><br>";
|
|
return editStr;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 开启事务
|
|
var res = await UseTranAsync(async () =>
|
|
{
|
|
var addRes = await AddOrUpdateEmoticonData(EmoticonData);
|
|
});
|
|
//Console.WriteLine(res.IsSuccess);
|
|
var addStr = $"第 {index} 行 => 表情包:【{EmoticonData.EmoticonDataId}】<span style='color:#27af49'>新增成功!</span><br>";
|
|
return addStr;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var errorRes = $"第 {index} 行 => 表情包:【{EmoticonData.EmoticonDataId}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
|
|
return errorRes;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Excel数据导出处理
|
|
/// </summary>
|
|
public async Task<List<EmoticonDataVo>> HandleExportData(List<EmoticonDataVo> data)
|
|
{
|
|
return data;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|