refactor(codegen): 优化代码生成ServiceImpl模板的导入依赖
- 添加 ObjectUtil 导入以支持对象工具类功能pull/249/head
parent
4b8346ec80
commit
2ef409fa56
|
|
@ -1,15 +1,13 @@
|
|||
package ${basePackage}.module.${table.moduleName}.service.${table.businessName};
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ${jakartaPackage}.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
#if ($importEnable)
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
#end
|
||||
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
||||
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||
## 特殊:主子表专属逻辑
|
||||
|
|
@ -94,32 +92,6 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
// 返回
|
||||
return ${classNameVar}.getId();
|
||||
}
|
||||
#if ($importEnable)
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
||||
public ${sceneEnum.prefixClass}${table.className}ImportRespVO import${simpleClassName}List(List<${sceneEnum.prefixClass}${table.className}ImportExcelVO> importList) {
|
||||
if (CollUtil.isEmpty(importList)) {
|
||||
return ${sceneEnum.prefixClass}${table.className}ImportRespVO.builder()
|
||||
.successCount(0).failureCount(0).failureRows(new LinkedHashMap<>()).build();
|
||||
}
|
||||
// 遍历,逐个创建
|
||||
${sceneEnum.prefixClass}${table.className}ImportRespVO respVO = ${sceneEnum.prefixClass}${table.className}ImportRespVO.builder()
|
||||
.successCount(0).failureCount(0).failureRows(new LinkedHashMap<>()).build();
|
||||
AtomicInteger index = new AtomicInteger(1);
|
||||
importList.forEach(importItem -> {
|
||||
int currentIndex = index.getAndIncrement();
|
||||
try {
|
||||
create${simpleClassName}(BeanUtils.toBean(importItem, ${saveReqVOClass}.class));
|
||||
respVO.setSuccessCount(respVO.getSuccessCount() + 1);
|
||||
} catch (Exception ex) {
|
||||
respVO.getFailureRows().put(currentIndex, ex.getMessage());
|
||||
}
|
||||
});
|
||||
respVO.setFailureCount(respVO.getFailureRows().size());
|
||||
return respVO;
|
||||
}
|
||||
#end
|
||||
|
||||
@Override
|
||||
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||
|
|
@ -388,9 +360,6 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
#else
|
||||
#if ( $subTable.subJoinMany)
|
||||
private void create${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
list.forEach(o -> o.set${SubJoinColumnName}(${subJoinColumn.javaField}).clean());
|
||||
${subClassNameVars.get($index)}Mapper.insertBatch(list);
|
||||
}
|
||||
|
|
@ -448,4 +417,4 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
|||
#end
|
||||
|
||||
#end
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue