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

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;
import com.jeeplus.common.persistence.ActEntity;
import com.jeeplus.common.utils.Collections3;
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 com.jeeplus.modules.sys.entity.Workattachment;
import com.jeeplus.modules.workclientinfo.entity.WorkClientInfo;
import com.jeeplus.modules.workclientinfo.entity.WorkClientLinkman;
import com.jeeplus.modules.workcontractinfo.entity.WorkContractInfo;
import com.jeeplus.modules.workengineeringprice.entity.WorkEngineeringPrice;
import com.jeeplus.modules.workfullmanage.entity.WorkFullRecord;
import com.jeeplus.modules.workproject.entity.WorkProject;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 工程项目信息Entity
 * @author 杨帆
 * @version 2017-10-23
 */
public class WorkEngineeringProject extends ActEntity<WorkEngineeringProject> {
	
	private static final long serialVersionUID = 1L;
	private String reportNumber;		// 报告号
	private String isExt;		// 是否签署合同 0 是 1 不是
	private WorkContractInfo contractId;		// 合同外键id
	private String contractInfoName;
	private WorkProject projectId;		// 项目外键id
	private String businessType;		// 业务类型
	private Double preTrialAmount;		// 预送审金额
	private Date workStartDate;		// 工作开始时间
	private Date workEndDate;		// 工作结束时间
	private String emploperRequire;		// 业主要求
	private Area area;		// 工程所在地
	private Office office;		// 所属公司/部门
	private String hostOffice;		// 主办部门
	private String hostOfficeName;		// 主办部门
	private String jointlyOffice;		// 协办部门
	private String jointlyOfficeName;		// 协办部门
	private String hostOfficeMaster;		// 主办部门负责人
	private String hostOfficeMasterName;		// 主办部门负责人
	private String jointlyOfficeMaster;		// 协办部门负责人
	private String jointlyOfficeMasterName;		// 协办部门负责人
	private String hostOfficeMember;		// 主办部门项目组成员
	private String hostOfficeMemberNames;		// 主办部门项目组成员
	private String jointlyOfficeMember;		// 协办部门项目组成员
	private String jointlyOfficeMemberNames;		// 协办部门项目组成员
	private String status;		// 工程状态
	private String processInstanceId;		// 实例流程id
	private String name;
	private String ids;
	private String idNames;
	private String contractName;
	private String projectName;
	private WorkClientLinkman workClientLinkman;
	private WorkClientInfo workClientInfo;
	private String plan;
	private String processInstanceProofreadId;// 三级校审实例流程id
	private String proofreadStatus;// 三级校审状态
	private String proofreadMaster;// 三级校审负责人
	private String proofreadTotal;// 三级校审总工角色
	private String psort;//行业大分类
	private String ssort; //行业详细分类
	private String problem;
	private String reject;
	private String queryCon;
	private String masterId;
	private WorkFullRecord workFullRecord; //项目归档实体类
	private WorkEngineeringPrice workEngineeringPrice;
	private String totalProjectId;	//总项目编号
	private String totalProjectName;	//总项目名称
	private String isTotal;	//是否是总项目
	private String totalProjectIds; //父项目集合
	private String commonFlag;
	private String isTotalName;
	private Integer sort = 30;

	private List<User> hostOfficeMemberList = Lists.newArrayList();	//用户列表
	private List<User> jointlyOfficeMemberList = Lists.newArrayList();	//用户列表
	private List<WorkProjectPlan> workProjectPlans = Lists.newArrayList();	//用户列表
	private List<Workattachment> workAttachments = Lists.newArrayList();	//附件列表

	public List<WorkProjectPlan> getWorkProjectPlans() {
		return workProjectPlans;
	}

	public void setWorkProjectPlans(List<WorkProjectPlan> workProjectPlans) {
		this.workProjectPlans = workProjectPlans;
	}

	@ExcelField(title="项目成员", align=2, sort=13)
	public String getHostOfficeMemberIds() {
		return Collections3.extractToString(hostOfficeMemberList, "id", ",") ;
	}

	public void setHostOfficeMemberIds(String hostOfficeMember) {
		this.hostOfficeMemberList = Lists.newArrayList();
		for (String id : StringUtils.split(hostOfficeMember, ",")){
			this.hostOfficeMemberList.add(new User(id));
		}
	}

	@ExcelField(title="项目成员", align=2, sort=13)
	public String getJointlyOfficeMemberIds() {
		return Collections3.extractToString(jointlyOfficeMemberList, "id", ",") ;
	}

