luofl
2025-03-04 485b09d75ac79350392e234a62521050bf6374de
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
@@ -117,6 +117,9 @@
    private ShopBalanceStatementClient shopBalanceStatementClient;
    @Resource
    private ShopPointClient shopPointClient;
    @Resource
    private RedisTemplate redisTemplate;
    @Resource
@@ -130,6 +133,10 @@
    @Resource
    private RegionClient regionClient;
    @Resource
    private AppUserGiveawayTemporaryClient appUserGiveawayTemporaryClient;
    @Resource
    private ShopGiveawayTemporaryClient shopGiveawayTemporaryClient;
    @Override
@@ -290,15 +297,14 @@
        JSONObject jsonObject = JSONObject.parseObject(content);
        Long days = jsonObject.getLong("days");
        order.setOrderStatus(OrderStatus.COMPLETED.getCode());
        order.setIsCommission(0);
        order.setAfterSaleTime(LocalDateTime.now().plusDays(days));
        order.setEndTime(LocalDateTime.now());
        order.setCancellerAppUserId(loginUserApplet.getUserid());
        if (StringUtils.isNotEmpty(technicianId) && !"null".equals(technicianId)) {
            order.setTechnicianId(Integer.valueOf(technicianId));
        }
        // TODO
        orderMapper.updateById(order);
        commissionService.calculationCommissionShop(order.getId());
    }
