火车差标配置添加到数据库维护

This commit is contained in:
lulz1 2024-03-22 14:25:53 +08:00
parent d4b3faae80
commit ae189b0ee3
1 changed files with 28 additions and 48 deletions

View File

@ -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.
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 { List<TravelStandards> byStandardLevelAndProductType = travelStandardsRepository.
trainStandardsMap = new HashMap<>(); findByStandardLevelAndProductType(standardLevel, String.valueOf(LEG_TYPE_TRAIN));
//集团 if (byStandardLevelAndProductType.isEmpty()) {
String oneStandards = "商务座,一等双软,一等座,二等座,高级软卧,一等双软"; throw new NotFoundException("火车相关差标未配置,请联系管理员");
String twoStandards = "一等座,高级软卧,一等双软,动卧,软卧,硬卧,硬座"; }
String threeStandards = "一等座,一等双软,二等座,软卧,硬卧,硬座"; TravelStandards travelStandards = byStandardLevelAndProductType.get(0);
String fourStandards = "二等座,二等双软,软卧,无座,硬卧,硬座"; return travelStandards.getPrice();
trainStandardsMap.put(STANDARD_LEVEL_ONE, oneStandards);
trainStandardsMap.put(STANDARD_LEVEL_TWO, twoStandards); // if (trainStandardsMap.containsKey(standardLevel)) {
trainStandardsMap.put(STANDARD_LEVEL_THREE, threeStandards); // return trainStandardsMap.get(standardLevel);
trainStandardsMap.put(STANDARD_LEVEL_FOUR, fourStandards); // } else {
//仪表 // List<TravelStandards> byStandardLevelAndProductType = travelStandardsRepository.
String oneStandardsYB = "一等座,高级软卧,一等双软,动卧,软卧,硬卧,硬座"; // findByStandardLevelAndProductType(standardLevel, String.valueOf(LEG_TYPE_TRAIN));
String twoStandardsYB = "一等座,高级软卧,一等双软,动卧,软卧,硬卧,硬座"; // if (byStandardLevelAndProductType.isEmpty()) {
String threeStandardsYB = "一等座,一等双软,二等座,软卧,硬卧,硬座"; // throw new NotFoundException("火车相关差标未配置,请联系管理员");
String fourStandardsYB = "二等座,二等双软,软卧,无座,硬卧,硬座"; // }
trainStandardsMap.put(STANDARD_LEVEL_ONE_YB, oneStandardsYB); // TravelStandards travelStandards = byStandardLevelAndProductType.get(0);
trainStandardsMap.put(STANDARD_LEVEL_TWO_YB, twoStandardsYB); // trainStandardsMap.put(travelStandards.getStandardLevel(), travelStandards.getPrice());
trainStandardsMap.put(STANDARD_LEVEL_THREE_YB, threeStandardsYB); // return travelStandards.getPrice();
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);
} }
} }