|
@@ -1,26 +1,49 @@
|
|
|
package com.zhongzheng.modules.distribution.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.google.zxing.BarcodeFormat;
|
|
|
+import com.google.zxing.common.BitMatrix;
|
|
|
+import com.google.zxing.qrcode.QRCodeWriter;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.common.utils.ToolsUtils;
|
|
|
import com.zhongzheng.modules.distribution.bo.DistributionActivityPosterAddBo;
|
|
|
import com.zhongzheng.modules.distribution.bo.DistributionActivityPosterEditBo;
|
|
|
import com.zhongzheng.modules.distribution.bo.DistributionActivityPosterQueryBo;
|
|
|
+import com.zhongzheng.modules.distribution.bo.DistributionLinkAddBo;
|
|
|
import com.zhongzheng.modules.distribution.domain.DistributionActivity;
|
|
|
import com.zhongzheng.modules.distribution.domain.DistributionActivityPoster;
|
|
|
import com.zhongzheng.modules.distribution.mapper.DistributionActivityPosterMapper;
|
|
|
import com.zhongzheng.modules.distribution.service.IDistributionActivityPosterService;
|
|
|
import com.zhongzheng.modules.distribution.service.IDistributionActivityService;
|
|
|
+import com.zhongzheng.modules.distribution.service.IDistributionLinkService;
|
|
|
+import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
|
|
|
import com.zhongzheng.modules.distribution.vo.DistributionActivityPosterVo;
|
|
|
+import com.zhongzheng.modules.distribution.vo.DistributionActivityVo;
|
|
|
+import com.zhongzheng.modules.distribution.vo.DistributionSellerVo;
|
|
|
+import com.zhongzheng.modules.order.domain.Order;
|
|
|
+import com.zhongzheng.modules.system.domain.SysTenant;
|
|
|
+import com.zhongzheng.modules.system.service.ISysTenantService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.*;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.net.URL;
|
|
|
+import java.util.Base64;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -38,6 +61,21 @@ public class DistributionActivityPosterServiceImpl extends ServiceImpl<Distribut
|
|
|
@Autowired
|
|
|
private IDistributionActivityService iDistributionActivityService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IDistributionSellerService iDistributionSellerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDistributionLinkService iDistributionLinkService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysTenantService iSysTenantService;
|
|
|
+
|
|
|
+ @Value("${aliyun.oss.endpoint}")
|
|
|
+ private String ALIYUN_OSS_ENDPOINT;
|
|
|
+
|
|
|
+ @Value("${certificate.host}")
|
|
|
+ private String CERTIFICATE_HOST;
|
|
|
+
|
|
|
@Override
|
|
|
public DistributionActivityPosterVo queryById(Long posterId){
|
|
|
DistributionActivityPoster db = this.baseMapper.selectById(posterId);
|
|
@@ -45,8 +83,76 @@ public class DistributionActivityPosterServiceImpl extends ServiceImpl<Distribut
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DistributionActivityPosterVo makePoster(DistributionActivityPosterQueryBo bo) {
|
|
|
- return null;
|
|
|
+ public String makePoster(DistributionActivityPosterQueryBo bo) {
|
|
|
+ DistributionActivityVo activityVo = iDistributionActivityService.queryById(bo.getDistributionId());
|
|
|
+ DistributionActivityPoster db = this.baseMapper.selectById(activityVo.getPosterId());
|
|
|
+ DistributionSellerVo sellerVo = iDistributionSellerService.queryById(bo.getSellerId());
|
|
|
+ String posterConfig = db.getPosterConfig();
|
|
|
+ if(Validator.isEmpty(posterConfig)){
|
|
|
+ throw new CustomException("海报暂未设置");
|
|
|
+ }
|
|
|
+ String bacImg = db.getUrl();
|
|
|
+ JSONObject posterObj = JSON.parseObject(posterConfig);
|
|
|
+ JSONObject cardObj = posterObj.getJSONObject("cardCode");
|
|
|
+ JSONObject disObj = posterObj.getJSONObject("distribution");
|
|
|
+ String urlBase64 = null;
|
|
|
+ try {
|
|
|
+ String imageLocalUrl = ALIYUN_OSS_ENDPOINT + "/" + bacImg;
|
|
|
+ URL url = new URL(imageLocalUrl);
|
|
|
+ BufferedImage imageLocal = ImageIO.read(url);
|
|
|
+ // 以本地图片为模板
|
|
|
+ Graphics2D g = imageLocal.createGraphics();
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ SysTenant sysTenant = iSysTenantService.getOne(new LambdaQueryWrapper<SysTenant>().eq(SysTenant::getTenantId, ToolsUtils.getTenantId()));
|
|
|
+ //电子名片
|
|
|
+ boolean cardChecked = Boolean.valueOf(String.valueOf(cardObj.get("checked")));
|
|
|
+ if(cardChecked){
|
|
|
+ Integer top = Integer.valueOf(String.valueOf(cardObj.get("top")));
|
|
|
+ Integer left = Integer.valueOf(String.valueOf(cardObj.get("left")));
|
|
|
+ Integer width = Integer.valueOf(String.valueOf(cardObj.get("width")));
|
|
|
+ Integer height = Integer.valueOf(String.valueOf(cardObj.get("height")));
|
|
|
+ String qrTxt = sysTenant.getHostH5Seller()+"/pages/vcard/index?sellerCode="+sellerVo.getShareCode();
|
|
|
+ QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
|
|
+ BitMatrix bitMatrix = qrCodeWriter.encode(qrTxt, BarcodeFormat.QR_CODE, width, height);
|
|
|
+ BufferedImage qrImage = ToolsUtils.toBufferedImage(bitMatrix);
|
|
|
+ // 在模板上添加用户二维码(地址,左边距,上边距,图片宽度,图片高度,未知)
|
|
|
+ g.drawImage(qrImage, left, top, width, height, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //分销码
|
|
|
+ boolean disChecked = Boolean.valueOf(String.valueOf(disObj.get("checked")));
|
|
|
+ if(disChecked){
|
|
|
+ DistributionLinkAddBo addBo = new DistributionLinkAddBo();
|
|
|
+ String linkCode =activityVo.getDistributionId()+"_"+sellerVo.getSellerId()+"_"+ToolsUtils.getRandomString(8);
|
|
|
+ addBo.setLinkCode(linkCode);
|
|
|
+ addBo.setSellerId(sellerVo.getSellerId());
|
|
|
+ addBo.setDistributionId(activityVo.getDistributionId());
|
|
|
+ addBo.setOwner(1);
|
|
|
+ iDistributionLinkService.insertByAddBo(addBo);
|
|
|
+
|
|
|
+ Integer top = Integer.valueOf(String.valueOf(disObj.get("top")));
|
|
|
+ Integer left = Integer.valueOf(String.valueOf(disObj.get("left")));
|
|
|
+ Integer width = Integer.valueOf(String.valueOf(disObj.get("width")));
|
|
|
+ Integer height = Integer.valueOf(String.valueOf(disObj.get("height")));
|
|
|
+ String qrTxt = sysTenant.getHostH5Seller()+"/pages5/scan/retailact?sellerCode="+sellerVo.getShareCode()+"&distributionId="+activityVo.getDistributionId()+"&linkCode="+linkCode;
|
|
|
+ QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
|
|
+ BitMatrix bitMatrix = qrCodeWriter.encode(qrTxt, BarcodeFormat.QR_CODE, width, height);
|
|
|
+ BufferedImage qrImage = ToolsUtils.toBufferedImage(bitMatrix);
|
|
|
+ // 在模板上添加用户二维码(地址,左边距,上边距,图片宽度,图片高度,未知)
|
|
|
+ g.drawImage(qrImage, left, top, width, height, null);
|
|
|
+ }
|
|
|
+ // 完成模板修改
|
|
|
+ g.dispose();
|
|
|
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
+ ImageIO.write(imageLocal, "jpg", os);
|
|
|
+ //转换为base64
|
|
|
+ Base64.Encoder encoder1 = Base64.getEncoder();
|
|
|
+ urlBase64 = "data:image/jpeg;base64,"
|
|
|
+ + encoder1.encodeToString(os.toByteArray());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return urlBase64;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -118,4 +224,6 @@ public class DistributionActivityPosterServiceImpl extends ServiceImpl<Distribut
|
|
|
}
|
|
|
return this.removeByIds(ids);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|