package com.openhis.web.pharmacymanage.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.openhis.web.inhospitalnursestation.dto.AdmissionPageParam;
import com.openhis.web.pharmacymanage.dto.*;
import org.springframework.web.bind.annotation.*;

import com.core.common.core.domain.R;
import com.openhis.web.pharmacymanage.appservice.ISummaryDispenseMedicineAppService;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;


/**
 * 住院汇总发药
 *
 * @author yuxj
 * @date 2025/6/3
 */
@RestController
@RequestMapping("/pharmacy-manage/summary-dispense-medicine")
@Slf4j
@AllArgsConstructor
public class SummaryDispenseMedicineController {

    @Resource
    public ISummaryDispenseMedicineAppService medicineSummaryDispenseService;

    /**
     * 获取页面初始化信息
     *
     * @return 初始化信息
     */
    @GetMapping(value = "/init")
    public R<?> medicineDispenseInit() {
        return medicineSummaryDispenseService.init();
    }

    /**
     * 分页查询住院病人列表
     *
     * @param admissionPageParam 查询条件
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param request 请求数据
     * @return 病人列表
     */
    @GetMapping("/encounter-list")
    public R<?> getEncounterInfoList(AdmissionPageParam admissionPageParam, String startTime, String endTime,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
        @RequestParam(name = "searchKey", required = false) String searchKey, HttpServletRequest request) {
        return medicineSummaryDispenseService.getEncounterInfoListPage(admissionPageParam, startTime, endTime, pageNo,
            pageSize, searchKey, request);
    }

    /**
     * 住院汇总药品
     *
     * @param searchParam 查询信息
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 药品汇总
     */
    @GetMapping("/medication_summary-list")
    public R<?> getSummaryMedicationInfo(MedicineSummarySearchParam searchParam,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return medicineSummaryDispenseService.getSummaryMedicationInfo(searchParam, pageNo, pageSize);
    }

    /**
     * 住院汇总发药单
     *
     * @param searchParam 查询条件
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param request 请求数据
     * @return 汇总单汇总
     */
    @GetMapping("/from_summary-list")
    public R<?> getSummaryFromInfo(FromSummarySearchParam searchParam, String startTime, String endTime,
        String searchKey, @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return medicineSummaryDispenseService.getSummaryFromInfo(searchParam, startTime, endTime, searchKey, pageNo,
            pageSize, request);
    }

    /**
     * 住院药品汇总发药单详细
     *
     * @param searchParam 查询条件
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param request 请求数据
     */
    @GetMapping("/from-list")
    public R<?> getFromInfo(FromSearchParam searchParam, String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return medicineSummaryDispenseService.getOrderInfo(searchParam, searchKey, pageNo, pageSize, request);
    }

    /**
     * 药品发药
     *
     * @param dispenseMedicineList 发药信息
     * @return 处理结果
     */
    @PutMapping("/summary-dispense-medicine")
    public R<?> SummaryDispenseMedicine(@RequestBody List<DispenseItemDto> dispenseMedicineList) {
        return medicineSummaryDispenseService.SummaryDispenseMedicine(dispenseMedicineList);
    }

    /**
     * 作废
     *
     * @param dispenseMedicineList 作废信息
     * @return 处理结果
     */
    @PutMapping("/dispense-cancel")
    public R<?> dispenseCancel(@RequestBody List<DispenseItemDto> dispenseMedicineList) {
        return medicineSummaryDispenseService.dispenseCancel(dispenseMedicineList);
    }

    /**
     * 退药处理
     *
     * @param dispenseMedicineList 退药清单
     * @return 处理结果
     */
    @PutMapping("/medicine-return")
    public R<?> medicineReturn(@RequestBody List<DispenseItemDto> dispenseMedicineList) {
        return medicineSummaryDispenseService.medicineReturn(dispenseMedicineList);
    }

    /**
     * 住院发药
     *
     * @param searchParam 查询条件
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param request 请求数据
     */

    @GetMapping(value = "/excel-out")
    public void excelOut(MedicineSummarySearchParam searchParam,
                              @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                              @RequestParam(value = "pageSize", defaultValue = "10000") Integer pageSize,
                              @RequestParam(name = "searchKey", required = false) String searchKey,
                              HttpServletRequest request,HttpServletResponse response) {
        medicineSummaryDispenseService.makeExcelFile(searchParam, pageNo, pageSize, searchKey, request, response);

    }
    /**
     * 住院药品汇总
     *
     * @param searchParam 查询条件
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param request 请求数据
     */





}
