原始代码
public String selectLevyInvoiceNameString_Cache(String merId) { List<TMerchantLevyInvoiceTypeVO> merLevyInvoiceTypeList = CacheUtil.getCache("merLevyInvoiceTypeList" + merId, 90, () -> merchantLevyInvoiceTypeDAO.selectList(merId)); if (CollectionUtil.isEmpty(merLevyInvoiceTypeList)) { return ""; } StringBuilder invoiceType = new StringBuilder(); for (TMerchantLevyInvoiceTypeVO tMerchantLevyInvoiceTypeVO : merLevyInvoiceTypeList) { LevyInvoiceClassVO cache = CacheUtil.getCache("levyInvoiceClass" + tMerchantLevyInvoiceTypeVO.getInvoiceTypeId(), 90, () -> { Result<LevyInvoiceClassVO> voResult = levyInvoiceClassService.getById(tMerchantLevyInvoiceTypeVO.getInvoiceTypeId()); if (voResult.isSuccess() && voResult.getResult() != null) { return voResult.getResult(); } return new LevyInvoiceClassVO(); } ); String invoiceTypeName = cache.getBillClassName(); if (StringUtils.isBlank(invoiceTypeName)) { continue; } if (invoiceType.length() > 0) { invoiceType.append("/"); } invoiceType.append(invoiceTypeName); } return invoiceType.toString(); }
重构后:
public String selectLevyInvoiceNameString_Cache(String merId) { return CacheUtil.getCache("merLevyInvoiceTypeList" + merId, 90, () -> { List<TMerchantLevyInvoiceTypeVO> merLevyInvoiceTypeList = merchantLevyInvoiceTypeDAO.selectList(merId); if (CollectionUtil.isEmpty(merLevyInvoiceTypeList)) { return ""; } StringBuilder invoiceType = new StringBuilder(); for (TMerchantLevyInvoiceTypeVO tMerchantLevyInvoiceTypeVO : merLevyInvoiceTypeList) { LevyInvoiceClassVO cache = CacheUtil.getCache("levyInvoiceClass" + tMerchantLevyInvoiceTypeVO.getInvoiceTypeId(), (int) MINUTES.toSeconds(30), () -> { Result<LevyInvoiceClassVO> voResult = levyInvoiceClassService.getById(tMerchantLevyInvoiceTypeVO.getInvoiceTypeId()); if (voResult.isSuccess() && voResult.getResult() != null) { return voResult.getResult(); } return new LevyInvoiceClassVO(); } ); String invoiceTypeName = cache.getBillClassName(); if (StringUtils.isBlank(invoiceTypeName)) { continue; } if (invoiceType.length() > 0) { invoiceType.append("/"); } invoiceType.append(invoiceTypeName); } return invoiceType.toString(); }); }
标签:voResult,缓存,tMerchantLevyInvoiceTypeVO,invoiceType,return,merLevyInvoiceTypeList From: https://www.cnblogs.com/buguge/p/16795545.html