package com.ruoyi.web.controller.homepage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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.system.domain.Overview;
import com.ruoyi.system.service.IOverviewService;

@RestController
@RequestMapping("/homepage/overview")
public class OverviewController extends BaseController
{
    @Autowired
    private IOverviewService overviewService;

    @PreAuthorize("@ss.hasPermi('homepage:overview:query')")
    @GetMapping
    public AjaxResult getInfo()
    {
        Overview overview = overviewService.selectOverviewOne();
        return success(overview);
    }

    @PreAuthorize("@ss.hasPermi('homepage:overview:query')")
    @GetMapping(value = "/{overviewId}")
    public AjaxResult getInfoById(@PathVariable Long overviewId)
    {
        return success(overviewService.selectOverviewById(overviewId));
    }

    @PreAuthorize("@ss.hasPermi('homepage:overview:edit')")
    @Log(title = "概况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Overview overview)
    {
        overview.setCreateBy(getUsername());
        return toAjax(overviewService.insertOverview(overview));
    }

    @PreAuthorize("@ss.hasPermi('homepage:overview:edit')")
    @Log(title = "概况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Overview overview)
    {
        overview.setUpdateBy(getUsername());
        return toAjax(overviewService.updateOverview(overview));
    }

    @PreAuthorize("@ss.hasPermi('homepage:overview:remove')")
    @Log(title = "概况", businessType = BusinessType.DELETE)
    @DeleteMapping("/{overviewId}")
    public AjaxResult remove(@PathVariable Long overviewId)
    {
        return toAjax(overviewService.deleteOverviewById(overviewId));
    }
}
