|
|
@@ -1,5 +1,6 @@
|
|
|
package com.yc.ship.module.marketing.service.policy;
|
|
|
|
|
|
+import com.yc.ship.framework.common.enums.CommonStatusEnum;
|
|
|
import com.yc.ship.framework.common.util.collection.CollectionUtils;
|
|
|
import com.yc.ship.module.marketing.dal.dataobject.policydetail.PolicyDetailDO;
|
|
|
import com.yc.ship.module.marketing.dal.mysql.policydetail.PolicyDetailMapper;
|
|
|
@@ -7,6 +8,8 @@ import com.yc.ship.module.product.dal.dataobject.voyage.VoyageDO;
|
|
|
import com.yc.ship.module.product.service.voyage.VoyageService;
|
|
|
import com.yc.ship.module.system.api.area.AreaApi;
|
|
|
import com.yc.ship.module.system.api.area.dto.AreaCountryDTO;
|
|
|
+import com.yc.ship.module.trade.api.dto.OrderPolicyDTO;
|
|
|
+import com.yc.ship.module.trade.api.trade.TradeApi;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
@@ -46,6 +49,10 @@ public class PolicyServiceImpl implements PolicyService {
|
|
|
|
|
|
@Resource
|
|
|
private VoyageService voyageService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TradeApi tradeApi;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Long createPolicy(PolicySaveReqVO createReqVO) {
|
|
|
@@ -146,8 +153,11 @@ public class PolicyServiceImpl implements PolicyService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<PolicyRespVO> getUsablePolicyByVoyageId(Long voyageId) {
|
|
|
+ public List<PolicyRespVO> getUsablePolicyByVoyageId(Long voyageId, Long orderId) {
|
|
|
+ List<OrderPolicyDTO> orderPolicyList = tradeApi.getOrderPolicyList(orderId);
|
|
|
+ List<Long> orderPolicyIds = CollectionUtils.convertList(orderPolicyList, OrderPolicyDTO::getPolicyId);
|
|
|
VoyageDO voyage = voyageService.getVoyage(voyageId);
|
|
|
+ LocalDateTime boardingTime = voyage.getBoardingTime();
|
|
|
List<PolicyDetailDO> policyDetails = policyDetailMapper.selectListByVoyageId(voyageId);
|
|
|
List<Long> policyIds = CollectionUtils.convertList(policyDetails, PolicyDetailDO::getPolicyId);
|
|
|
if(CollectionUtils.isAnyEmpty(policyIds)) {
|
|
|
@@ -155,8 +165,9 @@ public class PolicyServiceImpl implements PolicyService {
|
|
|
}
|
|
|
List<PolicyDO> policyList = policyMapper.selectList(policyIds);
|
|
|
List<PolicyDO> result = policyList.stream().filter(policyDO -> {
|
|
|
- LocalDateTime boardingTime = voyage.getBoardingTime();
|
|
|
- return boardingTime.plusDays(policyDO.getEarlyDays() * -1L).isAfter(LocalDateTime.now());
|
|
|
+ return (boardingTime.plusDays(policyDO.getEarlyDays() * -1L).isAfter(LocalDateTime.now())
|
|
|
+ && Objects.equals(policyDO.getStatus(), CommonStatusEnum.ENABLE.getStatus()))
|
|
|
+ || orderPolicyIds.contains(policyDO.getId());
|
|
|
}).collect(Collectors.toList());
|
|
|
List<PolicyRespVO> policyRespVOS = BeanUtils.toBean(result, PolicyRespVO.class);
|
|
|
Map<Long, PolicyDetailDO> policyDetailDOMap = CollectionUtils.convertMap(policyDetails, PolicyDetailDO::getPolicyId);
|
|
|
@@ -170,6 +181,16 @@ public class PolicyServiceImpl implements PolicyService {
|
|
|
policyRespVO.setRoomModelIds(policyDetailDO.getRoomModelIds());
|
|
|
policyRespVO.setSurplusNum(policyDetailDO.getSurplusNum());
|
|
|
}
|
|
|
+ if(Objects.equals(policyRespVO.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
|
|
|
+ policyRespVO.setCanAddRoom(false);
|
|
|
+ policyRespVO.setName(policyRespVO.getName()+"(已下架)");
|
|
|
+ } else {
|
|
|
+ if (boardingTime.plusDays(policyRespVO.getEarlyDays() * -1L).isAfter(LocalDateTime.now())) {
|
|
|
+ policyRespVO.setCanAddRoom(true);
|
|
|
+ } else {
|
|
|
+ policyRespVO.setCanAddRoom(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
return policyRespVOS;
|
|
|
}
|