|
@@ -1,5 +1,6 @@
|
|
package com.caimei.service.impl;
|
|
package com.caimei.service.impl;
|
|
|
|
|
|
|
|
+import com.caimei.config.FastDfsClient;
|
|
import com.caimei.mapper.AuthProductMapper;
|
|
import com.caimei.mapper.AuthProductMapper;
|
|
import com.caimei.model.ResponseJson;
|
|
import com.caimei.model.ResponseJson;
|
|
import com.caimei.model.dto.ProductSaveDto;
|
|
import com.caimei.model.dto.ProductSaveDto;
|
|
@@ -8,16 +9,28 @@ import com.caimei.model.po.ProductPo;
|
|
import com.caimei.model.vo.ProductFormVo;
|
|
import com.caimei.model.vo.ProductFormVo;
|
|
import com.caimei.model.vo.ProductListVo;
|
|
import com.caimei.model.vo.ProductListVo;
|
|
import com.caimei.service.AuthProductService;
|
|
import com.caimei.service.AuthProductService;
|
|
|
|
+import com.caimei.utils.Base64Util;
|
|
|
|
+import com.caimei.utils.ImageUtils;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import javax.imageio.ImageIO;
|
|
import javax.validation.constraints.NotNull;
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
+import java.awt.*;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Description
|
|
* Description
|
|
@@ -32,6 +45,12 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
@Resource
|
|
@Resource
|
|
private AuthProductMapper authProductMapper;
|
|
private AuthProductMapper authProductMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FastDfsClient client;
|
|
|
|
+
|
|
|
|
+ @Value("${caimei.imageDomain}")
|
|
|
|
+ private String imageDomain;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public ResponseJson<PageInfo<ProductListVo>> getProductList(Integer authId, String productName, String snCode, Integer pageNum, Integer pageSize) {
|
|
public ResponseJson<PageInfo<ProductListVo>> getProductList(Integer authId, String productName, String snCode, Integer pageNum, Integer pageSize) {
|
|
if (null == authId) {
|
|
if (null == authId) {
|
|
@@ -55,9 +74,9 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
}
|
|
}
|
|
authProductMapper.updateProductStatusByProductId(productId, status);
|
|
authProductMapper.updateProductStatusByProductId(productId, status);
|
|
if (status == 0) {
|
|
if (status == 0) {
|
|
- return ResponseJson.success("下架授权商品成功");
|
|
|
|
|
|
+ return ResponseJson.success("下线授权商品成功");
|
|
} else {
|
|
} else {
|
|
- return ResponseJson.success("上架授权商品成功");
|
|
|
|
|
|
+ return ResponseJson.success("上线授权商品成功");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -74,7 +93,7 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ResponseJson saveProduct(ProductSaveDto productSaveDto) {
|
|
|
|
|
|
+ public ResponseJson saveProduct(ProductSaveDto productSaveDto) throws IOException {
|
|
Integer productId = productSaveDto.getProductId();
|
|
Integer productId = productSaveDto.getProductId();
|
|
Integer authId = productSaveDto.getAuthId();
|
|
Integer authId = productSaveDto.getAuthId();
|
|
Integer brandId = productSaveDto.getBrandId();
|
|
Integer brandId = productSaveDto.getBrandId();
|
|
@@ -140,11 +159,33 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
product.setCreateBy(createBy);
|
|
product.setCreateBy(createBy);
|
|
// 创建时间
|
|
// 创建时间
|
|
product.setCreateTime(new Date());
|
|
product.setCreateTime(new Date());
|
|
|
|
+ // 商品图片和授权牌照添加水印
|
|
|
|
+ if (StringUtils.isNotBlank(product.getProductImage())) {
|
|
|
|
+ //商品图片添加水印
|
|
|
|
+ product.setPcImage(addWaterMark(product.getProductImage(), 1));
|
|
|
|
+ product.setAppletsImage(addWaterMark(product.getProductImage(), 2));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(product.getCertificateImage())) {
|
|
|
|
+ //授权牌照添加水印
|
|
|
|
+ product.setPcCertificateImage(addWaterMark(product.getCertificateImage(), 1));
|
|
|
|
+ product.setAppletsCertificateImage(addWaterMark(product.getCertificateImage(), 2));
|
|
|
|
+ }
|
|
// 插入授权商品
|
|
// 插入授权商品
|
|
authProductMapper.insertProduct(product);
|
|
authProductMapper.insertProduct(product);
|
|
} else {
|
|
} else {
|
|
// 商品id
|
|
// 商品id
|
|
product.setProductId(productId);
|
|
product.setProductId(productId);
|
|
|
|
+ ProductPo productImages = authProductMapper.getImageByProductId(productId);
|
|
|
|
+ if (StringUtils.isNotBlank(product.getProductImage()) && !product.getProductImage().equals(productImages.getProductImage())) {
|
|
|
|
+ //商品图片添加水印
|
|
|
|
+ product.setPcImage(addWaterMark(product.getProductImage(), 1));
|
|
|
|
+ product.setAppletsImage(addWaterMark(product.getProductImage(), 2));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(product.getCertificateImage()) && !product.getCertificateImage().equals(productImages.getCertificateImage())) {
|
|
|
|
+ //商品图片添加水印
|
|
|
|
+ product.setPcCertificateImage(addWaterMark(product.getCertificateImage(), 1));
|
|
|
|
+ product.setAppletsCertificateImage(addWaterMark(product.getCertificateImage(), 2));
|
|
|
|
+ }
|
|
// 更新授权商品
|
|
// 更新授权商品
|
|
authProductMapper.updateProductByProductId(product);
|
|
authProductMapper.updateProductByProductId(product);
|
|
}
|
|
}
|
|
@@ -159,6 +200,21 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
return ResponseJson.success("保存授权商品成功");
|
|
return ResponseJson.success("保存授权商品成功");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private String addWaterMark(String image,Integer type) throws IOException {
|
|
|
|
+ //type:1pc,2applets
|
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("/images/pcWaterMark.png");
|
|
|
|
+ InputStream inputStreamImg = classPathResource.getInputStream();
|
|
|
|
+ Image pcWaterMarkImg = ImageIO.read(inputStreamImg);
|
|
|
|
+ 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);
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>>水印图片上传成功:" + imagePath);
|
|
|
|
+ return imagePath;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public ResponseJson<ProductFormVo> getProductFormData(Integer productId) {
|
|
public ResponseJson<ProductFormVo> getProductFormData(Integer productId) {
|
|
if (null == productId) {
|
|
if (null == productId) {
|
|
@@ -177,4 +233,18 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
public List<Integer> getProductIdsByAuthId(Integer authId) {
|
|
public List<Integer> getProductIdsByAuthId(Integer authId) {
|
|
return authProductMapper.getProductIdsByAuthId(authId);
|
|
return authProductMapper.getProductIdsByAuthId(authId);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private String saveImage(MultipartFile file) throws IOException {
|
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
|
+ String randomUUID = UUID.randomUUID().toString();
|
|
|
|
+ int index = originalFilename.lastIndexOf(".");
|
|
|
|
+ String exet = originalFilename.substring(index);
|
|
|
|
+ String filePath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempImage/";
|
|
|
|
+ filePath += "\\" + randomUUID + exet;
|
|
|
|
+ file.transferTo(new File(filePath));
|
|
|
|
+ log.info(">>>>>>>>>>>>>>>>水印图片上传路径:" + filePath);
|
|
|
|
+ return client.uploadFile(filePath);
|
|
|
|
+ }
|
|
}
|
|
}
|