|
@@ -281,6 +281,8 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// 授权列表
|
|
|
List<AuthImportPo> authImportList = new ArrayList<>();
|
|
|
|
|
|
+ List<String> tempImageList = new ArrayList<>();
|
|
|
+
|
|
|
try {
|
|
|
FileInputStream fis = new FileInputStream(filePath);
|
|
|
// 得到表格数据
|
|
@@ -339,6 +341,9 @@ public class AuthServiceImpl implements AuthService {
|
|
|
if (cellTotalNum < 13) {
|
|
|
return ResponseJson.error(authParty + "机构商品表格式错误");
|
|
|
}
|
|
|
+ // 获取表格图片
|
|
|
+ Map<String, XSSFPictureData> pictures = ExcelOperateUtil.getPictures(productSheet);
|
|
|
+ Map<String, String> imageMap = ExcelOperateUtil.printImg(pictures);
|
|
|
// 校验商品数据是否符合规范
|
|
|
int productRowNum = productSheet.getLastRowNum();
|
|
|
for (int k = 1; k <= productRowNum; k++) {
|
|
@@ -374,8 +379,6 @@ public class AuthServiceImpl implements AuthService {
|
|
|
brandId = authProductMapper.getBrandIdByBrandName(brand);
|
|
|
}
|
|
|
}
|
|
|
- Map<String, XSSFPictureData> pictures = ExcelOperateUtil.getPictures(productSheet);
|
|
|
- Map<String, String> imageMap = ExcelOperateUtil.printImg(pictures);
|
|
|
// 校验商品图片
|
|
|
String productImage = imageMap.get(k + "-3");
|
|
|
if (StringUtils.isEmpty(productImage)) {
|
|
@@ -434,21 +437,16 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// sn码
|
|
|
product.setSnCode(snCode);
|
|
|
// 商品图片
|
|
|
- product.setProductImage(productImage);
|
|
|
+ product.setProductImage(uploadImage(productImage));
|
|
|
// 授权牌照
|
|
|
- product.setCertificateImage(certificateImage);
|
|
|
+ product.setCertificateImage(uploadImage(certificateImage));
|
|
|
// 参数列表
|
|
|
product.setParamList(paramList);
|
|
|
// 创建人
|
|
|
product.setCreateBy(createBy);
|
|
|
productList.add(product);
|
|
|
- // 删除临时图片文件
|
|
|
- for (String image : imageMap.values()) {
|
|
|
- if (StringUtils.isNotEmpty(image)) {
|
|
|
- File tempFile = new File(image);
|
|
|
- tempFile.delete();
|
|
|
- }
|
|
|
- }
|
|
|
+ tempImageList.add(productImage);
|
|
|
+ tempImageList.add(certificateImage);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -466,7 +464,13 @@ public class AuthServiceImpl implements AuthService {
|
|
|
} finally {
|
|
|
// 删除临时数据
|
|
|
File tempFile = new File(filePath);
|
|
|
- tempFile.delete();
|
|
|
+ boolean delete = tempFile.delete();
|
|
|
+ log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时表格:" + delete);
|
|
|
+ tempImageList.forEach(tempImagePath->{
|
|
|
+ File tempImage = new File(tempImagePath);
|
|
|
+ boolean del = tempImage.delete();
|
|
|
+ log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时商品图片:" + del);
|
|
|
+ });
|
|
|
}
|
|
|
// 保存授权数据
|
|
|
authImportList.forEach(authImportPo -> {
|
|
@@ -487,8 +491,8 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// 上传商品图片和授权牌照
|
|
|
String productImage = productDto.getProductImage();
|
|
|
String certificateImage = productDto.getCertificateImage();
|
|
|
- productDto.setProductImage(uploadImage(productImage));
|
|
|
- productDto.setCertificateImage(uploadImage(certificateImage));
|
|
|
+ productDto.setProductImage(productImage);
|
|
|
+ productDto.setCertificateImage(certificateImage);
|
|
|
authProductService.saveProduct(productDto);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
@@ -665,14 +669,11 @@ public class AuthServiceImpl implements AuthService {
|
|
|
return ResponseJson.success("导出成功");
|
|
|
}
|
|
|
|
|
|
- private String uploadImage(String filePath) throws FileNotFoundException {
|
|
|
+ private String uploadImage(String filePath) throws IOException {
|
|
|
// 临时图片
|
|
|
File tempFile = new File(filePath);
|
|
|
log.info("【图片上传】>>>>>>>>>>>>>>>>图片临时路径:" + filePath);
|
|
|
String imageUrl = imageDomain + "/" + client.uploadFile(filePath);
|
|
|
- // 删除临时图片
|
|
|
- boolean delete = tempFile.delete();
|
|
|
- log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时图片:" + delete);
|
|
|
return imageUrl;
|
|
|
}
|
|
|
|