package com.jpsoft.shinestar.modules.base.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jpsoft.shinestar.modules.base.dao.TerminalInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.TerminalInfo;
import com.jpsoft.shinestar.modules.base.service.TerminalInfoService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Transactional
@Component(value="terminalInfoService")
public class TerminalInfoServiceImpl implements TerminalInfoService {
	@Resource(name="terminalInfoDAO")
	private TerminalInfoDAO terminalInfoDAO;

	@Override
	public TerminalInfo get(String id) {
		// TODO Auto-generated method stub
		return terminalInfoDAO.get(id);
	}

	@Override
	public int insert(TerminalInfo model) {
		// TODO Auto-generated method stub
		//model.setId(UUID.randomUUID().toString());
		
		return terminalInfoDAO.insert(model);
	}

	@Override
	public int update(TerminalInfo model) {
		// TODO Auto-generated method stub
		return terminalInfoDAO.update(model);		
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return terminalInfoDAO.delete(id);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = terminalInfoDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<TerminalInfo> list() {
		// TODO Auto-generated method stub
		return terminalInfoDAO.list();
	}

	@Override
	public int getCountByName(String name,String excludeId){
		return terminalInfoDAO.getCountByName(name,excludeId);
	}
		
	@Override
	public Page<TerminalInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
        Page<TerminalInfo> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
            terminalInfoDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public void updateActiveByTerminalNo(String terminalNo, boolean active) {
		terminalInfoDAO.updateActiveByTerminalNo(terminalNo,active);
	}
}