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.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.yanzhu.jh.project.domain.SurProjectInsurance;
import com.yanzhu.jh.project.service.ISurProjectInsuranceService;
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;

/**
 * 项目保险Conller
 */
@RestController
@RequestMapping("/bgscreen/insurance")
public class ProjectInsuranceController extends BaseController {

    @Autowired
    private ISurProjectInsuranceService surProjectInsuranceService;
    @Autowired
    private RedisCache redisCache;
    /**
     * 根据条件查询项目保险
     * @param deptId
     * @param projectId
     * @return
     */
    @GetMapping("/getProjectInsuranceList")
    public TableDataInfo getProjectInsuranceList(String deptId,String projectId){
        SurProjectInsurance surProjectInsurance = new SurProjectInsurance();
        if(deptId!=null && !"0".equals(deptId)){
            surProjectInsurance.setNowDept(deptId);
        }
        if(projectId!=null && !"0".equals(projectId)){
            surProjectInsurance.setProjectId(Convert.toLong(projectId));
        }
        return getDataTable(surProjectInsuranceService.selectBgscreenInsuranceList(surProjectInsurance));
    }

    /**
     * 按项目获取保险信息
     * @param id
     * @return
     */
    @GetMapping("/getProjectInsurance")
    public AjaxResult getProjectInsurance(Long id){
        String key="bgscreen_insurance_getProjectInsurance_"+id;
        Object obj=redisCache.getCacheObject(key);
        if(obj!=null){
            return AjaxResult.success(obj);
        }
        List list=surProjectInsuranceService.selectProjectInsuranceListByProjectId(id);
        redisCache.setCacheObject(key, list, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.MINUTES);
        return AjaxResult.success(list);
    }

}
