zxl
2 天以前 6db5d5a8fca3aa7e08190c2cfde2fa6cc72cfea2
framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java
@@ -23,11 +23,15 @@
import cn.lili.common.utils.CurrencyUtil;
import cn.lili.common.utils.SnowFlake;
import cn.lili.common.utils.StringUtils;
import cn.lili.common.vo.ResultMessage;
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;
import cn.lili.modules.member.mapper.MemberMapper;
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
import cn.lili.modules.order.cart.entity.enums.DeliveryMethodEnum;
import cn.lili.modules.order.order.aop.OrderLogPoint;
@@ -82,17 +86,22 @@
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
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;
import java.util.stream.Collectors;
import cn.lili.modules.permission.entity.dos.Role;
/**
@@ -107,6 +116,8 @@
    private static final String ORDER_SN_COLUMN = "order_sn";
    @Autowired
    private MemberMapper memberMapperMapper;
    /**
     * 延时任务
     */
@@ -184,7 +195,10 @@
    @Autowired
    private AdminUserService adminUserService;
    @Resource
    private RedisTemplate<Object,Object> redisTemplate;
    private final static  String LOCK_ORDER_NO_MQ="lock_order_no_mq:";
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void intoDB(TradeDTO tradeDTO) {
@@ -239,23 +253,57 @@
    }
    @Override
    public IPage<OrderSimpleVO> queryByParams(OrderSearchParams orderSearchParams) {
    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");
        queryWrapper.orderByDesc("o.id");
        IPage<OrderSimpleVO> page =  this.baseMapper.queryByParams(PageUtil.initPage(orderSearchParams), queryWrapper);
        if (!adminUserService.havePermissionRole(AdminRoleEnum.ORDER_INFO_PERMISSION)){
            for (OrderSimpleVO vo : page.getRecords()){
                vo.setConsigneeName(CommonUtil.maskName(vo.getConsigneeName()));
                vo.setConsigneeMobile(CommonUtil.maskMobile(vo.getConsigneeMobile()));
        if (needHide){
            if (!adminUserService.havePermissionRole(AdminRoleEnum.ORDER_INFO_PERMISSION)){
                for (OrderSimpleVO vo : page.getRecords()){
                    vo.setConsigneeName(CommonUtil.maskName(vo.getConsigneeName()));
                    vo.setConsigneeMobile(CommonUtil.maskMobile(vo.getConsigneeMobile()));
                }
            }
        }
        return page;
    }
    @Override
    public IPage<OrderSimpleXcxVO> queryByXcxParams(OrderSearchXcxParams orderSearchParams) {
        QueryWrapper queryWrapper = orderSearchParams.queryWrapper();
@@ -404,8 +452,6 @@
                vo.setConsigneeMobile(CommonUtil.maskMobile(vo.getConsigneeMobile()));
            }
        }
        XSSFWorkbook workbook = initOrderExportData(orderExportDTOS);
        try {
            // 设置响应头
@@ -443,6 +489,30 @@
    }
    @Override
    @Transactional
    public String sendMqMessage(String snNo) {
        //限制30秒只能请求一次避免出现重新提交问题
        Boolean b = redisTemplate.opsForValue().setIfAbsent(LOCK_ORDER_NO_MQ + snNo, snNo,30, TimeUnit.SECONDS);
        if ( Boolean.FALSE.equals(b)){
            throw new ServiceException("请在30秒后重试");
        }
        Order order = this.getBySn(snNo);
        if (order == null) {
            throw new ServiceException(ResultCode.ORDER_NOT_EXIST);
        }
        if (!OrderStatusEnum.PAID.name().equals(order.getOrderStatus())) {
            throw new ServiceException("订单状态不是已支付状态");
        }
        OrderMessage orderMessage = new OrderMessage();
        //发送订单已付款消息
        orderMessage.setOrderSn(order.getSn());
        orderMessage.setPaymentMethod(order.getPaymentMethod());
        orderMessage.setNewStatus(OrderStatusEnum.PAID);
        this.sendUpdateStatusMessage(orderMessage);
        return null;
    }
    @Override
    @OrderLogPoint(description = "'订单['+#orderSn+']取消,原因为:'+#reason", orderSn = "#orderSn")
    @Transactional(rollbackFor = Exception.class)
    public Order cancel(String orderSn, String reason) {
@@ -473,6 +543,7 @@
            throw new ServiceException(ResultCode.ORDER_CAN_NOT_CANCEL);
        }
    }
    @Override
@@ -1392,7 +1463,7 @@
        // 创建表头
        Row header = sheet.createRow(0);
        String[] headers = {"主订单编号", "子订单编号", "选购商品", "商品数量", "商品ID", "商品单价", "订单应付金额",
                "运费", "优惠总金额", "平台优惠", "商家优惠", "商家改价", "支付方式", "收件人", "收件人手机号",
                "运费", "优惠总金额", "平台优惠", "商家优惠", "商家改价", "支付方式","买家名称", "收件人", "收件人手机号",
                "省", "市", "区", "街道", "详细地址", "买家留言", "订单提交时间", "支付完成时间", "来源",
                "订单状态", "订单类型", "售后状态", "取消原因", "发货时间", "完成时间", "店铺"};
@@ -1417,24 +1488,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());
        }
        //修改列宽