@@ -439,52 +445,26 @@
        if (200 == r.getCode()) {
            this.updateById(order);
        }
        R r1 = balanceChangeRecordClient.deleteBalanceChangeRecordCopy(orderId, Arrays.asList(4));
        if (200 != r1.getCode()) { // 项目没有分布式事务,此处报错可能会导致数据不一致
         throw new RuntimeException("订单取消失败");
        }
        R r2 = userPointClient.deleteUserPointCopy(orderId, Arrays.asList(2,8,9,10,14));
        if (200 != r2.getCode()) { // 项目没有分布式事务,此处报错可能会导致数据不一致
            throw new RuntimeException("订单取消失败");
        }
        R<Boolean> r3 = shopBalanceStatementClient.deleteShopBalanceStatementCopy(orderId, Arrays.asList(1,2,3));
        if (200 != r3.getCode()) { // 项目没有分布式事务,此处报错可能会导致数据不一致
            throw new RuntimeException("订单取消失败");
        }
        shopPointClient.deleteShopPointCopy(orderId, Arrays.asList(1,2,3));
        appUserGiveawayTemporaryClient.delAppUserGiveawayTemporary(orderId);
        shopGiveawayTemporaryClient.delShopGiveawayTemporary(orderId);
        return r;
    }
    /**
     * 确认发货操作
     *
     * @return
     */
    @Override
    public R confirmDelivery(ConfirmDelivery confirmDelivery) {
        Order order = this.getById(confirmDelivery.getOrderId());
        if (1 == order.getPayStatus()) {
            return R.fail("订单还未完成支付");
        }
        if (1 == order.getOrderType() || null == order.getAddressJson()) {
            return R.fail("该订单不支付快递配送");
        }
        if (1 != order.getOrderStatus()) {
            return R.fail("无效的操作");
        }
        //添加快递号和修改订单状态
        order.setExpressJson(confirmDelivery.getCode());
        order.setDeliverProvince(confirmDelivery.getDeliverProvince());
        order.setDeliverProvinceCode(confirmDelivery.getDeliverProvinceCode());
        order.setDeliverCity(confirmDelivery.getDeliverCity());
        order.setDeliverCityCode(confirmDelivery.getDeliverCityCode());
        order.setDeliverDistrict(confirmDelivery.getDeliverDistrict());
        order.setDeliverDistrictCode(confirmDelivery.getDeliverDistrictCode());
        order.setOrderStatus(2);
        //添加查询快递信息队列
        //一小时后定时查询快递信息
        SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData();
        JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
        Integer waitTime = jsonObject.getInteger("waitTime");
        redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(waitTime).toEpochSecond(ZoneOffset.UTC));
        JSONObject jsonObject1 = JSON.parseObject(confirmDelivery.getCode());
        String com = jsonObject1.getString("com");
        String num = jsonObject1.getString("num");
        UserAddress userAddress = JSON.parseObject(order.getAddressJson(), UserAddress.class);
        MapTrackKD100Vo mapTrackKD100Vo = ExpressDeliveryUtil.kd100MapTrack(com, num, order.getDeliverProvince() + order.getDeliverCity(),
                userAddress.getProvince() + userAddress.getCity());
        order.setExpressResult(JSON.toJSONString(mapTrackKD100Vo));
        this.updateById(order);
        return R.ok();
    }
    /**
@@ -980,11 +960,15 @@
        }
    }
    @SneakyThrows
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importExpress(String url) {
        URL url1 = new URL(url);
        URL url1 = null;
        try {
            url1 = new URL(url);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        try (InputStream fileInputStream = url1.openStream()) {
            Workbook workbook = new XSSFWorkbook(fileInputStream);
            Sheet sheet = workbook.getSheetAt(0); // 获取第一个Sheet
@@ -1048,7 +1032,10 @@
                confirmDelivery.setDeliverProvinceCode(regionBiCode.getData().getCode());
                confirmDelivery.setDeliverCity(regionBiCode1.getData().getName());
                confirmDelivery.setDeliverCityCode(regionBiCode1.getData().getCode());
                confirmDelivery(confirmDelivery);
                R r = confirmDelivery(confirmDelivery);
                if (R.isError(r)) {
                    throw new ServiceException(r.getMsg(), 500);
                }
            }
        } catch (IOException e) {
@@ -1059,6 +1046,50 @@
    }
    /**
     * 确认发货操作
     *
     * @return
     */
    @Override
    public R confirmDelivery(ConfirmDelivery confirmDelivery) {
        Order order = this.getById(confirmDelivery.getOrderId());
        if (1 == order.getPayStatus()) {
            return R.fail("订单还未完成支付");
        }
        if (1 == order.getOrderType() || null == order.getAddressJson()) {
            return R.fail("该订单不支付快递配送");
        }
        if (1 != order.getOrderStatus()) {
            return R.fail("无效的操作");
        }
        //添加快递号和修改订单状态
        order.setExpressJson(confirmDelivery.getCode());
        order.setDeliverProvince(confirmDelivery.getDeliverProvince());
        order.setDeliverProvinceCode(confirmDelivery.getDeliverProvinceCode());
        order.setDeliverCity(confirmDelivery.getDeliverCity());
        order.setDeliverCityCode(confirmDelivery.getDeliverCityCode());
        order.setDeliverDistrict(confirmDelivery.getDeliverDistrict());
        order.setDeliverDistrictCode(confirmDelivery.getDeliverDistrictCode());
        order.setOrderStatus(2);
        //添加查询快递信息队列
        //一小时后定时查询快递信息
        SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData();
        JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
        Integer waitTime = jsonObject.getInteger("waitTime");
        redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(waitTime).toEpochSecond(ZoneOffset.UTC));
        JSONObject jsonObject1 = JSON.parseObject(confirmDelivery.getCode());
        String com = jsonObject1.getString("com");
        String num = jsonObject1.getString("num");
        UserAddress userAddress = JSON.parseObject(order.getAddressJson(), UserAddress.class);
        MapTrackKD100Vo mapTrackKD100Vo = ExpressDeliveryUtil.kd100MapTrack(com, num, order.getDeliverProvince() + order.getDeliverCity(),
                userAddress.getProvince() + userAddress.getCity());
        order.setExpressResult(JSON.toJSONString(mapTrackKD100Vo));
        this.updateById(order);
        return R.ok();
    }
    public static void importExpress2(String filePath) throws MalformedURLException {
        // 从网络地址读取