| | |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | import com.vincent.rsf.server.system.entity.User; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.GrantedAuthority; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | |
| | | import java.util.List; |
| | |
| | | */ |
| | | |
| | | public class BaseController { |
| | | |
| | | public User getLoginUser() { |
| | | try { |
| | | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| | |
| | | return loginUser == null ? null : loginUser.getTenantId(); |
| | | } |
| | | |
| | | public boolean hasAuthority(String authority) { |
| | | if (authority == null || authority.trim().isEmpty()) { |
| | | return false; |
| | | } |
| | | try { |
| | | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| | | if (authentication == null || authentication.getAuthorities() == null) { |
| | | return false; |
| | | } |
| | | for (GrantedAuthority grantedAuthority : authentication.getAuthorities()) { |
| | | if (grantedAuthority != null && authority.equals(grantedAuthority.getAuthority())) { |
| | | return true; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | System.out.println(e.getMessage()); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public <T extends BaseParam> T buildParam(Map<String, Object> map, Class<T> clz) { |
| | | if (!Objects.isNull(map.get("meta"))) { |
| | | Map<String, Object> meta = (Map<String, Object>) map.get("meta"); |
| | |
| | | map.put(key, meta.get(key)); |
| | | }); |
| | | map.remove("meta"); |
| | | } |
| | | // 移除筛选条件里面的 $ |
| | | for (String key : map.keySet()) { |
| | | Object value = map.get(key); |
| | | if (key.equals("orderBy")) { |
| | | String newValue = value.toString().replace("$", ""); |
| | | map.replace("orderBy", value, newValue); |
| | | } |
| | | } |
| | | T t = null; |
| | | try { |
| | |
| | | } |
| | | |
| | | } |
| | | |