package com.casic.missiles.service.Impl.business;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.casic.missiles.dto.IdDTO;
import com.casic.missiles.dto.ReturnDTO;
import com.casic.missiles.dto.ReturnUtil;
import com.casic.missiles.dto.business.outsource.OutsourcerUserListRequest;
import com.casic.missiles.enums.BusinessExceptionEnum;
import com.casic.missiles.exception.BusinessException;
import com.casic.missiles.mapper.business.BusinessOutsourcerUserInfoMapper;
import com.casic.missiles.model.business.BusinessOutsourcerUserInfo;
import com.casic.missiles.service.business.IBusinessOutsourcerUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

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

/**
 * <p>
 * 分包方-人员信息表 服务实现类
 * </p>
 *
 * @author wangpeng
 * @since 2023-03-23
 */
@Service
public class BusinessOutsourcerUserInfoServiceImpl extends ServiceImpl<BusinessOutsourcerUserInfoMapper, BusinessOutsourcerUserInfo> implements IBusinessOutsourcerUserInfoService {
    @Autowired
    private BusinessOutsourcerUserInfoMapper userInfoMapper;

    @Override
    public Page<BusinessOutsourcerUserInfo> listPage(Page<BusinessOutsourcerUserInfo> page, OutsourcerUserListRequest request) {
        QueryWrapper<BusinessOutsourcerUserInfo> wrapper = getWrapper(request);
        Page<BusinessOutsourcerUserInfo> infoPage = userInfoMapper.selectPage(page, wrapper);
        if(Objects.isNull(infoPage) || CollectionUtils.isEmpty(infoPage.getRecords())){
            return new Page<>();
        }
        return infoPage;
    }

    @Override
    public List<BusinessOutsourcerUserInfo> list(OutsourcerUserListRequest request) {
        QueryWrapper<BusinessOutsourcerUserInfo> wrapper = getWrapper(request);
        List<BusinessOutsourcerUserInfo> infoList = userInfoMapper.selectList(wrapper);
        if(Objects.isNull(infoList)){
            return new ArrayList<>();
        }
        return infoList;
    }

    private QueryWrapper<BusinessOutsourcerUserInfo> getWrapper(OutsourcerUserListRequest request) {
        QueryWrapper<BusinessOutsourcerUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("outsourcer_id", request.getOutsourcerId());
        return wrapper;
    }
}
