package com.sysu.admin.controller.lz.everyday;

import com.sysu.admin.support.base.BaseService;
import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service
public class LzEverydayService extends BaseService<LzEveryday, Integer> {

    @Autowired
    private LzEverydayRepository lzEverydayRepository;
    @Autowired
    private LzEverydayImgService lzEverydayImgService;

    public List<LzEveryday> findListByTreeId(Integer treeId, Date startDate , Date endDate){
        List<LzEveryday> lzEverydayList = lzEverydayRepository.findAllByTreeIdAndCreateDateBetweenOrderByIdAsc(treeId, startDate, endDate);
        lzEverydayList.forEach(lzEveryday -> {
            lzEveryday.setLzEverydayImage(lzEverydayImgService.findAllByEverydayId(lzEveryday.getId()));
        });
        return lzEverydayList;
    }

    @Override
    public JpaPlusRepository<LzEveryday, Integer> r() {
        return lzEverydayRepository;
    }
}
