LoginApi.java 1.91 KB
package com.huaheng.api.general.controller;

import com.alibaba.fastjson.JSONException;
import com.huaheng.common.utils.DataUtils;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.system.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.Map;


@RestController
@RequestMapping("/api")
@Api(tags = {"Login"}, description = "登陆接口")
public class LoginApi extends BaseController {

    @Autowired
    private IUserService userService;

    @PostMapping("/login")
    @ApiOperation("登陆接口")
    public AjaxResult login(@RequestBody @ApiParam(value="登陆的Map集合") Map<String, String> param)
    {
        if  (param.get("username") == null)
            throw new JSONException("username(用户名)不能为空");
        if  (param.get("password") == null)
            throw new JSONException("password(密码)不能为空");
        if  (param.get("warehouseCode") == null)
            throw new JSONException("warehouseCode(仓库编码)不能为空");
        String username = param.get("username");
        String password = param.get("password");
        String warehouseCode = param.get("warehouseCode");
        AjaxResult ajaxResult = userService.login(username, password,  warehouseCode, false);
        return ajaxResult;
    }


    @PostMapping("/heartbeat")
    @ApiOperation("心跳接口,用于延长cookie有效期")
    public AjaxResult heartbeat()
    {
        return AjaxResult.success("success");
    }


}