All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quhaodian.user.data.service.impl.MenuServiceImpl Maven / Gradle / Ivy

There is a newer version: 1.8.7
Show newest version
package com.quhaodian.user.data.service.impl;

import com.quhaodian.data.core.Finder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.quhaodian.data.core.Updater;
import com.quhaodian.user.data.dao.MenuDao;
import com.quhaodian.user.data.entity.Menu;
import com.quhaodian.user.data.service.MenuService;

import com.quhaodian.data.page.Filter;
import com.quhaodian.data.page.Order;
import com.quhaodian.data.page.Page;
import com.quhaodian.data.page.Pageable;
import java.util.List;
import java.util.LinkedList;
import com.quhaodian.data.utils.FilterUtils;


/**
* Created by imake on 2017年07月21日14:37:30.
*/
@Service
@Transactional
public class MenuServiceImpl implements MenuService {

	private MenuDao dao;


	@Override
	public List findChildMenu(Integer id) {
		Finder finder = Finder.create("from Menu t where t.parent.id=" + id);
		finder.append(" and t.catalog =0 ");
		finder.append(" order by t.sortNum asc");
		finder.setCacheable(true);
		List ms = dao.find(finder);
		return ms;
	}

	@Override
	public List findChild(Integer id) {
		Finder finder = Finder.create("from Menu t where t.parent.id=" + id);
		finder.append(" order by t.sortNum asc");
		finder.setCacheable(true);
		List ms = dao.find(finder);
		return ms;
	}


	@Override
	public List childs(Integer id) {
		List ms = null;
		Menu menu = dao.findById(id);
		if (menu != null) {
			Finder finder = Finder.create("from Menu t where t.lft >=:lft and t.rgt<=:rgt ");
			finder.append(" order by t.lft asc");
			finder.setParam("lft", menu.getLft());
			finder.setParam("rgt", menu.getRgt());
			finder.setCacheable(false);
			ms = dao.find(finder);
		}

		return ms;
	}

	@Override
	@Transactional(readOnly = true)
	public Menu findById(Integer id) {
		return dao.findById(id);
	}

	@Override
	public List findByTops(Integer pid) {
		LinkedList result = new LinkedList();
		Menu catalog = dao.findById(pid);
	    if(catalog != null){
			while ( catalog != null && catalog.getParent() != null ) {
				result.addFirst(catalog);
				catalog = dao.findById(catalog.getParentId());
			}
			result.addFirst(catalog);
	    }
		return result;
	}

	@Override
    @Transactional
	public Menu save(Menu bean) {
		dao.save(bean);
		return bean;
	}

	@Override
    @Transactional
	public Menu update(Menu bean) {
		Updater updater = new Updater(bean);
		return dao.updateByUpdater(updater);
	}

	@Override
    @Transactional
	public Menu deleteById(Integer id) {
		Menu bean = dao.findById(id);
        dao.deleteById(id);
		return bean;
	}

	@Override
    @Transactional	
	public Menu[] deleteByIds(Integer[] ids) {
		Menu[] beans = new Menu[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}


	@Autowired
	public void setDao(MenuDao dao) {
		this.dao = dao;
	}

	@Override
    public Page page(Pageable pageable){
         return dao.page(pageable);
    }


    @Override
	public Page page(Pageable pageable, Object search) {
		List filters=	FilterUtils.getFilters(search);
		if (filters!=null) {
			pageable.getFilters().addAll(filters);
		}
		return dao.page(pageable);
	}

    @Override
    public List list(int first, Integer size, List filters, List orders) {
        return dao.list(first,size,filters,orders);}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy