diff --git a/njzscloud-svr/src/main/java/com/njzscloud/supervisory/order/service/OrderInfoService.java b/njzscloud-svr/src/main/java/com/njzscloud/supervisory/order/service/OrderInfoService.java index 4c9b8b0..e902e65 100644 --- a/njzscloud-svr/src/main/java/com/njzscloud/supervisory/order/service/OrderInfoService.java +++ b/njzscloud-svr/src/main/java/com/njzscloud/supervisory/order/service/OrderInfoService.java @@ -21,7 +21,7 @@ import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.google.common.base.Strings; +// import com.google.common.base.Strings; import com.njzscloud.common.core.ex.Exceptions; import com.njzscloud.common.mp.support.PageParam; import com.njzscloud.common.mp.support.PageResult; @@ -65,19 +65,21 @@ import com.njzscloud.supervisory.station.service.StationManageService; import com.njzscloud.supervisory.sys.auth.pojo.result.MyResult; import com.njzscloud.supervisory.sys.dict.pojo.DictItemEntity; import com.njzscloud.supervisory.sys.dict.service.DictItemService; -import com.njzscloud.supervisory.sys.role.pojo.entity.RoleEntity; -import com.njzscloud.supervisory.sys.role.service.RoleService; +// import com.njzscloud.supervisory.sys.role.pojo.entity.RoleEntity; +// import com.njzscloud.supervisory.sys.role.service.RoleService; import com.njzscloud.supervisory.sys.stationletter.constant.WarnCategory; -import com.njzscloud.supervisory.sys.user.pojo.entity.UserEntity; -import com.njzscloud.supervisory.sys.user.pojo.result.SysUserRoleEntity; -import com.njzscloud.supervisory.sys.user.service.UserRoleService; -import com.njzscloud.supervisory.sys.user.service.UserService; +// import com.njzscloud.supervisory.sys.user.pojo.entity.UserEntity; +// import com.njzscloud.supervisory.sys.user.pojo.result.SysUserRoleEntity; +// import com.njzscloud.supervisory.sys.user.service.UserRoleService; +// import com.njzscloud.supervisory.sys.user.service.UserService; import com.njzscloud.supervisory.voicebox.service.CloudVoiceboxService; -import com.njzscloud.supervisory.wxPay.contant.TempType; +// import com.njzscloud.supervisory.wxPay.contant.TempType; +// import com.njzscloud.supervisory.wxPay.dto.RefundRequestDto; +// import com.njzscloud.supervisory.wxPay.param.TemplateMessageParam; import com.njzscloud.supervisory.wxPay.dto.RefundRequestDto; -import com.njzscloud.supervisory.wxPay.param.TemplateMessageParam; import com.njzscloud.supervisory.wxPay.service.PaymentService; -import com.njzscloud.supervisory.wxPay.service.WechatTemplateMessageService; +// import com.njzscloud.supervisory.wxPay.service.WechatTemplateMessageService; +// import com.njzscloud.supervisory.wxPay.service.WechatTemplateMessageService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -114,13 +116,13 @@ public class OrderInfoService extends ServiceImpl Exceptions.clierr("站点信息错误")); - Assert.isTrue(Integer.valueOf(1).equals(stationInfo.getStationType()), () -> Exceptions.clierr("系统暂未对接,预约失败")); + // Assert.isTrue(Integer.valueOf(1).equals(stationInfo.getStationType()), () -> Exceptions.clierr("系统暂未对接,预约失败")); Assert.isFalse(this.exists(Wrappers.lambdaQuery().eq(OrderInfoEntity::getSn, addOrderInfoParam.getSn())), () -> Exceptions.exception("订单创建失败,订单号重复")); AddOrderCargoPlaceParam cargoPlace = addOrderInfoParam.getCargoPlace(); long cargoPlaceId = orderCargoPlaceService.add(cargoPlace); @@ -182,7 +184,7 @@ public class OrderInfoService extends ServiceImpl Exceptions.clierr("您没有权限确认此单")); - // baseMapper.busyTruck(truckId, Boolean.TRUE); - OrderCargoPlaceEntity cargoPlaceEntity = orderCargoPlaceService.getById(orderInfo.getCargoPlaceId()); - String area = cargoPlaceEntity.getArea(); - BizAuditConfigEntity bizAuditConfigEntity = bizAuditConfigService.getOne(Wrappers.lambdaQuery(BizAuditConfigEntity.class).eq(BizAuditConfigEntity::getArea, area)); - AuditStatus auditStatus = AuditStatus.DaiShenHe; - if (bizAuditConfigEntity != null) { - String areaRole = bizAuditConfigEntity.getAreaRole(); - String cityRole = bizAuditConfigEntity.getCityRole(); - if (areaRole != null && cityRole != null) { - auditStatus = AuditStatus.QuDaiShenHe; - } else if (areaRole == null && cityRole != null) { - auditStatus = AuditStatus.ShiDaiShenHe; - } - } + Boolean driverHasInProgress = baseMapper.hasInProgressOrder(driverId, + Arrays.asList(OrderStatus.QingYunZhong.getVal(), OrderStatus.YiJinChang.getVal(), OrderStatus.YiChuChang.getVal())); + Assert.isFalse(driverHasInProgress, () -> Exceptions.clierr("您有正在进行中的订单,不能接单")); + + baseMapper.busyDriver(driverId, Boolean.TRUE); + baseMapper.busyTruck(truckId, Boolean.TRUE); + + String certificateSn = SnUtil.next(CERTIFICATE_SN_CODE); this.updateById(new OrderInfoEntity() .setId(orderInfo.getId()) .setDriverConfirmTime(LocalDateTime.now()) - .setAuditStatus(auditStatus) + .setAuditStatus(AuditStatus.TongGuo) .setTruckId(truckId) - .setOrderStatus(OrderStatus.YiJieDan) + .setOrderStatus(OrderStatus.QingYunZhong) + .setCertificateSn(certificateSn) + .setCheckStatus(CheckStatus.WeiKanLiao) + .setTransTime(LocalDateTime.now()) ); - try { - // 通知审核人 - RoleEntity roleEntity = new RoleEntity(); - if (null != bizAuditConfigEntity && !Strings.isNullOrEmpty(bizAuditConfigEntity.getAreaRole()) - && AuditStatus.QuDaiShenHe.equals(auditStatus)) { - roleEntity = roleService.getOne(Wrappers.lambdaQuery(RoleEntity.class).eq( - RoleEntity::getRoleCode, bizAuditConfigEntity.getAreaRole())); - } else if (null != bizAuditConfigEntity && !Strings.isNullOrEmpty(bizAuditConfigEntity.getCityRole()) - && AuditStatus.ShiDaiShenHe.equals(auditStatus)) { - roleEntity = roleService.getOne(Wrappers.lambdaQuery(RoleEntity.class).eq( - RoleEntity::getRoleCode, bizAuditConfigEntity.getCityRole())); + + Assert.notNull(truckId, () -> Exceptions.clierr("订单未分配车辆")); + BizTruckEntity truckInfo = baseMapper.getTruckInfo(truckId); + Assert.notNull(truckInfo, () -> Exceptions.clierr("车辆不存在")); + + String gpsId = truckInfo.getGps(); + String licensePlate = truckInfo.getLicensePlate(); + if (checkGps) { + Assert.notEmpty(gpsId, () -> Exceptions.clierr("车辆未绑定GPS")); + DeviceLocalizerEntity deviceLocalizerEntity = baseMapper.gpsLastOnlineTime(gpsId); + LocalDateTime lastTime = deviceLocalizerEntity.getLastTime(); + + boolean after = lastTime == null || lastTime.isBefore(LocalDateTime.now().minusMinutes(5)); + if (after) { + bizWarnService.save(new BizWarnEntity() + .setWarnCategory(WarnCategory.EQUIPMENT.getVal()) + .setWarnContent(StrUtil.format("{} 绑定的 GPS 设备已离线,设备号:{}", licensePlate, gpsId)) + .setOrderId(orderInfo.getId()) + ); + return; } - if (null != roleEntity && null != roleEntity.getId()) { - List userIds = userRoleService.list(Wrappers.lambdaQuery(SysUserRoleEntity.class) - .eq(SysUserRoleEntity::getRoleId, roleEntity.getId())); - UserEntity orderUserEntity = userService.getById(orderInfo.getUserId()); - OrderGoodsEntity entity = orderGoodsService.getById(orderInfo.getGoodsId()); - BizCompanyEntity companyEntity = bizCompanyService.getById(orderInfo.getTransCompanyId()); - Set openId = new HashSet<>(); - TemplateMessageParam param; - for (SysUserRoleEntity userRoleEntity : userIds) { - UserEntity userEntity = userService.getById(userRoleEntity.getUserId()); - if (null != userEntity && !Strings.isNullOrEmpty(userEntity.getOpenid())) { - if (openId.add(userEntity.getOpenid())) { - param = new TemplateMessageParam(); - param.setUserId(userRoleEntity.getUserId()); - param.setTempType(TempType.AUDIT_PENDING.getVal()); - param.setSn(orderInfo.getSn()); - param.setCfCompanyName(orderUserEntity.getNickname()); - param.setGoodsName(entity.getGoodsName()); - param.setCompanyName(companyEntity.getCompanyName()); - param.setCreateTime(orderInfo.getCreateTime()); - log.info("发送审核通知模板消息,参数:{}", param); - wechatTemplateMessageService.sendTemplateMessage(param); - } - } else { - log.info("未查到用户信息:{}", userRoleEntity.getUserId()); - } - } - } - } catch (Exception e) { - log.error("通知失败", e); } + + startTrack(gpsId, licensePlate, orderInfo.getId(), truckId); + + CompletableFuture.runAsync(() -> Websocket.publish(new WsMsg().setEvent("down/order/status_change") + .setData(MapUtil.builder() + .put("sn", orderInfo.getSn()) + .put("licensePlate", licensePlate) + .put("orderStatus", OrderStatus.QingYunZhong) + .build()))).exceptionally(e -> { + log.error("订单状态改变事件发布失败,订单{},状态{}", orderInfo.getSn(), OrderStatus.QingYunZhong, e); + return null; + }); } @Transactional(rollbackFor = Exception.class) @@ -2386,7 +2376,7 @@ public class OrderInfoService extends ServiceImpl