package com.weaver.seconddev.chapanda.test;


import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.weaver.seconddev.chapanda.beisen.entity.BeisenStaffDepartmentDto;
import com.weaver.seconddev.chapanda.beisen.entity.BeisenStaffDto;
import com.weaver.seconddev.chapanda.beisen.entity.BeisenStaffPositionDto;
import org.apache.commons.lang3.StringUtils;

public class Test88 {

    public static void main(String[] args) {
        String bodyData = "{\"total\":1,\"code\":200,\"message\":\"操作成功\",\"sortCursor\":null,\"lastData\":false,\"items\":[{\"staffDto\":{\"avatar\":null,\"departmentId\":836572,\"departmentName\":\"人力资源中心\",\"employedDate\":\"2022-02-17T00:00:00.0000\",\"jobCode\":\"\",\"lineManagerId\":0,\"staffCode\":\"1000003111\",\"staffStatus\":0,\"isDelete\":0,\"allowLogin\":0,\"userId\":404156367,\"tenantId\":431582,\"email\":\"testwangbo@chabaidao.com\",\"userType\":3,\"userStatus\":0,\"origin\":8,\"originalId\":\"404156367\",\"name\":\"测试王波\",\"englishName\":\"\",\"sex\":\"\",\"educationBackground\":\"\",\"mobile\":\"\",\"workPhone\":\"\",\"homePhone\":\"\",\"idCardType\":\"\",\"idCardNumber\":\"\",\"maritalStatus\":\"\",\"nation\":\"\",\"backupMail\":\"\",\"address\":\"\",\"nativePlace\":\"\",\"personalHomePage\":\"\",\"politicalStatus\":\"\",\"speciality\":\"\",\"graduateFrom\":\"\",\"major\":\"\",\"positionCategory\":\"\",\"msn\":\"\",\"qq\":\"\",\"skype\":\"\",\"blog\":\"\",\"gTalk\":\"\",\"aboutMe\":\"\",\"bindMsn\":\"\",\"officeLocation\":\"\",\"bizTitleId\":\"00000000-0000-0000-0000-000000000000\",\"weChat\":\"\",\"modifiedBy\":10000,\"createBy\":402172443,\"bu\":0,\"version\":0},\"departmentDto\":{\"id\":836572,\"name\":\"人力资源中心\",\"code\":\"07\",\"description\":null,\"abbreviation\":\"人力资源中心\",\"parentId\":836553,\"path\":\"/1676228/836553/836572\",\"level\":3,\"status\":1,\"originalId\":\"428102\",\"staffNumber\":4,\"isDelete\":0,\"orderId\":12,\"orgLeaders\":[{\"lids\":[404155397],\"type\":1}],\"modifiedTime\":\"2025-07-10T07:27:41.4690\",\"createTime\":\"2022-07-01T01:44:57.0500\",\"modifiedBy\":10000,\"createBy\":10000,\"languageDic\":{\"name_srp\":\"\",\"shortName_zh_TW\":\"\",\"name_ru\":\"\",\"name_in\":\"\",\"name_en_US\":\"\",\"shortName_bn\":\"\",\"shortName_ko\":\"\",\"name_de\":\"\",\"shortName_it\":\"\",\"shortName_ru\":\"\",\"shortName_km\":\"\",\"shortName_tr\":\"\",\"name_bur\":\"\",\"name_zh_TW\":\"\",\"name_lo\":\"\",\"shortName_pl\":\"\",\"name_ja\":\"\",\"name_km\":\"\",\"name_fr\":\"\",\"shortName_tl\":\"\",\"shortName_fr\":\"\",\"name_tl\":\"\",\"name_it\":\"\",\"shortName_de\":\"\",\"shortName_en_US\":\"\",\"name_pl\":\"\",\"shortName_pt\":\"\",\"name_ko\":\"\",\"shortName_lo\":\"\",\"shortName_ms\":\"\",\"name_tr\":\"\",\"name_es\":\"\",\"name_bn\":\"\",\"shortName_th\":\"\",\"name_th\":\"\",\"name_ms\":\"\",\"name_vi\":\"\",\"shortName_bur\":\"\",\"name_pt\":\"\",\"shortName_vi\":\"\",\"shortName_in\":\"\",\"shortName_srp\":\"\",\"shortName_es\":\"\",\"shortName_ja\":\"\"},\"version\":2},\"positionDto\":{\"status\":null,\"isDelete\":0,\"setID\":null,\"version\":0},\"reportings\":[]}]}";

        BeisenStaffDto beisenStaffDto = new BeisenStaffDto();

        if(StringUtils.isNotBlank(bodyData)){
            JSONObject bodyJson = new JSONObject(bodyData);
            if(bodyJson.containsKey("code")){
                String code = bodyJson.getStr("code");
                System.out.println("code:{}"+code);
                if("200".equals(code)){
                    JSONArray itemsArray = bodyJson.getJSONArray("items");
                    System.out.println("itemsArray:{}"+itemsArray.size());
                    if(!itemsArray.isEmpty()){

                        JSONObject itemObject = itemsArray.getJSONObject(0);
                        System.out.println(("itemObject:{}"+itemObject.size()));

                        if(itemObject.containsKey("staffDto")){
                            JSONObject staffDto = itemObject.getJSONObject("staffDto");
                            System.out.println("staffDto:{}"+staffDto.size());
                            beisenStaffDto.setDepartmentId(staffDto.getStr("departmentId"));
                            beisenStaffDto.setDepartmentName(staffDto.getStr("departmentName"));
                            String employedDate = staffDto.getStr("employedDate");
                            System.out.println("employedDate:{}"+employedDate);

                            if(employedDate !=null && !"".equals(employedDate) && !"null".equals(employedDate)){
                                if(employedDate.contains("T")){
                                    employedDate = employedDate.substring(0,employedDate.indexOf("T"));
                                }
                            }

                            System.out.println("employedDate:{}"+employedDate);

                            beisenStaffDto.setEmployedDate(employedDate);

                            beisenStaffDto.setJobCode(staffDto.getStr("jobCode"));
                            beisenStaffDto.setPositionName(staffDto.getStr("positionName"));
                            beisenStaffDto.setLineManagerId(staffDto.getStr("lineManagerId"));
                            beisenStaffDto.setStaffCode(staffDto.getStr("staffCode"));
                            beisenStaffDto.setStaffStatus(staffDto.getStr("staffStatus"));

                            System.out.println("staffStatus:{}"+staffDto.getStr("staffStatus"));

                            beisenStaffDto.setIsDelete(staffDto.getStr("isDelete"));
//                            beisenStaffDto.setUserId(staffDto.getStr("userId"));
                            beisenStaffDto.setTenantId(staffDto.getStr("tenantId"));
                            beisenStaffDto.setEmail(staffDto.getStr("email"));
                            beisenStaffDto.setUserType(staffDto.getStr("userType"));
                            beisenStaffDto.setUserStatus(staffDto.getStr("userStatus"));
                            System.out.println("userStatus:{}"+staffDto.getStr("userStatus"));
                            beisenStaffDto.setOrigin(staffDto.getStr("origin"));
                            beisenStaffDto.setOriginalId(staffDto.getStr("originalId"));
                            beisenStaffDto.setName(staffDto.getStr("name"));
                            beisenStaffDto.setEnglishName(staffDto.getStr("englishName"));
                            beisenStaffDto.setSex(staffDto.getStr("sex"));
                            String birthday =  staffDto.getStr("birthday");
                            System.out.println("birthday:{}"+staffDto.getStr("birthday"));

                            if(!"null".equals(birthday) && birthday !=null ){
                                if(birthday.contains("T")){
                                    birthday = birthday.substring(0,birthday.indexOf("T"));
                                }
                            }

                            System.out.println("birthday:{}"+staffDto.getStr("birthday"));
                            beisenStaffDto.setBirthday(birthday);
                            beisenStaffDto.setMobile(staffDto.getStr("mobile"));
                            beisenStaffDto.setIdCardType(staffDto.getStr("idCardType"));

                            String graduateDate = staffDto.getStr("graduateDate");

                            if(!"null".equals(graduateDate) && graduateDate !=null ){
                                if(graduateDate.contains("T")){
                                    graduateDate = graduateDate.substring(0,graduateDate.indexOf("T"));
                                }
                            }


                            System.out.println("graduateDate:{}"+graduateDate);
                            beisenStaffDto.setGraduateDate(graduateDate);

                            beisenStaffDto.setNativePlace(staffDto.getStr("nativePlace"));
                            String beganWorkDate = staffDto.getStr("beganWorkDate");
                            if(!"null".equals(beganWorkDate) && beganWorkDate !=null ){
                                if(beganWorkDate.contains("T")){
                                    beganWorkDate = beganWorkDate.substring(0,beganWorkDate.indexOf("T"));
                                }
                            }
                            System.out.println("graduateDate:{}"+graduateDate);
                            beisenStaffDto.setBeganWorkDate(beganWorkDate);
                            beisenStaffDto.setGraduateFrom(staffDto.getStr("graduateFrom"));
                            beisenStaffDto.setMajor(staffDto.getStr("major"));
                            beisenStaffDto.setPositionCategory(staffDto.getStr("positionCategory"));
                        }

                        BeisenStaffDepartmentDto beisenStaffDepartmentDto = new BeisenStaffDepartmentDto();
                        if(itemObject.containsKey("departmentDto")){
                            JSONObject departmentDto = itemObject.getJSONObject("departmentDto");
                            beisenStaffDepartmentDto.setId(departmentDto.getStr("id"));
                            beisenStaffDepartmentDto.setName(departmentDto.getStr("name"));
                            beisenStaffDepartmentDto.setCode(departmentDto.getStr("code"));
                            beisenStaffDepartmentDto.setAbbreviation(departmentDto.getStr("abbreviation"));
                            beisenStaffDepartmentDto.setParentId(departmentDto.getStr("parentId"));
                            beisenStaffDepartmentDto.setLevel(departmentDto.getStr("level"));
                            beisenStaffDepartmentDto.setStatus(departmentDto.getStr("status"));
                            beisenStaffDepartmentDto.setIsDelete(departmentDto.getStr("isDelete"));
                            beisenStaffDepartmentDto.setOriginalId(departmentDto.getStr("originalId"));
                        }
                        beisenStaffDto.setBeisenStaffDepartmentDto(beisenStaffDepartmentDto);

                        BeisenStaffPositionDto beisenStaffPositionDto = new BeisenStaffPositionDto();
                        if(itemObject.containsKey("positionDto")){
                            JSONObject positionDto = itemObject.getJSONObject("positionDto");

                            beisenStaffPositionDto.setId(positionDto.getStr("id"));
                            beisenStaffPositionDto.setName(positionDto.getStr("name"));
                            beisenStaffPositionDto.setCode(positionDto.getStr("code"));
                            beisenStaffPositionDto.setStatus(positionDto.getStr("status"));
                            beisenStaffPositionDto.setIsDelete(positionDto.getStr("isDelete"));
                        }
                        beisenStaffDto.setBeisenStaffPositionDto(beisenStaffPositionDto);
                    }
                }
            }
        }
    }
}
