package com.openhis.web.adjustprice.controller;

import java.util.List;

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

import org.springframework.web.bind.annotation.*;

import com.core.common.core.domain.R;
import com.core.common.utils.StringUtils;
import com.openhis.web.adjustprice.appservice.IAdjustPriceService;
import com.openhis.web.adjustprice.dto.AdjustPriceDataVo;
import com.openhis.web.adjustprice.dto.AdjustPriceManagerSearchParam;

/**
 * @ClassName ChangePriceListPageController
 * @Description TODO
 * @Author raymond
 * @Date 2025/10/23 15:16
 * @Version 1.0
 **/
@RestController
@RequestMapping("/change/price/list")
public class ChangePriceDataListPageController {

    @Resource
    private IAdjustPriceService adjustPriceService;

    /**
     * Desc: 查询 调价管理列表页面 分页查询当前人 提交的调价单
     *
     * @param adjustPriceManagerSearchParam
     * @param pageNo
     * @param pageSize
     * @param searchKey
     * @param request
     * @Author raymond
     * @Date 15:47 2025/10/23
     * @return com.core.common.core.domain.R<?>
     **/
    @GetMapping(value = "getPage")
    public R<?> getPage(AdjustPriceManagerSearchParam adjustPriceManagerSearchParam,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
        @RequestParam(name = "searchKey", required = false) String searchKey, HttpServletRequest request) {
        return this.adjustPriceService.searchChangePriceSubmitDataToPage(adjustPriceManagerSearchParam, pageNo,
            pageSize, searchKey, request);
    }

    /**
     * Desc: 根据单据号 进行提交审核操作
     *
     * @param busNo
     * @Author raymond
     * @Date 09:38 2025/10/23
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "updateStatusByApproval")
    public R<?> updateStatusByApproval(@RequestParam String busNo) {
        return this.adjustPriceService.updateExamineByApproval(busNo);
    }

    /**
     * Desc: 作废 调价单数据
     *
     * @param busNo
     * @Author raymond
     * @Date 14:47 2025/10/21
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "cancelChangePriceData")
    public R<?> cancelChangePriceData(@RequestParam String busNo) {
        return this.adjustPriceService.cancelChangePriceData(busNo);
    }

    /**
     * Desc: 根据供应商和药品名称加载要修改的药品数据
     *
     *
     * @Author raymond
     * @Date 08:47 2025/10/15
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "submitChangePriceData")
    public R<?> submitChangePriceData(@RequestBody List<AdjustPriceDataVo> dataVoList) {
        return adjustPriceService.submitChangePriceData(dataVoList);
    }

    /**
     * Desc: 根据 单据号 药品调价单 查询详情
     *
     * @param busNo
     * @Author raymond
     * @Date 12:01 2025/10/21
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "searchChangePriceDataByMed")
    public R<?> searchChangePriceDataByMed(@RequestParam String busNo) {
        if (StringUtils.isEmpty(busNo)) {
            return R.fail();
        }
        return this.adjustPriceService.searchChangePriceDataByMed(busNo);
    }

    /**
     * Desc: 根据 单据号 耗材调价单 查询详情
     *
     * @param busNo
     * @Author raymond
     * @Date 12:01 2025/10/21
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "searchChangePriceDataByDevice")
    public R<?> searchChangePriceDataByDevice(@RequestParam String busNo) {
        if (StringUtils.isEmpty(busNo)) {
            return R.fail();
        }
        return this.adjustPriceService.searchChangePriceDataByDevice(busNo);
    }

    /**
     * Desc: 根据 单据号 诊疗调价单 查询详情
     *
     * @param busNo
     * @Author raymond
     * @Date 12:01 2025/10/21
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "searchChangePriceDataByActivity")
    public R<?> searchChangePriceDataByActivity(@RequestParam String busNo) {
        if (StringUtils.isEmpty(busNo)) {
            return R.fail();
        }
        return this.adjustPriceService.searchChangePriceDataByActivity(busNo);
    }

    /**
     * Desc: 根据 单据号 挂号调价单 查询详情
     *
     * @param busNo
     * @Author raymond
     * @Date 12:01 2025/10/21
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "searchChangePriceDataByHealth")
    public R<?> searchChangePriceDataByHealth(@RequestParam String busNo) {
        if (StringUtils.isEmpty(busNo)) {
            return R.fail();
        }
        return this.adjustPriceService.searchChangePriceDataByHealth(busNo);
    }
}
