Browse Source

巡查方法调整并添加初始化数据入口

dev_shibei_match
jianjun 4 years ago
parent
commit
e964b04213
  1. 2
      epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java
  2. 50
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/InitDataController.java
  3. 57
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java

2
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;
/**

50
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<Boolean> getStaffBaseInfo(@PathVariable String customerId) {
UpsertPatrolRecordForm formDTO = new UpsertPatrolRecordForm();
formDTO.setCustomerId(customerId);
return new Result().ok(userPatrolRecordService.insertPatrolRecord(formDTO));
}
}

57
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<UserPatrolRecor
log.warn("del effectRow:{}", effectRow);
return true;
}
MidPatrolRecordResult recordResult = data.get(NumConstant.ZERO);
UserPatrolRecordEntity recordEntity = buildEntity(recordResult);
List<UserPatrolRecordEntity> 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<UserPatrolRecor
public Boolean updatePatrolRecord(UpsertPatrolRecordForm patrolRecordForm) {
log.info("updatePatrolRecord param:{}", JSON.toJSONString(patrolRecordForm));
ValidatorUtils.validateEntity(patrolRecordForm);
boolean delFlag = false;
MidPatrolFormDTO midPatrolFormDTO = buildParam(patrolRecordForm);
Result<List<MidPatrolRecordResult>> record = dataStatisticalOpenFeignClient.getPatrolRecordList(midPatrolFormDTO);
if (record == null || !record.success()) {
@ -103,34 +104,34 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor
List<MidPatrolRecordResult> 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<List<MidPatrolDetailResult>> detailResult = dataStatisticalOpenFeignClient.getPatrolDetailList(midPatrolFormDTO);
if (detailResult == null || !detailResult.success()) {
log.error("获取巡查记录明细失败,param:{}", JSON.toJSONString(midPatrolFormDTO));
return;
}
UserPatrolDetailEntity detailEntity = buildDetailEntity(o, detailResult);
//先删除再新增
LambdaQueryWrapper<UserPatrolDetailEntity> 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<List<MidPatrolDetailResult>> detailResult = dataStatisticalOpenFeignClient.getPatrolDetailList(midPatrolFormDTO);
if (detailResult == null || !detailResult.success()) {
log.error("获取巡查记录明细失败,param:{}", JSON.toJSONString(midPatrolFormDTO));
return false;
}
UserPatrolDetailEntity detailEntity = buildDetailEntity(recordResult, detailResult);
//先删除再新增
LambdaQueryWrapper<UserPatrolDetailEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserPatrolDetailEntity::getStaffPatrolRecId, recordEntity.getId());
userPatrolDetailDao.delete(wrapper);
int insert = userPatrolDetailDao.insert(detailEntity);
return true;
}

Loading…
Cancel
Save