package com.hotent.uc.params.org;

import com.hotent.base.annotation.ExcelColumn;
import com.hotent.base.util.AppUtil;
import com.hotent.base.util.BeanUtils;
import com.hotent.uc.manager.OrgManager;
import com.hotent.uc.model.Org;
import com.hotent.uc.util.OperateLogUtil;
import com.hotent.uc.util.UpdateCompare;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 
 * @author liangqf
 *<pre>组织视图</pre>
 */
@ApiModel
public class OrgVo implements UpdateCompare {
	
	@ApiModelProperty(name="name",notes="组织名称",required=true)
	@ExcelColumn(value = "name", col = 0)
	private String name;

	@ApiModelProperty(name="id",notes="id")
	private String id;
	
	@ApiModelProperty(name="code",notes="组织代码",required=true)
	@ExcelColumn(value = "code", col = 1)
	private String code;
	
	@ApiModelProperty(name="parentId",notes="父组织id",example="0")
	private String parentId;
	
	@ApiModelProperty(name="grade",notes="级别")
	private String grade;
	
	@ApiModelProperty(name="demId",notes="维度id",required=true)
	private String demId;
	
	@ApiModelProperty(name="orderNo",notes="排序号")
	private Long orderNo;

    @ApiModelProperty(name="limitNum",notes="组织限编用户数量(0:不受限制)")
    protected Integer limitNum=0;

    @ApiModelProperty(name="nowNum",notes="组织现编用户数量")
    protected Integer nowNum;

    @ApiModelProperty(name="exceedLimitNum",notes="是否允许超过限编(0:允许；1:不允许)")
    protected Integer exceedLimitNum=0;

	@ApiModelProperty(name="orgType", notes="组织类型(0:组织 1:部门 2:关联组织 3:虚拟组织)")
	protected Integer orgType=0;

	@ApiModelProperty(name="joinExtSystemType",notes="集成的外部系统（0=无，1=钉钉2=企业微信）",required=true)
	private String joinExtSystemType;

	@ApiModelProperty(name="joinExtSystemSyndir",notes="同步方向0=向第三方系统同步 ，1=第三方系统向中台同步",required=false)
	private String joinExtSystemSyndir;


	@ApiModelProperty(name="dataScope",notes="人员（数据）级别0：省，1：市，2：区（县）")
	private Integer dataScope;

	@ApiModelProperty(value = "所属省")
	private String provinceCode;

	@ApiModelProperty(value = "所属市")
	private String cityCode;

	@ApiModelProperty(value = "所属区、县")
	private String countyCode;

	@ApiModelProperty(value = "法人代表")
	private String corporateRepresentative;

	public String getCorporateRepresentative() {
		return corporateRepresentative;
	}

	public void setCorporateRepresentative(String corporateRepresentative) {
		this.corporateRepresentative = corporateRepresentative;
	}

	public String getJoinExtSystemType() {
		return joinExtSystemType;
	}

	public void setJoinExtSystemType(String joinExtSystemType) {
		this.joinExtSystemType = joinExtSystemType;
	}

	public String getJoinExtSystemSyndir() {
		return joinExtSystemSyndir;
	}

	public void setJoinExtSystemSyndir(String joinExtSystemSyndir) {
		this.joinExtSystemSyndir = joinExtSystemSyndir;
	}

	public String getId() {
		return id;
	}

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

	public Integer getLimitNum() {
        return limitNum;
    }

    public void setLimitNum(Integer limitNum) {
        this.limitNum = limitNum;
    }

    public Integer getNowNum() {
        return nowNum;
    }

    public void setNowNum(Integer nowNum) {
        this.nowNum = nowNum;
    }

    public Integer getExceedLimitNum() {
        return exceedLimitNum;
    }

    public void setExceedLimitNum(Integer exceedLimitNum) {
        this.exceedLimitNum = exceedLimitNum;
    }

    public String getName() {
		return name;
	}

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

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public String getGrade() {
		return grade;
	}

	public void setGrade(String grade) {
		this.grade = grade;
	}

	public String getDemId() {
		return demId;
	}

	public void setDemId(String demId) {
		this.demId = demId;
	}

	public Long getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(Long orderNo) {
		this.orderNo = orderNo;
	}

	public Integer getOrgType() {
		return orgType;
	}

	public void setOrgType(Integer orgType) {
		this.orgType = orgType;
	}

	public Integer getDataScope() {
		return dataScope;
	}

	public void setDataScope(Integer dataScope) {
		this.dataScope = dataScope;
	}

	public String getProvinceCode() {
		return provinceCode;
	}

	public void setProvinceCode(String provinceCode) {
		this.provinceCode = provinceCode;
	}

	public String getCityCode() {
		return cityCode;
	}

	public void setCityCode(String cityCode) {
		this.cityCode = cityCode;
	}

	public String getCountyCode() {
		return countyCode;
	}

	public void setCountyCode(String countyCode) {
		this.countyCode = countyCode;
	}

	public String toString() {
		return "{"
				+ "\""+"name"+"\""+":"+"\""+this.name+"\","
				+"\""+"code"+"\""+":"+"\""+this.code+"\","
				+"\""+"parentId"+"\""+":"+"\""+this.parentId+"\","
				+"\""+"grade"+"\""+":"+"\""+this.grade+"\","
				+"\""+"demId"+"\""+":"+"\""+this.demId+"\","
				+"\""+"orderNo"+"\""+":"+"\""+this.orderNo+"\""
				+ "}";
	}
	
	@Override
	public String compare() throws Exception {
	    OrgManager service =	AppUtil.getBean(OrgManager.class);
	    Org oldVo=service.getByCode(this.code);
		return OperateLogUtil.compare(this,changeVo(oldVo));
	}


	public OrgVo changeVo(Org oldVo) {
		OrgVo newVo=new OrgVo();
		if (BeanUtils.isEmpty(newVo)) return newVo;
		newVo.setCode(oldVo.getCode());
		newVo.setDemId(oldVo.getDemId());
		newVo.setGrade(oldVo.getGrade());
		newVo.setName(oldVo.getName());
		newVo.setOrderNo(oldVo.getOrderNo());
		newVo.setParentId(oldVo.getParentId());
		return newVo;
	}

	public OrgVo changeVoOpen(Org oldVo) {
		OrgVo newVo=new OrgVo();
		newVo.setCode(oldVo.getCode());
		newVo.setDemId(oldVo.getDemId());
		newVo.setGrade(oldVo.getGrade());
		newVo.setName(oldVo.getName());
		newVo.setOrderNo(oldVo.getOrderNo());
		newVo.setParentId(oldVo.getParentId());
		newVo.setId(oldVo.getId());
		return newVo;
	}


	public static Org parse(OrgVo orgVo){
		Org role = new Org();
		role.setName(orgVo.getName());
		role.setCode(orgVo.getCode());
		return role;
	}
}
