package thyyxxk.webserver.controller.medicalinsurance;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.medicalinsurance.manage.*;
import thyyxxk.webserver.entity.medicalinsurance.manage.deptmanage.DeptInfo;
import thyyxxk.webserver.entity.medicalinsurance.manage.deptmanage.MedStaffQuery;
import thyyxxk.webserver.entity.medicalinsurance.manage.examination.BilgItemInfo;
import thyyxxk.webserver.entity.medicalinsurance.manage.frontsheet.BriefSheet;
import thyyxxk.webserver.entity.medicalinsurance.manage.setllist.SetllistQualityControlInquiry;
import thyyxxk.webserver.entity.medicalinsurance.manage.setllist.SetllistQuantityCountInquiry;
import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SlctSetlPrm;
import thyyxxk.webserver.service.externalhttp.SiInjurySystem;
import thyyxxk.webserver.service.medicalinsurance.SiManageService;
import thyyxxk.webserver.utils.TokenUtil;

import java.util.List;
import java.util.Map;

/**
 * @description: 医保管理入口
 * @author: DingJie
 * @create: 2021/7/3011:14
 */
@RestController
@RequestMapping("/siManage")
public class SiManageController {
    private final SiManageService service;
    private final SiInjurySystem injurySystem;
    @Value("${si-injury-systm-url}")
    private String siInjurySystemUrl;

    @Autowired
    public SiManageController(SiManageService service, SiInjurySystem injurySystem) {
        this.service = service;
        this.injurySystem = injurySystem;
    }

    @PostMapping("/institutionSettlementLedgerCheck")
    public ResultVo<String> institutionSettlementLedgerCheck(@RequestBody InstStlLdgChk instStlLdgChk) {
        return service.institutionSettlementLedgerCheck(instStlLdgChk);
    }

    @PostMapping("/institutionSettlementDetailCheck")
    public ResultVo<List<InsSetlDetlChkRslt>> institutionSettlementDetailCheck(@RequestBody InstStlLdgChk instStlLdgChk) {
        return service.institutionSettlementDetailCheck(instStlLdgChk);
    }

    @PostMapping("/uploadCatalogueContrast")
    public ResultVo<String> uploadCatalogueContrast(@RequestBody CatalogueContrast catalogueContrast) {
        if (catalogueContrast.getYbType() == 2) {
            catalogueContrast.setStaffId(TokenUtil.getInstance().getTokenUserId());
            return injurySystem.catalogueMatch(siInjurySystemUrl, catalogueContrast);
        }
        return service.uploadCatalogueContrast(catalogueContrast);
    }

    @PostMapping("/revokeCatalogueContrast")
    public ResultVo<String> revokeCatalogueContrast(@RequestBody CatalogueContrast catalogueContrast) {
        if (catalogueContrast.getYbType() == 2) {
            catalogueContrast.setStaffId(TokenUtil.getInstance().getTokenUserId());
            return injurySystem.cancelCatalogueMatch(siInjurySystemUrl, catalogueContrast);
        }
        return service.revokeCatalogueContrast(catalogueContrast);
    }

    @PassToken
    @PostMapping("/autoRecoveryTrade")
    public ResultVo<String> autoRecoveryTrade(@RequestBody AtoRcvTrd atoRcvTrd) {
        return service.autoRecoveryTrade(atoRcvTrd);
    }

    @PostMapping("/selectSetlinfos")
    public ResultVo<Map<String, Object>> selectSetlinfos(@RequestBody @Validated SlctSetlPrm slctSetlPrm) {
        return service.selectSetlinfos(slctSetlPrm);
    }

    @PassToken
    @GetMapping("/detailAnalyse")
    public ResultVo<String> detailAnalyse(@RequestParam("patNo") String patNo,
                                          @RequestParam("times") int times,
                                          @RequestParam("ledger") int ledger,
                                          @RequestParam("type") int type) {
        return service.detailAnalyse(patNo, times, ledger, type);
    }

    @PassToken
    @PostMapping("/deptInfoUpload")
    public ResultVo<String> deptInfoUpload(@RequestBody DeptInfo deptInfo) {
        return service.deptInfoUpload(deptInfo);
    }

