| | |
| | | package com.whyc.service; |
| | | |
| | | 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.pojo.DocUser; |
| | | import com.whyc.pojo.Material; |
| | | import com.whyc.pojo.ProductBom; |
| | | 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 com.whyc.util.*; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.FileCopyUtils; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | 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); |
| | |
| | | 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(); |
| | | |
| | | //获取各自物料的图纸 |
| | | String dwgUrl = mapper.selectById(materialId).getDwgUrl(); |
| | | String dwgUrl2 = mapper.selectById(materialId2).getDwgUrl(); |
| | | if(dwgUrl == null || dwgUrl2 == null){ |
| | | return new Response().set(1,false,"无法对比,所选物料至少有1个不存在图纸"); |
| | | } |
| | | String dwgFileStr = CommonUtil.getProjectDir() + File.separator + dwgUrl; |
| | | String dwgFileStr2 = CommonUtil.getProjectDir() + File.separator + dwgUrl2; |
| | | |
| | | String absoluteDwgPngPath = dwgFileStr.substring(0,dwgFileStr.lastIndexOf("."))+"-dwg.png"; |
| | | String absoluteDwgPngPath2 = dwgFileStr2.substring(0,dwgFileStr2.lastIndexOf("."))+"-dwg.png"; |
| | | if(!new File(absoluteDwgPngPath).exists()){ |
| | | DwgToPngUtil.dwg2png(new File(dwgFileStr)); |
| | | } |
| | | if(!new File(absoluteDwgPngPath2).exists()) { |
| | | DwgToPngUtil.dwg2png(new File(dwgFileStr2)); |
| | | } |
| | | |
| | | ByteArrayOutputStream stream = ImageDiff.compareImages(absoluteDwgPngPath, absoluteDwgPngPath2); |
| | | return new Response().setII(1,true, Base64.encodeBase64String(stream.toByteArray()),null); |
| | | //String fileName = "name.png"; |
| | | //OutputStream toClient = null; |
| | | //try { |
| | | // response.setContentType("application/octet-stream"); |
| | | // response.setHeader("Content-Disposition","attachment;filename=" + fileName); |
| | | // response.addHeader("Pragma", "no-cache"); |
| | | // response.addHeader("Cache-Control", "no-cache"); |
| | | // toClient = response.getOutputStream(); |
| | | // stream.writeTo(toClient); |
| | | // //toClient.write(stream.toByteArray()); |
| | | // toClient.flush(); |
| | | // toClient.close(); |
| | | //} catch (IOException e) { |
| | | // e.printStackTrace(); |
| | | //} |
| | | // |
| | | // |
| | | //return null; |
| | | } |
| | | |
| | | public void updateDwgUrlAndPicUrl(List<Material> materialUpdateList) { |
| | | mapper.updateDwgUrlAndPicUrl(materialUpdateList); |
| | | } |
| | | } |