package cn.stylefeng.rest.modular.work; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjUtil; import cn.stylefeng.guns.modular.business.dto.ImPushDataDTO; import cn.stylefeng.guns.modular.business.entity.*; import cn.stylefeng.guns.modular.business.service.*; import cn.stylefeng.guns.modular.business.service.impl.ImBizService; import cn.stylefeng.roses.kernel.customer.modular.entity.Customer; import cn.stylefeng.roses.kernel.customer.modular.service.CustomerService; import cn.stylefeng.roses.kernel.rule.enums.ImPushTypeEnum; import cn.stylefeng.roses.kernel.rule.enums.ImUserTypeEnum; import cn.stylefeng.roses.kernel.rule.enums.OrderStatusFlagEnum; import cn.stylefeng.roses.kernel.rule.enums.PostIdEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * 定时任务-订单超时取消 */ @Slf4j @Component @EnableScheduling public class OrderOutTimeCancelWork { @Resource IOrderConsultOneService orderConsultOneService; @Resource IMentalTestRecordService mentalTestRecordService; @Resource IMentalAppointmentService mentalAppointmentService; @Resource IOrderMentalTestService orderMentalTestService; @Resource ICourseOrderService courseOrderService; @Resource ICounsellingOrderService counsellingOrderService; @Resource ImBizService imBizService; @Resource CustomerService customerService; @Resource ICounsellingOrderReservationService counsellingOrderReservationService; @Resource ICounsellingInfoService counsellingInfoService; @Resource IImGroupService imGroupService; @Resource ICounsellingUserService counsellingUserService; /** * 固定时间延迟 @Scheduled(fixedDelay = 时间间隔(毫秒) ) * * @Scheduled(fixedRate = 1000 * 60) * Corn表达式 @Scheduled(cron = Corn表达式) * @Scheduled(cron = "0 0/30 * * * *") */ @Scheduled(fixedRate = 1000 * 60) public void autoCancelOrderConsultOne() { Date date = new Date(); Date outTime = DateUtil.offset(date, DateField.MINUTE, -30); // 超时未支付订单列表 List outOrderConsultOneList = orderConsultOneService.list( Wrappers.lambdaUpdate() .eq(OrderConsultOne::getStatusFlag, OrderStatusFlagEnum.WAIT_PAY.getCode()) .le(OrderConsultOne::getCreateTime, outTime) ); for (OrderConsultOne orderConsultOne : outOrderConsultOneList) { // 取消1v1咨询订单 boolean update = orderConsultOneService.update( Wrappers.lambdaUpdate() .set(OrderConsultOne::getStatusFlag, OrderStatusFlagEnum.CANCEL.getCode()) .set(OrderConsultOne::getCancelTime, date) .set(OrderConsultOne::getCancelRemark, "订单未支付超时取消") //.set(OrderConsultOne::getMentalAppointmentId, null) .eq(OrderConsultOne::getId, orderConsultOne.getId()) ); if (update) { // // 心理测试记录置空 // mentalTestRecordService.update( // Wrappers.lambdaUpdate() // .set(MentalTestRecord::getOrderConsultOneId, null) // .set(MentalTestRecord::getMentalAppointmentId, null) // .eq(MentalTestRecord::getMentalAppointmentId, orderConsultOne.getMentalAppointmentId()) // ); // 取消1v1咨询预约 mentalAppointmentService.update( Wrappers.lambdaUpdate() .set(MentalAppointment::getStatusFlag, OrderStatusFlagEnum.CANCEL.getCode()) .eq(MentalAppointment::getId, orderConsultOne.getMentalAppointmentId()) ); } } } @Scheduled(fixedRate = 1000 * 60) public void autoCancelOrderMentalTest() { Date outTime = DateUtil.offset(new Date(), DateField.MINUTE, -30); // 超时订单未支付,自动取消 orderMentalTestService.update( Wrappers.lambdaUpdate() .set(OrderMentalTest::getStatusFlag, OrderStatusFlagEnum.CANCEL.getCode()) .set(OrderMentalTest::getCancelTime, new Date()) .set(OrderMentalTest::getCancelRemark, "订单未支付超时取消") .eq(OrderMentalTest::getStatusFlag, OrderStatusFlagEnum.WAIT_PAY.getCode()) .le(OrderMentalTest::getCreateTime, outTime) ); } @Scheduled(fixedRate = 1000 * 60) public void autoCancelOrderCourse() { Date outTime = DateUtil.offset(new Date(), DateField.MINUTE, -30); List courseOrderList = courseOrderService.list( Wrappers.lambdaQuery() .eq(CourseOrder::getStatusFlag, OrderStatusFlagEnum.WAIT_PAY.getCode()) .le(CourseOrder::getCreateTime, outTime) ); if (CollectionUtil.isNotEmpty(courseOrderList)){ log.info("自动取消课程订单:"+courseOrderList.size()); courseOrderList.parallelStream().forEach(courseOrder -> { Customer customer = this.customerService.getById(courseOrder.getUserId()); // 推送消息内容 String pushContent = "用户:"+customer.getNickName()+"有未支付的课程订单,发起聊天。"; // IM推送数据json ImPushDataDTO pushData = ImPushDataDTO.builder() .type(ImPushTypeEnum.S_TO_W_TIP_COURSE_NOT_PAY.getCode()) .objId(ObjUtil.toString(courseOrder.getId())) .title("通知") .content(pushContent) // .extra("发起聊天") .data1(ObjUtil.toString(courseOrder.getUserId())) .build(); if (courseOrder.getCourseUserId() != null){ imBizService.messageSendSystem(courseOrder.getUserId()+"", new String[]{courseOrder.getCourseUserId()+""}, pushData, ImUserTypeEnum.WORKER, PostIdEnum.PO_11, true); } }); // 超时订单未支付,自动取消 courseOrderService.update( Wrappers.lambdaUpdate() .set(CourseOrder::getStatusFlag, OrderStatusFlagEnum.CANCEL.getCode()) .set(CourseOrder::getCancelTime, new Date()) .set(CourseOrder::getCancelRemark, "订单未支付超时取消") .eq(CourseOrder::getStatusFlag, OrderStatusFlagEnum.WAIT_PAY.getCode()) .le(CourseOrder::getCreateTime, outTime) ); } } @Scheduled(fixedRate = 1000 * 60) public void autNoticeOrderCourse() { Date nowDate = new Date(); Date endDate = DateUtil.offset(nowDate, DateField.MINUTE, -5); Date beginDate = DateUtil.offset(endDate, DateField.MINUTE, -1); List courseOrderList = courseOrderService.list( Wrappers.lambdaQuery() .eq(CourseOrder::getStatusFlag, OrderStatusFlagEnum.WAIT_PAY.getCode()) .ge(CourseOrder::getCreateTime, beginDate).lt(CourseOrder::getCreateTime,endDate).eq(CourseOrder::getIsDelete,0) ); if (CollectionUtil.isNotEmpty(courseOrderList)){ // log.info("自动取消课程订单:"+courseOrderList.size()); courseOrderList.parallelStream().forEach(courseOrder -> { Customer customer = this.customerService.getById(courseOrder.getUserId()); // 推送消息内容 String pushContent = "用户:"+customer.getNickName()+"有未支付的课程订单,发起聊天。"; // IM推送数据json ImPushDataDTO pushData = ImPushDataDTO.builder() .type(ImPushTypeEnum.S_TO_W_TIP_COURSE_NOT_PAY.getCode()) .objId(ObjUtil.toString(courseOrder.getId())) .title("通知") .content(pushContent) // .extra("发起聊天") .data1(ObjUtil.toString(courseOrder.getUserId())) .build(); if (courseOrder.getCourseUserId() != null){ imBizService.messageSendSystem(courseOrder.getUserId()+"", new String[]{courseOrder.getCourseUserId()+""}, pushData, ImUserTypeEnum.WORKER, PostIdEnum.PO_11, true); } }); } List counsellingOrderList = counsellingOrderService.list( Wrappers.lambdaQuery() .eq(CounsellingOrder::getStatusFlag, OrderStatusFlagEnum.WAIT_PAY.getCode()) .ge(CounsellingOrder::getCreateTime, beginDate).lt(CounsellingOrder::getCreateTime,endDate).eq(CounsellingOrder::getIsDelete,0) ); if (CollectionUtil.isNotEmpty(counsellingOrderList)) { counsellingOrderList.parallelStream().forEach(counsellingOrder -> { // CustomerUpdateRequest customerUpdateRequest = JSONUtil.toBean(counsellingOrder.getUserInfoJson(), CustomerUpdateRequest.class); Customer customer = this.customerService.getById(counsellingOrder.getUserId()); // 推送消息内容 String pushContent; if (counsellingOrder.getOrderType().intValue() == 1) { pushContent = "用户:" + customer.getNickName() + "有未支付的面诊订单,发起聊天。"; } else { pushContent = "用户:" + customer.getNickName() + "有未支付的疗程订单,发起聊天。"; } // IM推送数据json ImPushDataDTO pushData = ImPushDataDTO.builder() .type(ImPushTypeEnum.S_TO_W_TIP_CONSULT_NOT_PAY.getCode()) .objId(ObjUtil.toString(counsellingOrder.getId())) .title("通知") .content(pushContent) // .extra("发起聊天") .data1(ObjUtil.toString(counsellingOrder.getUserId())) .build(); if (counsellingOrder.getConsultantUserId() != null){ // 发送 imBizService.messageSendSystem(counsellingOrder.getUserId() + "", new String[]{counsellingOrder.getConsultantUserId() + ""}, pushData, ImUserTypeEnum.WORKER, PostIdEnum.PO_21, true); } }); } } @Scheduled(fixedRate = 1000 * 60) public void autoCancelOrderCounsel() { Date outTime = DateUtil.offset(new Date(), DateField.MINUTE, -30); List counsellingOrderList = counsellingOrderService.list( Wrappers.lambdaQuery() .eq(CounsellingOrder::getStatusFlag, OrderStatusFlagEnum.WAIT_PAY.getCode()) .le(CounsellingOrder::getCreateTime, outTime).eq(CounsellingOrder::getIsDelete,0) ); if (CollectionUtil.isNotEmpty(counsellingOrderList)) { log.info("自动取消咨询订单:"+counsellingOrderList.size()); counsellingOrderList.parallelStream().forEach(counsellingOrder -> { // CustomerUpdateRequest customerUpdateRequest = JSONUtil.toBean(counsellingOrder.getUserInfoJson(),CustomerUpdateRequest.class); Customer customer = this.customerService.getById(counsellingOrder.getUserId()); // 推送消息内容 String pushContent; if (counsellingOrder.getOrderType().intValue() == 1) { pushContent = "用户:" + customer.getNickName() + "有未支付的面诊订单,发起聊天。"; } else { pushContent = "用户:" + customer.getNickName() + "有未支付的疗程订单,发起聊天。"; } // IM推送数据json ImPushDataDTO pushData = ImPushDataDTO.builder() .type(ImPushTypeEnum.S_TO_W_TIP_CONSULT_NOT_PAY.getCode()) .objId(ObjUtil.toString(counsellingOrder.getId())) .title("通知") .content(pushContent) // .extra("发起聊天") .data1(ObjUtil.toString(counsellingOrder.getUserId())) .build(); if (counsellingOrder.getConsultantUserId() != null) { // 发送 imBizService.messageSendSystem(counsellingOrder.getUserId() + "", new String[]{counsellingOrder.getConsultantUserId() + ""}, pushData, ImUserTypeEnum.WORKER, PostIdEnum.PO_21, true); } }); // 超时订单未支付,自动取消 counsellingOrderService.update( Wrappers.lambdaUpdate() .set(CounsellingOrder::getStatusFlag, OrderStatusFlagEnum.CANCEL.getCode()) .set(CounsellingOrder::getCancelTime, new Date()) .set(CounsellingOrder::getCancelRemark, "订单未支付超时取消") .eq(CounsellingOrder::getStatusFlag, OrderStatusFlagEnum.WAIT_PAY.getCode()) .le(CounsellingOrder::getCreateTime, outTime).eq(CounsellingOrder::getIsDelete,0) ); } } /** * 预约提醒 */ @Scheduled(fixedRate = 1000 * 90) public void orderReservationWarn() { Date nowDate = new Date(); Date minuteEndTime = DateUtil.offsetMinute(nowDate,30); Date minuteStartTime = DateUtil.offsetSecond(minuteEndTime,-90);; Date endTime = DateUtil.offsetHour(nowDate,24); Date startTime = DateUtil.offsetSecond(endTime,-90); List counsellingOrderReservationList = this.counsellingOrderReservationService.list(new LambdaQueryWrapper().eq(CounsellingOrderReservation::getStauts,2) .le(CounsellingOrderReservation::getReservationBeginTime,endTime).gt(CounsellingOrderReservation::getReservationBeginTime,startTime)); if (CollectionUtil.isNotEmpty(counsellingOrderReservationList)){ log.info("预约提醒:"+counsellingOrderReservationList.size()); counsellingOrderReservationList.parallelStream().forEach(counsellingOrderReservation -> { CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(counsellingOrderReservation.getCounsellingInfoId()); // 推送消息内容 String pushContent = "你的预约("+DateUtil.formatDate(counsellingOrderReservation.getReservationBeginTime())+" "+DateUtil.format(counsellingOrderReservation.getReservationBeginTime(),"HH:mm")+"-"+DateUtil.format(counsellingOrderReservation.getReservationEndTime(),"HH:mm")+")即将开始,请按时参加"; // IM推送数据json ImPushDataDTO pushData = ImPushDataDTO.builder() .type(ImPushTypeEnum.S_TO_C_TIP_COUSULT_APPOINTMENT_UPCOMING.getCode()) .objId(ObjUtil.toString(counsellingOrderReservation.getId())) .title("通知") .content(pushContent) // .extra("("+DateUtil.formatDate(counsellingOrderReservation.getReservationBeginTime())+" "+DateUtil.format(counsellingOrderReservation.getReservationBeginTime(),"HH:mm")+"-"+DateUtil.format(counsellingOrderReservation.getReservationEndTime(),"HH:mm")+")") .build(); // 发送预约 imBizService.messageSendSystem(counsellingInfo.getUserId()+"", new String[]{counsellingOrderReservation.getUserId()+""}, pushData, ImUserTypeEnum.USER, null, true); }); } //30分钟 List counsellingOrderReservationList1 = this.counsellingOrderReservationService.list(new LambdaQueryWrapper().eq(CounsellingOrderReservation::getStauts,2) .le(CounsellingOrderReservation::getReservationBeginTime,minuteEndTime).gt(CounsellingOrderReservation::getReservationBeginTime,minuteStartTime)); if (CollectionUtil.isNotEmpty(counsellingOrderReservationList1)){ counsellingOrderReservationList1.parallelStream().forEach(counsellingOrderReservation -> { CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(counsellingOrderReservation.getCounsellingInfoId()); // 推送消息内容 String pushContent = "你的预约("+DateUtil.formatDate(counsellingOrderReservation.getReservationBeginTime())+" "+DateUtil.format(counsellingOrderReservation.getReservationBeginTime(),"HH:mm")+"-"+DateUtil.format(counsellingOrderReservation.getReservationEndTime(),"HH:mm")+")即将开始,请按时参加"; // IM推送数据json ImPushDataDTO pushData = ImPushDataDTO.builder() .type(ImPushTypeEnum.S_TO_C_TIP_COUSULT_APPOINTMENT_UPCOMING.getCode()) .objId(ObjUtil.toString(counsellingOrderReservation.getId())) .title("通知") .content(pushContent) // .extra("("+DateUtil.formatDate(counsellingOrderReservation.getReservationBeginTime())+" "+DateUtil.format(counsellingOrderReservation.getReservationBeginTime(),"HH:mm")+"-"+DateUtil.format(counsellingOrderReservation.getReservationEndTime(),"HH:mm")+")") .build(); // 发送预约 imBizService.messageSendSystem(counsellingInfo.getUserId()+"", new String[]{counsellingOrderReservation.getUserId()+""}, pushData, ImUserTypeEnum.USER, null, true); }); } } /** * 过期 */ @Scheduled(fixedRate = 1000 * 60 *5) public void expireCourseAndCounselling() { Date nowDate = new Date(); Date endDate = DateUtil.offsetMinute(nowDate,5); List counsellingOrderList = this.counsellingOrderService.list(new LambdaQueryWrapper() .eq(CounsellingOrder::getIsDelete,0) .le(CounsellingOrder::getEffectiveEndTime,endDate).ge(CounsellingOrder::getEffectiveEndTime,nowDate) .eq(CounsellingOrder::getStatusFlag,OrderStatusFlagEnum.PAY_SUCCESS.getCode())); //解散群聊 if (CollectionUtil.isNotEmpty(counsellingOrderList)){ // List orderIds = counsellingOrderList.stream().map(CounsellingOrder::getId).collect(Collectors.toList()); // this.imGroupService.update(new LambdaUpdateWrapper() // .set(ImGroup::getStatusFlag,2).set(ImGroup::getDisbandDate,new Date()) // .in(ImGroup::getOrderId,orderIds).eq(ImGroup::getGroupType,2)); this.counsellingOrderService.update(new LambdaUpdateWrapper() .set(CounsellingOrder::getStatusFlag,2).eq(CounsellingOrder::getIsDelete,0) .set(CounsellingOrder::getResidueClassHours,0) .le(CounsellingOrder::getEffectiveEndTime,endDate).ge(CounsellingOrder::getEffectiveEndTime,nowDate) .eq(CounsellingOrder::getStatusFlag,OrderStatusFlagEnum.PAY_SUCCESS.getCode())); } List courseOrderList = this.courseOrderService.list(new LambdaQueryWrapper() .eq(CourseOrder::getIsDelete,0) .le(CourseOrder::getEffectiveEndTime,endDate).ge(CourseOrder::getEffectiveEndTime,nowDate) .eq(CourseOrder::getStatusFlag,OrderStatusFlagEnum.PAY_SUCCESS.getCode())); //解散群聊 if (CollectionUtil.isNotEmpty(courseOrderList)){ log.info("过期群聊提醒:"+courseOrderList.size()); List orderIds = courseOrderList.stream().map(CourseOrder::getId).collect(Collectors.toList()); this.imGroupService.update(new LambdaUpdateWrapper() .set(ImGroup::getStatusFlag,2).set(ImGroup::getDisbandDate,new Date()) .in(ImGroup::getOrderId,orderIds).eq(ImGroup::getGroupType,1)); this.courseOrderService.update(new LambdaUpdateWrapper() .set(CourseOrder::getStatusFlag,2).eq(CourseOrder::getIsDelete,0) .le(CourseOrder::getEffectiveEndTime,endDate).ge(CourseOrder::getEffectiveEndTime,nowDate) .eq(CourseOrder::getStatusFlag,OrderStatusFlagEnum.PAY_SUCCESS.getCode())); } } // /** // * 课程群聊提醒 // */ // @Scheduled(fixedRate = 1000 * 60 *10) // public void warnCourseGroup(){ // Date endDate = new Date(); // Date startDate = DateUtil.offsetMinute(endDate,-10); // endDate = DateUtil.offsetHour(endDate,-48); // startDate = DateUtil.offsetHour(startDate,-48); // List imGroupList = this.imGroupService.list(new LambdaQueryWrapper() // .eq(ImGroup::getStatusFlag,1).le(ImGroup::getLastChatTime,endDate) // .gt(ImGroup::getLastChatTime,startDate).eq(ImGroup::getGroupType,1)); // if (CollectionUtil.isNotEmpty(imGroupList)){ // log.info("课程群聊提醒:"+imGroupList.size()); // imGroupList.stream().forEach(imGroup -> { // CourseOrder courseOrder = this.courseOrderService.getById(imGroup.getOrderId()); // List userIds = new ArrayList<>(); // if (courseOrder.getCourseUserId() != null){ // userIds.add(courseOrder.getCourseUserId().toString()); // } // if (courseOrder.getTutoringUserId() != null){ // userIds.add(courseOrder.getTutoringUserId().toString()); // } // if (CollectionUtil.isNotEmpty(userIds)){ // // 推送消息内容 // String pushContent = "群聊:课程咨询,已有两日未发送信息,查看聊天。"; // // IM推送数据json // ImPushDataDTO pushData = ImPushDataDTO.builder() // .type(ImPushTypeEnum.S_TO_W_TIP_COURSE_GROUP_TALK.getCode()) // .objId(ObjUtil.toString(imGroup.getId())) // .title("通知") // .content(pushContent) //// .extra("查看聊天") // .build(); // imBizService.messageSendSystem(courseOrder.getUserId()+"", userIds.toArray(new String[userIds.size()]), pushData, ImUserTypeEnum.WORKER, PostIdEnum.PO_11, true); // } // }); // } // } /** * 定时自动更新预约 */ @Scheduled(fixedRate = 1000 * 60 ) public void autoCounsellingReservationOrder() { Date nowDate = new Date(); Date startTime = DateUtil.offsetMinute(nowDate,-1); //查询待服务的预约 List waitList = this.counsellingOrderReservationService.list(new LambdaQueryWrapper() .ge(CounsellingOrderReservation::getReservationBeginTime,startTime).le(CounsellingOrderReservation::getReservationBeginTime,nowDate) .eq(CounsellingOrderReservation::getStauts,2)); if (CollectionUtil.isNotEmpty(waitList)){ //更新为服务中 List idList = waitList.stream().map(CounsellingOrderReservation::getId).collect(Collectors.toList()); log.info("自动更新待服务的咨询,ids:"+idList.toString()); this.counsellingOrderReservationService.update(new LambdaUpdateWrapper().set(CounsellingOrderReservation::getStauts,3) .set(CounsellingOrderReservation::getServiceBeginTime,new Date()) .in(CounsellingOrderReservation::getId,idList)); } // //查询结束的预约 // List waitList1 = this.counsellingOrderReservationService.list(new LambdaQueryWrapper() // .le(CounsellingOrderReservation::getReservationEndTime,startTime).eq(CounsellingOrderReservation::getStauts,2)); // // if (CollectionUtil.isNotEmpty(waitList1)){ // //更新为已完成 // List idList = waitList1.stream().map(CounsellingOrderReservation::getId).collect(Collectors.toList()); // log.info("自动更新待服务的咨询,ids:"+idList.toString()); // this.counsellingOrderReservationService.update(new LambdaUpdateWrapper().set(CounsellingOrderReservation::getStauts,4) // .set(CounsellingOrderReservation::getServiceBeginTime,new Date()) // .in(CounsellingOrderReservation::getId,idList)); // } //查询服务中的预约 List serviceList = this.counsellingOrderReservationService.list(new LambdaQueryWrapper() .le(CounsellingOrderReservation::getReservationEndTime,nowDate) .eq(CounsellingOrderReservation::getStauts,3)); if (CollectionUtil.isNotEmpty(serviceList)){ log.info("自动更新服务中的咨询,ids:"+serviceList.stream().map(CounsellingOrderReservation::getId).collect(Collectors.toList()).toString()); serviceList.stream().forEach(counsellingOrderReservation -> { counsellingOrderReservation.setStauts(4); //分钟数 long minute = DateUtil.between(counsellingOrderReservation.getReservationBeginTime(),counsellingOrderReservation.getReservationEndTime(), DateUnit.MINUTE); int ceil = (int) Math.ceil(minute / 60d); counsellingOrderReservation.setConsumeCourseHour(ceil); counsellingOrderReservation.setServiceEndTime(new Date()); counsellingOrderReservation.setServieCompleteTime(new Date()); this.counsellingOrderReservationService.updateById(counsellingOrderReservation); CounsellingOrder counsellingOrder = this.counsellingOrderService.getById(counsellingOrderReservation.getCounsellingOrderId()); //更新咨询用户信息 CounsellingUser counsellingUser = this.counsellingUserService.getOne(new LambdaQueryWrapper().eq(CounsellingUser::getUserId,counsellingOrder.getUserId()).eq(CounsellingUser::getCounsellingInfoId,counsellingOrder.getCounsellingInfoId())); //如果是首次面诊跟新完成状态 if (counsellingOrderReservation.getReservationType().intValue() == 1){ counsellingOrder.setStatusFlag(2); //更新客户是否完成首次咨询预约 this.customerService.update(new LambdaUpdateWrapper().set(Customer::getIsFirstAppointment,1).eq(Customer::getCustomerId,counsellingOrder.getUserId())); counsellingUser.setIsFirstAppointment(3); counsellingUser.setStatusFlag(2); }else { //判断是否完成咨询订单服务 if (counsellingOrder.getResidueClassHours().intValue() - ceil <= 0 ){ counsellingOrder.setStatusFlag(2); } //扣除咨询课时 counsellingOrder.setResidueClassHours(counsellingOrder.getResidueClassHours().intValue() - ceil); counsellingUser.setResidueClassHours(counsellingUser.getResidueClassHours().intValue() - ceil); } this.counsellingUserService.updateById(counsellingUser); this.counsellingOrderService.updateById(counsellingOrder); }); } } /** * 过期完成咨询师服务 */ @Scheduled(fixedRate = 1000 * 60*5 ) public void autoCounsellingUserCompelete(){ Date nowDate = new Date(); Date endDate = DateUtil.offsetMinute(nowDate,5); List counsellingUserList = this.counsellingUserService.list(new LambdaQueryWrapper() .eq(CounsellingUser::getIsDelete,0) .le(CounsellingUser::getEffectiveEndTime,endDate).ge(CounsellingUser::getEffectiveEndTime,nowDate)); //解散群聊 if (CollectionUtil.isNotEmpty(counsellingUserList)){ List orderIds = counsellingUserList.stream().map(CounsellingUser::getId).collect(Collectors.toList()); log.info("过期用户咨询师信息ids:"+orderIds.toString()); this.imGroupService.update(new LambdaUpdateWrapper() .set(ImGroup::getStatusFlag,2).set(ImGroup::getDisbandDate,new Date()) .set(ImGroup::getIsDelete,1) .in(ImGroup::getOrderId,orderIds).eq(ImGroup::getGroupType,2)); this.counsellingUserService.update(new LambdaUpdateWrapper() .set(CounsellingUser::getStatusFlag,2).eq(CounsellingUser::getIsDelete,0) .set(CounsellingUser::getResidueClassHours,0) .le(CounsellingUser::getEffectiveEndTime,endDate).ge(CounsellingUser::getEffectiveEndTime,nowDate) .eq(CounsellingUser::getStatusFlag,OrderStatusFlagEnum.PAY_SUCCESS.getCode())); } } /** * 到预约时间自动取消预约 */ @Scheduled(fixedRate = 1000 * 30) public void autoCancelCounsellingReservation() { Date endDate = new Date(); Date startDate = DateUtil.offset(endDate,DateField.SECOND,-30); List counsellingOrderReservationList = this.counsellingOrderReservationService.list(new LambdaQueryWrapper().ge(CounsellingOrderReservation::getReservationBeginTime,startDate) .le(CounsellingOrderReservation::getReservationBeginTime,endDate).eq(CounsellingOrderReservation::getStauts,1)); if (CollectionUtil.isNotEmpty(counsellingOrderReservationList)){ counsellingOrderReservationList.stream().forEach(counsellingOrderReservation -> { if (counsellingOrderReservation.getReservationType().intValue() ==1){ this.counsellingOrderService.update(new LambdaUpdateWrapper().set(CounsellingOrder::getFirstAppointmentDate,null).set(CounsellingOrder::getFirstAppointmentTimes,null) .eq(CounsellingOrder::getId,counsellingOrderReservation.getCounsellingOrderId())); //处理用户咨询预约 this.counsellingUserService.update(new LambdaUpdateWrapper().eq(CounsellingUser::getCounsellingInfoId,counsellingOrderReservation.getCounsellingInfoId()) .eq(CounsellingUser::getUserId,counsellingOrderReservation.getUserId()).set(CounsellingUser::getFirstAppointmentDate,null) .set(CounsellingUser::getFirstAppointmentTimes,null).set(CounsellingUser::getIsFirstAppointment,1)); } counsellingOrderReservation.setStauts(5); counsellingOrderReservation.setCancleReason("到期时间自动取消预约"); this.counsellingOrderReservationService.updateById(counsellingOrderReservation); }); } } /** * 检查课程群聊是否两天未发送消息 */ @Scheduled(fixedRate = 1000 * 60) public void checkCourseGroup(){ Date endDate = new Date(); Date beginDate = DateUtil.offsetMinute(endDate,-1); //两天前 endDate = DateUtil.offsetMinute(endDate,-10); beginDate = DateUtil.offsetMinute(beginDate,-10); List imGroupList = this.imGroupService.list(new LambdaQueryWrapper().eq(ImGroup::getGroupType,1).eq(ImGroup::getStatusFlag,1) .ge(ImGroup::getLastChatTime,beginDate).lt(ImGroup::getLastChatTime,endDate)); if (CollectionUtil.isNotEmpty(imGroupList)){ imGroupList.stream().forEach(imGroup -> { CourseOrder courseOrder = this.courseOrderService.getById(imGroup.getOrderId()); if (courseOrder != null && courseOrder.getCourseUserId() != null){ List userIds = new ArrayList<>(); if (courseOrder.getCourseUserId() != null){ userIds.add(courseOrder.getCourseUserId().toString()); } if (courseOrder.getTutoringUserId() != null){ userIds.add(courseOrder.getTutoringUserId().toString()); } // 推送消息内容 String pushContent = "群聊:"+imGroup.getName()+",已有两日未发消息,"; // IM推送数据json ImPushDataDTO pushData = ImPushDataDTO.builder() .type(ImPushTypeEnum.S_TO_W_TIP_COURSE_GROUP_TALK.getCode()) .objId(ObjUtil.toString(imGroup.getId())) .title("通知") .content(pushContent) // .extra("去查看。") .build(); // 发送预约提示 imBizService.messageSendSystem(courseOrder.getUserId()+"", userIds.toArray(new String[0]), pushData, ImUserTypeEnum.WORKER, PostIdEnum.PO_11, true); } }); } } }