package com.ruoyi.web.controller.care;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.care.domain.CareProtocol;
import com.ruoyi.care.service.ICareProtocolService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 协议Controller
 * 
 * @author qy
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/care/protocol")
public class CareProtocolController extends BaseController
{
    @Autowired
    private ICareProtocolService careProtocolService;

    /**
     * 查询协议列表
     */
    @PreAuthorize("@ss.hasPermi('care:protocol:list')")
    @GetMapping("/list")
    public TableDataInfo list(CareProtocol careProtocol)
    {
        startPage();
        List<CareProtocol> list = careProtocolService.selectCareProtocolList(careProtocol);
        return getDataTable(list);
    }

    /**
     * 导出协议列表
     */
    @PreAuthorize("@ss.hasPermi('care:protocol:export')")
    @Log(title = "协议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CareProtocol careProtocol)
    {
        List<CareProtocol> list = careProtocolService.selectCareProtocolList(careProtocol);
        ExcelUtil<CareProtocol> util = new ExcelUtil<CareProtocol>(CareProtocol.class);
        util.exportExcel(response, list, "协议数据");
    }

    /**
     * 获取协议详细信息
     */
    @PreAuthorize("@ss.hasPermi('care:protocol:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(careProtocolService.selectCareProtocolById(id));
    }

    /**
     * 新增协议
     */
    @PreAuthorize("@ss.hasPermi('care:protocol:add')")
    @Log(title = "协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CareProtocol careProtocol)
    {
        return toAjax(careProtocolService.insertCareProtocol(careProtocol));
    }

    /**
     * 修改协议
     */
    @PreAuthorize("@ss.hasPermi('care:protocol:edit')")
    @Log(title = "协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CareProtocol careProtocol)
    {
        return toAjax(careProtocolService.updateCareProtocol(careProtocol));
    }

    /**
     * 删除协议
     */
    @PreAuthorize("@ss.hasPermi('care:protocol:remove')")
    @Log(title = "协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(careProtocolService.deleteCareProtocolByIds(ids));
    }
}
