feat 添加表情包管理

This commit is contained in:
AERWEN\26795 2023-10-29 10:15:57 +08:00
parent e15f62732e
commit fed8e54d63
11 changed files with 696 additions and 4 deletions

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using ARW.Model.Models.Business.EmotionManage.EmoticonDatas;
namespace ARW.Model.Dto.Business.EmotionManage.EmoticonDatas
{
/// <summary>
/// 表情包输入对象
///
/// @author lwh
/// @date 2023-10-28
/// </summary>
public class EmoticonDataDto
{
public int EmoticonDataId { get; set; }
public long EmoticonDataGuid { get; set; }
[Required(ErrorMessage = "分类guid不能为空")]
public long EmoticonCategoryGuid { get; set; }
public string EmoticonDataName { get; set; }
[Required(ErrorMessage = "图片不能为空")]
public string EmoticonDataImg { get; set; }
[Required(ErrorMessage = "排序不能为空")]
public int EmoticonDataSort { get; set; }
}
/// <summary>
/// 表情包查询对象
///
/// @author lwh
/// @date 2023-10-28
/// </summary>
public class EmoticonDataQueryDto : PagerInfo
{
public long? EmoticonCategoryGuid { get; set; }
public string EmoticonDataName { get; set; }
public string ids { get; set; }
}
}

View File

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using SqlSugar;
using OfficeOpenXml.Attributes;
using Newtonsoft.Json;
namespace ARW.Model.Models.Business.EmotionManage.EmoticonDatas
{
/// <summary>
/// 表情包,数据实体对象
///
/// @author lwh
/// @date 2023-10-28
/// </summary>
[SugarTable("tb_emoticon_data")]
public class EmoticonData : BusinessBase
{
/// <summary>
/// 描述 :
/// 空值 : false
/// </summary>
[EpplusTableColumn(Header = "EmoticonDataId")]
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "emoticon_data_id")]
public int EmoticonDataId { get; set; }
/// <summary>
/// 描述 :
/// 空值 : false
/// </summary>
[EpplusTableColumn(Header = "EmoticonDataGuid")]
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "emoticon_data_guid")]
public long EmoticonDataGuid { get; set; }
/// <summary>
/// 描述 :分类guid
/// 空值 : false
/// </summary>
[EpplusTableColumn(Header = "分类guid")]
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "emoticon_category_guid")]
public long EmoticonCategoryGuid { get; set; }
/// <summary>
/// 描述 :名称
/// 空值 : true
/// </summary>
[EpplusTableColumn(Header = "名称")]
[SugarColumn(ColumnName = "emoticon_data_name")]
public string EmoticonDataName { get; set; }
/// <summary>
/// 描述 :图片
/// 空值 : false
/// </summary>
[EpplusTableColumn(Header = "图片")]
[SugarColumn(ColumnName = "emoticon_data_img")]
public string EmoticonDataImg { get; set; }
/// <summary>
/// 描述 :排序
/// 空值 : false
/// </summary>
[EpplusTableColumn(Header = "排序")]
[SugarColumn(ColumnName = "emoticon_data_sort")]
public int EmoticonDataSort { get; set; }
}
}

View File

