package com.zcloud.util;

import com.alibaba.fastjson.JSONObject;
import com.zcloud.entity.PageData;

import java.util.concurrent.CountDownLatch;

/**
 * @author fangjiakai
 * @date 2024/10/17 8:47
 */
public class AsyncPlsUserTask implements Runnable {

    private PageData user;
    private String url;
    private String corpId;
    private CountDownLatch latch;

    public AsyncPlsUserTask(PageData user, String url, String corpId, CountDownLatch latch) {
        this.user = user;
        this.url = url;
        this.corpId = corpId;
        this.latch = latch;
    }

    @Override
    public void run() {
        user.put("name", user.getString("NAME"));
        user.put("cardNo", user.getString("CARDNO"));
        user.put("empNo", "");
        user.put("sex", "");
        user.put("certType", "");
        user.put("certNo", "");
        user.put("staffType", "");
        user.put("phone", "");
        user.put("age", "");
        user.put("addr", "");
        user.put("remark", "");
        user.put("enterpriseName", "");
        user.put("jobsName", "");
        user.put("avatar", "");
        JSONObject body = null;
        try {
            if (user.get("office") != null) {
                body = PLSUtil.GeneralPost(url, "/deploy/psnmgt/insertPsnIfon", user, corpId);
                if (body != null && "200".equals(body.getString("code"))) {
                    user.put("PLS_ID", body.getString("data"));
                } else {
                    System.out.println(body);
                    throw new RuntimeException("远程调用失败");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("远程调用失败");
        }finally {
            latch.countDown();
        }
    }
}
