feat 添加涉及产品接口
This commit is contained in:
parent
9b8b05bc05
commit
4468dda253
@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using ARW.Model.Models.Business.ProductsInvolveds;
|
||||||
|
|
||||||
|
namespace ARW.Model.Dto.Business.ProductsInvolveds
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 涉及产品输入对象
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-11-22
|
||||||
|
/// </summary>
|
||||||
|
public class ProductsInvolvedDto
|
||||||
|
{
|
||||||
|
|
||||||
|
public int ProductsInvolvedId { get; set; }
|
||||||
|
|
||||||
|
public long ProductsInvolvedGuid { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "名称不能为空")]
|
||||||
|
public string ProductsInvolvedName { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "排序不能为空")]
|
||||||
|
public int ProductsInvolvedSort { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 涉及产品查询对象
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-11-22
|
||||||
|
/// </summary>
|
||||||
|
public class ProductsInvolvedQueryDto : PagerInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
public string ProductsInvolvedName { get; set; }
|
||||||
|
|
||||||
|
public string ids { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using SqlSugar;
|
||||||
|
using OfficeOpenXml.Attributes;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace ARW.Model.Models.Business.ProductsInvolveds
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 涉及产品,数据实体对象
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-11-22
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("tb_products_involved")]
|
||||||
|
public class ProductsInvolved : BusinessBase
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "ProductsInvolvedId")]
|
||||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "products_involved_id")]
|
||||||
|
public int ProductsInvolvedId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "ProductsInvolvedGuid")]
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "products_involved_guid")]
|
||||||
|
public long ProductsInvolvedGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :名称
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "名称")]
|
||||||
|
[SugarColumn(ColumnName = "products_involved_name")]
|
||||||
|
public string ProductsInvolvedName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :排序
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "排序")]
|
||||||
|
[SugarColumn(ColumnName = "products_involved_sort")]
|
||||||
|
public int ProductsInvolvedSort { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using OfficeOpenXml.Attributes;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ARW.Model.Vo.Business.ProductsInvolveds
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 涉及产品展示对象
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-11-22
|
||||||
|
/// </summary>
|
||||||
|
public class ProductsInvolvedVo
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :
|
||||||
|
/// </summary>
|
||||||
|
[EpplusIgnore]
|
||||||
|
public int ProductsInvolvedId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :
|
||||||
|
/// </summary>
|
||||||
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
|
[EpplusIgnore]
|
||||||
|
public long ProductsInvolvedGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :名称
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "涉及产品名称")]
|
||||||
|
public string ProductsInvolvedName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :排序
|
||||||
|
/// </summary>
|
||||||
|
[EpplusTableColumn(Header = "排序")]
|
||||||
|
public int ProductsInvolvedSort { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using Infrastructure.Attribute;
|
||||||
|
using ARW.Repository.System;
|
||||||
|
using ARW.Model.Models.Business.ProductsInvolveds;
|
||||||
|
|
||||||
|
namespace ARW.Repository.Business.ProductsInvolveds
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 涉及产品仓储
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-11-22
|
||||||
|
/// </summary>
|
||||||
|
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||||
|
public class ProductsInvolvedRepository : BaseRepository<ProductsInvolved>
|
||||||
|
{
|
||||||
|
#region 业务逻辑代码
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,170 @@
|
|||||||
|
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.ProductsInvolveds;
|
||||||
|
using ARW.Service.Business.IBusinessService.ProductsInvolveds;
|
||||||
|
using ARW.Model.Dto.Business.ProductsInvolveds;
|
||||||
|
using ARW.Model.Models.Business.ProductsInvolveds;
|
||||||
|
using ARW.Model.Vo.Business.ProductsInvolveds;
|
||||||
|
|
||||||
|
namespace ARW.Service.Business.BusinessService.ProductsInvolveds
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 涉及产品接口实现类
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-11-22
|
||||||
|
/// </summary>
|
||||||
|
[AppService(ServiceType = typeof(IProductsInvolvedService), ServiceLifetime = LifeTime.Transient)]
|
||||||
|
public class ProductsInvolvedServiceImpl : BaseService<ProductsInvolved>, IProductsInvolvedService
|
||||||
|
{
|
||||||
|
private readonly ProductsInvolvedRepository _ProductsInvolvedRepository;
|
||||||
|
|
||||||
|
public ProductsInvolvedServiceImpl(ProductsInvolvedRepository ProductsInvolvedRepository)
|
||||||
|
{
|
||||||
|
this._ProductsInvolvedRepository = ProductsInvolvedRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 业务逻辑代码
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询涉及产品分页列表
|
||||||
|
/// </summary>
|
||||||
|
public async Task<PagedInfo<ProductsInvolvedVo>> GetProductsInvolvedList(ProductsInvolvedQueryDto parm)
|
||||||
|
{
|
||||||
|
//开始拼装查询条件d
|
||||||
|
var predicate = Expressionable.Create<ProductsInvolved>();
|
||||||
|
|
||||||
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.ProductsInvolvedName), s => s.ProductsInvolvedName.Contains(parm.ProductsInvolvedName));
|
||||||
|
var query = _ProductsInvolvedRepository
|
||||||
|
.Queryable()
|
||||||
|
.Where(predicate.ToExpression())
|
||||||
|
.OrderBy(s => s.ProductsInvolvedSort,OrderByType.Asc)
|
||||||
|
.Select(s => new ProductsInvolvedVo
|
||||||
|
{
|
||||||
|
ProductsInvolvedId = s.ProductsInvolvedId,
|
||||||
|
ProductsInvolvedGuid = s.ProductsInvolvedGuid,
|
||||||
|
ProductsInvolvedName = s.ProductsInvolvedName,
|
||||||
|
ProductsInvolvedSort = s.ProductsInvolvedSort,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return await query.ToPageAsync(parm);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加或修改涉及产品
|
||||||
|
/// </summary>
|
||||||
|
public async Task<string> AddOrUpdateProductsInvolved(ProductsInvolved model)
|
||||||
|
{
|
||||||
|
if (model.ProductsInvolvedId != 0)
|
||||||
|
{
|
||||||
|
var response = await _ProductsInvolvedRepository.UpdateAsync(model);
|
||||||
|
return "修改成功!";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
var response = await _ProductsInvolvedRepository.InsertReturnSnowflakeIdAsync(model);
|
||||||
|
return "添加成功!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Excel处理
|
||||||
|
/// <summary>
|
||||||
|
/// 数据导入处理
|
||||||
|
/// </summary>
|
||||||
|
public async Task<ProductsInvolvedVo> HandleImportData(ProductsInvolvedVo ProductsInvolved)
|
||||||
|
{
|
||||||
|
return ProductsInvolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Excel导入
|
||||||
|
/// </summary>
|
||||||
|
public async Task<string> ImportExcel(ProductsInvolved ProductsInvolved,int index,bool isUpdateSupport,string user)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 空值判断
|
||||||
|
// if (ProductsInvolved.ProductsInvolvedId == null) throw new CustomException("涉及产品不能为空");
|
||||||
|
|
||||||
|
if (isUpdateSupport)
|
||||||
|
{
|
||||||
|
// 判断唯一值
|
||||||
|
var model = await GetFirstAsync(s => s.ProductsInvolvedId == ProductsInvolved.ProductsInvolvedId);
|
||||||
|
|
||||||
|
// 如果为空就新增数据
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
// 开启事务
|
||||||
|
var res = await UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
var addRes = await AddOrUpdateProductsInvolved(ProductsInvolved);
|
||||||
|
});
|
||||||
|
var addStr = $"第 {index} 行 => 涉及产品:【{ProductsInvolved.ProductsInvolvedId}】<span style='color:#27af49'>新增成功!</span><br>";
|
||||||
|
return addStr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 如果有数据就进行修改
|
||||||
|
// 开启事务
|
||||||
|
await UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
ProductsInvolved.ProductsInvolvedId = model.ProductsInvolvedId;
|
||||||
|
ProductsInvolved.ProductsInvolvedGuid = model.ProductsInvolvedGuid;
|
||||||
|
ProductsInvolved.Update_by = user;
|
||||||
|
ProductsInvolved.Update_time = DateTime.Now;
|
||||||
|
var editRes = await AddOrUpdateProductsInvolved(ProductsInvolved);
|
||||||
|
});
|
||||||
|
var editStr = $"第 {index} 行 => 涉及产品:【{ProductsInvolved.ProductsInvolvedId}】<span style='color:#e6a23c'>更新成功!</span><br>";
|
||||||
|
return editStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// 开启事务
|
||||||
|
var res = await UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
var addRes = await AddOrUpdateProductsInvolved(ProductsInvolved);
|
||||||
|
});
|
||||||
|
//Console.WriteLine(res.IsSuccess);
|
||||||
|
var addStr = $"第 {index} 行 => 涉及产品:【{ProductsInvolved.ProductsInvolvedId}】<span style='color:#27af49'>新增成功!</span><br>";
|
||||||
|
return addStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var errorRes = $"第 {index} 行 => 涉及产品:【{ProductsInvolved.ProductsInvolvedId}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
|
||||||
|
return errorRes;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Excel数据导出处理
|
||||||
|
/// </summary>
|
||||||
|
public async Task<List<ProductsInvolvedVo>> HandleExportData(List<ProductsInvolvedVo> data)
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ARW.Model;
|
||||||
|
using ARW.Model.Dto.Business.ProductsInvolveds;
|
||||||
|
using ARW.Model.Models.Business.ProductsInvolveds;
|
||||||
|
using ARW.Model.Vo.Business.ProductsInvolveds;
|
||||||
|
|
||||||
|
namespace ARW.Service.Business.IBusinessService.ProductsInvolveds
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 涉及产品接口类
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-11-22
|
||||||
|
/// </summary>
|
||||||
|
public interface IProductsInvolvedService : IBaseService<ProductsInvolved>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取涉及产品分页列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<PagedInfo<ProductsInvolvedVo>> GetProductsInvolvedList(ProductsInvolvedQueryDto parm);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加或修改涉及产品
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> AddOrUpdateProductsInvolved(ProductsInvolved parm);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据导入处理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="shopVo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ProductsInvolvedVo> HandleImportData(ProductsInvolvedVo ProductsInvolvedVo);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Excel导入
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ProductsInvolved"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> ImportExcel(ProductsInvolved ProductsInvolved,int index,bool isUpdateSupport,string user);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Excel导出
|
||||||
|
/// </summary>
|
||||||
|
Task<List<ProductsInvolvedVo>> HandleExportData(List<ProductsInvolvedVo> data);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,180 @@
|
|||||||
|
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.ProductsInvolveds;
|
||||||
|
using ARW.Service.Business.IBusinessService.ProductsInvolveds;
|
||||||
|
using ARW.Admin.WebApi.Controllers;
|
||||||
|
using ARW.Model.Models.Business.ProductsInvolveds;
|
||||||
|
using ARW.Model.Vo.Business.ProductsInvolveds;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using ARW.Admin.WebApi.Framework;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ARW.WebApi.Controllers.Business.ProductsInvolveds
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 涉及产品控制器
|
||||||
|
///
|
||||||
|
/// @author lwh
|
||||||
|
/// @date 2023-11-22
|
||||||
|
/// </summary>
|
||||||
|
[Verify]
|
||||||
|
[Route("business/[controller]")]
|
||||||
|
public class ProductsInvolvedController : BaseController
|
||||||
|
{
|
||||||
|
private readonly IProductsInvolvedService _ProductsInvolvedService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 依赖注入
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ProductsInvolvedService">涉及产品服务</param>
|
||||||
|
public ProductsInvolvedController(IProductsInvolvedService ProductsInvolvedService)
|
||||||
|
{
|
||||||
|
_ProductsInvolvedService = ProductsInvolvedService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取涉及产品列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm">查询参数</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("getProductsInvolvedList")]
|
||||||
|
[ActionPermissionFilter(Permission = "business:productsinvolved:list")]
|
||||||
|
public async Task<IActionResult> GetProductsInvolvedList([FromQuery] ProductsInvolvedQueryDto parm)
|
||||||
|
{
|
||||||
|
var res = await _ProductsInvolvedService.GetProductsInvolvedList(parm);
|
||||||
|
return SUCCESS(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加或修改涉及产品
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("addOrUpdateProductsInvolved")]
|
||||||
|
[ActionPermissionFilter(Permission = "business:productsinvolved:addOrUpdate")]
|
||||||
|
[Log(Title = "添加或修改涉及产品", BusinessType = BusinessType.ADDORUPDATE)]
|
||||||
|
public async Task<IActionResult> AddOrUpdateProductsInvolved([FromBody] ProductsInvolvedDto parm)
|
||||||
|
{
|
||||||
|
if (parm == null) { throw new CustomException("请求参数错误"); }
|
||||||
|
|
||||||
|
var modal = new ProductsInvolved();
|
||||||
|
if (parm.ProductsInvolvedId != 0) modal = parm.Adapt<ProductsInvolved>().ToUpdate(HttpContext);
|
||||||
|
else modal = parm.Adapt<ProductsInvolved>().ToCreate(HttpContext);
|
||||||
|
|
||||||
|
var res = await _ProductsInvolvedService.AddOrUpdateProductsInvolved(modal);
|
||||||
|
return SUCCESS(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除涉及产品
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpDelete("{ids}")]
|
||||||
|
[ActionPermissionFilter(Permission = "business:productsinvolved: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 = _ProductsInvolvedService.Delete(idsArr);
|
||||||
|
return SUCCESS("删除成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导入涉及产品
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
||||||
|
/// <param name="updateSupport">是否需要更新</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("importData")]
|
||||||
|
[Log(Title = "涉及产品导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
|
||||||
|
[ActionPermissionFilter(Permission = "business:productsinvolved:import")]
|
||||||
|
public async Task<IActionResult> ImportExcel([FromForm(Name = "file")] IFormFile formFile,bool updateSupport)
|
||||||
|
{
|
||||||
|
var isUpdateSupport = updateSupport;
|
||||||
|
IEnumerable<ProductsInvolvedVo> parm = ExcelHelper<ProductsInvolvedVo>.ImportData(formFile.OpenReadStream());
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
var msgList = new List<string>();
|
||||||
|
foreach (ProductsInvolvedVo item in parm)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
var ProductsInvolved = await _ProductsInvolvedService.HandleImportData(item);
|
||||||
|
var modal = ProductsInvolved.Adapt<ProductsInvolved>().ToCreate(HttpContext);
|
||||||
|
var user = JwtUtil.GetLoginUser(App.HttpContext).UserName;
|
||||||
|
var msg = await _ProductsInvolvedService.ImportExcel(modal,i,isUpdateSupport,user);
|
||||||
|
msgList.Add(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCESS(msgList.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 涉及产品导入模板下载
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("importTemplate")]
|
||||||
|
[Log(Title = "涉及产品模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public IActionResult ImportTemplateExcel()
|
||||||
|
{
|
||||||
|
List<ProductsInvolvedVo> ProductsInvolved = new List<ProductsInvolvedVo>();
|
||||||
|
MemoryStream stream = new MemoryStream();
|
||||||
|
|
||||||
|
// 示例数据
|
||||||
|
var values = new List<string>() { "人工智能", "100" };
|
||||||
|
string sFileName = DownloadImportTemplate(ProductsInvolved, stream, "涉及产品导入模板", values);
|
||||||
|
|
||||||
|
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{sFileName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导出涉及产品
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Log(Title = "涉及产品导出", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||||||
|
[HttpGet("exportProductsInvolved")]
|
||||||
|
[ActionPermissionFilter(Permission = "business:productsinvolved:export")]
|
||||||
|
public async Task<IActionResult> ExportExcel([FromQuery] ProductsInvolvedQueryDto parm)
|
||||||
|
{
|
||||||
|
parm.PageSize = 10000;
|
||||||
|
var list = await _ProductsInvolvedService.GetProductsInvolvedList(parm);
|
||||||
|
var data = list.Result;
|
||||||
|
|
||||||
|
// 选中数据
|
||||||
|
if (!string.IsNullOrEmpty(parm.ids))
|
||||||
|
{
|
||||||
|
int[] idsArr = Tools.SpitIntArrary(parm.ids);
|
||||||
|
var selectDataList = new List<ProductsInvolvedVo>();
|
||||||
|
foreach (var item in idsArr)
|
||||||
|
{
|
||||||
|
var select_data = data.Where(s => s.ProductsInvolvedId == item).First();
|
||||||
|
selectDataList.Add(select_data);
|
||||||
|
}
|
||||||
|
data = selectDataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 导出数据处理
|
||||||
|
var handleData = await _ProductsInvolvedService.HandleExportData(data);
|
||||||
|
|
||||||
|
string sFileName = ExportExcel(handleData, "ProductsInvolved", "涉及产品列表");
|
||||||
|
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user