package com.lz.modules.flow.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lz.common.utils.Constant;
import com.lz.common.utils.NumberUtil;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class TypeFlowDto {
    private String type;
    private Long flowId;

    public TypeFlowDto() {
    }

    public TypeFlowDto(String type, Long flowId) {
        this.type = type;
        this.flowId = flowId;
    }


    public static Long getFlowId(String flowInfo, String orderTo, Integer type) {
        Map<String, JSONObject> map = JSONObject.parseObject(flowInfo, Map.class);
        JSONObject flowType = map.get(orderTo);
        Map<String, Integer> list = JSONObject.parseObject(flowType.toJSONString(), Map.class);
        return NumberUtil.objToLongDefault(list.get(Constant.TYPE + type),0l);
    }


    public static void main(String[] args) {
        Map<String, Map<String, Long>> map = new HashMap<>();
        Map<String, Long> map1 = new HashMap<>();
        map1.put("type1" ,6l);
        map1.put("type2", 1l);


        Map<String,Long> map2 = new HashMap<>();
        map2.put("type1",7l);
        map2.put("type2",2l);

        map.put("child",map1);
        map.put("self",map2);

        String a = JSON.toJSONString(map);
        System.out.println(a);
        Long b = getFlowId(a,"self",2);
        System.out.println(b);




    }



}
