package com.engine.salary.biz;

import com.engine.salary.entity.hrm.SubCompanyInfo;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;

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

public class SubCompanyBiz {

    public List<SubCompanyInfo> list() {
        List<SubCompanyInfo> returnList = new ArrayList<>();

        RecordSet rs = new RecordSet();
        rs.executeQuery("select id, subcompanyname from HrmsubCompany");
        while (rs.next()) {
            returnList.add(
                    SubCompanyInfo.builder()
                            .id(Long.valueOf(rs.getString(1)))
                            .name(rs.getString(2)).build()
            );
        }
        return returnList;
    }

    /**
     * 获取所有上级分部
     *
     * @param subId
     * @param returnList
     * @return
     */
    public List<String> getSupSubCompanyLists(String subId, List<String> returnList) {
        RecordSet rs = new RecordSet();
        rs.executeSql("select supsubcomid from HrmsubCompany where id=" + subId);
        while (rs.next()) {
            String supsubcomid = rs.getString(1);
            if (!StringUtils.equals(supsubcomid, "0")) {
                returnList.add(supsubcomid);
                getSupSubCompanyLists(supsubcomid, returnList);
            }
        }
        return returnList;
    }


}
