b端登录&客户模糊查询&实体自增
This commit is contained in:
parent
e0e23dbe48
commit
f6f591a870
@ -18,6 +18,7 @@ package com.aircraft.utils;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.jwt.JWT;
|
import cn.hutool.jwt.JWT;
|
||||||
import cn.hutool.jwt.JWTUtil;
|
import cn.hutool.jwt.JWTUtil;
|
||||||
|
import com.aircraft.exception.BadRequestException;
|
||||||
import com.aircraft.utils.enums.UserTypeEnum;
|
import com.aircraft.utils.enums.UserTypeEnum;
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
@ -25,6 +26,8 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import com.aircraft.utils.enums.DataScopeEnum;
|
import com.aircraft.utils.enums.DataScopeEnum;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -32,6 +35,7 @@ import org.springframework.web.context.request.RequestContextHolder;
|
|||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,10 +66,34 @@ public class SecurityUtils {
|
|||||||
* @return UserDetails
|
* @return UserDetails
|
||||||
*/
|
*/
|
||||||
public static UserDetails getCurrentUser() {
|
public static UserDetails getCurrentUser() {
|
||||||
UserDetailsService userDetailsService = SpringBeanHolder.getBean(UserDetailsService.class);
|
// UserDetailsService userDetailsService = SpringBeanHolder.getBean(UserDetailsService.class);
|
||||||
|
// return userDetailsService.loadUserByUsername(getCurrentUsername());
|
||||||
|
String userType = String.valueOf(getCurrentUserTypeVo());
|
||||||
|
UserDetailsService userDetailsService;
|
||||||
|
|
||||||
|
if (UserTypeEnum.CUSTOMER.equals(UserTypeEnum.valueOf(userType))) {
|
||||||
|
userDetailsService = SpringBeanHolder.getBean("bUserDetailsService", UserDetailsService.class);
|
||||||
|
} else {
|
||||||
|
userDetailsService = SpringBeanHolder.getBean("userDetailsService", UserDetailsService.class);
|
||||||
|
}
|
||||||
return userDetailsService.loadUserByUsername(getCurrentUsername());
|
return userDetailsService.loadUserByUsername(getCurrentUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加获取当前用户类型的方法
|
||||||
|
public static String getCurrentUserTypeVo() {
|
||||||
|
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
if (authentication == null) {
|
||||||
|
throw new BadRequestException("当前登录状态过期");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从认证信息中获取用户类型(在登录时设置)
|
||||||
|
if (authentication.getDetails() instanceof Map) {
|
||||||
|
Map<?, ?> details = (Map<?, ?>) authentication.getDetails();
|
||||||
|
return (String) details.get("userType");
|
||||||
|
}
|
||||||
|
return "ADMIN"; // 默认类型
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前用户的数据权限
|
* 获取当前用户的数据权限
|
||||||
* @return /
|
* @return /
|
||||||
|
@ -61,6 +61,11 @@ public class SpringBeanHolder implements ApplicationContextAware, DisposableBean
|
|||||||
return (T) applicationContext.getBean(name);
|
return (T) applicationContext.getBean(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加按名称和类型获取 Bean 的方法
|
||||||
|
public static <T> T getBean(String name, Class<T> clazz) {
|
||||||
|
return applicationContext.getBean(name, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
|
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
|
||||||
*/
|
*/
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package com.aircraft.modules.security.rest;
|
package com.aircraft.modules.security.rest;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.aircraft.utils.enums.UserTypeEnum;
|
||||||
import com.wf.captcha.base.Captcha;
|
import com.wf.captcha.base.Captcha;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@ -97,7 +98,10 @@ public class AuthController {
|
|||||||
if (!passwordEncoder.matches(password, jwtUser.getPassword())) {
|
if (!passwordEncoder.matches(password, jwtUser.getPassword())) {
|
||||||
throw new BadRequestException("登录密码错误");
|
throw new BadRequestException("登录密码错误");
|
||||||
}
|
}
|
||||||
Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
|
Map<String, String> details = new HashMap<>();
|
||||||
|
details.put("userType", String.valueOf(jwtUser.getUserType().getValue()));
|
||||||
|
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
|
||||||
|
authentication.setDetails(details);
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
// 生成令牌
|
// 生成令牌
|
||||||
String token = tokenProvider.createToken(jwtUser);
|
String token = tokenProvider.createToken(jwtUser);
|
||||||
|
@ -19,6 +19,7 @@ import cn.hutool.core.date.DateField;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
//import com.aircraft.modules.security.service.dto.JwtCustomerDto;
|
//import com.aircraft.modules.security.service.dto.JwtCustomerDto;
|
||||||
|
import com.aircraft.modules.security.service.dto.JwtCustomerDto;
|
||||||
import io.jsonwebtoken.*;
|
import io.jsonwebtoken.*;
|
||||||
import io.jsonwebtoken.io.Decoders;
|
import io.jsonwebtoken.io.Decoders;
|
||||||
import io.jsonwebtoken.security.Keys;
|
import io.jsonwebtoken.security.Keys;
|
||||||
@ -87,29 +88,29 @@ public class TokenProvider implements InitializingBean {
|
|||||||
.compact();
|
.compact();
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * 创建Token 设置永不过期,
|
* 创建Token 设置永不过期,
|
||||||
// * Token 的时间有效性转到Redis 维护
|
* Token 的时间有效性转到Redis 维护
|
||||||
// * @param user /
|
* @param user /
|
||||||
// * @return /
|
* @return /
|
||||||
// */
|
*/
|
||||||
// public String createToken(JwtCustomerDto user) {
|
public String createToken(JwtCustomerDto user) {
|
||||||
// // 设置参数
|
// 设置参数
|
||||||
// Map<String, Object> claims = new HashMap<>(6);
|
Map<String, Object> claims = new HashMap<>(6);
|
||||||
// // 设置用户ID
|
// 设置用户ID
|
||||||
// claims.put(AUTHORITIES_UID_KEY, user.getUser().getId());
|
claims.put(AUTHORITIES_UID_KEY, user.getUser().getId());
|
||||||
// // 设置UUID,确保每次Token不一样
|
// 设置UUID,确保每次Token不一样
|
||||||
// claims.put(AUTHORITIES_UUID_KEY, IdUtil.simpleUUID());
|
claims.put(AUTHORITIES_UUID_KEY, IdUtil.simpleUUID());
|
||||||
// // 直接调用 Jwts.builder() 创建新实例
|
// 直接调用 Jwts.builder() 创建新实例
|
||||||
// return Jwts.builder()
|
return Jwts.builder()
|
||||||
// // 设置自定义 Claims
|
// 设置自定义 Claims
|
||||||
// .setClaims(claims)
|
.setClaims(claims)
|
||||||
// // 设置主题
|
// 设置主题
|
||||||
// .setSubject(user.getUsername())
|
.setSubject(user.getUsername())
|
||||||
// // 使用预生成的签名密钥和算法签名
|
// 使用预生成的签名密钥和算法签名
|
||||||
// .signWith(signingKey, SignatureAlgorithm.HS512)
|
.signWith(signingKey, SignatureAlgorithm.HS512)
|
||||||
// .compact();
|
.compact();
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 依据Token 获取鉴权信息
|
* 依据Token 获取鉴权信息
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
//package com.aircraft.modules.security.service;
|
package com.aircraft.modules.security.service;
|
||||||
//
|
|
||||||
//import com.aircraft.modules.security.service.dto.JwtCustomerDto;
|
import com.aircraft.modules.security.service.dto.JwtCustomerDto;
|
||||||
//import com.aircraft.modules.security.service.dto.JwtUserDto;
|
import com.aircraft.modules.security.service.dto.JwtUserDto;
|
||||||
//import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
//
|
|
||||||
//import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
//
|
|
||||||
//@Service
|
@Service
|
||||||
//public class BOnlineUserService {
|
public class BOnlineUserService {
|
||||||
// public void save(JwtCustomerDto user, String token, HttpServletRequest request) {
|
public void save(JwtCustomerDto user, String token, HttpServletRequest request) {
|
||||||
// // 实现B端在线用户存储逻辑
|
// 实现B端在线用户存储逻辑
|
||||||
// // 可存入不同redis前缀的键值对
|
// 可存入不同redis前缀的键值对
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public void kickOutForUsername(String username) {
|
public void kickOutForUsername(String username) {
|
||||||
// // B端踢人逻辑
|
// B端踢人逻辑
|
||||||
// }
|
}
|
||||||
//}
|
}
|
@ -1,27 +1,28 @@
|
|||||||
//package com.aircraft.modules.security.service;
|
package com.aircraft.modules.security.service;
|
||||||
//
|
|
||||||
//import com.aircraft.modules.security.service.dto.JwtCustomerDto;
|
import com.aircraft.modules.security.service.dto.JwtCustomerDto;
|
||||||
//import com.aircraft.modules.security.service.dto.JwtUserDto;
|
import com.aircraft.modules.security.service.dto.JwtUserDto;
|
||||||
//import com.aircraft.modules.system.domain.CnCustomer;
|
import com.aircraft.modules.system.domain.CnCustomer;
|
||||||
//import com.aircraft.modules.system.service.CnCustomerService;
|
import com.aircraft.modules.system.service.CnCustomerService;
|
||||||
//import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
//import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
//import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
//import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
//
|
|
||||||
//@Slf4j
|
@Slf4j
|
||||||
//@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
//@Service("bUserDetailsService")
|
@Service("bUserDetailsService")
|
||||||
//public class BUserDetailsService implements UserDetailsService {
|
public class BUserDetailsService implements UserDetailsService {
|
||||||
//
|
|
||||||
// private final CnCustomerService cnCustomerService;
|
private final CnCustomerService cnCustomerService;
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public JwtCustomerDto loadUserByUsername(String phone) {
|
public JwtCustomerDto loadUserByUsername(String phone) {
|
||||||
// // 查询B端用户表(如b_user)
|
// 查询B端用户表(如b_user)
|
||||||
// CnCustomer customer = cnCustomerService.findByphone(phone);
|
CnCustomer customer = cnCustomerService.findByphone(phone);
|
||||||
// // 转换JwtUserDto(包含权限信息)
|
// 转换JwtUserDto(包含权限信息)
|
||||||
//// return convertToJwtUser(customer);
|
// return convertToJwtUser(customer);
|
||||||
// return null;
|
return null;
|
||||||
// }
|
}
|
||||||
//}
|
|
||||||
|
}
|
@ -1,82 +1,82 @@
|
|||||||
///*
|
/*
|
||||||
// * Copyright 2019-2025 Zheng Jie
|
* Copyright 2019-2025 Zheng Jie
|
||||||
// *
|
*
|
||||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// * you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
// * You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
// *
|
*
|
||||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
// *
|
*
|
||||||
// * Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// * See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
// * limitations under the License.
|
* limitations under the License.
|
||||||
// */
|
*/
|
||||||
//package com.aircraft.modules.security.service.dto;
|
package com.aircraft.modules.security.service.dto;
|
||||||
//
|
|
||||||
//import com.aircraft.modules.system.domain.CnCustomer;
|
import com.aircraft.modules.system.domain.CnCustomer;
|
||||||
//import com.aircraft.modules.system.domain.Dept;
|
import com.aircraft.modules.system.domain.Dept;
|
||||||
//import com.aircraft.modules.system.domain.EmEmployees;
|
import com.aircraft.modules.system.domain.EmEmployees;
|
||||||
//import com.aircraft.utils.enums.UserTypeEnum;
|
import com.aircraft.utils.enums.UserTypeEnum;
|
||||||
//import com.alibaba.fastjson2.annotation.JSONField;
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
//import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
//import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
//import lombok.Getter;
|
import lombok.Getter;
|
||||||
//import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
//
|
|
||||||
//import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
//import java.util.List;
|
import java.util.List;
|
||||||
//import java.util.Set;
|
import java.util.Set;
|
||||||
//import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @author Zheng Jie
|
* @author Zheng Jie
|
||||||
// * @date 2018-11-23
|
* @date 2018-11-23
|
||||||
// */
|
*/
|
||||||
//@Getter
|
@Getter
|
||||||
//@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
//public class JwtCustomerDto implements UserDetails {
|
public class JwtCustomerDto implements UserDetails {
|
||||||
//
|
|
||||||
// @ApiModelProperty(value = "用户")
|
@ApiModelProperty(value = "用户")
|
||||||
// private LoginUserDto user;
|
private LoginUserDto user;
|
||||||
//
|
|
||||||
// @ApiModelProperty(value = "角色")
|
@ApiModelProperty(value = "角色")
|
||||||
// private final List<AuthorityDto> authorities;
|
private final List<AuthorityDto> authorities;
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// @JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
// public String getPassword() {
|
public String getPassword() {
|
||||||
// return user.getPassword();
|
return user.getPassword();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// @JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
// public String getUsername() {
|
public String getUsername() {
|
||||||
// return user.getUsername();
|
return user.getUsername();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
// @Override
|
@Override
|
||||||
// public boolean isAccountNonExpired() {
|
public boolean isAccountNonExpired() {
|
||||||
// return true;
|
return true;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
// @Override
|
@Override
|
||||||
// public boolean isAccountNonLocked() {
|
public boolean isAccountNonLocked() {
|
||||||
// return true;
|
return true;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
// @Override
|
@Override
|
||||||
// public boolean isCredentialsNonExpired() {
|
public boolean isCredentialsNonExpired() {
|
||||||
// return true;
|
return true;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// @JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
// public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
// return user.getEnabled();
|
return user.getEnabled();
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
@ -9,8 +9,12 @@ import com.aircraft.modules.security.config.BLoginProperties;
|
|||||||
import com.aircraft.modules.security.config.LoginProperties;
|
import com.aircraft.modules.security.config.LoginProperties;
|
||||||
import com.aircraft.modules.security.config.SecurityProperties;
|
import com.aircraft.modules.security.config.SecurityProperties;
|
||||||
import com.aircraft.modules.security.security.TokenProvider;
|
import com.aircraft.modules.security.security.TokenProvider;
|
||||||
|
import com.aircraft.modules.security.service.BOnlineUserService;
|
||||||
|
import com.aircraft.modules.security.service.BUserDetailsService;
|
||||||
import com.aircraft.modules.security.service.OnlineUserService;
|
import com.aircraft.modules.security.service.OnlineUserService;
|
||||||
import com.aircraft.modules.security.service.UserDetailsServiceImpl;
|
import com.aircraft.modules.security.service.UserDetailsServiceImpl;
|
||||||
|
import com.aircraft.modules.security.service.dto.AuthUserDto;
|
||||||
|
import com.aircraft.modules.security.service.dto.JwtCustomerDto;
|
||||||
import com.aircraft.modules.system.domain.CnCustomer;
|
import com.aircraft.modules.system.domain.CnCustomer;
|
||||||
import com.aircraft.modules.system.service.CnCustomerService;
|
import com.aircraft.modules.system.service.CnCustomerService;
|
||||||
import com.aircraft.utils.PageResult;
|
import com.aircraft.utils.PageResult;
|
||||||
@ -70,9 +74,9 @@ public class CnCustomerController {
|
|||||||
private final LoginProperties loginProperties;
|
private final LoginProperties loginProperties;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
private final UserDetailsServiceImpl userDetailsService;
|
private final UserDetailsServiceImpl userDetailsService;
|
||||||
// private final BUserDetailsService bUserDetailsService;
|
private final BUserDetailsService bUserDetailsService;
|
||||||
// private final BLoginProperties bLoginProperties;
|
private final BLoginProperties bLoginProperties;
|
||||||
// private final BOnlineUserService bOnlineUserService;
|
private final BOnlineUserService bOnlineUserService;
|
||||||
|
|
||||||
@Log("分页查询客户")
|
@Log("分页查询客户")
|
||||||
@ApiOperation(value = "分页查询客户", notes = "分页查询客户")
|
@ApiOperation(value = "分页查询客户", notes = "分页查询客户")
|
||||||
@ -84,24 +88,24 @@ public class CnCustomerController {
|
|||||||
return new ResponseEntity<>(records,HttpStatus.OK);
|
return new ResponseEntity<>(records,HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Log("删除客户")
|
// @Log("删除客户")
|
||||||
@ApiOperation(value = "删除客户")
|
// @ApiOperation(value = "删除客户")
|
||||||
@RequestMapping(value = "{id}", method = {RequestMethod.DELETE})
|
// @RequestMapping(value = "{id}", method = {RequestMethod.DELETE})
|
||||||
@ApiImplicitParam(name = "id", value = "客户ID", required = true, paramType = "path")
|
// @ApiImplicitParam(name = "id", value = "客户ID", required = true, paramType = "path")
|
||||||
public ResponseEntity<Object> delete(@PathVariable final Integer id) {
|
// public ResponseEntity<Object> delete(@PathVariable final Integer id) {
|
||||||
try {
|
// try {
|
||||||
CnCustomer entity = entityService.getById(id);
|
// CnCustomer entity = entityService.getById(id);
|
||||||
entity.setDelFlag(1);
|
// entity.setDelFlag(1);
|
||||||
entityService.updateById(entity);
|
// entityService.updateById(entity);
|
||||||
return new ResponseEntity<>("成功删除客户", HttpStatus.OK);
|
// return new ResponseEntity<>("成功删除客户", HttpStatus.OK);
|
||||||
} catch (DataIntegrityViolationException e) {
|
// } catch (DataIntegrityViolationException e) {
|
||||||
LOG.error("删除客户失败", e);
|
// LOG.error("删除客户失败", e);
|
||||||
throw new RuntimeException( "删除客户失败,该客户不能删除,存在其他关联数据");
|
// throw new RuntimeException( "删除客户失败,该客户不能删除,存在其他关联数据");
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
LOG.error("删除客户失败", e);
|
// LOG.error("删除客户失败", e);
|
||||||
throw new RuntimeException("删除客户失败", e);
|
// throw new RuntimeException("删除客户失败", e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Log("查询单个客户")
|
@Log("查询单个客户")
|
||||||
@ApiOperation(value = "查询单个客户")
|
@ApiOperation(value = "查询单个客户")
|
||||||
@ -122,6 +126,8 @@ public class CnCustomerController {
|
|||||||
@RequestMapping(method = {RequestMethod.POST})
|
@RequestMapping(method = {RequestMethod.POST})
|
||||||
public ResponseEntity<Object> add(@Valid @RequestBody final CnCustomer entity) {
|
public ResponseEntity<Object> add(@Valid @RequestBody final CnCustomer entity) {
|
||||||
try {
|
try {
|
||||||
|
entity.setStatus("1");
|
||||||
|
entity.setPassword(passwordEncoder.encode("123456"));
|
||||||
entityService.save(entity);
|
entityService.save(entity);
|
||||||
return new ResponseEntity<>("成功保存客户", HttpStatus.OK);
|
return new ResponseEntity<>("成功保存客户", HttpStatus.OK);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -156,89 +162,48 @@ public class CnCustomerController {
|
|||||||
return new ResponseEntity<>(Collections.emptyList(),HttpStatus.OK);
|
return new ResponseEntity<>(Collections.emptyList(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Log("用户登录")
|
@Log("B端用户登录")
|
||||||
// @ApiOperation("登录授权")
|
@ApiOperation("B端登录授权")
|
||||||
// @AnonymousPostMapping(value = "/login")
|
@AnonymousPostMapping(value = "/b/login")
|
||||||
// public ResponseEntity<Object> login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception {
|
public ResponseEntity<Object> loginB(@Validated @RequestBody AuthUserDto authUser,
|
||||||
// // 密码解密
|
HttpServletRequest request) throws Exception {
|
||||||
// String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
|
||||||
// // 查询验证码
|
|
||||||
// String code = redisUtils.get(authUser.getUuid(), String.class);
|
|
||||||
// // 清除验证码
|
|
||||||
// redisUtils.del(authUser.getUuid());
|
|
||||||
// if (StringUtils.isBlank(code)) {
|
|
||||||
// throw new BadRequestException("验证码不存在或已过期");
|
|
||||||
// }
|
|
||||||
// if (StringUtils.isBlank(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) {
|
|
||||||
// throw new BadRequestException("验证码错误");
|
|
||||||
// }
|
|
||||||
// // 获取用户信息
|
|
||||||
// JwtUserDto jwtUser = userDetailsService.loadUserByUsername(authUser.getUsername());
|
|
||||||
// // 验证用户密码
|
|
||||||
// if (!passwordEncoder.matches(password, jwtUser.getPassword())) {
|
|
||||||
// throw new BadRequestException("登录密码错误");
|
|
||||||
// }
|
|
||||||
// Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
|
|
||||||
// SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
||||||
// // 生成令牌
|
|
||||||
// String token = tokenProvider.createToken(jwtUser);
|
|
||||||
// // 返回 token 与 用户信息
|
|
||||||
// Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
|
|
||||||
// put("token", properties.getTokenStartWith() + token);
|
|
||||||
// put("user", jwtUser);
|
|
||||||
// }};
|
|
||||||
// if (loginProperties.isSingleLogin()) {
|
|
||||||
// // 踢掉之前已经登录的token
|
|
||||||
// onlineUserService.kickOutForUsername(authUser.getUsername());
|
|
||||||
// }
|
|
||||||
// // 保存在线信息
|
|
||||||
// onlineUserService.save(jwtUser, token, request);
|
|
||||||
// // 返回登录信息
|
|
||||||
// return ResponseEntity.ok(authInfo);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Log("B端用户登录")
|
// 1. 密码解密(与后台相同)
|
||||||
// @ApiOperation("B端登录授权")
|
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
||||||
// @AnonymousPostMapping(value = "/b/login")
|
|
||||||
// public ResponseEntity<Object> loginB(@Validated @RequestBody AuthUserDto authUser,
|
// 3. 使用B端专属服务加载用户 ★核心修改★
|
||||||
// HttpServletRequest request) throws Exception {
|
// 假设:BUserDetailsService 是专门为B端实现的UserDetailsService
|
||||||
//
|
JwtCustomerDto jwtUser = bUserDetailsService.loadUserByUsername(authUser.getUsername());
|
||||||
// // 1. 密码解密(与后台相同)
|
|
||||||
// String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
// 4. 密码验证(保持相同逻辑)
|
||||||
//
|
if (!passwordEncoder.matches(password, jwtUser.getPassword())) {
|
||||||
// // 3. 使用B端专属服务加载用户 ★核心修改★
|
throw new BadRequestException("登录密码错误");
|
||||||
// // 假设:BUserDetailsService 是专门为B端实现的UserDetailsService
|
}
|
||||||
// JwtCustomerDto jwtUser = bUserDetailsService.loadUserByUsername(authUser.getUsername());
|
|
||||||
//
|
// 5. 设置认证信息
|
||||||
// // 4. 密码验证(保持相同逻辑)
|
Authentication authentication = new UsernamePasswordAuthenticationToken(
|
||||||
// if (!passwordEncoder.matches(password, jwtUser.getPassword())) {
|
jwtUser, null, jwtUser.getAuthorities()
|
||||||
// throw new BadRequestException("登录密码错误");
|
);
|
||||||
// }
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
//
|
|
||||||
// // 5. 设置认证信息
|
// 6. 生成令牌(复用相同机制)
|
||||||
// Authentication authentication = new UsernamePasswordAuthenticationToken(
|
String token = tokenProvider.createToken(jwtUser);
|
||||||
// jwtUser, null, jwtUser.getAuthorities()
|
|
||||||
// );
|
// 7. 返回信息(可调整返回字段)
|
||||||
// SecurityContextHolder.getContext().setAuthentication(authentication);
|
Map<String, Object> authInfo = new HashMap<>(2) {{
|
||||||
//
|
put("token", properties.getTokenStartWith() + token);
|
||||||
// // 6. 生成令牌(复用相同机制)
|
put("user", jwtUser); // 返回B端用户信息
|
||||||
// String token = tokenProvider.createToken(jwtUser);
|
}};
|
||||||
//
|
|
||||||
// // 7. 返回信息(可调整返回字段)
|
// 8. 单设备登录控制(可选)
|
||||||
// Map<String, Object> authInfo = new HashMap<>(2) {{
|
if (bLoginProperties.isSingleLogin()) { // B端专属配置
|
||||||
// put("token", properties.getTokenStartWith() + token);
|
bOnlineUserService.kickOutForUsername(authUser.getUsername());
|
||||||
// put("user", jwtUser); // 返回B端用户信息
|
}
|
||||||
// }};
|
|
||||||
//
|
// 9. 保存B端在线用户 ★核心修改★
|
||||||
// // 8. 单设备登录控制(可选)
|
bOnlineUserService.save(jwtUser, token, request);
|
||||||
// if (bLoginProperties.isSingleLogin()) { // B端专属配置
|
|
||||||
// bOnlineUserService.kickOutForUsername(authUser.getUsername());
|
return ResponseEntity.ok(authInfo);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // 9. 保存B端在线用户 ★核心修改★
|
|
||||||
// bOnlineUserService.save(jwtUser, token, request);
|
|
||||||
//
|
|
||||||
// return ResponseEntity.ok(authInfo);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,10 @@ public class EmEmployeesController {
|
|||||||
if (!passwordEncoder.matches(password, jwtUser.getPassword())) {
|
if (!passwordEncoder.matches(password, jwtUser.getPassword())) {
|
||||||
throw new BadRequestException("登录密码错误");
|
throw new BadRequestException("登录密码错误");
|
||||||
}
|
}
|
||||||
Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
|
Map<String, String> details = new HashMap<>();
|
||||||
|
details.put("userType", String.valueOf(jwtUser.getUserType().getValue()));
|
||||||
|
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
|
||||||
|
authentication.setDetails(details);
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
// 生成令牌
|
// 生成令牌
|
||||||
String token = tokenProvider.createToken(jwtUser);
|
String token = tokenProvider.createToken(jwtUser);
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package com.aircraft.modules.system.domain;
|
package com.aircraft.modules.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.aircraft.base.BaseEntity;
|
import com.aircraft.base.BaseEntity;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
*
|
*
|
||||||
@ -21,6 +25,7 @@ public class CnCustomer extends BaseEntity {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(value="id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.aircraft.modules.system.domain;
|
package com.aircraft.modules.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.aircraft.base.BaseEntity;
|
import com.aircraft.base.BaseEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -20,6 +22,7 @@ public class EmArea extends BaseEntity {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(value="id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.aircraft.modules.system.domain;
|
package com.aircraft.modules.system.domain;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.aircraft.base.BaseEntity;
|
import com.aircraft.base.BaseEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -21,6 +24,7 @@ public class EmScenic extends BaseEntity {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(value="id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,6 +6,7 @@ import com.aircraft.modules.system.mapper.CnCustomerMapper;
|
|||||||
import com.aircraft.modules.system.service.CnCustomerService;
|
import com.aircraft.modules.system.service.CnCustomerService;
|
||||||
import com.aircraft.utils.PageResult;
|
import com.aircraft.utils.PageResult;
|
||||||
import com.aircraft.utils.PageUtil;
|
import com.aircraft.utils.PageUtil;
|
||||||
|
import com.aircraft.utils.StringUtils;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@ -50,7 +51,10 @@ public class CnCustomerServiceImpl extends ServiceImpl<CnCustomerMapper, CnCusto
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private QueryWrapper<CnCustomer> buildWrapper(CnCustomer example) {
|
private QueryWrapper<CnCustomer> buildWrapper(CnCustomer example) {
|
||||||
|
String phone = example.getPhone();
|
||||||
QueryWrapper<CnCustomer> wrapper = new QueryWrapper<>();
|
QueryWrapper<CnCustomer> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.lambda()
|
||||||
|
.eq(StringUtils.isNotEmpty(phone),CnCustomer::getPhone,phone);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user