package com.xinelu.manage.controller.departmentdiseasetype;

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.departmentdiseasetype.DepartmentDiseaseType;
import com.xinelu.manage.dto.department.DepartmentDTO;
import com.xinelu.manage.dto.departmentdiseasetype.DepartmentDiseaseTypeDto;
import com.xinelu.manage.service.departmentdiseasetype.IDepartmentDiseaseTypeService;
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-02-26
 */
@RestController
@RequestMapping("/system/departmentDisease")
public class DepartmentDiseaseTypeController extends BaseController {
    @Resource
    private IDepartmentDiseaseTypeService departmentDiseaseTypeService;

    /**
     * 查询科室病种信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:departmentDisease:list')")
    @GetMapping("/list")
    public TableDataInfo list(DepartmentDiseaseTypeDto departmentDiseaseType) {
        startPage();
        List<DepartmentDiseaseType> list = departmentDiseaseTypeService.selectDepartmentDiseaseTypeList(departmentDiseaseType);
        return getDataTable(list);
    }

    /**
     * 查询科室病种信息列表 不分页 问卷使用
     */
    @GetMapping("/diseaseList")
    public AjaxResult diseaseList(DepartmentDiseaseTypeDto departmentDiseaseType) {
        return AjaxResult.success(departmentDiseaseTypeService.selectDepartmentDiseaseTypeList(departmentDiseaseType));
    }

    /**
     * 导出科室病种信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:departmentDisease:export')")
    @Log(title = "科室病种信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DepartmentDiseaseTypeDto departmentDiseaseType) {
        List<DepartmentDiseaseType> list = departmentDiseaseTypeService.selectDepartmentDiseaseTypeList(departmentDiseaseType);
        ExcelUtil<DepartmentDiseaseType> util = new ExcelUtil<DepartmentDiseaseType>(DepartmentDiseaseType.class);
        util.exportExcel(response, list, "科室病种信息数据");
    }

    /**
     * 获取科室病种信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:departmentDisease:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(departmentDiseaseTypeService.selectDepartmentDiseaseTypeById(id));
    }

    /**
     * 新增科室病种信息
     */
    @PreAuthorize("@ss.hasPermi('system:departmentDisease:add')")
    @Log(title = "科室病种信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DepartmentDiseaseType departmentDiseaseType) {
        return toAjax(departmentDiseaseTypeService.insertDepartmentDiseaseType(departmentDiseaseType));
    }

    /**
     * 修改科室病种信息
     */
    @PreAuthorize("@ss.hasPermi('system:departmentDisease:edit')")
    @Log(title = "科室病种信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody DepartmentDiseaseType departmentDiseaseType) {
        return toAjax(departmentDiseaseTypeService.updateDepartmentDiseaseType(departmentDiseaseType));
    }

    /**
     * 删除科室病种信息
     */
    @PreAuthorize("@ss.hasPermi('system:departmentDisease:remove')")
    @Log(title = "科室病种信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(departmentDiseaseTypeService.deleteDepartmentDiseaseTypeByIds(ids));
    }

    /**
     * 科室病种数量
     */
    @GetMapping("/selectDiseaseCount")
    public AjaxResult selectDiseaseTypeCount(DepartmentDTO departmentDto) {
        return departmentDiseaseTypeService.selectDiseaseTypeCount(departmentDto);
    }
}