package com.wb.permission.domain;

import com.wb.permission.pojo.WbTenancy;
import com.wb.util.SysUtil;
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-16 14:00:59
*/
@Service
public class WbTenancyBO {
    @Autowired
    SqlSessionTemplate sqlSessionTemplate;

    /**
    * Description: 新增和修改
    * @param wbTenancy
    * @return
    * Note: Nothing much.
    */
    public void save(WbTenancy wbTenancy){
        if (StringUtils.isEmpty(wbTenancy.getTenancyId())) {
            wbTenancy.setTenancyId(SysUtil.getId());
            sqlSessionTemplate.insert("resources/permission.WbTenancyMapper.insertSelective",wbTenancy);
        }else{
            sqlSessionTemplate.update("resources/permission.WbTenancyMapper.updateByPrimaryKeySelective",wbTenancy);
        }
    }

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

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

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

}