package com.hzya.frame.u8c.Encapsulation.service.impl;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.basedao.service.impl.BaseService;
import com.hzya.frame.sysnew.application.database.dao.ISysApplicationDatabaseDao;
import com.hzya.frame.sysnew.application.database.entity.SysApplicationDatabaseEntity;
import com.hzya.frame.sysnew.application.entity.SysApplicationEntity;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
import com.hzya.frame.u8c.Encapsulation.dao.IEncapsulationDao;
import com.hzya.frame.u8c.Encapsulation.entity.EncapsulationEntity;
import com.hzya.frame.u8c.Encapsulation.service.IEncapsulationService;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * (BdCorp)表服务实现类
 *
 * @author makejava
 * @since 2023-09-06 14:47:18
 */
@Service("encapsulationImpl")
public class EncapsulationImpl extends BaseService<EncapsulationEntity, String> implements IEncapsulationService {

    private IEncapsulationDao encapsulationDao;

    @Autowired
    public void setEncapsulationDao(IEncapsulationDao dao) {
        this.encapsulationDao = dao;
        this.dao = dao;
    }
    @Resource
    private ISysApplicationDatabaseDao sysApplicationDatabaseDao;
    @Value("${zt.url}")
    private String ztUrl;
    private final Object lock = new Object();

