package com.sw.mes.yb.pc.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.pc.dao.CrucibleCheckDataItemDAO;
import com.sw.mes.yb.pc.entity.CrucibleCheckDataItem;
import com.sw.mes.yb.pc.service.CrucibleCheckDataItemService;
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 CrucibleCheckDataItemServiceImpl extends BaseServiceImpl<CrucibleCheckDataItem> implements CrucibleCheckDataItemService {

    CrucibleCheckDataItemDAO crucibleCheckItemDAO;

    @Autowired
    public void setDao(CrucibleCheckDataItemDAO crucibleCheckItemDAO) {
        this.crucibleCheckItemDAO = crucibleCheckItemDAO;
        super.setBaseDao(crucibleCheckItemDAO);
    }

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

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

    @Override
    public List<CrucibleCheckDataItem> findAll() {
        return crucibleCheckItemDAO.findAll();
    }

    @Override
    public List<CrucibleCheckDataItem> findByCheckData_Id(Long checkDataId) {
        return crucibleCheckItemDAO.findByCheckData_Id(checkDataId);
    }

    @Override
    public void deleteByCheckDataId(Long checkDataId) {
        crucibleCheckItemDAO.deleteByCheckDataId(checkDataId);
    }

}
