Commit 571762e0 by HlQ

[fix] mall 绑定事件 Bug 修改

1 parent 5111b8c7
......@@ -65,13 +65,13 @@ public class EventController {
return eventService.list(dto);
}
@PostMapping("/bind/{agentUid}")
@PostMapping("/bind/{agentUid}/{mallUid}")
@SaCheckPermission(value = "event:bind", orRole = "admin")
public String bind(@PathVariable String agentUid, @RequestBody List<RAgentEvent> dtoList) {
return agentEventService.bind(agentUid, dtoList);
public String bind(@PathVariable String agentUid, @PathVariable String mallUid, @RequestBody List<RAgentEvent> dtoList) {
return agentEventService.bind(agentUid, mallUid, dtoList);
}
@PostMapping("/unbind")
@PostMapping("/unbind/{agentUid}/{mallUid}")
@SaCheckPermission(value = "event:unbind", orRole = "admin")
public String unbind(List<Long> idList) {
return agentEventService.unbind(idList);
......
......@@ -263,9 +263,9 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
var accountList = orgDTO.getAccountList();
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 existMallList = mallService.lambdaQuery().eq(Mall::getAgentUid, agentUid).list();
var existMallList = mallService.list();
var uid2MallMap = existMallList.stream().collect(Collectors.toMap(Mall::getUid, Function.identity()));
List<MAccount> insAccList = new ArrayList<>();
......@@ -286,8 +286,8 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
List<Mall> updMallList = new ArrayList<>();
mallList.forEach(m -> {
if (uid2MallMap.containsKey(m.getUid())) {
var acc = uid2MallMap.get(m.getUid());
m.setId(acc.getId());
var mall = uid2MallMap.get(m.getUid());
m.setId(mall.getId());
updMallList.add(m);
} else {
m.setAgentUid(agentUid);
......@@ -295,10 +295,18 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
insMallList.add(m);
}
});
Opt.ofEmptyAble(insAccList).ifPresent(accountService::saveBatch);
Opt.ofEmptyAble(insMallList).ifPresent(mallService::saveBatch);
Opt.ofEmptyAble(updAccList).ifPresent(accountService::updateBatchById);
Opt.ofEmptyAble(updMallList).ifPresent(mallService::updateBatchById);
if (CollUtil.isNotEmpty(insAccList)) {
accountService.saveBatch(insAccList);
}
if (CollUtil.isNotEmpty(insMallList)) {
mallService.saveBatch(insMallList);
}
if (CollUtil.isNotEmpty(updAccList)) {
accountService.updateBatchById(updAccList);
}
if (CollUtil.isNotEmpty(updMallList)) {
mallService.updateBatchById(updMallList);
}
return "success";
}
......
......@@ -18,7 +18,6 @@ import vion.service.monitor.IEventRecordService;
import vion.service.monitor.IMallService;
import vion.vo.monitor.MallVO;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
......@@ -50,9 +49,9 @@ public class MallServiceImpl extends MPJBaseServiceImpl<MallMapper, Mall> implem
.in("mall_uid", mallUidList)
.orderByDesc("mall_uid", "create_time");
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;
}
......
package vion.service.impl.monitor;
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 vion.mapper.monitor.RAgentEventMapper;
import vion.model.monitor.RAgentEvent;
import vion.service.monitor.IRAgentEventService;
import vion.utils.JsonUtil;
import java.util.ArrayList;
import java.util.List;
......@@ -17,32 +22,42 @@ import java.util.stream.Collectors;
* @date 2024/10/31
*/
@Service
@RequiredArgsConstructor
public class RAgentEventServiceImpl extends MPJBaseServiceImpl<RAgentEventMapper, RAgentEvent> implements IRAgentEventService {
private final MqttClientTemplate client;
@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));
var agentEventList = this.lambdaQuery().eq(RAgentEvent::getAgentUid, agentUid).list();
var mallUid2AEMap = agentEventList.stream().collect(Collectors.toMap(RAgentEvent::getMallUid, Function.identity()));
var agentEventList = this.lambdaQuery().eq(RAgentEvent::getMallUid, mallUid).list();
var eventUid2AEMap = agentEventList.stream().collect(Collectors.toMap(RAgentEvent::getEventUid, Function.identity()));
List<RAgentEvent> updList = new ArrayList<>();
List<RAgentEvent> insList = new ArrayList<>();
dtoList.forEach(dto -> {
if (mallUid2AEMap.containsKey(dto.getMallUid())) {
var ae = mallUid2AEMap.get(dto.getMallUid());
if (eventUid2AEMap.containsKey(dto.getEventUid())) {
var ae = eventUid2AEMap.get(dto.getEventUid());
dto.setId(ae.getId());
updList.add(dto);
} else {
insList.add(dto);
}
});
Opt.ofEmptyAble(updList).ifPresent(this::updateBatchById);
Opt.ofEmptyAble(insList).ifPresent(this::saveBatch);
if (CollUtil.isNotEmpty(updList)) {
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 "绑定成功";
}
@Override
public String unbind(List<Long> idList) {
// todo
// client.publish(StrUtil.format("/SA/{}/event/push", agentUid), JsonUtil.toJsonByte(agentEvent), MqttQoS.QOS2);
return this.removeBatchByIds(idList) ? "解绑成功" : "解绑失败";
}
}
......@@ -11,7 +11,7 @@ import java.util.List;
*/
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);
......
......@@ -5,6 +5,7 @@ import lombok.Setter;
import vion.model.monitor.EventRecord;
import java.time.LocalDateTime;
import java.util.List;
/**
* 项目mall信息
......@@ -59,5 +60,5 @@ public class MallVO {
private LocalDateTime updateTime;
private EventRecord eventRecord;
private List<EventRecord> eventRecordList;
}
\ 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!