Kaynağa Gözat

正品联盟part8

Aslee 3 yıl önce
ebeveyn
işleme
1893f2cdc0

+ 2 - 1
src/main/java/com/caimei/controller/AuthProductApi.java

@@ -17,6 +17,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 
+import java.io.IOException;
 import java.util.Map;
 
 /**
@@ -92,7 +93,7 @@ public class AuthProductApi {
      */
     @ApiOperation("添加/编辑授权商品")
     @PostMapping("/save")
-    public ResponseJson saveProduct(@RequestBody ProductSaveDto productSaveDto) {
+    public ResponseJson saveProduct(@RequestBody ProductSaveDto productSaveDto) throws IOException {
         return authProductService.saveProduct(productSaveDto);
     }
 

+ 2 - 3
src/main/java/com/caimei/mapper/AuthProductMapper.java

@@ -1,10 +1,7 @@
 package com.caimei.mapper;
 
-import com.caimei.model.po.CmBrandAuthPo;
 import com.caimei.model.po.ProductParamPo;
 import com.caimei.model.po.ProductPo;
-import com.caimei.model.vo.AuthVo;
-import com.caimei.model.vo.BrandVo;
 import com.caimei.model.vo.ProductFormVo;
 import com.caimei.model.vo.ProductListVo;
 import org.apache.ibatis.annotations.Mapper;
@@ -42,4 +39,6 @@ public interface AuthProductMapper {
     List<ProductParamPo> getParamsByProductId(Integer productId);
 
     List<Integer> getProductIdsByAuthId(Integer authId);
+
+    ProductPo getImageByProductId(Integer productId);
 }

+ 2 - 0
src/main/java/com/caimei/mapper/ShopMapper.java

@@ -57,4 +57,6 @@ public interface ShopMapper {
     void updateShopInfo(ShopInfoDto shopInfoVo);
 
     List<ShopInfoVo> getShopInfoByUserId(Integer authUserId);
+
+    Integer getUserIdByShopName(String shopName);
 }

+ 20 - 0
src/main/java/com/caimei/model/po/ProductPo.java

@@ -42,11 +42,31 @@ public class ProductPo {
      */
     private String productImage;
 
+    /**
+     * pc添加水印商品图片
+     */
+    private String pcImage;
+
+    /**
+     * 小程序添加水印商品图片
+     */
+    private String appletsImage;
+
     /**
      * 授权牌照
      */
     private String certificateImage;
 
+    /**
+     * pc添加水印授权牌照
+     */
+    private String pcCertificateImage;
+
+    /**
+     * 小程序添加水印授权牌照
+     */
+    private String appletsCertificateImage;
+
     /**
      * 上架状态:0下架,1上架
      */

+ 6 - 0
src/main/java/com/caimei/model/vo/ShopListVo.java

@@ -40,6 +40,12 @@ public class ShopListVo implements Serializable {
     @ApiModelProperty("所属品牌")
     private String brandName;
 
+    /**
+     * 品牌id
+     */
+    @ApiModelProperty("所属品牌")
+    private String brandId;
+
     /**
      * 手机号
      */

+ 10 - 0
src/main/java/com/caimei/model/vo/UserLoginVo.java

@@ -37,6 +37,16 @@ public class UserLoginVo implements Serializable {
      */
     @ApiModelProperty("供应商状态:0已停用 1已启用")
     private Integer shopStatus;
+    /**
+     * 供应商类型:1品牌方 2代理商
+     */
+    @ApiModelProperty("供应商类型:1品牌方 2代理商")
+    private Integer shopType;
+    /**
+     * 品牌id
+     */
+    @ApiModelProperty("品牌id")
+    private Integer brandId;
     /**
      * 用户身份: 1管理员 2供应商
      */

+ 2 - 1
src/main/java/com/caimei/service/AuthProductService.java

@@ -6,6 +6,7 @@ import com.caimei.model.vo.ProductFormVo;
 import com.caimei.model.vo.ProductListVo;
 import com.github.pagehelper.PageInfo;
 
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -58,7 +59,7 @@ public interface AuthProductService {
      * }
      * @return ResponseJson
      */
-    ResponseJson saveProduct(ProductSaveDto productSaveDto);
+    ResponseJson saveProduct(ProductSaveDto productSaveDto) throws IOException;
 
     /**
      * 获取授权商品回显数据

+ 73 - 3
src/main/java/com/caimei/service/impl/AuthProductServiceImpl.java

@@ -1,5 +1,6 @@
 package com.caimei.service.impl;
 
+import com.caimei.config.FastDfsClient;
 import com.caimei.mapper.AuthProductMapper;
 import com.caimei.model.ResponseJson;
 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.ProductListVo;
 import com.caimei.service.AuthProductService;
+import com.caimei.utils.Base64Util;
+import com.caimei.utils.ImageUtils;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 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.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;
+import java.io.InputStream;
 import java.util.Date;
 import java.util.List;
+import java.util.UUID;
 
 /**
  * Description
@@ -32,6 +45,12 @@ public class AuthProductServiceImpl implements AuthProductService {
     @Resource
     private AuthProductMapper authProductMapper;
 
+    @Autowired
+    private FastDfsClient client;
+
+    @Value("${caimei.imageDomain}")
+    private String imageDomain;
+
     @Override
     public ResponseJson<PageInfo<ProductListVo>> getProductList(Integer authId, String productName, String snCode, Integer pageNum, Integer pageSize) {
         if (null == authId) {
@@ -55,9 +74,9 @@ public class AuthProductServiceImpl implements AuthProductService {
         }
         authProductMapper.updateProductStatusByProductId(productId, status);
         if (status == 0) {
-            return ResponseJson.success("下授权商品成功");
+            return ResponseJson.success("下线授权商品成功");
         } else {
-            return ResponseJson.success("上授权商品成功");
+            return ResponseJson.success("上线授权商品成功");
         }
     }
 
@@ -74,7 +93,7 @@ public class AuthProductServiceImpl implements AuthProductService {
     }
 
     @Override
-    public ResponseJson saveProduct(ProductSaveDto productSaveDto) {
+    public ResponseJson saveProduct(ProductSaveDto productSaveDto) throws IOException {
         Integer productId = productSaveDto.getProductId();
         Integer authId = productSaveDto.getAuthId();
         Integer brandId = productSaveDto.getBrandId();
@@ -140,11 +159,33 @@ public class AuthProductServiceImpl implements AuthProductService {
             product.setCreateBy(createBy);
             // 创建时间
             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);
         } else {
             // 商品id
             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);
         }
@@ -159,6 +200,21 @@ public class AuthProductServiceImpl implements AuthProductService {
         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
     public ResponseJson<ProductFormVo> getProductFormData(Integer productId) {
         if (null == productId) {
@@ -177,4 +233,18 @@ public class AuthProductServiceImpl implements AuthProductService {
     public List<Integer> getProductIdsByAuthId(Integer 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);
+    }
 }

+ 2 - 2
src/main/java/com/caimei/service/impl/AuthServiceImpl.java

@@ -61,9 +61,9 @@ public class AuthServiceImpl implements AuthService {
         }
         authMapper.updateAuthStatusByAuthId(authId, status);
         if (status == 0) {
-            return ResponseJson.success("下品牌授权成功");
+            return ResponseJson.success("下线品牌授权成功");
         } else {
-            return ResponseJson.success("上品牌授权成功");
+            return ResponseJson.success("上线品牌授权成功");
         }
     }
 

+ 17 - 6
src/main/java/com/caimei/service/impl/ShopServiceImpl.java

@@ -89,20 +89,26 @@ public class ShopServiceImpl implements ShopService {
         String uuid = UUID.randomUUID().toString().replaceAll("-", "");
         String filePath = uuid + "." + fileType;
         String contentType = OSSUtils.getContentType(fileAllName);
+        log.info(">>>>>>>>>>>>>上传文件,用户id:" + authUserId);
         try {
             //保存本地
             File uploadFile = OSSUtils.ossUpload(file);
             //判断文件的唯一性,转换成16进制md5值
             String md5Hex = DigestUtils.md5Hex(new FileInputStream(uploadFile));
-            CmBrandAuthFilePo searchFile = new CmBrandAuthFilePo();
-            searchFile.setAuthUserId(authUserId);
-            searchFile.setMd5Hex(md5Hex);
-            // 查找该供应商下是否已存在相同文件
-            CmBrandAuthFilePo cmBrandAuthFile = shopMapper.getStatementFile(searchFile);
+            CmBrandAuthFilePo cmBrandAuthFile = null;
+            if (null != authUserId) {
+                // 查找该供应商下是否已存在相同文件
+                CmBrandAuthFilePo searchFile = new CmBrandAuthFilePo();
+                searchFile.setAuthUserId(authUserId);
+                searchFile.setMd5Hex(md5Hex);
+                cmBrandAuthFile = shopMapper.getStatementFile(searchFile);
+            }
             if (cmBrandAuthFile == null) {
                 log.info("默认路径>>>" + uploadFile.getAbsolutePath());
                 // 修改情况下,如果原来已经选择了文件代理声明,并且旧文件与新文件不同,需要将旧文件删除
-                deleteFile(authUserId, brandId);
+                if (null != authUserId) {
+                    deleteFile(authUserId, brandId);
+                }
                 //将新文件上传oss
                 OSSUtils.ossUpload(filePath, uploadFile, contentType);
                 //删除本地文件
@@ -155,6 +161,11 @@ public class ShopServiceImpl implements ShopService {
             if (null != userIdByMobile) {
                 return ResponseJson.error("该手机号已被使用,请重新输入", null);
             }
+            // 添加时验证供应商名称是否已被使用
+            Integer userIdByShopName = shopMapper.getUserIdByShopName(shopName);
+            if (null != userIdByShopName) {
+                return ResponseJson.error("该供应商名称已经存在,请重新输入", null);
+            }
         }
         // 更新品牌授权logo
         shopInfoList.forEach(shopInfo->{

+ 80 - 0
src/main/java/com/caimei/utils/Base64Util.java

@@ -0,0 +1,80 @@
+package com.caimei.utils;
+
+import org.springframework.web.multipart.MultipartFile;
+import sun.misc.BASE64Decoder;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class Base64Util implements MultipartFile{
+    private final byte[] imgContent;
+    private final String header;
+
+    public Base64Util(byte[] imgContent, String header) {
+        this.imgContent = imgContent;
+        this.header = header.split(";")[0];
+    }
+
+    @Override
+    public String getName() {
+        return System.currentTimeMillis() + Math.random() + "." + header.split("/")[1];
+    }
+
+    @Override
+    public String getOriginalFilename() {
+        return System.currentTimeMillis() + (int) Math.random() * 10000 + "." + header.split("/")[1];
+    }
+
+    @Override
+    public String getContentType() {
+        return header.split(":")[1];
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return imgContent == null || imgContent.length == 0;
+    }
+
+    @Override
+    public long getSize() {
+        return imgContent.length;
+    }
+
+    @Override
+    public byte[] getBytes() throws IOException {
+        return imgContent;
+    }
+
+    @Override
+    public ByteArrayInputStream getInputStream() throws IOException {
+        return new ByteArrayInputStream(imgContent);
+    }
+
+    @Override
+    public void transferTo(File dest) throws IOException, IllegalStateException {
+        new FileOutputStream(dest).write(imgContent);
+    }
+
+    public static MultipartFile base64ToMultipart(String base64) {
+        try {
+            String[] baseStrs = base64.split(",");
+
+            BASE64Decoder decoder = new BASE64Decoder();
+            byte[] b = new byte[0];
+            b = decoder.decodeBuffer(baseStrs[1]);
+
+            for (int i = 0; i < b.length; ++i) {
+                if (b[i] < 0) {
+                    b[i] += 256;
+                }
+            }
+            return new Base64Util(b, baseStrs[0]);
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+}

+ 196 - 0
src/main/java/com/caimei/utils/ImageUtils.java

@@ -0,0 +1,196 @@
+package com.caimei.utils;
+
+import org.springframework.util.StringUtils;
+import sun.misc.BASE64Encoder;
+
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2020/3/16
+ */
+public class ImageUtils {
+
+	public static String getImageURL(String dirName, String src, String domain) {
+		return getImageURL(dirName, src, 0,domain);
+	}
+
+	/***
+	 * 获取图片地址
+	 *
+	 * @param src
+	 *            保存在数据库中的图片文件名
+	 * @param type
+	 *            图片的前缀 (如 type = 200 那么则获取的图片是 200_XXX的图片)
+	 * @param dirName
+	 *            图片保存的文件夹名 如 (league)
+	 * @param domain
+	 * 			   加上域名拼成完整路径
+	 * @return
+	 */
+	public static String getImageURL(String dirName, String src, int type, String domain) {
+
+
+		//正式环境 域名 http --- https处理
+		if (domain != null && !"".equals(domain) && domain.startsWith("http:") && domain.toLowerCase().lastIndexOf("config/beta")== -1 && domain.toLowerCase().lastIndexOf("localhost")== -1) {
+			domain = domain.replace("http:", "https:");
+		}
+
+		//正式环境 图片地址 http --- https处理
+		if(src != null && src.startsWith("https:")){
+			//非正式环境 使用http
+			if (domain !=null && !"".equals(domain) && domain.toLowerCase().lastIndexOf("config/beta")>-1 || domain.toLowerCase().lastIndexOf("localhost")>-1){
+				src = src.replace("https:","http:");
+			}
+			return src;
+		}
+
+		//正式环境 图片地址  http --- https处理
+		if(src != null && src.startsWith("http:")){
+			//非正式环境 使用http
+			if (domain !=null && !"".equals(domain) && domain.toLowerCase().lastIndexOf("config/beta")==-1 && domain.toLowerCase().lastIndexOf("localhost")==-1){
+				src = src.replace("http:","https:");
+			}
+			return src;
+		}
+		type = 0 ;
+		dirName = dirName.trim();
+		if (dirName == null) {dirName = "";}
+		if(src == null || src.equalsIgnoreCase("null")) {src = "";}
+		if (src.indexOf(",") > 0) {
+			String tmp = src;
+			src = tmp.substring(0, tmp.indexOf(","));
+		}
+		String image = "/img/default/none.jpg";
+		if (dirName.equals("user")) {
+			image = "/img/default/HeaderImg.png";
+		} else if (dirName.equals("club")) {
+			image = "/img/default/default_club.jpg";
+		} else if (dirName.equals("shopLogo")) {
+			image = "/img/default/suppliver.jpg";
+		}else if (dirName.equals("caiMeiImage")) {
+			image = "/img/default/caiMeiImage.jpg";
+		}else {
+			image = "/img/default/none.jpg";
+		}
+		if (src != null && !src.equals("")) {
+			if (type != 0 || dirName.equals("product")) {
+				src = src.replace("\\", "/");
+				String srcActual = src;
+				String subDirName = "";
+				int index = src.lastIndexOf("/");
+
+				if (index != -1) {
+					subDirName = src.substring(0, index + 1);
+					srcActual = src.substring(index + 1);
+				}
+				boolean b = src.startsWith("/uploadFile");
+				if(b){
+					image = src;
+				}else{
+					image = "/uploadFile/" + dirName + "/" + subDirName
+							+ (type == 0 ? "" : type + "_") + srcActual;
+				}
+			} else {
+				boolean b = src.startsWith("/uploadFile");
+				if(b){
+					image = src;
+				}else{
+					image = "/uploadFile/" + dirName + "/" + src;
+				}
+			}
+		}else {
+			if(StringUtils.isEmpty(image)) {
+				image = "/img/default/none.jpg";
+			}
+		}
+		return domain + image;
+	}
+
+	public static String getProductImageURL(String image, int type, String domain) {
+		if (image == null) {
+			return getImageURL("product", "", type, domain);
+		}
+		return getImageURL("product", image, type, domain);
+	}
+
+	/**
+	 * 添加水印图片
+	 * @param waterMarkImg	水印图片
+	 * @param srcImgURL		原图片路径
+	 * @param degree		旋转角度
+	 * @return
+	 */
+	public static String markImageByIcon(Image waterMarkImg, String srcImgURL, Integer degree) {
+		//io流
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		try {
+			//原图片
+			ImageIcon imageIcon = new ImageIcon(new URL(srcImgURL));
+			Image srcImg = imageIcon.getImage();
+			BufferedImage buffImg = ImageIO.read(new URL(srcImgURL));
+
+			// 1、得到画笔对象
+			Graphics2D g = buffImg.createGraphics();
+
+			// 2、设置对线段的锯齿状边缘处理
+			g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+					RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+
+			g.drawImage(
+					srcImg.getScaledInstance(srcImg.getWidth(null),
+							srcImg.getHeight(null), Image.SCALE_SMOOTH), 0, 0,
+					null);
+			// 3、设置水印旋转
+			if (null != degree) {
+				g.rotate(Math.toRadians(degree),
+						(double) buffImg.getWidth() / 2,
+						(double) buffImg.getHeight() / 2);
+			}
+
+
+			g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,
+					1f));
+
+			// 6、水印图片的位置
+			int srcWidth = srcImg.getWidth(null);
+			int srcHeight = srcImg.getHeight(null);
+			int waterMarkWidth = waterMarkImg.getWidth(null);
+			int waterMarkHeight = waterMarkImg.getHeight(null);
+			g.drawImage(waterMarkImg, (srcWidth - waterMarkWidth) / 2, srcHeight - waterMarkHeight, null);
+			g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
+			// 7、释放资源
+			g.dispose();
+
+			//将图片写入流中
+			ImageIO.write(buffImg, "png", baos);
+			//转换成字节
+			byte[] bytes = baos.toByteArray();
+			BASE64Encoder encoder = new BASE64Encoder();
+			//转换成base64串
+			String addImage = encoder.encodeBuffer(bytes).trim();
+			//删除 \r\n
+			addImage = addImage.replaceAll("\n", "").replaceAll("\r", "");
+			return "data:image/jpg;base64," + addImage;
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				if (null != baos) {
+					baos.close();
+				}
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+		return null;
+	}
+}

+ 2 - 2
src/main/java/com/caimei/utils/OSSUtils.java

@@ -57,7 +57,7 @@ public class OSSUtils {
             OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
             ObjectMetadata meta = new ObjectMetadata();
             meta.setContentType(contentType);
-            fileName = active + "/" + fileName;
+            fileName = active + "/authFile/" + fileName;
             UploadFileRequest uploadFileRequest = new UploadFileRequest(privateBucket, fileName);
             // 指定上传的本地文件。
             uploadFileRequest.setUploadFile(file.toString());
@@ -182,7 +182,7 @@ public class OSSUtils {
         OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
         // 删除文件。如需删除文件夹,请将ObjectName设置为对应的文件夹名称。
         // 如果文件夹非空,则需要将文件夹下的所有object删除后才能删除该文件夹。
-        ossClient.deleteObject(privateBucket, active + "/" + fileName);
+        ossClient.deleteObject(privateBucket, active + "/authFile/" + fileName);
         // 关闭OSSClient。
         ossClient.shutdown();
     }

+ 27 - 13
src/main/resources/backup.sql

@@ -30,28 +30,21 @@ CREATE TABLE `cm_brand_auth_shop_info` (
     COMMENT = '正品联盟供应商信息';
 
 
-INSERT INTO `cm_brand_auth_user` (`authUserId`, `name`, `password`, `userIdentity`, `status`) VALUES ('1', 'admin', '21D34CF4A2F21FDD791C4C1B67C3F954', '1', '1');
+INSERT INTO `cm_brand_auth_user` (`authUserId`, `name`, `password`, `userIdentity`, `status`) VALUES ('1', 'admin', '2A84213D52B1A2C85FB385A3DEDC789F', '1', '1');
 
 
 ALTER TABLE `cm_brand_auth`
-    DROP COLUMN `statementImage`,
-    DROP COLUMN `statementLink`,
-    DROP COLUMN `statementContent`,
-    DROP COLUMN `statementType`,
-    DROP COLUMN `agentName`,
-    DROP COLUMN `agentFlag`,
-    DROP COLUMN `securityLink`,
-    DROP COLUMN `countryId`,
-    DROP COLUMN `brandId`,
     ADD COLUMN `authUserId` INT NULL COMMENT '供应商用户id' AFTER `id`,
     ADD COLUMN `status` INT NULL COMMENT '上架状态:0已下架,1已上架' AFTER `authParty`;
 
 
-
-
 ALTER TABLE `cm_brand_auth_product`
     ADD COLUMN `status` INT NULL COMMENT '上架状态:0下架,1上架' AFTER `certificateImage`,
-    ADD COLUMN `brandId` INT NULL COMMENT '品牌id' AFTER `authId`;
+    ADD COLUMN `brandId` INT NULL COMMENT '品牌id' AFTER `authId`,
+    ADD COLUMN `pcImage` VARCHAR(255) NULL COMMENT 'pc添加水印商品图片' AFTER `image`,
+    ADD COLUMN `appletsImage` VARCHAR(255) NULL COMMENT '小程序添加水印商品图片' AFTER `pcImage`,
+    ADD COLUMN `pcCertificateImage` VARCHAR(255) NULL COMMENT 'pc添加水印授权牌照' AFTER `certificateImage`,
+    ADD COLUMN `appletsCertificateImage` VARCHAR(255) NULL COMMENT '小程序添加水印授权牌照' AFTER `pcCertificateImage`;
 
 
 CREATE TABLE `cm_brand_auth_file` (
@@ -69,4 +62,25 @@ CREATE TABLE `cm_brand_auth_file` (
     COMMENT = '品牌授权代理声明文件';
 
 
+# -----------------------------------------------------------------
+ALTER TABLE `cm_brand_auth`
+    DROP COLUMN `statementImage`,
+    DROP COLUMN `statementLink`,
+    DROP COLUMN `statementContent`,
+    DROP COLUMN `statementType`,
+    DROP COLUMN `agentName`,
+    DROP COLUMN `agentFlag`,
+    DROP COLUMN `securityLink`,
+    DROP COLUMN `countryId`,
+    DROP COLUMN `brandId`;
+
+UPDATE `cm_brand_auth` set authUserId = 2,status = 1 where id = 1;
+UPDATE `cm_brand_auth` set authUserId = 2,status = 1 where id between 3 and 55;
+UPDATE `cm_brand_auth` set authUserId = 3,status = 1 where id = 2;
+
+UPDATE `cm_brand_auth_product` set brandId = 144 where id = 1;
+UPDATE `cm_brand_auth_product` set brandId = 39 where id = 2;
+UPDATE `cm_brand_auth_product` set brandId = 204 where id between 3 and 62;
+
+
 

BIN
src/main/resources/images/appletsWaterMark.png


BIN
src/main/resources/images/pcWaterMark.png


+ 1 - 0
src/main/resources/mapper/AuthMapper.xml

@@ -27,5 +27,6 @@
         <if test="authParty != null and authParty != ''">
             and a.authParty like CONCAT('%',#{authParty},'%')
         </if>
+        order by a.createTime desc
     </select>
 </mapper>

+ 24 - 4
src/main/resources/mapper/AuthProductMapper.xml

@@ -2,9 +2,11 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.mapper.AuthProductMapper">
     <insert id="insertProduct" keyColumn="id" keyProperty="productId" useGeneratedKeys="true" parameterType="com.caimei.model.po.ProductPo">
-        insert into cm_brand_auth_product(`authId`, `brandId`, `name`, `snCode`, `image`, `certificateImage`, `status`,
+        insert into cm_brand_auth_product(`authId`, `brandId`, `name`, `snCode`, `image`,`pcImage`,`appletsImage`, `certificateImage`,
+                                          `pcCertificateImage`,`appletsCertificateImage`, `status`,
                                           `createTime`, `createBy`)
-        values (#{authId}, #{brandId}, #{productName}, #{snCode}, #{productImage}, #{certificateImage}, #{status}, #{createTime},
+        values (#{authId}, #{brandId}, #{productName}, #{snCode}, #{productImage}, #{pcImage}, #{appletsImage},
+                #{certificateImage}, #{pcCertificateImage}, #{appletsCertificateImage}, #{status}, #{createTime},
                 #{createBy})
     </insert>
     <insert id="insertProductParam">
@@ -19,12 +21,26 @@
     </update>
     <update id="updateProductByProductId">
         update cm_brand_auth_product
-        set `brandId`          = #{brandId},
+        <set>
+            `brandId`          = #{brandId},
             `name`             = #{productName},
             `snCode`           = #{snCode},
             `image`            = #{productImage},
             `certificateImage` = #{certificateImage},
-            `status`           = #{status}
+            `status`           = #{status},
+            <if test="pcImage != null and pcImage != ''">
+                `pcImage`      = #{pcImage},
+            </if>
+            <if test="appletsImage != null and appletsImage != ''">
+                `appletsImage` = #{appletsImage},
+            </if>
+            <if test="pcCertificateImage != null and pcCertificateImage != ''">
+                `pcCertificateImage`      = #{pcCertificateImage},
+            </if>
+            <if test="appletsCertificateImage != null and appletsCertificateImage != ''">
+                `appletsCertificateImage`      = #{appletsCertificateImage},
+            </if>
+        </set>
         where id = #{productId};
     </update>
     <delete id="deleteProductByProductId">
@@ -44,6 +60,7 @@
         <if test="snCode != null and snCode != ''">
             and snCode like CONCAT('%',#{snCode},'%')
         </if>
+        order by p.createTime desc
     </select>
     <select id="getProductIdBySnCode" resultType="java.lang.Integer">
         select id from cm_brand_auth_product where snCode = #{snCode} limit 1
@@ -68,4 +85,7 @@
     <select id="getProductIdsByAuthId" resultType="java.lang.Integer">
         select id from cm_brand_auth_product where authId = #{authId}
     </select>
+    <select id="getImageByProductId" resultType="com.caimei.model.po.ProductPo">
+        select image as productImage,certificateImage from cm_brand_auth_product where id = #{productId}
+    </select>
 </mapper>

+ 6 - 3
src/main/resources/mapper/ShopMapper.xml

@@ -91,8 +91,8 @@
         delete from cm_brand_auth_shop_info where id = #{infoId}
     </delete>
     <select id="getShopList" resultType="com.caimei.model.vo.ShopListVo">
-        select u.authUserId,u.name,u.shopType,group_concat(cb.name) as brandName,u.mobile,u.linkMan,
-            u.status as shopStatus,u.createTime,
+        select u.authUserId,u.name,u.shopType,group_concat(cb.name) as brandName,group_concat(cb.id) as brandId,
+               u.mobile,u.linkMan,u.status as shopStatus,u.createTime,
             (select au.name from cm_brand_auth_user au where au.authUserId = u.createBy) as createBy
             from cm_brand_auth_user u
             left join cm_brand_auth_shop_info s on u.authUserId = s.authUserId
@@ -168,7 +168,7 @@
         where validFlag = 1
     </select>
     <select id="getUserIdByMobile" resultType="java.lang.Integer">
-        select authUserId from cm_brand_auth_user where mobile = #{mobile} and userIdentity = 2
+        select authUserId from cm_brand_auth_user where mobile = #{mobile} and userIdentity = 2 limit 1
     </select>
     <select id="getDbInfoBrandList" resultType="com.caimei.model.vo.ShopBrandVo">
         select id,brandId
@@ -192,4 +192,7 @@
                  left join cm_brand_auth_file f on i.authUserId = f.authUserId and i.brandId = f.brandId
         where i.authUserId = #{authUserId}
     </select>
+    <select id="getUserIdByShopName" resultType="java.lang.Integer">
+        select authUserId from cm_brand_auth_user where name = #{shopName} and userIdentity = 2 limit 1
+    </select>
 </mapper>

+ 10 - 2
src/main/resources/mapper/UserMapper.xml

@@ -14,8 +14,16 @@
         limit 1;
     </select>
     <select id="getShopUserByMobile" resultType="com.caimei.model.vo.UserLoginVo">
-        select authUserId, name, password, userIdentity, status as shopStatus
-        from cm_brand_auth_user
+        select u.authUserId,
+               u.name,
+               password,
+               userIdentity,
+               u.status as shopStatus,
+               shopType,
+               if(u.shopType = 1, b.id, null) as brandId
+        from cm_brand_auth_user u
+                 left join cm_brand_auth_shop_info i on u.authUserId = i.authUserId
+                 left join cm_brand b on i.brandId = b.id
         where mobile = #{mobile}
         limit 1;
     </select>

+ 17 - 0
src/test/java/com/caimei/AdminApplicationTests.java

@@ -1,9 +1,16 @@
 package com.caimei;
 
+import com.caimei.utils.ImageUtils;
 import com.caimei.utils.JwtUtil;
 import com.caimei.utils.OSSUtils;
 import org.junit.Test;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.core.io.ClassPathResource;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.io.IOException;
+import java.io.InputStream;
 
 @SpringBootTest
 public class AdminApplicationTests {
@@ -12,4 +19,14 @@ public class AdminApplicationTests {
     public void JWTToken(){
         OSSUtils.deleteSingleFile("5dbb6eb668174438ae5f9b5a1d99f7cf.ppt");
     }
+
+    @Test
+    public void  drawImage() throws IOException {
+        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);
+    }
 }