package com.xinelu.manage.controller.nursestationclassify;

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.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.web.bind.annotation.*;

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

/**
 * 护理机构分类信息Controller
 *
 * @author ZHANGHENG
 * @date 2023-02-08
 */
@RestController
@RequestMapping("/system/stationClassify")
public class NurseStationClassifyController extends BaseController {
    @Resource
    private INurseClassifyInfoService nurseClassifyInfoService;

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

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

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

    /**
     * 新增护理机构分类信息
     */
    @PreAuthorize("@ss.hasPermi('system:stationClassify:add')")
    @Log(title = "护理机构分类信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody NurseClassifyInfoDTO nurseClassifyInfoList) {
        if (Objects.isNull(nurseClassifyInfoList)) {
            return AjaxResult.error("请添加护理机构分类！");
        }
        return nurseClassifyInfoService.insertNurseStationClassifyInfo(nurseClassifyInfoList.getNurseClassifyInfoList());
    }

    /**
     * 修改护理机构分类信息
     */
    @PreAuthorize("@ss.hasPermi('system:stationClassify:edit')")
    @Log(title = "护理机构分类信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody NurseClassifyInfo nurseClassifyInfo) {
        if (Objects.isNull(nurseClassifyInfo) || Objects.isNull(nurseClassifyInfo.getId())) {
            return AjaxResult.error("护理机构信息不能为空！");
        }
        return nurseClassifyInfoService.updateNurseStationClassifyInfo(nurseClassifyInfo);
    }

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