-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix create time and modify time not in effect (#3885)
- Loading branch information
1 parent
006dd94
commit e7d33b6
Showing
26 changed files
with
156 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...e-service/src/main/java/org/apache/streampark/console/base/mybatis/entity/BaseEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.streampark.console.base.mybatis.entity; | ||
|
||
import com.baomidou.mybatisplus.annotation.FieldFill; | ||
import com.baomidou.mybatisplus.annotation.TableField; | ||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
/** Base entity. */ | ||
@Data | ||
public abstract class BaseEntity implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** create time */ | ||
@TableField(fill = FieldFill.INSERT) | ||
private Date createTime; | ||
|
||
/** modify time */ | ||
@TableField(fill = FieldFill.INSERT_UPDATE) | ||
private Date modifyTime; | ||
} |
55 changes: 55 additions & 0 deletions
55
...main/java/org/apache/streampark/console/base/mybatis/handler/DefaultBaseFieldHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.streampark.console.base.mybatis.handler; | ||
|
||
import org.apache.streampark.console.base.mybatis.entity.BaseEntity; | ||
|
||
import org.apache.ibatis.reflection.MetaObject; | ||
|
||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Date; | ||
import java.util.Optional; | ||
|
||
/** Automatically generate common basic field values when adding and modifying data. */ | ||
@Component | ||
public class DefaultBaseFieldHandler implements MetaObjectHandler { | ||
|
||
@Override | ||
public void insertFill(MetaObject metaObject) { | ||
baseEntity(metaObject).ifPresent(entity -> { | ||
entity.setCreateTime(new Date()); | ||
entity.setModifyTime(new Date()); | ||
}); | ||
|
||
} | ||
|
||
@Override | ||
public void updateFill(MetaObject metaObject) { | ||
baseEntity(metaObject).ifPresent(entity -> entity.setModifyTime(new Date())); | ||
} | ||
|
||
private Optional<BaseEntity> baseEntity(MetaObject metaObject) { | ||
return Optional.ofNullable(metaObject) | ||
.map(MetaObject::getOriginalObject) | ||
.filter(BaseEntity.class::isInstance) | ||
.map(BaseEntity.class::cast); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.