| | |
| | | import com.zy.system.entity.license.LicenseVerify; |
| | | import com.zy.system.service.*; |
| | | import com.zy.system.timer.LicenseTimer; |
| | | import com.zy.system.timer.LoadingConfigTimer; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Created by vincent on 2019-07-30 |
| | |
| | | private RolePermissionService rolePermissionService; |
| | | @Autowired |
| | | private LicenseTimer licenseTimer; |
| | | @Autowired |
| | | private LoadingConfigTimer loadingConfigTimer; |
| | | |
| | | @PostMapping("/login.action") |
| | | @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "登录") |
| | |
| | | return R.parse(CodeRes.USER_10003); |
| | | } |
| | | String token = Cools.enToken(System.currentTimeMillis() + param.get("username"), user.getPassword()); |
| | | userLoginService.delete(new EntityWrapper<UserLogin>().eq("user_id", user.getId())); |
| | | UserLogin userLogin = new UserLogin(); |
| | | if (loadingConfigTimer.getTokenNumber() == 1) { |
| | | userLoginService.delete(new EntityWrapper<UserLogin>().eq("user_id", user.getId()).eq("system", "WMS")); |
| | | } UserLogin userLogin = new UserLogin(); |
| | | userLogin.setUserId(user.getId()); |
| | | userLogin.setToken(token); |
| | | userLogin.setCreateTime(new Date()); |
| | |
| | | Long leaderId = role.getLeader(); |
| | | roleResourceService.delete(new EntityWrapper<RoleResource>().eq("role_id", roleId)); |
| | | rolePermissionService.delete(new EntityWrapper<RolePermission>().eq("role_id", roleId)); |
| | | if (!Cools.isEmpty(powers)) { |
| | | if (!Cools.isEmpty(powers)){ |
| | | List<PowerDto> dtos = JSON.parseArray(powers, PowerDto.class); |
| | | for (PowerDto dto : dtos) { |
| | | Resource resource = resourceService.selectOne(new EntityWrapper<Resource>().eq("id", dto.getTwo()).eq("level", 2)); |
| | | if (!Cools.isEmpty(resource)) { |
| | | // 校验上级权限 |
| | | if (leaderId != null) { |
| | | RoleResource roleResource = roleResourceService.selectOne(new EntityWrapper<RoleResource>().eq("role_id", leaderId).eq("resource_id", resource.getId())); |
| | | if (null == roleResource) { |
| | | throw new CoolException(resource.getName().concat("无法授权给").concat(role.getName())); |
| | | if (isNumber(dto.getTwo())) { |
| | | Resource resource = resourceService.selectOne(new EntityWrapper<Resource>().eq("id", dto.getTwo()).eq("level", 2)); |
| | | if (!Cools.isEmpty(resource)) { |
| | | // 校验上级权限 |
| | | if (leaderId != null) { |
| | | RoleResource roleResource = roleResourceService.selectOne(new EntityWrapper<RoleResource>().eq("role_id", leaderId).eq("resource_id", resource.getId())); |
| | | if (null == roleResource) { |
| | | throw new CoolException(resource.getName().concat("无法授权给").concat(role.getName())); |
| | | } |
| | | } |
| | | RoleResource roleResource = new RoleResource(); |
| | | roleResource.setRoleId(roleId); |
| | | roleResource.setResourceId(resource.getId()); |
| | | roleResourceService.insert(roleResource); |
| | | } |
| | | RoleResource roleResource = new RoleResource(); |
| | | roleResource.setRoleId(roleId); |
| | | roleResource.setResourceId(resource.getId()); |
| | | roleResourceService.insert(roleResource); |
| | | } else { |
| | | Permission permission = permissionService.selectOne(new EntityWrapper<Permission>().eq("action", dto.getTwo())); |
| | | if (!Cools.isEmpty(permission)) { |
| | | if (!Cools.isEmpty(permission)){ |
| | | RolePermission rolePermission = new RolePermission(); |
| | | rolePermission.setRoleId(roleId); |
| | | rolePermission.setPermissionId(permission.getId()); |
| | | rolePermissionService.insert(rolePermission); |
| | | } |
| | | } |
| | | for (String three : dto.getThree()) { |
| | | for (String three : dto.getThree()){ |
| | | Resource resource1 = resourceService.selectOne(new EntityWrapper<Resource>().eq("id", three).eq("level", 3)); |
| | | if (!Cools.isEmpty(resource1)) { |
| | | // 校验上级权限 |
| | | if (leaderId != null) { |
| | | RoleResource roleResource = roleResourceService.selectOne(new EntityWrapper<RoleResource>().eq("role_id", leaderId).eq("resource_id", resource1.getId())); |
| | | if (null == roleResource) { |
| | | throw new CoolException(resource.getName().concat("的").concat(resource1.getName().concat("无法授权给").concat(role.getName()))); |
| | | throw new CoolException(resource1.getName().concat("无法授权给").concat(role.getName())); |
| | | } |
| | | } |
| | | RoleResource roleResource = new RoleResource(); |
| | |
| | | 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(); |
| | | } |
| | | |
| | | @RequestMapping("/menu/pda/auth") |
| | | @ManagerAuth |
| | | public R menuPda(){ |
| | | Long userId = getUserId(); |
| | | List<RolePermission> rolePermissions; |
| | | if (userId == 9527L) { |
| | | rolePermissions = rolePermissionService.selectList(new EntityWrapper<>()); |
| | | } else { |
| | | return R.error(); |
| | | Long roleId = getUser().getRoleId(); |
| | | rolePermissions = rolePermissionService.selectList(new EntityWrapper<RolePermission>().eq("role_id", roleId)); |
| | | } |
| | | if (Cools.isEmpty(rolePermissions)) { |
| | | return R.ok(); |
| | | } |
| | | List<Long> collect = rolePermissions.stream().map(RolePermission::getPermissionId).distinct().collect(Collectors.toList()); |
| | | List<Permission> permissions = permissionService.selectBatchIds(collect); |
| | | return R.ok().add(permissions); |
| | | } |
| | | |
| | | @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)); |
| | | } |
| | | // @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(); |
| | | // } |
| | | // } |
| | | // |
| | | // @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)); |
| | | // } |
| | | |
| | | } |