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.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) ->
|
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(long totalCount, OrderChannelEnum orderChannel) {
|
List<UserSubmitKeyLimitDto> list = getUserSubmitKeyCountList(true);
|
if (list.size() == 0) {
|
return Integer.MAX_VALUE;
|
}
|
for (UserSubmitKeyLimitDto t : list) {
|
if (totalCount >= t.getTotalCount()) {
|
if(orderChannel==OrderChannelEnum.cyx){
|
return t.getPerCountCyx();
|
}
|
else if(orderChannel==OrderChannelEnum.bps){
|
return t.getPerCountBps();
|
}
|
else if(orderChannel==OrderChannelEnum.unknown){
|
return t.getPerCountUnknown();
|
}
|
return Integer.MAX_VALUE;
|
}
|
}
|
return Integer.MAX_VALUE;
|
}
|
}
|