Commit 6982243370fcd5f3234b61a0b6d4dab109b991f3
1 parent
c320b525
perf:【INFRA 基础设施】优化一些 todo 提到的问题
Showing
11 changed files
with
15 additions
and
44 deletions
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java
| @@ -215,4 +215,11 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> { | @@ -215,4 +215,11 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> { | ||
| 215 | return delete(new LambdaQueryWrapper<T>().eq(field, value)); | 215 | return delete(new LambdaQueryWrapper<T>().eq(field, value)); |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | + default int deleteBatch(SFunction<T, ?> field, Collection<?> values) { | ||
| 219 | + if (CollUtil.isEmpty(values)) { | ||
| 220 | + return 0; | ||
| 221 | + } | ||
| 222 | + return delete(new LambdaQueryWrapper<T>().in(field, values)); | ||
| 223 | + } | ||
| 224 | + | ||
| 218 | } | 225 | } |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseErpMapper.java
| @@ -28,7 +28,7 @@ public interface Demo03CourseErpMapper extends BaseMapperX<Demo03CourseDO> { | @@ -28,7 +28,7 @@ public interface Demo03CourseErpMapper extends BaseMapperX<Demo03CourseDO> { | ||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | default int deleteByStudentIds(List<Long> studentIds) { | 30 | default int deleteByStudentIds(List<Long> studentIds) { |
| 31 | - return delete(Demo03CourseDO::getStudentId, studentIds); | 31 | + return deleteBatch(Demo03CourseDO::getStudentId, studentIds); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | } | 34 | } |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeErpMapper.java
| @@ -32,7 +32,7 @@ public interface Demo03GradeErpMapper extends BaseMapperX<Demo03GradeDO> { | @@ -32,7 +32,7 @@ public interface Demo03GradeErpMapper extends BaseMapperX<Demo03GradeDO> { | ||
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | default int deleteByStudentIds(List<Long> studentIds) { | 34 | default int deleteByStudentIds(List<Long> studentIds) { |
| 35 | - return delete(Demo03GradeDO::getStudentId, studentIds); | 35 | + return deleteBatch(Demo03GradeDO::getStudentId, studentIds); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | } | 38 | } |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03CourseInnerMapper.java
| @@ -23,7 +23,7 @@ public interface Demo03CourseInnerMapper extends BaseMapperX<Demo03CourseDO> { | @@ -23,7 +23,7 @@ public interface Demo03CourseInnerMapper extends BaseMapperX<Demo03CourseDO> { | ||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | default int deleteByStudentIds(List<Long> studentIds) { | 25 | default int deleteByStudentIds(List<Long> studentIds) { |
| 26 | - return delete(Demo03CourseDO::getStudentId, studentIds); | 26 | + return deleteBatch(Demo03CourseDO::getStudentId, studentIds); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | } | 29 | } |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03GradeInnerMapper.java
| @@ -23,7 +23,7 @@ public interface Demo03GradeInnerMapper extends BaseMapperX<Demo03GradeDO> { | @@ -23,7 +23,7 @@ public interface Demo03GradeInnerMapper extends BaseMapperX<Demo03GradeDO> { | ||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | default int deleteByStudentIds(List<Long> studentIds) { | 25 | default int deleteByStudentIds(List<Long> studentIds) { |
| 26 | - return delete(Demo03GradeDO::getStudentId, studentIds); | 26 | + return deleteBatch(Demo03GradeDO::getStudentId, studentIds); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | } | 29 | } |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03CourseNormalMapper.java
| @@ -23,7 +23,7 @@ public interface Demo03CourseNormalMapper extends BaseMapperX<Demo03CourseDO> { | @@ -23,7 +23,7 @@ public interface Demo03CourseNormalMapper extends BaseMapperX<Demo03CourseDO> { | ||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | default int deleteByStudentIds(List<Long> studentIds) { | 25 | default int deleteByStudentIds(List<Long> studentIds) { |
| 26 | - return delete(Demo03CourseDO::getStudentId, studentIds); | 26 | + return deleteBatch(Demo03CourseDO::getStudentId, studentIds); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | } | 29 | } |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03GradeNormalMapper.java
| @@ -23,7 +23,7 @@ public interface Demo03GradeNormalMapper extends BaseMapperX<Demo03GradeDO> { | @@ -23,7 +23,7 @@ public interface Demo03GradeNormalMapper extends BaseMapperX<Demo03GradeDO> { | ||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | default int deleteByStudentIds(List<Long> studentIds) { | 25 | default int deleteByStudentIds(List<Long> studentIds) { |
| 26 | - return delete(Demo03GradeDO::getStudentId, studentIds); | 26 | + return deleteBatch(Demo03GradeDO::getStudentId, studentIds); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | } | 29 | } |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentErpServiceImpl.java
| @@ -129,16 +129,12 @@ public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { | @@ -129,16 +129,12 @@ public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { | ||
| 129 | 129 | ||
| 130 | @Override | 130 | @Override |
| 131 | public void deleteDemo03Course(Long id) { | 131 | public void deleteDemo03Course(Long id) { |
| 132 | - // 校验存在 | ||
| 133 | - validateDemo03CourseExists(id); | ||
| 134 | // 删除 | 132 | // 删除 |
| 135 | demo03CourseErpMapper.deleteById(id); | 133 | demo03CourseErpMapper.deleteById(id); |
| 136 | } | 134 | } |
| 137 | 135 | ||
| 138 | @Override | 136 | @Override |
| 139 | public void deleteDemo03CourseListByIds(List<Long> ids) { | 137 | public void deleteDemo03CourseListByIds(List<Long> ids) { |
| 140 | - // 校验存在 | ||
| 141 | - validateDemo03CourseExists(ids); | ||
| 142 | // 删除 | 138 | // 删除 |
| 143 | demo03CourseErpMapper.deleteByIds(ids); | 139 | demo03CourseErpMapper.deleteByIds(ids); |
| 144 | } | 140 | } |
| @@ -154,13 +150,6 @@ public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { | @@ -154,13 +150,6 @@ public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { | ||
| 154 | } | 150 | } |
| 155 | } | 151 | } |
| 156 | 152 | ||
| 157 | - private void validateDemo03CourseExists(List<Long> ids) { | ||
| 158 | - List<Demo03CourseDO> list = demo03CourseErpMapper.selectByIds(ids); | ||
| 159 | - if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | ||
| 160 | - throw exception(DEMO03_COURSE_NOT_EXISTS); | ||
| 161 | - } | ||
| 162 | - } | ||
| 163 | - | ||
| 164 | private void deleteDemo03CourseByStudentId(Long studentId) { | 153 | private void deleteDemo03CourseByStudentId(Long studentId) { |
| 165 | demo03CourseErpMapper.deleteByStudentId(studentId); | 154 | demo03CourseErpMapper.deleteByStudentId(studentId); |
| 166 | } | 155 | } |
| @@ -198,16 +187,12 @@ public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { | @@ -198,16 +187,12 @@ public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { | ||
| 198 | 187 | ||
| 199 | @Override | 188 | @Override |
| 200 | public void deleteDemo03Grade(Long id) { | 189 | public void deleteDemo03Grade(Long id) { |
| 201 | - // 校验存在 | ||
| 202 | - validateDemo03GradeExists(id); | ||
| 203 | // 删除 | 190 | // 删除 |
| 204 | demo03GradeErpMapper.deleteById(id); | 191 | demo03GradeErpMapper.deleteById(id); |
| 205 | } | 192 | } |
| 206 | 193 | ||
| 207 | @Override | 194 | @Override |
| 208 | public void deleteDemo03GradeListByIds(List<Long> ids) { | 195 | public void deleteDemo03GradeListByIds(List<Long> ids) { |
| 209 | - // 校验存在 | ||
| 210 | - validateDemo03GradeExists(ids); | ||
| 211 | // 删除 | 196 | // 删除 |
| 212 | demo03GradeErpMapper.deleteByIds(ids); | 197 | demo03GradeErpMapper.deleteByIds(ids); |
| 213 | } | 198 | } |
| @@ -223,13 +208,6 @@ public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { | @@ -223,13 +208,6 @@ public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { | ||
| 223 | } | 208 | } |
| 224 | } | 209 | } |
| 225 | 210 | ||
| 226 | - private void validateDemo03GradeExists(List<Long> ids) { | ||
| 227 | - List<Demo03GradeDO> list = demo03GradeErpMapper.selectByIds(ids); | ||
| 228 | - if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | ||
| 229 | - throw exception(DEMO03_GRADE_NOT_EXISTS); | ||
| 230 | - } | ||
| 231 | - } | ||
| 232 | - | ||
| 233 | private void deleteDemo03GradeByStudentId(Long studentId) { | 211 | private void deleteDemo03GradeByStudentId(Long studentId) { |
| 234 | demo03GradeErpMapper.deleteByStudentId(studentId); | 212 | demo03GradeErpMapper.deleteByStudentId(studentId); |
| 235 | } | 213 | } |
yudao-module-infra/src/main/resources/codegen/java/dal/do.vm
| @@ -77,8 +77,8 @@ public class ${table.className}DO extends BaseDO { | @@ -77,8 +77,8 @@ public class ${table.className}DO extends BaseDO { | ||
| 77 | private ${column.javaType} ${column.javaField}; | 77 | private ${column.javaType} ${column.javaField}; |
| 78 | #end | 78 | #end |
| 79 | #end | 79 | #end |
| 80 | + | ||
| 80 | ## 特殊:主子表专属逻辑(非 ERP 模式) | 81 | ## 特殊:主子表专属逻辑(非 ERP 模式) |
| 81 | -## TODO @puhui999:这里空行看看,会不会多了一个哈 | ||
| 82 | #if ( $voType == 20 && $subTables && $subTables.size() > 0 && $table.templateType != 11 ) | 82 | #if ( $voType == 20 && $subTables && $subTables.size() > 0 && $table.templateType != 11 ) |
| 83 | #foreach ($subTable in $subTables) | 83 | #foreach ($subTable in $subTables) |
| 84 | #set ($index = $foreach.count - 1) | 84 | #set ($index = $foreach.count - 1) |
yudao-module-infra/src/main/resources/codegen/java/dal/mapper_sub.vm
| @@ -56,7 +56,7 @@ public interface ${subTable.className}Mapper extends BaseMapperX<${subTable.clas | @@ -56,7 +56,7 @@ public interface ${subTable.className}Mapper extends BaseMapperX<${subTable.clas | ||
| 56 | 56 | ||
| 57 | #if ( $table.templateType != 2 && $deleteBatchEnable) | 57 | #if ( $table.templateType != 2 && $deleteBatchEnable) |
| 58 | default int deleteBy${SubJoinColumnName}s(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) { | 58 | default int deleteBy${SubJoinColumnName}s(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) { |
| 59 | - return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s); | 59 | + return deleteBatch(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s); |
| 60 | } | 60 | } |
| 61 | #end | 61 | #end |
| 62 | 62 |
yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm
| @@ -334,18 +334,13 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -334,18 +334,13 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 334 | 334 | ||
| 335 | @Override | 335 | @Override |
| 336 | public void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id) { | 336 | public void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id) { |
| 337 | - // 校验存在 | ||
| 338 | - validate${subSimpleClassName}Exists(id); | ||
| 339 | // 删除 | 337 | // 删除 |
| 340 | ${subClassNameVars.get($index)}Mapper.deleteById(id); | 338 | ${subClassNameVars.get($index)}Mapper.deleteById(id); |
| 341 | } | 339 | } |
| 342 | 340 | ||
| 343 | -## TODO @puhui999:批量删除的时候,要不直接删除,就不“校验存在”;ps:主子表删除的时候,子表的处理,也要处理下哈; | ||
| 344 | #if ($deleteBatchEnable) | 341 | #if ($deleteBatchEnable) |
| 345 | @Override | 342 | @Override |
| 346 | public void delete${subSimpleClassName}ListByIds(List<${subPrimaryColumn.javaType}> ids) { | 343 | public void delete${subSimpleClassName}ListByIds(List<${subPrimaryColumn.javaType}> ids) { |
| 347 | - // 校验存在 | ||
| 348 | - validate${subSimpleClassName}Exists(ids); | ||
| 349 | // 删除 | 344 | // 删除 |
| 350 | ${subClassNameVars.get($index)}Mapper.deleteByIds(ids); | 345 | ${subClassNameVars.get($index)}Mapper.deleteByIds(ids); |
| 351 | } | 346 | } |
| @@ -362,15 +357,6 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -362,15 +357,6 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 362 | } | 357 | } |
| 363 | } | 358 | } |
| 364 | 359 | ||
| 365 | -#if ($deleteBatchEnable) | ||
| 366 | - private void validate${subSimpleClassName}Exists(List<${subPrimaryColumn.javaType}> ids) { | ||
| 367 | - List<${subTable.className}DO> list = ${subClassNameVar}Mapper.selectByIds(ids); | ||
| 368 | - if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | ||
| 369 | - throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS); | ||
| 370 | - } | ||
| 371 | - } | ||
| 372 | -#end | ||
| 373 | - | ||
| 374 | ## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作 | 360 | ## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作 |
| 375 | #else | 361 | #else |
| 376 | #if ( $subTable.subJoinMany) | 362 | #if ( $subTable.subJoinMany) |