LoginController.java 2.47 KB
package cn.com.glsx.merchants.controller;

import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.request.example.*;
import cn.com.glsx.merchants.response.ProductResponse;
import cn.com.glsx.merchants.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.FileCopyUtils;

import cn.com.glsx.merchants.response.LoginResponse;
import cn.com.glsx.merchants.response.ExampleResponse;
import cn.com.glsx.merchants.response.UploadFileResponse;
import cn.com.glsx.framework.rop.response.RopResponse;

import com.rop.AbstractRopRequest;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import com.rop.session.SimpleSession;

/**
 * @author zhouhaibao
 * @version 1.0
 * @description: 用户登录接口
 * @date 2021/7/13 10:00
 */
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
@Api("用户登录")
@Slf4j
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录示例
     *
     * @param request
     * @return
     */
    @ServiceMethod(method = "merchants.api.example.login", needInSession = NeedInSessionType.NO)
    @ApiOperation("登录")
    public RopResponse<LoginResponse> login(LoginRequest request) {
        try {
            LoginResponse response = loginService.login(request);
            // 创建会话
            return RopResponse.success(response);
        } catch (RpcServiceException e) {
            log.info("=======LoginController__invoke__findMerProMenuTreeRemote__exception:{}", e.getMessage());
            return RopResponse.error(e.getErrId(), e.getMessage());
        }
    }

    /**
     * 登出示例
     *
     * @param request
     * @return
     */
    @ServiceMethod(method = "merchants.api.example.logout", needInSession = NeedInSessionType.YES)
    @ApiOperation("登出")
    public RopResponse<Boolean> logout(AbstractRopRequest request) {
        loginService.logout(request);
        // 删除会话
        return RopResponse.success(true);
    }
}