diff --git a/ARW.Model/Dto/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryDto.cs b/ARW.Model/Dto/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryDto.cs new file mode 100644 index 0000000..7d04610 --- /dev/null +++ b/ARW.Model/Dto/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryDto.cs @@ -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 +{ + /// + /// 店铺商品类目输入对象 + /// + /// @author 黎文豪 + /// @date 2023-06-15 + /// + 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; } + + + + + + } + + + /// + /// 店铺商品类目查询对象 + /// + /// @author 黎文豪 + /// @date 2023-06-15 + /// + public class ShopGoodsCategoryQueryDto : PagerInfo + { + + public string ShopGoodsCategoryName { get; set; } + + public int? ShopGoodsCategoryDisplayStatus { get; set; } + + public string ids { get; set; } + } + + + + +} diff --git a/ARW.Model/Models/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategory.cs b/ARW.Model/Models/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategory.cs new file mode 100644 index 0000000..97a72cb --- /dev/null +++ b/ARW.Model/Models/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategory.cs @@ -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 +{ + /// + /// 店铺商品类目,数据实体对象 + /// + /// @author 黎文豪 + /// @date 2023-06-15 + /// + [SugarTable("tb_shop_goods_category")] + public class ShopGoodsCategory : BusinessBase + { + + /// + /// 描述 : + /// 空值 : false + /// + [EpplusTableColumn(Header = "ShopGoodsCategoryId")] + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "shop_goods_category_id")] + public int ShopGoodsCategoryId { get; set; } + + + /// + /// 描述 : + /// 空值 : false + /// + [EpplusTableColumn(Header = "ShopGoodsCategoryGuid")] + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "shop_goods_category_guid")] + public long ShopGoodsCategoryGuid { get; set; } + + + /// + /// 描述 :店铺guid + /// 空值 : false + /// + [EpplusTableColumn(Header = "店铺guid")] + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(ColumnName = "shop_guid")] + public long ShopGuid { get; set; } + + + /// + /// 描述 :父级guid + /// 空值 : false + /// + [EpplusTableColumn(Header = "父级guid")] + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(ColumnName = "shop_goods_category_parent_guid")] + public long ShopGoodsCategoryParentGuid { get; set; } + + + /// + /// 描述 :祖级guid + /// 空值 : false + /// + [EpplusTableColumn(Header = "祖级guid")] + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(ColumnName = "shop_goods_category_ancestral_guid")] + public string ShopGoodsCategoryAncestralGuid { get; set; } + + + /// + /// 描述 :名称 + /// 空值 : false + /// + [EpplusTableColumn(Header = "名称")] + [SugarColumn(ColumnName = "shop_goods_category_name")] + public string ShopGoodsCategoryName { get; set; } + + + /// + /// 描述 :显示状态 + /// 空值 : false + /// + [EpplusTableColumn(Header = "显示状态")] + [SugarColumn(ColumnName = "shop_goods_category_display_status")] + public int ShopGoodsCategoryDisplayStatus { get; set; } + + + /// + /// 描述 :排序 + /// 空值 : false + /// + [EpplusTableColumn(Header = "排序")] + [SugarColumn(ColumnName = "shop_goods_category_sort")] + public int ShopGoodsCategorySort { 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/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryVo.cs b/ARW.Model/Vo/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryVo.cs new file mode 100644 index 0000000..8acd3e7 --- /dev/null +++ b/ARW.Model/Vo/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryVo.cs @@ -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 +{ + /// + /// 店铺商品类目展示对象 + /// + /// @author 黎文豪 + /// @date 2023-06-15 + /// + public class ShopGoodsCategoryVo + { + + + /// + /// 描述 : + /// + [EpplusIgnore] + public int ShopGoodsCategoryId { get; set; } + + + /// + /// 描述 : + /// + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(IsTreeKey = true)] + [EpplusIgnore] + public long ShopGoodsCategoryGuid { get; set; } + + + /// + /// 描述 :店铺guid + /// + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(IsTreeKey = true)] + [EpplusTableColumn(Header = "店铺guid")] + public long ShopGuid { get; set; } + + + /// + /// 描述 :父级guid + /// + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(IsTreeKey = true)] + [EpplusTableColumn(Header = "父级guid")] + public long ShopGoodsCategoryParentGuid { get; set; } + + + /// + /// 描述 :祖级guid + /// + [JsonConverter(typeof(ValueToStringConverter))] + [SugarColumn(IsTreeKey = true)] + [EpplusTableColumn(Header = "祖级guid")] + public string ShopGoodsCategoryAncestralGuid { get; set; } + + + /// + /// 描述 :名称 + /// + [EpplusTableColumn(Header = "名称")] + public string ShopGoodsCategoryName { get; set; } + + + /// + /// 描述 :显示状态 + /// + [EpplusTableColumn(Header = "显示状态")] + public int ShopGoodsCategoryDisplayStatus { get; set; } + + + /// + /// 描述 :排序 + /// + [EpplusTableColumn(Header = "排序")] + public int ShopGoodsCategorySort { get; set; } + + [EpplusIgnore] + public string ParentName { get; set; } + + [EpplusIgnore] + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + [SugarColumn(IsIgnore = true)] + public List Children { get; set; } + } +} diff --git a/ARW.Repository/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryRepository.cs b/ARW.Repository/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryRepository.cs new file mode 100644 index 0000000..c74d566 --- /dev/null +++ b/ARW.Repository/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryRepository.cs @@ -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 +{ + /// + /// 店铺商品类目仓储 + /// + /// @author 黎文豪 + /// @date 2023-06-15 + /// + [AppService(ServiceLifetime = LifeTime.Transient)] + public class ShopGoodsCategoryRepository : BaseRepository + { + #region 业务逻辑代码 + #endregion + } +} \ No newline at end of file diff --git a/ARW.Service/Business/BusinessService/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryService.cs b/ARW.Service/Business/BusinessService/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryService.cs new file mode 100644 index 0000000..864c9c7 --- /dev/null +++ b/ARW.Service/Business/BusinessService/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryService.cs @@ -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 +{ + /// + /// 店铺商品类目接口实现类 + /// + /// @author 黎文豪 + /// @date 2023-06-15 + /// + [AppService(ServiceType = typeof(IShopGoodsCategoryService), ServiceLifetime = LifeTime.Transient)] + public class ShopGoodsCategoryServiceImpl : BaseService, IShopGoodsCategoryService + { + private readonly ShopGoodsCategoryRepository _ShopGoodsCategoryRepository; + + public ShopGoodsCategoryServiceImpl(ShopGoodsCategoryRepository ShopGoodsCategoryRepository) + { + this._ShopGoodsCategoryRepository = ShopGoodsCategoryRepository; + } + + #region 业务逻辑代码 + + + /// + /// 查询店铺商品类目树形列表 + /// + public async Task> GetShopGoodsCategoryTreeList(ShopGoodsCategoryQueryDto parm) + { + //开始拼装查询条件 + var predicate = Expressionable.Create(); + + predicate = predicate.AndIF(parm.ShopGoodsCategoryDisplayStatus != null, s => s.ShopGoodsCategoryDisplayStatus == parm.ShopGoodsCategoryDisplayStatus); + var query = _ShopGoodsCategoryRepository + .Queryable() + .LeftJoin((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); + } + + + /// + /// 查询店铺商品类目列表 + /// + public async Task> GetShopGoodsCategoryList(ShopGoodsCategoryQueryDto parm) + { + //开始拼装查询条件d + var predicate = Expressionable.Create(); + + 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(); + } + + /// + /// 添加或修改店铺商品类目 + /// + public async Task 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处理 + /// + /// 数据导入处理 + /// + public async Task HandleImportData(ShopGoodsCategoryVo ShopGoodsCategory) + { + return ShopGoodsCategory; + } + + + /// + /// Excel导入 + /// + public async Task 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}】新增成功!
"; + 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}】更新成功!
"; + return editStr; + } + } + else{ + // 开启事务 + var res = await UseTranAsync(async () => + { + var addRes = await AddOrUpdateShopGoodsCategory(ShopGoodsCategory); + }); + //Console.WriteLine(res.IsSuccess); + var addStr = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryId}】新增成功!
"; + return addStr; + } + } + catch (Exception ex) + { + var errorRes = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryId}】导入失败!{ex.Message}
"; + return errorRes; + throw; + } + } + + + + /// + /// Excel数据导出处理 + /// + public async Task> HandleExportData(List data) + { + return data; + } + + #endregion + + + +#endregion + + } +} diff --git a/ARW.Service/Business/IBusinessService/GoodsManager/ShopGoodsCategorys/IShopGoodsCategoryService.cs b/ARW.Service/Business/IBusinessService/GoodsManager/ShopGoodsCategorys/IShopGoodsCategoryService.cs new file mode 100644 index 0000000..a486c6a --- /dev/null +++ b/ARW.Service/Business/IBusinessService/GoodsManager/ShopGoodsCategorys/IShopGoodsCategoryService.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.GoodsManager.ShopGoodsCategorys; +using ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys; +using ARW.Model.Vo.Business.GoodsManager.ShopGoodsCategorys; + +namespace ARW.Service.Business.IBusinessService.GoodsManager.ShopGoodsCategorys +{ + /// + /// 店铺商品类目接口类 + /// + /// @author 黎文豪 + /// @date 2023-06-15 + /// + public interface IShopGoodsCategoryService : IBaseService + { + /// + /// 获取店铺商品类目树形列表 + /// + /// + /// + Task> GetShopGoodsCategoryTreeList(ShopGoodsCategoryQueryDto parm); + + /// + /// 获取店铺商品类目列表 + /// + /// + /// + Task> GetShopGoodsCategoryList(ShopGoodsCategoryQueryDto parm); + + + /// + /// 添加或修改店铺商品类目 + /// + /// + /// + Task AddOrUpdateShopGoodsCategory(ShopGoodsCategory parm); + + + /// + /// 数据导入处理 + /// + /// + /// + Task HandleImportData(ShopGoodsCategoryVo ShopGoodsCategoryVo); + + + /// + /// Excel导入 + /// + /// + /// + Task ImportExcel(ShopGoodsCategory ShopGoodsCategory,int index,bool isUpdateSupport,string user); + + /// + /// Excel导出 + /// + Task> HandleExportData(List data); + + + } +} diff --git a/ARW.WebApi/Controllers/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryController.cs b/ARW.WebApi/Controllers/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryController.cs new file mode 100644 index 0000000..6974329 --- /dev/null +++ b/ARW.WebApi/Controllers/Business/GoodsManager/ShopGoodsCategorys/ShopGoodsCategoryController.cs @@ -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 +{ + /// + /// 店铺商品类目控制器 + /// + /// @author 黎文豪 + /// @date 2023-06-15 + /// + [Verify] + [Route("business/[controller]")] + public class ShopGoodsCategoryController : BaseController + { + private readonly IShopGoodsCategoryService _ShopGoodsCategoryService; + + /// + /// 依赖注入 + /// + /// 店铺商品类目服务 + public ShopGoodsCategoryController(IShopGoodsCategoryService ShopGoodsCategoryService) + { + _ShopGoodsCategoryService = ShopGoodsCategoryService; + } + + + /// + /// 获取店铺商品类目树形列表 + /// + /// 查询参数 + /// + [HttpGet("getShopGoodsCategoryTreeList")] + [ActionPermissionFilter(Permission = "business:shopgoodscategory:treelist")] + public async Task GetShopGoodsCategoryList([FromQuery] ShopGoodsCategoryQueryDto parm) + { + var res = await _ShopGoodsCategoryService.GetShopGoodsCategoryTreeList(parm); + res ??= new List(); + + return SUCCESS(res); + } + + /// + /// 添加或修改店铺商品类目 + /// + /// + /// + [HttpPost("addOrUpdateShopGoodsCategory")] + [ActionPermissionFilter(Permission = "business:shopgoodscategory:addOrUpdate")] + [Log(Title = "添加或修改店铺商品类目", BusinessType = BusinessType.ADDORUPDATE)] + public async Task AddOrUpdateShopGoodsCategory([FromBody] ShopGoodsCategoryDto parm) + { + if (parm == null) { throw new CustomException("请求参数错误"); } + + var modal = new ShopGoodsCategory(); + if (parm.ShopGoodsCategoryId != 0) modal = parm.Adapt().ToUpdate(HttpContext); + else modal = parm.Adapt().ToCreate(HttpContext); + + var res = await _ShopGoodsCategoryService.AddOrUpdateShopGoodsCategory(modal); + return SUCCESS(res); + } + + /// + /// 删除店铺商品类目 + /// + /// + [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("删除成功!"); + } + + /// + /// 导入店铺商品类目 + /// + /// 使用IFromFile必须使用name属性否则获取不到文件 + /// 是否需要更新 + /// + [HttpPost("importData")] + [Log(Title = "店铺商品类目导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)] + [ActionPermissionFilter(Permission = "business:business:shopgoodscategory: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 (ShopGoodsCategoryVo item in parm) + { + i++; + var ShopGoodsCategory = await _ShopGoodsCategoryService.HandleImportData(item); + var modal = ShopGoodsCategory.Adapt().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()); + } + + + /// + /// 店铺商品类目导入模板下载 + /// + /// + [HttpGet("importTemplate")] + [Log(Title = "店铺商品类目模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = false, IsSaveResponseData = false)] + [AllowAnonymous] + public IActionResult ImportTemplateExcel() + { + List ShopGoodsCategory = new List(); + MemoryStream stream = new MemoryStream(); + + // 示例数据 + var allValues = new List>(); + var values = new List() { "111", "222", "333" }; + var values2 = new List() { "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}"); + } + + /// + /// 导出店铺商品类目 + /// + /// + [Log(Title = "店铺商品类目导出", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)] + [HttpGet("exportShopGoodsCategory")] + [ActionPermissionFilter(Permission = "business:shopgoodscategory:export")] + public async Task 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(); + 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 }); + } + + + + + } +} diff --git a/ARW.WebApi/wwwroot/CodeGenTemplate/Upload.txt b/ARW.WebApi/wwwroot/CodeGenTemplate/Upload.txt index b5ccfd6..a0702cf 100644 --- a/ARW.WebApi/wwwroot/CodeGenTemplate/Upload.txt +++ b/ARW.WebApi/wwwroot/CodeGenTemplate/Upload.txt @@ -7,7 +7,7 @@ * @LastEditTime: (${replaceDto.AddTime}) -->