package com.dy.pipIrrBase.role; 
 | 
  
 | 
import com.dy.common.webUtil.QueryResultVo; 
 | 
import com.dy.pipIrrBase.user.QueryVo; 
 | 
import com.dy.pipIrrGlobal.daoBa.BaRoleMapper; 
 | 
import com.dy.pipIrrGlobal.daoBa.BaRolePrivilegeMapper; 
 | 
import com.dy.pipIrrGlobal.pojoBa.BaRole; 
 | 
import com.dy.pipIrrGlobal.pojoBa.BaRolePrivilege; 
 | 
import lombok.extern.slf4j.Slf4j; 
 | 
import org.apache.dubbo.common.utils.PojoUtils; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.stereotype.Service; 
 | 
import org.springframework.transaction.annotation.Transactional; 
 | 
  
 | 
import java.util.List; 
 | 
import java.util.Map; 
 | 
  
 | 
@Slf4j 
 | 
@Service 
 | 
public class RoleSv { 
 | 
  
 | 
    private BaRoleMapper dao; 
 | 
    private BaRolePrivilegeMapper rolePrivDao ; 
 | 
  
 | 
    @Autowired 
 | 
    private void setDao(BaRoleMapper dao){ 
 | 
        this.dao = dao; 
 | 
    } 
 | 
  
 | 
    @Autowired 
 | 
    private void setRolePrivDao(BaRolePrivilegeMapper dao){ 
 | 
        this.rolePrivDao = dao; 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 得到所有角色 
 | 
     * @return 所有角色集合 
 | 
     */ 
 | 
    public QueryResultVo<List<BaRole>> selectAll(){ 
 | 
        QueryResultVo<List<BaRole>> rsVo = new QueryResultVo<>() ; 
 | 
        rsVo.obj = this.dao.selectAll() ; 
 | 
        return rsVo ; 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 得到一个角色 
 | 
     * @param id 角色ID 
 | 
     * @return 角色实体 
 | 
     */ 
 | 
    public BaRole selectById(Long id){ 
 | 
        return this.dao.selectById(id) ; 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 得到一个用户 
 | 
     * @param vo 查询条件值对象 
 | 
     * @return 用户实体 
 | 
     */ 
 | 
    @SuppressWarnings("unchecked") 
 | 
    public QueryResultVo<List<BaRole>> selectSome(QueryVo vo){ 
 | 
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo) ; 
 | 
        Long itemTotal = this.dao.selectTotal(params) ; 
 | 
  
 | 
        QueryResultVo<List<BaRole>> rsVo = new QueryResultVo<>() ; 
 | 
        rsVo.pageSize = vo.pageSize ; 
 | 
        rsVo.pageCurr = vo.pageCurr ; 
 | 
        rsVo.calculateAndSet(itemTotal, params); 
 | 
        rsVo.obj = this.dao.selectSome(params) ; 
 | 
  
 | 
        return rsVo ; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 保存实体 
 | 
     * @param po 实体 
 | 
     * @return 影响记录数量 
 | 
     */ 
 | 
    @Transactional 
 | 
    public int save(BaRole po){ 
 | 
        return this.dao.putin(po) ; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 保存修改实体 
 | 
     * @param po 实体 
 | 
     * @return 影响记录数量 
 | 
     */ 
 | 
    @Transactional 
 | 
    public int update(BaRole po){ 
 | 
        return this.dao.updateByPrimaryKeySelective(po) ; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 设置角色权限 
 | 
     * @param roleId 角色id 
 | 
     * @param priviIds 选择的权限id集合 
 | 
     * @return 插入角色与权限关联记录数量 
 | 
     */ 
 | 
    public int setRoles(Long roleId, Long[] priviIds){ 
 | 
        this.rolePrivDao.deleteByRoleId(roleId) ; 
 | 
        int count = 0 ; 
 | 
        if(priviIds != null && priviIds.length > 0){ 
 | 
            for(Long privId : priviIds){ 
 | 
                count += this.rolePrivDao.insertSelective(new BaRolePrivilege(roleId, privId)) ; 
 | 
            } 
 | 
        } 
 | 
        return count ; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 保存修改实体 
 | 
     * @param id 实体ID 
 | 
     * @return 影响记录数量 
 | 
     */ 
 | 
    @Transactional 
 | 
    public int delete(Long id){ 
 | 
        //int count = this.dao.deleteLogicById(id) ; 
 | 
        //逻辑删除,所以不实际删除其关联的权限 
 | 
        //if(count > 0){ 
 | 
        //    this.rolePrivDao.deleteByRoleId(id) ; 
 | 
        //} 
 | 
        //return count ; 
 | 
        return this.dao.deleteLogicById(id) ; 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |