package com.jeesharp.business.modules.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jeesharp.business.modules.mall.entity.MallOrderItem;
import com.jeesharp.business.modules.mall.mapper.MallOrderItemMapper;
import com.jeesharp.business.modules.mall.service.MallOrderItemService;
import com.jeesharp.business.modules.mall.vo.MallOrderItemQueryVO;
import com.jeesharp.framework.mybatis.core.service.CrudService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

/**
 * 商城订单明细领域服务实现。
 *
 * @author jeesharp
 * @since 2026-05-15
 */
@Service
@Transactional(readOnly = true)
public class MallOrderItemServiceImpl extends CrudService<MallOrderItemMapper, MallOrderItem, MallOrderItemQueryVO>
    implements MallOrderItemService {

    @Override
    @Transactional(readOnly = false)
    public void createItem(MallOrderItem item) {
        save(item);
    }

    @Override
    public List<MallOrderItem> findByOrderIds(List<String> orderIds) {
        if (orderIds == null || orderIds.isEmpty()) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<MallOrderItem> w = new LambdaQueryWrapper<>();
        w.in(MallOrderItem::getOrderId, orderIds);
        w.eq(MallOrderItem::getDelFlag, "0");
        w.orderByAsc(MallOrderItem::getCreateDate);
        return getBaseMapper().selectList(w);
    }
}
