地区数据初始化之后,数据无法访问,因为缓存没有更新。现在更新为初始化完成,即清空与地区相关的缓存
This commit is contained in:
parent
f9f8cce13e
commit
f949896685
@ -1,8 +1,7 @@
|
||||
package cn.lili.modules.base.serviceimpl;
|
||||
|
||||
import cn.lili.common.utils.HttpClientUtils;
|
||||
import cn.lili.common.cache.Cache;
|
||||
import cn.lili.common.utils.SnowFlake;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.modules.base.mapper.RegionMapper;
|
||||
import cn.lili.modules.base.service.RegionService;
|
||||
import cn.lili.modules.system.entity.dos.Region;
|
||||
@ -13,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -33,24 +33,28 @@ public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> impleme
|
||||
*/
|
||||
private String syncUrl = "https://restapi.amap.com/v3/config/district?subdistrict=4&key=e456d77800e2084a326f7b777278f89d";
|
||||
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
@Override
|
||||
public void synchronizationData(String url) {
|
||||
try {
|
||||
|
||||
//清空数据
|
||||
QueryWrapper<Region> queryWrapper = new QueryWrapper();
|
||||
queryWrapper.ne("id", "-1");
|
||||
this.remove(queryWrapper);
|
||||
|
||||
//读取数据
|
||||
String jsonString = HttpClientUtils.doGet(StringUtils.isEmpty(url) ? syncUrl : url, null);
|
||||
|
||||
//构造存储数据库的对象集合
|
||||
List<Region> regions = this.initData(jsonString);
|
||||
for (int i = 0; i < (regions.size() / 100 + (regions.size() % 100 == 0 ? 0 : 1)); i++) {
|
||||
int endPoint = Math.min((100 + (i * 100)), regions.size());
|
||||
this.saveBatch(regions.subList(i * 100, endPoint));
|
||||
}
|
||||
// //清空数据
|
||||
// QueryWrapper<Region> queryWrapper = new QueryWrapper();
|
||||
// queryWrapper.ne("id", "-1");
|
||||
// this.remove(queryWrapper);
|
||||
//
|
||||
// //读取数据
|
||||
// String jsonString = HttpClientUtils.doGet(StringUtils.isEmpty(url) ? syncUrl : url, null);
|
||||
//
|
||||
// //构造存储数据库的对象集合
|
||||
// List<Region> regions = this.initData(jsonString);
|
||||
// for (int i = 0; i < (regions.size() / 100 + (regions.size() % 100 == 0 ? 0 : 1)); i++) {
|
||||
// int endPoint = Math.min((100 + (i * 100)), regions.size());
|
||||
// this.saveBatch(regions.subList(i * 100, endPoint));
|
||||
// }
|
||||
//删除缓存
|
||||
cache.vagueDel("{regions}");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ public class ManagerSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.authorizeRequests();
|
||||
// 配置的url 不需要授权
|
||||
for (String url : ignoredUrlsProperties.getUrls()) {
|
||||
log.error(url);
|
||||
registry.antMatchers(url).permitAll();
|
||||
}
|
||||
registry
|
||||
|
Loading…
x
Reference in New Issue
Block a user