Source:
public BaseResponseDto generateIndexLoan(String loginName) { List<LoanModel> loanModels = Lists.newArrayList(); if ((loginName == null || loginName.equals("")) && (investMapper.findCountNormalAndNewBieSuccessByInvestTime(loginName, DateTime.parse("2016-06-14").toDate()) == 0 && investMapper.findCountInvestProductTypeSuccessByLoginName(loginName,ProductType.EXPERIENCE) == 0)) { loanModels.addAll(loanMapper.findHomeLoanByIsContainNewbie(LoanStatus.RAISING, true,ProductType.EXPERIENCE)); } if(investMapper.findCountNormalAndNewBieSuccessByInvestTime(loginName,null) == 0){ loanModels.addAll(loanMapper.findHomeLoanByIsContainNewbie(LoanStatus.RAISING, true,null)); } List<LoanModel> notContainNewbieList = loanMapper.findHomeLoanByIsContainNewbie(LoanStatus.RAISING, false,null); if (CollectionUtils.isNotEmpty(notContainNewbieList)) { loanModels.addAll(notContainNewbieList); } if (CollectionUtils.isEmpty(loanModels)) { List<LoanModel> completeLoanModels = loanMapper.findHomeLoanByIsContainNewbie(LoanStatus.COMPLETE, false,null); if (CollectionUtils.isNotEmpty(completeLoanModels)) { loanModels.add(completeLoanModels.get(0)); } } BaseResponseDto<LoanListResponseDataDto> dto = new BaseResponseDto<>(); LoanListResponseDataDto loanListResponseDataDto = new LoanListResponseDataDto(); loanListResponseDataDto.setLoanList(convertLoanDto(loanModels)); dto.setData(loanListResponseDataDto); dto.setCode(ReturnMessage.SUCCESS.getCode()); dto.setMessage(ReturnMessage.SUCCESS.getMsg()); return dto; }

Target:
public BaseResponseDto generateIndexLoan(String loginName) { List<LoanModel> loanModels = Lists.newArrayList(); List<ProductType> allProductTypesCondition = Lists.newArrayList(ProductType._30,ProductType._90,ProductType._180,ProductType._360,ProductType.EXPERIENCE); List<ProductType> noContainExperienceCondition = Lists.newArrayList(ProductType._30,ProductType._90,ProductType._180,ProductType._360); ActivityType activityType = ActivityType.NORMAL; if (Strings.isNullOrEmpty(loginName) || investMapper.findCountSuccessByLoginNameAndProductTypes(loginName,allProductTypesCondition) == 0) { loanModels.addAll(loanMapper.findByProductType(LoanStatus.RAISING,Lists.newArrayList(ProductType.EXPERIENCE), ActivityType.NEWBIE)); } if(investMapper.findCountSuccessByLoginNameAndProductTypes(loginName,noContainExperienceCondition) == 0){ activityType = null; } List<LoanModel> notContainNewbieList = loanMapper.findByProductType(LoanStatus.RAISING,noContainExperienceCondition,activityType); if (CollectionUtils.isNotEmpty(notContainNewbieList)) { loanModels.addAll(notContainNewbieList); } if (CollectionUtils.isEmpty(loanModels)) { List<LoanModel> completeLoanModels = loanMapper.findByProductType(LoanStatus.COMPLETE, allProductTypesCondition,null); if (CollectionUtils.isNotEmpty(completeLoanModels)) { loanModels.add(completeLoanModels.get(0)); } } BaseResponseDto<LoanListResponseDataDto> dto = new BaseResponseDto<>(); LoanListResponseDataDto loanListResponseDataDto = new LoanListResponseDataDto(); loanListResponseDataDto.setLoanList(convertLoanDto(loginName, loanModels)); dto.setData(loanListResponseDataDto); dto.setCode(ReturnMessage.SUCCESS.getCode()); dto.setMessage(ReturnMessage.SUCCESS.getMsg()); return dto; }