/**
 * Created by MyPC on 2019/11/5.
 */
'use strict';
const hash= require('../class/hash');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;

module.exports = (sequelize, DataTypes) => {

    const staff = sequelize.define('staff', {
        sid  : {type: DataTypes.INTEGER(11), primaryKey: true, autoIncrement: true},
        username: DataTypes.STRING,
        passwork: DataTypes.STRING,

        isadmin: DataTypes.INTEGER,

        staffManage: DataTypes.STRING,
        cid: DataTypes.INTEGER,

        othercid: DataTypes.STRING,
        category: DataTypes.STRING,
        othercategory: DataTypes.STRING,

        departmentID: DataTypes.INTEGER,

        departmentName: DataTypes.STRING,
        gender: DataTypes.STRING,
        qq: DataTypes.STRING,
        phone: DataTypes.STRING,
        telephone: DataTypes.STRING,
        email: DataTypes.STRING,
        avatar: DataTypes.STRING,
        birthday: DataTypes.STRING,

        position: DataTypes.STRING,
        appDate: DataTypes.STRING,
        jobNumber: DataTypes.STRING,
        hiredate: DataTypes.STRING,
        hireBiasDate: DataTypes.INTEGER,

        probationaryDate: DataTypes.DATE,
        practiceDate: DataTypes.DATE,
        regularsDate: DataTypes.DATE,

        dimissionReason: DataTypes.STRING,
        nature: DataTypes.INTEGER,
        pendStatus: DataTypes.INTEGER,
        wxid: DataTypes.STRING,
        wecat:DataTypes.STRING,
        pendingApprovals: DataTypes.STRING,


        processApprovals: DataTypes.STRING,
        pendingApprovalsLeave: DataTypes.INTEGER,
        processApprovalsLeave: DataTypes.STRING,
        processLeaveCC: DataTypes.STRING,

        staffManageLeave: DataTypes.STRING,
        InductionDate: DataTypes.DATE,
        dimissionDate: DataTypes.DATE,
        processCC: DataTypes.STRING,
        remittanceName: DataTypes.STRING,
        bankName: DataTypes.STRING,
        bankNumber: DataTypes.STRING,
        coupletNumber: DataTypes.STRING,
        salaryCard: DataTypes.STRING,
        salaryBank: DataTypes.STRING,
        did: DataTypes.STRING,
        didName: DataTypes.STRING,


        baseWage: DataTypes.STRING,
        postWage: DataTypes.STRING,
        achievementBonus: DataTypes.STRING,
        qualifications: DataTypes.STRING,
        marriage: DataTypes.STRING,
        nativePlace: DataTypes.STRING,
        emergencyContacts: DataTypes.STRING,
        living: DataTypes.STRING,
        IDcards: DataTypes.STRING,

        IDcardsImgA: DataTypes.STRING,
        IDcardsImgB: DataTypes.STRING,
        certificate: DataTypes.STRING,
        diploma: DataTypes.STRING,
        professionalTitle: DataTypes.STRING,
        updateDate: DataTypes.DATE,
        seniorityFormula: DataTypes.STRING,
        cldAccess: DataTypes.STRING,
        nation: DataTypes.STRING,

        graduateInstitutions: DataTypes.STRING,
        major: DataTypes.STRING,
        education: DataTypes.STRING,
        graduationTime: DataTypes.DATE,
        registeredResidence: DataTypes.STRING,
        householdRegistrationType: DataTypes.STRING,
        IDcardsValidity: DataTypes.DATE,
        positionId: DataTypes.STRING,
        appliedPromote: DataTypes.STRING,
        applyLeaveDate: DataTypes.DATE,


    }, {tableName:'CLD_staff'});

    /*
     * 根据ID合集获得客户信息
     * */
    staff.getOne=async function(sid,attributes){

        if(!hash.isNotANumber(sid)){
            sid=hash.hashDecode(sid);
            if(!hash.isNotANumber(sid)){
                return [];
            }
        }

        var condition={
            raw:true,
            where: {
                sid: sid

        }};
        if(hash.isExistence(attributes)){
            condition.attributes=attributes;
        }
        var detail = await this.findOne(condition);

        detail.sid=hash.hashEncode(detail.sid.toString());

        /*list.forEach(function(v,i){
            list[i].sid=hash.hashEncode(v.sid.toString());
            //console.log(clientList[i].dataValues.cidKey);
            //console.log(hash.hashDecode(clientList[i].dataValues.cidKey.toString()));
        });*/
        return detail;
    };

    return staff;
};

