| | |
| | | package com.stylefeng.guns.modular.system.util.quartz.jobs; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics; |
| | | import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService; |
| | | import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar; |
| | | import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService; |
| | | import com.stylefeng.guns.modular.system.util.PushUtil; |
| | | import com.stylefeng.guns.modular.system.util.TextToSpeechUtil; |
| | | import com.stylefeng.guns.modular.system.util.quartz.QuartzUtil; |
| | | import com.stylefeng.guns.modular.system.util.quartz.model.QuartzEnum; |
| | | import com.stylefeng.guns.modular.system.util.quartz.model.QuartzJob; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.quartz.JobDataMap; |
| | | import org.quartz.JobDetail; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobKey; |
| | | import org.quartz.*; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Timer; |
| | | import java.util.TimerTask; |
| | | |
| | | /** |
| | | * 订单司机超时提醒任务 |
| | |
| | | |
| | | @Override |
| | | public QuartzJob buildQuartzJob() { |
| | | return super.buildQuartzJob(); |
| | | return buildQuartzJob(QuartzEnum.JOB_NAME.getValue()); |
| | | } |
| | | |
| | | @Override |
| | | public QuartzJob buildQuartzJob(String name) { |
| | | return super.buildQuartzJob(name); |
| | | return buildQuartzJob(name, QuartzEnum.DEFAULT_GROUP.getValue()); |
| | | } |
| | | |
| | | @Override |
| | | public QuartzJob buildQuartzJob(String name, String group) { |
| | | return super.buildQuartzJob(name, group); |
| | | return buildQuartzJob(name, QuartzEnum.DEFAULT_GROUP.getValue(), null); |
| | | } |
| | | |
| | | @Override |
| | | public QuartzJob buildQuartzJob(String name, String group, JobDataMap jobDataMap) { |
| | | return super.buildQuartzJob(name, group, jobDataMap); |
| | | QuartzJob job = new OrderTimeOutJob(); |
| | | if(ToolUtil.isNotEmpty(name)){ |
| | | job.setName(name); |
| | | }else{ |
| | | job.setName(QuartzEnum.JOB_NAME.getValue()); |
| | | } |
| | | if(ToolUtil.isNotEmpty(group)){ |
| | | job.setGroup(group); |
| | | }else{ |
| | | job.setGroup(QuartzEnum.DEFAULT_GROUP.getValue()); |
| | | } |
| | | if(null != jobDataMap){ |
| | | job.setJobDataMap(jobDataMap); |
| | | } |
| | | return job; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void run(JobExecutionContext jobExecutionContext) { |
| | | JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap(); |
| | | Integer driverId = jobDataMap.getIntegerFromString("driverId"); |
| | | Integer orderId = jobDataMap.getIntegerFromString("orderId"); |
| | | Integer orderType = jobDataMap.getIntegerFromString("orderType"); |
| | | JobDetail jobDetail = jobExecutionContext.getJobDetail(); |
| | | JobDataMap jobDataMap = jobDetail.getJobDataMap(); |
| | | String name = jobDetail.getKey().getName(); |
| | | log.info("执行{}定时任务逻辑 JobDataMap:{}", name, JSON.toJSONString(jobDataMap)); |
| | | Integer timeOutType = jobDataMap.getIntValue("timeOutType"); |
| | | Integer driverId = jobDataMap.getIntValue("driverId"); |
| | | Integer orderId = jobDataMap.getIntValue("orderId"); |
| | | Integer orderType = jobDataMap.getIntValue("orderType"); |
| | | Integer language = jobDataMap.getIntValue("language"); |
| | | long timeOut = jobDataMap.getLongValue("timeOut"); |
| | | String describe = jobDataMap.getString("describe"); |
| | | if(3 == timeOutType){ |
| | | Integer m = Double.valueOf((System.currentTimeMillis() - timeOut) / 60000).intValue(); |
| | | if(orderType == 1){ |
| | | if(0 == m){ |
| | | describe = language == 1 ? "您的打车订单已超时,请抓紧!" : language == 2 ? "Your ride order is overdue, please go faster." : "Votre commande de course est en retard, veuillez aller plus vite."; |
| | | }else{ |
| | | describe = language == 1 ? "您的打车订单已超时" + m + "分钟,请抓紧!" : language == 2 ? "Your ride order is overdue for " + m + " minute(s), please go faster." : "Votre commande de course est en retard depuis " + m + " minute(s), veuillez aller plus vite."; |
| | | } |
| | | } |
| | | if(orderType == 4){ |
| | | if(0 == m){ |
| | | describe = language == 1 ? "您的包裹订单已超时,请抓紧!" : language == 2 ? "Your delivery order is overdue, please go faster." : "Votre commande de Delivery est en retard, veuillez aller plus vite."; |
| | | }else{ |
| | | describe = language == 1 ? "您的包裹订单已超时" + m + "分钟,请抓紧!" : language == 2 ? "Your delivery order is overdue for " + m + " minute(s), please go faster." : "Votre commande de Delivery est en retard depuis " + m + " minute(s), veuillez aller plus vite."; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | if(1 == orderType){ |
| | | //结束预约单出发循环提醒定时 |
| | | OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); |
| | | if(2 != orderPrivateCar.getState()){ |
| | | List<Integer> list = Arrays.asList(4, 5, 6, 7, 8, 9, 10, 11, 12); |
| | | if(1 == timeOutType && list.contains(orderPrivateCar.getState())){ |
| | | JobKey key = jobExecutionContext.getJobDetail().getKey(); |
| | | boolean b = QuartzUtil.deleteQuartzTask(key); |
| | | if(!b){ |
| | |
| | | } |
| | | return; |
| | | } |
| | | if(2 == timeOutType && (System.currentTimeMillis() >= timeOut || list.contains(orderPrivateCar.getState()))){ |
| | | JobKey key = jobExecutionContext.getJobDetail().getKey(); |
| | | boolean b = QuartzUtil.deleteQuartzTask(key); |
| | | if(!b){ |
| | | log.error("定时任务关闭失败:" + key.toString()); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | //结束超时循环提醒定时 |
| | | if(3 == timeOutType && list.contains(orderPrivateCar.getState())){ |
| | | JobKey key = jobExecutionContext.getJobDetail().getKey(); |
| | | boolean b = QuartzUtil.deleteQuartzTask(key); |
| | | if(!b){ |
| | | log.error("定时任务关闭失败:" + key.toString()); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | |
| | | } |
| | | if(4 == orderType){ |
| | | OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId); |
| | | if(2 != orderLogistics.getState()){ |
| | | List<Integer> list = Arrays.asList(4, 5, 6, 7, 8, 9, 10, 11, 12, 13); |
| | | if(1 == timeOutType && list.contains(orderLogistics.getState())){ |
| | | JobKey key = jobExecutionContext.getJobDetail().getKey(); |
| | | boolean b = QuartzUtil.deleteQuartzTask(key); |
| | | if(!b){ |
| | | log.error("定时任务关闭失败:" + key.toString()); |
| | | } |
| | | return; |
| | | } |
| | | //结束超时循环提醒定时 |
| | | if(3 == timeOutType && list.contains(orderLogistics.getState())){ |
| | | JobKey key = jobExecutionContext.getJobDetail().getKey(); |
| | | boolean b = QuartzUtil.deleteQuartzTask(key); |
| | | if(!b){ |
| | |
| | | return; |
| | | } |
| | | } |
| | | pushUtil.pushOrderTimeOut(2, driverId, orderId, orderType, describe); |
| | | |
| | | String audioUrl = null; |
| | | try { |
| | | audioUrl = TextToSpeechUtil.create(language == 1 ? "cmn-CN" : language == 2 ? "en-US" : "fr-FR", describe, "orderTimeOut" + driverId + "_" + timeOutType + ".mp3"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | //定时任务删除语音文件 |
| | | new Timer().schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | Process process = null; |
| | | try { |
| | | process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/orderTimeOut" + driverId + "_" + timeOutType + ".mp3"); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | if (process != null) { |
| | | process.destroy(); |
| | | } |
| | | } |
| | | }, 30000); |
| | | |
| | | log.info("开始推送提醒-{}:orderId={};orderType={};timeOutType={};describe={};audioUrl={}", System.currentTimeMillis(), orderId, orderType, timeOutType, describe, audioUrl); |
| | | pushUtil.pushOrderTimeOut(2, driverId, timeOutType, orderId, orderType, describe, audioUrl); |
| | | } |
| | | |
| | | |