package com.openhis.web.document.controller;

import com.core.common.core.domain.R;
import com.openhis.web.document.appservice.IDocRecordAppService;
import com.openhis.web.document.appservice.IDocStatisticsAppService;
import com.openhis.web.document.dto.DocStatisticsDto;
import com.openhis.web.document.dto.DocStatisticsQueryParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * DocStatistics文书统计  controller
 *
 * @author wanghaiming
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/document/statistics")
@Slf4j
@AllArgsConstructor
public class DocStatisticsController {

    private final IDocStatisticsAppService docStatisticsAppService;

    @PostMapping("/createOrUpdte")
    public R<?> createOrUpdte(List<DocStatisticsDto> docStatisticsList) {
        return docStatisticsAppService.createOrUpdte(docStatisticsList);
    }

    @DeleteMapping("/delete")
    public R<?> delete(List<Long> ids) {
        return docStatisticsAppService.delete(ids);
    }

    @GetMapping("/queryByRecordId")
    public R<?> queryByRecordId(Long recordId) {
        return docStatisticsAppService.queryByRecordId(recordId);
    }

    @GetMapping("/queryByEncounterId")
    public R<?> queryByEncounterId(Long encounterId) {
        return docStatisticsAppService.queryByEncounterId(encounterId);
    }

    @GetMapping("/getStatisticsList")
    R<?> getStatisticsList(DocStatisticsQueryParam queryParam,
                           @RequestParam(value = "isPage", defaultValue = "1") Integer isPage,
                           @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                           @RequestParam(name = "searchKey", required = false) String searchKey, HttpServletRequest request) {
        return docStatisticsAppService.getStatisticsList(queryParam, isPage, pageNo, pageSize, searchKey, request);
    }


}