	public void setJointlyOfficeMemberIds(String jointlyOfficeMember) {
		this.jointlyOfficeMemberList = Lists.newArrayList();
		for (String id : StringUtils.split(jointlyOfficeMember, ",")){
			this.jointlyOfficeMemberList.add(new User(id));
		}
	}

	public String getPsort() {
		return psort;
	}

	public void setPsort(String psort) {
		this.psort = psort;
	}

	public String getSsort() {
		return ssort;
	}

	public void setSsort(String ssort) {
		this.ssort = ssort;
	}

	public String getPlan() {
		return plan;
	}

	public void setPlan(String plan) {
		this.plan = plan;
	}

	public String getHostOfficeMemberNames() {
		return hostOfficeMemberNames ;
	}


	public String getHostOfficeName() {
		return hostOfficeName;
	}

	public void setHostOfficeName(String hostOfficeName) {
		this.hostOfficeName = hostOfficeName;
	}

	public String getJointlyOfficeName() {
		return jointlyOfficeName;
	}

	public void setJointlyOfficeName(String jointlyOfficeName) {
		this.jointlyOfficeName = jointlyOfficeName;
	}

	public String getHostOfficeMasterName() {
		return hostOfficeMasterName;
	}

	public void setHostOfficeMasterName(String hostOfficeMasterName) {
		this.hostOfficeMasterName = hostOfficeMasterName;
	}

	public String getJointlyOfficeMasterName() {
		return jointlyOfficeMasterName;
	}

	public void setJointlyOfficeMasterName(String jointlyOfficeMasterName) {
		this.jointlyOfficeMasterName = jointlyOfficeMasterName;
	}

	public void setHostOfficeMemberNames(String hostOfficeMemberNames) {
		this.hostOfficeMemberNames = hostOfficeMemberNames;
	}

	public String getJointlyOfficeMemberNames() {
		return jointlyOfficeMemberNames;
	}

	public void setJointlyOfficeMemberNames(String jointlyOfficeMemberNames) {
		this.jointlyOfficeMemberNames = jointlyOfficeMemberNames;
	}

	public List<User> getHostOfficeMemberList() {
		return hostOfficeMemberList;
	}

	public void setHostOfficeMemberList(List<User> hostOfficeMemberList) {
		this.hostOfficeMemberList = hostOfficeMemberList;
	}

	public List<User> getJointlyOfficeMemberList() {
		return jointlyOfficeMemberList;
	}

	public void setJointlyOfficeMemberList(List<User> jointlyOfficeMemberList) {
		this.jointlyOfficeMemberList = jointlyOfficeMemberList;
	}

	public WorkClientInfo getWorkClientInfo() {
		return workClientInfo;
	}

	public void setWorkClientInfo(WorkClientInfo workClientInfo) {
		this.workClientInfo = workClientInfo;
	}

	// -- 临时属性 --//
	// 流程任务
	private Task task;
	private Map<String, Object> variables;
	// 运行中的流程实例
	private ProcessInstance processInstance;
	// 历史的流程实例
	private HistoricProcessInstance historicProcessInstance;
	// 流程定义
	private ProcessDefinition processDefinition;

	private String companyId;  //公司id

	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public Map<String, Object> getVariables() {
		return variables;
	}

	public void setVariables(Map<String, Object> variables) {
		this.variables = variables;
	}

	public ProcessInstance getProcessInstance() {
		return processInstance;
	}

	public void setProcessInstance(ProcessInstance processInstance) {
		this.processInstance = processInstance;
	}

	public HistoricProcessInstance getHistoricProcessInstance() {
		return historicProcessInstance;
	}

	public void setHistoricProcessInstance(HistoricProcessInstance historicProcessInstance) {
		this.historicProcessInstance = historicProcessInstance;
	}

	public ProcessDefinition getProcessDefinition() {
		return processDefinition;
	}

	public void setProcessDefinition(ProcessDefinition processDefinition) {
		this.processDefinition = processDefinition;
	}

