|
|
@ -1,20 +1,37 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
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.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.PatrolConstant; |
|
|
|
import com.epmet.dao.CustomerStaffDao; |
|
|
|
import com.epmet.dao.StaffPatrolDetailDao; |
|
|
|
import com.epmet.dao.StaffPatrolRecordDao; |
|
|
|
import com.epmet.dao.UserBaseInfoDao; |
|
|
|
import com.epmet.dto.form.PatrolTrackFormDTO; |
|
|
|
import com.epmet.dto.form.RecordListFormDTO; |
|
|
|
import com.epmet.dto.CustomerGridDTO; |
|
|
|
import com.epmet.dto.StaffPatrolDetailDTO; |
|
|
|
import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.entity.StaffPatrolDetailEntity; |
|
|
|
import com.epmet.entity.StaffPatrolRecordEntity; |
|
|
|
import com.epmet.feign.GovOrgFeignClient; |
|
|
|
import com.epmet.service.StaffPatrolDetailService; |
|
|
|
import com.epmet.service.StaffPatrolRecordService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -24,41 +41,206 @@ import java.util.List; |
|
|
|
* @since v1.0.0 2021-06-07 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class StaffPatrolRecordServiceImpl extends BaseServiceImpl<StaffPatrolRecordDao, StaffPatrolRecordEntity> implements StaffPatrolRecordService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CustomerStaffDao customerStaffDao; |
|
|
|
@Resource |
|
|
|
private StaffPatrolDetailService staffPatrolDetailService; |
|
|
|
@Resource |
|
|
|
private GovOrgFeignClient govOrgFeignClient; |
|
|
|
@Autowired |
|
|
|
private CustomerStaffDao customerStaffDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private StaffPatrolRecordDao staffPatrolRecordDao; |
|
|
|
@Autowired |
|
|
|
private StaffPatrolRecordDao staffPatrolRecordDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private StaffPatrolDetailDao staffPatrolDetailDao; |
|
|
|
@Autowired |
|
|
|
private StaffPatrolDetailDao staffPatrolDetailDao; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 查询经纬度 |
|
|
|
* @Param userIds |
|
|
|
* @author zxc |
|
|
|
* @date 2021/6/9 10:40 上午 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public UserNameAndLLResultDTO selectLL(List<String> userIds) { |
|
|
|
UserNameAndLLResultDTO result = new UserNameAndLLResultDTO(); |
|
|
|
if (CollectionUtils.isEmpty(userIds)){ |
|
|
|
return result; |
|
|
|
} |
|
|
|
// 经纬度查询
|
|
|
|
List<GridManagerUserListResultDTO> llResult = baseDao.selectLL(userIds); |
|
|
|
if (!CollectionUtils.isEmpty(llResult)){ |
|
|
|
result.setLl(llResult); |
|
|
|
} |
|
|
|
// 姓名查询
|
|
|
|
List<UserNameResultDTO> nameResult = customerStaffDao.selectUserName(userIds); |
|
|
|
if (!CollectionUtils.isEmpty(nameResult)){ |
|
|
|
result.setUserNames(nameResult); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 巡查界面初始化 |
|
|
|
* |
|
|
|
* @param tokenDto token |
|
|
|
* @param formDTO 入参 |
|
|
|
* @return com.epmet.dto.result.StaffPatrolInitResultDTO |
|
|
|
* @author zhaoqifeng |
|
|
|
* @date 2021/6/7 16:47 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public StaffPatrolInitResultDTO init(TokenDto tokenDto, StaffPatrolInitFormDTO formDTO) { |
|
|
|
StaffPatrolInitResultDTO result = new StaffPatrolInitResultDTO(); |
|
|
|
QueryWrapper<StaffPatrolRecordEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq(StringUtils.isNotBlank(formDTO.getGridId()), "GRID", formDTO.getGridId()) |
|
|
|
.eq("STAFF_ID", tokenDto.getUserId()) |
|
|
|
.orderByDesc("PATROL_START_TIME") |
|
|
|
.last("limit 1"); |
|
|
|
StaffPatrolRecordEntity entity = baseDao.selectOne(wrapper); |
|
|
|
if (null == entity) { |
|
|
|
result.setLatestSerialNum(NumConstant.ONE_NEG); |
|
|
|
result.setStatus(PatrolConstant.END); |
|
|
|
result.setStaffPatrolRecId(StrConstant.EPMETY_STR); |
|
|
|
return result; |
|
|
|
} |
|
|
|
StaffPatrolDetailDTO detail = staffPatrolDetailService.getLastDetail(entity.getId()); |
|
|
|
result.setStaffPatrolRecId(entity.getId()); |
|
|
|
result.setStatus(entity.getStatus()); |
|
|
|
result.setLatestSerialNum(PatrolConstant.END.equals(entity.getStatus()) ? NumConstant.ONE_NEG : detail.getSerialNum()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 开始巡查 |
|
|
|
* |
|
|
|
* @param tokenDto token |
|
|
|
* @param formDTO 入参 |
|
|
|
* @return com.epmet.dto.result.StartPatrolResultDTO |
|
|
|
* @author zhaoqifeng |
|
|
|
* @date 2021/6/7 16:49 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public StartPatrolResultDTO startPatrol(TokenDto tokenDto, StartPatrolFormDTO formDTO) { |
|
|
|
//获取最新的巡查记录
|
|
|
|
QueryWrapper<StaffPatrolRecordEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq(StringUtils.isNotBlank(formDTO.getGridId()), "GRID", formDTO.getGridId()) |
|
|
|
.orderByDesc("PATROL_START_TIME") |
|
|
|
.last("limit 1"); |
|
|
|
StaffPatrolRecordEntity entity = baseDao.selectOne(wrapper); |
|
|
|
|
|
|
|
CustomerGridFormDTO customerGridFormDTO = new CustomerGridFormDTO(); |
|
|
|
customerGridFormDTO.setGridId(formDTO.getGridId()); |
|
|
|
Result<CustomerGridDTO> gridResult = govOrgFeignClient.getGridBaseInfoByGridId(customerGridFormDTO); |
|
|
|
if (!gridResult.success() || null == gridResult.getData()) { |
|
|
|
//查询网格名称失败
|
|
|
|
log.error(String.format("查找网格信息失败,网格Id:【%s】", formDTO.getGridId())); |
|
|
|
throw new RenException(gridResult.getCode(), gridResult.getMsg()); |
|
|
|
} |
|
|
|
CustomerGridDTO grid = gridResult.getData(); |
|
|
|
|
|
|
|
//判断巡查是否结束,如果未结束,返回消息提示
|
|
|
|
if (null != entity && PatrolConstant.PATROLLING.equals(entity.getStatus())) { |
|
|
|
throw new RenException(EpmetErrorCode.PATROL_IS_NOT_OVER.getCode(), String.format(PatrolConstant.NOT_END_MSG, grid.getGridName(), |
|
|
|
grid.getGridName())); |
|
|
|
} |
|
|
|
//创建巡查记录
|
|
|
|
StaffPatrolRecordEntity record = new StaffPatrolRecordEntity(); |
|
|
|
record.setCustomerId(grid.getCustomerId()); |
|
|
|
record.setAgencyId(grid.getPid()); |
|
|
|
record.setGridPids(grid.getPids()); |
|
|
|
record.setGrid(formDTO.getGridId()); |
|
|
|
record.setStaffId(tokenDto.getUserId()); |
|
|
|
record.setPatrolStartTime(new Date()); |
|
|
|
record.setStatus(PatrolConstant.PATROLLING); |
|
|
|
insert(record); |
|
|
|
|
|
|
|
//保存记录明细
|
|
|
|
StaffPatrolDetailEntity detailEntity = new StaffPatrolDetailEntity(); |
|
|
|
detailEntity.setStaffPatrolRecId(record.getId()); |
|
|
|
detailEntity.setCustomerId(grid.getCustomerId()); |
|
|
|
detailEntity.setSerialNum(formDTO.getSerialNum()); |
|
|
|
detailEntity.setUploadTime(new Date()); |
|
|
|
detailEntity.setLatitude(formDTO.getLatitude()); |
|
|
|
detailEntity.setLongitude(formDTO.getLongitude()); |
|
|
|
detailEntity.setSpeed(formDTO.getSpeed()); |
|
|
|
staffPatrolDetailService.insert(detailEntity); |
|
|
|
|
|
|
|
StartPatrolResultDTO result = new StartPatrolResultDTO(); |
|
|
|
result.setStaffPatrolRecId(record.getId()); |
|
|
|
result.setCarmDown(NumConstant.THIRTY); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 结束巡查 |
|
|
|
* |
|
|
|
* @param tokenDto |
|
|
|
* @param formDTO |
|
|
|
* @return void |
|
|
|
* @author zhaoqifeng |
|
|
|
* @date 2021/6/7 16:49 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void endPatrol(TokenDto tokenDto, StartPatrolFormDTO formDTO) { |
|
|
|
StaffPatrolRecordEntity record = baseDao.selectById(formDTO.getStaffPatrolRecId()); |
|
|
|
if (null == record) { |
|
|
|
throw new RenException("巡查记录不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
record.setActrualEndTime(new Date()); |
|
|
|
record.setUpdatedTime(null); |
|
|
|
record.setPatrolEndTime(DateUtils.parse(formDTO.getPatrolEndTime(), DateUtils.DATE_TIME_PATTERN)); |
|
|
|
record.setTotalTime(DateUtils.calculateSecond(record.getPatrolStartTime(), record.getPatrolEndTime())); |
|
|
|
record.setStatus(PatrolConstant.END); |
|
|
|
|
|
|
|
//保存记录明细
|
|
|
|
StaffPatrolDetailEntity detailEntity = new StaffPatrolDetailEntity(); |
|
|
|
detailEntity.setStaffPatrolRecId(record.getId()); |
|
|
|
detailEntity.setCustomerId(record.getCustomerId()); |
|
|
|
detailEntity.setSerialNum(formDTO.getSerialNum()); |
|
|
|
detailEntity.setUploadTime(new Date()); |
|
|
|
detailEntity.setLatitude(formDTO.getLatitude()); |
|
|
|
detailEntity.setLongitude(formDTO.getLongitude()); |
|
|
|
detailEntity.setSpeed(formDTO.getSpeed()); |
|
|
|
staffPatrolDetailService.insert(detailEntity); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 上传巡查记录 |
|
|
|
* |
|
|
|
* @param tokenDto |
|
|
|
* @param formDTO |
|
|
|
* @return com.epmet.dto.result.PatrolUploadResultDTO |
|
|
|
* @author zhaoqifeng |
|
|
|
* @date 2021/6/7 16:49 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public PatrolUploadResultDTO uploadDetail(TokenDto tokenDto, PatrolUploadFormDTO formDTO) { |
|
|
|
StaffPatrolDetailEntity detailEntity = new StaffPatrolDetailEntity(); |
|
|
|
detailEntity.setStaffPatrolRecId(formDTO.getStaffPatrolRecId()); |
|
|
|
detailEntity.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
detailEntity.setSerialNum(formDTO.getSerialNum()); |
|
|
|
detailEntity.setUploadTime(new Date()); |
|
|
|
detailEntity.setLatitude(formDTO.getLatitude()); |
|
|
|
detailEntity.setLongitude(formDTO.getLongitude()); |
|
|
|
detailEntity.setSpeed(formDTO.getSpeed()); |
|
|
|
detailEntity.setAccuracy(formDTO.getAccuracy()); |
|
|
|
detailEntity.setAltitude(formDTO.getAltitude()); |
|
|
|
detailEntity.setVerticalaccuracy(formDTO.getVerticalAccuracy()); |
|
|
|
detailEntity.setHorizontalaccuracy(formDTO.getHorizontalAccuracy()); |
|
|
|
staffPatrolDetailService.insert(detailEntity); |
|
|
|
|
|
|
|
PatrolUploadResultDTO dto = new PatrolUploadResultDTO(); |
|
|
|
dto.setStaffPatrolRecId(formDTO.getStaffPatrolRecId()); |
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 查询经纬度 |
|
|
|
* @Param userIds |
|
|
|
* @author zxc |
|
|
|
* @date 2021/6/9 10:40 上午 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public UserNameAndLLResultDTO selectLL(List<String> userIds) { |
|
|
|
UserNameAndLLResultDTO result = new UserNameAndLLResultDTO(); |
|
|
|
if (CollectionUtils.isEmpty(userIds)){ |
|
|
|
return result; |
|
|
|
} |
|
|
|
// 经纬度查询
|
|
|
|
List<GridManagerUserListResultDTO> llResult = baseDao.selectLL(userIds); |
|
|
|
if (!CollectionUtils.isEmpty(llResult)){ |
|
|
|
result.setLl(llResult); |
|
|
|
} |
|
|
|
// 姓名查询
|
|
|
|
List<UserNameResultDTO> nameResult = customerStaffDao.selectUserName(userIds); |
|
|
|
if (!CollectionUtils.isEmpty(nameResult)){ |
|
|
|
result.setUserNames(nameResult); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 002、查看巡查记录 |
|
|
|