    /**
     * @param object
     * @return java.lang.Object
     * @Author lvleigang
     * @Description 采购订单删除接口 8000350080
     * 0、根据采购订单号查询入库单号,1、库存采购入库单取消签字 8000350061，2、库存采购入库单删除 8000350058,3、采购订单弃审 8000350059,4、采购订单删除 8000350056
     *
     * @Date 9:44 上午 2024/9/4
     **/
    @Override
    public Object purchaseOrderDelete(JSONObject object) {
        JSONObject returnObject = new JSONObject();

        JSONObject jsonObject = getData("jsonStr", object, JSONObject.class);
        //判断是否存在参数
        if (!checkStr(jsonObject.getString("code"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("corp"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "公司为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_begin"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据开始日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_end"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据结束日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("coperator"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "操作员为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("cgrkqxqz"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存采购入库单取消签字接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("cgrksc"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存采购入库单删除接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("cgddqs"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "采购订单弃审接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("cgddsc"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "采购订单删除接口编号为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("dataSourceCode"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "数据源编码为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("publicKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "publicKey为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("secretKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "secretKey为空");
            return returnObject;
        }
        //根据采购订单号查询入库单号
        EncapsulationEntity encapsulationEntity = new EncapsulationEntity();
        encapsulationEntity.setCode(jsonObject.getString("code"));
        encapsulationEntity.setDataSourceCode(jsonObject.getString("dataSourceCode"));
        encapsulationEntity.setType("21");
        List<EncapsulationEntity> encapsulationEntities = encapsulationDao.queryCgrkddh(encapsulationEntity);
        if(encapsulationEntities == null || encapsulationEntities.size() != 1){
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "查到多条采购入库单");
            return returnObject;
        }
        //执行库存采购入库单取消签字接口
        String cgrkdqxqz = getsendBody("1", jsonObject, encapsulationEntities.get(0).getCode(),encapsulationEntities.get(0).getUnitcode());
        boolean cgrkdqxqzflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("cgrkqxqz"), jsonObject.getString("cgrkqxqz").substring(0,6), cgrkdqxqz);
        if (!cgrkdqxqzflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "采购入库单取消签字失败");
            return returnObject;
        }
        //执行库存采购入库单删除
        String cgrkdsc = getsendBody("2", jsonObject, encapsulationEntities.get(0).getCode(),encapsulationEntities.get(0).getUnitcode());
        boolean cgrkdscfiag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("cgrksc"), jsonObject.getString("cgrksc").substring(0,6), cgrkdsc);
        if (!cgrkdscfiag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "采购入库单删除失败");
            return returnObject;
        }
        //执行采购订单弃审
        String cgddqs = getsendBody("3", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean cgddqsflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("cgddqs"), jsonObject.getString("cgddqs").substring(0,6), cgddqs);
        if (!cgddqsflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "采购订单弃审失败");
            return returnObject;
        }
        //执行采购订单删除
        String cgddsc = getsendBody("4", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean cgddscflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("cgddsc"), jsonObject.getString("cgddsc").substring(0,6), cgddsc);
        if (cgddscflag) {
            returnObject.put("status", "success");
            returnObject.put("errormsg", "采购订单删除成功");
            return returnObject;
        } else {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "采购订单删除失败");
            return returnObject;
        }
    }
    /**
     * @param entity
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 数据表
     * @Date 11:52 上午 2024/3/27
     **/
    @Override
    public SysExtensionApiEntity addPurchaseOrderDelete(SysExtensionApiEntity entity) {
        try {
            Map<String, String> headers = entity.getHeaders();
            SysApplicationEntity applicationEntity = entity.getReceiveApp();
            SysApplicationDatabaseEntity sysApplicationDatabaseEntity = new SysApplicationDatabaseEntity();
            sysApplicationDatabaseEntity.setSts("Y");
            sysApplicationDatabaseEntity.setDbStatus("1");
            sysApplicationDatabaseEntity.setAppId(applicationEntity.getId());
            sysApplicationDatabaseEntity.setDataSourceCode("master");
            List<SysApplicationDatabaseEntity> sysDataSourceEntities = sysApplicationDatabaseDao.queryDSBase(sysApplicationDatabaseEntity);
            if(sysDataSourceEntities != null && sysDataSourceEntities.size() > 0){
                String parm = entity.getBodys();
                JSONObject jsonObject = JSONObject.parseObject(parm);
                jsonObject.put("dataSourceCode",sysDataSourceEntities.get(0).getSourceCode());
                jsonObject.put("publicKey",entity.getSendApp().getPublicKey());
                jsonObject.put("secretKey",entity.getSendApp().getSecretKey());

                jsonObject.put("cgrkqxqz",headers.get("cgrkqxqz"));
                jsonObject.put("cgrksc",headers.get("cgrksc"));
                jsonObject.put("cgddqs",headers.get("cgddqs"));
                jsonObject.put("cgddsc",headers.get("cgddsc"));
                entity.setBodys(jsonObject.toJSONString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return entity;
    }
    /**
     * @param object
     * @return java.lang.Object
     * @Author lvleigang
     * @Description 采购入库单删除接口 8000350081
     * 1、库存采购入库单取消签字 8000350061，2、库存采购入库单删除 8000350058
     * @Date 9:44 上午 2024/9/4
     **/
    @Override
    public Object purchaseWarehousingDelete(JSONObject object) {
        JSONObject returnObject = new JSONObject();

        JSONObject jsonObject = getData("jsonStr", object, JSONObject.class);
        //判断是否存在参数
        if (!checkStr(jsonObject.getString("code"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("corp"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "公司为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_begin"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据开始日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_end"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据结束日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("coperator"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "操作员为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("cgrkqxqz"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存采购入库单取消签字接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("cgrksc"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存采购入库单删除接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("dataSourceCode"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "数据源编码为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("publicKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "publicKey为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("secretKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "secretKey为空");
            return returnObject;
        }
        //执行库存采购入库单取消签字接口
        String cgrkdqxqz = getsendBody("1", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean cgrkdqxqzflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("cgrkqxqz"), jsonObject.getString("cgrkqxqz").substring(0,6), cgrkdqxqz);
        if (!cgrkdqxqzflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "采购入库单取消签字失败");
            return returnObject;
        }

        //执行库存采购入库单删除接口
        String cgrkdsc = getsendBody("2", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean cgrkdscfiag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("cgrksc"), jsonObject.getString("cgrksc").substring(0,6), cgrkdsc);
        if (cgrkdscfiag) {
            returnObject.put("status", "success");
            returnObject.put("errormsg", "采购入库单删除成功");
            return returnObject;
        } else {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "采购入库单删除失败");
            return returnObject;
        }
    }
    /**
     * @param entity
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 数据表
     * @Date 11:52 上午 2024/3/27
     **/
    @Override
    public SysExtensionApiEntity addPurchaseWarehousingDelete(SysExtensionApiEntity entity) {
        try {
            Map<String, String> headers = entity.getHeaders();
            SysApplicationEntity applicationEntity = entity.getReceiveApp();
            SysApplicationDatabaseEntity sysApplicationDatabaseEntity = new SysApplicationDatabaseEntity();
            sysApplicationDatabaseEntity.setSts("Y");
            sysApplicationDatabaseEntity.setDbStatus("1");
            sysApplicationDatabaseEntity.setAppId(applicationEntity.getId());
            sysApplicationDatabaseEntity.setDataSourceCode("master");
            List<SysApplicationDatabaseEntity> sysDataSourceEntities = sysApplicationDatabaseDao.queryDSBase(sysApplicationDatabaseEntity);
            if(sysDataSourceEntities != null && sysDataSourceEntities.size() > 0){
                String parm = entity.getBodys();
                JSONObject jsonObject = JSONObject.parseObject(parm);
                jsonObject.put("dataSourceCode",sysDataSourceEntities.get(0).getSourceCode());
                jsonObject.put("publicKey",entity.getSendApp().getPublicKey());
                jsonObject.put("secretKey",entity.getSendApp().getSecretKey());

                jsonObject.put("cgrkqxqz",headers.get("cgrkqxqz"));
                jsonObject.put("cgrksc",headers.get("cgrksc"));
                entity.setBodys(jsonObject.toJSONString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return entity;
    }
    /**
     * @param object
     * @return java.lang.Object
     * @Author lvleigang
     * @Description 销售订单删除接口  8000350082
     * 0、根据销售钉订单号查询出销售出库单号，1、库存销售出库单取消签字 8000350062 ,2、库存销售出库单删除 8000350063 ,3、销售订单取消审批 8000350064 ,4、销售订单删除 8000350065
     * @Date 9:44 上午 2024/9/4
     **/
    @Override
    public Object salesOrderDelete(JSONObject object) {
        JSONObject returnObject = new JSONObject();

        JSONObject jsonObject = getData("jsonStr", object, JSONObject.class);
        //判断是否存在参数
        if (!checkStr(jsonObject.getString("code"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("corp"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "公司为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_begin"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据开始日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_end"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据结束日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("coperator"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "操作员为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("kcxsckqxqz"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存销售出库单取消签字接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("kcxscksc"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存销售出库单删除接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("xsddqxsp"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "销售订单取消审批接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("xsddsc"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "销售订单删除接口编号为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("dataSourceCode"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "数据源编码为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("publicKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "publicKey为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("secretKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "secretKey为空");
            return returnObject;
        }
        //根据销售钉订单号查询出销售出库单号
        EncapsulationEntity encapsulationEntity = new EncapsulationEntity();
        encapsulationEntity.setCode(jsonObject.getString("code"));
        encapsulationEntity.setDataSourceCode(jsonObject.getString("dataSourceCode"));
        encapsulationEntity.setType("30");
        List<EncapsulationEntity> encapsulationEntities = encapsulationDao.queryCgrkddh(encapsulationEntity);
        if(encapsulationEntities == null || encapsulationEntities.size() != 1){
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "查到多条销售出库单");
            return returnObject;
        }
        //库存销售出库单取消签字,
        String cgrkdqxqz = getsendBody("1", jsonObject, encapsulationEntities.get(0).getCode(), encapsulationEntities.get(0).getUnitcode());
        boolean cgrkdqxqzflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("kcxsckqxqz"), jsonObject.getString("kcxsckqxqz").substring(0,6), cgrkdqxqz);
        if (!cgrkdqxqzflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存销售出库单取消签字失败");
            return returnObject;
        }
        //库存销售出库单删除
        String cgrkdsc = getsendBody("2", jsonObject, encapsulationEntities.get(0).getCode(), encapsulationEntities.get(0).getUnitcode());
        boolean cgrkdscfiag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("kcxscksc"), jsonObject.getString("kcxscksc").substring(0,6), cgrkdsc);
        if (!cgrkdscfiag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存销售出库单删除失败");
            return returnObject;
        }
        //销售订单取消审批,,
        String cgddqs = getsendBody("3", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean cgddqsflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("xsddqxsp"), jsonObject.getString("xsddqxsp").substring(0,6), cgddqs);
        if (!cgddqsflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "销售订单取消审批失败");
            return returnObject;
        }
        //销售订单删除
        String cgddsc = getsendBody("4", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean cgddscflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("xsddsc"), jsonObject.getString("xsddsc").substring(0,6), cgddsc);
        if (cgddscflag) {
            returnObject.put("status", "success");
            returnObject.put("errormsg", "销售订单删除成功");
            return returnObject;
        } else {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "销售订单删除失败");
            return returnObject;
        }
    }
    /**
     * @param entity
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 数据表
     * @Date 11:52 上午 2024/3/27
     **/
    @Override
    public SysExtensionApiEntity addSalesOrderDelete(SysExtensionApiEntity entity) {
        try {
            Map<String, String> headers = entity.getHeaders();
            SysApplicationEntity applicationEntity = entity.getReceiveApp();
            SysApplicationDatabaseEntity sysApplicationDatabaseEntity = new SysApplicationDatabaseEntity();
            sysApplicationDatabaseEntity.setSts("Y");
            sysApplicationDatabaseEntity.setDbStatus("1");
            sysApplicationDatabaseEntity.setAppId(applicationEntity.getId());
            sysApplicationDatabaseEntity.setDataSourceCode("master");
            List<SysApplicationDatabaseEntity> sysDataSourceEntities = sysApplicationDatabaseDao.queryDSBase(sysApplicationDatabaseEntity);
            if(sysDataSourceEntities != null && sysDataSourceEntities.size() > 0){
                String parm = entity.getBodys();
                JSONObject jsonObject = JSONObject.parseObject(parm);
                jsonObject.put("dataSourceCode",sysDataSourceEntities.get(0).getSourceCode());
                jsonObject.put("publicKey",entity.getSendApp().getPublicKey());
                jsonObject.put("secretKey",entity.getSendApp().getSecretKey());

                jsonObject.put("kcxsckqxqz",headers.get("kcxsckqxqz"));
                jsonObject.put("kcxscksc",headers.get("kcxscksc"));
                jsonObject.put("xsddqxsp",headers.get("xsddqxsp"));
                jsonObject.put("xsddsc",headers.get("xsddsc"));
                entity.setBodys(jsonObject.toJSONString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return entity;
    }
    /**
     * @param object
     * @return java.lang.Object
     * @Author lvleigang
     * @Description 调拨订单删除接口 8000350083
     *
     * 0、根据调拨订单号查询调拨入库，调拨出库单据，1、库存调拨出库取消签字 8000350066 2、库存调拨出库删除 8000350067
     * 3、调拨入库取消签字 8000350068 4、调拨入库删除 8000350069 5、调拨订单弃审 8000350070 6、调拨订单删除 8000350071
     * @Date 9:44 上午 2024/9/4
     **/
    @Override
    public Object transferOrderDelete(JSONObject object) {
        JSONObject returnObject = new JSONObject();
        JSONObject jsonObject = getData("jsonStr", object, JSONObject.class);
        //判断是否存在参数
        if (!checkStr(jsonObject.getString("code"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("corp"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "公司为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_begin"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据开始日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_end"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据结束日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("coperator"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "操作员为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("kcdbckqxqz"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存调拨出库取消签字接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("kcdbcksc"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存调拨出库删除删除接口编号为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("dbrkqxqz"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "调拨入库取消签字接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("dbrksc"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "调拨入库删除接口编号为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("dbddqs"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "调拨订单弃审接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("dbddsc"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "调拨订单删除接口编号为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("dataSourceCode"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "数据源编码为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("publicKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "publicKey为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("secretKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "secretKey为空");
            return returnObject;
        }
        //根据调拨订单号查询调拨入库
        EncapsulationEntity rk = new EncapsulationEntity();
        rk.setCode(jsonObject.getString("code"));
        rk.setDataSourceCode(jsonObject.getString("dataSourceCode"));
        rk.setCbilltypecode("4E");
        List<EncapsulationEntity> rklist = encapsulationDao.queryCgrkddh(rk);
        if(rklist == null || rklist.size() != 1){
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "查到多条调拨入库单");
            return returnObject;
        }
        //根据调拨订单号查询调拨出库
        EncapsulationEntity ck = new EncapsulationEntity();
        ck.setCode(jsonObject.getString("code"));
        ck.setDataSourceCode(jsonObject.getString("dataSourceCode"));
        ck.setCbilltypecode("4Y");
        List<EncapsulationEntity> cklist = encapsulationDao.queryCgrkddh(ck);
        if(cklist == null || cklist.size() != 1){
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "查到多条调拨出库单");
            return returnObject;
        }
        //调拨入库取消签字
        String dbrk = getsendBody("1", jsonObject, rklist.get(0).getCode(),rklist.get(0).getUnitcode());
        boolean dbrkflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("dbrkqxqz"), jsonObject.getString("dbrkqxqz").substring(0,6), dbrk);
        if (!dbrkflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "调拨入库取消签字失败");
            return returnObject;
        }
        //调拨入库删除
        String dbrksc = getsendBody("2", jsonObject, rklist.get(0).getCode(), rklist.get(0).getUnitcode());
        boolean dbrkscflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("dbrksc"), jsonObject.getString("dbrksc").substring(0,6), dbrksc);
        if (!dbrkscflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "调拨入库删除失败");
            return returnObject;
        }
        //库存调拨出库取消签字
        String dbck = getsendBody("1", jsonObject, cklist.get(0).getCode(), cklist.get(0).getUnitcode());
        boolean dbckflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("kcdbckqxqz"), jsonObject.getString("kcdbckqxqz").substring(0,6), dbck);
        if (!dbckflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存调拨出库取消签字失败");
            return returnObject;
        }
        //库存调拨出库删除
        String dbcksc = getsendBody("2", jsonObject, cklist.get(0).getCode(), cklist.get(0).getUnitcode());
        boolean dbckscflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("kcdbcksc"), jsonObject.getString("kcdbcksc").substring(0,6), dbcksc);
        if (!dbckscflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存调拨出库删除失败");
            return returnObject;
        }
        //调拨订单弃审
        String dbdd = getsendBody("3", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean dbddflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("dbddqs"), jsonObject.getString("dbddqs").substring(0,6), dbdd);
        if (!dbddflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "调拨订单弃审失败");
            return returnObject;
        }
        //调拨订单删除
        String dbddsc = getsendBody("4", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean dbddscflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("dbddsc"), jsonObject.getString("dbddsc").substring(0,6), dbddsc);
        if (!dbddscflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "调拨订单删除失败");
            return returnObject;
        }

        returnObject.put("status", "success");
        returnObject.put("errormsg", "调拨订单删除成功");
        return returnObject;


    }
    /**
     * @param entity
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 数据表
     * @Date 11:52 上午 2024/3/27
     **/
    @Override
    public SysExtensionApiEntity addTransferOrderDelete(SysExtensionApiEntity entity) {
        try {
            Map<String, String> headers = entity.getHeaders();
            SysApplicationEntity applicationEntity = entity.getReceiveApp();
            SysApplicationDatabaseEntity sysApplicationDatabaseEntity = new SysApplicationDatabaseEntity();
            sysApplicationDatabaseEntity.setSts("Y");
            sysApplicationDatabaseEntity.setDbStatus("1");
            sysApplicationDatabaseEntity.setAppId(applicationEntity.getId());
            sysApplicationDatabaseEntity.setDataSourceCode("master");
            List<SysApplicationDatabaseEntity> sysDataSourceEntities = sysApplicationDatabaseDao.queryDSBase(sysApplicationDatabaseEntity);
            if(sysDataSourceEntities != null && sysDataSourceEntities.size() > 0){
                String parm = entity.getBodys();
                JSONObject jsonObject = JSONObject.parseObject(parm);
                jsonObject.put("dataSourceCode",sysDataSourceEntities.get(0).getSourceCode());
                jsonObject.put("publicKey",entity.getSendApp().getPublicKey());
                jsonObject.put("secretKey",entity.getSendApp().getSecretKey());

                jsonObject.put("kcdbckqxqz",headers.get("kcdbckqxqz"));
                jsonObject.put("kcdbcksc",headers.get("kcdbcksc"));
                jsonObject.put("dbrkqxqz",headers.get("dbrkqxqz"));
                jsonObject.put("dbrksc",headers.get("dbrksc"));
                jsonObject.put("dbddqs",headers.get("dbddqs"));
                jsonObject.put("dbddsc",headers.get("dbddsc"));
                entity.setBodys(jsonObject.toJSONString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return entity;
    }
    /**
     * @param object
     * @return java.lang.Object
     * @Author lvleigang
     * @Description 产成品入库删除接口 8000350084
     * 1、库存产成品入库单取消签字 8000350072 2、库存产成品入库单删除 8000350073
     * @Date 9:44 上午 2024/9/4
     **/
    @Override
    public Object finishedProductsAreStoredDelete(JSONObject object) {
        JSONObject returnObject = new JSONObject();
        JSONObject jsonObject = getData("jsonStr", object, JSONObject.class);
        //判断是否存在参数
        if (!checkStr(jsonObject.getString("code"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("corp"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "公司为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_begin"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据开始日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_end"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据结束日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("coperator"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "操作员为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("kcccprkqxqz"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存产成品入库单取消签字接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("kcccprksc"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存产成品入库单删除接口编号为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("dataSourceCode"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "数据源编码为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("publicKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "publicKey为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("secretKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "secretKey为空");
            return returnObject;
        }

        //库存产成品入库单取消签字
        String qxqz = getsendBody("1", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean qxqzflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("kcccprkqxqz"), jsonObject.getString("kcccprkqxqz").substring(0,6), qxqz);
        if (!qxqzflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存产成品入库单取消签字失败");
            return returnObject;
        }
        //库存产成品入库单删除
        String sc = getsendBody("2", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean scflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("kcccprksc"), jsonObject.getString("kcccprksc").substring(0,6), sc);
        if (!scflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存产成品入库单删除失败");
            return returnObject;
        }

        returnObject.put("status", "success");
        returnObject.put("errormsg", "库存产成品入库删除成功");
        return returnObject;

    }
    /**
     * @param entity
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 数据表
     * @Date 11:52 上午 2024/3/27
     **/
    @Override
    public SysExtensionApiEntity addFinishedProductsAreStoredDelete(SysExtensionApiEntity entity) {
        try {
            Map<String, String> headers = entity.getHeaders();
            SysApplicationEntity applicationEntity = entity.getReceiveApp();
            SysApplicationDatabaseEntity sysApplicationDatabaseEntity = new SysApplicationDatabaseEntity();
            sysApplicationDatabaseEntity.setSts("Y");
            sysApplicationDatabaseEntity.setDbStatus("1");
            sysApplicationDatabaseEntity.setAppId(applicationEntity.getId());
            sysApplicationDatabaseEntity.setDataSourceCode("master");
            List<SysApplicationDatabaseEntity> sysDataSourceEntities = sysApplicationDatabaseDao.queryDSBase(sysApplicationDatabaseEntity);
            if(sysDataSourceEntities != null && sysDataSourceEntities.size() > 0){
                String parm = entity.getBodys();
                JSONObject jsonObject = JSONObject.parseObject(parm);
                jsonObject.put("dataSourceCode",sysDataSourceEntities.get(0).getSourceCode());
                jsonObject.put("publicKey",entity.getSendApp().getPublicKey());
                jsonObject.put("secretKey",entity.getSendApp().getSecretKey());

                jsonObject.put("kcccprkqxqz",headers.get("kcccprkqxqz"));
                jsonObject.put("kcccprksc",headers.get("kcccprksc"));
                entity.setBodys(jsonObject.toJSONString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return entity;
    }
    /**
     * @param object
     * @return java.lang.Object
     * @Author lvleigang
     * @Description 材料出库删除接口  8000350085
     * 1、库存材料出库取消签字 8000350074 2、库存材料出库单删除 8000350075
     * @Date 9:44 上午 2024/9/4
     **/
    @Override
    public Object materialDeliveryDelete(JSONObject object) {
        JSONObject returnObject = new JSONObject();
        JSONObject jsonObject = getData("jsonStr", object, JSONObject.class);
        //判断是否存在参数
        if (!checkStr(jsonObject.getString("code"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("corp"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "公司为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_begin"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据开始日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_end"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据结束日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("coperator"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "操作员为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("qxqzApi"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存材料出库取消签字接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("scApi"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存材料出库单删除接口编号为空");
            return returnObject;
        }

        if (!checkStr(jsonObject.getString("dataSourceCode"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "数据源编码为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("publicKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "publicKey为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("secretKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "secretKey为空");
            return returnObject;
        }

        //库存材料出库取消签字
        String qxqz = getsendBody("1", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean qxqzflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("qxqzApi"), jsonObject.getString("qxqzApi").substring(0,6), qxqz);
        if (!qxqzflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存材料出库取消签字失败");
            return returnObject;
        }
        //库存材料出库单删除
        String sc = getsendBody("2", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean scflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("scApi"), jsonObject.getString("scApi").substring(0,6), sc);
        if (!scflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存材料出库单删除失败");
            return returnObject;
        }

        returnObject.put("status", "success");
        returnObject.put("errormsg", "库存材料出库删除成功");
        return returnObject;

    }
    /**
     * @param entity
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 数据表
     * @Date 11:52 上午 2024/3/27
     **/
    @Override
    public SysExtensionApiEntity addMaterialDeliveryDelete(SysExtensionApiEntity entity) {
        try {
            Map<String, String> headers = entity.getHeaders();
            SysApplicationEntity applicationEntity = entity.getReceiveApp();
            SysApplicationDatabaseEntity sysApplicationDatabaseEntity = new SysApplicationDatabaseEntity();
            sysApplicationDatabaseEntity.setSts("Y");
            sysApplicationDatabaseEntity.setDbStatus("1");
            sysApplicationDatabaseEntity.setAppId(applicationEntity.getId());
            sysApplicationDatabaseEntity.setDataSourceCode("master");
            List<SysApplicationDatabaseEntity> sysDataSourceEntities = sysApplicationDatabaseDao.queryDSBase(sysApplicationDatabaseEntity);
            if(sysDataSourceEntities != null && sysDataSourceEntities.size() > 0){
                String parm = entity.getBodys();
                JSONObject jsonObject = JSONObject.parseObject(parm);
                jsonObject.put("dataSourceCode",sysDataSourceEntities.get(0).getSourceCode());
                jsonObject.put("publicKey",entity.getSendApp().getPublicKey());
                jsonObject.put("secretKey",entity.getSendApp().getSecretKey());

                jsonObject.put("qxqzApi",headers.get("qxqzApi"));
                jsonObject.put("scApi",headers.get("scApi"));
                entity.setBodys(jsonObject.toJSONString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return entity;
    }
    /**
     * @param object
     * @return java.lang.Object
     * @Author lvleigang
     * @Description 其他出库单删除接口 8000350086
     * 1、库存其他出库取消签字 8000350076 2、库存其他出库删除 8000350077
     * @Date 9:44 上午 2024/9/4
     **/
    @Override
    public Object otherWarehouseOrdersDelete(JSONObject object) {
        JSONObject returnObject = new JSONObject();
        JSONObject jsonObject = getData("jsonStr", object, JSONObject.class);
        //判断是否存在参数
        if (!checkStr(jsonObject.getString("code"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("corp"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "公司为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_begin"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据开始日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_end"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据结束日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("coperator"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "操作员为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("qxqzApi"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存其他出库取消签字接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("scApi"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存其他出库删除接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("dataSourceCode"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "数据源编码为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("publicKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "publicKey为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("secretKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "secretKey为空");
            return returnObject;
        }

        //库存其他出库取消签字
        String qxqz = getsendBody("1", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean qxqzflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("qxqzApi"), jsonObject.getString("qxqzApi").substring(0,6), qxqz);
        if (!qxqzflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存其他出库取消签字失败");
            return returnObject;
        }
        //库存其他出库删除
        String sc = getsendBody("2", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean scflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("scApi"), jsonObject.getString("scApi").substring(0,6), sc);
        if (!scflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存其他出库删除失败");
            return returnObject;
        }

        returnObject.put("status", "success");
        returnObject.put("errormsg", "库存其他出库删除成功");
        return returnObject;

    }
    /**
     * @param entity
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 数据表
     * @Date 11:52 上午 2024/3/27
     **/
    @Override
    public SysExtensionApiEntity addOtherWarehouseOrdersDelete(SysExtensionApiEntity entity) {
        try {
            Map<String, String> headers = entity.getHeaders();
            SysApplicationEntity applicationEntity = entity.getReceiveApp();
            SysApplicationDatabaseEntity sysApplicationDatabaseEntity = new SysApplicationDatabaseEntity();
            sysApplicationDatabaseEntity.setSts("Y");
            sysApplicationDatabaseEntity.setDbStatus("1");
            sysApplicationDatabaseEntity.setAppId(applicationEntity.getId());
            sysApplicationDatabaseEntity.setDataSourceCode("master");
            List<SysApplicationDatabaseEntity> sysDataSourceEntities = sysApplicationDatabaseDao.queryDSBase(sysApplicationDatabaseEntity);
            if(sysDataSourceEntities != null && sysDataSourceEntities.size() > 0){
                String parm = entity.getBodys();
                JSONObject jsonObject = JSONObject.parseObject(parm);
                jsonObject.put("dataSourceCode",sysDataSourceEntities.get(0).getSourceCode());
                jsonObject.put("publicKey",entity.getSendApp().getPublicKey());
                jsonObject.put("secretKey",entity.getSendApp().getSecretKey());

                jsonObject.put("qxqzApi",headers.get("qxqzApi"));
                jsonObject.put("scApi",headers.get("scApi"));
                entity.setBodys(jsonObject.toJSONString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return entity;
    }
    /**
     * @param object
     * @return java.lang.Object
     * @Author lvleigang
     * @Description 其他入库单删除接口 8000350087
     * 1、库存其他入库单取消签字.8000350078 2、库存其他入库删除 8000350079
     * @Date 9:44 上午 2024/9/4
     **/
    @Override
    public Object otherWarehouseReceiptDelete(JSONObject object) {
        JSONObject returnObject = new JSONObject();
        JSONObject jsonObject = getData("jsonStr", object, JSONObject.class);
        //判断是否存在参数
        if (!checkStr(jsonObject.getString("code"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("corp"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "公司为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_begin"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据开始日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("date_end"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "单据结束日期为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("coperator"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "操作员为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("qxqzApi"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存其他入库单取消签字接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("scApi"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存其他入库删除接口编号为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("dataSourceCode"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "数据源编码为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("publicKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "publicKey为空");
            return returnObject;
        }
        if (!checkStr(jsonObject.getString("secretKey"))) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "secretKey为空");
            return returnObject;
        }

        //库存其他入库单取消签字
        String qxqz = getsendBody("1", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean qxqzflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("qxqzApi"), jsonObject.getString("qxqzApi").substring(0,6), qxqz);
        if (!qxqzflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存其他入库单取消签字失败");
            return returnObject;
        }
        //库存其他入库删除
        String sc = getsendBody("2", jsonObject, jsonObject.getString("code"), jsonObject.getString("corp"));
        boolean scflag = sendPost(jsonObject.getString("publicKey"), jsonObject.getString("secretKey"), jsonObject.getString("scApi"), jsonObject.getString("scApi").substring(0,6), sc);
        if (!scflag) {
            returnObject.put("status", "falied");
            returnObject.put("errormsg", "库存其他入库删除失败");
            return returnObject;
        }
        returnObject.put("status", "success");
        returnObject.put("errormsg", "库存其他入库删除成功");
        return returnObject;
    }
    /**
     * @param entity
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 数据表
     * @Date 11:52 上午 2024/3/27
     **/
    @Override
    public SysExtensionApiEntity addOtherWarehouseReceiptDelete(SysExtensionApiEntity entity) {
        try {
            Map<String, String> headers = entity.getHeaders();
            SysApplicationEntity applicationEntity = entity.getReceiveApp();
            SysApplicationDatabaseEntity sysApplicationDatabaseEntity = new SysApplicationDatabaseEntity();
            sysApplicationDatabaseEntity.setSts("Y");
            sysApplicationDatabaseEntity.setDbStatus("1");
            sysApplicationDatabaseEntity.setAppId(applicationEntity.getId());
            sysApplicationDatabaseEntity.setDataSourceCode("master");
            List<SysApplicationDatabaseEntity> sysDataSourceEntities = sysApplicationDatabaseDao.queryDSBase(sysApplicationDatabaseEntity);
            if(sysDataSourceEntities != null && sysDataSourceEntities.size() > 0){
                String parm = entity.getBodys();
                JSONObject jsonObject = JSONObject.parseObject(parm);
                jsonObject.put("dataSourceCode",sysDataSourceEntities.get(0).getSourceCode());
                jsonObject.put("publicKey",entity.getSendApp().getPublicKey());
                jsonObject.put("secretKey",entity.getSendApp().getSecretKey());

                jsonObject.put("qxqzApi",headers.get("qxqzApi"));
                jsonObject.put("scApi",headers.get("scApi"));
                entity.setBodys(jsonObject.toJSONString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return entity;
    }

    //拼装数据
    private String getsendBody(String type, JSONObject object, String code,String unitcode) {
        JSONObject jsonObject1 = new JSONObject();

        switch (type) {
            case "1": //取消签字参数类型1、库存采购入库单取消签字 2\库存销售出库单取消签字 3\库存调拨出库取消签字4\调拨入库取消签字 5\库存产成品入库单取消签字
                //6\库存材料出库取消签字  7\库存其他出库取消签字  8\库存其他入库单取消签字
                JSONObject unsignInfo = new JSONObject();
                unsignInfo.put("coperator", object.getString("coperator"));

                JSONObject queryInfo = new JSONObject();
                queryInfo.put("date_end", object.getString("date_end"));
                queryInfo.put("date_begin", object.getString("date_begin"));
                queryInfo.put("corp", unitcode);
                queryInfo.put("billcode", code);

                jsonObject1.put("unsignInfo", unsignInfo);
                jsonObject1.put("queryInfo", queryInfo);
                break;
            case "2": //删除接口1、库存采购入库单删除 2\库存销售出库单删除 3\库存调拨出库删除 4\调拨入库删除 5\库存产成品入库单删除
                //6\库存材料出库单删除  7\库存其他出库删除  8\库存其他入库删除
                JSONObject unsignInfo2 = new JSONObject();
                unsignInfo2.put("coperator", object.getString("coperator"));

                JSONObject queryInfo2 = new JSONObject();
                queryInfo2.put("date_end", object.getString("date_end"));
                queryInfo2.put("date_begin", object.getString("date_begin"));
                queryInfo2.put("corp", unitcode);
                queryInfo2.put("billcode", code);

                jsonObject1.put("deleteInfo", unsignInfo2);
                jsonObject1.put("queryInfo", queryInfo2);
                break;
            case "3": //弃审 1、采购订单弃审 2\销售订单取消审批 3\调拨订单弃审
                JSONObject unsignInfo3 = new JSONObject();
                unsignInfo3.put("approvid", object.getString("coperator"));

                JSONObject queryInfo3 = new JSONObject();
                queryInfo3.put("date_end", object.getString("date_end"));
                queryInfo3.put("date_begin", object.getString("date_begin"));
                queryInfo3.put("corp", unitcode);
                queryInfo3.put("code", code);

                jsonObject1.put("approveinfo", unsignInfo3);
                jsonObject1.put("queryinfo", queryInfo3);
                break;
            case "4": //删除 1\采购订单删除 2\销售订单删除 3\调拨订单删除
                JSONObject unsignInfo4 = new JSONObject();
                unsignInfo4.put("coperator", object.getString("coperator"));

                JSONObject queryInfo4 = new JSONObject();
                queryInfo4.put("date_end", object.getString("date_end"));
                queryInfo4.put("date_begin", object.getString("date_begin"));
                queryInfo4.put("corp", unitcode);
                queryInfo4.put("code", code);

                jsonObject1.put("deleteinfo", unsignInfo4);
                jsonObject1.put("queryinfo", queryInfo4);
                break;
            default:
        }
        return jsonObject1.toJSONString();
    }

    /**
     * @param publicKey
     * @param secretKey
     * @param apiCode
     * @param appId
     * @param bodys
     * @return java.lang.String
     * @Author lvleigang
     * @Description 发送接口
     * @Date 3:05 下午 2024/9/4
     **/
    private boolean sendPost(String publicKey, String secretKey, String apiCode, String appId, String bodys) {

        StringBuilder returnBody = new StringBuilder();
        Integer outTime = 6000;
        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        // HttpClient
        CloseableHttpClient closeableHttpClient = httpClientBuilder.disableCookieManagement().build();
        HttpPost post = new HttpPost(ztUrl);
        CloseableHttpResponse response = null;
        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(outTime).build();
        post.setConfig(requestConfig);//设置请求参数【超时时间】
        post.setHeader("publicKey", publicKey);
        post.setHeader("secretKey", secretKey);
        post.setHeader("apiCode", apiCode);
        post.setHeader("appId", appId);

        try {
            if (bodys != null && !"".equals(bodys)) {
                ByteArrayEntity entity = new ByteArrayEntity(bodys.getBytes("UTF-8"));
                entity.setContentType("application/json");
                post.setEntity(entity);
            }
            response = closeableHttpClient.execute(post);

            HttpEntity entity = response.getEntity();
            synchronized (lock) {
                returnBody.append(EntityUtils.toString(entity, "UTF-8"));
            }
            logger.info("返回结果：" + returnBody);
        } catch (Exception e) {
            logger.error("请求错误：" + e.getMessage());
            returnBody.append(e.getMessage());
        } finally {
            try {
                // 关闭响应对象
                if (response != null) {
                    response.close();
                }
                // 关闭响应对象
                if (closeableHttpClient != null) {
                    closeableHttpClient.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

        if (returnBody != null && !"".equals(returnBody)) {
            if (JSONUtil.isTypeJSON(returnBody.toString())) {
                JSONObject jsonObject1 = JSONObject.parseObject(returnBody.toString());
                if (jsonObject1.getString("status") != null && "200".equals(jsonObject1.getString("status"))) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    }


}
