xiaoyong931011
2022-09-22 7cf7a80569d3cb907e0260abc3b2dbd36ec6c4c2
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
package cc.mrbird.febs.mall.service.impl;
 
import cc.mrbird.febs.common.utils.AppContants;
import cc.mrbird.febs.common.utils.RedisUtils;
import cc.mrbird.febs.mall.entity.AppVersion;
import cc.mrbird.febs.mall.entity.DataDictionaryCustom;
import cc.mrbird.febs.mall.mapper.AppVersionMapper;
import cc.mrbird.febs.mall.mapper.DataDictionaryCustomMapper;
import cc.mrbird.febs.mall.service.ICommonService;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * @author wzy
 * @date 2021-09-16
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class CommonService implements ICommonService {
    private final RedisUtils redisUtils;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final AppVersionMapper appVersionMapper;
 
    @Override
    public boolean verifyCode(String account, String code) {
        if ("SMS_CODE".equals(code)) {
            return true;
        }
 
        String cacheCode = redisUtils.getString(AppContants.VERIFY_CODE_PREFIX + account);
        if (StrUtil.isBlank(cacheCode)) {
            return false;
        }
        if (code.equals(cacheCode)) {
            redisUtils.del(AppContants.VERIFY_CODE_PREFIX + account);
            return true;
        } else {
            return false;
        }
    }
 
    @Override
    public List<DataDictionaryCustom> findDataDicByType(String type) {
        return dataDictionaryCustomMapper.selectDicByType(type);
    }
 
    @Override
    public List<AppVersion> findAppVersion() {
        return appVersionMapper.selectList(null);
    }
 
    @Override
    public void addDataDic(String type, String code, Object value, String description) {
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(type, code);
 
        String data = JSONObject.toJSONString(value);
        if (dic != null) {
            dic.setValue(data);
            dataDictionaryCustomMapper.updateById(dic);
            return;
        }
 
        dic = new DataDictionaryCustom();
        dic.setCode(code);
        dic.setType(type);
        dic.setValue(data);
        dic.setDescription(description);
        dataDictionaryCustomMapper.insert(dic);
    }
}