package org.jeecg.modules.tax.xxgx.kpzdgl.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecg.common.util.DateUtils;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description: 开票终端
 * @Author: jeecg-boot
 * @Date:   2023-08-19
 * @Version: V1.0
 */
@Data
@TableName("cs_xx_kpzd")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="cs_xx_kpzd对象", description="开票终端")
public class CsXxKpzd implements Serializable {
    private static final long serialVersionUID = 1L;

	/**编号*/
	@TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "编号")
    private String id;
	/**创建人*/
    @ApiModelProperty(value = "创建人")
    private String createBy;
	/**创建日期*/
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建日期")
    private Date createTime;
	/**更新人*/
    @ApiModelProperty(value = "更新人")
    private String updateBy;
	/**更新日期*/
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新日期")
    private Date updateTime;
	/**所属部门*/
    @ApiModelProperty(value = "所属部门")
    private String sysOrgCode;
	/**租户编号*/
	@Excel(name = "租户编号", width = 15)
    @ApiModelProperty(value = "租户编号")
    private Integer tenantId;
	/**企业主键*/
	@Excel(name = "企业主键", width = 15)
    @ApiModelProperty(value = "企业主键")
    private String companyId;
	/**终端代码*/
	@Excel(name = "终端代码", width = 15)
    @ApiModelProperty(value = "终端代码")
    private String zddm;
	/**终端名称*/
	@Excel(name = "终端名称", width = 15)
    @ApiModelProperty(value = "终端名称")
    private String zdmc;
	/**终端类型*/
	@Excel(name = "终端类型", width = 15, dicCode = "kpzdlx")
	@Dict(dicCode = "kpzdlx")
    @ApiModelProperty(value = "终端类型")
    private String zdlx;
	/**服务器（税控设备）*/
	@Excel(name = "服务器（税控设备）", width = 15)
    @ApiModelProperty(value = "服务器（税控设备）")
    private String fwqid;
	/**开票模式*/
	@Excel(name = "开票模式", width = 15, dicCode = "kpzdms")
	@Dict(dicCode = "kpzdms")
    @ApiModelProperty(value = "开票模式")
    private String kpms;
	/**特定业务*/
	@Excel(name = "特定业务", width = 15)
    @ApiModelProperty(value = "特定业务")
    private String tdyw;
	/**发票类型代码*/
	@Excel(name = "发票类型代码", width = 15)
    @ApiModelProperty(value = "发票类型代码")
    private String fplxdm;
	/**企业代码*/
	@Excel(name = "企业代码", width = 15)
    @ApiModelProperty(value = "企业代码")
    private String nsrdm;
	/**企业税号*/
	@Excel(name = "企业税号", width = 15)
    @ApiModelProperty(value = "企业税号")
    private String nsrsbh;
	/**企业名称*/
	@Excel(name = "企业名称", width = 15)
    @ApiModelProperty(value = "企业名称")
    private String nsrmc;
	/**销方银行*/
	@Excel(name = "销方银行", width = 15)
    @ApiModelProperty(value = "销方银行")
    private String xfyh;
	/**银行账号*/
	@Excel(name = "银行账号", width = 15)
    @ApiModelProperty(value = "银行账号")
    private String xfyhzh;
	/**地址*/
	@Excel(name = "地址", width = 15)
    @ApiModelProperty(value = "地址")
    private String xfdz;
	/**电话*/
	@Excel(name = "电话", width = 15)
    @ApiModelProperty(value = "电话")
    private String xfdh;
	/**开票人*/
	@Excel(name = "开票人", width = 15)
    @ApiModelProperty(value = "开票人")
    private String kpr;
	/**收款人*/
	@Excel(name = "收款人", width = 15)
    @ApiModelProperty(value = "收款人")
    private String skr;
	/**复核人*/
	@Excel(name = "复核人", width = 15)
    @ApiModelProperty(value = "复核人")
    private String fhr;
	/**电子税务局账号*/
	@Excel(name = "电子税务局账号", width = 15)
    @ApiModelProperty(value = "电子税务局账号")
    private String dzswjzh;
	/**电子税务登录密码*/
	@Excel(name = "电子税务登录密码", width = 15)
    @ApiModelProperty(value = "电子税务登录密码")
    private String dzswjmm;
	/**用户身份*/
    @Excel(name = "用户身份", width = 15)
    @ApiModelProperty(value = "用户身份")
    private String dljs;
	/**手机号*/
	@Excel(name = "手机号", width = 15)
    @ApiModelProperty(value = "手机号")
    private String sjh;
	/**身份证号*/
	@Excel(name = "身份证号", width = 15)
    @ApiModelProperty(value = "身份证号")
    private String sfzh;
	/**角色密码*/
	@Excel(name = "角色密码", width = 15)
    @ApiModelProperty(value = "角色密码")
    private String dljsmm;
	/**扫码频率*/
	@Excel(name = "扫码频率", width = 15)
    @ApiModelProperty(value = "扫码频率")
    private Integer smpl;
	/**最近扫码时间*/
	@Excel(name = "最近扫码时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "最近扫码时间")
    private Date zjsmsj;

    /**下次认证时间*/
    @Excel(name = "下次认证时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "下次认证时间")
    @TableField(exist = false)
    private Date xcrzsj;

    /**登录时间*/
    @Excel(name = "登录时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(shape = JsonFormat.Shape.STRING,timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "登录时间")
    private Date dlsj;
    /**默认终端：是、否*/
    @Excel(name = "默认终端：是、否", width = 15)
    @ApiModelProperty(value = "默认终端：是、否")
    private String ismrzd;

    @Excel(name = "认证结果：已认证；认证失效", width = 15)
    @ApiModelProperty(value = "认证结果：已认证；认证失效")
    private String rzjg;

    @Excel(name = "在线状态:在线；离线", width = 15)
    @ApiModelProperty(value = "在线状态:在线；离线")
    private String zxzt;


    @Excel(name = "电子税务局配置id", width = 15)
    @ApiModelProperty(value = "电子税务局配置id")
    private String dzswjpzid;
    @Excel(name = "主管税务机关代码", width = 15)
    @ApiModelProperty(value = "主管税务机关代码")
    @TableField(exist = false)
    private String zgswjgdm;
    @Excel(name = "主管水务机关名称", width = 15)
    @ApiModelProperty(value = "主管水务机关名称")
    @TableField(exist = false)
    private String zgswjgmc;

    //    /**所属税区*/
//    @Excel(name = "所属税区", width = 15)
//    @ApiModelProperty(value = "所属税区")
//    private String sssq;

//    /**是否开启调度：是、否*/
//    @Excel(name = "是否开启调度：是、否", width = 15)
//    @ApiModelProperty(value = "是否开启调度：是、否")
//    private String iskqdd;

    public Date getXcrzsj() {
        //计算下次扫码时间
        if(this.getZjsmsj() == null || this.getSmpl() == null || this.getSmpl() == 0){
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(this.getZjsmsj());
        calendar.add(Calendar.HOUR, this.getSmpl());
        return calendar.getTime();
    }

    public String getRzjg() {
        String rzjg = this.rzjg;
        if(StringUtils.isEmpty(rzjg)) {
            //计算下次扫码时间
            Date xcrzsj = getXcrzsj();
            Date currentTime = new Date();
            if (xcrzsj != null) {
                if (DateUtils.compare(xcrzsj, currentTime) > 0) {
                    rzjg = "认证失效";
                } else {
                    rzjg = "已认证";
                }
            }
        }
        return rzjg;
    }
}
