parent
9e3aea74b6
commit
ec6d8a742d
|
|
@ -41,6 +41,11 @@ spring:
|
|||
username: nacos
|
||||
password: u9Hc7tLFBY
|
||||
|
||||
fire:
|
||||
brigade:
|
||||
online-cache-ttl-seconds: 20
|
||||
online-cache-fail-ttl-seconds: 10
|
||||
|
||||
video:
|
||||
platform:
|
||||
hst:
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ spring:
|
|||
server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
namespace: ${spring.cloud.nacos.config.namespace}
|
||||
|
||||
fire:
|
||||
brigade:
|
||||
online-cache-ttl-seconds: 20
|
||||
online-cache-fail-ttl-seconds: 10
|
||||
|
||||
video:
|
||||
platform:
|
||||
hst:
|
||||
|
|
|
|||
|
|
@ -5,15 +5,19 @@ import com.alibaba.cola.dto.Response;
|
|||
import com.alibaba.cola.dto.SingleResponse;
|
||||
import com.zcloud.zcGbsServicer.api.FireBrigadeServiceI;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeAddCmd;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeOnlineStatusQry;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadePageQry;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeUpdateCmd;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeCO;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeOnlineStatusCO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Api(tags = "消防队伍")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
|
|
@ -28,6 +32,12 @@ public class FireBrigadeController {
|
|||
return fireBrigadeService.listPage(qry);
|
||||
}
|
||||
|
||||
@ApiOperation("批量刷新消防队伍在线状态缓存(供会议室等场景调用,可定时轮询)")
|
||||
@PostMapping("/online/status")
|
||||
public SingleResponse<List<FireBrigadeOnlineStatusCO>> onlineStatus(@RequestBody(required = false) FireBrigadeOnlineStatusQry qry) {
|
||||
return fireBrigadeService.queryOnlineStatus(qry == null ? new FireBrigadeOnlineStatusQry() : qry);
|
||||
}
|
||||
|
||||
@ApiOperation("新增")
|
||||
@PostMapping("/save")
|
||||
public SingleResponse<FireBrigadeCO> save(@Validated @RequestBody FireBrigadeAddCmd cmd) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberAddCmd;
|
|||
import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberPageQry;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberUpdateCmd;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeMemberCO;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeMemberStatusCO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
|
@ -22,6 +23,12 @@ public class FireBrigadeMemberController {
|
|||
|
||||
private final FireBrigadeMemberServiceI fireBrigadeMemberService;
|
||||
|
||||
@ApiOperation("查询当前登录用户是否为消防队成员")
|
||||
@GetMapping("/current/status")
|
||||
public SingleResponse<FireBrigadeMemberStatusCO> currentMemberStatus() {
|
||||
return fireBrigadeMemberService.currentMemberStatus();
|
||||
}
|
||||
|
||||
@ApiOperation("分页查询")
|
||||
@PostMapping("/list")
|
||||
public PageResponse<FireBrigadeMemberCO> list(@RequestBody FireBrigadeMemberPageQry qry) {
|
||||
|
|
|
|||
|
|
@ -12,9 +12,15 @@ public interface FireBrigadeMemberCoConvertor {
|
|||
|
||||
@Mapping(target = "fireBrigadeId", ignore = true)
|
||||
@Mapping(source = "fireBrigadeId", target = "fireBrigadeBizId")
|
||||
@Mapping(source = "userName", target = "name")
|
||||
@Mapping(source = "dutyName", target = "duty")
|
||||
@Mapping(source = "orgName", target = "org")
|
||||
List<FireBrigadeMemberCO> converDOsToCOs(List<FireBrigadeUserDO> fireBrigadeUserDOs);
|
||||
|
||||
@Mapping(target = "fireBrigadeId", ignore = true)
|
||||
@Mapping(source = "fireBrigadeId", target = "fireBrigadeBizId")
|
||||
@Mapping(source = "userName", target = "name")
|
||||
@Mapping(source = "dutyName", target = "duty")
|
||||
@Mapping(source = "orgName", target = "org")
|
||||
FireBrigadeMemberCO converDOToCO(FireBrigadeUserDO fireBrigadeUserDO);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.zcloud.zcGbsServicer.service;
|
|||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.cola.dto.PageResponse;
|
||||
import com.alibaba.cola.dto.SingleResponse;
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
|
|
@ -78,7 +79,7 @@ public class AlarmRecordServiceImpl extends FireAlarmServiceSupport implements A
|
|||
record.setId(nextId());
|
||||
record.setFireAlarmInfoId(nextBizId());
|
||||
fillCreateAudit(record);
|
||||
record.setAlarmMode(ALARM_MODE_PHONE);
|
||||
record.setAlarmMode(resolveAlarmMode(cmd.getAlarmMode()));
|
||||
record.setAlarmUserId(cmd.getAlarmUserId());
|
||||
record.setAlarmUserName(cmd.getReporter());
|
||||
record.setAlarmPhone(cmd.getAlarmPhone());
|
||||
|
|
@ -138,6 +139,7 @@ public class AlarmRecordServiceImpl extends FireAlarmServiceSupport implements A
|
|||
throw new BizException("仅当前处置消防队成员可消警");
|
||||
}
|
||||
record.setClearReason(cmd.getDesc().trim());
|
||||
record.setClearPhotos(toPhotoJson(cmd.getPhotos()));
|
||||
record.setClearId(currentUserId());
|
||||
record.setClearName(currentUserName());
|
||||
record.setClearTime(LocalDateTime.now());
|
||||
|
|
@ -186,10 +188,39 @@ public class AlarmRecordServiceImpl extends FireAlarmServiceSupport implements A
|
|||
co.setClearId(record.getClearId());
|
||||
co.setClearName(record.getClearName());
|
||||
co.setClearTime(formatTime(record.getClearTime()));
|
||||
co.setPhotos(Collections.emptyList());
|
||||
co.setPhotos(parsePhotos(record.getClearPhotos()));
|
||||
return co;
|
||||
}
|
||||
|
||||
private String toPhotoJson(List<String> photos) {
|
||||
if (photos == null || photos.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
List<String> paths = photos.stream()
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toList());
|
||||
return paths.isEmpty() ? null : JSONUtil.toJsonStr(paths);
|
||||
}
|
||||
|
||||
private List<String> parsePhotos(String clearPhotos) {
|
||||
if (StrUtil.isBlank(clearPhotos)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return JSONUtil.toList(clearPhotos, String.class);
|
||||
}
|
||||
|
||||
private Integer resolveAlarmMode(Integer alarmMode) {
|
||||
if (alarmMode == null) {
|
||||
return ALARM_MODE_PHONE;
|
||||
}
|
||||
if (!Integer.valueOf(ALARM_MODE_PHONE).equals(alarmMode)
|
||||
&& !Integer.valueOf(ALARM_MODE_APP).equals(alarmMode)) {
|
||||
throw new BizException("接报方式无效");
|
||||
}
|
||||
return alarmMode;
|
||||
}
|
||||
|
||||
private Integer parseStatus(String status) {
|
||||
if (StrUtil.isBlank(status)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ public class FireAlarmMeetingUserServiceImpl extends FireAlarmServiceSupport imp
|
|||
private final FireAlarmMeetingUserRepository fireAlarmMeetingUserRepository;
|
||||
private final FireBrigadeRepository fireBrigadeRepository;
|
||||
private final FireAlarmMeetingUserCoConvertor fireAlarmMeetingUserCoConvertor;
|
||||
private final FireAlarmUserResolver fireAlarmUserResolver;
|
||||
|
||||
@Override
|
||||
public PageResponse<FireAlarmMeetingUserCO> listPage(FireAlarmMeetingUserPageQry qry) {
|
||||
|
|
@ -49,13 +50,15 @@ public class FireAlarmMeetingUserServiceImpl extends FireAlarmServiceSupport imp
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SingleResponse<FireAlarmMeetingUserCO> add(FireAlarmMeetingUserAddCmd cmd) {
|
||||
if (fireAlarmMeetingUserRepository.existsByLocalUserId(cmd.getLocalUserId(), null)) {
|
||||
Long userTenantId = fireAlarmUserResolver.resolveUserTenantId(cmd.getLocalUserId());
|
||||
if (fireAlarmMeetingUserRepository.existsByLocalUserId(cmd.getLocalUserId(), userTenantId, null)) {
|
||||
throw new BizException("会议用户已存在");
|
||||
}
|
||||
FireAlarmMeetingUserDO user = new FireAlarmMeetingUserDO();
|
||||
user.setId(nextId());
|
||||
user.setFireAlarmMeetingUserId(nextBizId());
|
||||
fillCreateAudit(user);
|
||||
fireAlarmUserResolver.applyLocalUserTenant(user, cmd.getLocalUserId());
|
||||
fillMeetingUser(user, cmd);
|
||||
fireAlarmMeetingUserRepository.save(user);
|
||||
return SingleResponse.of(fireAlarmMeetingUserCoConvertor.converDOToCO(user));
|
||||
|
|
@ -68,10 +71,12 @@ public class FireAlarmMeetingUserServiceImpl extends FireAlarmServiceSupport imp
|
|||
if (user == null) {
|
||||
throw new BizException("会议用户不存在");
|
||||
}
|
||||
if (fireAlarmMeetingUserRepository.existsByLocalUserId(cmd.getLocalUserId(), cmd.getId())) {
|
||||
if (fireAlarmMeetingUserRepository.existsByLocalUserId(cmd.getLocalUserId(),
|
||||
fireAlarmUserResolver.resolveUserTenantId(cmd.getLocalUserId()), cmd.getId())) {
|
||||
throw new BizException("会议用户已存在");
|
||||
}
|
||||
fillUpdateAudit(user);
|
||||
fireAlarmUserResolver.applyLocalUserTenant(user, cmd.getLocalUserId());
|
||||
fillMeetingUser(user, cmd);
|
||||
fireAlarmMeetingUserRepository.updateById(user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package com.zcloud.zcGbsServicer.service;
|
||||
|
||||
import com.alibaba.cola.dto.MultiResponse;
|
||||
import com.jjb.saas.framework.repository.basedo.BaseDO;
|
||||
import com.zcloud.gbscommon.zclouduser.facade.ZcloudUserFacade;
|
||||
import com.zcloud.gbscommon.zclouduser.response.ZcloudUserCo;
|
||||
import com.zcloud.zcGbsServicer.persistence.repository.AlarmUserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -12,11 +15,14 @@ import java.util.LinkedHashMap;
|
|||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class FireAlarmUserResolver {
|
||||
|
||||
@DubboReference(check = false)
|
||||
private ZcloudUserFacade zcloudUserFacade;
|
||||
|
||||
private final AlarmUserRepository alarmUserRepository;
|
||||
|
||||
public Map<Long, ZcloudUserCo> getUserMap(Collection<Long> userIds) {
|
||||
if (userIds == null || userIds.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
|
|
@ -39,4 +45,20 @@ public class FireAlarmUserResolver {
|
|||
}
|
||||
return userMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 alarm 库 user 视图查询用户所属 tenant_id。
|
||||
*/
|
||||
public Long resolveUserTenantId(Long userId) {
|
||||
return alarmUserRepository.getTenantIdByUserId(userId);
|
||||
}
|
||||
|
||||
public void applyLocalUserTenant(BaseDO dataObject, Long localUserId) {
|
||||
Long tenantId = resolveUserTenantId(localUserId);
|
||||
if (tenantId == null) {
|
||||
return;
|
||||
}
|
||||
dataObject.setTenantId(tenantId);
|
||||
dataObject.setOrgId(tenantId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberAddCmd;
|
|||
import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberPageQry;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberUpdateCmd;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeMemberCO;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeMemberStatusCO;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireAlarmMeetingRoomDO;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireAlarmMeetingUserDO;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireBrigadeDO;
|
||||
|
|
@ -47,6 +48,20 @@ public class FireBrigadeMemberServiceImpl extends FireAlarmServiceSupport implem
|
|||
private final FireAlarmUserResolver fireAlarmUserResolver;
|
||||
private final FireBrigadeMemberCoConvertor fireBrigadeMemberCoConvertor;
|
||||
|
||||
@Override
|
||||
public SingleResponse<FireBrigadeMemberStatusCO> currentMemberStatus() {
|
||||
Long userId = currentUserId();
|
||||
FireBrigadeMemberStatusCO co = new FireBrigadeMemberStatusCO();
|
||||
co.setUserId(userId);
|
||||
if (userId == null) {
|
||||
co.setFireBrigadeMember(false);
|
||||
return SingleResponse.of(co);
|
||||
}
|
||||
List<FireBrigadeUserDO> relations = fireBrigadeUserRepository.listByUserId(userId);
|
||||
co.setFireBrigadeMember(relations != null && !relations.isEmpty());
|
||||
return SingleResponse.of(co);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResponse<FireBrigadeMemberCO> listPage(FireBrigadeMemberPageQry qry) {
|
||||
FireBrigadeDO brigade = getBrigade(qry.getFireBrigadeId());
|
||||
|
|
@ -55,7 +70,7 @@ public class FireBrigadeMemberServiceImpl extends FireAlarmServiceSupport implem
|
|||
List<FireBrigadeMemberCO> data = relations
|
||||
.stream()
|
||||
.map(item -> buildCO(item, brigade, userMap))
|
||||
.filter(item -> StrUtil.isBlank(qry.getName()) || StrUtil.containsIgnoreCase(item.getUserName(), qry.getName().trim()))
|
||||
.filter(item -> StrUtil.isBlank(qry.getName()) || StrUtil.containsIgnoreCase(item.getName(), qry.getName().trim()))
|
||||
.collect(Collectors.toList());
|
||||
int pageSize = qry.getPageSize() <= 0 ? data.size() : qry.getPageSize();
|
||||
int pageIndex = qry.getPageIndex() <= 0 ? 1 : qry.getPageIndex();
|
||||
|
|
@ -75,6 +90,7 @@ public class FireBrigadeMemberServiceImpl extends FireAlarmServiceSupport implem
|
|||
if (fireBrigadeUserRepository.existsRelation(brigade.getFireBrigadeId(), userId, null)) {
|
||||
throw new BizException("消防队员已存在");
|
||||
}
|
||||
prepareMemberRelation(userId, brigade.getFireBrigadeId(), null);
|
||||
FireBrigadeUserDO relation = new FireBrigadeUserDO();
|
||||
relation.setId(nextId());
|
||||
relation.setFireBrigadeUserId(nextBizId());
|
||||
|
|
@ -102,11 +118,13 @@ public class FireBrigadeMemberServiceImpl extends FireAlarmServiceSupport implem
|
|||
if (fireBrigadeUserRepository.existsRelation(brigade.getFireBrigadeId(), userId, relation.getId())) {
|
||||
throw new BizException("消防队员已存在");
|
||||
}
|
||||
prepareMemberRelation(userId, brigade.getFireBrigadeId(), relation.getId());
|
||||
relation.setFireBrigadeId(brigade.getFireBrigadeId());
|
||||
relation.setUserId(userId);
|
||||
fillMemberSnapshot(relation, cmd);
|
||||
fillUpdateAudit(relation);
|
||||
fireBrigadeUserRepository.updateById(relation);
|
||||
syncCreateMeetingUser(relation, brigade);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -179,11 +197,12 @@ public class FireBrigadeMemberServiceImpl extends FireAlarmServiceSupport implem
|
|||
co.setUserId(relation.getUserId() == null ? null : String.valueOf(relation.getUserId()));
|
||||
co.setDutyId(relation.getDutyId());
|
||||
co.setCorpId(relation.getCorpId());
|
||||
co.setUserName(selectText(user == null ? null : user.getName(), co.getUserName()));
|
||||
co.setIdNo(selectText(user == null ? null : user.getUserIdCard(), co.getIdNo()));
|
||||
co.setPhone(selectText(user == null ? null : user.getPhone(), co.getPhone()));
|
||||
co.setDutyName(selectText(user == null ? null : user.getPostName(), co.getDutyName()));
|
||||
co.setOrgName(selectText(user == null ? null : user.getDepartmentName(), co.getOrgName()));
|
||||
co.setGender(relation.getGender());
|
||||
co.setName(selectText(relation.getUserName(), user == null ? null : user.getName()));
|
||||
co.setIdNo(selectText(relation.getIdNo(), user == null ? null : user.getUserIdCard()));
|
||||
co.setPhone(selectText(relation.getPhone(), user == null ? null : user.getPhone()));
|
||||
co.setDuty(selectText(relation.getDutyName(), user == null ? null : user.getPostName()));
|
||||
co.setOrg(selectText(relation.getOrgName(), user == null ? null : user.getDepartmentName()));
|
||||
if (brigade.getLeaderUserId() != null && brigade.getLeaderUserId().equals(relation.getUserId())) {
|
||||
co.setRoleCode(1);
|
||||
}
|
||||
|
|
@ -201,6 +220,24 @@ public class FireBrigadeMemberServiceImpl extends FireAlarmServiceSupport implem
|
|||
relation.setOrgName(cmd.getOrg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户换队时软删除其他队伍的有效成员关系。
|
||||
*/
|
||||
private void prepareMemberRelation(Long userId, String targetFireBrigadeId, Long currentRelationId) {
|
||||
List<FireBrigadeUserDO> activeRelations = fireBrigadeUserRepository.listByUserId(userId);
|
||||
if (activeRelations == null) {
|
||||
return;
|
||||
}
|
||||
for (FireBrigadeUserDO rel : activeRelations) {
|
||||
if (currentRelationId != null && currentRelationId.equals(rel.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (!targetFireBrigadeId.equals(rel.getFireBrigadeId())) {
|
||||
fireBrigadeUserRepository.removeById(rel.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void syncCreateMeetingUser(FireBrigadeUserDO relation, FireBrigadeDO brigade) {
|
||||
if (StrUtil.isBlank(hstVideoPlatformProperties.getDefaultUserPassword())) {
|
||||
throw new BizException("视频平台默认用户密码未配置,不能创建消防会议账号");
|
||||
|
|
@ -237,7 +274,8 @@ public class FireBrigadeMemberServiceImpl extends FireAlarmServiceSupport implem
|
|||
|
||||
private void upsertMeetingUserMapping(FireBrigadeUserDO relation, FireBrigadeDO brigade,
|
||||
String thirdUserName, Map<String, Object> data, String syncMsg) {
|
||||
FireAlarmMeetingUserDO meetingUser = fireAlarmMeetingUserRepository.getByLocalUserId(relation.getUserId());
|
||||
Long userTenantId = fireAlarmUserResolver.resolveUserTenantId(relation.getUserId());
|
||||
FireAlarmMeetingUserDO meetingUser = fireAlarmMeetingUserRepository.getByLocalUserId(relation.getUserId(), userTenantId);
|
||||
boolean isNew = meetingUser == null;
|
||||
if (meetingUser == null) {
|
||||
meetingUser = new FireAlarmMeetingUserDO();
|
||||
|
|
@ -248,6 +286,7 @@ public class FireBrigadeMemberServiceImpl extends FireAlarmServiceSupport implem
|
|||
else {
|
||||
fillUpdateAudit(meetingUser);
|
||||
}
|
||||
fireAlarmUserResolver.applyLocalUserTenant(meetingUser, relation.getUserId());
|
||||
|
||||
FireAlarmMeetingRoomDO room = fireAlarmMeetingRoomRepository.getByRoomCode(hstVideoPlatformProperties.getDefaultRoomCode());
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
|
@ -306,7 +345,8 @@ public class FireBrigadeMemberServiceImpl extends FireAlarmServiceSupport implem
|
|||
if (activeRelations != null && !activeRelations.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
FireAlarmMeetingUserDO meetingUser = fireAlarmMeetingUserRepository.getByLocalUserId(relation.getUserId());
|
||||
FireAlarmMeetingUserDO meetingUser = fireAlarmMeetingUserRepository.getByLocalUserId(relation.getUserId(),
|
||||
fireAlarmUserResolver.resolveUserTenantId(relation.getUserId()));
|
||||
if (meetingUser == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -333,7 +373,8 @@ public class FireBrigadeMemberServiceImpl extends FireAlarmServiceSupport implem
|
|||
}
|
||||
|
||||
private String resolveThirdUserName(Long localUserId) {
|
||||
FireAlarmMeetingUserDO meetingUser = fireAlarmMeetingUserRepository.getByLocalUserId(localUserId);
|
||||
FireAlarmMeetingUserDO meetingUser = fireAlarmMeetingUserRepository.getByLocalUserId(localUserId,
|
||||
fireAlarmUserResolver.resolveUserTenantId(localUserId));
|
||||
if (meetingUser != null && StrUtil.isNotBlank(meetingUser.getThirdUserName())) {
|
||||
return meetingUser.getThirdUserName().trim();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.zcloud.zcGbsServicer.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.jjb.saas.framework.auth.utils.AuthContext;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireAlarmMeetingUserDO;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireBrigadeDO;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireBrigadeUserDO;
|
||||
|
|
@ -8,14 +9,19 @@ import com.zcloud.zcGbsServicer.persistence.repository.FireAlarmMeetingUserRepos
|
|||
import com.zcloud.zcGbsServicer.persistence.repository.FireBrigadeUserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
|
|
@ -24,29 +30,105 @@ import java.util.stream.Collectors;
|
|||
public class FireBrigadeOnlineStatusService {
|
||||
|
||||
private static final int USER_ONLINE_IN_MEETING = 1;
|
||||
private static final long REFRESH_DEBOUNCE_MS = 5000L;
|
||||
|
||||
private final FireBrigadeUserRepository fireBrigadeUserRepository;
|
||||
private final FireAlarmMeetingUserRepository fireAlarmMeetingUserRepository;
|
||||
private final HstVideoPlatformClient hstVideoPlatformClient;
|
||||
|
||||
public Map<String, Boolean> calculateOnlineMap(List<FireBrigadeDO> brigades) {
|
||||
private final ConcurrentHashMap<String, OnlineCacheEntry> onlineCache = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, Long> refreshGuard = new ConcurrentHashMap<>();
|
||||
|
||||
@Value("${fire.brigade.online-cache-ttl-seconds:20}")
|
||||
private long onlineCacheTtlSeconds;
|
||||
|
||||
@Value("${fire.brigade.online-cache-fail-ttl-seconds:10}")
|
||||
private long onlineCacheFailTtlSeconds;
|
||||
|
||||
/**
|
||||
* 列表展示用:优先读有效缓存,其次读过期缓存,最后默认未在线;不调用第三方。
|
||||
*/
|
||||
public Map<String, Boolean> getOnlineMapForList(Collection<String> brigadeBizIds, Long tenantId) {
|
||||
if (brigadeBizIds == null || brigadeBizIds.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, Boolean> result = new LinkedHashMap<>();
|
||||
for (String brigadeBizId : brigadeBizIds) {
|
||||
if (StrUtil.isBlank(brigadeBizId)) {
|
||||
continue;
|
||||
}
|
||||
String normalizedId = brigadeBizId.trim();
|
||||
OnlineCacheEntry cacheEntry = onlineCache.get(buildCacheKey(normalizedId, tenantId));
|
||||
result.put(normalizedId, cacheEntry == null ? Boolean.FALSE : cacheEntry.online);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表请求后异步刷新缓存,不阻塞接口响应。
|
||||
*/
|
||||
public void scheduleRefreshOnlineMap(List<FireBrigadeDO> brigades) {
|
||||
if (brigades == null || brigades.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Long tenantId = resolveTenantId(brigades);
|
||||
if (isCacheValidForAll(brigades, tenantId)) {
|
||||
return;
|
||||
}
|
||||
List<FireBrigadeDO> snapshot = new ArrayList<>(brigades);
|
||||
String refreshKey = buildRefreshKey(snapshot, tenantId);
|
||||
long now = System.currentTimeMillis();
|
||||
Long lastRefreshAt = refreshGuard.get(refreshKey);
|
||||
if (lastRefreshAt != null && now - lastRefreshAt < REFRESH_DEBOUNCE_MS) {
|
||||
return;
|
||||
}
|
||||
refreshGuard.put(refreshKey, now);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
refreshOnlineMap(snapshot);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
log.warn("异步刷新消防队伍在线状态失败", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步调用第三方刷新在线状态并写入缓存。
|
||||
*/
|
||||
public Map<String, Boolean> refreshOnlineMap(List<FireBrigadeDO> brigades) {
|
||||
if (brigades == null || brigades.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Set<String> brigadeBizIds = brigades.stream()
|
||||
.map(FireBrigadeDO::getFireBrigadeId)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
if (brigadeBizIds.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
List<FireBrigadeUserDO> allBrigadeUsers = fireBrigadeUserRepository.listAll();
|
||||
Map<String, List<FireBrigadeUserDO>> brigadeUserMap = allBrigadeUsers.stream()
|
||||
.filter(item -> item != null && brigadeBizIds.contains(item.getFireBrigadeId()))
|
||||
Long tenantId = resolveTenantId(brigades);
|
||||
long now = System.currentTimeMillis();
|
||||
OnlineComputeResult computeResult = computeOnlineMap(brigadeBizIds, tenantId);
|
||||
long ttlMs = computeResult.degraded
|
||||
? onlineCacheFailTtlSeconds * 1000L
|
||||
: onlineCacheTtlSeconds * 1000L;
|
||||
long expireAt = now + ttlMs;
|
||||
for (Map.Entry<String, Boolean> entry : computeResult.onlineMap.entrySet()) {
|
||||
onlineCache.put(buildCacheKey(entry.getKey(), tenantId), new OnlineCacheEntry(entry.getValue(), expireAt));
|
||||
}
|
||||
return computeResult.onlineMap;
|
||||
}
|
||||
|
||||
private OnlineComputeResult computeOnlineMap(Set<String> brigadeBizIds, Long tenantId) {
|
||||
List<FireBrigadeUserDO> brigadeUsers = fireBrigadeUserRepository.listByFireBrigadeIds(brigadeBizIds, tenantId);
|
||||
Map<String, List<FireBrigadeUserDO>> brigadeUserMap = brigadeUsers.stream()
|
||||
.filter(item -> item != null && StrUtil.isNotBlank(item.getFireBrigadeId()))
|
||||
.collect(Collectors.groupingBy(FireBrigadeUserDO::getFireBrigadeId, LinkedHashMap::new, Collectors.toList()));
|
||||
if (brigadeUserMap.isEmpty()) {
|
||||
return buildOfflineMap(brigadeBizIds);
|
||||
return new OnlineComputeResult(buildOfflineMap(brigadeBizIds), false);
|
||||
}
|
||||
|
||||
Set<Long> localUserIds = brigadeUserMap.values().stream()
|
||||
|
|
@ -55,47 +137,46 @@ public class FireBrigadeOnlineStatusService {
|
|||
.filter(java.util.Objects::nonNull)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
if (localUserIds.isEmpty()) {
|
||||
return buildOfflineMap(brigadeBizIds);
|
||||
return new OnlineComputeResult(buildOfflineMap(brigadeBizIds), false);
|
||||
}
|
||||
|
||||
Map<Long, String> meetingAccountMap = fireAlarmMeetingUserRepository.listAll().stream()
|
||||
Map<Long, String> meetingAccountMap = fireAlarmMeetingUserRepository.listByLocalUserIds(localUserIds, tenantId).stream()
|
||||
.filter(item -> item != null && item.getLocalUserId() != null)
|
||||
.filter(item -> localUserIds.contains(item.getLocalUserId()))
|
||||
.filter(item -> StrUtil.isNotBlank(item.getThirdUserName()))
|
||||
.collect(Collectors.toMap(FireAlarmMeetingUserDO::getLocalUserId,
|
||||
item -> item.getThirdUserName().trim(),
|
||||
(left, right) -> left,
|
||||
LinkedHashMap::new));
|
||||
if (meetingAccountMap.isEmpty()) {
|
||||
return buildOfflineMap(brigadeBizIds);
|
||||
return new OnlineComputeResult(buildOfflineMap(brigadeBizIds), false);
|
||||
}
|
||||
|
||||
Set<String> onlineMeetingAccounts = queryOnlineMeetingAccounts(new LinkedHashSet<>(meetingAccountMap.values()));
|
||||
OnlineQueryResult queryResult = queryOnlineMeetingAccounts(new LinkedHashSet<>(meetingAccountMap.values()));
|
||||
Map<String, Boolean> result = buildOfflineMap(brigadeBizIds);
|
||||
if (onlineMeetingAccounts.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!queryResult.onlineMeetingAccounts.isEmpty()) {
|
||||
for (Map.Entry<String, List<FireBrigadeUserDO>> entry : brigadeUserMap.entrySet()) {
|
||||
boolean online = entry.getValue().stream()
|
||||
.map(FireBrigadeUserDO::getUserId)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.map(meetingAccountMap::get)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.anyMatch(onlineMeetingAccounts::contains);
|
||||
.anyMatch(queryResult.onlineMeetingAccounts::contains);
|
||||
result.put(entry.getKey(), online);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return new OnlineComputeResult(result, queryResult.degraded);
|
||||
}
|
||||
|
||||
private Set<String> queryOnlineMeetingAccounts(Set<String> meetingAccounts) {
|
||||
private OnlineQueryResult queryOnlineMeetingAccounts(Set<String> meetingAccounts) {
|
||||
if (meetingAccounts == null || meetingAccounts.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
return new OnlineQueryResult(Collections.emptySet(), false);
|
||||
}
|
||||
Set<String> result = new LinkedHashSet<>();
|
||||
boolean authInvalid = false;
|
||||
boolean degraded = false;
|
||||
for (String meetingAccount : meetingAccounts) {
|
||||
if (authInvalid) {
|
||||
degraded = true;
|
||||
break;
|
||||
}
|
||||
try {
|
||||
|
|
@ -105,6 +186,7 @@ public class FireBrigadeOnlineStatusService {
|
|||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
degraded = true;
|
||||
if (isInvalidAuth(ex)) {
|
||||
authInvalid = true;
|
||||
log.warn("查询视频平台用户在线状态失败,视频平台 HTTP API 鉴权无效,请检查 key/secret 是否为后台 HTTP API 分配的凭证,当前账号={}",
|
||||
|
|
@ -114,7 +196,46 @@ public class FireBrigadeOnlineStatusService {
|
|||
log.warn("查询视频平台用户在线状态失败,userName={}", meetingAccount, ex);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return new OnlineQueryResult(result, degraded);
|
||||
}
|
||||
|
||||
private Long resolveTenantId(List<FireBrigadeDO> brigades) {
|
||||
if (brigades != null) {
|
||||
for (FireBrigadeDO brigade : brigades) {
|
||||
if (brigade != null && brigade.getTenantId() != null) {
|
||||
return brigade.getTenantId();
|
||||
}
|
||||
}
|
||||
}
|
||||
return AuthContext.getTenantId();
|
||||
}
|
||||
|
||||
private boolean isCacheValidForAll(List<FireBrigadeDO> brigades, Long tenantId) {
|
||||
long now = System.currentTimeMillis();
|
||||
for (FireBrigadeDO brigade : brigades) {
|
||||
if (brigade == null || StrUtil.isBlank(brigade.getFireBrigadeId())) {
|
||||
continue;
|
||||
}
|
||||
OnlineCacheEntry cacheEntry = onlineCache.get(buildCacheKey(brigade.getFireBrigadeId().trim(), tenantId));
|
||||
if (cacheEntry == null || cacheEntry.expireAt <= now) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String buildCacheKey(String brigadeBizId, Long tenantId) {
|
||||
return (tenantId == null ? "0" : tenantId) + ":" + brigadeBizId;
|
||||
}
|
||||
|
||||
private String buildRefreshKey(List<FireBrigadeDO> brigades, Long tenantId) {
|
||||
String ids = brigades.stream()
|
||||
.map(FireBrigadeDO::getFireBrigadeId)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.map(String::trim)
|
||||
.sorted()
|
||||
.collect(Collectors.joining(","));
|
||||
return (tenantId == null ? "0" : tenantId) + ":" + ids;
|
||||
}
|
||||
|
||||
private boolean isInvalidAuth(Exception ex) {
|
||||
|
|
@ -172,4 +293,34 @@ public class FireBrigadeOnlineStatusService {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final class OnlineCacheEntry {
|
||||
private final boolean online;
|
||||
private final long expireAt;
|
||||
|
||||
private OnlineCacheEntry(boolean online, long expireAt) {
|
||||
this.online = online;
|
||||
this.expireAt = expireAt;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class OnlineComputeResult {
|
||||
private final Map<String, Boolean> onlineMap;
|
||||
private final boolean degraded;
|
||||
|
||||
private OnlineComputeResult(Map<String, Boolean> onlineMap, boolean degraded) {
|
||||
this.onlineMap = onlineMap;
|
||||
this.degraded = degraded;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class OnlineQueryResult {
|
||||
private final Set<String> onlineMeetingAccounts;
|
||||
private final boolean degraded;
|
||||
|
||||
private OnlineQueryResult(Set<String> onlineMeetingAccounts, boolean degraded) {
|
||||
this.onlineMeetingAccounts = onlineMeetingAccounts;
|
||||
this.degraded = degraded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,11 @@ import com.zcloud.gbscommon.zclouduser.response.ZcloudUserCo;
|
|||
import com.zcloud.zcGbsServicer.api.FireBrigadeServiceI;
|
||||
import com.zcloud.zcGbsServicer.command.convertor.FireBrigadeCoConvertor;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeAddCmd;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeOnlineStatusQry;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadePageQry;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeUpdateCmd;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeCO;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeOnlineStatusCO;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireBrigadeDO;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireBrigadeUserDO;
|
||||
import com.zcloud.zcGbsServicer.persistence.repository.FireBrigadeRepository;
|
||||
|
|
@ -20,8 +22,10 @@ import lombok.RequiredArgsConstructor;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
|
@ -46,13 +50,46 @@ public class FireBrigadeServiceImpl extends FireAlarmServiceSupport implements F
|
|||
params.put("brigadeName", qry.getName());
|
||||
PageResponse<FireBrigadeDO> page = fireBrigadeRepository.listPage(params);
|
||||
Map<Long, ZcloudUserCo> userMap = getLeaderUserMap(page.getData());
|
||||
Map<String, Boolean> onlineMap = fireBrigadeOnlineStatusService.calculateOnlineMap(page.getData());
|
||||
List<FireBrigadeCO> data = page.getData().stream()
|
||||
.map(item -> buildCO(item, userMap, onlineMap))
|
||||
List<String> brigadeBizIds = page.getData().stream()
|
||||
.map(FireBrigadeDO::getFireBrigadeId)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.toList());
|
||||
Map<String, Integer> memberCountMap = fireBrigadeUserRepository.countByFireBrigadeIds(brigadeBizIds);
|
||||
Map<String, Boolean> onlineMap = fireBrigadeOnlineStatusService.getOnlineMapForList(brigadeBizIds, currentTenantId());
|
||||
List<FireBrigadeCO> data = page.getData().stream()
|
||||
.map(item -> buildCO(item, userMap, onlineMap, memberCountMap))
|
||||
.collect(Collectors.toList());
|
||||
fireBrigadeOnlineStatusService.scheduleRefreshOnlineMap(page.getData());
|
||||
return PageResponse.of(data, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleResponse<List<FireBrigadeOnlineStatusCO>> queryOnlineStatus(FireBrigadeOnlineStatusQry qry) {
|
||||
List<String> fireBrigadeIds = qry == null || qry.getFireBrigadeIds() == null
|
||||
? Collections.emptyList()
|
||||
: new ArrayList<>(qry.getFireBrigadeIds().stream()
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new)));
|
||||
if (fireBrigadeIds.isEmpty()) {
|
||||
return SingleResponse.of(Collections.emptyList());
|
||||
}
|
||||
|
||||
List<FireBrigadeDO> brigades = fireBrigadeRepository.listByFireBrigadeIds(fireBrigadeIds);
|
||||
Map<String, Boolean> onlineMap = fireBrigadeOnlineStatusService.refreshOnlineMap(brigades);
|
||||
List<FireBrigadeOnlineStatusCO> data = fireBrigadeIds.stream()
|
||||
.map(fireBrigadeId -> {
|
||||
FireBrigadeOnlineStatusCO co = new FireBrigadeOnlineStatusCO();
|
||||
co.setFireBrigadeId(fireBrigadeId);
|
||||
boolean online = Boolean.TRUE.equals(onlineMap.get(fireBrigadeId));
|
||||
co.setOnline(online);
|
||||
co.setOnlineText(online ? "在线" : "未在线");
|
||||
return co;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return SingleResponse.of(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SingleResponse<FireBrigadeCO> add(FireBrigadeAddCmd cmd) {
|
||||
|
|
@ -68,10 +105,11 @@ public class FireBrigadeServiceImpl extends FireAlarmServiceSupport implements F
|
|||
fillCreateAudit(brigade);
|
||||
fillBrigade(brigade, cmd);
|
||||
fireBrigadeRepository.save(brigade);
|
||||
ensureLeaderRelation(brigade);
|
||||
// ensureLeaderRelation(brigade); // 新增队伍时不再自动创建负责人成员记录,后续单独维护
|
||||
return SingleResponse.of(buildCO(brigade,
|
||||
getLeaderUserMap(Collections.singletonList(brigade)),
|
||||
fireBrigadeOnlineStatusService.calculateOnlineMap(Collections.singletonList(brigade))));
|
||||
fireBrigadeOnlineStatusService.refreshOnlineMap(Collections.singletonList(brigade)),
|
||||
fireBrigadeUserRepository.countByFireBrigadeIds(Collections.singletonList(brigade.getFireBrigadeId()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -90,7 +128,7 @@ public class FireBrigadeServiceImpl extends FireAlarmServiceSupport implements F
|
|||
fillUpdateAudit(brigade);
|
||||
fillBrigade(brigade, cmd);
|
||||
fireBrigadeRepository.updateById(brigade);
|
||||
ensureLeaderRelation(brigade);
|
||||
// ensureLeaderRelation(brigade); // 编辑队伍时不再自动维护负责人成员记录,后续单独维护
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -101,7 +139,8 @@ public class FireBrigadeServiceImpl extends FireAlarmServiceSupport implements F
|
|||
}
|
||||
return buildCO(brigade,
|
||||
getLeaderUserMap(Collections.singletonList(brigade)),
|
||||
fireBrigadeOnlineStatusService.calculateOnlineMap(Collections.singletonList(brigade)));
|
||||
fireBrigadeOnlineStatusService.refreshOnlineMap(Collections.singletonList(brigade)),
|
||||
fireBrigadeUserRepository.countByFireBrigadeIds(Collections.singletonList(brigade.getFireBrigadeId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -166,13 +205,13 @@ public class FireBrigadeServiceImpl extends FireAlarmServiceSupport implements F
|
|||
}
|
||||
|
||||
private FireBrigadeCO buildCO(FireBrigadeDO brigade, Map<Long, ZcloudUserCo> userMap,
|
||||
Map<String, Boolean> onlineMap) {
|
||||
Map<String, Boolean> onlineMap, Map<String, Integer> memberCountMap) {
|
||||
FireBrigadeCO co = fireBrigadeCoConvertor.converDOToCO(brigade);
|
||||
ZcloudUserCo leader = brigade.getLeaderUserId() == null ? null : userMap.get(brigade.getLeaderUserId());
|
||||
co.setLeaderDeptName(selectText(leader == null ? null : leader.getDepartmentName(), co.getLeaderDeptName()));
|
||||
co.setLeaderName(selectText(leader == null ? null : leader.getName(), co.getLeaderName()));
|
||||
co.setLeaderPhone(selectText(leader == null ? null : leader.getPhone(), co.getLeaderPhone()));
|
||||
co.setMemberCount(fireBrigadeUserRepository.listByFireBrigadeId(brigade.getFireBrigadeId()).size());
|
||||
co.setMemberCount(memberCountMap == null ? 0 : memberCountMap.getOrDefault(brigade.getFireBrigadeId(), 0));
|
||||
boolean online = onlineMap != null && Boolean.TRUE.equals(onlineMap.get(brigade.getFireBrigadeId()));
|
||||
co.setOnline(online);
|
||||
co.setOnlineText(online ? "在线" : "未在线");
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberAddCmd;
|
|||
import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberPageQry;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberUpdateCmd;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeMemberCO;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeMemberStatusCO;
|
||||
|
||||
public interface FireBrigadeMemberServiceI {
|
||||
|
||||
|
|
@ -20,4 +21,6 @@ public interface FireBrigadeMemberServiceI {
|
|||
void remove(Long id);
|
||||
|
||||
void removeBatch(Long[] ids);
|
||||
|
||||
SingleResponse<FireBrigadeMemberStatusCO> currentMemberStatus();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,14 +3,20 @@ package com.zcloud.zcGbsServicer.api;
|
|||
import com.alibaba.cola.dto.PageResponse;
|
||||
import com.alibaba.cola.dto.SingleResponse;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeAddCmd;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeOnlineStatusQry;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadePageQry;
|
||||
import com.zcloud.zcGbsServicer.dto.FireBrigadeUpdateCmd;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeCO;
|
||||
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeOnlineStatusCO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FireBrigadeServiceI {
|
||||
|
||||
PageResponse<FireBrigadeCO> listPage(FireBrigadePageQry qry);
|
||||
|
||||
SingleResponse<List<FireBrigadeOnlineStatusCO>> queryOnlineStatus(FireBrigadeOnlineStatusQry qry);
|
||||
|
||||
SingleResponse<FireBrigadeCO> add(FireBrigadeAddCmd cmd);
|
||||
|
||||
void edit(FireBrigadeUpdateCmd cmd);
|
||||
|
|
|
|||
|
|
@ -41,4 +41,7 @@ public class AlarmRecordAddCmd extends Command {
|
|||
@NotNull
|
||||
@ApiModelProperty("纬度")
|
||||
private Double lat;
|
||||
|
||||
@ApiModelProperty("接报方式,1:电话接报,2:APP报警;不传默认1")
|
||||
private Integer alarmMode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.zcloud.zcGbsServicer.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.alibaba.cola.dto.Command;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
|
@ -35,12 +36,14 @@ public class FireBrigadeMemberAddCmd extends Command {
|
|||
private String dutyId;
|
||||
|
||||
@ApiModelProperty("职务名称")
|
||||
@JsonAlias("dutyName")
|
||||
private String duty;
|
||||
|
||||
@ApiModelProperty("机构ID")
|
||||
private String corpId;
|
||||
|
||||
@ApiModelProperty("机构名称")
|
||||
@JsonAlias("orgName")
|
||||
private String org;
|
||||
|
||||
@ApiModelProperty("角色编码")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package com.zcloud.zcGbsServicer.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FireBrigadeOnlineStatusQry {
|
||||
|
||||
@ApiModelProperty("消防队伍业务ID列表,取自列表接口 fireBrigadeId 字段;调用后会刷新在线状态缓存")
|
||||
private List<String> fireBrigadeIds;
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.zcloud.zcGbsServicer.dto.clientobject;
|
|||
|
||||
import com.alibaba.cola.dto.ClientObject;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
|
@ -37,6 +38,10 @@ public class FireBrigadeCO extends ClientObject {
|
|||
private String brigadeInfo;
|
||||
|
||||
private Integer memberCount;
|
||||
|
||||
@ApiModelProperty("是否在线,列表接口返回缓存值(首次默认未在线,后台异步刷新)")
|
||||
private Boolean online;
|
||||
|
||||
@ApiModelProperty("在线状态文案")
|
||||
private String onlineText;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.zcloud.zcGbsServicer.dto.clientobject;
|
||||
|
||||
import com.alibaba.cola.dto.ClientObject;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
|
@ -12,22 +11,13 @@ public class FireBrigadeMemberCO extends ClientObject {
|
|||
private Long fireBrigadeId;
|
||||
private String fireBrigadeBizId;
|
||||
private String userId;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String userName;
|
||||
|
||||
private String name;
|
||||
private String gender;
|
||||
private String idNo;
|
||||
private String phone;
|
||||
private String dutyId;
|
||||
|
||||
@JsonProperty("duty")
|
||||
private String dutyName;
|
||||
|
||||
private String duty;
|
||||
private String corpId;
|
||||
|
||||
@JsonProperty("org")
|
||||
private String orgName;
|
||||
|
||||
private String org;
|
||||
private Integer roleCode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package com.zcloud.zcGbsServicer.dto.clientobject;
|
||||
|
||||
import com.alibaba.cola.dto.ClientObject;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FireBrigadeMemberStatusCO extends ClientObject {
|
||||
|
||||
@ApiModelProperty("当前登录用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("是否为消防队成员")
|
||||
private Boolean fireBrigadeMember;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.zcloud.zcGbsServicer.dto.clientobject;
|
||||
|
||||
import com.alibaba.cola.dto.ClientObject;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FireBrigadeOnlineStatusCO extends ClientObject {
|
||||
|
||||
@ApiModelProperty("消防队伍业务ID")
|
||||
private String fireBrigadeId;
|
||||
|
||||
@ApiModelProperty("是否在线")
|
||||
private Boolean online;
|
||||
|
||||
@ApiModelProperty("在线状态文案")
|
||||
private String onlineText;
|
||||
}
|
||||
|
|
@ -35,6 +35,7 @@ public class FireAlarmInfoDO extends BaseDO {
|
|||
private Long clearId;
|
||||
private String clearName;
|
||||
private String clearReason;
|
||||
private String clearPhotos;
|
||||
private String meetingRoomId;
|
||||
private String meetingRoomName;
|
||||
private Long meetingApplyUserId;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.zcloud.zcGbsServicer.persistence.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface AlarmUserMapper {
|
||||
|
||||
Long selectTenantIdByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package com.zcloud.zcGbsServicer.persistence.repository;
|
||||
|
||||
public interface AlarmUserRepository {
|
||||
|
||||
Long getTenantIdByUserId(Long userId);
|
||||
}
|
||||
|
|
@ -4,15 +4,16 @@ import com.alibaba.cola.dto.PageResponse;
|
|||
import com.jjb.saas.framework.repository.repo.BaseRepository;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireAlarmMeetingUserDO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface FireAlarmMeetingUserRepository extends BaseRepository<FireAlarmMeetingUserDO> {
|
||||
|
||||
PageResponse<FireAlarmMeetingUserDO> listPage(Map<String, Object> params);
|
||||
boolean existsByLocalUserId(Long localUserId, Long tenantId, Long excludeId);
|
||||
FireAlarmMeetingUserDO getByLocalUserId(Long localUserId, Long tenantId);
|
||||
List<FireAlarmMeetingUserDO> listByLocalUserIds(Collection<Long> localUserIds, Long tenantId);
|
||||
|
||||
boolean existsByLocalUserId(Long localUserId, Long excludeId);
|
||||
|
||||
FireAlarmMeetingUserDO getByLocalUserId(Long localUserId);
|
||||
|
||||
java.util.List<FireAlarmMeetingUserDO> listAll();
|
||||
List<FireAlarmMeetingUserDO> listAll();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,16 @@ import com.alibaba.cola.dto.PageResponse;
|
|||
import com.jjb.saas.framework.repository.repo.BaseRepository;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireBrigadeDO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface FireBrigadeRepository extends BaseRepository<FireBrigadeDO> {
|
||||
|
||||
PageResponse<FireBrigadeDO> listPage(Map<String, Object> params);
|
||||
|
||||
List<FireBrigadeDO> listByFireBrigadeIds(Collection<String> fireBrigadeIds);
|
||||
|
||||
boolean existsByBrigadeName(String brigadeName, Long excludeId);
|
||||
|
||||
FireBrigadeDO getByFireBrigadeId(String fireBrigadeId);
|
||||
|
|
|
|||
|
|
@ -3,12 +3,20 @@ package com.zcloud.zcGbsServicer.persistence.repository;
|
|||
import com.jjb.saas.framework.repository.repo.BaseRepository;
|
||||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireBrigadeUserDO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface FireBrigadeUserRepository extends BaseRepository<FireBrigadeUserDO> {
|
||||
|
||||
List<FireBrigadeUserDO> listAll();
|
||||
|
||||
List<FireBrigadeUserDO> listByFireBrigadeIds(Collection<String> fireBrigadeIds);
|
||||
|
||||
List<FireBrigadeUserDO> listByFireBrigadeIds(Collection<String> fireBrigadeIds, Long tenantId);
|
||||
|
||||
Map<String, Integer> countByFireBrigadeIds(Collection<String> fireBrigadeIds);
|
||||
|
||||
List<FireBrigadeUserDO> listByFireBrigadeId(String fireBrigadeId);
|
||||
|
||||
List<FireBrigadeUserDO> listByUserId(Long userId);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.zcloud.zcGbsServicer.persistence.repository.impl;
|
||||
|
||||
import com.zcloud.zcGbsServicer.persistence.mapper.AlarmUserMapper;
|
||||
import com.zcloud.zcGbsServicer.persistence.repository.AlarmUserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AlarmUserRepositoryImpl implements AlarmUserRepository {
|
||||
|
||||
private final AlarmUserMapper alarmUserMapper;
|
||||
|
||||
@Override
|
||||
public Long getTenantIdByUserId(Long userId) {
|
||||
if (userId == null) {
|
||||
return null;
|
||||
}
|
||||
return alarmUserMapper.selectTenantIdByUserId(userId);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,9 @@ import com.zcloud.zcGbsServicer.persistence.repository.FireAlarmMeetingUserRepos
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
|
|
@ -57,13 +60,16 @@ public class FireAlarmMeetingUserRepositoryImpl extends BaseRepositoryImpl<FireA
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByLocalUserId(Long localUserId, Long excludeId) {
|
||||
public boolean existsByLocalUserId(Long localUserId, Long tenantId, Long excludeId) {
|
||||
if (localUserId == null) {
|
||||
return false;
|
||||
}
|
||||
QueryWrapper<FireAlarmMeetingUserDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("local_user_id", localUserId).eq("delete_enum", "FALSE");
|
||||
if (AuthContext.getTenantId() != null) {
|
||||
if (tenantId != null) {
|
||||
wrapper.eq("tenant_id", tenantId);
|
||||
}
|
||||
else if (AuthContext.getTenantId() != null) {
|
||||
wrapper.eq("tenant_id", AuthContext.getTenantId());
|
||||
}
|
||||
if (excludeId != null) {
|
||||
|
|
@ -73,20 +79,37 @@ public class FireAlarmMeetingUserRepositoryImpl extends BaseRepositoryImpl<FireA
|
|||
}
|
||||
|
||||
@Override
|
||||
public FireAlarmMeetingUserDO getByLocalUserId(Long localUserId) {
|
||||
public FireAlarmMeetingUserDO getByLocalUserId(Long localUserId, Long tenantId) {
|
||||
if (localUserId == null) {
|
||||
return null;
|
||||
}
|
||||
QueryWrapper<FireAlarmMeetingUserDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("local_user_id", localUserId).eq("delete_enum", "FALSE").last("limit 1");
|
||||
if (AuthContext.getTenantId() != null) {
|
||||
if (tenantId != null) {
|
||||
wrapper.eq("tenant_id", tenantId);
|
||||
}
|
||||
else if (AuthContext.getTenantId() != null) {
|
||||
wrapper.eq("tenant_id", AuthContext.getTenantId());
|
||||
}
|
||||
return this.getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<FireAlarmMeetingUserDO> listAll() {
|
||||
public List<FireAlarmMeetingUserDO> listByLocalUserIds(Collection<Long> localUserIds, Long tenantId) {
|
||||
if (localUserIds == null || localUserIds.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
LambdaQueryWrapper<FireAlarmMeetingUserDO> wrapper = new LambdaQueryWrapper<FireAlarmMeetingUserDO>()
|
||||
.in(FireAlarmMeetingUserDO::getLocalUserId, localUserIds)
|
||||
.eq(FireAlarmMeetingUserDO::getDeleteEnum, "FALSE");
|
||||
if (tenantId != null) {
|
||||
wrapper.eq(FireAlarmMeetingUserDO::getTenantId, tenantId);
|
||||
}
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FireAlarmMeetingUserDO> listAll() {
|
||||
return this.list(new LambdaQueryWrapper<FireAlarmMeetingUserDO>()
|
||||
.eq(FireAlarmMeetingUserDO::getTenantId, AuthContext.getTenantId())
|
||||
.eq(FireAlarmMeetingUserDO::getDeleteEnum, "FALSE"));
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ import com.zcloud.zcGbsServicer.persistence.repository.FireBrigadeRepository;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
|
|
@ -30,6 +33,17 @@ public class FireBrigadeRepositoryImpl extends BaseRepositoryImpl<FireBrigadeMap
|
|||
return PageHelper.pageToResponse(result, result.getRecords());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FireBrigadeDO> listByFireBrigadeIds(Collection<String> fireBrigadeIds) {
|
||||
if (fireBrigadeIds == null || fireBrigadeIds.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return this.list(new LambdaQueryWrapper<FireBrigadeDO>()
|
||||
.in(FireBrigadeDO::getFireBrigadeId, fireBrigadeIds)
|
||||
.eq(FireBrigadeDO::getTenantId, AuthContext.getTenantId())
|
||||
.eq(FireBrigadeDO::getDeleteEnum, "FALSE"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByBrigadeName(String brigadeName, Long excludeId) {
|
||||
if (StrUtil.isBlank(brigadeName)) {
|
||||
|
|
|
|||
|
|
@ -6,10 +6,15 @@ import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
|
|||
import com.zcloud.zcGbsServicer.persistence.dataobject.FireBrigadeUserDO;
|
||||
import com.zcloud.zcGbsServicer.persistence.mapper.FireBrigadeUserMapper;
|
||||
import com.zcloud.zcGbsServicer.persistence.repository.FireBrigadeUserRepository;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
|
|
@ -22,6 +27,36 @@ public class FireBrigadeUserRepositoryImpl extends BaseRepositoryImpl<FireBrigad
|
|||
.eq(FireBrigadeUserDO::getDeleteEnum, "FALSE"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FireBrigadeUserDO> listByFireBrigadeIds(Collection<String> fireBrigadeIds) {
|
||||
return listByFireBrigadeIds(fireBrigadeIds, AuthContext.getTenantId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FireBrigadeUserDO> listByFireBrigadeIds(Collection<String> fireBrigadeIds, Long tenantId) {
|
||||
if (fireBrigadeIds == null || fireBrigadeIds.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
LambdaQueryWrapper<FireBrigadeUserDO> wrapper = new LambdaQueryWrapper<FireBrigadeUserDO>()
|
||||
.in(FireBrigadeUserDO::getFireBrigadeId, fireBrigadeIds)
|
||||
.eq(FireBrigadeUserDO::getDeleteEnum, "FALSE");
|
||||
if (tenantId != null) {
|
||||
wrapper.eq(FireBrigadeUserDO::getTenantId, tenantId);
|
||||
}
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> countByFireBrigadeIds(Collection<String> fireBrigadeIds) {
|
||||
if (fireBrigadeIds == null || fireBrigadeIds.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return listByFireBrigadeIds(fireBrigadeIds).stream()
|
||||
.filter(item -> item != null && StrUtil.isNotBlank(item.getFireBrigadeId()))
|
||||
.collect(Collectors.groupingBy(FireBrigadeUserDO::getFireBrigadeId,
|
||||
Collectors.collectingAndThen(Collectors.counting(), Long::intValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FireBrigadeUserDO> listByFireBrigadeId(String fireBrigadeId) {
|
||||
return this.list(new LambdaQueryWrapper<FireBrigadeUserDO>()
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ CREATE TABLE `fire_alarm_info` (
|
|||
`clear_id` bigint DEFAULT NULL COMMENT '消警人ID',
|
||||
`clear_name` varchar(64) DEFAULT NULL COMMENT '消警人姓名',
|
||||
`clear_reason` varchar(1000) DEFAULT NULL COMMENT '消警说明',
|
||||
`clear_photos` varchar(2000) DEFAULT NULL COMMENT '消警现场照片路径,JSON数组',
|
||||
`meeting_room_id` varchar(64) DEFAULT NULL COMMENT '会议室ID',
|
||||
`meeting_room_name` varchar(128) DEFAULT NULL COMMENT '会议室名称',
|
||||
`meeting_apply_user_id` bigint DEFAULT NULL COMMENT '申请入会本地用户ID',
|
||||
|
|
@ -197,7 +198,7 @@ CREATE TABLE `fire_brigade_user` (
|
|||
`env` varchar(32) DEFAULT NULL COMMENT '环境',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_fire_brigade_user_id` (`fire_brigade_user_id`) USING BTREE,
|
||||
UNIQUE KEY `uk_fire_brigade_user_rel` (`fire_brigade_id`,`user_id`) USING BTREE,
|
||||
UNIQUE KEY `uk_fire_brigade_user_rel` (`fire_brigade_id`,`user_id`,`delete_enum`) USING BTREE,
|
||||
KEY `idx_fire_brigade_id` (`fire_brigade_id`) USING BTREE,
|
||||
KEY `idx_user_id` (`user_id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='消防队伍人员表';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.zcloud.zcGbsServicer.persistence.mapper.AlarmUserMapper">
|
||||
|
||||
<select id="selectTenantIdByUserId" resultType="java.lang.Long">
|
||||
SELECT tenant_id
|
||||
FROM user
|
||||
WHERE id = #{userId}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue