zj
2025-02-25 dd315d5732e14fcf3df71e0cf213cc442bd8607b
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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.C2cPaymentMethod;
import project.c2c.C2cPaymentMethodService;
import project.redis.RedisHandler;
 
public class C2cPaymentMethodServiceImpl implements C2cPaymentMethodService {
    
    private RedisHandler redisHandler;
    private JdbcTemplate jdbcTemplate;
 
    @Override
    public C2cPaymentMethod get(String id) {
        return (C2cPaymentMethod) this.redisHandler.get(RedisKeys.C2C_PAYMENT_METHOD_ID + id);
    }
    
    @Override
    public C2cPaymentMethod getC2cPaymentMethod(String id) {
        List<C2cPaymentMethod> list = jdbcTemplate.query("SELECT * FROM T_C2C_PAYMENT_METHOD WHERE UUID=?", RecordObjectMapper.newInstance(C2cPaymentMethod.class), id);
        if (null != list && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
    
    @Override
    public Map<String, C2cPaymentMethod> getByPartyId(String partyId) {
        Map<String, C2cPaymentMethod> map = (Map<String, C2cPaymentMethod>) this.redisHandler.get(RedisKeys.C2C_PAYMENT_METHOD_PARTY_ID + partyId);
        if (null == map || 0 == map.size()) {
            return new HashMap<String, C2cPaymentMethod>();
        }
        return map;
    }
    
    @Override
    public Map<String, String> getMethodConfigMapByPartyId(String partyId) {        
        Map<String, String> res = new HashMap<String, String>();
        
        Map<String, C2cPaymentMethod> methodMap = this.getByPartyId(partyId);
        if (null == methodMap || 0 == methodMap.size()) {
            return res;
        }
        
        for (String key : methodMap.keySet()) {
            C2cPaymentMethod method = methodMap.get(key);
            if (null != method) {
                res.put(method.getMethodConfigId(), method.getMethodName());
            }
        }
        
        return res;
    }
    
    @Override
    public List<C2cPaymentMethod> getMethodConfigListByPartyId(String partyId) {        
        List<C2cPaymentMethod> res = new ArrayList<C2cPaymentMethod>();
        
        Map<String, C2cPaymentMethod> methodMap = this.getByPartyId(partyId);
        if (null == methodMap || 0 == methodMap.size()) {
            return res;
        }
        
        for (String key : methodMap.keySet()) {
            C2cPaymentMethod method = methodMap.get(key);
            if (null != method) {
                res.add(method);
            }
        }
        
        return res;        
    }
    
    @Override
    public Map<String, String> getMethodIdTypeMap() {
        Map<String, String> map = (Map<String, String>) this.redisHandler.get(RedisKeys.C2C_PAYMENT_METHOD_ID_TYPE);
        if (null == map || map.isEmpty()) {
            return new HashMap<String, String>();
        }
        return map;
    }
    
    @Override
    public void save(C2cPaymentMethod entity) {
        String insertSql = "INSERT INTO T_C2C_PAYMENT_METHOD(UUID,PARTY_ID,METHOD_CONFIG_ID,METHOD_TYPE,METHOD_NAME,METHOD_IMG,"
                + "REAL_NAME,PARAM_NAME1,PARAM_VALUE1,PARAM_NAME2,PARAM_VALUE2,PARAM_NAME3,PARAM_VALUE3,PARAM_NAME4,PARAM_VALUE4,"
                + "PARAM_NAME5,PARAM_VALUE5,PARAM_NAME6,PARAM_VALUE6,PARAM_NAME7,PARAM_VALUE7,PARAM_NAME8,PARAM_VALUE8,PARAM_NAME9,"
                + "PARAM_VALUE9,PARAM_NAME10,PARAM_VALUE10,PARAM_NAME11,PARAM_VALUE11,PARAM_NAME12,PARAM_VALUE12,PARAM_NAME13,"
                + "PARAM_VALUE13,PARAM_NAME14,PARAM_VALUE14,PARAM_NAME15,PARAM_VALUE15,QRCODE,REMARK,CREATE_TIME,UPDATE_TIME) "
                + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        jdbcTemplate.update(insertSql,entity.getId(),entity.getPartyId(),entity.getMethodConfigId(),entity.getMethodType(),entity.getMethodName(),
                entity.getMethodImg(),entity.getRealName(),entity.getParamName1(),entity.getParamValue1(),entity.getParamName2(),entity.getParamValue2(),
                entity.getParamName3(),entity.getParamValue3(),entity.getParamName4(),entity.getParamValue4(),entity.getParamName5(),entity.getParamValue5(),
                entity.getParamName6(),entity.getParamValue6(),entity.getParamName7(),entity.getParamValue7(),entity.getParamName8(),entity.getParamValue8(),
                entity.getParamName9(),entity.getParamValue9(),entity.getParamName10(),entity.getParamValue10(),entity.getParamName11(),entity.getParamValue11(),
                entity.getParamName12(),entity.getParamValue12(),entity.getParamName13(),entity.getParamValue13(),entity.getParamName14(),entity.getParamValue14(),
                entity.getParamName15(),entity.getParamValue15(),entity.getQrcode(),entity.getRemark(),entity.getCreateTime(),entity.getUpdateTime());
    }
    
    @Override
    public void delete(String id) {
        C2cPaymentMethod entity = this.get(id);
        if (entity != null) {
            jdbcTemplate.update("DELETE FROM T_C2C_PAYMENT_METHOD WHERE UUID=?", entity.getId());
            this.redisHandler.remove(RedisKeys.C2C_PAYMENT_METHOD_ID + entity.getId().toString());
 
            Map<String, C2cPaymentMethod> map = (Map<String, C2cPaymentMethod>) this.redisHandler.get(RedisKeys.C2C_PAYMENT_METHOD_PARTY_ID + entity.getPartyId().toString());
            if (map != null && !map.isEmpty()) {
                map.remove(id);
            } else {
                map = new ConcurrentHashMap<String, C2cPaymentMethod>();
            }
            this.redisHandler.setSync(RedisKeys.C2C_PAYMENT_METHOD_PARTY_ID + entity.getPartyId().toString(), map);
 
            Map<String, String> map1 = (Map<String, String>) this.redisHandler.get(RedisKeys.C2C_PAYMENT_METHOD_ID_TYPE);
            if (map1 != null && !map1.isEmpty()) {
                map1.remove(id);
            } else {
                map1 = new ConcurrentHashMap<String, String>();
            }
            this.redisHandler.setSync(RedisKeys.C2C_PAYMENT_METHOD_ID_TYPE, map1);
        }
    }
 
    @Override
    public boolean update(C2cPaymentMethod entity) {
        try {
            String updateSql = "UPDATE T_C2C_PAYMENT_METHOD SET PARTY_ID=?,METHOD_CONFIG_ID=?,METHOD_TYPE=?,METHOD_NAME=?,METHOD_IMG=?,REAL_NAME=?,"
                    + "PARAM_NAME1=?,PARAM_VALUE1=?,PARAM_NAME2=?,PARAM_VALUE2=?,PARAM_NAME3=?,PARAM_VALUE3=?,PARAM_NAME4=?,PARAM_VALUE4=?,"
                    + "PARAM_NAME5=?,PARAM_VALUE5=?,PARAM_NAME6=?,PARAM_VALUE6=?,PARAM_NAME7=?,PARAM_VALUE7=?,PARAM_NAME8=?,PARAM_VALUE8=?,"
                    + "PARAM_NAME9=?,PARAM_VALUE9=?,PARAM_NAME10=?,PARAM_VALUE10=?,PARAM_NAME11=?,PARAM_VALUE11=?,PARAM_NAME12=?,PARAM_VALUE12=?,"
                    + "PARAM_NAME13=?,PARAM_VALUE13=?,PARAM_NAME14=?,PARAM_VALUE14=?,PARAM_NAME15=?,PARAM_VALUE15=?,QRCODE=?,REMARK=?,UPDATE_TIME=? WHERE UUID=?";
 
            jdbcTemplate.update(updateSql,entity.getPartyId(),entity.getMethodConfigId(),entity.getMethodType(),entity.getMethodName(),
                            entity.getMethodImg(),entity.getRealName(),entity.getParamName1(),entity.getParamValue1(),entity.getParamName2(),entity.getParamValue2(),
                            entity.getParamName3(),entity.getParamValue3(),entity.getParamName4(),entity.getParamValue4(),entity.getParamName5(),entity.getParamValue5(),
                            entity.getParamName6(),entity.getParamValue6(),entity.getParamName7(),entity.getParamValue7(),entity.getParamName8(),entity.getParamValue8(),
                            entity.getParamName9(),entity.getParamValue9(),entity.getParamName10(),entity.getParamValue10(),entity.getParamName11(),entity.getParamValue11(),
                            entity.getParamName12(),entity.getParamValue12(),entity.getParamName13(),entity.getParamValue13(),entity.getParamName14(),entity.getParamValue14(),
                            entity.getParamName15(),entity.getParamValue15(),entity.getQrcode(),entity.getRemark(),entity.getUpdateTime(),entity.getId());
            return true;
        } catch(RuntimeException e) {
            return false;
        }
    }
 
    public void setRedisHandler(RedisHandler redisHandler) {
        this.redisHandler = redisHandler;
    }
 
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
 
}