package com.seeyon.apps.ydctu8c.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.ext.workflow.vo.FormDataVo;
import com.seeyon.apps.ydctu8c.vo.U8cResponse;
import com.seeyon.cap4.form.api.FormDataApi4Cap4;
import com.seeyon.cap4.form.bean.FormDataMasterBean;
import com.seeyon.cap4.form.bean.FormDataSubBean;
import com.seeyon.ctp.common.exceptions.BusinessException;

import java.util.List;

public class Cap4ReturnUtil {

    public void setParamReturn(String method, U8cResponse u8cResponse, FormDataVo formDataVo) throws BusinessException {
        if("/u8cloud/api/uapbd/custdoc/insert".equals(method)){
            String data = u8cResponse.getData();
            JSONArray jsonArray = (JSONArray) JSON.parse(data);
            JSONObject jsonObject = jsonArray.getJSONObject(0);
            JSONObject parentvo = jsonObject.getJSONObject("parentvo");
            formDataVo.getNewFieldDataMap().put("客商主键", parentvo.getString("pk_cubasdoc"));
            JSONArray banks = jsonObject.getJSONArray("BANK");
//            银行id
            String bankIds = "";
            for(int i = 0 ; i < banks.size() ; i++){
                JSONObject bank = banks.getJSONObject(i);
                String bankNo = bank.getString("account");
                String bankId = bank.getString("pk_custbank");
                bankIds = bankIds+bankNo+":"+bankId+";";
            }
            bankIds = bankIds.substring(0,bankIds.length() - 1);
            formDataVo.getNewFieldDataMap().put("U8C返回客商银行对照", bankIds);
        }
    }


}