	public String getIds() {
		List<String> idList = Lists.newArrayList();
		if (StringUtils.isNotBlank(ids)) {
			String ss = ids.trim().replace("　", ",").replace(" ", ",").replace("，", ",").replace("'", "");
			for (String s : ss.split(",")) {
				// if(s.matches("\\d*")) {
				idList.add("'" + s + "'");
				// }
			}
		}
		return StringUtils.join(idList, ",");
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public String getIdNames() {
		List<String> idList = Lists.newArrayList();
		if (StringUtils.isNotBlank(idNames)) {
			String ss = idNames.trim().replace("　", ",").replace(" ", ",").replace("，", ",").replace("'", "");
			for (String s : ss.split(",")) {
				// if(s.matches("\\d*")) {
				idList.add("'" + s + "'");
				// }
			}
		}
		return StringUtils.join(idList, ",");
	}

	public void setIdNames(String idNames) {
		this.idNames = idNames;
	}

	public String getName() {
		return name;
	}

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

	public String getContractName() {
		return contractName;
	}

	public void setContractName(String contractName) {
		this.contractName = contractName;
	}

	public String getProjectName() {
		return projectName;
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	public WorkEngineeringProject() {
		super();
	}

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

	@ExcelField(title="报告号", align=2, sort=1)
	public String getReportNumber() {
		return reportNumber;
	}

	public void setReportNumber(String reportNumber) {
		this.reportNumber = reportNumber;
	}
	
	@NotNull(message="合同外键id不能为空")
	@ExcelField(title="合同外键id", align=2, sort=8)
	public WorkContractInfo getContractId() {
		return contractId;
	}

	public void setContractId(WorkContractInfo contractId) {
		this.contractId = contractId;
	}

	public WorkClientLinkman getWorkClientLinkman() {
		return workClientLinkman;
	}

	public void setWorkClientLinkman(WorkClientLinkman workClientLinkman) {
		this.workClientLinkman = workClientLinkman;
	}

	@NotNull(message="项目外键id不能为空")
	@ExcelField(title="项目外键id", align=2, sort=9)
	public WorkProject getProjectId() {
		return projectId;
	}

	public void setProjectId(WorkProject projectId) {
		this.projectId = projectId;
	}
	
	@ExcelField(title="业务类型", mainDictType="business_type", align=2, sort=10)
	public String getBusinessType() {
		return businessType;
	}

	public void setBusinessType(String businessType) {
		this.businessType = businessType;
	}
	
	@ExcelField(title="预送审金额", align=2, sort=11)
	public Double getPreTrialAmount() {
		return preTrialAmount;
	}

	public void setPreTrialAmount(Double preTrialAmount) {
		this.preTrialAmount = preTrialAmount;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@NotNull(message="工作开始时间不能为空")
	@ExcelField(title="工作开始时间", align=2, sort=12)
	public Date getWorkStartDate() {
		return workStartDate;
	}

	public void setWorkStartDate(Date workStartDate) {
		this.workStartDate = workStartDate;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@NotNull(message="工作结束时间不能为空")
	@ExcelField(title="工作结束时间", align=2, sort=13)
	public Date getWorkEndDate() {
		return workEndDate;
	}

	public void setWorkEndDate(Date workEndDate) {
		this.workEndDate = workEndDate;
	}
	
	@ExcelField(title="业主要求", align=2, sort=14)
	public String getEmploperRequire() {
		return emploperRequire;
	}

	public void setEmploperRequire(String emploperRequire) {
		this.emploperRequire = emploperRequire;
	}
	
	@ExcelField(title="工程所在地", align=2, sort=15)
	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}
	
	@NotNull(message="所属公司/部门不能为空")
	@ExcelField(title="所属公司/部门", fieldType=Office.class, value="office.name", align=2, sort=16)
	public Office getOffice() {
		return office;
	}

	public void setOffice(Office office) {
		this.office = office;
	}
	
	@ExcelField(title="主办部门", align=2, sort=17)
	public String getHostOffice() {
		return hostOffice;
	}

	public void setHostOffice(String hostOffice) {
		this.hostOffice = hostOffice;
	}
	
	@ExcelField(title="协办部门", align=2, sort=18)
	public String getJointlyOffice() {
		return jointlyOffice;
	}

	public void setJointlyOffice(String jointlyOffice) {
		this.jointlyOffice = jointlyOffice;
	}
	
	@ExcelField(title="主办部门负责人", align=2, sort=19)
	public String getHostOfficeMaster() {
		return hostOfficeMaster;
	}

	public void setHostOfficeMaster(String hostOfficeMaster) {
		this.hostOfficeMaster = hostOfficeMaster;
	}
	
	@ExcelField(title="协办部门负责人", align=2, sort=20)
	public String getJointlyOfficeMaster() {
		return jointlyOfficeMaster;
	}

	public void setJointlyOfficeMaster(String jointlyOfficeMaster) {
		this.jointlyOfficeMaster = jointlyOfficeMaster;
	}
	
	@ExcelField(title="主办部门项目组成员", align=2, sort=21)
	public String getHostOfficeMember() {
		return hostOfficeMember;
	}

	public void setHostOfficeMember(String hostOfficeMember) {
		this.hostOfficeMember = hostOfficeMember;
	}
	
	@ExcelField(title="协办部门项目组成员", align=2, sort=22)
	public String getJointlyOfficeMember() {
		return jointlyOfficeMember;
	}

	public void setJointlyOfficeMember(String jointlyOfficeMember) {
		this.jointlyOfficeMember = jointlyOfficeMember;
	}
	
	@ExcelField(title="工程状态", dictType="engineering_type", align=2, sort=23)
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}
	
	@ExcelField(title="实例流程id", align=2, sort=24)
	public String getProcessInstanceId() {
		return processInstanceId;
	}

	public void setProcessInstanceId(String processInstanceId) {
		this.processInstanceId = processInstanceId;
	}

	public String getCompanyId() {
		return companyId;
	}

	public void setCompanyId(String companyId) {
		this.companyId = companyId;
	}

	public String getProcessInstanceProofreadId() {
		return processInstanceProofreadId;
	}

	public void setProcessInstanceProofreadId(String processInstanceProofreadId) {
		this.processInstanceProofreadId = processInstanceProofreadId;
	}

	public String getProofreadStatus() {
		return proofreadStatus;
	}

	public void setProofreadStatus(String proofreadStatus) {
		this.proofreadStatus = proofreadStatus;
	}

	public String getProofreadMaster() {
		return proofreadMaster;
	}

	public void setProofreadMaster(String proofreadMaster) {
		this.proofreadMaster = proofreadMaster;
	}

	public String getProofreadTotal() {
		return proofreadTotal;
	}

	public void setProofreadTotal(String proofreadTotal) {
		this.proofreadTotal = proofreadTotal;
	}

	public String getProblem() {
		return problem;
	}

	public void setProblem(String problem) {
		this.problem = problem;
	}

	public String getReject() {
		return reject;
	}

	public void setReject(String reject) {
		this.reject = reject;
	}

	public String getQueryCon() {
		return queryCon;
	}

	public void setQueryCon(String queryCon) {
		this.queryCon = queryCon;
	}

	public WorkFullRecord getWorkFullRecord() {
		return workFullRecord;
	}

	public void setWorkFullRecord(WorkFullRecord workFullRecord) {
		this.workFullRecord = workFullRecord;
	}

	public List<Workattachment> getWorkAttachments() {
		return workAttachments;
	}

	public void setWorkAttachments(List<Workattachment> workAttachments) {
		this.workAttachments = workAttachments;
	}

	public String getMasterId() {
		return masterId;
	}

	public void setMasterId(String masterId) {
		this.masterId = masterId;
	}

	public String getIsExt() {
		return isExt;
	}

	public void setIsExt(String isExt) {
		this.isExt = isExt;
	}

	public String getContractInfoName() {
		return contractInfoName;
	}

	public void setContractInfoName(String contractInfoName) {
		this.contractInfoName = contractInfoName;
	}

	public WorkEngineeringPrice getWorkEngineeringPrice() {
		return workEngineeringPrice;
	}

	public void setWorkEngineeringPrice(WorkEngineeringPrice workEngineeringPrice) {
		this.workEngineeringPrice = workEngineeringPrice;
	}

	public String getTotalProjectId() {
		return totalProjectId;
	}

	public void setTotalProjectId(String totalProjectId) {
		this.totalProjectId = totalProjectId;
	}

	public String getTotalProjectName() {
		return totalProjectName;
	}

	public void setTotalProjectName(String totalProjectName) {
		this.totalProjectName = totalProjectName;
	}

	public String getIsTotal() {
		return isTotal;
	}

	public void setIsTotal(String isTotal) {
		this.isTotal = isTotal;
	}

	public String getTotalProjectIds() {
		return totalProjectIds;
	}

	public void setTotalProjectIds(String totalProjectIds) {
		this.totalProjectIds = totalProjectIds;
	}

	public String getCommonFlag() {
		return commonFlag;
	}

	public void setCommonFlag(String commonFlag) {
		this.commonFlag = commonFlag;
	}

	public String getIsTotalName() {
		return isTotalName;
	}

	public void setIsTotalName(String isTotalName) {
		this.isTotalName = isTotalName;
	}

	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}
}