diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseCreateDO.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseCreateDO.java new file mode 100644 index 00000000..6f6282b5 --- /dev/null +++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseCreateDO.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * 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 top.continew.starter.extension.crud.model.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; + +import java.io.Serial; +import java.time.LocalDateTime; + +/** + * 实体类基类 + * + *

+ * 通用字段:创建人、创建时间 + *

+ * + * @author Charles7c + * @since 2.0.1 + */ +public class BaseCreateDO extends BaseIdDO { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 创建人 + */ + @TableField(fill = FieldFill.INSERT) + private Long createUser; + + /** + * 创建时间 + */ + @TableField(fill = FieldFill.INSERT) + private LocalDateTime createTime; + + public Long getCreateUser() { + return createUser; + } + + public void setCreateUser(Long createUser) { + this.createUser = createUser; + } + + public LocalDateTime getCreateTime() { + return createTime; + } + + public void setCreateTime(LocalDateTime createTime) { + this.createTime = createTime; + } +} diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseDO.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseDO.java index c0367c9b..3e17461c 100644 --- a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseDO.java +++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseDO.java @@ -18,10 +18,8 @@ package top.continew.starter.extension.crud.model.entity; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import java.io.Serial; -import java.io.Serializable; import java.time.LocalDateTime; /** @@ -30,17 +28,11 @@ import java.time.LocalDateTime; * @author Charles7c * @since 1.0.0 */ -public class BaseDO implements Serializable { +public class BaseDO extends BaseIdDO { @Serial private static final long serialVersionUID = 1L; - /** - * ID - */ - @TableId - private Long id; - /** * 创建人 */ @@ -65,14 +57,6 @@ public class BaseDO implements Serializable { @TableField(fill = FieldFill.UPDATE) private LocalDateTime updateTime; - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - public Long getCreateUser() { return createUser; } diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseIdDO.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseIdDO.java new file mode 100644 index 00000000..4d07e1c4 --- /dev/null +++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseIdDO.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * 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 top.continew.starter.extension.crud.model.entity; + +import com.baomidou.mybatisplus.annotation.TableId; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 实体类基类 + * + *

+ * 通用字段:ID 主键 + *

+ * + * @author Charles7c + * @since 2.0.1 + */ +public class BaseIdDO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @TableId + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } +} diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseUpdateDO.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseUpdateDO.java new file mode 100644 index 00000000..c1c85cdf --- /dev/null +++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/model/entity/BaseUpdateDO.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * 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 top.continew.starter.extension.crud.model.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; + +import java.io.Serial; +import java.time.LocalDateTime; + +/** + * 实体类基类 + * + *

+ * 通用字段:创建人、创建时间 + *

+ * + * @author Charles7c + * @since 2.0.1 + */ +public class BaseUpdateDO extends BaseIdDO { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 修改人 + */ + @TableField(fill = FieldFill.UPDATE) + private Long updateUser; + + /** + * 修改时间 + */ + @TableField(fill = FieldFill.UPDATE) + private LocalDateTime updateTime; + + public Long getUpdateUser() { + return updateUser; + } + + public void setUpdateUser(Long updateUser) { + this.updateUser = updateUser; + } + + public LocalDateTime getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(LocalDateTime updateTime) { + this.updateTime = updateTime; + } +} diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/service/BaseService.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/service/BaseService.java index fc9a5d8c..d56e1ac2 100644 --- a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/service/BaseService.java +++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/service/BaseService.java @@ -18,7 +18,6 @@ package top.continew.starter.extension.crud.service; import cn.hutool.core.lang.tree.Tree; import jakarta.servlet.http.HttpServletResponse; -import top.continew.starter.extension.crud.model.req.BaseReq; import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.query.SortQuery; import top.continew.starter.extension.crud.model.resp.PageResp; @@ -35,7 +34,7 @@ import java.util.List; * @author Charles7c * @since 1.0.0 */ -public interface BaseService { +public interface BaseService { /** * 分页查询列表 diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/service/impl/BaseServiceImpl.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/service/impl/BaseServiceImpl.java index 2dc4cbef..9534d788 100644 --- a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/service/impl/BaseServiceImpl.java +++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/continew/starter/extension/crud/service/impl/BaseServiceImpl.java @@ -39,8 +39,7 @@ import top.continew.starter.data.mybatis.plus.base.BaseMapper; import top.continew.starter.data.mybatis.plus.query.QueryWrapperHelper; import top.continew.starter.data.mybatis.plus.service.impl.ServiceImpl; import top.continew.starter.extension.crud.annotation.TreeField; -import top.continew.starter.extension.crud.model.entity.BaseDO; -import top.continew.starter.extension.crud.model.req.BaseReq; +import top.continew.starter.extension.crud.model.entity.BaseIdDO; import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.query.SortQuery; import top.continew.starter.extension.crud.model.resp.PageResp; @@ -65,7 +64,7 @@ import java.util.Optional; * @author Charles7c * @since 1.0.0 */ -public abstract class BaseServiceImpl, T extends BaseDO, L, D, Q, C extends BaseReq> extends ServiceImpl implements BaseService { +public abstract class BaseServiceImpl, T extends BaseIdDO, L, D, Q, C> extends ServiceImpl implements BaseService { private final Class[] typeArgumentCache = ClassUtils.getTypeArguments(this.getClass()); protected final Class listClass = this.currentListClass(); @@ -75,7 +74,7 @@ public abstract class BaseServiceImpl, T extends BaseDO, @Override public PageResp page(Q query, PageQuery pageQuery) { - QueryWrapper queryWrapper = this.handleQueryWrapper(query); + QueryWrapper queryWrapper = this.buildQueryWrapper(query); IPage page = baseMapper.selectPage(pageQuery.toPage(), queryWrapper); PageResp pageResp = PageResp.build(page, listClass); pageResp.getList().forEach(this::fill); @@ -171,7 +170,7 @@ public abstract class BaseServiceImpl, T extends BaseDO, * @return 列表信息 */ protected List list(Q query, SortQuery sortQuery, Class targetClass) { - QueryWrapper queryWrapper = this.handleQueryWrapper(query); + QueryWrapper queryWrapper = this.buildQueryWrapper(query); // 设置排序 this.sort(queryWrapper, sortQuery); List entityList = baseMapper.selectList(queryWrapper); @@ -222,11 +221,12 @@ public abstract class BaseServiceImpl, T extends BaseDO, } /** - * 处理查询条件 + * 构建 QueryWrapper * + * @param query 查询条件 * @return QueryWrapper */ - protected QueryWrapper handleQueryWrapper(Q query) { + protected QueryWrapper buildQueryWrapper(Q query) { QueryWrapper queryWrapper = new QueryWrapper<>(); // 解析并拼接查询条件 return QueryWrapperHelper.build(query, queryFields, queryWrapper);