String productUrl = ""; if (null != resultList && resultList.size() > 0) { if ("2".equals(agentInfo.getIdentityType())) { for (int i = 0; i < resultList.size(); i++) { ProductInfo productInfo = new ProductInfo(); productInfo.setInternal_id(resultList.get(i).getInternal_id()); productInfo.setProduct_abbr(resultList.get(i).getProduct_abbr()); //整理中介产品信息 productUrl = productService.getProductUrl(resultList.get(i), agentInfo.getIdentityType(), agentStaffVo, request); productInfo.setProductUrl(productUrl); productInfo.setInsuranceNotice(Commonconst.INSURANCE_NOTICE_2); productInfo.setPrivacyPolicy(Commonconst.PRIVACY_POLICY); productInfo.setPrivacyPolicyUrl(productService.getPrivacyPolicyUrl(request)); productInfoList.add(productInfo); } } else { for (int i = 0; i < resultList.size(); i++) { ProductInfo productInfo = new ProductInfo(); productInfo.setInternal_id(resultList.get(i).getInternal_id()); productInfo.setProduct_abbr(resultList.get(i).getProduct_abbr()); //整理非中介渠道产品信息 productUrl = productService.getProductUrl(resultList.get(i), agentInfo.getIdentityType(), agentStaffVo, request); productInfo.setProductUrl(productUrl); if ("ANHMB".equals(resultList.get(i).getInternal_id())) { productInfo.setInsuranceNotice(Commonconst.INSURANCE_NOTICE_3); } else if ("RNMRB02".equals(resultList.get(i).getInternal_id())) { productInfo.setInsuranceNotice(Commonconst.INSURANCE_NOTICE_4); } else if ("ANMRB02".equals(resultList.get(i).getInternal_id()) || "ANMMB03".equals(resultList.get(i).getInternal_id()) || "ANMRB03".equals(resultList.get(i).getInternal_id()) || "ANMRB04".equals(resultList.get(i).getInternal_id()) || "ANEMRB".equals(resultList.get(i).getInternal_id()) || "BNFIB".equals(resultList.get(i).getInternal_id())) { productInfo.setInsuranceNotice(Commonconst.INSURANCE_NOTICE_1); } else { productInfo.setInsuranceNotice(Commonconst.INSURANCE_NOTICE_2); } productInfoList.add(productInfo); } } }缩短执行时间
时间: 2024-02-19 12:03:20 浏览: 151
jquery.post用法关于type设置问题补充
这段代码的执行时间可以通过以下几个方面进行缩短:
1. 使用增强for循环:可以将for循环改成增强for循环,这样可以简化代码,同时也可以提高执行效率。例如:
```
for (ProductInfo result : resultList) {
ProductInfo productInfo = new ProductInfo();
productInfo.setInternal_id(result.getInternal_id());
productInfo.setProduct_abbr(result.getProduct_abbr());
//省略中间代码
productInfoList.add(productInfo);
}
```
2. 减少重复计算:在for循环中,多次调用get方法获取相同的值,可以将这些值缓存起来,减少重复计算。例如:
```
for (ProductInfo result : resultList) {
ProductInfo productInfo = new ProductInfo();
String internal_id = result.getInternal_id();
String product_abbr = result.getProduct_abbr();
productInfo.setInternal_id(internal_id);
productInfo.setProduct_abbr(product_abbr);
//省略中间代码
productInfoList.add(productInfo);
}
```
3. 简化判断逻辑:在第二个for循环中,对于不同的产品内部id,需要设置不同的保险提示语。可以使用Map来存储每个内部id对应的提示语,然后在for循环中查找对应的提示语即可。例如:
```
Map<String, String> insuranceNoticeMap = new HashMap<>();
insuranceNoticeMap.put("ANHMB", Commonconst.INSURANCE_NOTICE_3);
insuranceNoticeMap.put("RNMRB02", Commonconst.INSURANCE_NOTICE_4);
insuranceNoticeMap.put("ANMRB02", Commonconst.INSURANCE_NOTICE_1);
insuranceNoticeMap.put("ANMMB03", Commonconst.INSURANCE_NOTICE_1);
insuranceNoticeMap.put("ANMRB03", Commonconst.INSURANCE_NOTICE_1);
insuranceNoticeMap.put("ANMRB04", Commonconst.INSURANCE_NOTICE_1);
insuranceNoticeMap.put("ANEMRB", Commonconst.INSURANCE_NOTICE_1);
insuranceNoticeMap.put("BNFIB", Commonconst.INSURANCE_NOTICE_1);
for (ProductInfo result : resultList) {
ProductInfo productInfo = new ProductInfo();
String internal_id = result.getInternal_id();
String product_abbr = result.getProduct_abbr();
productInfo.setInternal_id(internal_id);
productInfo.setProduct_abbr(product_abbr);
//省略中间代码
productInfo.setInsuranceNotice(insuranceNoticeMap.getOrDefault(internal_id, Commonconst.INSURANCE_NOTICE_2));
productInfoList.add(productInfo);
}
```
通过以上优化措施,可以缩短代码的执行时间,提高代码的效率。
阅读全文