|
|
@@ -10,6 +10,7 @@ import com.dk.common.util.oauth.JwtUtil;
|
|
|
import com.dk.mdm.infrastructure.convert.mst.StaffConvert;
|
|
|
import com.dk.mdm.mapper.mst.StaffMapper;
|
|
|
import com.dk.common.model.response.mst.StaffResponse;
|
|
|
+import com.dk.mdm.model.query.mst.StaffQuery;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
@@ -19,13 +20,14 @@ import org.springframework.stereotype.Component;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
- * @desc : AuthUtils
|
|
|
* @author : 洪旭东
|
|
|
- * @date : 2022-06-07 16:13
|
|
|
+ * @desc : AuthUtils
|
|
|
+ * @date : 2022-06-07 16:13
|
|
|
*/
|
|
|
@Component("MdmAuthUtils")
|
|
|
@Slf4j
|
|
|
@@ -47,129 +49,148 @@ public class AuthUtils {
|
|
|
private HttpServletRequest httpServletRequest;
|
|
|
|
|
|
/**
|
|
|
- * @desc : 查询当前用户
|
|
|
+ * @desc : 查询当前用户
|
|
|
* @author : 洪旭东
|
|
|
- * @date : 2022-06-07 16:19
|
|
|
+ * @date : 2022-06-07 16:19
|
|
|
*/
|
|
|
- public StaffEntity getStaff(){
|
|
|
+ public StaffEntity getStaff() {
|
|
|
return getStaff(httpServletRequest.getHeader("Authorization"));
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
+ * @return com.dongke.auth.pojo.User
|
|
|
* @date_time 2021-12-23 09:25
|
|
|
* @author H_x_d
|
|
|
- * @description 通过token获取用户信息,如果redis中失效,重新查询
|
|
|
- * @return com.dongke.auth.pojo.User
|
|
|
+ * @description 通过token获取用户信息, 如果redis中失效,重新查询
|
|
|
*/
|
|
|
- public StaffEntity getStaff(String token){
|
|
|
- if (token==null) {
|
|
|
- return null;
|
|
|
+ public StaffEntity getStaff(String token) {
|
|
|
+ if (token == null) {
|
|
|
+ // 体验可能为空
|
|
|
+ StaffQuery staffQuery = new StaffQuery();
|
|
|
+ staffQuery.setCpId(2);
|
|
|
+ staffQuery.setStaffCode("东科智云-体验");
|
|
|
+ List<StaffResponse> staffResponses = staffMapper.selectByCond(staffQuery);
|
|
|
+ StaffEntity staffEntity = staffConvert.convertToEntity(staffResponses.get(0));
|
|
|
+ if (staffEntity != null) {
|
|
|
+ staffEntity.setCpCode("DK-STD");
|
|
|
+ staffEntity.setAppCode("CP-WXP");
|
|
|
+ saveStaff(staffEntity);
|
|
|
+ }
|
|
|
+ return staffEntity;
|
|
|
}
|
|
|
try {
|
|
|
String[] tokens = token.split(" ");
|
|
|
String decrypt = AESSecurityUtil.decrypt(AESKey, tokens[1]);
|
|
|
String userId = JwtUtil.getUserId(decrypt);
|
|
|
- log.info("staffId=>{}",userId);
|
|
|
+ log.info("staffId=>{}", userId);
|
|
|
String appCode = JwtUtil.getAppCode(decrypt);
|
|
|
- log.info("appCode=>{}",appCode);
|
|
|
+ log.info("appCode=>{}", appCode);
|
|
|
String cpId = JwtUtil.getCpId(decrypt);
|
|
|
- log.info("cpId=>{}",cpId);
|
|
|
+ log.info("cpId=>{}", cpId);
|
|
|
String cpCode = JwtUtil.getCpCode(decrypt);
|
|
|
- log.info("cpCode=>{}",cpCode);
|
|
|
+ log.info("cpCode=>{}", cpCode);
|
|
|
String key = Constant.RedisConstant.REDIS_USER_LOGIN.getName() + '_' + userId + '_' + appCode;
|
|
|
String json = stringRedisTemplate.opsForValue().get(key);
|
|
|
- if (json==null){
|
|
|
+ if (json == null) {
|
|
|
return null;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
StaffEntity staffEntity = JSONObject.parseObject(JSONObject.toJSONString(JSONObject.parseObject(json)), StaffEntity.class);
|
|
|
staffEntity.setAppCode(appCode);
|
|
|
staffEntity.setCpCode(cpCode);
|
|
|
- staffEntity.setCpId(Integer.parseInt(cpId) );
|
|
|
+ staffEntity.setCpId(Integer.parseInt(cpId));
|
|
|
return staffEntity;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- log.error(e.toString(),e);
|
|
|
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(),"解析accessToken失败");
|
|
|
+ log.error(e.toString(), e);
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), "解析accessToken失败");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * @desc : 清除redis用户信息
|
|
|
+ * @desc : 清除redis用户信息
|
|
|
* @author : 周兴
|
|
|
- * @date : 2023/1/6 15:46
|
|
|
+ * @date : 2023/1/6 15:46
|
|
|
*/
|
|
|
- public void cleanStaff(){
|
|
|
+ public void cleanStaff() {
|
|
|
String appCode = JwtUtil.getAppCode(httpServletRequest);
|
|
|
cleanStaff(Constant.RedisConstant.REDIS_STAFF.getName() + appCode + Constant.StringConstant.SYSTEM_MAGIN_LINE.getName() + getStaff().getStaffId());
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * @desc : 清除redis用户信息
|
|
|
+ * @desc : 清除redis用户信息
|
|
|
* @author : 周兴
|
|
|
- * @date : 2023/1/6 15:46
|
|
|
+ * @date : 2023/1/6 15:46
|
|
|
*/
|
|
|
- public void cleanStaff(Long userId){
|
|
|
+ public void cleanStaff(Long userId) {
|
|
|
String appCode = JwtUtil.getAppCode(httpServletRequest);
|
|
|
stringRedisTemplate.delete(Constant.RedisConstant.REDIS_STAFF.getName() + appCode + Constant.StringConstant.SYSTEM_MAGIN_LINE.getName() + userId);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * @desc : 清除redis用户信息
|
|
|
+ * @desc : 清除redis用户信息
|
|
|
* @author : 周兴
|
|
|
- * @date : 2023/1/6 15:46
|
|
|
+ * @date : 2023/1/6 15:46
|
|
|
*/
|
|
|
- public void cleanStaff(String key){
|
|
|
+ public void cleanStaff(String key) {
|
|
|
stringRedisTemplate.delete(key);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * @desc : 清除登录用户信息
|
|
|
+ * @desc : 清除登录用户信息
|
|
|
* @author : 周兴
|
|
|
- * @date : 2023/1/5 13:08
|
|
|
+ * @date : 2023/1/5 13:08
|
|
|
*/
|
|
|
- public void cleanLoginStaff(){
|
|
|
+ public void cleanLoginStaff() {
|
|
|
StaffEntity staffEntity = getStaff();
|
|
|
cleanLoginStaff(Constant.RedisConstant.REDIS_LOGIN.getName() + Constant.StringConstant.SYSTEM_MAGIN_LINE.getName() + staffEntity.getStaffCode());
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * @desc : 清除缓存
|
|
|
+ * @desc : 清除缓存
|
|
|
* @author : 周兴
|
|
|
- * @date : 2023/1/5 13:09
|
|
|
+ * @date : 2023/1/5 13:09
|
|
|
*/
|
|
|
- public void cleanLoginStaff(String key){
|
|
|
+ public void cleanLoginStaff(String key) {
|
|
|
stringRedisTemplate.delete(key);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
+ * @return User
|
|
|
* @date_time 2021-12-23 09:22
|
|
|
* @author H_x_d
|
|
|
* @description 保存用户信息 + 权限ID 到Redis
|
|
|
- * @return User
|
|
|
*/
|
|
|
- public StaffEntity saveStaff(String staffId, String cpCode, String appCode){
|
|
|
+ public StaffEntity saveStaff(String staffId, String cpCode, String appCode) {
|
|
|
StaffResponse staff = staffMapper.selectById(staffId);
|
|
|
StaffEntity staffEntity = staffConvert.convertToEntity(staff);
|
|
|
- if (staffEntity!=null) {
|
|
|
+ if (staffEntity != null) {
|
|
|
staffEntity.setAppCode(appCode);
|
|
|
staffEntity.setCpCode(cpCode);
|
|
|
saveStaff(staffEntity);
|
|
|
}
|
|
|
return staffEntity;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * @desc : 保存员工
|
|
|
+ * @desc : 保存员工
|
|
|
* @author : 周兴
|
|
|
- * @date : 2023/1/6 15:18
|
|
|
+ * @date : 2023/1/6 15:18
|
|
|
*/
|
|
|
- public StaffEntity saveStaff(StaffEntity staff){
|
|
|
- if(staff != null ){
|
|
|
+ public StaffEntity saveStaff(StaffEntity staff) {
|
|
|
+ if (staff != null) {
|
|
|
String userId = staff.getWxUserId();
|
|
|
String appCode = staff.getAppCode();
|
|
|
String key = Constant.RedisConstant.REDIS_USER_LOGIN.getName() + '_' + userId + '_' + appCode;
|
|
|
String mapStr = stringRedisTemplate.opsForValue().get(key);
|
|
|
- Map<String,Object> userMap = JSONObject.parseObject(mapStr);
|
|
|
+ Map<String, Object> userMap = JSONObject.parseObject(mapStr);
|
|
|
if (userMap != null) {
|
|
|
- userMap.put("staffId",staff.getStaffId());
|
|
|
- userMap.put("staffCode",staff.getStaffCode());
|
|
|
- userMap.put("gradeCode",staff.getGradeCode());
|
|
|
- userMap.put("cpId",staff.getCpId());
|
|
|
- userMap.put("cpCode",staff.getCpCode());
|
|
|
- userMap.put("orgId",staff.getOrgId());
|
|
|
- userMap.put("opUpdateTime",LocalDateTime.now());
|
|
|
+ userMap.put("staffId", staff.getStaffId());
|
|
|
+ userMap.put("staffCode", staff.getStaffCode());
|
|
|
+ userMap.put("gradeCode", staff.getGradeCode());
|
|
|
+ userMap.put("cpId", staff.getCpId());
|
|
|
+ userMap.put("cpCode", staff.getCpCode());
|
|
|
+ userMap.put("orgId", staff.getOrgId());
|
|
|
+ userMap.put("opUpdateTime", LocalDateTime.now());
|
|
|
stringRedisTemplate.opsForValue().set(key, JSONObject.toJSONString(userMap));
|
|
|
}
|
|
|
}
|