yangys
2024-05-09 60e317f7782c718d28920060fd686d2092c99c1e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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;
 
/* loaded from: blade-starter-coderule-9.3.0.0-SNAPSHOT.jar:org/springblade/core/coderule/handler/MasterlinkObjectTypeHandler.class */
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;
    }
}