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.CrucibleCheckDAO;
import com.sw.mes.yb.pc.entity.CrucibleCheck;
import com.sw.mes.yb.pc.service.CrucibleCheckService;
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 CrucibleCheckServiceImpl extends BaseServiceImpl<CrucibleCheck> implements CrucibleCheckService {

    CrucibleCheckDAO crucibleCheckDAO;

    @Autowired
    public void setDao(CrucibleCheckDAO crucibleCheckDAO) {
        this.crucibleCheckDAO = crucibleCheckDAO;
        super.setBaseDao(crucibleCheckDAO);
    }


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

    @Override
    public CrucibleCheck getByName(String name) {
        List<CrucibleCheck> list = crucibleCheckDAO.findByName(name);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }


}
