| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import cn.hutool.crypto.asymmetric.Sign; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.PositionUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.PlatformJobMapper; |
| | | import com.doumee.dao.business.PlatformMapper; |
| | | import com.doumee.dao.business.join.PlatformJobJoinMapper; |
| | | import com.doumee.dao.business.model.Platform; |
| | | import com.doumee.dao.business.model.PlatformBooks; |
| | | import com.doumee.dao.business.model.PlatformJob; |
| | | import com.doumee.dao.business.model.PlatformReason; |
| | | import com.doumee.dao.web.reqeust.JobDetailDTO; |
| | | import com.doumee.dao.web.reqeust.LineUpDetailDTO; |
| | | import com.doumee.dao.web.reqeust.SignInDTO; |
| | | import com.doumee.dao.web.response.DriverHomeVO; |
| | | import com.doumee.dao.web.response.LineUpVO; |
| | | import com.doumee.service.business.PlatformJobService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | 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 java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 月台调度作业信息表Service实现 |
| | |
| | | |
| | | @Autowired |
| | | private PlatformJobMapper platformJobMapper; |
| | | |
| | | @Autowired |
| | | private PlatformJobJoinMapper platformJobJoinMapper; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Autowired |
| | | private PlatformMapper platformMapper; |
| | | |
| | | |
| | | @Override |
| | | public Integer create(PlatformJob platformJob) { |
| | |
| | | QueryWrapper<PlatformJob> wrapper = new QueryWrapper<>(platformJob); |
| | | return platformJobMapper.selectCount(wrapper); |
| | | } |
| | | |
| | | //TODO |
| | | @Override |
| | | public DriverHomeVO getDriverHome(Integer memberId){ |
| | | DriverHomeVO driverHomeVO = new DriverHomeVO(); |
| | | //TODO 轮播图 |
| | | |
| | | List<PlatformJob> platformJobList = platformJobMapper.selectList(new QueryWrapper<PlatformJob>() |
| | | .lambda() |
| | | .eq(PlatformJob::getDriverId,memberId) |
| | | // .like(PlatformJob::get) |
| | | .orderByDesc(PlatformJob::getId)); |
| | | driverHomeVO.setPlatformJobList(platformJobList); |
| | | |
| | | |
| | | return driverHomeVO; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 距离签到 |
| | | * @param signInDTO |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |
| | | public void signIn(SignInDTO signInDTO){ |
| | | if(Objects.isNull(signInDTO) |
| | | || Objects.isNull(signInDTO.getSignType()) |
| | | || Objects.isNull(signInDTO.getJobId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | PlatformJob platformJob = platformJobMapper.selectById(signInDTO.getJobId()); |
| | | if(Objects.isNull(platformJob)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | if(!Constants.equalsInteger(platformJob.getStatus(),Constants.PlatformJobStatus.WART_SIGN_IN.getKey())){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"业务状态已流转,请刷新查看"); |
| | | } |
| | | if(Constants.equalsInteger(signInDTO.getSignType(),Constants.ZERO)){ |
| | | this.distanceSignIn(signInDTO,platformJob); |
| | | }else if(Constants.equalsInteger(signInDTO.getSignType(),Constants.ONE)){ |
| | | this.sceneSignIn(signInDTO); |
| | | } |
| | | platformJob.setSignDate(new Date()); |
| | | platformJob.setSingType(Constants.ZERO); |
| | | platformJob.setStatus(Constants.PlatformJobStatus.WAIT_CALL.getKey()); |
| | | platformJobMapper.updateById(platformJob); |
| | | } |
| | | |
| | | |
| | | public void distanceSignIn(SignInDTO signInDTO , PlatformJob platformJob){ |
| | | if(Objects.isNull(signInDTO.getLat()) |
| | | || Objects.isNull(signInDTO.getLnt())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"经纬度信息异常"); |
| | | } |
| | | //获取签到点的经纬度 |
| | | Double lat = Double.parseDouble(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_PLACE_LAT).getCode()); |
| | | Double lnt = Double.parseDouble(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_PLACE_LNT).getCode()); |
| | | BigDecimal distance = new BigDecimal(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_PLACE_DISTANCE).getCode()); |
| | | //获取2个点的距离X米 |
| | | Double getDistanceDouble = PositionUtil.getDistance(signInDTO.getLnt(),signInDTO.getLat(),lnt,lat); |
| | | //转换km |
| | | BigDecimal getDistance = BigDecimal.valueOf(getDistanceDouble).divide(new BigDecimal(1000),2,BigDecimal.ROUND_HALF_UP); |
| | | if(distance.compareTo(getDistance)<Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"超出可签到距离,可签到距离["+distance+"]公里]"); |
| | | } |
| | | platformJob.setSignDistance(BigDecimal.valueOf(getDistanceDouble)); |
| | | } |
| | | |
| | | public void sceneSignIn(SignInDTO signInDTO){ |
| | | if( StringUtils.isNotBlank(signInDTO.getQrCodeKey())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | if(!signInDTO.getQrCodeKey().equals(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE).getCode())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"二维码已过期,请刷新重试"); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public PlatformJob getDetail(JobDetailDTO jobDetailDTO){ |
| | | if(Objects.isNull(jobDetailDTO) |
| | | || Objects.isNull(jobDetailDTO.getJobId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | PlatformJob platformJob = platformJobMapper.selectById(jobDetailDTO.getJobId()); |
| | | if(Objects.isNull(platformJob)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | if(Constants.equalsInteger(platformJob.getStatus(),Constants.PlatformJobStatus.WART_SIGN_IN.getKey())){ |
| | | //待签到 计算距离 |
| | | if(Objects.nonNull(jobDetailDTO.getLnt())&&Objects.nonNull(jobDetailDTO.getLat())){ |
| | | //获取签到点的经纬度 |
| | | Double lat = Double.parseDouble(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_PLACE_LAT).getCode()); |
| | | Double lnt = Double.parseDouble(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_PLACE_LNT).getCode()); |
| | | //获取2个点的距离X米 |
| | | Double getDistanceDouble = PositionUtil.getDistance(jobDetailDTO.getLnt(),jobDetailDTO.getLat(),lnt,lat); |
| | | //转换km |
| | | BigDecimal getDistance = BigDecimal.valueOf(getDistanceDouble).divide(new BigDecimal(1000),2,BigDecimal.ROUND_HALF_UP); |
| | | platformJob.setGetDistance(getDistance); |
| | | } |
| | | }else if( Constants.equalsInteger(platformJob.getStatus(),Constants.PlatformJobStatus.WAIT_CALL.getKey()) |
| | | || Constants.equalsInteger(platformJob.getStatus(),Constants.PlatformJobStatus.IN_WAIT.getKey()) |
| | | ){//查询排队情况 |
| | | Long lineUpNum = platformJobMapper.selectCount(new QueryWrapper<PlatformJob>().lambda() |
| | | .eq(PlatformJob::getIsdeleted,Constants.ZERO) |
| | | .in(PlatformJob::getStatus,Constants.PlatformJobStatus.WAIT_CALL.getKey() |
| | | ,Constants.PlatformJobStatus.IN_WAIT.getKey() |
| | | ,Constants.PlatformJobStatus.TRANSFERING.getKey()) |
| | | .gt(PlatformJob::getSignDate,platformJob.getSignDate()) |
| | | .like(PlatformJob::getArriveDate,DateUtil.getDate(platformJob.getArriveDate(),"yyyy-MM-dd"))); |
| | | platformJob.setLineUpNum(lineUpNum); |
| | | }else if(Constants.equalsInteger(platformJob.getStatus(),Constants.PlatformJobStatus.WORKING.getKey())){ |
| | | //作业月台信息 |
| | | Platform platform = platformMapper.selectById(platformJob.getPlatformId()); |
| | | if(Objects.nonNull(platform)){ |
| | | platformJob.setPlatformName(platform.getName()); |
| | | } |
| | | } |
| | | return platformJob; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public LineUpVO lineUpDetail(LineUpDetailDTO lineUpDetailDTO){ |
| | | if(Objects.isNull(lineUpDetailDTO) |
| | | || Objects.isNull(lineUpDetailDTO.getQueryType())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | LineUpVO lineUpVO = new LineUpVO(); |
| | | //查询所有任务 |
| | | List<PlatformJob> platformJobList = platformJobJoinMapper.selectJoinList(PlatformJob.class, |
| | | new MPJLambdaWrapper<PlatformJob>() |
| | | .selectAll(PlatformJob.class) |
| | | .selectAs(PlatformReason::getGroupId,PlatformJob::getGroupId) |
| | | .leftJoin(PlatformBooks.class,PlatformBooks::getJobId,PlatformJob::getId) |
| | | .leftJoin(PlatformReason.class,PlatformReason::getId,PlatformBooks::getReasonId) |
| | | .eq(PlatformJob::getIsdeleted,Constants.ZERO) |
| | | .eq(Constants.equalsInteger(lineUpDetailDTO.getQueryType(),Constants.ZERO) |
| | | ,PlatformJob::getDrivierPhone,lineUpDetailDTO.getMobile()) |
| | | .eq(Constants.equalsInteger(lineUpDetailDTO.getQueryType(),Constants.ONE) |
| | | ,PlatformJob::getId,lineUpDetailDTO.getJobId()) |
| | | .in(PlatformJob::getStatus,Constants.PlatformJobStatus.WAIT_CALL.getKey(), |
| | | Constants.PlatformJobStatus.IN_WAIT.getKey(), |
| | | Constants.PlatformJobStatus.CALLED.getKey()) |
| | | .orderByAsc(PlatformJob::getSignDate) |
| | | ); |
| | | //获取所有月台 |
| | | List<Integer> platformIdList = platformJobList.stream().map(m->m.getGroupId()).collect(Collectors.toList()); |
| | | List<Platform> platformList = platformMapper.selectList(new QueryWrapper<Platform>().lambda() |
| | | .eq(Platform::getIsdeleted,Constants.ZERO) |
| | | .in(Platform::getId,platformIdList)); |
| | | |
| | | for (Platform platform:platformList) { |
| | | //查询本月台下 自己的数据 最早签到的 |
| | | PlatformJob platformJob = platformJobList.stream().filter(i->Constants.equalsInteger(i.getGroupId(),platform.getId())).findFirst().orElse(null); |
| | | //查询在当前月台下 签到排队车辆数据 |
| | | List<PlatformJob> platformJobSignInList = platformJobJoinMapper.selectJoinList(PlatformJob.class, |
| | | new MPJLambdaWrapper<PlatformJob>() |
| | | .selectAll(PlatformJob.class) |
| | | .selectAs(PlatformReason::getGroupId,PlatformJob::getGroupId) |
| | | .leftJoin(PlatformBooks.class,PlatformBooks::getJobId,PlatformJob::getId) |
| | | .leftJoin(PlatformReason.class,PlatformReason::getId,PlatformBooks::getReasonId) |
| | | .eq(PlatformJob::getIsdeleted,Constants.ZERO) |
| | | .ge(Objects.nonNull(platformJob),PlatformJob::getSignDate,DateUtil.getDate(platformJob.getSignDate(),"yyyy-MM-dd HH:mm:ss")) |
| | | .in(PlatformJob::getStatus,Constants.PlatformJobStatus.WAIT_CALL.getKey(), |
| | | Constants.PlatformJobStatus.IN_WAIT.getKey(), |
| | | Constants.PlatformJobStatus.CALLED.getKey()) |
| | | .orderByDesc(PlatformJob::getSignDate)); |
| | | platform.setSignJobList(platformJobSignInList); |
| | | //查询当前月台下 |
| | | List<PlatformJob> platformJobWorkList = platformJobJoinMapper.selectJoinList(PlatformJob.class, |
| | | new MPJLambdaWrapper<PlatformJob>() |
| | | .selectAll(PlatformJob.class) |
| | | .selectAs(PlatformReason::getGroupId,PlatformJob::getGroupId) |
| | | .leftJoin(PlatformBooks.class,PlatformBooks::getJobId,PlatformJob::getId) |
| | | .leftJoin(PlatformReason.class,PlatformReason::getId,PlatformBooks::getReasonId) |
| | | .eq(PlatformJob::getIsdeleted,Constants.ZERO) |
| | | .eq(PlatformJob::getStatus,Constants.PlatformJobStatus.WORKING.getKey()) |
| | | .orderByDesc(PlatformJob::getSignDate)); |
| | | platform.setSignJobList(platformJobSignInList); |
| | | platform.setWorkJobList(platformJobWorkList); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | lineUpVO.setPlatformList(platformList); |
| | | |
| | | |
| | | return lineUpVO; |
| | | } |
| | | |
| | | |
| | | |
| | | } |