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.CrucibleCheckItemDAO;
import com.sw.mes.yb.pc.entity.CrucibleCheckItem;
import com.sw.mes.yb.pc.service.CrucibleCheckItemService;
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 CrucibleCheckItemServiceImpl extends BaseServiceImpl<CrucibleCheckItem> implements CrucibleCheckItemService {

    CrucibleCheckItemDAO crucibleCheckItemDAO;

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


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

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

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

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

    @Override
    public List<CrucibleCheckItem> findAllOrderByPriority() {
        return crucibleCheckItemDAO.findAllOrderByPriority();
    }

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

}
