| package com.dy.pmsBase.role; | 
|   | 
| import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | 
| import com.dy.common.webUtil.QueryResultVo; | 
| import com.dy.pmsGlobal.daoBa.BaPrivilegeMapper; | 
| import com.dy.pmsGlobal.daoBa.BaRoleMapper; | 
| import com.dy.pmsGlobal.daoBa.BaRolePrivilegeMapper; | 
| import com.dy.pmsGlobal.pojoBa.BaRole; | 
| import com.dy.pmsGlobal.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 rpDao; | 
|     private BaPrivilegeMapper priDao; | 
|   | 
|     @Autowired | 
|     public RoleSv(BaRoleMapper dao, BaRolePrivilegeMapper rpDao,BaPrivilegeMapper priDao) { | 
|         this.dao = dao; | 
|         this.rpDao = rpDao; | 
|         this.priDao = priDao; | 
|     } | 
|   | 
|     @Transactional | 
|     public int save(BaRole role) { | 
|         int count = dao.insert(role); | 
|         // 添加角色权限 | 
|         updateRolePrivileges(role.id,role.priIds); | 
|         return count; | 
|     } | 
|   | 
|     /** | 
|      * 逻辑删除实体 | 
|      * @param id 实体ID | 
|      * @return 影响记录数量 | 
|      */ | 
|     @Transactional | 
|     public int delete(Long id) { | 
|         return this.dao.deleteLogicById(id); | 
|     } | 
|   | 
|     /** | 
|      * 禁用或启用角色信息 | 
|      * @param id | 
|      * @param disabled | 
|      * @return | 
|      */ | 
|     @Transactional | 
|     public int disabled(Long id,Boolean disabled) { | 
|         BaRole role=new BaRole(); | 
|         role.id=id; | 
|         role.disabled=disabled; | 
|         return dao.updateByPrimaryKeySelective(role); | 
|     } | 
|   | 
|     @Transactional | 
|     public int update(BaRole role) { | 
|         int count = dao.updateByPrimaryKeySelective(role); | 
|         // 更新角色权限 | 
|         updateRolePrivileges(role.id,role.priIds); | 
|         return count; | 
|     } | 
|   | 
|     /** | 
|      * 添加或更新角色权限 | 
|      * @param roleId 角色ID | 
|      * @param priIds 权限id | 
|      * @return | 
|      */ | 
|     private void updateRolePrivileges(Long roleId,List<Long> priIds) { | 
|         if(CollectionUtils.isEmpty(priIds)){ | 
|             return; | 
|         } | 
|         // 删除角色权限 | 
|         rpDao.deleteByRoleId(roleId); | 
|         priIds.stream().forEach(rp -> { | 
|             if(priDao.selectByPrimaryKey(rp.longValue()) != null){ | 
|                 rpDao.insert(new BaRolePrivilege(roleId, rp.longValue())); | 
|             } | 
|         }); | 
|     } | 
|   | 
|     public BaRole selectById(String roleId) { | 
|         return dao.selectByPrimaryKey(Long.valueOf(roleId)); | 
|     } | 
|   | 
|     public List<BaRole> selectAll() { | 
|         return dao.selectAll(); | 
|     } | 
|   | 
|     /** | 
|      * 获取角色列表 | 
|      */ | 
|     public QueryResultVo<List<BaRole>> selectSome(QueryVo queryVo) { | 
|         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); | 
|   | 
|         //查询符合条件的记录总数 | 
|         Long itemTotal = this.dao.selectSomeCount(params); | 
|   | 
|         QueryResultVo<List<BaRole>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ; | 
|         //计算分页等信息 | 
|         rsVo.calculateAndSet(itemTotal, params); | 
|   | 
|         //查询符合条件的记录 | 
|         rsVo.obj = this.dao.selectSome(params) ; | 
|         return rsVo ; | 
|     } | 
|   | 
| } |