/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.workattendance.entity;

import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;

import com.google.common.collect.Lists;
import com.jeeplus.common.persistence.DataEntity;
import com.jeeplus.common.utils.Collections3;
import com.jeeplus.common.utils.IdGen;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import com.jeeplus.modules.sys.entity.Area;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.User;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 考勤规则Entity
 * @author 杨帆
 * @version 2018-09-05
 */
public class WorkAttendanceRule extends DataEntity<WorkAttendanceRule> {
	
	private static final long serialVersionUID = 1L;
	private String companyId;		// 公司
	private Office branchOffice;		// 分公司
	private String branchOfficeId;		// 分公司
	private String type;		// 考勤方式(签到，打卡，不考勤)
	@DateTimeFormat(pattern = "HH:mm:ss")
	private Date startTime;		// 上班时间
	@DateTimeFormat(pattern = "HH:mm:ss")
	private Date endTime;		// 下班时间
	private String workCount;		// 工作日计算加班/不计算加班
	private String workNeed;		// 工作日需要加班/需要算加班
	private String workType;		// 工作日处理方式 计算调休/发放工资
	@DateTimeFormat(pattern = "HH:mm:ss")
	private Date workStartTime;		// 上班时间
	@DateTimeFormat(pattern = "HH:mm:ss")
	private Date workEndTime;		// 下班时间
	private String notWorkCount;		// 非工作日计算加班/不计算加班
	private String notWorkNeed;		// 非工作日需要加班/需要算加班
	private String notWorkType;		// 非工作日处理方式 计算调休/发放工资
	private String leaveType;		// 调休请假类型
	private String leaveTypeName;		//调休请假类型
	private String name;		// 名称
	private String number;     //规则编号
	private List<WorkAttendancePlace> workAttendancePlaces;//考勤地点/wifi集合
	private List<User> userList;
	private List<Office> officeList;
	private List<WorkAttendanceRuleRecord> workAttendanceRuleRecordList = Lists.newArrayList();
	private List<WorkAttendanceRuleRecord> workAttendanceRuleRecordOfficeList = Lists.newArrayList();
	private Area area;
	private String view;
	
	public WorkAttendanceRule() {
		super();
	}

	public WorkAttendanceRule(String id){
		super(id);
	}

	@ExcelField(title="公司", align=2, sort=1)
	public String getCompanyId() {
		return companyId;
	}

	public void setCompanyId(String companyId) {
		this.companyId = companyId;
	}
	
	@ExcelField(title="分公司", align=2, sort=2)
	public Office getBranchOffice() {
		return branchOffice;
	}

	public void setBranchOffice(Office branchOffice) {
		this.branchOffice = branchOffice;
	}
	
	@ExcelField(title="考勤方式(签到，打卡，不考勤)", align=2, sort=3)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	@JsonFormat(pattern = "HH:mm:ss")
	@ExcelField(title="上班时间", align=2, sort=4)
	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	
	@JsonFormat(pattern = "HH:mm:ss")
	@ExcelField(title="下班时间", align=2, sort=5)
	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	
	@ExcelField(title="工作日计算加班/不计算加班", align=2, sort=6)
	public String getWorkCount() {
		return workCount;
	}

	public void setWorkCount(String workCount) {
		this.workCount = workCount;
	}
	
	@ExcelField(title="工作日需要加班/需要算加班", align=2, sort=7)
	public String getWorkNeed() {
		return workNeed;
	}

	public void setWorkNeed(String workNeed) {
		this.workNeed = workNeed;
	}
	
	@ExcelField(title="工作日处理方式 计算调休/发放工资", align=2, sort=8)
	public String getWorkType() {
		return workType;
	}

	public void setWorkType(String workType) {
		this.workType = workType;
	}
	
	@JsonFormat(pattern = "HH:mm:ss")
	@ExcelField(title="上班时间", align=2, sort=9)
	public Date getWorkStartTime() {
		return workStartTime;
	}

	public void setWorkStartTime(Date workStartTime) {
		this.workStartTime = workStartTime;
	}
	
	@JsonFormat(pattern = "HH:mm:ss")
	@ExcelField(title="下班时间", align=2, sort=10)
	public Date getWorkEndTime() {
		return workEndTime;
	}

	public void setWorkEndTime(Date workEndTime) {
		this.workEndTime = workEndTime;
	}
	
	@ExcelField(title="非工作日计算加班/不计算加班", align=2, sort=11)
	public String getNotWorkCount() {
		return notWorkCount;
	}

