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.HospitalExamOrderParam;
import com.fs.hospital.vo.HospitalExamOrderVO;
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.HospitalExamOrder;
import com.fs.hospital.service.IHospitalExamOrderService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 检验单Controller
 *
 * @author fs
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/hospital/hospitalExamOrder")
public class HospitalExamOrderController extends BaseController
{
    @Autowired
    private IHospitalExamOrderService hospitalExamOrderService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询检验单列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalExamOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalExamOrderParam param)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.setHospitalId( loginUser.getHospital().getHospitalId());
        List<HospitalExamOrderVO> list = hospitalExamOrderService.selectHospitalExamOrderListVO(param);
        return getDataTable(list);
    }

    /**
     * 导出检验单列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalExamOrder:export')")
    @Log(title = "检验单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalExamOrderParam param)
    {
        List<HospitalExamOrderVO> list = hospitalExamOrderService.selectHospitalExamOrderListVO(param);
        ExcelUtil<HospitalExamOrderVO> util = new ExcelUtil<HospitalExamOrderVO>(HospitalExamOrderVO.class);
        return util.exportExcel(list, "检验单数据");
    }

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


    /**
     * 修改检验单
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalExamOrder:edit')")
    @Log(title = "检验单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalExamOrder hospitalExamOrder)
    {
        return toAjax(hospitalExamOrderService.updateHospitalExamOrder(hospitalExamOrder));
    }


}
