案例效果
如何使用第三方数据源导入
实现思路
- 第三方数据源配置上指定数据源,使用第三方数据源查出你们部门表数据。
- 部门解析器解析查出的bean,转换成jepaas平台的部门表(需要按照jepaas的部门表字段设置数据)
- 执行排序操作,因为数据有依赖关系,父数据在最上,要在前,子数据在后
- 本实例适用于任何第三方数据源导入JEPaaS的操作,用户只需要定义Parser即可。后续会支持任何Excel模型的导入。
操作步骤
写代码
相关代码
package com.project.demo.controller;
import com.google.common.base.Strings;
import com.je.core.base.MethodArgument;
import com.je.core.controller.PlatformController;
import com.je.core.result.BaseRespResult;
import com.je.core.util.SpringContextHolder;
import com.je.third.importsource.DataSourceImportSource;
import com.project.demo.parser.DepartmentImportParser;
import com.project.demo.parser.EndUserImportParser;
import com.project.demo.service.DepartmentImportService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.sql.DataSource;
import java.sql.SQLException;
/**
* @program: je-platform
* @author: LIULJ
* @create: 2020/7/26
* @description:
*/
@Controller
@RequestMapping(value = "/je/demo/import")
public class ImportController extends PlatformController {
@RequestMapping(value = {"/doImportDepartment"},method = {RequestMethod.POST},produces = {"application/json; charset=utf-8"})
@ResponseBody
public BaseRespResult doImportDepartment(MethodArgument param) throws SQLException {
String dsName = param.getRequest().getParameter("dsName");
if(Strings.isNullOrEmpty(dsName)){
return BaseRespResult.errorResult("请指定数据源!");
}
DataSource departDataSource = SpringContextHolder.getBean("dsName");
if(departDataSource == null){
return BaseRespResult.errorResult("没有找到指定数据源!");
}
String sql = "SELECT * FROM JE_CORE_DEPARTMENT";
DataSourceImportSource dataSourceImportSource = new DataSourceImportSource(departDataSource,sql);
DepartmentImportParser departmentImportParser = new DepartmentImportParser();
DepartmentImportService departmentImportService = new DepartmentImportService(dataSourceImportSource,departmentImportParser);
int result = departmentImportService.doImport();
return BaseRespResult.successResult("成功导入" + result + "条记录!");
}
@RequestMapping(value = {"/doImportUser"},method = {RequestMethod.POST},produces = {"application/json; charset=utf-8"})
@ResponseBody
public BaseRespResult doImportUser(MethodArgument param) throws SQLException {
String dsName = param.getRequest().getParameter("dsName");
if(Strings.isNullOrEmpty(dsName)){
return BaseRespResult.errorResult("请指定数据源!");
}
DataSource departDataSource = SpringContextHolder.getBean("dsName");
if(departDataSource == null){
return BaseRespResult.errorResult("没有找到指定数据源!");
}
String sql = "SELECT * FROM JE_CORE_ENDUSER";
DataSourceImportSource dataSourceImportSource = new DataSourceImportSource(departDataSource,sql);
EndUserImportParser endUserImportParser = new EndUserImportParser();
DepartmentImportService departmentImportService = new DepartmentImportService(dataSourceImportSource,endUserImportParser);
int result = departmentImportService.doImport();
return BaseRespResult.successResult("成功导入" + result + "条记录!");
}
}
关键字,相关问题
- 三方数据源
最后编辑: 肖海杰 文档更新时间: 2024-08-21 10:58 作者:肖海杰