package com.td.Dawa.game.excelresources.service;

import com.td.Dawa.common.service.*;
import com.td.Dawa.game.excelresources.pojo.ExcelResources;
import com.td.Dawa.game.excelresources.vo.ExcelResourcesClientVo;
import com.td.Dawa.game.excelresources.vo.ExcelResourcesVo;
import com.td.Dawa.game.excelresources.repository.ExcelResourcesRepository;
import com.td.Dawa.util.CopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Service
@Transactional
public class ExcelResourcesServiceImpl extends CommonServiceImpl<ExcelResourcesVo, ExcelResources, Integer> implements ExcelResourcesService{

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ExcelResourcesRepository excelResourcesRepository;

    @Override
    public List<ExcelResourcesClientVo> findByArtIdIn(Integer[] artIds) {
        List<ExcelResources> excelResources = excelResourcesRepository.findAllByArtIdIn(artIds,  Sort.by(Sort.Direction.DESC, "artId"));
        return CopyUtil.copyList(excelResources,ExcelResourcesClientVo.class);
    }
}
