package com.xinelu.manage.controller.basenursinginfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.basenursinginfo.BaseNursingInfo;
import com.xinelu.manage.service.basenursinginfo.IBaseNursingInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 护理知识库Controller
 *
 * @author xinelu
 * @date 2024-05-17
 */
@RestController
@RequestMapping("/system/baseNursing")
public class BaseNursingInfoController extends BaseController {
    @Resource
    private IBaseNursingInfoService baseNursingInfoService;

    /**
     * 查询护理知识库列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseNursing:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseNursingInfo baseNursingInfo) {
        startPage();
        List<BaseNursingInfo> list = baseNursingInfoService.selectBaseNursingInfoList(baseNursingInfo);
        return getDataTable(list);
    }

    /**
     * 导出护理知识库列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseNursing:export')")
    @Log(title = "护理知识库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseNursingInfo baseNursingInfo) {
        List<BaseNursingInfo> list = baseNursingInfoService.selectBaseNursingInfoList(baseNursingInfo);
        ExcelUtil<BaseNursingInfo> util = new ExcelUtil<>(BaseNursingInfo.class);
        util.exportExcel(response, list, "护理知识库数据");
    }

    /**
     * 获取护理知识库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:baseNursing:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(baseNursingInfoService.selectBaseNursingInfoById(id));
    }

    /**
     * 新增护理知识库
     */
    @PreAuthorize("@ss.hasPermi('system:baseNursing:add')")
    @Log(title = "护理知识库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BaseNursingInfo baseNursingInfo) {
        return toAjax(baseNursingInfoService.insertBaseNursingInfo(baseNursingInfo));
    }

    /**
     * 修改护理知识库
     */
    @PreAuthorize("@ss.hasPermi('system:baseNursing:edit')")
    @Log(title = "护理知识库", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody BaseNursingInfo baseNursingInfo) {
        return toAjax(baseNursingInfoService.updateBaseNursingInfo(baseNursingInfo));
    }

    /**
     * 删除护理知识库
     */
    @PreAuthorize("@ss.hasPermi('system:baseNursing:remove')")
    @Log(title = "护理知识库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseNursingInfoService.deleteBaseNursingInfoByIds(ids));
    }
}
