package com.saye.hrs.service.impl;

import com.saye.hrs.mapper.OfficeMapper;
import com.saye.hrs.service.OfficeService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import javax.annotation.Resource;

/**
 * (Office)表服务实现类
 *
 * @author makejava
 * @since 2021-09-16 08:46:45
 */
@Service
public class OfficeServiceImpl implements OfficeService {
    @Resource
    private OfficeMapper officeMapper;

    @Override
    public HashMap<Object, Object> findOfficeById(HashMap<Object,Object> map) {
        return this.officeMapper.findOfficeById(map);
    }

    @Override
    public  List<HashMap<Object, Object>> findOfficeList(HashMap<Object,Object> map) {
        List<HashMap<Object, Object>> firstList = this.officeMapper.findFirstStageOffice(map);
        LinkedHashMap<Object,Integer> firstMap = new LinkedHashMap();
        for (int i = 0; i < firstList.size(); i++) {
            firstMap.put(firstList.get(i).get("OFFICE_ID"),i);
        }
        List<HashMap<Object, Object>> secondList = this.officeMapper.findSecondStageOffice(map);
        for (int i = 0; i < secondList.size(); i++) {
            Object p_id = secondList.get(i).get("P_ID");
            if (firstMap.containsKey(p_id)){
                secondList.add(i,firstList.get(firstMap.get(p_id)));
                firstMap.remove(p_id);
                i++;
            }
        }
        return secondList;
    }

    @Override
    public void insertOffice(HashMap<Object,Object> map) {
        this.officeMapper.insertOffice(map);
    }

    @Override
    public void updateOffice(HashMap<Object,Object> map) {
        this.officeMapper.updateOffice(map);
    }

    @Override
    public void deleteOfficeById(HashMap<Object,Object> map) {
        this.officeMapper.deleteOfficeById(map);
    }
}
