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.DeviceCheckDAO;
import com.sw.mes.yb.deviceCheck.entity.DeviceCheck;
import com.sw.mes.yb.deviceCheck.service.DeviceCheckService;
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 DeviceCheckServiceImpl extends BaseServiceImpl<DeviceCheck> implements DeviceCheckService {

    DeviceCheckDAO deviceCheckDAO;

    @Autowired
    public void setDao(DeviceCheckDAO deviceCheckDAO) {
        this.deviceCheckDAO = deviceCheckDAO;
        super.setBaseDao(deviceCheckDAO);
    }

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

    @Override
    public DeviceCheck findByDeviceNoOrderByCreateTimeDescLimit1(String deviceNo) {
        return deviceCheckDAO.findByDeviceNoOrderByCreateTimeDescLimit1(deviceNo);
    }

}
