| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | 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.whyc.util.CommonUtil; |
| | | import com.whyc.util.ThreadLocalUtil; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.poi.openxml4j.opc.OPCPackage; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.xssf.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | |
| | | spare.setSupplier(supplier); |
| | | |
| | | spareList.add(spare); |
| | | //第七列为图片 TODO 待处理 |
| | | /*Cell cell = row.getCell(7); |
| | | CellType cellType = cell.getCellType(); |
| | | System.out.println("-");*/ |
| | | |
| | | } |
| | | addBatch(spareList); |
| | | |
| | | //第七列为图片-浮动式图片 TODO 待处理 处理已存在的物料 |
| | | //获取绘图对象中的所有图形 |
| | | XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch(); |
| | | if (drawing == null) { |
| | | drawing = (XSSFDrawing) sheet.createDrawingPatriarch(); |
| | | } |
| | | List<XSSFShape> shapes = drawing.getShapes(); |
| | | for (XSSFShape shape : shapes) { |
| | | if (shape instanceof XSSFPicture) { |
| | | XSSFPicture pic = (XSSFPicture) shape; |
| | | XSSFClientAnchor anchor = pic.getClientAnchor(); |
| | | //获取图片所在的起始行 |
| | | int rowIndex = anchor.getRow1(); |
| | | byte[] data = pic.getPictureData().getData(); |
| | | |
| | | DeviceSpare spare = spareList.get(rowIndex - 1); |
| | | //对存储路径进行定义 |
| | | Date now = new Date(); |
| | | String timeFormat = ThreadLocalUtil.format(ThreadLocalUtil.TIME_YYYY_MM_DD_HH_MM_SS_UNION, now); |
| | | String dirMonth = ThreadLocalUtil.format(ThreadLocalUtil.TIME_YYYY_MM, now); |
| | | String fileDirPath = CommonUtil.getRootFile() + "deviceSpare" + File.separator + dirMonth; |
| | | File fileDir = new File(fileDirPath); |
| | | //如果文件夹不存在则创建 |
| | | if (!fileDir.exists()) { |
| | | fileDir.mkdirs(); |
| | | } |
| | | String filePath = fileDirPath + File.separator + timeFormat+"_"+spare.getName()+"_"+spare.getModel()+"_"+spare.getVersion()+".png"; |
| | | |
| | | // 保存图片到本地 |
| | | try (FileOutputStream fos = new FileOutputStream(filePath)) { |
| | | fos.write(data); |
| | | } |
| | | String split = "pis_file"+File.separator+"deviceSpare"; |
| | | String picUrl = File.separator + filePath.substring(filePath.indexOf(split)); |
| | | spare.setPictureUrl(picUrl); |
| | | } |
| | | } |
| | | |
| | | //新增列表 |
| | | List<DeviceSpare> spareListNew = new ArrayList<>(); |
| | | //更新列表 |
| | | List<DeviceSpare> spareListUpdate = new ArrayList<>(); |
| | | //查询库中的所有设备器件 |
| | | List<DeviceSpare> deviceSpareListInDB = mapper.selectList((Wrapper<DeviceSpare>) CommonUtil.nullObject); |
| | | for (DeviceSpare spare : spareList){ |
| | | for (DeviceSpare spareInDB : deviceSpareListInDB){ |
| | | if (spare.getName().equals(spareInDB.getName()) |
| | | && spare.getModel().equals(spareInDB.getModel()) |
| | | && spare.getVersion().equals(spareInDB.getVersion()) |
| | | && spare.getBrand().equals(spareInDB.getBrand()) |
| | | && spare.getType().equals(spareInDB.getType()) |
| | | && spare.getSupplier().equals(spareInDB.getSupplier()) |
| | | ){ |
| | | spare.setId(spareInDB.getId()); |
| | | spare.setQuantity(spareInDB.getQuantity()+spare.getQuantity()); |
| | | if (spare.getPictureUrl() != null && spareInDB.getPictureUrl()!=null){ |
| | | spare.setPictureUrl(spareInDB.getPictureUrl()+","+spare.getPictureUrl()); |
| | | } |
| | | spareListUpdate.add(spare); |
| | | |
| | | }else{ |
| | | spareListNew.add(spare); |
| | | } |
| | | } |
| | | } |
| | | //更新TODO |
| | | |
| | | //addBatch(spareList); |
| | | |
| | | return null; |
| | | } |