优化 产品导入导出模板为一致

This commit is contained in:
袁锋 2025-11-15 23:32:27 +08:00
parent 9db1775917
commit eb1748ff79
4 changed files with 81 additions and 20 deletions

View File

@ -109,14 +109,14 @@ public class ProductInfoController {
@GetMapping("/export-excel")
@Operation(summary = "导出产品资料 Excel")
@PreAuthorize("@ss.hasPermission('oms:product-info:export')")
// @PreAuthorize("@ss.hasPermission('oms:product-info:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportProductInfoExcel(@Valid ProductInfoPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ProductInfoRespVO> list = productInfoService.getProductInfoPage(pageReqVO).getList();
List<ProductInfoExcelVO> list = productInfoService.exportExcel(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "产品资料.xlsx", "数据", ProductInfoRespVO.class,list);
ExcelUtils.write(response, "产品资料.xlsx", "数据", ProductInfoExcelVO.class,list);
}
}

View File

@ -34,6 +34,16 @@ public class ProductInfoExcelVO {
@HeadFontStyle(color = Font.COLOR_RED)
private String name;
@Schema(description = "*品类")
@ExcelColumnSelect(functionName = "ExcelSelectProductTypeFunction")
@ExcelProperty("*品类(尺码唛,价钱卡,纸盒,主唛,挂卡,洗水唛)")
@HeadFontStyle(color = Font.COLOR_RED)
private String productType;
@Schema(description = "*品牌名称")
@ExcelProperty("*品牌名称")
@HeadFontStyle(color = Font.COLOR_RED)
private String brandName;
@Schema(description = "产品简介")
@ExcelProperty("产品简介")
@ -57,16 +67,6 @@ public class ProductInfoExcelVO {
@ExcelProperty("材质(颜色)")
private String material;
@Schema(description = "品类")
@ExcelColumnSelect(functionName = "ExcelSelectProductTypeFunction")
@ExcelProperty("品类(尺码唛,价钱卡,纸盒,主唛,挂卡,洗水唛)")
private String productType;
@Schema(description = "品牌名称")
@ExcelProperty("品牌名称")
private String brandName;
@Schema(description = "备注")
@ExcelProperty("备注")
private String remarks;

View File

@ -63,6 +63,7 @@ public interface ProductInfoService {
* @return 产品资料 分页
*/
PageResult<ProductInfoRespVO> getProductInfoPage(ProductInfoPageReqVO pageReqVO);
PageResult<ProductInfoExcelVO> exportExcel(ProductInfoPageReqVO pageReqVO);
PageResult<ProductInfoRespVO> queryPage(QueryFilterInfo<ProductInfoPageReqVO> queryFilterInfo);

View File

@ -217,6 +217,52 @@ public class ProductInfoServiceImpl implements ProductInfoService {
});
return new PageResult<>(resList, productInfoDOPageResult.getTotal());
}
@Override
public PageResult<ProductInfoExcelVO> exportExcel(ProductInfoPageReqVO pageReqVO) {
PageResult<ProductInfoDO> productInfoDOPageResult = productInfoMapper.selectPage(pageReqVO);
List<ProductInfoDO> list = productInfoDOPageResult.getList();
List<ProductInfoExcelVO> resList = new ArrayList<>();
Set<String> groupIds = new HashSet<>();
Set<Long> productTypeIds = new HashSet<>();
Set<Long> brandIds = new HashSet<>();
for (ProductInfoDO infoDO : list) {
String customerGroupId = infoDO.getCustomerGroupId();
if(FuncUtil.isNotEmpty(customerGroupId)){
groupIds.add(customerGroupId);
}
Long productTypeId = infoDO.getProductTypeId();
if(FuncUtil.isNotEmpty(productTypeId)){
productTypeIds.add(productTypeId);
}
Long brandId = infoDO.getBrandId();
if(FuncUtil.isNotEmpty(brandId)){
brandIds.add(brandId);
}
}
initBrandNameCache(brandIds);
initCustomerGroupNameCache(groupIds);
initProductTypeNameCache(productTypeIds);
list.forEach(productInfoDO -> {
ProductInfoExcelVO vo = new ProductInfoExcelVO();
ProductInfoRespVO respVO = BeanUtils.toBean(productInfoDO, ProductInfoRespVO.class);
wrapperBrandName(respVO);
wrapperProductTypeName(respVO);
wrapperCustomerGroupName(respVO);
vo.setCode(productInfoDO.getCode());
vo.setName(productInfoDO.getName());
vo.setIntroduction(productInfoDO.getProductionInfo());
vo.setSpecWidth(FuncUtil.toStr(productInfoDO.getSpecSizeWidth(),""));
vo.setSpecHeight(FuncUtil.toStr(productInfoDO.getSpecSizeHeight(),""));
vo.setSpecThickness(FuncUtil.toStr(productInfoDO.getSpecSizeThk(),""));
vo.setMaterial(FuncUtil.toStr(productInfoDO.getSpecMaterial(),""));
vo.setProductType(respVO.getProductTypeName());
vo.setBrandName(respVO.getBrandName());
vo.setRemarks(productInfoDO.getRemark());
resList.add(vo);
});
return new PageResult<>(resList, productInfoDOPageResult.getTotal());
}
@Override
@ -311,6 +357,7 @@ public class ProductInfoServiceImpl implements ProductInfoService {
String code = excelVO.getCode();
if(FuncUtil.isNotEmpty(code)){
// 覆盖
try {
LambdaQueryWrapper<ProductInfoDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
@ -360,9 +407,23 @@ public class ProductInfoServiceImpl implements ProductInfoService {
code = productInfo.getCode();
}
if(FuncUtil.isEmpty(code)){
return ""+(i+1)+"行编码为空:"+code;
return ""+(i+1)+"行编码 不能为空:"+code;
}
String brandName = excelVO.getBrandName();
if(FuncUtil.isEmpty(brandName)){
return ""+(i+1)+"行品牌名称 不能为空:"+brandName;
}
String productType = excelVO.getProductType();
if(FuncUtil.isEmpty(productType)){
return ""+(i+1)+"行品类(尺码唛,价钱卡,纸盒,主唛,挂卡,洗水唛) 不能为空:"+brandName;
}
Long productTypeId = toProductTypeId(excelVO.getProductType());
if(FuncUtil.isEmpty(productTypeId)){
return ""+(i+1)+"行品类(尺码唛,价钱卡,纸盒,主唛,挂卡,洗水唛) 请维护该分类的的资料:"+brandName;
}
productInfo.setProductTypeId(productTypeId);
productInfo.setCode(code);
productInfo.setTemplateType("2");
@ -372,8 +433,6 @@ public class ProductInfoServiceImpl implements ProductInfoService {
productInfo.setSpecMaterial(excelVO.getMaterial());
productInfo.setRemark(excelVO.getRemarks());
Long productTypeId = toProductTypeId(excelVO.getProductType());
productInfo.setProductTypeId(productTypeId);
if(FuncUtil.isNotEmpty(brandName)){
Long brandId = brandIdCache.get(brandName);
@ -381,10 +440,11 @@ public class ProductInfoServiceImpl implements ProductInfoService {
productInfo.setBrandId(brandId);
}else {
BrandDO brandDO = brandService.getBrandByName(brandName);
if(FuncUtil.isNotEmpty(brandDO)){
productInfo.setBrandId(brandDO.getId());
brandIdCache.put(brandName,brandDO.getId());
if(FuncUtil.isEmpty(brandDO)){
return ""+(i+1)+"行品牌不存在,请维护该品牌的资料:"+brandName;
}
productInfo.setBrandId(brandDO.getId());
brandIdCache.put(brandName,brandDO.getId());
}
}
newList.add(productInfo);
@ -546,7 +606,7 @@ public class ProductInfoServiceImpl implements ProductInfoService {
if(FuncUtil.isNotEmpty(ids)){
List<ProductTypeDO> dos = productTypeMapper.selectBatchIds(ids);
for (ProductTypeDO db : dos) {
brandNameCache.put(db.getId(), db.getLabel());
ProductTypeNameCache.put(db.getId(), db.getLabel());
}
}
}