package com.cpop.jambox.business.service.impl;

import com.cpop.jambox.business.vo.NavigationVo;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cpop.jambox.business.entity.website.Navigation;
import com.cpop.jambox.business.mapper.NavigationMapper;
import com.cpop.jambox.business.service.NavigationService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 果酱模块化官网 导航栏表 服务层实现。
 *
 * @author Yxz
 * @since 2024-01-19
 */
@Service("navigationService")
public class NavigationServiceImpl extends ServiceImpl<NavigationMapper, Navigation> implements NavigationService {

    /**
     * 查询所有果酱模块化官网 导航栏表
     *
     * @author: Yxz
     * @date: 2024/1/22 18:53
     * @param: []
     * @return: java.util.List<com.cpop.jambox.business.vo.NavigationVo>
     **/
    @Override
    public List<NavigationVo> getList() {
        List<NavigationVo> navigationVoList = this.list().stream().map(entity -> {
            NavigationVo vo = new NavigationVo();
            BeanUtils.copyProperties(entity,vo,"updateTime");

            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            // 格式化为字符串
            String updateTime = entity.getUpdateTime().format(formatter);
            vo.setUpdateTime(updateTime);

            return vo;
        }).collect(Collectors.toList());
        return navigationVoList;
    }
}
