package com.engine.kq.biz;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import weaver.common.DateUtil;
import weaver.common.StringUtil;
import weaver.general.Util;

public class KQScheduleSign extends BaseBean {
  private int id;
  private int userid;
  private int usertype = 1;
  private int signtype;
  private String signdate;
  private String signtime;
  private String clientaddress;
  private String signfrom;
  private String longitude;
  private String latitude;
  private String addr;
  private int isincom = 1;
  private int isimport = 1;
  private String uuid;
  private String suuid;
  private String importsql;

  public void save() throws Exception {
    String sql = "";
    RecordSet rs = new RecordSet();

    boolean needImport = true;
    //已经导入的数据不再重复导入
    sql = " select count(*) from HrmScheduleSign where userid =" + this.userid + " and signdate='" + this.signdate + "' and signtime='" + this.signtime + "'";
    rs.execute(sql);
    if (rs.next()) {
      if (rs.getInt(1) > 0) needImport = false;
    }
    if (needImport) {
      sql = " insert into HrmScheduleSign (userid, usertype, signtype, signdate, signtime, clientaddress, isincom, isimport, signfrom, longitude, latitude, addr) "
              + " values(?,?,?,?,?,?,?,?,?,?,?,?)";
      List<Object> params = new ArrayList<>();
      params.add(this.userid);
      params.add(this.usertype);
      params.add(this.signtype);
      params.add(this.signdate);
      params.add(this.signtime);
      params.add(Util.null2String(this.clientaddress));
      params.add(this.isincom);
      params.add(this.isimport);
      params.add(Util.null2String(this.signfrom));
      params.add(Util.null2String(this.longitude));
      params.add(Util.null2String(this.latitude));
      params.add(Util.null2String(this.addr));
      rs.executeUpdate(sql,params);
    }
  }

  public static void delete(String date_from, String date_to) throws Exception {
    String sql = "";
    RecordSet rs = new RecordSet();
    sql = " delete HrmScheduleSign where isimport=1 and signdate >='" + date_from + "' and signdate < '" + date_to + "'";
    rs.execute(sql);
  }

  public static void delete(String date_from, String date_to, int userId) throws Exception {
    String sql = "";
    RecordSet rs = new RecordSet();
    sql = " delete HrmScheduleSign where isimport=1 and signdate >='" + date_from + "' and signdate <= '" + date_to + "' and userId=" + userId;
    rs.execute(sql);
  }

  public void deleteByUser() throws Exception {
    String sql = "";
    RecordSet rs = new RecordSet();
    sql = " delete HrmScheduleSign where signdate ='" + signdate + "' and signtype = '" + signtype + "' and userId=" + userid;
    rs.execute(sql);
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public int getUserid() {
    return userid;
  }

  public void setUserid(int userid) {
    this.userid = userid;
  }

  public int getUsertype() {
    return usertype;
  }

  public void setUsertype(int usertype) {
    this.usertype = usertype;
  }

  public int getSigntype() {
    return signtype;
  }

  public void setSigntype(int signtype) {
    this.signtype = signtype;
  }

  public String getSigndate() {
    return signdate;
  }

  public void setSigndate(String signdate) {
    this.signdate = signdate;
  }

  public String getSigntime() {
    return signtime;
  }

  public void setSigntime(String signtime) {
    this.signtime = signtime;
  }

  public String getClientaddress() {
    return clientaddress;
  }

  public void setClientaddress(String clientaddress) {
    this.clientaddress = clientaddress;
  }

  public int getIsincom() {
    return isincom;
  }

  public void setIsincom(int isincom) {
    this.isincom = isincom;
  }

  public String getSignfrom() {
    return signfrom;
  }

  public void setSignfrom(String signfrom) {
    this.signfrom = signfrom;
  }

  public String getLongitude() {
    return longitude;
  }

  public void setLongitude(String longitude) {
    this.longitude = longitude;
  }

  public String getLatitude() {
    return latitude;
  }

  public void setLatitude(String latitude) {
    this.latitude = latitude;
  }

  public String getAddr() {
    return addr;
  }

  public void setAddr(String addr) {
    this.addr = addr;
  }

  public int getIsimport() {
    return isimport;
  }

  public void setIsimport(int isimport) {
    this.isimport = isimport;
  }

  public String getUuid() {
    return uuid;
  }

  public void setUuid(String uuid) {
    this.uuid = uuid;
  }

  public String getSuuid() {
    return suuid;
  }

  public void setSuuid(String suuid) {
    this.suuid = suuid;
  }

  public String getImportsql() {
    return importsql;
  }

  public void setImportsql(String importsql) {
    this.importsql = importsql;
  }
}
