package com.fs.company.controller.store;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.framework.security.LoginUser;
import com.fs.his.param.FsDrugReportParam;
import com.fs.his.service.IFsDrugReportService;
import com.fs.his.vo.FsDrugReportListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用药报告Controller
 *
 * @author fs
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/store/drugReport")
public class FsDrugReportController extends BaseController
{
    @Autowired
    private IFsDrugReportService fsDrugReportService;

    /**
     * 查询用药报告列表
     */
    @PreAuthorize("@ss.hasPermi('store:drugReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsDrugReportParam fsDrugReport)
    {
        startPage();
        LoginUser loginUser = com.fs.framework.security.SecurityUtils.getLoginUser();
        fsDrugReport.setCompanyId(loginUser.getUser().getCompanyId());
        List<FsDrugReportListVO> list = fsDrugReportService.selectFsDrugReportListVO(fsDrugReport);
        return getDataTable(list);
    }

    /**
     * 导出用药报告列表
     */
    @PreAuthorize("@ss.hasPermi('store:drugReport:export')")
    @Log(title = "用药报告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsDrugReportParam fsDrugReport)
    {
        LoginUser loginUser = com.fs.framework.security.SecurityUtils.getLoginUser();
        fsDrugReport.setCompanyId(loginUser.getUser().getCompanyId());
        List<FsDrugReportListVO> list = fsDrugReportService.selectFsDrugReportListVO(fsDrugReport);
        ExcelUtil<FsDrugReportListVO> util = new ExcelUtil<FsDrugReportListVO>(FsDrugReportListVO.class);
        return util.exportExcel(list, "用药报告数据");
    }

    /**
     * 获取用药报告详细信息
     */
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        return AjaxResult.success(fsDrugReportService.selectFsDrugReportByReportIdVO(reportId));
    }

}
