package com.fdkankan.platform.feign;

import com.fdkankan.common.user.SSOUser;
import com.fdkankan.platform.goods.entity.Company;
import com.fdkankan.platform.goods.service.ICompanyService;
import com.fdkankan.platform.user.entity.User;
import com.fdkankan.platform.user.entity.UserIncrement;
import com.fdkankan.platform.user.service.IUserIncrementService;
import com.fdkankan.platform.user.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 提供计算调用
 */
@RestController
@RequestMapping("/feign/user")
public class UserFeign {

    private static Logger log = LoggerFactory.getLogger("feignVisitLog");

    @Autowired
    private IUserService userService;
    @Autowired
    private IUserIncrementService userIncrementService;
    @Autowired
    private ICompanyService companyService;

    @PostMapping("/getUserByName")
    public User getUserByName(@RequestParam(value = "userName", required = false) String userName) {
        log.info("modeling服务调用:getUserByName,参数：userName:{},",userName);
        User entity = userService.getUserByUserName(userName);
        log.info("modeling服务调用:getUserByName,返回:{}",entity);
        return entity;
    }
    @PostMapping("/getUserIncrementByCameraId")
    public UserIncrement getUserIncrementByCameraId(@RequestParam(value = "cameraId", required = false) Long cameraId) {
        log.info("modeling服务调用:getUserIncrementByCameraId,参数：cameraId:{},",cameraId);
        UserIncrement entity = userIncrementService.getByCameraId(cameraId);
        log.info("modeling服务调用:getUserIncrementByCameraId,返回:{}",entity);
        return entity;
    }
    @PostMapping("/getSSOUserByUserId")
    public SSOUser getSSOUserByUserId(@RequestParam(value = "userId", required = false) Long userId) {
        log.info("scene服务调用:getSSOUserByUserId,参数：userId:{},",userId);
        SSOUser ssoUser =  userService.getSSOUserByUserId(userId);
        log.info("scene服务调用:getSSOUserByUserId,返回:{}",ssoUser);
        return ssoUser;
    }
    @PostMapping("/getCompanyById")
    public Company getCompanyById(@RequestParam(value = "companyId", required = false) Long companyId) {
        log.info("scene服务调用: getCompanyById,参数：companyId:{},",companyId);
        Company entity = companyService.getById(companyId);
        log.info("scene服务调用: getCompanyById,返回:{}",entity);
        return entity;
    }

    @PostMapping("/getUserByUserId")
    public User getUserByUserId(@RequestParam(value = "userId")  Long userId) {
        log.info("feign调用: getUserByUserId,参数：userId:{},",userId);
        User user = userService.getUserByUserId(userId);
        log.info("feign调用: getUserByUserId,返回：{},",user);
        return user;
    }
    @PostMapping("/getUserLikeUserName")
    List<User> getUserLikeUserName(@RequestParam(value = "searchKey") String searchKey){
        log.info("feign调用: getUserLikeUserName,参数：searchKey:{},",searchKey);
        List<User> userList = userService.getUserLikeUserName(searchKey);
        log.info("feign调用: getUserLikeUserName,返回：{},",userList);
        return userList;
    }
}

