feat 添加经营类目接口
This commit is contained in:
parent
37a5a651eb
commit
ecc421b701
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
||||||
|
|
||||||
|
namespace ARW.Model.Dto.Api.GoodsManager.GoodsCategorys
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 经营类目查询对象Api
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-07-08
|
||||||
|
/// </summary>
|
||||||
|
public class GoodsCategoryQueryDtoApi : PagerInfo
|
||||||
|
{
|
||||||
|
public string GoodsCategoryName { get; set; }
|
||||||
|
public int? GoodsCategoryDisplayStatus { get; set; }
|
||||||
|
public int? GoodsCategoryIsPopular { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 经营类目详情输入对象Api
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-07-08
|
||||||
|
/// </summary>
|
||||||
|
public class GoodsCategoryDtoApi
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "GoodsCategoryGuid不能为空")]
|
||||||
|
public long GoodsCategoryGuid { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
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.Api.GoodsManager.GoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 经营类目展示对象Api
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-07-08
|
||||||
|
/// </summary>
|
||||||
|
public class GoodsCategoryVoApi
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :
|
||||||
|
/// </summary>
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[SugarColumn(IsTreeKey = true)]
|
||||||
|
[EpplusIgnore]
|
||||||
|
public long GroupId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :父级guid
|
||||||
|
/// </summary>
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
public long ParentGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :图片
|
||||||
|
/// </summary>
|
||||||
|
[EpplusIgnore]
|
||||||
|
public string Thumbnail { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
public List<GoodsCategoryVoApi> Children { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
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 ARW.Model;
|
||||||
|
using ARW.Repository;
|
||||||
|
using ARW.Repository.Business.GoodsManager.GoodsCategorys;
|
||||||
|
using ARW.Service.Api.IBusinessService.GoodsManager.GoodsCategorys;
|
||||||
|
using ARW.Model.Dto.Api.GoodsManager.GoodsCategorys;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
||||||
|
using ARW.Model.Vo.Api.GoodsManager.GoodsCategorys;
|
||||||
|
|
||||||
|
namespace ARW.Service.Api.BusinessService.GoodsManager.GoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 经营类目接口实现类Api
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-07-08
|
||||||
|
/// </summary>
|
||||||
|
[AppService(ServiceType = typeof(IGoodsCategoryServiceApi), ServiceLifetime = LifeTime.Transient)]
|
||||||
|
public class GoodsCategoryServiceImplApi : BaseService<GoodsCategory>, IGoodsCategoryServiceApi
|
||||||
|
{
|
||||||
|
private readonly GoodsCategoryRepository _GoodsCategoryRepository;
|
||||||
|
|
||||||
|
public GoodsCategoryServiceImplApi(GoodsCategoryRepository GoodsCategoryRepository)
|
||||||
|
{
|
||||||
|
this._GoodsCategoryRepository = GoodsCategoryRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Api接口代码
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询经营类目树形列表(Api)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<GoodsCategoryVoApi>> GetGoodsCategoryTreeListApi(GoodsCategoryQueryDtoApi parm)
|
||||||
|
{
|
||||||
|
//开始拼装查询条件d
|
||||||
|
var predicate = Expressionable.Create<GoodsCategory>();
|
||||||
|
|
||||||
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.GoodsCategoryName), s => s.GoodsCategoryName.Contains(parm.GoodsCategoryName));
|
||||||
|
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()
|
||||||
|
.Where(predicate.ToExpression())
|
||||||
|
.OrderBy(s => s.ProductCategorySort, OrderByType.Asc)
|
||||||
|
.Select((s) => new GoodsCategoryVoApi
|
||||||
|
{
|
||||||
|
GroupId = s.GoodsCategoryGuid,
|
||||||
|
ParentGuid = s.GoodsCategoryParentGuid,
|
||||||
|
Name = s.GoodsCategoryName,
|
||||||
|
Thumbnail = s.GoodsCategoryImg,
|
||||||
|
});
|
||||||
|
|
||||||
|
return await query.ToTreeAsync(it => it.Children, it => it.ParentGuid, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ARW.Model;
|
||||||
|
using ARW.Model.Dto.Api.GoodsManager.GoodsCategorys;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
||||||
|
using ARW.Model.Vo.Api.GoodsManager.GoodsCategorys;
|
||||||
|
|
||||||
|
namespace ARW.Service.Api.IBusinessService.GoodsManager.GoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 经营类目接口类Api
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-07-08
|
||||||
|
/// </summary>
|
||||||
|
public interface IGoodsCategoryServiceApi : IBaseService<GoodsCategory>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取经营类目树形列表(Api)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<List<GoodsCategoryVoApi>> GetGoodsCategoryTreeListApi(GoodsCategoryQueryDtoApi parm);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -122,7 +122,7 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.GoodsCategorys
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (model.GoodsCategoryParentGuid != 0) throw new CustomException("不允许添加三级类目!");
|
//if (model.GoodsCategoryParentGuid != 0) throw new CustomException("不允许添加三级类目!");
|
||||||
var info = _GoodsCategoryRepository.GetFirst(it => it.GoodsCategoryGuid == model.GoodsCategoryParentGuid);
|
var info = _GoodsCategoryRepository.GetFirst(it => it.GoodsCategoryGuid == model.GoodsCategoryParentGuid);
|
||||||
model.GoodsCategoryAncestralGuid = "0";
|
model.GoodsCategoryAncestralGuid = "0";
|
||||||
if (info != null) model.GoodsCategoryAncestralGuid = info.GoodsCategoryAncestralGuid + "," + model.GoodsCategoryParentGuid;
|
if (info != null) model.GoodsCategoryAncestralGuid = info.GoodsCategoryAncestralGuid + "," + model.GoodsCategoryParentGuid;
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
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.Admin.WebApi.Controllers;
|
||||||
|
using ARW.Model.Dto.Api.GoodsManager.GoodsCategorys;
|
||||||
|
using ARW.Service.Api.IBusinessService.GoodsManager.GoodsCategorys;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
||||||
|
using ARW.Model.Vo.Api.GoodsManager.GoodsCategorys;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Geocoding;
|
||||||
|
|
||||||
|
namespace ARW.WebApi.Controllers.Api.GoodsManager.GoodsCategorys
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 经营类目控制器Api
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-07-08
|
||||||
|
/// </summary>
|
||||||
|
[Verify]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class GoodsCategoryApiController : BaseController
|
||||||
|
{
|
||||||
|
private readonly IGoodsCategoryServiceApi _GoodsCategoryServiceApi;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 依赖注入
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="GoodsCategoryServiceApi">经营类目经营类目Api服务</param>
|
||||||
|
public GoodsCategoryApiController(IGoodsCategoryServiceApi GoodsCategoryServiceApi)
|
||||||
|
{
|
||||||
|
_GoodsCategoryServiceApi = GoodsCategoryServiceApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取经营类目树形列表(Api)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm">查询参数</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("getGoodsCategoryTreeList")]
|
||||||
|
public async Task<IActionResult> GetGoodsCategoryTreeListApi([FromQuery] GoodsCategoryQueryDtoApi parm)
|
||||||
|
{
|
||||||
|
var res = await _GoodsCategoryServiceApi.GetGoodsCategoryTreeListApi(parm);
|
||||||
|
if (res == null)
|
||||||
|
res = new List<GoodsCategoryVoApi>();
|
||||||
|
|
||||||
|
return SUCCESS(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user