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

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.sys.dao.MenuDAO;
import com.jpsoft.shinestar.modules.sys.entity.Menu;
import com.jpsoft.shinestar.modules.sys.service.MenuService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="menuService")
public class MenuServiceImpl implements MenuService {
	@Resource(name="menuDAO")
	private MenuDAO menuDAO;

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

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

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

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

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = menuDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<Menu> list() {
		// TODO Auto-generated method stub
		return menuDAO.list();
	}
		
	@Override
	public Page<Menu> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
        Page<Menu> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
            menuDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public List<Menu> query(Map<String, Object> searchParams, int limit, List<Sort> sortList) {
		Page<Menu> page = PageHelper.startPage(1,limit,false).doSelectPage(()->{
			menuDAO.search(searchParams,sortList);
		});

		return page.getResult();
	}

	@Override
	public List<Menu> findAllocMenu(String subject, String parentId) {
		return menuDAO.findAllocMenu(subject, parentId);
	}
}