com.dahuatech.icc.multiinone.accesscontrol.AccessBaseAuthSDK Maven / Gradle / Ivy
The newest version!
package com.dahuatech.icc.multiinone.accesscontrol;
import com.dahuatech.hutool.log.Log;
import com.dahuatech.hutool.log.LogFactory;
import com.dahuatech.icc.multiinone.brm.QueryPersonDetailSDK;
import com.dahuatech.icc.multiinone.brm.domain.CardInfo;
import com.dahuatech.icc.multiinone.brm.enums.QueryPersonTypeEnums;
import com.dahuatech.icc.multiinone.brm.vo.QueryPersonDetailRequest;
import com.dahuatech.icc.multiinone.brm.vo.QueryPersonDetailResponse;
import com.dahuatech.icc.multiinone.exception.BusinessException;
import com.dahuatech.icc.multiinone.utils.CollectionsUtils;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigBaseInfo;
public class AccessBaseAuthSDK {
protected final Log logger = LogFactory.get();
private QueryPersonDetailSDK queryPersonDetailSDK = new QueryPersonDetailSDK();
protected CardInfo getMainCard(OauthConfigBaseInfo oauthConfigBaseInfo,Long personId, String personCode){
QueryPersonDetailRequest queryPersonDetailRequest = new QueryPersonDetailRequest();
queryPersonDetailRequest.setOauthConfigBaseInfo(oauthConfigBaseInfo);
if(personId != null){
queryPersonDetailRequest.setPersonId(personId);
queryPersonDetailRequest.setQueryPersonType(QueryPersonTypeEnums.QueryById.type);
}else{
queryPersonDetailRequest.setCode(personCode);
queryPersonDetailRequest.setQueryPersonType(QueryPersonTypeEnums.QueryByCode.type);
}
QueryPersonDetailResponse queryPersonDetailResponse = queryPersonDetailSDK.queryDetail(queryPersonDetailRequest);
if(CollectionsUtils.isEmpty(queryPersonDetailResponse.getCards())){
throw new BusinessException("The person provided does not have an card.");
}
for(CardInfo cardInfo : queryPersonDetailResponse.getCards()){
if("1".equals(cardInfo.getIsMainCard())){
return cardInfo;
}
}
throw new BusinessException("The person provided does not have main card info.");
}
}