package com.fdkankan.modeling.feign;

import com.alibaba.fastjson.JSONObject;
import com.fdkankan.common.response.ResultData;
import com.fdkankan.modeling.entity.ScenePro;
import com.fdkankan.modeling.service.ISceneProService;
import com.fdkankan.platform.api.feign.PlatformClient;
import com.fdkankan.platform.api.vo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class UserFeign {

    @Resource
    private PlatformClient platformClient;
    @Autowired
    private ISceneProService sceneProService;

    public User findByUserName(String userName) {
        ResultData resultData  = platformClient.getUserByName(userName);
        if(resultData.getCode() != 200 && resultData.getData()==null){
            return null;
        }
        Object userData = resultData.getData();
        return JSONObject.parseObject(JSONObject.toJSONString(userData), User.class);
    }

    public int updateUserUsedSpaceBySceneNum(Long userId, String projectNum) {
        ScenePro sceneProEntity = sceneProService.findBySceneNum(projectNum);
        if(sceneProEntity == null) {
            log.info("该场景不存在无法扣除容量，场景码为：" + projectNum);
            return -1;
        }
        //todo
        return 0;
    }
}
