Merge remote-tracking branch 'origin/master'
| | |
| | | |
| | | /** |
| | | * 获取故障码列表 |
| | | * |
| | | * @param keyword 关键词 |
| | | * @return 故障码列表 |
| | | */ |
| | | List<LightReportErrorBo> listReportError(String keyword, Long userid); |
| | | List<LightReportErrorBo> listReportError(String keyword, int error_code, Long userid); |
| | | } |
| | | |
| | | |
| | |
| | | AND ( |
| | | t3.id LIKE CONCAT('%', #{keyword},'%') |
| | | OR t3.pole_name LIKE CONCAT('%', #{keyword},'%') |
| | | OR t1.error_code LIKE CONCAT('%', #{keyword},'%') |
| | | ) |
| | | </if> |
| | | <if test="userid != null"> |
| | | AND (t3.user_id = #{userid} OR t3.client_id = #{userid}) |
| | | </if> |
| | | <if test="error_code != null"> |
| | | AND t1.error_code = #{error_code} |
| | | </if> |
| | | </where> |
| | | ORDER BY t1.light_report_error_id DESC |
| | | </select> |
| | |
| | | package com.sandu.common.security.token; |
| | | |
| | | import com.sandu.common.enums.AdminStatusStatus; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.redis.RedisService; |
| | | import com.sandu.common.security.LoginUserInfo; |
| | | import com.sandu.common.security.config.SecurityProperties; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import io.jsonwebtoken.*; |
| | | import io.jsonwebtoken.io.Decoders; |
| | | import io.jsonwebtoken.io.DecodingException; |
| | | import io.jsonwebtoken.security.Keys; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.boot.autoconfigure.cache.CacheProperties; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.security.core.GrantedAuthority; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | if (loginUserInfo.getUserId() == null) { |
| | | throw new IllegalArgumentException("用户id不能为空"); |
| | | } |
| | | RedisService redisService = SpringContextHolder.getBean(RedisService.class); |
| | | String authorities = loginUserInfo.getAuthorities().stream() |
| | | .map(GrantedAuthority::getAuthority) |
| | | .collect(Collectors.joining(",")); |
| | | |
| | | long now = (new Date()).getTime(); |
| | | Date expiration = new Date(now + properties.getTokenValidityInSeconds()); |
| | | |
| | | return Jwts.builder() |
| | | String token = Jwts.builder() |
| | | .setSubject(loginUserInfo.getUserId().toString()) |
| | | .claim(AUTHORITIES_KEY, authorities) |
| | | .claim(CREDENTIALS_KEY, loginUserInfo.getAccount()) |
| | |
| | | .setExpiration(expiration) |
| | | .signWith(key, SignatureAlgorithm.HS512) |
| | | .compact(); |
| | | |
| | | String key = String.format("%d_%d", loginUserInfo.getUserId(), loginUserInfo.getAdministratorType()); |
| | | redisService.set(key, token); |
| | | return token; |
| | | } |
| | | |
| | | @Override |
| | | public LoginUserInfo validateToken(String token) { |
| | | try { |
| | | RedisService redisService = SpringContextHolder.getBean(RedisService.class); |
| | | |
| | | Claims claims = Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token).getBody(); |
| | | LoginUserInfo loginUserInfo = new LoginUserInfo(); |
| | | loginUserInfo.setUserId(Long.valueOf(claims.getSubject())); |
| | |
| | | loginUserInfo.setAdministratorType(Integer.parseInt(claims.get(ADMINISTRATOR_KEY).toString())); |
| | | loginUserInfo.setToken(token); |
| | | loginUserInfo.setStatus(AdminStatusStatus.NORMAL.getCode()); |
| | | String key = String.format("%d_%d", loginUserInfo.getUserId(), loginUserInfo.getAdministratorType()); |
| | | String redisToken = String.valueOf(redisService.get(key)); |
| | | if (redisToken == null || !token.equals(redisToken)) { |
| | | throw new BusinessException("token无效"); |
| | | } |
| | | return loginUserInfo; |
| | | } catch (io.jsonwebtoken.security.SecurityException | MalformedJwtException e) { |
| | | log.info("Invalid JWT signature."); |
| | |
| | | String token = IdUtil.simpleUUID(); |
| | | loginUserInfo.setToken(token); |
| | | loginUserInfo.setCreateTimestamp(System.currentTimeMillis()); |
| | | redisService.set(UserModel.USER_TOKEN.key(token), loginUserInfo.getUserId(), UserModel.USER_TOKEN.expireSeconds()); |
| | | redisService.set(UserModel.USER_INFO.key(loginUserInfo.getUserId().toString()), loginUserInfo); |
| | | redisService.set(UserModel.USER_TOKEN.key(token), loginUserInfo, UserModel.USER_TOKEN.expireSeconds()); |
| | | redisService.set(UserModel.USER_INFO.key(loginUserInfo.getUserId().toString() + loginUserInfo.getAdministratorType()), loginUserInfo); |
| | | return token; |
| | | } |
| | | |
| | |
| | | if (token == null) { |
| | | return null; |
| | | } |
| | | Long userId = (Long) redisService.get(UserModel.USER_TOKEN.key(token)); |
| | | if (userId == null) { |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) redisService.get(UserModel.USER_TOKEN.key(token)); |
| | | if (loginUserInfo == null) { |
| | | return null; |
| | | } |
| | | LoginUserInfo userInfo = (LoginUserInfo) redisService.get(UserModel.USER_INFO.key(userId.toString())); |
| | | LoginUserInfo userInfo |
| | | = (LoginUserInfo) redisService.get(UserModel.USER_INFO.key(loginUserInfo.getUserId().toString() + loginUserInfo.getAdministratorType().toString())); |
| | | if (userInfo != null) { |
| | | if (redisService.getExpire(token) < UserModel.USER_TOKEN.expireSeconds()) { |
| | | redisService.expire(token, UserModel.USER_TOKEN.expireSeconds()); |
| | |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.enums.AdminStatusStatus; |
| | | import com.sandu.common.enums.ResponseStatusEnums; |
| | | import com.sandu.common.enums.RoleLevelStatus; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.log.Log; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.redis.RedisService; |
| | | import com.sandu.common.redis.UserModel; |
| | | import com.sandu.common.security.LoginUserInfo; |
| | | import com.sandu.common.security.annotation.AnonymousAccess; |
| | | import com.sandu.common.security.config.SecurityProperties; |
| | |
| | | private final TokenProvider tokenProvider; |
| | | private final AdminRoleRelationService adminRoleRelationService; |
| | | private PermissionConfig permissionConfig; |
| | | private final RedisService redisService; |
| | | |
| | | @Log("后台用户登录") |
| | | @AnonymousAccess |
| | |
| | | loginUserInfo.setAccount(admin.getUsername()); |
| | | loginUserInfo.setStatus(admin.getStatus()); |
| | | loginUserInfo.setIp(IpUtil.getRealIp()); |
| | | loginUserInfo.setAdministratorType(AdministratorEnums.ADMIN.getCode()); |
| | | |
| | | //确定用户角色权限 |
| | | AdminRoleRelation adminRoleRelation = adminRoleRelationService.getOne(Wrappers.lambdaQuery(AdminRoleRelation.class).eq(AdminRoleRelation::getAdminId, loginUserInfo.getUserId())); |
| | | Role role = roleService.getOne(Wrappers.lambdaQuery(Role.class).eq(Role::getId, adminRoleRelation.getRoleId())); |
| | | if (role != null && role.getLevel().equals(RoleLevelStatus.SUPER.getCode())) { |
| | | loginUserInfo.setAdministratorType(AdministratorEnums.ADMIN.getCode()); |
| | | } else { |
| | | loginUserInfo.setAdministratorType(AdministratorEnums.CUSTOMER.getCode()); |
| | | } |
| | | |
| | | loginUserInfo.setPermission(grantedAuthorities.stream().map(GrantedAuthority::getAuthority).collect(Collectors.joining(","))); |
| | | |
| | | // 生成令牌 |
| | |
| | | // @Log("后台用户信息") |
| | | @GetMapping(value = "/info") |
| | | public ResponseVO<Object> getUserInfo() { |
| | | System.out.println(SecurityUtils.getUserDetails().getAdministratorType() + " ---------"); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<Role> roles; |
| | | MapBuilder<Object, Object> builder; |
| | |
| | | return ResponseUtil.success(builder.build()); |
| | | } |
| | | |
| | | @GetMapping(value = "/logout") |
| | | public ResponseVO<Object> LogOut() { |
| | | // redisService.set(UserModel.USER_INFO.key(SecurityUtils.getUserId().toString() + SecurityUtils.getUserDetails().getAdministratorType()), null); |
| | | // redisService.set(UserModel.USER_TOKEN.key(UserModel.USER_TOKEN.key(SecurityUtils.getUserDetails().getToken())), null); |
| | | |
| | | |
| | | String key = String.format("%d_%d", SecurityUtils.getUserDetails().getUserId(), SecurityUtils.getUserDetails().getAdministratorType()); |
| | | redisService.set(key, null); |
| | | return ResponseUtil.success("退出登录成功"); |
| | | } |
| | | |
| | | private MenuNode covertMenuNode(Menu menu, List<Menu> menuList) { |
| | | MenuNode node = new MenuNode(); |
| | | BeanUtils.copyProperties(menu, node); |
| | |
| | | } |
| | | |
| | | @GetMapping("/error/list") |
| | | public ResponseVO<Object> listReportError(BaseConditionVO conditionVO, @RequestParam(required = false) String keyword) { |
| | | public ResponseVO<Object> listReportError(BaseConditionVO conditionVO, @RequestParam(required = false) String keyword |
| | | , @RequestParam(required = false) int errorCode) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_ERROR_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | List<LightReportErrorBo> list = lightReportErrorService.listReportError(conditionVO.getPageNo(), conditionVO.getPageSize(), keyword); |
| | | List<LightReportErrorBo> list = lightReportErrorService.listReportError(conditionVO.getPageNo(), conditionVO.getPageSize(), keyword, errorCode); |
| | | return ResponseUtil.success(list); |
| | | } |
| | | |
| | |
| | | List<Map<String, Object>> list = lightService.controlBrightness(paramList); |
| | | return ResponseUtil.success(list); |
| | | } |
| | | |
| | | @PostMapping("/EnergySaving") |
| | | public ResponseVO<Object> controlEnergySaving() { |
| | | return ResponseUtil.success(lightService.controlEnergySaving()); |
| | |
| | | */ |
| | | @Data |
| | | public class PwdParam { |
| | | @NotBlank(message = "旧密码不能为空") |
| | | private String oldPass; |
| | | // @NotBlank(message = "旧密码不能为空") |
| | | // private String oldPass; |
| | | @NotBlank(message = "新密码不能为空") |
| | | @Size(min = 6,message = "密码最短必须是6位") |
| | | private String newPass; |
| | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 修改密码 |
| | | * @param param |
| | | * @return |
| | | */ |
| | | public boolean updateMyPassword(PwdParam param) { |
| | | if (!StrUtil.equals(param.getNewPass(), param.getConfirmPass())) { |
| | | throw new BusinessException("两次密码不一致"); |
| | |
| | | if (admin == null) { |
| | | throw new BusinessException("用户不存在"); |
| | | } |
| | | if (!passwordEncoder.matches(param.getOldPass(), admin.getPassword())) { |
| | | throw new BusinessException("旧密码不正确"); |
| | | } |
| | | // if (!passwordEncoder.matches(param.getOldPass(), admin.getPassword())) { |
| | | // throw new BusinessException("旧密码不正确"); |
| | | // } |
| | | Admin update = new Admin(); |
| | | update.setId(userId); |
| | | update.setPassword(passwordEncoder.encode(param.getNewPass())); |
| | |
| | | save(lightReportError); |
| | | } |
| | | |
| | | public List<LightReportErrorBo> listReportError(int pageNo, int pageSize, String keyword) { |
| | | public List<LightReportErrorBo> listReportError(int pageNo, int pageSize, String keyword, int error_code) { |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | List<LightReportErrorBo> lightReportErrorBos; |
| | | //为null的话是超管 |
| | | if (SecurityUtils.getClientId() == null) { |
| | | lightReportErrorBos = baseMapper.listReportError(keyword, null); |
| | | }else{ |
| | | lightReportErrorBos = baseMapper.listReportError(keyword, SecurityUtils.getUserId()); |
| | | lightReportErrorBos = baseMapper.listReportError(keyword, error_code, null); |
| | | } else { |
| | | lightReportErrorBos = baseMapper.listReportError(keyword, error_code, SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | for (LightReportErrorBo lightReportErrorBo : lightReportErrorBos) { |