package com.fs.hospital.controller.hospital;

import java.util.List;

import com.fs.common.utils.ServletUtils;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.hospital.domain.HospitalInspectItem;
import com.fs.hospital.service.IHospitalInspectItemService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 检查Controller
 *
 * @author fs
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/hospital/hospitalInspectItem")
public class HospitalInspectItemController extends BaseController
{
    @Autowired
    private IHospitalInspectItemService hospitalInspectItemService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询检查列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInspectItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalInspectItem hospitalInspectItem)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalInspectItem.setHospitalId( loginUser.getHospital().getHospitalId());
        List<HospitalInspectItem> list = hospitalInspectItemService.selectHospitalInspectItemList(hospitalInspectItem);
        return getDataTable(list);
    }

    /**
     * 导出检查列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInspectItem:export')")
    @Log(title = "检查", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalInspectItem hospitalInspectItem)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalInspectItem.setHospitalId( loginUser.getHospital().getHospitalId());
        List<HospitalInspectItem> list = hospitalInspectItemService.selectHospitalInspectItemList(hospitalInspectItem);
        ExcelUtil<HospitalInspectItem> util = new ExcelUtil<HospitalInspectItem>(HospitalInspectItem.class);
        return util.exportExcel(list, "检查数据");
    }

    /**
     * 获取检查详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInspectItem:query')")
    @GetMapping(value = "/{inspectId}")
    public AjaxResult getInfo(@PathVariable("inspectId") Long inspectId)
    {
        return AjaxResult.success(hospitalInspectItemService.selectHospitalInspectItemByInspectId(inspectId));
    }

    /**
     * 新增检查
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInspectItem:add')")
    @Log(title = "检查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalInspectItem hospitalInspectItem)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalInspectItem.setHospitalId( loginUser.getHospital().getHospitalId());
        return toAjax(hospitalInspectItemService.insertHospitalInspectItem(hospitalInspectItem));
    }

    /**
     * 修改检查
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInspectItem:edit')")
    @Log(title = "检查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalInspectItem hospitalInspectItem)
    {
        return toAjax(hospitalInspectItemService.updateHospitalInspectItem(hospitalInspectItem));
    }

    /**
     * 删除检查
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInspectItem:remove')")
    @Log(title = "检查", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inspectIds}")
    public AjaxResult remove(@PathVariable Long[] inspectIds)
    {
        return toAjax(hospitalInspectItemService.deleteHospitalInspectItemByInspectIds(inspectIds));
    }
}
