| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | SignService signService; |
| | | |
| | | @Autowired |
| | | private OperateService operateService; |
| | | |
| | | @Autowired |
| | | PropertiesConfig propertiesConfig; |
| | | |
| | | @Autowired |
| | | private ScheduleService scheduleService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "跳转首页") |
| | |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage() + ex.getStackTrace() + "\n"); |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return mv; |
| | |
| | | mv.setViewName("monitor"); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage() + ex.getStackTrace() + "\n"); |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return mv; |
| | |
| | | @PostMapping(value = "/login", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<TokenEntity> login(@RequestBody UserEntity user, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | String str = userService.validateNewPwd(user); |
| | | String str = userService.validateLoginPwd(user); |
| | | if (str != null) { |
| | | return fail(str, null); |
| | | } |
| | | |
| | | UserEntity ue = userService.selectByUid(user.getUid()); |
| | | if (ue == null) { |
| | | return fail("用户名不存在!", null); |
| | | 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); |
| | | if (!Md5Helper.validatePassword(user.getPwd(), ue.getPwd())) { |
| | | tokenService.setPwdErrCache(ue); |
| | | le.setStatus(0); |
| | | le.setDescr("密码错误"); |
| | | loginService.insertLogin(le); |
| | | return fail("密码不正确!", null); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return success(flag ? "登出成功" : "登出失败", flag); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), false); |
| | | return fail(ex, false); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return success(flag ? "用户已登录" : "用户未登录", flag); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), false); |
| | | return fail(ex, false); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return success(ue); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | } |