|
|
@ -18,12 +18,12 @@ |
|
|
|
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.constant.SystemMessageType; |
|
|
|
import com.epmet.dto.user.param.MidPatrolFormDTO; |
|
|
|
import com.epmet.dto.user.result.MidPatrolDetailResult; |
|
|
|
import com.epmet.dto.user.result.MidPatrolRecordResult; |
|
|
@ -59,48 +59,76 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor |
|
|
|
private UserPatrolDetailDao userPatrolDetailDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean upsertPatrolRecord(UpsertPatrolRecordForm patrolRecordForm) { |
|
|
|
log.info("upsertPatrolRecord param:{}",JSON.toJSONString(patrolRecordForm)); |
|
|
|
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()){ |
|
|
|
if (record == null || !record.success()) { |
|
|
|
log.error("获取巡查记录失败,param:{}", JSON.toJSONString(midPatrolFormDTO)); |
|
|
|
return false; |
|
|
|
} |
|
|
|
List<MidPatrolRecordResult> data = record.getData(); |
|
|
|
if (CollectionUtils.isEmpty(data)){ |
|
|
|
if (CollectionUtils.isEmpty(data)) { |
|
|
|
//数据已被删除了
|
|
|
|
delFlag = true; |
|
|
|
//暂时设置error 用于排错
|
|
|
|
log.error("获取巡查记录返回为空,param:{}", JSON.toJSONString(midPatrolFormDTO)); |
|
|
|
int effectRow = baseDao.deleteById(patrolRecordForm.getPatrolId()); |
|
|
|
log.warn("del effectRow:{}",effectRow); |
|
|
|
log.warn("del effectRow:{}", effectRow); |
|
|
|
return true; |
|
|
|
} |
|
|
|
MidPatrolRecordResult recordResult = data.get(NumConstant.ZERO); |
|
|
|
switch (patrolRecordForm.getActionType()){ |
|
|
|
case SystemMessageType.USER_PATROL_START: |
|
|
|
//insert
|
|
|
|
baseDao.insert(buildEntity(recordResult)); |
|
|
|
break; |
|
|
|
case SystemMessageType.USER_PATROL_STOP: |
|
|
|
//update
|
|
|
|
baseDao.updateById(buildEntity(recordResult)); |
|
|
|
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); |
|
|
|
UserPatrolRecordEntity recordEntity = buildEntity(recordResult); |
|
|
|
|
|
|
|
userPatrolDetailDao.insert(detailEntity); |
|
|
|
break; |
|
|
|
default: |
|
|
|
log.info("======"); |
|
|
|
//insert
|
|
|
|
baseDao.insert(recordEntity); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
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()) { |
|
|
|
log.error("获取巡查记录失败,param:{}", JSON.toJSONString(midPatrolFormDTO)); |
|
|
|
return false; |
|
|
|
} |
|
|
|
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); |
|
|
|
|
|
|
|
//update
|
|
|
|
int effectRow = baseDao.updateById(recordEntity); |
|
|
|
if (effectRow == 0) { |
|
|
|
baseDao.insert(recordEntity); |
|
|
|
} |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
@ -109,8 +137,8 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor |
|
|
|
UserPatrolDetailEntity detailEntity = new UserPatrolDetailEntity(); |
|
|
|
detailEntity.setCustomerId(recordResult.getCustomerId()); |
|
|
|
detailEntity.setStaffPatrolRecId(recordResult.getId()); |
|
|
|
StringBuilder sb =new StringBuilder(); |
|
|
|
detailResult.getData().forEach(o->{ |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
detailResult.getData().forEach(o -> { |
|
|
|
sb.append(o.getLongitude()) |
|
|
|
.append(StrConstant.COMMA) |
|
|
|
.append(o.getLatitude()) |
|
|
|