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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.basedao.service.impl.BaseService;
import com.hzya.frame.u8c.ax.dao.IAxDao;
import com.hzya.frame.u8c.ax.entity.*;
import com.hzya.frame.u8c.ax.service.IAxService;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
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.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * (BdCorp)表服务实现类
 *
 * @author makejava
 * @since 2023-09-06 14:47:18
 */
@Service("axServiceImpl")
public class AxServiceImpl extends BaseService<ArchivesEntity, String> implements IAxService {
    private IAxDao axDao;

    @Autowired
    public void setAxDao(IAxDao dao) {
        this.axDao = dao;
        this.dao = dao;
    }

    @Value("${zt.url}")
    private String voucherUrl;
    private final String publicKey = "ZJYAWb7lhAUTYqekPkU+uHJv1/ObJxb7dT7sD8HPRDGAgyhCe7eDIk+3zDUT+v578prj";
    private final String secretKey = "fviZnLBsQUAGF8w8FSOdJi7XlIm/XAZclMxRagDLfTyJFlvnIBF3w66Hrpfzs8cYj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=";
    private final String appId = "800016";
    private final String pzApiCodexz = "8000160014";//凭证新增
    private final String pzApiCodexg = "8000160031";//凭证修改
    private final String pzApiCodesc = "8000160033";//凭证删除
    private final String pzApiCodezf = "8000160032";//凭证作废

    private final String ryApiCodexz = "8000160029";//人员对照新增
    private final String ryApiCodexg = "8000160029";//人员对照修改
    private final String ryApiCodesc = "8000160030";//人员对照删除

    private final String bmApiCodexz = "8000160015";//部门档案新增
    private final String bmApiCodexg = "8000160016";//部门档案修改
    private final String bmApiCodesc = "8000160017";//部门档案删除

    private final String chApiCodexz = "8000160025";//存货对照新增
    private final String chApiCodexg = "8000160026";//存货对照修改
    private final String chApiCodesc = "8000160027";//存货对照删除

    private final String ksApiCodexz = "8000160018";//客商辅助核算新增
    private final String ksApiCodexg = "8000160019";//客商辅助核算修改
    private final String ksApiCodesc = "8000160020";//客商辅助核算删除

    private final String slApiCodexz = "8000160014";//税率新增
    private final String slApiCodexg = "8000160014";//税率修改
    private final String slApiCodesc = "8000160014";//税率删除

    private final String xmApiCodexz = "8000160021";//项目辅助核算新增
    private final String xmApiCodexg = "8000160022";//项目辅助核算修改
    private final String xmApiCodesc = "8000160023";//项目辅助核算删除

    private final String yhlbApiCodexz = "8000160014";//银行类别新增
    private final String yhlbApiCodexg = "8000160014";//银行类别修改
    private final String yhlbApiCodesc = "8000160014";//银行类别删除

    private final String yhzhApiCodexz = "8000160014";//银行账户新增
    private final String yhzhApiCodexg = "8000160014";//银行账户修改
    private final String yhzhApiCodesc = "8000160014";//银行账户删除

    private final String zcApiCodexz = "8000160014";//资产类别新增
    private final String zcApiCodexg = "8000160014";//资产类别修改
    private final String zcApiCodesc = "8000160014";//资产类别删除

