package com.hzya.frame.seeyon.invoice.service.impl;

import cn.hutool.http.HttpRequest;
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.mdm.mdmModuleSource.dao.impl.MdmModuleSourceDaoImpl;
import com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity;
import com.hzya.frame.seeyon.dao.ICtpAttachmentDao;
import com.hzya.frame.seeyon.entity.CtpAttachmentEntity;
import com.hzya.frame.seeyon.invoice.dao.IInvoiceDao;
import com.hzya.frame.seeyon.invoice.dao.IInvoiceDetailsDao;
import com.hzya.frame.seeyon.invoice.entity.InvoiceEntity;
import com.hzya.frame.seeyon.invoice.entity.InvoiceState;
import com.hzya.frame.seeyon.invoice.service.IInvoiceService;
import com.hzya.frame.seeyon.util.OARestUtil;
import com.hzya.frame.seeyon.util.YzfSignUtil;
import com.hzya.frame.seeyon.zxbank.entity.PayState;
import com.hzya.frame.seeyon.zxbank.entity.ZxBankEntity;
import com.hzya.frame.sysnew.comparison.service.impl.ComparisonServiceImpl;
import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity;
import com.hzya.frame.sysnew.integtationTaskLivingDetails.service.IIntegrationTaskLivingDetailsService;
import com.hzya.frame.uuid.UUIDLong;
import com.hzya.frame.uuid.UUIDUtils;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import com.hzya.frame.web.exception.BaseSystemException;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;

