1、excel格式大致这样
2、一级不能相同,二三级都可以,但是不能在同级下面出现相同的
3、具体的代码映射我就不写了,直接得到对应的集合
public int importAssetTaskType(List<ImportAssetTaskTypeVo> assetTaskTypeList) {
List<ItopsAsset> resultAsset = new ArrayList<>();
Map<String, Long> oneMap = new HashMap<>();//标识不能有重复的一级
Map<String, Long> twoMap = new HashMap<>();//标识不能有重复的二级(做第一次判断)
Map<String, String> twoKeyOneKey = new HashMap<>();//放二级名字和一级名字使用
Map<String, Long> threeMap = new HashMap<>();//识不能有重复的三级(做第一次判断)
Map<String, String> three2Map = new HashMap<>();//标识在一级下面不能有重复的二级
Map<String, String> threeMap1 = new HashMap<>();//标识三级上面不能有重复的
List<ImportAssetTaskTypeVo> resultList = new ArrayList<>();
for (ImportAssetTaskTypeVo importAssetTaskTypeVo : assetTaskTypeList) {
String oneLevel = importAssetTaskTypeVo.getOneLevel();
String twoLevel = importAssetTaskTypeVo.getTwoLevel();
String threeLevel = importAssetTaskTypeVo.getThreeLevel();
if (!oneMap.containsKey(oneLevel)){//如果当前一级名称重复,就不会再次添加
Long oneId = DistributedIdUtil.getDistributedIdBySnowFlake();//唯一主键
oneMap.put(oneLevel,oneId);//为的是在录入二级的时候得到父id
ImportAssetTaskTypeVo taskTypeVo = new ImportAssetTaskTypeVo();
taskTypeVo.setAssetTaskTypeId(oneId);//主键
taskTypeVo.setAssetName(oneLevel);//级别名称
taskTypeVo.setTypeLevel(1);//标识几级数据
taskTypeVo.setParentId(0L);//父id
resultList.add(taskTypeVo);
}
if (!twoMap.containsKey(twoLevel) || !oneLevel.equals(twoKeyOneKey.get(twoLevel))){
twoKeyOneKey.put(twoLevel,oneLevel);
Long oneId = oneMap.get(oneLevel);//得到当前二级的父id
Long twoId = DistributedIdUtil.getDistributedIdBySnowFlake();
ImportAssetTaskTypeVo taskTypeVo = new ImportAssetTaskTypeVo();
taskTypeVo.setAssetTaskTypeId(twoId);
taskTypeVo.setAssetName(twoLevel);
taskTypeVo.setTypeLevel(2);
taskTypeVo.setParentId(oneId);
taskTypeVo.setParentName(oneLevel);
twoMap.put(twoLevel,twoId);//防止重复的二级进入
resultList.add(taskTypeVo);
}
if (!threeMap.containsKey(threeLevel) || !three2Map.containsKey(oneLevel) || !threeLevel.equals(threeMap1.get(twoLevel))){
threeMap1.put(twoLevel,threeLevel);//保存当前三级的二级名称,目的是不让当前三级出现在童一个二级下
three2Map.put(oneLevel,threeLevel);//保存当前二级的父级名称
Long twoId = twoMap.get(twoLevel);//获取到当前三级的父id
Long threeId = DistributedIdUtil.getDistributedIdBySnowFlake();
Long assetTaskTypeId = DistributedIdUtil.getDistributedIdBySnowFlake();//资产台账中使用到的id
ImportAssetTaskTypeVo taskTypeVo = new ImportAssetTaskTypeVo();
taskTypeVo.setAssetTaskTypeId(threeId);
taskTypeVo.setAssetName(threeLevel);
taskTypeVo.setTypeLevel(3);
taskTypeVo.setParentId(twoId);
taskTypeVo.setParentName(twoLevel);
threeMap.put(threeLevel,threeId);
resultList.add(taskTypeVo);
itopsAsset.setAssetTaskTypeId(assetTaskTypeId);
itopsAsset.setAssetParentId(threeId);
}
resultAsset.add(itopsAsset);
}
int count = itopsAssetTaskTypeMapper.addBatch(resultList);//批量添加数据
return count;
}