|  |  | 
 |  |  | import com.doumee.core.tms.model.response.TmsBaseResponse; | 
 |  |  | import com.doumee.core.tms.model.response.TmsLockStatusQueryResponse; | 
 |  |  | import com.doumee.core.utils.*; | 
 |  |  | import com.doumee.core.wx.wxPlat.WxPlatConstants; | 
 |  |  | import com.doumee.core.wx.wxPlat.WxPlatNotice; | 
 |  |  | import com.doumee.dao.business.*; | 
 |  |  | import com.doumee.dao.business.dao.SmsConfigMapper; | 
 |  |  | import com.doumee.dao.business.dao.SmsEmailMapper; | 
 |  |  | 
 |  |  | import com.doumee.dao.openapi.request.*; | 
 |  |  | import com.doumee.dao.openapi.response.*; | 
 |  |  |  | 
 |  |  | import com.doumee.dao.system.SystemUserMapper; | 
 |  |  | import com.doumee.dao.system.model.SystemUser; | 
 |  |  | import com.doumee.dao.web.reqeust.*; | 
 |  |  | import com.doumee.dao.web.response.DriverHomeVO; | 
 |  |  | import com.doumee.dao.web.response.LineUpVO; | 
 |  |  | import com.doumee.dao.web.response.PlatformWorkVO; | 
 |  |  | import com.doumee.dao.web.response.platformReport.WholeProvinceBoardVO; | 
 |  |  | import com.doumee.service.business.PlatformJobService; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
 |  |  | 
 |  |  | import org.slf4j.LoggerFactory; | 
 |  |  | import org.springframework.beans.BeanUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  |  | 
 |  |  | import java.math.BigDecimal; | 
 |  |  | import java.math.RoundingMode; | 
 |  |  | import java.net.URLEncoder; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.concurrent.TimeUnit; | 
 |  |  | import java.util.stream.Collectors; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  | 
 |  |  |     private EmayService emayService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private RedisTemplate<String, Object> redisTemplate; | 
 |  |  |     @Autowired | 
 |  |  |     private PlatformBroadcastLogMapper platformBroadcastLogMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private PlatformWarnEventServiceImpl platformWarnEventService; | 
 |  |  |     @Autowired | 
 |  |  |     private MemberMapper memberMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private WxNoticeConfigMapper wxNoticeConfigMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private SystemUserMapper systemUserMapper; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Integer create(PlatformJob platformJob) { | 
 |  |  | 
 |  |  |                 .leftJoin(Platform.class,Platform::getId,PlatformJob::getPlatformId) | 
 |  |  |                 .eq(PlatformJob::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(PlatformJob::getDrivierPhone,loginUserInfo.getMobile()) | 
 |  |  |                 .and(i->i.like(PlatformJob::getDoneDate,DateUtil.getCurrDate()) | 
 |  |  |                         .or().in(PlatformJob::getStatus,Constants.PlatformJobStatus.WAIT_CALL.getKey() | 
 |  |  |                                 ,Constants.PlatformJobStatus.WAIT_CONFIRM.getKey(), | 
 |  |  |                                 Constants.PlatformJobStatus.WART_SIGN_IN.getKey(), | 
 |  |  |                                 Constants.PlatformJobStatus.IN_WAIT.getKey(), | 
 |  |  |                                 Constants.PlatformJobStatus.CALLED.getKey(), | 
 |  |  |                                 Constants.PlatformJobStatus.WORKING.getKey()) | 
 |  |  |                 ) | 
 |  |  |                 .orderByDesc(PlatformJob::getId) | 
 |  |  |         ); | 
 |  |  |         for (PlatformJob platformJob:platformJobList) { | 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         driverHomeVO.setPlatformJobList(platformJobList); | 
 |  |  |  | 
 |  |  |         // 园区导览图  图片 | 
 |  |  |         driverHomeVO.setReservationMap(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.PLATFORM_GUIDEMAP).getCode()); | 
 |  |  |         // 预约指南 文本 | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     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())){ | 
 |  |  |         if(!signInDTO.getQrCodeKey().equals( | 
 |  |  |                 systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE_PREFIX).getCode() +  systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE).getCode())){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"二维码已过期,请刷新重试"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | 
 |  |  |                                 ,PlatformJob::getId,lineUpDetailDTO.getJobId()) | 
 |  |  |                         .in(PlatformJob::getStatus,Constants.PlatformJobStatus.WAIT_CALL.getKey(), | 
 |  |  |                                 Constants.PlatformJobStatus.IN_WAIT.getKey(), | 
 |  |  |                                 Constants.PlatformJobStatus.WORKING.getKey(), | 
 |  |  |                                 Constants.PlatformJobStatus.CALLED.getKey()) | 
 |  |  |                         .orderByDesc(PlatformJob::getStatus) | 
 |  |  |                         .orderByAsc(PlatformJob::getSignDate) | 
 |  |  | 
 |  |  |                 emayService,smsEmailMapper,smsConfigMapper,platformJobMapper,platformJob.getId(), | 
 |  |  |                 SmsConstants.platformJobContent.platformJobCallIn,null,null | 
 |  |  |         ); | 
 |  |  |  | 
 |  |  |          | 
 |  |  |         //公众号模板消息 | 
 |  |  |         if(Objects.nonNull(platformJob.getDriverId())) { | 
 |  |  |           this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobCallIn,platformJob); | 
 |  |  |         } | 
 |  |  |         return platformJob; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void sendWxNotice(String objCode,PlatformJob platformJob){ | 
 |  |  |         SystemUser driver = systemUserMapper.selectOne(new QueryWrapper<SystemUser>().lambda() | 
 |  |  |                 .eq(SystemUser::getDeleted, Constants.ZERO) | 
 |  |  |                 .eq(SystemUser::getType, Constants.ZERO) | 
 |  |  |                 .eq(SystemUser::getMobile,platformJob.getDrivierPhone()) | 
 |  |  |                 .last(" limit 1 ")); | 
 |  |  |         if (Objects.nonNull(driver) && StringUtils.isNotBlank(driver.getOpenid())) { | 
 |  |  |             PlatformJob p = platformJobJoinMapper.selectJoinOne(PlatformJob.class, | 
 |  |  |                     new MPJLambdaWrapper<PlatformJob>() | 
 |  |  |                             .selectAll(PlatformJob.class) | 
 |  |  |                             .selectAs(Platform::getName,PlatformJob::getPlatformName) | 
 |  |  |                             .leftJoin(Platform.class,Platform::getId,PlatformJob::getPlatformId) | 
 |  |  |                             .eq(PlatformJob::getId,platformJob.getId()) | 
 |  |  |                             .last(" limit 1") | 
 |  |  |             ); | 
 |  |  |  | 
 |  |  |             WxPlatNotice wxPlatNotice = new WxPlatNotice(); | 
 |  |  |             wxPlatNotice.sendPlatformJobTemplateNotice(systemDictDataBiz, | 
 |  |  |                     wxNoticeConfigMapper, p, | 
 |  |  |                     objCode, | 
 |  |  |                     systemDictDataBiz.queryByCode(Constants.WX_PLATFORM, Constants.WX_PLATFORM_ACCESS_TOKEN).getCode(), | 
 |  |  |                     Arrays.asList(driver.getOpenid().split(",")) | 
 |  |  |             ); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private Logger logger = LoggerFactory.getLogger(PlatformJobServiceImpl.class); | 
 |  |  |  | 
 |  |  | 
 |  |  |                 SmsConstants.platformJobContent.platformJobSingIn,platform.getName(),null | 
 |  |  |         ); | 
 |  |  |  | 
 |  |  |         //公众号模板消息 | 
 |  |  |         if(Objects.nonNull(platformJob.getDriverId())){  | 
 |  |  |             this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobSingIn,platformJob); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         //广播 led通知 | 
 |  |  |         platformJob.setPlatformName(platform.getName()); | 
 |  |  |         this.broadcastAndLEed(platformJob,Constants.PlatformLedContent.CALLING.getInfo(), | 
 |  |  | 
 |  |  |                 SmsConstants.platformJobContent.platformJobMove,oldPlatform.getName(),platform.getName() | 
 |  |  |         ); | 
 |  |  |  | 
 |  |  |         //公众号模板消息 | 
 |  |  |         if(Objects.nonNull(platformJob.getDriverId())) {  | 
 |  |  |             this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobMove,platformJob); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         platformJob.setPlatformName(oldPlatform.getName()); | 
 |  |  |         platformJob.setPlatformId(oldPlatform.getId()); | 
 |  |  |         this.broadcastAndLEed(platformJob, StringUtils.isBlank(oldPlatform.getLedContent())?Constants.PlatformLedContent.IDEL_CONTNET.getName():oldPlatform.getLedContent(), | 
 |  |  | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,业务状态已流转!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Platform platform = platformJoinMapper.selectById(jobOperateDTO.getPlatformId()); | 
 |  |  |         Platform platform = platformJoinMapper.selectById(platformJob.getPlatformId()); | 
 |  |  |         if(Objects.isNull(platform)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到月台信息"); | 
 |  |  |         } | 
 |  |  | 
 |  |  |                 emayService,smsEmailMapper,smsConfigMapper,platformJobMapper,platformJob.getId(), | 
 |  |  |                 SmsConstants.platformJobContent.platformJobOverNum,null,null | 
 |  |  |         ); | 
 |  |  |  | 
 |  |  |         //公众号模板消息 | 
 |  |  |         if(Objects.nonNull(platformJob.getDriverId())){ | 
 |  |  |             this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobOverNum,platformJob); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         platformJob.setPlatformName(platform.getName()); | 
 |  |  |         this.broadcastAndLEed(platformJob, StringUtils.isBlank(platform.getLedContent())?Constants.PlatformLedContent.IDEL_CONTNET.getName():platform.getLedContent(), | 
 |  |  |                 null | 
 |  |  | 
 |  |  |                 emayService,smsEmailMapper,smsConfigMapper,platformJobMapper,platformJob.getId(), | 
 |  |  |                 SmsConstants.platformJobContent.platformJobError,platform.getName(),null | 
 |  |  |         ); | 
 |  |  |  | 
 |  |  |         //公众号模板消息 | 
 |  |  |         if(Objects.nonNull(platformJob.getDriverId())) { | 
 |  |  |             this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobError,platformJob); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         platformJob.setPlatformName(platform.getName()); | 
 |  |  |         this.broadcastAndLEed(platformJob, StringUtils.isBlank(platform.getLedContent())?Constants.PlatformLedContent.IDEL_CONTNET.getName():platform.getLedContent(), | 
 |  |  | 
 |  |  |                 emayService,smsEmailMapper,smsConfigMapper,platformJobMapper,platformJob.getId(), | 
 |  |  |                 SmsConstants.platformJobContent.platformJobWorking,platform.getName(),null | 
 |  |  |         ); | 
 |  |  |  | 
 |  |  |         //公众号模板消息 | 
 |  |  |         if(Objects.nonNull(platformJob.getDriverId())) { | 
 |  |  |             this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobWorking,platformJob); | 
 |  |  |         } | 
 |  |  |         //广播 led通知 | 
 |  |  |         platformJob.setPlatformName(platform.getName()); | 
 |  |  |         this.broadcastAndLEed(platformJob,Constants.PlatformLedContent.WORKING.getInfo(), | 
 |  |  | 
 |  |  |  | 
 |  |  |         return platformJob; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 完成作业 | 
 |  |  |      */ | 
 |  |  |   | 
 |  |  |     @Override | 
 |  |  |     public PlatformJob getLastWaitJob(String uuid, LoginUserInfo loginUser){ | 
 |  |  |         String u = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.BIGSCREEN_UUID); | 
 |  |  |         if(!StringUtils.equals(u,uuid)){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,二维码已失效!"); | 
 |  |  |         } | 
 |  |  |         PlatformJob platformJob =  platformJobMapper.selectOne(new QueryWrapper<PlatformJob>().lambda() | 
 |  |  |                 .eq(PlatformJob::getDrivierPhone,loginUser.getMobile()) | 
 |  |  |                 .eq(PlatformJob::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(PlatformJob::getStatus,Constants.PlatformJobStatus.WART_SIGN_IN.getKey()) | 
 |  |  |                 .orderByDesc(PlatformJob::getCreateDate) | 
 |  |  |                 .last(" limit 1 ") ); | 
 |  |  |             return platformJob; | 
 |  |  |     } | 
 |  |  |      | 
 |  |  |     @Override | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     public PlatformJob finishWork(JobOperateDTO jobOperateDTO){ | 
 |  |  | 
 |  |  |                 emayService,smsEmailMapper,smsConfigMapper,platformJobMapper,platformJob.getId(), | 
 |  |  |                 SmsConstants.platformJobContent.platformJobFinish,platform.getName(),null | 
 |  |  |         ); | 
 |  |  |  | 
 |  |  |         //公众号模板消息 | 
 |  |  |         if(Objects.nonNull(platformJob.getDriverId())) { | 
 |  |  |             this.sendWxNotice(WxPlatConstants.platformJobContent.platformJobFinish,platformJob); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //广播 led通知 | 
 |  |  |         platformJob.setPlatformName(platform.getName()); | 
 |  |  |         this.broadcastAndLEed(platformJob,Constants.PlatformLedContent.DONE.getInfo(), | 
 |  |  | 
 |  |  |             List<PlatformJob> calledList = platformJobList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.PlatformJobStatus.CALLED.getKey())).collect(Collectors.toList()); | 
 |  |  |             largeScreenDataVO.setWaitWorkList(calledList); | 
 |  |  |         } | 
 |  |  |         largeScreenDataVO.setQrCode(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE).getCode()); | 
 |  |  |         String u =  UUID.randomUUID().toString(); | 
 |  |  |         redisTemplate.opsForValue().set(Constants.RedisKeys.BIGSCREEN_UUID,u,3, TimeUnit.MINUTES); | 
 |  |  |         String url = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),Constants.WxUrlParams.BISCREEN_CODE,u); | 
 |  |  |         largeScreenDataVO.setQrCode(url); | 
 |  |  |         largeScreenDataVO.setAttention(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_ATTENTION).getCode()); | 
 |  |  |         return largeScreenDataVO; | 
 |  |  |  | 
 |  |  |     } | 
 |  |  | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  |