package com.lz.modules.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.Query;
import com.lz.modules.app.dto.StaffOccupationInfoDto;
import com.lz.modules.app.dao.StaffOccupationDao;
import com.lz.modules.app.entity.StaffOccupationEntity;
import com.lz.modules.app.service.StaffOccupationService;
import com.lz.modules.job.model.responseBo.DepartmentStaffBo;
import com.lz.modules.performance.dto.StaffTypeDto;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;


@Service("staffOccupationService")
public class StaffOccupationServiceImpl extends ServiceImpl<StaffOccupationDao, StaffOccupationEntity> implements StaffOccupationService {

    @Autowired
    StaffOccupationDao staffOccupationDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<StaffOccupationEntity> page = this.page(
                new Query<StaffOccupationEntity>().getPage(params),
                new QueryWrapper<StaffOccupationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public StaffOccupationEntity getStaffOccupationByStaffId(Long staffId) {
        return staffOccupationDao.getStaffOccupationByStaffId(staffId);
    }

    @Override
    public int updateStatusByStaffId(Long staffId, Integer status) {
        return staffOccupationDao.updateStatusByStaffId(staffId, status);
    }

    @Override
    public int addStaffOccupationBatch(List<StaffOccupationEntity> staffs) {
        return staffOccupationDao.addStaffOccupationBatch(staffs);
    }

    @Override
    public StaffOccupationInfoDto getOccupationByStaffId(Long staffId) {
        return staffOccupationDao.getOccupationByStaffId(staffId);
    }

    @Override
    public void updateAllOccupation() {
        staffOccupationDao.updateAllOccupation();
    }
    @Override
    public void updateStatusByStaff(Long staffId, DepartmentStaffBo departmentStaffBo){
        staffOccupationDao.updateStatusByStaff(staffId, departmentStaffBo);
    }

    @Override
    public List<String> removeDimissionStaffByStaffIds(List<String> staffIds) {
        if(CollectionUtils.isEmpty(staffIds)){
            return Collections.EMPTY_LIST;
        }
        return staffOccupationDao.removeDimissionStaffByStaffIds(staffIds);
    }

    @Override
    public List<StaffOccupationEntity> selectAll(){
        return staffOccupationDao.selectAll();
    }

    @Override
    public List<StaffTypeDto> selectStaffTypesByStaffIds(List<Long> staffIds) {
        return staffOccupationDao.selectStaffTypesByStaffIds(staffIds);
    }
}
