需求:查询两张表的数据,对数据进行合并。
/**
* 查询全部.
*
* @param entity
* @param requestData
* @return
*/
@RequestMapping(value = "findAll", method = RequestMethod.GET)
@ResponseBody
public Map findAll(SysWorkflow entity, SysWorkflowPass pass, PageRequestData requestData) {
Map map1 = workflowService.findAll(entity, requestData.getPageable());
requestData.setPage(null);
Map map2 = workflowPassService.findAll(pass, requestData.getPageable());
return combine(map1, map2);
}
private Map combine(Map map1, Map map2) {
Map map = new HashMap();
List list2 = (List) map2.get("data");
List list1 = (List) map1.get("data");
List list = new ArrayList();
for (SysWorkflowPass sysWorkflowPass : list2) {
SysWorkFlowPassDto dto = new SysWorkFlowPassDto();
dto.setId(sysWorkflowPass.getId());
dto.setCreateDate(sysWorkflowPass.getCreateDate());
dto.setModifyDate(sysWorkflowPass.getModifyDate());
dto.setSignedUsers(sysWorkflowPass.getSignedUsers());
dto.setVersion(sysWorkflowPass.getVersion());
dto.setWorkflowType(sysWorkflowPass.getWorkflowPass());
dto.setName(sysWorkflowPass.getName());
list.add(dto);
}
for (SysWorkflow sysWorkflow : list1) {
SysWorkFlowPassDto dto = new SysWorkFlowPassDto();
dto.setId(sysWorkflow.getId());
dto.setCreateDate(sysWorkflow.getCreateDate());
dto.setModifyDate(sysWorkflow.getModifyDate());
dto.setSignedUsers(sysWorkflow.getSignedUsers());
dto.setVersion(sysWorkflow.getVersion());
dto.setWorkflowType(sysWorkflow.getWorkflowType().getName());
dto.setName(sysWorkflow.getName());
list.add(dto);
}
map.put("data", list);
Long total1 = (Long) map1.get("total");
Long total2 = (Long) map2.get("total");
map.put("total", total1 + total2);
map.put("success", "Boolean");
return map;
}