diff --git a/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java b/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java
index 23d412318b..3fd1db81ac 100644
--- a/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java
+++ b/epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java
@@ -19,7 +19,7 @@ public class UpsertPatrolRecordForm {
/**
* 巡查记录id
*/
- @NotEmpty(message = "customerId不能为空")
+ @NotEmpty(message = "patrolId不能为空")
private String patrolId;
/**
diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/InitDataController.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/InitDataController.java
new file mode 100644
index 0000000000..e8da4e413e
--- /dev/null
+++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/InitDataController.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright 2018 人人开源 https://www.renren.io
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.epmet.opendata.controller;
+
+import com.epmet.commons.tools.utils.Result;
+import com.epmet.opendata.dto.form.UpsertPatrolRecordForm;
+import com.epmet.opendata.service.UserPatrolRecordService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+
+/**
+ * 中间库数据初始化controller
+ *
+ * @author generator generator@elink-cn.com
+ * @since v1.0.0 2021-10-14
+ */
+@RestController
+@RequestMapping("init")
+public class InitDataController {
+
+ @Autowired
+ private UserPatrolRecordService userPatrolRecordService;
+
+ /**
+ * @Author sun
+ * @Description 网格员信息中间库同步
+ **/
+ @PostMapping("patrol/{customerId}")
+ public Result getStaffBaseInfo(@PathVariable String customerId) {
+ UpsertPatrolRecordForm formDTO = new UpsertPatrolRecordForm();
+ formDTO.setCustomerId(customerId);
+ return new Result().ok(userPatrolRecordService.insertPatrolRecord(formDTO));
+ }
+}
diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java
index 3eaf06633c..105b170038 100644
--- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java
+++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java
@@ -40,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
+import java.util.ArrayList;
import java.util.List;
@@ -79,13 +80,14 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl insertList = new ArrayList<>();
+ data.forEach(o-> insertList.add(buildEntity(o)));
//insert
- baseDao.insert(recordEntity);
-
-
+ if (CollectionUtils.isEmpty(insertList)){
+ log.error("构建要插入的数据为空,param:{}", JSON.toJSONString(midPatrolFormDTO));
+ return false;
+ }
+ this.insertBatch(insertList, NumConstant.ONE_HUNDRED);
return true;
}
@@ -93,7 +95,6 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl> record = dataStatisticalOpenFeignClient.getPatrolRecordList(midPatrolFormDTO);
if (record == null || !record.success()) {
@@ -103,34 +104,34 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl data = record.getData();
if (CollectionUtils.isEmpty(data)) {
//数据已被删除了
- delFlag = true;
//暂时设置error 用于排错
log.error("获取巡查记录返回为空,param:{}", JSON.toJSONString(midPatrolFormDTO));
int effectRow = baseDao.deleteById(patrolRecordForm.getPatrolId());
log.warn("del effectRow:{}", effectRow);
return true;
}
- MidPatrolRecordResult recordResult = data.get(NumConstant.ZERO);
- UserPatrolRecordEntity recordEntity = buildEntity(recordResult);
+ data.forEach(o->{
+ UserPatrolRecordEntity recordEntity = buildEntity(o);
+ //update
+ int effectRow = baseDao.updateById(recordEntity);
+ if (effectRow == NumConstant.ZERO) {
+ baseDao.insert(recordEntity);
+ }
+ midPatrolFormDTO.setPage(false);
+ //todo 过滤掉巡查结束时间之后的轨迹
+ Result> detailResult = dataStatisticalOpenFeignClient.getPatrolDetailList(midPatrolFormDTO);
+ if (detailResult == null || !detailResult.success()) {
+ log.error("获取巡查记录明细失败,param:{}", JSON.toJSONString(midPatrolFormDTO));
+ return;
+ }
+ UserPatrolDetailEntity detailEntity = buildDetailEntity(o, detailResult);
+ //先删除再新增
+ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(UserPatrolDetailEntity::getStaffPatrolRecId, recordEntity.getId());
+ userPatrolDetailDao.delete(wrapper);
+ int insert = userPatrolDetailDao.insert(detailEntity);
+ });
- //update
- int effectRow = baseDao.updateById(recordEntity);
- if (effectRow == 0) {
- baseDao.insert(recordEntity);
- }
- midPatrolFormDTO.setPage(false);
- //todo 过滤掉巡查结束时间之后的轨迹
- Result> detailResult = dataStatisticalOpenFeignClient.getPatrolDetailList(midPatrolFormDTO);
- if (detailResult == null || !detailResult.success()) {
- log.error("获取巡查记录明细失败,param:{}", JSON.toJSONString(midPatrolFormDTO));
- return false;
- }
- UserPatrolDetailEntity detailEntity = buildDetailEntity(recordResult, detailResult);
- //先删除再新增
- LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(UserPatrolDetailEntity::getStaffPatrolRecId, recordEntity.getId());
- userPatrolDetailDao.delete(wrapper);
- int insert = userPatrolDetailDao.insert(detailEntity);
return true;
}