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.business.outsource.OutsourcerAbilityListRequest;
import com.casic.missiles.mapper.business.BusinessOutsourcerAbilityMapper;
import com.casic.missiles.model.business.BusinessOutsourcerAbility;
import com.casic.missiles.service.business.IBusinessOutsourcerAbilityService;
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 BusinessOutsourcerAbilityServiceImpl extends ServiceImpl<BusinessOutsourcerAbilityMapper, BusinessOutsourcerAbility> implements IBusinessOutsourcerAbilityService {
    @Autowired
    private BusinessOutsourcerAbilityMapper abilityMapper;

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

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

    }

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