package com.casic.missiles.modular.system.model;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.casic.missiles.core.enums.OperationEnum;
import com.casic.missiles.core.util.ToolUtil;
import com.casic.missiles.modular.sync.handler.base.DeptAbstractRequiredModel;
import lombok.Data;

import java.io.Serializable;

/**
 * <p>
 * <p>
 * </p>
 *
 * @author stylefeng123
 * @since 2019-08-16
 */
@TableName("bus_dept_sync")
@Data
public class DeptSync extends Model<DeptSync> implements DeptAbstractRequiredModel {

    private static final long serialVersionUID = 1L;

    /**
     * 组织code
     */
    private String orgaCode;
    /**
     * 组织机构名称
     */
    private String orgaName;
    /**
     * 组织机构父类名称
     */
    private String superCode;
    /**
     * 是否父级
     */
    private String isSuper;
    /**
     * 操作标识
     */
    @TableField("action_type")
    private String actionType;


    public String getOrgaCode() {
        return orgaCode;
    }


    @Override
    public String getTargetSimplename() {
        return this.orgaName;
    }

    @Override
    public String getTargetFullname() {
        return this.orgaName;
    }

    @Override
    public String getTargetPid() {
        return this.superCode;
    }

    @Override
    public String getTargetId() {
        return this.orgaCode;
    }

    @Override
    public String getTargetOperation() {
        //增量同步数据操作
        if (ToolUtil.isEmpty(this.actionType)) {
            return OperationEnum.INSERT_TYPE.getValue();
        }
        switch (this.actionType) {

            case "1":
                return OperationEnum.INSERT_TYPE.getValue();
            case "2":
                return OperationEnum.DEL_TYPE.getValue();
            case "3":
                return OperationEnum.UPDATE_TYPE.getValue();

            default:
                return OperationEnum.INSERT_TYPE.getValue();
        }
    }

    @Override
    protected Serializable pkVal() {
        return this.getOrgaCode();
    }

    @Override
    public String toString() {
        return "DeptSync{" +
                "orgaCode=" + orgaCode +
                ", orgaName=" + orgaName +
                ", superCode=" + superCode +
                ", isSuper=" + isSuper +
                ", actionType=" + actionType +
                "}";
    }
}
