| | |
| | | import org.springblade.core.mp.base.BaseEntity; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tenant.mp.TenantEntity; |
| | | import org.springblade.core.tool.utils.*; |
| | | |
| | | import java.lang.reflect.Field; |
| | |
| | | * @Date 2022/9/20 16:16 |
| | | * @Version 1.0 |
| | | */ |
| | | public class EnhancementServicesTool <T extends BaseEntity> { |
| | | public class EnhancementServicesTool <T extends TenantEntity> { |
| | | public void resolveEntity(T entity) { |
| | | try { |
| | | BladeUser user = AuthUtil.getUser(); |
| | |
| | | |
| | | entity.setUpdateTime(now); |
| | | entity.setIsDeleted(0); |
| | | Field field = ReflectUtil.getField(entity.getClass(), "tenantId"); |
| | | if (ObjectUtil.isNotEmpty(field)) { |
| | | Method getTenantId = ClassUtil.getMethod(entity.getClass(), "getTenantId", new Class[0]); |
| | | String tenantId = String.valueOf(getTenantId.invoke(entity)); |
| | | if (ObjectUtil.isEmpty(tenantId)) { |
| | | Method setTenantId = ClassUtil.getMethod(entity.getClass(), "setTenantId", new Class[]{String.class}); |
| | | setTenantId.invoke(entity, null); |
| | | } |
| | | } |
| | | entity.setTenantId(user.getTenantId()); |
| | | |
| | | } catch (Throwable var8) { |
| | | try { |
| | | throw var8; |
| | | } catch (IllegalAccessException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (InvocationTargetException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | throw var8; |
| | | } |
| | | } |
| | | } |