    @PassToken
    @PostMapping("/deptInfoBatchUpload")
    public ResultVo<String> deptInfoBatchUpload(@RequestBody List<DeptInfo> deptInfos) {
        return service.deptInfoBatchUpload(deptInfos);
    }

    @PassToken
    @PostMapping("/deptInfoModify")
    public ResultVo<String> deptInfoModify(@RequestBody DeptInfo deptInfo) {
        return service.deptInfoModify(deptInfo);
    }

    @PassToken
    @PostMapping("/deptInfoDelete")
    public ResultVo<String> deptInfoDelete(@RequestBody DeptInfo deptInfo) {
        return service.deptInfoDelete(deptInfo);
    }

    @PostMapping("/queryDeptInfo")
    public ResultVo<JSONArray> queryDeptInfo() {
        return service.queryDeptInfo();
    }

    @PostMapping("/queryMedStaffInfo")
    public ResultVo<JSONArray> queryMedStaffInfo(@RequestBody MedStaffQuery query) {
        return service.queryMedStaffInfo(query);
    }

    @PassToken
    @PostMapping("/queryExaminationExInfo")
    public ResultVo<JSONObject> queryExaminationExInfo(@RequestBody BilgItemInfo bilgItemInfo) {
        return service.queryExaminationExInfo(bilgItemInfo);
    }

    @PassToken
    @GetMapping("/queryExaminationDetail")
    public ResultVo<JSONObject> queryExaminationDetail(@RequestParam("psnNo") String psnNo, @RequestParam("reportNo") String reportNo) {
        return service.queryExaminationDetail(psnNo, reportNo);
    }

    @PassToken
    @GetMapping("/modifySetllistState")
    public ResultVo<String> modifySetllistState(@RequestParam("psnNo") String psnNo, @RequestParam("setlId") String setlId, @RequestParam("type") int type) {
        return service.modifySetllistState(psnNo, setlId, type);
    }

    @PassToken
    @GetMapping("/querySetllistInfo")
    public ResultVo<JSONObject> querySetllistInfo(@RequestParam("psnNo") String psnNo, @RequestParam("setlId") String setlId) {
        return service.querySetllistInfo(psnNo, setlId);
    }

    @PassToken
    @GetMapping("/querySetllistQualityControl")
    public ResultVo<JSONObject> querySetllistQualityControl(SetllistQualityControlInquiry inquiry) {
        return service.querySetllistQualityControl(inquiry);
    }

    @PassToken
    @GetMapping("/querySetllistQuantityCount")
    public ResultVo<JSONObject> querySetllistQuantityCount(SetllistQuantityCountInquiry inquiry) {
        return service.querySetllistQuantityCount(inquiry);
    }

    @GetMapping("/selectSheets")
    public ResultVo<List<BriefSheet>> selectSheets(@RequestParam("month") String month,
                                                   @RequestParam("status") Integer status) {
        return service.selectSheets(month, status);
    }

    @PostMapping("/siUploadSheets")
    public ResultVo<String> uploadFrontSheet(@RequestBody List<BriefSheet> list) {
        return service.uploadFrontSheetBatch(list);
    }

    @PassToken
    @GetMapping("/uploadActOrder")
    public ResultVo<String> uploadActOrder(@RequestParam("patNo") String patNo, @RequestParam("times") int times) {
        return service.uploadActOrder(patNo, times);
    }

    @PassToken
    @GetMapping("/uploadClinicRecord")
    public ResultVo<String> uploadClinicRecord(@RequestParam("patNo") String patNo, @RequestParam("times") int times) {
        return service.uploadClinicRecord(patNo, times);
    }

    @PassToken
    @GetMapping("/uploadEmergencyRecord")
    public ResultVo<String> uploadEmergencyRecord(@RequestParam("patNo") String patNo, @RequestParam("times") int times) {
        return service.uploadEmergencyRecord(patNo, times);
    }

    @GetMapping("/selectSetlPrescription")
    public ResultVo<List<Map<String, Object>>> selectSetlPrescription(@RequestParam("mdtrtId") String mdtrtId) {
        return service.selectSetlPrescription(mdtrtId);
    }

    @GetMapping("/selectMzBl")
    public ResultVo<Map<String, Object>> selectMzBl(@RequestParam("patNo") String patNo, @RequestParam("times") int times) {
        return service.selectMzBl(patNo, times);
    }


}