whycxzp
2023-03-01 93a16e3707b870856594e89b950174b64bb7d6cd
src/main/java/com/whyc/service/MaterialService.java
@@ -274,15 +274,15 @@
                        cellValue = cell.getStringCellValue();
                        switch (m){
                            case 2:{material.setCategory(cellValue);}break;
                            //case 2:{material.setCategory(cellValue);}break;
                            case 3:{material.setSubCode(cellValue);}break;
                            case 4:{material.setSubName(cellValue);}break;
                            case 5:{material.setSubModel(cellValue);}break;
                            case 6:{material.setMaterial(cellValue);}break;
                            case 7:{material.setThickness(cellValue);}break;
                            //case 6:{material.setMaterial(cellValue);}break;
                            //case 7:{material.setThickness(cellValue);}break;
                            //case 8:{material.setProducer(cellValue);}break;
                            case 9:{material.setSurfaceDetail(cellValue);}break;
                            case 10:{material.setNotes(cellValue);}break;
                            //case 9:{material.setSurfaceDetail(cellValue);}break;
                            //case 10:{material.setNotes(cellValue);}break;
                            case 11:{
                                //图片从1开始,0是yc logo
                                PictureData pictureData = allPictures.get(l - 7);
@@ -434,6 +434,45 @@
        return new Response().set(1,true,"上传完成");
    }
    /**
     * @param multipartFile 更新的图纸或图片
     * @param material
     */
    @Transactional
    public Response updatePicOrDwg(MultipartFile multipartFile, Material material) throws IOException {
        List<String> currentFileList = new LinkedList<>();
        List<String> uploadingFileList = new LinkedList<>();
        String dirPathDB = "doc_file" + File.separator + "material" + File.separator + material.getId() + "-" + material.getSubCode() + "-" + material.getSubModel();
        String dirPath = CommonUtil.getRootFile() + "material" + File.separator + material.getId() + "-" + material.getSubCode() + "-" + material.getSubModel();
        File dirFile = new File(dirPath);
        Date now = new Date();
        //long timestamp = now.getTime();
        String formattedTimestamp = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(now);
        if (!dirFile.exists()) {
            dirFile.mkdirs();
        }
        String originalFilename = multipartFile.getOriginalFilename();
        String fileSuffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
        String fileFullName = File.separator + originalFilename.substring(0, originalFilename.lastIndexOf(".")) + "_" + formattedTimestamp + originalFilename.substring(originalFilename.lastIndexOf("."));
        File zipFile = new File(dirPath + fileFullName);
        multipartFile.transferTo(zipFile);
        //路径不存在,说明是首次上传,设置物料对应的fileUrl
        Material temp = new Material();
        temp.setId(material.getId());
        if(fileSuffix.equals("dwg")){
            temp.setDwgUrl(dirPathDB + fileFullName);
        }else {
            temp.setPictureUrl(dirPathDB + fileFullName);
        }
        mapper.updateById(temp);
        return new Response().set(1, true, "上传完成");
    }
    public Response dwgCompare(int materialId, int materialId2) throws IOException {
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletResponse response = servletRequestAttributes.getResponse();
@@ -457,7 +496,7 @@
        }
        ByteArrayOutputStream stream = ImageDiff.compareImages(absoluteDwgPngPath, absoluteDwgPngPath2);
        return new Response().setII(1,true, Base64.encodeBase64(stream.toByteArray()),null);
        return new Response().setII(1,true, Base64.encodeBase64String(stream.toByteArray()),null);
        //String fileName = "name.png";
        //OutputStream toClient = null;
        //try {
@@ -477,4 +516,8 @@
        //
        //return null;
    }
    public void updateDwgUrlAndPicUrl(List<Material> materialUpdateList) {
        mapper.updateDwgUrlAndPicUrl(materialUpdateList);
    }
}