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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.code.PublicCommon;
import com.ruoyi.common.page.PageResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.controller.req.OrderChangeRecordPageReq;
import com.ruoyi.frequency.orderextensionrecord.entity.OrderExtensionRecord;
import com.ruoyi.frequency.orderextensionrecord.mapper.OrderExtensionRecordMapper;
import com.ruoyi.frequency.orderextensionrecord.service.OrderExtensionRecordService;
import com.ruoyi.response.ResponseData;
import com.ruoyi.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单延期记录Service业务层处理
 *
 * @author liwenlong
 * @date 2023-11-03
 */
@Service
public class OrderExtensionRecordServiceImpl extends ServiceImpl<OrderExtensionRecordMapper, OrderExtensionRecord>  implements OrderExtensionRecordService
{
    @Autowired
    private OrderExtensionRecordMapper orderExtensionRecordMapper;

    /**
     * 查询订单延期记录
     *
     * @param id 订单延期记录主键
     * @return 订单延期记录
     */
    @Override
    public OrderExtensionRecord selectOrderExtensionRecordById(Long id)
    {
        return orderExtensionRecordMapper.selectOrderExtensionRecordById(id);
    }

    /**
     * 查询订单延期记录列表
     *
     * @param orderExtensionRecord 订单延期记录
     * @return 订单延期记录
     */
    @Override
    public List<OrderExtensionRecord> selectOrderExtensionRecordList(OrderExtensionRecord orderExtensionRecord)
    {
        return orderExtensionRecordMapper.selectOrderExtensionRecordList(orderExtensionRecord);
    }

    /**
     * 新增订单延期记录
     *
     * @param orderExtensionRecord 订单延期记录
     * @return 结果
     */
    @Override
    public int insertOrderExtensionRecord(OrderExtensionRecord orderExtensionRecord)
    {
        orderExtensionRecord.setCreateTime(DateUtils.getNowDate());
        return orderExtensionRecordMapper.insert(orderExtensionRecord);
    }

    /**
     * 修改订单延期记录
     *
     * @param orderExtensionRecord 订单延期记录
     * @return 结果
     */
    @Override
    public int updateOrderExtensionRecord(OrderExtensionRecord orderExtensionRecord)
    {
        orderExtensionRecord.setUpdateTime(DateUtils.getNowDate());
        return orderExtensionRecordMapper.updateById(orderExtensionRecord);
    }

    /**
     * 批量删除订单延期记录
     *
     * @param ids 需要删除的订单延期记录主键
     * @return 结果
     */
    @Override
    public int deleteOrderExtensionRecordByIds(Long[] ids,Integer delFalg)
    {
        this.lambdaUpdate().set(OrderExtensionRecord::getDelFlag,delFalg).in(OrderExtensionRecord::getId,ids).update();
        return ids.length;
    }

    @Override
    public ResponseData<PageResult<Page<OrderExtensionRecord>>> orderExtensionRecordPage(OrderChangeRecordPageReq req, UserVo userVo) {
        Page<OrderExtensionRecord> page = this.lambdaQuery().eq(OrderExtensionRecord::getDelFlag,PublicCommon.启用)
                .eq(OrderExtensionRecord::getOrderId,req.getOrderId())
                .orderByDesc(OrderExtensionRecord::getCreateTime).page(new Page<>(req.getPageNo(), req.getPageSize()));
        return ResponseData.success(new PageResult<>(page));
    }
}
