bug 和优化

This commit is contained in:
mx 2024-12-25 13:59:26 +08:00
parent 78be975a6a
commit 4624b9d0b7
6 changed files with 49 additions and 7 deletions

View File

@ -4,7 +4,7 @@ import java.util.HashMap;
import java.util.Map;
public class TranslationThreadLocal {
Map<String, String> cache = new HashMap<>();
Map<String, Object> cache = new HashMap<>();
/*把线程相关的部分内聚到 类里面 相当于map 每个类是对应key*/
private static ThreadLocal<TranslationThreadLocal> t = new ThreadLocal<TranslationThreadLocal>();
@ -25,9 +25,20 @@ public class TranslationThreadLocal {
}
public String get(String key1, String key2) {
return cache.get(key1 + "_" + key2);
Object o = cache.get(key1 + "_" + key2);
if (o == null){
return null;
}
public String set(String key1, String key2, String val) {
return o.toString();
}
public Object set(String key1, String key2, String val) {
return cache.put(key1 + "_" + key2, val);
}
public Object get(String key1) {
return cache.get(key1);
}
public Object set(String key1, Object val) {
return cache.put(key1, val);
}
}

View File

@ -1,6 +1,7 @@
package com.pusong.common.redis.manager;
import com.pusong.common.core.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.Cache;
@ -12,6 +13,7 @@ import java.util.concurrent.Callable;
*
* @author LionLi
*/
@Slf4j
public class CaffeineCacheDecorator implements Cache {
Logger logger = LoggerFactory.getLogger(CaffeineCacheDecorator.class);

View File

@ -54,8 +54,10 @@ public class TranslationHandler extends JsonSerializer<Object> implements Contex
if (result != null){
TranslationThreadLocal.getThreadInstance().set(value.toString(), translation.other(), result.toString());
}
// TranslationThreadLocal.getThreadInstance().set(value.toString(), translation.other(), "111");
}
gen.writeObject(result);
gen.writeObject(1);
} else {
gen.writeObject(value);
}

View File

@ -6,6 +6,7 @@ import com.pusong.common.translation.annotation.TranslationType;
import com.pusong.common.translation.constant.TransConstant;
import com.pusong.common.translation.core.TranslationInterface;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -16,6 +17,7 @@ import org.slf4j.LoggerFactory;
*/
@AllArgsConstructor
@TranslationType(type = TransConstant.DICT_TYPE_TO_LABEL)
@Slf4j
public class DictTypeTranslationImpl implements TranslationInterface<String> {
private final static Logger logger = LoggerFactory.getLogger(DictTypeTranslationImpl.class);

View File

@ -393,7 +393,6 @@ public class PsContractInfoServiceImpl implements IPsContractInfoService {
bo.setInContractStatus(List.of(ContractStatusEnum.SUCCESS.getCode()));
log.info("托管服务");
}
QueryWrapper<PsContractInfo> lqw = buildQueryWrapper(bo);
Page<PsContractInfoVo> result = baseMapper.selectPageContractList(pageQuery.build(), lqw);
if(CollectionUtils.isEmpty(result.getRecords())){
@ -738,8 +737,23 @@ public class PsContractInfoServiceImpl implements IPsContractInfoService {
List<PsContractBusinessBo> detailBos = new ArrayList<>();
for (PsCompanyInfoBo psCompanyInfoBo : bo.getServiceCompanyInfoList()) {
for (PsContractBusinessBo item : psCompanyInfoBo.getBusinessList()) {
item.setBusinessTypeName(dictDataService.selectDictLabel("contract_type",item.getBusinessType()));
SysDictData contractType = dictDataService.selectDict("contract_type", item.getBusinessType());
item.setBusinessTypeName(contractType.getDictLabel());
detailBos.add(item);
for (PsContractBusinessDetailBo detailBo : item.getDetailBos()) {
contractType = dictDataService.selectDict("service_project", detailBo.getBusinessProject());
String dictLabel = contractType.getDictLabel();
String remark = contractType.getRemark();
if (!StringUtils.isEmpty(remark)){
JSONObject jsonObject = JSONObject.parseObject(remark);
String extend = jsonObject.getString("extend");
if (extend != null){
dictLabel += extend;
}
}
detailBo.setBusinessProjectLabel(dictLabel);
}
}
}

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pusong.common.json.TranslationThreadLocal;
import lombok.RequiredArgsConstructor;
import com.pusong.common.core.constant.CacheNames;
import com.pusong.common.core.exception.ServiceException;
@ -25,6 +26,7 @@ import com.pusong.system.domain.vo.SysDictTypeVo;
import com.pusong.system.mapper.SysDictDataMapper;
import com.pusong.system.mapper.SysDictTypeMapper;
import com.pusong.system.service.ISysDictTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@ -43,6 +45,7 @@ import java.util.stream.Collectors;
*/
@RequiredArgsConstructor
@Service
@Slf4j
public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService {
private final SysDictTypeMapper baseMapper;
@ -217,7 +220,15 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
*/
@Override
public String getDictLabel(String dictType, String dictValue, String separator) {
List<SysDictDataVo> datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
Object result = TranslationThreadLocal.getThreadInstance().get(dictType);
List<SysDictDataVo> datas;
if (result != null && result instanceof List){
datas = (List<SysDictDataVo>)result;
}else{
datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
TranslationThreadLocal.getThreadInstance().set(dictType, datas);
}
Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel);
if (StringUtils.containsAny(dictValue, separator)) {
return Arrays.stream(dictValue.split(separator))