yangys
2024-05-07 eaf6878850c029ac359d60409c7c9fcfa09c1852
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
package com.qianwen.core.coderule.handler;
 
import java.util.List;
import com.qianwen.core.cache.utils.CacheUtil;
import com.qianwen.core.coderule.constant.CodeRuleConstant;
import com.qianwen.core.coderule.model.CodeRuleEntryModel;
import com.qianwen.core.coderule.model.CodeRuleModel;
import com.qianwen.core.tool.utils.CollectionUtil;
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/MasterlinkCodeRuleModelHandler.class */
public class MasterlinkCodeRuleModelHandler implements CodeRuleModelHandler {
    private static final String CODE_RULE_CACHE_ID = "codeRule:id:";
    private static final String CODE_RULE_CACHE = "blade:codeRule";
    private static final CodeRuleModel SEARCHED_DATA_CODE_RULE_MODEL = new CodeRuleModel(Boolean.TRUE);
    private final JdbcTemplate jdbcTemplate;
 
    public MasterlinkCodeRuleModelHandler(final JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
 
    @Override // com.qianwen.core.coderule.handler.CodeRuleModelHandler
    public CodeRuleModel getCodeRuleById(Long codeRuleId) {
        CodeRuleModel dataCoreRule = (CodeRuleModel) CacheUtil.get(CODE_RULE_CACHE, CODE_RULE_CACHE_ID, codeRuleId, CodeRuleModel.class, Boolean.FALSE);
        if (dataCoreRule == null || !dataCoreRule.getSearched().booleanValue()) {
            List<CodeRuleModel> list = this.jdbcTemplate.query(CodeRuleConstant.DATA_BY_CORE_RULE_ID, new Object[]{codeRuleId}, new BeanPropertyRowMapper(CodeRuleModel.class));
            if (CollectionUtil.isNotEmpty(list)) {
                dataCoreRule = list.iterator().next();
                List<CodeRuleEntryModel> entryList = this.jdbcTemplate.query(CodeRuleConstant.ENTRY_DATA_BY_CORE_RULE_ID, new Object[]{codeRuleId}, new BeanPropertyRowMapper(CodeRuleEntryModel.class));
                dataCoreRule.setCodeRuleEntryModelList(entryList);
                dataCoreRule.setSearched(Boolean.TRUE);
            } else {
                dataCoreRule = SEARCHED_DATA_CODE_RULE_MODEL;
            }
            CacheUtil.put(CODE_RULE_CACHE, CODE_RULE_CACHE_ID, codeRuleId, dataCoreRule, Boolean.FALSE);
        }
        if (StringUtil.isNotBlank(dataCoreRule.getBill_form_id())) {
            return dataCoreRule;
        }
        return null;
    }
}