package com.gci.boot.modules.demo.utildemo;

import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.gci.boot.common.util.DateUtils;
import com.gci.boot.common.util.JsonUtil;
import com.gci.boot.modules.projects.entity.TbVehicleCheck;
import com.gci.boot.modules.projects.entity.TbVehicleCheckDetail;
import com.gci.boot.modules.system.entity.SysUser;

public class JsonUtilDemo {

    public static void test(){
        SysUser user = new SysUser();
        user.setUsername("admin");
        user.setRealname("管理员");
        user.setCreateTime(new Date());
        //对象非空字段转json
        System.out.println(JsonUtil.object2Json(user));
        //对象非空字段转json，格式美化
        System.out.println(JsonUtil.object2JsonPretty(user));
        //对象全部字段转json
        System.out.println(JsonUtil.object2JsonAll(user));
        //对象全部字段转json，格式美化
        System.out.println(JsonUtil.object2JsonAllPretty(user));

        String jsonStr = "{\"username\":\"admin\",\"realname\":\"管理员\",\"createTime\":\"2023-08-21 16:03:26\"}";
        String jsonListStr = "[{\"username\":\"admin\",\"realname\":\"管理员\",\"createTime\":\"2023-08-21 16:03:26\"}]";
        //json字符串转map
        Map<String, Object> map = JsonUtil.json2Map(jsonStr);
        //json字符串转对象
        SysUser sysUser = JsonUtil.json2Object(jsonStr, SysUser.class);
        //json字符串转map列表
        List<Map> mapList = JsonUtil.json2MapList(jsonListStr);
        //json字符串转对象列表
        List<SysUser> userList = JsonUtil.json2List(jsonListStr, SysUser.class);
    }

    public static void main(String[] args) {
        test();
        TbVehicleCheck item = new TbVehicleCheck();
        /*item.setId("1111");
        item.setName("nnn");
        LinkedHashMap<String,List<TbVehicleCheckTemplateProject>> projects = new LinkedHashMap<>();
        List<TbVehicleCheckTemplateProject> projectList = new ArrayList<>();
		for (int i=666;i<668;i++) {
			String name = "name111";
			TbVehicleCheckTemplateProject p = new TbVehicleCheckTemplateProject();
			p.setName(name);
			p.setContent("content"+i);
			List<TbVehicleCheckTemplateProject> project = projects.getOrDefault(name, new ArrayList<TbVehicleCheckTemplateProject>());
			project.add(p);
			projects.put(name, project);
			
			projectList.add(p);
			
		}
		//item.setProjects(projects);
*/        
        System.out.println(JsonUtil.object2JsonAll(item));

		Date nextMonth = DateUtils.getLastDayForNextMonth(new Date(),1,2);
        System.out.println(DateUtils.formatTime(nextMonth));
    }
}
