package net.northking.cctp.platform.api.user;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.platform.api.user.service.UserApiService;
import net.northking.cctp.platform.dto.user.CltUserLoginDto;
import net.northking.cctp.platform.dto.user.UserQueryByDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "平台用户")
@RequestMapping("/v1")
@RestController
public class UserQueryCtrl {
    /**
     * 日志
     */
    private final static Logger logger = LoggerFactory.getLogger(UserQueryCtrl.class);

    @Autowired
    private UserApiService userApiService;

    @ApiOperation(value = "查询雪狼用户id")
    @GetMapping(value = "/query/selectOperCode/{userId}",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<String> selectOperCode(
            @PathVariable("userId") String userId) {
        long startTime = System.currentTimeMillis();
        ResultWrapper<String> wrapper = new ResultWrapper<>();
        String result = userApiService.selectOperCode(userId);
        long endTime = System.currentTimeMillis();
        logger.info("查询雪狼用户id 耗时:" + (endTime - startTime));
        return wrapper.success(result);
    }

    /**
     * 查询所有用户雪狼信息数据
     *
     * @return 用户列表
     */
    @ApiOperation(value = "查询所有用户雪狼信息数据")
    @PostMapping(value = "/query/all/users",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<List<CltUserLoginDto>> allUsers(@RequestBody UserQueryByDto query) {
        ResultWrapper<List<CltUserLoginDto>> wrapper = new ResultWrapper<>();
        List<CltUserLoginDto> list = userApiService.getAllUsers(query.getUsername());
        return wrapper.success(list);
    }


}
