All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dahuatech.icc.multiinone.brm.vo.AddPersonCardRequest Maven / Gradle / Ivy

The newest version!
package com.dahuatech.icc.multiinone.brm.vo;

import com.dahuatech.icc.brm.enums.PaperTypeEnum;
import com.dahuatech.icc.brm.enums.PersonType;
import com.dahuatech.icc.brm.enums.SexEnum;
import com.dahuatech.icc.multiinone.brm.domain.CardInfo;
import com.dahuatech.icc.multiinone.brm.domain.PersonInfo;
import com.dahuatech.icc.multiinone.exception.BusinessException;
import com.dahuatech.icc.multiinone.utils.StringUtils;
import com.dahuatech.icc.multiinone.vo.BaseRequest;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 人员卡片新增请求
 */
public class AddPersonCardRequest extends BaseRequest {
    /**人员信息*/
    private PersonInfo personInfo;
    /**卡片信息*/
    private List cards;

    public void businessValid() {
        //人员校验
        //卡片校验
        personValid();
        cardValid();
    }

    public PersonInfo getPersonInfo() {
        return personInfo;
    }

    public void setPersonInfo(PersonInfo personInfo) {
        this.personInfo = personInfo;
    }

    public List getCards() {
        return cards;
    }

    public void setCards(List cards) {
        this.cards = cards;
    }

    private void personValid(){
        if(personInfo == null){
            throw new BusinessException("用户信息信息为空");
        }
        if(StringUtils.isEmpty(personInfo.getCode())){
            throw new BusinessException("人员编码为空");
        }
        if(personInfo.getPaperType() == null){
            throw new BusinessException("证件类型为空");
        }
        if(!PaperTypeEnum.isRightType(personInfo.getPaperType())){
            throw new BusinessException("证件类型非法");
        }
        if(StringUtils.isEmpty(personInfo.getPaperNumber())){
            throw new BusinessException("证件号码为空");
        }
        if(StringUtils.isEmpty(personInfo.getName())){
            throw new BusinessException("人员姓名为空");
        }
        if(StringUtils.isEmpty(personInfo.getPaperAddress())){
            throw new BusinessException("证件地址为空");
        }
        if(personInfo.getDepartmentId() == null){
            personInfo.setDepartmentId(1l);
        }
        if(personInfo.getPersonType() != null && !PersonType.validCode(personInfo.getPersonType())){
            throw new BusinessException("人员类型非法");
        }
        if(!StringUtils.isEmpty(personInfo.getPhone()) && !personInfo.getPhone().matches("^|[0-9]{11}$")){
            throw new BusinessException("电话非法");
        }
        if(!StringUtils.isEmpty(personInfo.getEmail()) && !personInfo.getEmail().matches("^([0-9A-Za-z_-]+@[0-9A-Za-z_-]+(\\\\.[0-9A-Za-z_-]+)+)?$")){
            throw new BusinessException("电子邮箱非法");
        }
        if(personInfo.getBirthday() != null){
            if(personInfo.getBirthday().after(new Date())){
                throw new BusinessException("生日非法");
            }
        }
        if(personInfo.getSex() != null && SexEnum.forValue(personInfo.getSex()) == null){
            throw new BusinessException("性别非法");
        }
    }

    private void cardValid(){
        if(cards == null || cards.size() == 0){
            return;
        }
        for(CardInfo cardInfo :cards){
            if(StringUtils.isEmpty(cardInfo.getCardNumber())){
                throw new BusinessException("卡号为空");
            }
            if(!cardInfo.getCardNumber().matches("^$|[A-Z0-9]{8,16}$")){
                throw new BusinessException("卡号非法");
            }
            if(StringUtils.isEmpty(cardInfo.getCategory())){
                throw new BusinessException("卡介质为空");
            }
            if(!cardInfo.getCategory().matches("0|1|2|3")){
                throw new BusinessException("卡介质非法");
            }
            if(StringUtils.isEmpty(cardInfo.getStartDate())){
                throw new BusinessException("卡片有效期-开始时间为空");
            }
            if(StringUtils.isEmpty(cardInfo.getEndDate())){
                throw new BusinessException("卡片有效期-结束时间为空");
            }
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            dateFormat.setLenient(false);
            try{
                dateFormat.parse(cardInfo.getStartDate());
            }catch (Exception e){
                throw new BusinessException("卡片有效期-开始时间格式非法");
            }
            try{
                dateFormat.parse(cardInfo.getEndDate());
            }catch (Exception e){
                throw new BusinessException("卡片有效期-结束时间格式非法");
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy