|
|
@ -17,7 +17,6 @@ |
|
|
|
|
|
|
|
package com.epmet.service.screen.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
@ -31,11 +30,14 @@ import com.epmet.entity.screen.IndexGroupDetailTemplateEntity; |
|
|
|
import com.epmet.entity.screen.IndexGroupEntity; |
|
|
|
import com.epmet.entity.screen.IndexGroupTemplateEntity; |
|
|
|
import com.epmet.service.screen.IndexGroupService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
@ -47,6 +49,7 @@ import java.util.stream.Collectors; |
|
|
|
* @author generator generator@elink-cn.com |
|
|
|
* @since v1.0.0 2020-08-19 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class IndexGroupServiceImpl extends BaseServiceImpl<IndexGroupDao, IndexGroupEntity> implements IndexGroupService { |
|
|
|
@Autowired |
|
|
@ -67,30 +70,49 @@ private IndexGroupTemplateDao indexGroupTemplateDao; |
|
|
|
} |
|
|
|
Map<String, IndexGroupTemplateEntity> groupMap = groupTempList.stream().collect(Collectors.toMap(IndexGroupTemplateEntity::getId, o -> o)); |
|
|
|
Map<String,IndexGroupEntity> groupEntityMap = new HashMap<>(); |
|
|
|
Map<String,String> groupNewIdMap = new HashMap<>(); |
|
|
|
|
|
|
|
groupDetailTempList.forEach(groupDetailTemp->{ |
|
|
|
String indexGroupId = groupDetailTemp.getIndexGroupId(); |
|
|
|
IndexGroupTemplateEntity group = groupMap.get(indexGroupId); |
|
|
|
if (group == null){ |
|
|
|
System.out.println(JSON.toJSONString(groupDetailTemp)); |
|
|
|
List<IndexGroupEntity> insertGroupList = new ArrayList<>(); |
|
|
|
groupMap.forEach((oldGroupTempId,o)->{ |
|
|
|
IndexGroupEntity newGroupEntity = ConvertUtils.sourceToTarget(o, IndexGroupEntity.class); |
|
|
|
String newGroupId = UniqueIdGenerator.generate(); |
|
|
|
newGroupEntity.setId(newGroupId); |
|
|
|
newGroupEntity.setCustomerId(customerId); |
|
|
|
String oldPid = newGroupEntity.getParentIndexGroupId(); |
|
|
|
String newPid = groupNewIdMap.get(oldPid); |
|
|
|
/*if (StringUtils.isBlank(newPid)){ |
|
|
|
newPid = UniqueIdGenerator.generate(); |
|
|
|
groupNewIdMap.put(oldPid,newPid); |
|
|
|
}*/ |
|
|
|
//newGroupEntity.setParentIndexGroupId(newPid);
|
|
|
|
groupNewIdMap.put(oldGroupTempId,newGroupId); |
|
|
|
//groupEntityMap.put(newGroupId,newGroupEntity);
|
|
|
|
insertGroupList.add(newGroupEntity); |
|
|
|
}); |
|
|
|
insertGroupList.forEach(o-> { |
|
|
|
String parentIndexGroupId = groupNewIdMap.get(o.getParentIndexGroupId()); |
|
|
|
if (StringUtils.isBlank(parentIndexGroupId)){ |
|
|
|
parentIndexGroupId = "0"; |
|
|
|
} |
|
|
|
o.setParentIndexGroupId(parentIndexGroupId); |
|
|
|
}); |
|
|
|
groupDetailTempList.forEach(groupDetailTemp->{ |
|
|
|
String oldIndexGroupId = groupDetailTemp.getIndexGroupId(); |
|
|
|
System.out.println(oldIndexGroupId); |
|
|
|
|
|
|
|
IndexGroupEntity groupEntity = groupEntityMap.get(indexGroupId); |
|
|
|
if (groupEntity == null){ |
|
|
|
groupEntity = ConvertUtils.sourceToTarget(group, IndexGroupEntity.class); |
|
|
|
String groupId = UniqueIdGenerator.generate(); |
|
|
|
groupEntity.setId(groupId); |
|
|
|
groupEntity.setCustomerId(customerId); |
|
|
|
groupEntityMap.put(indexGroupId,groupEntity); |
|
|
|
} |
|
|
|
|
|
|
|
IndexGroupDetailEntity entity = ConvertUtils.sourceToTarget(groupDetailTemp, IndexGroupDetailEntity.class); |
|
|
|
entity.setId(UniqueIdGenerator.generate()); |
|
|
|
entity.setIndexGroupId(groupEntity.getId()); |
|
|
|
String newGroupId = groupNewIdMap.get(oldIndexGroupId); |
|
|
|
if (StringUtils.isBlank(newGroupId)){ |
|
|
|
log.error("新旧id映射关系有误"); |
|
|
|
return; |
|
|
|
} |
|
|
|
entity.setIndexGroupId(newGroupId); |
|
|
|
entity.setCustomerId(customerId); |
|
|
|
indexGroupDetailDao.insert(entity); |
|
|
|
}); |
|
|
|
this.insertBatch(groupEntityMap.values(),10); |
|
|
|
this.insertBatch(insertGroupList,10); |
|
|
|
|
|
|
|
|
|
|
|
/* List<IndexGroupEntity> groupEntityList = groupTempList.stream().map(groupTemp -> { |
|
|
|