zj
2024-11-06 6f0c22dd9de33c38bb2c536937026e51b0b91b6e
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package project.c2c.internal;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
import org.springframework.jdbc.core.JdbcTemplate;
 
import kernel.bo.RecordObjectMapper;
import project.RedisKeys;
import project.c2c.C2cPaymentMethodConfig;
import project.c2c.C2cPaymentMethodConfigService;
import project.redis.RedisHandler;
 
public class C2cPaymentMethodConfigServiceImpl implements C2cPaymentMethodConfigService {
    
    private RedisHandler redisHandler;
    private JdbcTemplate jdbcTemplate;
 
    @Override
    public C2cPaymentMethodConfig get(String id) {
        return (C2cPaymentMethodConfig) this.redisHandler.get(RedisKeys.C2C_PAYMENT_METHOD_CONFIG_ID + id);
    }
    
    @Override
    public C2cPaymentMethodConfig getC2cPaymentMethodConfig(String id) {
        List<C2cPaymentMethodConfig> list = jdbcTemplate.query("SELECT * FROM T_C2C_PAYMENT_METHOD_CONFIG WHERE UUID=?", RecordObjectMapper.newInstance(C2cPaymentMethodConfig.class), id);
        if (null != list && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
    
    @Override
    public Map<String, String> getMethodConfigIdTypeMap() {
        Map<String, String> map = (Map<String, String>) this.redisHandler.get(RedisKeys.C2C_PAYMENT_METHOD_CONFIG_ID_TYPE);
        if (null == map || map.isEmpty()) {
            return new HashMap<String, String>();
        }
        return map;
    }
 
    @Override
    public void save(C2cPaymentMethodConfig entity) {
        if (null == entity) {
            return;
        }
        String insertSql = "INSERT INTO T_C2C_PAYMENT_METHOD_CONFIG(UUID,METHOD_TYPE,METHOD_NAME,METHOD_IMG,PARAM_NAME1,PARAM_NAME2,"
                + "PARAM_NAME3,PARAM_NAME4,PARAM_NAME5,PARAM_NAME6,PARAM_NAME7,PARAM_NAME8,PARAM_NAME9,PARAM_NAME10,PARAM_NAME11,"
                + "PARAM_NAME12,PARAM_NAME13,PARAM_NAME14,PARAM_NAME15,CREATE_TIME,UPDATE_TIME) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        jdbcTemplate.update(insertSql,entity.getId(),entity.getMethodType(),entity.getMethodName(),entity.getMethodImg(),entity.getParamName1(),
                entity.getParamName2(),entity.getParamName3(),entity.getParamName4(),entity.getParamName5(),entity.getParamName6(),
                entity.getParamName7(),entity.getParamName8(),entity.getParamName9(),entity.getParamName10(),entity.getParamName11(),
                entity.getParamName12(),entity.getParamName13(),entity.getParamName14(),entity.getParamName15(),entity.getCreateTime(),entity.getUpdateTime());
    }
 
    @Override
    public void delete(String id) {
        C2cPaymentMethodConfig entity = this.get(id);
        if (entity != null) {
            jdbcTemplate.update("DELETE FROM T_C2C_PAYMENT_METHOD_CONFIG WHERE UUID=?", entity.getId());
            this.redisHandler.remove(RedisKeys.C2C_PAYMENT_METHOD_CONFIG_ID + entity.getId().toString());
 
            Map<String, String> map1 = (Map<String, String>) this.redisHandler.get(RedisKeys.C2C_PAYMENT_METHOD_CONFIG_ID_TYPE);
            if (map1 != null && !map1.isEmpty()) {
                map1.remove(id);
            } else {
                map1 = new ConcurrentHashMap<String, String>();
            }
            this.redisHandler.setSync(RedisKeys.C2C_PAYMENT_METHOD_CONFIG_ID_TYPE, map1);
        }
    }
 
    @Override
    public boolean update(C2cPaymentMethodConfig entity) {
        try {
            String updateSql = "UPDATE T_C2C_PAYMENT_METHOD_CONFIG SET METHOD_TYPE=?, METHOD_NAME=?, METHOD_IMG=?, "
                    + "PARAM_NAME1=?, PARAM_NAME2=?, PARAM_NAME3=?, PARAM_NAME4=?, PARAM_NAME5=?, PARAM_NAME6=?, PARAM_NAME7=?, PARAM_NAME8=?, PARAM_NAME9=?, PARAM_NAME10=?, PARAM_NAME11=?, PARAM_NAME12=?, PARAM_NAME13=?, PARAM_NAME14=?, PARAM_NAME15=?, "
                    + "UPDATE_TIME=? WHERE UUID=?";
            jdbcTemplate.update(updateSql, entity.getMethodType(), entity.getMethodName(), entity.getMethodImg(), 
                    entity.getParamName1(),entity.getParamName2(),entity.getParamName3(),entity.getParamName4(),
                    entity.getParamName5(),entity.getParamName6(),entity.getParamName7(),entity.getParamName8(),
                    entity.getParamName9(),entity.getParamName10(),entity.getParamName11(),entity.getParamName12(),
                    entity.getParamName13(),entity.getParamName14(),entity.getParamName15(),entity.getUpdateTime(), entity.getId());
            return true;
        } catch(RuntimeException e) {
            return false;
        }
    }
    
    public List<C2cPaymentMethodConfig> getAll() {
        List<C2cPaymentMethodConfig> list = jdbcTemplate.query("SELECT * FROM T_C2C_PAYMENT_METHOD_CONFIG", RecordObjectMapper.newInstance(C2cPaymentMethodConfig.class));
        if (null == list) {
            list = new ArrayList<C2cPaymentMethodConfig>();
        }
        return list;
    }
    
    public Map<String, String> getMethodConfigMap() {
        
        List<C2cPaymentMethodConfig> methodConfigList = this.getAll();
        
        Map<String, String> methodConfigMap = new HashMap<String, String>();
        for (int i = 0; i < methodConfigList.size(); i++) {
            C2cPaymentMethodConfig config = methodConfigList.get(i);
            if (null != config) {
                methodConfigMap.put(config.getId().toString(), config.getMethodName());
            }
        }
        
        return methodConfigMap;
    }
 
    public void setRedisHandler(RedisHandler redisHandler) {
        this.redisHandler = redisHandler;
    }
 
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
 
}