From dd5b15229cb15459fa7c31ccea77dac28cbfafbd Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 13 四月 2020 10:04:20 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java |  197 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 197 insertions(+), 0 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java
index af1b5c6..e7cfea4 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsTextTemplateServiceImpl.java
@@ -14,6 +14,7 @@
 import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
 import com.yeshi.fanli.entity.goods.ShareGoodsTextTemplate;
 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.exception.goods.ShareGoodsTextTemplateException;
 import com.yeshi.fanli.service.inter.config.ConfigService;
@@ -221,6 +222,196 @@
 	}
 
 	@Override
+	public String getTextTemplateByTB(Long uid) {
+		String template = "";
+		ShareGoodsTextTemplate objct = shareGoodsTextTemplateMapper.selectByUid(uid);
+		if (objct != null && !StringUtil.isNullOrEmpty(objct.getShareTextTemplate())) {
+			template = objct.getShareTextTemplate();
+			if (template.contains("{鍟嗗搧鍘熶环}")|| template.contains("{浼樻儬鍒搁潰棰潁") ||
+					template.contains("{浼樻儬鍒镐环}")|| template.contains("{鏈堥攢閲弣")) {
+				template = ""; // 鑰佹澘鍒嗕韩
+			}
+		} 
+		if (StringUtil.isNullOrEmpty(template)) {
+			template = configService.get(ConfigKeyEnum.shareCommentTextTB.getKey());
+		}
+		
+		return template;
+	}
+	
+	@Override
+	public String getTextTemplateByJD(Long uid) {
+		String template = "";
+		ShareGoodsTextTemplate objct = shareGoodsTextTemplateMapper.selectByUid(uid);
+		if (objct != null && !StringUtil.isNullOrEmpty(objct.getShareJDTextTemplate())) {
+			template = objct.getShareJDTextTemplate();
+			if (template.contains("{鍟嗗搧鍘熶环}")|| template.contains("{鏈堥攢閲弣") || template.contains("{鐭摼鎺")) {
+				template = ""; // 鑰佹澘鍒嗕韩
+			}
+		} 
+		if (StringUtil.isNullOrEmpty(template)) {
+			template = configService.get(ConfigKeyEnum.shareCommentTextJD.getKey());
+		}
+		return template;
+	}
+	
+	@Override
+	public String getTextTemplateByPDD(Long uid) {
+		String template = "";
+		ShareGoodsTextTemplate objct = shareGoodsTextTemplateMapper.selectByUid(uid);
+		if (objct != null && !StringUtil.isNullOrEmpty(objct.getSharePDDTextTemplate())) {
+			template = objct.getSharePDDTextTemplate();
+			if (template.contains("{鍟嗗搧鍘熶环}")|| template.contains("{鎬婚攢閲弣") || template.contains("{鐭摼鎺")) {
+				template = ""; // 鑰佹澘鍒嗕韩
+			}
+		} 
+		if (StringUtil.isNullOrEmpty(template)) {
+			template = configService.get(ConfigKeyEnum.shareCommentTextPDD.getKey());
+		}
+		
+		return template;
+	}
+	
+	@Override
+	public void saveTemplateTB(Long uid, String template) throws ShareGoodsTextTemplateException {
+		verifyRightTB(template);
+		ShareGoodsTextTemplate old = shareGoodsTextTemplateMapper.selectByUid(uid);
+		if (old != null) {
+			ShareGoodsTextTemplate update = new ShareGoodsTextTemplate();
+			update.setId(old.getId());
+			update.setShareTextTemplate(template);
+			update.setUpdateTime(new Date());
+			shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update);
+		} else {
+			ShareGoodsTextTemplate textTemplate = new ShareGoodsTextTemplate();
+			textTemplate.setCreateTime(new Date());
+			textTemplate.setShareTextTemplate(template);
+			textTemplate.setUid(uid);
+			shareGoodsTextTemplateMapper.insertSelective(textTemplate);
+		}
+	}
+
+	@Override
+	public void saveTemplateJD(Long uid, String template) throws ShareGoodsTextTemplateException {
+		verifyRightJD(template);
+		ShareGoodsTextTemplate old = shareGoodsTextTemplateMapper.selectByUid(uid);
+		if (old != null) {
+			ShareGoodsTextTemplate update = new ShareGoodsTextTemplate();
+			update.setId(old.getId());
+			update.setShareJDTextTemplate(template);
+			update.setUpdateTime(new Date());
+			shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update);
+		} else {
+			ShareGoodsTextTemplate textTemplate = new ShareGoodsTextTemplate();
+			textTemplate.setCreateTime(new Date());
+			textTemplate.setShareJDTextTemplate(template);
+			textTemplate.setUid(uid);
+			shareGoodsTextTemplateMapper.insertSelective(textTemplate);
+		}
+	}
+
+	@Override
+	public void saveTemplatePDD(Long uid, String template) throws ShareGoodsTextTemplateException {
+		verifyRightPDD(template);
+		ShareGoodsTextTemplate old = shareGoodsTextTemplateMapper.selectByUid(uid);
+		if (old != null) {
+			ShareGoodsTextTemplate update = new ShareGoodsTextTemplate();
+			update.setId(old.getId());
+			update.setSharePDDTextTemplate(template);
+			update.setUpdateTime(new Date());
+			shareGoodsTextTemplateMapper.updateByPrimaryKeySelective(update);
+		} else {
+			ShareGoodsTextTemplate textTemplate = new ShareGoodsTextTemplate();
+			textTemplate.setCreateTime(new Date());
+			textTemplate.setSharePDDTextTemplate(template);
+			textTemplate.setUid(uid);
+			shareGoodsTextTemplateMapper.insertSelective(textTemplate);
+		}
+	}
+	
+	
+	
+	@Override
+	public void verifyRightTB(String template) throws ShareGoodsTextTemplateException {
+		String[] keys = new String[] { "{鍘熶环}", "{鍒稿悗浠穧","{娣樺彛浠" };
+		int keysCount = 0;
+		for (String key : keys)
+			if (template != null && template.contains(key))
+				keysCount++;
+		if (keysCount == 0)
+			throw new ShareGoodsTextTemplateException(1, "妯℃澘鏍煎紡鏈夎");
+	}
+	
+	@Override
+	public void verifyRightJD(String template) throws ShareGoodsTextTemplateException {
+		String[] keys = new String[] { "{鍘熶环}", "{鍒稿悗浠穧","{閾炬帴}" };
+		int keysCount = 0;
+		for (String key : keys)
+			if (template != null && template.contains(key))
+				keysCount++;
+		if (keysCount == 0)
+			throw new ShareGoodsTextTemplateException(1, "妯℃澘鏍煎紡鏈夎");
+	}
+	
+	
+	@Override
+	public void verifyRightPDD(String template) throws ShareGoodsTextTemplateException {
+		String[] keys = new String[] { "{鍘熶环}", "{鍒稿悗浠穧","{閾炬帴}" };
+		int keysCount = 0;
+		for (String key : keys)
+			if (template != null && template.contains(key))
+				keysCount++;
+		if (keysCount == 0)
+			throw new ShareGoodsTextTemplateException(1, "妯℃澘鏍煎紡鏈夎");
+	}
+	
+	
+	@Override
+	public String createContentTB(String template, TaoBaoGoodsBrief goods, String token, boolean coupon) {
+		String commentText = template.replace("{鍘熶环}", goods.getZkPrice().toString());
+		commentText = commentText.replace("{娣樺彛浠", TaoBaoUtil.filterTaoToken(token));
+		if (!coupon) {
+			commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘");
+			commentText = commentText.replace("銆愬埜鍚庝环銆憑鍒稿悗浠穧鍏�", "");
+		} else {
+			commentText = commentText.replace("{鍒稿悗浠穧",
+					TaoBaoUtil.getAfterUseCouplePrice(goods) + "");
+		}
+		return deleteBlankLine(commentText);
+	}
+	
+	@Override
+	public String createContentJD(String template, JDGoods goods, String jumpLink, boolean coupon) {
+		String commentText = template.replace("{鍘熶环}", goods.getPrice().toString());
+		commentText = commentText.replace("{閾炬帴}", jumpLink);
+		if (!coupon) {
+			commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘");
+			commentText = commentText.replace("銆愬埜鍚庝环銆憑鍒稿悗浠穧鍏�", "");
+		} else {
+			commentText = commentText.replace("{鍒稿悗浠穧",
+					BigDecimalUtil.getWithNoZera(JDUtil.getQuanPrice(goods)).toString());
+		}
+		return deleteBlankLine(commentText);
+	}
+	
+	@Override
+	public String createContentPDD(String template, PDDGoodsDetail goods, String jumpLink, boolean coupon) {
+		String commentText = template.replace("{鍘熶环}", MoneyBigDecimalUtil
+				.div(new BigDecimal(goods.getMinGroupPrice()), new BigDecimal(100)).setScale(2).toString());
+		commentText = commentText.replace("{閾炬帴}", jumpLink);
+		if (!coupon) {
+			commentText = commentText.replace("棰嗗埜鎶㈣喘", "鎶㈣喘");
+			commentText = commentText.replace("銆愬埜鍚庝环銆憑鍒稿悗浠穧鍏�", "");
+		} else {
+			commentText = commentText.replace("{鍒稿悗浠穧",
+					BigDecimalUtil.getWithNoZera(PinDuoDuoUtil.getQuanPrice(goods)).toString());
+		}
+		return deleteBlankLine(commentText);
+	}
+	
+	
+	
+	@Override
 	public void isCommonTemplateRight(String template) throws ShareGoodsTextTemplateException {
 		String[] keys = new String[] { "{鏍囬}", "{搴楅摵绫诲瀷}", "{鍟嗗搧鍘熶环}", "{鏈堥攢閲弣", "{鐭摼}", "{娣樺彛浠" };
 		int keysCount = 0;
@@ -298,6 +489,12 @@
 			throw new ShareGoodsTextTemplateException(1, "妯℃澘鏍煎紡鏈夎");
 	}
 
+	private String deleteBlankLine(String st){
+		return st.replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n").replace("\r\n\r\n", "\r\n");
+	}
+	
+	
+	
 	@Override
 	public String createContentByTemplate(String template, Long uid, TaoBaoGoodsBrief goods, String token,
 			String shortLink, boolean hasCoupon, Long tljId) {

--
Gitblit v1.8.0