package com.gci.boot.modules.gis.service.impl;

import cn.hutool.core.date.BetweenFormatter;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gci.boot.modules.gis.entity.TbGisChargeLog;
import com.gci.boot.modules.gis.mapper.TbGisChargeLogMapper;
import com.gci.boot.modules.gis.service.ITbGisChargeLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 充电记录表 服务实现类
 * </p>
 *
 * @author 2464
 * @since 2023-09-01
 */
@Service
public class TbGisChargeLogServiceImpl extends ServiceImpl<TbGisChargeLogMapper, TbGisChargeLog> implements ITbGisChargeLogService {

    @Autowired
    private TbGisChargeLogMapper gisChargeLogMapper;

    @Override
    public IPage<TbGisChargeLog> pageBuild(Page<TbGisChargeLog> page, LambdaQueryWrapper<TbGisChargeLog> lambdaQueryWrapper) {
        Page<TbGisChargeLog> chargeLogPage = gisChargeLogMapper.pageBuild(page, lambdaQueryWrapper);
        for (TbGisChargeLog record : chargeLogPage.getRecords()) {
            if (ObjectUtil.isAllNotEmpty(record.getStartTime(),record.getEndTime())) {
                String s = DateUtil.formatBetween(record.getStartTime(), record.getEndTime(), BetweenFormatter.Level.SECOND);
                record.setDuration(s);
            }
        }
        return chargeLogPage;
    }
}
