package com.kiisoo.ic.wx.service;

import com.alibaba.fastjson.JSON;
import com.kiisoo.ic.common.utils.httpClientUtil.HttpClientUtil;
import com.kiisoo.ic.common.utils.httpClientUtil.HttpResult;
import com.kiisoo.ic.employee.entity.PrivilageCpUserDO;
import com.kiisoo.ic.employee.service.EmployeeService;
import com.kiisoo.ic.wx.constants.Constant;
import com.kiisoo.ic.wx.utils.UrlUtil;
import com.kiisoo.ic.wx.entity.CreateWXDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 增加企业微信
 */
@Service
public class AddWXService {

    @Autowired
    private EmployeeService employeeServicel;
    String token = "a";
    boolean ifHad = false;
    String tock = "";
    /**
     * 增加企业微信
     */
    public void addWX(String phone, String name){
        //查看此人是否已经创建过企业微信
        PrivilageCpUserDO privilageCpUserDO = employeeServicel.getUserWX(phone);
        //如果已经创建过
        if(privilageCpUserDO == null){
            return;
        }
        //创建企业微信基础数据
        CreateWXDO createWXDO = new CreateWXDO();
        createWXDO.setUserid(phone);
        createWXDO.setName(name);
        //未创建，则创建
        HttpResult result = HttpClientUtil.httpPost(UrlUtil.getAddWXUrl(token), JSON.toJSONString(createWXDO), tock);
        //是否添加微信成功
        boolean ifAdd = UrlUtil.compHttpResult(result, Constant.ADD_URL_RETURN_PARAM, Constant.ADD_URL_SUCC_CODE);
        //如果成功，则添加对应的表信息
//        if(ifAdd){
//
//        }
    }
}