    private final Object lock = new Object();

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 凭证新增
     * @Date 3:42 下午 2024/4/24
     **/
    @Override
    public Object thirdInterfaceVoucherInsert(JSONObject object) {
        JSONObject jsonObject = object.getJSONObject("jsonStr");
        if (jsonObject == null) {
            return BaseResult.getFailureMessageEntity("数据为空，请先传递数据");
        }
        if (!checkStr(jsonObject.getString("voucherType"))) {
            return BaseResult.getFailureMessageEntity("voucherType为空");
        }
        if (!checkStr(jsonObject.getString("usercode"))) {
            return BaseResult.getFailureMessageEntity("usercode为空");
        }
        if (!checkStr(jsonObject.getString("password"))) {
            return BaseResult.getFailureMessageEntity("password为空");
        }
        if (!checkStr(jsonObject.getString("trantype"))) {
            return BaseResult.getFailureMessageEntity("trantype为空");
        }
        if (!checkStr(jsonObject.getString("system"))) {
            return BaseResult.getFailureMessageEntity("system为空");
        }
        if (!checkStr(jsonObject.getString("data"))) {
            return BaseResult.getFailureMessageEntity("data为空");
        }
        String bodys = jsonObject.getString("data");
        List<String> fzhs = Arrays.asList(new String[]{"1", "2", "6", "73", "D01", "jobass", "93", "96", "22"});
        switch (jsonObject.getString("voucherType")) {
            case "add"://新增
                VoucherRoot entity1 = getData("data", jsonObject, VoucherRoot.class);
                if (entity1 == null || entity1.getVoucher() == null || entity1.getVoucher().size() == 0) {
                    return BaseResult.getFailureMessageEntity("data为空");
                }
                for (int i = 0; i < entity1.getVoucher().size(); i++) {
                    Voucher voucher = entity1.getVoucher().get(i);
                    if (voucher.getDetails() != null && voucher.getDetails().size() > 0) {
                        for (int a = 0; a < voucher.getDetails().size(); a++) {
                            VoucherDetails voucherDetails = voucher.getDetails().get(a);
                            if (voucherDetails.getAss() != null && voucherDetails.getAss().size() > 0) {
                                for (int b = 0; b < voucherDetails.getAss().size(); b++) {
                                    Ass ass = voucherDetails.getAss().get(b);
                                    if (ass.getChecktypecode() != null && !"".equals(ass.getChecktypecode())) {
                                        //存在需要转换的
                                        if (fzhs.contains(ass.getChecktypecode())) {
                                            ArchivesEntity archivesEntity = new ArchivesEntity();
                                            archivesEntity.setArchivesType(ass.getChecktypecode());
                                            archivesEntity.setLeftCode(ass.getCheckvaluecode());
                                            archivesEntity.setLeftOrg(voucher.getPk_corp());

                                            List<ArchivesEntity> archivesEntities = axDao.queryArchivesData(archivesEntity);
                                            if (archivesEntities != null && archivesEntities.size() > 0) {
                                                ass.setCheckvaluecode(archivesEntities.get(0).getRightCode());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                bodys = JSON.toJSONString(entity1);
                break;
            case "update"://修改
                VoucherRoot entity = getData("data", jsonObject, VoucherRoot.class);
                if (entity == null || entity.getVoucher() == null || entity.getVoucher().size() == 0) {
                    return BaseResult.getFailureMessageEntity("data为空");
                }
                for (int i = 0; i < entity.getVoucher().size(); i++) {
                    Voucher voucher = entity.getVoucher().get(i);
                    if (voucher.getDetails() != null && voucher.getDetails().size() > 0) {
                        for (int a = 0; a < voucher.getDetails().size(); a++) {
                            VoucherDetails voucherDetails = voucher.getDetails().get(a);
                            if (voucherDetails.getAss() != null && voucherDetails.getAss().size() > 0) {
                                for (int b = 0; b < voucherDetails.getAss().size(); b++) {
                                    Ass ass = voucherDetails.getAss().get(b);
                                    if (ass.getChecktypecode() != null && !"".equals(ass.getChecktypecode())) {
                                        //存在需要转换的
                                        if (fzhs.contains(ass.getChecktypecode())) {
                                            ArchivesEntity archivesEntity = new ArchivesEntity();
                                            archivesEntity.setArchivesType(ass.getChecktypecode());
                                            archivesEntity.setLeftCode(ass.getCheckvaluecode());
                                            archivesEntity.setLeftOrg(voucher.getPk_corp());
                                            List<ArchivesEntity> archivesEntities = axDao.queryArchivesData(archivesEntity);
                                            if (archivesEntities != null && archivesEntities.size() > 0) {
                                                ass.setCheckvaluecode(archivesEntities.get(0).getRightCode());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                bodys = JSON.toJSONString(entity);
                break;
            case "delete"://删除
                break;
            case "cancellation"://作废
                break;
            default:
                break;
        }
        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        // HttpClient
        CloseableHttpClient closeableHttpClient = httpClientBuilder.disableCookieManagement().build();
        HttpPost post = new HttpPost(voucherUrl);
        CloseableHttpResponse response = null;

        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(60000).build();
        post.setConfig(requestConfig);//设置请求参数【超时时间】
        post.setHeader("usercode", jsonObject.getString("usercode"));
        post.setHeader("password", jsonObject.getString("password"));
        post.setHeader("trantype", jsonObject.getString("trantype"));
        post.setHeader("system", jsonObject.getString("system"));
        post.setHeader("publicKey", publicKey);
        post.setHeader("secretKey", secretKey);
        post.setHeader("appId", appId);
        post.setHeader("needStackTrace", jsonObject.getString("needStackTrace"));
        switch (jsonObject.getString("voucherType")) {
            case "add"://新增
                post.setHeader("apiCode", pzApiCodexz);
                break;
            case "update"://修改
                post.setHeader("apiCode", pzApiCodexg);
                break;
            case "delete"://删除
                post.setHeader("apiCode", pzApiCodesc);
                break;
            case "cancellation"://作废
                post.setHeader("apiCode", pzApiCodezf);
                break;
            default:
                break;
        }
        StringBuilder body = new StringBuilder();
        try {
            if (bodys != null && !"".equals(bodys)) {
                ByteArrayEntity byteArrayEntity = new ByteArrayEntity(bodys.getBytes("UTF-8"));
                byteArrayEntity.setContentType("application/json");
                post.setEntity(byteArrayEntity);
            }
            response = closeableHttpClient.execute(post);
            HttpEntity httpEntity = response.getEntity();
            synchronized (lock) {
                body.append(EntityUtils.toString(httpEntity));
            }
            logger.info("返回结果：" + body);
            JsonResultEntity resultEntity = JSON.parseObject(body.toString(), JsonResultEntity.class);
            return resultEntity;
        } catch (Exception e) {
            logger.error("请求错误：" + e.getMessage());
            body.append(e.getMessage());
            return BaseResult.getFailureMessageEntity("转发失败", body);
        } finally {
            try {
                // 关闭响应对象
                if (response != null) {
                    response.close();
                }
                // 关闭响应对象
                if (closeableHttpClient != null) {
                    closeableHttpClient.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 档案新增
     * @Date 3:42 下午 2024/4/24
     **/
    @Override
    public Object thirdInterfaceArchivesInsert(JSONObject object) {
        JSONObject jsonObject = object.getJSONObject("jsonStr");
        if (jsonObject == null) {
            return BaseResult.getFailureMessageEntity("数据为空，请先传递数据");
        }
        if (!checkStr(jsonObject.getString("archivesType"))) {
            return BaseResult.getFailureMessageEntity("档案类型为空");
        }
        if (!checkStr(jsonObject.getString("usercode"))) {
            return BaseResult.getFailureMessageEntity("usercode为空");
        }
        if (!checkStr(jsonObject.getString("password"))) {
            return BaseResult.getFailureMessageEntity("password为空");
        }
        if (!checkStr(jsonObject.getString("trantype"))) {
            return BaseResult.getFailureMessageEntity("trantype为空");
        }
        if (!checkStr(jsonObject.getString("system"))) {
            return BaseResult.getFailureMessageEntity("system为空");
        }
        if (!checkStr(jsonObject.getString("data"))) {
            return BaseResult.getFailureMessageEntity("data为空");
        }
        List<String> fzhs = Arrays.asList(new String[]{"1", "2", "6", "73", "D01", "jobass", "93", "96", "22"});
        if (!fzhs.contains(jsonObject.getString("archivesType"))) {
            return BaseResult.getFailureMessageEntity("档案类型错误，请联系管理员");
        }
        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        // HttpClient
        CloseableHttpClient closeableHttpClient = httpClientBuilder.disableCookieManagement().build();
        HttpPost post = new HttpPost(voucherUrl);
        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(60000).build();
        post.setConfig(requestConfig);//设置请求参数【超时时间】
        post.setHeader("usercode", jsonObject.getString("usercode"));
        post.setHeader("password", jsonObject.getString("password"));
        post.setHeader("trantype", jsonObject.getString("trantype"));
        post.setHeader("system", jsonObject.getString("system"));
        post.setHeader("publicKey", publicKey);
        post.setHeader("secretKey", secretKey);
        post.setHeader("appId", appId);
        CloseableHttpResponse response = null;
        switch (jsonObject.getString("archivesType")) {
            case "1"://人员对照
                post.setHeader("apiCode", ryApiCodexz);
                break;
            case "2"://部门档案
                post.setHeader("apiCode", bmApiCodexz);
                break;
            case "6"://存货对照
                post.setHeader("apiCode", chApiCodexz);
                break;
            case "73"://客商辅助核算
                post.setHeader("apiCode", ksApiCodexz);
                break;
            case "D01"://税率
                post.setHeader("apiCode", slApiCodexz);
                break;
            case "jobass"://项目辅助核算
                post.setHeader("apiCode", xmApiCodexz);
                break;
            case "93"://银行类别
                post.setHeader("apiCode", yhlbApiCodexz);
                break;
            case "96"://银行账户
                post.setHeader("apiCode", yhzhApiCodexz);
                break;
            case "22"://资产类别
                post.setHeader("apiCode", zcApiCodexz);
                break;
            default:
                break;
        }
        StringBuilder body = new StringBuilder();
        try {
            String senddata = jsonObject.getString("data");
            if ("1".equals(jsonObject.getString("archivesType"))) {
                JSONObject sendJson = JSONObject.parseObject(senddata);
				JSONObject sendObject = new JSONObject();

				if (sendJson != null) {
                    JSONArray psn = sendJson.getJSONArray("psn");
                    JSONArray sendpsn = new JSONArray();
                    if (psn != null && psn.size() > 0) {
                        for (int i = 0; i < psn.size(); i++) {
                            JSONObject person = psn.getJSONObject(i);
                            JSONObject parentvo = person.getJSONObject("parentvo");
                            JSONObject psnmanvo = parentvo.getJSONObject("psnmanvo");

                            ArchivesEntity archivesEntity = new ArchivesEntity();
                            archivesEntity.setArchivesType("2");
                            archivesEntity.setLeftCode(psnmanvo.getString("pk_deptdoc"));
                            archivesEntity.setLeftOrg(parentvo.getString("currentcorp"));
                            List<ArchivesEntity> archivesEntities = axDao.queryArchivesData(archivesEntity);
                            if (archivesEntities != null && archivesEntities.size() > 0) {
								psnmanvo.put("pk_deptdoc",archivesEntities.get(0).getRightCode());
                            }
							parentvo.put("psnmanvo",psnmanvo);
							person.put("parentvo",parentvo);
                            sendpsn.add(person);
                        }
                    }
					sendObject.put("psn",sendpsn);
				}
				senddata = sendObject.toJSONString();
            }
            ByteArrayEntity byteArrayEntity = new ByteArrayEntity(senddata.getBytes("UTF-8"));
            byteArrayEntity.setContentType("application/json");
            post.setEntity(byteArrayEntity);
            response = closeableHttpClient.execute(post);
            HttpEntity httpEntity = response.getEntity();
            synchronized (lock) {
                body.append(EntityUtils.toString(httpEntity));
            }
            logger.info("返回结果：" + body);
            JsonResultEntity resultEntity = JSON.parseObject(body.toString(), JsonResultEntity.class);
            return resultEntity;
            //todo 暂时不保存
            //JsonResultEntity resultEntity = JSON.parseObject(body.toString(),JsonResultEntity.class);
            //if(resultEntity.isFlag() && "200".equals(resultEntity.getStatus())){
            //	if(JSONUtil.isTypeJSON(resultEntity.getAttribute().toString())){
            //		JSONObject attribute = JSONObject.parseObject(resultEntity.getAttribute().toString());
            //		if("success".equals(attribute.getString("status"))){
            //			if(attribute.getString("data") == null || "".equals(attribute.getString("data")) ){
            //				return resultEntity;
            //			}
            //			JSONArray jsonArray = JSONArray.parseArray(attribute.getString("data"));
            //			if(jsonArray == null || jsonArray.size() == 0 ){
            //				return resultEntity;
            //			}
            //			//解析具体数据
            //			switch (jsonObject.getString("archivesType")){
            //				case "1"://人员对照
            //
            //
            //					break;
            //				case "2"://部门档案
            //					//[{"pk_corp":"1001","unitcode":"01","unitname":"临安奥星电子股份有限公司","createdate":"2024-04-24","deptattr":"1","deptname":"DEV测试一级部门","deptcode":"99","pk_deptdoc":"1001F1100000000067BR"}]
            //					for (int i = 0; i < jsonArray.size(); i++) {
            //						JSONObject object1 = jsonArray.getJSONObject(i);
            //						ArchivesEntity archivesEntity = new ArchivesEntity();
            //						archivesEntity.setArchivesType(jsonObject.getString("archivesType"));
            //						archivesEntity.setCreate();
            //						archivesEntity.setLeftCode(object1.getString("unitcode"));//左
            //						archivesEntity.setLeftName(object1.getString("unitname"));//左
            //						archivesEntity.setRightId(object1.getString("pk_deptdoc"));//右
            //						archivesEntity.setRightCode(object1.getString("unitcode"));//右
            //						archivesEntity.setRightName(object1.getString("unitname"));//右
            //						axDao.saveArchivesByType(archivesEntity);
            //					}
            //					break;
            //				case "6"://存货对照
            //					for (int i = 0; i < jsonArray.size(); i++) {
            //						JSONObject object1 = jsonArray.getJSONObject(i);
            //						ArchivesEntity archivesEntity = new ArchivesEntity();
            //						archivesEntity.setArchivesType(jsonObject.getString("archivesType"));
            //						archivesEntity.setCreate();
            //						archivesEntity.setLeftCode(object1.getString("invclasscode"));//左
            //						archivesEntity.setLeftName(object1.getString("invclassname"));//左
            //						archivesEntity.setRightId(object1.getString("pk_invcl"));//右
            //						archivesEntity.setRightCode(object1.getString("invclasscode"));//右
            //						archivesEntity.setRightName(object1.getString("invclassname"));//右
            //						axDao.saveArchivesByType(archivesEntity);
            //					}
            //					break;
            //				case "73"://客商辅助核算
            //					break;
            //				case "D01"://税率
            //					break;
            //				case "jobass"://项目辅助核算
            //					break;
            //				case "93"://银行类别
            //					break;
            //				case "96"://银行账户
            //					break;
            //				case "22"://资产类别
            //					break;
            //				default:
            //					break;
            //			}
            //			return resultEntity;
            //		}else {
            //			return resultEntity;
            //		}
            //	}else {
            //		return resultEntity;
            //	}
            //}else {
            //	//解析返回
            //	return resultEntity;
            //}
        } catch (Exception e) {
            logger.error("请求错误：" + e.getMessage());
            body.append(e.getMessage());
            return BaseResult.getFailureMessageEntity("转发失败", body);
        } finally {
            try {
                // 关闭响应对象
                if (response != null) {
                    response.close();
                }
                // 关闭响应对象
                if (closeableHttpClient != null) {
                    closeableHttpClient.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 档案修改
     * @Date 3:42 下午 2024/4/24
     **/
    @Override
    public Object thirdInterfaceArchivesUpdate(JSONObject object) {
        JSONObject jsonObject = object.getJSONObject("jsonStr");
        if (jsonObject == null) {
            return BaseResult.getFailureMessageEntity("数据为空，请先传递数据");
        }
        if (!checkStr(jsonObject.getString("archivesType"))) {
            return BaseResult.getFailureMessageEntity("档案类型为空");
        }
        if (!checkStr(jsonObject.getString("usercode"))) {
            return BaseResult.getFailureMessageEntity("usercode为空");
        }
        if (!checkStr(jsonObject.getString("password"))) {
            return BaseResult.getFailureMessageEntity("password为空");
        }
        if (!checkStr(jsonObject.getString("trantype"))) {
            return BaseResult.getFailureMessageEntity("trantype为空");
        }
        if (!checkStr(jsonObject.getString("system"))) {
            return BaseResult.getFailureMessageEntity("system为空");
        }
        if (!checkStr(jsonObject.getString("data"))) {
            return BaseResult.getFailureMessageEntity("data为空");
        }
        List<String> fzhs = Arrays.asList(new String[]{"1", "2", "6", "73", "D01", "jobass", "93", "96", "22"});
        if (!fzhs.contains(jsonObject.getString("archivesType"))) {
            return BaseResult.getFailureMessageEntity("档案类型错误，请联系管理员");
        }
        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        // HttpClient
        CloseableHttpClient closeableHttpClient = httpClientBuilder.disableCookieManagement().build();
        HttpPost post = new HttpPost(voucherUrl);
        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(60000).build();
        post.setConfig(requestConfig);//设置请求参数【超时时间】
        post.setHeader("usercode", jsonObject.getString("usercode"));
        post.setHeader("password", jsonObject.getString("password"));
        post.setHeader("trantype", jsonObject.getString("trantype"));
        post.setHeader("system", jsonObject.getString("system"));
        post.setHeader("publicKey", publicKey);
        post.setHeader("secretKey", secretKey);
        post.setHeader("appId", appId);
        CloseableHttpResponse response = null;
        switch (jsonObject.getString("archivesType")) {
            case "1"://人员对照
                post.setHeader("apiCode", ryApiCodexg);
                break;
            case "2"://部门档案
                post.setHeader("apiCode", bmApiCodexg);
                break;
            case "6"://存货对照
                post.setHeader("apiCode", chApiCodexg);
                break;
            case "73"://客商辅助核算
                post.setHeader("apiCode", ksApiCodexg);
                break;
            case "D01"://税率
                post.setHeader("apiCode", slApiCodexg);
                break;
            case "jobass"://项目辅助核算
                post.setHeader("apiCode", xmApiCodexg);
                break;
            case "93"://银行类别
                post.setHeader("apiCode", yhlbApiCodexg);
                break;
            case "96"://银行账户
                post.setHeader("apiCode", yhzhApiCodexg);
                break;
            case "22"://资产类别
                post.setHeader("apiCode", zcApiCodexg);
                break;
            default:
                break;
        }
        StringBuilder body = new StringBuilder();
        try {
            ByteArrayEntity byteArrayEntity = new ByteArrayEntity(jsonObject.getString("data").getBytes("UTF-8"));
            byteArrayEntity.setContentType("application/json");
            post.setEntity(byteArrayEntity);
            response = closeableHttpClient.execute(post);
            HttpEntity httpEntity = response.getEntity();
            synchronized (lock) {
                body.append(EntityUtils.toString(httpEntity));
            }
            logger.info("返回结果：" + body);
            JsonResultEntity resultEntity = JSON.parseObject(body.toString(), JsonResultEntity.class);
            return resultEntity;
            //JsonResultEntity resultEntity = JSON.parseObject(body.toString(),JsonResultEntity.class);
            //if(resultEntity.isFlag() && "200".equals(resultEntity.getStatus())){
            //	if(JSONUtil.isTypeJSON(resultEntity.getAttribute().toString())){
            //		//JSONObject attribute = JSONObject.parseObject(resultEntity.getAttribute().toString());
            //		JSONObject attribute = JSONObject.parseObject("{\n" +
            //				"    \"status\": \"success\",\n" +
            //				"    \"data\": \"[{\\\"pk_invcl\\\":\\\"0001F11000000000I6NN\\\",\\\"invclasscode\\\":\\\"04\\\",\\\"invclassname\\\":\\\"成品测试\\\",\\\"invclasslev\\\":\\\"1\\\",\\\"pk_corp\\\":\\\"0001\\\",\\\"unitcode\\\":\\\"0001\\\",\\\"unitname\\\":\\\"集团\\\"}]\",\n" +
            //				"    \"taskNumber\": \"202404250048\"\n" +
            //				"}");
            //		if("success".equals(attribute.getString("status"))){
            //			if(attribute.getString("data") == null || "".equals(attribute.getString("data")) ){
            //				return resultEntity;
            //			}
            //			JSONArray jsonArray = JSONArray.parseArray(attribute.getString("data"));
            //			if(jsonArray == null || jsonArray.size() == 0 ){
            //				return resultEntity;
            //			}
            //			//解析具体数据
            //			switch (jsonObject.getString("archivesType")){
            //				case "1"://人员对照
            //					break;
            //				case "2"://部门档案
            //					break;
            //				case "6"://存货对照
            //					for (int i = 0; i < jsonArray.size(); i++) {
            //						JSONObject object1 = jsonArray.getJSONObject(i);
            //						ArchivesEntity archivesEntity = new ArchivesEntity();
            //						archivesEntity.setArchivesType(jsonObject.getString("archivesType"));
            //						archivesEntity.setUpdate();
            //						archivesEntity.setLeftCode(object1.getString("invclasscode"));//左
            //						archivesEntity.setLeftName(object1.getString("invclassname"));//左
            //						archivesEntity.setRightId(object1.getString("pk_invcl"));//右
            //						archivesEntity.setRightCode(object1.getString("invclasscode"));//右
            //						archivesEntity.setRightName(object1.getString("invclassname"));//右
            //						axDao.updateArchivesByType(archivesEntity);
            //					}
            //					break;
            //				case "73"://客商辅助核算
            //					break;
            //				case "D01"://税率
            //					break;
            //				case "jobass"://项目辅助核算
            //					break;
            //				case "93"://银行类别
            //					break;
            //				case "96"://银行账户
            //					break;
            //				case "22"://资产类别
            //					break;
            //				default:
            //					break;
            //			}
            //			return resultEntity;
            //		}else {
            //			return resultEntity;
            //		}
            //	}else {
            //		return resultEntity;
            //	}
            //}else {
            //	//解析返回
            //	return resultEntity;
            //}
        } catch (Exception e) {
            logger.error("请求错误：" + e.getMessage());
            body.append(e.getMessage());
            return BaseResult.getFailureMessageEntity("转发失败", body);
        } finally {
            try {
                // 关闭响应对象
                if (response != null) {
                    response.close();
                }
                // 关闭响应对象
                if (closeableHttpClient != null) {
                    closeableHttpClient.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 档案删除
     * @Date 3:42 下午 2024/4/24
     **/
    @Override
    public Object thirdInterfaceArchivesDelete(JSONObject object) {
        JSONObject jsonObject = object.getJSONObject("jsonStr");
        if (jsonObject == null) {
            return BaseResult.getFailureMessageEntity("数据为空，请先传递数据");
        }
        if (!checkStr(jsonObject.getString("archivesType"))) {
            return BaseResult.getFailureMessageEntity("档案类型为空");
        }
        if (!checkStr(jsonObject.getString("usercode"))) {
            return BaseResult.getFailureMessageEntity("usercode为空");
        }
        if (!checkStr(jsonObject.getString("password"))) {
            return BaseResult.getFailureMessageEntity("password为空");
        }
        if (!checkStr(jsonObject.getString("trantype"))) {
            return BaseResult.getFailureMessageEntity("trantype为空");
        }
        if (!checkStr(jsonObject.getString("system"))) {
            return BaseResult.getFailureMessageEntity("system为空");
        }
        if (!checkStr(jsonObject.getString("data"))) {
            return BaseResult.getFailureMessageEntity("data为空");
        }
        List<String> fzhs = Arrays.asList(new String[]{"1", "2", "6", "73", "D01", "jobass", "93", "96", "22"});
        if (!fzhs.contains(jsonObject.getString("archivesType"))) {
            return BaseResult.getFailureMessageEntity("档案类型错误，请联系管理员");
        }
        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        // HttpClient
        CloseableHttpClient closeableHttpClient = httpClientBuilder.disableCookieManagement().build();
        HttpPost post = new HttpPost(voucherUrl);
        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(60000).build();
        post.setConfig(requestConfig);//设置请求参数【超时时间】
        post.setHeader("usercode", jsonObject.getString("usercode"));
        post.setHeader("password", jsonObject.getString("password"));
        post.setHeader("trantype", jsonObject.getString("trantype"));
        post.setHeader("system", jsonObject.getString("system"));
        post.setHeader("publicKey", publicKey);
        post.setHeader("secretKey", secretKey);
        post.setHeader("appId", appId);
        CloseableHttpResponse response = null;
        switch (jsonObject.getString("archivesType")) {
            case "1"://人员对照
                post.setHeader("apiCode", ryApiCodesc);
                break;
            case "2"://部门档案
                post.setHeader("apiCode", bmApiCodesc);
                break;
            case "6"://存货对照
                post.setHeader("apiCode", chApiCodesc);
                break;
            case "73"://客商辅助核算
                post.setHeader("apiCode", ksApiCodesc);
                break;
            case "D01"://税率
                post.setHeader("apiCode", slApiCodesc);
                break;
            case "jobass"://项目辅助核算
                post.setHeader("apiCode", xmApiCodesc);
                break;
            case "93"://银行类别
                post.setHeader("apiCode", yhlbApiCodesc);
                break;
            case "96"://银行账户
                post.setHeader("apiCode", yhzhApiCodesc);
                break;
            case "22"://资产类别
                post.setHeader("apiCode", zcApiCodesc);
                break;
            default:
                break;
        }
        StringBuilder body = new StringBuilder();
        try {
            ByteArrayEntity byteArrayEntity = new ByteArrayEntity(jsonObject.getString("data").getBytes("UTF-8"));
            byteArrayEntity.setContentType("application/json");
            post.setEntity(byteArrayEntity);
            response = closeableHttpClient.execute(post);
            HttpEntity httpEntity = response.getEntity();
            synchronized (lock) {
                body.append(EntityUtils.toString(httpEntity));
            }
            logger.info("返回结果：" + body);
            JsonResultEntity resultEntity = JSON.parseObject(body.toString(), JsonResultEntity.class);
            return resultEntity;
            //JsonResultEntity resultEntity = JSON.parseObject(body.toString(),JsonResultEntity.class);
            //if(resultEntity.isFlag() && "200".equals(resultEntity.getStatus())){
            //	if(JSONUtil.isTypeJSON(resultEntity.getAttribute().toString())){
            //		//JSONObject attribute = JSONObject.parseObject(resultEntity.getAttribute().toString());
            //		JSONObject attribute = JSONObject.parseObject("{\n" +
            //				"    \"status\": \"success\",\n" +
            //				"    \"data\": \"[{\\\"pk_invcl\\\":\\\"0001F11000000000I6NN\\\",\\\"invclasscode\\\":\\\"04\\\",\\\"invclassname\\\":\\\"成品测试\\\",\\\"invclasslev\\\":\\\"1\\\",\\\"pk_corp\\\":\\\"0001\\\",\\\"unitcode\\\":\\\"0001\\\",\\\"unitname\\\":\\\"集团\\\"}]\",\n" +
            //				"    \"taskNumber\": \"202404250048\"\n" +
            //				"}");
            //		if("success".equals(attribute.getString("status"))){
            //			if(attribute.getString("data") == null || "".equals(attribute.getString("data")) ){
            //				return resultEntity;
            //			}
            //			JSONArray jsonArray = JSONArray.parseArray(attribute.getString("data"));
            //			if(jsonArray == null || jsonArray.size() == 0 ){
            //				return resultEntity;
            //			}
            //			//解析具体数据
            //			switch (jsonObject.getString("archivesType")){
            //				case "1"://人员对照
            //					break;
            //				case "2"://部门档案
            //					break;
            //				case "6"://存货对照
            //					for (int i = 0; i < jsonArray.size(); i++) {
            //						JSONObject object1 = jsonArray.getJSONObject(i);
            //						ArchivesEntity archivesEntity = new ArchivesEntity();
            //						archivesEntity.setArchivesType(jsonObject.getString("archivesType"));
            //						archivesEntity.setUpdate();
            //						archivesEntity.setLeftCode(object1.getString("invclasscode"));//左
            //						archivesEntity.setLeftName(object1.getString("invclassname"));//左
            //						archivesEntity.setRightId(object1.getString("pk_invcl"));//右
            //						archivesEntity.setRightCode(object1.getString("invclasscode"));//右
            //						archivesEntity.setRightName(object1.getString("invclassname"));//右
            //						axDao.deleteArchivesByType(archivesEntity);
            //					}
            //					break;
            //				case "73"://客商辅助核算
            //					break;
            //				case "D01"://税率
            //					break;
            //				case "jobass"://项目辅助核算
            //					break;
            //				case "93"://银行类别
            //					break;
            //				case "96"://银行账户
            //					break;
            //				case "22"://资产类别
            //					break;
            //				default:
            //					break;
            //			}
            //			return resultEntity;
            //		}else {
            //			return resultEntity;
            //		}
            //	}else {
            //		return resultEntity;
            //	}
            //}else {
            //	//解析返回
            //	return resultEntity;
            //}
        } catch (Exception e) {
            logger.error("请求错误：" + e.getMessage());
            body.append(e.getMessage());
            return BaseResult.getFailureMessageEntity("转发失败", body);
        } finally {
            try {
                // 关闭响应对象
                if (response != null) {
                    response.close();
                }
                // 关闭响应对象
                if (closeableHttpClient != null) {
                    closeableHttpClient.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
