Authored by qinchao

入驻状态接口,增加新的状态值

package com.yohoufo.order.service.impl;
import com.yoho.core.cache.LocalCache;
import com.yoho.core.config.ConfigReader;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.enums.StoredSellerStatusEnum;
... ... @@ -26,11 +28,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@Service
public class StoreSellerServiceImpl implements IStoredSellerService {
... ... @@ -61,6 +65,29 @@ public class StoreSellerServiceImpl implements IStoredSellerService {
@Autowired
private MerchantOrderPaymentService merchantOrderPaymentService;
@Autowired
private ConfigReader configReader;
//缓存
private LocalCache localCache_switch = new LocalCache();
private static final String SWITCH_CACHE_KEY = "popUploadPhotoSwitchCacheKey";
@PostConstruct
private void init() {
localCache_switch.init(SWITCH_CACHE_KEY, 2, TimeUnit.MINUTES, (String s, Object o) -> {
logger.info("StoreSellerServiceImpl init popUploadPhotoSwitchCacheKey s = {}, o = {}", s, o);
return configReader.getBoolean("ufo.order.popUploadPhotoSwitch",Boolean.TRUE);
});
}
private boolean getPopUploadPhotoSwitch(){
Object value=localCache_switch.get(SWITCH_CACHE_KEY);
if(null == value) {
return Boolean.TRUE;
}
return (Boolean) value;
}
/**
* 批量获取商户的入驻信息
... ... @@ -106,6 +133,11 @@ public class StoreSellerServiceImpl implements IStoredSellerService {
isZhiMaCert = true;
}
Boolean isZhiMaCertWithPhoto = false ;
if(zhiMaCert!=null&&1==zhiMaCert.getValidPhoto()){
isZhiMaCertWithPhoto=true;
}
//storedBefore 是否曾经入驻过 true or false ,入驻商户肯定入驻过,不是入驻商户,则判断是否有退驻信息
Boolean storedBefore = false;
... ... @@ -126,6 +158,9 @@ public class StoreSellerServiceImpl implements IStoredSellerService {
EntrySellerType entrySellerType = sellerService.getEntrySellerType(uid);
SellerResp sellerResp = new SellerResp();
sellerResp.setZhiMaCert(isZhiMaCert);
sellerResp.setZhiMaCertWithPhoto(isZhiMaCertWithPhoto);//新的芝麻认证状态(带身份证图片)
sellerResp.setPopUploadPhotoSwitch(getPopUploadPhotoSwitch());
sellerResp.setPhotoCheckExceedLimit(isPhotoCheckExceedLimit(uid));
sellerResp.setStoredBefore(storedBefore);
if (storedBefore) {
sellerResp.setOverMaxJoinTimesTip("您已退出入驻,没有入驻资格!");
... ... @@ -265,4 +300,14 @@ public class StoreSellerServiceImpl implements IStoredSellerService {
return null;
}
private boolean isPhotoCheckExceedLimit(int targetUid) {
ApiResponse<Boolean> resp = ufoServiceCaller.call("ufo.user.photoCheckExceedLimit", ApiResponse.class, targetUid);
if (resp != null&&resp.getCode()==200) {
if (resp.getData() != null) {
return (Boolean)resp.getData();
}
}
return false;
}
}
... ...
... ... @@ -124,6 +124,19 @@ public class RealNameAuthorizeController {
return new ApiResponse(zhiMaCertInfo);
}
@RequestMapping(params = "method=ufo.user.photoCheckExceedLimit")
public ApiResponse photoCheckExceedLimit(@RequestParam("uid") Integer uid) throws GatewayException {
logger.info("enter realNameAuthorize.photoCheckExceedLimit param uid is {}", uid);
//(1) 优先校验请求的参数
if (uid == null || uid <=0 ){
throw new GatewayException(400, "参数错误,uid不存在!");
}
boolean b =realNameAuthorizeService.isPhotoCheckExceedLimit(uid);
return new ApiResponse(b);
}
/**
* 6.9.1版本 ,上传身份证图片并校验
* 由于调用百度云ocr验证接口,需求file格式
... ...
... ... @@ -27,6 +27,9 @@ public interface IRealNameAuthorizeService {
ZhiMaCert getValidZhiMaCert(int uid);
boolean isPhotoCheckExceedLimit(Integer uid);
List<String> zhiMaCertUploadPhotoAndCheck(MultipartFile[] multipartFile, String bucket, Integer limitType, RealNameAuthorizeReqVO reqVO) throws Exception;
AuthorizeResultRespVO zhiMaCertWithPhotoInit(RealNameAuthorizeReqVO reqVO);
... ...
... ... @@ -11,6 +11,8 @@ import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.alipay.api.response.AlipayUserInfoShareResponse;
import com.alipay.api.response.ZhimaCustomerCertificationQueryResponse;
import com.google.common.collect.Lists;
import com.yoho.core.cache.LocalCache;
import com.yoho.core.config.ConfigReader;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.reviewed.request.ImageBO;
... ... @@ -42,6 +44,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
... ... @@ -54,6 +57,7 @@ import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
... ... @@ -82,8 +86,8 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
@Value("${zhimacert.switch:true}")
private boolean zhiMaCertSwitch;
// 需要放到zk上
private Integer maxPhotoCheckCount = 10;
@Autowired
private ConfigReader configReader;
//@Value("${file.saveDir}")
private String saveDir="D:/pic";
... ... @@ -93,6 +97,26 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
//缓存
private LocalCache localCache_switch = new LocalCache();
private static final String CACHE_KEY = "photoCheckExceedLimitCacheKey";
@PostConstruct
private void init() {
localCache_switch.init(CACHE_KEY, 5, TimeUnit.MINUTES, (String s, Object o) -> {
logger.info("realNameAuthorizeServiceImpl init photoCheckExceedLimitCacheKey s = {}, o = {}", s, o);
return configReader.getInt("ufo.user.photoCheckLimit",10);
});
}
private int getPhotoCheckLimit(){
Object value=localCache_switch.get(CACHE_KEY);
if(null == value) {
return 10;
}
return (Integer) value;
}
public UserAuthorizeInfo getValidAuthorizeInfo(int uid){
logger.info("RealNameAuthorizeServiceImpl getValidAuthorizeInfo uid is {} ",uid);
// 从redis缓存中获取
... ... @@ -353,15 +377,25 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
39 *
40 * @return返回字符串格式 yyyy-MM-dd HH:mm:ss
41 */
public static String getStringDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
String dateString = formatter.format(currentTime);
return dateString;
public static String getStringDate(String fmt) {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(fmt);
String dateString = formatter.format(currentTime);
return dateString;
}
@Override
public boolean isPhotoCheckExceedLimit(Integer uid){
return isPhotoCheckExceedLimit(getStringDate("yyyyMMdd") ,uid);
}
public static void main(String[] args) {
System.out.println(getStringDate());
private boolean isPhotoCheckExceedLimit(String dayStr ,Integer uid){
Long count = cacheService.getPhotoCheckCount(dayStr,uid);
logger.info("zhiMaCertUploadPhotoAndCheck getPhotoCheckCount count {},uid {} ",count,uid);
if(count!=null&&count>=getPhotoCheckLimit()){
return true;
}
return false;
}
... ... @@ -374,12 +408,8 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
}
//每天:记录一个累加的次数 ,超过一定的数量不允许继续调
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String dayStr = formatter.format(currentTime);
Long count = cacheService.getPhotoCheckCount(dayStr,reqVO.getUid());
logger.info("zhiMaCertUploadPhotoAndCheck getPhotoCheckCount count {},reqVO {} ",count,reqVO);
if(count!=null&&count>=maxPhotoCheckCount){
String dayStr = getStringDate("yyyyMMdd");
if(isPhotoCheckExceedLimit(dayStr,reqVO.getUid())){
throw new GatewayException(400, "超过当日最大调用次数!");
}
... ... @@ -605,7 +635,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
}
//7+14+
String transactionId="ufoCert"+getStringDate()+zhiMaCert.getId();
String transactionId="ufoCert"+getStringDate("yyyyMMddHHmmss")+zhiMaCert.getId();
String bizNo=ZhiMaCallUtil.zhiMaCertInit(transactionId,reqVO.getCertName(),reqVO.getCertNo());
... ...