package com.glxp.mipsdl.client.dsxyy;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.glxp.mipsdl.client.CommonHttpClient;
import com.glxp.mipsdl.config.ThirdSysConfig;
import com.glxp.mipsdl.constant.ConstantType;
import com.glxp.mipsdl.constant.Constants;
import com.glxp.mipsdl.dao.auth.AuthUserDao;
import com.glxp.mipsdl.dao.auth.AuthWarehouseDao;
import com.glxp.mipsdl.dao.basic.BasicBussinessTypeDao;
import com.glxp.mipsdl.dao.basic.BasicCorpDao;
import com.glxp.mipsdl.dao.basic.BasicProductsDao;
import com.glxp.mipsdl.dao.basic.BasicUdirelDao;
import com.glxp.mipsdl.dao.inout.IoCodeDao;
import com.glxp.mipsdl.dao.inout.IoOrderDao;
import com.glxp.mipsdl.dao.inout.IoOrderDetailBizDao;
import com.glxp.mipsdl.dao.thrsys.*;
import com.glxp.mipsdl.entity.auth.AuthUserEntity;
import com.glxp.mipsdl.entity.auth.AuthWarehouseEntity;
import com.glxp.mipsdl.entity.basic.BasicBussinessTypeEntity;
import com.glxp.mipsdl.entity.basic.BasicCorpEntity;
import com.glxp.mipsdl.entity.basic.BasicProductsEntity;
import com.glxp.mipsdl.entity.basic.BasicUdirelEntity;
import com.glxp.mipsdl.entity.inout.IoCodeEntity;
import com.glxp.mipsdl.entity.inout.IoOrderDetailBizEntity;
import com.glxp.mipsdl.entity.inout.IoOrderEntity;
import com.glxp.mipsdl.entity.inout.IoOrderInvoiceEntity;
import com.glxp.mipsdl.entity.thrsys.*;
import com.glxp.mipsdl.http.HttpClient;
import com.glxp.mipsdl.req.base.*;
import com.glxp.mipsdl.req.dsxyy.DsBusTypeRequest;
import com.glxp.mipsdl.req.dsxyy.DsOrderRequest;
import com.glxp.mipsdl.req.dsxyy.DsProductRequest;
import com.glxp.mipsdl.req.dsxyy.DsUnitRequest;
import com.glxp.mipsdl.req.post.PostFileThrOrderRequest;
import com.glxp.mipsdl.req.post.PostThrCorpRequest;
import com.glxp.mipsdl.req.post.PostThrInvProductsRequest;
import com.glxp.mipsdl.req.post.PostThrProductsRequest;
import com.glxp.mipsdl.res.BaseResponse;
import com.glxp.mipsdl.res.PageSimpleResponse;
import com.glxp.mipsdl.res.udiwms.ThrProductsResponse;
import com.glxp.mipsdl.service.auth.AuthWarehouseService;
import com.glxp.mipsdl.service.order.OrderUploadLogService;
import com.glxp.mipsdl.service.thrsys.ThrCorpService;
import com.glxp.mipsdl.service.thrsys.ThrSystemDetailService;
import com.glxp.mipsdl.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 东山县医院接口对接
 */
@Slf4j
@Service(value = "100006HttpClient")  //bean注册名称，使用编码 + HttpClient，文件接口加 FileClient
public class DsxyyClient extends CommonHttpClient {

    @Resource
    private ThrSystemDetailService thrSystemDetailService;
    @Resource
    private HttpClient httpClient;
    @Resource
    private ThrBustypeOriginDao thrBustypeOriginDao;
    @Resource
    private IoOrderDao orderDao;
    @Resource
    private ThrSystemBusApiDao thrSystemBusApiDao;
    @Resource
    private BasicBussinessTypeDao basicBussinessTypeDao;
    @Resource
    private BasicCorpDao basicCorpDao;
    @Resource
    private IoCodeDao codeDao;
    @Resource
    private AuthWarehouseDao authWarehouseDao;
    @Resource
    private ThrInvWarehouseDao thrInvWarehouseDao;
    @Resource
    private AuthWarehouseService authWarehouseService;
    @Resource
    private ThirdSysConfig thirdSysConfig;
    @Resource
    private ThrCorpService thrCorpService;
    @Resource
    private IoOrderDetailBizDao orderDetailBizDao;
    @Resource
    private SubmitOrderUtil submitOrderUtil;
    @Resource
    AuthUserDao authUserDao;
    @Resource
    private BasicUdirelDao basicUdirelDao;
    @Resource
    private BasicProductsDao basicProductsDao;
    @Resource
    private ThrProductsDao thrProductsDao;
    @Resource
    private OrderUploadLogService orderUploadLogService;
    @Resource
    private ThrOrderUploadBustypesMapper thrOrderUploadBustypesMapper;
    @Resource
    ThrCorpDao thrCorpDao;

