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.GoodsServicess; using ARW.Service.Business.IBusinessService.GoodsManager.GoodsServicess; using ARW.Admin.WebApi.Controllers; using ARW.Model.Models.Business.GoodsManager.GoodsServicess; using ARW.Model.Vo.Business.GoodsManager.GoodsServicess; using Microsoft.AspNetCore.Authorization; using ARW.Admin.WebApi.Framework; using ARW.Service.Business.IBusinessService.ShopManager.Shops; namespace ARW.WebApi.Controllers.Business.GoodsManager.GoodsServicess { /// /// 商品服务与承诺控制器 /// /// @author lwh /// @date 2023-06-18 /// [Verify] [Route("business/[controller]")] public class GoodsServicesController : BaseController { private readonly IGoodsServicesService _GoodsServicesService; private readonly IShopService _ShopService; /// /// 依赖注入 /// /// 商品服务与承诺服务 public GoodsServicesController(IGoodsServicesService GoodsServicesService, IShopService shopService) { _GoodsServicesService = GoodsServicesService; _ShopService = shopService; } /// /// 获取商品服务与承诺列表 /// /// 查询参数 /// [HttpGet("getGoodsServicesList")] [ActionPermissionFilter(Permission = "business:goodsservices:list")] public async Task GetGoodsServicesList([FromQuery] GoodsServicesQueryDto 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 _GoodsServicesService.GetGoodsServicesList(parm); return SUCCESS(res); } /// /// 添加或修改商品服务与承诺 /// /// /// [HttpPost("addOrUpdateGoodsServices")] [ActionPermissionFilter(Permission = "business:goodsservices:addOrUpdate")] [Log(Title = "添加或修改商品服务与承诺", BusinessType = BusinessType.ADDORUPDATE)] public async Task AddOrUpdateGoodsServices([FromBody] GoodsServicesDto parm) { if (parm == null) { throw new CustomException("请求参数错误"); } var modal = new GoodsServices(); if (parm.GoodsServicesId != 0) modal = parm.Adapt().ToUpdate(HttpContext); else modal = parm.Adapt().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 _GoodsServicesService.AddOrUpdateGoodsServices(modal); return SUCCESS(res); } /// /// 删除商品服务与承诺 /// /// [HttpDelete("{ids}")] [ActionPermissionFilter(Permission = "business:goodsservices: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 = _GoodsServicesService.Delete(idsArr); return SUCCESS("删除成功!"); } /// /// 导出商品服务与承诺 /// /// [Log(Title = "商品服务与承诺导出", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)] [HttpGet("exportGoodsServices")] [ActionPermissionFilter(Permission = "business:goodsservices:export")] public async Task ExportExcel([FromQuery] GoodsServicesQueryDto parm) { parm.PageSize = 10000; var list = await _GoodsServicesService.GetGoodsServicesList(parm); var data = list.Result; // 选中数据 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.GoodsServicesId == item).First(); selectDataList.Add(select_data); } data = selectDataList; } // 导出数据处理 var handleData = await _GoodsServicesService.HandleExportData(data); string sFileName = ExportExcel(handleData, "GoodsServices", "商品服务与承诺列表"); return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); } } }