Commit 571762e0 by HlQ

[fix] mall 绑定事件 Bug 修改

1 parent 5111b8c7
...@@ -65,13 +65,13 @@ public class EventController { ...@@ -65,13 +65,13 @@ public class EventController {
return eventService.list(dto); return eventService.list(dto);
} }
@PostMapping("/bind/{agentUid}") @PostMapping("/bind/{agentUid}/{mallUid}")
@SaCheckPermission(value = "event:bind", orRole = "admin") @SaCheckPermission(value = "event:bind", orRole = "admin")
public String bind(@PathVariable String agentUid, @RequestBody List<RAgentEvent> dtoList) { public String bind(@PathVariable String agentUid, @PathVariable String mallUid, @RequestBody List<RAgentEvent> dtoList) {
return agentEventService.bind(agentUid, dtoList); return agentEventService.bind(agentUid, mallUid, dtoList);
} }
@PostMapping("/unbind") @PostMapping("/unbind/{agentUid}/{mallUid}")
@SaCheckPermission(value = "event:unbind", orRole = "admin") @SaCheckPermission(value = "event:unbind", orRole = "admin")
public String unbind(List<Long> idList) { public String unbind(List<Long> idList) {
return agentEventService.unbind(idList); return agentEventService.unbind(idList);
......
...@@ -263,9 +263,9 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp ...@@ -263,9 +263,9 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
var accountList = orgDTO.getAccountList(); var accountList = orgDTO.getAccountList();
var mallList = orgDTO.getMallList(); var mallList = orgDTO.getMallList();
var existAccList = accountService.lambdaQuery().eq(MAccount::getAgentUid, agentUid).list(); var existAccList = accountService.list();
var uid2AccMap = existAccList.stream().collect(Collectors.toMap(MAccount::getUid, Function.identity())); var uid2AccMap = existAccList.stream().collect(Collectors.toMap(MAccount::getUid, Function.identity()));
var existMallList = mallService.lambdaQuery().eq(Mall::getAgentUid, agentUid).list(); var existMallList = mallService.list();
var uid2MallMap = existMallList.stream().collect(Collectors.toMap(Mall::getUid, Function.identity())); var uid2MallMap = existMallList.stream().collect(Collectors.toMap(Mall::getUid, Function.identity()));
List<MAccount> insAccList = new ArrayList<>(); List<MAccount> insAccList = new ArrayList<>();
...@@ -286,8 +286,8 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp ...@@ -286,8 +286,8 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
List<Mall> updMallList = new ArrayList<>(); List<Mall> updMallList = new ArrayList<>();
mallList.forEach(m -> { mallList.forEach(m -> {
if (uid2MallMap.containsKey(m.getUid())) { if (uid2MallMap.containsKey(m.getUid())) {
var acc = uid2MallMap.get(m.getUid()); var mall = uid2MallMap.get(m.getUid());
m.setId(acc.getId()); m.setId(mall.getId());
updMallList.add(m); updMallList.add(m);
} else { } else {
m.setAgentUid(agentUid); m.setAgentUid(agentUid);
...@@ -295,10 +295,18 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp ...@@ -295,10 +295,18 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
insMallList.add(m); insMallList.add(m);
} }
}); });
Opt.ofEmptyAble(insAccList).ifPresent(accountService::saveBatch); if (CollUtil.isNotEmpty(insAccList)) {
Opt.ofEmptyAble(insMallList).ifPresent(mallService::saveBatch); accountService.saveBatch(insAccList);
Opt.ofEmptyAble(updAccList).ifPresent(accountService::updateBatchById); }
Opt.ofEmptyAble(updMallList).ifPresent(mallService::updateBatchById); if (CollUtil.isNotEmpty(insMallList)) {
mallService.saveBatch(insMallList);
}
if (CollUtil.isNotEmpty(updAccList)) {
accountService.updateBatchById(updAccList);
}
if (CollUtil.isNotEmpty(updMallList)) {
mallService.updateBatchById(updMallList);
}
return "success"; return "success";
} }
......
...@@ -18,7 +18,6 @@ import vion.service.monitor.IEventRecordService; ...@@ -18,7 +18,6 @@ import vion.service.monitor.IEventRecordService;
import vion.service.monitor.IMallService; import vion.service.monitor.IMallService;
import vion.vo.monitor.MallVO; import vion.vo.monitor.MallVO;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -50,9 +49,9 @@ public class MallServiceImpl extends MPJBaseServiceImpl<MallMapper, Mall> implem ...@@ -50,9 +49,9 @@ public class MallServiceImpl extends MPJBaseServiceImpl<MallMapper, Mall> implem
.in("mall_uid", mallUidList) .in("mall_uid", mallUidList)
.orderByDesc("mall_uid", "create_time"); .orderByDesc("mall_uid", "create_time");
var eventRecordList = eventRecordService.list(eventRecWrapper); var eventRecordList = eventRecordService.list(eventRecWrapper);
var eventUid2SelfMap = eventRecordList.stream().collect(Collectors.toMap(EventRecord::getEventUid, Function.identity())); var mallUid2SelfMap = eventRecordList.stream().collect(Collectors.groupingBy(EventRecord::getMallUid));
r.forEach(tmp -> tmp.setEventRecord(eventUid2SelfMap.get(tmp.getUid()))); r.forEach(tmp -> tmp.setEventRecordList(mallUid2SelfMap.get(tmp.getUid())));
}); });
return mallVOPage; return mallVOPage;
} }
......
package vion.service.impl.monitor; package vion.service.impl.monitor;
import com.github.yulichang.base.MPJBaseServiceImpl; import com.github.yulichang.base.MPJBaseServiceImpl;
import org.dromara.hutool.core.lang.Opt; import lombok.RequiredArgsConstructor;
import net.dreamlu.iot.mqtt.codec.MqttQoS;
import net.dreamlu.iot.mqtt.spring.client.MqttClientTemplate;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import vion.mapper.monitor.RAgentEventMapper; import vion.mapper.monitor.RAgentEventMapper;
import vion.model.monitor.RAgentEvent; import vion.model.monitor.RAgentEvent;
import vion.service.monitor.IRAgentEventService; import vion.service.monitor.IRAgentEventService;
import vion.utils.JsonUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -17,32 +22,42 @@ import java.util.stream.Collectors; ...@@ -17,32 +22,42 @@ import java.util.stream.Collectors;
* @date 2024/10/31 * @date 2024/10/31
*/ */
@Service @Service
@RequiredArgsConstructor
public class RAgentEventServiceImpl extends MPJBaseServiceImpl<RAgentEventMapper, RAgentEvent> implements IRAgentEventService { public class RAgentEventServiceImpl extends MPJBaseServiceImpl<RAgentEventMapper, RAgentEvent> implements IRAgentEventService {
private final MqttClientTemplate client;
@Override @Override
public String bind(String agentUid, List<RAgentEvent> dtoList) { public String bind(String agentUid, String mallUid, List<RAgentEvent> dtoList) {
dtoList.forEach(ae -> ae.setAgentUid(agentUid)); dtoList.forEach(ae -> ae.setAgentUid(agentUid));
var agentEventList = this.lambdaQuery().eq(RAgentEvent::getAgentUid, agentUid).list(); var agentEventList = this.lambdaQuery().eq(RAgentEvent::getMallUid, mallUid).list();
var mallUid2AEMap = agentEventList.stream().collect(Collectors.toMap(RAgentEvent::getMallUid, Function.identity())); var eventUid2AEMap = agentEventList.stream().collect(Collectors.toMap(RAgentEvent::getEventUid, Function.identity()));
List<RAgentEvent> updList = new ArrayList<>(); List<RAgentEvent> updList = new ArrayList<>();
List<RAgentEvent> insList = new ArrayList<>(); List<RAgentEvent> insList = new ArrayList<>();
dtoList.forEach(dto -> { dtoList.forEach(dto -> {
if (mallUid2AEMap.containsKey(dto.getMallUid())) { if (eventUid2AEMap.containsKey(dto.getEventUid())) {
var ae = mallUid2AEMap.get(dto.getMallUid()); var ae = eventUid2AEMap.get(dto.getEventUid());
dto.setId(ae.getId()); dto.setId(ae.getId());
updList.add(dto); updList.add(dto);
} else { } else {
insList.add(dto); insList.add(dto);
} }
}); });
Opt.ofEmptyAble(updList).ifPresent(this::updateBatchById); if (CollUtil.isNotEmpty(updList)) {
Opt.ofEmptyAble(insList).ifPresent(this::saveBatch); this.updateBatchById(updList);
}
if (CollUtil.isNotEmpty(insList)) {
this.saveBatch(insList);
}
dtoList.forEach(dto -> client.publish(StrUtil.format("/SA/{}/event/push", agentUid), JsonUtil.toJsonByte(dto), MqttQoS.QOS2));
return "绑定成功"; return "绑定成功";
} }
@Override @Override
public String unbind(List<Long> idList) { public String unbind(List<Long> idList) {
// todo
// client.publish(StrUtil.format("/SA/{}/event/push", agentUid), JsonUtil.toJsonByte(agentEvent), MqttQoS.QOS2);
return this.removeBatchByIds(idList) ? "解绑成功" : "解绑失败"; return this.removeBatchByIds(idList) ? "解绑成功" : "解绑失败";
} }
} }
...@@ -11,7 +11,7 @@ import java.util.List; ...@@ -11,7 +11,7 @@ import java.util.List;
*/ */
public interface IRAgentEventService extends MPJBaseService<RAgentEvent> { public interface IRAgentEventService extends MPJBaseService<RAgentEvent> {
String bind(String agentUid, List<RAgentEvent> dtoList); String bind(String agentUid, String mallUid, List<RAgentEvent> dtoList);
String unbind(List<Long> idList); String unbind(List<Long> idList);
......
...@@ -5,6 +5,7 @@ import lombok.Setter; ...@@ -5,6 +5,7 @@ import lombok.Setter;
import vion.model.monitor.EventRecord; import vion.model.monitor.EventRecord;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* 项目mall信息 * 项目mall信息
...@@ -59,5 +60,5 @@ public class MallVO { ...@@ -59,5 +60,5 @@ public class MallVO {
private LocalDateTime updateTime; private LocalDateTime updateTime;
private EventRecord eventRecord; private List<EventRecord> eventRecordList;
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!