001/* 002 * Copyright 2024-2025, Warm-Flow (290631660@qq.com). 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.dromara.warm.flow.core.handler; 017 018import org.dromara.warm.flow.core.entity.RootEntity; 019import org.dromara.warm.flow.core.utils.IdUtils; 020import org.dromara.warm.flow.core.utils.ObjectUtil; 021 022import java.util.Date; 023import java.util.Objects; 024 025/** 026 * 数据填充handler,以下三个接口按照实际情况实现 027 * 028 * @author warm 029 * @since 2023/4/1 15:37 030 */ 031public interface DataFillHandler { 032 033 /** 034 * id填充 035 * 036 * @param object 037 */ 038 default void idFill(Object object) { 039 RootEntity entity = (RootEntity) object; 040 if (ObjectUtil.isNotNull(entity)) { 041 if (Objects.isNull(entity.getId())) { 042 entity.setId(IdUtils.nextId()); 043 } 044 } 045 } 046 047 /** 048 * 新增填充 049 * 050 * @param object 051 */ 052 default void insertFill(Object object) { 053 RootEntity entity = (RootEntity) object; 054 if (ObjectUtil.isNotNull(entity)) { 055 entity.setCreateTime(ObjectUtil.isNotNull(entity.getCreateTime()) ? entity.getCreateTime() : new Date()); 056 entity.setUpdateTime(ObjectUtil.isNotNull(entity.getUpdateTime()) ? entity.getUpdateTime() : new Date()); 057 } 058 } 059 060 /** 061 * 设置更新常用参数 062 * 063 * @param object 064 */ 065 default void updateFill(Object object) { 066 RootEntity entity = (RootEntity) object; 067 if (ObjectUtil.isNotNull(entity)) { 068 entity.setUpdateTime(ObjectUtil.isNotNull(entity.getUpdateTime()) ? entity.getUpdateTime() : new Date()); 069 } 070 } 071}