/*
 * Copyright ©2023 CJB-CNIT Team. All rights reserved
 */
package com.openhis.web.reportmanage.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.core.common.core.domain.R;
import com.openhis.web.reportmanage.appservice.IMedicationDeviceReportAppService;

import lombok.extern.slf4j.Slf4j;

/**
 * 药品耗材统计查询用 controller
 *
 * @author liuhr
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/report-manage/medication-device")
@Slf4j
public class MedicationDeviceReportController {

    @Autowired
    private IMedicationDeviceReportAppService medicationDeviceReportAppService;

    /**
     * 药品耗材日结/周结/月结算（统计筛选时间区内）
     *
     * @param dispenseDateSTime 开始时间
     * @param dispenseDateSTime 结束时间
     * @return 药品耗材日结/周结/月结算单
     */
    @GetMapping(value = "/med-dev-all")
    public R<?> selectMedDevReport(@RequestParam String dispenseDateSTime, @RequestParam String dispenseDateETime) {

        return R.ok(medicationDeviceReportAppService.selectMedDevReport(dispenseDateSTime, dispenseDateETime));
    }

    /**
     * 药品耗材日结/周结/月结算 明细清单
     *
     * @param orgId 科室
     * @param name 项目名称
     * @param dispenseDateSTime 开始时间
     * @param dispenseDateETime 结束时间
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 药品耗材日结/周结/月结算单
     */
    @GetMapping(value = "/med-dev-info")
    public R<?> selectMedDdevInfo(@RequestParam Long orgId, @RequestParam String dispenseDateSTime,
        @RequestParam String dispenseDateETime, @RequestParam(name = "name", required = false) String name,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return R.ok(medicationDeviceReportAppService.selectMedDdevInfo(orgId, name, dispenseDateSTime,
            dispenseDateETime, pageNo, pageSize));
    }

    /**
     * 导出
     *
     * @param orgId 科室
     * @param name 项目名称
     * @param dispenseDateSTime 开始时间
     * @param dispenseDateETime 结束时间
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 单据详情
     */
    @GetMapping(value = "/excel-out")
    public void makeExcelFile(@RequestParam Long orgId, @RequestParam String dispenseDateSTime,
        @RequestParam String dispenseDateETime, @RequestParam(name = "name", required = false) String name,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletResponse response) {
        medicationDeviceReportAppService.makeExcelFile(orgId, name, dispenseDateSTime, dispenseDateETime, pageNo,
            pageSize, response);
    }

}
