| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.dataInterchange.api.feignClient.UPExgMsgTakeEwayBillAckClient; |
| | | import com.ruoyi.dataInterchange.api.vo.UPExgMsgTakeEwayBillAckVo; |
| | | import com.ruoyi.system.api.model.Car; |
| | | import com.ruoyi.system.api.model.Driver; |
| | | import com.ruoyi.system.api.model.Enterprise; |
| | | import com.ruoyi.system.api.model.Order; |
| | | import com.ruoyi.system.mapper.OrderMapper; |
| | | import com.ruoyi.system.query.OrderListReq; |
| | | import com.ruoyi.system.service.ICarService; |
| | | import com.ruoyi.system.service.IDriverService; |
| | | import com.ruoyi.system.service.IEnterpriseService; |
| | | import com.ruoyi.system.service.IOrderService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneOffset; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | |
| | | |
| | | /** |
| | |
| | | @Service |
| | | public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService { |
| | | |
| | | @Resource |
| | | private UPExgMsgTakeEwayBillAckClient upExgMsgTakeEwayBillAckClient; |
| | | |
| | | @Resource |
| | | private IEnterpriseService enterpriseService; |
| | | |
| | | @Resource |
| | | private IDriverService driverService; |
| | | |
| | | @Resource |
| | | private ICarService carService; |
| | | |
| | | |
| | | /** |
| | | * 存储新订单数据 |
| | | */ |
| | | @Override |
| | | public void taskSaveNewOrder() { |
| | | Order order = this.getOne(new LambdaQueryWrapper<Order>().orderByDesc(Order::getCreateTime).last(" limit 1")); |
| | | Long createTime = -1L; |
| | | if (null != order) { |
| | | createTime = order.getCreateTime().toEpochSecond(ZoneOffset.ofHours(8)); |
| | | } |
| | | List<UPExgMsgTakeEwayBillAckVo> list = upExgMsgTakeEwayBillAckClient.findByCreateTimeAfter(createTime).getData(); |
| | | if (null == list || list.isEmpty()) { |
| | | return; |
| | | } |
| | | List<Enterprise> list1 = enterpriseService.list(); |
| | | List<Driver> driverList = driverService.list(new LambdaQueryWrapper<Driver>().eq(Driver::getStatus, 1)); |
| | | List<Car> carList = carService.list(); |
| | | List<Order> orders = new ArrayList<>(); |
| | | for (UPExgMsgTakeEwayBillAckVo vo : list) { |
| | | order = new Order(); |
| | | Optional<Car> carOptional = carList.stream().filter(s -> s.getVehicleNumber().equals(vo.getVehicleNo())).findFirst(); |
| | | if (carOptional.isPresent()) { |
| | | order.setCarId(carOptional.get().getId()); |
| | | } |
| | | Optional<Driver> optional = driverList.stream().filter(s -> s.getVehicleNumber().equals(vo.getVehicleNo())).findFirst(); |
| | | if (optional.isPresent()) { |
| | | order.setDriverId(optional.get().getId()); |
| | | } |
| | | Enterprise enterprise = list1.stream().filter(s -> s.getCode().equals(vo.getInferiorPlatformId().toString())).findFirst().get(); |
| | | order.setEnterpriseId(enterprise.getId()); |
| | | order.setOrderTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(vo.getCreateTime() * 1000), ZoneOffset.ofHours(8)).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | |
| | | |
| | | order.setCreateTime(LocalDateTime.now()); |
| | | order.setVehicleNumber(vo.getVehicleNo()); |
| | | orders.add(order); |
| | | } |
| | | if (orders.size() > 0) { |
| | | this.saveBatch(orders); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 定时保存车辆id和司机id |
| | | */ |
| | | @Override |
| | | public void taskSaveCarIdAndDriverId() { |
| | | List<Order> list = this.list(new LambdaQueryWrapper<Order>().isNull(Order::getCarId).or().isNull(Order::getDriverId)); |
| | | List<Car> carList = carService.list(); |
| | | List<Driver> driverList = driverService.list(new LambdaQueryWrapper<Driver>().eq(Driver::getStatus, 1)); |
| | | for (Order order : list) { |
| | | Optional<Driver> optional = driverList.stream().filter(s -> s.getVehicleNumber().equals(order.getVehicleNumber())).findFirst(); |
| | | if (optional.isPresent()) { |
| | | order.setDriverId(optional.get().getId()); |
| | | this.updateById(order); |
| | | } |
| | | Optional<Car> optional1 = carList.stream().filter(s -> s.getVehicleNumber().equals(order.getVehicleNumber())).findFirst(); |
| | | if (optional1.isPresent()) { |
| | | order.setCarId(optional1.get().getId()); |
| | | this.updateById(order); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取订单列表 |
| | | * |
| | | * @param req |
| | | * @return |
| | | */ |
| | |
| | | PageInfo<Order> pageInfo = new PageInfo<>(req.getPageCurr(), req.getPageSize()); |
| | | return this.baseMapper.getOrderList(pageInfo, req); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |