package com.cf.imes.module.executor.service.orderbody;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cf.imes.framework.common.enums.DeletedCodeEnum;
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
import com.cf.imes.module.executor.controller.admin.order.vo.product.OrderBodyRespVO;
import com.cf.imes.module.executor.dal.dataobject.orderBody.OrderBodyDO;
import com.cf.imes.module.executor.dal.mysql.orderBody.OrderBodyMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单柜体接口实现类 Service Impl
 *
 * @author Gqr
 * @since 2026/4/7 15:28
 */
@Service
public class OrderBodyServiceImpl implements OrderBodyService {
    @Resource
    private OrderBodyMapper orderBodyMapper;

    @Override
    public List<OrderBodyRespVO> getOrderBodyList(Long orderId, Long... organIds) {
        Long userOrganId = SecurityFrameworkUtils.getUserOrganId();
        if (ObjectUtil.isNull(userOrganId) && ArrayUtil.isNotEmpty(organIds)) {
            userOrganId = organIds[0];
        }
        List<OrderBodyDO> orderBodyDOS = orderBodyMapper.selectList(new LambdaQueryWrapper<OrderBodyDO>()
                .eq(OrderBodyDO::getOrderId, orderId)
                .eq(OrderBodyDO::getDeleted, DeletedCodeEnum.NOT_DELETED.getStatus())
                .eq(OrderBodyDO::getOrganId, userOrganId)
        );
        return BeanUtil.copyToList(orderBodyDOS, OrderBodyRespVO.class);
    }
}
