package com.ningdatech.kqapi.zzsfw.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.kqapi.common.util.NdDateUtils;
import com.ningdatech.kqapi.zzsfw.model.entity.DscSxAdsShareItemQltQlsxCommonIDVKq;
import com.ningdatech.kqapi.zzsfw.mapper.DscSxAdsShareItemQltQlsxCommonIDVKqMapper;
import com.ningdatech.kqapi.zzsfw.service.IDscSxAdsShareItemQltQlsxCommonIDVKqService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 省回流_政务服务_数据共享_事项基本信息表 服务实现类
 * </p>
 *
 * @author ZPF
 * @since 2023-10-25
 */
@Service
public class DscSxAdsShareItemQltQlsxCommonIDVKqServiceImpl extends ServiceImpl<DscSxAdsShareItemQltQlsxCommonIDVKqMapper, DscSxAdsShareItemQltQlsxCommonIDVKq> implements IDscSxAdsShareItemQltQlsxCommonIDVKqService {

    @Override
    public String getNewestUpdateDate() {
        List<DscSxAdsShareItemQltQlsxCommonIDVKq> dataList = baseMapper.selectList(Wrappers.lambdaQuery(DscSxAdsShareItemQltQlsxCommonIDVKq.class)
                .select(DscSxAdsShareItemQltQlsxCommonIDVKq::getUpdateDate));
        if (CollUtil.isNotEmpty(dataList)){
            // 根据更新时间降序排序
            dataList.sort((o1, o2) -> o2.getUpdateDate().compareTo(o1.getUpdateDate()));
            LocalDateTime updateDate = dataList.get(0).getUpdateDate();
            return NdDateUtils.format(updateDate, NdDateUtils.DEFAULT_DATE_FORMAT);
        }
        return null;
    }
}
