|
@@ -2,6 +2,7 @@ package com.caimei.service.auth.impl;
|
|
|
|
|
|
import com.aliyun.oss.OSS;
|
|
|
import com.aliyun.oss.OSSClientBuilder;
|
|
|
+import com.caimei.config.FastDfsClient;
|
|
|
import com.caimei.mapper.cmMapper.AuthMapper;
|
|
|
import com.caimei.mapper.cmMapper.AuthProductMapper;
|
|
|
import com.caimei.mapper.cmMapper.ShopMapper;
|
|
@@ -27,11 +28,17 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.imageio.ImageIO;
|
|
|
+import javax.swing.*;
|
|
|
import java.awt.*;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.net.URL;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -63,6 +70,9 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
@Value("${caimei.oldapi}")
|
|
|
private String wwwServer;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FastDfsClient client;
|
|
|
+
|
|
|
@Autowired
|
|
|
public void setUploadService(UploadService uploadService) {
|
|
|
this.uploadService = uploadService;
|
|
@@ -117,8 +127,24 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
return ResponseJson.success("删除授权商品成功");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存逻辑
|
|
|
+ * relationId
|
|
|
+ * null
|
|
|
+ * 新设备:插入设备、插入关联信息
|
|
|
+ * 关联设备:更新设备、插入关联信息
|
|
|
+ * notNull
|
|
|
+ * 数据库新设备
|
|
|
+ * 新设备:更新设备、原设备无需更新关联关系
|
|
|
+ * 关联设备:更新设备、更新关联信息(若原设备无机构关联,应删除该设备)
|
|
|
+ * 数据库关联设备
|
|
|
+ * 新设备:插入设备、更新关联信息
|
|
|
+ * 关联设备:更新设备、更新关联信息
|
|
|
+ */
|
|
|
@Override
|
|
|
- public ResponseJson saveProduct(ProductSaveDto productSaveDto, boolean importFlag) throws IOException {
|
|
|
+ public ResponseJson saveProduct(ProductSaveDto productSaveDto) throws IOException {
|
|
|
+ Integer relationId = productSaveDto.getRelationId();
|
|
|
+ Integer authType = productSaveDto.getAuthType();
|
|
|
Integer productId = productSaveDto.getProductId();
|
|
|
Integer authId = productSaveDto.getAuthId();
|
|
|
Integer brandId = productSaveDto.getBrandId();
|
|
@@ -127,8 +153,7 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
String productImage = productSaveDto.getProductImage();
|
|
|
String snCode = productSaveDto.getSnCode();
|
|
|
String certificateImage = productSaveDto.getCertificateImage();
|
|
|
- Integer addQrCodeFlag = productSaveDto.getAddQrCodeFlag();
|
|
|
- Integer addTemplateType = productSaveDto.getAddTemplateType();
|
|
|
+ Integer certificateImageType = productSaveDto.getCertificateImageType();
|
|
|
Integer createBy = productSaveDto.getCreateBy();
|
|
|
String purchaseWay = productSaveDto.getPurchaseWay();
|
|
|
String invoiceImage = productSaveDto.getInvoiceImage();
|
|
@@ -163,29 +188,28 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
if (null != productIdBySnCode && !productIdBySnCode.equals(productId)) {
|
|
|
return ResponseJson.error("参数异常,该商品SN码已存在,请重新输入", null);
|
|
|
}
|
|
|
- /*if (1 == source && StringUtils.isBlank(certificateImage)) {
|
|
|
- return ResponseJson.error("参数异常,请上传授权牌照", null);
|
|
|
- }*/
|
|
|
- if (!importFlag && 1 == source) {
|
|
|
- if (null == addQrCodeFlag) {
|
|
|
- return ResponseJson.error("参数异常,请选择是否生成二维码授权牌", null);
|
|
|
- }
|
|
|
- if (1 == addQrCodeFlag && null == addTemplateType) {
|
|
|
- return ResponseJson.error("参数异常,请选择二维码授权牌模板", null);
|
|
|
+ if (1 == source) {
|
|
|
+ if (2 == certificateImageType && StringUtils.isEmpty(certificateImage)) {
|
|
|
+ return ResponseJson.error("授权牌不能为空");
|
|
|
}
|
|
|
+ }else {
|
|
|
+ // 机构添加默认模板库生成
|
|
|
+ certificateImageType = 1;
|
|
|
}
|
|
|
// 是否为添加操作
|
|
|
- boolean insertFlag = null == productId;
|
|
|
+ boolean newRelation = null == relationId;
|
|
|
+ ProductRelationVo dbRelation = null;
|
|
|
ProductFormVo dbProduct = null;
|
|
|
- if (!insertFlag) {
|
|
|
- dbProduct = authProductMapper.getProductFormByProductId(productId);
|
|
|
+ if (!newRelation) {
|
|
|
+ dbRelation = authProductMapper.getProductRelation(relationId);
|
|
|
+ dbProduct = authProductMapper.getProductFormData(relationId);
|
|
|
}
|
|
|
/*
|
|
|
组装商品数据
|
|
|
*/
|
|
|
ProductPo product = new ProductPo();
|
|
|
- // 授权id
|
|
|
- product.setAuthId(authId);
|
|
|
+ // 设备id
|
|
|
+ product.setProductId(productId);
|
|
|
// 品牌id
|
|
|
product.setBrandId(brandId);
|
|
|
// 设备分类id
|
|
@@ -200,8 +224,7 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
product.setSnCode(snCode);
|
|
|
// 授权牌照
|
|
|
product.setCertificateImage(certificateImage);
|
|
|
- product.setAddQrCodeFlag(addQrCodeFlag);
|
|
|
- product.setAddTemplateType(addTemplateType);
|
|
|
+ product.setCertificateImageType(certificateImageType);
|
|
|
// 购买渠道
|
|
|
product.setPurchaseWay(purchaseWay);
|
|
|
// 发票图片
|
|
@@ -220,117 +243,64 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
product.setAuditTime(new Date());
|
|
|
product.setCheckFlag(0);
|
|
|
product.setShopAuditStatus(1 == source ? 1 : 2);
|
|
|
- if (insertFlag) {
|
|
|
- // 原授权牌照
|
|
|
- product.setOriginalCertificateImage(product.getCertificateImage());
|
|
|
- // 创建人id
|
|
|
- product.setCreateBy(createBy);
|
|
|
- // 创建来源
|
|
|
- product.setCreateSource(source);
|
|
|
- // 创建时间
|
|
|
- product.setCreateTime(new Date());
|
|
|
- if (1 == source && StringUtils.isNotEmpty(product.getCertificateImage()) && (null == addQrCodeFlag || 0 == addQrCodeFlag)) {
|
|
|
- //授权牌照不添加二维码,直接添加水印
|
|
|
- product.setPcCertificateImage(addWaterMark(product.getCertificateImage(), 1));
|
|
|
- product.setAppletsCertificateImage(addWaterMark(product.getCertificateImage(), 2));
|
|
|
+ // 创建人id
|
|
|
+ product.setCreateBy(createBy);
|
|
|
+ // 创建来源
|
|
|
+ product.setCreateSource(source);
|
|
|
+ // 创建时间
|
|
|
+ product.setCreateTime(new Date());
|
|
|
+
|
|
|
+ if (newRelation) {
|
|
|
+ if (1 == authType) {
|
|
|
+ // 插入授权商品
|
|
|
+ authProductMapper.insertProduct(product);
|
|
|
+ // 插入机构设备关联关系
|
|
|
+ relationId = authProductMapper.insertProductRelation(authId, product.getProductId(), authType);
|
|
|
+ } else {
|
|
|
+ // 关联设备,更新设备
|
|
|
+ authProductMapper.updateProductByProductId(product);
|
|
|
+ // 插入机构设备关联关系
|
|
|
+ relationId = authProductMapper.insertProductRelation(authId, product.getProductId(), authType);
|
|
|
}
|
|
|
- // 插入授权商品
|
|
|
- authProductMapper.insertProduct(product);
|
|
|
- if (1 == source && StringUtils.isNotEmpty(product.getCertificateImage()) && (null != addQrCodeFlag && 1 == addQrCodeFlag)) {
|
|
|
- // 生成二维码授权牌
|
|
|
- String addQrCodeImg = addQrCode(product.getCertificateImage(), product.getProductId(), addTemplateType);
|
|
|
- product.setCertificateImage(addQrCodeImg);
|
|
|
- //授权牌照添加水印
|
|
|
- product.setPcCertificateImage(addWaterMark(addQrCodeImg, 1));
|
|
|
- product.setAppletsCertificateImage(addWaterMark(addQrCodeImg, 2));
|
|
|
- //更新授权牌照
|
|
|
- authProductMapper.updateCertificateImage(product);
|
|
|
- }
|
|
|
- // 自动生成授权牌
|
|
|
-
|
|
|
} else {
|
|
|
- // 商品id
|
|
|
- product.setProductId(productId);
|
|
|
- if (1 == source) {
|
|
|
- ProductPo dbProductImage = authProductMapper.getImageByProductId(productId);
|
|
|
- // 数据库该商品授权牌是否添加二维码
|
|
|
- Integer dbAddQrCodeFlag = dbProductImage.getAddQrCodeFlag();
|
|
|
- // 数据库该商品授权牌添加二维码模板
|
|
|
- Integer dbAddTemplateType = dbProductImage.getAddTemplateType();
|
|
|
- // 授权牌照是否重新上传
|
|
|
- boolean updateImageFlag = (StringUtils.isNotBlank(product.getCertificateImage()) && !product.getCertificateImage().equals(dbProductImage.getCertificateImage())) || (StringUtils.isEmpty(dbProductImage.getPcCertificateImage()) || StringUtils.isEmpty(dbProductImage.getAppletsCertificateImage()));
|
|
|
- boolean addQrCodeSign = false;
|
|
|
- boolean addWaterMarkSign = false;
|
|
|
- if (StringUtils.isNotEmpty(product.getCertificateImage())) {
|
|
|
- if (null != dbAddQrCodeFlag && 1 == dbAddQrCodeFlag) {
|
|
|
- if (0 == addQrCodeFlag) {
|
|
|
- // 原本是,现在否
|
|
|
- if (updateImageFlag) {
|
|
|
- // 新上传图片,将原图片替换为当前图片,生成水印图片
|
|
|
- product.setOriginalCertificateImage(product.getCertificateImage());
|
|
|
- addWaterMarkSign = true;
|
|
|
- } else {
|
|
|
- // 原图片,将当前授权牌替换为原图,生成水印图片
|
|
|
- product.setCertificateImage(dbProductImage.getOriginalCertificateImage());
|
|
|
- addWaterMarkSign = true;
|
|
|
- }
|
|
|
- } else if (1 == addQrCodeFlag) {
|
|
|
- // 原本是,现在是
|
|
|
- if (updateImageFlag) {
|
|
|
- // 新上传图片,将原图片替换为当前图片,生成二维码授权牌,生成水印图片
|
|
|
- product.setOriginalCertificateImage(product.getCertificateImage());
|
|
|
- addQrCodeSign = true;
|
|
|
- addWaterMarkSign = true;
|
|
|
- } else if (!addTemplateType.equals(dbAddTemplateType)) {
|
|
|
- // 原图片,更改模板,将当前授权牌替换为原图,生成二维码授权牌,生成水印图片
|
|
|
- product.setCertificateImage(dbProductImage.getOriginalCertificateImage());
|
|
|
- addQrCodeSign = true;
|
|
|
- addWaterMarkSign = true;
|
|
|
- }
|
|
|
- // else 原图片,不更改模板,不做更改
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (1 == addQrCodeFlag) {
|
|
|
- // 原本否,现在是
|
|
|
- if (updateImageFlag) {
|
|
|
- // 新上传图片,将原图片替换为当前图片,生成二维码授权牌,生成水印图片
|
|
|
- product.setOriginalCertificateImage(product.getCertificateImage());
|
|
|
- addQrCodeSign = true;
|
|
|
- addWaterMarkSign = true;
|
|
|
- } else {
|
|
|
- // 原图片,生成二维码授权牌,生成水印图片
|
|
|
- addQrCodeSign = true;
|
|
|
- addWaterMarkSign = true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 原本否,现在否
|
|
|
- if (updateImageFlag) {
|
|
|
- // 新上传图片,将原图片替换为当前图片,生成二维码授权牌,生成水印图片
|
|
|
- product.setOriginalCertificateImage(product.getCertificateImage());
|
|
|
- addWaterMarkSign = true;
|
|
|
- }
|
|
|
- // 原图片,不做更改
|
|
|
- }
|
|
|
+ if (1 == dbRelation.getAuthType()) {
|
|
|
+ // 更新设备
|
|
|
+ authProductMapper.updateProductByProductId(product);
|
|
|
+ if (2 == authType) {
|
|
|
+ // 更新机构设备关联关系
|
|
|
+ authProductMapper.updateProductRelation(dbRelation.getRelationId(), authId, product.getProductId(), authType);
|
|
|
+ // 原本关联的新增设备若无关联机构,删除该设备
|
|
|
+ Integer relationCount = authProductMapper.getProductRelationCount(dbProduct.getProductId());
|
|
|
+ if (relationCount <= 0) {
|
|
|
+ authProductMapper.deleteProductByProductId(dbProduct.getProductId());
|
|
|
}
|
|
|
- }else {
|
|
|
- product.setPcCertificateImage(null);
|
|
|
- product.setAppletsCertificateImage(null);
|
|
|
}
|
|
|
- if (addQrCodeSign) {
|
|
|
- // 生成二维码授权牌
|
|
|
- String addQrCodeImg = addQrCode(product.getCertificateImage(), productId, addTemplateType);
|
|
|
- product.setCertificateImage(addQrCodeImg);
|
|
|
- }
|
|
|
- if (addWaterMarkSign) {
|
|
|
- //授权牌照添加水印
|
|
|
- product.setPcCertificateImage(addWaterMark(product.getCertificateImage(), 1));
|
|
|
- product.setAppletsCertificateImage(addWaterMark(product.getCertificateImage(), 2));
|
|
|
+ } else {
|
|
|
+ if (1 == authType) {
|
|
|
+ // 插入授权商品
|
|
|
+ authProductMapper.insertProduct(product);
|
|
|
+ } else {
|
|
|
+ // 更新设备
|
|
|
+ authProductMapper.updateProductByProductId(product);
|
|
|
}
|
|
|
+ // 更新机构设备关联关系
|
|
|
+ authProductMapper.updateProductRelation(dbRelation.getRelationId(), authId, product.getProductId(), authType);
|
|
|
}
|
|
|
- // 自动生成授权牌
|
|
|
-
|
|
|
- // 更新授权商品
|
|
|
- authProductMapper.updateProductByProductId(product);
|
|
|
+ }
|
|
|
+ ProductFormVo newDbProduct = authProductMapper.getProductFormData(relationId);
|
|
|
+ // 保存之后生成授权牌和水印授权牌
|
|
|
+ if (1 == product.getCertificateImageType()) {
|
|
|
+ // 模板库生成
|
|
|
+ // 获取对应模板
|
|
|
+ TemplateVo authTemplate = authMapper.getAuthTemplate(authId, null, 2);
|
|
|
+ certificateImage = generateAuthImage(authTemplate, newDbProduct);
|
|
|
+ product.setCertificateImage(certificateImage);
|
|
|
+ }
|
|
|
+ // 添加水印
|
|
|
+ if (StringUtils.isNotEmpty(product.getCertificateImage())) {
|
|
|
+ product.setPcCertificateImage(addWaterMark(product.getCertificateImage(), 1));
|
|
|
+ product.setAppletsCertificateImage(addWaterMark(product.getCertificateImage(), 2));
|
|
|
+ authProductMapper.updateCertificateImage(product);
|
|
|
}
|
|
|
// 删除商品参数
|
|
|
authProductMapper.deleteParamsByProductId(product.getProductId());
|
|
@@ -345,6 +315,203 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
return ResponseJson.success("保存授权商品成功");
|
|
|
}
|
|
|
|
|
|
+ public String generateAuthImage(TemplateVo authTemplate, ProductFormVo product) {
|
|
|
+ if (null != authTemplate) {
|
|
|
+ // 根据模板id设置相关数据
|
|
|
+ Map<String, Object> templateInfo = getTemplateInfo(authTemplate, product);
|
|
|
+ Object templateImage = templateInfo.get("templateImage");
|
|
|
+ if (null != templateImage) {
|
|
|
+ String authImage = ImageUtils.generateAuthImage(templateInfo);
|
|
|
+ log.info("【图片上传】>>>>>>>>>>>>>>>>图片临时路径:" + authImage);
|
|
|
+ // 临时图片
|
|
|
+ File tempFile = new File(authImage);
|
|
|
+ String imageUrl = null;
|
|
|
+ try {
|
|
|
+ imageUrl = imageDomain + "/" + client.uploadFile(authImage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 删除临时图片
|
|
|
+ boolean delete = tempFile.delete();
|
|
|
+ log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时图片:" + delete);
|
|
|
+ return imageUrl;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String,Object> getTemplateInfo(TemplateVo template, ProductFormVo product) {
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ Integer templateId = template.getTemplateId();
|
|
|
+ if (1 == templateId) {
|
|
|
+ map.put("templateImage", template.getTemplateImage());
|
|
|
+ double rate = 0.15;
|
|
|
+ String productName = product.getProductName();
|
|
|
+ if (StringUtils.isNotEmpty(productName)) {
|
|
|
+ map.put("addWord1_content", productName);
|
|
|
+ map.put("addWord1_color", "0,0,0");
|
|
|
+ map.put("addWord1_type", "思源宋体");
|
|
|
+ map.put("addWord1_style", Font.BOLD);
|
|
|
+ map.put("addWord1_size", (int) Math.round(233 * rate));
|
|
|
+ // 获取设备名字位置
|
|
|
+ try {
|
|
|
+ ImageIcon imageIcon = new ImageIcon(new URL(template.getTemplateImage()));
|
|
|
+ Image srcImg = imageIcon.getImage();
|
|
|
+ int srcWidth = srcImg.getWidth(null);
|
|
|
+ int wordWidth = ImageUtils.getWordWidth(new Font("思源宋体", Font.BOLD, (int) Math.round(233 * rate)), productName);
|
|
|
+ int x = (srcWidth - (int) Math.round(238 * rate) - wordWidth) / 2 + (int) Math.round(238 * rate);
|
|
|
+ int y = (int) Math.round(1630 * rate);
|
|
|
+ // 居中
|
|
|
+ map.put("addWord1_x", x);
|
|
|
+ map.put("addWord1_y", y);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 添加认证编号信息
|
|
|
+ if (StringUtils.isNotEmpty(product.getSnCode())) {
|
|
|
+ map.put("addWord2_content", product.getSnCode());
|
|
|
+ map.put("addWord2_color", "218,185,107");
|
|
|
+ map.put("addWord2_type", "思源宋体");
|
|
|
+ map.put("addWord2_style", Font.BOLD);
|
|
|
+ map.put("addWord2_size", (int) Math.round(90 * rate));
|
|
|
+ map.put("addWord2_x", (int) Math.round(2168 * rate));
|
|
|
+ map.put("addWord2_y", (int) Math.round(3165 * rate));
|
|
|
+ }
|
|
|
+ // 添加认证日期信息
|
|
|
+ if (null != product.getCreateTime()) {
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
|
|
|
+ map.put("addWord3_content", format.format(product.getCreateTime()));
|
|
|
+ map.put("addWord3_color", "218,185,107");
|
|
|
+ map.put("addWord3_type", "思源宋体");
|
|
|
+ map.put("addWord3_style", Font.PLAIN);
|
|
|
+ map.put("addWord3_size", (int) Math.round(90 * rate));
|
|
|
+ map.put("addWord3_x", (int) Math.round(2085 * rate));
|
|
|
+ map.put("addWord3_y", (int) Math.round(3292 * rate));
|
|
|
+ }
|
|
|
+ // 添加二维码信息
|
|
|
+ if (StringUtils.isNotEmpty(template.getQrPosition())) {
|
|
|
+ String qrCodeLink = wwwServer + "/product/auth/product-" + product.getProductId() + ".html";
|
|
|
+ map.put("addQr1_link", qrCodeLink);
|
|
|
+ map.put("addQr1_size", template.getQrSize());
|
|
|
+ String[] split = template.getQrPosition().split(",");
|
|
|
+ if (split.length == 2) {
|
|
|
+ map.put("addQr1_x", Integer.parseInt(split[0]));
|
|
|
+ map.put("addQr1_y", Integer.parseInt(split[1]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*private void insertProduct(Integer createBy, Integer source, ProductPo product) throws IOException {
|
|
|
+ // 添加新设备
|
|
|
+ // 原授权牌照
|
|
|
+ product.setOriginalCertificateImage(product.getCertificateImage());
|
|
|
+ if (1 == source && StringUtils.isNotEmpty(product.getCertificateImage()) && (null == addQrCodeFlag || 0 == addQrCodeFlag)) {
|
|
|
+ //授权牌照不添加二维码,直接添加水印
|
|
|
+ product.setPcCertificateImage(addWaterMark(product.getCertificateImage(), 1));
|
|
|
+ product.setAppletsCertificateImage(addWaterMark(product.getCertificateImage(), 2));
|
|
|
+ }
|
|
|
+ if (1 == source && StringUtils.isNotEmpty(product.getCertificateImage()) && (null != addQrCodeFlag && 1 == addQrCodeFlag)) {
|
|
|
+ // 生成二维码授权牌
|
|
|
+ String addQrCodeImg = addQrCode(product.getCertificateImage(), product.getProductId(), addTemplateType);
|
|
|
+ product.setCertificateImage(addQrCodeImg);
|
|
|
+ //授权牌照添加水印
|
|
|
+ product.setPcCertificateImage(addWaterMark(addQrCodeImg, 1));
|
|
|
+ product.setAppletsCertificateImage(addWaterMark(addQrCodeImg, 2));
|
|
|
+ //更新授权牌照
|
|
|
+ authProductMapper.updateCertificateImage(product);
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ /*private void updateProduct(Integer productId, Integer addQrCodeFlag, Integer addTemplateType, Integer source, ProductPo product) throws IOException {
|
|
|
+ // 商品id
|
|
|
+ product.setProductId(productId);
|
|
|
+ if (1 == source) {
|
|
|
+ ProductPo dbProductImage = authProductMapper.getImageByProductId(productId);
|
|
|
+ // 数据库该商品授权牌是否添加二维码
|
|
|
+ Integer dbAddQrCodeFlag = dbProductImage.getAddQrCodeFlag();
|
|
|
+ // 数据库该商品授权牌添加二维码模板
|
|
|
+ Integer dbAddTemplateType = dbProductImage.getAddTemplateType();
|
|
|
+ // 授权牌照是否重新上传
|
|
|
+ boolean updateImageFlag = (StringUtils.isNotBlank(product.getCertificateImage()) && !product.getCertificateImage().equals(dbProductImage.getCertificateImage())) || (StringUtils.isEmpty(dbProductImage.getPcCertificateImage()) || StringUtils.isEmpty(dbProductImage.getAppletsCertificateImage()));
|
|
|
+ boolean addQrCodeSign = false;
|
|
|
+ boolean addWaterMarkSign = false;
|
|
|
+ if (StringUtils.isNotEmpty(product.getCertificateImage())) {
|
|
|
+ if (null != dbAddQrCodeFlag && 1 == dbAddQrCodeFlag) {
|
|
|
+ if (0 == addQrCodeFlag) {
|
|
|
+ // 原本是,现在否
|
|
|
+ if (updateImageFlag) {
|
|
|
+ // 新上传图片,将原图片替换为当前图片,生成水印图片
|
|
|
+ product.setOriginalCertificateImage(product.getCertificateImage());
|
|
|
+ addWaterMarkSign = true;
|
|
|
+ } else {
|
|
|
+ // 原图片,将当前授权牌替换为原图,生成水印图片
|
|
|
+ product.setCertificateImage(dbProductImage.getOriginalCertificateImage());
|
|
|
+ addWaterMarkSign = true;
|
|
|
+ }
|
|
|
+ } else if (1 == addQrCodeFlag) {
|
|
|
+ // 原本是,现在是
|
|
|
+ if (updateImageFlag) {
|
|
|
+ // 新上传图片,将原图片替换为当前图片,生成二维码授权牌,生成水印图片
|
|
|
+ product.setOriginalCertificateImage(product.getCertificateImage());
|
|
|
+ addQrCodeSign = true;
|
|
|
+ addWaterMarkSign = true;
|
|
|
+ } else if (!addTemplateType.equals(dbAddTemplateType)) {
|
|
|
+ // 原图片,更改模板,将当前授权牌替换为原图,生成二维码授权牌,生成水印图片
|
|
|
+ product.setCertificateImage(dbProductImage.getOriginalCertificateImage());
|
|
|
+ addQrCodeSign = true;
|
|
|
+ addWaterMarkSign = true;
|
|
|
+ }
|
|
|
+ // else 原图片,不更改模板,不做更改
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (1 == addQrCodeFlag) {
|
|
|
+ // 原本否,现在是
|
|
|
+ if (updateImageFlag) {
|
|
|
+ // 新上传图片,将原图片替换为当前图片,生成二维码授权牌,生成水印图片
|
|
|
+ product.setOriginalCertificateImage(product.getCertificateImage());
|
|
|
+ addQrCodeSign = true;
|
|
|
+ addWaterMarkSign = true;
|
|
|
+ } else {
|
|
|
+ // 原图片,生成二维码授权牌,生成水印图片
|
|
|
+ addQrCodeSign = true;
|
|
|
+ addWaterMarkSign = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 原本否,现在否
|
|
|
+ if (updateImageFlag) {
|
|
|
+ // 新上传图片,将原图片替换为当前图片,生成二维码授权牌,生成水印图片
|
|
|
+ product.setOriginalCertificateImage(product.getCertificateImage());
|
|
|
+ addWaterMarkSign = true;
|
|
|
+ }
|
|
|
+ // 原图片,不做更改
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ product.setPcCertificateImage(null);
|
|
|
+ product.setAppletsCertificateImage(null);
|
|
|
+ }
|
|
|
+ if (addQrCodeSign) {
|
|
|
+ // 生成二维码授权牌
|
|
|
+ String addQrCodeImg = addQrCode(product.getCertificateImage(), productId, addTemplateType);
|
|
|
+ product.setCertificateImage(addQrCodeImg);
|
|
|
+ }
|
|
|
+ if (addWaterMarkSign) {
|
|
|
+ //授权牌照添加水印
|
|
|
+ product.setPcCertificateImage(addWaterMark(product.getCertificateImage(), 1));
|
|
|
+ product.setAppletsCertificateImage(addWaterMark(product.getCertificateImage(), 2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 自动生成授权牌
|
|
|
+
|
|
|
+ // 更新授权商品
|
|
|
+ authProductMapper.updateProductByProductId(product);
|
|
|
+ }*/
|
|
|
+
|
|
|
private String addWaterMark(String image,Integer type) throws IOException {
|
|
|
//type:1pc,2applets
|
|
|
ClassPathResource classPathResource = new ClassPathResource("/images/newPcWaterMark.png");
|
|
@@ -367,7 +534,7 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
return imagePath;
|
|
|
}
|
|
|
|
|
|
- private String addQrCode(String certificateImage, Integer productId, Integer addTemplateType) throws IOException {
|
|
|
+ /*private String addQrCode(String certificateImage, Integer productId, Integer addTemplateType) throws IOException {
|
|
|
String qrCodeLink = wwwServer + "/product/auth/product-" + productId + ".html";
|
|
|
String qrCodeImage = ImageUtils.addQrCode(certificateImage, qrCodeLink, addTemplateType);
|
|
|
String imagePath = null;
|
|
@@ -381,20 +548,17 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
log.info(">>>>>>>>>>>>>>>>二维码图片上传失败");
|
|
|
}
|
|
|
return imagePath;
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
@Override
|
|
|
- public ResponseJson<ProductFormVo> getProductFormData(Integer productId) {
|
|
|
- if (null == productId) {
|
|
|
- return ResponseJson.error("参数异常,请输入商品id", null);
|
|
|
- }
|
|
|
- ProductFormVo productForm = authProductMapper.getProductFormByProductId(productId);
|
|
|
+ public ResponseJson<ProductFormVo> getProductFormData(Integer relationId) {
|
|
|
+ ProductFormVo productForm = authProductMapper.getProductFormData(relationId);
|
|
|
if (null == productForm) {
|
|
|
- return ResponseJson.error("商品不存在", null);
|
|
|
+ return ResponseJson.error("设备不存在", null);
|
|
|
}
|
|
|
List<ProductParamPo> paramList = authProductMapper.getProductTypeParamList(productForm.getProductTypeId());
|
|
|
if (null == paramList || paramList.size() == 0) {
|
|
|
- paramList = authProductMapper.getParamsByProductId(productId);
|
|
|
+ paramList = authProductMapper.getParamsByProductId(productForm.getProductId());
|
|
|
}
|
|
|
productForm.setParamList(paramList);
|
|
|
return ResponseJson.success(productForm);
|
|
@@ -678,4 +842,16 @@ public class AuthProductServiceImpl implements AuthProductService {
|
|
|
return ResponseJson.success();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResponseJson<ProductFormVo> getProductDetails(Integer productId, String snCode) {
|
|
|
+ ProductFormVo product = authProductMapper.getProductDetails(productId, snCode);
|
|
|
+ return ResponseJson.success(product);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson<List<String>> getSnCodeList(Integer authUserId) {
|
|
|
+ List<String> snCodeList = authProductMapper.getSnCodeList(authUserId);
|
|
|
+ return ResponseJson.success(snCodeList);
|
|
|
+ }
|
|
|
+
|
|
|
}
|