peng
3 天以前 9f92aa108c24a67fabe80977cede0e0352318681
framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java
@@ -27,6 +27,7 @@
import cn.lili.modules.goods.entity.dos.Goods;
import cn.lili.modules.goods.entity.dto.GoodsCompleteMessage;
import cn.lili.modules.goods.service.GoodsService;
import cn.lili.modules.lmk.domain.vo.OrderCountVO;
import cn.lili.modules.lmk.enums.general.AdminRoleEnum;
import cn.lili.modules.member.entity.dos.Member;
import cn.lili.modules.member.entity.dto.MemberAddressDTO;
@@ -70,6 +71,7 @@
import cn.lili.trigger.util.DelayQueueTools;
import cn.lili.utils.COSUtil;
import cn.lili.utils.CommonUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -97,6 +99,7 @@
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -197,6 +200,7 @@
    private RedisTemplate<Object,Object> redisTemplate;
    private final static  String LOCK_ORDER_NO_MQ="lock_order_no_mq:";
    private final static  String LOCK_EDIT_ORDER_ADDRESS="lock_edit_order_address:";
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void intoDB(TradeDTO tradeDTO) {
@@ -251,6 +255,41 @@
    }
    @Override
    public OrderCountVO countByIdOrder(String id) {
        OrderSearchParams orderSearchParams = new OrderSearchParams();
        orderSearchParams.setOrderStatus(OrderStatusEnum.COMPLETED.name());
        orderSearchParams.setMemberId(id);
        QueryWrapper queryWrapper = orderSearchParams.queryWrapper();
        queryWrapper.groupBy("o.id");
        queryWrapper.orderByDesc("o.id");
        List<OrderSimpleVO> list =  this.baseMapper.queryByParamsCount(queryWrapper);
        OrderCountVO orderCountVO = new OrderCountVO();
        orderCountVO.setOrderNumCount(0);
        orderCountVO.setOrderPriceCount(BigDecimal.ZERO);
        if (CollectionUtil.isEmpty(list)) {
            return orderCountVO;
        }else {
            for (OrderSimpleVO vo : list) {
                if (vo == null) {
                    System.out.println("出现空元素");
                    continue; // 跳过null元素,或根据业务处理
                }
                orderCountVO.setOrderNumCount(orderCountVO.getOrderNumCount() + 1);
                // 金额累加:用BigDecimal处理,避免精度问题
                BigDecimal flowPrice = vo.getFlowPrice() != null ?
                        BigDecimal.valueOf(vo.getFlowPrice()) : BigDecimal.ZERO;
                // 用BigDecimal的add方法累加
                BigDecimal totalPrice = orderCountVO.getOrderPriceCount().add(flowPrice);
                orderCountVO.setOrderPriceCount(totalPrice);
            }
        }
        return orderCountVO;
    }
    @Override
    public IPage<OrderSimpleVO> queryByParams(OrderSearchParams orderSearchParams,Boolean needHide) {
        QueryWrapper queryWrapper = orderSearchParams.queryWrapper();
        queryWrapper.groupBy("o.id");
@@ -265,17 +304,8 @@
            }
        }
//        for (OrderSimpleVO vo : page.getRecords()){
//            Member member = memberMapperMapper.selectById(vo.getMemberId());
//            if (member != null){
//                vo.setNickName(member.getNickName());
//            }
//        }
        return page;
    }
    @Override
    public IPage<OrderSimpleXcxVO> queryByXcxParams(OrderSearchXcxParams orderSearchParams) {
        QueryWrapper queryWrapper = orderSearchParams.queryWrapper();
@@ -424,8 +454,6 @@
                vo.setConsigneeMobile(CommonUtil.maskMobile(vo.getConsigneeMobile()));
            }
        }
        XSSFWorkbook workbook = initOrderExportData(orderExportDTOS);
        try {
            // 设置响应头
@@ -460,6 +488,18 @@
        Receipt receipt = receiptService.getByOrderSn(orderSn);
        //查询订单和自订单,然后写入vo返回
        return new OrderDetailVO(order, orderItems, orderLogs, receipt);
    }
    @Override
    public OrderDetailVO queryEditAddressDetail(String orderSn) {
        Order order = this.getBySn(orderSn);
        if (order == null) {
            throw new ServiceException(ResultCode.ORDER_NOT_EXIST);
        }
        //查询订单项信息
        List<OrderItem> orderItems = orderItemService.getByOrderSn(orderSn);
        //查询订单和自订单,然后写入vo返回
        return new OrderDetailVO(order, orderItems, null, null);
    }
    @Override
@@ -517,6 +557,7 @@
            throw new ServiceException(ResultCode.ORDER_CAN_NOT_CANCEL);
        }
    }
    @Override
@@ -638,16 +679,52 @@
        return order;
    }
    @Override
    @SystemLogPoint(description = "修改订单", customerLog = "'订单[' + #orderSn + ']收货信息修改,修改为'+#memberAddressDTO.consigneeDetail")
    @Transactional(rollbackFor = Exception.class)
    public Order updateAddressConsignee(String orderSn, MemberAddressDTO memberAddressDTO) {
        Order order = this.getBySn(orderSn);
        if (order == null) {
            throw new ServiceException(ResultCode.ORDER_NOT_EXIST);
        }
        //限制30秒只能请求一次避免出现重新提交问题
        Boolean b = redisTemplate.opsForValue().setIfAbsent(LOCK_EDIT_ORDER_ADDRESS + orderSn, orderSn,30, TimeUnit.SECONDS);
        if ( Boolean.FALSE.equals(b)){
            throw new ServiceException("请在30秒后重试");
        }
        String modifyAddressFlag = order.getModifyAddressFlag();
        if (StringUtils.isNotBlank(modifyAddressFlag)) {
            throw new ServiceException("当前订单已经被领取");
        }
        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        wrapper.eq("id", order.getId());
        // 使用 last 方法拼接 FOR UPDATE 语句
        wrapper.last("FOR UPDATE");
        baseMapper.selectOne(wrapper);
        //要记录之前的收货地址,所以需要以代码方式进行调用 不采用注解
        String message = "订单[" + orderSn + "]收货信息修改,由[" +order.getConsigneeAddressPath()+  order.getConsigneeDetail() + "]修改为[" + memberAddressDTO.getConsigneeAddressPath()+ memberAddressDTO.getConsigneeDetail() + "]";
        //记录订单操作日志
        BeanUtil.copyProperties(memberAddressDTO, order);
        order.setModifyAddressFlag(ModifyAddressEnums.USED.name());
        this.updateById(order);
        OrderLog orderLog = new OrderLog(orderSn, UserContext.getCurrentUser().getId(), UserContext.getCurrentUser().getRole().getRole(),
                UserContext.getCurrentUser().getUsername(), message);
        orderLogService.save(orderLog);
        return order;
    }
    @Override
    @OrderLogPoint(description = "'订单['+#orderSn+']发货,发货单号['+#logisticsNo+']'", orderSn = "#orderSn")
    @Transactional(rollbackFor = Exception.class)
    public Order delivery(String orderSn, String logisticsNo, String logisticsId) {
        Order order = OperationalJudgment.judgment(this.getBySn(orderSn));
        //如果订单未发货,并且订单状态值等于待发货
        log.info("获取到的订单信息为{}", JSON.toJSONString(order));
        if (order.getDeliverStatus().equals(DeliverStatusEnum.UNDELIVERED.name()) && order.getOrderStatus().equals(OrderStatusEnum.UNDELIVERED.name())) {
            //获取对应物流
            Logistics logistics = logisticsService.getById(logisticsId);
            log.info("获取到的物流信息id为{}", logisticsId);
            log.info("获取到的物流信息为{}", JSON.toJSONString(logistics));
            if (logistics == null) {
                throw new ServiceException(ResultCode.ORDER_LOGISTICS_ERROR);
            }
@@ -1314,6 +1391,12 @@
        this.update(new LambdaUpdateWrapper<Order>()
                .eq(Order::getSn, orderSn)
                .set(Order::getOrderStatus, orderStatusEnum.name()));
        //修改订单商品 todo 所有的订单需要审核后才能退款
        orderItemService.update(new LambdaUpdateWrapper<OrderItem>()
                .eq(OrderItem::getOrderSn,orderSn)
                .set(OrderItem::getAfterSaleStatus, OrderItemAfterSaleStatusEnum.NOT_APPLIED.name())
                .set(OrderItem::getCommentStatus,CommentStatusEnum.UNFINISHED.name())
                .set(OrderItem::getComplainStatus, OrderComplaintStatusEnum.NO_APPLY.name()));
        //修改订单
        OrderMessage orderMessage = new OrderMessage();
        orderMessage.setNewStatus(orderStatusEnum);
@@ -1436,7 +1519,7 @@
        // 创建表头
        Row header = sheet.createRow(0);
        String[] headers = {"主订单编号", "子订单编号", "选购商品", "商品数量", "商品ID", "商品单价", "订单应付金额",
                "运费", "优惠总金额", "平台优惠", "商家优惠", "商家改价", "支付方式", "收件人", "收件人手机号",
                "运费", "优惠总金额", "平台优惠", "商家优惠", "商家改价", "支付方式","买家名称", "收件人", "收件人手机号",
                "省", "市", "区", "街道", "详细地址", "买家留言", "订单提交时间", "支付完成时间", "来源",
                "订单状态", "订单类型", "售后状态", "取消原因", "发货时间", "完成时间", "店铺"};
@@ -1461,24 +1544,27 @@
            row.createCell(10).setCellValue(dto.getStoreMarketingCost()!=null?dto.getStoreMarketingCost():0);
            row.createCell(11).setCellValue(dto.getUpdatePrice()!=null?dto.getUpdatePrice():0);
            row.createCell(12).setCellValue(dto.getPaymentMethod());
            row.createCell(13).setCellValue(dto.getConsigneeName());
            row.createCell(14).setCellValue(dto.getConsigneeMobile());
            row.createCell(15).setCellValue(dto.getProvince());
            row.createCell(16).setCellValue(dto.getCity());
            row.createCell(17).setCellValue(dto.getDistrict());
            row.createCell(18).setCellValue(dto.getStreet());
            row.createCell(19).setCellValue(dto.getConsigneeDetail());
            row.createCell(20).setCellValue(dto.getRemark());
            row.createCell(21).setCellValue(dto.getCreateTime());
            row.createCell(22).setCellValue(dto.getPaymentTime());
            row.createCell(23).setCellValue(dto.getClientType());
            row.createCell(24).setCellValue(dto.getOrderStatus());
            row.createCell(25).setCellValue(dto.getOrderType());
            row.createCell(26).setCellValue(dto.getAfterSaleStatus());
            row.createCell(27).setCellValue(dto.getCancelReason());
            row.createCell(28).setCellValue(dto.getLogisticsTime());
            row.createCell(29).setCellValue(dto.getCompleteTime());
            row.createCell(30).setCellValue(dto.getStoreName());
            row.createCell(13).setCellValue(dto.getNickName());
            row.createCell(14).setCellValue(dto.getConsigneeName());
            row.createCell(15).setCellValue(dto.getConsigneeMobile());
            row.createCell(16).setCellValue(dto.getProvince());
            row.createCell(17).setCellValue(dto.getCity());
            row.createCell(18).setCellValue(dto.getDistrict());
            row.createCell(19).setCellValue(dto.getStreet());
            row.createCell(20).setCellValue(dto.getConsigneeDetail());
            row.createCell(21).setCellValue(dto.getRemark());
            row.createCell(22).setCellValue(dto.getCreateTime());
            row.createCell(23).setCellValue(dto.getPaymentTime());
            row.createCell(24).setCellValue(dto.getClientType());
            row.createCell(25).setCellValue(dto.getOrderStatus());
            row.createCell(26).setCellValue(dto.getOrderType());
            row.createCell(27).setCellValue(dto.getAfterSaleStatus());
            row.createCell(28).setCellValue(dto.getCancelReason());
            row.createCell(29).setCellValue(dto.getLogisticsTime());
            row.createCell(30).setCellValue(dto.getCompleteTime());
            row.createCell(31).setCellValue(dto.getStoreName());
        }
        //修改列宽