package com.engine.htsc.clwhsq.service.impl;

import com.engine.core.impl.Service;
import com.engine.htsc.clwhsq.service.ClwhsqService;
import org.apache.poi.hssf.record.DVALRecord;
import weaver.conn.RecordSet;
import weaver.hrm.User;
import weaver.interfaces.htsc.comInfo.PropBean;

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

public class ClwhsqServiceImpl extends Service implements ClwhsqService {
    @Override
    public Map<String, Object> getNbsh(User user, Map<String, Object> param) {
        String szjgName = (String)  param.get("szjgName");
//        String deptid = (String)  param.get("deptid");
        ArrayList<User> list = new ArrayList<>();
        PropBean pp = new PropBean();
        RecordSet rs = new RecordSet();
        String clwhsq_szjgName = pp.getPropName("clwhsq_szjgName");
        HashMap<String, Object> map = new HashMap<>();
        if(Objects.equals(clwhsq_szjgName,szjgName)){
            String sql = "select * from hrmresource where departmentid in (select id from HRMDEPARTMENT WHERE supdepid = (select id from HRMDEPARTMENT where departmentname = '"+szjgName+"')) and status = 1";
            rs.execute(sql);
            while(rs.next()){
                User user1 = new User();
                user1.setUid(Integer.parseInt(rs.getString("id")));
                user1.setLastname(rs.getString("lastname"));
                user1.setUserDepartment(Integer.parseInt(rs.getString("departmentid")));
                list.add(user1);
            }
            List<Integer> collect = list.stream().map((item) -> {
                return item.getUID();
            }).collect(Collectors.toList());
            map.put("userIds",collect);
            map.put("list",list);
            return map;
        }else{
            String  sql = "select  * from hrmresource where seclevel BETWEEN 0 and 49 and status = 1 and  departmentid = " + user.getUserDepartment();
            rs.execute(sql);
            while(rs.next()){
                User user1 = new User();
                user1.setUid(Integer.parseInt(rs.getString("id")));
                user1.setLastname(rs.getString("lastname"));
                user1.setUserDepartment(Integer.parseInt(rs.getString("departmentid")));
                list.add(user1);
            }
            List<Integer> collect = list.stream().map((item) -> {
                return item.getUID();
            }).collect(Collectors.toList());
            map.put("userIds",collect);
            map.put("list",list);
            return map;

        }


    }
}
