feat 初始化商品类目
This commit is contained in:
parent
1f6e73d914
commit
4f17c322cd
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
||||
|
||||
namespace ARW.Model.Dto.Business.GoodsManager.GoodsCategorys
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品类目输入对象
|
||||
///
|
||||
/// @author 黎文豪
|
||||
/// @date 2023-06-12
|
||||
/// </summary>
|
||||
public class GoodsCategoryDto
|
||||
{
|
||||
|
||||
public int GoodsCategoryId { get; set; }
|
||||
|
||||
public long GoodsCategoryGuid { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "父级guid不能为空")]
|
||||
public long GoodsCategoryParentGuid { get; set; }
|
||||
|
||||
public string GoodsCategoryAncestralGuid { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "名称不能为空")]
|
||||
public string GoodsCategoryName { get; set; }
|
||||
|
||||
public string GoodsCategoryImg { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "显示状态不能为空")]
|
||||
public int GoodsCategoryDisplayStatus { get; set; }
|
||||
|
||||
public int? GoodsCategoryIsPopular { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "排序不能为空")]
|
||||
public int ProductCategorySort { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 商品类目查询对象
|
||||
///
|
||||
/// @author 黎文豪
|
||||
/// @date 2023-06-12
|
||||
/// </summary>
|
||||
public class GoodsCategoryQueryDto : PagerInfo
|
||||
{
|
||||
|
||||
public string GoodsCategoryName { get; set; }
|
||||
|
||||
public int? GoodsCategoryDisplayStatus { get; set; }
|
||||
|
||||
public int? GoodsCategoryIsPopular { get; set; }
|
||||
|
||||
public string ids { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SqlSugar;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ARW.Model.Models.Business.GoodsManager.GoodsCategorys
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品类目,数据实体对象
|
||||
///
|
||||
/// @author 黎文豪
|
||||
/// @date 2023-06-12
|
||||
/// </summary>
|
||||
[SugarTable("tb_goods_category")]
|
||||
public class GoodsCategory : BusinessBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "GoodsCategoryId")]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "goods_category_id")]
|
||||
public int GoodsCategoryId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "GoodsCategoryGuid")]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "goods_category_guid")]
|
||||
public long GoodsCategoryGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :父级guid
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "父级guid")]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName = "goods_category_parent_guid")]
|
||||
public long GoodsCategoryParentGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :祖级guid
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "祖级guid")]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName = "goods_category_ancestral_guid")]
|
||||
public string GoodsCategoryAncestralGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :名称
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "名称")]
|
||||
[SugarColumn(ColumnName = "goods_category_name")]
|
||||
public string GoodsCategoryName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :图片
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "图片")]
|
||||
[SugarColumn(ColumnName = "goods_category_img")]
|
||||
public string GoodsCategoryImg { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :显示状态
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "显示状态")]
|
||||
[SugarColumn(ColumnName = "goods_category_display_status")]
|
||||
public int GoodsCategoryDisplayStatus { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :是否为热门
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "是否为热门")]
|
||||
[SugarColumn(ColumnName = "goods_category_is_popular")]
|
||||
public int? GoodsCategoryIsPopular { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :排序
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "排序")]
|
||||
[SugarColumn(ColumnName = "product_category_sort")]
|
||||
public int ProductCategorySort { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<GoodsCategory> Children { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
using Newtonsoft.Json;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ARW.Model.Vo.Business.GoodsManager.GoodsCategorys
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品类目展示对象
|
||||
///
|
||||
/// @author 黎文豪
|
||||
/// @date 2023-06-12
|
||||
/// </summary>
|
||||
public class GoodsCategoryVo
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public int GoodsCategoryId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
[SugarColumn(IsTreeKey = true)]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[EpplusIgnore]
|
||||
public long GoodsCategoryGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :父级guid
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[EpplusTableColumn(Header = "父级guid")]
|
||||
public long GoodsCategoryParentGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :祖级guid
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[EpplusTableColumn(Header = "祖级guid")]
|
||||
public string GoodsCategoryAncestralGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :名称
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "名称")]
|
||||
public string GoodsCategoryName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :图片
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public string GoodsCategoryImg { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :显示状态
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "显示状态")]
|
||||
public int GoodsCategoryDisplayStatus { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :是否为热门
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public int? GoodsCategoryIsPopular { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :排序
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "排序")]
|
||||
public int ProductCategorySort { get; set; }
|
||||
|
||||
[EpplusIgnore]
|
||||
public string ParentName { get; set; }
|
||||
|
||||
[EpplusIgnore]
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<GoodsCategoryVo> Children { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using Infrastructure.Attribute;
|
||||
using ARW.Repository.System;
|
||||
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
||||
|
||||
namespace ARW.Repository.Business.GoodsManager.GoodsCategorys
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品类目仓储
|
||||
///
|
||||
/// @author 黎文豪
|
||||
/// @date 2023-06-12
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class GoodsCategoryRepository : BaseRepository<GoodsCategory>
|
||||
{
|
||||
#region 业务逻辑代码
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
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.GoodsCategorys;
|
||||
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsCategorys;
|
||||
using ARW.Model.Dto.Business.GoodsManager.GoodsCategorys;
|
||||
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
||||
using ARW.Model.Vo.Business.GoodsManager.GoodsCategorys;
|
||||
|
||||
namespace ARW.Service.Business.BusinessService.GoodsManager.GoodsCategorys
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品类目接口实现类
|
||||
///
|
||||
/// @author 黎文豪
|
||||
/// @date 2023-06-12
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IGoodsCategoryService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class GoodsCategoryServiceImpl : BaseService<GoodsCategory>, IGoodsCategoryService
|
||||
{
|
||||
private readonly GoodsCategoryRepository _GoodsCategoryRepository;
|
||||
|
||||
public GoodsCategoryServiceImpl(GoodsCategoryRepository GoodsCategoryRepository)
|
||||
{
|
||||
this._GoodsCategoryRepository = GoodsCategoryRepository;
|
||||
}
|
||||
|
||||
#region 业务逻辑代码
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询商品类目树形列表
|
||||
/// </summary>
|
||||
public async Task<List<GoodsCategoryVo>> GetGoodsCategoryTreeList(GoodsCategoryQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<GoodsCategory>();
|
||||
|
||||
predicate = predicate.AndIF(parm.GoodsCategoryDisplayStatus != null, s => s.GoodsCategoryDisplayStatus == parm.GoodsCategoryDisplayStatus);
|
||||
predicate = predicate.AndIF(parm.GoodsCategoryIsPopular != null, s => s.GoodsCategoryIsPopular == parm.GoodsCategoryIsPopular);
|
||||
var query = _GoodsCategoryRepository
|
||||
.Queryable()
|
||||
.LeftJoin<GoodsCategory>((s, c) => s.GoodsCategoryParentGuid == c.GoodsCategoryGuid)
|
||||
.Where(predicate.ToExpression())
|
||||
.OrderBy(s => s.ProductCategorySort, OrderByType.Asc)
|
||||
.Select((s, c) => new GoodsCategoryVo
|
||||
{
|
||||
GoodsCategoryId = s.GoodsCategoryId,
|
||||
GoodsCategoryGuid = s.GoodsCategoryGuid,
|
||||
GoodsCategoryParentGuid = s.GoodsCategoryParentGuid,
|
||||
GoodsCategoryAncestralGuid = s.GoodsCategoryAncestralGuid,
|
||||
GoodsCategoryName = s.GoodsCategoryName,
|
||||
GoodsCategoryImg = s.GoodsCategoryImg,
|
||||
GoodsCategoryDisplayStatus = s.GoodsCategoryDisplayStatus,
|
||||
GoodsCategoryIsPopular = s.GoodsCategoryIsPopular,
|
||||
ProductCategorySort = s.ProductCategorySort,
|
||||
ParentName = c.GoodsCategoryName,
|
||||
});
|
||||
|
||||
return await query.ToTreeAsync(it => it.Children, it => it.GoodsCategoryParentGuid, 0);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询商品类目列表
|
||||
/// </summary>
|
||||
public Task<List<GoodsCategoryVo>> GetGoodsCategoryList(GoodsCategoryQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件d
|
||||
var predicate = Expressionable.Create<GoodsCategory>();
|
||||
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.GoodsCategoryName), it => it.GoodsCategoryName.Contains(parm.GoodsCategoryName));
|
||||
predicate = predicate.AndIF(parm.GoodsCategoryDisplayStatus != null, it => it.GoodsCategoryDisplayStatus == parm.GoodsCategoryDisplayStatus);
|
||||
predicate = predicate.AndIF(parm.GoodsCategoryIsPopular != null, it => it.GoodsCategoryIsPopular == parm.GoodsCategoryIsPopular);
|
||||
var query = _GoodsCategoryRepository
|
||||
.Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.OrderBy(s => s.ProductCategorySort, OrderByType.Asc)
|
||||
.Select(s => new GoodsCategoryVo
|
||||
{
|
||||
GoodsCategoryId = s.GoodsCategoryId,
|
||||
GoodsCategoryGuid = s.GoodsCategoryGuid,
|
||||
GoodsCategoryParentGuid = s.GoodsCategoryParentGuid,
|
||||
GoodsCategoryAncestralGuid = s.GoodsCategoryAncestralGuid,
|
||||
GoodsCategoryName = s.GoodsCategoryName,
|
||||
GoodsCategoryImg = s.GoodsCategoryImg,
|
||||
GoodsCategoryDisplayStatus = s.GoodsCategoryDisplayStatus,
|
||||
GoodsCategoryIsPopular = s.GoodsCategoryIsPopular,
|
||||
ProductCategorySort = s.ProductCategorySort,
|
||||
});
|
||||
|
||||
|
||||
return query.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改商品类目
|
||||
/// </summary>
|
||||
public async Task<string> AddOrUpdateGoodsCategory(GoodsCategory model)
|
||||
{
|
||||
if (model.GoodsCategoryId != 0)
|
||||
{
|
||||
var type = await _GoodsCategoryRepository.GetListAsync(s => s.GoodsCategoryParentGuid == model.GoodsCategoryGuid);
|
||||
if (type != null)
|
||||
{
|
||||
foreach (var item in type)
|
||||
{
|
||||
if (model.GoodsCategoryParentGuid == item.GoodsCategoryGuid) throw new CustomException("上级菜单不能选择自己的子级!");
|
||||
}
|
||||
}
|
||||
if (model.GoodsCategoryParentGuid == model.GoodsCategoryGuid) throw new CustomException("上级菜单不能选择与当前菜单一样的!");
|
||||
var response = await _GoodsCategoryRepository.UpdateAsync(model);
|
||||
return "修改成功!";
|
||||
}
|
||||
else
|
||||
{
|
||||
var info = _GoodsCategoryRepository.GetFirst(it => it.GoodsCategoryGuid == model.GoodsCategoryParentGuid);
|
||||
model.GoodsCategoryAncestralGuid = "0";
|
||||
if (info != null) model.GoodsCategoryAncestralGuid = info.GoodsCategoryAncestralGuid + "," + model.GoodsCategoryParentGuid;
|
||||
|
||||
var response = await _GoodsCategoryRepository.InsertReturnSnowflakeIdAsync(model);
|
||||
return "添加成功!";
|
||||
}
|
||||
}
|
||||
|
||||
#region Excel处理
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Excel数据导出处理
|
||||
/// </summary>
|
||||
public async Task<List<GoodsCategoryVo>> HandleExportData(List<GoodsCategoryVo> data)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
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.GoodsCategorys;
|
||||
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
||||
using ARW.Model.Vo.Business.GoodsManager.GoodsCategorys;
|
||||
|
||||
namespace ARW.Service.Business.IBusinessService.GoodsManager.GoodsCategorys
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品类目接口类
|
||||
///
|
||||
/// @author 黎文豪
|
||||
/// @date 2023-06-12
|
||||
/// </summary>
|
||||
public interface IGoodsCategoryService : IBaseService<GoodsCategory>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取商品类目树形列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<GoodsCategoryVo>> GetGoodsCategoryTreeList(GoodsCategoryQueryDto parm);
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品类目列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<GoodsCategoryVo>> GetGoodsCategoryList(GoodsCategoryQueryDto parm);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改商品类目
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> AddOrUpdateGoodsCategory(GoodsCategory parm);
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Excel导出
|
||||
/// </summary>
|
||||
Task<List<GoodsCategoryVo>> HandleExportData(List<GoodsCategoryVo> data);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
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.GoodsCategorys;
|
||||
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsCategorys;
|
||||
using ARW.Admin.WebApi.Controllers;
|
||||
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
||||
using ARW.Model.Vo.Business.GoodsManager.GoodsCategorys;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using ARW.Admin.WebApi.Framework;
|
||||
|
||||
|
||||
namespace ARW.WebApi.Controllers.Business.GoodsManager.GoodsCategorys
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品类目控制器
|
||||
///
|
||||
/// @author 黎文豪
|
||||
/// @date 2023-06-12
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("business/[controller]")]
|
||||
public class GoodsCategoryController : BaseController
|
||||
{
|
||||
private readonly IGoodsCategoryService _GoodsCategoryService;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖注入
|
||||
/// </summary>
|
||||
/// <param name="GoodsCategoryService">商品类目服务</param>
|
||||
public GoodsCategoryController(IGoodsCategoryService GoodsCategoryService)
|
||||
{
|
||||
_GoodsCategoryService = GoodsCategoryService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品类目树形列表
|
||||
/// </summary>
|
||||
/// <param name="parm">查询参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getGoodsCategoryTreeList")]
|
||||
[ActionPermissionFilter(Permission = "business:goodscategory:treelist")]
|
||||
public async Task<IActionResult> GetGoodsCategoryList([FromQuery] GoodsCategoryQueryDto parm)
|
||||
{
|
||||
var res = await _GoodsCategoryService.GetGoodsCategoryTreeList(parm);
|
||||
res ??= new List<GoodsCategoryVo>();
|
||||
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改商品类目
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("addOrUpdateGoodsCategory")]
|
||||
[ActionPermissionFilter(Permission = "business:goodscategory:addOrUpdate")]
|
||||
[Log(Title = "添加或修改商品类目", BusinessType = BusinessType.ADDORUPDATE)]
|
||||
public async Task<IActionResult> AddOrUpdateGoodsCategory([FromBody] GoodsCategoryDto parm)
|
||||
{
|
||||
if (parm == null) { throw new CustomException("请求参数错误"); }
|
||||
|
||||
var modal = new GoodsCategory();
|
||||
if (parm.GoodsCategoryId != 0) modal = parm.Adapt<GoodsCategory>().ToUpdate(HttpContext);
|
||||
else modal = parm.Adapt<GoodsCategory>().ToCreate(HttpContext);
|
||||
|
||||
var res = await _GoodsCategoryService.AddOrUpdateGoodsCategory(modal);
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除商品类目
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{ids}")]
|
||||
[ActionPermissionFilter(Permission = "business:goodscategory: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 = _GoodsCategoryService.Delete(idsArr);
|
||||
return SUCCESS("删除成功!");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导出商品类目
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "商品类目导出", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||||
[HttpGet("exportGoodsCategory")]
|
||||
[ActionPermissionFilter(Permission = "business:goodscategory:export")]
|
||||
public async Task<IActionResult> ExportExcel([FromQuery] GoodsCategoryQueryDto parm)
|
||||
{
|
||||
var list = await _GoodsCategoryService.GetGoodsCategoryList(parm);
|
||||
var data = list;
|
||||
|
||||
// 选中数据
|
||||
if (!string.IsNullOrEmpty(parm.ids))
|
||||
{
|
||||
int[] idsArr = Tools.SpitIntArrary(parm.ids);
|
||||
var selectDataList = new List<GoodsCategoryVo>();
|
||||
foreach (var item in idsArr)
|
||||
{
|
||||
var select_data = data.Where(s => s.GoodsCategoryId == item).First();
|
||||
selectDataList.Add(select_data);
|
||||
|
||||
// 查看当前数据有没有子级
|
||||
var newGoodsCategorys = data.FindAll(delegate (GoodsCategoryVo goodsCategory)
|
||||
{
|
||||
string[] parentGoodsCategoryId = goodsCategory.GoodsCategoryAncestralGuid.Split(",", StringSplitOptions.RemoveEmptyEntries);
|
||||
return parentGoodsCategoryId.Contains(select_data.GoodsCategoryGuid.ToString());
|
||||
});
|
||||
string[] goodsCategoryArr = newGoodsCategorys.Select(x => x.GoodsCategoryGuid.ToString()).ToArray();
|
||||
var ancestorArr = data.Where(s => goodsCategoryArr.Contains(s.GoodsCategoryGuid.ToString())).ToList();
|
||||
selectDataList.AddRange(ancestorArr);
|
||||
}
|
||||
data = selectDataList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 导出数据处理
|
||||
var handleData = await _GoodsCategoryService.HandleExportData(data);
|
||||
|
||||
string sFileName = ExportExcel(handleData, "GoodsCategory", "商品类目列表");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -394,6 +394,7 @@ function getList() {
|
||||
}
|
||||
});
|
||||
}
|
||||
$end
|
||||
|
||||
|
||||
// 多选框选中数据
|
||||
|
Loading…
Reference in New Issue
Block a user