Bladeren bron

物料库导出

yzc 1 jaar geleden
bovenliggende
commit
4bc314c732

+ 7 - 4
hx-item/src/main/java/com/fjhx/item/entity/product/bo/MaterialExcelExportBo.java

@@ -1,5 +1,6 @@
 package com.fjhx.item.entity.product.bo;
 
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
 import com.alibaba.excel.annotation.write.style.ColumnWidth;
 import com.alibaba.excel.annotation.write.style.ContentRowHeight;
@@ -11,8 +12,10 @@ import java.math.BigDecimal;
 
 @Getter
 @Setter
+@ExcelIgnoreUnannotated
 @ContentRowHeight(50)
 public class MaterialExcelExportBo {
+    private String productImgPath;
     @ColumnWidth(10)
     @ExcelProperty("物料图片")
     private WriteCellData<Void> productImg;
@@ -21,13 +24,13 @@ public class MaterialExcelExportBo {
     private String productClassifyNames;
     @ColumnWidth(15)
     @ExcelProperty("物料名称")
-    private String productName;
+    private String name;
     @ColumnWidth(15)
     @ExcelProperty("物料编号")
-    private String productCode;
+    private String customCode;
     @ColumnWidth(15)
     @ExcelProperty("关联原材料")
-    private String rawMaterialName;
+    private String attrRawMaterialName;
     @ColumnWidth(15)
     @ExcelProperty("材质")
     private String material;
@@ -48,7 +51,7 @@ public class MaterialExcelExportBo {
     private String colorLayer;
     @ColumnWidth(15)
     @ExcelProperty("颜色")
-    private String productColor;
+    private String color;
     @ColumnWidth(15)
     @ExcelProperty("安全库存")
     private String stockThreshold;

+ 3 - 0
hx-item/src/main/java/com/fjhx/item/entity/product/bo/ProductExcelExportBo.java

@@ -1,5 +1,6 @@
 package com.fjhx.item.entity.product.bo;
 
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
 import com.alibaba.excel.annotation.write.style.ColumnWidth;
 import com.alibaba.excel.annotation.write.style.ContentRowHeight;
@@ -12,7 +13,9 @@ import java.math.BigDecimal;
 @Getter
 @Setter
 @ContentRowHeight(50)
+@ExcelIgnoreUnannotated
 public class ProductExcelExportBo {
+    private String productImgPath;
     @ColumnWidth(10)
     @ExcelProperty("产品图片")
     private WriteCellData<Void> productImg;

+ 74 - 172
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -54,15 +54,14 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import javax.imageio.IIOException;
 import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.math.BigDecimal;
 import java.net.URL;
 import java.util.*;
+import java.util.function.BiConsumer;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -356,90 +355,9 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         saveOrEditCustomInfo(productInfoDto);
     }
 
-//    /**
-//     * 获取产品价格
-//     */
-//    @Override
-//    public ProductInfo getProductPrice(ProductInfo productInfo) {
-//        Long id = productInfo.getId();
-//        BigDecimal length = productInfo.getLength();
-//        BigDecimal width = productInfo.getWidth();
-//        Long technologyId = productInfo.getTechnologyId();
-//        Assert.notEmpty(length, "产品长度不能为空!");
-//        Assert.notEmpty(width, "产品宽度不能为空!");
-//        Assert.notEmpty(technologyId, "工艺id不能为空");
-//
-//        //获取物料价格
-//        BigDecimal materialPrice = BigDecimal.ZERO;
-//        List<ProductBomDetail> productBomDetailList = new ArrayList<>();
-//        if (ObjectUtil.isNotEmpty(id)) {
-//            productBomDetailList = productBomDetailService.list(q -> q.eq(ProductBomDetail::getProductId, id));
-//        } else {
-//            ProductBomDetail productBomDetail = new ProductBomDetail();
-//            productBomDetail.setMaterialId(productInfo.getRawMaterialId());
-//            productBomDetail.setType(1);
-//            productBomDetail.setQuantity(BigDecimal.ONE);
-//            productBomDetailList.add(productBomDetail);
-//        }
-//
-//        for (ProductBomDetail productBomDetail : productBomDetailList) {
-//            ProductInfo materialInfo = this.getById(productBomDetail.getMaterialId());
-//            if (ObjectUtil.equals(productBomDetail.getType(), 1)) {
-//                //原材料 产品长 * 产品宽 * 原材料单价
-//                BigDecimal multiply = length.multiply(width).multiply(materialInfo.getPrice());
-//                materialPrice = materialPrice.add(multiply);
-//            } else {
-//                //普通物料 产品库BOM该物料数量 * 物料单价
-//                BigDecimal multiply = productBomDetail.getQuantity().multiply(materialInfo.getPrice());
-//                materialPrice = materialPrice.add(multiply);
-//            }
-//        }
-//
-//        //获取工序价格
-//        List<ProcessesBo> processesList = baseMapper.getProcessesByTechnologyId(productInfo.getTechnologyId());
-//        BigDecimal processesPrice = processesList.stream().map(ProcessesBo::getCostPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
-//
-//        productInfo.setPrice(materialPrice.add(processesPrice));
-//        return productInfo;
-//    }
-
     @DSTransactional
     @Override
     public void edit(ProductInfoDto productInfoDto) {
-
-//        //修改物料时 更新关联产品价格
-//        if (ObjectUtil.equals(productInfoDto.getDefinition(), 2)) {
-//            List<ProductBomDetail> productBomDetailList = productBomDetailService.list(q -> q
-//                    .eq(ProductBomDetail::getMaterialId, productInfoDto.getId())
-//            );
-//
-//            //获取物料信息
-//            ProductInfo materialInfo = this.getById(productInfoDto.getId());
-//            BigDecimal oldPrice = materialInfo.getPrice();
-//            BigDecimal newPrice = productInfoDto.getPrice();
-//
-//            for (ProductBomDetail productBomDetail : productBomDetailList) {
-//                ProductInfo productInfo = this.getById(productBomDetail.getProductId());
-//
-//                if (ObjectUtil.equals(productBomDetail.getType(), 1)) {
-//                    oldPrice = productInfo.getLength().multiply(productInfo.getWidth()).multiply(oldPrice);
-//                    newPrice = productInfo.getLength().multiply(productInfo.getWidth()).multiply(newPrice);
-//                } else {
-//                    oldPrice = oldPrice.multiply(productBomDetail.getQuantity());
-//                    newPrice = newPrice.multiply(productBomDetail.getQuantity());
-//                }
-//
-//                BigDecimal subtract = newPrice.subtract(oldPrice);
-//                this.update(q -> q
-//                        .in(ProductInfo::getId, productInfo.getId())
-//                        .setSql("price = price + " + subtract)
-//                        .set(BasePo::getUpdateTime, new Date())
-//                        .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-//                );
-//            }
-//        }
-
-
         // 禁止产品编号修改
         productInfoDto.setCode(null);
         //检查【产品名称】和【规格型号】不能同时重复,但可以单项重复。
@@ -469,9 +387,6 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             productInfoDto.setCompanyId(SecurityUtils.getCompanyId());
         }
 
-//        //修改产品时 修改原材料
-//        saveOrEditRawMaterial(productInfoDto);
-
         this.updateById(productInfoDto);
         ObsFileUtil.editFile(productInfoDto.getFileList(), productInfoDto.getId());
         ObsFileUtil.editFile(productInfoDto.getProdFileList(), productInfoDto.getId(), 2);
@@ -509,36 +424,6 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         }
     }
 
-//    /**
-//     * 保存修改产品原材料
-//     */
-//    private void saveOrEditRawMaterial(ProductInfoDto productInfoDto) {
-//        //操作非产品时跳过
-//        if (ObjectUtil.notEqual(productInfoDto.getDefinition(), 1)) {
-//            return;
-//        }
-//
-//        Long rawMaterialId = productInfoDto.getRawMaterialId();
-//        Assert.notEmpty(rawMaterialId, "原材料Id不能为空");
-//
-//        List<ProductBomDetail> productBomDetailList = productInfoDto.getProductBomDetailList();
-//        if (ObjectUtil.isNotEmpty(productBomDetailList)) {
-//            List<ProductBomDetail> rawMaterialList = productBomDetailList.stream()
-//                    .filter(item -> ObjectUtil.equals(item.getType(), 1)).collect(Collectors.toList());
-//
-//            if (ObjectUtil.isEmpty(rawMaterialList)) {
-//                ProductBomDetail productBomDetail = new ProductBomDetail();
-//                productBomDetail.setMaterialId(rawMaterialId);
-//                productBomDetail.setType(1);
-//                productBomDetail.setQuantity(BigDecimal.ONE);
-//                productBomDetailList.add(productBomDetail);
-//            } else {
-//                ProductBomDetail productBomDetail = rawMaterialList.get(0);
-//                productBomDetail.setMaterialId(rawMaterialId);
-//            }
-//        }
-//    }
-
     @DSTransactional
     @Override
     public void delete(Long id) {
@@ -578,7 +463,6 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
     @DSTransactional
     @Override
     public synchronized void editAvailableQuantity(List<AvailableStockBo> inOutList, Long businessId, ProductAvailableRecordType businessType, Long companyId) {
-
         if (ObjectUtil.isEmpty(inOutList)) {
             return;
         }
@@ -1102,9 +986,35 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         return baseMapper.getProductAnalysisPage(page, wrapper);
     }
 
+    private <T> void setExcelImg(List<T> list, SFunction<T, String> getIdFun, BiConsumer<T, WriteCellData> setBic) {
+        for (T t : list) {
+            try {
+                String fileUrl = getIdFun.apply(t);
+                //解析图片后缀
+                int lastIndex = fileUrl.lastIndexOf(".");
+                String suffix = fileUrl.substring(lastIndex + 1, fileUrl.length());
 
-    private List<ProductExcelExportBo> excelExportComm(ProductInfoSelectDto dto) {
+                BufferedImage image = ImageIO.read(new URL(fileUrl));
+                if (ObjectUtil.isNotEmpty(image)) {
+                    //获取图片宽高,用以计算比例
+                    Double imgWidth = Double.valueOf(image.getWidth());
+                    Double imgHeight = Double.valueOf(image.getHeight());
+                    //------------------
+                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                    ImageIO.write(image, suffix, baos);
+                    WriteCellData<Void> voidWriteCellData = ExcelImgUtils.imageCells(baos.toByteArray(), imgWidth, imgHeight, 10.0 * 5.8, 50.0);
+                    setBic.accept(t, voidWriteCellData);
+                }
+            } catch (Exception e) {
+                log.warn(String.format("Excel导出图片处理异常:(%s) %s", e.getClass().getSimpleName(), e.getMessage()));
+            }
+        }
+    }
+
+    @Override
+    public void excelExport(HttpServletResponse httpServletResponse, ProductInfoSelectDto dto) {
         IWrapper<ProductInfo> wrapper = getPageWrapper(dto);
+        wrapper.eq("pi", ProductInfo::getDefinition, 1);
         List<ProductInfoVo> productInfoList = baseMapper.getList(wrapper);
         List<Long> pIds = productInfoList.stream().map(ProductInfo::getId).collect(Collectors.toList());
 
@@ -1132,30 +1042,8 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             //获取产品图片信息
             List<FileInfoVo> fileInfoVoList = fileMap.get(productInfo.getId());
             if (ObjectUtil.isNotEmpty(fileInfoVoList)) {
-                try {
-                    String fileUrl = fileInfoVoList.get(0).getFileUrl();
-
-                    //解析图片后缀
-                    int lastIndex = fileUrl.lastIndexOf(".");
-                    String suffix = fileUrl.substring(lastIndex + 1, fileUrl.length());
-
-                    BufferedImage image = ImageIO.read(new URL(fileUrl));
-                    if (ObjectUtil.isNotEmpty(image)) {
-                        //获取图片宽高,用以计算比例
-                        Double imgWidth = Double.valueOf(image.getWidth());
-                        Double imgHeight = Double.valueOf(image.getHeight());
-                        //------------------
-                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                        ImageIO.write(image, suffix, baos);
-                        WriteCellData<Void> voidWriteCellData = ExcelImgUtils.imageCells(baos.toByteArray(), imgWidth, imgHeight, 10.0 * 5.8, 50.0);
-                        bo.setProductImg(voidWriteCellData);
-                    }
-                } catch (IIOException iioe) {
-                    log.error(iioe.getMessage());
-                } catch (IOException e) {
-                    log.error("导出失败" + e.getMessage(), e);
-                    throw new ServiceException("导出失败" + e.getMessage());
-                }
+                String fileUrl = fileInfoVoList.get(0).getFileUrl();
+                bo.setProductImgPath(fileUrl);
             }
 
             bo.setProductCode(productInfo.getCustomCode());
@@ -1187,44 +1075,58 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
 
             productExcelExportBoList.add(bo);
         }
-        return productExcelExportBoList;
-    }
 
-    private <V> void setExcelImg(List<V> list, SFunction<V, String> getIdFun, SFunction<V, WriteCellData> setFun) {
-        for (V v : list) {
-            try {
-                String fileUrl = getIdFun.apply(v);
-                //解析图片后缀
-                int lastIndex = fileUrl.lastIndexOf(".");
-                String suffix = fileUrl.substring(lastIndex + 1, fileUrl.length());
+        //处理产品图片
+        setExcelImg(productExcelExportBoList, ProductExcelExportBo::getProductImgPath, ProductExcelExportBo::setProductImg);
 
-                BufferedImage image = ImageIO.read(new URL(fileUrl));
-                if (ObjectUtil.isNotEmpty(image)) {
-                    //获取图片宽高,用以计算比例
-                    Double imgWidth = Double.valueOf(image.getWidth());
-                    Double imgHeight = Double.valueOf(image.getHeight());
-                    //------------------
-                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                    ImageIO.write(image, suffix, baos);
-                    WriteCellData<Void> voidWriteCellData = ExcelImgUtils.imageCells(baos.toByteArray(), imgWidth, imgHeight, 10.0 * 5.8, 50.0);
-                    setFun.apply(v).setData(voidWriteCellData);
-                }
-            } catch (Exception e) {
-                log.warn(String.format("Excel导出图片处理异常:(%s) %s", e.getClass().getSimpleName(), e.getMessage()));
-            }
-        }
-    }
 
-    @Override
-    public void excelExport(HttpServletResponse httpServletResponse, ProductInfoSelectDto dto) {
-        List<ProductExcelExportBo> productExcelExportBoList = excelExportComm(dto);
         ExcelUtil.export(httpServletResponse, productExcelExportBoList, ProductExcelExportBo.class);
     }
 
     @Override
     public void materialExcelExport(HttpServletResponse httpServletResponse, ProductInfoSelectDto dto) {
-        List<ProductExcelExportBo> productExcelExportBoList = excelExportComm(dto);
-        List<MaterialExcelExportBo> materialExcelExportBos = BeanUtil.copyToList(productExcelExportBoList, MaterialExcelExportBo.class);
+        IWrapper<ProductInfo> wrapper = getPageWrapper(dto);
+        wrapper.eq("pi", ProductInfo::getDefinition, 2);
+        List<ProductInfoVo> productInfoList = baseMapper.getList(wrapper);
+        setPageInfo(productInfoList);
+
+        //处理物料图片
+        List<Long> pIds = productInfoList.stream().map(ProductInfo::getId).collect(Collectors.toList());
+        Map<Long, List<FileInfoVo>> fileMap = ObsFileUtil.getFileMap(pIds, 0);
+
+        Map<String, Map<String, String>> allDictKVMap = DictUtils.getAllDictKVMap();
+
+        List<MaterialExcelExportBo> materialExcelExportBos = new ArrayList<>();
+        for (ProductInfoVo productInfo : productInfoList) {
+            MaterialExcelExportBo bo = BeanUtil.copyProperties(productInfo, MaterialExcelExportBo.class);
+
+            //获取物料图片信息
+            List<FileInfoVo> fileInfoVoList = fileMap.get(productInfo.getId());
+            if (ObjectUtil.isNotEmpty(fileInfoVoList)) {
+                String fileUrl = fileInfoVoList.get(0).getFileUrl();
+                bo.setProductImgPath(fileUrl);
+            }
+
+            bo.setFrontalTexture(allDictKVMap.get("front_lines").get(productInfo.getFrontalTexture()));
+            bo.setReverseTexture(allDictKVMap.get("back_lines").get(productInfo.getReverseTexture()));
+            bo.setColorLayer(allDictKVMap.get("color_layer").get(productInfo.getColorLayer()));
+
+            //处理长宽高
+            BigDecimal length = productInfo.getLength();
+            BigDecimal width = productInfo.getWidth();
+            BigDecimal height = productInfo.getHeight();
+            bo.setProductSize(String.format("%s * %s * %s",
+                    ObjectUtil.isEmpty(length) ? BigDecimal.ZERO : length,
+                    ObjectUtil.isEmpty(width) ? BigDecimal.ZERO : width,
+                    ObjectUtil.isEmpty(height) ? BigDecimal.ZERO : height)
+            );
+
+            materialExcelExportBos.add(bo);
+        }
+
+        //处理物料图片
+        setExcelImg(materialExcelExportBos, MaterialExcelExportBo::getProductImgPath, MaterialExcelExportBo::setProductImg);
+
         ExcelUtil.export(httpServletResponse, materialExcelExportBos, MaterialExcelExportBo.class);
     }