
package com.smallchill.system.service.impl;

import org.springframework.stereotype.Service;

import com.smallchill.core.base.service.BaseService;
import com.smallchill.core.plugins.dao.Blade;
import com.smallchill.core.toolbox.Record;
import com.smallchill.system.model.Menu;
import com.smallchill.system.service.MenuService;

@Service
public class MenuServiceImpl extends BaseService<Menu> implements MenuService {

	@Override
	public int findLastNum(String code) {
		try{
			Blade blade = Blade.create(Menu.class);
			Menu menu = blade.findFirstBy("pCode = #{pCode} order by num desc", Record.create().set("pCode", code));
			return menu.getNum() + 1;
		}
		catch(Exception ex){
			return 1;
		}
	}

	@Override
	public boolean isExistCode(String code) {
		Blade blade = Blade.create(Menu.class);
		String sql = "select * from tfw_menu where code = #{code}";
		boolean temp = blade.isExist(sql, Record.create().set("code", code));
		return temp;
	}

	@Override
	public boolean updateStatus(String ids, Object status) {
		Record paras = Record.create().set("status", status).set("ids", ids.split(","));
		/*SQLManager sql = Blade.dao();
		int cnt = sql.executeUpdate("update tfw_menu set status=#{status} where id in (#{join(ids)})", paras);
		return cnt > 0;*/
		Blade blade = Blade.create(Menu.class);
		boolean temp = blade.updateBy("status=#{status}", "id in (#{join(ids)})", paras);
		return temp;
	}

}
