package cn.com.ty.lift.system.appmenu.service.impl;

import cn.com.ty.lift.system.appmenu.mapper.AppuserMenuMapper;
import cn.com.ty.lift.system.appmenu.mapper.entity.AppMenuRequest;
import cn.com.ty.lift.system.appmenu.mapper.entity.Appmenu;
import cn.com.ty.lift.system.appmenu.mapper.entity.AppuserMenu;
import cn.com.ty.lift.system.appmenu.service.IAppuserMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * app角色权限-ServiceImpl
 *
 * @author Xson
 * @date 2020-06-04
 */
@Service
@Transactional
public class AppuserMenuServiceImpl extends ServiceImpl<AppuserMenuMapper, AppuserMenu>
    implements IAppuserMenuService {
	
	@Autowired
	private AppuserMenuMapper appuserMenuMapper;

	@Override
	public List<Appmenu> getAllMenuByLevelId(Integer levelId) {
		return appuserMenuMapper.findMenuByUserLevelId(levelId);
	}

	@Override
	public void updateUserMenu(AppMenuRequest request) {
		appuserMenuMapper.deleteByLevelId(request.getLevelId());
		for(Integer id : request.getIds()) {
			AppuserMenu am = new AppuserMenu();
			am.setAppmenuId(id);
			am.setUserLevelId(request.getLevelId());
			appuserMenuMapper.insert(am);
		}
		
	}


}
