RestTest.java 8.57 KB
package cn.com.glsx.test;

import cn.com.glsx.admin.modules.model.ElectricFenceSnsModel;
import cn.com.glsx.admin.modules.model.SimpleTreeModel;
import cn.com.glsx.admin.modules.model.param.ElectricFenceBO;
import cn.com.glsx.usercenter.api.dto.response.User;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import java.util.Date;
import java.util.List;

public class RestTest {

    public static void main(String[] args) {
//        RestTemplate restTemplate = new RestTemplate();
//        String url = "";
//        R messageList = restTemplate.getForObject(url, R.class);

//        test();
//        testOrg();

        ElectricFenceBO fenceBO = new ElectricFenceBO();
        //fenceBO.setId(1024L);
        fenceBO.setFenceName("特约店围栏-新增测试5");
        fenceBO.setBizFenceType(1);
        fenceBO.setShapeType(1);
        fenceBO.setRadius(1000);
        fenceBO.setLnglat("113.528632,22.443676");
        fenceBO.setTimeType(0);
        fenceBO.setEnableStatus(1);
        fenceBO.setRemark("这是一个测试围栏");
//        electricFenceService.updateFence(fenceBO);

        List<ElectricFenceSnsModel> snList = Lists.newArrayList();
        ElectricFenceSnsModel snsModel = new ElectricFenceSnsModel();
        snsModel.setSn("8130902018");
        snsModel.setName("刘建平");
        snsModel.setVin("LBEYFAKD2CY146068");
        snsModel.setUserTel("13800138000");
        snsModel.setTime("");
        snsModel.setAddress("测试地址");
        snList.add(snsModel);
        fenceBO.setSnList(snList);

        System.out.println(JSON.toJSONString(fenceBO));
    }

    public static void test() {
        String str = "{\"code\":200,\"data\":{\"id\":1,\"username\":\"超级管理员\",\"account\":\"admin\",\"gender\":0,\"phoneNumber\":\"13800138000\",\"portrait\":null,\"email\":null},\"message\":\"success\"}";
//        R r = JSON.parseObject(str, R.class, new ParserConfig(), Feature.values());
//        System.out.println(r);

        R<User> r2 = JSON.parseObject(str, new TypeReference<R<User>>() {
        });
        System.out.println(r2);

        Gson gson = new GsonBuilder().serializeNulls().create();
        R<User> r3 = gson.fromJson(str, new TypeToken<R<User>>() {
        }.getType());
        System.out.println(r3);
    }

    public static void testOrg() {
        String json = "[\n" +
                "    {\n" +
                "      \"userNumber\": 0,\n" +
                "      \"children\": [\n" +
                "        {\n" +
                "          \"userNumber\": 0,\n" +
                "          \"children\": [\n" +
                "            {\n" +
                "              \"userNumber\": 0,\n" +
                "              \"children\": [\n" +
                "                {\n" +
                "                  \"userNumber\": 0,\n" +
                "                  \"children\": [\n" +
                "                    {\n" +
                "                      \"userNumber\": 3,\n" +
                "                      \"children\": [\n" +
                "                        {\n" +
                "                          \"userNumber\": 1,\n" +
                "                          \"children\": [],\n" +
                "                          \"id\": 165,\n" +
                "                          \"origin\": {\n" +
                "                            \"orgId\": 165,\n" +
                "                            \"orgName\": \"广州恒福店\",\n" +
                "                            \"parentId\": 162,\n" +
                "                            \"tenantId\": 33,\n" +
                "                            \"isRoot\": 0\n" +
                "                          },\n" +
                "                          \"depth\": 5,\n" +
                "                          \"parentId\": 162,\n" +
                "                          \"label\": \"广州恒福店\"\n" +
                "                        },\n" +
                "                        {\n" +
                "                          \"userNumber\": 1,\n" +
                "                          \"children\": [],\n" +
                "                          \"id\": 169,\n" +
                "                          \"origin\": {\n" +
                "                            \"orgId\": 169,\n" +
                "                            \"orgName\": \"广州恒源店\",\n" +
                "                            \"parentId\": 162,\n" +
                "                            \"tenantId\": 33,\n" +
                "                            \"isRoot\": 0\n" +
                "                          },\n" +
                "                          \"depth\": 5,\n" +
                "                          \"parentId\": 162,\n" +
                "                          \"label\": \"广州恒源店\"\n" +
                "                        }\n" +
                "                      ],\n" +
                "                      \"id\": 162,\n" +
                "                      \"origin\": {\n" +
                "                        \"orgId\": 162,\n" +
                "                        \"orgName\": \"广州店\",\n" +
                "                        \"parentId\": 161,\n" +
                "                        \"tenantId\": 33,\n" +
                "                        \"isRoot\": 0\n" +
                "                      },\n" +
                "                      \"depth\": 4,\n" +
                "                      \"parentId\": 161,\n" +
                "                      \"label\": \"广州店\"\n" +
                "                    }\n" +
                "                  ],\n" +
                "                  \"id\": 161,\n" +
                "                  \"origin\": {\n" +
                "                    \"orgId\": 161,\n" +
                "                    \"orgName\": \"广州市\",\n" +
                "                    \"parentId\": 160,\n" +
                "                    \"tenantId\": 33,\n" +
                "                    \"isRoot\": 0\n" +
                "                  },\n" +
                "                  \"depth\": 3,\n" +
                "                  \"parentId\": 160,\n" +
                "                  \"label\": \"广州市\"\n" +
                "                }\n" +
                "              ],\n" +
                "              \"id\": 160,\n" +
                "              \"origin\": {\n" +
                "                \"orgId\": 160,\n" +
                "                \"orgName\": \"广东省\",\n" +
                "                \"parentId\": 157,\n" +
                "                \"tenantId\": 33,\n" +
                "                \"isRoot\": 0\n" +
                "              },\n" +
                "              \"depth\": 2,\n" +
                "              \"parentId\": 157,\n" +
                "              \"label\": \"广东省\"\n" +
                "            }\n" +
                "          ],\n" +
                "          \"id\": 157,\n" +
                "          \"origin\": {\n" +
                "            \"orgId\": 157,\n" +
                "            \"orgName\": \"华南区\",\n" +
                "            \"parentId\": 156,\n" +
                "            \"tenantId\": 33,\n" +
                "            \"isRoot\": 0\n" +
                "          },\n" +
                "          \"depth\": 1,\n" +
                "          \"parentId\": 156,\n" +
                "          \"label\": \"华南区\"\n" +
                "        }\n" +
                "      ],\n" +
                "      \"id\": 156,\n" +
                "      \"origin\": {\n" +
                "        \"orgId\": 156,\n" +
                "        \"orgName\": \"广汽本田\",\n" +
                "        \"parentId\": 156,\n" +
                "        \"tenantId\": 33,\n" +
                "        \"isRoot\": 1\n" +
                "      },\n" +
                "      \"depth\": 0,\n" +
                "      \"parentId\": 156,\n" +
                "      \"label\": \"广汽本田\"\n" +
                "    }\n" +
                "  ]";
        Gson gson = new GsonBuilder().serializeNulls().create();
        List<SimpleTreeModel> r3 = gson.fromJson(json, new TypeToken<List<SimpleTreeModel>>() {
        }.getType());
        System.out.println(r3);
    }
}