Pu Zhibing
2025-02-08 d94776ba25ffcd19cdd7970048ed88d9212bd394
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
@@ -43,9 +43,11 @@
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jetbrains.annotations.Nullable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@@ -59,6 +61,7 @@
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -316,8 +319,11 @@
        }
        //搜索条件,用户姓名
        if(StringUtils.isNotEmpty(orderPageList.getUserName())){
            List<AppUser> data = appUserClient.getAppUserByName(orderPageList.getUserName()).getData();
            List<AppUser> data = appUserClient.getAppUserByNameNoFilter(orderPageList.getUserName()).getData();
            List<Long> collect = data.stream().map(AppUser::getId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(collect)){
                return new PageInfo<>();
            }
            if(null != orderPageList.getAppUserIds()){
                List<Long> appUserIds = orderPageList.getAppUserIds();
                appUserIds.addAll(collect);
@@ -328,19 +334,31 @@
        }
        //搜索条件,用户电话
        if(StringUtils.isNotEmpty(orderPageList.getPhone())){
            List<AppUser> data = appUserClient.getAppUserByPhone(orderPageList.getPhone()).getData();
            List<AppUser> data = appUserClient.getAppUserByPhoneNoFilter(orderPageList.getPhone()).getData();
            List<Long> collect = data.stream().map(AppUser::getId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(collect)){
                return new PageInfo<>();
            }
            if(null != orderPageList.getAppUserIds()){
                List<Long> appUserIds = orderPageList.getAppUserIds();
                if (!containsAny(appUserIds,collect)) {
                    return new PageInfo<>();
                }
                appUserIds.addAll(collect);
                orderPageList.setAppUserIds(appUserIds);
            }else{
                orderPageList.setAppUserIds(collect);
            }
        }
        PageInfo<OrderPageListVo> pageInfo = new PageInfo(orderPageList.getPageCurr(), orderPageList.getPageSize());
        if (null != orderPageList.getAppUserIds()){
            orderPageList.setAppUserIds(orderPageList.getAppUserIds().stream().distinct().collect(Collectors.toList()));
        }
        PageInfo<OrderPageListVo> pageInfo = new PageInfo<>(orderPageList.getPageCurr(), orderPageList.getPageSize());
        List<OrderPageListVo> list = this.baseMapper.getOrderPageList(pageInfo, orderPageList);
        for (OrderPageListVo orderPageListVo : list) {
            Long appUserId = orderPageListVo.getAppUserId();
@@ -373,6 +391,29 @@
        }
        return pageInfo.setRecords(list);
    }
    /**
     * 判断 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;
    }
@@ -436,7 +477,7 @@
        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");
@@ -447,7 +488,8 @@
        this.updateById(order);
        return R.ok();
    }
    
    /**
     * 取消订单操作
@@ -940,22 +982,23 @@
            Workbook workbook = new XSSFWorkbook(fileInputStream);
            Sheet sheet = workbook.getSheetAt(0); // 获取第一个Sheet
            int lastRowNum = sheet.getLastRowNum();
            for (int i = 2; i <= lastRowNum; i++) {
            for (int i = 1; i <= lastRowNum; i++) {
                Row row = sheet.getRow(i);
                row.getCell(1).setCellType(CellType.STRING);
                String orderNum = row.getCell(1).getStringCellValue();
                // 订单编号
                row.getCell(0).setCellType(CellType.STRING);
                String orderNum = row.getCell(0).getStringCellValue();
                // 快递单号
                row.getCell(7).setCellType(CellType.STRING);
                String expressNum = row.getCell(7).getStringCellValue();
                row.getCell(1).setCellType(CellType.STRING);
                String expressNum = row.getCell(1).getStringCellValue();
                // 快递公司名称
                row.getCell(8).setCellType(CellType.STRING);
                String expressName = row.getCell(8).getStringCellValue();
                row.getCell(2).setCellType(CellType.STRING);
                String expressName = row.getCell(2).getStringCellValue();
                // 省区划代码
                row.getCell(10).setCellType(CellType.STRING);
                String provinceCode = row.getCell(10).getStringCellValue();
                row.getCell(3).setCellType(CellType.STRING);
                String provinceCode = row.getCell(3).getStringCellValue();
                // 市区划代码
                row.getCell(12).setCellType(CellType.STRING);
                String cityCode = row.getCell(12).getStringCellValue();
                row.getCell(4).setCellType(CellType.STRING);
                String cityCode = row.getCell(4).getStringCellValue();
                Order order = this.getOne(new LambdaQueryWrapper<Order>()
                        .eq(Order::getOrderNumber, orderNum)
                );
@@ -989,7 +1032,7 @@
                    throw new ServiceException("城市编码错误:"+cityCode, 500);
                }
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("com", expressName);
                jsonObject.put("com", companyNameByCode);
                jsonObject.put("num", expressNum);
                ConfirmDelivery confirmDelivery =new ConfirmDelivery();
                confirmDelivery.setOrderId(order.getId());
@@ -1037,7 +1080,4 @@
        }
    }
    public static void main(String[] args) throws MalformedURLException {
        importExpress2("http://qijishenghuiyuan.obs.cn-southwest-2.myhuaweicloud.com/admin/69c1fcbe5c114f2a9f38703e4f5e1af0.xlsx");
    }
}