package com.sw.mes.agv.service.impl;

import com.sw.mes.agv.dao.MonitorEquipmentChargeDAO;
import com.sw.mes.agv.entity.MonitorEquipmentCharge;
import com.sw.mes.agv.service.MonitorEquipmentChargeService;
import com.sw.mes.base.factory.utils.PageUtils;
import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.core.utils.RequestPage;
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 MonitorEquipmentChargeServiceImpl extends BaseServiceImpl<MonitorEquipmentCharge> implements MonitorEquipmentChargeService {
	
	MonitorEquipmentChargeDAO monitorEquipmentChargeDAO;

	@Autowired
	public void setDao(MonitorEquipmentChargeDAO monitorEquipmentChargeDAO) {
		this.monitorEquipmentChargeDAO = monitorEquipmentChargeDAO;
		super.setBaseDao(monitorEquipmentChargeDAO);
	}

	@Override
	public List<MonitorEquipmentCharge> findAll(RequestPage page) {
		org.springframework.data.domain.Page<MonitorEquipmentCharge> springDataPage = monitorEquipmentChargeDAO.findAll(PageUtils.createPageable(page));
		page.setTotal(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	@Override
	public List<MonitorEquipmentCharge> findAll(Specification<MonitorEquipmentCharge> specification) {
		return monitorEquipmentChargeDAO.findAll(specification);
	}

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

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

	@Override
	public List<MonitorEquipmentCharge> findSlingStateNotEqual(String state) {
		return monitorEquipmentChargeDAO.findSlingStateNotEqual(state);
	}

	@Override
	public List<MonitorEquipmentCharge> findBySlingState(String slingState) {
		return monitorEquipmentChargeDAO.findBySlingState(slingState);
	}

	@Override
	public List<MonitorEquipmentCharge> findByEquipments(List<String> equipmentList) {
		return monitorEquipmentChargeDAO.findByEquipments(equipmentList);
	}

	@Override
	public List<MonitorEquipmentCharge> findByEquipmentsAndStoreCode(List<String> equipmentList, Boolean isHave) {
		if(isHave) {
			return monitorEquipmentChargeDAO.findByEquipmentsAndStoreCodeIsNotNull(equipmentList);
		} else {
			return monitorEquipmentChargeDAO.findByEquipmentsAndStoreCodeIsNull(equipmentList);
		}
	}

	@Override
	public List<MonitorEquipmentCharge> findByEquipmentsAndSlingState(List<String> equipmentList, String daidiaoliao) {
		return monitorEquipmentChargeDAO.findByEquipmentsAndSlingState(equipmentList, daidiaoliao);
	}

	@Override
	public void deleteByName(String deviceName) {
		monitorEquipmentChargeDAO.deleteByName(deviceName);
	}

}
