package com.fs.hospital.controller.hospital;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.common.utils.ServletUtils;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.hospital.param.HospitalInspectOrderParam;
import com.fs.hospital.vo.HospitalInspectOrderVO;
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.HospitalInspectOrder;
import com.fs.hospital.service.IHospitalInspectOrderService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 检查单Controller
 *
 * @author fs
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/hospital/hospitalInspectOrder")
public class HospitalInspectOrderController extends BaseController
{
    @Autowired
    private IHospitalInspectOrderService hospitalInspectOrderService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询检查单列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInspectOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalInspectOrderParam param)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.setHospitalId( loginUser.getHospital().getHospitalId());
        List<HospitalInspectOrderVO> list = hospitalInspectOrderService.selectHospitalInspectOrderListVO(param);
        return getDataTable(list);
    }

    /**
     * 导出检查单列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInspectOrder:export')")
    @Log(title = "检查单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalInspectOrderParam param)
    {
        List<HospitalInspectOrderVO> list = hospitalInspectOrderService.selectHospitalInspectOrderListVO(param);
        ExcelUtil<HospitalInspectOrderVO> util = new ExcelUtil<HospitalInspectOrderVO>(HospitalInspectOrderVO.class);
        return util.exportExcel(list, "检查单数据");
    }

    /**
     * 获取检查单详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInspectOrder:query')")
    @GetMapping(value = "/{orderId}")
    public R getInfo(@PathVariable("orderId") Long orderId)
    {
        return hospitalInspectOrderService.selectHospitalInspectOrderVOByOrderId(orderId);
    }


    /**
     * 修改检查单
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInspectOrder:edit')")
    @Log(title = "检查单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalInspectOrder hospitalInspectOrder)
    {
        return toAjax(hospitalInspectOrderService.updateHospitalInspectOrder(hospitalInspectOrder));
    }



}