@Service(value = "InvoiceServiceImpl")
public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> implements IInvoiceService {
    @Autowired
    private MdmModuleSourceDaoImpl mdmModuleSourceDaoImpl;

    @Autowired
    private IInvoiceDao invoiceDao;
    @Autowired
    private IInvoiceDetailsDao invoiceDetailsDao;

    @Autowired
    private IIntegrationTaskLivingDetailsService taskLivingDetailsService;
    @Autowired
    private ComparisonServiceImpl comparisonServiceimpl;
    @Autowired
    private ICtpAttachmentDao ctpAttachmentDao;

    @Value("${zt.url}")
    private String url;

    @Value("${invoice_pdf.url:}")
    private String invoicePdfUrl;
    @Value("${invoice_ofd.url:}")
    private String invoiceOfdUrl;

    @Override
    public JsonResultEntity queryArchives(JSONObject json) {
        JSONObject jsonObject = json.getJSONObject("jsonStr");
        //根据插件分类查询主数据来源表
        List<MdmModuleSourceEntity> list = mdmModuleSourceDaoImpl.MdmModuleSourceentityGroupByType();
        if (CollectionUtils.isEmpty(list)) {
            logger.info("没有类型为插件得数据,无法获取数据");
            return BaseResult.getFailureMessageEntity("数据来源表无插件类型");
        }
        for (MdmModuleSourceEntity mdmModuleSourceEntity : list) {
            String tableName = "";
            List<Object> object=new ArrayList<>();
            List<JSONObject> listAll  = new ArrayList<>();
            try {
                String appTyp = mdmModuleSourceEntity.getAppType();//系统类型  1、致远OA 2、用友U8C 3、用友BIP
                String dbCode = mdmModuleSourceEntity.getDbCode();//数据源编码
                String mdmCode = mdmModuleSourceEntity.getMdmCode();//主数据编码
                switch (appTyp){
                    case "1":
                        switch (mdmCode){
                            case "10049"://杭泰开票申请单
                                tableName = "mdm_invoice_application";
                                listAll = bindingInvoice(jsonObject, mdmModuleSourceEntity, dbCode);
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }
                //将查询出来的数据进行组装，调用通用方法新增或者更新
                if (null != listAll && listAll.size() > 0) {
                    object = ParametricDocument(listAll, mdmCode, tableName);
                    if (CollectionUtils.isNotEmpty(object)) {
                        for (Object obj : object) {
                            //更新单据视图推送标识，不再抽取
                            JSONObject attributeResult = (JSONObject) JSON.toJSON(obj);
                            if (attributeResult.getString("status").equals("200")) {
                                String resultString = attributeResult.getString("list");
                                if ("10049".equals(mdmCode)) {
                                    JSONArray jsonArray = JSONArray.parseArray(resultString);
                                    if (CollectionUtils.isNotEmpty(jsonArray)) {
                                        for (Object o : jsonArray) {
                                            JSONObject attributeArray = (JSONObject) JSON.toJSON(o);
                                            String cmpApply = attributeArray.getString(tableName);
                                            JSONObject jsonObjectCmpApply = JSONObject.parseObject(cmpApply);
                                            String id = jsonObjectCmpApply.getString("data_id");//主表id
                                            String vdef1 = jsonObjectCmpApply.getString("business_no");//主表id
                                            logger.info("=====开始根据单据id:{},单据号：{},更新表：formmain_0331的推送标识", id, vdef1);
                                            InvoiceEntity invoiceEntity = new InvoiceEntity();
                                            invoiceEntity.setPush_status("1");
                                            invoiceEntity.setId(id);
                                            invoiceEntity.setDataSourceCode(mdmModuleSourceEntity.getDataSourceCode());
                                            invoiceDao.updateInvoicePush(invoiceEntity);
                                            //保存业务数据日志
                                            saveTaskLivingDetails(id, jsonObjectCmpApply.getString("business_no"), listAll.get(0).toString(), object.toString(), true,"MakeInvoicePluginInitializer");
                                        }
                                    }
                                }
                            } else {
                                saveTaskLivingDetails(JSONObject.parseObject(listAll.get(0).getString("mdm_invoice_application")).getString("data_id"), JSONObject.parseObject(listAll.get(0).getString("mdm_invoice_application")).getString("business_no"), listAll.get(0).toString(), JSON.parseObject(JSON.toJSONString(object)).getString("msg"), false,"MakeInvoicePluginInitializer");
                            }
                        }
                    }
                } else {
                    logger.info("三维单据视图数据没有需要同步中台的数据");
                }
            }catch (Exception e){
                logger.info("杭泰付款单同步失败:{}",e.getMessage());
                saveTaskLivingDetails(JSONObject.parseObject(listAll.get(0).getString("mdm_invoice_application")).getString("data_id"),JSONObject.parseObject(listAll.get(0).getString("mdm_invoice_application")).getString("business_no"),listAll.get(0).toString(),JSON.parseObject(JSON.toJSONString(object)).getString("msg")==null?JSON.parseObject(JSON.toJSONString(object)).getString("list"):JSON.parseObject(JSON.toJSONString(object)).getString("msg"),false,"MakeInvoicePluginInitializer");
                e.printStackTrace();
            }
        }
        return BaseResult.getSuccessMessageEntity("开票申请单同步成功");
    }

    @Override
    public JsonResultEntity queryInvoiceResult(JSONObject json) {
        try {
            InvoiceEntity invoiceEntity = json.toJavaObject(InvoiceEntity.class);
            invoiceEntity.setDataSourceCode("HT-OA");
            logger.info("=======开始查询杭泰税务的开票申请单返回结果=========");
            List<InvoiceEntity> invoiceEntities = invoiceDao.queryInvoiceResult(invoiceEntity);
            if(CollectionUtils.isEmpty(invoiceEntities)){
                logger.info("=====杭泰税务中没有需要查询申请单详情得数据========");
                return BaseResult.getSuccessMessageEntity("查询成功");
            }
            for (InvoiceEntity entity : invoiceEntities) {
                long timestamp = System.currentTimeMillis();
                Map<String, Object> parametersMap = new HashMap<>();
                parametersMap.put("accessKey","6X3B526P5HqE6ums");
                parametersMap.put("timestamp",timestamp);
                String sign = YzfSignUtil.signRequest(parametersMap,"34e5fc32ac894a2ba2ade8c3852c7a0a");
                 JSONObject jsonObject=new JSONObject();
                 jsonObject.put("serialNumber",entity.getId());
                 jsonObject.put("accessKey","6X3B526P5HqE6ums");
                 jsonObject.put("sign",sign);
                 jsonObject.put("timestamp",timestamp);
                 logger.info("=======调用杭泰税务查询申请单详情的请求参数为:{}=======",jsonObject.toJSONString());
                //发送数据
                String result = HttpRequest.post(url).
                        header("appId", "800060").
                        header("apiCode", "8000600003").
                                header("publicKey", "ZJYAmRjjYEDgqw4UXWHZNicYclErG0hsrwKQcHukPlP0K1pCe7eDIk+3zDUT+v578prj").
                        header("secretKey", "D6AHU3PL8UsNfK6A8I6mL4X1ma2NXckX/vM7AOzI/jmzJf+R1aY06Q6SBz7Y7drHj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=").
                        body(jsonObject.toJSONString()).
                        execute().
                        body();
                logger.info("=====调用杭泰税务查询申请单详情的返回参数为:{}===========",result);
                JSONObject resultJson = JSONObject.parseObject(result);
                if (!resultJson.getBoolean("flag")) {
                    saveTaskLivingDetails(entity.getId(), entity.getBusiness_no(), jsonObject.toJSONString(), resultJson.toJSONString(), false,"");
                } else {
                    JSONObject attribute = resultJson.getJSONObject("attribute");
                    if("0".equals(attribute.getString("code"))){
                       JSONObject jsonResult=JSONObject.parseObject(attribute.getString("result"));
                        if(null !=jsonResult){
                            JSONArray jsonArray = jsonResult.getJSONArray("invoiceInfoVOList");
                            if(CollectionUtils.isNotEmpty(jsonArray)){
                                for (int i = 0; i < jsonArray.size(); i++) {
                                    //表单的附件字段=ctpAttachment的Sub_reference，表单的Summary_id=ctpAttachment的att_reference
                                    String sub_reference = String.valueOf(UUIDLong.longUUID());
                                    String att_reference = entity.getSummaryId();//Summary_id
                                    JSONObject invoiceInfo = jsonArray.getJSONObject(i);
                                    String invoiceCode = invoiceInfo.getString("invoiceCode");//发票代码
                                    String invoiceNumber = invoiceInfo.getString("invoiceNumber");//发票号码
                                    String resultStatus = InvoiceState.invoiceStateGetValue(jsonResult.getString("resultStatus"));//开票结果
                                    entity.setInvoice_code(invoiceCode);
                                    entity.setInvoice_number(invoiceNumber);
                                    entity.setResult_status(resultStatus);
                                    //将开票结果，发票号码，发票代码，回写OA
                                    invoiceDao.updateInvoiceResult(entity);
                                    if (null != invoiceInfo.getString("url") || null != invoiceInfo.getString("ofdUrl")) {
                                        String pdfUrl = invoiceInfo.getString("url");//pdf文件
                                        String ofdUrl = invoiceInfo.getString("ofdUrl");//ofd文件
                                        String xmlUrl = invoiceInfo.getString("xmlUrl");//xml文件
                                        //获取pdf文件到本地 并为pdf取名，否则会报无法访问错误
                                        logger.info("========开始将pdf文件保存到本地========");
                                        String pdfFileName = generateFileName(pdfUrl, "pdf");
                                        String pdfSavePath = invoicePdfUrl + pdfFileName;
                                        downloadPdf(pdfUrl, pdfSavePath);
                                        logger.info("========pdf文件保存到本地完成========");
                                        File filePdf = new File(pdfSavePath);
                                        logger.info("========开始将pdf文件上传OA========");
                                        ManyfileUpload(filePdf, entity, sub_reference, att_reference, jsonObject);
                                        logger.info("========pdf文件上传OA完成========");
                                        //获取ofd文件到本地
                                        logger.info("========开始将ofd文件保存到本地========");
                                        String ofdFileName = generateFileName(ofdUrl, "ofd");
                                        String ofdSavePath = ofdUrl + ofdFileName;
                                        downloadPdf(ofdUrl, ofdSavePath);
                                        logger.info("========ofd文件保存到本地完成========");
                                        File fileOfd = new File(ofdSavePath);
                                        logger.info("========开始将ofd文件上传OA========");
                                        ManyfileUpload(fileOfd, entity, sub_reference, att_reference, jsonObject);
                                        logger.info("========ofd文件上传OA完成========");
                                    }
                                }
                            }
                        }
                    }
                }

            }
        }catch (Exception e){
            logger.info("======查询杭泰税务申请单详情失败====",e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    //进项发票推送结果查询（查询发票批量录入结果）
    @Override
    public JsonResultEntity queryInputInvoiceResult(JSONObject json) {
        try {
            InvoiceEntity invoiceEntity = json.toJavaObject(InvoiceEntity.class);
            invoiceEntity.setDataSourceCode("HT-OA");
            logger.info("=======开始查询杭泰税务的发票批量录入返回结果=========");
            List<InvoiceEntity> invoiceEntities = invoiceDao.queryInputInvoiceResult(invoiceEntity);
            if(CollectionUtils.isEmpty(invoiceEntities)){
                logger.info("=====杭泰税务中没有需要查询发票批量录入返回结果的数据========");
                return BaseResult.getSuccessMessageEntity("查询成功");
            }
            for (InvoiceEntity entity : invoiceEntities) {
                long timestamp = System.currentTimeMillis();
                Map<String, Object> parametersMap = new HashMap<>();
                parametersMap.put("accessKey","6X3B526P5HqE6ums");
                parametersMap.put("timestamp",timestamp);
                String sign = YzfSignUtil.signRequest(parametersMap,"34e5fc32ac894a2ba2ade8c3852c7a0a");
                JSONObject jsonObject=new JSONObject();
                jsonObject.put("serialNumber",entity.getId());
                jsonObject.put("accessKey","6X3B526P5HqE6ums");
                jsonObject.put("sign",sign);
                jsonObject.put("timestamp",timestamp);
                logger.info("=======调用杭泰税务查询发票批量录入结果的请求参数为:{}=======",jsonObject.toJSONString());
                //发送数据
                String result = HttpRequest.post(url).
                        header("appId", "800060").
                        header("apiCode", "8000600006").
                        header("publicKey", "ZJYAmRjjYEDgqw4UXWHZNicYclErG0hsrwKQcHukPlP0K1pCe7eDIk+3zDUT+v578prj").
                        header("secretKey", "D6AHU3PL8UsNfK6A8I6mL4X1ma2NXckX/vM7AOzI/jmzJf+R1aY06Q6SBz7Y7drHj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=").
                        body(jsonObject.toJSONString()).
                        execute().
                        body();
                logger.info("=====调用杭泰税务查询发票批量录入结果的返回参数为:{}===========",result);
                JSONObject resultJson = JSONObject.parseObject(result);
                if (!resultJson.getBoolean("flag")) {
                    saveTaskLivingDetails(entity.getId(), entity.getBusiness_no(), jsonObject.toJSONString(), resultJson.toJSONString(), false,"");
                } else {
                    JSONObject attribute = resultJson.getJSONObject("attribute");
                    if("0".equals(attribute.getString("code"))) {
                        JSONObject jsonResult = JSONObject.parseObject(attribute.getString("result"));
                        if (null != jsonResult) {
                            String serialNumber = jsonResult.getString("serialNumber");//流水号
                            String status = jsonResult.getString("status");//发票批量录入返回结果状态
                            if(serialNumber.equals(entity.getId())){
                                //修改发票批量录入结果状态
                                logger.info("=========开始更新进项发票的结果==========");
                                entity.setInput_result_status(InvoiceState.invoiceStateGetValue(status));
                                entity.setDataSourceCode("HT-OA");
                                invoiceDao.updateInvoiceResult(entity);
                                logger.info("=========更新进项发票的结果完成==========");
                                saveTaskLivingDetails(entity.getId(),entity.getBusiness_no(),jsonObject.toJSONString(), resultJson.toJSONString(), true,"");
                            }
                        }
                    }
                        }
            }
        }catch (Exception e){
            logger.info("======查询杭泰税务发票批量录入结果失败====",e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    private void ManyfileUpload(File file,InvoiceEntity entity,String sub_reference,String att_reference,JSONObject jsonObject){
        JSONObject jsonObjectOfd = OARestUtil.fileUpload(file,"8000590003","8000590001");
        if (jsonObjectOfd.getString("fileUrl") != null) {
            entity.setUrl(sub_reference);
            entity.setDataSourceCode("HT-OA");
            invoiceDao.updateInvoiceUrl(entity);
            //根据附件id查询附件业务数据
            String file_url = jsonObjectOfd.getString("fileUrl");
            CtpAttachmentEntity ctpAttachmentEntity = new CtpAttachmentEntity();
            ctpAttachmentEntity.setFile_url(file_url);
            ctpAttachmentEntity.setSub_reference(sub_reference);
            ctpAttachmentEntity.setAtt_reference(att_reference);
            ctpAttachmentEntity.setDataSourceCode("HT-OA");
            List<CtpAttachmentEntity> ctpAttachmentEntities = ctpAttachmentDao.queryCtpAttachment(ctpAttachmentEntity);
            //如果没有查询到数据，就新增附件业务，否则更新
            if (ctpAttachmentEntities.size() == 0) {
                String category = jsonObject.getString("category");
                String type = jsonObject.getString("type");
                String filename = jsonObject.getString("filename");
                String mime_type = jsonObject.getString("mimeType");
                String attachment_size = jsonObject.getString("size");
                String id = String.valueOf(UUIDLong.longUUID());
                ctpAttachmentEntity.setCategory(category);
                ctpAttachmentEntity.setFilename(filename);
                ctpAttachmentEntity.setType(type);
                ctpAttachmentEntity.setMime_type(mime_type);
                ctpAttachmentEntity.setAttachment_size(attachment_size);
                ctpAttachmentEntity.setId(id);
                ctpAttachmentEntity.setCategory("66");
                ctpAttachmentEntity.setCreatedate(new Date());
                ctpAttachmentEntity.setDataSourceCode("HT-OA");
                ctpAttachmentDao.saveCtpAttachment(ctpAttachmentEntity);
            } else {
                if (ctpAttachmentEntities.size() > 1) {
                    throw new BaseSystemException("OA附件业务表中查到多条记录");
                }
                //更新数据到OA附件业务表中
                ctpAttachmentDao.updateCtpAttachment(ctpAttachmentEntity);
            }
            logger.info("=====电子回单执行完毕=======");
        }
        file.delete();
    }

    private void downloadPdf(String pdfUrl, String savePath) {
        try {
            URL url = new URL(pdfUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("Post");
            int responseCode = connection.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                InputStream inputStream = connection.getInputStream();
                FileOutputStream outputStream = new FileOutputStream(savePath);

                byte[] buffer = new byte[4096];
                int bytesRead;
                while ((bytesRead = inputStream.read(buffer)) != -1) {
                    outputStream.write(buffer, 0, bytesRead);
                }

                outputStream.close();
                inputStream.close();
            } else {
                logger.info("下载失败，响应码: {}" , responseCode);
            }
            connection.disconnect();
        }catch (Exception e){
            logger.info("====查询申请单详情获取税务pdf或ofd文件失败:{}========",e.getMessage());
            e.printStackTrace();
        }
    }

    private String generateFileName(String url, String extension) {
        // 这里简单根据 URL 的参数生成文件名，你可以根据实际需求调整
        String[] parts = url.split("&");
        String fphm = "";
        for (String part : parts) {
            if (part.startsWith("fphm=")) {
                fphm = part.substring(5);
                break;
            }
        }
        return fphm + "." + extension;
    }

    private List<JSONObject> bindingInvoice(JSONObject jsonObject, MdmModuleSourceEntity mdmModuleSourceEntity, String dbCode) {
        List<JSONObject> list = new ArrayList<>();
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("select * from v_hzya_invoice where push_status is null ");
        mdmModuleSourceEntity.setDataSourceCode(dbCode);
        List<HashMap<String, Object>> hashMaps = invoiceDao.queryInvoice(stringBuffer.toString(), mdmModuleSourceEntity);
        int i = 0;
        if (CollectionUtils.isNotEmpty(hashMaps)) {
            for (HashMap<String, Object> hashMap : hashMaps) {
                JSONObject main = new JSONObject();
                JSONObject invoice = new JSONObject();
                for (String key : hashMap.keySet()) {
                    invoice.put(key.toLowerCase(), hashMap.get(key));
                }
                //获取明细信息
                Long formmainId = (Long) hashMap.get("data_id");
                StringBuffer stringBufferDetails = new StringBuffer();
                stringBufferDetails.append("SELECT * FROM v_hzya_invoice_details WHERE f_id = '"+formmainId+"' " );
                List<HashMap<String, Object>> hashMapsDetails = invoiceDetailsDao.queryInvoiceDetails(stringBufferDetails.toString(),mdmModuleSourceEntity);
                JSONArray invoiceDetails = new JSONArray();
                if(CollectionUtils.isNotEmpty(hashMapsDetails)){
                    for (HashMap<String, Object> detailsMap : hashMapsDetails) {
                        JSONObject details = new JSONObject();
                        for (String key : detailsMap.keySet()) {
                            details.put(key.toLowerCase(), detailsMap.get(key));
                        }
                        invoiceDetails.add(details);
                    }
                }
                main.put("mdm_invoice_application_details", invoiceDetails);
                main.put("mdm_invoice_application", invoice);
                list.add(main);
            }
        }
        return list;
    }

    private List<Object> ParametricDocument(List<JSONObject>  hashMaps,String mdmCode,String tableName){
        JSONObject jsonObjectUser = new JSONObject();
        List<Object> result=new ArrayList<>();
        try {
            for (JSONObject hashMap : hashMaps) {
                JSONObject main = hashMap.getJSONObject(tableName);
                JSONObject jsonStr = new JSONObject();
                jsonObjectUser.put("data_id", main.get("data_id"));
                jsonObjectUser.put("mdmCode", mdmCode);
                jsonStr.put("jsonStr", jsonObjectUser);
                //先查询编码和名称查询是否存在
                Object attribute = comparisonServiceimpl.queryEntityPage(jsonStr);
                logger.info("得到的attribute值为：{}", jsonStr.toJSONString(attribute));
                JSONObject jsonObjectAttribute = (JSONObject) JSON.toJSON(attribute);
                JSONObject pageInfo = jsonObjectAttribute.getJSONObject("pageInfo");
                JSONArray jsonArrayList = pageInfo.getJSONArray("list");
                //如果jsonArrayList为null，说明没有值，在表中不存在
                if (jsonArrayList == null || jsonArrayList.size() == 0) {
                    hashMap.put("appName","数智中台");
                    hashMap.put("appCode","800004");
                    hashMap.put("mdmCode", mdmCode);
                    hashMap.put("optionName", "数智中台");
                    jsonStr.put("jsonStr", hashMap);
                    Object  object = comparisonServiceimpl.saveEntity(jsonStr);
                    logger.info("应付单新增结果为：{}", JSON.toJSONString(object));
                    result.add(object);
                } else {
                    hashMap.put("appName","数智中台");
                    hashMap.put("appCode","800004");
                    hashMap.put("mdmCode", mdmCode);
                    hashMap.put("optionName", "数智中台");
                    jsonStr.put("jsonStr", hashMap);
                    Object object = comparisonServiceimpl.updateEntity(jsonStr);
                    logger.info("应付单更新结果为：{}", JSON.toJSONString(result));
                    result.add(object);
                }
            }
            return result;
        }catch (Exception e){
            logger.info("将数据查询之后进行组装调用通用方法错误:{}",e.getMessage());
            //保存业务数据日志
            saveTaskLivingDetails(jsonObjectUser.getString("data_id"),hashMaps.get(0).getString("business_no"),hashMaps.get(0).toString(),result.toString(),false,"MakeInvoicePluginInitializer");
            e.printStackTrace();
        }
        return null;
    }

    private void saveTaskLivingDetails(String rootAppPk,String rootAppBill,String rootAppNewData,String newTransmitInfo,boolean flag,String plugin) {
        try {
            IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity();
            integrationTaskLivingDetailsEntity.setId(UUIDUtils.getUUID());
            integrationTaskLivingDetailsEntity.setSts("Y");
            integrationTaskLivingDetailsEntity.setCreate_user_id("1");
            integrationTaskLivingDetailsEntity.setModify_user_id("1");
            integrationTaskLivingDetailsEntity.setCreate_time(new Date());
            integrationTaskLivingDetailsEntity.setModify_time(new Date());
            integrationTaskLivingDetailsEntity.setOrg_id("0");
            integrationTaskLivingDetailsEntity.setCompanyId("0");
            integrationTaskLivingDetailsEntity.setRootAppPk(rootAppPk);
            integrationTaskLivingDetailsEntity.setRootAppBill(rootAppBill);
            integrationTaskLivingDetailsEntity.setPluginId(plugin);
            integrationTaskLivingDetailsEntity.setRootAppNewData(rootAppNewData);
            integrationTaskLivingDetailsEntity.setNewTransmitInfo(newTransmitInfo);
            if(flag){
                taskLivingDetailsService.saveLogToSuccess(integrationTaskLivingDetailsEntity);
            }else {
                taskLivingDetailsService.saveLogToFail(integrationTaskLivingDetailsEntity);
            }
        }catch (Exception e){
            logger.info("抽取杭泰付款单保存日志到集成任务日志明细中失败:{}",e.getMessage());
            e.printStackTrace();
        }
    }

}
