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