| package com.zy.acs.manager.system.controller; | 
|   | 
| import com.baomidou.mybatisplus.core.metadata.OrderItem; | 
| import com.zy.acs.framework.common.Cools; | 
| import com.zy.acs.manager.common.domain.BaseParam; | 
| import com.zy.acs.manager.system.entity.User; | 
| import org.springframework.security.core.Authentication; | 
| import org.springframework.security.core.context.SecurityContextHolder; | 
|   | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * Created by vincent on 1/30/2024 | 
|  */ | 
| public class BaseController { | 
|   | 
|     public User getLoginUser() { | 
|         try { | 
|             Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | 
|             if (authentication != null) { | 
|                 Object object = authentication.getPrincipal(); | 
|                 if (object instanceof User) { | 
|                     return (User) object; | 
|                 } | 
|             } | 
|         } catch (Exception e) { | 
|             System.out.println(e.getMessage()); | 
|         } | 
|         return null; | 
|     } | 
|   | 
|     public Long getLoginUserId() { | 
|         User loginUser = getLoginUser(); | 
|         return loginUser == null ? null : loginUser.getId(); | 
|     } | 
|   | 
|     public Long getTenantId() { | 
|         User loginUser = getLoginUser(); | 
|         return loginUser == null ? null : loginUser.getTenantId(); | 
|     } | 
|   | 
|     public <T extends BaseParam> T buildParam(Map<String, Object> map, Class<T> clz) { | 
|         T t  = null; | 
|         try { | 
|             t = clz.getDeclaredConstructor().newInstance(); | 
|             t.syncMap(map); | 
|         } catch (Exception e) { | 
|             e.printStackTrace(); | 
|         } | 
|         return t; | 
|     } | 
|   | 
|     public Boolean hasCreateTimeDesc(List<OrderItem> orderItems) { | 
|         if (Cools.isEmpty(orderItems)) { | 
|             return true; | 
|         } | 
|         if (orderItems.size() > 1) { | 
|             return false; | 
|         } | 
|         OrderItem orderItem = orderItems.get(0); | 
|         if (!orderItem.getColumn().equals("create_time")) { | 
|             return false; | 
|         } | 
|         if (orderItem.isAsc()) { | 
|             return false; | 
|         } | 
|         return true; | 
|     } | 
|   | 
| } |