管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-10-11 a47aa433d7a54910351ecca27b44a539653eab35
src/main/java/com/lf/server/controller/all/SignController.java
@@ -1,21 +1,24 @@
package com.lf.server.controller.all;
import com.lf.server.aspect.LogAspect;
import com.lf.server.aspect.SysLog;
import com.lf.server.config.PropertiesConfig;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.all.StaticData;
import com.lf.server.entity.sys.LoginEntity;
import com.lf.server.entity.sys.TokenEntity;
import com.lf.server.entity.sys.UsersEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.*;
import com.lf.server.service.sys.LoginService;
import com.lf.server.service.sys.TokenService;
import com.lf.server.service.sys.UsersService;
import com.lf.server.service.sys.UserService;
import com.lf.server.service.all.SignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
@@ -33,7 +36,7 @@
@RequestMapping("/sign")
public class SignController extends BaseController {
    @Autowired
    UsersService userService;
    UserService userService;
    @Autowired
    LoginService loginService;
@@ -53,7 +56,7 @@
    public ModelAndView toIndex(ModelAndView mv, HttpServletRequest req) {
        mv.setViewName("index");
        UsersEntity ue = tokenService.getCurrentUser(req);
        UserEntity ue = tokenService.getCurrentUser(req);
        if (ue != null) {
            mv.addObject("msg", "Hello " + ue.getUname() + " !");
        }
@@ -78,7 +81,7 @@
        mv.setViewName("druid");
        try {
            UsersEntity ue = tokenService.getCurrentUser(req);
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                String sessionId = WebHelper.getCookieByKey(StaticData.DRUID_COOKIE_KEY, req);
                if (StringHelper.isNull(sessionId)) {
@@ -86,7 +89,7 @@
                }
            }
        } catch (Exception ex) {
            //
            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
        }
        return mv;
@@ -99,12 +102,12 @@
        try {
            mv.setViewName("redirect:/toLogin");
            UsersEntity ue = tokenService.getCurrentUser(req);
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                mv.setViewName("monitor");
            }
        } catch (Exception ex) {
            //
            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
        }
        return mv;
@@ -116,7 +119,7 @@
            @ApiImplicitParam(name = "user", value = "用戶名", dataType = "UsersEntity", paramType = "body", example = "")
    })
    @PostMapping(value = "/login", produces = "application/json; charset=UTF-8")
    public ResponseMsg<TokenEntity> login(@RequestBody UsersEntity user, HttpServletRequest req, HttpServletResponse res) {
    public ResponseMsg<TokenEntity> login(@RequestBody UserEntity user, HttpServletRequest req, HttpServletResponse res) {
        try {
            if (user == null) {
                return fail("请输入用户名和密码!", null);
@@ -132,7 +135,7 @@
            String uid = RsaHelper.decrypt(user.getUid());
            String pwd = RsaHelper.decrypt(user.getPwd());
            UsersEntity ue = userService.selectByUid(uid);
            UserEntity ue = userService.selectByUid(uid);
            if (ue == null) {
                return fail("用户名不存在!", null);
            }
@@ -190,7 +193,7 @@
            Boolean flag = tokenService.isLogin(req, res);
            if (flag) {
                // 写日志
                UsersEntity ue = tokenService.getCurrentUser(req);
                UserEntity ue = tokenService.getCurrentUser(req);
                LoginEntity le = loginService.getNewLogin(ue.getId(), 2, req);
                Integer rows = loginService.insertLogin(le);
            }
@@ -204,9 +207,9 @@
    @SysLog()
    @ApiOperation(value = "获取当前用户")
    @GetMapping("/getCurrentUser")
    public ResponseMsg<UsersEntity> getCurrentUser(HttpServletRequest req) {
    public ResponseMsg<UserEntity> getCurrentUser(HttpServletRequest req) {
        try {
            UsersEntity ue = tokenService.getCurrentUser(req);
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("没有找到", null);
            }