package com.sw.mes.yb.deviceCheck.service.impl;

import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.core.utils.RequestPage;
import com.sw.mes.base.factory.utils.PageUtils;
import com.sw.mes.yb.deviceCheck.dao.SpotCheckItemDAO;
import com.sw.mes.yb.deviceCheck.entity.SpotCheckItem;
import com.sw.mes.yb.deviceCheck.service.SpotCheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SpotCheckItemServiceImpl extends BaseServiceImpl<SpotCheckItem> implements SpotCheckItemService {

    SpotCheckItemDAO spotCheckItemDAO;

    @Autowired
    public void setDao(SpotCheckItemDAO spotCheckItemDAO) {
        this.spotCheckItemDAO = spotCheckItemDAO;
        super.setBaseDao(spotCheckItemDAO);
    }


    @Override
    public List<SpotCheckItem> findByExample(Specification<SpotCheckItem> specification, RequestPage page) {
        org.springframework.data.domain.Page<SpotCheckItem> springDataPage = spotCheckItemDAO.findAll(specification, PageUtils.createPageable(page));
        page.setTotal(springDataPage.getTotalElements());
        return springDataPage.getContent();
    }

    @Override
    public void saveInBatch(List<SpotCheckItem> itemList) {
        spotCheckItemDAO.saveAll(itemList);
    }

    @Override
    public List<SpotCheckItem> findByParentId(Integer parentId) {
        return spotCheckItemDAO.findByParentId(parentId);
    }

    @Override
    public List<SpotCheckItem> findAll() {
        return spotCheckItemDAO.findAll();
    }

    @Override
    public List<SpotCheckItem> findAllOrderByPriority() {
        return spotCheckItemDAO.findAllOrderByPriority();
    }

    @Override
    public void deleteByParentId(Integer parentId) {
        spotCheckItemDAO.deleteByParentId(parentId);
    }

}
