1. 场景描述
通过java代码从外围接口中获取数据并落地,已经存在的不落地,不存在的落地,因有部分字段变化是正常的,只需比对3个字段相同即为相同。
2. 解决方案
设置定时任务(三个标签完成springboot定时任务配置),比对接口中获取的数据和本地落地的数据是否相同。
2.1 真实代码
@Scheduled(cron = "0 10 2 * * ? ")
public void execAppUser() {
synchronized (this) {
JSONArray array = null;
try {
array = testService.getUsers();
} catch (Exception e) {
e.printStackTrace();
}
//接口获取user
List iusers = JSONObject.parseArray(array.toJSONString(), AppUser.class);
List users = appUserService.getAllUsers();
for (AppUser iuser : iusers) {
if (users.contains(iuser)){
continue;
}
appUserService.insert(iuser);
}
}
}
2.2 代码说明
(1)使用users.contains(iuser)ÿ