package com.tofly.ghrq_route.module.incident.domain;

import com.tofly.ghrq_route.common.util.date.DateUtils;

import java.util.HashMap;
import java.util.Map;

public class CarUploadBean {
    /**
     * onTime : null
     * lng : null
     * deptid : 1
     * avatar : /dyrqcar/carpic/1322095940139556866.png
     * offTime : null
     * carnum : 川A55555
     * lat : null
     * carid : 1
     * deptname : 总经理办公室
     */

    private String onTime;
    private Double lng;
    private int deptid;
    private String avatar;
    private String offTime;
    private String carnum;
    private Double lat;
    private int carid;
    private String deptname;

    public String getOnTime() {
        return onTime;
    }

    public void setOnTime(String onTime) {
        this.onTime = onTime;
    }

    public Double getLng() {
        return lng;
    }

    public void setLng(Double lng) {
        this.lng = lng;
    }

    public int getDeptid() {
        return deptid;
    }

    public void setDeptid(int deptid) {
        this.deptid = deptid;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getOffTime() {
        return offTime;
    }

    public void setOffTime(String offTime) {
        this.offTime = offTime;
    }

    public String getCarnum() {
        return carnum;
    }

    public void setCarnum(String carnum) {
        this.carnum = carnum;
    }

    public Double getLat() {
        return lat;
    }

    public void setLat(Double lat) {
        this.lat = lat;
    }

    public int getCarid() {
        return carid;
    }

    public void setCarid(int carid) {
        this.carid = carid;
    }

    public String getDeptname() {
        return deptname;
    }

    public void setDeptname(String deptname) {
        this.deptname = deptname;
    }

    public int get_sign_state() {
        int sign_state = 0;
        if (onTime != null && !onTime.isEmpty()) {
            sign_state = 1;
            if (offTime != null && !offTime.isEmpty()) {
                String now = DateUtils.getCurrentDate();
                long offset = DateUtils.getTimeOffset(offTime, now);
                if (offset / 1000 >= 10 * 60) {  //超过10分钟，表明已经离线
                    sign_state = 2;
                }
            }
            return sign_state;
        }

        return sign_state;
    }

    public HashMap<String, Object> getAttrsFromDevice(){
        HashMap<String, Object> attributes = new HashMap<>();
        attributes.put(DeviceUploadBean.USERID_KEY, getCarid());
        attributes.put(DeviceUploadBean.AVATAR, getAvatar());
        attributes.put(DeviceUploadBean.USERNAME, getCarnum());
        attributes.put(DeviceUploadBean.DEPID, getDeptid());
        attributes.put(DeviceUploadBean.DEPNAME, getDeptname());
        attributes.put(DeviceUploadBean.LAT, getLat());
        attributes.put(DeviceUploadBean.LNG, getLng());
        attributes.put(DeviceUploadBean.ON_TIME, getOnTime());
        attributes.put(DeviceUploadBean.OFF_TIME, getOffTime());
        return attributes;
    }

    public static CarUploadBean getCarFromAttrs(Map<String, Object> attributes){
        CarUploadBean carUploadBean = new CarUploadBean();
        if (attributes != null) {
            carUploadBean.setCarnum((String) attributes.get(DeviceUploadBean.USERNAME));
            carUploadBean.setCarid((int) attributes.get(DeviceUploadBean.USERID_KEY));
            carUploadBean.setAvatar((String) attributes.get(DeviceUploadBean.AVATAR));
            carUploadBean.setDeptid((int) attributes.get(DeviceUploadBean.DEPID));
            carUploadBean.setDeptname((String) attributes.get(DeviceUploadBean.DEPNAME));
            carUploadBean.setOffTime((String) attributes.get(DeviceUploadBean.OFF_TIME));
            carUploadBean.setOnTime((String) attributes.get(DeviceUploadBean.ON_TIME));
            carUploadBean.setLng((double) attributes.get(DeviceUploadBean.LNG));
            carUploadBean.setLat((double) attributes.get(DeviceUploadBean.LAT));
        }
        return carUploadBean;
    }
}
