fixed 完善商品类目及平台与商户权限

This commit is contained in:
lwh 2023-06-16 19:37:39 +08:00
parent 18ddd54bb1
commit fcd62fa197
11 changed files with 219 additions and 79 deletions

View File

@ -18,13 +18,11 @@ namespace ARW.Model.Dto.Business.GoodsManager.ShopGoodsCategorys
public long ShopGoodsCategoryGuid { get; set; }
[Required(ErrorMessage = "店铺guid不能为空")]
public long ShopGuid { get; set; }
[Required(ErrorMessage = "父级guid不能为空")]
[Required(ErrorMessage = "上级类目不能为空")]
public long ShopGoodsCategoryParentGuid { get; set; }
[Required(ErrorMessage = "祖级guid不能为空")]
public string ShopGoodsCategoryAncestralGuid { get; set; }
[Required(ErrorMessage = "名称不能为空")]
@ -51,7 +49,8 @@ namespace ARW.Model.Dto.Business.GoodsManager.ShopGoodsCategorys
/// </summary>
public class ShopGoodsCategoryQueryDto : PagerInfo
{
public long ShopGuid { get; set;}
public string ShopName { get; set; }
public string ShopGoodsCategoryName { get; set; }
public int? ShopGoodsCategoryDisplayStatus { get; set; }

View File

@ -37,42 +37,60 @@ namespace ARW.Model.Vo.Business.GoodsManager.ShopGoodsCategorys
/// 描述 :店铺guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(IsTreeKey = true)]
[EpplusTableColumn(Header = "店铺guid")]
[EpplusIgnore]
public long ShopGuid { get; set; }
/// <summary>
/// 描述 :店铺名称
/// </summary>
[EpplusTableColumn(Header = "店铺名称")]
public string ShopName { get; set; }
/// <summary>
/// 描述 :父级guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(IsTreeKey = true)]
[EpplusTableColumn(Header = "父级guid")]
[EpplusIgnore]
public long ShopGoodsCategoryParentGuid { get; set; }
[EpplusTableColumn(Header = "上级类目")]
public string ParentName { get; set; }
/// <summary>
/// 描述 :祖级guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(IsTreeKey = true)]
[EpplusTableColumn(Header = "祖级guid")]
[EpplusIgnore]
public string ShopGoodsCategoryAncestralGuid { get; set; }
/// <summary>
/// 描述 :名称
/// </summary>
[EpplusTableColumn(Header = "名称")]
[EpplusTableColumn(Header = "商品类目名称")]
public string ShopGoodsCategoryName { get; set; }
/// <summary>
/// 描述 :显示状态
/// </summary>
[EpplusTableColumn(Header = "显示状态")]
[EpplusIgnore]
public int ShopGoodsCategoryDisplayStatus { get; set; }
/// <summary>
/// 描述 :显示状态名称
/// </summary>
[EpplusTableColumn(Header = "显示状态")]
public string ShopGoodsCategoryDisplayStatusName { get; set; }
/// <summary>
/// 描述 :排序
@ -80,8 +98,6 @@ namespace ARW.Model.Vo.Business.GoodsManager.ShopGoodsCategorys
[EpplusTableColumn(Header = "排序")]
public int ShopGoodsCategorySort { get; set; }
[EpplusIgnore]
public string ParentName { get; set; }
[EpplusIgnore]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]

View File

@ -14,6 +14,11 @@ 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;
using ARW.Model.Models.Business.ShopManager.Shops;
using ARW.Repository.System;
using ARW.Repository.Business.ShopManager.Shops;
using Senparc.CO2NET.Extensions;
using ARW.Model.System;
namespace ARW.Service.Business.BusinessService.GoodsManager.ShopGoodsCategorys
{
@ -27,43 +32,51 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.ShopGoodsCategorys
public class ShopGoodsCategoryServiceImpl : BaseService<ShopGoodsCategory>, IShopGoodsCategoryService
{
private readonly ShopGoodsCategoryRepository _ShopGoodsCategoryRepository;
private readonly ShopRepository _ShopRepository;
private readonly SysDictDataRepository _SysDictDataRepository;
public ShopGoodsCategoryServiceImpl(ShopGoodsCategoryRepository ShopGoodsCategoryRepository)
public ShopGoodsCategoryServiceImpl(ShopGoodsCategoryRepository ShopGoodsCategoryRepository, SysDictDataRepository sysDictDataRepository, ShopRepository shopRepository)
{
this._ShopGoodsCategoryRepository = ShopGoodsCategoryRepository;
_SysDictDataRepository = sysDictDataRepository;
_ShopRepository = shopRepository;
}
#region
/// <summary>
#region
/// <summary>
/// 查询店铺商品类目树形列表
/// </summary>
public async Task<List<ShopGoodsCategoryVo>> GetShopGoodsCategoryTreeList(ShopGoodsCategoryQueryDto parm)
{
public async Task<List<ShopGoodsCategoryVo>> GetShopGoodsCategoryTreeList(ShopGoodsCategoryQueryDto parm)
{
//开始拼装查询条件
var predicate = Expressionable.Create<ShopGoodsCategory>();
predicate = predicate.AndIF(parm.ShopGuid != 0, s => s.ShopGuid == parm.ShopGuid);
predicate = predicate.AndIF(parm.ShopGoodsCategoryDisplayStatus != null, s => s.ShopGoodsCategoryDisplayStatus == parm.ShopGoodsCategoryDisplayStatus);
var query = _ShopGoodsCategoryRepository
.Queryable()
.LeftJoin<ShopGoodsCategory>((s, c) => s.ShopGoodsCategoryParentGuid == c.ShopGoodsCategoryGuid)
.LeftJoin<ShopGoodsCategory>((s, c) => s.ShopGoodsCategoryParentGuid == c.ShopGoodsCategoryGuid)
.LeftJoin<Shop>((s, c, d) => s.ShopGuid == d.ShopGuid)
.Where(predicate.ToExpression())
.OrderBy(s => s.ShopGoodsCategorySort,OrderByType.Asc)
.Select((s,c) => new ShopGoodsCategoryVo
.WhereIF(!string.IsNullOrEmpty(parm.ShopName), (s, c, d) => d.ShopName.Contains(parm.ShopName))
.OrderBy(s => s.ShopGoodsCategorySort, OrderByType.Asc)
.Select((s, c, d) => 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,
});
ShopGoodsCategoryId = s.ShopGoodsCategoryId,
ShopGoodsCategoryGuid = s.ShopGoodsCategoryGuid,
ShopGuid = s.ShopGuid,
ShopName = d.ShopName,
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);
return await query.ToTreeAsync(it => it.Children, it => it.ShopGoodsCategoryParentGuid, 0);
}
@ -75,29 +88,35 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.ShopGoodsCategorys
//开始拼装查询条件d
var predicate = Expressionable.Create<ShopGoodsCategory>();
predicate = predicate.AndIF(parm.ShopGuid != 0, s => s.ShopGuid == parm.ShopGuid);
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()
.LeftJoin<ShopGoodsCategory>((s, c) => s.ShopGoodsCategoryParentGuid == c.ShopGoodsCategoryGuid)
.LeftJoin<Shop>((s, c, d) => s.ShopGuid == d.ShopGuid)
.Where(predicate.ToExpression())
.OrderBy(s => s.ShopGoodsCategorySort,OrderByType.Asc)
.Select(s => new ShopGoodsCategoryVo
.WhereIF(!string.IsNullOrEmpty(parm.ShopName), (s, c, d) => d.ShopName.Contains(parm.ShopName))
.OrderBy(s => s.ShopGoodsCategorySort, OrderByType.Asc)
.Select((s, c, d) => 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,
});
ShopGoodsCategoryId = s.ShopGoodsCategoryId,
ShopGoodsCategoryGuid = s.ShopGoodsCategoryGuid,
ShopGuid = s.ShopGuid,
ShopName = d.ShopName,
ShopGoodsCategoryParentGuid = s.ShopGoodsCategoryParentGuid,
ShopGoodsCategoryAncestralGuid = s.ShopGoodsCategoryAncestralGuid,
ShopGoodsCategoryName = s.ShopGoodsCategoryName,
ShopGoodsCategoryDisplayStatus = s.ShopGoodsCategoryDisplayStatus,
ShopGoodsCategorySort = s.ShopGoodsCategorySort,
ParentName = c.ShopGoodsCategoryName,
});
return await query.ToListAsync();
return await query.ToListAsync();
}
/// <summary>
/// <summary>
/// 添加或修改店铺商品类目
/// </summary>
public async Task<string> AddOrUpdateShopGoodsCategory(ShopGoodsCategory model)
@ -128,30 +147,72 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.ShopGoodsCategorys
}
#region Excel处理
/// <summary>
/// <summary>
/// 数据导入处理
/// </summary>
public async Task<ShopGoodsCategoryVo> HandleImportData(ShopGoodsCategoryVo ShopGoodsCategory)
public async Task<ShopGoodsCategoryVo> HandleImportData(ShopGoodsCategoryVo ShopGoodsCategory, long userId, int index)
{
return ShopGoodsCategory;
try
{
// 店铺名称转Guid
var shoper = await _ShopRepository.GetFirstAsync(s => s.ShopName == ShopGoodsCategory.ShopName);
if (shoper == null) throw new Exception($"找不到店铺【{ShopGoodsCategory.ShopName}】");
if (userId != 1)
{
var shop = await _ShopRepository.GetFirstAsync(s => s.ShopUserId == userId);
if (shop == null) throw new Exception("该用户没有店铺");
// 店铺是否为自己的
if (shop.ShopName != ShopGoodsCategory.ShopName) throw new Exception("只允许添加自己的店铺数据");
}
ShopGoodsCategory.ShopGuid = shoper.ShopGuid;
// 上级类目名称转guid (本店铺的类目)
if (!string.IsNullOrEmpty(ShopGoodsCategory.ParentName))
{
var category = await _ShopGoodsCategoryRepository.GetFirstAsync(s => s.ShopGoodsCategoryName == ShopGoodsCategory.ParentName && s.ShopGuid == ShopGoodsCategory.ShopGuid);
ShopGoodsCategory.ShopGoodsCategoryParentGuid = category.ShopGoodsCategoryGuid;
}
// 显示状态
var lable = ShopGoodsCategory.ShopGoodsCategoryDisplayStatusName;
ShopGoodsCategory.ShopGoodsCategoryDisplayStatus = Convert.ToInt32(_SysDictDataRepository.GetDictValueByName("display_status", lable));
return ShopGoodsCategory;
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Excel导入
/// </summary>
public async Task<string> ImportExcel(ShopGoodsCategory ShopGoodsCategory,int index,bool isUpdateSupport,string user)
public async Task<string> ImportExcel(ShopGoodsCategoryVo ShopGoodsCategoryVo, int index, bool isUpdateSupport, LoginUser user)
{
try
{
// 空值判断
// if (ShopGoodsCategory.ShopGoodsCategoryId == null) throw new CustomException("店铺商品类目不能为空");
var category = await HandleImportData(ShopGoodsCategoryVo, user.UserId,index);
var ShopGoodsCategory = new ShopGoodsCategory
{
ShopGoodsCategoryId= category.ShopGoodsCategoryId,
ShopGoodsCategoryGuid= category.ShopGoodsCategoryGuid,
ShopGuid = category.ShopGuid,
ShopGoodsCategoryParentGuid = category.ShopGoodsCategoryParentGuid,
ShopGoodsCategoryName = category.ShopGoodsCategoryName,
ShopGoodsCategoryDisplayStatus = category.ShopGoodsCategoryDisplayStatus,
ShopGoodsCategorySort = category.ShopGoodsCategorySort
};
if (isUpdateSupport)
{
// 判断唯一值
var model = await GetFirstAsync(s => s.ShopGoodsCategoryId == ShopGoodsCategory.ShopGoodsCategoryId);
// 如果为空就新增数据
if (model == null)
{
@ -160,7 +221,7 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.ShopGoodsCategorys
{
var addRes = await AddOrUpdateShopGoodsCategory(ShopGoodsCategory);
});
var addStr = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryId}】<span style='color:#27af49'>新增成功!</span><br>";
var addStr = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryName}】<span style='color:#27af49'>新增成功!</span><br>";
return addStr;
}
else
@ -171,48 +232,53 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.ShopGoodsCategorys
{
ShopGoodsCategory.ShopGoodsCategoryId = model.ShopGoodsCategoryId;
ShopGoodsCategory.ShopGoodsCategoryGuid = model.ShopGoodsCategoryGuid;
ShopGoodsCategory.Update_by = user;
ShopGoodsCategory.Update_by = user.UserName;
ShopGoodsCategory.Update_time = DateTime.Now;
var editRes = await AddOrUpdateShopGoodsCategory(ShopGoodsCategory);
});
var editStr = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryId}】<span style='color:#e6a23c'>更新成功!</span><br>";
var editStr = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryName}】<span style='color:#e6a23c'>更新成功!</span><br>";
return editStr;
}
}
else{
// 开启事务
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>";
var addStr = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryName}】<span style='color:#27af49'>新增成功!</span><br>";
return addStr;
}
}
catch (Exception ex)
{
var errorRes = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategory.ShopGoodsCategoryId}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
var errorRes = $"第 {index} 行 => 店铺商品类目:【{ShopGoodsCategoryVo.ShopGoodsCategoryName}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
return errorRes;
throw;
}
}
/// <summary>
/// Excel数据导出处理
/// </summary>
public async Task<List<ShopGoodsCategoryVo>> HandleExportData(List<ShopGoodsCategoryVo> data)
{
foreach (var item in data)
{
item.ShopGoodsCategoryDisplayStatusName = _SysDictDataRepository.GetDictNameByName("display_status", item.ShopGoodsCategoryDisplayStatus.ToString());
}
return data;
}
#endregion
#endregion
#endregion
}
}

