package com.hzya.frame.sysnew.grovy.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
import com.hzya.frame.sysnew.grovy.service.IGroovyIntegrationService;
import com.hzya.frame.util.GroovyUtil;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Groovy 脚本执行实现类
 *
 * @author 👻👻👻👻👻👻👻👻👻👻 gjh
 * @version 1.0
 * @content
 * @date 2024-05-15 13:50
 */
@Service(value = "groovyIntegrationService")
public class GroovyIntegrationServiceImpl implements IGroovyIntegrationService {
    private static final Logger logger = LoggerFactory.getLogger(GroovyIntegrationServiceImpl.class);


    @Override
    public Object groovyScriptExecution(JSONObject jsonObject) {
        Object object = GroovyUtil.execute(jsonObject);
        return object;
    }

    public static void main(String[] args) {
        java.lang.String str = "{\"data\":{\"year\":\"2024\",\"prepared\":\"demo\",\"modify_time\":1730863191000,\"num\":\"13\",\"gl_detail\":[{\"create_user_id\":\"1\",\"amount\":\"5000\",\"formmain_id\":\"9da5a28900084951913df0d233427178\",\"create_time\":1730863191000,\"company_id\":\"0\",\"globalcreditamount\":\"0\",\"modify_time\":1730863191000,\"localcreditamount\":\"0\",\"localdebitamount\":\"5000\",\"explanation\":\"演示分录1\",\"globaldebitamount\":\"5000\",\"detail_id\":\"1\",\"groupdebitamount\":\"5000\",\"sts\":\"Y\",\"currtype_code\":\"CNY\",\"org_id\":\"0\",\"busidate\":\"2024-11-05\",\"groupcreditamount\":\"0\",\"detailindex\":\"1\",\"account_code\":\"100210\",\"id\":\"0eb6d3d5f12944e1bcbb00883cc4f13e\",\"data_status\":\"Y\",\"modify_user_id\":\"1\",\"sorts\":1},{\"create_user_id\":\"1\",\"amount\":\"5000\",\"formmain_id\":\"9da5a28900084951913df0d233427178\",\"create_time\":1730863191000,\"company_id\":\"0\",\"globalcreditamount\":\"5000\",\"modify_time\":1730863191000,\"localcreditamount\":\"5000\",\"localdebitamount\":\"0\",\"explanation\":\"演示分录2\",\"globaldebitamount\":\"0\",\"detail_id\":\"2\",\"groupdebitamount\":\"0\",\"sts\":\"Y\",\"currtype_code\":\"CNY\",\"org_id\":\"0\",\"busidate\":\"2024-11-05\",\"groupcreditamount\":\"5000\",\"detailindex\":\"2\",\"account_code\":\"2231\",\"id\":\"db9c531af7a94af2975d1c9f1ae21813\",\"data_status\":\"Y\",\"modify_user_id\":\"1\",\"sorts\":2}],\"document_rule_num\":1,\"add_status\":\"0\",\"vouchertype\":\"01\",\"attachment\":\"0\",\"delete_status\":\"1\",\"id\":\"9da5a28900084951913df0d233427178\",\"data_status\":\"Y\",\"modify_user_id\":\"1\",\"sorts\":1,\"document_rule\":\"PZ-20241106-00001\",\"create_user_id\":\"1\",\"period\":\"11\",\"create_time\":1730863191000,\"company_id\":\"Y\",\"update_status\":\"1\",\"accbook_code\":\"101-0002\",\"sts\":\"Y\",\"org_id\":\"Y\",\"prepareddate\":\"2024-11-05\",\"voucher_id\":\"1\",\"gl_fixtmpfreevalue\":[{\"create_user_id\":\"1\",\"formmain_id\":\"9da5a28900084951913df0d233427178\",\"create_time\":1730863191000,\"company_id\":\"0\",\"checktypecode\":\"0012\",\"modify_time\":1730863191000,\"checkvaluecode\":\"101\",\"detail_id\":\"2\",\"sts\":\"Y\",\"org_id\":\"0\",\"voucher_id\":\"1\",\"id\":\"779d40051ae3470583885d9c202d5ba1\",\"data_status\":\"Y\",\"modify_user_id\":\"1\",\"sorts\":1},{\"create_user_id\":\"1\",\"formmain_id\":\"9da5a28900084951913df0d233427178\",\"create_time\":1730863191000,\"company_id\":\"0\",\"checktypecode\":\"0006\",\"modify_time\":1730863191000,\"checkvaluecode\":\"000001\",\"detail_id\":\"2\",\"sts\":\"Y\",\"org_id\":\"0\",\"voucher_id\":\"1\",\"id\":\"f313361e495445958245ec61a00a1216\",\"data_status\":\"Y\",\"modify_user_id\":\"1\",\"sorts\":2}]},\"query\":\"[]\",\"header\":\"[{\\\"parameterType\\\":\\\"fundamental\\\",\\\"index\\\":0,\\\"concreteType\\\":\\\"String\\\",\\\"id\\\":\\\"77ba4bd1-c693-488f-b3b7-69bb4c02be76\\\",\\\"parameterName\\\":\\\"pubKey\\\",\\\"example\\\":\\\"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmlnN6sXjhJN6wUY0DILqiIL1ZX9ZU5Q40Hrr+4qhf3fddV/+/D1CyJo7aVGd3mJjD1BC1RXtnfxetaLzLrfTViq80RQvmmmKgt6rKiYMiW8ibcWoKaWMvwrlm0uT7RzYeXDP0l4qvoe8vjVWL63mQbx0y17p4opwTA9BV7P/CZ+9QyIJstN+yAg/owlNn48Jq4WspQps0/Zl/HvpiRjAPggVOqZLXkCjoBGrpNn/tlrDFbt+btK7tjhvsfT1zPMVAq8dNUKCMw5LoLsMxfT/ZWlI62zUAIbyO2/0iv5kCZw0I+DxPmGKVEOQ4x9FwXosSSD202H93CuBvVy/P31iUwIDAQAB\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"index\\\":1,\\\"concreteType\\\":\\\"String\\\",\\\"id\\\":\\\"df32aa53-9c8e-4d31-8a9b-d78bc70f9214\\\",\\\"parameterName\\\":\\\"client_id\\\",\\\"example\\\":\\\"u8c\\\"},{\\\"parameterType\\\":\\\"authport\\\",\\\"index\\\":2,\\\"concreteType\\\":\\\"String\\\",\\\"id\\\":\\\"de304f55-ca04-47d9-93f9-70b52d9bba50\\\",\\\"parameterName\\\":\\\"access_token\\\",\\\"example\\\":[\\\"attribute\\\",\\\"data\\\",\\\"access_token\\\"]}]\",\"body\":\"[{\\\"parameterType\\\":\\\"complex\\\",\\\"children\\\":[{\\\"parameterType\\\":\\\"complex\\\",\\\"children\\\":[{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":2,\\\"parameterName\\\":\\\"accbookCode\\\",\\\"id\\\":\\\"95ff2224-bdb7-4a9d-a45b-8c19f444022b\\\",\\\"example\\\":\\\"X0644-0001\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":3,\\\"parameterName\\\":\\\"prepareddate\\\",\\\"id\\\":\\\"7106bf79-133c-446e-be58-bf18d43a7c14\\\",\\\"example\\\":\\\"2023-09-19\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":4,\\\"parameterName\\\":\\\"year\\\",\\\"id\\\":\\\"9b005ca9-e246-41c0-bbbb-aead5d6f44f1\\\",\\\"example\\\":\\\"2023\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":5,\\\"parameterName\\\":\\\"num\\\",\\\"id\\\":\\\"fbe1d3a2-69e9-4df7-91d0-bb9005cd333e\\\",\\\"example\\\":\\\"4\\\"},{\\\"parameterType\\\":\\\"complexlist\\\",\\\"children\\\":[{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":7,\\\"parameterName\\\":\\\"detailindex\\\",\\\"id\\\":\\\"386e20b9-5992-4a95-8fa7-fb64677d55e9\\\",\\\"example\\\":\\\"1\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":8,\\\"parameterName\\\":\\\"explanation\\\",\\\"id\\\":\\\"20cab876-bd5a-46b8-96ba-7112104a273f\\\",\\\"example\\\":\\\"测试\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":9,\\\"parameterName\\\":\\\"accountCode\\\",\\\"id\\\":\\\"e1a89672-8449-4bda-a404-478f0594ac70\\\",\\\"example\\\":\\\"150401\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":10,\\\"parameterName\\\":\\\"currtypeCode\\\",\\\"id\\\":\\\"43b33900-c5da-4afb-bbd7-0865bd02db58\\\",\\\"example\\\":\\\"CNY\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":11,\\\"parameterName\\\":\\\"amount\\\",\\\"id\\\":\\\"4b0fd6a4-b1d0-489e-aec1-ca509e9221ad\\\",\\\"example\\\":\\\"1000\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":12,\\\"parameterName\\\":\\\"localdebitamount\\\",\\\"id\\\":\\\"9a43ad19-f903-4a8a-a5ac-f13c9fba445e\\\",\\\"example\\\":\\\"1000\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":13,\\\"parameterName\\\":\\\"localcreditamount\\\",\\\"id\\\":\\\"df2d1f92-89cb-411d-83ba-62366e931dba\\\",\\\"example\\\":\\\"0\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":14,\\\"parameterName\\\":\\\"groupdebitamount\\\",\\\"id\\\":\\\"61965366-0500-40d7-bae4-5dd16eb90761\\\",\\\"example\\\":\\\"1000\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":15,\\\"parameterName\\\":\\\"groupcreditamount\\\",\\\"id\\\":\\\"bdc3c6c2-de87-45f1-85cf-24f3b92920c6\\\",\\\"example\\\":\\\"0\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":16,\\\"parameterName\\\":\\\"globaldebitamount\\\",\\\"id\\\":\\\"a6069792-2a6b-43ba-97d7-504e1c5e3156\\\",\\\"example\\\":\\\"1000\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":17,\\\"parameterName\\\":\\\"globalcreditamount\\\",\\\"id\\\":\\\"528b2c6b-86a5-47ec-8b26-00259dacb0b4\\\",\\\"example\\\":\\\"0\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":18,\\\"parameterName\\\":\\\"busidate\\\",\\\"id\\\":\\\"11636e2a-b9d8-4ee3-81fc-0e809d11bf4f\\\",\\\"example\\\":\\\"2023-09-19\\\"},{\\\"parameterType\\\":\\\"complexlist\\\",\\\"children\\\":[{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":20,\\\"parameterName\\\":\\\"checktypecode\\\",\\\"id\\\":\\\"b56bf160-7180-47ea-996a-acd8307eb5fa\\\",\\\"example\\\":\\\"0004\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":21,\\\"parameterName\\\":\\\"checkvaluecode\\\",\\\"id\\\":\\\"88d4fbb0-d3b7-4f1e-981d-71e60d10e603\\\",\\\"example\\\":\\\"X0015\\\"}],\\\"concreteType\\\":\\\"ObjectCom\\\",\\\"index\\\":19,\\\"parameterName\\\":\\\"ass\\\",\\\"id\\\":\\\"c10103af-f382-4c9b-a8f4-0738b664abb0\\\"}],\\\"concreteType\\\":\\\"ObjectCom\\\",\\\"index\\\":6,\\\"parameterName\\\":\\\"detail\\\",\\\"id\\\":\\\"70f9d810-039e-4884-b986-bc5b75331fb4\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":22,\\\"parameterName\\\":\\\"period\\\",\\\"id\\\":\\\"de91d6ad-c07b-4f84-a8c9-52e87de39d50\\\",\\\"example\\\":\\\"09\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":23,\\\"parameterName\\\":\\\"vouchertype\\\",\\\"id\\\":\\\"5de12ed3-d27e-4848-a008-5fb2e5c656a8\\\",\\\"example\\\":\\\"01\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":24,\\\"parameterName\\\":\\\"attachment\\\",\\\"id\\\":\\\"cc0ae4fb-5f33-46c9-a0bf-775b46ae8511\\\",\\\"example\\\":\\\"0\\\"},{\\\"parameterType\\\":\\\"fundamental\\\",\\\"concreteType\\\":\\\"String\\\",\\\"index\\\":25,\\\"parameterName\\\":\\\"prepared\\\",\\\"id\\\":\\\"4b1622d6-980e-4920-82d0-e078e8bdb009\\\",\\\"example\\\":\\\"zhuc\\\"}],\\\"concreteType\\\":\\\"Object\\\",\\\"index\\\":1,\\\"parameterName\\\":\\\"sendData\\\",\\\"id\\\":\\\"2fc2918b-73fd-4c31-ba9f-1721132f1fdf\\\"}],\\\"concreteType\\\":\\\"Object\\\",\\\"index\\\":0,\\\"id\\\":\\\"669eebef-e4ae-474e-9b88-46a5490dc3db\\\",\\\"parameterName\\\":\\\"body\\\",\\\"first\\\":true}]\"}";
        A88772 s = new A88772();
        s.execute(str);
    }

