代码合并
This commit is contained in:
parent
632947357e
commit
e14b2d3754
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bonus.material.purchase.config;
|
package com.bonus.material.purchase.config;
|
||||||
|
|
||||||
import com.bonus.common.core.constant.SecurityConstants;
|
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.common.core.web.domain.AjaxResult;
|
||||||
import com.bonus.system.api.RemoteDictDataService;
|
import com.bonus.system.api.RemoteDictDataService;
|
||||||
import com.bonus.system.api.RemoteUserService;
|
import com.bonus.system.api.RemoteUserService;
|
||||||
|
|
@ -12,15 +13,15 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 远程调用查询键值配置类
|
|
||||||
* @Author ma_sh
|
* @Author ma_sh
|
||||||
* @create 2024/10/23 16:51
|
* @create 2024/10/23 19:06
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -35,10 +36,12 @@ public class RemoteConfig {
|
||||||
/**
|
/**
|
||||||
* 获取字典值
|
* 获取字典值
|
||||||
* @param dictType
|
* @param dictType
|
||||||
* @param dictLabel
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getDictValue(String dictType, String dictLabel) {
|
public Map<String, String> getDictValue(String dictType) {
|
||||||
|
if (StringUtils.isBlank(dictType)) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Map<String, String> dictMap = new LinkedHashMap<>();
|
Map<String, String> dictMap = new LinkedHashMap<>();
|
||||||
AjaxResult ajaxResult = remoteDictDataService.dictType(dictType, SecurityConstants.INNER);
|
AjaxResult ajaxResult = remoteDictDataService.dictType(dictType, SecurityConstants.INNER);
|
||||||
|
|
@ -55,37 +58,39 @@ public class RemoteConfig {
|
||||||
dictMap = dataList.stream()
|
dictMap = dataList.stream()
|
||||||
.collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
|
.collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
|
||||||
}
|
}
|
||||||
return dictMap.get(dictLabel);
|
return dictMap;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("远程调用查询字典键值失败:", e.getMessage());
|
log.error("远程调用查询字典键值失败:", e.getMessage());
|
||||||
}
|
}
|
||||||
return null;
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户名
|
* 获取用户名
|
||||||
* @param userId
|
* @param userIds
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getUserName(String userId) {
|
public Map<Long, String> getUserName(Long[] userIds) {
|
||||||
|
if (userIds == null || userIds.length == 0) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String userName = "";
|
AjaxResult ajaxResult = remoteUserService.getUsers(userIds, SecurityConstants.INNER);
|
||||||
AjaxResult ajaxResult = remoteUserService.getInfo(Long.parseLong(userId), SecurityConstants.INNER);
|
// 假设 ajaxResult.get("data") 返回的是 List<LinkedHashMap>
|
||||||
if (ajaxResult.isSuccess()) {
|
List<LinkedHashMap> rawData = (List<LinkedHashMap>) ajaxResult.get("data");
|
||||||
// ajaxResult.get("data") 返回的是 LinkedHashMap
|
|
||||||
LinkedHashMap<String, Object> rawDataList = (LinkedHashMap<String, Object>) ajaxResult.get("data");
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
if (rawDataList != null) {
|
List<SysUser> dataList = rawData.stream()
|
||||||
SysUser sysUser = objectMapper.convertValue(rawDataList, SysUser.class);
|
.map(rawDatum -> objectMapper.convertValue(rawDatum, SysUser.class))
|
||||||
userName = sysUser.getNickName();
|
.collect(Collectors.toList());
|
||||||
}
|
// 创建一个以 createBy 为键,nickName 为值的映射
|
||||||
}
|
Map<Long, String> nickNameMap = dataList.stream()
|
||||||
return userName;
|
.collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName));
|
||||||
} catch (IllegalArgumentException e) {
|
return nickNameMap;
|
||||||
|
} catch (Exception e) {
|
||||||
log.error("远程调用查询用户名失败:", e.getMessage());
|
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.constant.MaterialConstants;
|
||||||
import com.bonus.common.biz.enums.HttpCodeEnum;
|
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.utils.StringUtils;
|
||||||
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.config.RemoteConfig;
|
||||||
|
|
@ -83,12 +84,39 @@ public class PurchaseBindServiceImpl implements IPurchaseBindService {
|
||||||
* @param list
|
* @param list
|
||||||
*/
|
*/
|
||||||
private void extracted(List<PurchaseVo> list) {
|
private void extracted(List<PurchaseVo> list) {
|
||||||
for (PurchaseVo purchaseVo : list) {
|
Long[] array = list.stream()
|
||||||
String userName = remoteConfig.getUserName(purchaseVo.getCreateBy());
|
// 提取 createBy 字段
|
||||||
purchaseVo.setCreateBy(userName == null ? "" : userName);
|
.map(PurchaseVo::getCreateBy)
|
||||||
String dictValue = remoteConfig.getDictValue("purchase_task_status", purchaseVo.getStatus().toString());
|
.map(createBy -> {
|
||||||
purchaseVo.setStatusName(dictValue == null ? "" : dictValue);
|
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
|
@Override
|
||||||
public List<PurchaseVo> getDetails(PurchaseDto dto) {
|
public List<PurchaseVo> getDetails(PurchaseDto dto) {
|
||||||
List<PurchaseVo> list = purchaseBindMapper.getDetails(dto);
|
List<PurchaseVo> list = purchaseBindMapper.getDetails(dto);
|
||||||
|
Map<String, String> labelMap = remoteConfig.getDictValue("purchase_task_status");
|
||||||
if (CollectionUtils.isNotEmpty(list)) {
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
for (PurchaseVo purchaseVo : 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;
|
return list;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.bonus.material.purchase.service.impl;
|
||||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||||
import com.bonus.common.biz.constant.MaterialConstants;
|
import com.bonus.common.biz.constant.MaterialConstants;
|
||||||
import com.bonus.common.biz.enums.HttpCodeEnum;
|
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.common.core.web.domain.AjaxResult;
|
||||||
import com.bonus.material.ma.mapper.MachineMapper;
|
import com.bonus.material.ma.mapper.MachineMapper;
|
||||||
import com.bonus.material.purchase.config.RemoteConfig;
|
import com.bonus.material.purchase.config.RemoteConfig;
|
||||||
|
|
@ -64,12 +65,39 @@ public class PurchaseStorageServiceImpl implements IPurchaseStorageService {
|
||||||
* @param list
|
* @param list
|
||||||
*/
|
*/
|
||||||
private void extracted(List<PurchaseVo> list) {
|
private void extracted(List<PurchaseVo> list) {
|
||||||
for (PurchaseVo purchaseVo : list) {
|
Long[] array = list.stream()
|
||||||
String userName = remoteConfig.getUserName(purchaseVo.getCreateBy());
|
// 提取 createBy 字段
|
||||||
purchaseVo.setCreateBy(userName == null ? "" : userName);
|
.map(PurchaseVo::getCreateBy)
|
||||||
String dictValue = remoteConfig.getDictValue("purchase_task_status", purchaseVo.getStatus().toString());
|
.map(createBy -> {
|
||||||
purchaseVo.setStatusName(dictValue == null ? "" : dictValue);
|
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
|
@Override
|
||||||
public List<PurchaseVo> getDetails(PurchaseDto dto) {
|
public List<PurchaseVo> getDetails(PurchaseDto dto) {
|
||||||
List<PurchaseVo> list = purchaseBindMapper.getDetails(dto);
|
List<PurchaseVo> list = purchaseBindMapper.getDetails(dto);
|
||||||
|
Map<String, String> labelMap = remoteConfig.getDictValue("purchase_task_status");
|
||||||
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(list)) {
|
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(list)) {
|
||||||
for (PurchaseVo purchaseVo : 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;
|
return list;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue