package com.ruoyi.frequency.mallordergoods.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.frequency.mallordergoods.entity.MallOrderGoods;
import com.ruoyi.frequency.mallordergoods.mapper.MallOrderGoodsMapper;
import com.ruoyi.frequency.mallordergoods.service.MallOrderGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单商品Service业务层处理
 *
 * @author liwenlong
 * @date 2024-01-25
 */
@Service
public class MallOrderGoodsServiceImpl extends ServiceImpl<MallOrderGoodsMapper, MallOrderGoods>  implements MallOrderGoodsService
{
    @Autowired
    private MallOrderGoodsMapper mallOrderGoodsMapper;

    /**
     * 查询订单商品
     *
     * @param id 订单商品主键
     * @return 订单商品
     */
    @Override
    public MallOrderGoods selectMallOrderGoodsById(Long id)
    {
        return mallOrderGoodsMapper.selectMallOrderGoodsById(id);
    }

    /**
     * 查询订单商品列表
     *
     * @param mallOrderGoods 订单商品
     * @return 订单商品
     */
    @Override
    public List<MallOrderGoods> selectMallOrderGoodsList(MallOrderGoods mallOrderGoods)
    {
        return mallOrderGoodsMapper.selectMallOrderGoodsList(mallOrderGoods);
    }

    /**
     * 新增订单商品
     *
     * @param mallOrderGoods 订单商品
     * @return 结果
     */
    @Override
    public int insertMallOrderGoods(MallOrderGoods mallOrderGoods)
    {
        mallOrderGoods.setCreateData();
        return mallOrderGoodsMapper.insert(mallOrderGoods);
    }

    /**
     * 修改订单商品
     *
     * @param mallOrderGoods 订单商品
     * @return 结果
     */
    @Override
    public int updateMallOrderGoods(MallOrderGoods mallOrderGoods)
    {
        mallOrderGoods.setUpdateData();
        return mallOrderGoodsMapper.updateMallOrderGoods(mallOrderGoods);
    }

    /**
     * 批量删除订单商品
     *
     * @param ids 需要删除的订单商品主键
     * @return 结果
     */
    @Override
    public int deleteMallOrderGoodsByIds(Long[] ids,Integer delFlag)
    {
        this.lambdaUpdate().set(MallOrderGoods::getDelFlag,delFlag).in(MallOrderGoods::getId,ids).update();
        return ids.length;
    }

    @Override
    public List<MallOrderGoods> orderGoodsList(List<Long> orderIdList) {
        if (orderIdList.size() == 0){
            return new ArrayList<>();
        }
        List<MallOrderGoods> orderGoodsList =  this.baseMapper.orderGoodsList(orderIdList);

        return orderGoodsList;
    }
}
