package com.fdkankan.platform.feign;

import com.fdkankan.common.response.ResultData;
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) {
        User entity = userService.getUserByUserName(userName);
        return entity;
    }
    @PostMapping("/getUserIncrementByCameraId")
    public UserIncrement getUserIncrementByCameraId(@RequestParam(value = "cameraId", required = false) Long cameraId) {
        UserIncrement entity = userIncrementService.getByCameraId(cameraId);
        return entity;
    }
    @PostMapping("/getSSOUserByUserId")
    public SSOUser getSSOUserByUserId(@RequestParam(value = "userId", required = false) Long userId) {
        SSOUser ssoUser =  userService.getSSOUserByUserId(userId);
        return ssoUser;
    }
    @PostMapping("/getCompanyById")
    public Company getCompanyById(@RequestParam(value = "companyId", required = false) Long companyId) {
        Company entity = companyService.getById(companyId);
        return entity;
    }

    @PostMapping("/getUserByUserId")
    public User getUserByUserId(@RequestParam(value = "userId")  Long userId) {
        User user = userService.getUserByUserId(userId);
        return user;
    }
    @PostMapping("/getUserLikeUserName")
    List<User> getUserLikeUserName(@RequestParam(value = "searchKey") String searchKey){
        List<User> userList = userService.getUserLikeUserName(searchKey);
        return userList;
    }

    /**
     * 更新用户已下载次数
     * @param userId 用户id
     * @param downLoadNum 下载次数
     * @return
     */
    @PostMapping("/updateDownloadNum")
    ResultData updateDownloadNum(@RequestParam(value = "userId") long userId,
        @RequestParam(value = "downLoadNum") int downLoadNum){
        return userService.updateDownloadNum(userId, downLoadNum);
    }
}

