1
zj
2024-06-13 8eea5be3b36875bd4ffe70e6c3a5bb07b1d829bf
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
package com.yami.trading.service.finance.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.trading.bean.finance.Finance;
import com.yami.trading.dao.finance.FinanceMapper;
import com.yami.trading.service.finance.service.FinanceRedisKeys;
import com.yami.trading.service.finance.service.FinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
@Service
@Transactional
public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> implements FinanceService {
 
    @Autowired
    private RedisTemplate redisTemplate;
 
    public void save(Finance entity, String login_safeword, String operaterUsername) {
 
 
        //todo
//        User sec =  this.secUserService.findByUserName(operaterUsername);
//        String sysSafeword = sec.getSafePassword();
//        String safeword_md5 = passwordEncoder.encode(login_safeword);
//        if (!safeword_md5.equals(sysSafeword)) {
//            throw new BusinessException("资金密码错误");
//        }
        this.save(entity);
//        redisHandler.setSync(FinanceRedisKeys.FINANCE_ID + entity.getId().toString(), entity);
        redisTemplate.opsForValue().set(FinanceRedisKeys.FINANCE_ID + entity.getUuid(), entity);
 
        Map<String, Finance> cacheMap = (Map<String, Finance>) redisTemplate.opsForValue().get(FinanceRedisKeys.FINANCE_MAP);
        if (cacheMap == null) {
            cacheMap = new ConcurrentHashMap<String, Finance>();
        }
        cacheMap.put(entity.getUuid(), entity);
//        redisHandler.setSync(FinanceRedisKeys.FINANCE_MAP, cacheMap);
        redisTemplate.opsForValue().set(FinanceRedisKeys.FINANCE_MAP, cacheMap);
 
    }
 
    public void update(Finance entity, String login_safeword, String operaterUsername) {
 
        System.out.println("operaterUsername => " + operaterUsername);
        //todo
//        User sec =  this.secUserService.findByUserName(operaterUsername);
 
//        String sysSafeword = sec.getSafePassword();
//        String safeword_md5 = passwordEncoder.encode(login_safeword);
//        if (!safeword_md5.equals(sysSafeword)) {
//            throw new BusinessException("资金密码错误");
//        }
 
        this.updateById(entity);
//        redisHandler.setSync(FinanceRedisKeys.FINANCE_ID + entity.getId().toString(), entity);
        redisTemplate.opsForValue().set(FinanceRedisKeys.FINANCE_ID + entity.getUuid(), entity);
 
        Map<String, Finance> cacheMap = (Map<String, Finance>) redisTemplate.opsForValue().get(FinanceRedisKeys.FINANCE_MAP);
        if (cacheMap == null) {
            cacheMap = new ConcurrentHashMap<String, Finance>();
        }
        cacheMap.put(entity.getUuid(), entity);
        redisTemplate.opsForValue().set(FinanceRedisKeys.FINANCE_MAP, cacheMap);
 
    }
 
    public void delete(String id, String login_safeword, String operaterUsername) {
 
        //todo
//        User sec =  this.secUserService.findByUserName(operaterUsername);
//        String sysSafeword = sec.getSafePassword();
//        String safeword_md5 = passwordEncoder.encode(login_safeword);
//        if (!safeword_md5.equals(sysSafeword)) {
//            throw new BusinessException("资金密码错误");
//        }
 
 
        Finance entity = findById(id);
        this.removeById(entity);
//        redisHandler.remove(FinanceRedisKeys.FINANCE_ID + entity.getUuid().toString());
        redisTemplate.delete(FinanceRedisKeys.FINANCE_ID + entity.getUuid());
 
        Map<String, Finance> cacheMap = (Map<String, Finance>) redisTemplate.opsForValue().get(FinanceRedisKeys.FINANCE_MAP);
        if (cacheMap != null && !cacheMap.isEmpty()) {
            cacheMap.remove(entity.getUuid());
            redisTemplate.opsForValue().set(FinanceRedisKeys.FINANCE_MAP, cacheMap);
        }
 
 
    }
 
    public Finance findById(String id) {
        return (Finance) redisTemplate.opsForValue().get(FinanceRedisKeys.FINANCE_ID + id);
    }
 
    public List<Finance> findAll() {
        Map<String, Finance> cacheMap = (Map<String, Finance>) redisTemplate.opsForValue().get(FinanceRedisKeys.FINANCE_MAP);
        if (cacheMap != null && !cacheMap.isEmpty()) {
            return new ArrayList<>(cacheMap.values());
        }
        return new ArrayList<>();
    }
 
    public List<Finance> findAllState_1() {
        LambdaQueryWrapper<Finance> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Finance::getState, 1);
        queryWrapper.orderByAsc(Finance::getInvestmentMin);
        return list(queryWrapper);
    }
 
    @Override
    public List<Finance> selectAllNoCache() {
        return list();
    }
}