From 2ff08d144935938b91af4e725577882976ef4627 Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期四, 01 八月 2024 08:52:39 +0800 Subject: [PATCH] # --- zy-asrs-common/src/main/java/com/zy/asrs/common/web/AuthController.java | 104 ++++++++++++++++++++++++++------------------------- 1 files changed, 53 insertions(+), 51 deletions(-) diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/web/AuthController.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/web/AuthController.java index df4a984..adc8247 100644 --- a/zy-asrs-common/src/main/java/com/zy/asrs/common/web/AuthController.java +++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/web/AuthController.java @@ -7,15 +7,11 @@ import com.zy.asrs.common.domain.entity.Parameter; import com.zy.asrs.common.domain.enums.HtmlNavIconType; import com.zy.asrs.common.domain.enums.LoginSystemType; -import com.zy.asrs.common.properties.OSinfo; -import com.zy.asrs.common.properties.SystemProperties; import com.zy.asrs.common.sys.entity.*; import com.zy.asrs.common.sys.service.*; import com.zy.asrs.common.utils.RandomValidateCodeUtil; import com.zy.asrs.framework.annotations.ManagerAuth; -import com.zy.asrs.framework.common.AesUtils; import com.zy.asrs.framework.common.Cools; -import com.zy.asrs.framework.common.DateUtils; import com.zy.asrs.framework.common.R; import com.zy.asrs.framework.exception.CoolException; import org.springframework.beans.factory.annotation.Autowired; @@ -44,6 +40,10 @@ private ResourceService resourceService; @Autowired private RoleResourceService roleResourceService; + @Autowired + private HostService hostService; + @Autowired + private ConfigService configService; @RequestMapping("/login.action") @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "鐧诲綍") @@ -79,11 +79,47 @@ userLogin.setToken(token); userLogin.setCreateTime(new Date()); userLogin.setSystem(system); + if (user.getRoleId() == 2) { + userLogin.setHostId(hostService.getTop1().getId()); + } userLoginService.save(userLogin); Map<String, Object> res = new HashMap<>(); res.put("username", user.getUsername()); res.put("token", token); return R.ok(res); + } + + @RequestMapping("/show/host.action") + @ManagerAuth + public R showHosts() { + Long hostId = getHostId(); + String hostName = null; + if (hostId != null) { + Host host = hostService.getById(hostId); + if (host != null) { + hostName = host.getName(); + } + } + return R.ok().add(Cools + .add("root", getUser().getRoleId() == 2) + .add("host", getHostId() == null) + .add("hostName", hostName) + ); + } + + @RequestMapping(value = "/root/change/host/auth") + @ManagerAuth + public R rootChangeHost(@RequestParam Long hostId) { + UserLogin userLogin = userLoginService.getOne(new LambdaQueryWrapper<UserLogin>().eq(UserLogin::getUserId, getUserId()).eq(UserLogin::getSystem, String.valueOf(LoginSystemType.WMS))); + if (userLogin != null) { + userLogin.setHostId(hostId); + if (!userLoginService.updateById(userLogin)) { + throw new CoolException("淇敼鍟嗘埛澶辫触"); + } + return R.ok(); + } else { + return R.error(); + } } @RequestMapping("/code/switch.action") @@ -130,10 +166,6 @@ oneLevel = resourceService.list(new LambdaQueryWrapper<Resource>().eq(Resource::getLevel, 1).orderByAsc(Resource::getSort)); resourceWrapper = new LambdaQueryWrapper<Resource>().eq(Resource::getLevel, 2).eq(Resource::getStatus, 1).orderByAsc(Resource::getSort); } else { - // 婵�娲荤爜楠岃瘉 - if (!SystemProperties.SYSTEM_ACTIVATION) { - return R.ok(); - } oneLevel = resourceService.list(new LambdaQueryWrapper<Resource>().eq(Resource::getLevel, 1).eq(Resource::getStatus, 1).orderByAsc(Resource::getSort)); // 鑾峰彇褰撳墠鐢ㄦ埛鐨勬墍鏈変簩绾ц彍鍗� user = userService.getById(getUserId()); @@ -158,11 +190,11 @@ // 鏄惁鎷ユ湁鏌ョ湅鏉冮檺 if (getUserId() != 9527) { Resource view = resourceService.getOne(new LambdaQueryWrapper<Resource>().eq(Resource::getResourceId, resource.getId()).like(Resource::getCode, "#view")); - if (!Cools.isEmpty(view)){ + if (!Cools.isEmpty(view)) { RoleResource param = new RoleResource(); param.setResourceId(view.getId()); param.setRoleId(user.getRoleId()); - if (null == roleResourceService.getOne(new LambdaQueryWrapper<>(param))){ + if (null == roleResourceService.getOne(new LambdaQueryWrapper<>(param))) { continue; } } @@ -303,48 +335,18 @@ return R.ok(resources); } - @GetMapping(value = "/system/activation/auth") - public R activation() { - if (SystemProperties.SYSTEM_ACTIVATION) { - String activationCode = SystemProperties.getActivationCode(OSinfo.getOSname().getActivationCodePath()); - String timeStr = AesUtils.decrypt(activationCode, SystemProperties.SALT); - if (null == timeStr) { - SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE; - return R.error(); - } - Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss); - if (new Date().getTime() < exprTime.getTime()) { - return R.ok().add(DateUtils.convert(exprTime)); - } else { - SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE; - return R.error(); - } - } else { - return R.error(); - } - } + @RequestMapping("/loginInformation") + public R getLoginPageInformation() { + Config loginLogo = configService.selectByCode("loginLogo"); + Config loginCopyrightText = configService.selectByCode("loginCopyrightText"); + Config loginCopyrightImg1 = configService.selectByCode("loginCopyrightImg1"); - @PostMapping(value = "/system/secret/auth") - @ManagerAuth - public R systemSecret(@RequestParam(value = "secret") String secret) { - if (Cools.isEmpty(secret)) { - return R.error("璇疯緭鍏ユ縺娲荤爜"); - } - // 楠岃瘉婵�娲荤爜 - String timeStr = AesUtils.decrypt(secret, SystemProperties.SALT); - if (null == timeStr) { - return R.error("婵�娲荤爜閿欒"); - } - Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss); - if (new Date().getTime() >= exprTime.getTime()) { - return R.error("婵�娲荤爜宸插け鏁�"); - } - boolean result = SystemProperties.saveActivationCode(OSinfo.getOSname().getActivationCodePath(), secret); - if (!result) { - return R.error("婵�娲诲け璐�"); - } - SystemProperties.SYSTEM_ACTIVATION = Boolean.TRUE; - return R.ok("婵�娲绘垚鍔燂紝鏈夋晥鏈熻嚦"+DateUtils.convert(exprTime)); + HashMap<String, Object> map = new HashMap<>(); + map.put("loginLogo", loginLogo.getValue()); + map.put("loginCopyrightText", loginCopyrightText.getValue()); + map.put("loginCopyrightImg1", loginCopyrightImg1.getStatus() == 1 ? loginCopyrightImg1.getValue() : ""); + + return R.ok().add(map); } } -- Gitblit v1.9.1