Browse Source

物关系修改组名称缓存问题

2024年10月21日13:55:30
thing_master
lishuai 1 year ago
parent
commit
5286fb7250
  1. 1
      modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java
  2. 2
      modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java
  3. 21
      modules/thing/src/main/java/com/thing/thing/relation/root/service/impl/IotThingRelationRootServiceImpl.java

1
modules/thing/src/main/java/com/thing/thing/relation/detail/controller/IotThingRelationDetailController.java

@ -22,7 +22,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;

2
modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java

@ -996,7 +996,7 @@ public class IotThingRelationDetailServiceImpl extends BaseServiceImpl<IotThingR
List<IotThingRelationDetailExcel> resList = list.stream().map(node -> { List<IotThingRelationDetailExcel> resList = list.stream().map(node -> {
IotThingRelationDetailExcel excel = new IotThingRelationDetailExcel(); IotThingRelationDetailExcel excel = new IotThingRelationDetailExcel();
excel.setFromName(node.get("fromName").asText()); excel.setFromName(node.get("fromName").asText());
excel.setFromCode(node.get("fromCode").asText());
excel.setFromCode(node.get("fromCode").isEmpty() ? "" : node.get("fromCode").asText());
excel.setToName(node.get("toName").asText()); excel.setToName(node.get("toName").asText());
excel.setToCode(node.get("toCode").asText()); excel.setToCode(node.get("toCode").asText());
excel.setConfig(node.get("config").isEmpty() ? "" : node.get("config").asText()); excel.setConfig(node.get("config").isEmpty() ? "" : node.get("config").asText());

21
modules/thing/src/main/java/com/thing/thing/relation/root/service/impl/IotThingRelationRootServiceImpl.java

@ -200,11 +200,29 @@ public class IotThingRelationRootServiceImpl extends BaseServiceImpl<IotThingRel
iotThingRelationRootInsert.getGroupName()+CacheInit.KEY+ iotThingRelationRootInsert.getName()+CacheInit.KEY+ iotThingRelationRootInsert.getId(),nodes); iotThingRelationRootInsert.getGroupName()+CacheInit.KEY+ iotThingRelationRootInsert.getName()+CacheInit.KEY+ iotThingRelationRootInsert.getId(),nodes);
} }
private void updateRootAndCacheAny(IotThingRelationRootEntity iotThingRelationRootInsert) {
IotThingRelationRootDTO relationRootDTO = ConvertUtils.sourceToTarget(iotThingRelationRootInsert, IotThingRelationRootDTO.class);
ObjectNode nodes = JsonConverter.convertToJsonObjectObjectNode(relationRootDTO);
nodes.put("fromId", "0");
nodes.put("rootId", nodes.get("id").asText());
nodes.put("toId", nodes.get("id").asText());
nodes.put("toName", nodes.get("name").asText());
nodes.put("rootThingId", "0");
cache.updateAccurateKeyMap(CacheNameEnum.THING_ROOT_RELATION,
iotThingRelationRootInsert.getGroupName()+CacheInit.KEY+ iotThingRelationRootInsert.getName()+CacheInit.KEY+ iotThingRelationRootInsert.getId(),nodes);
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void update(IotThingRelationRootDTO dto) { public void update(IotThingRelationRootDTO dto) {
Long id = dto.getId(); Long id = dto.getId();
IotThingRelationRootEntity iotThingRelationRootEntity = mapper.selectOneById(id); IotThingRelationRootEntity iotThingRelationRootEntity = mapper.selectOneById(id);
String oldKey = iotThingRelationRootEntity.getGroupName() + CacheInit.KEY + iotThingRelationRootEntity.getName() + CacheInit.KEY + iotThingRelationRootEntity.getId();
iotThingRelationRootEntity.setName(dto.getName()); iotThingRelationRootEntity.setName(dto.getName());
String url = BizUtils.trimAll(dto.getUrl()); String url = BizUtils.trimAll(dto.getUrl());
if(StringUtils.isNotBlank(url)){ if(StringUtils.isNotBlank(url)){
@ -214,8 +232,9 @@ public class IotThingRelationRootServiceImpl extends BaseServiceImpl<IotThingRel
iotThingRelationRootEntity.setUrl(url); iotThingRelationRootEntity.setUrl(url);
iotThingRelationRootEntity.setRemark(dto.getRemark()); iotThingRelationRootEntity.setRemark(dto.getRemark());
iotThingRelationRootEntity.setGroupName(dto.getGroupName()); iotThingRelationRootEntity.setGroupName(dto.getGroupName());
mapper.insertOrUpdateSelective(iotThingRelationRootEntity);
mapper.update(iotThingRelationRootEntity);
//更新缓存 //更新缓存
cache.deleteKeyMap(CacheNameEnum.THING_ROOT_RELATION,oldKey);
updateRootAndCache(iotThingRelationRootEntity); updateRootAndCache(iotThingRelationRootEntity);
} }

Loading…
Cancel
Save