package com.aiotagro.cattletrade.business.service.impl;

import com.aiotagro.cattletrade.business.dto.JbqLogDto;
import com.aiotagro.cattletrade.business.entity.Delivery;
import com.aiotagro.cattletrade.business.entity.JbqClientLog;
import com.aiotagro.cattletrade.business.mapper.DeliveryMapper;
import com.aiotagro.cattletrade.business.mapper.JbqClientLogMapper;
import com.aiotagro.cattletrade.business.service.IJbqClientLogService;
import com.aiotagro.common.core.web.domain.PageResultResponse;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 智能耳标日志表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-12-26
 */
@Service
public class JbqClientLogServiceImpl extends ServiceImpl<JbqClientLogMapper, JbqClientLog> implements IJbqClientLogService {

    @Autowired
    private JbqClientLogMapper jbqServerMapper;
    @Autowired
    private DeliveryMapper deliveryMapper;
    @Override
    public PageResultResponse jbqLogList(JbqLogDto dto) {
        if (dto.getDeliveryId() == null) {
            return new PageResultResponse(500, "运单id不能为空");
        }
        Delivery delivery = deliveryMapper.selectById(dto.getDeliveryId());
        if (delivery == null) {
            return new PageResultResponse(500, "运单不存在");
        }
        Integer deliveryId = dto.getDeliveryId();
        Date createTime = delivery.getCreateTime();
        Date checkTime = delivery.getCheckTime();
        if (checkTime == null) {
            checkTime = new Date();
        }
        Page<JbqClientLog> result = PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<JbqClientLog> list = jbqServerMapper.jbqLogList(deliveryId,createTime,checkTime);
        return new PageResultResponse(result.getTotal(), list);
    }
}
