package com.base.plan.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.base.core.utiles.ListUtils;
import com.base.orbit.utils.BizUtils;
import com.base.plan.mapper.WindowResourceMapper;
import com.base.plan.model.entity.StripInfo;
import com.base.plan.model.entity.WindowResource;
import com.plan.api.model.WindowResourceRpcDTO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

@Service
public class WindowResourceService extends ServiceImpl<WindowResourceMapper, WindowResource> {

    public void saveWindowResource(List<WindowResource> windowResourceList) {
        if (!CollectionUtils.isEmpty(windowResourceList)) {
            this.saveOrUpdateBatch(windowResourceList);
        }
    }

    public List<WindowResourceRpcDTO> getWindowResourceInfo(List<String> reqIds) {
        QueryWrapper<WindowResource> windowResourceQueryWrapper = new QueryWrapper<>();
        windowResourceQueryWrapper.in(!ListUtils.isNoE(reqIds), "req_id", reqIds);
        List<WindowResource> windowResources = baseMapper.selectList(windowResourceQueryWrapper);
        if (!ListUtils.isNoE(windowResources)) {
            List<WindowResourceRpcDTO> resourceRpcDTOS = BizUtils.copyEntityToDto(WindowResourceRpcDTO.class, windowResources);
            return resourceRpcDTOS;
        }
        return Collections.emptyList();
    }
}
