配置类定义
This commit is contained in:
parent
cc0f05de55
commit
8f4bb21f93
|
|
@ -1,90 +0,0 @@
|
||||||
package com.bonus.material.purchase.config;
|
|
||||||
|
|
||||||
import com.bonus.common.core.constant.SecurityConstants;
|
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
|
||||||
import com.bonus.system.api.RemoteDictDataService;
|
|
||||||
import com.bonus.system.api.RemoteUserService;
|
|
||||||
import com.bonus.system.api.domain.SysDictData;
|
|
||||||
import com.bonus.system.api.domain.SysUser;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 框架远程调用配置类
|
|
||||||
* @Author ma_sh
|
|
||||||
* @create 2024/10/23 16:10
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class RemoteConfig {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RemoteDictDataService remoteDictDataService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RemoteUserService remoteUserService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取字典值
|
|
||||||
* @param dictType
|
|
||||||
* @param dictLabel
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getDictValue(String dictType, String dictLabel) {
|
|
||||||
try {
|
|
||||||
Map<String, String> dictMap = new LinkedHashMap<>();
|
|
||||||
AjaxResult ajaxResult = remoteDictDataService.dictType(dictType, SecurityConstants.INNER);
|
|
||||||
if (ajaxResult.isSuccess()) {
|
|
||||||
// 假设 ajaxResult.get("data") 返回的是 List<LinkedHashMap>
|
|
||||||
List<LinkedHashMap> rawData = (List<LinkedHashMap>) ajaxResult.get("data");
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
// 将 rawData 转换为 SysDictData 列表
|
|
||||||
List<SysDictData> dataList = rawData.stream()
|
|
||||||
.map(rawDatum -> objectMapper.convertValue(rawDatum, SysDictData.class))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
// 使用 Map 存储字典数据以提高查找速度
|
|
||||||
dictMap = dataList.stream()
|
|
||||||
.collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
|
|
||||||
}
|
|
||||||
return dictMap.get(dictLabel);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("远程调用查询字典键值失败:", e.getMessage());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户名
|
|
||||||
* @param userId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getUserName(String userId) {
|
|
||||||
try {
|
|
||||||
String userName = "";
|
|
||||||
AjaxResult ajaxResult = remoteUserService.getInfo(Long.parseLong(userId), SecurityConstants.INNER);
|
|
||||||
if (ajaxResult.isSuccess()) {
|
|
||||||
// ajaxResult.get("data") 返回的是 LinkedHashMap
|
|
||||||
LinkedHashMap<String, Object> rawDataList = (LinkedHashMap<String, Object>) ajaxResult.get("data");
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
if (rawDataList != null) {
|
|
||||||
SysUser sysUser = objectMapper.convertValue(rawDataList, SysUser.class);
|
|
||||||
userName = sysUser.getNickName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return userName;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
log.error("远程调用查询用户名失败:", e.getMessage());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -8,7 +8,6 @@ import com.bonus.common.biz.enums.HttpCodeEnum;
|
||||||
import com.bonus.common.core.utils.DateUtils;
|
import com.bonus.common.core.utils.DateUtils;
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import com.bonus.common.security.utils.SecurityUtils;
|
import com.bonus.common.security.utils.SecurityUtils;
|
||||||
import com.bonus.material.purchase.config.RemoteConfig;
|
|
||||||
import com.bonus.material.purchase.dto.PurchaseDto;
|
import com.bonus.material.purchase.dto.PurchaseDto;
|
||||||
import com.bonus.material.purchase.mapper.PurchaseBindMapper;
|
import com.bonus.material.purchase.mapper.PurchaseBindMapper;
|
||||||
import com.bonus.material.purchase.service.IPurchaseBindService;
|
import com.bonus.material.purchase.service.IPurchaseBindService;
|
||||||
|
|
@ -42,9 +41,6 @@ public class PurchaseBindServiceImpl implements IPurchaseBindService {
|
||||||
@Resource
|
@Resource
|
||||||
private TmTaskMapper tmTaskMapper;
|
private TmTaskMapper tmTaskMapper;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RemoteConfig remoteConfig;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有绑定信息
|
* 查询所有绑定信息
|
||||||
* @param dto
|
* @param dto
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue