Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
c301c710a8
|
|
@ -1,6 +1,7 @@
|
|||
package com.bonus.material.purchase.config;
|
||||
|
||||
import com.bonus.common.core.constant.SecurityConstants;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.system.api.RemoteDictDataService;
|
||||
import com.bonus.system.api.RemoteUserService;
|
||||
|
|
@ -12,15 +13,15 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
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:51
|
||||
* @create 2024/10/23 19:06
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
|
|
@ -35,10 +36,12 @@ public class RemoteConfig {
|
|||
/**
|
||||
* 获取字典值
|
||||
* @param dictType
|
||||
* @param dictLabel
|
||||
* @return
|
||||
*/
|
||||
public String getDictValue(String dictType, String dictLabel) {
|
||||
public Map<String, String> getDictValue(String dictType) {
|
||||
if (StringUtils.isBlank(dictType)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
try {
|
||||
Map<String, String> dictMap = new LinkedHashMap<>();
|
||||
AjaxResult ajaxResult = remoteDictDataService.dictType(dictType, SecurityConstants.INNER);
|
||||
|
|
@ -55,37 +58,39 @@ public class RemoteConfig {
|
|||
dictMap = dataList.stream()
|
||||
.collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
|
||||
}
|
||||
return dictMap.get(dictLabel);
|
||||
return dictMap;
|
||||
} catch (Exception e) {
|
||||
log.error("远程调用查询字典键值失败:", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户名
|
||||
* @param userId
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
public String getUserName(String userId) {
|
||||
public Map<Long, String> getUserName(Long[] userIds) {
|
||||
if (userIds == null || userIds.length == 0) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
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) {
|
||||
AjaxResult ajaxResult = remoteUserService.getUsers(userIds, SecurityConstants.INNER);
|
||||
// 假设 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);
|
||||
List<SysUser> dataList = rawData.stream()
|
||||
.map(rawDatum -> objectMapper.convertValue(rawDatum, SysUser.class))
|
||||
.collect(Collectors.toList());
|
||||
// 创建一个以 createBy 为键,nickName 为值的映射
|
||||
Map<Long, String> nickNameMap = dataList.stream()
|
||||
.collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName));
|
||||
return nickNameMap;
|
||||
} catch (Exception e) {
|
||||
log.error("远程调用查询用户名失败:", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.bonus.common.biz.config.QrCodeUtils;
|
|||
import com.bonus.common.biz.constant.MaterialConstants;
|
||||
import com.bonus.common.biz.enums.HttpCodeEnum;
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.purchase.config.RemoteConfig;
|
||||
|
|
@ -83,12 +84,39 @@ public class PurchaseBindServiceImpl implements IPurchaseBindService {
|
|||
* @param list
|
||||
*/
|
||||
private void extracted(List<PurchaseVo> list) {
|
||||
for (PurchaseVo purchaseVo : list) {
|
||||
String userName = remoteConfig.getUserName(purchaseVo.getCreateBy());
|
||||
purchaseVo.setCreateBy(userName == null ? "" : userName);
|
||||
String dictValue = remoteConfig.getDictValue("purchase_task_status", purchaseVo.getStatus().toString());
|
||||
purchaseVo.setStatusName(dictValue == null ? "" : dictValue);
|
||||
}
|
||||
Long[] array = list.stream()
|
||||
// 提取 createBy 字段
|
||||
.map(PurchaseVo::getCreateBy)
|
||||
.map(createBy -> {
|
||||
try {
|
||||
// 转换为 Long
|
||||
return Long.parseLong(createBy);
|
||||
} catch (NumberFormatException e) {
|
||||
// 处理转换失败的情况,可以返回 null
|
||||
return null;
|
||||
}
|
||||
})
|
||||
// 过滤掉 null 值
|
||||
.filter(value -> value != null)
|
||||
.toArray(Long[]::new);// 转换为 Long[] 数组
|
||||
Map<Long, String> nickNameMap = remoteConfig.getUserName(array);
|
||||
Map<String, String> labelMap = remoteConfig.getDictValue("purchase_task_status");
|
||||
// 更新 list 中每个 PurchaseVo 对象的 name 字段
|
||||
list.forEach(purchaseVo -> {
|
||||
// 更新 createBy 为 nickName
|
||||
String createBy = purchaseVo.getCreateBy();
|
||||
if (StringUtils.isNotBlank(createBy)) {
|
||||
Long createById = Long.parseLong(createBy);
|
||||
String nickName = nickNameMap.get(createById);
|
||||
purchaseVo.setCreateBy(nickName != null ? nickName : createBy); // 设置为 nickName 或原值
|
||||
}
|
||||
// 更新状态名称
|
||||
Integer status = purchaseVo.getStatus();
|
||||
if (status != null) {
|
||||
String dictValue = labelMap.get(status.toString());
|
||||
purchaseVo.setStatusName(dictValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -114,10 +142,15 @@ public class PurchaseBindServiceImpl implements IPurchaseBindService {
|
|||
@Override
|
||||
public List<PurchaseVo> getDetails(PurchaseDto dto) {
|
||||
List<PurchaseVo> list = purchaseBindMapper.getDetails(dto);
|
||||
Map<String, String> labelMap = remoteConfig.getDictValue("purchase_task_status");
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
for (PurchaseVo purchaseVo : list) {
|
||||
String name = remoteConfig.getDictValue("purchase_task_status", purchaseVo.getStatus().toString());
|
||||
purchaseVo.setStatusName(name == null ? "" : name);
|
||||
// 更新状态名称
|
||||
Integer status = purchaseVo.getStatus();
|
||||
if (status != null) {
|
||||
String dictValue = labelMap.get(status.toString());
|
||||
purchaseVo.setStatusName(dictValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.bonus.material.purchase.service.impl;
|
|||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||
import com.bonus.common.biz.constant.MaterialConstants;
|
||||
import com.bonus.common.biz.enums.HttpCodeEnum;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.ma.mapper.MachineMapper;
|
||||
import com.bonus.material.purchase.config.RemoteConfig;
|
||||
|
|
@ -64,12 +65,39 @@ public class PurchaseStorageServiceImpl implements IPurchaseStorageService {
|
|||
* @param list
|
||||
*/
|
||||
private void extracted(List<PurchaseVo> list) {
|
||||
for (PurchaseVo purchaseVo : list) {
|
||||
String userName = remoteConfig.getUserName(purchaseVo.getCreateBy());
|
||||
purchaseVo.setCreateBy(userName == null ? "" : userName);
|
||||
String dictValue = remoteConfig.getDictValue("purchase_task_status", purchaseVo.getStatus().toString());
|
||||
purchaseVo.setStatusName(dictValue == null ? "" : dictValue);
|
||||
}
|
||||
Long[] array = list.stream()
|
||||
// 提取 createBy 字段
|
||||
.map(PurchaseVo::getCreateBy)
|
||||
.map(createBy -> {
|
||||
try {
|
||||
// 转换为 Long
|
||||
return Long.parseLong(createBy);
|
||||
} catch (NumberFormatException e) {
|
||||
// 处理转换失败的情况,可以返回 null
|
||||
return null;
|
||||
}
|
||||
})
|
||||
// 过滤掉 null 值
|
||||
.filter(value -> value != null)
|
||||
.toArray(Long[]::new);// 转换为 Long[] 数组
|
||||
Map<Long, String> nickNameMap = remoteConfig.getUserName(array);
|
||||
Map<String, String> labelMap = remoteConfig.getDictValue("purchase_task_status");
|
||||
// 更新 list 中每个 PurchaseVo 对象的 name 字段
|
||||
list.forEach(purchaseVo -> {
|
||||
// 更新 createBy 为 nickName
|
||||
String createBy = purchaseVo.getCreateBy();
|
||||
if (StringUtils.isNotBlank(createBy)) {
|
||||
Long createById = Long.parseLong(createBy);
|
||||
String nickName = nickNameMap.get(createById);
|
||||
purchaseVo.setCreateBy(nickName != null ? nickName : createBy); // 设置为 nickName 或原值
|
||||
}
|
||||
// 更新状态名称
|
||||
Integer status = purchaseVo.getStatus();
|
||||
if (status != null) {
|
||||
String dictValue = labelMap.get(status.toString());
|
||||
purchaseVo.setStatusName(dictValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,10 +108,15 @@ public class PurchaseStorageServiceImpl implements IPurchaseStorageService {
|
|||
@Override
|
||||
public List<PurchaseVo> getDetails(PurchaseDto dto) {
|
||||
List<PurchaseVo> list = purchaseBindMapper.getDetails(dto);
|
||||
Map<String, String> labelMap = remoteConfig.getDictValue("purchase_task_status");
|
||||
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(list)) {
|
||||
for (PurchaseVo purchaseVo : list) {
|
||||
String name = remoteConfig.getDictValue("purchase_task_status", purchaseVo.getStatus().toString());
|
||||
purchaseVo.setStatusName(name == null ? "" : name);
|
||||
// 更新状态名称
|
||||
Integer status = purchaseVo.getStatus();
|
||||
if (status != null) {
|
||||
String dictValue = labelMap.get(status.toString());
|
||||
purchaseVo.setStatusName(dictValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
|
|
|||
Loading…
Reference in New Issue