    static class A88772 {
        String execute(String jsonStr) {
            com.alibaba.fastjson.JSONObject reqData = com.alibaba.fastjson.JSON.parseObject(jsonStr);
            com.alibaba.fastjson.JSONObject data = reqData.getJSONObject("data");
            com.alibaba.fastjson.JSONArray gl_detail = data.getJSONArray("gl_detail");
            com.alibaba.fastjson.JSONArray gl_fixtmpfreevalue = data.getJSONArray("gl_fixtmpfreevalue");

            com.alibaba.fastjson.JSONObject returnObject = new com.alibaba.fastjson.JSONObject();
            com.alibaba.fastjson.JSONObject sendData = new com.alibaba.fastjson.JSONObject();
            sendData.put("accbookCode",data.getString("accbook_code"));
            sendData.put("prepareddate",data.getString("prepareddate"));
            sendData.put("year",data.getString("year"));
            sendData.put("num",data.getString("num"));
            sendData.put("period",data.getString("period"));
            sendData.put("vouchertype",data.getString("vouchertype"));
            sendData.put("attachment",data.getString("attachment"));
            sendData.put("prepared",data.getString("prepared"));
            com.alibaba.fastjson.JSONArray detail = new com.alibaba.fastjson.JSONArray();
            if(gl_detail != null && gl_detail.size() > 0){
                for (int i = 0; i < gl_detail.size(); i++) {
                    com.alibaba.fastjson.JSONObject detaildata = gl_detail.getJSONObject(i);
                    com.alibaba.fastjson.JSONObject object1 = new com.alibaba.fastjson.JSONObject();
                    object1.put("detailindex",detaildata.getString("detailindex"));
                    object1.put("explanation",detaildata.getString("explanation"));
                    object1.put("accountCode",detaildata.getString("account_code"));
                    object1.put("currtypeCode",detaildata.getString("currtype_code"));
                    object1.put("amount",detaildata.getString("amount"));
                    object1.put("localdebitamount",detaildata.getString("localdebitamount"));
                    object1.put("localcreditamount",detaildata.getString("localcreditamount"));
                    object1.put("groupdebitamount",detaildata.getString("groupdebitamount"));
                    object1.put("groupcreditamount",detaildata.getString("groupcreditamount"));
                    object1.put("globaldebitamount",detaildata.getString("globaldebitamount"));
                    object1.put("globalcreditamount",detaildata.getString("globalcreditamount"));
                    object1.put("busidate",detaildata.getString("busidate"));
                    detail.add(object1);
                    if(gl_fixtmpfreevalue != null && gl_fixtmpfreevalue.size() > 0){
                        com.alibaba.fastjson.JSONArray ass = new com.alibaba.fastjson.JSONArray();
                        for (int i1 = 0; i1 < gl_fixtmpfreevalue.size(); i1++) {
                            if(gl_fixtmpfreevalue.getJSONObject(i1).getString("voucher_id").equals(data.getString("voucher_id"))
                                && gl_fixtmpfreevalue.getJSONObject(i1).getString("detail_id").equals(detaildata.getString("detail_id"))){
                                com.alibaba.fastjson.JSONObject assdetail1 = new com.alibaba.fastjson.JSONObject();
                                assdetail1.put("checktypecode",gl_fixtmpfreevalue.getJSONObject(i1).getString("checktypecode"));
                                assdetail1.put("checkvaluecode",gl_fixtmpfreevalue.getJSONObject(i1).getString("checkvaluecode"));
                                ass.add(assdetail1);
                            }
                        }
                        if(ass.size() > 0){
                            object1.put("ass",ass);

                        }
                    }
                }
            }
            sendData.put("detail",detail);
            returnObject.put("bodys",sendData);
            return returnObject.toJSONString();
        }
    }


}
