package com.ruoyi.system.domain.cnooc;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class User {
    public static void main(String[] args) {
        String getJson = "[\n" +
                "    {\n" +
                "        \"userList\": [\n" +
                "            {\n" +
                "                \"cid\": 1509449970526724098,\n" +
                "                \"userid\": \"aiyk\",\n" +
                "                \"username\": \"艾昀堃\",\n" +
                "                \"depart\": \"19\",\n" +
                "                \"sex\": null,\n" +
                "                \"iphone\": null,\n" +
                "                \"birth\": null\n" +
                "            },\n" +
                "            {\n" +
                "                \"cid\": 1605118314544566274,\n" +
                "                \"userid\": \"banym\",\n" +
                "                \"username\": \"班月明\",\n" +
                "                \"depart\": \"19\",\n" +
                "                \"sex\": null,\n" +
                "                \"iphone\": null,\n" +
                "                \"birth\": null\n" +
                "            }\n" +
                "        \n" +
                "        ],\n" +
                "        \"deptid\": \"19\",\n" +
                "        \"deptname\": \"运行一部\"\n" +
                "    }\n" +
                "]";

        List<User> userList = JSON.parseArray(getJson, User.class);
        System.out.println("list = " + userList);
        System.out.println("list = " + JSON.toJSONString(userList));
    }

    /**
     * 上级组织机构编码
     */
    @JSONField(name = "deptid")
    private Long deptId;
    /**
     * 上级组织机构名称
     */
//    @JSONField(name = "deptname")
//    private String deptName;


    @JSONField(name = "userList")
    private List<ChildrenUser> children = new ArrayList<>();

    @Data
    public static class ChildrenUser {

        /**
         * ID
         */
        @JSONField(name = "cid")
        private Long userId;//": 1605118314544566274,

        /**
         * 账号
         */
        @JSONField(name = "userid")
        private String userName;//": "banym",

        /**
         * 姓名
         */
        @JSONField(name = "username")
        private String nickName;//": "班月明",

        /**
         * 邮箱
         */
        @JSONField(name = "useremail")
        private String email;

        /**
         * 部门ID
         */
//        @JSONField(name = "depart")
//        private Long deptId;//": "19",

        /**
         * 性别
         */
//        @JSONField(name = "sex")
//        private String sex;//": null,

        /**
         * 手机号码
         */
//        @JSONField(name = "iphone")
//        private String phonenumber;//": null,

        /**
         * 出生年月
         */
//        @JSONField(name = "")
//        private String birth;//": null
        public void setUserName(String userName) {
            this.userName = userName == null ? null : userName.replaceAll("\\s*", "");
        }

        public void setNickName(String nickName) {
            //可以替换大部分空白字符， 不限于空格 ； \s 可以匹配空格、制表符、换页符等空白字符的其中任意一个。
            this.nickName = nickName == null ? null : nickName.replaceAll("\\s*", "");

        }

        public void setEmail(String email) {
            this.email = email == null ? null : email.replaceAll("\\s*", "");
        }
    }
}
