luofl
2025-03-17 e23242d09e31e1c78f7ecdbc2859c9f99a3c4171
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
@@ -34,6 +34,7 @@
import com.ruoyi.system.api.feignClient.SysUserClient;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.*;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -482,6 +483,16 @@
        return R.ok(collect);
    }
    /**
     * 获取指定门店的核销订单
     */
    @GetMapping("/getRedeemedOrdersByShop")
    public R<List<Order>> getRedeemedOrdersByShop(@RequestParam("shopId") Integer shopId) {
        return R.ok(orderService.list(new LambdaQueryWrapper<Order>()
                .isNotNull(Order::getEndTime)
                .eq(Order::getShopId, shopId)));
    }
    /**
     * 获取订单快递明细
@@ -545,11 +556,55 @@
    @GetMapping("/exportExpress")
    public void exportExpress(HttpServletResponse response, OrderPageList orderPage) {
        //搜索条件,用户姓名
        if (StringUtils.isNotEmpty(orderPage.getUserName())) {
            List<AppUser> data = appUserClient.getAppUserByNameNoFilter(orderPage.getUserName()).getData();
            List<Long> collect = data.stream().map(AppUser::getId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(collect)) {
                return;
            }
            if (null != orderPage.getAppUserIds()) {
                List<Long> appUserIds = orderPage.getAppUserIds();
                appUserIds.addAll(collect);
                orderPage.setAppUserIds(appUserIds);
            } else {
                orderPage.setAppUserIds(collect);
            }
        }
        //搜索条件,用户电话
        if (StringUtils.isNotEmpty(orderPage.getPhone())) {
            List<AppUser> data = appUserClient.getAppUserByPhoneNoFilter(orderPage.getPhone()).getData();
            List<Long> collect = data.stream().map(AppUser::getId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(collect)) {
                return;
            }
            if (null != orderPage.getAppUserIds()) {
                List<Long> appUserIds = orderPage.getAppUserIds();
                if (!containsAny(appUserIds, collect)) {
                    return;
                }
                appUserIds.addAll(collect);
                orderPage.setAppUserIds(appUserIds);
            } else {
                orderPage.setAppUserIds(collect);
            }
        }
        if (null != orderPage.getAppUserIds()) {
            orderPage.setAppUserIds(orderPage.getAppUserIds().stream().distinct().collect(Collectors.toList()));
        }
//        UserAddress userAddress = JSON.parseObject(order.getAddressJson(), UserAddress.class);
//        orderInfo.setRecipient(userAddress.getRecieveName() + "-" + userAddress.getRecievePhone());
//        userAddress.setRecieveAddress(userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getRecieveAddress());
//        orderInfo.setAddress(userAddress.getRecieveAddress());
        List<OrderExport> orderExportList = orderMapper.getOrderExportList(orderPage);
        orderExportList.forEach(orderExport -> {
            Long appUserId = orderExport.getAppUserId();
            AppUser appUserById = appUserClient.getAppUserById(appUserId);
            if (null != appUserById){
            if (null != appUserById) {
                orderExport.setUserName(appUserById.getName());
                orderExport.setPhone(appUserById.getPhone());
            }
@@ -557,7 +612,8 @@
            if (StringUtils.isNotEmpty(goodJson) && !"NULL".equals(goodJson)) {
                Goods goods = JSONObject.parseObject(goodJson, Goods.class);
                orderExport.setGoodsName(goods.getName());
                orderExport.setCostPrice(goods.getShopCost().add(goods.getOperatingCost()));
                orderExport.setCompanyCostPrice(goods.getOperatingCost());
                orderExport.setSupplierCostPrice(goods.getShopCost());
            }
            String expressJson = orderExport.getExpressJson();
@@ -566,6 +622,17 @@
                orderExport.setExpressNum(jsonObject.getString("num"));
                orderExport.setExpressName(ExpressCompanyMap.getCompanyNameByCode(jsonObject.getString("com")));
            }
            String addressJson = orderExport.getAddressJson();
            if (StringUtils.isNotEmpty(addressJson)) {
                UserAddress userAddress = JSON.parseObject(addressJson, UserAddress.class);
                orderExport.setAddress(
                                userAddress.getProvince() +
                                userAddress.getCity() +
                                userAddress.getDistrict() +
                                userAddress.getRecieveAddress()
                );
            }
        });
@@ -576,6 +643,29 @@
    /**
     * 判断 list1 是否包含 list2 中的至少一个元素
     *
     * @param list1 第一个列表
     * @param list2 第二个列表
     * @return 如果 list1 包含 list2 中的至少一个元素,返回 true;否则返回 false
     */
    private boolean containsAny(List<Long> list1, List<Long> list2) {
        // 将 list1 转换为 HashSet 以提高查询效率
        Set<Long> set1 = new HashSet<>(list1);
        // 遍历 list2,检查是否有元素存在于 set1 中
        for (Long element : list2) {
            if (set1.contains(element)) {
                return true;
            }
        }
        // 如果没有找到共同元素,返回 false
        return false;
    }
    /**
     * 获取用户订单数量
     *
     * @param appUserId