Administrator
2025-04-21 a217652d33c75df23202828000d82d0ca8555ac2
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
package com.taoke.autopay.service.impl;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.taoke.autopay.dto.ChannelOrderCountDTO;
import com.taoke.autopay.dto.UserSubmitKeyLimitDto;
import com.taoke.autopay.entity.OrderChannelEnum;
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) ->
               o1.getOrderType()==o2.getOrderType() ? o2.getBeforeCount() - o1.getBeforeCount():o1.getOrderType() - o2.getOrderType());
        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 orderType, long beforeCount, OrderChannelEnum orderChannel) {
        List<UserSubmitKeyLimitDto> list = getUserSubmitKeyCountList(true);
        if (list.isEmpty()) {
            return Integer.MAX_VALUE;
        }
        for (UserSubmitKeyLimitDto t : list) {
            if(t.getOrderType()!=orderType){
                continue;
            }
            if (beforeCount >= t.getBeforeCount()) {
                for(ChannelOrderCountDTO tt:t.getTodayOrderCountList()){
                    if(tt.getOrderChannel() ==orderChannel){
                        return tt.getOrderCount();
                    }
                }
                return Integer.MAX_VALUE;
            }
        }
        return Integer.MAX_VALUE;
    }
}