package org.jeecg.modules.okki.account.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.FastJsonUtil;
import org.jeecg.common.util.ThreadPoolUtil;
import org.jeecg.modules.okki.account.dto.OkkiBindSiteDto;
import org.jeecg.modules.okki.account.entity.OkkiAccount;
import org.jeecg.modules.okki.account.mapper.OkkiAccountMapper;
import org.jeecg.modules.okki.account.param.OkkiAccountResetPwdParam;
import org.jeecg.modules.okki.account.service.IOkkiAccountService;
import org.jeecg.modules.okki.site.service.IOkkiSiteService;
import org.jeecg.modules.okki.siteuser.entity.OkkiSiteUser;
import org.jeecg.modules.okki.siteuser.service.IOkkiSiteUserService;
import org.jeecg.modules.okki.utils.HttpClientUtils;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Description: 小二账号
 * @Author: jeecg-boot
 * @Date: 2024-05-22
 * @Version: V1.0
 */
@Slf4j
@Service
public class OkkiAccountServiceImpl extends ServiceImpl<OkkiAccountMapper, OkkiAccount> implements IOkkiAccountService {

    @Value("${OKKI.BASE_URL_V1}")
    private String URL;

    @Value("${OKKI.CLIENT_SECRET}")
    private String CLIENT_SECRET;

    @Autowired
    private ISysDictService sysDictService;

    @Autowired
    private IOkkiSiteUserService okkiSiteUserService;

    @Autowired
    private IOkkiSiteService okkiSiteService;

