package com.yanzhu.jh.bigscreen.web.controller;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.yanzhu.jh.video.domain.SurProjectPhotography;
import com.yanzhu.jh.video.service.ISurProjectPhotographyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/bgscreen/photography")
public class ProjectPhotographyController extends BaseController {

    @Autowired
    ISurProjectPhotographyService photographyService;
    @Autowired
    private RedisCache redisCache;

    @GetMapping("/listPhotography")
    public AjaxResult listPhotography(long projectId){
        SurProjectPhotography where =new SurProjectPhotography();
        where.setProjectId(projectId);
        String key="bgscreen_photography_listPhotography_"+where.getProjectId();
        Object obj=redisCache.getCacheObject(key);
        if(obj!=null){
            return AjaxResult.success(obj);
        }
        List<SurProjectPhotography> list=photographyService.selectSurProjectPhotographyList(where);
        redisCache.setCacheObject(key, list, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.MINUTES);
        return AjaxResult.success(list);
    }

    @GetMapping("/selectLastPhotography")
    public AjaxResult getLast(long projectId){
        SurProjectPhotography where =new SurProjectPhotography();
        where.setProjectId(projectId);
        where.setIsDel(0l);
        String key="bgscreen_selectLastPhotography_listPhotography_"+where.getProjectId();
        Object obj=redisCache.getCacheObject(key);
        if(obj!=null){
            return AjaxResult.success(obj);
        }
        List<SurProjectPhotography> list=photographyService.selectLastPhotography(where);
        redisCache.setCacheObject(key, list, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.MINUTES);
        return AjaxResult.success(list);
    }
}
