把老系统中的数据,整理清洗,导出成excel;把excel上传到新系统,插入数据库中,完成数据迁移.
1.kettle数据导出
2.数据校验
3.mysql数据插入
采用批量插入的方式:每次插入100条.
<insert id="insertBatch">
INSERT INTO tb_user
(id, name)
VALUES
<foreach collection ="list" item="user" separator =",">
(#{user.id}, #{user.name})
</foreach >
</insert>
参考:包含唯一字段的批量插入;mybatis获取批量插入的主键自增id
4.超大excel上传问题
5.json文件解析
一个json文件《组织机构数据.json》里面是组织树的数据。把它解析成集合list,分析它的数据
public class Region {
private String orgName;
private String orgCode;
private String orgType;
private String parentCode;
public String getOrgName() {
return orgName;
}
public void setOrgName(String orgName) {
this.orgName = orgName;
}
public String getOrgCode() {
return orgCode;
}
public void setOrgCode(String orgCode) {
this.orgCode = orgCode;
}
public String getOrgType() {
return orgType;
}
public void setOrgType(String orgType) {
this.orgType = orgType;
}
public String getParentCode() {
return parentCode;
}
public void setParentCode(String parentCode) {
this.parentCode = parentCode;
}
@Override
public String toString() {
return "Region{" + "orgName='" + orgName + '\'' + ", orgCode='" + orgCode + '\'' + ", orgType='" + orgType + '\'' + ", parentCode='" + parentCode + '\'' + '}';
}
}
public class RegionVo extends Region {
private List<RegionVo> children;
public List<RegionVo> getChildren() {
return children;
}
public void setChildren(List<RegionVo> children) {
this.children = children;
}
@Override
public String toString() {
return "RegionVo{" + "children=" + children + '}';
}
}
public class Result<T> {
private T data;
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
public class JsonRead {
public static void main(String[] args) {
File file = new File("C:\\Users\\xionghao5\\Desktop\\json\\组织机构数据.json");
RegionVo regionVo = getJsonFromJsonFile(file);
}
public static RegionVo getJsonFromJsonFile(File file) {
RegionVo regionVo = null;
try {
String content = FileUtils.readFileToString(file, "UTF-8");
JSONObject jsonObject = JSON.parseObject(content);
Result<RegionVo> result = JSON.parseObject(content, new TypeReference<Result<RegionVo>>() {});
RegionVo data = result.getData();
List<Region> list = new ArrayList<>();
getRegions(data, list);
for (Region region : list) {
System.out.println(region);
}
System.out.println(list.size());
} catch (Exception e) {
e.printStackTrace();
}
return regionVo;
}
private static void getRegions(RegionVo data, List<Region> list) {
list.add(getRegionFromRegionVo(data));
List<RegionVo> children = data.getChildren();
if (children == null) {
return;
}
for (RegionVo child : children) {
getRegions(child, list);
}
return;
}
public static Region getRegionFromRegionVo(RegionVo regionVo) {
Region region = new Region();
region.setOrgCode(regionVo.getOrgCode());
region.setOrgName(regionVo.getOrgName());
region.setOrgType(regionVo.getOrgType());
region.setParentCode(regionVo.getParentCode());
return region;
}
}