package com.glxp.mipsdl.controller;

import com.glxp.mipsdl.client.ClientProcessor;
import com.glxp.mipsdl.client.ctqyy.entity.InvProjectResultEntity;
import com.glxp.mipsdl.client.pzh.PzhzdClient;
import com.glxp.mipsdl.req.base.*;
import com.glxp.mipsdl.req.ctqyy.DlThirdProjectRequest;
import com.glxp.mipsdl.req.ctqyy.FilterThrHslbRequest;
import com.glxp.mipsdl.req.ctqyy.GetSickPrescribeRequest;
import com.glxp.mipsdl.req.ctqyy.GetSickRequest;
import com.glxp.mipsdl.req.post.PostCollectOrderRequest;
import com.glxp.mipsdl.req.post.PostRelProductRequest;
import com.glxp.mipsdl.req.pzh.USignRequest;
import com.glxp.mipsdl.res.BaseResponse;
import com.glxp.mipsdl.util.DictUtl;
import com.glxp.mipsdl.util.ResultVOUtils;
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.RestController;

import javax.annotation.Resource;

/**
 * 提供给UDI管理系统的接口
 */
@RestController
public class UdiWmsController {

    @Resource
    private PzhzdClient pzhzdClient;

    /**
     * 获取第三方系统往来单位信息接口
     *
     * @param udiwmsUnitRequest
     * @return
     */
    @PostMapping("/udiwms/erp/getUnits")
    public BaseResponse getUnits(@RequestBody UdiwmsUnitRequest udiwmsUnitRequest) {
        return ClientProcessor.getHttpClient().getUnit(udiwmsUnitRequest);
    }

    /**
     * 获取第三方系统生产企业接口
     *
     * @param udiwmsManuRequest
     * @return
     */
    @PostMapping("/udiwms/erp/getManus")
    public BaseResponse getManus(@RequestBody UdiwmsManuRequest udiwmsManuRequest) {
        return ClientProcessor.getHttpClient().getManu(udiwmsManuRequest);
    }


    /**
     * 获取第三方系统产品信息接口
     *
     * @param udiwmsProductRequest
     * @return
     */
    @PostMapping("/udiwms/erp/getProducts")
    public BaseResponse getProducts(@RequestBody UdiwmsProductRequest udiwmsProductRequest) {
        return ClientProcessor.getHttpClient().getProducts(udiwmsProductRequest);
    }

    /**
     * 获取仓库信息接口
     *
     * @param udiwmsWarehouseRequest
     * @return
     */
    @PostMapping("/udiwms/erp/getWarehouse")
    public BaseResponse getWarehouse(@RequestBody UdiwmsWarehouseRequest udiwmsWarehouseRequest) {
        return ClientProcessor.getHttpClient().getWarehouse(udiwmsWarehouseRequest);
    }

    /**
     * 获取单据信息接口
     *
     * @param udiwmsOrderQueryRequest
     * @return
     */
    @PostMapping("/udiwms/erp/getOrders")
    public BaseResponse getOrders(@RequestBody UdiwmsOrderQueryRequest udiwmsOrderQueryRequest) {
        return ClientProcessor.getHttpClient().getOrders(udiwmsOrderQueryRequest);
    }

    /**
     * 获取单据类型接口
     *
     * @param udiwmsBusTypeRequest
     * @return
     */
    @PostMapping("/udiwms/erp/getOrderType")
    public BaseResponse getOrderTypes(@RequestBody UdiwmsBusTypeRequest udiwmsBusTypeRequest) {
        return ClientProcessor.getHttpClient().getOrderTypes(udiwmsBusTypeRequest);
    }

    /**
     * 提交单据接口
     *
     * @param udiwmsOrderRequest
     * @return
     */
    @PostMapping("/udiwms/erp/submitOrders")
    public BaseResponse submitOrders(@RequestBody UdiwmsOrderRequest udiwmsOrderRequest) {
        return ClientProcessor.getHttpClient().submitOrders(udiwmsOrderRequest);
    }

    /**
     * 获取库存产品信息接口
     *
     * @param udiwmsInvProductsRequest
     * @return
     */
    @PostMapping("/udiwms/erp/inv/getInvProduct")
    public BaseResponse getInvProduct(@RequestBody UdiwmsInvProductsRequest udiwmsInvProductsRequest) {
        return ClientProcessor.getHttpClient().getInvProducts(udiwmsInvProductsRequest);
    }


    /**
     * 获取库存产明细/出入库明细接口（普耗出入库）
     *
     * @param udiwmsInvProductsRequest
     * @return
     */
    @PostMapping("/udiwms/erp/inv/getInvResult")
    public BaseResponse getInvResult(@RequestBody UdiwmsInvProductsRequest udiwmsInvProductsRequest) {
        return ClientProcessor.getHttpClient().getInvResult(udiwmsInvProductsRequest);
    }


    /**
     * 获取库存收费出入库明细 （收费出入库）
     *
     * @param udiwmsInvProductsRequest
     * @return
     */
    @PostMapping("/udiwms/erp/inv/getInvFeeResult")
    public BaseResponse getInvFeeResult(@RequestBody UdiwmsInvProductsRequest udiwmsInvProductsRequest) {
        return ClientProcessor.getHttpClient().getInvFeeResult(udiwmsInvProductsRequest);
    }

    /**
     * 获取库存出入库扫码明细 （高值出入库）
     *
     * @param udiwmsInvProductsRequest
     * @return
     */
    @PostMapping("/udiwms/erp/inv/getInvCodeResult")
    public BaseResponse getInvCodeResult(@RequestBody UdiwmsInvProductsRequest udiwmsInvProductsRequest) {
        return ClientProcessor.getHttpClient().getInvCodeResult(udiwmsInvProductsRequest);
    }


    /**
     * 提交产品到第三方系统接口
     *
     * @param udiwmsAddProductsRequest
     * @return
     */
    @PostMapping("/udiwms/erp/post/product")
    public BaseResponse postProduct(@RequestBody UdiwmsAddProductsRequest udiwmsAddProductsRequest) {
        return ClientProcessor.getHttpClient().submitProducts(udiwmsAddProductsRequest);
    }

    /**
     * 添加第三方系统往来单位信息
     *
     * @param udiwmsAddUnitRequest
     * @return
     */
    @PostMapping("/udiwms/erp/post/unit")
    public BaseResponse postUnit(@RequestBody UdiwmsAddUnitRequest udiwmsAddUnitRequest) {
        return ClientProcessor.getHttpClient().submitUnit(udiwmsAddUnitRequest);
    }


    /**
     * 添加第三方系统生产企业
     *
     * @param udiwmsAddManuRequest
     * @return
     */
    @PostMapping("/udiwms/erp/post/manu")
    public BaseResponse postManu(@RequestBody UdiwmsAddManuRequest udiwmsAddManuRequest) {
        return ClientProcessor.getHttpClient().submitManu(udiwmsAddManuRequest);
    }


    /**
     * 获取患者信息
     *
     * @param getSickRequest
     * @return
     */
    @PostMapping("/udiwms/erp/sicker/getInfo")
    public BaseResponse getSickerInfo(@RequestBody GetSickRequest getSickRequest) {
        return ClientProcessor.getHttpClient().getSickInfo(getSickRequest);
    }

    /**
     * 获取患者处方信息
     *
     * @param getSickPrescribeRequest
     * @return
     */
    @PostMapping("/udiwms/erp/sicker/getPrescribe")
    public BaseResponse getSickPrescribe(@RequestBody GetSickPrescribeRequest getSickPrescribeRequest) {
        return ClientProcessor.getHttpClient().getSickPescribe(getSickPrescribeRequest);
    }


    /**
     * 获取项目组套字典
     *
     * @return
     */
    @PostMapping("/udiwms/erp/basic/getProject")
    public BaseResponse getBasicProject(@RequestBody DlThirdProjectRequest dlThirdProjectRequest) {
        return ClientProcessor.getHttpClient().getBasicProject(dlThirdProjectRequest);
    }


    /**
     * 获取项目组套字典
     *
     * @return
     */
    @PostMapping("/udiwms/erp/basic/getHslb")
    public BaseResponse getHslb(@RequestBody FilterThrHslbRequest filterThrHslbRequest) {
        return ClientProcessor.getHttpClient().getHsfl(filterThrHslbRequest);
    }


    @PostMapping("/udiwms/erp/testThirdSys")
    public BaseResponse testThirdSys() {
        return ClientProcessor.getHttpClient().testConnect();
    }


    @PostMapping("/udiwms/erp/testLocal")
    public BaseResponse testLocal() {
        return ResultVOUtils.success("连接第三方服务成功！");
    }


    //片仔癀用友U8专属接口

    /**
     * 提交采购计划
     *
     * @return
     */
    @PostMapping("/udiwms/erp/order/postOrder")
    public BaseResponse postOrder(@RequestBody UdiwmsOrderRequest udiwmsOrderRequest) {
        if (!DictUtl.CURRENT_HOSP_CODE.equals("100002")) {
            return ResultVOUtils.error(500, "未设置系统版本");
        }
        return pzhzdClient.postOrder(udiwmsOrderRequest);
    }

    /**
     * 获取现存量接口
     *
     * @param udiwmsInvProductsRequest
     * @return
     */
    @GetMapping("/udiwms/erp/getOnhand")
    public BaseResponse getOnHand(@RequestBody UdiwmsInvProductsRequest udiwmsInvProductsRequest) {
        if (!DictUtl.CURRENT_HOSP_CODE.equals("100002")) {
            return ResultVOUtils.error(500, "未设置系统版本");
        }
        return pzhzdClient.getOnHand(udiwmsInvProductsRequest);
    }

    /**
     * 签字ERP订单接口
     *
     * @param signRequest
     * @return
     */
    @PostMapping("/udiwms/erp/signBill")
    public BaseResponse signBill(@RequestBody USignRequest signRequest) {
        if (!DictUtl.CURRENT_HOSP_CODE.equals("100002")) {
            return ResultVOUtils.error(500, "未设置系统版本");
        }
        return pzhzdClient.signBill(signRequest);
    }

    //修改ERP订单接口
    @PostMapping("/udiwms/erp/modifyBill")
    public BaseResponse modifyBill(@RequestBody UdiwmsPostBillRequest udiwmsPostBillRequest) {
        if (!DictUtl.CURRENT_HOSP_CODE.equals("100002")) {
            return ResultVOUtils.error(500, "未设置系统版本");
        }
        return pzhzdClient.modifyBill(udiwmsPostBillRequest);
    }


    /**
     * 提交关联产品到第三方系统接口
     *
     * @param postRelProductRequest
     * @return
     */
    @PostMapping("/udiwms/erp/post/udiRel/product")
    public BaseResponse postRelProduct(@RequestBody PostRelProductRequest postRelProductRequest) {
        return ClientProcessor.getHttpClient().postRelProduct(postRelProductRequest);
    }


    /**
     * 处方入库
     *
     * @param udiwmsBasicSkPrescribeRequest
     * @return
     */
    @PostMapping("/udiwms/erp/getPrescribes")
    public BaseResponse getPrescribes(@RequestBody UdiwmsBasicSkPrescribeRequest udiwmsBasicSkPrescribeRequest) {
        return ClientProcessor.getHttpClient().getPrescribes(udiwmsBasicSkPrescribeRequest);
    }

    /**
     * 器械处方
     *
     * @param udiwmsBasicSkPrescribeRequest
     * @return
     */
    @PostMapping("/udiwms/erp/getPrescribesQx")
    public BaseResponse getPrescribesQx(@RequestBody UdiwmsBasicSkPrescribeRequest udiwmsBasicSkPrescribeRequest) {
        return ClientProcessor.getHttpClient().getPrescribesQx(udiwmsBasicSkPrescribeRequest);
    }

    /**
     * 采购计划入库
     *
     * @param udiwmsThrOrderRequest
     * @return
     */
    @PostMapping("/udiwms/erp/getThrOrders")
    public BaseResponse getThrOrders(@RequestBody UdiwmsThrOrderRequest udiwmsThrOrderRequest) {
        return ClientProcessor.getHttpClient().getThrOrders(udiwmsThrOrderRequest);
    }


    /**
     * 业务单据上传医保
     *
     * @param postCollectOrderRequest
     * @return
     */
    @PostMapping("/udiwms/erp/uploadCollectOrder")
    public BaseResponse uploadCollectOrder(@RequestBody PostCollectOrderRequest postCollectOrderRequest) {
        return ClientProcessor.getHttpClient().uploadCollectOrder(postCollectOrderRequest);
    }

}
