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

import javax.servlet.http.HttpServletRequest;

import com.openhis.web.reportmanage.appservice.IDepartmentRevenueStatisticsAppService;
import com.openhis.web.reportmanage.dto.DepartmentRevenueStatisticsPageDto;
import com.openhis.web.reportmanage.mapper.DepartmentRevenueStatisticsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.core.common.core.domain.R;
import com.openhis.common.enums.DispenseStatus;
import com.openhis.common.enums.RequestStatus;
import com.openhis.common.utils.HisQueryUtils;
import com.openhis.web.reportmanage.appservice.IDrugDosageSettlementAppService;
import com.openhis.web.reportmanage.dto.DrugDosageSettlementPageDto;
import com.openhis.web.reportmanage.dto.DrugDosageSettlementSearchParam;
import com.openhis.web.reportmanage.mapper.DrugDosageSettlementMapper;

/**
 * 科室收入统计 controller
 *
 * @author yuxj
 * @date 2025-09-23
 */
@Service
public class DepartmentRevenueStatisticsAppServiceImpl implements IDepartmentRevenueStatisticsAppService {

    @Autowired
    private DepartmentRevenueStatisticsMapper departmentRevenueStatisticsMapper;

    /**
     * 科室收入统计
     *
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param searchKey 模糊查询关键字
     * @param request 请求数据
     * @return
     */
    @Override
    public R<?> getPage(Integer pageNo, Integer pageSize,
        String searchKey, HttpServletRequest request) {

        // 构建查询条件
        QueryWrapper<DrugDosageSettlementSearchParam> queryWrapper = HisQueryUtils.buildQueryWrapper(
            null, searchKey, null, request);

        Page<DepartmentRevenueStatisticsPageDto> drugDosageReportPage =
            departmentRevenueStatisticsMapper.selectPage(new Page<>(pageNo, pageSize), queryWrapper,
                DispenseStatus.COMPLETED.getValue(), RequestStatus.COMPLETED.getValue());

        return R.ok(drugDosageReportPage);
    }
}
