diff --git a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/controller/admin/productinfo/vo/ProductInfoExcelVO.java b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/controller/admin/productinfo/vo/ProductInfoExcelVO.java index bc5c463..5c424d6 100644 --- a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/controller/admin/productinfo/vo/ProductInfoExcelVO.java +++ b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/controller/admin/productinfo/vo/ProductInfoExcelVO.java @@ -1,5 +1,6 @@ package cn.hangtag.module.oms.controller.admin.productinfo.vo; +import cn.hangtag.framework.excel.core.annotations.ExcelColumnSelect; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.write.style.ContentStyle; import com.alibaba.excel.annotation.write.style.HeadFontStyle; @@ -23,12 +24,12 @@ import org.apache.poi.ss.usermodel.IndexedColors; @Accessors(chain = false) // 保持 chain = false 避免导入数据异常 public class ProductInfoExcelVO { - @Schema(description = "产品编码") + @Schema(description = "*产品编码") @ExcelProperty("*产品编码") @HeadFontStyle(color = Font.COLOR_RED) private String code; - @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "*产品编码", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("*产品名称") @HeadFontStyle(color = Font.COLOR_RED) private String name; @@ -56,6 +57,11 @@ public class ProductInfoExcelVO { @ExcelProperty("材质(颜色)") private String material; + @Schema(description = "品类") + @ExcelColumnSelect(functionName = "ExcelSelectProductTypeFunction") + @ExcelProperty("品类(尺码唛,价钱卡,纸盒,主唛,挂卡,洗水唛)") + private String productType; + @Schema(description = "品牌名称") @ExcelProperty("品牌名称") private String brandName; diff --git a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ExcelSelectProductTypeFunction.java b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ExcelSelectProductTypeFunction.java new file mode 100644 index 0000000..7379321 --- /dev/null +++ b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ExcelSelectProductTypeFunction.java @@ -0,0 +1,35 @@ +package cn.hangtag.module.oms.service.productinfo; + +import cn.hangtag.framework.excel.core.function.ExcelColumnSelectFunction; +import cn.hangtag.framework.mybatis.core.dataobject.BaseDO; +import cn.hangtag.module.oms.base.dal.dataobject.producttype.ProductTypeDO; +import cn.hangtag.module.oms.base.dal.mysql.producttype.ProductTypeMapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@Component +public class ExcelSelectProductTypeFunction implements ExcelColumnSelectFunction { + + @Resource + private ProductTypeMapper productTypeMapper; + @Override + public String getName() { + return "ExcelSelectProductTypeFunction"; + } + + @Override + public List getOptions() { + List dos = productTypeMapper.selectList(new LambdaQueryWrapper().eq(BaseDO::getDeleted, false) + .orderByDesc(ProductTypeDO::getSort)); + List labels = new ArrayList<>(); + for (ProductTypeDO aDo : dos) { + labels.add(aDo.getLabel()); + } + return labels; + } +} diff --git a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoServiceImpl.java b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoServiceImpl.java index 4f26802..384984d 100644 --- a/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoServiceImpl.java +++ b/hangtag-module-oms/hangtag-module-oms-biz/src/main/java/cn/hangtag/module/oms/service/productinfo/ProductInfoServiceImpl.java @@ -301,8 +301,11 @@ public class ProductInfoServiceImpl implements ProductInfoService { for (int i = 0; i < list.size(); i++) { ProductInfoExcelVO excelVO = list.get(i); + // 判断是否为空行 下拉导致很多空行 + if (isAllFieldsEmpty(excelVO)) { + continue; + } ProductInfoDO productInfo = new ProductInfoDO(); - String code = excelVO.getCode(); if(FuncUtil.isNotEmpty(code)){ try { @@ -313,10 +316,23 @@ public class ProductInfoServiceImpl implements ProductInfoService { }else { code = productInfo.getCode(); } + if(FuncUtil.isEmpty(code)){ + return "第"+(i+1)+"行编码为空:"+code; + } productInfo.setName(excelVO.getName()); String brandName = excelVO.getBrandName(); productInfo.setCode(code); productInfo.setTemplateType("2"); + + productInfo.setSpecSizeWidth(FuncUtil.toDouble(excelVO.getSpecWidth())); + productInfo.setSpecSizeHeight(FuncUtil.toDouble(excelVO.getSpecHeight())); + productInfo.setSpecSizeThk(FuncUtil.toDouble(excelVO.getSpecThickness())); + 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); if(FuncUtil.isNotEmpty(brandId)){ @@ -328,7 +344,6 @@ public class ProductInfoServiceImpl implements ProductInfoService { brandIdCache.put(brandName,brandDO.getId()); } } - } newList.add(productInfo); } @@ -337,7 +352,18 @@ public class ProductInfoServiceImpl implements ProductInfoService { return ""; } - + public boolean isAllFieldsEmpty(ProductInfoExcelVO excelVO) { + if (excelVO == null) { + return true; + } +// + if(FuncUtil.isEmpty(excelVO.getCode()) + && FuncUtil.isEmpty(excelVO.getName()) + ){ + return true; + } + return false; + } private List wrapperRespVO(List list){ List resList = new ArrayList<>(); list.forEach(productInfoDO -> { @@ -450,6 +476,25 @@ public class ProductInfoServiceImpl implements ProductInfoService { } return vo; } + private static LFUCache ProductTypeIdCache = CacheUtil.newLFUCache(10000, 1000 * 60 * 60); + + private Long toProductTypeId(String name){ + if(FuncUtil.isEmpty(name)){ + return null; + } + Long s = ProductTypeIdCache.get(name); + if (FuncUtil.isEmpty(s)) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(ProductTypeDO::getLabel,name); + lambdaQueryWrapper.last("limit 1"); + ProductTypeDO productTypeDO = productTypeMapper.selectOne(lambdaQueryWrapper); + if(FuncUtil.isNotEmpty(productTypeDO)){ + s = productTypeDO.getId(); + ProductTypeIdCache.put(name, productTypeDO.getId()); + } + } + return s; + } private void initProductTypeNameCache(Set ids){ if(FuncUtil.isNotEmpty(ids)){ List dos = productTypeMapper.selectBatchIds(ids); diff --git a/hangtag-ui/hangtag-ui-admin/src/views/oms/productinfo/index.vue b/hangtag-ui/hangtag-ui-admin/src/views/oms/productinfo/index.vue index e3f6b01..778654a 100644 --- a/hangtag-ui/hangtag-ui-admin/src/views/oms/productinfo/index.vue +++ b/hangtag-ui/hangtag-ui-admin/src/views/oms/productinfo/index.vue @@ -111,8 +111,17 @@ excel导入 - + + + + 下载模板 +