@ -0,0 +1,69 @@
using Newtonsoft.Json;
using OfficeOpenXml.Attributes;
using SqlSugar;
using System;
namespace ARW.Model.Vo.Business.EmotionManage.EmoticonDatas
{
/// <summary>
/// 表情包展示对象
///
/// @author lwh
/// @date 2023-10-28
/// </summary>
public class EmoticonDataVo
{
/// <summary>
/// 描述 :
/// </summary>
[EpplusIgnore]
public int EmoticonDataId { get; set; }
/// <summary>
/// 描述 :
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[EpplusIgnore]
public long EmoticonDataGuid { get; set; }
/// <summary>
/// 描述 :分类guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[EpplusIgnore]
public long EmoticonCategoryGuid { get; set; }
/// <summary>
/// 描述 : 分类名称
/// </summary>
[EpplusTableColumn(Header = "表情包分类名称")]
public string EmoticonCategoryName { get; set; }
/// <summary>
/// 描述 :名称
/// </summary>
[EpplusTableColumn(Header = "表情包名称")]
public string EmoticonDataName { get; set; }
/// <summary>
/// 描述 :图片
/// </summary>
[EpplusTableColumn(Header = "表情包图片")]
public string EmoticonDataImg { get; set; }
/// <summary>
/// 描述 :排序
/// </summary>
[EpplusTableColumn(Header = "表情包排序")]
public int EmoticonDataSort { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using System;
using Infrastructure.Attribute;
using ARW.Repository.System;
using ARW.Model.Models.Business.EmotionManage.EmoticonDatas;
namespace ARW.Repository.Business.EmotionManage.EmoticonDatas
{
/// <summary>
/// 表情包仓储
///
/// @author lwh
/// @date 2023-10-28
/// </summary>
[AppService(ServiceLifetime = LifeTime.Transient)]
public class EmoticonDataRepository : BaseRepository<EmoticonData>
{
#region
#endregion
}
}

View File

@ -0,0 +1,177 @@
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
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ARW.Model;
using ARW.Model.Dto.Business.EmotionManage.EmoticonDatas;
using ARW.Model.Models.Business.EmotionManage.EmoticonDatas;
using ARW.Model.Vo.Business.EmotionManage.EmoticonDatas;
namespace ARW.Service.Business.IBusinessService.EmotionManage.EmoticonDatas
{
/// <summary>
/// 表情包接口类
///
/// @author lwh
/// @date 2023-10-28
/// </summary>
public interface IEmoticonDataService : IBaseService<EmoticonData>
{
/// <summary>
/// 获取表情包分页列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
Task<PagedInfo<EmoticonDataVo>> GetEmoticonDataList(EmoticonDataQueryDto parm);
/// <summary>
/// 添加或修改表情包
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
Task<string> AddOrUpdateEmoticonData(EmoticonData parm);
/// <summary>
/// 数据导入处理
/// </summary>
/// <param name="shopVo"></param>
/// <returns></returns>
Task<EmoticonDataVo> HandleImportData(EmoticonDataVo EmoticonDataVo);
/// <summary>
/// Excel导入
/// </summary>
/// <param name="EmoticonData"></param>
/// <returns></returns>
Task<string> ImportExcel(EmoticonData EmoticonData,int index,bool isUpdateSupport,string user);
/// <summary>
/// Excel导出
/// </summary>
Task<List<EmoticonDataVo>> HandleExportData(List<EmoticonDataVo> data);
}
}

View File

@ -33,7 +33,7 @@ namespace ARW.Service.Business.IBusinessService.EmotionManage.EmotionCategorys
Task<List<EmotionCategoryVo>> GetEmotionCategoryList(EmotionCategoryQueryDto parm);
/// <summary>
/// <summary>
/// 添加或修改表情包分类
/// </summary>
/// <param name="parm"></param>
@ -54,7 +54,7 @@ namespace ARW.Service.Business.IBusinessService.EmotionManage.EmotionCategorys
/// </summary>
/// <param name="EmotionCategory"></param>
/// <returns></returns>
Task<string> ImportExcel(EmotionCategory EmotionCategory,int index,bool isUpdateSupport,string user);
Task<string> ImportExcel(EmotionCategory EmotionCategory, int index, bool isUpdateSupport, string user);
/// <summary>
/// Excel导出

View File

@ -0,0 +1,213 @@
using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure.Model;
using Mapster;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ARW.Admin.WebApi.Extensions;
using ARW.Admin.WebApi.Filters;
using ARW.Common;
using ARW.Model.Dto.Business.EmotionManage.EmoticonDatas;
using ARW.Service.Business.IBusinessService.EmotionManage.EmoticonDatas;
using ARW.Admin.WebApi.Controllers;
using ARW.Model.Models.Business.EmotionManage.EmoticonDatas;
using ARW.Model.Vo.Business.EmotionManage.EmoticonDatas;
using Microsoft.AspNetCore.Authorization;
using ARW.Admin.WebApi.Framework;
namespace ARW.WebApi.Controllers.Business.EmotionManage.EmoticonDatas
{
/// <summary>
/// 表情包控制器
///
/// @author lwh
/// @date 2023-10-28
/// </summary>
[Verify]
[Route("business/[controller]")]
public class EmoticonDataController : BaseController
{
private readonly IEmoticonDataService _EmoticonDataService;
/// <summary>
/// 依赖注入
/// </summary>
/// <param name="EmoticonDataService">表情包服务</param>
public EmoticonDataController(IEmoticonDataService EmoticonDataService)
{
_EmoticonDataService = EmoticonDataService;
}
/// <summary>
/// 获取表情包列表
/// </summary>
/// <param name="parm">查询参数</param>
/// <returns></returns>
[HttpGet("getEmoticonDataList")]
[ActionPermissionFilter(Permission = "business:emoticondata:list")]
public async Task<IActionResult> GetEmoticonDataList([FromQuery] EmoticonDataQueryDto parm)
{
var res = await _EmoticonDataService.GetEmoticonDataList(parm);
return SUCCESS(res);
}
/// <summary>
/// 添加或修改表情包
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpPost("addOrUpdateEmoticonData")]
[ActionPermissionFilter(Permission = "business:emoticondata:addOrUpdate")]
[Log(Title = "添加或修改表情包", BusinessType = BusinessType.ADDORUPDATE)]
public async Task<IActionResult> AddOrUpdateEmoticonData([FromBody] EmoticonDataDto parm)
{
if (parm == null) { throw new CustomException("请求参数错误"); }
var modal = new EmoticonData();
if (parm.EmoticonDataId != 0) modal = parm.Adapt<EmoticonData>().ToUpdate(HttpContext);
else modal = parm.Adapt<EmoticonData>().ToCreate(HttpContext);
var res = await _EmoticonDataService.AddOrUpdateEmoticonData(modal);
return SUCCESS(res);
}
/// <summary>
/// 批量添加添加表情包
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpPost("batchAddEmoticonData")]
[ActionPermissionFilter(Permission = "business:emoticondata:import")]
[Log(Title = "批量添加添加表情包", BusinessType = BusinessType.ADDORUPDATE)]
public async Task<IActionResult> BatchAddEmoticonData([FromBody] EmoticonDataDto parm)
{
if (parm == null) { throw new CustomException("请求参数错误"); }
var user = JwtUtil.GetLoginUser(HttpContext);
var imgList = parm.EmoticonDataImg.Split(",");
foreach (var item in imgList)
{
var data = new EmoticonData
{
EmoticonCategoryGuid = parm.EmoticonCategoryGuid,
EmoticonDataImg = item,
EmoticonDataSort = 100,
Create_by = user.UserName,
Create_time = DateTime.Now,
};
await _EmoticonDataService.AddOrUpdateEmoticonData(data);
}
return SUCCESS("批量添加成功");
}
/// <summary>
/// 删除表情包
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "business:emoticondata:delete")]
[Log(Title = "表情包删除", BusinessType = BusinessType.DELETE)]
public IActionResult Delete(string ids)
{
long[] idsArr = Tools.SpitLongArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _EmoticonDataService.Delete(idsArr);
return SUCCESS("删除成功!");
}
/// <summary>
/// 导入表情包
/// </summary>
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
/// <param name="updateSupport">是否需要更新</param>
/// <returns></returns>
[HttpPost("importData")]
[Log(Title = "表情包导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
[ActionPermissionFilter(Permission = "business:emoticondata:import")]
public async Task<IActionResult> ImportExcel([FromForm(Name = "file")] IFormFile formFile, bool updateSupport)
{
var isUpdateSupport = updateSupport;
IEnumerable<EmoticonDataVo> parm = ExcelHelper<EmoticonDataVo>.ImportData(formFile.OpenReadStream());
var i = 0;
var msgList = new List<string>();
foreach (EmoticonDataVo item in parm)
{
i++;
var EmoticonData = await _EmoticonDataService.HandleImportData(item);
var modal = EmoticonData.Adapt<EmoticonData>().ToCreate(HttpContext);
var user = JwtUtil.GetLoginUser(App.HttpContext).UserName;
var msg = await _EmoticonDataService.ImportExcel(modal, i, isUpdateSupport, user);
msgList.Add(msg);
}
return SUCCESS(msgList.ToArray());
}
/// <summary>
/// 表情包导入模板下载
/// </summary>
/// <returns></returns>
[HttpGet("importTemplate")]
[Log(Title = "表情包模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
[AllowAnonymous]
public IActionResult ImportTemplateExcel()
{
List<EmoticonDataVo> EmoticonData = new List<EmoticonDataVo>();
MemoryStream stream = new MemoryStream();
// 示例数据
var values = new List<string>() { "111", "222", "333" };
string sFileName = DownloadImportTemplate(EmoticonData, stream, "表情包导入模板", values);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{sFileName}");
}
/// <summary>
/// 导出表情包
/// </summary>
/// <returns></returns>
[Log(Title = "表情包导出", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
[HttpGet("exportEmoticonData")]
[ActionPermissionFilter(Permission = "business:emoticondata:export")]
public async Task<IActionResult> ExportExcel([FromQuery] EmoticonDataQueryDto parm)
{
parm.PageSize = 10000;
var list = await _EmoticonDataService.GetEmoticonDataList(parm);
var data = list.Result;
// 选中数据
if (!string.IsNullOrEmpty(parm.ids))
{
int[] idsArr = Tools.SpitIntArrary(parm.ids);
var selectDataList = new List<EmoticonDataVo>();
foreach (var item in idsArr)
{
var select_data = data.Where(s => s.EmoticonDataId == item).First();
selectDataList.Add(select_data);
}
data = selectDataList;
}
// 导出数据处理
var handleData = await _EmoticonDataService.HandleExportData(data);
string sFileName = ExportExcel(handleData, "EmoticonData", "表情包列表");
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
}
}
}

View File

@ -48,7 +48,7 @@ namespace ARW.WebApi.Controllers.Business.EmotionManage.EmotionCategorys
/// <returns></returns>
[HttpGet("getEmotionCategoryTreeList")]
[ActionPermissionFilter(Permission = "business:emotioncategory:treelist")]
public async Task<IActionResult> GetEmotionCategoryList([FromQuery] EmotionCategoryQueryDto parm)
public async Task<IActionResult> GetEmotionCategoryTreeList([FromQuery] EmotionCategoryQueryDto parm)
{
var res = await _EmotionCategoryService.GetEmotionCategoryTreeList(parm);
res ??= new List<EmotionCategoryVo>();
@ -56,6 +56,22 @@ namespace ARW.WebApi.Controllers.Business.EmotionManage.EmotionCategorys
return SUCCESS(res);
}
/// <summary>
/// 获取表情包分类列表
/// </summary>
/// <param name="parm">查询参数</param>
/// <returns></returns>
[HttpGet("getEmotionCategoryList")]
public async Task<IActionResult> GetEmotionCategoryList([FromQuery] EmotionCategoryQueryDto parm)
{
var res = await _EmotionCategoryService.GetEmotionCategoryList(parm);
res ??= new List<EmotionCategoryVo>();
return SUCCESS(res);
}
/// <summary>
/// 添加或修改表情包分类
/// </summary>

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB