com.dahuatech.icc.multiinone.accesscontrol.vo.AuthByPersonRequest Maven / Gradle / Ivy
The newest version!
package com.dahuatech.icc.multiinone.accesscontrol.vo;
import com.dahuatech.hutool.log.Log;
import com.dahuatech.hutool.log.LogFactory;
import com.dahuatech.icc.assesscontrol.model.v202103.authPerson.AuthPersonAddRequest;
import com.dahuatech.icc.brm.model.v202010.card.BrmCard;
import com.dahuatech.icc.brm.model.v202010.card.BrmCardBatchAddRequest;
import com.dahuatech.icc.brm.model.v202010.person.BrmPersonBatchAddRequest;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.multiinone.accesscontrol.domain.CardBatchAdd;
import com.dahuatech.icc.multiinone.accesscontrol.domain.PersonBatchAdd;
import com.dahuatech.icc.multiinone.vo.BaseRequest;
import com.dahuatech.icc.util.CollectionUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* program:java-sdk
*
* Author: 312013
* Date:2022-08-08 09:43
* Description: 按人授权,包含人员信息、卡片信息、权限信息
*/
public class AuthByPersonRequest extends BaseRequest {
private static final Log logger = LogFactory.get();
public PersonBatchAdd personInfos;
public CardBatchAdd cardInfos;
public AuthInfo authInfo;
public PersonBatchAdd getPersonInfos() {
return personInfos;
}
public void setPersonInfos(PersonBatchAdd personInfos) {
this.personInfos = personInfos;
}
public CardBatchAdd getCardInfos() {
return cardInfos;
}
public void setCardInfos(CardBatchAdd cardInfos) {
this.cardInfos = cardInfos;
}
public AuthInfo getAuthInfo() {
return authInfo;
}
public void setAuthInfo(AuthInfo authInfo) {
this.authInfo = authInfo;
}
public class AuthInfo {
private String timeQuantumId;
private List cardPrivilegeDetails;
private List cardNumbers;
public List getCardNumbers() {
return cardNumbers;
}
public void setCardNumbers(List cardNumbers) {
this.cardNumbers = cardNumbers;
}
public String getTimeQuantumId() {
return timeQuantumId;
}
public void setTimeQuantumId(String timeQuantumId) {
this.timeQuantumId = timeQuantumId;
}
public List getCardPrivilegeDetails() {
return cardPrivilegeDetails;
}
public void setCardPrivilegeDetails(List cardPrivilegeDetails) {
this.cardPrivilegeDetails = cardPrivilegeDetails;
}
public class CardPrivilegeDetail {
private Integer privilegeType;
private String resouceCode;
public Integer getPrivilegeType() {
return privilegeType;
}
public void setPrivilegeType(Integer privilegeType) {
this.privilegeType = privilegeType;
}
public String getResouceCode() {
return resouceCode;
}
public void setResouceCode(String resouceCode) {
this.resouceCode = resouceCode;
}
}
}
public void businessValid() {
}
public BrmPersonBatchAddRequest parseToBrmPersonBatchAddRequest(){
BrmPersonBatchAddRequest brmPersonBatchAddRequest = null;
try {
brmPersonBatchAddRequest = BrmPersonBatchAddRequest.builder().personList(this.getPersonInfos().getPersonList()).build();
brmPersonBatchAddRequest.setService(this.getPersonInfos().getService());
}catch (ClientException clientException){
clientException.printStackTrace();
}
return brmPersonBatchAddRequest;
}
public BrmCardBatchAddRequest parseToBrmCardBatchAddRequest(){
BrmCardBatchAddRequest brmPersonBatchAddRequest = null;
try {
List cardList = this.cardInfos.getCardList();
List personList = this.personInfos.getPersonList();
final Map cardNumberMap = new HashMap();
for(BrmCard brmCard : cardList){cardNumberMap.put(brmCard.getCardNumber(), brmCard);}
for(BrmPersonBatchAddRequest.PersonBatchData personBatchData : personList){
List personCardNumbers = personBatchData.getCardNumbers();
if(!CollectionUtil.isEmpty(personCardNumbers)){
for(String personCardNumber : personCardNumbers) {
if(cardNumberMap.containsKey(personCardNumber)){
//设置卡片对应的人员id
cardNumberMap.get(personCardNumber).setPersonId(personBatchData.getId());
}
}
}
}
List brmCards = new ArrayList();
for(BrmCard brmCard : cardNumberMap.values()) {
brmCards.add(brmCard);
}
this.cardInfos.setCardList(brmCards);
brmPersonBatchAddRequest = BrmCardBatchAddRequest.builder().cardList(this.cardInfos.getCardList()).build();
brmPersonBatchAddRequest.setFieldExt(this.getCardInfos().getFieldExt());
return brmPersonBatchAddRequest;
}catch (ClientException clientException){
clientException.printStackTrace();
}
return brmPersonBatchAddRequest;
}
public AuthPersonAddRequest parseToAuthPersonAddRequest() {
AuthPersonAddRequest authPersonAddRequest = null;
try {
List cardNumbers = this.getAuthInfo().getCardNumbers();
if(CollectionUtil.isEmpty(cardNumbers)){
cardNumbers = new ArrayList();
for(BrmCard brmCard: this.cardInfos.getCardList()){
cardNumbers.add(brmCard.getCardNumber());
}
}
Long timeId = null;
if(authInfo.getTimeQuantumId() != null){
timeId = Long.parseLong(authInfo.getTimeQuantumId());
}
authPersonAddRequest = AuthPersonAddRequest.builder().cardNumbers(cardNumbers).cardPrivilegeDetails(authInfo.getCardPrivilegeDetails()).timeQuantumId(timeId).build();
return authPersonAddRequest;
}catch (ClientException clientException){
clientException.printStackTrace();
}catch (NumberFormatException e){
logger.error("numberForMat exception: TimeQuantumId");
}
return authPersonAddRequest;
}
}