package com.qianwen.core.coderule.handler;
|
|
import java.util.List;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import com.qianwen.core.coderule.constant.CodeRuleConstant;
|
import com.qianwen.core.coderule.dto.RefObjectTypeInfoDTO;
|
import com.qianwen.core.coderule.model.ObjectType;
|
import com.qianwen.core.tool.utils.CollectionUtil;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.core.tool.utils.StringUtil;
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
public class MasterlinkObjectTypeHandler implements ObjectTypeHandler {
|
private static final Logger log = LoggerFactory.getLogger(MasterlinkObjectTypeHandler.class);
|
private final JdbcTemplate jdbcTemplate;
|
|
public MasterlinkObjectTypeHandler(final JdbcTemplate jdbcTemplate) {
|
this.jdbcTemplate = jdbcTemplate;
|
}
|
|
@Override // com.qianwen.core.coderule.handler.ObjectTypeHandler
|
public String getRefObject(String objectTypeId, String fieldName) {
|
String result = "";
|
List<String> refObjects = this.jdbcTemplate.queryForList(CodeRuleConstant.REF_OBJECT_BY_ID_FIELD, String.class, new Object[]{objectTypeId, fieldName});
|
if (CollectionUtil.isNotEmpty(refObjects)) {
|
result = refObjects.iterator().next();
|
}
|
return result;
|
}
|
|
@Override // com.qianwen.core.coderule.handler.ObjectTypeHandler
|
public ObjectType getObjectType(String objectTypeId) {
|
ObjectType result = null;
|
List<ObjectType> objectTypes = this.jdbcTemplate.query(CodeRuleConstant.OBJECT_TYPE_BY_ID, new Object[]{objectTypeId}, new BeanPropertyRowMapper(ObjectType.class));
|
if (CollectionUtil.isNotEmpty(objectTypes)) {
|
result = objectTypes.iterator().next();
|
}
|
return result;
|
}
|
|
@Override // com.qianwen.core.coderule.handler.ObjectTypeHandler
|
public RefObjectTypeInfoDTO getRefObjectTypeInfo(ObjectType objectType, String id) {
|
RefObjectTypeInfoDTO result = null;
|
String querySql = StringUtil.format(CodeRuleConstant.CODE_NAME_BY_ID, new Object[]{objectType.getRefCode(), objectType.getRefName(), objectType.getTableName(), objectType.getPrimaryKey()});
|
List<RefObjectTypeInfoDTO> refObjectTypeInfoDTOS = this.jdbcTemplate.query(querySql, new Object[]{id}, new BeanPropertyRowMapper(RefObjectTypeInfoDTO.class));
|
if (CollectionUtil.isNotEmpty(refObjectTypeInfoDTOS)) {
|
result = refObjectTypeInfoDTOS.iterator().next();
|
}
|
return result;
|
}
|
|
@Override // com.qianwen.core.coderule.handler.ObjectTypeHandler
|
public RefObjectTypeInfoDTO getRefObjectTypeInfo(String objectTypeId, String fieldName, String id) {
|
RefObjectTypeInfoDTO result = null;
|
String refObject = getRefObject(objectTypeId, fieldName);
|
if (Func.isNotEmpty(refObject)) {
|
ObjectType objectType = getObjectType(refObject);
|
if (Func.isNotEmpty(objectType)) {
|
result = getRefObjectTypeInfo(objectType, id);
|
} else {
|
log.error("根据业务对象编码{}获取不到业务对象数据", refObject);
|
}
|
} else {
|
log.error("根据业务对象{}和业务对象字段{}获取不到引用对象数据", objectTypeId, fieldName);
|
}
|
return result;
|
}
|
}
|