package com.younike.system.service.impl;

import java.util.Date;
import java.util.List;
import java.time.LocalDateTime;

import com.younike.common.utils.DateUtils;
import com.younike.system.domain.OrderRecord;
import com.younike.system.domain.ServerUser;
import com.younike.system.domain.vo.OrderGoodsVo;
import com.younike.system.mapper.OrderRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.younike.system.mapper.OrderGoodsMapper;
import com.younike.system.domain.OrderGoods;
import com.younike.system.service.IOrderGoodsService;

/**
 * 订单商品Service业务层处理
 * 
 * @author elev
 * @date 2022-01-06
 */
@Service
public class OrderGoodsServiceImpl implements IOrderGoodsService {
    @Autowired
    private OrderGoodsMapper orderGoodsMapper;
    @Autowired
    private OrderRecordMapper orderRecordMapper;

    /**
     * 查询订单商品
     * 
     * @param orderId 订单商品主键
     * @return 订单商品
     */
    @Override
    public OrderGoods selectOrderGoodsByOrderId(Long orderId) {
        return orderGoodsMapper.selectOrderGoodsByOrderId(orderId);
    }

    /**
     * 查询订单商品列表
     * 
     * @param orderGoods 订单商品
     * @return 订单商品
     */
    @Override
    public List<OrderGoods> selectOrderGoodsList(OrderGoods orderGoods) {
        return orderGoodsMapper.selectOrderGoodsList(orderGoods);
    }

    /**
     * 新增订单商品
     * 
     * @param orderGoods 订单商品
     * @return 结果
     */
    @Override
    public int insertOrderGoods(OrderGoods orderGoods) {
        orderGoods.setCreateTime(LocalDateTime.now());
        return orderGoodsMapper.insertOrderGoods(orderGoods);
    }

    /**
     * 修改订单商品
     * 
     * @param orderGoods 订单商品
     * @return 结果
     */
    @Override
    public int updateOrderGoods(OrderGoods orderGoods) {
        orderGoods.setUpdateTime(LocalDateTime.now());
        return orderGoodsMapper.updateOrderGoods(orderGoods);
    }

    /**
     * 批量删除订单商品
     * 
     * @param orderIds 需要删除的订单商品主键
     * @return 结果
     */
    @Override
    public int deleteOrderGoodsByOrderIds(Long[] orderIds) {
        return orderGoodsMapper.deleteOrderGoodsByOrderIds(orderIds);
    }

    /**
     * 删除订单商品信息
     * 
     * @param orderId 订单商品主键
     * @return 结果
     */
    @Override
    public int deleteOrderGoodsByOrderId(Long orderId)
    {
        return orderGoodsMapper.deleteOrderGoodsByOrderId(orderId);
    }

    @Override
    public OrderGoodsVo getNowWeekDate(OrderGoodsVo orderGoodsVo) {
        Date startTime = DateUtils.getMondayOfThisWeek();
        Date endTime = DateUtils.getSundayOfThisWeek();
        orderGoodsVo.setStartTime(startTime);
        orderGoodsVo.setEndTime(endTime);
        return orderGoodsMapper.getNowWeekDate(orderGoodsVo);
    }

    @Override
    public List<OrderGoodsVo> getOrderList(OrderGoodsVo orderGoodsVo) {
        return orderGoodsMapper.getOrderList(orderGoodsVo);
    }

    @Override
    public OrderGoodsVo getOrderInfo(OrderGoodsVo orderGoodsVo) {
        List<OrderRecord> orderRecordList = orderRecordMapper.getOrderRecordList(orderGoodsVo);
        OrderGoodsVo orderInfo = orderGoodsMapper.getOrderInfo(orderGoodsVo);
        orderInfo.setOrderRecordList(orderRecordList);
        return orderInfo;
    }

    @Override
    public OrderGoodsVo getOrderNumDate(OrderGoodsVo orderGoodsVo) {
        return orderGoodsMapper.getNowWeekDate(orderGoodsVo);
    }
}
