package com.casic.PgInterface.patroler.dto;

import com.casic.PgInterface.patroler.domain.PgInPgPerson;
import com.casic.PgInterface.patroler.domain.PgInPgStatus;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by yxw on 2018/4/2.
 */
public class PgInPgInfoDto{

    private Long personId;
    private String userName;//入廊人员
    private String phoneNumber;//联系方式
    private String userCode;//人员编号
    private String personType;//人员类别
    private String unit;
    private String isInPg;//是否在廊内
    private String lastInTime;//最后入廊时间
    private String inTime;//入廊时间
    private String outTime;//出廊时间
    private String inPgNum;//入廊次数
    private int timeout;//超时标记

    public Long getPersonId() {
        return personId;
    }

    public void setPersonId(Long personId) {
        this.personId = personId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserCode() {
        return userCode;
    }

    public void setUserCode(String userCode) {
        this.userCode = userCode;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getPersonType() {
        return personType;
    }

    public void setPersonType(String personType) {
        this.personType = personType;
    }

    public String getIsInPg() {
        return isInPg;
    }

    public void setIsInPg(String isInPg) {
        this.isInPg = isInPg;
    }

    public String getLastInTime() {
        return lastInTime;
    }

    public void setLastInTime(String lastInTime) {
        this.lastInTime = lastInTime;
    }

    public String getInPgNum() {
        return inPgNum;
    }

    public void setInPgNum(String inPgNum) {
        this.inPgNum = inPgNum;
    }

    public String getInTime() {
        return inTime;
    }

    public void setInTime(String inTime) {
        this.inTime = inTime;
    }

    public String getOutTime() {
        return outTime;
    }

    public void setOutTime(String outTime) {
        this.outTime = outTime;
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public PgInPgInfoDto(PgInPgPerson pgInPgPerson, PgInPgStatus pgInPgStatus, int inPgNum) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        this.setPersonId(pgInPgPerson.getId());
        this.setUserName(pgInPgPerson.getUserName());
        this.setUserCode(pgInPgPerson.getUserCode());
        this.setPhoneNumber(pgInPgPerson.getPhoneNumber());
        this.setIsInPg(String.valueOf(pgInPgPerson.getIsInPg()));
        this.setPersonType(pgInPgPerson.getPersonType());
        this.setUnit(pgInPgPerson.getUnit());
        this.setTimeout(0);
        if (pgInPgStatus!=null&&pgInPgStatus.getInTime() != null) {
            this.setLastInTime(sdf.format(pgInPgStatus.getInTime()));

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(pgInPgStatus.getInTime());
            calendar.add(Calendar.HOUR,1);
            Date expectDate = calendar.getTime();
            Date now = new Date();
            this.setTimeout( 0 > expectDate.compareTo(now) && pgInPgStatus.getOutTime() ==null ? 1:0);
        }
        else
            this.setLastInTime("");
        this.setInPgNum(String.valueOf(inPgNum));
    }

    public PgInPgInfoDto(PgInPgStatus pgInPgStatus) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        this.setUserName(pgInPgStatus.getPgInPgPersonId().getUserName());
        this.setPhoneNumber(pgInPgStatus.getPgInPgPersonId().getPhoneNumber());
        this.setPersonType(pgInPgStatus.getPgInPgPersonId().getPersonType());
        this.setUnit(pgInPgStatus.getPgInPgPersonId().getUnit());
        this.setInTime(sdf.format(pgInPgStatus.getInTime()));
        this.setTimeout(0);
        if (pgInPgStatus.getOutTime() != null)
            this.setOutTime(sdf.format(pgInPgStatus.getOutTime()));
        else {
            this.setOutTime("");

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(pgInPgStatus.getInTime());
            calendar.add(Calendar.HOUR,1);
            Date expectDate = calendar.getTime();
            Date now = new Date();
            this.setTimeout( 0 > expectDate.compareTo(now) && pgInPgStatus.getOutTime() ==null ? 1:0);
        }
    }

    public PgInPgInfoDto()
    {

    }
}
