|
@@ -12,7 +12,6 @@ import com.usky.fire.domain.MhCompany;
|
|
import com.usky.fire.mapper.MhBuildMapper;
|
|
import com.usky.fire.mapper.MhBuildMapper;
|
|
import com.usky.fire.mapper.MhCompanyMapper;
|
|
import com.usky.fire.mapper.MhCompanyMapper;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.HttpGet;
|
|
import org.apache.http.client.methods.HttpGet;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
@@ -26,7 +25,6 @@ import org.springframework.stereotype.Component;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -37,10 +35,10 @@ public class MhScheduledImport {
|
|
|
|
|
|
private static final int PAGE_SIZE = 10000;
|
|
private static final int PAGE_SIZE = 10000;
|
|
private static final String BUILD_URL = "http://10.90.12.78:8085/Warehouse/minhang/getData/buildDataList?";
|
|
private static final String BUILD_URL = "http://10.90.12.78:8085/Warehouse/minhang/getData/buildDataList?";
|
|
- private static final String BUILD_URL_TEST = "https://aqpc.shxf-119.com/Warehouse/minhang/getData/buildDataList?";
|
|
|
|
|
|
+ // private static final String BUILD_URL_TEST = "https://aqpc.shxf-119.com/Warehouse/minhang/getData/buildDataList?";
|
|
private static final String COMPANY_URL = "http://10.90.12.78:8085/Warehouse/minhang/getData/companyDataList?";
|
|
private static final String COMPANY_URL = "http://10.90.12.78:8085/Warehouse/minhang/getData/companyDataList?";
|
|
- private static final String COMPANY_URL_TEST = "https://aqpc.shxf-119.com/Warehouse/minhang/getData/companyDataList?";
|
|
|
|
- // private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
+ // private static final String COMPANY_URL_TEST = "https://aqpc.shxf-119.com/Warehouse/minhang/getData/companyDataList?";
|
|
|
|
+ private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
// private static final DateTimeFormatter inputFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
|
// private static final DateTimeFormatter inputFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
|
@Autowired
|
|
@Autowired
|
|
private MhCompanyMapper mhCompanyMapper;
|
|
private MhCompanyMapper mhCompanyMapper;
|
|
@@ -59,7 +57,7 @@ public class MhScheduledImport {
|
|
//@Scheduled(cron = "0 0 8,20 * * ?")
|
|
//@Scheduled(cron = "0 0 8,20 * * ?")
|
|
// 8点、20点执行一次
|
|
// 8点、20点执行一次
|
|
//@Scheduled(fixedRate = 40000)
|
|
//@Scheduled(fixedRate = 40000)
|
|
- @Scheduled(fixedRate = 30000)
|
|
|
|
|
|
+ @Scheduled(fixedRate = 3600000)
|
|
public void executeTask() {
|
|
public void executeTask() {
|
|
log.info("定时任务开始执行: " + new java.util.Date());
|
|
log.info("定时任务开始执行: " + new java.util.Date());
|
|
|
|
|
|
@@ -125,17 +123,11 @@ public class MhScheduledImport {
|
|
mhBuild.setProperty(row.getInteger("property"));
|
|
mhBuild.setProperty(row.getInteger("property"));
|
|
mhBuild.setPropertyStr(row.getString("propertyStr"));
|
|
mhBuild.setPropertyStr(row.getString("propertyStr"));
|
|
mhBuild.setManageCompany(row.getString("manageCompany"));
|
|
mhBuild.setManageCompany(row.getString("manageCompany"));
|
|
- mhBuild.setBuildNatures(row.getString("buildNatures") != null
|
|
|
|
- ? Arrays.asList(row.getString("buildNatures").split(","))
|
|
|
|
- : Collections.emptyList());
|
|
|
|
- mhBuild.setFireFightingDevices(row.getString("fireFightingDevices") != null
|
|
|
|
- ? Arrays.asList(row.getString("fireFightingDevices").split(","))
|
|
|
|
- : Collections.emptyList());
|
|
|
|
- mhBuild.setCompanyInfos(row.getString("companyInfos") != null
|
|
|
|
- ? Arrays.asList(row.getString("companyInfos").split(","))
|
|
|
|
- : Collections.emptyList());
|
|
|
|
|
|
+ mhBuild.setBuildNatures(row.getString("buildNatures"));
|
|
|
|
+ mhBuild.setFireFightingDevices(row.getString("fireFightingDevices"));
|
|
|
|
+ mhBuild.setCompanyInfos(row.getString("companyInfos"));
|
|
mhBuild.setCompanyOperLogs(row.getString("companyOperLogs"));
|
|
mhBuild.setCompanyOperLogs(row.getString("companyOperLogs"));
|
|
- mhBuild.setUpdateTime(LocalDateTime.parse(row.getString("updateTime")));
|
|
|
|
|
|
+ mhBuild.setUpdateTime(LocalDateTime.parse(row.getString("updateTime"), formatter));
|
|
mhBuild.setUpdateTimeStr(row.getString("updateTimeStr"));
|
|
mhBuild.setUpdateTimeStr(row.getString("updateTimeStr"));
|
|
mhBuild.setUpdateBy(row.getString("updateBy"));
|
|
mhBuild.setUpdateBy(row.getString("updateBy"));
|
|
mhBuild.setUpperUpdateCompany(row.getString("upperUpdateCompany"));
|
|
mhBuild.setUpperUpdateCompany(row.getString("upperUpdateCompany"));
|
|
@@ -236,9 +228,9 @@ public class MhScheduledImport {
|
|
mhCompany.setIsExamine(row.getInteger("isExamine"));
|
|
mhCompany.setIsExamine(row.getInteger("isExamine"));
|
|
mhCompany.setHaveTrouble(row.getString("haveTrouble"));
|
|
mhCompany.setHaveTrouble(row.getString("haveTrouble"));
|
|
mhCompany.setCreateBy(row.getString("createBy"));
|
|
mhCompany.setCreateBy(row.getString("createBy"));
|
|
- mhCompany.setCreateTime(LocalDateTime.parse(row.getString("createTime")));
|
|
|
|
|
|
+ mhCompany.setCreateTime(LocalDateTime.parse(row.getString("createTime"), formatter));
|
|
mhCompany.setUpdateBy(row.getString("updateBy"));
|
|
mhCompany.setUpdateBy(row.getString("updateBy"));
|
|
- mhCompany.setUpdateTime(LocalDateTime.parse(row.getString("updateTime")));
|
|
|
|
|
|
+ mhCompany.setUpdateTime(LocalDateTime.parse(row.getString("updateTime"), formatter));
|
|
return mhCompany;
|
|
return mhCompany;
|
|
|
|
|
|
|
|
|
|
@@ -283,12 +275,12 @@ public class MhScheduledImport {
|
|
|
|
|
|
// 获取建筑信息
|
|
// 获取建筑信息
|
|
private List<MhBuild> callApiToGetBuildingData(LocalDateTime latestCreateTime, int page) {
|
|
private List<MhBuild> callApiToGetBuildingData(LocalDateTime latestCreateTime, int page) {
|
|
- return callApiToGetMhBuildData(BUILD_URL_TEST, latestCreateTime, page, MhScheduledImport.PAGE_SIZE);
|
|
|
|
|
|
+ return callApiToGetMhBuildData(BUILD_URL, latestCreateTime, page, MhScheduledImport.PAGE_SIZE);
|
|
}
|
|
}
|
|
|
|
|
|
// 获取单位数据
|
|
// 获取单位数据
|
|
private List<MhCompany> callApiToGetCompanyData(LocalDateTime latestCreateTime, int page) {
|
|
private List<MhCompany> callApiToGetCompanyData(LocalDateTime latestCreateTime, int page) {
|
|
- return callApiToGetCompanyData(COMPANY_URL_TEST, latestCreateTime, page, PAGE_SIZE);
|
|
|
|
|
|
+ return callApiToGetCompanyData(COMPANY_URL, latestCreateTime, page, PAGE_SIZE);
|
|
}
|
|
}
|
|
|
|
|
|
// 公共方法:发送 HTTP GET 请求并处理响应
|
|
// 公共方法:发送 HTTP GET 请求并处理响应
|
|
@@ -410,9 +402,9 @@ public class MhScheduledImport {
|
|
newData.select(MhCompany::getCreateTime)
|
|
newData.select(MhCompany::getCreateTime)
|
|
.orderByDesc(MhCompany::getCreateTime)
|
|
.orderByDesc(MhCompany::getCreateTime)
|
|
.last("LIMIT 1");
|
|
.last("LIMIT 1");
|
|
- MhCompany latestRecord = mhCompanyMapper.selectOne(newData);
|
|
|
|
- log.info("最新一条单位数据{} ", latestRecord);
|
|
|
|
- return latestRecord != null ? latestRecord.getCreateTime() : null;
|
|
|
|
|
|
+ LocalDateTime latestRecord = mhCompanyMapper.selectOne(newData).getCreateTime();
|
|
|
|
+ log.info("最新一条单位数据创建时间{} ", latestRecord);
|
|
|
|
+ return latestRecord;
|
|
}
|
|
}
|
|
|
|
|
|
// 获取数据库中mh_build最新的一条记录的 updateTime
|
|
// 获取数据库中mh_build最新的一条记录的 updateTime
|
|
@@ -421,13 +413,15 @@ public class MhScheduledImport {
|
|
newData.select(MhBuild::getUpdateTime)
|
|
newData.select(MhBuild::getUpdateTime)
|
|
.orderByDesc(MhBuild::getUpdateTime)
|
|
.orderByDesc(MhBuild::getUpdateTime)
|
|
.last("LIMIT 1");
|
|
.last("LIMIT 1");
|
|
- MhBuild latestRecord = mhBuildMapper.selectOne(newData);
|
|
|
|
- log.info("最新一条建筑数据{} ", latestRecord);
|
|
|
|
- return latestRecord != null ? latestRecord.getUpdateTime() : null;
|
|
|
|
|
|
+ LocalDateTime latestRecord = mhBuildMapper.selectOne(newData).getUpdateTime();
|
|
|
|
+ log.info("最新一条建筑数据更新时间{} ", latestRecord);
|
|
|
|
+ return latestRecord;
|
|
}
|
|
}
|
|
|
|
|
|
// 将数据存储到本地数据库的方法
|
|
// 将数据存储到本地数据库的方法
|
|
private void storeDataToLocalDatabase(List<MhCompany> datmhCompanyaList) {
|
|
private void storeDataToLocalDatabase(List<MhCompany> datmhCompanyaList) {
|
|
|
|
+ int insertCount = 0;
|
|
|
|
+ int updateCount = 0;
|
|
for (MhCompany mhCompany : datmhCompanyaList) {
|
|
for (MhCompany mhCompany : datmhCompanyaList) {
|
|
// Integer id = Integer.valueOf(data[0]);
|
|
// Integer id = Integer.valueOf(data[0]);
|
|
// String companyName = data[1];
|
|
// String companyName = data[1];
|
|
@@ -479,11 +473,19 @@ public class MhScheduledImport {
|
|
// }
|
|
// }
|
|
|
|
|
|
mhCompanyMapper.insert(mhCompany);
|
|
mhCompanyMapper.insert(mhCompany);
|
|
|
|
+ insertCount++;
|
|
|
|
+ } else if (recordExists(id)) {
|
|
|
|
+ mhCompanyMapper.updateById(mhCompany);
|
|
|
|
+ updateCount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ log.info("成功插入{} 条单位数据", insertCount);
|
|
|
|
+ log.info("成功更新{} 条单位数据", updateCount);
|
|
}
|
|
}
|
|
|
|
|
|
private void storeBuildingDataToLocalDatabase(List<MhBuild> dataList) {
|
|
private void storeBuildingDataToLocalDatabase(List<MhBuild> dataList) {
|
|
|
|
+ int insertCount = 0;
|
|
|
|
+ int updateCount = 0;
|
|
for (MhBuild mhBuild : dataList) {
|
|
for (MhBuild mhBuild : dataList) {
|
|
// Integer id = Integer.valueOf(data[0]);
|
|
// Integer id = Integer.valueOf(data[0]);
|
|
Long id = mhBuild.getId();
|
|
Long id = mhBuild.getId();
|
|
@@ -569,8 +571,14 @@ public class MhScheduledImport {
|
|
// mhBuildMapper.insert(mhBuilding);
|
|
// mhBuildMapper.insert(mhBuilding);
|
|
|
|
|
|
mhBuildMapper.insert(mhBuild);
|
|
mhBuildMapper.insert(mhBuild);
|
|
|
|
+ insertCount++;
|
|
|
|
+ } else if (buildingRecordExists(id)) {
|
|
|
|
+ mhBuildMapper.updateById(mhBuild);
|
|
|
|
+ updateCount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ log.info("成功插入 {} 条建筑数据", insertCount);
|
|
|
|
+ log.info("成功更新 {} 条建筑数据", updateCount);
|
|
}
|
|
}
|
|
|
|
|
|
// 检查记录是否已经存在于数据库中-单位
|
|
// 检查记录是否已经存在于数据库中-单位
|