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

import java.util.List;

import cn.com.ty.lift.ud.appmenu.mapper.AppuserMenuMapper;
import cn.com.ty.lift.ud.appmenu.mapper.entity.AppMenuRequest;
import cn.com.ty.lift.ud.appmenu.mapper.entity.Appmenu;
import cn.com.ty.lift.ud.appmenu.mapper.entity.AppuserMenu;
import cn.com.ty.lift.ud.appmenu.service.IAppuserMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 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(Long levelId) {
        return appuserMenuMapper.findMenuByUserLevelId(levelId);
    }

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

    }

    @Override
    public List<Appmenu> getMenuByLevelIdLimit5(Long levelId) {
        return appuserMenuMapper.getMenuByLevelIdLimit5(levelId);
    }

}
