1. 开发流程
1.业务场景梳理,选择合适的开发模板继承并进行开发,当前支持的模板类型有部门模板、用户模板、成本中心模板、成本中心项模板、成本中心项用户模板、报销单模板、借款单模板、差旅申请单模板
数据写入模板
主要同步基础数据,将企业业务系统作为基础数据来源,常见实现有部门模板,用户模板,成本中心模板,成本中心项模板等。
数据写出模板
主要用于同步业务数据,将在汇联易中产生的业务数据同步至企业业务系统,常见模板有报销单模板,借款单模板,还款单模板等。
2.接口调用过程封装,举例如下:
@Service
public class SampleIntegrationRequestService {
private static final String BLUFOCUS_URL = "someurl";
private SampleRestService sampleRestService;
public SampleIntegrationRequestService(SampleRestService sampleRestService) {
this.sampleRestService = sampleRestService;
}
private IntegrationQueryResponseDTO getIntegrationResponse(Map<String, Object> param) {
String content = JSON.toJSONString(param);
String result = sampleRestService.doRest(BLUFOCUS_URL, String.class, content, HttpMethod.POST, null, false);
JSONObject respJson = JSONObject.parseObject(result);
IntegrationQueryResponseDTO responseDTO = new IntegrationQueryResponseDTO();
responseDTO.setResponseBody(respJson);
JSONObject resultJson = (JSONObject) respJson.get("result");
JSONArray allRecords = resultJson.getJSONArray("record");
responseDTO.setPage((int) param.get("pagenum"));
responseDTO.setSize(allRecords.size());
responseDTO.setTotal((Integer) resultJson.get("totalCount"));
responseDTO.setSuccess(respJson.getBoolean("success"));
return responseDTO;
}
@Performance(apiName = "查询系统部门信息", dataSource = "BLUFCUS")
public IntegrationQueryResponseDTO getDeprtmentResponse(Map<String, Object> param) {
param.put("data_type", "unit");
return this.getIntegrationResponse(param);
}
@Performance(apiName = "查询系统用户信息", dataSource = "BLUFCUS")
public IntegrationQueryResponseDTO getUserResponse(Map<String, Object> param) {
param.put("data_type", "employees");
return this.getIntegrationResponse(param);
}
}
注:此处使用了Performance注解采集接口调用信息;封装后的接口调用服务返回的数据类型是IntegrationQueryResponseDTO,需要在接口实现类中实现数据的封装。数据封装代码片段如下:
JSONObject respJson = JSONObject.parseObject(result);
IntegrationQueryResponseDTO responseDTO = new IntegrationQueryResponseDTO();
responseDTO.setResponseBody(respJson);
JSONObject resultJson = (JSONObject) respJson.get("result"); JSONArray allRecords = resultJson.getJSONArray("record"); responseDTO.setPage((int) param.get("pagenum"));
responseDTO.setSize(allRecords.size());
responseDTO.setTotal((Integer) resultJson.get("totalCount"));
responseDTO.setSuccess(respJson.getBoolean("success"));
查询获得的分页信息需要按照上述代码片段封装到IntegrationQueryResponseDTO,用于模板程序自动处理分页查询。
3.根据业务场景,可选择继承业务模板或者ArtemisDataInputerTemplate/ArtemisDataOutputerTemplate, 其中继承时所需泛型参数,即为数据在各环节流转时所需要的数据类型。
数据写入流程开发举例:
1). 同步任务入口
Map<String, Object> param = new HashMap<String, Object>();
param.put("action", "query");//下游接口所需参数
param.put("data_type", "unit");//下游接口所需参数
param.put("fetchall", "false");//下游接口所需参数
param.put(RequestConstant.DEFAULT_PAGE_KEY, 1);//分页参数,主要用于自动处理分页数据滚动
param.put(RequestConstant.DEFAULT_SIZE_KEY, 10);//分页参数,主要用于自动处理分页数据滚动
Boolean result = sampleArtemisDepartmentInputService.doArtemisDataInput(param);
2). 重载doIntegrationApi
在本步骤中需要注意分页查询时模板程序可实现自动滚动查询,模板中使用默认参数名存储分页所需页码和页容量,重载时需要将该参数转换成下游接口实际所需分页参数
下游查询程序:
@Override
public IntegrationQueryResponseDTO doIntegrationApi(Map<String, Object> param) {
//做一下页码数据的转换,其他字段保留
param.put("pagesize", param.get(RequestConstant.DEFAULT_SIZE_KEY));//将默认分页信息转化成下游所需参数形式
param.put("pagenum", param.get(RequestConstant.DEFAULT_PAGE_KEY));//将默认分页信息转化成下游所需参数形式
//调用集成系统service,进行数据查询
IntegrationQueryResponseDTO jsonObj = sampleIntegrationRequestService.getDeprtmentResponse(param);
return jsonObj;
}
3). 重载doArtemisParameterAdaption
需要将调用下游接口所获得返回值进行转换与封装,组装成汇联易接口所能识别的数据。进而调用汇联易接口进行数据写入。该步骤涉及:a.数据Mapping表查询,b.数据属性转化,(大部分场景返回值应为数组)
@Override
public List<CommonIntegrationDTO<SampleDept>> doArtemisParameterAdaption(JSONObject raw) {
//主要实现数据类型转换与映射,将下游接口返回值封装成接口所需对象即可
...
return depts;
}
4)重载doArtemisApi
主要实现汇联易产品接口调用与mapping关系持久化,该过程在内置模板中会进行实例化, 若选择使用模板程序,则此步骤可省略,如果需要自己实现,可参见以下案例:
@Override
public ArtemisSimpleResponseDTO doArtemisApi(List<CommonIntegrationDTO<SampleDept>> sampleDepts) {
ArtemisSimpleResponseDTO artemisResponseDTO = new ArtemisSimpleResponseDTO();
// 遍历信息
for (CommonIntegrationDTO<SampleDept> sampleDept : sampleDepts) {
switch (sampleDept.getAction()) {
case ActionConstant.ACTION_INSERT: // 新增
DepartmentDTO createRresult = artemisDepartmentService.createDepartment(sampleDept.getT());
MidDataMapping midDataMapping = new MidDataMapping();
ArtemisResponseDTO artemisResponse = new ArtemisResponseDTO();
midDataMapping.setArtId(createRresult.getDepartmentOID().toString());
midDataMapping.setDataType(MidDataMappingConstant.DEPT_MAPPING);
midDataMapping.setDataKey(sampleDept.getT().getUnitId().toString());
midDataMapping.setIsEnabled(true);
midDataMapping.setIsDeleted(false);
midDataMapping.setCreatedDate(ZonedDateTime.now());
midDataMappingService.saveMidDataMapping(midDataMapping);
artemisResponse.setKey(createRresult.getCustDeptNumber());
artemisResponse.setOid(createRresult.getDepartmentOID());
artemisResponse.setErrorCode(ResponseConstant.RES_0000);
artemisResponseDTO.setRequestJson(JSONObject.toJSONString(sampleDept));
artemisResponseDTO.put(artemisResponse);
break;
case ActionConstant.ACTION_UPDATE: // 修改
ArtemisResponseDTO updateResult = artemisDepartmentService.updateDepartment(sampleDept.getT());
artemisResponseDTO.setRequestJson(JSONObject.toJSONString(sampleDept));
artemisResponseDTO.put(updateResult);
break;
case ActionConstant.ACTION_DELETE: // 刪除
DepartmentPathDTO departmentPathDTO = new DepartmentPathDTO();
departmentPathDTO.setDeleteDepartmentOIDs(Arrays.asList(sampleDept.getT().getDepartmentOID()));
List<ArtemisResponseDTO> deleteResult = artemisDepartmentService.deleteDepartments(departmentPathDTO);
MidDataMapping deleteMidDataMapping = new MidDataMapping();
deleteMidDataMapping.setArtId(deleteResult.get(0).getOid().toString());
deleteMidDataMapping.setDataType(MidDataMappingConstant.DEPT_MAPPING);
deleteMidDataMapping.setDataKey(sampleDept.getT().getUnitId().toString());
deleteMidDataMapping.setIsEnabled(false);
deleteMidDataMapping.setIsDeleted(true);
midDataMappingService.saveMidDataMapping(deleteMidDataMapping);
artemisResponseDTO.setRequestJson(JSONObject.toJSONString(sampleDept));
artemisResponseDTO.put(deleteResult.get(0));
break;
}
}
return artemisResponseDTO;
}