214 lines
8.1 KiB
C#
214 lines
8.1 KiB
C#
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 });
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|