package com.infoepoch.pms.agent.infractructure.basic.user;

import com.infoepoch.pms.agent.common.utils.OracleUtils;
import com.infoepoch.pms.agent.common.utils.enums.DatabaseUtils;
import com.infoepoch.pms.agent.common.utils.enums.EnumUtils;
import com.infoepoch.pms.agent.domain.baisc.user.IUserQueryRepository;
import com.infoepoch.pms.agent.domain.baisc.user.User;
import com.infoepoch.pms.agent.domain.baisc.user.UserCriteria;
import com.infoepoch.pms.agent.domain.baisc.user.UserType;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Repository;

import java.util.*;
import java.util.stream.Collectors;

@Repository
public class UserQueryRepository implements IUserQueryRepository {

    @Autowired
    private JdbcTemplate jdbcTemplate;


    @Override
    public List<User> selectByCriteria(UserCriteria criteria) {
        StringBuffer sql = new StringBuffer("SELECT A.*,B.UOR_ORGANIZATION_ID,C.BO_NAME FROM BAS_USER A LEFT JOIN BAS_USER_ORGANIZATION_RELA B ON U_ID = UOR_USER_ID LEFT JOIN BAS_ORGANIZATION C ON UOR_ORGANIZATION_ID = BO_ID");
        List<Object> paramList = OracleUtils.combinationSql(sql, createUserCriteriaAndMap(criteria), "U_DISPLAY_ORDER,U_ID", false);
        SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sql.toString(), paramList.toArray());
        List<User> userList = new ArrayList<>();
        while (sqlRowSet.next())
            userList.add(convertUser(sqlRowSet));
        return userList;
    }
    @Override
    public List<User> selectByCriteriaProp(UserCriteria criteria) {
        StringBuffer sql = new StringBuffer("SELECT A.*,C.BO_NAME FROM BAS_USER A  LEFT JOIN BAS_ORGANIZATION C ON A.U_ORGANIZATION_ID = C.BO_ID");
        List<Object> paramList = OracleUtils.combinationSql(sql, createUserCriteriaAndMap(criteria), "U_DISPLAY_ORDER,U_ID", false);
        SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sql.toString(), paramList.toArray());
        List<User> userList = new ArrayList<>();
        while (sqlRowSet.next())
            userList.add(convertUserProp(sqlRowSet));
        return userList;
    }

    @Override
    public List<User> selectByCriteriaByPage(UserCriteria criteria, int pageIndex, int pageSize) {
        StringBuffer sql = new StringBuffer("SELECT A.*,B.UOR_ORGANIZATION_ID,C.BO_NAME FROM BAS_USER A LEFT JOIN BAS_USER_ORGANIZATION_RELA B ON U_ID = UOR_USER_ID LEFT JOIN BAS_ORGANIZATION C ON UOR_ORGANIZATION_ID = BO_ID");
        List<Object> paramList = OracleUtils.combinationSql(sql, createUserCriteriaAndMap(criteria), pageIndex, pageSize, "U_DISPLAY_ORDER,U_ID", false);
        SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sql.toString(), paramList.toArray());
        List<User> userList = new ArrayList<>();
        while (sqlRowSet.next())
            userList.add(convertUser(sqlRowSet));
        return userList;
    }

    @Override
    public List<User> selectByCriteriaByPageNotRela(UserCriteria criteria, int pageIndex, int pageSize) {
        StringBuffer sql = new StringBuffer("SELECT A.*,C.BO_NAME FROM BAS_USER A LEFT JOIN BAS_ORGANIZATION C ON U_ORGANIZATION_ID = BO_ID");
        List<Object> paramList = OracleUtils.combinationSql(sql, createUserCriteriaNotRelaAndMap(criteria), pageIndex, pageSize, "U_DISPLAY_ORDER,U_ID", false);
        SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sql.toString(), paramList.toArray());
        List<User> userList = new ArrayList<>();
        while (sqlRowSet.next())
            userList.add(convertUserNotRela(sqlRowSet));
        return userList;
    }

    @Override
    public List<User> selectByCriteriaNotRela(UserCriteria criteria) {
        StringBuffer sql = new StringBuffer("SELECT A.*,C.BO_NAME FROM BAS_USER A LEFT JOIN BAS_ORGANIZATION C ON U_ORGANIZATION_ID = BO_ID");
        List<Object> paramList = OracleUtils.combinationSql(sql, createUserCriteriaNotRelaAndMap(criteria),"U_DISPLAY_ORDER,U_ID", false);
        SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sql.toString(), paramList.toArray());
        List<User> userList = new ArrayList<>();
        while (sqlRowSet.next())
            userList.add(convertUserNotRela(sqlRowSet));
        return userList;
    }

    @Override
    public Integer selectCountByCriteriaByPageNotRela(UserCriteria criteria) {
        StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM BAS_USER A LEFT JOIN BAS_ORGANIZATION C ON U_ORGANIZATION_ID = BO_ID");
        List<Object> paramList = OracleUtils.combinationSql(sql, createUserCriteriaNotRelaAndMap(criteria),"U_DISPLAY_ORDER,U_ID", false);
        return jdbcTemplate.queryForObject(sql.toString(), paramList.toArray(), Integer.class);
    }

    private Map<String, Object> createUserCriteriaAndMapProp(UserCriteria criteria) {
        Map<String, Object> andMap = new HashMap<>();
        if (criteria.isDisabled() != null) {
            if (criteria.isDisabled()) {
                andMap.put(" U_DISABLED = 1 ", null);
            } else {
                andMap.put(" U_DISABLED = 0 ", null);
            }
        }
        if (StringUtils.isNotBlank(criteria.getUserName())) {
            andMap.put(" U_USERNAME LIKE ?", "%" + criteria.getUserName() + "%");
        }
        if (StringUtils.isNotBlank(criteria.getFullName())) {
            andMap.put(" U_FULLNAME LIKE ?", "%" + criteria.getFullName() + "%");
        }
        if (CollectionUtils.isNotEmpty(criteria.getOrganizationIds())) {
            andMap.put(OracleUtils.placeholderIn("U_ORGANIZATION_ID", criteria.getOrganizationIds()), criteria.getOrganizationIds());
        }
        if (CollectionUtils.isNotEmpty(criteria.getUserIds())) {
            andMap.put(OracleUtils.placeholderIn("U_ID", criteria.getUserIds()), criteria.getUserIds());
        }
        if (CollectionUtils.isNotEmpty(criteria.getJobNumbers())) {
            andMap.put(OracleUtils.placeholderIn("U_JOB_NUMBER", criteria.getJobNumbers()), criteria.getJobNumbers());
        }
        if (StringUtils.isNotEmpty(criteria.getOrganizationId())) {
            andMap.put("U_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION T WHERE T.BO_ID != '5241' START WITH T.BO_ID = ? CONNECT BY PRIOR T.BO_ID = T.BO_PARENT_ID)", criteria.getOrganizationId());
        }
        if (CollectionUtils.isNotEmpty(criteria.getBranchCompanyIds())){
            String placeholders = criteria.getBranchCompanyIds()
                    .stream()
                    .map(id -> "?")
                    .collect(Collectors.joining(", "));
            andMap.put(" U_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION T START WITH BO_ID IN ("+ placeholders +") CONNECT BY PRIOR T.BO_ID = T.BO_PARENT_ID ) ", criteria.getBranchCompanyIds());
        }
        if (StringUtils.isNotBlank(criteria.getJobNumberContain())) {
            andMap.put(" U_JOB_NUMBER LIKE ? ", criteria.getJobNumberContain());
        }
        if (CollectionUtils.isNotEmpty(criteria.getUsernameList())) {
            andMap.put(OracleUtils.placeholderIn("U_USERNAME", criteria.getUsernameList()), criteria.getUsernameList());
        }
        if (StringUtils.isNotBlank(criteria.getRoleName())) {
            andMap.put(" U_ID IN (SELECT UR_USER_ID FROM BAS_USER_ROLE LEFT JOIN BAS_ROLE ON UR_ROLE_ID = RL_ID WHERE RL_NAME = ?) ", criteria.getRoleName());
        }
        if (StringUtils.isNotBlank(criteria.getPropSessionTerm())) {
            andMap.put(" U_ID IN ( SELECT PE_EMPLOYEE_ID FROM T_PROP_EMPLOYEE WHERE PE_SESSION_TERM = ? and PE_CITY_NAME =? ) ", Arrays.asList(criteria.getPropSessionTerm(), criteria.getCityName()));
        }
        if (StringUtils.isNotBlank(criteria.getOrganizationName())) {
            andMap.put(" U_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION WHERE BO_NAME LIKE ? ) ", "%" + criteria.getOrganizationName() + "%");
        }
        if(StringUtils.isNotBlank(criteria.getDepartmentId())) {
            andMap.put(" U_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION T WHERE T.BO_ID != '5241' START WITH T.BO_ID = ? CONNECT BY PRIOR T.BO_ID = T.BO_PARENT_ID) ", criteria.getDepartmentId());
        }
        if (criteria.getHasLeader() != null) {
            if (!criteria.getHasLeader()) {
                if (criteria.getBranchCompanyFlag() != null && criteria.getBranchCompanyFlag()) {
                    andMap.put(" SUBSTR(U_POSITION, LENGTH(U_POSITION)-5, LENGTH(U_POSITION)) NOT IN ('JS0003','JS0005') ", null);
                } else {
                    andMap.put(" SUBSTR(U_POSITION, LENGTH(U_POSITION)-5, LENGTH(U_POSITION)) NOT IN ('JS0003','JS0005','JS0052','JS0053') ", null);
                }

            }
        }
        if (criteria.getDepartmentManagerFlag() != null) {//JS0003	总经理 JS0005 副总经理  JS0053 部门经理  JS0052 部门副经理 JS0055 中心经理  JS0056	中心副经理 JS0054	职员
            andMap.put(" SUBSTR(U_POSITION, LENGTH(U_POSITION)-5, LENGTH(U_POSITION))  IN ('JS0053','JS0052') ", null);
        }
        return andMap;
    }

    @Override
    public List<User> selectByCriteriaByPageProp(UserCriteria criteria, int pageIndex, int pageSize) {
        StringBuffer sql = new StringBuffer("SELECT A.*,C.BO_NAME FROM BAS_USER A  LEFT JOIN BAS_ORGANIZATION C ON A.U_ORGANIZATION_ID = C.BO_ID");
        List<Object> paramList = OracleUtils.combinationSql(sql, createUserCriteriaAndMapProp(criteria), pageIndex, pageSize, "U_DISPLAY_ORDER,U_ID", false);
        SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sql.toString(), paramList.toArray());
        List<User> userList = new ArrayList<>();
        while (sqlRowSet.next())
            userList.add(convertUserProp(sqlRowSet));
        return userList;
    }
    @Override
    public int selectCountByCriteria(UserCriteria criteria) {
        StringBuffer sql = new StringBuffer("SELECT COUNT(1) FROM BAS_USER A LEFT JOIN BAS_USER_ORGANIZATION_RELA B ON U_ID = UOR_USER_ID LEFT JOIN BAS_ORGANIZATION C ON UOR_ORGANIZATION_ID = BO_ID");
        List<Object> paramList = OracleUtils.combinationSql(sql, createUserCriteriaAndMap(criteria), "U_DISPLAY_ORDER,U_ID", false);
        return jdbcTemplate.queryForObject(sql.toString(), paramList.toArray(), Integer.class);
    }

    @Override
    public int selectCountByCriteriaProp(UserCriteria criteria) {
        StringBuffer sql = new StringBuffer("SELECT COUNT(1)  FROM BAS_USER A  LEFT JOIN BAS_ORGANIZATION C ON A.U_ORGANIZATION_ID = C.BO_ID");
        List<Object> paramList = OracleUtils.combinationSql(sql, createUserCriteriaAndMapProp(criteria), "U_DISPLAY_ORDER,U_ID", false);
        return jdbcTemplate.queryForObject(sql.toString(), paramList.toArray(), Integer.class);
    }
    /**
     * @param criteria
     * @return
     */
    private Map<String, Object> createUserCriteriaAndMap(UserCriteria criteria) {
        Map<String, Object> andMap = new HashMap<>();
        if (criteria.isDisabled() != null) {
            if (criteria.isDisabled()) {
                andMap.put(" U_DISABLED = 1 ", null);
            } else {
                andMap.put(" U_DISABLED = 0 ", null);
            }
        }
        if (StringUtils.isNotBlank(criteria.getUserName())) {
            andMap.put(" U_USERNAME LIKE ?", "%" + criteria.getUserName() + "%");
        }
        if (StringUtils.isNotBlank(criteria.getFullName())) {
            andMap.put(" U_FULLNAME LIKE ?", "%" + criteria.getFullName() + "%");
        }
        if (CollectionUtils.isNotEmpty(criteria.getOrganizationIds())) {
            andMap.put(OracleUtils.placeholderIn("UOR_ORGANIZATION_ID", criteria.getOrganizationIds()), criteria.getOrganizationIds());
        }
        if (CollectionUtils.isNotEmpty(criteria.getUserIds())) {
            andMap.put(OracleUtils.placeholderIn("U_ID", criteria.getUserIds()), criteria.getUserIds());
        }
        if (CollectionUtils.isNotEmpty(criteria.getJobNumbers())) {
            andMap.put(OracleUtils.placeholderIn("U_JOB_NUMBER", criteria.getJobNumbers()), criteria.getJobNumbers());
        }
        if (StringUtils.isNotEmpty(criteria.getOrganizationId())) {
            andMap.put("UOR_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION T WHERE T.BO_ID != '5241' START WITH T.BO_ID = ? CONNECT BY PRIOR T.BO_ID = T.BO_PARENT_ID)", criteria.getOrganizationId());
        }
        if (CollectionUtils.isNotEmpty(criteria.getBranchCompanyIds())){
            String placeholders = criteria.getBranchCompanyIds()
                    .stream()
                    .map(id -> "?")
                    .collect(Collectors.joining(", "));
            andMap.put(" UOR_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION T START WITH BO_ID IN ("+ placeholders +") CONNECT BY PRIOR T.BO_ID = T.BO_PARENT_ID ) ", criteria.getBranchCompanyIds());
        }
        if (StringUtils.isNotBlank(criteria.getJobNumberContain())) {
            andMap.put(" U_JOB_NUMBER LIKE ? ", criteria.getJobNumberContain());
        }
        if (CollectionUtils.isNotEmpty(criteria.getUsernameList())) {
            andMap.put(OracleUtils.placeholderIn("U_USERNAME", criteria.getUsernameList()), criteria.getUsernameList());
        }
        if (StringUtils.isNotBlank(criteria.getRoleName())) {
            andMap.put(" U_ID IN (SELECT UR_USER_ID FROM BAS_USER_ROLE LEFT JOIN BAS_ROLE ON UR_ROLE_ID = RL_ID WHERE RL_NAME = ?) ", criteria.getRoleName());
        }
        if (StringUtils.isNotBlank(criteria.getPropSessionTerm())) {
            andMap.put(" U_ID IN ( SELECT PE_EMPLOYEE_ID FROM T_PROP_EMPLOYEE WHERE PE_SESSION_TERM = ? and PE_CITY_NAME =? ) ", Arrays.asList(criteria.getPropSessionTerm(), criteria.getCityName()));
        }
//        if (StringUtils.isNotBlank(criteria.getPropSessionTermBrief())) {
//            andMap.put(" U_ID IN ( SELECT PE_EMPLOYEE_ID FROM T_PROP_EMPLOYEE WHERE PE_SESSION_TERM = (select ST_TERM_NAME from t_prop_session_term where ST_TERM_BRIEF =?  ) ) ",criteria.getPropSessionTermBrief());
            // U_ID in (
            //   select PE_EMPLOYEE_ID from t_prop_employee
            //   where PE_SESSION_TERM = (select ST_TERM_NAME from t_prop_session_term where ST_TERM_BRIEF ='苏州六届一次职代会'  )
            // )
//        }
        if (StringUtils.isNotBlank(criteria.getOrganizationName())) {
            andMap.put(" UOR_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION WHERE BO_NAME LIKE ? ) ", "%" + criteria.getOrganizationName() + "%");
        }
        if(StringUtils.isNotBlank(criteria.getDepartmentId())) {
            andMap.put(" UOR_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION T WHERE T.BO_ID != '5241' START WITH T.BO_ID = ? CONNECT BY PRIOR T.BO_ID = T.BO_PARENT_ID) ", criteria.getDepartmentId());
        }
        if (criteria.getHasLeader() != null) {
            if (!criteria.getHasLeader()) {
                if (criteria.getBranchCompanyFlag() != null && criteria.getBranchCompanyFlag()) {
                    andMap.put(" SUBSTR(U_POSITION, LENGTH(U_POSITION)-5, LENGTH(U_POSITION)) NOT IN ('JS0003','JS0005') ", null);
                } else {
                    andMap.put(" SUBSTR(U_POSITION, LENGTH(U_POSITION)-5, LENGTH(U_POSITION)) NOT IN ('JS0003','JS0005','JS0052','JS0053') ", null);
                }

            }
        }
        if (criteria.getDepartmentManagerFlag() != null) {//JS0003	总经理 JS0005 副总经理  JS0053 部门经理  JS0052 部门副经理 JS0055 中心经理  JS0056	中心副经理 JS0054	职员
             andMap.put(" SUBSTR(U_POSITION, LENGTH(U_POSITION)-5, LENGTH(U_POSITION))  IN ('JS0053','JS0052') ", null);
        }
        return andMap;
    }

    private Map<String, Object> createUserCriteriaNotRelaAndMap(UserCriteria criteria) {
        Map<String, Object> andMap = new HashMap<>();
        if (criteria.isDisabled() != null) {
            if (criteria.isDisabled()) {
                andMap.put(" U_DISABLED = 1 ", null);
            } else {
                andMap.put(" U_DISABLED = 0 ", null);
            }
        }
        if (StringUtils.isNotBlank(criteria.getUserName())) {
            andMap.put(" U_USERNAME LIKE ?", "%" + criteria.getUserName() + "%");
        }
        if (StringUtils.isNotBlank(criteria.getFullName())) {
            andMap.put(" U_FULLNAME LIKE ?", "%" + criteria.getFullName() + "%");
        }
        if (CollectionUtils.isNotEmpty(criteria.getOrganizationIds())) {
            andMap.put(OracleUtils.placeholderIn("U_ORGANIZATION_ID", criteria.getOrganizationIds()), criteria.getOrganizationIds());
        }
        if (CollectionUtils.isNotEmpty(criteria.getUserIds())) {
            andMap.put(OracleUtils.placeholderIn("U_ID", criteria.getUserIds()), criteria.getUserIds());
        }
        if (CollectionUtils.isNotEmpty(criteria.getJobNumbers())) {
            andMap.put(OracleUtils.placeholderIn("U_JOB_NUMBER", criteria.getJobNumbers()), criteria.getJobNumbers());
        }
        if (StringUtils.isNotEmpty(criteria.getOrganizationId())) {
            andMap.put("U_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION T WHERE T.BO_ID != '5241' START WITH T.BO_ID = ? CONNECT BY PRIOR T.BO_ID = T.BO_PARENT_ID)", criteria.getOrganizationId());
        }
        if (CollectionUtils.isNotEmpty(criteria.getBranchCompanyIds())){
            String placeholders = criteria.getBranchCompanyIds()
                    .stream()
                    .map(id -> "?")
                    .collect(Collectors.joining(", "));
            andMap.put(" U_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION T START WITH BO_ID IN ("+ placeholders +") CONNECT BY PRIOR T.BO_ID = T.BO_PARENT_ID ) ", criteria.getBranchCompanyIds());
        }
        if (StringUtils.isNotBlank(criteria.getJobNumberContain())) {
            andMap.put(" U_JOB_NUMBER LIKE ? ", criteria.getJobNumberContain());
        }
        if (CollectionUtils.isNotEmpty(criteria.getUsernameList())) {
            andMap.put(OracleUtils.placeholderIn("U_USERNAME", criteria.getUsernameList()), criteria.getUsernameList());
        }
        if (StringUtils.isNotBlank(criteria.getRoleName())) {
            andMap.put(" U_ID IN (SELECT UR_USER_ID FROM BAS_USER_ROLE LEFT JOIN BAS_ROLE ON UR_ROLE_ID = RL_ID WHERE RL_NAME = ?) ", criteria.getRoleName());
        }
        if (StringUtils.isNotBlank(criteria.getPropSessionTerm())) {
            andMap.put(" U_ID IN ( SELECT PE_EMPLOYEE_ID FROM T_PROP_EMPLOYEE WHERE PE_SESSION_TERM = ? and PE_CITY_NAME =? ) ", Arrays.asList(criteria.getPropSessionTerm(), criteria.getCityName()));
        }
//        if (StringUtils.isNotBlank(criteria.getPropSessionTermBrief())) {
//            andMap.put(" U_ID IN ( SELECT PE_EMPLOYEE_ID FROM T_PROP_EMPLOYEE WHERE PE_SESSION_TERM = (select ST_TERM_NAME from t_prop_session_term where ST_TERM_BRIEF =?  ) ) ",criteria.getPropSessionTermBrief());
        // U_ID in (
        //   select PE_EMPLOYEE_ID from t_prop_employee
        //   where PE_SESSION_TERM = (select ST_TERM_NAME from t_prop_session_term where ST_TERM_BRIEF ='苏州六届一次职代会'  )
        // )
//        }
        if (StringUtils.isNotBlank(criteria.getOrganizationName())) {
            andMap.put(" U_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION WHERE BO_NAME LIKE ? ) ", "%" + criteria.getOrganizationName() + "%");
        }
        if(StringUtils.isNotBlank(criteria.getDepartmentId())) {
            andMap.put(" U_ORGANIZATION_ID IN (SELECT BO_ID FROM BAS_ORGANIZATION T WHERE T.BO_ID != '5241' START WITH T.BO_ID = ? CONNECT BY PRIOR T.BO_ID = T.BO_PARENT_ID) ", criteria.getDepartmentId());
        }
        if (criteria.getHasLeader() != null) {
            if (!criteria.getHasLeader()) {
                if (criteria.getBranchCompanyFlag() != null && criteria.getBranchCompanyFlag()) {
                    andMap.put(" SUBSTR(U_POSITION, LENGTH(U_POSITION)-5, LENGTH(U_POSITION)) NOT IN ('JS0003','JS0005') ", null);
                } else {
                    andMap.put(" SUBSTR(U_POSITION, LENGTH(U_POSITION)-5, LENGTH(U_POSITION)) NOT IN ('JS0003','JS0005','JS0052','JS0053') ", null);
                }

            }
        }
        if (criteria.getDepartmentManagerFlag() != null) {//JS0003	总经理 JS0005 副总经理  JS0053 部门经理  JS0052 部门副经理 JS0055 中心经理  JS0056	中心副经理 JS0054	职员
            andMap.put(" SUBSTR(U_POSITION, LENGTH(U_POSITION)-5, LENGTH(U_POSITION))  IN ('JS0053','JS0052') ", null);
        }
        return andMap;
    }

    /**
     * @param sqlRowSet
     * @return
     */
    private User convertUser(SqlRowSet sqlRowSet) {
        return new User(
                sqlRowSet.getString("U_ID"),
                sqlRowSet.getString("UOR_ORGANIZATION_ID"),
                EnumUtils.getByValue(UserType.class, sqlRowSet.getInt("U_TYPE")),
                sqlRowSet.getString("U_POSITION"),
                sqlRowSet.getString("U_DISPLAY_ORDER"),
                sqlRowSet.getString("U_USERNAME"),
                sqlRowSet.getString("U_FULLNAME"),
                sqlRowSet.getString("U_SEX"),
                sqlRowSet.getString("U_MOBILE"),
                sqlRowSet.getString("U_EMAIL"),
                sqlRowSet.getBoolean("U_DISABLED"),
                DatabaseUtils.getBigField(sqlRowSet, "U_DESCRIPTION"),
                DatabaseUtils.getBigField(sqlRowSet, "U_OA_DATA"),
                DatabaseUtils.getBigField(sqlRowSet, "U_HR_DATA"),
                sqlRowSet.getString("U_JOB_NUMBER"),
                sqlRowSet.getObject("U_ORG_CONFIRM_STATUS") == null ? null : sqlRowSet.getInt("U_ORG_CONFIRM_STATUS"),
                sqlRowSet.getString("BO_NAME")
        );
    }

    private User convertUserNotRela(SqlRowSet sqlRowSet) {
        return new User(
                sqlRowSet.getString("U_ID"),
                sqlRowSet.getString("U_ORGANIZATION_ID"),
                EnumUtils.getByValue(UserType.class, sqlRowSet.getInt("U_TYPE")),
                sqlRowSet.getString("U_POSITION"),
                sqlRowSet.getString("U_DISPLAY_ORDER"),
                sqlRowSet.getString("U_USERNAME"),
                sqlRowSet.getString("U_FULLNAME"),
                sqlRowSet.getString("U_SEX"),
                sqlRowSet.getString("U_MOBILE"),
                sqlRowSet.getString("U_EMAIL"),
                sqlRowSet.getBoolean("U_DISABLED"),
                DatabaseUtils.getBigField(sqlRowSet, "U_DESCRIPTION"),
                DatabaseUtils.getBigField(sqlRowSet, "U_OA_DATA"),
                DatabaseUtils.getBigField(sqlRowSet, "U_HR_DATA"),
                sqlRowSet.getString("U_JOB_NUMBER"),
                sqlRowSet.getObject("U_ORG_CONFIRM_STATUS") == null ? null : sqlRowSet.getInt("U_ORG_CONFIRM_STATUS"),
                sqlRowSet.getString("BO_NAME")
        );
    }
    private User convertUserProp(SqlRowSet sqlRowSet) {
        return new User(
                sqlRowSet.getString("U_ID"),
                sqlRowSet.getString("U_ORGANIZATION_ID"),
                EnumUtils.getByValue(UserType.class, sqlRowSet.getInt("U_TYPE")),
                sqlRowSet.getString("U_POSITION"),
                sqlRowSet.getString("U_DISPLAY_ORDER"),
                sqlRowSet.getString("U_USERNAME"),
                sqlRowSet.getString("U_FULLNAME"),
                sqlRowSet.getString("U_SEX"),
                sqlRowSet.getString("U_MOBILE"),
                sqlRowSet.getString("U_EMAIL"),
                sqlRowSet.getBoolean("U_DISABLED"),
                DatabaseUtils.getBigField(sqlRowSet, "U_DESCRIPTION"),
                DatabaseUtils.getBigField(sqlRowSet, "U_OA_DATA"),
                DatabaseUtils.getBigField(sqlRowSet, "U_HR_DATA"),
                sqlRowSet.getString("U_JOB_NUMBER"),
                sqlRowSet.getObject("U_ORG_CONFIRM_STATUS") == null ? null : sqlRowSet.getInt("U_ORG_CONFIRM_STATUS"),
                sqlRowSet.getString("BO_NAME")
        );
    }

}
