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

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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.farming.domain.BizLivestockKnowledge;
import com.ruoyi.web.modules.farming.service.IBizLivestockKnowledgeService;

/**
 * 综合牧业知识库
 */
@RestController
@RequestMapping("/techService/knowledge")
public class BizLivestockKnowledgeController extends BaseController
{
    @Autowired
    private IBizLivestockKnowledgeService bizLivestockKnowledgeService;

    @PreAuthorize("@ss.hasPermi('techService:knowledge:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizLivestockKnowledge query)
    {
        startPage();
        List<BizLivestockKnowledge> list = bizLivestockKnowledgeService.selectBizLivestockKnowledgeList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('techService:knowledge:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizLivestockKnowledgeService.selectBizLivestockKnowledgeById(id));
    }

    @PreAuthorize("@ss.hasPermi('techService:knowledge:add')")
    @Log(title = "综合牧业知识库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizLivestockKnowledge row)
    {
        row.setCreateBy(getUsername());
        return toAjax(bizLivestockKnowledgeService.insertBizLivestockKnowledge(row));
    }

    @PreAuthorize("@ss.hasPermi('techService:knowledge:edit')")
    @Log(title = "综合牧业知识库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizLivestockKnowledge row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(bizLivestockKnowledgeService.updateBizLivestockKnowledge(row));
    }

    @PreAuthorize("@ss.hasPermi('techService:knowledge:remove')")
    @Log(title = "综合牧业知识库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizLivestockKnowledgeService.deleteBizLivestockKnowledgeByIds(ids, getUsername()));
    }

    @PreAuthorize("@ss.hasPermi('techService:knowledge:syncKb')")
    @Log(title = "综合牧业知识库同步", businessType = BusinessType.UPDATE)
    @PostMapping("/syncKb/{id}")
    public AjaxResult syncKb(@PathVariable Long id)
    {
        return toAjax(bizLivestockKnowledgeService.syncKb(id));
    }

    @PreAuthorize("@ss.hasPermi('techService:knowledge:removeKb')")
    @Log(title = "综合牧业知识库移出", businessType = BusinessType.UPDATE)
    @PostMapping("/removeKb/{id}")
    public AjaxResult removeKb(@PathVariable Long id)
    {
        return toAjax(bizLivestockKnowledgeService.removeKb(id));
    }
}
