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.SpotCheckDAO;
import com.sw.mes.yb.deviceCheck.entity.SpotCheck;
import com.sw.mes.yb.deviceCheck.service.SpotCheckService;
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 SpotCheckServiceImpl extends BaseServiceImpl<SpotCheck> implements SpotCheckService {

    SpotCheckDAO spotCheckDAO;

    @Autowired
    public void setDao(SpotCheckDAO spotCheckDAO) {
        this.spotCheckDAO = spotCheckDAO;
        super.setBaseDao(spotCheckDAO);
    }


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

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


}
