package com.ruoyi.web.modules.industryservice.controller;

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.web.modules.industryservice.domain.BizRuralThreeAssets;
import com.ruoyi.web.modules.industryservice.service.IBizRuralThreeAssetsService;

/**
 * 农村三资数据填报 REST。
 * <p>Base：{@code /dataModel/ruralThreeAssets}；权限 {@code dataModel:ruralThreeAssets:*}；无导入导出。</p>
 */
@RestController
@RequestMapping("/dataModel/ruralThreeAssets")
public class BizRuralThreeAssetsController extends BaseController
{
    @Autowired
    private IBizRuralThreeAssetsService service;

    @PreAuthorize("@ss.hasPermi('dataModel:ruralThreeAssets:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizRuralThreeAssets query)
    {
        startPage();
        List<BizRuralThreeAssets> list = service.selectBizRuralThreeAssetsList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('dataModel:ruralThreeAssets:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(service.selectBizRuralThreeAssetsById(id));
    }

    @PreAuthorize("@ss.hasPermi('dataModel:ruralThreeAssets:add')")
    @Log(title = "农村三资数据填报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BizRuralThreeAssets row)
    {
        row.setCreateBy(getUsername());
        return toAjax(service.insertBizRuralThreeAssets(row));
    }

    @PreAuthorize("@ss.hasPermi('dataModel:ruralThreeAssets:edit')")
    @Log(title = "农村三资数据填报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BizRuralThreeAssets row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(service.updateBizRuralThreeAssets(row));
    }

    @PreAuthorize("@ss.hasPermi('dataModel:ruralThreeAssets:remove')")
    @Log(title = "农村三资数据填报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(service.deleteBizRuralThreeAssetsByIds(ids, getUsername()));
    }

    @PreAuthorize("@ss.hasPermi('dataModel:ruralThreeAssets:list')")
    @GetMapping("/townOptions")
    public AjaxResult townOptions()
    {
        return success(service.listTownOptions());
    }

    @PreAuthorize("@ss.hasPermi('dataModel:ruralThreeAssets:list')")
    @GetMapping("/villageTree")
    public AjaxResult villageTree()
    {
        return success(service.listVillageTree());
    }
}
