Authored by tanling

Merge branch 'test6.9.3' of http://git.yoho.cn/ufo/yohoufo-fore into test6.9.3

package com.yohoufo.common.utils;
import com.google.common.collect.Sets;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by li.ma on 2019/5/7.
*/
public class DomainCheckUtil {
// 图片的域名只能是公司内部的域名
private static Set<String> YOHODOMAINLIST = Sets.newHashSet("yohobuy.com", "yoho.cn", "yhbimg.com", "yohoboys.com");
/**
* 是否存在非法的域名
* @param imageUrl
* @return true 存在
*/
public static boolean existInvalidDomain(String imageUrl) {
if (imageUrl.startsWith("//")) {
return compareDomain(imageUrl.substring(2, imageUrl.indexOf('/', 2)));
}
String propertyStr = imageUrl.replace('\\', '/');
Pattern p = Pattern.compile("[http:|https:]//(.+?)[/|'|\"|\\s|>]", Pattern.CASE_INSENSITIVE);
Matcher matcher = p.matcher(propertyStr);
while (matcher.find()) {
String domainStr = matcher.group(1); // 查询字符串中链接的域名
if (compareDomain(domainStr)) {
return true;
}
}
return false;
}
public static boolean compareDomain(String domain) {
boolean result = true;
for (String yohoDomainStr : YOHODOMAINLIST) {
if (domain.endsWith(yohoDomainStr)) { // 如果域名并不是YOHO相关的域名,则剔除
result = false;
}
}
return result;
}
public static void main(String[] args) {
//System.out.println(queryInvalidDomain("//img01.yohoboys.com/license/1554113944689/Screenshot_20190401_173857_com.yoho.jpg"));
System.out.println(existInvalidDomain("http://img01.yohoboys.com/license/1554113944689/Screenshot_20190401_173857_com.yoho.jpg"));
}
}
... ...
... ... @@ -160,7 +160,7 @@ public class BuyerOrderCancelService {
inBoxFacade.noticeSellerWhenBuyerCancelNoResponsibility(psog, orderCode);
}else {
inBoxFacade.buyerCancelBeforeSellerDeliver(buyerUid, orderCode,
penaltyAmount.toPlainString(), psog);
penaltyAmount.toPlainString(), psog,reSellAfterCancel);
}
//TODO 整个过程异步去执行(考虑退费依赖订单状态)
//(退费)退保证金给卖家
... ...
... ... @@ -1505,7 +1505,7 @@ public class InBoxFacade {
}
}
public void buyerCancelBeforeSellerDeliver(int buyerUid, long orderCode,String compesant, SellerOrderGoods sog) {
public void buyerCancelBeforeSellerDeliver(int buyerUid, long orderCode,String compesant, SellerOrderGoods sog,boolean autoReSellFlag) {
Integer sellerUid = sog.getUid();
String prdName = sog.getProductName();
String sizeName = sog.getSizeName();
... ... @@ -1522,6 +1522,9 @@ public class InBoxFacade {
Product product = productMapper.selectByPrimaryKey(sog.getProductId());
String productCode = product.getProductCode();
InboxBusinessTypeEnum ibtOfSeller = InboxBusinessTypeEnum.SALE_CLOSED_BY_BUYER_AFTER_PAID;
if(autoReSellFlag){
ibtOfSeller = InboxBusinessTypeEnum.SALE_CLOSED_AUTO_RESELL_BY_BUYER_AFTER_PAID;
}
String paramsOfSeller = buildParams(prdName, sizeName,productCode);
InboxReqVO reqOfSeller = buildInboxReqVO(sellerUid, paramsOfSeller, ibtOfSeller);
InBoxResponse respOfSeller = inBoxSDK.addInbox(reqOfSeller);
... ... @@ -1536,7 +1539,11 @@ public class InBoxFacade {
}
List<String> mobileList = Arrays.asList(phone);
String content= getReplacedContent(InboxBusinessTypeEnum.SMS_CANCELED_BY_BUYER_AFTER_PAID.getContent(),orderCode,prdName,sizeName,productCode);
InboxBusinessTypeEnum sms=InboxBusinessTypeEnum.SMS_CANCELED_BY_BUYER_AFTER_PAID;
if(autoReSellFlag){
sms=InboxBusinessTypeEnum.SMS_CANCELED_AUTO_RESELL_BY_BUYER_AFTER_PAID;
}
String content= getReplacedContent(sms.getContent(),orderCode,prdName,sizeName,productCode);
sendSmsService.smsSendByMobile(content,mobileList);
logger.info("record buyerCancelBeforeSellerDeliver inbox sms msg, sellerUid {}, orderCode {},prdName {} ,sizeName {} ,productCode {}",
sellerUid, orderCode, prdName,sizeName,productCode);
... ...
... ... @@ -5,8 +5,14 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.utils.DomainCheckUtil;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -36,6 +42,8 @@ public class SelfShelvesServiceImpl implements SelfShelvesService {
@Override
public int save(ProductSelfShelves pss, String price, String saleTime, List<String> imageList) {
checkImageDomain(imageList);
pss.setPrice(StringUtils.isEmpty(price) ? null : new BigDecimal(price));
pss.setSaleTime(StringUtils.isEmpty(saleTime) ? null : (int)convertDateToLong(saleTime));
pss.setCreateTime(DateUtil.getCurrentTimeSecond());
... ... @@ -53,10 +61,12 @@ public class SelfShelvesServiceImpl implements SelfShelvesService {
return num;
}
public static void main(String[] args){
String price = "123456.66";
BigDecimal bd=new BigDecimal(price);
System.out.println(bd);
private void checkImageDomain(List<String> imageList) {
imageList.stream().forEach(item -> {
if (DomainCheckUtil.existInvalidDomain(item)) {
throw new UfoServiceException(500, "系统异常");
}
});
}
private long convertDateToLong(String date) {
... ... @@ -72,5 +82,4 @@ public class SelfShelvesServiceImpl implements SelfShelvesService {
}
return dateDate.getTime() / 1000;
}
}
... ...