admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
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
package com.yeshi.fanli.service.impl.user.vip;
 
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.user.vip.UserVipConfigMapper;
import com.yeshi.fanli.entity.bus.user.vip.UserVipConfig;
import com.yeshi.fanli.exception.user.vip.UserVipConfigException;
import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class UserVipConfigServiceImpl implements UserVipConfigService {
 
    @Resource
    private UserVipConfigMapper userVipConfigMapper;
 
    @Override
    public UserVipConfig getByKey(String key) {
        return userVipConfigMapper.getByKey(key, new Date());
    }
 
    @Override
    @Cacheable(value = "vipconfigCache", key = "'getValueByKey-' + #key")
    public String getValueByKey(String key) {
        UserVipConfig config = userVipConfigMapper.getByKey(key, new Date());
        if (config != null) {
            return config.getValue();
        }
        return null;
    }
 
    @Override
    public UserVipConfig getByKey(String key, Date date) {
        if (date == null)
            return getByKey(key);
        return userVipConfigMapper.getByKey(key, date);
    }
 
    @Override
    public String getValueByKey(String key, Date date) {
        if (date == null)
            return getValueByKey(key);
        UserVipConfig config = userVipConfigMapper.getByKey(key, date);
        if (config != null) {
            return config.getValue();
        }
        return null;
    }
    
    @Override
    public List<UserVipConfig> query(int page, int pageSize, String key) {
        return userVipConfigMapper.query((page - 1) * pageSize, pageSize, key);
    }
    
    @Override
    public long count(String key) {
        return userVipConfigMapper.count(key);
    }
    
    
    @Override
    public void save(UserVipConfig record) throws UserVipConfigException {
        String name = record.getName();
        if (StringUtil.isNullOrEmpty(name))
            throw new UserVipConfigException(1, "名称不能为空");
        
        if (StringUtil.isNullOrEmpty(record.getValue()))
            throw new UserVipConfigException(1, "值不能为空");
        
        if (StringUtil.isNullOrEmpty(record.getKey()))
            throw new UserVipConfigException(1, "标识不能为空");
 
        
        String remark = record.getRemark();
        if ("null".equalsIgnoreCase(remark)) {
            record.setRemark("");
        }
        
        
        record.setUpdateTime(new Date());
        if (record.getId() == null) {
            record.setStartTime(new Date());
            record.setCreateTime(new Date());
            userVipConfigMapper.insert(record);
        } else {
            UserVipConfig resultObj = userVipConfigMapper.selectByPrimaryKey(record.getId());
            if (resultObj == null)
                throw new UserVipConfigException(1, "修改内容已不存在");
            record.setCreateTime(resultObj.getCreateTime());
            userVipConfigMapper.updateByPrimaryKey(record);
        }
    }
    
    
    @Override
    public void delete(List<Long> idsList) {
        if (idsList != null)
            for (Long id : idsList)
                userVipConfigMapper.deleteByPrimaryKey(id);
 
    }
 
}