View File

@ -314,6 +314,13 @@ namespace ARW.Service.Business.BusinessService.ShopManager.Shops
}
public async Task<bool> CheckRepeatShopName(string shopName)
{
var query = await _ShopRepository.GetFirstAsync(s => s.ShopName == shopName);
return query != null ;
}
#endregion
}

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using ARW.Model;
using ARW.Model.Dto.Business.GoodsManager.ShopGoodsCategorys;
using ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys;
using ARW.Model.System;
using ARW.Model.Vo.Business.GoodsManager.ShopGoodsCategorys;
namespace ARW.Service.Business.IBusinessService.GoodsManager.ShopGoodsCategorys
@ -46,7 +47,7 @@ namespace ARW.Service.Business.IBusinessService.GoodsManager.ShopGoodsCategorys
/// </summary>
/// <param name="shopVo"></param>
/// <returns></returns>
Task<ShopGoodsCategoryVo> HandleImportData(ShopGoodsCategoryVo ShopGoodsCategoryVo);
Task<ShopGoodsCategoryVo> HandleImportData(ShopGoodsCategoryVo ShopGoodsCategoryVo,long userId,int index);
/// <summary>
@ -54,7 +55,7 @@ namespace ARW.Service.Business.IBusinessService.GoodsManager.ShopGoodsCategorys
/// </summary>
/// <param name="shopVo"></param>
/// <returns></returns>
Task<string> ImportExcel(ShopGoodsCategory ShopGoodsCategory,int index,bool isUpdateSupport,string user);
Task<string> ImportExcel(ShopGoodsCategoryVo ShopGoodsCategory,int index,bool isUpdateSupport,LoginUser user);
/// <summary>
/// Excel导出

