package com.cirle.scientific.service.impl;/*
 *24901
 *2022/11/10
 *14:07
 */

import cn.hutool.core.bean.BeanUtil;
import com.cirle.scientific.dao.QkjConferenceDao;
import com.cirle.scientific.dao.QkjPhotoWallDao;
import com.cirle.scientific.dto.QkjPhotoWallResDto;
import com.cirle.scientific.po.QkjConference;
import com.cirle.scientific.po.QkjPhotoWall;
import com.cirle.scientific.service.QkjPhotoWallService;
import com.cirle.scientific.utils.OSSPathUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Service
public class QkjPhotoWallServiceImpl implements QkjPhotoWallService {

    private QkjPhotoWallDao qkjPhotoWallDao;

    private QkjConferenceDao qkjConferenceDao;

    @Autowired
    public void setQkjConferenceDao(QkjConferenceDao qkjConferenceDao) {
        this.qkjConferenceDao = qkjConferenceDao;
    }

    @Autowired
    public void setQkjPhotoWallDao(QkjPhotoWallDao qkjPhotoWallDao) {
        this.qkjPhotoWallDao = qkjPhotoWallDao;
    }



    @Override
    public Map<String , Object> findAll(Integer page, Integer size, Integer id, Integer type) {
        Map<String, Object> results = new HashMap<>();
        List<QkjPhotoWall> qkjPhotoWallList = qkjPhotoWallDao.findAllByTypeAndObjId(type, id, (page - 1) * size, size);
        List<QkjPhotoWallResDto> qkjPhotoWallResDtoList = new LinkedList<>();
        for (QkjPhotoWall qkjPhotoWall : qkjPhotoWallList) {
            QkjPhotoWallResDto qkjPhotoWallResDto = BeanUtil.copyProperties(qkjPhotoWall, QkjPhotoWallResDto.class);
            qkjPhotoWallResDtoList.add(qkjPhotoWallResDto);
        }
        //查询课件的封面图以及标题
        QkjConference allById = qkjConferenceDao.findConferAllById(id);
        if (allById != null) {
            results.put("ConferenceCoverImg", OSSPathUtil.jointFileUrl(allById.getCoverImg()));
            results.put("ConferenceTitle",allById.getTitle());
        }
        results.put("results", qkjPhotoWallResDtoList);
        results.put("total", qkjPhotoWallDao.findAllByTypeAndObjId(type,id));
        return results;
    }
}
