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.common.util.FormatUtil;
import com.gci.boot.modules.gis.entity.TbGisFenceAlarm;
import com.gci.boot.modules.gis.mapper.TbGisFenceAlarmMapper;
import com.gci.boot.modules.gis.service.ITbGisFenceAlarmService;
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 TbGisFenceAlarmServiceImpl extends ServiceImpl<TbGisFenceAlarmMapper, TbGisFenceAlarm> implements ITbGisFenceAlarmService {

    @Autowired
    private TbGisFenceAlarmMapper gisFenceAlarmMapper;

    @Override
    public IPage<TbGisFenceAlarm> pageBuild(Page<TbGisFenceAlarm> page, LambdaQueryWrapper<TbGisFenceAlarm> lambdaQueryWrapper) {
        Page<TbGisFenceAlarm> list = gisFenceAlarmMapper.pageBuild(page, lambdaQueryWrapper);
        for (TbGisFenceAlarm record : list.getRecords()) {
            String duration = FormatUtil.formattedTimeDifference(record.getStartTime(), record.getEndTime());
            record.setDuration(duration);
        }
        return list;
    }
}
