package com.qmth.qrzk.supplypaper.model;

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

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.qmth.qrzk.repository.common.enumeration.PaperType;


/**
 * 供卷省份打印任务
 * @author zhengmin
 *
 */
@Entity
@Table(name="qr_print_prov_task")
public class PrintProvTask {

	@Id
	@GeneratedValue
	private Long id;
	@Column(name="user_id")
	private Integer userId;
	
	private String username;
	
	@Column(name="prov_code",length=2)
	private Integer provCode;
	
	@Column(name="prov_name",length=30)
	private String provName;
	
	@Column(name="batch_id")
	private Integer batchId;
	
	@Column(name="scan_user_id")
	private Integer scanUserId;
	
	@Column(name="scan_user_name")
	private String scanUserName;
	
	@Transient
	private boolean isAllComlete;
	
	@Transient
	private int progress;
	
	@Column(name="course_count")
	private int courseCount;
	
	@Enumerated(EnumType.STRING)
	@Column(name="paper_type")
	private PaperType paperType;
	
	@Transient
	private String paperTypeLabel;
	
	@Transient
	private int paperCount;//试卷打印份数
	@Transient
	private boolean isSelected;
	
	@OneToMany(cascade=CascadeType.ALL)
	@JoinColumn(name="task_id")
	private List<PrintProvTaskItem> taskItems = new ArrayList<PrintProvTaskItem>();
	
	@Transient
	private String printSortNo;//客户端排序
	
	public String getPrintSortNo() {
		return printSortNo;
	}

	public void setPrintSortNo(String printSortNo) {
		this.printSortNo = printSortNo;
	}

	public Long getId() {
		return id;
	}

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

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Integer getProvCode() {
		return provCode;
	}

	public void setProvCode(Integer provCode) {
		this.provCode = provCode;
	}

	public String getProvName() {
		return provName;
	}

	public void setProvName(String provName) {
		this.provName = provName;
	}

	public List<PrintProvTaskItem> getTaskItems() {
		return taskItems;
	}

	public void setTaskItems(List<PrintProvTaskItem> taskItems) {
		this.taskItems = taskItems;
	}

	public Integer getBatchId() {
		return batchId;
	}

	public void setBatchId(Integer batchId) {
		this.batchId = batchId;
	}

	public boolean isAllComlete() {
		isAllComlete = true;
		for(PrintProvTaskItem item : this.taskItems){
			if(!item.isComplete()){
				isAllComlete = false;
			}
		}
		return isAllComlete;
	}

	public void setAllComlete(boolean isAllComlete) {
		this.isAllComlete = isAllComlete;
	}

	
	
	public int getProgress() {
		/**
		int c = 0;
		for(PrintProvTaskItem item : this.taskItems){
			if(item.isComplete()){
				c++;
			}
		}
		progress = c*100/this.courseCount;
		**/
		return progress;
	}

	public void setProgress(int progress) {
		this.progress = progress;
	}

	public int getCourseCount() {
		return courseCount;
	}

	public void setCourseCount(int courseCount) {
		this.courseCount = courseCount;
	}

	public void addTaskItem(PrintProvTaskItem item){
		this.taskItems.add(item);
	}

	public int getPaperCount() {
		int sum = 0;
		for(PrintProvTaskItem item : this.getTaskItems()){
			sum = sum + item.getBlankCount()+item.getAcidCount();
		}
		return sum;
	}

	public void setPaperCount(int paperCount) {
		this.paperCount = paperCount;
	}

	public boolean isSelected() {
		return isSelected;
	}

	public void setSelected(boolean isSelected) {
		this.isSelected = isSelected;
	}

	public PaperType getPaperType() {
		return paperType;
	}

	public void setPaperType(PaperType paperType) {
		this.paperType = paperType;
	}

	public String getPaperTypeLabel() {
		return paperType != null?paperType.getValue():null;
	}

	public void setPaperTypeLabel(String paperTypeLabel) {
		this.paperTypeLabel = paperTypeLabel;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public Integer getScanUserId() {
		return scanUserId;
	}

	public void setScanUserId(Integer scanUserId) {
		this.scanUserId = scanUserId;
	}

	public String getScanUserName() {
		return scanUserName;
	}

	public void setScanUserName(String scanUserName) {
		this.scanUserName = scanUserName;
	}
	
}