    @Override
    public BaseResponse getUnit(UdiwmsUnitRequest udiwmsUnitRequest) {
        DsUnitRequest dsUnitRequest = new DsUnitRequest();
        BeanUtil.copyProperties(udiwmsUnitRequest, dsUnitRequest);
        String response = httpClient.postJson(thrSystemDetailService.getUrl(Constants.URL_NAME_CORP_URL), dsUnitRequest);
        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse getProducts(UdiwmsProductRequest udiwmsProductRequest) {
        DsProductRequest dsProductRequest = new DsProductRequest();
        BeanUtil.copyProperties(udiwmsProductRequest, dsProductRequest);
        String response = httpClient.postJson(thrSystemDetailService.getUrl(Constants.URL_NAME_PI_QUERY_URL), dsProductRequest);

        BaseResponse<PageSimpleResponse<ThrProductsResponse>> baseResponse =
                JSONObject.parseObject(response, new TypeReference<BaseResponse<PageSimpleResponse<ThrProductsResponse>>>() {
                });

        //       过滤西药库产品
        if (CollUtil.isNotEmpty(baseResponse.getData().getList())) {
            Iterator<ThrProductsResponse> iterator = baseResponse.getData().getList().iterator();
            while (iterator.hasNext()) {
                ThrProductsResponse item = iterator.next();
                if (item.getRemark() != null && item.getRemark().contains("西药库")) {
                    iterator.remove();
                    baseResponse.getData().setTotal(-555l);
                }
            }
        }
//        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse getOrderTypes(UdiwmsBusTypeRequest udiwmsBusTypeRequest) {
        DsBusTypeRequest dsBusTypeRequest = new DsBusTypeRequest();
        BeanUtil.copyProperties(udiwmsBusTypeRequest, dsBusTypeRequest);
        String response = httpClient.postJson(thrSystemDetailService.getUrl(Constants.URL_NAME_BUS_TYPE_QUERY_URL), udiwmsBusTypeRequest);
        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse getOrders(UdiwmsOrderQueryRequest udiwmsOrderQueryRequest) {
        if (StrUtil.isBlank(udiwmsOrderQueryRequest.getBillType())) {
            return ResultVOUtils.error(500, "单据类型不能为空");
        }
        //查询绑定的第三方单据类型
        String thirdAction = thrBustypeOriginDao.findThirdActionByBillType(udiwmsOrderQueryRequest.getBillType(), DictUtl.CURRENT_HOSP_CODE);
        udiwmsOrderQueryRequest.setBillType(thirdAction);
        String response = httpClient.postJson(thrSystemDetailService.getUrl(Constants.URL_NAME_ORDER_QUERY_URL), udiwmsOrderQueryRequest);
        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse submitOrders(UdiwmsOrderRequest udiwmsOrderRequest) {
        if (StrUtil.isBlank(udiwmsOrderRequest.getBillNo())) {
            return ResultVOUtils.error(500, "单据号不能为空");
        }

        DsOrderRequest dsOrderRequest = new DsOrderRequest();
        BeanUtil.copyProperties(udiwmsOrderRequest, dsOrderRequest);

        //查询单据和详情信息，组装第三方系统接口参数
        IoOrderEntity orderEntity = orderDao.selectOne(new LambdaQueryWrapper<IoOrderEntity>().eq(IoOrderEntity::getBillNo, udiwmsOrderRequest.getBillNo()).last("limit 1"));

        if (orderEntity.getAuditTime() == null)
            dsOrderRequest.setBillDate(DateUtil.formatDateTime(orderEntity.getCreateTime()));
        else {
            dsOrderRequest.setBillDate(DateUtil.formatDateTime(orderEntity.getAuditTime()));
        }

        //设置操作人
        if (orderEntity.getReviewUser() != null) {
            AuthUserEntity authAdmin = authUserDao.selectById(orderEntity.getReviewUser());
            dsOrderRequest.setOperUser(authAdmin.getUserName());
        } else if (orderEntity.getCreateUser() != null) {
            AuthUserEntity authAdmin = authUserDao.selectById(orderEntity.getCreateUser());
            dsOrderRequest.setOperUser(authAdmin.getUserName());
        }
        //查询对应的第三方单据类型
        ThrSystemBusApiEntity thrSystemBusApiEntity = thrSystemBusApiDao.selectOne(new LambdaQueryWrapper<ThrSystemBusApiEntity>().eq(ThrSystemBusApiEntity::getCode, udiwmsOrderRequest.getBillType()));
        if (StrUtil.isBlank(thrSystemBusApiEntity.getUrl())) {
            return ResultVOUtils.error(500, "接口未配置，无法提交！");
        }

        dsOrderRequest.setBillType(thrSystemBusApiEntity.getThirdBuyCode());
        if (orderEntity.getInvCode().equals("1000000")) {
            dsOrderRequest.setLocInvCode("1161");
            dsOrderRequest.setLocInvName("设备科");
        } else {
            dsOrderRequest.setLocInvCode("4050");
            dsOrderRequest.setLocInvName("西药库");
        }


        //查询单据类型，设置往来单位信息
        BasicBussinessTypeEntity basicBussinessTypeEntity = basicBussinessTypeDao.selectByAction(udiwmsOrderRequest.getBillType());
        if (basicBussinessTypeEntity.getCorpType().equals(Constants.CORP_HOSPTIAL)) {
            //医院客户
            dsOrderRequest.setCorpId(orderEntity.getFromCorp());
            //查询客户名称
            String corpName = basicCorpDao.selectNameByErpId(orderEntity.getFromCorp());
            dsOrderRequest.setCorpName(corpName);
        } else if (basicBussinessTypeEntity.getCorpType().equals(Constants.CORP_INTTERNAL)) {


            BasicCorpEntity basicCorpEntity = null;
            if (StrUtil.isNotEmpty(orderEntity.getFromCorp())) {
                basicCorpEntity = basicCorpDao.selectByErpId(orderEntity.getFromCorp());
            }
            if (basicCorpEntity != null) {
                dsOrderRequest.setCorpId(basicCorpEntity.getThirdId());
                dsOrderRequest.setCorpName(basicCorpEntity.getName());
                List<ThrCorpEntity> thrCorpEntities = thrCorpDao.selectList(new QueryWrapper<ThrCorpEntity>().eq("name", basicCorpEntity.getThirdName()));
                if (CollUtil.isNotEmpty(thrCorpEntities)) {
                    for (ThrCorpEntity temp : thrCorpEntities) {
                        if (StrUtil.isNotEmpty(temp.getKfdm()) && temp.getKfdm().equals(udiwmsOrderRequest.getLocInvCode())) {
                            udiwmsOrderRequest.setCorpId(temp.getUnitId()); //往来单位编码，需转换为第三方系统的ID
                            udiwmsOrderRequest.setCorpName(temp.getName()); //往来单位名称，需转换为第三方系统的名称
                        }
                    }
                }

            } else {
                AuthWarehouseEntity warehouseEntity = authWarehouseDao.selectOne(new QueryWrapper<AuthWarehouseEntity>().eq("code", udiwmsOrderRequest.getCorpId()));
                try {
                    //根据第三方系统标识，获取对应字段的值
                    ThrInvWarehouseEntity thrInvWarehouseEntity = thrInvWarehouseDao.selectOne(new LambdaQueryWrapper<ThrInvWarehouseEntity>()
                            .eq(ThrInvWarehouseEntity::getCode, authWarehouseService.getThirdInvCode(warehouseEntity))
                            .eq(ThrInvWarehouseEntity::getThirdSysFk, thirdSysConfig.getThirdId()));

                    dsOrderRequest.setCorpId(thrInvWarehouseEntity.getCode());
                    dsOrderRequest.setCorpName(thrInvWarehouseEntity.getName());
                } catch (Exception e) {
                    String msg = "查询单据对应往来单位的第三方仓库信息异常";
                    orderUploadLogService.updateLocalErr(orderEntity, msg);
                    log.error("----单据提交-----" + orderEntity.getBillNo() + msg);
                    return ResultVOUtils.error(500, msg);
                }
            }

        } else if (basicBussinessTypeEntity.getCorpType().equals(Constants.CORP_SP)) {
            //供应商
            BasicCorpEntity basicCorpEntity = basicCorpDao.selectByErpId(orderEntity.getFromCorp());
            if (null != basicCorpEntity) {
                dsOrderRequest.setCorpId(basicCorpEntity.getThirdId());
                dsOrderRequest.setCorpName(basicCorpEntity.getName());

                List<ThrCorpEntity> thrCorpEntities = thrCorpDao.selectList(new QueryWrapper<ThrCorpEntity>().eq("name", basicCorpEntity.getThirdName()));
                if (CollUtil.isNotEmpty(thrCorpEntities)) {
                    for (ThrCorpEntity temp : thrCorpEntities) {
                        if (StrUtil.isNotEmpty(temp.getKfdm()) && temp.getKfdm().equals(udiwmsOrderRequest.getLocInvCode())) {
                            udiwmsOrderRequest.setCorpId(temp.getUnitId()); //往来单位编码，需转换为第三方系统的ID
                            udiwmsOrderRequest.setCorpName(temp.getName()); //往来单位名称，需转换为第三方系统的名称
                        }
                    }
                }

            } else {
                String msg = "查询单据对应的第三方往来单位信息异常";
                orderUploadLogService.updateLocalErr(orderEntity, msg);
                log.error("----单据提交-----" + orderEntity.getBillNo() + msg);
                return ResultVOUtils.error(500, msg);
            }


        }

//        //查询仓库信息
//        AuthWarehouseEntity warehouseEntity = authWarehouseDao.selectOne(new LambdaQueryWrapper<AuthWarehouseEntity>().eq(AuthWarehouseEntity::getCode, orderEntity.getInvCode()));
//        try {
//            ThrInvWarehouseEntity thrInvWarehouseEntity = thrInvWarehouseDao.selectOne(new LambdaQueryWrapper<ThrInvWarehouseEntity>()
//                    .eq(ThrInvWarehouseEntity::getCode, authWarehouseService.getThirdInvCode(warehouseEntity))
//                    .eq(ThrInvWarehouseEntity::getThirdSysFk, thirdSysConfig.getThirdId()));
//
//            dsOrderRequest.setLocInvCode(thrInvWarehouseEntity.getCode());
//            dsOrderRequest.setLocInvName(thrInvWarehouseEntity.getName());
//
//            dsOrderRequest.setLocStorageCode(thrInvWarehouseEntity.getCode());
//            dsOrderRequest.setLocStorageName(thrInvWarehouseEntity.getName());
//        } catch (Exception e) {
//            log.info("查询第三方系统仓库信息异常", e);
//        }

//        if (StrUtil.nullToEmpty(thrSystemBusApiEntity.getUrl()).equals("useOut")) {
//            dsOrderRequest.setCorpId(dsOrderRequest.getLocStorageCode());
//            dsOrderRequest.setCorpName(dsOrderRequest.getLocStorageName());
//
//            ThrInvWarehouseEntity thrInvWarehouseEntity = thrInvWarehouseDao.selectOne(new LambdaQueryWrapper<ThrInvWarehouseEntity>().eq(ThrInvWarehouseEntity::getCode, "29")
//                    .eq(ThrInvWarehouseEntity::getThirdSysFk, thirdSysConfig.getThirdId()));
//            dsOrderRequest.setLocStorageCode("29");
//            dsOrderRequest.setLocStorageName(thrInvWarehouseEntity.getName());
//        }

        dsOrderRequest.setBillFlag("1");
        //设置单据出入库类型
        if (basicBussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_PUT)) {
            dsOrderRequest.setInoutType(1); //入库
        } else if (basicBussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)) {
            dsOrderRequest.setInoutType(2); //出库
        }

        dsOrderRequest.setRemark("udi管理系统提交单据");

        //组装单据明细数据
        List<IoCodeEntity> ioCodeEntities = codeDao.selectList(new LambdaQueryWrapper<IoCodeEntity>()
                .eq(IoCodeEntity::getOrderId, orderEntity.getBillNo())
        );

        List<UdiwmsOrderDetailRequest> items = new ArrayList<>();
        //查询业务单据详情
        List<IoOrderDetailBizEntity> detailBizEntities = orderDetailBizDao.selectList(new LambdaQueryWrapper<IoOrderDetailBizEntity>().eq(IoOrderDetailBizEntity::getOrderIdFk, orderEntity.getBillNo()));

        for (IoOrderDetailBizEntity detailBizEntity : detailBizEntities) {

            //查询产品信息
            BasicUdirelEntity basicUdirel = basicUdirelDao.selectById(detailBizEntity.getBindRlFk());
            BasicProductsEntity basicProducts = basicProductsDao.selectOne(new LambdaQueryWrapper<BasicProductsEntity>().eq(BasicProductsEntity::getUuid, basicUdirel.getUuid()).last("limit 1"));

            UdiwmsOrderDetailRequest item = new UdiwmsOrderDetailRequest();
            BeanUtil.copyProperties(detailBizEntity, item);

            item.setProductDate(StrUtil.isBlank(detailBizEntity.getProductDate()) ? "19990101" : "20" + detailBizEntity.getProductDate());
            item.setExpireDate(StrUtil.isBlank(detailBizEntity.getExpireDate()) ? "20991231" : "20" + detailBizEntity.getExpireDate());

            String thirdProductId = (String) ReflectUtil.getFieldValue(basicUdirel, thirdSysConfig.getThirdId());
            item.setProductId(thirdProductId); //产品ID

            //查询第三方产品名称
            ThrProductsEntity thrProductsEntity = thrProductsDao.selectOne(new LambdaQueryWrapper<ThrProductsEntity>()
                    .eq(ThrProductsEntity::getCode, thirdProductId).last("limit 1"));
            if (thrProductsEntity == null) {
                String errMsg = "提交失败，错误信息：" + detailBizEntity.getCoName() + "产品DI未关联第三方产品信息";
                orderUploadLogService.updateLocalErr(orderEntity, errMsg);
                return ResultVOUtils.error(500, errMsg);
            }
            if (StrUtil.isEmpty(thrProductsEntity.getPrice())) {
                item.setPrice(new BigDecimal(0));
            } else
                item.setPrice(new BigDecimal(thrProductsEntity.getPrice()));


            String fphm = "";
            String fprq = null;
            List<IoOrderInvoiceEntity> invoiceList = IoOrderInvoiceEntity.builder().build()
                    .selectList(Wrappers.lambdaQuery(IoOrderInvoiceEntity.class).eq(IoOrderInvoiceEntity::getOrderIdFk, orderEntity.getBillNo())
                            .eq(IoOrderInvoiceEntity::getBindRlFk, detailBizEntity.getBindRlFk())
                            .eq(StrUtil.isNotEmpty(detailBizEntity.getBatchNo()), IoOrderInvoiceEntity::getBatchNo, detailBizEntity.getBatchNo()).
                                    groupBy(IoOrderInvoiceEntity::getInvoiceEncode));
            if (CollectionUtil.isNotEmpty(invoiceList)) {
                fphm = invoiceList.stream().map(IoOrderInvoiceEntity::getInvoiceEncode).collect(Collectors.joining(","));
                if (invoiceList.get(0).getInvoiceDate() != null)
                    fprq = DateUtil.formatDateTime(invoiceList.get(0).getInvoiceDate());
            }

            item.setFirstSalesInvNo(fphm);
            item.setSecSalesInvNo(fphm);
            item.setInvoiceDate(fprq);
            boolean isNeedFp = false;
            ThrOrderUploadBustypesEntity thrOrderUploadBustypesEntity = thrOrderUploadBustypesMapper.selectOne(new QueryWrapper<ThrOrderUploadBustypesEntity>().eq("action", basicBussinessTypeEntity.getAction()).last("limit 1"));
            if (thrOrderUploadBustypesEntity != null && IntUtil.value(thrOrderUploadBustypesEntity.getOrderStatus()) == 3) {
                isNeedFp = true;
            }
            if (basicBussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_PUT) && StrUtil.isEmpty(fphm) && isNeedFp) {
                String errMsg = "提交失败，错误信息：" + detailBizEntity.getCoName() + "发票缺失,请补齐后重新提交";
                orderUploadLogService.updateLocalErr(orderEntity, errMsg);
                return ResultVOUtils.error(500, errMsg);
            }

            item.setProductName(thrProductsEntity.getName()); //产品名称
            item.setBindRlFk(detailBizEntity.getBindRlFk());
            item.setStandard(detailBizEntity.getSpec()); //规格型号
            item.setBillNo(detailBizEntity.getOrderIdFk()); //单据号
            item.setRegisterNo(detailBizEntity.getCertCode()); //注册/备案证号
            item.setManufactory(basicProducts.getManufactory()); //生产厂家
            item.setMeasname(basicProducts.getMeasname()); //计量单位
            item.setAllowNoBatch(IntUtil.value(basicProducts.getAllowNoBatch())); //是否允许无批次号
            item.setManufactoryCode(thrProductsEntity.getManufactoryCode());
            item.setSupCode(thrProductsEntity.getSupCode());
            item.setCplb(thrProductsEntity.getFlbm());
            item.setCount(detailBizEntity.getCount());
            //封装条码信息
            submitOrderUtil.setCodeList(ioCodeEntities, detailBizEntity, item);
            items.add(item);
        }

        Collections.reverse(items);
        dsOrderRequest.setItem(items);

        return submitOrderUtil.submitOrder(orderEntity, dsOrderRequest);
    }


    @Override
    public BaseResponse getInvProducts(UdiwmsInvProductsRequest udiwmsInvProductsRequest) {
        String response = httpClient.postJson(thrSystemDetailService.getUrl(Constants.URL_NAME_INV_PI_URL), udiwmsInvProductsRequest);
        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse getWarehouse(UdiwmsWarehouseRequest udiwmsWarehouseRequest) {
        String response = httpClient.postJson(thrSystemDetailService.getUrl(Constants.URL_NAME_WAREHOUSE_QUERY_URL), udiwmsWarehouseRequest);
        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse postProducts(PostThrProductsRequest postThrProductsRequest) {
        postThrProductsRequest.setUploadType("文件导入");
        String response = httpClient.postUDIWMSJson(thirdSysConfig.getPostPiUrl(), postThrProductsRequest);
        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse postCorps(PostThrCorpRequest postThrCorpRequest) {
        postThrCorpRequest.setUploadType("文件导入");
        String response = httpClient.postUDIWMSJson(thirdSysConfig.getPostCorpUrl(), postThrCorpRequest);
        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse postOrderDetail(PostFileThrOrderRequest postFileThrOrderRequest) {
        postFileThrOrderRequest.setUploadType("文件导入");
        String response = httpClient.postUDIWMSJson(thirdSysConfig.getPostOrderUrl(), postFileThrOrderRequest);
        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse postInvProducts(PostThrInvProductsRequest postThrInvProductsRequest) {
        String response = httpClient.postUDIWMSJson(thirdSysConfig.getPostInvPiUrl(), postThrInvProductsRequest);
        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse testConnect() {
        UdiwmsUnitRequest udiwmsUnitRequest = new UdiwmsUnitRequest();
        udiwmsUnitRequest.setPage(1);
        udiwmsUnitRequest.setLimit(1);
        BaseResponse baseResponse = getUnit(udiwmsUnitRequest);
        if (baseResponse.getCode() == 20000) {
            return ResultVOUtils.success("连接成功");
        }
        return ResultVOUtils.error(500, "连接失败！");
    }

    @Override
    public BaseResponse queryUdiInvProducts(UdiwmsQueryUdiInvProductsRequest queryUdiInvProductsRequest) {
        String response = httpClient.postUDIWMSJson(thirdSysConfig.getQueryInvUrl(), queryUdiInvProductsRequest);
        BaseResponse baseResponse = JSONObject.parseObject(response, BaseResponse.class);
        return baseResponse;
    }

    @Override
    public BaseResponse submitProducts(UdiwmsAddProductsRequest udiwmsAddProductsRequest) {
        return null;
    }

    @Override
    public BaseResponse submitUnit(UdiwmsAddUnitRequest udiwmsAddUnitRequest) {
        return null;
    }

    @Override
    public BaseResponse submitPreInOrders(UdiwmsPreInOrderRequest udiwmsPreInOrderRequest) {
        return null;
    }
}
