package com.yuanchu.mom.service.imp; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.yuanchu.mom.common.GetLook; import com.yuanchu.mom.common.PrintChina; import com.yuanchu.mom.dto.RolePowerDto; import com.yuanchu.mom.dto.UserPageDto; import com.yuanchu.mom.mapper.PowerMapper; import com.yuanchu.mom.mapper.RoleMapper; import com.yuanchu.mom.mapper.UserMapper; import com.yuanchu.mom.pojo.Menu; import com.yuanchu.mom.pojo.Power; import com.yuanchu.mom.pojo.Role; import com.yuanchu.mom.pojo.User; import com.yuanchu.mom.service.RoleService; import com.yuanchu.mom.service.UserService; import com.yuanchu.mom.utils.Jwt; import com.yuanchu.mom.utils.QueryWrappers; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.DigestUtils; import java.util.HashMap; import java.util.List; import java.util.Map; @Service @AllArgsConstructor public class RoleServiceImp implements RoleService { private RoleMapper roleMapper; private PowerMapper powerMapper; private GetLook getLook; @Override public List selectList() { return roleMapper.selectList(null); } @Override public Map selectUserList(IPage page, Role role) { Map map = new HashMap<>(); map.put("head", PrintChina.printChina(Role.class)); Map map1 = getLook.selectPowerByMethodAndUserId("selectRoleLists"); if(map1.get("look")==1) role.setCreateUser(map1.get("userId")); map.put("body", roleMapper.selectPage(page, QueryWrappers.queryWrappers(role))); return map; } @Override public int delRole(Integer id) { return roleMapper.deleteById(id); } @Override @Transactional(rollbackFor = Exception.class) public int addRole(RolePowerDto rolePowerDto) { Role role = new Role(); role.setName(rolePowerDto.getRoleName()); int insert = roleMapper.insert(role); if (insert == 1){ rolePowerDto.getPowers().forEach(a->{ a.setRoleId(role.getId()); powerMapper.insert(a); }); } return 1; } @Override public List selectMenuList() { return roleMapper.selectMenuList(); } @Override @Transactional(rollbackFor = Exception.class) public int upRole(RolePowerDto rolePowerDto) { Role role = new Role(); role.setName(rolePowerDto.getRoleName()); role.setId(rolePowerDto.getRoleId2()); int up = roleMapper.updateById(role); if (up == 1){ powerMapper.delete(Wrappers.lambdaUpdate().eq(Power::getRoleId, role.getId())); rolePowerDto.getPowers().forEach(a->{ a.setRoleId(role.getId()); powerMapper.insert(a); }); } return 1; } }