|
|
@@ -108,9 +108,314 @@ public class PriceTemplateServiceImpl implements PriceTemplateService {
|
|
|
// 更新
|
|
|
PriceTemplateDO updateObj = BeanUtils.toBean(updateReqVO, PriceTemplateDO.class);
|
|
|
priceTemplateMapper.updateById(updateObj);
|
|
|
- deleteRelation(id);
|
|
|
- saveRelation(id, updateReqVO);
|
|
|
+ // 修改相关关联数据,表里存在的修改,不存在的新增,删除的则直接删除
|
|
|
+ updateRelationIncremental(id, updateReqVO);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateRelationIncremental(Long objectId, PriceTemplateSaveReqVO vo) {
|
|
|
+ // 更新房型价格系数
|
|
|
+ updateRoomModels(objectId, vo.getRoomModelList());
|
|
|
+ // 更新楼层价格系数
|
|
|
+ updateFloors(objectId, vo.getFloorList());
|
|
|
+ // 更新区域加价
|
|
|
+ updateAreas(objectId, vo.getAreaList());
|
|
|
+ // 更新区域基准价
|
|
|
+ updateBasicAreas(objectId, vo.getBasicAreaList());
|
|
|
+ // 更新附加产品
|
|
|
+ updateSpus(objectId, vo.getSpuList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateRoomModels(Long objectId, List<PriceRoomModelDO> roomModelList) {
|
|
|
+ if (CollectionUtils.isAnyEmpty(roomModelList)) {
|
|
|
+ priceRoomModelMapper.deleteByObjectId(objectId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 查询出现在数据库中的数据
|
|
|
+ List<PriceRoomModelDO> existingList = priceRoomModelMapper.selectListByObjectId(objectId);
|
|
|
+ Map<Long, PriceRoomModelDO> existingMap = CollectionUtils.convertMap(existingList, PriceRoomModelDO::getId);
|
|
|
+
|
|
|
+ List<PriceRoomModelDO> toInsert = new ArrayList<>();
|
|
|
+ List<PriceRoomModelDO> toUpdate = new ArrayList<>();
|
|
|
+ List<Long> frontIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (PriceRoomModelDO roomModel : roomModelList) {
|
|
|
+ if (roomModel.getId() == null) {
|
|
|
+ // 不存在,则插入
|
|
|
+ roomModel.setObjectId(objectId);
|
|
|
+ toInsert.add(roomModel);
|
|
|
+ } else {
|
|
|
+ // 原有数据,则更新
|
|
|
+ frontIds.add(roomModel.getId());
|
|
|
+ roomModel.setObjectId(objectId);
|
|
|
+ toUpdate.add(roomModel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!toInsert.isEmpty()) {
|
|
|
+ priceRoomModelMapper.insertBatch(toInsert);
|
|
|
+ }
|
|
|
+ if (!toUpdate.isEmpty()) {
|
|
|
+ priceRoomModelMapper.updateBatch(toUpdate);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> toDeleteIds = existingMap.keySet().stream()
|
|
|
+ .filter(id -> !frontIds.contains(id))
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
+ if (!toDeleteIds.isEmpty()) {
|
|
|
+ priceRoomModelMapper.deleteByIds(toDeleteIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (PriceRoomModelDO roomModel : roomModelList) {
|
|
|
+ // 更新房型入住模式
|
|
|
+ updateRoomModelTypes(objectId, roomModel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateRoomModelTypes(Long objectId, PriceRoomModelDO roomModel) {
|
|
|
+ List<PriceRoomModelTypeDO> roomModelTypeList = roomModel.getRoomModelTypeList();
|
|
|
+ if (CollectionUtils.isAnyEmpty(roomModelTypeList)) {
|
|
|
+ priceRoomModelTypeMapper.deleteByObjectIdAndRoomModelId(objectId, roomModel.getRoomModelId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PriceRoomModelTypeDO> existingList = priceRoomModelTypeMapper.selectByObjectIdAndRoomModelId(objectId, roomModel.getRoomModelId());
|
|
|
+ Map<Long, PriceRoomModelTypeDO> existingMap = CollectionUtils.convertMap(existingList, PriceRoomModelTypeDO::getId);
|
|
|
+
|
|
|
+ List<PriceRoomModelTypeDO> toInsert = new ArrayList<>();
|
|
|
+ List<PriceRoomModelTypeDO> toUpdate = new ArrayList<>();
|
|
|
+ List<PriceSingleSettingDO> singleSettingToInsert = new ArrayList<>();
|
|
|
+ List<PriceSingleSettingDO> singleSettingToUpdate = new ArrayList<>();
|
|
|
+ List<Long> frontIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (PriceRoomModelTypeDO roomModelType : roomModelTypeList) {
|
|
|
+ if (roomModelType.getId() == null) {
|
|
|
+ Long roomModelTypeId = IdUtil.getSnowflakeNextId();
|
|
|
+ roomModelType.setId(roomModelTypeId);
|
|
|
+ roomModelType.setRoomModelId(roomModel.getRoomModelId());
|
|
|
+ roomModelType.setRoomModelName(roomModel.getRoomModelName());
|
|
|
+ roomModelType.setObjectId(objectId);
|
|
|
+ toInsert.add(roomModelType);
|
|
|
+ } else {
|
|
|
+ frontIds.add(roomModelType.getId());
|
|
|
+ roomModelType.setObjectId(objectId);
|
|
|
+ toUpdate.add(roomModelType);
|
|
|
+ }
|
|
|
+
|
|
|
+ PriceSingleSettingDO singleSetting = roomModelType.getSingleSetting();
|
|
|
+ if (singleSetting != null) {
|
|
|
+ if (singleSetting.getId() == null) {
|
|
|
+ singleSetting.setRoomModelId(roomModel.getRoomModelId());
|
|
|
+ singleSetting.setObjectId(objectId);
|
|
|
+ singleSetting.setRoomModelTypeId(roomModelType.getId());
|
|
|
+ singleSettingToInsert.add(singleSetting);
|
|
|
+ } else {
|
|
|
+ singleSetting.setObjectId(objectId);
|
|
|
+ singleSettingToUpdate.add(singleSetting);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!toInsert.isEmpty()) {
|
|
|
+ priceRoomModelTypeMapper.insertBatch(toInsert);
|
|
|
+ }
|
|
|
+ if (!toUpdate.isEmpty()) {
|
|
|
+ priceRoomModelTypeMapper.updateBatch(toUpdate);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> toDeleteIds = existingMap.keySet().stream()
|
|
|
+ .filter(id -> !frontIds.contains(id))
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
+ if (!toDeleteIds.isEmpty()) {
|
|
|
+ priceRoomModelTypeMapper.deleteByIds(toDeleteIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!singleSettingToInsert.isEmpty()) {
|
|
|
+ priceSingleSettingMapper.insertBatch(singleSettingToInsert);
|
|
|
+ }
|
|
|
+ if (!singleSettingToUpdate.isEmpty()) {
|
|
|
+ priceSingleSettingMapper.updateBatch(singleSettingToUpdate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateFloors(Long objectId, List<PriceFloorDO> floorList) {
|
|
|
+ if (CollectionUtils.isAnyEmpty(floorList)) {
|
|
|
+ priceFloorMapper.deleteByObjectId(objectId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PriceFloorDO> existingList = priceFloorMapper.selectListByObjectId(objectId);
|
|
|
+ Map<Long, PriceFloorDO> existingMap = CollectionUtils.convertMap(existingList, PriceFloorDO::getId);
|
|
|
+
|
|
|
+ List<PriceFloorDO> toInsert = new ArrayList<>();
|
|
|
+ List<PriceFloorDO> toUpdate = new ArrayList<>();
|
|
|
+ List<Long> frontIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (PriceFloorDO floor : floorList) {
|
|
|
+ if (floor.getId() == null) {
|
|
|
+ floor.setObjectId(objectId);
|
|
|
+ toInsert.add(floor);
|
|
|
+ } else {
|
|
|
+ frontIds.add(floor.getId());
|
|
|
+ floor.setObjectId(objectId);
|
|
|
+ toUpdate.add(floor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!toInsert.isEmpty()) {
|
|
|
+ priceFloorMapper.insertBatch(toInsert);
|
|
|
+ }
|
|
|
+ if (!toUpdate.isEmpty()) {
|
|
|
+ priceFloorMapper.updateBatch(toUpdate);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> toDeleteIds = existingMap.keySet().stream()
|
|
|
+ .filter(id -> !frontIds.contains(id))
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
+ if (!toDeleteIds.isEmpty()) {
|
|
|
+ priceFloorMapper.deleteByIds(toDeleteIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateAreas(Long objectId, List<PriceAreaDO> areaList) {
|
|
|
+ if (CollectionUtils.isAnyEmpty(areaList)) {
|
|
|
+ priceAreaMapper.deleteByObjectId(objectId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ List<PriceAreaDO> existingList = priceAreaMapper.selectListByObjectId(objectId);
|
|
|
+ Map<Long, PriceAreaDO> existingMap = CollectionUtils.convertMap(existingList, PriceAreaDO::getId);
|
|
|
+
|
|
|
+ List<PriceAreaDO> toInsert = new ArrayList<>();
|
|
|
+ List<PriceAreaDO> toUpdate = new ArrayList<>();
|
|
|
+ List<Long> frontIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (PriceAreaDO area : areaList) {
|
|
|
+ processAreaForBatch(objectId, area, frontIds, toInsert, toUpdate);
|
|
|
+ List<PriceAreaDO> children = area.getChildren();
|
|
|
+ if (!CollectionUtils.isAnyEmpty(children)) {
|
|
|
+ for (PriceAreaDO child : children) {
|
|
|
+ child.setParentAreaId(area.getAreaId());
|
|
|
+ child.setParentAreaName(area.getAreaName());
|
|
|
+ processAreaForBatch(objectId, child, frontIds, toInsert, toUpdate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!toInsert.isEmpty()) {
|
|
|
+ priceAreaMapper.insertBatch(toInsert);
|
|
|
+ }
|
|
|
+ if (!toUpdate.isEmpty()) {
|
|
|
+ priceAreaMapper.updateBatch(toUpdate);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> toDeleteIds = existingMap.keySet().stream()
|
|
|
+ .filter(id -> !frontIds.contains(id))
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
+ if (!toDeleteIds.isEmpty()) {
|
|
|
+ priceAreaMapper.deleteByIds(toDeleteIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processAreaForBatch(Long objectId, PriceAreaDO area, List<Long> frontIds, List<PriceAreaDO> toInsert, List<PriceAreaDO> toUpdate) {
|
|
|
+ if (area.getId() == null) {
|
|
|
+ area.setObjectId(objectId);
|
|
|
+ toInsert.add(area);
|
|
|
+ } else {
|
|
|
+ frontIds.add(area.getId());
|
|
|
+ area.setObjectId(objectId);
|
|
|
+ toUpdate.add(area);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateBasicAreas(Long objectId, List<BasicPriceAreaDO> basicAreaList) {
|
|
|
+ if (CollectionUtils.isAnyEmpty(basicAreaList)) {
|
|
|
+ basicPriceAreaMapper.deleteByObjectId(objectId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BasicPriceAreaDO> existingList = basicPriceAreaMapper.selectListByObjectId(objectId);
|
|
|
+ Map<Long, BasicPriceAreaDO> existingMap = CollectionUtils.convertMap(existingList, BasicPriceAreaDO::getId);
|
|
|
+
|
|
|
+ List<BasicPriceAreaDO> toInsert = new ArrayList<>();
|
|
|
+ List<BasicPriceAreaDO> toUpdate = new ArrayList<>();
|
|
|
+ List<Long> frontIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (BasicPriceAreaDO area : basicAreaList) {
|
|
|
+ processBasicAreaForBatch(objectId, area, frontIds, toInsert, toUpdate);
|
|
|
+ List<BasicPriceAreaDO> children = area.getChildren();
|
|
|
+ if (!CollectionUtils.isAnyEmpty(children)) {
|
|
|
+ for (BasicPriceAreaDO child : children) {
|
|
|
+ child.setParentAreaId(area.getAreaId());
|
|
|
+ child.setParentAreaName(area.getAreaName());
|
|
|
+ processBasicAreaForBatch(objectId, child, frontIds, toInsert, toUpdate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!toInsert.isEmpty()) {
|
|
|
+ basicPriceAreaMapper.insertBatch(toInsert);
|
|
|
+ }
|
|
|
+ if (!toUpdate.isEmpty()) {
|
|
|
+ basicPriceAreaMapper.updateBatch(toUpdate);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> toDeleteIds = existingMap.keySet().stream()
|
|
|
+ .filter(id -> !frontIds.contains(id))
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
+ if (!toDeleteIds.isEmpty()) {
|
|
|
+ basicPriceAreaMapper.deleteByIds(toDeleteIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processBasicAreaForBatch(Long objectId, BasicPriceAreaDO area, List<Long> frontIds, List<BasicPriceAreaDO> toInsert, List<BasicPriceAreaDO> toUpdate) {
|
|
|
+ if (area.getId() == null) {
|
|
|
+ area.setObjectId(objectId);
|
|
|
+ toInsert.add(area);
|
|
|
+ } else {
|
|
|
+ frontIds.add(area.getId());
|
|
|
+ area.setObjectId(objectId);
|
|
|
+ toUpdate.add(area);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateSpus(Long objectId, List<PriceSpuDO> spuList) {
|
|
|
+ if (CollectionUtils.isAnyEmpty(spuList)) {
|
|
|
+ priceSpuMapper.deleteByObjectId(objectId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PriceSpuDO> existingList = priceSpuMapper.selectListByObjectId(objectId);
|
|
|
+ Map<Long, PriceSpuDO> existingMap = CollectionUtils.convertMap(existingList, PriceSpuDO::getId);
|
|
|
+
|
|
|
+ List<PriceSpuDO> toInsert = new ArrayList<>();
|
|
|
+ List<PriceSpuDO> toUpdate = new ArrayList<>();
|
|
|
+ List<Long> frontIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (PriceSpuDO spu : spuList) {
|
|
|
+ if (spu.getId() == null) {
|
|
|
+ spu.setObjectId(objectId);
|
|
|
+ toInsert.add(spu);
|
|
|
+ } else {
|
|
|
+ frontIds.add(spu.getId());
|
|
|
+ spu.setObjectId(objectId);
|
|
|
+ toUpdate.add(spu);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!toInsert.isEmpty()) {
|
|
|
+ priceSpuMapper.insertBatch(toInsert);
|
|
|
+ }
|
|
|
+ if (!toUpdate.isEmpty()) {
|
|
|
+ priceSpuMapper.updateBatch(toUpdate);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> toDeleteIds = existingMap.keySet().stream()
|
|
|
+ .filter(id -> !frontIds.contains(id))
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
+ if (!toDeleteIds.isEmpty()) {
|
|
|
+ priceSpuMapper.deleteByIds(toDeleteIds);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -185,6 +490,7 @@ public class PriceTemplateServiceImpl implements PriceTemplateService {
|
|
|
//插入房型价格系数
|
|
|
List<PriceRoomModelDO> roomModelList = vo.getRoomModelList();
|
|
|
roomModelList.stream().forEach(roomModel -> {
|
|
|
+ roomModel.setId(null);
|
|
|
roomModel.setObjectId(objectId);
|
|
|
});
|
|
|
priceRoomModelMapper.insertBatch(roomModelList);
|
|
|
@@ -205,6 +511,7 @@ public class PriceTemplateServiceImpl implements PriceTemplateService {
|
|
|
roomModelTypeDOList.add(roomModelType);
|
|
|
PriceSingleSettingDO singleSetting = roomModelType.getSingleSetting();
|
|
|
if(singleSetting != null) {
|
|
|
+ singleSetting.setId(null);
|
|
|
singleSetting.setRoomModelId(roomModel.getRoomModelId());
|
|
|
singleSetting.setObjectId(objectId);
|
|
|
singleSetting.setRoomModelTypeId(roomModelTypeId);
|
|
|
@@ -222,6 +529,7 @@ public class PriceTemplateServiceImpl implements PriceTemplateService {
|
|
|
//插入楼层价格系数
|
|
|
List<PriceFloorDO> floorList = vo.getFloorList();
|
|
|
floorList.stream().forEach(floor -> {
|
|
|
+ floor.setId(null);
|
|
|
floor.setObjectId(objectId);
|
|
|
});
|
|
|
if(floorList.size() > 0) {
|
|
|
@@ -231,12 +539,14 @@ public class PriceTemplateServiceImpl implements PriceTemplateService {
|
|
|
List<PriceAreaDO> areaList = vo.getAreaList();
|
|
|
List<PriceAreaDO> insertAreaList = new ArrayList<>();
|
|
|
areaList.stream().forEach(area -> {
|
|
|
+ area.setId(null);
|
|
|
area.setObjectId(objectId);
|
|
|
insertAreaList.add(area);
|
|
|
List<PriceAreaDO> children = area.getChildren();
|
|
|
if (children != null) {
|
|
|
children.stream().forEach(child -> {
|
|
|
child.setObjectId(objectId);
|
|
|
+ child.setId(null);
|
|
|
child.setParentAreaId(area.getAreaId());
|
|
|
child.setParentAreaName(area.getAreaName());
|
|
|
insertAreaList.add(child);
|
|
|
@@ -251,11 +561,13 @@ public class PriceTemplateServiceImpl implements PriceTemplateService {
|
|
|
List<BasicPriceAreaDO> basicAreaList = vo.getBasicAreaList();
|
|
|
List<BasicPriceAreaDO> insertBasicAreaList = new ArrayList<>();
|
|
|
basicAreaList.stream().forEach(area -> {
|
|
|
+ area.setId(null);
|
|
|
area.setObjectId(objectId);
|
|
|
insertBasicAreaList.add(area);
|
|
|
List<BasicPriceAreaDO> children = area.getChildren();
|
|
|
if (children != null) {
|
|
|
children.stream().forEach(child -> {
|
|
|
+ child.setId(null);
|
|
|
child.setObjectId(objectId);
|
|
|
child.setParentAreaId(area.getAreaId());
|
|
|
child.setParentAreaName(area.getAreaName());
|
|
|
@@ -270,6 +582,7 @@ public class PriceTemplateServiceImpl implements PriceTemplateService {
|
|
|
List<PriceSpuDO> spuList = vo.getSpuList();
|
|
|
if(!CollectionUtils.isAnyEmpty(spuList)) {
|
|
|
spuList.stream().forEach(spu -> {
|
|
|
+ spu.setId(null);
|
|
|
spu.setObjectId(objectId);
|
|
|
});
|
|
|
priceSpuMapper.insertBatch(spuList);
|