package com.taoke.autopay.service.impl;
|
|
import com.taoke.autopay.dao.SystemConfigMapper;
|
import com.taoke.autopay.dto.WXAppInfoDto;
|
import com.taoke.autopay.entity.SystemConfig;
|
import com.taoke.autopay.entity.SystemConfigKeyEnum;
|
import com.taoke.autopay.service.SystemConfigService;
|
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @author hxh
|
* @title: SystemConfigServiceImpl
|
* @description: 系统配置服务实现
|
* @date 2024/6/28 17:50
|
*/
|
@Service
|
public class SystemConfigServiceImpl implements SystemConfigService {
|
|
@Resource
|
private SystemConfigMapper systemConfigMapper;
|
|
@Override
|
public WXAppInfoDto getWxAppInfo() {
|
SystemConfig c1 = get(SystemConfigKeyEnum.WX_APP_ID);
|
SystemConfig c2 = get(SystemConfigKeyEnum.WX_APP_SECRET);
|
if (c1 != null && c2 != null) {
|
return new WXAppInfoDto(c1.getValue(), c2.getValue());
|
}
|
return null;
|
}
|
|
|
@Cacheable(value = "configCache", key = "'getWxAppInfoCache'")
|
@Override
|
public WXAppInfoDto getWxAppInfoCache() {
|
return getWxAppInfo();
|
}
|
|
@Override
|
public SystemConfig get(SystemConfigKeyEnum key) {
|
if (key == null) {
|
return null;
|
}
|
SystemConfigMapper.DaoQuery daoQuery = new SystemConfigMapper.DaoQuery();
|
daoQuery.count = 1;
|
daoQuery.start = 0;
|
daoQuery.key = key.getKey();
|
|
List<SystemConfig> list = systemConfigMapper.list(daoQuery);
|
if (list != null && list.size() > 0) {
|
return list.get(0);
|
}
|
return null;
|
}
|
|
@Cacheable(value = "configCache", key = "'getCache-'+#key")
|
@Override
|
public SystemConfig getCache(SystemConfigKeyEnum key) {
|
|
return get(key);
|
}
|
|
@Override
|
public String getValue(SystemConfigKeyEnum key) {
|
SystemConfig config = get(key);
|
if (config != null) {
|
return config.getValue();
|
}
|
return null;
|
}
|
|
@Cacheable(value = "configCache", key = "'getValueCache-'+#key")
|
@Override
|
public String getValueCache(SystemConfigKeyEnum key) {
|
SystemConfig config = get(key);
|
if (config != null) {
|
return config.getValue();
|
}
|
return null;
|
}
|
|
@CacheEvict(value = "configCache", allEntries = true)
|
@Override
|
public void clearCache() {
|
|
}
|
|
@Override
|
public void setValue(SystemConfigKeyEnum key, String val) {
|
SystemConfig config = get(key);
|
if (config != null) {
|
SystemConfig update = new SystemConfig();
|
update.setId(config.getId());
|
update.setValue(val);
|
update.setUpdateTime(new Date());
|
systemConfigMapper.updateByPrimaryKeySelective(update);
|
}
|
}
|
|
|
}
|