|
|
@ -18,21 +18,19 @@ |
|
|
|
package com.epmet.opendata.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.dto.user.param.MidPatrolFormDTO; |
|
|
|
import com.epmet.dto.user.result.MidPatrolDetailResult; |
|
|
|
import com.epmet.dto.user.result.MidPatrolRecordResult; |
|
|
|
import com.epmet.feign.DataStatisticalOpenFeignClient; |
|
|
|
import com.epmet.opendata.dao.UserPatrolDetailDao; |
|
|
|
import com.epmet.opendata.dao.UserPatrolRecordDao; |
|
|
|
import com.epmet.opendata.dto.form.UpsertPatrolRecordForm; |
|
|
|
import com.epmet.opendata.entity.UserPatrolDetailEntity; |
|
|
|
import com.epmet.opendata.entity.UserPatrolRecordEntity; |
|
|
|
import com.epmet.opendata.service.UserPatrolDetailService; |
|
|
|
import com.epmet.opendata.service.UserPatrolRecordService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
@ -57,13 +55,12 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor |
|
|
|
@Autowired |
|
|
|
private DataStatisticalOpenFeignClient dataStatisticalOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private UserPatrolDetailDao userPatrolDetailDao; |
|
|
|
private UserPatrolDetailService userPatrolDetailService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean insertPatrolRecord(UpsertPatrolRecordForm patrolRecordForm) { |
|
|
|
log.info("upsertPatrolRecord 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()) { |
|
|
@ -73,7 +70,6 @@ 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()); |
|
|
@ -117,37 +113,82 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor |
|
|
|
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); |
|
|
|
UserPatrolDetailEntity detailEntity = buildDetailEntity(o); |
|
|
|
//先删除再新增
|
|
|
|
LambdaQueryWrapper<UserPatrolDetailEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
wrapper.eq(UserPatrolDetailEntity::getStaffPatrolRecId, recordEntity.getId()); |
|
|
|
userPatrolDetailDao.delete(wrapper); |
|
|
|
int insert = userPatrolDetailDao.insert(detailEntity); |
|
|
|
userPatrolDetailService.deleteByPatrolId(recordEntity.getId()); |
|
|
|
boolean insert = userPatrolDetailService.insert(detailEntity); |
|
|
|
}); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean reloadPatrolData(String customerId) { |
|
|
|
int pageNo = 1; |
|
|
|
int pageSize = 1000; |
|
|
|
List<MidPatrolRecordResult> resultList = null; |
|
|
|
do { |
|
|
|
MidPatrolFormDTO param = new MidPatrolFormDTO(); |
|
|
|
param.setCustomerId(customerId); |
|
|
|
param.setPageNo(pageNo++); |
|
|
|
param.setPageSize(pageSize); |
|
|
|
Result<List<MidPatrolRecordResult>> record = dataStatisticalOpenFeignClient.getPatrolRecordList(param); |
|
|
|
if (record == null || !record.success()) { |
|
|
|
log.error("获取巡查记录失败,param:{}", JSON.toJSONString(param)); |
|
|
|
return false; |
|
|
|
} |
|
|
|
resultList = record.getData(); |
|
|
|
if (CollectionUtils.isEmpty(resultList)){ |
|
|
|
log.warn("不存在巡查记录,param:{}", JSON.toJSONString(param)); |
|
|
|
return false; |
|
|
|
} |
|
|
|
insertRecordBatch(resultList,true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}while (!CollectionUtils.isEmpty(resultList) && resultList.size()> pageSize ); |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
private Boolean insertRecordBatch(List<MidPatrolRecordResult> list,boolean isReload){ |
|
|
|
List<UserPatrolRecordEntity> insertList = new ArrayList<>(); |
|
|
|
list.forEach(o-> insertList.add(buildEntity(o))); |
|
|
|
//insert
|
|
|
|
if (CollectionUtils.isEmpty(insertList)){ |
|
|
|
log.error("构建要插入的数据为空,param:{}", JSON.toJSONString(list)); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (isReload){ |
|
|
|
userPatrolDetailService.deleteByCustomerId(list.get(0).getCustomerId()); |
|
|
|
} |
|
|
|
this.insertBatch(insertList, NumConstant.ONE_HUNDRED); |
|
|
|
List<UserPatrolDetailEntity> insertDetailList = new ArrayList<>(); |
|
|
|
list.forEach(o-> { |
|
|
|
insertDetailList.add(buildDetailEntity(o)); |
|
|
|
if (!isReload){ |
|
|
|
//先删除再新增
|
|
|
|
userPatrolDetailService.deleteByPatrolId(o.getId()); |
|
|
|
} |
|
|
|
}); |
|
|
|
if (CollectionUtils.isEmpty(insertList)){ |
|
|
|
log.warn("构建要插入的数据为空,param:{}", JSON.toJSONString(list)); |
|
|
|
} |
|
|
|
userPatrolDetailService.insertBatch(insertDetailList, NumConstant.ONE_HUNDRED); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@NotNull |
|
|
|
private UserPatrolDetailEntity buildDetailEntity(MidPatrolRecordResult recordResult, Result<List<MidPatrolDetailResult>> detailResult) { |
|
|
|
private UserPatrolDetailEntity buildDetailEntity(MidPatrolRecordResult recordResult) { |
|
|
|
UserPatrolDetailEntity detailEntity = new UserPatrolDetailEntity(); |
|
|
|
detailEntity.setCustomerId(recordResult.getCustomerId()); |
|
|
|
detailEntity.setStaffPatrolRecId(recordResult.getId()); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
detailResult.getData().forEach(o -> { |
|
|
|
sb.append(o.getLongitude()) |
|
|
|
.append(StrConstant.COMMA) |
|
|
|
.append(o.getLatitude()) |
|
|
|
.append(StrConstant.SEMICOLON); |
|
|
|
}); |
|
|
|
detailEntity.setRoute(sb.toString()); |
|
|
|
detailEntity.setRoute(recordResult.getRoute()); |
|
|
|
detailEntity.setId(recordResult.getId()); |
|
|
|
detailEntity.setRevision(recordResult.getRevision()); |
|
|
|
detailEntity.setCreatedBy(recordResult.getCreatedBy()); |
|
|
@ -188,8 +229,8 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor |
|
|
|
MidPatrolFormDTO midPatrolFormDTO = new MidPatrolFormDTO(); |
|
|
|
midPatrolFormDTO.setCustomerId(patrolRecordForm.getCustomerId()); |
|
|
|
midPatrolFormDTO.setPatrolId(patrolRecordForm.getPatrolId()); |
|
|
|
midPatrolFormDTO.setPageNo(1); |
|
|
|
midPatrolFormDTO.setPageSize(1); |
|
|
|
midPatrolFormDTO.setPageNo(patrolRecordForm.getPageNo()); |
|
|
|
midPatrolFormDTO.setPageSize(patrolRecordForm.getPageSize()); |
|
|
|
return midPatrolFormDTO; |
|
|
|
} |
|
|
|
} |
|
|
|