package thyyxxk.webserver.controller.medicalinsurance;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
import thyyxxk.webserver.entity.datamodify.TYbSetModifyTime;
import thyyxxk.webserver.entity.datamodify.TYbSetlModifyReq;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyInactpatient;
import thyyxxk.webserver.entity.medicalinsurance.setllistupld.PatientBldInfo;
import thyyxxk.webserver.entity.medicalinsurance.setllistupld.SetlAuditLog;
import thyyxxk.webserver.entity.medicalinsurance.setllistupld.UpldCollection;
import thyyxxk.webserver.entity.medicalinsurance.setllistupldTemp.UpldCollectionTemp;
import thyyxxk.webserver.entity.querydata.AutoUploadBill;
import thyyxxk.webserver.entity.querydata.JieSuanDanChaXun;
import thyyxxk.webserver.entity.querydata.SiSetlinfoTemp;
import thyyxxk.webserver.entity.querydata.TSetlDeptConf;
import thyyxxk.webserver.entity.querydata.TUploadDrgGroup;
import thyyxxk.webserver.entity.vo.quality.QualityInfoVO;
import thyyxxk.webserver.service.medicalinsurance.UploadBillingList;
import thyyxxk.webserver.service.medicalinsurance.SetlListUpldService;
import thyyxxk.webserver.utils.ResultVoUtil;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 描述： 结算单上传
 * </p>
 *
 * @author xc
 * @date 2021-12-09 10:45
 */
@RestController
@RequestMapping("/setlListUpld")
public class SetlListUpldController {

    private final SetlListUpldService service;
    private final UploadBillingList uploadBillingList;

    public SetlListUpldController(SetlListUpldService service, UploadBillingList uploadBillingList) {
        this.service = service;
        this.uploadBillingList = uploadBillingList;
    }

    /**
     * @description:选中上传
     * @author: lihong
     * @date: 2022/12/14 10:23
     * @param: siPatInfos
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @PostMapping("/upldSetlList")
    @PassToken
    public ResultVo<String> upldSetlList(@RequestBody List<SiSetlinfoTemp> siPatInfos) {
        return service.upldSetlListBatch(siPatInfos);
    }

    /**
     * @description: 全部上传
     * @author: lihong
     * @date: 2022/12/14 10:11
     * @param: param
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @PostMapping("/upldSetlListTimes")
    public ResultVo<String> upldSetlListTimes(@RequestBody JieSuanDanChaXun param) {
        return service.upldSetlListTimes(param);
    }

    @GetMapping("/getMedType")
    public ResultVo<List<Object>> getMedType() {
        return service.getMedType();
    }

    @GetMapping("/getMedChrgitmType")
    public ResultVo<List<Object>> getMedChrgitmType() {
        return service.getMedChrgitmType();
    }

    @GetMapping("/getFundPayType")
    public ResultVo<List<Object>> getFundPayType() {
        return service.getFundPayType();
    }

    //查询结算上传列表
    @PostMapping("/huoQuJieSuanRenYuan")
    public ResultVo<IPage<SiSetlinfoTemp>> huoQuJieSuanRenYuan(@RequestBody JieSuanDanChaXun param) {
        return service.huoQuJieSuanRenYuan(param);
    }


    /**
     * @description:查询是否为在院病人
     * @author: lihong
     * @date: 2022/12/26 16:24
     * @param: patNo
     * @param: times
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.Boolean>
     **/
    @GetMapping("/isInHospital")
    public ResultVo<Boolean> isInHospital(@RequestParam("patNo") String patNo,
                                          @RequestParam("times") Integer times
    ) {
        return service.isInHospital(patNo, times);
    }

    /**
     * @description:申请撤回审核记录
     * @author: lihong
     * @date: 2022/12/28 11:21
     * @param: patNo
     * @param: times
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.Boolean>
     **/
    @GetMapping("/shenQingCheHui")
    public ResultVo<String> shenQingCheHui(@RequestParam("patNo") String patNo,
                                           @RequestParam("times") Integer times
    ) {
        return service.shenQingCheHui(patNo, times);
    }

    /**
     * @description:获取审核信息
     * @author: lihong
     * @date: 2022/12/28 16:05
     * @param: patNo
     * @param: times
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @GetMapping("/querySetlModifyReq")
    public ResultVo<TYbSetlModifyReq> querySetlModifyReq(@RequestParam("patNo") String patNo,
                                                         @RequestParam("times") Integer times
    ) {
        return service.querySetlModifyReq(patNo, times);
    }

    @GetMapping("/getUploadInfo")
    @PassToken
    public ResultVo<UpldCollection> getUploadInfo(@RequestParam("patNo") String patNo,
                                                  @RequestParam("times") Integer times,
                                                  @RequestParam("ledgerSn") Integer ledgerSn) throws Exception {
        return service.getUploadInfo(patNo, times, ledgerSn);
    }

    /**
     * @description:查看结算清单打印页面
     * @author: lihong
     * @date: 2022/12/14 14:47
     * @param: patNo
     * @param: times
     * @param: ledgerSn
     * @return: thyyxxk.webserver.entity.ResultVo<thyyxxk.webserver.entity.medicalinsurance.setllistupldTemp.UpldCollectionTemp>
     **/
    @GetMapping("/daYingShangChuanJieSuanDan")
    @PassToken
    public ResultVo<UpldCollectionTemp> daYingShangChuanJieSuanDan(@RequestParam("patNo") String patNo,
                                                                   @RequestParam("times") Integer times,
                                                                   @RequestParam("ledgerSn") Integer ledgerSn) throws Exception {
        return service.daYingShangChuanJieSuanDan(patNo, times, ledgerSn);
    }


    @PostMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response,
                            @RequestBody @Validated JieSuanDanChaXun param) {
        service.exportExcel(response, param);
    }

    @GetMapping("/jieSuanDanKeXiuGaiXinXi")
    public ResultVo<ZyInactpatient> jieSuanDanKeXiuGaiXinXi(@RequestParam("patNo") String patNo,
                                                            @RequestParam("times") Integer times,
                                                            @RequestParam("ledgerSn") Integer ledgerSn) {
        return service.jieSuanDanKeXiuGaiXinXi(patNo, times, ledgerSn);
    }

    @GetMapping("/getJieSuanDetail")
    public ResultVo<SiSetlinfoTemp> getJieSuanDetail(@RequestParam("patNo") String patNo,
                                                     @RequestParam("times") Integer times,
                                                     @RequestParam("ledgerSn") Integer ledgerSn) {
        return service.getJieSuanDetail(patNo, times, ledgerSn);
    }

    @GetMapping("/shouShuBianMa")
    public ResultVo<IPage<GetDropdownBox>> shouShuBianMa(@RequestParam("content") String content,
                                                         @RequestParam("currentPage") long currentPage) {
        return service.shouShuBianMa(content, currentPage);
    }

    /**
     * @description:保存修改 并申请审核
     * @author: lihong
     * @date: 2022/12/13 8:59
     * @param: param
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @PostMapping("/setlModifyReq")
    public ResultVo<String> setlModifyReq(@RequestBody ZyInactpatient param) {
        return service.setlModifyReq(param);
    }

    /**
     * @description: 病案检查
     * @author: lihong
     * @date: 2023/1/6 14:47
     * @param: param
     * @return: thyyxxk.webserver.entity.ResultVo<java.util.Map < java.lang.String, java.util.List < thyyxxk.webserver.entity.dictionary.CodeName>>>
     **/
    @PostMapping("/sheetVerification")
    public ResultVo<Map<String, List<CodeName>>> sheetVerification(@RequestBody ZyInactpatient param) {
        return service.sheetVerification(param);
    }

    /**
     * @description:结算单是否质控通过
     * @author: lihong
     * @date: 2022/12/26 11:09
     * @param: patNo
     * @param: times
     * @return: thyyxxk.webserver.entity.ResultVo<java.util.Map < java.lang.String, java.lang.Object>>
     **/
    @GetMapping("/qualityPass")
    public ResultVo<Map<String, Object>> qualityPass(@RequestParam("patNo") String patNo,
                                                     @RequestParam("times") Integer times) {
        return service.qualityPass(patNo, times);
    }

    /**
     * @description:drg分组测算
     * @author: lihong
     * @date: 2022/12/8 11:12
     * @param: param
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @PostMapping("/drgGroupTest")
    public ResultVo<String> drgGroupTest(@RequestBody ZyInactpatient param) {
        return service.drgGroupTest(param);
    }

    /**
     * @description:质控测算接口
     * @author: lihong
     * @date: 2022/12/14 15:08
     * @param: param
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @PostMapping("/drgQualityTest")
    public ResultVo<List<QualityInfoVO>> drgQualityTest(@RequestBody ZyInactpatient param) {
        return service.drgQualityTest(param);
    }

    /**
     * @description:审核通过 或 审核驳回
     * @author: lihong
     * @date: 2022/12/13 8:58
     * @param: param
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @PostMapping("/setlUploadAudit")
    public ResultVo<String> setlUploadAudit(@RequestBody TYbSetlModifyReq param) {
        return service.setlUploadAudit(param.getId(), param.getAuditFlag(), param.getAuditRemark(), param.getAuditStaff(), param.getAuditName());
    }

    /**
     * @description: 申请审核
     * @author: lihong
     * @date: 2022/12/13 8:59
     * @param: setlAuditLog
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @PostMapping("/sendAudit")
    public ResultVo<String> sendAudit(@RequestBody SetlAuditLog setlAuditLog) {
        return service.sendAudit(setlAuditLog);
    }

    /**
     * @description: 获取审核日志
     * @author: lihong
     * @date: 2022/12/13 9:01
     * @param: setlAuditLog
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @GetMapping("/listSetlAuditLog")
    public ResultVo<List<SetlAuditLog>> listSetlAuditLog(String patNo, Integer times) {
        return service.listSetlAuditLog(patNo, times);
    }

    @GetMapping("/xianZhiShiJian")
    public ResultVo<TYbSetModifyTime> xianZhiShiJian() {
        return service.xianZhiShiJian();
    }

    @GetMapping("/sheZhiShiJian")
    public ResultVo<String> sheZhiShiJian(@RequestParam("startTime") String startTime,
                                          @RequestParam("endTime") String endTime,
                                          @RequestParam("opId") String opId) {
        return service.sheZhiShiJian(startTime, endTime, opId);
    }

    @GetMapping("/getHuanZheFeiYong")
    public ResultVo<List<Map<String, String>>> getHuanZheFeiYong(@RequestParam("patNo") String patNo,
                                                                 @RequestParam("times") Integer times) {
        return service.getHuanZheFeiYong(patNo, times);
    }

    @GetMapping("/xiuGaiGuanChuangYiShen")
    public ResultVo<String> xiuGaiGuanChuangYiShen(@RequestParam("patNo") String patNo,
                                                   @RequestParam("times") Integer times,
                                                   @RequestParam("code") String code) {
        return service.xiuGaiGuanChuangYiShen(patNo, times, code);
    }

    @GetMapping("/modifyMedicalCategory")
    public ResultVo<String> modifyMedicalCategory(@RequestParam("iptMenType") String iptMenType,
                                                  @RequestParam("setlId") String setlId) {
        return service.modifyMedicalCategory(iptMenType, setlId);
    }

    @PostMapping("/addOrModifyBloodTransfusionVolume")
    public ResultVo<String> addOrModifyBloodTransfusionVolume(@RequestBody PatientBldInfo param) {
        return service.addOrModifyBloodTransfusionVolume(param);
    }

    @GetMapping("/removeBloodTransfusion")
    public ResultVo<String> removeBloodTransfusion(@RequestParam("id") Integer id) {
        return service.removeBloodTransfusion(id);
    }

    /**
     * @description:导出分组信息
     * @author: lihong
     * @date: 2023/1/4 14:35
     * @param: response
     * @param: param
     **/
    @PostMapping("/exportDrgGroupInfo")
    public void exportDrgGroupInfo(HttpServletResponse response, @RequestBody TUploadDrgGroup query) {
        service.exportDrgGroupInfo(response, query);
    }

    /**
     * @description:导出上传日志
     * @author: lihong
     * @date: 2023/1/4 14:35
     * @param: response
     * @param: param
     **/
    @PostMapping("/exportAutoUploadInfo")
    public void exportAutoUploadInfo(HttpServletResponse response, @RequestBody AutoUploadBill query) {
        service.exportAutoUploadInfo(response, query);
    }

    /**
     * @description:分页查询上传日志
     * @author: lihong
     * @date: 2023/1/4 14:34
     * @param: query
     * @return: com.baomidou.mybatisplus.core.metadata.IPage<thyyxxk.webserver.entity.querydata.AutoUploadBill>
     **/
    @PostMapping("/queryUploadInfo")
    public ResultVo<IPage<AutoUploadBill>> queryUploadInfo(@RequestBody AutoUploadBill query) {
        return ResultVoUtil.success(service.queryUploadInfo(query));
    }

    /**
     * @description: 查询科室配置信息
     * @author: lihong
     * @date: 2023/1/9 15:48
     * @param: query
     * @return: thyyxxk.webserver.entity.ResultVo<java.util.List < thyyxxk.webserver.entity.querydata.TSetlDeptConf>>
     **/
    @PostMapping("/querySetlDeptConfInfo")
    public ResultVo<List<String>> querySetlDeptConfInfo(@RequestBody TSetlDeptConf query) {
        return ResultVoUtil.success(service.querySetlDeptConfInfo(query));
    }

    /**
     * @description:保存科室配置信息
     * @author: lihong
     * @date: 2023/1/9 16:34
     * @param: list
     * @return: thyyxxk.webserver.entity.ResultVo<java.util.List < thyyxxk.webserver.entity.querydata.TSetlDeptConf>>
     **/
    @PostMapping("/saveSetlDeptConfInfo")
    public ResultVo<List<TSetlDeptConf>> saveSetlDeptConfInfo(@RequestBody List<TSetlDeptConf> list) {
        service.saveSetlDeptConfInfo(list);
        return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_EL_MESSAGE, "保存成功!");
    }


    @GetMapping("/getUploadMaxDay")
    public ResultVo<Integer> getUploadMaxDay() {
        return service.getUploadMaxDay();
    }


    @PostMapping("/queryDrgGroupPage")
    public ResultVo<IPage<TUploadDrgGroup>> queryDrgGroupPage(@RequestBody TUploadDrgGroup query) {
        return ResultVoUtil.success(service.queryDrgGroupPage(query));
    }

    @PostMapping("/updateBmyBz")
    public ResultVo<String> updateBmyBz(@RequestBody SiSetlinfoTemp data) {
        return service.updateBmyBz(data);
    }

    @GetMapping("/validateYbCode")
    public ResultVo<String> validateYbCode(@RequestParam("code") String code) {
        return service.validateYbCode(code);
    }

    /**
     * @description:删除审核记录
     * @author: lihong
     * @date: 2023/3/10 11:54
     * @param: code
     * @return: thyyxxk.webserver.entity.ResultVo<java.lang.String>
     **/
    @PostMapping("/delAuditLog")
    public ResultVo<String> delAuditLog(@RequestBody TYbSetlModifyReq param) {
        return service.delAuditLog(param);
    }

    @GetMapping("/tasks")
    @PassToken
    public void tasks() {
        uploadBillingList.uploadStatement();
    }


}
