package com.unis.detectionnum.server.feign;

import com.alibaba.fastjson.JSON;
import com.unis.common.utils.CurrentUtil;
import com.unis.common.utils.ResponseWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 文件描述
 *
 * @author tongxi.xia
 * @date 2020年06月05日 17:56
 */
@Service
@Slf4j
public class GetUser {
    @Autowired
    private MyUserClient myUserClient;

    public UserDTO getCurrUserinfo() {

        UserDTO userDTO = new UserDTO();
        try {
            String userType  = CurrentUtil.getUserType();
            ResponseWrapper wrapper = myUserClient.findByUsername(userType,CurrentUtil.getUserAccount());
            if(wrapper.getInfoCode()!=200) {
                return null;
            }
            Object object = wrapper.getData();
            userDTO = JSON.parseObject(JSON.toJSONString(object), UserDTO.class);
            userDTO.setTyshxydm(CurrentUtil.getCreditCode());
            userDTO.setCompanyName(CurrentUtil.getCompanyName());
        } catch (Exception e) {
            log.error( "查找对象，发生异常", e.getMessage() );
            return null;
        }
        return userDTO;
    }
}
