whycxzp
2022-10-17 04d13e3a41ef798e07c25c1d3ad2002270a9cb76
src/main/java/com/whyc/service/ProductService.java
@@ -3,7 +3,6 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.FileUrlDTO;
import com.whyc.dto.Response;
@@ -11,6 +10,7 @@
import com.whyc.pojo.*;
import com.whyc.util.ActionUtil;
import com.whyc.util.CommonUtil;
import com.whyc.util.DateUtil;
import com.whyc.util.FileUtil;
import com.whyc.util.Zip4jUtil;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -45,6 +45,9 @@
    @Autowired
    private MaterialService mService;
    @Autowired
    private ProductLockLogService productLockLogService;
    //查询出所有的产品信息(分页加模糊查询<产品的编码,型号,名字,定制表编号>
    public Response getAllProduct(String subCode,String parentCode, String parentName, String parentModel, String customCode, int pageCurr, int pageSize) {
@@ -142,12 +145,34 @@
        for (int i = 0; i < fileList.size(); i++) {
            String fileTempUrl = fileList.get(i);
            //查询需上传的bom数据
            if (fileTempUrl.contains(".xls") && fileTempUrl.contains("(BOM)")) {
            //if (fileTempUrl.contains(".xls") && fileTempUrl.contains("(BOM)")) {
            if (fileTempUrl.substring(fileTempUrl.lastIndexOf(File.separator)+1).contains("(BOM).xls")) {
                Workbook workbook = null;
                InputStream inputStream = new FileInputStream(new File(fileTempUrl));
                workbook = WorkbookFactory.create(inputStream);
                inputStream.close();
                List<? extends PictureData> allPictures = workbook.getAllPictures();
                if(fileTempUrl.substring(fileTempUrl.lastIndexOf(".")+1).equals("xlsx")) {
                    Collections.sort(allPictures, new Comparator<PictureData>() {
                        @Override
                        public int compare(PictureData o1, PictureData o2) {
                            // Name: /xl/media/image1.png - Content Type: image/png
                            String s1 = o1.toString();
                            int contentTypeIndex = s1.indexOf(" - Content Type");
                            String s1Front = s1.substring(0, contentTypeIndex);
                            String imageNumStr1 = s1Front.substring(s1Front.lastIndexOf("/") + 1, s1Front.lastIndexOf(".")).replace("image", "");
                            String s2 = o2.toString();
                            int contentTypeIndex2 = s2.indexOf(" - Content Type");
                            String s2Front = s2.substring(0, contentTypeIndex2);
                            String imageNumStr2 = s2Front.substring(s2Front.lastIndexOf("/") + 1, s2Front.lastIndexOf(".")).replace("image", "");
                            return Integer.parseInt(imageNumStr1) - Integer.parseInt(imageNumStr2);
                        }
                    });
                }
                //取第一个sheet表
                Sheet sheet = workbook.getSheetAt(0);
                int lastRowNum = sheet.getLastRowNum();
@@ -170,6 +195,9 @@
                            cellValueInt = cell.getNumericCellValue();
                        } else if (j != 15) {
                            cellValue = cell.getStringCellValue();
                        }
                        if(cellValue!=null) {
                            cellValue = cellValue.trim();
                        }
                        switch (j) {
                            case 0: {
@@ -244,8 +272,8 @@
                                        provingFile.mkdirs();
                                    }
                                    String suffix = pictureData.suggestFileExtension();
                                    String picturePath = approvingPath + File.separator + bom.getSubModel() + "." + suffix;
                                    String picturePathFront = "doc_file" + File.separator + "product_submit" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp + File.separator + bom.getSubModel() + "." + suffix;
                                    String picturePath = approvingPath + File.separator + bom.getSubModel() + "-bom." + suffix;
                                    String picturePathFront = "doc_file" + File.separator + "product_submit" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp + File.separator + bom.getSubModel() + "-bom." + suffix;
                                    byte[] data = pictureData.getData();
                                    FileOutputStream fileOutputStream = null;
                                    File pictureFile = new File(picturePath);
@@ -436,6 +464,12 @@
                bomHistory.setProductId(his.getId());
                bomHistory.setMaterialId(bom.getMaterialId());
                bomHistory.setQuantity(bom.getQuantity());
                bomHistory.setCategory(bom.getCategory());
                bomHistory.setMaterial(bom.getMaterial());
                bomHistory.setNotes(bom.getNotes());
                bomHistory.setProducer(bom.getProducer());
                bomHistory.setSurfaceDetail(bom.getSurfaceDetail());
                bomHistory.setThickness(bom.getThickness());
                bomHistory.setSubSVersion(1);
                bomHistory.setSubEVersion(1);
                bomHistoryList.add(bomHistory);
@@ -444,8 +478,8 @@
        }else {
            File file = new File(fileUrl);
            List<String> fileUrlList = new LinkedList<>();
            List<String> dwgUrlList = null;
            List<String> picUrlList = null;
            List<String> excelExcludeUrlList = null;
            List<String> picUrlList = new LinkedList<>();
            //存于物料下,bom内有对应
            List<String> materialUrlList = new LinkedList<>();
            //存于产品下,bom内没对应
@@ -455,17 +489,17 @@
            fileUrlList = FileUtil.getStaticFilePath(file, fileUrlList);
            //图纸dwg 子件/产品
            dwgUrlList = fileUrlList.stream().filter(url -> url.contains(".dwg")).collect(Collectors.toList());
            picUrlList = fileUrlList.stream().filter(url -> url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList());
            excelExcludeUrlList = fileUrlList.stream().filter(url -> !(url.contains(".xls") || url.contains(".xlsx"))).collect(Collectors.toList());
            //picUrlList = fileUrlList.stream().filter(url -> url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList());
            List<ProductBom> finalBomList = bomList;
            dwgUrlList.forEach(dwgUrl -> {
            excelExcludeUrlList.forEach(excelExcludeUr -> {
                boolean existFlag = false;
                for (ProductBom bom : finalBomList) {
                    String filename = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1, dwgUrl.length() - 4);
                    String fileFullName = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1);
                    if (bom.getSubModel().toUpperCase().equals(filename.toUpperCase())) {
                        materialUrlList.add(dwgUrl);
                    String filename = excelExcludeUr.substring(excelExcludeUr.lastIndexOf(File.separator) + 1, excelExcludeUr.lastIndexOf("."));
                    String fileFullName = excelExcludeUr.substring(excelExcludeUr.lastIndexOf(File.separator) + 1);
                    if (bom.getSubModel().toUpperCase().equals(filename.toUpperCase()) && excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("dwg")) {
                        materialUrlList.add(excelExcludeUr);
                        existFlag = true;
@@ -473,24 +507,34 @@
                                + File.separator + fileFullName);
                        break;
                    }
                }
                if (!existFlag) {
                    productUrlList.add(dwgUrl);
                }
            });
                    else if((bom.getSubModel().toUpperCase()+"-BOM").equals(filename.toUpperCase()) && (excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("png") ||excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("jpeg"))
                    ){
                        picUrlList.add(excelExcludeUr);
                        existFlag = true;
            //一定是有对应物料的,从bom内剥离的
            picUrlList.forEach(picUrl -> {
                for (ProductBom bom : finalBomList) {
                    String filename = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1, picUrl.lastIndexOf("."));
                    String fileFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1);
                    if (bom.getSubModel().toUpperCase().equals(filename.toUpperCase())) {
                        bom.setPictureUrl("doc_file" + File.separator + "material"
                                + File.separator + fileFullName);
                        break;
                    }
                }
                if (!existFlag) {
                    productUrlList.add(excelExcludeUr);
                }
            });
            /*//一定是有对应物料的,包含从bom内剥离的(删除掉:上面已经处理)
            picUrlList.forEach(picUrl -> {
                for (ProductBom bom : finalBomList) {
                    String filename = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1, picUrl.lastIndexOf("."));
                    String fileFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1);
                    if ((bom.getSubModel().toUpperCase()+"-BOM").equals(filename.toUpperCase())) {
                        bom.setPictureUrl("doc_file" + File.separator + "material"
                                + File.separator + fileFullName);
                        break;
                    }
                }
            });*/
            //转移路径
            String projectDir = CommonUtil.getProjectDir();
@@ -514,10 +558,10 @@
                materialFile.mkdirs();
            }
            productUrlList.forEach(productUrl -> {
                String dwgName = productUrl.substring(productUrl.lastIndexOf(File.separator) + 1, productUrl.length() - 4);
                String fileName = productUrl.substring(productUrl.lastIndexOf(File.separator) + 1);
                try {
                    FileCopyUtils.copy(new File(productUrl), new File(productDir + File.separator + dwgName + ".dwg"));
                    FileCopyUtils.copy(new File(productUrl), new File(productDir + File.separator + fileName));
                } catch (IOException e) {
                    e.printStackTrace();
                }
@@ -549,21 +593,15 @@
            bomList.forEach(bom -> {
                if (!subCodeList.contains(bom.getSubCode()+"/"+bom.getSubModel())) {
                    Material material = new Material();
                    material.setCategory(bom.getCategory());
                    material.setCreateDate(bom.getCreateDate());
                    material.setCreateDate(date);
                    material.setDwgUrl(bom.getDwgUrl());
                    material.setFileUrl(bom.getFileUrl());
                    material.setMaterial(bom.getMaterial());
                    material.setNotes(bom.getNotes());
                    material.setPictureUrl(bom.getPictureUrl());
                    material.setProducer(bom.getProducer());
                    // TODO 是否要更新同物料编码的老物料状态为0?
                    material.setStatus(1);
                    material.setSubCode(bom.getSubCode());
                    material.setSubModel(bom.getSubModel());
                    material.setSubName(bom.getSubName());
                    material.setSurfaceDetail(bom.getSurfaceDetail());
                    material.setThickness(bom.getThickness());
                    material.setType(bom.getType());
                    material.setUnit(bom.getUnit());
@@ -577,6 +615,7 @@
                material.setSubCode(product.getParentCode());
                material.setSubName(product.getParentName());
                material.setSubModel(product.getParentModel());
                material.setCreateDate(date);
                material.setStatus(1);
                materialList.add(material);
@@ -615,6 +654,12 @@
                bom.setProductId(product.getId());
                bom.setMaterialId(bomMaterial.getId());
                bom.setQuantity(bomMaterial.getQuantity());
                bom.setCategory(bomMaterial.getCategory());
                bom.setMaterial(bomMaterial.getMaterial());
                bom.setNotes(bomMaterial.getNotes());
                bom.setProducer(bomMaterial.getProducer());
                bom.setSurfaceDetail(bomMaterial.getSurfaceDetail());
                bom.setThickness(bomMaterial.getThickness());
                bom.setSubVersion(1);
                bom.setCreateDate(date);
@@ -628,6 +673,12 @@
                bomHistory.setProductId(productHistory.getId());
                bomHistory.setMaterialId(bomMaterial.getId());
                bomHistory.setQuantity(bomMaterial.getQuantity());
                bomHistory.setCategory(bomMaterial.getCategory());
                bomHistory.setMaterial(bomMaterial.getMaterial());
                bomHistory.setNotes(bomMaterial.getNotes());
                bomHistory.setProducer(bomMaterial.getProducer());
                bomHistory.setSurfaceDetail(bomMaterial.getSurfaceDetail());
                bomHistory.setThickness(bomMaterial.getThickness());
                bomHistory.setSubSVersion(1);
                bomHistory.setSubEVersion(1);
                bomHistory.setCreateDate(date);
@@ -637,6 +688,19 @@
            pbhService.insertBatch(bomHistoryList);
        }
        //添加新增日志到tb_product_lock_log表
        ProductLockLog lockLog = new ProductLockLog();
        lockLog.setParentCode(parentCode);
        lockLog.setCustomCode(customCode);
        lockLog.setVersion(nextVersion);
        lockLog.setVersionTime(DateUtil.YYYY_MM_DD_HH_MM_SS.format(product.getVersionTime()));
        lockLog.setReason("产品bom上传");
        lockLog.setOwner(ActionUtil.getUser().getName());
        lockLog.setCreateTime(date);
        //-1代表日志类型为:产品bom上传
        lockLog.setLockFlag(-1);
        productLockLogService.insert(lockLog);
        return new Response().setII(1,"新增完成");
    }
@@ -659,4 +723,10 @@
        List list=mapper.selectList(null);
        return new Response().setII(1,list.size()>0,list,"");
    }
    //根据产品id查询被锁定的物料dwg和产品丝印
    public Response getLockedByProductId(int productId) {
        List listMaterial=mapper.selectListMaterial(productId);
        List listProduct=mapper.selectListProduct(productId);
        return new Response().setIII(1,listMaterial.size()>0||listProduct.size()>0,listMaterial,listProduct,"");
    }
}