package com.xinelu.manage.controller.nurseclassifyinfo;

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.custominterface.Insert;
import com.xinelu.common.custominterface.Update;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.nurseclassifyinfo.NurseClassifyInfo;
import com.xinelu.manage.dto.nurseclassifyinfo.NurseClassifyInfoDTO;
import com.xinelu.manage.service.nurseclassifyinfo.INurseClassifyInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 护理机构和护理项目分类信息Controller
 *
 * @author xinyilu
 * @date 2023-02-08
 */
@RestController
@RequestMapping("/classifyItem/info")
public class NurseClassifyInfoController extends BaseController {
    @Resource
    private INurseClassifyInfoService nurseClassifyInfoService;

    /**
     * 查询护理项目分类信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(NurseClassifyInfo nurseClassifyInfo) {
        startPage();
        List<NurseClassifyInfo> list = nurseClassifyInfoService.selectNurseClassifyInfoList(nurseClassifyInfo);
        return getDataTable(list);
    }

    /**
     * 导出护理项目分类信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:classifyItem:export')")
    @Log(title = "护理机构和护理项目分类信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NurseClassifyInfo nurseClassifyInfo) {
        List<NurseClassifyInfo> list = nurseClassifyInfoService.selectNurseClassifyInfoList(nurseClassifyInfo);
        ExcelUtil<NurseClassifyInfo> util = new ExcelUtil<>(NurseClassifyInfo.class);
        util.exportExcel(response, list, "护理机构和护理项目分类信息数据");
    }

    /**
     * 获取护理项目分类信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:classifyItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(nurseClassifyInfoService.selectNurseClassifyInfoById(id));
    }

    /**
     * 新增护理项目分类信息
     */
    @PreAuthorize("@ss.hasPermi('system:classifyItem:add')")
    @Log(title = "护理机构和护理项目分类信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated(Insert.class) @RequestBody NurseClassifyInfoDTO nurseClassifyInfo) {
        return nurseClassifyInfoService.insertNurseClassifyInfo(nurseClassifyInfo.getNurseClassifyInfoList());
    }

    /**
     * 修改护理项目分类信息
     */
    @PreAuthorize("@ss.hasPermi('system:classifyItem:edit')")
    @Log(title = "护理机构和护理项目分类信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@Validated(Update.class) @RequestBody NurseClassifyInfo nurseClassifyInfo) {
        return nurseClassifyInfoService.updateNurseClassifyInfo(nurseClassifyInfo);
    }

    /**
     * 删除护理项目分类信息
     */
    @PreAuthorize("@ss.hasPermi('system:classifyItem:remove')")
    @Log(title = "护理机构和护理项目分类信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return nurseClassifyInfoService.deleteNurseClassifyInfoByIds(ids);
    }
}