昨天写的条件匹配被吐槽太low,直接在serviceImpl实现类里面加了写死的中文条件匹配,应该用enum枚举,这样的代码更高效简洁。
贴上前辈改的条件查询,里面的priceList.stream().collect(Collectors.groupingBy(x -> x.getLoadStandard()));不太懂,会有关于这一块详细的学习记录。
serviceImpl实现类相关代码块实现
List<String> loadStandList = new ArrayList<>();
loadStandList.add(LoadStandardEnum.USUAL.getCode()); // 标准
loadStandList.add(LoadStandardEnum.UNUSUAL_SMALL.getCode()); // 非标小
loadStandList.add(LoadStandardEnum.UNUSUAL_LARGE.getCode()); // 非标大
for (int i = 0; i < len; i++) {
bid = bidList.get(i);
// 报价
String price = null;
String totalTrainNum = null;
String offerCapacity = null;
List<TBidModel> priceList = bid.gettBidModelsThree();
Map<String, List<TBidModel>> priceMap = priceList
.stream()
.collect(Collectors.groupingBy(x -> x.getLoadStandard()));
String tempStr1 = "";
String tempStr2 = "";
String tempStr3 = "";
String tempStr4 = "";
for(String loadStand: loadStandList) {
List<TBidModel> list = priceMap.get(loadStand);
if (EmptyUtil.isEmpty(list)) {
tempStr1 += "N/";
tempStr2 += "N/";
tempStr3 += "N/";
tempStr4 += "N/";
} else {
TBidModel tbm = list.get(0);
if (hiredType == hiredYesCode) {
price = settleType == taxYesCode ? tbm.getOfferHiredPriceTax(): tbm.getOfferHiredPriceTaxNo();
} else {
price = settleType == taxYesCode ? tbm.getOfferPriceTax(): tbm.getOfferPriceTaxNo();
}
totalTrainNum = tbm.getTotalTrainNum();
offerCapacity = tbm.getCapacity();
tempStr1 += price + "/";
tempStr2 += offerCapacity + "/";
tempStr3 += totalTrainNum + "/";
if (DecimalUtil.isNumeric(offerCapacity) && DecimalUtil.isNumeric(totalTrainNum)) {
tempStr4 += DecimalUtil.divide(offerCapacity, totalTrainNum, 2) + "/";
} else {
tempStr4 += "N/";
}
}
}
tempStr1 = tempStr1.substring(0, tempStr1.length() - 1);
tempStr2 = tempStr2.substring(0, tempStr2.length() - 1);
tempStr3 = tempStr3.substring(0, tempStr3.length() - 1);
tempStr4 = tempStr4.substring(0, tempStr4.length() - 1);
row.put("bidderName" + i , bid.getBidderCompanyName());
row.put("offerPrice" + i, tempStr1);
row.put("offerCapacity" + i, tempStr2);
row.put("totalTrainNum" + i, tempStr3);
row.put("vehicleCapacity" + i, tempStr4);
}
enum类的实现
public enum LoadStandardEnum {
USUAL("10", "标准"),
UNUSUAL_SMALL("20", "非标小"),
UNUSUAL_LARGE("30", "非标大");
private String code;
private String value;
LoadStandardEnum(String code, String value) {
this.code = code;
this.value = value;
}
public static String getValue(String code) {
for (LoadStandardEnum statusEnum : LoadStandardEnum.values()) {
if (statusEnum.code.equals(code)) {
return statusEnum.value;
}
}
return null;
}
public String getCode() {
return code;
}
public String getValue() {
return value;
}
}