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

import java.math.BigDecimal;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.enums.order.OrderPriceEnums;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.code.PublicCommon;
import com.ruoyi.frequency.orderpricerecord.mapper.OrderPriceRecordMapper;
import com.ruoyi.frequency.orderpricerecord.entity.OrderPriceRecord;
import com.ruoyi.frequency.orderpricerecord.service.OrderPriceRecordService;

/**
 * 订单价格明细记录Service业务层处理
 *
 * @author liwenlong
 * @date 2024-01-24
 */
@Service
public class OrderPriceRecordServiceImpl extends ServiceImpl<OrderPriceRecordMapper, OrderPriceRecord>  implements OrderPriceRecordService {
    @Autowired
    private OrderPriceRecordMapper orderPriceRecordMapper;

    /**
     * 查询订单价格明细记录
     *
     * @param id 订单价格明细记录主键
     * @return 订单价格明细记录
     */
    @Override
    public OrderPriceRecord selectOrderPriceRecordById(Long id) {
        return orderPriceRecordMapper.selectOrderPriceRecordById(id);
    }

    /**
     * 查询订单价格明细记录列表
     *
     * @param orderPriceRecord 订单价格明细记录
     * @return 订单价格明细记录
     */
    @Override
    public List<OrderPriceRecord> selectOrderPriceRecordList(OrderPriceRecord orderPriceRecord) {
        return orderPriceRecordMapper.selectOrderPriceRecordList(orderPriceRecord);
    }

    /**
     * 新增订单价格明细记录
     *
     * @param orderPriceRecord 订单价格明细记录
     * @return 结果
     */
    @Override
    public int insertOrderPriceRecord(OrderPriceRecord orderPriceRecord) {
        orderPriceRecord.setCreateData();
        return orderPriceRecordMapper.insert(orderPriceRecord);
    }

    /**
     * 修改订单价格明细记录
     *
     * @param orderPriceRecord 订单价格明细记录
     * @return 结果
     */
    @Override
    public int updateOrderPriceRecord(OrderPriceRecord orderPriceRecord) {
        orderPriceRecord.setUpdateData();
        return orderPriceRecordMapper.updateOrderPriceRecord(orderPriceRecord);
    }

    /**
     * 批量删除订单价格明细记录
     *
     * @param ids 需要删除的订单价格明细记录主键
     * @return 结果
     */
    @Override
    public int deleteOrderPriceRecordByIds(Long[] ids, Integer delFlag) {
        this.lambdaUpdate().set(OrderPriceRecord::getDelFlag, delFlag).in(OrderPriceRecord::getId, ids).update();
        return ids.length;
    }

    @Override
    public void addOrderPriceRecord(OrderPriceEnums orderPriceEnums, Long id, BigDecimal amount) {
        OrderPriceRecord orderPriceRecord = new OrderPriceRecord();
        orderPriceRecord.setOrderId(id);
        orderPriceRecord.setType(orderPriceEnums.getCode());
        orderPriceRecord.setPrice(amount);
        orderPriceRecord.setCreateData();
        orderPriceRecord.setName(orderPriceEnums.getName());
        orderPriceRecordMapper.insert(orderPriceRecord);
    }


}
