package com.ruoyi.web.controller.dxp.system.share;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dxp.domain.ServiceCache;
import com.ruoyi.dxp.service.IServiceCacheService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务缓存Controller
 * 
 * @author jy
 * @date 2023-01-04
 */
@RestController
@RequestMapping("/system/share/serviceCache")
public class ServiceCacheController extends BaseController
{
    @Autowired
    private IServiceCacheService serviceCacheService;

    /**
     * 查询服务缓存列表
     */
    @PreAuthorize("@ss.hasPermi('system/share:serviceCache:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceCache serviceCache)
    {
        startPage();
        List<ServiceCache> list = serviceCacheService.selectServiceCacheList(serviceCache);
        return getDataTable(list);
    }

    /**
     * 导出服务缓存列表
     */
    @PreAuthorize("@ss.hasPermi('system/share:serviceCache:export')")
    @Log(title = "服务缓存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceCache serviceCache)
    {
        List<ServiceCache> list = serviceCacheService.selectServiceCacheList(serviceCache);
        ExcelUtil<ServiceCache> util = new ExcelUtil<ServiceCache>(ServiceCache.class);
        util.exportExcel(response, list, "服务缓存数据");
    }

    /**
     * 获取服务缓存详细信息
     */
    @PreAuthorize("@ss.hasPermi('system/share:serviceCache:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceCacheService.selectServiceCacheById(id));
    }

    /**
     * 新增服务缓存
     */
    @PreAuthorize("@ss.hasPermi('system/share:serviceCache:add')")
    @Log(title = "服务缓存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceCache serviceCache)
    {
        return serviceCacheService.save(serviceCache);
    }

    /**
     * 修改服务缓存
     */
    @PreAuthorize("@ss.hasPermi('system/share:serviceCache:edit')")
    @Log(title = "服务缓存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceCache serviceCache)
    {
        return serviceCacheService.save(serviceCache);
    }

    /**
     * 删除服务缓存
     */
    @PreAuthorize("@ss.hasPermi('system/share:serviceCache:remove')")
    @Log(title = "服务缓存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long ids)
    {
        return toAjax(serviceCacheService.deleteServiceCacheById(ids));
    }
}
