Browse Source

代码生成模板-->添加下载导出xx基础信息模板、导入xx基本信息列表

master
daikun1@bosssoft.com.cn 2 years ago
parent
commit
183574e72a
  1. 34
      win-module-infra/win-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm
  2. 9
      win-module-infra/win-module-infra-biz/src/main/resources/codegen/java/service/service.vm
  3. 24
      win-module-infra/win-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm
  4. 2
      win-module-infra/win-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm

34
win-module-infra/win-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm

@ -108,4 +108,38 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas);
}
@GetMapping("/get-import-template")
@Operation(summary = "获得导入${table.classComment}模板")
public void importTemplate(HttpServletResponse response) throws IOException {
List<${table.className}ExcelVO> list = Arrays.asList();
// 输出
ExcelUtils.write(response, "${table.classComment}基本信息导入模板.xls", "${table.classComment}基本信息列表", ${table.className}ExcelVo.class, list);
}
@PostMapping("/import")
@Operation(summary = "导入${table.classComment}基本信息")
@Parameters({
@Parameter(name = "file", description = "Excel 文件", required = true),
@Parameter(name = "mode", description = "导入模式1更新2追加3覆盖", example = "1"),
@Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true")
})
#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:import')")#end
public CommonResult<Map<String, Object>> importExcel(HttpServletResponse response,
@RequestParam("file") MultipartFile file,
@RequestParam(value = "mode") Integer mode,
@RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception {
List<${table.className}ExcelVO> list = ExcelUtils.read(file, ${table.className}ExcelVO.class);
List<${table.className}ExcelVO> errorList = ${classNameVar}Service.import${table.className}List(list, mode, updatePart);
Map<String, Object> returnMap = new HashMap<>();
returnMap.put("errorCount", errorList.size());
if(!errorList.isEmpty()) {
String url = ExcelUtils.writeLocalFile("${table.classComment}基本信息导入错误数据" + LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) + ".xlsx", "错误列表", errorList);
returnMap.put("errorFile", url);
}
return success(returnMap);
}
}

9
win-module-infra/win-module-infra-biz/src/main/resources/codegen/java/service/service.vm

@ -67,4 +67,13 @@ public interface ${table.className}Service {
*/
List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO);
/**
* 导入${table.classComment}主信息
*
* @param datas 导入${table.classComment}主信息列表
* @param mode 导入模式1更新2追加3覆盖
* @param updatePart 是否支持更新
* @return 导入结果
*/
public List<${table.className}ExcelVO> import${table.className}List(List<${table.className}ExcelVO> datas, Integer mode, boolean updatePart);
}

24
win-module-infra/win-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm

@ -79,4 +79,28 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
return ${classNameVar}Mapper.selectList(exportReqVO);
}
@Override
public List<${table.className}ExcelVO> import${table.className}List(List<${table.className}ExcelVO> datas, Integer mode, boolean updatePart) {
if (CollUtil.isEmpty(datas)) {
throw exception(${simpleClassName_underlineCase.toUpperCase()}_IMPORT_LIST_IS_EMPTY);
}
List<${table.className}ExcelVO> errorList = new ArrayList<>();
datas.forEach(item -> {
if(errorList == null){
// 判断如果不存在,在进行插入
${table.className}DO obj = ${classNameVar}Mapper.selectByCode(item.getCode());
if (obj == null&& mode != 3) {
${classNameVar}Mapper.insert(${table.className}Convert.INSTANCE.convert(item));
}
else if (obj != null && mode != 2) {// 如果存在,判断是否允许更新
${table.className}DO ${classNameVar}DO = ${table.className}Convert.INSTANCE.convert(item);
${classNameVar}DO.setId(obj.getId());
${classNameVar}Mapper.updateById(obj);
}
}
});
return errorList;
}
}

2
win-module-infra/win-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm

@ -55,7 +55,7 @@
<Detail ref="detailRef" :isBasic="true" :allSchemas="${simpleClassName}.allSchemas" />
<!-- 导入 -->
<ImportForm ref="importFormRef" url="/wms/${classNameVar}/import" :importTemplateData="importTemplateData" @success="importSuccess" />
<ImportForm ref="importFormRef" url="/${table.moduleName}/${simpleClassName_strikeCase}/import" :importTemplateData="importTemplateData" @success="importSuccess" />
</template>
<script setup lang="ts">

Loading…
Cancel
Save