Administrator
2020-02-28 306345e91a05dfbdf6ced32cf0cfc3f378aaac4d
发圈画图+添加评论
3个文件已修改
2个文件已添加
228 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java 141 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java 79 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/image/share/down_tip_jd_pdd.png 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/image/share/down_tip_tb.png 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareControllerV2.java
@@ -614,9 +614,9 @@
                recommendText = template.replace("[商品标题]", goods.getTitle()).replace("[销量]",
                        TaoBaoUtil.getSaleCount(taoBaoLink.getGoods().getBiz30day()));
                if (StringUtil.isNullOrEmpty(goods.getDescription())) {
                    recommendText = recommendText.replace("推荐语:[推荐语]", "");
                    recommendText = recommendText.replace("推荐理由:[推荐语]", "");
                } else {
                    recommendText = recommendText.replace("[推荐语]", goods.getDescription());
                    recommendText = recommendText.replace("[推荐理由]", goods.getDescription());
                }
                String quickCommentText = configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey());
@@ -790,7 +790,7 @@
            recommendText = template.replace("[商品标题]", jdGoods.getSkuName()).replace("[销量]",
                    JDUtil.getSaleCount(jdGoods.getInOrderCount30Days()));
            // 无推荐语
            recommendText = recommendText.replace("推荐语:[推荐语]", "");
            recommendText = recommendText.replace("推荐理由:[推荐语]", "");
            String quickCommentText = configService.get(ConfigKeyEnum.quickShareJDCommentText.getKey());
            commentText = quickCommentText.replace("[原价]", jdGoods.getPrice().toString());
@@ -969,7 +969,7 @@
                salesTip = "0";
            }
            recommendText = recommendText.replace("[销量]", salesTip);
            recommendText = recommendText.replace("推荐语:[推荐语]", "");
            recommendText = recommendText.replace("推荐理由:[推荐语]", "");
            String quickCommentText = configService.get(ConfigKeyEnum.quickSharePDDCommentText.getKey());
            commentText = quickCommentText.replace("[原价]", MoneyBigDecimalUtil
fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java
@@ -2,11 +2,8 @@
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
@@ -22,25 +19,16 @@
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.tencentcloud.COSManager;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.yeshi.fanli.dao.dynamic.GoodsEvaluateDao;
import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.dto.jd.JDCouponInfo;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.activity.ActivityUser;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.dynamic.CommentInfo;
import com.yeshi.fanli.entity.dynamic.DynamicInfo;
import com.yeshi.fanli.entity.dynamic.CommentInfo.CommentInfoEnum;
import com.yeshi.fanli.entity.dynamic.DynamicInfo;
import com.yeshi.fanli.entity.dynamic.GoodsEvaluate;
import com.yeshi.fanli.entity.dynamic.GoodsEvaluate.EvaluateEnum;
import com.yeshi.fanli.entity.dynamic.GoodsPicture;
@@ -48,13 +36,17 @@
import com.yeshi.fanli.entity.dynamic.ImgInfo.ImgEnum;
import com.yeshi.fanli.entity.dynamic.SimpleGoods;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoLink;
import com.yeshi.fanli.exception.dynamic.ActivityUserException;
import com.yeshi.fanli.exception.dynamic.GoodsEvaluateException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.activity.ActivityUserService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.dynamic.GoodsEvaluateService;
import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.FilePathEnum;
@@ -63,11 +55,13 @@
import com.yeshi.fanli.util.cache.JDGoodsCacheUtil;
import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.jd.JDApiUtil;
import com.yeshi.fanli.util.jd.JDUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.vo.goods.CouponInfoVO;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
import net.sf.json.JSONObject;
@Service
public class GoodsEvaluateServiceImpl implements GoodsEvaluateService {
@@ -92,6 +86,14 @@
    @Resource
    private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
    @Resource
    private ConfigService configService;
    @Resource
    private ShareGoodsService shareGoodsService;
    @Override
    public String saveHead(MultipartFile file, GoodsEvaluate record) throws GoodsEvaluateException {
@@ -205,17 +207,18 @@
        List<String> listOld = new ArrayList<String>();
        // 处理图片
        GoodsDetailVO oldGoodsVO = null;
        List<ImgInfo> resultList = resultObj.getImgList();
        if (resultList != null && resultList.size() > 0) {
            for (ImgInfo info : resultList) {
                ImgEnum type = info.getType();
                if (type == ImgEnum.video) {
                    imgVideo = info;
                } else if (type == ImgEnum.goods || type == ImgEnum.img) {
                    String url = info.getUrl();
                    if (!StringUtil.isNullOrEmpty(url)) {
                        listOld.add(url);
                    }
                } else if (type == ImgEnum.goods ) {
                    listOld.add(info.getUrl());
                    oldGoodsVO = info.getGoodsVO();
                } else if (type == ImgEnum.img){
                    listOld.add(info.getUrl());
                }
            }
        }
@@ -298,8 +301,28 @@
            picNum = 1;
        }
        GoodsDetailVO goodsDetailVO = getGoodsDetailVO(goodsId, goodsType);
        ;
        GoodsDetailVO goodsDetailVO = null;
        JDGoods jdGoods = null;
        PDDGoodsDetail pddGoods = null;
        BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
        BigDecimal shareRate = hongBaoManageService.getShareRate();
        BigDecimal vipFanLiRate = hongBaoManageService.getVIPFanLiRate();
        ConfigParamsDTO params = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE, vipFanLiRate);
        if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
            try {
                TaoBaoGoodsBrief goodsBrief = redisManager.getTaoBaoGoodsBrief(goodsId);
                goodsDetailVO = GoodsDetailVOFactory.convertTaoBao(goodsBrief, params);
            } catch (TaobaoGoodsDownException e) {
                throw new GoodsEvaluateException(1, "商品已下架");
            }
        } else if (goodsType == Constant.SOURCE_TYPE_JD) {
            jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
            goodsDetailVO = GoodsDetailVOFactory.convertJDGoods(jdGoods, params);
        } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
            pddGoods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
            goodsDetailVO = GoodsDetailVOFactory.convertPDDGoods(pddGoods, params);
        }
        if (goodsDetailVO == null) {
            throw new GoodsEvaluateException(1, "该商品信息不存在");
        }
@@ -371,6 +394,59 @@
        resultObj.setGoods(goodsDetailVO);
        resultObj.setMainPicNum(picNum);
        resultObj.setImgList(listImg);
        boolean addComment = true;
        List<CommentInfo> commentsNew = new ArrayList<>();
        List<CommentInfo> comments = resultObj.getComments();
        if (comments != null) {
            for (CommentInfo commentInfo: comments) {
                if (commentInfo.getType() == CommentInfoEnum.goodsCoupon) {
                    if (oldGoodsVO != null && oldGoodsVO.getGoodsId().longValue() == goodsId.longValue()
                            && oldGoodsVO.getGoodsType() == goodsType) {
                        addComment = true;
                    } else {
                        addComment = false;
                    }
                    continue;
                }
                commentsNew.add(commentInfo);
            }
        }
        if (addComment) {
            String commentText = "";
            if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
                TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(0L, goodsId, null);
                String template = configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey());
                commentText = template.replace("[口令]", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
            } else if (goodsType == Constant.SOURCE_TYPE_JD) {
                String couponUrl = null;
                JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(jdGoods);
                if (couponInfo != null) {
                    couponUrl = couponInfo.getLink();
                }
                String materialId = "https://item.jd.com/" + goodsId + ".html";
                String jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "","0");
                String template = configService.get(ConfigKeyEnum.quickShareJDCommentText.getKey());
                commentText = template.replace("[链接]", jumpLink);
            } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
                String jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsId, PinDuoDuoApiUtil.PID_SHARE + "", "0");
                String template = configService.get(ConfigKeyEnum.quickSharePDDCommentText.getKey());
                commentText = template.replace("[链接]", jumpLink);
            }
            commentText = commentText.replace("[原价]", goodsDetailVO.getZkPrice().toString());
            if (!goodsDetailVO.isHasCoupon()) {
                commentText = commentText.replace("领券抢购", "抢购");
            }
            CommentInfo commentInfo = new CommentInfo();
            commentInfo.setId(UUID.randomUUID().toString().replace("-", ""));
            commentInfo.setContent(commentText);
            commentInfo.setType(CommentInfoEnum.goodsCoupon);
            commentsNew.add(commentInfo);
            resultObj.setComments(commentsNew);
        }
        goodsEvaluateDao.save(resultObj);
        // 删除图片
@@ -1333,6 +1409,25 @@
                    }
                    imgInfo.setGoods(simpleGoods);
                    goodsEvaluate.setGoods(goodsVO);
                    TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(0L, goodsVO.getGoodsId(), null);
                    String template = configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey());
                    String commentText = template.replace("[口令]", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
                    commentText = commentText.replace("[原价]", goodsVO.getZkPrice().toString());
                    if (!goodsVO.isHasCoupon()) {
                        commentText = commentText.replace("领券抢购", "抢购");
                    }
                    CommentInfo commentInfo = new CommentInfo();
                    commentInfo.setId(UUID.randomUUID().toString().replace("-", ""));
                    commentInfo.setContent(commentText);
                    commentInfo.setType(CommentInfoEnum.goodsCoupon);
                    List<CommentInfo> commentsNew = new ArrayList<>();
                    commentsNew.add(commentInfo);
                    goodsEvaluate.setComments(commentsNew);
                }
                imgList.add(imgInfo);
            }
fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
@@ -265,7 +265,8 @@
            Font boldFont36 = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
            int px = 640; // 图片宽度
            int py = 1154; // 图片高度
//            int py = 1154; // 图片高度 显示邀请码
            int py = 1060; // 图片高度
            final BufferedImage targetImg = new BufferedImage(px, py, BufferedImage.TYPE_INT_RGB);
            HashMap<Key, Object> mapH = new HashMap<Key, Object>();
            mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 抗锯齿 (抗锯齿总开关)  
@@ -330,6 +331,8 @@
                g2d.drawString(title.substring(0, length2), spacing, y + 45 + row * 36);
            }
            
            int baoYouLength = spacing;
            if (!goods.isHasCoupon()) {
                // 无券
                g2d.setColor(new Color(229, 0, 92));
@@ -368,16 +371,18 @@
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                g2d.drawRoundRect(spacing + 42, y + 140, textLength + 20, 39, 10, 10);
                g2d.drawString(quanAmount, spacing + 55, y + 170);
                baoYouLength =spacing + 42 + textLength + 20  + 20;
            }
            // 自营 、包邮
            InputStream ziying = null;
            if (goods.getShopType() == 21) {
                InputStream ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_ziying.png");
                g2d.drawImage(ImageIO.read(ziying), spacing + 180, y + 150, 60, 30, null);
                ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_ziying.png");
            } else if (goods.isBaoyou()) {
                InputStream ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_baoyou.png");
                g2d.drawImage(ImageIO.read(ziying), spacing + 180, y + 150, 60, 30, null);
                ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_baoyou.png");
            }
            g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null);
            // 销量
            String sale = null;
@@ -398,29 +403,27 @@
            int textLength = fm.stringWidth(sale);
            g2d.setFont(font24);
            g2d.setColor(new Color(153, 153, 153));
            g2d.drawString(sale, spacing + 580 - textLength, y + 125);
            g2d.drawString(sale, spacing + 605 - textLength, y + 125);
            
            
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.setColor(new Color(255,222, 235));
            g2d.fillRoundRect(spacing, y + 200, 385, 203, 10, 10);
            // 下单提示
            InputStream downTip = null;
            if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
                downTip = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/down_tip_tb.png");
            } else {
                downTip = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/down_tip_jd_pdd.png");
            }
            g2d.drawImage(ImageIO.read(downTip), spacing, y + 200, 382, 203, null);
            
            Font font22 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(22.0f);
            g2d.setFont(font22);
            g2d.setColor(new Color(229,0, 92));
            g2d.drawString("如何下单?", spacing + 6, y + 245);
            g2d.drawString("1.长按识别本图", spacing + 6, y + 290);
            g2d.drawString("2.点击页面右上角[ ... ],选择[复制链接]", spacing + 6, y + 330);
            g2d.drawString("3.打开"+source+"App,领券下单", spacing + 6, y + 370);
            // 二维码图框
            InputStream codeFrame = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/qr_code_frame01.png");
            g2d.drawImage(ImageIO.read(codeFrame), spacing + 405, y + 200, 200, 203, null);
            
            // 画二维码
            int codeSize = 170;
            int pX =  spacing + 420;
            int pY =  y + 215;
            int codeSize = 190;
            int pX =  spacing + 411;
            int pY =  y + 207;
            g2d.drawImage(ImageIO.read(qrcode), pX, pY, codeSize, codeSize, null);
            int portraitSize = 200 * 5 / 23;
@@ -437,25 +440,25 @@
            g2d.drawImage(portraitImg, pPX, pPY, portraitSize, portraitSize, null);
            
                                
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.setColor(new Color(255,231, 224));
            g2d.fillRoundRect(spacing, y + 420, 607, 79, 10, 10);
            InputStream banliStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/banlikuaisheng.png");
            g2d.drawImage(ImageIO.read(banliStream), spacing + 20, y + 440, 170, 38, null);
            inviteCode = "邀请码:" + inviteCode;
            Font font26d28 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(26.28f);
            FontMetrics fmcode = g2d.getFontMetrics(font26d28);
            int codeLength = fmcode.stringWidth(inviteCode);
            // 邀请码背景
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.setColor(new Color(229,71, 27));
            g2d.fillRoundRect(spacing + (600 - (int)(codeLength * 1.1)), y + 440, 10 + codeLength, 37, 10, 10);
            // 邀请码文字
            g2d.setFont(font26d28);
            g2d.setColor(new Color(255, 255, 255));
            g2d.drawString(inviteCode, spacing + (600 - (int)(codeLength * 1.1) + 5), y + 468);
//            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//            g2d.setColor(new Color(255,231, 224));
//            g2d.fillRoundRect(spacing, y + 420, 607, 79, 10, 10);
//
//            InputStream banliStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/banlikuaisheng.png");
//            g2d.drawImage(ImageIO.read(banliStream), spacing + 20, y + 440, 170, 38, null);
//
//            inviteCode = "邀请码:" + inviteCode;
//            Font font26d28 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(26.28f);
//            FontMetrics fmcode = g2d.getFontMetrics(font26d28);
//            int codeLength = fmcode.stringWidth(inviteCode);
//            // 邀请码背景
//            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//            g2d.setColor(new Color(229,71, 27));
//            g2d.fillRoundRect(spacing + (600 - (int)(codeLength * 1.1)), y + 440, 10 + codeLength, 37, 10, 10);
//            // 邀请码文字
//            g2d.setFont(font26d28);
//            g2d.setColor(new Color(255, 255, 255));
//            g2d.drawString(inviteCode, spacing + (600 - (int)(codeLength * 1.1) + 5), y + 468);
            
            g2d.dispose();
fanli/src/main/resource/image/share/down_tip_jd_pdd.png
fanli/src/main/resource/image/share/down_tip_tb.png