diff --git a/continew-starter-extension/continew-starter-extension-crud/pom.xml b/continew-starter-extension/continew-starter-extension-crud/pom.xml index bc645adb..c3758e59 100644 --- a/continew-starter-extension/continew-starter-extension-crud/pom.xml +++ b/continew-starter-extension/continew-starter-extension-crud/pom.xml @@ -16,6 +16,12 @@ ContiNew Starter 扩展模块 - CRUD(增删改查) + + + cn.crane4j + crane4j-spring-boot-starter + + org.springframework.data spring-data-commons @@ -44,11 +50,5 @@ top.charles7c.continew continew-starter-api-doc - - - - cn.crane4j - crane4j-spring-boot-starter - \ No newline at end of file diff --git a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseServiceImpl.java b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseServiceImpl.java index dca7db9a..2584f2ff 100644 --- a/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseServiceImpl.java +++ b/continew-starter-extension/continew-starter-extension-crud/src/main/java/top/charles7c/continew/starter/extension/crud/base/BaseServiceImpl.java @@ -146,26 +146,31 @@ public abstract class BaseServiceImpl, T extends BaseDO, } @Override + @Transactional(rollbackFor = Exception.class) public Long add(C req) { - if (null == req) { - return 0L; - } + this.beforeAdd(req); T entity = BeanUtil.copyProperties(req, entityClass); baseMapper.insert(entity); + this.afterAdd(req, entity); return entity.getId(); } @Override + @Transactional(rollbackFor = Exception.class) public void update(C req, Long id) { + this.beforeUpdate(req, id); T entity = this.getById(id); BeanUtil.copyProperties(req, entity, CopyOptions.create().ignoreNullValue()); baseMapper.updateById(entity); + this.afterUpdate(req, entity); } @Override @Transactional(rollbackFor = Exception.class) public void delete(List ids) { + this.beforeDelete(ids); baseMapper.deleteBatchIds(ids); + this.afterDelete(ids); } @Override @@ -212,6 +217,57 @@ public abstract class BaseServiceImpl, T extends BaseDO, } } + /** + * 新增前置处理 + * + * @param req 创建信息 + */ + protected void beforeAdd(C req) { + } + + /** + * 修改前置处理 + * + * @param req 修改信息 + * @param id ID + */ + protected void beforeUpdate(C req, Long id) { + } + + /** + * 删除前置处理 + * + * @param ids ID 列表 + */ + protected void beforeDelete(List ids) { + } + + /** + * 新增后置处理 + * + * @param req 创建信息 + * @param entity 实体信息 + */ + protected void afterAdd(C req, T entity) { + } + + /** + * 修改后置处理 + * + * @param req 修改信息 + * @param entity 实体信息 + */ + protected void afterUpdate(C req, T entity) { + } + + /** + * 删除后置处理 + * + * @param ids ID 列表 + */ + private void afterDelete(List ids) { + } + /** * 获取当前实体类型 *