package com.wb.permission.domain;

import com.wb.permission.pojo.WbRoleResource;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* Description:
* Author: wangll
* Version: 1.0
* Create Date: 2020-03-20 14:24:49
*/
@Service
public class WbRoleResourceBO {
    @Autowired
    SqlSessionTemplate sqlSessionTemplate;

    /**
    * Description: 新增和修改
    * @param wbRoleResource
    * @return
    * Note: Nothing much.
    */
    public void save(WbRoleResource wbRoleResource){
        if (StringUtils.isEmpty(wbRoleResource)) {
            sqlSessionTemplate.insert("resources/permission.WbRoleResourceMapper.insertSelective",wbRoleResource);
        }else{
            sqlSessionTemplate.update("resources/permission.WbRoleResourceMapper.updateByPrimaryKeySelective",wbRoleResource);
        }
    }

    /**
    * Description: 新增
    * @param wbRoleResource
    * @return
    * Note: Nothing much.
    */
    public void insert(WbRoleResource wbRoleResource){
       sqlSessionTemplate.insert("resources/permission.WbRoleResourceMapper.insertSelective",wbRoleResource);
    }

    /**
    * Description: 修改
    * @param wbRoleResource
    * @return
    * Note: Nothing much.
    */
    public void update(WbRoleResource wbRoleResource){
       sqlSessionTemplate.update("resources/permission.WbRoleResourceMapper.updateByPrimaryKeySelective",wbRoleResource);
    }

    /**
    * Description: 删除
    * @param id
    * @return
    * Note: Nothing much.
    */
    public void delete(String id){
       sqlSessionTemplate.delete("resources/permission.WbRoleResourceMapper.deleteByPrimaryKey",id);
    }

    /**
     * Description: 删除角色菜单关系
     * 通过租户、角色、菜单
     * @param wbRoleResource
     * @return
     * Note: Nothing much.
     */
    public void deleteByRoleMenu(WbRoleResource wbRoleResource){
        sqlSessionTemplate.delete("resources/permission.WbRoleResourceMapper.deleteByRoleMenu",wbRoleResource);
    }

}