火车差标配置添加到数据库维护
This commit is contained in:
parent
d4b3faae80
commit
ae189b0ee3
|
@ -5,6 +5,7 @@ import com.chint.domain.exceptions.NotFoundException;
|
|||
import com.chint.domain.repository.TravelStandardsRepository;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -15,60 +16,39 @@ import static com.chint.infrastructure.constant.RankConstant.*;
|
|||
|
||||
@Component
|
||||
public class TrainStandardsService {
|
||||
public static final HashMap<String, String> trainStandardsMap;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TravelStandardsRepository travelStandardsRepository;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
List<TravelStandards> allTrain = travelStandardsRepository.findAllTrain();
|
||||
allTrain.forEach(it -> trainStandardsMap.put(it.getStandardLevel(), it.getPrice()));
|
||||
}
|
||||
// @PostConstruct
|
||||
// private void init() {
|
||||
// List<TravelStandards> allTrain = travelStandardsRepository.findAllTrain();
|
||||
// allTrain.forEach(it -> trainStandardsMap.put(it.getStandardLevel(), it.getPrice()));
|
||||
// }
|
||||
|
||||
@Cacheable(value = "TrainStandards" , key = "#standardLevel")
|
||||
public String priceTrainStandards(String standardLevel) {
|
||||
if (trainStandardsMap.containsKey(standardLevel)) {
|
||||
return trainStandardsMap.get(standardLevel);
|
||||
} else {
|
||||
List<TravelStandards> byStandardLevelAndProductType = travelStandardsRepository.
|
||||
findByStandardLevelAndProductType(standardLevel, String.valueOf(LEG_TYPE_TRAIN));
|
||||
if (byStandardLevelAndProductType.isEmpty()) {
|
||||
throw new NotFoundException("火车相关差标未配置,请联系管理员");
|
||||
}
|
||||
TravelStandards travelStandards = byStandardLevelAndProductType.get(0);
|
||||
trainStandardsMap.put(travelStandards.getStandardLevel(), travelStandards.getPrice());
|
||||
return travelStandards.getPrice();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
trainStandardsMap = new HashMap<>();
|
||||
//集团
|
||||
String oneStandards = "商务座,一等双软,一等座,二等座,高级软卧,一等双软";
|
||||
String twoStandards = "一等座,高级软卧,一等双软,动卧,软卧,硬卧,硬座";
|
||||
String threeStandards = "一等座,一等双软,二等座,软卧,硬卧,硬座";
|
||||
String fourStandards = "二等座,二等双软,软卧,无座,硬卧,硬座";
|
||||
trainStandardsMap.put(STANDARD_LEVEL_ONE, oneStandards);
|
||||
trainStandardsMap.put(STANDARD_LEVEL_TWO, twoStandards);
|
||||
trainStandardsMap.put(STANDARD_LEVEL_THREE, threeStandards);
|
||||
trainStandardsMap.put(STANDARD_LEVEL_FOUR, fourStandards);
|
||||
//仪表
|
||||
String oneStandardsYB = "一等座,高级软卧,一等双软,动卧,软卧,硬卧,硬座";
|
||||
String twoStandardsYB = "一等座,高级软卧,一等双软,动卧,软卧,硬卧,硬座";
|
||||
String threeStandardsYB = "一等座,一等双软,二等座,软卧,硬卧,硬座";
|
||||
String fourStandardsYB = "二等座,二等双软,软卧,无座,硬卧,硬座";
|
||||
trainStandardsMap.put(STANDARD_LEVEL_ONE_YB, oneStandardsYB);
|
||||
trainStandardsMap.put(STANDARD_LEVEL_TWO_YB, twoStandardsYB);
|
||||
trainStandardsMap.put(STANDARD_LEVEL_THREE_YB, threeStandardsYB);
|
||||
trainStandardsMap.put(STANDARD_LEVEL_FOUR_YB, fourStandardsYB);
|
||||
//物联
|
||||
String oneStandardsWL = "商务座,一等座,高级软卧,一等双软,动卧,软卧,硬卧,硬座";
|
||||
String twoStandardsWL = "一等座,高级软卧,一等双软,动卧,软卧,硬卧,硬座";
|
||||
String threeStandardsWL = "一等座,二等座,二等双软,动卧,软卧,硬卧,硬座";
|
||||
String fourStandardsWL = "二等座,二等双软,软卧,无座,硬卧,硬座";
|
||||
trainStandardsMap.put(STANDARD_LEVEL_ONE_WL, oneStandardsWL);
|
||||
trainStandardsMap.put(STANDARD_LEVEL_TWO_WL, twoStandardsWL);
|
||||
trainStandardsMap.put(STANDARD_LEVEL_THREE_WL, threeStandardsWL);
|
||||
trainStandardsMap.put(STANDARD_LEVEL_FOUR_WL, fourStandardsWL);
|
||||
List<TravelStandards> byStandardLevelAndProductType = travelStandardsRepository.
|
||||
findByStandardLevelAndProductType(standardLevel, String.valueOf(LEG_TYPE_TRAIN));
|
||||
if (byStandardLevelAndProductType.isEmpty()) {
|
||||
throw new NotFoundException("火车相关差标未配置,请联系管理员");
|
||||
}
|
||||
TravelStandards travelStandards = byStandardLevelAndProductType.get(0);
|
||||
return travelStandards.getPrice();
|
||||
|
||||
// if (trainStandardsMap.containsKey(standardLevel)) {
|
||||
// return trainStandardsMap.get(standardLevel);
|
||||
// } else {
|
||||
// List<TravelStandards> byStandardLevelAndProductType = travelStandardsRepository.
|
||||
// findByStandardLevelAndProductType(standardLevel, String.valueOf(LEG_TYPE_TRAIN));
|
||||
// if (byStandardLevelAndProductType.isEmpty()) {
|
||||
// throw new NotFoundException("火车相关差标未配置,请联系管理员");
|
||||
// }
|
||||
// TravelStandards travelStandards = byStandardLevelAndProductType.get(0);
|
||||
// trainStandardsMap.put(travelStandards.getStandardLevel(), travelStandards.getPrice());
|
||||
// return travelStandards.getPrice();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue