/** * Title: initMockData<br> * Description: 初始化测试数据 <br> * * @author xiebin * @date 2015年12月11日上午11:42:24 * @param interFaceInfo */ public void initMockData(InterFaceInfo interFaceInfo) { int ifId = interFaceInfo.getId(); // 初始化测试数据 List<ReturnCode> returnList = retrunCodeService.getReturnCodeByIfId(ifId); // 遍历返回码 更新测试数据 for (ReturnCode rscdObj : returnList) { IfSysMock mock = (IfSysMock) SpringContextHolder.getBean(IfSysMock.class); mock.setIfId(ifId); mock.setRspCodeId(rscdObj.getId()); // 测试数据表中确认是否已经存在对应返回码的测试数据 List<IfSysMock> ifMockList = ifSysMockService.getMockInfoByIfIdAndRspCdId(mock); if (ifMockList == null || ifMockList.size() == 0) { // 获取接口请求字段的JSON展示字符串 InterFaceField interFaceField = (InterFaceField) SpringContextHolder.getBean(InterFaceField.class); interFaceField.setIfId(ifId); interFaceField.setFieldFlag("1"); String reqJson = interFaceFieldService.getJsonStr(interFaceField); // 获取接口响应字段的JSON展示字符串 interFaceField.setFieldFlag("2"); String rspJson = interFaceFieldService.getJsonStr(interFaceField); mock.setRequestJson(reqJson); mock.setResponseJson(rspJson); // 如果还没有测试数据 则默认添加一条 ifSysMockService.addIfSysMock(mock); } } }
@RequestMapping("/getrspcdbyifid.do") public @ResponseBody RetrunCodeRspDto getReturnCodeByIfId(@RequestBody ReturnCodeReqDto dto) { debug("调用getReturnCodeByIfId"); RetrunCodeRspDto rdto = new RetrunCodeRspDto(); int ifId = dto.getIfId(); if (ifId == 0) { rdto.setRspCd(CodeItem.IF_ID_FAILURE); return rdto; } List<ReturnCode> list = retrunCodeService.getReturnCodeByIfId(ifId); if (list != null) { rdto.setList(list); rdto.setRspCd(SysCode.SUCCESS); } else { rdto.setRspCd(CodeItem.FAILURE); } return rdto; }