48 行
1.6 KiB
Java
48 行
1.6 KiB
Java
|
|
package com.xuqm.im.service;
|
||
|
|
|
||
|
|
import com.xuqm.im.entity.ImGlobalMuteEntity;
|
||
|
|
import com.xuqm.im.repository.ImGlobalMuteRepository;
|
||
|
|
import org.springframework.stereotype.Service;
|
||
|
|
|
||
|
|
import java.time.LocalDateTime;
|
||
|
|
import java.util.UUID;
|
||
|
|
|
||
|
|
@Service
|
||
|
|
public class GlobalMuteService {
|
||
|
|
|
||
|
|
private final ImGlobalMuteRepository repository;
|
||
|
|
|
||
|
|
public GlobalMuteService(ImGlobalMuteRepository repository) {
|
||
|
|
this.repository = repository;
|
||
|
|
}
|
||
|
|
|
||
|
|
public boolean isEnabled(String appId) {
|
||
|
|
return repository.findByAppId(appId).map(ImGlobalMuteEntity::isEnabled).orElse(false);
|
||
|
|
}
|
||
|
|
|
||
|
|
public ImGlobalMuteEntity get(String appId) {
|
||
|
|
return repository.findByAppId(appId).orElseGet(() -> {
|
||
|
|
ImGlobalMuteEntity entity = new ImGlobalMuteEntity();
|
||
|
|
entity.setId(UUID.randomUUID().toString());
|
||
|
|
entity.setAppId(appId);
|
||
|
|
entity.setEnabled(false);
|
||
|
|
entity.setCreatedAt(LocalDateTime.now());
|
||
|
|
entity.setUpdatedAt(LocalDateTime.now());
|
||
|
|
return entity;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
public ImGlobalMuteEntity setEnabled(String appId, boolean enabled) {
|
||
|
|
ImGlobalMuteEntity entity = repository.findByAppId(appId).orElseGet(() -> {
|
||
|
|
ImGlobalMuteEntity created = new ImGlobalMuteEntity();
|
||
|
|
created.setId(UUID.randomUUID().toString());
|
||
|
|
created.setAppId(appId);
|
||
|
|
created.setCreatedAt(LocalDateTime.now());
|
||
|
|
return created;
|
||
|
|
});
|
||
|
|
entity.setEnabled(enabled);
|
||
|
|
entity.setUpdatedAt(LocalDateTime.now());
|
||
|
|
return repository.save(entity);
|
||
|
|
}
|
||
|
|
}
|