package com.ruoyi.web.modules.architecture.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.architecture.domain.BizWithdrawalPeriodStandard;
import com.ruoyi.web.modules.architecture.service.IBizWithdrawalPeriodStandardService;

/**
 * 休药期标准管理
 */
@RestController
@RequestMapping("/withdrawalPeriod/standard")
public class BizWithdrawalPeriodStandardController extends BaseController
{
    @Autowired
    private IBizWithdrawalPeriodStandardService bizWithdrawalPeriodStandardService;

    @PreAuthorize("@ss.hasPermi('withdrawalPeriod:standard:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizWithdrawalPeriodStandard query)
    {
        startPage();
        List<BizWithdrawalPeriodStandard> list = bizWithdrawalPeriodStandardService.selectBizWithdrawalPeriodStandardList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('withdrawalPeriod:standard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizWithdrawalPeriodStandardService.selectBizWithdrawalPeriodStandardById(id));
    }

    @PreAuthorize("@ss.hasPermi('withdrawalPeriod:standard:add')")
    @Log(title = "休药期标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BizWithdrawalPeriodStandard row)
    {
        row.setCreateBy(getUsername());
        return toAjax(bizWithdrawalPeriodStandardService.insertBizWithdrawalPeriodStandard(row));
    }

    @PreAuthorize("@ss.hasPermi('withdrawalPeriod:standard:edit')")
    @Log(title = "休药期标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BizWithdrawalPeriodStandard row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(bizWithdrawalPeriodStandardService.updateBizWithdrawalPeriodStandard(row));
    }

    @PreAuthorize("@ss.hasPermi('withdrawalPeriod:standard:remove')")
    @Log(title = "休药期标准", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizWithdrawalPeriodStandardService.deleteBizWithdrawalPeriodStandardByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('withdrawalPeriod:standard:syncKb')")
    @Log(title = "休药期标准同步知识库", businessType = BusinessType.UPDATE)
    @PostMapping("/syncKb/{id}")
    public AjaxResult syncKb(@PathVariable Long id)
    {
        return toAjax(bizWithdrawalPeriodStandardService.syncKb(id));
    }

    @PreAuthorize("@ss.hasPermi('withdrawalPeriod:standard:removeKb')")
    @Log(title = "休药期标准移出知识库", businessType = BusinessType.UPDATE)
    @PostMapping("/removeKb/{id}")
    public AjaxResult removeKb(@PathVariable Long id)
    {
        return toAjax(bizWithdrawalPeriodStandardService.removeKb(id));
    }
}
