diff --git a/ARW.Model/Dto/Business/EmotionManage/EmotionCategorys/EmotionCategoryDto.cs b/ARW.Model/Dto/Business/EmotionManage/EmotionCategorys/EmotionCategoryDto.cs new file mode 100644 index 0000000..ce0121b --- /dev/null +++ b/ARW.Model/Dto/Business/EmotionManage/EmotionCategorys/EmotionCategoryDto.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using ARW.Model.Models.Business.EmotionManage.EmotionCategorys; + +namespace ARW.Model.Dto.Business.EmotionManage.EmotionCategorys +{ + /// + /// 表情包分类输入对象 + /// + /// @author lwh + /// @date 2023-10-28 + /// + public class EmotionCategoryDto + { + + public int EmotionCategoryId { get; set; } + + public long EmotionCategoryGuid { get; set; } + + public long EmotionCategoryParentGuid { get; set; } + + public string EmotionCategoryAncestralGuid { get; set; } + + [Required(ErrorMessage = "名称不能为空")] + public string EmotionCategoryName { get; set; } + + public string EmotionCategoryImg { get; set; } + + [Required(ErrorMessage = "是否为热门 (1是 2否)不能为空")] + public int IsPopular { get; set; } + + [Required(ErrorMessage = "浏览次数不能为空")] + public int EmotionCategoryViewsNum { get; set; } + + [Required(ErrorMessage = "排序不能为空")] + public int EmotionCategorySort { get; set; } + + + + + + } + + + /// + /// 表情包分类查询对象 + /// + /// @author lwh + /// @date 2023-10-28 + /// + public class EmotionCategoryQueryDto : PagerInfo + { + + public string EmotionCategoryName { get; set; } + public int IsPopular { get; set; } + public string ids { get; set; } + } + + + + +} diff --git a/ARW.Model/Models/Business/EmotionManage/EmotionCategorys/EmotionCategory.cs b/ARW.Model/Models/Business/EmotionManage/EmotionCategorys/EmotionCategory.cs new file mode 100644 index 0000000..dec2955 --- /dev/null +++ b/ARW.Model/Models/Business/EmotionManage/EmotionCategorys/EmotionCategory.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using SqlSugar; +using OfficeOpenXml.Attributes; +using Newtonsoft.Json; + +namespace ARW.Model.Models.Business.EmotionManage.EmotionCategorys +{ + /// + /// 表情包分类,数据实体对象 + /// + /// @author lwh + /// @date 2023-10-28 + /// + [SugarTable("tb_emotion_category")] + public class EmotionCategory : BusinessBase + { + + /// + /// 描述 : + /// 空值 : false + /// + [EpplusTableColumn(Header = "EmotionCategoryId")] + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "emotion_category_id")] + public int EmotionCategoryId { get; set; } + + + /// + /// 描述 : + /// 空值 : false + /// + [EpplusTableColumn(Header = "EmotionCategoryGuid")] + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "emotion_category_guid")] + public long EmotionCategoryGuid { get; set; } + + + /// + /// 描述 :父级guid + /// 空值 : false + /// + [EpplusTableColumn(Header = "父级guid")] + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(ColumnName = "emotion_category_parent_guid")] + public long EmotionCategoryParentGuid { get; set; } + + + /// + /// 描述 :祖级guid + /// 空值 : false + /// + [EpplusTableColumn(Header = "祖级guid")] + [SugarColumn(ColumnName = "emotion_category_ancestral_guid")] + public string EmotionCategoryAncestralGuid { get; set; } + + + /// + /// 描述 :名称 + /// 空值 : false + /// + [EpplusTableColumn(Header = "名称")] + [SugarColumn(ColumnName = "emotion_category_name")] + public string EmotionCategoryName { get; set; } + + + /// + /// 描述 :图片 + /// 空值 : true + /// + [EpplusTableColumn(Header = "图片")] + [SugarColumn(ColumnName = "emotion_category_img")] + public string EmotionCategoryImg { get; set; } + + + /// + /// 描述 :是否为热门 (1是 2否) + /// 空值 : false + /// + [EpplusTableColumn(Header = "是否为热门 (1是 2否)")] + [SugarColumn(ColumnName = "is_popular")] + public int IsPopular { get; set; } + + + /// + /// 描述 :浏览次数 + /// 空值 : false + /// + [EpplusTableColumn(Header = "浏览次数")] + [SugarColumn(ColumnName = "emotion_category_views_num")] + public int EmotionCategoryViewsNum { get; set; } + + + /// + /// 描述 :排序 + /// 空值 : false + /// + [EpplusTableColumn(Header = "排序")] + [SugarColumn(ColumnName = "emotion_category_sort")] + public int EmotionCategorySort { get; set; } + + + + + + + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [SugarColumn(IsIgnore = true)] + public List Children { get; set; } + } +} \ No newline at end of file diff --git a/ARW.Model/Vo/Business/EmotionManage/EmotionCategorys/EmotionCategoryVo.cs b/ARW.Model/Vo/Business/EmotionManage/EmotionCategorys/EmotionCategoryVo.cs new file mode 100644 index 0000000..c05f3c8 --- /dev/null +++ b/ARW.Model/Vo/Business/EmotionManage/EmotionCategorys/EmotionCategoryVo.cs @@ -0,0 +1,103 @@ +using Newtonsoft.Json; +using OfficeOpenXml.Attributes; +using SqlSugar; +using System; +using ARW.Model.Models.Business.EmotionManage.EmotionCategorys; +using System.Collections.Generic; + +namespace ARW.Model.Vo.Business.EmotionManage.EmotionCategorys +{ + /// + /// 表情包分类展示对象 + /// + /// @author lwh + /// @date 2023-10-28 + /// + public class EmotionCategoryVo + { + + + /// + /// 描述 : + /// + [EpplusIgnore] + public int EmotionCategoryId { get; set; } + + + /// + /// 描述 : + /// + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(IsTreeKey = true)] + [EpplusIgnore] + public long EmotionCategoryGuid { get; set; } + + + /// + /// 描述 :父级guid + /// + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(IsTreeKey = true)] + [EpplusIgnore] + public long EmotionCategoryParentGuid { get; set; } + + + /// + /// 描述 :祖级guid + /// + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(IsTreeKey = true)] + [EpplusIgnore] + public string EmotionCategoryAncestralGuid { get; set; } + + + [EpplusTableColumn(Header = "上级名称")] + public string ParentName { get; set; } + + + /// + /// 描述 :名称 + /// + [EpplusTableColumn(Header = "名称")] + public string EmotionCategoryName { get; set; } + + + /// + /// 描述 :图片 + /// + [EpplusTableColumn(Header = "图片")] + public string EmotionCategoryImg { get; set; } + + + /// + /// 描述 :是否为热门 + /// + [EpplusIgnore] + public int IsPopular { get; set; } + + + [EpplusTableColumn(Header = "是否为热门")] + public string IsPopularName { get; set; } + + + /// + /// 描述 :浏览次数 + /// + [EpplusTableColumn(Header = "浏览次数")] + public int EmotionCategoryViewsNum { get; set; } + + + /// + /// 描述 :排序 + /// + [EpplusTableColumn(Header = "排序")] + public int EmotionCategorySort { get; set; } + + + + [EpplusIgnore] + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [SugarColumn(IsIgnore = true)] + public List Children { get; set; } + } +} diff --git a/ARW.Repository/Business/EmotionManage/EmotionCategorys/EmotionCategoryRepository.cs b/ARW.Repository/Business/EmotionManage/EmotionCategorys/EmotionCategoryRepository.cs new file mode 100644 index 0000000..1117431 --- /dev/null +++ b/ARW.Repository/Business/EmotionManage/EmotionCategorys/EmotionCategoryRepository.cs @@ -0,0 +1,20 @@ +using System; +using Infrastructure.Attribute; +using ARW.Repository.System; +using ARW.Model.Models.Business.EmotionManage.EmotionCategorys; + +namespace ARW.Repository.Business.EmotionManage.EmotionCategorys +{ + /// + /// 表情包分类仓储 + /// + /// @author lwh + /// @date 2023-10-28 + /// + [AppService(ServiceLifetime = LifeTime.Transient)] + public class EmotionCategoryRepository : BaseRepository + { + #region 业务逻辑代码 + #endregion + } +} \ No newline at end of file diff --git a/ARW.Service/Business/BusinessService/EmotionManage/EmotionCategorys/EmotionCategoryService.cs b/ARW.Service/Business/BusinessService/EmotionManage/EmotionCategorys/EmotionCategoryService.cs new file mode 100644 index 0000000..92b919d --- /dev/null +++ b/ARW.Service/Business/BusinessService/EmotionManage/EmotionCategorys/EmotionCategoryService.cs @@ -0,0 +1,231 @@ +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.EmotionCategorys; +using ARW.Service.Business.IBusinessService.EmotionManage.EmotionCategorys; +using ARW.Model.Dto.Business.EmotionManage.EmotionCategorys; +using ARW.Model.Models.Business.EmotionManage.EmotionCategorys; +using ARW.Model.Vo.Business.EmotionManage.EmotionCategorys; + +namespace ARW.Service.Business.BusinessService.EmotionManage.EmotionCategorys +{ + /// + /// 表情包分类接口实现类 + /// + /// @author lwh + /// @date 2023-10-28 + /// + [AppService(ServiceType = typeof(IEmotionCategoryService), ServiceLifetime = LifeTime.Transient)] + public class EmotionCategoryServiceImpl : BaseService, IEmotionCategoryService + { + private readonly EmotionCategoryRepository _EmotionCategoryRepository; + + public EmotionCategoryServiceImpl(EmotionCategoryRepository EmotionCategoryRepository) + { + this._EmotionCategoryRepository = EmotionCategoryRepository; + } + + #region 业务逻辑代码 + + + /// + /// 查询表情包分类树形列表 + /// + public async Task> GetEmotionCategoryTreeList(EmotionCategoryQueryDto parm) + { + //开始拼装查询条件 + var predicate = Expressionable.Create(); + predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.EmotionCategoryName), s => s.EmotionCategoryName.Contains(parm.EmotionCategoryName)); + predicate = predicate.AndIF(parm.IsPopular != 0, s => s.IsPopular == parm.IsPopular); + + var query = _EmotionCategoryRepository + .Queryable() + .LeftJoin((s, c) => s.EmotionCategoryParentGuid == c.EmotionCategoryGuid) + .Where(predicate.ToExpression()) + .OrderBy(s => s.EmotionCategorySort, OrderByType.Asc) + .Select((s, c) => new EmotionCategoryVo + { + EmotionCategoryId = s.EmotionCategoryId, + EmotionCategoryGuid = s.EmotionCategoryGuid, + EmotionCategoryParentGuid = s.EmotionCategoryParentGuid, + EmotionCategoryAncestralGuid = s.EmotionCategoryAncestralGuid, + EmotionCategoryName = s.EmotionCategoryName, + EmotionCategoryImg = s.EmotionCategoryImg, + IsPopular = s.IsPopular, + EmotionCategoryViewsNum = s.EmotionCategoryViewsNum, + EmotionCategorySort = s.EmotionCategorySort, + ParentName = c.EmotionCategoryName, + }); + + return await query.ToTreeAsync(it => it.Children, it => it.EmotionCategoryParentGuid, 0); + } + + + /// + /// 查询表情包分类列表 + /// + public async Task> GetEmotionCategoryList(EmotionCategoryQueryDto parm) + { + //开始拼装查询条件d + var predicate = Expressionable.Create(); + + predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.EmotionCategoryName), s => s.EmotionCategoryName.Contains(parm.EmotionCategoryName)); + predicate = predicate.AndIF(parm.IsPopular != 0, s => s.IsPopular == parm.IsPopular); + + var query = _EmotionCategoryRepository + .Queryable() + .LeftJoin((s, c) => s.EmotionCategoryParentGuid == c.EmotionCategoryGuid) + .Where(predicate.ToExpression()) + .OrderBy(s => s.EmotionCategorySort, OrderByType.Asc) + .Select((s, c) => new EmotionCategoryVo + { + EmotionCategoryId = s.EmotionCategoryId, + EmotionCategoryGuid = s.EmotionCategoryGuid, + EmotionCategoryParentGuid = s.EmotionCategoryParentGuid, + EmotionCategoryAncestralGuid = s.EmotionCategoryAncestralGuid, + EmotionCategoryName = s.EmotionCategoryName, + EmotionCategoryImg = s.EmotionCategoryImg, + IsPopular = s.IsPopular, + EmotionCategoryViewsNum = s.EmotionCategoryViewsNum, + EmotionCategorySort = s.EmotionCategorySort, + ParentName = c.EmotionCategoryName, + }); + + + return await query.ToListAsync(); + } + + /// + /// 添加或修改表情包分类 + /// + public async Task AddOrUpdateEmotionCategory(EmotionCategory model) + { + if (model.EmotionCategoryId != 0) + { + var type = await _EmotionCategoryRepository.GetListAsync(s => s.EmotionCategoryParentGuid == model.EmotionCategoryGuid); + if (type != null) + { + foreach (var item in type) + { + if (model.EmotionCategoryParentGuid == item.EmotionCategoryGuid) throw new CustomException("上级菜单不能选择自己的子级!"); + } + } + if (model.EmotionCategoryParentGuid == model.EmotionCategoryGuid) throw new CustomException("上级菜单不能选择与当前菜单一样的!"); + var response = await _EmotionCategoryRepository.UpdateAsync(model); + return "修改成功!"; + } + else + { + var info = _EmotionCategoryRepository.GetFirst(it => it.EmotionCategoryGuid == model.EmotionCategoryParentGuid); + model.EmotionCategoryAncestralGuid = "0"; + if (info != null) model.EmotionCategoryAncestralGuid = info.EmotionCategoryAncestralGuid + "," + model.EmotionCategoryParentGuid; + + var response = await _EmotionCategoryRepository.InsertReturnSnowflakeIdAsync(model); + return "添加成功!"; + } + } + + #region Excel处理 + /// + /// 数据导入处理 + /// + public async Task HandleImportData(EmotionCategoryVo EmotionCategory) + { + return EmotionCategory; + } + + + /// + /// Excel导入 + /// + public async Task ImportExcel(EmotionCategory EmotionCategory, int index, bool isUpdateSupport, string user) + { + try + { + // 空值判断 + // if (EmotionCategory.EmotionCategoryId == null) throw new CustomException("表情包分类不能为空"); + + if (isUpdateSupport) + { + // 判断唯一值 + var model = await GetFirstAsync(s => s.EmotionCategoryName == EmotionCategory.EmotionCategoryName); + + // 如果为空就新增数据 + if (model == null) + { + // 开启事务 + var res = await UseTranAsync(async () => + { + var addRes = await AddOrUpdateEmotionCategory(EmotionCategory); + }); + var addStr = $"第 {index} 行 => 表情包分类:【{EmotionCategory.EmotionCategoryName}】新增成功!
"; + return addStr; + } + else + { + // 如果有数据就进行修改 + // 开启事务 + await UseTranAsync(async () => + { + EmotionCategory.EmotionCategoryId = model.EmotionCategoryId; + EmotionCategory.EmotionCategoryGuid = model.EmotionCategoryGuid; + EmotionCategory.Update_by = user; + EmotionCategory.Update_time = DateTime.Now; + var editRes = await AddOrUpdateEmotionCategory(EmotionCategory); + }); + var editStr = $"第 {index} 行 => 表情包分类:【{EmotionCategory.EmotionCategoryName}】更新成功!
"; + return editStr; + } + } + else + { + // 开启事务 + var res = await UseTranAsync(async () => + { + var addRes = await AddOrUpdateEmotionCategory(EmotionCategory); + }); + //Console.WriteLine(res.IsSuccess); + var addStr = $"第 {index} 行 => 表情包分类:【{EmotionCategory.EmotionCategoryName}】新增成功!
"; + return addStr; + } + } + catch (Exception ex) + { + var errorRes = $"第 {index} 行 => 表情包分类:【{EmotionCategory.EmotionCategoryName}】导入失败!{ex.Message}
"; + return errorRes; + throw; + } + } + + + + /// + /// Excel数据导出处理 + /// + public async Task> HandleExportData(List data) + { + foreach (var item in data) + { + if (item.IsPopular == 1) item.IsPopularName = "是"; + else item.IsPopularName = "否"; + } + + return data; + } + + #endregion + + + + #endregion + + } +} diff --git a/ARW.Service/Business/IBusinessService/EmotionManage/EmotionCategorys/IEmotionCategoryService.cs b/ARW.Service/Business/IBusinessService/EmotionManage/EmotionCategorys/IEmotionCategoryService.cs new file mode 100644 index 0000000..4b38b40 --- /dev/null +++ b/ARW.Service/Business/IBusinessService/EmotionManage/EmotionCategorys/IEmotionCategoryService.cs @@ -0,0 +1,66 @@ +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.EmotionCategorys; +using ARW.Model.Models.Business.EmotionManage.EmotionCategorys; +using ARW.Model.Vo.Business.EmotionManage.EmotionCategorys; + +namespace ARW.Service.Business.IBusinessService.EmotionManage.EmotionCategorys +{ + /// + /// 表情包分类接口类 + /// + /// @author lwh + /// @date 2023-10-28 + /// + public interface IEmotionCategoryService : IBaseService + { + /// + /// 获取表情包分类树形列表 + /// + /// + /// + Task> GetEmotionCategoryTreeList(EmotionCategoryQueryDto parm); + + /// + /// 获取表情包分类列表 + /// + /// + /// + Task> GetEmotionCategoryList(EmotionCategoryQueryDto parm); + + + /// + /// 添加或修改表情包分类 + /// + /// + /// + Task AddOrUpdateEmotionCategory(EmotionCategory parm); + + + /// + /// 数据导入处理 + /// + /// + /// + Task HandleImportData(EmotionCategoryVo EmotionCategoryVo); + + + /// + /// Excel导入 + /// + /// + /// + Task ImportExcel(EmotionCategory EmotionCategory,int index,bool isUpdateSupport,string user); + + /// + /// Excel导出 + /// + Task> HandleExportData(List data); + + + } +} diff --git a/ARW.WebApi/Controllers/Business/EmotionManage/EmotionCategorys/EmotionCategoryController.cs b/ARW.WebApi/Controllers/Business/EmotionManage/EmotionCategorys/EmotionCategoryController.cs new file mode 100644 index 0000000..f2bd063 --- /dev/null +++ b/ARW.WebApi/Controllers/Business/EmotionManage/EmotionCategorys/EmotionCategoryController.cs @@ -0,0 +1,206 @@ +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.EmotionCategorys; +using ARW.Service.Business.IBusinessService.EmotionManage.EmotionCategorys; +using ARW.Admin.WebApi.Controllers; +using ARW.Model.Models.Business.EmotionManage.EmotionCategorys; +using ARW.Model.Vo.Business.EmotionManage.EmotionCategorys; +using Microsoft.AspNetCore.Authorization; +using ARW.Admin.WebApi.Framework; + + +namespace ARW.WebApi.Controllers.Business.EmotionManage.EmotionCategorys +{ + /// + /// 表情包分类控制器 + /// + /// @author lwh + /// @date 2023-10-28 + /// + [Verify] + [Route("business/[controller]")] + public class EmotionCategoryController : BaseController + { + private readonly IEmotionCategoryService _EmotionCategoryService; + + /// + /// 依赖注入 + /// + /// 表情包分类服务 + public EmotionCategoryController(IEmotionCategoryService EmotionCategoryService) + { + _EmotionCategoryService = EmotionCategoryService; + } + + + /// + /// 获取表情包分类树形列表 + /// + /// 查询参数 + /// + [HttpGet("getEmotionCategoryTreeList")] + [ActionPermissionFilter(Permission = "business:emotioncategory:treelist")] + public async Task GetEmotionCategoryList([FromQuery] EmotionCategoryQueryDto parm) + { + var res = await _EmotionCategoryService.GetEmotionCategoryTreeList(parm); + res ??= new List(); + + return SUCCESS(res); + } + + /// + /// 添加或修改表情包分类 + /// + /// + /// + [HttpPost("addOrUpdateEmotionCategory")] + [ActionPermissionFilter(Permission = "business:emotioncategory:addOrUpdate")] + [Log(Title = "添加或修改表情包分类", BusinessType = BusinessType.ADDORUPDATE)] + public async Task AddOrUpdateEmotionCategory([FromBody] EmotionCategoryDto parm) + { + if (parm == null) { throw new CustomException("请求参数错误"); } + + var modal = new EmotionCategory(); + if (parm.EmotionCategoryId != 0) modal = parm.Adapt().ToUpdate(HttpContext); + else modal = parm.Adapt().ToCreate(HttpContext); + + var res = await _EmotionCategoryService.AddOrUpdateEmotionCategory(modal); + return SUCCESS(res); + } + + /// + /// 删除表情包分类 + /// + /// + [HttpDelete("{ids}")] + [ActionPermissionFilter(Permission = "business:emotioncategory: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 = _EmotionCategoryService.Delete(idsArr); + return SUCCESS("删除成功!"); + } + + /// + /// 导入表情包分类 + /// + /// 使用IFromFile必须使用name属性否则获取不到文件 + /// 是否需要更新 + /// + [HttpPost("importData")] + [Log(Title = "表情包分类导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)] + [ActionPermissionFilter(Permission = "business:emotioncategory:import")] + public async Task ImportExcel([FromForm(Name = "file")] IFormFile formFile, bool updateSupport) + { + var isUpdateSupport = updateSupport; + IEnumerable parm = ExcelHelper.ImportData(formFile.OpenReadStream()); + + var i = 0; + var msgList = new List(); + foreach (EmotionCategoryVo item in parm) + { + if (!string.IsNullOrEmpty(item.ParentName)) + { + var category = await _EmotionCategoryService.GetFirstAsync(s => s.EmotionCategoryName == item.ParentName); + if (category == null) msgList.Add($"表情包分类:【{item.EmotionCategoryName}】导入失败!上级类目{item.ParentName}不存在!
"); + else item.EmotionCategoryParentGuid = category.EmotionCategoryGuid; + } + if (!string.IsNullOrEmpty(item.IsPopularName)) + { + if (item.IsPopularName == "是") item.IsPopular = 1; + if (item.IsPopularName == "否") item.IsPopular = 2; + } + i++; + var EmotionCategory = await _EmotionCategoryService.HandleImportData(item); + var modal = EmotionCategory.Adapt().ToCreate(HttpContext); + var user = JwtUtil.GetLoginUser(App.HttpContext).UserName; + var msg = await _EmotionCategoryService.ImportExcel(modal, i, isUpdateSupport, user); + msgList.Add(msg); + } + + return SUCCESS(msgList.ToArray()); + } + + + /// + /// 表情包分类导入模板下载 + /// + /// + [HttpGet("importTemplate")] + [Log(Title = "表情包分类模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = false, IsSaveResponseData = false)] + [AllowAnonymous] + public IActionResult ImportTemplateExcel() + { + List EmotionCategory = new List(); + MemoryStream stream = new MemoryStream(); + + // 示例数据 + var allValues = new List>(); + var values = new List() { "", "可爱loopy系列", "http://localhost:8888/Uploads/EmotionCategory/20231028/80EA7BE112F962E8.jpg", "是", "0", "1" }; + var values2 = new List() { "可爱loopy系列", "情侣", "http://localhost:8888/Uploads/EmotionCategory/20231028/80EA7BE112F962E8.jpg", "否", "0", "1" }; + allValues.Add(values); + allValues.Add(values2); + string sFileName = DownloadImportTemplate(EmotionCategory, stream, "表情包分类导入模板", allValues); + + return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{sFileName}"); + } + + /// + /// 导出表情包分类 + /// + /// + [Log(Title = "表情包分类导出", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)] + [HttpGet("exportEmotionCategory")] + [ActionPermissionFilter(Permission = "business:emotioncategory:export")] + public async Task ExportExcel([FromQuery] EmotionCategoryQueryDto parm) + { + var list = await _EmotionCategoryService.GetEmotionCategoryList(parm); + var data = list; + + // 选中数据 + if (!string.IsNullOrEmpty(parm.ids)) + { + int[] idsArr = Tools.SpitIntArrary(parm.ids); + var selectDataList = new List(); + foreach (var item in idsArr) + { + var select_data = data.Where(s => s.EmotionCategoryId == item).First(); + selectDataList.Add(select_data); + + // 查看当前数据有没有子级 + var newEmotionCategorys = data.FindAll(delegate (EmotionCategoryVo emotionCategory) + { + string[] parentEmotionCategoryId = emotionCategory.EmotionCategoryAncestralGuid.Split(",", StringSplitOptions.RemoveEmptyEntries); + return parentEmotionCategoryId.Contains(select_data.EmotionCategoryGuid.ToString()); + }); + string[] emotionCategoryArr = newEmotionCategorys.Select(x => x.EmotionCategoryGuid.ToString()).ToArray(); + var ancestorArr = data.Where(s => emotionCategoryArr.Contains(s.EmotionCategoryGuid.ToString())).ToList(); + selectDataList.AddRange(ancestorArr); + } + data = selectDataList; + } + + + + // 导出数据处理 + var handleData = await _EmotionCategoryService.HandleExportData(data); + + string sFileName = ExportExcel(handleData, "EmotionCategory", "表情包分类列表"); + return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); + } + + + + + } +} diff --git a/ARW.WebApi/appsettings.json b/ARW.WebApi/appsettings.json index 93c3acf..7782864 100644 --- a/ARW.WebApi/appsettings.json +++ b/ARW.WebApi/appsettings.json @@ -7,7 +7,7 @@ } }, "ConnectionStrings": { - "conn_db": "server=47.242.159.172;Database=xcx_temp;Uid=xcx_temp;Pwd=Wp8rNAKeKW3k4c3r;SslMode=none;CharSet=utf8mb4;AllowLoadLocalInfile=true;AllowUserVariables=true;", + "conn_db": "server=47.242.159.172;Database=emoticon;Uid=emoticon;Pwd=FBSrBYyPXPXwZkMd;SslMode=none;CharSet=utf8mb4;AllowLoadLocalInfile=true;AllowUserVariables=true;", //"conn_db": "server=127.0.0.1;Database=shop;Uid=root;Pwd=root;SslMode=none;CharSet=utf8mb4;AllowLoadLocalInfile=true;AllowUserVariables=true;", "conn_db_type": "8" //数据库类型 MySql = 0, SqlServer = 1 }, @@ -41,12 +41,12 @@ "templateCode": "SMS_154950909" }, "gen": { - "conn": "server=47.242.159.172;Database=xcx_temp;Uid=xcx_temp;Pwd=Wp8rNAKeKW3k4c3r;SslMode=none;CharSet=utf8mb4;AllowLoadLocalInfile=true;AllowUserVariables=true;", + "conn": "server=47.242.159.172;Database=emoticon;Uid=emoticon;Pwd=FBSrBYyPXPXwZkMd;SslMode=none;CharSet=utf8mb4;AllowLoadLocalInfile=true;AllowUserVariables=true;", "dbType": 8, //MySql = 0, SqlServer = 1 "autoPre": true, //自动去除表前缀 "author": "admin", "tablePrefix": "tb_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)", - "vuePath": "D:\\.Net\\Aerwen\\xcx_temp\\xcx_temp_back" //前端代码存储路径eg:D:\Work\ARWAdmin-Vue3 + "vuePath": "D:\\.Net\\Aerwen\\emoticon\\emoticon_back" //前端代码存储路径eg:D:\Work\ARWAdmin-Vue3 }, //邮箱配置信息 "MailOptions": {