|
@@ -12,6 +12,7 @@ import javax.annotation.Resource;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -48,7 +49,6 @@ public class PolicyServiceImpl implements PolicyService {
|
|
|
public Long createPolicy(PolicySaveReqVO createReqVO) {
|
|
public Long createPolicy(PolicySaveReqVO createReqVO) {
|
|
|
// 插入
|
|
// 插入
|
|
|
PolicyDO policy = BeanUtils.toBean(createReqVO, PolicyDO.class);
|
|
PolicyDO policy = BeanUtils.toBean(createReqVO, PolicyDO.class);
|
|
|
- policy.setSurplusNum(createReqVO.getDiscountNum());
|
|
|
|
|
policyMapper.insert(policy);
|
|
policyMapper.insert(policy);
|
|
|
handlePolicyDetail(policy.getId(), createReqVO);
|
|
handlePolicyDetail(policy.getId(), createReqVO);
|
|
|
// 返回
|
|
// 返回
|
|
@@ -76,17 +76,17 @@ public class PolicyServiceImpl implements PolicyService {
|
|
|
List<Long> voyageIds = reqVO.getVoyageIds();
|
|
List<Long> voyageIds = reqVO.getVoyageIds();
|
|
|
List<Long> roomModelIds = reqVO.getRoomModelIds();
|
|
List<Long> roomModelIds = reqVO.getRoomModelIds();
|
|
|
List<Long> areaIds = reqVO.getAreaIds();
|
|
List<Long> areaIds = reqVO.getAreaIds();
|
|
|
|
|
+ BigDecimal discountNum = reqVO.getDiscountNum();
|
|
|
List<PolicyDetailDO> policyDetailDOList = new ArrayList<>();
|
|
List<PolicyDetailDO> policyDetailDOList = new ArrayList<>();
|
|
|
voyageIds.stream().forEach(voyageId -> {
|
|
voyageIds.stream().forEach(voyageId -> {
|
|
|
- roomModelIds.stream().forEach(roomModelId -> {
|
|
|
|
|
- PolicyDetailDO policyDetailDO = new PolicyDetailDO();
|
|
|
|
|
- policyDetailDO.setShipId(reqVO.getShipId());
|
|
|
|
|
- policyDetailDO.setPolicyId(policyId);
|
|
|
|
|
- policyDetailDO.setVoyageId(voyageId);
|
|
|
|
|
- policyDetailDO.setRoomModelId(roomModelId);
|
|
|
|
|
- policyDetailDO.setAreaIds(areaIds);
|
|
|
|
|
- policyDetailDOList.add(policyDetailDO);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ PolicyDetailDO policyDetailDO = new PolicyDetailDO();
|
|
|
|
|
+ policyDetailDO.setShipId(reqVO.getShipId());
|
|
|
|
|
+ policyDetailDO.setPolicyId(policyId);
|
|
|
|
|
+ policyDetailDO.setVoyageId(voyageId);
|
|
|
|
|
+ policyDetailDO.setRoomModelIds(roomModelIds);
|
|
|
|
|
+ policyDetailDO.setAreaIds(areaIds);
|
|
|
|
|
+ policyDetailDO.setSurplusNum(discountNum);
|
|
|
|
|
+ policyDetailDOList.add(policyDetailDO);
|
|
|
});
|
|
});
|
|
|
if(policyDetailDOList.size() > 0) {
|
|
if(policyDetailDOList.size() > 0) {
|
|
|
policyDetailMapper.insertBatch(policyDetailDOList);
|
|
policyDetailMapper.insertBatch(policyDetailDOList);
|
|
@@ -105,23 +105,25 @@ public class PolicyServiceImpl implements PolicyService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<PolicyDO> getUsablePolicy(PolicyUsableReqVO reqVO) {
|
|
|
|
|
|
|
+ public List<PolicyRespVO> getUsablePolicy(PolicyUsableReqVO reqVO) {
|
|
|
//获取区域列表
|
|
//获取区域列表
|
|
|
List<Long> countryIds = reqVO.getCountryIds();
|
|
List<Long> countryIds = reqVO.getCountryIds();
|
|
|
List<AreaCountryDTO> areaCountryDTOS = areaApi.getAreaCountryListByCountryIds(countryIds);
|
|
List<AreaCountryDTO> areaCountryDTOS = areaApi.getAreaCountryListByCountryIds(countryIds);
|
|
|
Set<Long> areaIds = CollectionUtils.convertSet(areaCountryDTOS, AreaCountryDTO::getAreaId);
|
|
Set<Long> areaIds = CollectionUtils.convertSet(areaCountryDTOS, AreaCountryDTO::getAreaId);
|
|
|
|
|
+ List<Long> roomModelIds = reqVO.getRoomModelIds();
|
|
|
VoyageDO voyage = voyageService.getVoyage(reqVO.getVoyageId());
|
|
VoyageDO voyage = voyageService.getVoyage(reqVO.getVoyageId());
|
|
|
- List<PolicyDetailDO> policyDetails = policyDetailMapper.selectList(reqVO.getVoyageId(), reqVO.getRoomModelIds());
|
|
|
|
|
- List<PolicyDetailDO> policyDetailDOList = new ArrayList<>();
|
|
|
|
|
- policyDetails.stream().forEach(policyDetailDO -> {
|
|
|
|
|
- areaIds.stream().forEach(areaId -> {
|
|
|
|
|
- if(policyDetailDO.getAreaIds() != null && policyDetailDO.getAreaIds().contains(areaId)) {
|
|
|
|
|
- policyDetailDOList.add(policyDetailDO);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- List<Long> policyIds = CollectionUtils.convertList(policyDetailDOList, PolicyDetailDO::getPolicyId);
|
|
|
|
|
|
|
+ List<PolicyDetailDO> policyDetails = policyDetailMapper.selectListByVoyageId(reqVO.getVoyageId());
|
|
|
|
|
+ List<PolicyDetailDO> filterPolicyDetails = policyDetails.stream().filter(policyDetailDO -> {
|
|
|
|
|
+ List<Long> areaIds1 = policyDetailDO.getAreaIds();
|
|
|
|
|
+ List<Long> roomModelIds1 = policyDetailDO.getRoomModelIds();
|
|
|
|
|
+ if(CollectionUtils.isAnyEmpty(areaIds1) || CollectionUtils.isAnyEmpty(roomModelIds1)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return areaIds1.stream().anyMatch(areaIds::contains) && roomModelIds1.stream().anyMatch(roomModelIds::contains);
|
|
|
|
|
+ }
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> policyIds = CollectionUtils.convertList(filterPolicyDetails, PolicyDetailDO::getPolicyId);
|
|
|
if(CollectionUtils.isAnyEmpty(policyIds)) {
|
|
if(CollectionUtils.isAnyEmpty(policyIds)) {
|
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
|
}
|
|
}
|
|
@@ -130,11 +132,21 @@ public class PolicyServiceImpl implements PolicyService {
|
|
|
LocalDateTime boardingTime = voyage.getBoardingTime();
|
|
LocalDateTime boardingTime = voyage.getBoardingTime();
|
|
|
return boardingTime.plusDays(policyDO.getEarlyDays() * -1L).compareTo(LocalDateTime.now()) > 0;
|
|
return boardingTime.plusDays(policyDO.getEarlyDays() * -1L).compareTo(LocalDateTime.now()) > 0;
|
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
|
- return result;
|
|
|
|
|
|
|
+ List<PolicyRespVO> policyRespVOS = BeanUtils.toBean(result, PolicyRespVO.class);
|
|
|
|
|
+ Map<Long, PolicyDetailDO> policyDetailDOMap = CollectionUtils.convertMap(filterPolicyDetails, PolicyDetailDO::getPolicyId);
|
|
|
|
|
+ policyRespVOS.stream().forEach(policyRespVO -> {
|
|
|
|
|
+ PolicyDetailDO policyDetailDO = policyDetailDOMap.get(policyRespVO.getId());
|
|
|
|
|
+ if(policyDetailDO != null) {
|
|
|
|
|
+ policyRespVO.setAreaIds(policyDetailDO.getAreaIds());
|
|
|
|
|
+ policyRespVO.setRoomModelIds(policyDetailDO.getRoomModelIds());
|
|
|
|
|
+ policyRespVO.setSurplusNum(policyDetailDO.getSurplusNum());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return policyRespVOS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<PolicyDO> getUsablePolicyByVoyageId(Long voyageId) {
|
|
|
|
|
|
|
+ public List<PolicyRespVO> getUsablePolicyByVoyageId(Long voyageId) {
|
|
|
VoyageDO voyage = voyageService.getVoyage(voyageId);
|
|
VoyageDO voyage = voyageService.getVoyage(voyageId);
|
|
|
List<PolicyDetailDO> policyDetails = policyDetailMapper.selectListByVoyageId(voyageId);
|
|
List<PolicyDetailDO> policyDetails = policyDetailMapper.selectListByVoyageId(voyageId);
|
|
|
List<Long> policyIds = CollectionUtils.convertList(policyDetails, PolicyDetailDO::getPolicyId);
|
|
List<Long> policyIds = CollectionUtils.convertList(policyDetails, PolicyDetailDO::getPolicyId);
|
|
@@ -146,7 +158,17 @@ public class PolicyServiceImpl implements PolicyService {
|
|
|
LocalDateTime boardingTime = voyage.getBoardingTime();
|
|
LocalDateTime boardingTime = voyage.getBoardingTime();
|
|
|
return boardingTime.plusDays(policyDO.getEarlyDays() * -1L).compareTo(LocalDateTime.now()) > 0;
|
|
return boardingTime.plusDays(policyDO.getEarlyDays() * -1L).compareTo(LocalDateTime.now()) > 0;
|
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
|
- return result;
|
|
|
|
|
|
|
+ List<PolicyRespVO> policyRespVOS = BeanUtils.toBean(result, PolicyRespVO.class);
|
|
|
|
|
+ Map<Long, PolicyDetailDO> policyDetailDOMap = CollectionUtils.convertMap(policyDetails, PolicyDetailDO::getPolicyId);
|
|
|
|
|
+ policyRespVOS.stream().forEach(policyRespVO -> {
|
|
|
|
|
+ PolicyDetailDO policyDetailDO = policyDetailDOMap.get(policyRespVO.getId());
|
|
|
|
|
+ if(policyDetailDO != null) {
|
|
|
|
|
+ policyRespVO.setAreaIds(policyDetailDO.getAreaIds());
|
|
|
|
|
+ policyRespVO.setRoomModelIds(policyDetailDO.getRoomModelIds());
|
|
|
|
|
+ policyRespVO.setSurplusNum(policyDetailDO.getSurplusNum());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return policyRespVOS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|