两段代码,求重构方案,耦合度到最低!
代码1:
public PageBase getQueryListTemplate(String templateName, String creater, String startDate, String endDate, String sortColumn, String dir, PageBase pageBase) throws ExceptionWithKey { PageBase pb = queryTemplateDao.getQueryListTemplate(templateName, creater, startDate, endDate, sortColumn, dir, pageBase); // 查询 Time Level、Stat.Object两个字段的数据 List<QueryTemplate> list = pb.getItems(); for (QueryTemplate queryTemplate : list) { QueryTemplateContent content = queryTemplateContentDao.get(queryTemplate.getId()); String moLevel = this.getMOLevelByID(content.getMoLevel(), false); content.setMoLevel(moLevel); String timeLevelName = this.getTimeLevelName(content.getTimeLevel()); content.setTimeLevel(timeLevelName); queryTemplate.setQueryTemplateContent(content); } return pb; }
public PageBase getQueryTemplate(long templateType, String searchKey, String sortColumn, String dir, PageBase pageBase) throws ExceptionWithKey { PageBase pb = queryTemplateDao.getQueryTemplate(templateType, searchKey, sortColumn, dir, pageBase); // 查询 Time Level、Stat.Object两个字段的数据 List<QueryTemplate> list = pb.getItems(); for (QueryTemplate queryTemplate : list) { QueryTemplateContent content = queryTemplateContentDao .get(queryTemplate.getId()); String moLevel = this.getMOLevelByID(content.getMoLevel(), false); content.setMoLevel(moLevel); String timeLevelName = this.getTimeLevelName(content.getTimeLevel()); content.setTimeLevel(timeLevelName); queryTemplate.setQueryTemplateContent(content); } return pb; }