 package com.huatek.busi.controller;

import java.net.UnknownHostException;
import java.util.Map;

import com.huatek.busi.common.Md5Util;
import com.huatek.busi.service.BusiHomePageService;
import com.huatek.torch.frame.tools.ResultUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.service.login.LoginService;
import com.huatek.frame.base.dto.UserDTO;
import com.huatek.frame.base.vo.UserVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api(tags = {Tags.APP_LOGIN})
@Slf4j
@RestController
@RequestMapping("/app/login")
public class AppLoginController {
	
	@Value("${torch.login.time}")
	private long time;

    @Reference(check = false)
    private LoginService loginService;

    @Reference(check = false)
    private BusiHomePageService busiHomePageService;
    
    @ApiOperation(value = "列表分页查询", response = UserVO.class)
    @PostMapping(value = "/login", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> login(@RequestBody UserDTO user) throws UnknownHostException {
        log.info("*************");
        if(!busiHomePageService.verifyDongle()){
            return ResultUtil.put(Md5Util.DANGLE_CODE_FAIL, "", null);
        }
        return loginService.login(user,time);
    }
}
