admin
2024-08-04 bc56870059cca013649077af0e53891cba8dbfd1
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
package com.taoke.autopay.service.impl;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.taoke.autopay.dto.UserSubmitKeyLimitDto;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.service.UserSettingService;
import com.taoke.autopay.utils.StringUtil;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
 
/**
 * @author hxh
 * @title: UserSettingServiceImpl
 * @description: TODO
 * @date 2024/8/1 22:42
 */
@Service
public class UserSettingServiceImpl implements UserSettingService {
 
    @Resource
    private SystemConfigService systemConfigService;
 
 
    @Override
    public void setUserSubmitKeyCount(List<UserSubmitKeyLimitDto> limit) {
        if (limit == null) {
            limit = new ArrayList<>();
        }
        limit.sort((UserSubmitKeyLimitDto o1, UserSubmitKeyLimitDto o2) ->
                o2.getTotalCount() - o1.getTotalCount());
        systemConfigService.setValue(SystemConfigKeyEnum.USER_SUBMIT_KEY_COUNT_LIMIT, new Gson().toJson(limit));
    }
 
    @Override
    public List<UserSubmitKeyLimitDto> getUserSubmitKeyCountList(boolean fromCache) {
        String value = null;
        if (!fromCache) {
            value = systemConfigService.getValue(SystemConfigKeyEnum.USER_SUBMIT_KEY_COUNT_LIMIT);
        } else {
            value = systemConfigService.getValueCache(SystemConfigKeyEnum.USER_SUBMIT_KEY_COUNT_LIMIT);
        }
        if (StringUtil.isNullOrEmpty(value)) {
            return new ArrayList<>();
        }
        return new Gson().fromJson(value, new TypeToken<List<UserSubmitKeyLimitDto>>() {
        }.getType());
    }
 
    @Override
    public int getLimitCountByTotalCount(int totalCount) {
        List<UserSubmitKeyLimitDto> list = getUserSubmitKeyCountList(true);
        if (list.size() == 0) {
            return Integer.MAX_VALUE;
        }
        for (UserSubmitKeyLimitDto t : list) {
            if (totalCount >= t.getTotalCount()) {
                return t.getPerCount();
            }
        }
        return Integer.MAX_VALUE;
    }
}