|
@ -17,12 +17,30 @@ |
|
|
|
|
|
|
|
|
package com.epmet.opendata.service.impl; |
|
|
package com.epmet.opendata.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
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; |
|
|
|
|
|
import com.epmet.feign.DataStatisticalOpenFeignClient; |
|
|
|
|
|
import com.epmet.opendata.dao.UserPatrolDetailDao; |
|
|
import com.epmet.opendata.dao.UserPatrolRecordDao; |
|
|
import com.epmet.opendata.dao.UserPatrolRecordDao; |
|
|
import com.epmet.opendata.dto.form.UpsertPatrolRecordForm; |
|
|
import com.epmet.opendata.dto.form.UpsertPatrolRecordForm; |
|
|
|
|
|
import com.epmet.opendata.entity.UserPatrolDetailEntity; |
|
|
import com.epmet.opendata.entity.UserPatrolRecordEntity; |
|
|
import com.epmet.opendata.entity.UserPatrolRecordEntity; |
|
|
import com.epmet.opendata.service.UserPatrolRecordService; |
|
|
import com.epmet.opendata.service.UserPatrolRecordService; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -31,12 +49,115 @@ import org.springframework.stereotype.Service; |
|
|
* @author generator generator@elink-cn.com |
|
|
* @author generator generator@elink-cn.com |
|
|
* @since v1.0.0 2021-10-14 |
|
|
* @since v1.0.0 2021-10-14 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecordDao, UserPatrolRecordEntity> implements UserPatrolRecordService { |
|
|
public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecordDao, UserPatrolRecordEntity> implements UserPatrolRecordService { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private DataStatisticalOpenFeignClient dataStatisticalOpenFeignClient; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private UserPatrolDetailDao userPatrolDetailDao; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Boolean upsertPatrolRecord(UpsertPatrolRecordForm patrolRecordForm) { |
|
|
public Boolean upsertPatrolRecord(UpsertPatrolRecordForm patrolRecordForm) { |
|
|
return null; |
|
|
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); |
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
userPatrolDetailDao.insert(detailEntity); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
log.info("======"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NotNull |
|
|
|
|
|
private UserPatrolDetailEntity buildDetailEntity(MidPatrolRecordResult recordResult, Result<List<MidPatrolDetailResult>> detailResult) { |
|
|
|
|
|
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.setId(recordResult.getId()); |
|
|
|
|
|
detailEntity.setRevision(recordResult.getRevision()); |
|
|
|
|
|
detailEntity.setCreatedBy(recordResult.getCreatedBy()); |
|
|
|
|
|
detailEntity.setCreatedTime(recordResult.getCreatedTime()); |
|
|
|
|
|
detailEntity.setUpdatedBy(recordResult.getUpdatedBy()); |
|
|
|
|
|
detailEntity.setUpdatedTime(recordResult.getUpdatedTime()); |
|
|
|
|
|
detailEntity.setDelFlag(String.valueOf(recordResult.getDelFlag())); |
|
|
|
|
|
return detailEntity; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private UserPatrolRecordEntity buildEntity(MidPatrolRecordResult recordResult) { |
|
|
|
|
|
UserPatrolRecordEntity entity = new UserPatrolRecordEntity(); |
|
|
|
|
|
entity.setCustomerId(recordResult.getCustomerId()); |
|
|
|
|
|
entity.setGrid(recordResult.getGrid()); |
|
|
|
|
|
entity.setGridPids(recordResult.getGridPids()); |
|
|
|
|
|
entity.setStaffId(recordResult.getStaffId()); |
|
|
|
|
|
entity.setAgencyId(recordResult.getAgencyId()); |
|
|
|
|
|
entity.setPatrolStartTime(recordResult.getPatrolStartTime()); |
|
|
|
|
|
entity.setPatrolEndTime(recordResult.getPatrolEndTime()); |
|
|
|
|
|
entity.setActrualEndTime(recordResult.getActrualEndTime()); |
|
|
|
|
|
entity.setStartLocation(""); |
|
|
|
|
|
entity.setEndLocation(""); |
|
|
|
|
|
entity.setTotalTime(recordResult.getTotalTime()); |
|
|
|
|
|
entity.setDistance(0); |
|
|
|
|
|
entity.setStatus(recordResult.getStatus()); |
|
|
|
|
|
entity.setId(recordResult.getId()); |
|
|
|
|
|
entity.setRevision(recordResult.getRevision()); |
|
|
|
|
|
entity.setCreatedBy(recordResult.getCreatedBy()); |
|
|
|
|
|
entity.setCreatedTime(recordResult.getCreatedTime()); |
|
|
|
|
|
entity.setUpdatedBy(recordResult.getUpdatedBy()); |
|
|
|
|
|
entity.setUpdatedTime(recordResult.getUpdatedTime()); |
|
|
|
|
|
entity.setDelFlag(String.valueOf(recordResult.getDelFlag())); |
|
|
|
|
|
return entity; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NotNull |
|
|
|
|
|
private MidPatrolFormDTO buildParam(UpsertPatrolRecordForm patrolRecordForm) { |
|
|
|
|
|
MidPatrolFormDTO midPatrolFormDTO = new MidPatrolFormDTO(); |
|
|
|
|
|
midPatrolFormDTO.setCustomerId(patrolRecordForm.getCustomerId()); |
|
|
|
|
|
midPatrolFormDTO.setPatrolId(patrolRecordForm.getPatrolId()); |
|
|
|
|
|
midPatrolFormDTO.setPageNo(0); |
|
|
|
|
|
midPatrolFormDTO.setPageSize(1); |
|
|
|
|
|
return midPatrolFormDTO; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|