feat 初始化店铺商品类目
This commit is contained in:
parent
bfb6836568
commit
18ddd54bb1
@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys;
|
||||||
|
|
||||||
|
namespace ARW.Model.Dto.Business.GoodsManager.ShopGoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 店铺商品类目输入对象
|
||||||
|
///
|
||||||
|
/// @author 黎文豪
|
||||||
|
/// @date 2023-06-15
|
||||||
|
/// </summary>
|
||||||
|
public class ShopGoodsCategoryDto
|
||||||
|
{
|
||||||
|
|
||||||
|
public int ShopGoodsCategoryId { get; set; }
|
||||||
|
|
||||||
|
public long ShopGoodsCategoryGuid { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "店铺guid不能为空")]
|
||||||
|
public long ShopGuid { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "父级guid不能为空")]
|
||||||
|
public long ShopGoodsCategoryParentGuid { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "祖级guid不能为空")]
|
||||||
|
public string ShopGoodsCategoryAncestralGuid { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "名称不能为空")]
|
||||||
|
public string ShopGoodsCategoryName { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "显示状态不能为空")]
|
||||||
|
public int ShopGoodsCategoryDisplayStatus { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "排序不能为空")]
|
||||||
|
public int ShopGoodsCategorySort { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 店铺商品类目查询对象
|
||||||
|
///
|
||||||
|
/// @author 黎文豪
|
||||||
|
/// @date 2023-06-15
|
||||||
|
/// </summary>
|
||||||
|
public class ShopGoodsCategoryQueryDto : PagerInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
public string ShopGoodsCategoryName { get; set; }
|
||||||
|
|
||||||
|
public int? ShopGoodsCategoryDisplayStatus { get; set; }
|
||||||
|
|
||||||
|
public string ids { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using SqlSugar;
|
||||||
|
using OfficeOpenXml.Attributes;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 店铺商品类目,数据实体对象
|
||||||
|
///
|
||||||
|
/// @author 黎文豪
|
||||||
|
/// @date 2023-06-15
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("tb_shop_goods_category")]
|
||||||
|
public class ShopGoodsCategory : BusinessBase
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "ShopGoodsCategoryId")]
|
||||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "shop_goods_category_id")]
|
||||||
|
public int ShopGoodsCategoryId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "ShopGoodsCategoryGuid")]
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "shop_goods_category_guid")]
|
||||||
|
public long ShopGoodsCategoryGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :店铺guid
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "店铺guid")]
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[SugarColumn(ColumnName = "shop_guid")]
|
||||||
|
public long ShopGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :父级guid
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "父级guid")]
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[SugarColumn(ColumnName = "shop_goods_category_parent_guid")]
|
||||||
|
public long ShopGoodsCategoryParentGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :祖级guid
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "祖级guid")]
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[SugarColumn(ColumnName = "shop_goods_category_ancestral_guid")]
|
||||||
|
public string ShopGoodsCategoryAncestralGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :名称
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "名称")]
|
||||||
|
[SugarColumn(ColumnName = "shop_goods_category_name")]
|
||||||
|
public string ShopGoodsCategoryName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :显示状态
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "显示状态")]
|
||||||
|
[SugarColumn(ColumnName = "shop_goods_category_display_status")]
|
||||||
|
public int ShopGoodsCategoryDisplayStatus { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :排序
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "排序")]
|
||||||
|
[SugarColumn(ColumnName = "shop_goods_category_sort")]
|
||||||
|
public int ShopGoodsCategorySort { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
public List<ShopGoodsCategory> Children { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using OfficeOpenXml.Attributes;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ARW.Model.Vo.Business.GoodsManager.ShopGoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 店铺商品类目展示对象
|
||||||
|
///
|
||||||
|
/// @author 黎文豪
|
||||||
|
/// @date 2023-06-15
|
||||||
|
/// </summary>
|
||||||
|
public class ShopGoodsCategoryVo
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :
|
||||||
|
/// </summary>
|
||||||
|
[EpplusIgnore]
|
||||||
|
public int ShopGoodsCategoryId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :
|
||||||
|
/// </summary>
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[SugarColumn(IsTreeKey = true)]
|
||||||
|
[EpplusIgnore]
|
||||||
|
public long ShopGoodsCategoryGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :店铺guid
|
||||||
|
/// </summary>
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[SugarColumn(IsTreeKey = true)]
|
||||||
|
[EpplusTableColumn(Header = "店铺guid")]
|
||||||
|
public long ShopGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :父级guid
|
||||||
|
/// </summary>
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[SugarColumn(IsTreeKey = true)]
|
||||||
|
[EpplusTableColumn(Header = "父级guid")]
|
||||||
|
public long ShopGoodsCategoryParentGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :祖级guid
|
||||||
|
/// </summary>
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[SugarColumn(IsTreeKey = true)]
|
||||||
|
[EpplusTableColumn(Header = "祖级guid")]
|
||||||
|
public string ShopGoodsCategoryAncestralGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :名称
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "名称")]
|
||||||
|
public string ShopGoodsCategoryName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :显示状态
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "显示状态")]
|
||||||
|
public int ShopGoodsCategoryDisplayStatus { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :排序
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "排序")]
|
||||||
|
public int ShopGoodsCategorySort { get; set; }
|
||||||
|
|
||||||
|
[EpplusIgnore]
|
||||||
|
public string ParentName { get; set; }
|
||||||
|
|
||||||
|
[EpplusIgnore]
|
||||||
|
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
public List<ShopGoodsCategoryVo> Children { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using Infrastructure.Attribute;
|
||||||
|
using ARW.Repository.System;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys;
|
||||||
|
|
||||||
|
namespace ARW.Repository.Business.GoodsManager.ShopGoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 店铺商品类目仓储
|
||||||
|
///
|
||||||
|
/// @author 黎文豪
|
||||||
|
/// @date 2023-06-15
|
||||||
|
/// </summary>
|
||||||
|
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||||
|
public class ShopGoodsCategoryRepository : BaseRepository<ShopGoodsCategory>
|
||||||
|
{
|
||||||
|
#region 业务逻辑代码
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,218 @@
|
|||||||
|
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.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using ARW.Service.Business.IBusinessService.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using ARW.Model.Dto.Business.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using ARW.Model.Vo.Business.GoodsManager.ShopGoodsCategorys;
|
||||||
|
|
||||||
|
namespace ARW.Service.Business.BusinessService.GoodsManager.ShopGoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 店铺商品类目接口实现类
|
||||||
|
///
|
||||||
|
/// @author 黎文豪
|
||||||
|
/// @date 2023-06-15
|
||||||
|
/// </summary>
|
||||||
|
[AppService(ServiceType = typeof(IShopGoodsCategoryService), ServiceLifetime = LifeTime.Transient)]
|
||||||
|
public class ShopGoodsCategoryServiceImpl : BaseService<ShopGoodsCategory>, IShopGoodsCategoryService
|
||||||
|
{
|
||||||
|
private readonly ShopGoodsCategoryRepository _ShopGoodsCategoryRepository;
|
||||||
|
|
||||||
|
public ShopGoodsCategoryServiceImpl(ShopGoodsCategoryRepository ShopGoodsCategoryRepository)
|
||||||
|
{
|
||||||
|
this._ShopGoodsCategoryRepository = ShopGoodsCategoryRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 业务逻辑代码
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询店铺商品类目树形列表
|
||||||
|
/// </summary>
|
||||||
|
public async Task<List<ShopGoodsCategoryVo>> GetShopGoodsCategoryTreeList(ShopGoodsCategoryQueryDto parm)
|
||||||
|
{
|
||||||
|
//开始拼装查询条件
|
||||||
|
var predicate = Expressionable.Create<ShopGoodsCategory>();
|
||||||
|
|
||||||
|
predicate = predicate.AndIF(parm.ShopGoodsCategoryDisplayStatus != null, s => s.ShopGoodsCategoryDisplayStatus == parm.ShopGoodsCategoryDisplayStatus);
|
||||||
|
var query = _ShopGoodsCategoryRepository
|
||||||
|
.Queryable()
|
||||||
|
.LeftJoin<ShopGoodsCategory>((s, c) => s.ShopGoodsCategoryParentGuid == c.ShopGoodsCategoryGuid)
|
||||||
|
.Where(predicate.ToExpression())
|
||||||
|
.OrderBy(s => s.ShopGoodsCategorySort,OrderByType.Asc)
|
||||||
|
.Select((s,c) => new ShopGoodsCategoryVo
|
||||||
|
{
|
||||||
|
ShopGoodsCategoryId = s.ShopGoodsCategoryId,
|
||||||
|
ShopGoodsCategoryGuid = s.ShopGoodsCategoryGuid,
|
||||||
|
ShopGuid = s.ShopGuid,
|
||||||
|
ShopGoodsCategoryParentGuid = s.ShopGoodsCategoryParentGuid,
|
||||||
|
ShopGoodsCategoryAncestralGuid = s.ShopGoodsCategoryAncestralGuid,
|
||||||
|
ShopGoodsCategoryName = s.ShopGoodsCategoryName,
|
||||||
|
ShopGoodsCategoryDisplayStatus = s.ShopGoodsCategoryDisplayStatus,
|
||||||
|
ShopGoodsCategorySort = s.ShopGoodsCategorySort,
|
||||||
|
ParentName = c.ShopGoodsCategoryName,
|
||||||
|
});
|
||||||
|
|
||||||
|
return await query.ToTreeAsync(it => it.Children, it => it.ShopGoodsCategoryParentGuid, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询店铺商品类目列表
|
||||||
|
/// </summary>
|
||||||
|
public async Task<List<ShopGoodsCategoryVo>> GetShopGoodsCategoryList(ShopGoodsCategoryQueryDto parm)
|
||||||
|
{
|
||||||
|
//开始拼装查询条件d
|
||||||
|
var predicate = Expressionable.Create<ShopGoodsCategory>();
|
||||||
|
|
||||||
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.ShopGoodsCategoryName), s => s.ShopGoodsCategoryName.Contains(parm.ShopGoodsCategoryName));
|
||||||
|
predicate = predicate.AndIF(parm.ShopGoodsCategoryDisplayStatus != null, s => s.ShopGoodsCategoryDisplayStatus == parm.ShopGoodsCategoryDisplayStatus);
|
||||||
|
var query = _ShopGoodsCategoryRepository
|
||||||
|
.Queryable()
|
||||||
|
.Where(predicate.ToExpression())
|
||||||
|
.OrderBy(s => s.ShopGoodsCategorySort,OrderByType.Asc)
|
||||||
|
.Select(s => new ShopGoodsCategoryVo
|
||||||
|
{
|
||||||
|
ShopGoodsCategoryId = s.ShopGoodsCategoryId,
|
||||||
|
ShopGoodsCategoryGuid = s.ShopGoodsCategoryGuid,
|
||||||
|
ShopGuid = s.ShopGuid,
|
||||||
|
ShopGoodsCategoryParentGuid = s.ShopGoodsCategoryParentGuid,
|
||||||
|
ShopGoodsCategoryAncestralGuid = s.ShopGoodsCategoryAncestralGuid,
|
||||||
|
ShopGoodsCategoryName = s.ShopGoodsCategoryName,
|
||||||
|
ShopGoodsCategoryDisplayStatus = s.ShopGoodsCategoryDisplayStatus,
|
||||||
|
ShopGoodsCategorySort = s.ShopGoodsCategorySort,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return await query.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加或修改店铺商品类目
|
||||||
|
/// </summary>
|
||||||
|
public async Task<string> AddOrUpdateShopGoodsCategory(ShopGoodsCategory model)
|
||||||
|
{
|
||||||
|
if (model.ShopGoodsCategoryId != 0)
|
||||||
|
{
|
||||||
|
var type = await _ShopGoodsCategoryRepository.GetListAsync(s => s.ShopGoodsCategoryParentGuid == model.ShopGoodsCategoryGuid);
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
foreach (var item in type)
|
||||||
|
{
|
||||||
|
if (model.ShopGoodsCategoryParentGuid == item.ShopGoodsCategoryGuid) throw new CustomException("上级菜单不能选择自己的子级!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (model.ShopGoodsCategoryParentGuid == model.ShopGoodsCategoryGuid) throw new CustomException("上级菜单不能选择与当前菜单一样的!");
|
||||||
|
var response = await _ShopGoodsCategoryRepository.UpdateAsync(model);
|
||||||
|
return "修改成功!";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var info = _ShopGoodsCategoryRepository.GetFirst(it => it.ShopGoodsCategoryGuid == model.ShopGoodsCategoryParentGuid);
|
||||||
|
model.ShopGoodsCategoryAncestralGuid = "0";
|
||||||
|
if (info != null) model.ShopGoodsCategoryAncestralGuid = info.ShopGoodsCategoryAncestralGuid + "," + model.ShopGoodsCategoryParentGuid;
|
||||||
|
|
||||||
|
var response = await _ShopGoodsCategoryRepository.InsertReturnSnowflakeIdAsync(model);
|
||||||
|
return "添加成功!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Excel处理
|
||||||
|
/// <summary>
|
||||||
|
/// 数据导入处理
|
||||||
|
/// </summary>
|
||||||
|
public async Task<ShopGoodsCategoryVo> HandleImportData(ShopGoodsCategoryVo ShopGoodsCategory)
|
||||||
|
{
|
||||||
|
return ShopGoodsCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Excel导入
|
||||||
|
/// </summary>
|
||||||
|
public async Task<string> ImportExcel(ShopGoodsCategory ShopGoodsCategory,int index,bool isUpdateSupport,string user)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 空值判断
|
||||||
|
// if (ShopGoodsCategory.ShopGoodsCategoryId == null) throw new CustomException("店铺商品类目不能为空");
|
||||||
|
|
||||||
|
if (isUpdateSupport)
|
||||||
|
{
|
||||||
|
// 判断唯一值
|
||||||
|
var model = await GetFirstAsync(s => s.ShopGoodsCategoryId == ShopGoodsCategory.ShopGoodsCategoryId);
|
||||||
|
|
||||||
|
// 如果为空就新增数据
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
// 开启事务
|
||||||
|
var res = await UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
var addRes = await AddOrUpdateShopGoodsCategory(ShopGoodsCategory);
|
||||||
|
});
|
||||||
|
var addStr = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryId}】<span style='color:#27af49'>新增成功!</span><br>";
|
||||||
|
return addStr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 如果有数据就进行修改
|
||||||
|
// 开启事务
|
||||||
|
await UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
ShopGoodsCategory.ShopGoodsCategoryId = model.ShopGoodsCategoryId;
|
||||||
|
ShopGoodsCategory.ShopGoodsCategoryGuid = model.ShopGoodsCategoryGuid;
|
||||||
|
ShopGoodsCategory.Update_by = user;
|
||||||
|
ShopGoodsCategory.Update_time = DateTime.Now;
|
||||||
|
var editRes = await AddOrUpdateShopGoodsCategory(ShopGoodsCategory);
|
||||||
|
});
|
||||||
|
var editStr = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryId}】<span style='color:#e6a23c'>更新成功!</span><br>";
|
||||||
|
return editStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// 开启事务
|
||||||
|
var res = await UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
var addRes = await AddOrUpdateShopGoodsCategory(ShopGoodsCategory);
|
||||||
|
});
|
||||||
|
//Console.WriteLine(res.IsSuccess);
|
||||||
|
var addStr = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryId}】<span style='color:#27af49'>新增成功!</span><br>";
|
||||||
|
return addStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var errorRes = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryId}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
|
||||||
|
return errorRes;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Excel数据导出处理
|
||||||
|
/// </summary>
|
||||||
|
public async Task<List<ShopGoodsCategoryVo>> HandleExportData(List<ShopGoodsCategoryVo> data)
|
||||||
|
{
|
||||||
|
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.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using ARW.Model.Vo.Business.GoodsManager.ShopGoodsCategorys;
|
||||||
|
|
||||||
|
namespace ARW.Service.Business.IBusinessService.GoodsManager.ShopGoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 店铺商品类目接口类
|
||||||
|
///
|
||||||
|
/// @author 黎文豪
|
||||||
|
/// @date 2023-06-15
|
||||||
|
/// </summary>
|
||||||
|
public interface IShopGoodsCategoryService : IBaseService<ShopGoodsCategory>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取店铺商品类目树形列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<List<ShopGoodsCategoryVo>> GetShopGoodsCategoryTreeList(ShopGoodsCategoryQueryDto parm);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取店铺商品类目列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<List<ShopGoodsCategoryVo>> GetShopGoodsCategoryList(ShopGoodsCategoryQueryDto parm);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加或修改店铺商品类目
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> AddOrUpdateShopGoodsCategory(ShopGoodsCategory parm);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据导入处理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="shopVo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ShopGoodsCategoryVo> HandleImportData(ShopGoodsCategoryVo ShopGoodsCategoryVo);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Excel导入
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="shopVo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> ImportExcel(ShopGoodsCategory ShopGoodsCategory,int index,bool isUpdateSupport,string user);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Excel导出
|
||||||
|
/// </summary>
|
||||||
|
Task<List<ShopGoodsCategoryVo>> HandleExportData(List<ShopGoodsCategoryVo> data);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,195 @@
|
|||||||
|
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.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using ARW.Service.Business.IBusinessService.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using ARW.Admin.WebApi.Controllers;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using ARW.Model.Vo.Business.GoodsManager.ShopGoodsCategorys;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using ARW.Admin.WebApi.Framework;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ARW.WebApi.Controllers.Business.GoodsManager.ShopGoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 店铺商品类目控制器
|
||||||
|
///
|
||||||
|
/// @author 黎文豪
|
||||||
|
/// @date 2023-06-15
|
||||||
|
/// </summary>
|
||||||
|
[Verify]
|
||||||
|
[Route("business/[controller]")]
|
||||||
|
public class ShopGoodsCategoryController : BaseController
|
||||||
|
{
|
||||||
|
private readonly IShopGoodsCategoryService _ShopGoodsCategoryService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 依赖注入
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ShopGoodsCategoryService">店铺商品类目服务</param>
|
||||||
|
public ShopGoodsCategoryController(IShopGoodsCategoryService ShopGoodsCategoryService)
|
||||||
|
{
|
||||||
|
_ShopGoodsCategoryService = ShopGoodsCategoryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取店铺商品类目树形列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm">查询参数</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("getShopGoodsCategoryTreeList")]
|
||||||
|
[ActionPermissionFilter(Permission = "business:shopgoodscategory:treelist")]
|
||||||
|
public async Task<IActionResult> GetShopGoodsCategoryList([FromQuery] ShopGoodsCategoryQueryDto parm)
|
||||||
|
{
|
||||||
|
var res = await _ShopGoodsCategoryService.GetShopGoodsCategoryTreeList(parm);
|
||||||
|
res ??= new List<ShopGoodsCategoryVo>();
|
||||||
|
|
||||||
|
return SUCCESS(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加或修改店铺商品类目
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("addOrUpdateShopGoodsCategory")]
|
||||||
|
[ActionPermissionFilter(Permission = "business:shopgoodscategory:addOrUpdate")]
|
||||||
|
[Log(Title = "添加或修改店铺商品类目", BusinessType = BusinessType.ADDORUPDATE)]
|
||||||
|
public async Task<IActionResult> AddOrUpdateShopGoodsCategory([FromBody] ShopGoodsCategoryDto parm)
|
||||||
|
{
|
||||||
|
if (parm == null) { throw new CustomException("请求参数错误"); }
|
||||||
|
|
||||||
|
var modal = new ShopGoodsCategory();
|
||||||
|
if (parm.ShopGoodsCategoryId != 0) modal = parm.Adapt<ShopGoodsCategory>().ToUpdate(HttpContext);
|
||||||
|
else modal = parm.Adapt<ShopGoodsCategory>().ToCreate(HttpContext);
|
||||||
|
|
||||||
|
var res = await _ShopGoodsCategoryService.AddOrUpdateShopGoodsCategory(modal);
|
||||||
|
return SUCCESS(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除店铺商品类目
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpDelete("{ids}")]
|
||||||
|
[ActionPermissionFilter(Permission = "business:shopgoodscategory: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 = _ShopGoodsCategoryService.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:business:shopgoodscategory:import")]
|
||||||
|
public async Task<IActionResult> ImportExcel([FromForm(Name = "file")] IFormFile formFile, bool updateSupport)
|
||||||
|
{
|
||||||
|
var isUpdateSupport = updateSupport;
|
||||||
|
IEnumerable<ShopGoodsCategoryVo> parm = ExcelHelper<ShopGoodsCategoryVo>.ImportData(formFile.OpenReadStream());
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
var msgList = new List<string>();
|
||||||
|
foreach (ShopGoodsCategoryVo item in parm)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
var ShopGoodsCategory = await _ShopGoodsCategoryService.HandleImportData(item);
|
||||||
|
var modal = ShopGoodsCategory.Adapt<ShopGoodsCategory>().ToCreate(HttpContext);
|
||||||
|
var user = JwtUtil.GetLoginUser(App.HttpContext).UserName;
|
||||||
|
var msg = await _ShopGoodsCategoryService.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<ShopGoodsCategoryVo> ShopGoodsCategory = new List<ShopGoodsCategoryVo>();
|
||||||
|
MemoryStream stream = new MemoryStream();
|
||||||
|
|
||||||
|
// 示例数据
|
||||||
|
var allValues = new List<List<string>>();
|
||||||
|
var values = new List<string>() { "111", "222", "333" };
|
||||||
|
var values2 = new List<string>() { "444", "555", "666" };
|
||||||
|
allValues.Add(values);
|
||||||
|
allValues.Add(values2);
|
||||||
|
string sFileName = DownloadImportTemplate(ShopGoodsCategory, 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("exportShopGoodsCategory")]
|
||||||
|
[ActionPermissionFilter(Permission = "business:shopgoodscategory:export")]
|
||||||
|
public async Task<IActionResult> ExportExcel([FromQuery] ShopGoodsCategoryQueryDto parm)
|
||||||
|
{
|
||||||
|
var list = await _ShopGoodsCategoryService.GetShopGoodsCategoryList(parm);
|
||||||
|
var data = list;
|
||||||
|
|
||||||
|
// 选中数据
|
||||||
|
if (!string.IsNullOrEmpty(parm.ids))
|
||||||
|
{
|
||||||
|
int[] idsArr = Tools.SpitIntArrary(parm.ids);
|
||||||
|
var selectDataList = new List<ShopGoodsCategoryVo>();
|
||||||
|
foreach (var item in idsArr)
|
||||||
|
{
|
||||||
|
var select_data = data.Where(s => s.ShopGoodsCategoryId == item).First();
|
||||||
|
selectDataList.Add(select_data);
|
||||||
|
|
||||||
|
// 查看当前数据有没有子级
|
||||||
|
var newShopGoodsCategorys = data.FindAll(delegate (ShopGoodsCategoryVo shopGoodsCategory)
|
||||||
|
{
|
||||||
|
string[] parentShopGoodsCategoryId = shopGoodsCategory.ShopGoodsCategoryAncestralGuid.Split(",", StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
return parentShopGoodsCategoryId.Contains(select_data.ShopGoodsCategoryGuid.ToString());
|
||||||
|
});
|
||||||
|
string[] shopGoodsCategoryArr = newShopGoodsCategorys.Select(x => x.ShopGoodsCategoryGuid.ToString()).ToArray();
|
||||||
|
var ancestorArr = data.Where(s => shopGoodsCategoryArr.Contains(s.ShopGoodsCategoryGuid.ToString())).ToList();
|
||||||
|
selectDataList.AddRange(ancestorArr);
|
||||||
|
}
|
||||||
|
data = selectDataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 导出数据处理
|
||||||
|
var handleData = await _ShopGoodsCategoryService.HandleExportData(data);
|
||||||
|
|
||||||
|
string sFileName = ExportExcel(handleData, "ShopGoodsCategory", "店铺商品类目列表");
|
||||||
|
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@
|
|||||||
* @LastEditTime: (${replaceDto.AddTime})
|
* @LastEditTime: (${replaceDto.AddTime})
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<el-dialog title="导入" v-model="modelValue" width="400px" @closed="closeDialog">
|
<el-dialog title="导入" v-model="props.modelValue" width="400px" @closed="closeDialog">
|
||||||
<el-upload
|
<el-upload
|
||||||
name="file"
|
name="file"
|
||||||
ref="uploadRef"
|
ref="uploadRef"
|
||||||
|
Loading…
Reference in New Issue
Block a user