	public void setNotWorkCount(String notWorkCount) {
		this.notWorkCount = notWorkCount;
	}
	
	@ExcelField(title="非工作日需要加班/需要算加班", align=2, sort=12)
	public String getNotWorkNeed() {
		return notWorkNeed;
	}

	public void setNotWorkNeed(String notWorkNeed) {
		this.notWorkNeed = notWorkNeed;
	}
	
	@ExcelField(title="非工作日处理方式 计算调休/发放工资", align=2, sort=13)
	public String getNotWorkType() {
		return notWorkType;
	}

	public void setNotWorkType(String notWorkType) {
		this.notWorkType = notWorkType;
	}
	
	@ExcelField(title="名称", align=2, sort=20)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<WorkAttendancePlace> getWorkAttendancePlaces() {
		return workAttendancePlaces;
	}

	public void setWorkAttendancePlaces(List<WorkAttendancePlace> workAttendancePlaces) {
		this.workAttendancePlaces = workAttendancePlaces;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	/**
	 * 获取通知发送记录用户ID
	 * @return
	 */
	public String getworkAttendanceRuleRecordIds() {
		return Collections3.extractToString(workAttendanceRuleRecordList, "user.id", ",") ;
	}

	/**
	 * 设置通知发送记录用户ID
	 * @return
	 */
	public void setworkAttendanceRuleRecordIds(List<User> users) {
		this.workAttendanceRuleRecordList = Lists.newArrayList();
		if (users!=null && users.size()!=0) {
			for (User user : users) {
				if (user.getDelFlag().equals("0")) {
					WorkAttendanceRuleRecord entity = new WorkAttendanceRuleRecord();
					entity.setId(IdGen.uuid());
					entity.setWorkAttendanceRule(this);
					entity.setUser(user);
					this.workAttendanceRuleRecordList.add(entity);
				}
			}
		}
	}
	/**
	 * 设置通知发送记录用户ID
	 * @return
	 */
	public void setworkAttendanceRuleRecordOffices(List<Office> offices) {
		this.workAttendanceRuleRecordOfficeList = Lists.newArrayList();
		if (offices!=null && offices.size()!=0) {
			for (Office office : offices) {
				if (office.getDelFlag().equals("0")) {
					WorkAttendanceRuleRecord entity = new WorkAttendanceRuleRecord();
					entity.setId(IdGen.uuid());
					entity.setWorkAttendanceRule(this);
					entity.setOfficeId(office.getId());
					this.workAttendanceRuleRecordOfficeList.add(entity);
				}
			}
		}
	}

	/**
	 * 获取通知发送记录用户Name
	 * @return
	 */
	public String getworkAttendanceRuleRecordNames() {
		return Collections3.extractToString(workAttendanceRuleRecordList, "user.name", ",") ;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public List<Office> getOfficeList() {
		return officeList;
	}

	public void setOfficeList(List<Office> officeList) {
		this.officeList = officeList;
	}

	public List<WorkAttendanceRuleRecord> getWorkAttendanceRuleRecordList() {
		return workAttendanceRuleRecordList;
	}

	public void setWorkAttendanceRuleRecordOfficeList(List<WorkAttendanceRuleRecord> workAttendanceRuleRecordOfficeList) {
		this.workAttendanceRuleRecordOfficeList = workAttendanceRuleRecordOfficeList;
	}

	public void setWorkAttendanceRuleRecordList(List<WorkAttendanceRuleRecord> workAttendanceRuleRecordList) {
		this.workAttendanceRuleRecordList = workAttendanceRuleRecordList;
	}

	public List<WorkAttendanceRuleRecord> getWorkAttendanceRuleRecordOfficeList() {
		return workAttendanceRuleRecordOfficeList;
	}

    public Area getArea() {
        return area;
    }

    public void setArea(Area area) {
        this.area = area;
    }

	public String getBranchOfficeId() {
		return branchOfficeId;
	}

	public void setBranchOfficeId(String branchOfficeId) {
		this.branchOfficeId = branchOfficeId;
	}

	public String getView() {
		return view;
	}

	public void setView(String view) {
		this.view = view;
	}

	public String getLeaveType() {
		return leaveType;
	}

	public void setLeaveType(String leaveType) {
		this.leaveType = leaveType;
	}

	public String getLeaveTypeName() {
		return leaveTypeName;
	}

	public void setLeaveTypeName(String leaveTypeName) {
		this.leaveTypeName = leaveTypeName;
	}
}