feat 添加表情包分类
This commit is contained in:
parent
04296dc681
commit
e15f62732e
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 表情包分类输入对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-10-28
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 表情包分类查询对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-10-28
|
||||
/// </summary>
|
||||
public class EmotionCategoryQueryDto : PagerInfo
|
||||
{
|
||||
|
||||
public string EmotionCategoryName { get; set; }
|
||||
public int IsPopular { get; set; }
|
||||
public string ids { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 表情包分类,数据实体对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-10-28
|
||||
/// </summary>
|
||||
[SugarTable("tb_emotion_category")]
|
||||
public class EmotionCategory : BusinessBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "EmotionCategoryId")]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "emotion_category_id")]
|
||||
public int EmotionCategoryId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "EmotionCategoryGuid")]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "emotion_category_guid")]
|
||||
public long EmotionCategoryGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :父级guid
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "父级guid")]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName = "emotion_category_parent_guid")]
|
||||
public long EmotionCategoryParentGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :祖级guid
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "祖级guid")]
|
||||
[SugarColumn(ColumnName = "emotion_category_ancestral_guid")]
|
||||
public string EmotionCategoryAncestralGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :名称
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "名称")]
|
||||
[SugarColumn(ColumnName = "emotion_category_name")]
|
||||
public string EmotionCategoryName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :图片
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "图片")]
|
||||
[SugarColumn(ColumnName = "emotion_category_img")]
|
||||
public string EmotionCategoryImg { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :是否为热门 (1是 2否)
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "是否为热门 (1是 2否)")]
|
||||
[SugarColumn(ColumnName = "is_popular")]
|
||||
public int IsPopular { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :浏览次数
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "浏览次数")]
|
||||
[SugarColumn(ColumnName = "emotion_category_views_num")]
|
||||
public int EmotionCategoryViewsNum { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :排序
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "排序")]
|
||||
[SugarColumn(ColumnName = "emotion_category_sort")]
|
||||
public int EmotionCategorySort { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<EmotionCategory> Children { get; set; }
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 表情包分类展示对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-10-28
|
||||
/// </summary>
|
||||
public class EmotionCategoryVo
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public int EmotionCategoryId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(IsTreeKey = true)]
|
||||
[EpplusIgnore]
|
||||
public long EmotionCategoryGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :父级guid
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(IsTreeKey = true)]
|
||||
[EpplusIgnore]
|
||||
public long EmotionCategoryParentGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :祖级guid
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(IsTreeKey = true)]
|
||||
[EpplusIgnore]
|
||||
public string EmotionCategoryAncestralGuid { get; set; }
|
||||
|
||||
|
||||
[EpplusTableColumn(Header = "上级名称")]
|
||||
public string ParentName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :名称
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "名称")]
|
||||
public string EmotionCategoryName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :图片
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "图片")]
|
||||
public string EmotionCategoryImg { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :是否为热门
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public int IsPopular { get; set; }
|
||||
|
||||
|
||||
[EpplusTableColumn(Header = "是否为热门")]
|
||||
public string IsPopularName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :浏览次数
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "浏览次数")]
|
||||
public int EmotionCategoryViewsNum { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :排序
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "排序")]
|
||||
public int EmotionCategorySort { get; set; }
|
||||
|
||||
|
||||
|
||||
[EpplusIgnore]
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<EmotionCategoryVo> Children { get; set; }
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 表情包分类仓储
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-10-28
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class EmotionCategoryRepository : BaseRepository<EmotionCategory>
|
||||
{
|
||||
#region 业务逻辑代码
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 表情包分类接口实现类
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-10-28
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IEmotionCategoryService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class EmotionCategoryServiceImpl : BaseService<EmotionCategory>, IEmotionCategoryService
|
||||
{
|
||||
private readonly EmotionCategoryRepository _EmotionCategoryRepository;
|
||||
|
||||
public EmotionCategoryServiceImpl(EmotionCategoryRepository EmotionCategoryRepository)
|
||||
{
|
||||
this._EmotionCategoryRepository = EmotionCategoryRepository;
|
||||
}
|
||||
|
||||
#region 业务逻辑代码
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询表情包分类树形列表
|
||||
/// </summary>
|
||||
public async Task<List<EmotionCategoryVo>> GetEmotionCategoryTreeList(EmotionCategoryQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<EmotionCategory>();
|
||||
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<EmotionCategory>((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);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询表情包分类列表
|
||||
/// </summary>
|
||||
public async Task<List<EmotionCategoryVo>> GetEmotionCategoryList(EmotionCategoryQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件d
|
||||
var predicate = Expressionable.Create<EmotionCategory>();
|
||||
|
||||
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<EmotionCategory>((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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改表情包分类
|
||||
/// </summary>
|
||||
public async Task<string> 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处理
|
||||
/// <summary>
|
||||
/// 数据导入处理
|
||||
/// </summary>
|
||||
public async Task<EmotionCategoryVo> HandleImportData(EmotionCategoryVo EmotionCategory)
|
||||
{
|
||||
return EmotionCategory;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Excel导入
|
||||
/// </summary>
|
||||
public async Task<string> 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}】<span style='color:#27af49'>新增成功!</span><br>";
|
||||
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}】<span style='color:#e6a23c'>更新成功!</span><br>";
|
||||
return editStr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 开启事务
|
||||
var res = await UseTranAsync(async () =>
|
||||
{
|
||||
var addRes = await AddOrUpdateEmotionCategory(EmotionCategory);
|
||||
});
|
||||
//Console.WriteLine(res.IsSuccess);
|
||||
var addStr = $"第 {index} 行 => 表情包分类:【{EmotionCategory.EmotionCategoryName}】<span style='color:#27af49'>新增成功!</span><br>";
|
||||
return addStr;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var errorRes = $"第 {index} 行 => 表情包分类:【{EmotionCategory.EmotionCategoryName}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
|
||||
return errorRes;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Excel数据导出处理
|
||||
/// </summary>
|
||||
public async Task<List<EmotionCategoryVo>> HandleExportData(List<EmotionCategoryVo> data)
|
||||
{
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (item.IsPopular == 1) item.IsPopularName = "是";
|
||||
else item.IsPopularName = "否";
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 表情包分类接口类
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-10-28
|
||||
/// </summary>
|
||||
public interface IEmotionCategoryService : IBaseService<EmotionCategory>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取表情包分类树形列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<EmotionCategoryVo>> GetEmotionCategoryTreeList(EmotionCategoryQueryDto parm);
|
||||
|
||||
/// <summary>
|
||||
/// 获取表情包分类列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<EmotionCategoryVo>> GetEmotionCategoryList(EmotionCategoryQueryDto parm);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改表情包分类
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> AddOrUpdateEmotionCategory(EmotionCategory parm);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 数据导入处理
|
||||
/// </summary>
|
||||
/// <param name="shopVo"></param>
|
||||
/// <returns></returns>
|
||||
Task<EmotionCategoryVo> HandleImportData(EmotionCategoryVo EmotionCategoryVo);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Excel导入
|
||||
/// </summary>
|
||||
/// <param name="EmotionCategory"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> ImportExcel(EmotionCategory EmotionCategory,int index,bool isUpdateSupport,string user);
|
||||
|
||||
/// <summary>
|
||||
/// Excel导出
|
||||
/// </summary>
|
||||
Task<List<EmotionCategoryVo>> HandleExportData(List<EmotionCategoryVo> data);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 表情包分类控制器
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-10-28
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("business/[controller]")]
|
||||
public class EmotionCategoryController : BaseController
|
||||
{
|
||||
private readonly IEmotionCategoryService _EmotionCategoryService;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖注入
|
||||
/// </summary>
|
||||
/// <param name="EmotionCategoryService">表情包分类服务</param>
|
||||
public EmotionCategoryController(IEmotionCategoryService EmotionCategoryService)
|
||||
{
|
||||
_EmotionCategoryService = EmotionCategoryService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取表情包分类树形列表
|
||||
/// </summary>
|
||||
/// <param name="parm">查询参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getEmotionCategoryTreeList")]
|
||||
[ActionPermissionFilter(Permission = "business:emotioncategory:treelist")]
|
||||
public async Task<IActionResult> GetEmotionCategoryList([FromQuery] EmotionCategoryQueryDto parm)
|
||||
{
|
||||
var res = await _EmotionCategoryService.GetEmotionCategoryTreeList(parm);
|
||||
res ??= new List<EmotionCategoryVo>();
|
||||
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改表情包分类
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("addOrUpdateEmotionCategory")]
|
||||
[ActionPermissionFilter(Permission = "business:emotioncategory:addOrUpdate")]
|
||||
[Log(Title = "添加或修改表情包分类", BusinessType = BusinessType.ADDORUPDATE)]
|
||||
public async Task<IActionResult> AddOrUpdateEmotionCategory([FromBody] EmotionCategoryDto parm)
|
||||
{
|
||||
if (parm == null) { throw new CustomException("请求参数错误"); }
|
||||
|
||||
var modal = new EmotionCategory();
|
||||
if (parm.EmotionCategoryId != 0) modal = parm.Adapt<EmotionCategory>().ToUpdate(HttpContext);
|
||||
else modal = parm.Adapt<EmotionCategory>().ToCreate(HttpContext);
|
||||
|
||||
var res = await _EmotionCategoryService.AddOrUpdateEmotionCategory(modal);
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除表情包分类
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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("删除成功!");
|
||||
}
|
||||
|
||||
/// <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:emotioncategory:import")]
|
||||
public async Task<IActionResult> ImportExcel([FromForm(Name = "file")] IFormFile formFile, bool updateSupport)
|
||||
{
|
||||
var isUpdateSupport = updateSupport;
|
||||
IEnumerable<EmotionCategoryVo> parm = ExcelHelper<EmotionCategoryVo>.ImportData(formFile.OpenReadStream());
|
||||
|
||||
var i = 0;
|
||||
var msgList = new List<string>();
|
||||
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}】<span style='color:red'>导入失败!上级类目{item.ParentName}不存在!</span><br>");
|
||||
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<EmotionCategory>().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());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 表情包分类导入模板下载
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("importTemplate")]
|
||||
[Log(Title = "表情包分类模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
List<EmotionCategoryVo> EmotionCategory = new List<EmotionCategoryVo>();
|
||||
MemoryStream stream = new MemoryStream();
|
||||
|
||||
// 示例数据
|
||||
var allValues = new List<List<string>>();
|
||||
var values = new List<string>() { "", "可爱loopy系列", "http://localhost:8888/Uploads/EmotionCategory/20231028/80EA7BE112F962E8.jpg", "是", "0", "1" };
|
||||
var values2 = new List<string>() { "可爱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}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出表情包分类
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "表情包分类导出", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||||
[HttpGet("exportEmotionCategory")]
|
||||
[ActionPermissionFilter(Permission = "business:emotioncategory:export")]
|
||||
public async Task<IActionResult> 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<EmotionCategoryVo>();
|
||||
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 });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -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": {
|
||||
|
Loading…
Reference in New Issue
Block a user