管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-27 cec8c5738686bd16d17ae37455b85069e6babe29
src/main/java/com/lf/server/controller/all/SignController.java
@@ -1,15 +1,18 @@
package com.lf.server.controller.all;
import com.lf.server.aspect.LogAspect;
import com.lf.server.aspect.SysLog;
import com.lf.server.annotation.SysLog;
import com.lf.server.config.PropertiesConfig;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.all.SettingData;
import com.lf.server.entity.all.StaticData;
import com.lf.server.entity.sys.LoginEntity;
import com.lf.server.entity.sys.OperateEntity;
import com.lf.server.entity.sys.TokenEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.*;
import com.lf.server.service.all.ScheduleService;
import com.lf.server.service.sys.LoginService;
import com.lf.server.service.sys.OperateService;
import com.lf.server.service.sys.TokenService;
import com.lf.server.service.sys.UserService;
import com.lf.server.service.all.SignService;
@@ -17,8 +20,6 @@
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;
@@ -48,9 +49,13 @@
    SignService signService;
    @Autowired
    private OperateService operateService;
    @Autowired
    PropertiesConfig propertiesConfig;
    private static final Log log = LogFactory.getLog(SignController.class);
    @Autowired
    private ScheduleService scheduleService;
    @SysLog()
    @ApiOperation(value = "跳转首页")
@@ -91,7 +96,7 @@
                }
            }
        } catch (Exception ex) {
            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
            log.error(ex.getMessage(), ex);
        }
        return mv;
@@ -109,7 +114,7 @@
                mv.setViewName("monitor");
            }
        } catch (Exception ex) {
            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
            log.error(ex.getMessage(), ex);
        }
        return mv;
@@ -123,49 +128,41 @@
    @PostMapping(value = "/login", produces = "application/json; charset=UTF-8")
    public ResponseMsg<TokenEntity> login(@RequestBody UserEntity user, HttpServletRequest req, HttpServletResponse res) {
        try {
            if (user == null) {
                return fail("请输入用户名和密码!", null);
            }
            if (StringHelper.isEmpty(user.getUid())) {
                return fail("用户名不能为空!", null);
            }
            if (StringHelper.isEmpty(user.getPwd())) {
                return fail("密码不能为空!", null);
            String str = userService.validateLoginPwd(user);
            if (str != null) {
                return fail(str, null);
            }
            // 解密
            String uid = RsaHelper.decrypt(user.getUid());
            String pwd = RsaHelper.decrypt(user.getPwd());
            UserEntity ue = userService.selectByUid(uid);
            UserEntity ue = userService.selectByUid(user.getUid());
            if (ue == null) {
                return fail("用户名不存在!", null);
                return fail("用户名不存在", null);
            }
            LoginEntity le = loginService.getNewLogin(ue.getId(), 1, req);
            if (!Md5Helper.validatePassword(pwd, ue.getPwd())) {
                le.setStatus(0);
                le.setDescr("密码错误");
                loginService.insertLogin(le);
                return fail("密码不正确!", null);
            if (!Md5Helper.validatePassword(user.getPwd(), ue.getPwd())) {
                tokenService.setPwdErrCache(ue);
                return fail("密码不正确", null);
            }
            LoginEntity le = loginService.getNewLogin(ue.getId(), 1, 1, 1, req);
            Integer rows = loginService.insertLogin(le);
            if (rows == 0) {
                return fail("创建登录日志失败!", null);
                return fail("创建登录日志失败", null);
            }
            TokenEntity te = tokenService.getNewToken(ue.getId(), req);
            TokenEntity te = tokenService.getNewToken(ue, req);
            rows = tokenService.insertToken(te);
            if (rows == 0) {
                return fail("创建令牌信息失败!", null);
                return fail("创建令牌失败", null);
            }
            tokenService.saveToken(ue, te, req, res);
            return success(te);
            int onlineUser = scheduleService.countOnlineUsers();
            String msg = onlineUser >= SettingData.MAX_USER_LOGIN ? "警告:系统已经到达用户访问量的上限!" : "";
            return success(msg, te);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -183,7 +180,7 @@
            return success(flag ? "登出成功" : "登出失败", flag);
        } catch (Exception ex) {
            return fail(ex.getMessage(), false);
            return fail(ex, false);
        }
    }
@@ -196,13 +193,13 @@
            if (flag) {
                // 写日志
                UserEntity ue = tokenService.getCurrentUser(req);
                LoginEntity le = loginService.getNewLogin(ue.getId(), 2, req);
                LoginEntity le = loginService.getNewLogin(ue.getId(), 1, 2, 1, req);
                Integer rows = loginService.insertLogin(le);
            }
            return success(flag ? "用户已登录" : "用户未登录", flag);
        } catch (Exception ex) {
            return fail(ex.getMessage(), false);
            return fail(ex, false);
        }
    }
@@ -218,7 +215,7 @@
            return success(ue);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -231,7 +228,34 @@
            return success(key);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
    @ApiOperation(value = "插入操作日志")
    @GetMapping("/insertOpLog")
    public ResponseMsg<Object> insertOpLog(String m1, String m2, HttpServletRequest req) {
        try {
            if (StringHelper.isEmpty(m1)) {
                return fail("一级模块必填", 0);
            }
            OperateEntity oe = new OperateEntity();
            oe.setIp(WebHelper.getIpAddress(req));
            oe.setModular1(m1);
            oe.setModular2(m2);
            oe.setType(0);
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                oe.setUserid(ue.getId());
            }
            int rows = operateService.insertOperate(oe);
            return success(rows);
        } catch (Exception ex) {
            return fail(ex, 0);
        }
    }
}