|
@@ -23,7 +23,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.imageio.ImageIO;
|
|
|
-import javax.validation.constraints.NotNull;
|
|
|
import java.awt.*;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
@@ -176,13 +175,15 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
// 商品id
|
|
|
product.setProductId(productId);
|
|
|
ProductPo productImages = authProductMapper.getImageByProductId(productId);
|
|
|
- if (StringUtils.isNotBlank(product.getProductImage()) && !product.getProductImage().equals(productImages.getProductImage())) {
|
|
|
+ boolean updateImageFlag = (StringUtils.isNotBlank(product.getProductImage()) && !product.getProductImage().equals(productImages.getProductImage())) || (StringUtils.isEmpty(product.getPcImage()) || StringUtils.isEmpty(product.getAppletsImage()));
|
|
|
+ if (updateImageFlag) {
|
|
|
//商品图片添加水印
|
|
|
product.setPcImage(addWaterMark(product.getProductImage(), 1));
|
|
|
product.setAppletsImage(addWaterMark(product.getProductImage(), 2));
|
|
|
}
|
|
|
- if (StringUtils.isNotBlank(product.getCertificateImage()) && !product.getCertificateImage().equals(productImages.getCertificateImage())) {
|
|
|
- //商品图片添加水印
|
|
|
+ updateImageFlag = (StringUtils.isNotBlank(product.getCertificateImage()) && !product.getCertificateImage().equals(productImages.getCertificateImage())) || (StringUtils.isEmpty(product.getPcCertificateImage()) || StringUtils.isEmpty(product.getPcCertificateImage()));
|
|
|
+ if (updateImageFlag) {
|
|
|
+ //授权牌照添加水印
|
|
|
product.setPcCertificateImage(addWaterMark(product.getCertificateImage(), 1));
|
|
|
product.setAppletsCertificateImage(addWaterMark(product.getCertificateImage(), 2));
|
|
|
}
|
|
@@ -208,9 +209,14 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
classPathResource = new ClassPathResource("/images/appletsWaterMark.png");
|
|
|
inputStreamImg = classPathResource.getInputStream();
|
|
|
Image appletsWaterMarkImg = ImageIO.read(inputStreamImg);
|
|
|
- String Img = ImageUtils.markImageByIcon(type == 1 ? pcWaterMarkImg : appletsWaterMarkImg, image, null);
|
|
|
- MultipartFile ImgFile = Base64Util.base64ToMultipart(Img);
|
|
|
- String imagePath = imageDomain + "/" + saveImage(ImgFile);
|
|
|
+ String img = ImageUtils.markImageByIcon(type == 1 ? pcWaterMarkImg : appletsWaterMarkImg, image, null);
|
|
|
+ String imagePath = null;
|
|
|
+ if (StringUtils.isNotEmpty(img)) {
|
|
|
+ MultipartFile imgFile = Base64Util.base64ToMultipart(img);
|
|
|
+ if (null != imgFile) {
|
|
|
+ imagePath = imageDomain + "/" + saveImage(imgFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
log.info(">>>>>>>>>>>>>>>>水印图片上传成功:" + imagePath);
|
|
|
return imagePath;
|
|
|
}
|
|
@@ -247,4 +253,28 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
log.info(">>>>>>>>>>>>>>>>水印图片上传路径:" + filePath);
|
|
|
return client.uploadFile(filePath);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson updateAllWaterMark() {
|
|
|
+ List<ProductPo> productList = authProductMapper.getAllImage();
|
|
|
+ productList.forEach(product->{
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(product.getProductImage())) {
|
|
|
+ //商品图片添加水印
|
|
|
+ product.setPcImage(addWaterMark(product.getProductImage(), 1));
|
|
|
+ product.setAppletsImage(addWaterMark(product.getProductImage(), 2));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(product.getCertificateImage())) {
|
|
|
+ //授权牌照添加水印
|
|
|
+ product.setPcCertificateImage(addWaterMark(product.getCertificateImage(), 1));
|
|
|
+ product.setAppletsCertificateImage(addWaterMark(product.getCertificateImage(), 2));
|
|
|
+ }
|
|
|
+ // 更新授权商品
|
|
|
+ authProductMapper.updateImageByProductId(product);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return ResponseJson.success("更新商品水印图片成功");
|
|
|
+ }
|
|
|
}
|