    @Override
    public void insertAccount(OkkiAccount okkiAccount) {
        //查询账号是否已存在
        OkkiAccount one = this.getOne(new LambdaQueryWrapper<OkkiAccount>().eq(OkkiAccount::getAccount, okkiAccount.getAccount()));
        if (one != null) {
            throw new RuntimeException("账号已存在,请新增其他账号！");
        }
        //创建小二账号
        // 请求okki平台接口
        Map<String, String> query = new TreeMap<>();
        query.put("sign_method", "hmac-md5");
        query.put("timestamp", String.valueOf(System.currentTimeMillis()));
        query.put("site_id", "sp_weichi");
        query.put("method", "dumpUser");
        Map<String, Object> postData = new HashMap<>();
        try {
            String queryStr = HttpClientUtils.buildQueryString(query);
            postData.put("email", okkiAccount.getAccount());
            postData.put("pwd", okkiAccount.getPassword());
            postData.put("user_role", okkiAccount.getUserRole());

            String body = HttpClientUtils.toJsonString(postData);
            String signStr = queryStr + body;
            query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
            String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
            log.info("url:" + okkiUrl + ",body:" + body);
            String res = HttpClientUtils.doPost(okkiUrl, body);
            log.info(res);
            // {"code":0,"msg":"success","now":"2024-05-06 15:34:54","data":[]}
            JSONObject jsonObject = JSONObject.parseObject(res);
            if (jsonObject.get("code").equals(0)) {
                Object data = jsonObject.get("data");
                JSONObject jsonObject1 = JSONObject.parseObject(data.toString());
                Integer userId = (Integer) jsonObject1.get("user_id");
                Integer userStatus = (Integer) jsonObject1.get("user_status");
                okkiAccount.setUserId(userId);
                okkiAccount.setStatus(userStatus);
                this.save(okkiAccount);
                //关联站点
                if (!okkiAccount.getSiteIds().equals("")) {
                    bindSites(okkiAccount);
                }
            } else {
                throw new RuntimeException(jsonObject.get("msg").toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void insertAccountV2(OkkiAccount okkiAccount) {
        //查询账号是否已存在
        OkkiAccount one = this.getOne(new LambdaQueryWrapper<OkkiAccount>().eq(OkkiAccount::getAccount, okkiAccount.getAccount()));
        if (one != null) {
            throw new RuntimeException("账号已存在,请新增其他账号！");
        }
        //创建小二账号
        // 请求okki平台接口
        Map<String, String> query = new TreeMap<>();
        query.put("sign_method", "hmac-md5");
        query.put("timestamp", String.valueOf(System.currentTimeMillis()));
        query.put("site_id", "sp_weichi");
        query.put("method", "dumpUser");
        Map<String, Object> postData = new HashMap<>();
        try {
            String queryStr = HttpClientUtils.buildQueryString(query);
            postData.put("email", okkiAccount.getAccount());
            postData.put("pwd", okkiAccount.getPassword());
            postData.put("user_role", okkiAccount.getUserRole());
            postData.put("nickname", okkiAccount.getName());
            postData.put("account", okkiAccount.getAccount());
            postData.put("phone", okkiAccount.getPhone());
            log.info("postData:{}", FastJsonUtil.toJSONString(postData));

            String body = HttpClientUtils.toJsonString(postData);
            String signStr = queryStr + body;
            query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
            String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
            log.info("url:" + okkiUrl + ",body:" + body);
            String res = HttpClientUtils.doPost(okkiUrl, body);
            log.info(res);
            // {"code":0,"msg":"success","now":"2024-05-06 15:34:54","data":[]}
            JSONObject jsonObject = JSONObject.parseObject(res);
            if (jsonObject.get("code").equals(0)) {
                Object data = jsonObject.get("data");
                JSONObject jsonObject1 = JSONObject.parseObject(data.toString());
                Integer userId = (Integer) jsonObject1.get("user_id");
                Integer userStatus = (Integer) jsonObject1.get("user_status");
                okkiAccount.setUserId(userId);
                okkiAccount.setStatus(userStatus);
                this.save(okkiAccount);
                //关联站点
                if (!"".equals(okkiAccount.getSiteIds())) {
//                    bindSites(okkiAccount);
//                    bindSitesV2(okkiAccount);
                }
            } else {
                throw new RuntimeException(jsonObject.get("msg").toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void updateAccount(OkkiAccount okkiAccountParam) {
        final OkkiAccount okkiAccount = this.getById(okkiAccountParam.getId());
        okkiAccount.setUserId(okkiAccountParam.getUserId());
        okkiAccount.setName(okkiAccountParam.getName());
        okkiAccount.setSysUserCode(okkiAccountParam.getSysUserCode());
        this.updateById(okkiAccount);
    }

    @Override
    public void resetRole(OkkiAccount okkiAccountParam) {
        // 请求okki平台接口
        Map<String, String> query = new TreeMap<>();
        query.put("sign_method", "hmac-md5");
        query.put("timestamp", String.valueOf(System.currentTimeMillis()));
        query.put("site_id", "sp_weichi");
        query.put("method", "resetRole");
        Map<String, Object> postData = new HashMap<>();
        try {
            String queryStr = HttpClientUtils.buildQueryString(query);
            final OkkiAccount okkiAccount = this.getById(okkiAccountParam.getId());
            postData.put("user_id", okkiAccount.getUserId());
            postData.put("user_role", okkiAccountParam.getUserRole());

            String body = HttpClientUtils.toJsonString(postData);
            String signStr = queryStr + body;
            query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
            String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
            log.info("url:" + okkiUrl + ",body:" + body);
            String res = HttpClientUtils.doPost(okkiUrl, body);
            log.info(res);
            // {"code":0,"msg":"success","now":"2024-05-06 15:34:54","data":[]}
            JSONObject jsonObject = JSONObject.parseObject(res);
            if (jsonObject.get("code").equals(0)) {
                okkiAccount.setUserRole(okkiAccountParam.getUserRole());
                this.updateById(okkiAccount);
            } else {
                throw new RuntimeException(jsonObject.get("msg").toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void resetRoleV2(OkkiAccount okkiAccountParam) {
        // 请求okki平台接口
        Map<String, String> query = new TreeMap<>();
        query.put("sign_method", "hmac-md5");
        query.put("timestamp", String.valueOf(System.currentTimeMillis()));
        query.put("site_id", "sp_weichi");
        query.put("method", "resetUserInfo");
        Map<String, Object> postData = new HashMap<>();
        try {
            String queryStr = HttpClientUtils.buildQueryString(query);
            final OkkiAccount okkiAccount = this.getById(okkiAccountParam.getId());
            postData.put("user_id", okkiAccount.getUserId());
            if (okkiAccountParam.getUserRole() != null) {
                postData.put("user_role", okkiAccountParam.getUserRole());
            }

            if (StringUtils.isNotEmpty(okkiAccountParam.getName())) {
                postData.put("nickname", okkiAccountParam.getName());
            }

            if (StringUtils.isNotEmpty(okkiAccountParam.getAccount())) {
                postData.put("email", okkiAccountParam.getAccount());
            }

            if (StringUtils.isNotEmpty(okkiAccountParam.getPhone())) {
                postData.put("phone", okkiAccountParam.getPhone());
            }
            log.info("postData:{}", FastJsonUtil.toJSONString(postData));

            String body = HttpClientUtils.toJsonString(postData);
            String signStr = queryStr + body;
            query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
            String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
            log.info("url:" + okkiUrl + ",body:" + body);
            String res = HttpClientUtils.doPost(okkiUrl, body);
            log.info(res);
            // {"code":0,"msg":"success","now":"2024-05-06 15:34:54","data":[]}
            JSONObject jsonObject = JSONObject.parseObject(res);
            if (jsonObject.get("code").equals(0)) {
                okkiAccount.setUserRole(okkiAccountParam.getUserRole());
                if (StringUtils.isNotEmpty(okkiAccountParam.getName())) {
                    okkiAccount.setName(okkiAccountParam.getName());
                }

                if (StringUtils.isNotEmpty(okkiAccountParam.getAccount())) {
                    okkiAccount.setAccount(okkiAccountParam.getAccount());
                }

                if (StringUtils.isNotEmpty(okkiAccountParam.getPhone())) {
                    okkiAccount.setPhone(okkiAccountParam.getPhone());
                }
                this.updateById(okkiAccount);
            } else {
                throw new RuntimeException(jsonObject.get("msg").toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void bindSites(OkkiAccount okkiAccountParam) {
        // 请求okki平台接口
        Map<String, String> query = new TreeMap<>();
        query.put("sign_method", "hmac-md5");
        query.put("timestamp", String.valueOf(System.currentTimeMillis()));
        query.put("site_id", "sp_weichi");
        query.put("method", "bindSite");
        Map<String, Object> postData = new HashMap<>();
        try {
            String queryStr = HttpClientUtils.buildQueryString(query);
            final OkkiAccount okkiAccount = this.getById(okkiAccountParam.getId());
            postData.put("user_id", okkiAccount.getUserId());
            // 字符串转数组
            String siteIds = okkiAccountParam.getSiteIds();
            String[] split = siteIds.split(",");
            postData.put("site_ids", split);
            postData.put("type", "update");

            String body = HttpClientUtils.toJsonString(postData);
            String signStr = queryStr + body;
            query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
            String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
            log.info("url:" + okkiUrl + ",body:" + body);
            String res = HttpClientUtils.doPost(okkiUrl, body);
            log.info(res);
            JSONObject jsonObject = JSONObject.parseObject(res);
            if (jsonObject.get("code").equals(0)) {
                okkiAccount.setSiteIds(siteIds);
                this.updateById(okkiAccount);
            } else {
                throw new RuntimeException(jsonObject.get("msg").toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void bindSitesV2(OkkiAccount okkiAccountParam) {
        // 请求okki平台接口
        Map<String, String> query = new TreeMap<>();
        query.put("sign_method", "hmac-md5");
        query.put("timestamp", String.valueOf(System.currentTimeMillis()));
        query.put("site_id", "sp_weichi");
        query.put("method", "bindSiteWithRole");
        Map<String, Object> postData = new HashMap<>();
        try {
            String queryStr = HttpClientUtils.buildQueryString(query);
            final OkkiAccount okkiAccount = this.getById(okkiAccountParam.getId());
//            postData.put("user_id", okkiAccount.getUserId());

            // 字符串转数组
            String siteIds = okkiAccountParam.getSiteIds();
            String[] split = siteIds.split(",");
            postData.put("site_ids", split);

//            List<Integer> userIds = new ArrayList<>();
//            userIds.add(okkiAccount.getUserId());
//            Map<Integer,Object> map = new HashMap<>();
//            map.put(okkiAccount.getUserRole(),userIds);

//            List<Integer> userIds2 = new ArrayList<>();
//            userIds2.add(okkiAccount.getUserId());
//            map.put(2,userIds2);

            List<DictModel> dictModels = sysDictService.getDictItems("user_role");
//            log.info("dictModels:{}",FastJsonUtil.toJSONString(dictModels));
            Map<Integer, Object> userRoleMap = new HashMap<>();
            dictModels.forEach(c -> {
                List<Integer> userIds = new ArrayList<>();
                if (okkiAccount.getUserRole().equals(Integer.valueOf(c.getValue()))) {
                    userIds.add(okkiAccount.getUserId());
                }
                userRoleMap.put(Integer.valueOf(c.getValue()), userIds);
            });
            log.info("userRoleMap:{}", FastJsonUtil.toJSONString(userRoleMap));

            postData.put("user_sets", userRoleMap);
            log.info("postData:{}", FastJsonUtil.toJSONString(postData));

            String body = HttpClientUtils.toJsonString(postData);
            String signStr = queryStr + body;
            query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
            String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
            log.info("url:" + okkiUrl + ",body:" + body);
            String res = HttpClientUtils.doPost(okkiUrl, body);
            log.info(res);
            JSONObject jsonObject = JSONObject.parseObject(res);
            if (jsonObject.get("code").equals(0)) {
                okkiAccount.setSiteIds(siteIds);
                this.updateById(okkiAccount);
            } else {
                throw new RuntimeException(jsonObject.get("msg").toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void bindSitesV2(OkkiBindSiteDto okkiBindSiteDto) {
        // 请求okki平台接口
        Map<String, String> query = new TreeMap<>();
        query.put("sign_method", "hmac-md5");
        query.put("timestamp", String.valueOf(System.currentTimeMillis()));
        query.put("site_id", "sp_weichi");
        query.put("method", "bindSiteWithRole");
        Map<String, Object> postData = new HashMap<>();
        try {
            String queryStr = HttpClientUtils.buildQueryString(query);

            // 字符串转数组
            String siteIds = okkiBindSiteDto.getSiteId();
            String[] split = siteIds.split(",");
            postData.put("site_ids", split);

            Map<Integer, Object> userRoleMap = buildUserRoleMap(okkiBindSiteDto);
            postData.put("user_sets", userRoleMap);
            log.info("postData:{}", FastJsonUtil.toJSONString(postData));

            String body = HttpClientUtils.toJsonString(postData);
            String signStr = queryStr + body;
            query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
            String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
            log.info("url:" + okkiUrl + ",body:" + body);
            String res = HttpClientUtils.doPost(okkiUrl, body);
            log.info(res);
            JSONObject jsonObject = JSONObject.parseObject(res);
            if (jsonObject.get("code").equals(0)) {
                ThreadPoolUtil.execute(() -> {
                    // 保存站点数据
                    buildOkkiSiteUser(okkiBindSiteDto);

                    //更新飞书表格
                    okkiSiteService.saveOrUpdateFeishuSheetFields(okkiBindSiteDto.getSiteId());
                });
            } else {
                throw new RuntimeException(jsonObject.get("msg").toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 构建用户角色映射
     */
    private Map<Integer, Object> buildUserRoleMap(OkkiBindSiteDto okkiBindSiteDto) {
        Map<Integer, Object> userRoleMap = new HashMap<>();

        addRoleToMap(userRoleMap, 1, okkiBindSiteDto.getServiceManageUser());
        addRoleToMap(userRoleMap, 5, okkiBindSiteDto.getDataUser());
        addRoleToMap(userRoleMap, 2, okkiBindSiteDto.getKefuUser());
        addRoleToMap(userRoleMap, 7, okkiBindSiteDto.getSeoUser());
        addRoleToMap(userRoleMap, 9, okkiBindSiteDto.getSemManageUser());
        addRoleToMap(userRoleMap, 10, okkiBindSiteDto.getSemUser());
        addRoleToMap(userRoleMap, 4, okkiBindSiteDto.getUiUser());
        addRoleToMap(userRoleMap, 11, okkiBindSiteDto.getWebsiteUser());
        addRoleToMap(userRoleMap, 8, okkiBindSiteDto.getSocialUser());
        addRoleToMap(userRoleMap, 12, okkiBindSiteDto.getRdUser());

        return userRoleMap;
    }

    /**
     * 向用户角色映射中添加角色
     */
    private void addRoleToMap(Map<Integer, Object> userRoleMap, int roleType, String userId) {
        if (StringUtils.isNotEmpty(userId)) {
            String[] userIds = userId.split(",");
            userRoleMap.put(roleType, userIds);
        }
    }

    /**
     * 构建OkkiSite对象
     */
    private void buildOkkiSiteUser(OkkiBindSiteDto okkiBindSiteDto) {
        List<OkkiSiteUser> okkiSiteUsers = new ArrayList<>();

        try {
            // 删除已有的站点用户
            QueryWrapper<OkkiSiteUser> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("site_id", Integer.valueOf(okkiBindSiteDto.getSiteId()));
            boolean isRemoved = okkiSiteUserService.remove(queryWrapper);
            log.info("Removed existing site users for siteId {}: {}", okkiBindSiteDto.getSiteId(), isRemoved);

            // 用户类型映射
            Map<String, String> userTypeMapping = new HashMap<>();
            userTypeMapping.put("serviceManageUser", okkiBindSiteDto.getServiceManageUser());
            userTypeMapping.put("dataUser", okkiBindSiteDto.getDataUser());
            userTypeMapping.put("kefuUser", okkiBindSiteDto.getKefuUser());
            userTypeMapping.put("seoUser", okkiBindSiteDto.getSeoUser());
            userTypeMapping.put("semManageUser", okkiBindSiteDto.getSemManageUser());
            userTypeMapping.put("semUser", okkiBindSiteDto.getSemUser());
            userTypeMapping.put("uiUser", okkiBindSiteDto.getUiUser());
            userTypeMapping.put("websiteUser", okkiBindSiteDto.getWebsiteUser());
            userTypeMapping.put("socialUser", okkiBindSiteDto.getSocialUser());
            userTypeMapping.put("rdUser", okkiBindSiteDto.getRdUser());

            // 遍历映射关系，构建 OkkiSiteUser 对象
            for (Map.Entry<String, String> entry : userTypeMapping.entrySet()) {
                String userType = entry.getKey();
                String userIds = entry.getValue();

                if (userIds != null && !userIds.isEmpty()) {
                    String[] userArr = userIds.split(",");
                    for (String s : userArr) {
                        OkkiSiteUser okkiSiteUser = new OkkiSiteUser();
                        okkiSiteUser.setSiteId(Integer.valueOf(okkiBindSiteDto.getSiteId()));
                        okkiSiteUser.setUserId(Integer.valueOf(s));
                        okkiSiteUser.setType(userType);
                        okkiSiteUsers.add(okkiSiteUser);
                    }
                }
            }

            // 批量保存站点用户数据
            boolean isSaved = okkiSiteUserService.saveBatch(okkiSiteUsers);
            log.info("Saved site users for siteId {}: {}", okkiBindSiteDto.getSiteId(), isSaved);

        } catch (Exception e) {
            log.error("Error building OkkiSiteUser for siteId {}", okkiBindSiteDto.getSiteId(), e);
            throw new RuntimeException("Error building OkkiSiteUser", e);
        }
    }

    @Override
    public void resetPwd(OkkiAccountResetPwdParam okkiAccountResetPwdParam) {
        // 请求okki平台接口
        Map<String, String> query = new TreeMap<>();
        query.put("sign_method", "hmac-md5");
        query.put("timestamp", String.valueOf(System.currentTimeMillis()));
        query.put("site_id", "sp_weichi");
        query.put("method", "resetPwd");
        Map<String, Object> postData = new HashMap<>();
        try {
            String queryStr = HttpClientUtils.buildQueryString(query);
            final OkkiAccount okkiAccount = this.getById(okkiAccountResetPwdParam.getId());
            postData.put("user_id", okkiAccount.getUserId());
            postData.put("old_pwd", okkiAccountResetPwdParam.getOldPassword());
            postData.put("pwd", okkiAccountResetPwdParam.getNewPassword());

            String body = HttpClientUtils.toJsonString(postData);
            String signStr = queryStr + body;
            query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
            String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
            log.info("url:" + okkiUrl + ",body:" + body);
            String res = HttpClientUtils.doPost(okkiUrl, body);
            log.info(res);
            JSONObject jsonObject = JSONObject.parseObject(res);
            if (jsonObject.get("code").equals(0)) {
                okkiAccount.setPassword(okkiAccountResetPwdParam.getNewPassword());
                this.updateById(okkiAccount);
            } else {
                throw new RuntimeException(jsonObject.get("msg").toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 获取站点绑定信息
     *
     * @param siteId
     */
    @Override
    public Map<String, Object> getSiteBindInfo(Integer siteId) {
        Map<String, Object> mergedList = new HashMap<>();
        // 请求okki平台接口
        Map<String, String> query = new TreeMap<>();
        query.put("sign_method", "hmac-md5");
        query.put("timestamp", String.valueOf(System.currentTimeMillis()));
        query.put("site_id", "sp_weichi");
        query.put("method", "siteBindInfo");
        Map<String, Object> postData = new HashMap<>();
        try {
            String queryStr = HttpClientUtils.buildQueryString(query);
            postData.put("site_id", siteId);

            String body = HttpClientUtils.toJsonString(postData);
            String signStr = queryStr + body;
            query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
            String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
            log.info("url:" + okkiUrl + ",body:" + body);
            String res = HttpClientUtils.doPost(okkiUrl, body);
            log.info(res);
            // {"code":0,"msg":"success","now":"2024-05-06 15:34:54","data":[]}
            JSONObject jsonObject = JSONObject.parseObject(res);
            if (jsonObject.get("code").equals(0)) {
                JSONObject dataObject = jsonObject.getJSONObject("data");
                Map<String, Object> check = FastJsonUtil.parseObject(dataObject.get("check").toString(), Map.class);
                Map<String, Object> other = FastJsonUtil.parseObject(dataObject.get("other").toString(), Map.class);
                mergedList.putAll(check);
                mergedList.putAll(other);
            }
//            else {
//                throw new RuntimeException(jsonObject.get("msg").toString());
//            }
        } catch (Exception e) {
//            throw new RuntimeException(e);
        }
        return mergedList;
    }
}