View File

@ -78,5 +78,13 @@ namespace ARW.Service.Business.IBusinessService.ShopManager.Shops
/// <returns></returns>
Task<string> GetShopOperatorDetail(ShopOperatorQueryDto parm);
/// <summary>
/// 检查是否有重复商店名称
/// </summary>
/// <param name="shopName"></param>
/// <returns></returns>
Task<bool> CheckRepeatShopName(string shopName);
}
}

View File

@ -33,14 +33,17 @@ namespace ARW.WebApi.Controllers.Api.ShopManager.Shops
public class ShopApiController : BaseController
{
private readonly IShopServiceApi _ShopServiceApi;
private readonly IShopService _ShopService;
/// <summary>
/// 依赖注入
/// </summary>
/// <param name="ShopServiceApi">店铺店铺Api服务</param>
public ShopApiController(IShopServiceApi ShopServiceApi)
/// <param name="ShopService">店铺店铺服务</param>
public ShopApiController(IShopServiceApi ShopServiceApi, IShopService ShopService)
{
_ShopServiceApi = ShopServiceApi;
_ShopService = ShopService;
}
@ -80,6 +83,9 @@ namespace ARW.WebApi.Controllers.Api.ShopManager.Shops
{
if (parm == null) { throw new CustomException("请求参数错误"); }
var isRepeat = await _ShopService.CheckRepeatShopName(parm.ShopName);
if (isRepeat) throw new CustomException("商铺名称已存在");
var modal = new Shop();
if (parm.ShopId != 0) modal = parm.Adapt<Shop>().ToUpdate(HttpContext);
else modal = parm.Adapt<Shop>().ToCreate(HttpContext);

View File

@ -15,6 +15,7 @@ using ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys;
using ARW.Model.Vo.Business.GoodsManager.ShopGoodsCategorys;
using Microsoft.AspNetCore.Authorization;
using ARW.Admin.WebApi.Framework;
using ARW.Service.Business.IBusinessService.ShopManager.Shops;
namespace ARW.WebApi.Controllers.Business.GoodsManager.ShopGoodsCategorys
@ -30,14 +31,16 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.ShopGoodsCategorys
public class ShopGoodsCategoryController : BaseController
{
private readonly IShopGoodsCategoryService _ShopGoodsCategoryService;
private readonly IShopService _ShopService;
/// <summary>
/// 依赖注入
/// </summary>
/// <param name="ShopGoodsCategoryService">店铺商品类目服务</param>
public ShopGoodsCategoryController(IShopGoodsCategoryService ShopGoodsCategoryService)
public ShopGoodsCategoryController(IShopGoodsCategoryService ShopGoodsCategoryService, IShopService shopService)
{
_ShopGoodsCategoryService = ShopGoodsCategoryService;
_ShopService = shopService;
}
@ -50,6 +53,14 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.ShopGoodsCategorys
[ActionPermissionFilter(Permission = "business:shopgoodscategory:treelist")]
public async Task<IActionResult> GetShopGoodsCategoryList([FromQuery] ShopGoodsCategoryQueryDto parm)
{
var user = JwtUtil.GetLoginUser(App.HttpContext);
if (user.UserId != 1)
{
var shop = await _ShopService.GetFirstAsync(s => s.ShopUserId == user.UserId);
if (shop == null) throw new Exception("当前用户没有店铺");
parm.ShopGuid = shop.ShopGuid;
}
var res = await _ShopGoodsCategoryService.GetShopGoodsCategoryTreeList(parm);
res ??= new List<ShopGoodsCategoryVo>();
@ -72,6 +83,14 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.ShopGoodsCategorys
if (parm.ShopGoodsCategoryId != 0) modal = parm.Adapt<ShopGoodsCategory>().ToUpdate(HttpContext);
else modal = parm.Adapt<ShopGoodsCategory>().ToCreate(HttpContext);
var user = JwtUtil.GetLoginUser(App.HttpContext);
if (user.UserId != 1)
{
var shop = await _ShopService.GetFirstAsync(s => s.ShopUserId == user.UserId);
if (shop == null) throw new Exception("当前用户没有店铺");
modal.ShopGuid = shop.ShopGuid;
}
var res = await _ShopGoodsCategoryService.AddOrUpdateShopGoodsCategory(modal);
return SUCCESS(res);
}
@ -99,9 +118,10 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.ShopGoodsCategorys
/// <returns></returns>
[HttpPost("importData")]
[Log(Title = "店铺商品类目导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
[ActionPermissionFilter(Permission = "business:business:shopgoodscategory:import")]
[ActionPermissionFilter(Permission = "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());
@ -110,10 +130,10 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.ShopGoodsCategorys
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);
var user = JwtUtil.GetLoginUser(App.HttpContext);
//var ShopGoodsCategory = await _ShopGoodsCategoryService.HandleImportData(item,user.UserId,i);
//var modal = ShopGoodsCategory.Adapt<ShopGoodsCategory>().ToCreate(HttpContext);
var msg = await _ShopGoodsCategoryService.ImportExcel(item, i, isUpdateSupport, user);
msgList.Add(msg);
}
@ -135,10 +155,16 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.ShopGoodsCategorys
// 示例数据
var allValues = new List<List<string>>();
var values = new List<string>() { "111", "222", "333" };
var values2 = new List<string>() { "444", "555", "666" };
var values = new List<string>() { "我的店铺", "", "电脑", "显示", "1" };
var values2 = new List<string>() { "我的店铺", "电脑", "商业笔记本", "显示", "1" };
var values3 = new List<string>() { "我的店铺", "电脑", "游戏本", "显示", "2" };
var values4 = new List<string>() { "我的店铺", "", "外设", "显示", "2" };
var values5 = new List<string>() { "我的店铺", "外设", "鼠标", "显示", "1" };
allValues.Add(values);
allValues.Add(values2);
allValues.Add(values3);
allValues.Add(values4);
allValues.Add(values5);
string sFileName = DownloadImportTemplate(ShopGoodsCategory, stream, "店铺商品类目导入模板", allValues);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{sFileName}");
@ -153,6 +179,13 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.ShopGoodsCategorys
[ActionPermissionFilter(Permission = "business:shopgoodscategory:export")]
public async Task<IActionResult> ExportExcel([FromQuery] ShopGoodsCategoryQueryDto parm)
{
var user = JwtUtil.GetLoginUser(App.HttpContext);
if (user.UserId != 1)
{
var shop = await _ShopService.GetFirstAsync(s => s.ShopUserId == user.UserId);
if (shop == null) throw new Exception("当前用户没有店铺");
parm.ShopGuid = shop.ShopGuid;
}
var list = await _ShopGoodsCategoryService.GetShopGoodsCategoryList(parm);
var data = list;

View File

@ -108,6 +108,10 @@ namespace ARW.WebApi.Controllers.Business.ShopManager.Shops
{
if (parm == null) { throw new CustomException("请求参数错误"); }
// 检查是否有重复商店名称
var isRepeat = await _ShopService.CheckRepeatShopName(parm.ShopName);
if (isRepeat) throw new CustomException("商铺名称已存在");
var modal = new Shop();
if (parm.ShopId != 0) modal = parm.Adapt<Shop>().ToUpdate(HttpContext);
else modal = parm.Adapt<Shop>().ToCreate(HttpContext);

View File

@ -117,7 +117,7 @@ $if(replaceDto.ShowBtnImport)
/// <returns></returns>
[HttpPost("importData")]
[Log(Title = "${genTable.FunctionName}导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
[ActionPermissionFilter(Permission = "business:${replaceDto.PermissionPrefix}:import")]
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:import")]
public async Task<IActionResult> ImportExcel([FromForm(Name = "file")] IFormFile formFile,bool updateSupport)
{
var isUpdateSupport = updateSupport;

View File

@ -98,7 +98,7 @@ $end
$if(replaceDto.ShowBtnImport)
<el-col :span="1.5">
<el-button type="primary" plain icon="Upload" @click="UploadDialogVisible = true"
v-hasPermi="['business:student:import']">导入</el-button>
v-hasPermi="['${replaceDto.PermissionPrefix}:import']">导入</el-button>
</el-col>
$end
$if(replaceDto.ShowBtnExport)
@ -175,7 +175,7 @@ $if(replaceDto.ShowBtnAudit)
@click="handleAudit(scope.row)" v-hasPermi="['${replaceDto.PermissionPrefix}:audit']">审核</el-button>
$if(replaceDto.ShowBtnEdit)
<el-button type="primary" v-if="scope.row.${tool.FirstLowerCase(genTable.BusinessName)}AuditStatus == 2" size="small" icon="edit" @click="handleUpdate(scope.row)"
v-hasPermi="['${replaceDto.PermissionPrefix}:addOrUpdateKey']">编辑</el-button>
v-hasPermi="['${replaceDto.PermissionPrefix}:addOrUpdate']">编辑</el-button>
$end
$if(replaceDto.ShowBtnDelete)
<el-button type="danger" size="small" icon="delete" @click="handleDelete(scope.row)"
@ -187,7 +187,7 @@ $end
$else
$if(replaceDto.ShowBtnEdit)
<el-button type="primary" size="small" icon="edit" @click="handleUpdate(scope.row)"
v-hasPermi="['${replaceDto.PermissionPrefix}:addOrUpdateKey']">编辑</el-button>
v-hasPermi="['${replaceDto.PermissionPrefix}:addOrUpdate']">编辑</el-button>
$end
$if(replaceDto.ShowBtnDelete)
<el-button type="danger" size="small" icon="delete" @click="handleDelete(scope.row)"