package com.ruoyi.web.controller.homepage;

import java.util.List;
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.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Value;
import com.ruoyi.system.service.IValueService;

@RestController
@RequestMapping("/homepage/value")
public class ValueController extends BaseController
{
    @Autowired
    private IValueService valueService;

    @PreAuthorize("@ss.hasPermi('homepage:value:list')")
    @GetMapping("/list")
    public TableDataInfo list(Value value)
    {
        startPage();
        List<Value> list = valueService.selectValueList(value);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('homepage:value:query')")
    @GetMapping(value = "/{valueId}")
    public AjaxResult getInfo(@PathVariable Long valueId)
    {
        return success(valueService.selectValueById(valueId));
    }

    @PreAuthorize("@ss.hasPermi('homepage:value:add')")
    @Log(title = "价值与作用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Value value)
    {
        value.setCreateBy(getUsername());
        return toAjax(valueService.insertValue(value));
    }

    @PreAuthorize("@ss.hasPermi('homepage:value:edit')")
    @Log(title = "价值与作用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Value value)
    {
        value.setUpdateBy(getUsername());
        return toAjax(valueService.updateValue(value));
    }

    @PreAuthorize("@ss.hasPermi('homepage:value:remove')")
    @Log(title = "价值与作用", businessType = BusinessType.DELETE)
    @DeleteMapping("/{valueIds}")
    public AjaxResult remove(@PathVariable Long[] valueIds)
    {
        return toAjax(valueService.deleteValueByIds(valueIds));
    }
}
